Skip to content

Commit

Permalink
v3.2.0
Browse files Browse the repository at this point in the history
Add Pepecoin configiration to Bip-44 and Bip-49 coins.
  • Loading branch information
mrtnetwork committed Jun 24, 2024
1 parent 1ee573d commit ff1842e
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
26 changes: 20 additions & 6 deletions lib/bip/address/xrp_addr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ class _XRPAddressConst {
static const int xAddressPrefixLength = 2;
}

class XRPXAddressDecodeResult {
final List<int> bytes;
final int? tag;
final bool isTestnet;
XRPXAddressDecodeResult(
{required List<int> 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.
///
Expand Down Expand Up @@ -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<List<int>, int?> decodeXAddress(String addr, List<int>? prefix) {
static XRPXAddressDecodeResult decodeXAddress(
String addr, List<int>? prefix) {
List<int> addrDecBytes =
Base58Decoder.checkDecode(addr, Base58Alphabets.ripple);

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -371,8 +385,8 @@ class XrpXAddrDecoder implements BlockchainAddressDecoder {
@override
List<int> decodeAddr(String addr, [Map<String, dynamic> kwargs = const {}]) {
final prefix =
AddrKeyValidator.validateAddressArgs<List<int>>(kwargs, "prefix");
AddrKeyValidator.nullOrValidateAddressArgs<List<int>>(kwargs, "prefix");

return XRPAddressUtils.decodeXAddress(addr, prefix).item1;
return XRPAddressUtils.decodeXAddress(addr, prefix).bytes;
}
}
8 changes: 8 additions & 0 deletions lib/bip/bip/conf/bip44/bip44_coins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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,
Expand Down
32 changes: 30 additions & 2 deletions lib/bip/bip/conf/bip44/bip44_conf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>.from([0x02, 0xfa, 0xca, 0xfd]),
List<int>.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<int>.from([0x04, 0x32, 0xa9, 0xa8]),
List<int>.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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions lib/bip/bip/conf/bip49/bip49_coins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
34 changes: 34 additions & 0 deletions lib/bip/bip/conf/bip49/bip49_conf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>.from([0x02, 0xfa, 0xca, 0xfd]),
List<int>.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<int>.from([0x04, 0x32, 0xa9, 0xa8]),
List<int>.from([0x04, 0x32, 0xa2, 0x43]),
),
wifNetVer: CoinsConf.pepeTestnet.params.wifNetVer,
type: EllipticCurveTypes.secp256k1,
addressEncoder: ([dynamic kwargs]) => P2SHAddrEncoder(),
addrParams: {
"net_ver": CoinsConf.pepeTestnet.params.p2shNetVer!,
});
}
20 changes: 20 additions & 0 deletions lib/bip/coin_conf/coins_conf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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],
),
);
}
3 changes: 3 additions & 0 deletions lib/bip/slip/slip44/slip44.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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: [email protected]
Expand Down

0 comments on commit ff1842e

Please sign in to comment.