Skip to content

Commit

Permalink
Merge pull request #7 from sandrocsimas/main
Browse files Browse the repository at this point in the history
Support Electra Protocol
  • Loading branch information
mrtnetwork authored Dec 4, 2024
2 parents 23e5631 + 397e7d5 commit 1153595
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 27 deletions.
9 changes: 9 additions & 0 deletions lib/bip/bip/conf/bip44/bip44_coins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ class Bip44Coins extends BipCoins {
/// Zilliqa
static const zilliqa = Bip44Coins._('zilliqa');

/// Electra Protocol
static const electraProtocol = Bip44Coins._('electraProtocol');

// Test nets

/// Bitcoin Cash Testnet
Expand Down Expand Up @@ -355,6 +358,9 @@ class Bip44Coins extends BipCoins {
/// Ton Testnet
static const tonMainnet = Bip44Coins._('tonMainnet');

/// Electra Protocol Testnet
static const electraProtocolTestnet = Bip44Coins._('electraProtocolTestnet');

// Fields and methods

@override
Expand Down Expand Up @@ -478,7 +484,10 @@ class Bip44Coins extends BipCoins {
Bip44Coins.zilliqa: Bip44Conf.zilliqa,
Bip44Coins.tonTestnet: Bip44Conf.tonTestnet,
Bip44Coins.tonMainnet: Bip44Conf.tonMainnet,
Bip44Coins.electraProtocol: Bip44Conf.electraProtocolMainNet,
Bip44Coins.electraProtocolTestnet: Bip44Conf.electraProtocolTestNet,
};

@override
BipProposal get proposal => BipProposal.bip44;

Expand Down
39 changes: 38 additions & 1 deletion lib/bip/bip/conf/bip44/bip44_conf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'package:blockchain_utils/bip/bip/bip32/bip32_const.dart';
import 'package:blockchain_utils/bip/bip/bip32/bip32_key_net_ver.dart';
import 'package:blockchain_utils/bip/bip/conf/config/bip_bitcoin_cash_conf.dart';
import 'package:blockchain_utils/bip/bip/conf/config/bip_coin_conf.dart';
import 'package:blockchain_utils/bip/bip/conf/const/bip_conf_const.dart';
import 'package:blockchain_utils/bip/bip/conf/config/bip_litecoin_conf.dart';
import 'package:blockchain_utils/bip/bip/conf/const/bip_conf_const.dart';
import 'package:blockchain_utils/bip/coin_conf/coins_conf.dart';
import 'package:blockchain_utils/bip/ecc/curve/elliptic_curve_types.dart';
import 'package:blockchain_utils/bip/slip/slip44/slip44.dart';
Expand Down Expand Up @@ -1408,6 +1408,7 @@ class Bip44Conf {
addressEncoder: ([dynamic kwargs]) => TonAddrEncoder(),
addrParams: {"workchain": CoinsConf.tonMainnet.params.workchain},
);

static final BipCoinConfig tonTestnet = BipCoinConfig(
coinNames: CoinsConf.tonTestnet.coinName,
coinIdx: Slip44.testnet,
Expand All @@ -1419,4 +1420,40 @@ class Bip44Conf {
addressEncoder: ([dynamic kwargs]) => TonAddrEncoder(),
addrParams: {"workchain": CoinsConf.tonTestnet.params.workchain},
);

/// Configuration for Electra Protocol main net
static final BipCoinConfig electraProtocolMainNet = BipCoinConfig(
coinNames: CoinsConf.electraProtocolMainNet.coinName,
coinIdx: Slip44.electraProtocol,
isTestnet: false,
defPath: derPathNonHardenedFull,
keyNetVer: Bip32KeyNetVersions(
List<int>.from([0x04, 0x88, 0xb2, 0x1e]),
List<int>.from([0x04, 0x88, 0xad, 0xe4]),
),
wifNetVer: CoinsConf.electraProtocolMainNet.params.wifNetVer,
type: EllipticCurveTypes.secp256k1,
addressEncoder: ([dynamic kwargs]) => P2PKHAddrEncoder(),
addrParams: {
"net_ver": CoinsConf.electraProtocolMainNet.params.p2pkhNetVer!,
},
);

/// Configuration for Electra Protocol test net
static final BipCoinConfig electraProtocolTestNet = BipCoinConfig(
coinNames: CoinsConf.electraProtocolTestNet.coinName,
coinIdx: Slip44.electraProtocol,
isTestnet: true,
defPath: derPathNonHardenedFull,
keyNetVer: Bip32KeyNetVersions(
List<int>.from([0x04, 0x35, 0x87, 0xcf]),
List<int>.from([0x04, 0x35, 0x83, 0x94]),
),
wifNetVer: CoinsConf.electraProtocolTestNet.params.wifNetVer,
type: EllipticCurveTypes.secp256k1,
addressEncoder: ([dynamic kwargs]) => P2PKHAddrEncoder(),
addrParams: {
"net_ver": CoinsConf.electraProtocolTestNet.params.p2pkhNetVer!,
},
);
}
7 changes: 5 additions & 2 deletions lib/bip/bip/conf/bip49/bip49_coins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Bip49Coins extends BipCoins {
static const Bip49Coins litecoin = Bip49Coins._('litecoin');
static const Bip49Coins zcash = Bip49Coins._('zcash');
static const Bip49Coins pepecoin = Bip49Coins._('pepecoin');
static const Bip49Coins omniXep = Bip49Coins._('omniXep');
static const Bip49Coins electraProtocol = Bip49Coins._('electraProtocol');

// Test nets
static const Bip49Coins bitcoinCashTestnet =
Expand All @@ -30,6 +30,8 @@ class Bip49Coins extends BipCoins {
static const Bip49Coins litecoinTestnet = Bip49Coins._('litecoinTestnet');
static const Bip49Coins zcashTestnet = Bip49Coins._('zcashTestnet');
static const Bip49Coins pepecoinTestnet = Bip49Coins._('pepecoinTestnet');
static const Bip49Coins electraProtocolTestnet =
Bip49Coins._('electraProtocolTestnet');

final String name;

Expand Down Expand Up @@ -77,7 +79,8 @@ class Bip49Coins extends BipCoins {
Bip49Coins.zcashTestnet: Bip49Conf.zcashTestNet,
Bip49Coins.pepecoin: Bip49Conf.pepeMainnet,
Bip49Coins.pepecoinTestnet: Bip49Conf.pepeTestnet,
Bip49Coins.omniXep: Bip49Conf.omniXepMainNet
Bip49Coins.electraProtocol: Bip49Conf.electraProtocolMainNet,
Bip49Coins.electraProtocolTestnet: Bip49Conf.electraProtocolTestNet,
};

@override
Expand Down
53 changes: 36 additions & 17 deletions lib/bip/bip/conf/bip49/bip49_conf.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:blockchain_utils/bip/address/p2sh_addr.dart';
import 'package:blockchain_utils/bip/bip/bip32/bip32_key_net_ver.dart';
import 'package:blockchain_utils/bip/bip/conf/const/bip_conf_const.dart';
import 'package:blockchain_utils/bip/bip/conf/config/bip_bitcoin_cash_conf.dart';
import 'package:blockchain_utils/bip/bip/conf/config/bip_coin_conf.dart';
import 'package:blockchain_utils/bip/bip/conf/config/bip_litecoin_conf.dart';
import 'package:blockchain_utils/bip/bip/conf/const/bip_conf_const.dart';
import 'package:blockchain_utils/bip/coin_conf/coins_conf.dart';
import 'package:blockchain_utils/bip/ecc/curve/elliptic_curve_types.dart';
import 'package:blockchain_utils/bip/slip/slip44/slip44.dart';
Expand Down Expand Up @@ -411,20 +411,39 @@ class Bip49Conf {
"net_ver": CoinsConf.pepeTestnet.params.p2shNetVer!,
});

/// Configuration for Omni XEP main net
static final BipCoinConfig omniXepMainNet = BipCoinConfig(
coinNames: CoinsConf.omniXepMainNet.coinName,
coinIdx: Slip44.omniXep,
isTestnet: false,
defPath: derPathNonHardenedFull,
keyNetVer: Bip32KeyNetVersions(
List<int>.from([0x04, 0x88, 0xb2, 0x1e]),
List<int>.from([0x04, 0x88, 0xad, 0xe4]),
),
wifNetVer: CoinsConf.omniXepMainNet.params.wifNetVer,
type: EllipticCurveTypes.secp256k1,
addressEncoder: ([dynamic kwargs]) => P2SHAddrEncoder(),
addrParams: {
"net_ver": CoinsConf.omniXepMainNet.params.p2shNetVer!,
});
/// Configuration for Electra Protocol main net
static final BipCoinConfig electraProtocolMainNet = BipCoinConfig(
coinNames: CoinsConf.electraProtocolMainNet.coinName,
coinIdx: Slip44.electraProtocol,
isTestnet: false,
defPath: derPathNonHardenedFull,
keyNetVer: Bip32KeyNetVersions(
List<int>.from([0x04, 0x88, 0xb2, 0x1e]),
List<int>.from([0x04, 0x88, 0xad, 0xe4]),
),
wifNetVer: CoinsConf.electraProtocolMainNet.params.wifNetVer,
type: EllipticCurveTypes.secp256k1,
addressEncoder: ([dynamic kwargs]) => P2SHAddrEncoder(),
addrParams: {
"net_ver": CoinsConf.electraProtocolMainNet.params.p2shNetVer!,
},
);

/// Configuration for Electra Protocol test net
static final BipCoinConfig electraProtocolTestNet = BipCoinConfig(
coinNames: CoinsConf.electraProtocolTestNet.coinName,
coinIdx: Slip44.electraProtocol,
isTestnet: true,
defPath: derPathNonHardenedFull,
keyNetVer: Bip32KeyNetVersions(
List<int>.from([0x04, 0x35, 0x87, 0xcf]),
List<int>.from([0x04, 0x35, 0x83, 0x94]),
),
wifNetVer: CoinsConf.electraProtocolTestNet.params.wifNetVer,
type: EllipticCurveTypes.secp256k1,
addressEncoder: ([dynamic kwargs]) => P2SHAddrEncoder(),
addrParams: {
"net_ver": CoinsConf.electraProtocolTestNet.params.p2shNetVer!,
},
);
}
10 changes: 9 additions & 1 deletion lib/bip/bip/conf/bip84/bip84_coins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,21 @@ class Bip84Coins extends BipCoins {
// Main nets
static const Bip84Coins bitcoin = Bip84Coins._('bitcoin');
static const Bip84Coins litecoin = Bip84Coins._('litecoin');
static const Bip84Coins electraProtocol = Bip84Coins._('electraProtocol');

// Test nets
static const Bip84Coins bitcoinTestnet = Bip84Coins._('bitcoinTestnet');
static const Bip84Coins litecoinTestnet = Bip84Coins._('litecoinTestnet');
static const Bip84Coins electraProtocolTestnet =
Bip84Coins._('electraProtocolTestnet');

static const List<Bip84Coins> values = [
bitcoin,
litecoin,
electraProtocol,
bitcoinTestnet,
litecoinTestnet
litecoinTestnet,
electraProtocolTestnet,
];
final String name;

Expand Down Expand Up @@ -100,6 +106,8 @@ class Bip84Coins extends BipCoins {
Bip84Coins.bitcoinTestnet: Bip84Conf.bitcoinTestNet,
Bip84Coins.litecoin: Bip84Conf.litecoinMainNet,
Bip84Coins.litecoinTestnet: Bip84Conf.litecoinTestNet,
Bip84Coins.electraProtocol: Bip84Conf.electraProtocolMainNet,
Bip84Coins.electraProtocolTestnet: Bip84Conf.electraProtocolTestNet,
};

@override
Expand Down
38 changes: 37 additions & 1 deletion lib/bip/bip/conf/bip84/bip84_conf.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:blockchain_utils/bip/address/p2wpkh_addr.dart';
import 'package:blockchain_utils/bip/address/encoders.dart';
import 'package:blockchain_utils/bip/bip/bip32/bip32_key_net_ver.dart';
import 'package:blockchain_utils/bip/bip/conf/config/bip_coin_conf.dart';
import 'package:blockchain_utils/bip/bip/conf/const/bip_conf_const.dart';
Expand Down Expand Up @@ -72,4 +72,40 @@ class Bip84Conf {
addrParams: {"hrp": CoinsConf.litecoinTestNet.params.p2wpkhHrp!},
addressEncoder: ([dynamic kwargs]) => P2WPKHAddrEncoder(),
);

/// Configuration for Electra Protocol main net
static final BipCoinConfig electraProtocolMainNet = BipCoinConfig(
coinNames: CoinsConf.electraProtocolMainNet.coinName,
coinIdx: Slip44.electraProtocol,
isTestnet: false,
defPath: derPathNonHardenedFull,
keyNetVer: Bip32KeyNetVersions(
List<int>.from([0x04, 0x88, 0xb2, 0x1e]),
List<int>.from([0x04, 0x88, 0xad, 0xe4]),
),
wifNetVer: CoinsConf.electraProtocolMainNet.params.wifNetVer,
type: EllipticCurveTypes.secp256k1,
addressEncoder: ([dynamic kwargs]) => P2WPKHAddrEncoder(),
addrParams: {
"hrp": CoinsConf.electraProtocolMainNet.params.p2wpkhHrp!,
},
);

/// Configuration for Electra Protocol test net
static final BipCoinConfig electraProtocolTestNet = BipCoinConfig(
coinNames: CoinsConf.electraProtocolTestNet.coinName,
coinIdx: Slip44.electraProtocol,
isTestnet: true,
defPath: derPathNonHardenedFull,
keyNetVer: Bip32KeyNetVersions(
List<int>.from([0x04, 0x35, 0x87, 0xcf]),
List<int>.from([0x04, 0x35, 0x83, 0x94]),
),
wifNetVer: CoinsConf.electraProtocolTestNet.params.wifNetVer,
type: EllipticCurveTypes.secp256k1,
addressEncoder: ([dynamic kwargs]) => P2WPKHAddrEncoder(),
addrParams: {
"hrp": CoinsConf.electraProtocolMainNet.params.p2wpkhHrp!,
},
);
}
19 changes: 15 additions & 4 deletions lib/bip/coin_conf/coins_conf.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:blockchain_utils/bip/slip/slip173/slip173.dart';
import 'package:blockchain_utils/bip/coin_conf/coins_name.dart';
import 'package:blockchain_utils/bip/slip/slip173/slip173.dart';

import 'coin_conf.dart';

Expand Down Expand Up @@ -707,14 +707,25 @@ class CoinsConf {
),
);

/// Configuration for Omni XEP main net
static const CoinConf omniXepMainNet = CoinConf(
coinName: CoinNames("Omni XEP", "OXEP"),
/// Configuration for Electra Protocol main net
static const CoinConf electraProtocolMainNet = CoinConf(
coinName: CoinNames("Electra Protocol", "XEP"),
params: CoinParams(
p2pkhNetVer: [0x37],
p2shNetVer: [0x89],
wifNetVer: [0xa2],
p2wpkhHrp: "ep",
),
);

/// Configuration for Electra Protocol test net
static const CoinConf electraProtocolTestNet = CoinConf(
coinName: CoinNames("Electra Protocol TestNet", "XEP"),
params: CoinParams(
p2pkhNetVer: [0x8d],
p2shNetVer: [0x13],
wifNetVer: [0xef],
p2wpkhHrp: "te",
),
);
}
2 changes: 1 addition & 1 deletion lib/bip/slip/slip44/slip44.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,5 @@ class Slip44 {
static const int celo = 52752;
static const int piNetwork = 314159;
static const int pepecoin = 3434;
static const int omniXep = 597;
static const int electraProtocol = 597;
}

0 comments on commit 1153595

Please sign in to comment.