diff --git a/token-core/tcx-btc-kin/src/address.rs b/token-core/tcx-btc-kin/src/address.rs index e8cd6058..f34ad67e 100644 --- a/token-core/tcx-btc-kin/src/address.rs +++ b/token-core/tcx-btc-kin/src/address.rs @@ -273,6 +273,7 @@ mod tests { use crate::address::BtcKinAddress; use crate::tcx_keystore::Address; + use crate::tests::sample_hd_keystore; use crate::BtcKinNetwork; #[test] @@ -302,6 +303,18 @@ mod tests { .unwrap() .to_string(); assert_eq!(addr, "bc1qum864wd9nwsc0u9ytkctz6wzrw6g7zdntm7f4e"); + + let network = BtcKinNetwork::find_by_coin("DOGECOIN", "MAINNET").unwrap(); + let addr = BtcKinAddress::p2pkh(&pub_key, &network) + .unwrap() + .to_string(); + assert_eq!(addr, "DSBWjKzZtz7fPzu4N6mBRwQFHCQ6KQSjue"); + + let network = BtcKinNetwork::find_by_coin("DOGECOIN", "TESTNET").unwrap(); + let addr = BtcKinAddress::p2pkh(&pub_key, &network) + .unwrap() + .to_string(); + assert_eq!(addr, "nqEaTLjUpxaPGyUFPvQdgLzYX4nPLCD1Py"); } #[test] @@ -477,6 +490,23 @@ mod tests { assert_eq!(address, "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4"); } + #[test] + fn test_dogecoin_address() { + let mut hd = sample_hd_keystore(); + let account = hd + .derive_coin::(&CoinInfo { + coin: "DOGECOIN".to_string(), + derivation_path: "m/44'/3'/0'/0/0".to_string(), + curve: CurveType::SECP256k1, + network: "MAINNET".to_string(), + seg_wit: "NONE".to_string(), + }) + .unwrap(); + assert_eq!(account.address, "DQ4tVEqdPWHc1aVBm4Sfwft8XyNRPMEchR"); + assert_eq!(account.ext_pub_key, "xpub6CDSaXHQokkKmHHG2kNCFZeirJkcZgRZE97ZZUtViif3SFHSNVAvRpWC3CxeRt2VZetEGCcPTmWEFpKF4NDeeZrMNPQgfUaX5Hkw89kW8qE"); + } + + #[test] fn test_bip84_spec_vector() { let pub_key = TypedPublicKey::from_slice( diff --git a/token-core/tcx-btc-kin/src/lib.rs b/token-core/tcx-btc-kin/src/lib.rs index bac3d331..fe32347b 100644 --- a/token-core/tcx-btc-kin/src/lib.rs +++ b/token-core/tcx-btc-kin/src/lib.rs @@ -33,6 +33,8 @@ pub use transaction::{BtcKinTxInput, BtcKinTxOutput, OmniTxInput, Utxo}; pub const BITCOIN: &str = "BITCOIN"; pub const BITCOINCASH: &str = "BITCOINCASH"; +pub const DOGECOIN: &str = "DOGECOIN"; + pub const LITECOIN: &str = "LITECOIN"; pub const OMNI: &str = "OMNI"; @@ -90,6 +92,22 @@ pub mod bitcoincash { pub type MessageOutput = crate::transaction::BtcMessageOutput; } +pub mod dogecoin { + use crate::DOGECOIN; + + pub static CHAINS: [&str; 1] = [DOGECOIN]; + + pub type Address = crate::BtcKinAddress; + + pub type TransactionInput = crate::transaction::BtcKinTxInput; + + pub type TransactionOutput = crate::transaction::BtcKinTxOutput; + + pub type MessageInput = crate::transaction::BtcMessageInput; + + pub type MessageOutput = crate::transaction::BtcMessageOutput; +} + pub mod omni { use crate::OMNI; diff --git a/token-core/tcx-btc-kin/src/network.rs b/token-core/tcx-btc-kin/src/network.rs index 2fa40979..fc1978af 100644 --- a/token-core/tcx-btc-kin/src/network.rs +++ b/token-core/tcx-btc-kin/src/network.rs @@ -11,7 +11,7 @@ pub struct BtcKinNetwork { pub xpub_prefix: [u8; 4], pub xprv_prefix: [u8; 4], } -const BTC_KIN_NETWORKS: [BtcKinNetwork; 6] = [ +const BTC_KIN_NETWORKS: [BtcKinNetwork; 8] = [ BtcKinNetwork { coin: "BITCOIN", network: "MAINNET", @@ -72,6 +72,26 @@ const BTC_KIN_NETWORKS: [BtcKinNetwork; 6] = [ xpub_prefix: [0x04, 0x35, 0x87, 0xcf], xprv_prefix: [0x04, 0x35, 0x83, 0x94], }, + BtcKinNetwork { + coin: "DOGECOIN", + network: "TESTNET", + bech32_hrp: "", + p2pkh_prefix: 0x71, + p2sh_prefix: 0xc4, + private_prefix: 0xf1, + xpub_prefix: [0x04, 0x35, 0x87, 0xcf], + xprv_prefix: [0x04, 0x35, 0x83, 0x94], + }, + BtcKinNetwork { + coin: "DOGECOIN", + network: "MAINNET", + bech32_hrp: "", + p2pkh_prefix: 0x1e, + p2sh_prefix: 0x16, + private_prefix: 0x9e, + xpub_prefix: [0x02, 0xfa, 0xca, 0xfd], + xprv_prefix: [0x02, 0xfa, 0xc3, 0x98], + }, ]; impl BtcKinNetwork {