diff --git a/token-core/tcx-atom/src/address.rs b/token-core/tcx-atom/src/address.rs index 3eee55f3..ee455584 100644 --- a/token-core/tcx-atom/src/address.rs +++ b/token-core/tcx-atom/src/address.rs @@ -8,32 +8,36 @@ use tcx_primitive::TypedPublicKey; // size of address pub const LENGTH: usize = 20; + #[derive(PartialEq, Eq, Clone)] pub struct AtomAddress(String); impl Address for AtomAddress { - fn from_public_key(public_key: &TypedPublicKey, _coin: &CoinInfo) -> Result { - let prefix = "cosmos"; - + fn from_public_key(public_key: &TypedPublicKey, coin: &CoinInfo) -> Result { let pub_key_bytes = public_key.to_bytes(); let mut bytes = [0u8; LENGTH]; let pub_key_hash = ripemd160(&sha256(&pub_key_bytes)); bytes.copy_from_slice(&pub_key_hash[..LENGTH]); + let hrp = if (coin.hrp.is_empty()) { + "cosmos" + } else { + coin.hrp.as_str() + }; Ok(AtomAddress(bech32::encode( - prefix, + hrp, bytes.to_base32(), Variant::Bech32, )?)) } - fn is_valid(address: &str, _coin: &CoinInfo) -> bool { + fn is_valid(address: &str, coin: &CoinInfo) -> bool { let ret = bech32::decode(address); if let Ok(val) = ret { let (hrp, data, _) = val; let data = Vec::from_base32(&data).unwrap(); - if hrp.as_str() != "cosmos" { + if coin.hrp != hrp.as_str() { return false; } @@ -78,6 +82,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "".to_string(), + hrp: "cosmos".to_string(), } } @@ -154,10 +159,57 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "cosmos".to_string(), }; let address = AtomAddress::from_public_key(&pub_key, &coin_info) .unwrap() .to_string(); assert_eq!(address, "cosmos1hsk6jryyqjfhp5dhc55tc9jtckygx0eph6dd02"); } + + #[test] + fn test_sub_net() { + let pub_key_hex = "0317f65e6736ad182b47e386af40af0f26fb524bdd94e172a6145a6603d65a44b2"; + let pub_key = + TypedPublicKey::from_slice(CurveType::SECP256k1, &Vec::from_hex(pub_key_hex).unwrap()) + .unwrap(); + + let testcase = [ + ( + "dydx", + "m/44'/118'/0'/0/0", + "dydx1m566v5rcklnac8vc0dftfu4lnvznhlu7yg830z", + ), + ( + "osmo", + "m/44'/118'/0'/0/0", + "osmo1m566v5rcklnac8vc0dftfu4lnvznhlu79269e8", + ), + ( + "neutron", + "m/44'/118'/0'/0/0", + "neutron1m566v5rcklnac8vc0dftfu4lnvznhlu7fwqh4j", + ), + ( + "stride", + "m/44'/118'/0'/0/0", + "stride1m566v5rcklnac8vc0dftfu4lnvznhlu7w6ffme", + ), + ]; + for (hrp, path, expected_addr) in testcase { + let coin_info = CoinInfo { + coin: "COSMOS".to_string(), + derivation_path: path.to_string(), + curve: CurveType::SECP256k1, + network: "MAINNET".to_string(), + seg_wit: "NONE".to_string(), + hrp: hrp.to_string(), + }; + + let address = AtomAddress::from_public_key(&pub_key, &coin_info) + .unwrap() + .to_string(); + assert_eq!(address, expected_addr) + } + } } diff --git a/token-core/tcx-atom/src/signer.rs b/token-core/tcx-atom/src/signer.rs index 0fa6c860..9bd05ef5 100644 --- a/token-core/tcx-atom/src/signer.rs +++ b/token-core/tcx-atom/src/signer.rs @@ -50,6 +50,7 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let mut guard = KeystoreGuard::unlock_by_password(&mut keystore, TEST_PASSWORD).unwrap(); diff --git a/token-core/tcx-btc-kin/src/address.rs b/token-core/tcx-btc-kin/src/address.rs index f34ad67e..6a734e49 100644 --- a/token-core/tcx-btc-kin/src/address.rs +++ b/token-core/tcx-btc-kin/src/address.rs @@ -261,6 +261,7 @@ impl Display for BtcKinAddress { #[cfg(test)] mod tests { + use bitcoin::SchnorrSighashType::Default; use std::str::FromStr; use tcx_common::{FromHex, ToHex}; @@ -354,6 +355,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let ltc_xprv_str = BtcKinAddress::extended_private_key(&anprv, &coin_info).unwrap(); assert_eq!("xprv9yrdwPSRnvomqFK4u1y5uW2SaXS2Vnr3pAYTjJjbyRZR8p9BwoadRsCxtgUFdAKeRPbwvGRcCSYMV69nNK4N2kadevJ6L5iQVy1SwGKDTHQ", ltc_xprv_str); @@ -373,6 +375,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let ltc_xprv_str = BtcKinAddress::extended_public_key(&anpub, &coin_info).unwrap(); assert_eq!("xpub6JeaAjhtvtjCDnEo4Bjr7uEbGccaHnJtLY4aBnMaAYGjkBRB3fP9XvjcCbNjMiU1n5tt7dYKVgHPGzh3t3W6eLBxavxABTaoQ2jhbiQrfe4", ltc_xprv_str); @@ -464,6 +467,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let address = BtcKinAddress::from_public_key(&pub_key, &coin_info) .unwrap() @@ -521,6 +525,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_0".to_string(), + hrp: "".to_string(), }; let address = BtcKinAddress::from_public_key(&pub_key, &coin_info) .unwrap() diff --git a/token-core/tcx-btc-kin/src/bch_address.rs b/token-core/tcx-btc-kin/src/bch_address.rs index 8dca69e6..71017aee 100644 --- a/token-core/tcx-btc-kin/src/bch_address.rs +++ b/token-core/tcx-btc-kin/src/bch_address.rs @@ -196,6 +196,7 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let ret = BchAddress::from_public_key(&pk, &wrong_coin_info); assert_eq!(format!("{}", ret.err().unwrap()), "missing_network"); @@ -287,6 +288,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let address = BchAddress::from_public_key(&pub_key, &coin_info) .unwrap() diff --git a/token-core/tcx-btc-kin/src/message.rs b/token-core/tcx-btc-kin/src/message.rs index 70364652..408e26d5 100644 --- a/token-core/tcx-btc-kin/src/message.rs +++ b/token-core/tcx-btc-kin/src/message.rs @@ -11,6 +11,7 @@ use tcx_keystore::{Address, Keystore, MessageSigner, SignatureParameters}; const UTXO: &str = "0000000000000000000000000000000000000000000000000000000000000000"; const TAG: &str = "BIP0322-signed-message"; + fn get_spend_tx_id(data: &[u8], script_pub_key: Script) -> Result { let tag_hash = sha256(&TAG.as_bytes().to_vec()); let mut to_sign = Vec::new(); @@ -107,6 +108,7 @@ impl MessageSigner for Keystore { curve: CurveType::SECP256k1, network: params.network.to_string(), seg_wit: params.seg_wit.to_string(), + hrp: "".to_string(), }; let address = BtcKinAddress::from_public_key(&public_key, &coin_info)?; @@ -156,6 +158,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_0".to_string(), + hrp: "".to_string(), }; let account = ks.derive_coin::(&coin_info).unwrap(); @@ -179,6 +182,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "P2WPKH".to_string(), + hrp: "".to_string(), }; let account = ks.derive_coin::(&coin_info).unwrap(); @@ -214,6 +218,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let account = ks.derive_coin::(&coin_info).unwrap(); @@ -250,6 +255,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_0".to_string(), + hrp: "".to_string(), }; let account = ks.derive_coin::(&coin_info).unwrap(); @@ -285,6 +291,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_1".to_string(), + hrp: "".to_string(), }; let account = ks.derive_coin::(&coin_info).unwrap(); diff --git a/token-core/tcx-btc-kin/src/psbt.rs b/token-core/tcx-btc-kin/src/psbt.rs index edd30452..3f9638f6 100644 --- a/token-core/tcx-btc-kin/src/psbt.rs +++ b/token-core/tcx-btc-kin/src/psbt.rs @@ -445,6 +445,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "VERSION_1".to_string(), + hrp: "".to_string(), }; let account = hd.derive_coin::(&coin_info).unwrap(); @@ -484,6 +485,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "VERSION_1".to_string(), + hrp: "".to_string(), }; let account = hd.derive_coin::(&coin_info).unwrap(); diff --git a/token-core/tcx-btc-kin/src/signer.rs b/token-core/tcx-btc-kin/src/signer.rs index dcad738e..887c38f3 100644 --- a/token-core/tcx-btc-kin/src/signer.rs +++ b/token-core/tcx-btc-kin/src/signer.rs @@ -253,6 +253,7 @@ impl> KinTransaction curve: params.curve, network: params.network.clone(), seg_wit: params.seg_wit.clone(), + hrp: "".to_string(), }; let change_script = if let Some(change_address_index) = self.change_address_index && keystore.derivable() { @@ -1386,7 +1387,7 @@ mod tests { op_return: None, }; - let mut ks = wif_keystore("mszYqVnqKoQx4jcTdJXxwKAissE3Jbrrc1"); + let mut ks = wif_keystore(TEST_WIF); let params = SignatureParameters { curve: CurveType::SECP256k1, diff --git a/token-core/tcx-ckb/src/address.rs b/token-core/tcx-ckb/src/address.rs index df3e017d..cf60c173 100644 --- a/token-core/tcx-ckb/src/address.rs +++ b/token-core/tcx-ckb/src/address.rs @@ -104,6 +104,7 @@ mod tests { curve: CurveType::SECP256k1, network: network.to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let pub_key = TypedPublicKey::from_slice( @@ -132,6 +133,7 @@ mod tests { curve: CurveType::SECP256k1, network: network.to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; assert!(CkbAddress::is_valid(address, &coin_info)); } @@ -147,6 +149,7 @@ mod tests { curve: CurveType::SECP256k1, network: network.to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; assert!(!CkbAddress::is_valid(address, &coin_info)); } @@ -167,6 +170,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; assert!(!CkbAddress::is_valid(invalid_address, &coin_info)); } @@ -192,6 +196,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let address = CkbAddress::from_public_key(&pub_key, &coin_info) .unwrap() diff --git a/token-core/tcx-ckb/src/signer.rs b/token-core/tcx-ckb/src/signer.rs index 56fe7844..c1b9c1f5 100644 --- a/token-core/tcx-ckb/src/signer.rs +++ b/token-core/tcx-ckb/src/signer.rs @@ -304,6 +304,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let mut ks = @@ -439,6 +440,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let _account = ks.derive_coin::(&coin_info).unwrap().clone(); @@ -521,6 +523,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let mut ks = @@ -586,6 +589,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let mut ks = @@ -655,6 +659,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let mut ks = @@ -692,6 +697,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let mut ks = @@ -738,6 +744,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let mut ks = @@ -884,6 +891,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let mut ks = diff --git a/token-core/tcx-constants/src/btc_fork_network.rs b/token-core/tcx-constants/src/btc_fork_network.rs index 9cbddd1c..6a3d7bc7 100644 --- a/token-core/tcx-constants/src/btc_fork_network.rs +++ b/token-core/tcx-constants/src/btc_fork_network.rs @@ -254,6 +254,7 @@ mod test { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }) .unwrap(); diff --git a/token-core/tcx-constants/src/coin_info.rs b/token-core/tcx-constants/src/coin_info.rs index 7a161a3a..130142f0 100644 --- a/token-core/tcx-constants/src/coin_info.rs +++ b/token-core/tcx-constants/src/coin_info.rs @@ -12,6 +12,7 @@ pub fn get_xpub_prefix(network: &str) -> Vec { Vec::from_hex("043587cf").unwrap() } } + /// Blockchain basic config #[derive(Clone, Debug)] pub struct CoinInfo { @@ -20,6 +21,7 @@ pub struct CoinInfo { pub curve: CurveType, pub network: String, pub seg_wit: String, + pub hrp: String, } impl Default for CoinInfo { @@ -30,6 +32,7 @@ impl Default for CoinInfo { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), } } } @@ -43,6 +46,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -50,6 +54,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -57,6 +62,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "P2WPKH".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -64,6 +70,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "P2WPKH".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -71,6 +78,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_0".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -78,6 +86,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "VERSION_0".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -85,6 +94,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_1".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -92,6 +102,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "VERSION_1".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOINCASH".to_string(), @@ -99,6 +110,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOINCASH".to_string(), @@ -106,6 +118,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "LITECOIN".to_string(), @@ -113,6 +126,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "LITECOIN".to_string(), @@ -120,6 +134,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "LITECOIN".to_string(), @@ -127,6 +142,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "P2WPKH".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "LITECOIN".to_string(), @@ -134,6 +150,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "P2WPKH".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "TRON".to_string(), @@ -141,6 +158,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "NERVOS".to_string(), @@ -148,6 +166,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "NERVOS".to_string(), @@ -155,6 +174,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "POLKADOT".to_string(), @@ -162,6 +182,7 @@ lazy_static! { curve: CurveType::SR25519, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "KUSAMA".to_string(), @@ -169,6 +190,7 @@ lazy_static! { curve: CurveType::SR25519, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "TEZOS".to_string(), @@ -176,6 +198,7 @@ lazy_static! { curve: CurveType::ED25519, network: "MAINNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "FILECOIN".to_string(), @@ -183,6 +206,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "FILECOIN".to_string(), @@ -190,6 +214,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "FILECOIN".to_string(), @@ -197,6 +222,7 @@ lazy_static! { curve: CurveType::BLS, network: "MAINNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "FILECOIN".to_string(), @@ -204,6 +230,7 @@ lazy_static! { curve: CurveType::BLS, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "ETHEREUM".to_string(), @@ -211,6 +238,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "ETHEREUM".to_string(), @@ -218,6 +246,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "ETHEREUM2".to_string(), @@ -225,6 +254,7 @@ lazy_static! { curve: CurveType::BLS, network: "MAINNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "ETHEREUM2".to_string(), @@ -232,6 +262,7 @@ lazy_static! { curve: CurveType::BLS, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "COSMOS".to_string(), @@ -239,6 +270,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "EOS".to_string(), @@ -246,6 +278,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "COSMOS".to_string(), @@ -253,6 +286,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "EOS".to_string(), @@ -260,6 +294,7 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, ]; @@ -294,7 +329,6 @@ pub fn coin_info_from_param( #[cfg(test)] mod test { - #[test] fn test_coin_info_default() { let coin_info = super::CoinInfo::default(); diff --git a/token-core/tcx-eth/src/address.rs b/token-core/tcx-eth/src/address.rs index 852ce672..253f8c29 100644 --- a/token-core/tcx-eth/src/address.rs +++ b/token-core/tcx-eth/src/address.rs @@ -132,6 +132,7 @@ mod test { curve: CurveType::SECP256k1, network: "testnet".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let address = EthAddress::from_public_key(&typed_public_key, &coin_info).unwrap(); assert_eq!( @@ -212,6 +213,7 @@ mod test { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let address = EthAddress::from_public_key(&pub_key, &coin_info) .unwrap() diff --git a/token-core/tcx-filecoin/src/address.rs b/token-core/tcx-filecoin/src/address.rs index 72b8d422..89dc300f 100644 --- a/token-core/tcx-filecoin/src/address.rs +++ b/token-core/tcx-filecoin/src/address.rs @@ -166,6 +166,7 @@ mod tests { curve: CurveType::BLS, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; for (input, expected) in test_cases { @@ -261,6 +262,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; for (input, expected) in test_cases { diff --git a/token-core/tcx-keystore/src/keystore/hd.rs b/token-core/tcx-keystore/src/keystore/hd.rs index c2e72031..84dfe77a 100644 --- a/token-core/tcx-keystore/src/keystore/hd.rs +++ b/token-core/tcx-keystore/src/keystore/hd.rs @@ -346,6 +346,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -353,6 +354,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "P2WPKH".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -360,6 +362,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_0".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -367,6 +370,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_1".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -374,6 +378,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -381,6 +386,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "P2WPKH".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -388,6 +394,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "VERSION_0".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -395,6 +402,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "VERSION_1".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "TEZOS".to_string(), @@ -402,6 +410,7 @@ mod tests { curve: CurveType::ED25519, network: "MAINNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, ]; @@ -434,6 +443,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let _ = keystore .unlock(&Key::Password(TEST_PASSWORD.to_owned())) @@ -458,7 +468,7 @@ mod tests { seg_wit: "NONE".to_string(), curve: CurveType::SECP256k1, coin: "BITCOIN".to_string(), - public_key + public_key, }; assert_eq!(acc, expected); @@ -542,6 +552,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let _ = keystore .unlock(&Key::Password(TEST_PASSWORD.to_owned())) @@ -566,7 +577,7 @@ mod tests { seg_wit: "NONE".to_string(), curve: CurveType::SECP256k1, coin: "BITCOIN".to_string(), - public_key + public_key, }; assert_eq!(acc, expected); @@ -608,6 +619,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let _ = keystore .unlock(&Key::Password(TEST_PASSWORD.to_owned())) @@ -631,7 +643,7 @@ mod tests { seg_wit: "NONE".to_string(), curve: CurveType::SECP256k1, coin: "BITCOIN".to_string(), - public_key + public_key, }; assert_eq!(acc, expected); @@ -651,6 +663,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; m.iter(|| { @@ -674,6 +687,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -681,6 +695,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -688,6 +703,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -695,6 +711,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_0".to_string(), + hrp: "".to_string(), }, CoinInfo { coin: "BITCOIN".to_string(), @@ -702,6 +719,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_1".to_string(), + hrp: "".to_string(), }, ]; @@ -733,6 +751,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let acc = keystore.derive_coin::(&coin_info).unwrap(); assert_eq!(acc.ext_pub_key, "tpubDD7tXK8KeQ3YY83yWq755fHY2JW8Ha8Q765tknUM5rSvjPcGWfUppDFMpQ1ScziKfW3ZNtZvAD7M3u7bSs7HofjTD3KP3YxPK7X6hwV8Rk2"); @@ -743,6 +762,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let acc = keystore.derive_coin::(&coin_info).unwrap(); assert_eq!( @@ -765,6 +785,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let acc = keystore.derive_coin::(&coin_info).unwrap(); assert_eq!(acc.ext_pub_key, "xpub6CatWdiZiodmUeTDp8LT5or8nmbKNcuyvz7WyksVFkKB4RHwCD3XyuvPEbvqAQY3rAPshWcMLoP2fMFMKHPJ4ZeZXYVUhLv1VMrjPC7PW6V"); diff --git a/token-core/tcx-keystore/src/keystore/mod.rs b/token-core/tcx-keystore/src/keystore/mod.rs index e580753a..46e5d327 100644 --- a/token-core/tcx-keystore/src/keystore/mod.rs +++ b/token-core/tcx-keystore/src/keystore/mod.rs @@ -902,6 +902,7 @@ pub(crate) mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let k1_pub_key = Secp256k1PublicKey::from_slice( @@ -974,6 +975,7 @@ pub(crate) mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let k1_pub_key = Secp256k1PublicKey::from_slice( @@ -1018,6 +1020,7 @@ pub(crate) mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let typed_pk = TypedDeterministicPublicKey::from_hex(CurveType::SECP256k1, "03a25f12b68000000044efc688fe25a1a677765526ed6737b4bfcfb0122589caab7ca4b223ffa9bb37029d23439ecb195eb06a0d44a608960d18702fd97e19c53451f0548f568207af77").unwrap(); diff --git a/token-core/tcx-keystore/src/keystore/private.rs b/token-core/tcx-keystore/src/keystore/private.rs index 78e7740d..a898f9ce 100644 --- a/token-core/tcx-keystore/src/keystore/private.rs +++ b/token-core/tcx-keystore/src/keystore/private.rs @@ -270,6 +270,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }]; let excepts = ["0280c98b8ea7cab630defb0c09a4295c2193cdee016c1d5b9b0cb18572b9c370fe"]; diff --git a/token-core/tcx-migration/src/migration.rs b/token-core/tcx-migration/src/migration.rs index a7f1ffb6..be2eacab 100644 --- a/token-core/tcx-migration/src/migration.rs +++ b/token-core/tcx-migration/src/migration.rs @@ -401,6 +401,7 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; keystore.unlock(&key).unwrap(); @@ -458,6 +459,7 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; keystore.unlock_by_password("imtoken1").unwrap(); @@ -484,6 +486,7 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; keystore.unlock(&key).unwrap(); @@ -509,6 +512,7 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; keystore.unlock(&key).unwrap(); @@ -532,6 +536,7 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; keystore.unlock(&key).unwrap(); @@ -555,6 +560,7 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; keystore.unlock(&key).unwrap(); @@ -582,6 +588,7 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; keystore.unlock(&key).unwrap(); diff --git a/token-core/tcx-proto/src/params.proto b/token-core/tcx-proto/src/params.proto index 560ce6d6..30a35b4d 100644 --- a/token-core/tcx-proto/src/params.proto +++ b/token-core/tcx-proto/src/params.proto @@ -75,7 +75,7 @@ message DeriveAccountsParam { string segWit = 4; string chainId = 5; string curve = 6; - string bech32Prefix = 7; + string hrp = 7; } repeated Derivation derivations = 4; } diff --git a/token-core/tcx-substrate/src/address.rs b/token-core/tcx-substrate/src/address.rs index 717ee436..be79f135 100644 --- a/token-core/tcx-substrate/src/address.rs +++ b/token-core/tcx-substrate/src/address.rs @@ -76,6 +76,7 @@ mod test_super { curve: CurveType::SR25519, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, ), ( @@ -86,6 +87,7 @@ mod test_super { curve: CurveType::SR25519, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }, ), ]; @@ -104,6 +106,7 @@ mod test_super { curve: CurveType::SR25519, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let addr = SubstrateAddress::from_public_key(&typed_key, &kusama_coin_info).unwrap(); assert_eq!( @@ -124,6 +127,7 @@ mod test_super { curve: CurveType::SR25519, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let addresses = vec![ "FwMF8FdFKxPtt9enzZ2Zf7dJCxiu4HqK6GhRAsKCvbNkSqx", @@ -151,6 +155,7 @@ mod test_super { curve: CurveType::SR25519, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let addresses = vec![ "3BMEXohjFLZJGBLkCbF9zreee1eJjoM3ZB", diff --git a/token-core/tcx-tezos/src/address.rs b/token-core/tcx-tezos/src/address.rs index c0d5521d..e58779ff 100644 --- a/token-core/tcx-tezos/src/address.rs +++ b/token-core/tcx-tezos/src/address.rs @@ -95,6 +95,7 @@ mod test { curve: CurveType::ED25519, network: "MAINNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let pub_key = TypedPublicKey::from_slice( @@ -133,6 +134,7 @@ mod test { curve: CurveType::ED25519, network: "MAINNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let address = "tz1dLEU3WfzCrDq2bvoEz4cfLP5wg4S7xNo9"; //valid address let valid_result = TezosAddress::is_valid(address, &coin_info); @@ -155,6 +157,7 @@ mod test { curve: CurveType::ED25519, network: "MAINNET".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; let pub_key = TypedPublicKey::from_slice( diff --git a/token-core/tcx-tron/src/address.rs b/token-core/tcx-tron/src/address.rs index 3bda9feb..166b3e8d 100644 --- a/token-core/tcx-tron/src/address.rs +++ b/token-core/tcx-tron/src/address.rs @@ -66,6 +66,7 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), + hrp: "".to_string(), }; assert_eq!( @@ -133,6 +134,7 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), + hrp: "".to_string(), }; let address = TronAddress::from_public_key(&pub_key, &coin_info) .unwrap() diff --git a/token-core/tcx/src/api.rs b/token-core/tcx/src/api.rs index a5113553..5dd309e9 100644 --- a/token-core/tcx/src/api.rs +++ b/token-core/tcx/src/api.rs @@ -381,7 +381,7 @@ pub mod derive_accounts_param { #[prost(string, tag = "6")] pub curve: ::prost::alloc::string::String, #[prost(string, tag = "7")] - pub bech32_prefix: ::prost::alloc::string::String, + pub hrp: ::prost::alloc::string::String, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Oneof)] diff --git a/token-core/tcx/src/handler.rs b/token-core/tcx/src/handler.rs index 3987eb38..1c37813d 100644 --- a/token-core/tcx/src/handler.rs +++ b/token-core/tcx/src/handler.rs @@ -104,6 +104,7 @@ fn derive_account(keystore: &mut Keystore, derivation: &Derivation) -> Result Result> { if !derivation.path.is_empty() { coin_info.derivation_path = derivation.path; } + coin_info.hrp = derivation.hrp; let enc_xpub = if account.ext_pub_key.is_empty() { Ok("".to_string()) diff --git a/token-core/tcx/src/reset_password.rs b/token-core/tcx/src/reset_password.rs index c516853f..640d165f 100644 --- a/token-core/tcx/src/reset_password.rs +++ b/token-core/tcx/src/reset_password.rs @@ -1,3 +1,4 @@ +use std::ascii::AsciiExt; use std::fs; use std::io::Read; use std::path::Path; @@ -67,11 +68,16 @@ fn parse_coin_info_from_legacy_ks(value: Value) -> Result<(CoinInfo, String)> { }; let coin_info = CoinInfo { - coin: chain_str, + coin: chain_str.to_string(), derivation_path, curve: CurveType::SECP256k1, network, seg_wit, + hrp: if chain_str.eq_ignore_ascii_case("cosmos") { + "cosmos".to_string() + } else { + "".to_string() + }, }; return Ok((coin_info, address)); } else { @@ -141,6 +147,7 @@ fn parse_coin_info_from_legacy_tcx_ks(legacy_tcx_ks: Value) -> Result<(CoinInfo, curve, network, seg_wit, + hrp: "".to_string(), }; return Ok((coin_info, address)); } else { diff --git a/token-core/tcx/tests/derive_test.rs b/token-core/tcx/tests/derive_test.rs index e29cd1e7..48252eff 100644 --- a/token-core/tcx/tests/derive_test.rs +++ b/token-core/tcx/tests/derive_test.rs @@ -48,7 +48,7 @@ pub fn test_derive_accounts() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "LITECOIN".to_string(), @@ -57,7 +57,7 @@ pub fn test_derive_accounts() { seg_wit: "P2WPKH".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "LITECOIN".to_string(), @@ -66,7 +66,7 @@ pub fn test_derive_accounts() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "TRON".to_string(), @@ -75,7 +75,7 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "NERVOS".to_string(), @@ -84,7 +84,7 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "KUSAMA".to_string(), @@ -93,7 +93,7 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "POLKADOT".to_string(), @@ -102,7 +102,7 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "FILECOIN".to_string(), @@ -111,7 +111,7 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "FILECOIN".to_string(), @@ -120,7 +120,7 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "bls12-381".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "COSMOS".to_string(), @@ -129,7 +129,7 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "cosmos".to_string(), }, Derivation { chain_type: "EOS".to_string(), @@ -138,7 +138,7 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "ETHEREUM".to_string(), @@ -147,7 +147,7 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -156,7 +156,7 @@ pub fn test_derive_accounts() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -165,7 +165,7 @@ pub fn test_derive_accounts() { seg_wit: "P2WPKH".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -174,7 +174,7 @@ pub fn test_derive_accounts() { seg_wit: "VERSION_0".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -183,7 +183,7 @@ pub fn test_derive_accounts() { seg_wit: "VERSION_1".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "TEZOS".to_string(), @@ -192,7 +192,7 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "ed25519".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, ]; @@ -308,7 +308,7 @@ pub fn test_hd_store_derive_invalid_param() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "LITECOIN".to_string(), @@ -317,7 +317,7 @@ pub fn test_hd_store_derive_invalid_param() { seg_wit: "P2WPKH".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "LITECOIN".to_string(), @@ -326,7 +326,7 @@ pub fn test_hd_store_derive_invalid_param() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, ]; for derivation in invalid_derivations { @@ -444,7 +444,7 @@ pub fn test_derive_btc_legacy_sub_accounts() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }; let (_wallet, accounts) = import_and_derive(derivation); @@ -485,7 +485,7 @@ pub fn test_derive_btc_p2wpkh_sub_accounts() { seg_wit: "P2WPKH".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }; let (_wallet, accounts) = import_and_derive(derivation); @@ -526,7 +526,7 @@ pub fn test_derive_eth_sub_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }; let (_, accounts) = import_and_derive(derivation); @@ -633,7 +633,7 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "POLKADOT".to_string(), @@ -642,7 +642,7 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "POLKADOT".to_string(), @@ -651,7 +651,7 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "KUSAMA".to_string(), @@ -660,7 +660,7 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "KUSAMA".to_string(), @@ -669,7 +669,7 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "KUSAMA".to_string(), @@ -678,7 +678,7 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "KUSAMA".to_string(), @@ -687,7 +687,7 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "POLKADOT".to_string(), @@ -696,7 +696,7 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, ]; let param = DeriveAccountsParam { @@ -751,7 +751,7 @@ fn test_derive_other_curve_on_pk_keystore() { network: "".to_string(), curve: "secp256k1".to_string(), seg_wit: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "FILECOIN".to_string(), @@ -760,7 +760,7 @@ fn test_derive_other_curve_on_pk_keystore() { network: "".to_string(), curve: "secp256k1".to_string(), seg_wit: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, ], key: Some(api::derive_accounts_param::Key::Password( @@ -787,7 +787,7 @@ fn test_derive_other_curve_on_pk_keystore() { network: "".to_string(), curve: "ed25519".to_string(), seg_wit: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }], key: Some(api::derive_accounts_param::Key::Password( TEST_PASSWORD.to_string(), @@ -808,7 +808,7 @@ fn test_derive_other_curve_on_pk_keystore() { network: "".to_string(), curve: "sr25519".to_string(), seg_wit: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }], key: Some(api::derive_accounts_param::Key::Password( TEST_PASSWORD.to_string(), @@ -846,7 +846,7 @@ fn test_derive_mainnet_account_on_test_wif() { network: "TESTNET".to_string(), curve: "secp256k1".to_string(), seg_wit: "VERSION_1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }], key: Some(api::derive_accounts_param::Key::Password( TEST_PASSWORD.to_string(), diff --git a/token-core/tcx/tests/export_test.rs b/token-core/tcx/tests/export_test.rs index 02947c93..af788ca0 100644 --- a/token-core/tcx/tests/export_test.rs +++ b/token-core/tcx/tests/export_test.rs @@ -85,7 +85,7 @@ pub fn test_tezos_import_private_key_export() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -166,7 +166,7 @@ pub fn test_tezos_hd_private_key_export() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "ed25519".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -278,7 +278,7 @@ pub fn test_export_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOINCASH".to_string(), @@ -287,7 +287,7 @@ pub fn test_export_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "TRON".to_string(), @@ -296,7 +296,7 @@ pub fn test_export_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "ETHEREUM".to_string(), @@ -305,7 +305,7 @@ pub fn test_export_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "FILECOIN".to_string(), @@ -314,7 +314,7 @@ pub fn test_export_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -323,7 +323,7 @@ pub fn test_export_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -332,7 +332,7 @@ pub fn test_export_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -341,7 +341,7 @@ pub fn test_export_private_key() { seg_wit: "P2WPKH".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -350,7 +350,7 @@ pub fn test_export_private_key() { seg_wit: "VERSION_0".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -359,7 +359,7 @@ pub fn test_export_private_key() { seg_wit: "VERSION_1".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "EOS".to_string(), @@ -368,7 +368,7 @@ pub fn test_export_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, ]; let pks = vec![ @@ -489,7 +489,7 @@ pub fn test_chain_cannot_export_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }]; let export_info = vec![ diff --git a/token-core/tcx/tests/import_test.rs b/token-core/tcx/tests/import_test.rs index a7f11dbc..46dec444 100644 --- a/token-core/tcx/tests/import_test.rs +++ b/token-core/tcx/tests/import_test.rs @@ -83,7 +83,7 @@ pub fn test_import_mnemonic() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -152,7 +152,7 @@ pub fn test_import_mnemonic_ltc() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -201,7 +201,7 @@ pub fn test_import_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "LITECOIN".to_string(), @@ -210,7 +210,7 @@ pub fn test_import_private_key() { seg_wit: "P2WPKH".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "LITECOIN".to_string(), @@ -219,7 +219,7 @@ pub fn test_import_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "TRON".to_string(), @@ -228,7 +228,7 @@ pub fn test_import_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "NERVOS".to_string(), @@ -237,7 +237,7 @@ pub fn test_import_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "ETHEREUM".to_string(), @@ -246,7 +246,7 @@ pub fn test_import_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "COSMOS".to_string(), @@ -255,7 +255,7 @@ pub fn test_import_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "EOS".to_string(), @@ -264,7 +264,7 @@ pub fn test_import_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -273,7 +273,7 @@ pub fn test_import_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -282,7 +282,7 @@ pub fn test_import_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -291,7 +291,7 @@ pub fn test_import_private_key() { seg_wit: "P2WPKH".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -300,7 +300,7 @@ pub fn test_import_private_key() { seg_wit: "VERSION_0".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -309,7 +309,7 @@ pub fn test_import_private_key() { seg_wit: "VERSION_1".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }, ]; let param = DeriveAccountsParam { @@ -400,7 +400,7 @@ pub fn test_import_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -446,7 +446,7 @@ pub fn test_filecoin_private_key_secp256k1_import() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -513,7 +513,7 @@ pub fn test_filecoin_private_key_bls_import() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "bls12-381".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -581,7 +581,7 @@ pub fn test_fil_bls_tezos_reimport() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: case.2.to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: hd_import_result.id.to_string(), @@ -627,7 +627,7 @@ pub fn test_fil_bls_tezos_reimport() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: case.2.to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: pk_import_result.id.to_string(), @@ -676,7 +676,7 @@ pub fn test_import_sr25519_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -755,7 +755,7 @@ pub fn test_import_to_pk_which_from_hd() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }; let derive_param = DeriveAccountsParam { @@ -855,7 +855,7 @@ pub fn test_import_substrate_keystore() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }; let param = DeriveAccountsParam { @@ -947,7 +947,7 @@ pub fn test_import_substrate_keystore_v3() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }; let param = DeriveAccountsParam { @@ -1031,7 +1031,7 @@ pub fn test_import_multi_curve() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }; let param = DeriveAccountsParam { @@ -1057,7 +1057,7 @@ pub fn test_import_multi_curve() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }; let param = DeriveAccountsParam { diff --git a/token-core/tcx/tests/sign_test.rs b/token-core/tcx/tests/sign_test.rs index beb80fc0..8776be55 100644 --- a/token-core/tcx/tests/sign_test.rs +++ b/token-core/tcx/tests/sign_test.rs @@ -321,7 +321,7 @@ pub fn test_sign_tron_tx_by_pk() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -702,7 +702,7 @@ pub fn test_lock_after_sign() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }; let (wallet, _acc_rsp) = import_and_derive(derivation); @@ -912,7 +912,7 @@ pub fn test_sign_ethereum_legacy_tx() { seg_wit: "".to_string(), chain_id: "1".to_string(), curve: "secp256k1".to_string(), - bech32_prefix: "".to_string(), + hrp: "".to_string(), }; let (wallet, acc_rsp) = import_and_derive(derivation);