diff --git a/CHANGELOG.md b/CHANGELOG.md index 79f71a9..aa43c83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.0 + + - Add Pepecoin configiration to Bip-44 and Bip-49 coins. + ## 3.1.0 - Ton Address Support: Implemented functionality to support Ton addresses. diff --git a/lib/bip/address/xrp_addr.dart b/lib/bip/address/xrp_addr.dart index 2ca9fff..6fd5394 100644 --- a/lib/bip/address/xrp_addr.dart +++ b/lib/bip/address/xrp_addr.dart @@ -25,6 +25,15 @@ class _XRPAddressConst { static const int xAddressPrefixLength = 2; } +class XRPXAddressDecodeResult { + final List bytes; + final int? tag; + final bool isTestnet; + XRPXAddressDecodeResult( + {required List bytes, required this.tag, required this.isTestnet}) + : bytes = BytesUtils.toBytes(bytes, unmodifiable: true); +} + class XRPAddressUtils { /// Generates an XRP (Ripple) address from the provided address hash. /// @@ -89,7 +98,8 @@ class XRPAddressUtils { /// [prefix] The optional prefix representing the network type (mainnet or testnet). /// returns A tuple containing the address hash and an optional tag extracted from the X-Address. /// throws ArgumentException if the decoded address has invalid length, prefix mismatch, or an invalid tag. - static Tuple, int?> decodeXAddress(String addr, List? prefix) { + static XRPXAddressDecodeResult decodeXAddress( + String addr, List? prefix) { List addrDecBytes = Base58Decoder.checkDecode(addr, Base58Alphabets.ripple); @@ -138,7 +148,11 @@ class XRPAddressUtils { tag = readUint32LE(tagBytes); } - return Tuple(addrHash, tag); + return XRPXAddressDecodeResult( + bytes: addrHash, + tag: tag, + isTestnet: BytesUtils.bytesEqual( + prefixBytes, _XRPAddressConst._xAddressPrefixTest)); } /// Converts a classic XRP address to an X-Address. @@ -190,7 +204,7 @@ class XRPAddressUtils { return decode; } catch (e) { final xAddr = decodeXAddress(address, xAddrPrefix); - return xAddr.item1; + return xAddr.bytes; } } catch (e) { throw const AddressConverterException( @@ -241,7 +255,7 @@ class XRPAddressUtils { if (isClassicAddress(address)) { return address; } - final addrHash = decodeXAddress(address, null).item1; + final addrHash = decodeXAddress(address, null).bytes; return hashToAddress(addrHash); } } @@ -371,8 +385,8 @@ class XrpXAddrDecoder implements BlockchainAddressDecoder { @override List decodeAddr(String addr, [Map kwargs = const {}]) { final prefix = - AddrKeyValidator.validateAddressArgs>(kwargs, "prefix"); + AddrKeyValidator.nullOrValidateAddressArgs>(kwargs, "prefix"); - return XRPAddressUtils.decodeXAddress(addr, prefix).item1; + return XRPAddressUtils.decodeXAddress(addr, prefix).bytes; } } diff --git a/lib/bip/bip/conf/bip44/bip44_coins.dart b/lib/bip/bip/conf/bip44/bip44_coins.dart index 49e3c70..6bff0f2 100644 --- a/lib/bip/bip/conf/bip44/bip44_coins.dart +++ b/lib/bip/bip/conf/bip44/bip44_coins.dart @@ -147,6 +147,9 @@ class Bip44Coins implements CryptoCoins { /// Dogecoin static const dogecoin = Bip44Coins._('dogecoin'); + /// Pepecoin + static const pepecoin = Bip44Coins._('pepecoin'); + /// eCash static const ecash = Bip44Coins._('ecash'); @@ -320,6 +323,9 @@ class Bip44Coins implements CryptoCoins { /// Dogecoin Testnet static const dogecoinTestnet = Bip44Coins._('dogecoinTestnet'); + /// Pepecoin Testnet + static const pepecoinTestnet = Bip44Coins._('pepecoinTestnet'); + /// eCash Testnet static const ecashTestnet = Bip44Coins._('ecashTestnet'); @@ -399,6 +405,8 @@ class Bip44Coins implements CryptoCoins { Bip44Coins.dashTestnet: Bip44Conf.dashTestNet, Bip44Coins.dogecoin: Bip44Conf.dogecoinMainNet, Bip44Coins.dogecoinTestnet: Bip44Conf.dogecoinTestNet, + Bip44Coins.pepecoin: Bip44Conf.pepeMainnet, + Bip44Coins.pepecoinTestnet: Bip44Conf.pepeTestnet, Bip44Coins.ecash: Bip44Conf.ecashMainNet, Bip44Coins.ecashTestnet: Bip44Conf.ecashTestNet, Bip44Coins.elrond: Bip44Conf.elrond, diff --git a/lib/bip/bip/conf/bip44/bip44_conf.dart b/lib/bip/bip/conf/bip44/bip44_conf.dart index 735bf41..ef5c6bb 100644 --- a/lib/bip/bip/conf/bip44/bip44_conf.dart +++ b/lib/bip/bip/conf/bip44/bip44_conf.dart @@ -534,6 +534,34 @@ class Bip44Conf { }, ); + /// Configuration for Pepecoin main net + static final CoinConfig pepeMainnet = CoinConfig( + coinNames: CoinsConf.pepeMainnet.coinName, + coinIdx: Slip44.pepecoin, + isTestnet: false, + defPath: derPathNonHardenedFull, + keyNetVer: Bip32KeyNetVersions(List.from([0x02, 0xfa, 0xca, 0xfd]), + List.from([0x02, 0xfa, 0xc3, 0x98])), + wifNetVer: CoinsConf.pepeMainnet.params.wifNetVer, + type: EllipticCurveTypes.secp256k1, + addressEncoder: ([dynamic kwargs]) => P2PKHAddrEncoder(), + addrParams: {"net_ver": CoinsConf.pepeMainnet.params.p2pkhNetVer!}, + ); + + /// Configuration for Pepecoin test net + static final CoinConfig pepeTestnet = CoinConfig( + coinNames: CoinsConf.pepeTestnet.coinName, + coinIdx: Slip44.testnet, + isTestnet: true, + defPath: derPathNonHardenedFull, + keyNetVer: Bip32KeyNetVersions(List.from([0x04, 0x32, 0xa9, 0xa8]), + List.from([0x04, 0x32, 0xa2, 0x43])), + wifNetVer: CoinsConf.pepeTestnet.params.wifNetVer, + type: EllipticCurveTypes.secp256k1, + addressEncoder: ([dynamic kwargs]) => P2PKHAddrEncoder(), + addrParams: {"net_ver": CoinsConf.pepeTestnet.params.p2pkhNetVer!}, + ); + /// Configuration for eCash main net static final BipBitcoinCashConf ecashMainNet = BipBitcoinCashConf( coinNames: CoinsConf.ecashMainNet.coinName, @@ -1096,7 +1124,7 @@ class Bip44Conf { coinNames: CoinsConf.ripple.coinName, coinIdx: Slip44.ripple, isTestnet: false, - defPath: derPathNonHardenedFull, + defPath: derPathHardenedFull, keyNetVer: bip44BtcKeyNetVerMain, wifNetVer: null, type: EllipticCurveTypes.ed25519, @@ -1112,7 +1140,7 @@ class Bip44Conf { coinNames: CoinsConf.ripple.coinName, coinIdx: Slip44.testnet, isTestnet: true, - defPath: derPathNonHardenedFull, + defPath: derPathHardenedFull, keyNetVer: bip44BtcKeyNetVerMain, wifNetVer: null, type: EllipticCurveTypes.ed25519, diff --git a/lib/bip/bip/conf/bip49/bip49_coins.dart b/lib/bip/bip/conf/bip49/bip49_coins.dart index 682950a..5688b22 100644 --- a/lib/bip/bip/conf/bip49/bip49_coins.dart +++ b/lib/bip/bip/conf/bip49/bip49_coins.dart @@ -14,6 +14,7 @@ class Bip49Coins implements CryptoCoins { static const Bip49Coins ecash = Bip49Coins._('ecash'); static const Bip49Coins litecoin = Bip49Coins._('litecoin'); static const Bip49Coins zcash = Bip49Coins._('zcash'); + static const Bip49Coins pepecoin = Bip49Coins._('pepecoin'); // Test nets static const Bip49Coins bitcoinCashTestnet = @@ -27,6 +28,7 @@ class Bip49Coins implements CryptoCoins { static const Bip49Coins ecashTestnet = Bip49Coins._('ecashTestnet'); static const Bip49Coins litecoinTestnet = Bip49Coins._('litecoinTestnet'); static const Bip49Coins zcashTestnet = Bip49Coins._('zcashTestnet'); + static const Bip49Coins pepecoinTestnet = Bip49Coins._('pepecoinTestnet'); final String name; @@ -72,6 +74,8 @@ class Bip49Coins implements CryptoCoins { Bip49Coins.litecoinTestnet: Bip49Conf.litecoinTestNet, Bip49Coins.zcash: Bip49Conf.zcashMainNet, Bip49Coins.zcashTestnet: Bip49Conf.zcashTestNet, + Bip49Coins.pepecoin: Bip49Conf.pepeMainnet, + Bip49Coins.pepecoinTestnet: Bip49Conf.pepeTestnet }; @override BipProposal get proposal => BipProposal.bip49; diff --git a/lib/bip/bip/conf/bip49/bip49_conf.dart b/lib/bip/bip/conf/bip49/bip49_conf.dart index 0f66c3e..7776099 100644 --- a/lib/bip/bip/conf/bip49/bip49_conf.dart +++ b/lib/bip/bip/conf/bip49/bip49_conf.dart @@ -377,4 +377,38 @@ class Bip49Conf { }, }, ); + + /// Configuration for pepecoin main net + static final CoinConfig pepeMainnet = CoinConfig( + coinNames: CoinsConf.pepeMainnet.coinName, + coinIdx: Slip44.pepecoin, + isTestnet: false, + defPath: derPathNonHardenedFull, + keyNetVer: Bip32KeyNetVersions( + List.from([0x02, 0xfa, 0xca, 0xfd]), + List.from([0x02, 0xfa, 0xc3, 0x98]), + ), + wifNetVer: CoinsConf.pepeMainnet.params.wifNetVer, + type: EllipticCurveTypes.secp256k1, + addressEncoder: ([dynamic kwargs]) => P2SHAddrEncoder(), + addrParams: { + "net_ver": CoinsConf.pepeMainnet.params.p2shNetVer!, + }); + + /// Configuration for pepecoin test net + static final CoinConfig pepeTestnet = CoinConfig( + coinNames: CoinsConf.pepeTestnet.coinName, + coinIdx: Slip44.testnet, + isTestnet: true, + defPath: derPathNonHardenedFull, + keyNetVer: Bip32KeyNetVersions( + List.from([0x04, 0x32, 0xa9, 0xa8]), + List.from([0x04, 0x32, 0xa2, 0x43]), + ), + wifNetVer: CoinsConf.pepeTestnet.params.wifNetVer, + type: EllipticCurveTypes.secp256k1, + addressEncoder: ([dynamic kwargs]) => P2SHAddrEncoder(), + addrParams: { + "net_ver": CoinsConf.pepeTestnet.params.p2shNetVer!, + }); } diff --git a/lib/bip/coin_conf/coins_conf.dart b/lib/bip/coin_conf/coins_conf.dart index 471fe06..33d1f97 100644 --- a/lib/bip/coin_conf/coins_conf.dart +++ b/lib/bip/coin_conf/coins_conf.dart @@ -686,4 +686,24 @@ class CoinsConf { static const CoinConf tonMainnet = CoinConf( coinName: CoinNames("The Open Network", "TON"), params: CoinParams(workchain: 0)); + + /// Configuration for pepecoin main net + static const CoinConf pepeMainnet = CoinConf( + coinName: CoinNames("Pepecoin", "PEPE"), + params: CoinParams( + p2pkhNetVer: [0x38], + p2shNetVer: [0x16], + wifNetVer: [0x9e], + ), + ); + + /// Configuration for pepecoin test net + static const CoinConf pepeTestnet = CoinConf( + coinName: CoinNames("Pepecoin TestNet", "PEPE"), + params: CoinParams( + p2pkhNetVer: [0x71], + p2shNetVer: btcP2SHNetVerTn, + wifNetVer: [0xf1], + ), + ); } diff --git a/lib/bip/slip/slip44/slip44.dart b/lib/bip/slip/slip44/slip44.dart index 24d8a6c..c39823b 100644 --- a/lib/bip/slip/slip44/slip44.dart +++ b/lib/bip/slip/slip44/slip44.dart @@ -102,4 +102,7 @@ class Slip44 { static const int avalanche = 9000; static const int celo = 52752; static const int piNetwork = 314159; + + /// Unofficial coin id + static const int pepecoin = 3434; } diff --git a/pubspec.yaml b/pubspec.yaml index 18a070d..7a1d4ef 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: blockchain_utils description: Comprehensive Crypto & Blockchain Toolkit, Pure Dart, Cross-Platform, Encoding, Cryptography, Addresses, Mnemonics, & More. -version: 3.1.0 +version: 3.2.0 homepage: "https://github.com/mrtnetwork/blockchain_utils" repository: "https://github.com/mrtnetwork/blockchain_utils" Author: mrhaydari.t@gmail.com