From 4039e2f1acdbbed84ad161e6fe11426a9d24b06a Mon Sep 17 00:00:00 2001 From: sun Date: Thu, 15 Aug 2024 18:37:31 +0800 Subject: [PATCH] Feature/support dogecoin (#116) * add dogecoin testnet & mainnet * add dogecoin extend public key tests * fix: fix derive dogecoin unsupported_chain error --------- Co-authored-by: xiaoguang --- token-core/tcx-btc-kin/src/lib.rs | 4 +- token-core/tcx-constants/src/coin_info.rs | 56 +++++++++++++++++++++++ token-core/tcx/tests/derive_test.rs | 42 ++++++++++++++++- 3 files changed, 99 insertions(+), 3 deletions(-) diff --git a/token-core/tcx-btc-kin/src/lib.rs b/token-core/tcx-btc-kin/src/lib.rs index fe32347b..1b536764 100644 --- a/token-core/tcx-btc-kin/src/lib.rs +++ b/token-core/tcx-btc-kin/src/lib.rs @@ -65,8 +65,8 @@ pub enum Error { } pub mod bitcoin { - use crate::{BITCOIN, LITECOIN}; - pub const CHAINS: [&str; 2] = [BITCOIN, LITECOIN]; + use crate::{BITCOIN, DOGECOIN, LITECOIN}; + pub const CHAINS: [&str; 3] = [BITCOIN, LITECOIN, DOGECOIN]; pub type Address = crate::BtcKinAddress; pub type TransactionInput = crate::transaction::BtcKinTxInput; pub type TransactionOutput = crate::transaction::BtcKinTxOutput; diff --git a/token-core/tcx-constants/src/coin_info.rs b/token-core/tcx-constants/src/coin_info.rs index 130142f0..df9e6725 100644 --- a/token-core/tcx-constants/src/coin_info.rs +++ b/token-core/tcx-constants/src/coin_info.rs @@ -296,6 +296,62 @@ lazy_static! { seg_wit: "".to_string(), hrp: "".to_string(), }, + 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(), + }, + CoinInfo { + coin: "DOGECOIN".to_string(), + derivation_path: "m/44'/1'/0'/0/0".to_string(), + curve: CurveType::SECP256k1, + network: "TESTNET".to_string(), + seg_wit: "NONE".to_string(), + }, + CoinInfo { + coin: "DOGECOIN".to_string(), + derivation_path: "m/49'/3'/0'/0/0".to_string(), + curve: CurveType::SECP256k1, + network: "MAINNET".to_string(), + seg_wit: "P2WPKH".to_string(), + }, + CoinInfo { + coin: "DOGECOIN".to_string(), + derivation_path: "m/49'/1'/0'/0/0".to_string(), + curve: CurveType::SECP256k1, + network: "TESTNET".to_string(), + seg_wit: "P2WPKH".to_string(), + }, + CoinInfo { + coin: "DOGECOIN".to_string(), + derivation_path: "m/84'/3'/0'/0/0".to_string(), + curve: CurveType::SECP256k1, + network: "MAINNET".to_string(), + seg_wit: "VERSION_0".to_string(), + }, + CoinInfo { + coin: "DOGECOIN".to_string(), + derivation_path: "m/84'/1'/0'/0/0".to_string(), + curve: CurveType::SECP256k1, + network: "TESTNET".to_string(), + seg_wit: "VERSION_0".to_string(), + }, + CoinInfo { + coin: "DOGECOIN".to_string(), + derivation_path: "m/86'/3'/0'/0/0".to_string(), + curve: CurveType::SECP256k1, + network: "MAINNET".to_string(), + seg_wit: "VERSION_1".to_string(), + }, + CoinInfo { + coin: "DOGECOIN".to_string(), + derivation_path: "m/86'/1'/0'/0/0".to_string(), + curve: CurveType::SECP256k1, + network: "TESTNET".to_string(), + seg_wit: "VERSION_1".to_string(), + }, ]; RwLock::new(coin_infos) diff --git a/token-core/tcx/tests/derive_test.rs b/token-core/tcx/tests/derive_test.rs index 48252eff..eebe4234 100644 --- a/token-core/tcx/tests/derive_test.rs +++ b/token-core/tcx/tests/derive_test.rs @@ -194,6 +194,33 @@ pub fn test_derive_accounts() { curve: "ed25519".to_string(), hrp: "".to_string(), }, + Derivation { + chain_type: "DOGECOIN".to_string(), + path: "m/44'/3'/0'/0/0".to_string(), + network: "MAINNET".to_string(), + seg_wit: "NONE".to_string(), + chain_id: "".to_string(), + curve: "secp256k1".to_string(), + bech32_prefix: "".to_string(), + }, + Derivation { + chain_type: "DOGECOIN".to_string(), + path: "m/44'/1'/0'/0/0".to_string(), + network: "MAINNET".to_string(), + seg_wit: "NONE".to_string(), + chain_id: "".to_string(), + curve: "secp256k1".to_string(), + bech32_prefix: "".to_string(), + }, + Derivation { + chain_type: "DOGECOIN".to_string(), + path: "m/44'/1'/0'/0/0".to_string(), + network: "MAINNET".to_string(), + seg_wit: "VERSION_1".to_string(), + chain_id: "".to_string(), + curve: "secp256k1".to_string(), + bech32_prefix: "".to_string(), + }, ]; let param = DeriveAccountsParam { @@ -206,7 +233,7 @@ pub fn test_derive_accounts() { let derived_accounts_bytes = call_api("derive_accounts", param).unwrap(); let derived_accounts: DeriveAccountsResult = DeriveAccountsResult::decode(derived_accounts_bytes.as_slice()).unwrap(); - assert_eq!(17, derived_accounts.accounts.len()); + assert_eq!(20, derived_accounts.accounts.len()); assert_eq!( "LQ3JqCohgLQ3x1CJXYERnJTy1ySaqr1E32", derived_accounts.accounts[0].address @@ -290,6 +317,19 @@ pub fn test_derive_accounts() { derived_accounts.accounts[16].address ); + assert_eq!( + "DGUrMnbLGQzZV3H1AYackWuykSKqqUMGEf", + derived_accounts.accounts[17].address + ); + assert_eq!( + "DP48ckynvMTDkxC7SEvxtDztyFmZxviDCf", + derived_accounts.accounts[18].address + ); + assert_eq!( + "1p37xv5xzd92c4wh8zt96f77a8jlf3n2qh4cps03xgurmpnllxy5us2dwgfl", + derived_accounts.accounts[19].address + ); + remove_created_wallet(&import_result.id); }) }