diff --git a/token-core/tcx-atom/src/address.rs b/token-core/tcx-atom/src/address.rs index a0fe3454..32056425 100644 --- a/token-core/tcx-atom/src/address.rs +++ b/token-core/tcx-atom/src/address.rs @@ -1,10 +1,8 @@ -use anyhow::{anyhow, format_err}; +use anyhow::anyhow; use core::str::FromStr; -use std::collections::HashMap; -use std::sync::RwLock; +use crate::hrps::CHAIN_ID_HRP_MAP; use bech32::{FromBase32, ToBase32, Variant}; -use lazy_static::lazy_static; use tcx_common::{ripemd160, sha256}; use tcx_constants::CoinInfo; use tcx_keystore::{Address, Result}; @@ -13,39 +11,15 @@ use tcx_primitive::TypedPublicKey; // size of address pub const LENGTH: usize = 20; -// pub const HRP_MAP: -lazy_static! { - static ref CHAIN_ID_HRP_MAP: RwLock> = { - let mut chain_id_hrp_map = HashMap::new(); - chain_id_hrp_map.insert("cosmoshub-4".to_string(), "cosmos".to_string()); - chain_id_hrp_map.insert("osmosis-1".to_string(), "osmo".to_string()); - chain_id_hrp_map.insert("celestia".to_string(), "celestia".to_string()); - chain_id_hrp_map.insert("neutron-1".to_string(), "neutron".to_string()); - chain_id_hrp_map.insert("noble-1".to_string(), "noble".to_string()); - chain_id_hrp_map.insert("stride-1".to_string(), "stride".to_string()); - chain_id_hrp_map.insert("stargaze-1".to_string(), "stars".to_string()); - chain_id_hrp_map.insert("axelar-dojo-1".to_string(), "axelar".to_string()); - chain_id_hrp_map.insert("juno-1".to_string(), "juno".to_string()); - chain_id_hrp_map.insert("injective-1".to_string(), "inj".to_string()); - chain_id_hrp_map.insert("dydx-mainnet-1".to_string(), "dydx".to_string()); - chain_id_hrp_map.insert("dymension_1100-1".to_string(), "dym".to_string()); - chain_id_hrp_map.insert("secret-4".to_string(), "secret".to_string()); - chain_id_hrp_map.insert("archway-1".to_string(), "archway".to_string()); - chain_id_hrp_map.insert("akashnet-2".to_string(), "akash".to_string()); - chain_id_hrp_map.insert("core-1".to_string(), "persistence".to_string()); - RwLock::new(chain_id_hrp_map) - }; -} - -fn verify_hrp(coin_info: &CoinInfo) -> Result<()> { +fn find_hrp(chain_id: &str) -> Result { let map = CHAIN_ID_HRP_MAP.read().unwrap(); - let embed_hrp = map.get(&coin_info.chain_id); - if (embed_hrp.is_some()) { - if (&coin_info.hrp != embed_hrp.unwrap()) { - return Err(anyhow!("chain_id_and_hrp_not_match")); - } - } - return Ok(()); + let embed_hrp = map.get(chain_id); + + return if embed_hrp.is_some() { + Ok(embed_hrp.unwrap().to_string()) + } else { + Err(anyhow!("unknown_chain_id")) + }; } #[derive(PartialEq, Eq, Clone)] @@ -57,15 +31,10 @@ impl Address for AtomAddress { let mut bytes = [0u8; LENGTH]; let pub_key_hash = ripemd160(&sha256(&pub_key_bytes)); bytes.copy_from_slice(&pub_key_hash[..LENGTH]); - verify_hrp(&coin)?; - let hrp = if coin.hrp.is_empty() { - "cosmos" - } else { - coin.hrp.as_str() - }; + let hrp = find_hrp(&coin.chain_id)?; Ok(AtomAddress(bech32::encode( - hrp, + &hrp, bytes.to_base32(), Variant::Bech32, )?)) @@ -77,10 +46,6 @@ impl Address for AtomAddress { let (hrp, data, _) = val; let data = Vec::from_base32(&data).unwrap(); - if coin.hrp != hrp.as_str() { - return false; - } - if data.len() != 20 { return false; } @@ -118,13 +83,12 @@ mod tests { fn get_test_coin() -> CoinInfo { CoinInfo { - chain_id: "".to_string(), + chain_id: "cosmoshub-4".to_string(), coin: "COSMOS".to_string(), derivation_path: "m/44'/118'/0'/0/0".to_string(), curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "".to_string(), - hrp: "cosmos".to_string(), } } @@ -202,7 +166,6 @@ 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() @@ -220,34 +183,37 @@ mod tests { let testcase = [ ( "dydx", + "dydx-mainnet-1", "m/44'/118'/0'/0/0", "dydx1m566v5rcklnac8vc0dftfu4lnvznhlu7yg830z", ), ( "osmo", + "osmosis-1", "m/44'/118'/0'/0/0", "osmo1m566v5rcklnac8vc0dftfu4lnvznhlu79269e8", ), ( "neutron", + "neutron-1", "m/44'/118'/0'/0/0", "neutron1m566v5rcklnac8vc0dftfu4lnvznhlu7fwqh4j", ), ( "stride", + "stride-1", "m/44'/118'/0'/0/0", "stride1m566v5rcklnac8vc0dftfu4lnvznhlu7w6ffme", ), ]; - for (hrp, path, expected_addr) in testcase { + for (hrp, chain_id, path, expected_addr) in testcase { let coin_info = CoinInfo { - chain_id: "".to_string(), + chain_id: chain_id.to_string(), 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) @@ -256,6 +222,7 @@ mod tests { assert_eq!(address, expected_addr) } } + #[test] fn test_chain_id_hrp_verify() { let prv_str = "80e81ea269e66a0a05b11236df7919fb7fbeedba87452d667489d7403a02f005"; @@ -270,15 +237,26 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "cosmos-wrong".to_string(), }; let address = AtomAddress::from_public_key(&pub_key, &coin_info); assert_eq!( - format!("{}", address.err().unwrap()), - "chain_id_and_hrp_not_match" + format!("{}", address.unwrap().to_string()), + "cosmos1hsk6jryyqjfhp5dhc55tc9jtckygx0eph6dd02" ); + let coin_info = CoinInfo { + chain_id: "unknown-chainid".to_string(), + coin: "COSMOS".to_string(), + derivation_path: "m/44'/118'/0'/0/0".to_string(), + curve: CurveType::SECP256k1, + network: "MAINNET".to_string(), + seg_wit: "NONE".to_string(), + }; + + let address = AtomAddress::from_public_key(&pub_key, &coin_info); + assert_eq!(format!("{}", address.err().unwrap()), "unknown_chain_id"); + let coin_info = CoinInfo { chain_id: "cosmoshub-4".to_string(), coin: "COSMOS".to_string(), @@ -286,7 +264,6 @@ 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); diff --git a/token-core/tcx-atom/src/hrps.rs b/token-core/tcx-atom/src/hrps.rs new file mode 100644 index 00000000..68abcad9 --- /dev/null +++ b/token-core/tcx-atom/src/hrps.rs @@ -0,0 +1,190 @@ +use lazy_static::lazy_static; +use std::collections::HashMap; +use std::sync::RwLock; +lazy_static! { + pub static ref CHAIN_ID_HRP_MAP: RwLock> = { + let mut chain_id_hrp_map = HashMap::new(); + chain_id_hrp_map.insert("eightball-1".to_string(), "8ball".to_string()); + chain_id_hrp_map.insert("acre_9052-1".to_string(), "acre".to_string()); + chain_id_hrp_map.insert("agoric-3".to_string(), "agoric".to_string()); + chain_id_hrp_map.insert("aioz_168-1".to_string(), "aioz".to_string()); + chain_id_hrp_map.insert("akashnet-2".to_string(), "akash".to_string()); + chain_id_hrp_map.insert("akiro-1".to_string(), "akiro".to_string()); + chain_id_hrp_map.insert("althea_258432-1".to_string(), "althea".to_string()); + chain_id_hrp_map.insert("andromeda-1".to_string(), "andr".to_string()); + chain_id_hrp_map.insert("archway-1".to_string(), "archway".to_string()); + chain_id_hrp_map.insert("arkh".to_string(), "arkh".to_string()); + chain_id_hrp_map.insert("mantle-1".to_string(), "mantle".to_string()); + chain_id_hrp_map.insert("aura_6322-2".to_string(), "aura".to_string()); + chain_id_hrp_map.insert("xstaxy-1".to_string(), "aura".to_string()); + chain_id_hrp_map.insert("axelar-dojo-1".to_string(), "axelar".to_string()); + chain_id_hrp_map.insert("laozi-mainnet".to_string(), "band".to_string()); + chain_id_hrp_map.insert("beezee-1".to_string(), "bze".to_string()); + chain_id_hrp_map.insert("bitcanna-1".to_string(), "bcna".to_string()); + chain_id_hrp_map.insert("bitsong-2b".to_string(), "bitsong".to_string()); + chain_id_hrp_map.insert("blockx_19191-1".to_string(), "blockx".to_string()); + chain_id_hrp_map.insert("bluechip-1".to_string(), "bcp".to_string()); + chain_id_hrp_map.insert("bluzelle-9".to_string(), "bluzelle".to_string()); + chain_id_hrp_map.insert("bostrom".to_string(), "bostrom".to_string()); + chain_id_hrp_map.insert("canto_7700-1".to_string(), "canto".to_string()); + chain_id_hrp_map.insert("carbon-1".to_string(), "swth".to_string()); + chain_id_hrp_map.insert("celestia".to_string(), "celestia".to_string()); + chain_id_hrp_map.insert("cerberus-chain-1".to_string(), "cerberus".to_string()); + chain_id_hrp_map.insert("perun-1".to_string(), "c4e".to_string()); + chain_id_hrp_map.insert("cheqd-mainnet-1".to_string(), "cheqd".to_string()); + chain_id_hrp_map.insert("chihuahua-1".to_string(), "chihuahua".to_string()); + chain_id_hrp_map.insert("chimba".to_string(), "chimba".to_string()); + chain_id_hrp_map.insert("morocco-1".to_string(), "chronic".to_string()); + chain_id_hrp_map.insert("cifer-2".to_string(), "cife".to_string()); + chain_id_hrp_map.insert("cifer-1".to_string(), "cife".to_string()); + chain_id_hrp_map.insert("cnho_stables-1".to_string(), "cnho".to_string()); + chain_id_hrp_map.insert("comdex-1".to_string(), "comdex".to_string()); + chain_id_hrp_map.insert("commercio-3".to_string(), "did:com:".to_string()); + chain_id_hrp_map.insert("centauri-1".to_string(), "pica".to_string()); + chain_id_hrp_map.insert("cvn_2032-1".to_string(), "cvn".to_string()); + chain_id_hrp_map.insert("coreum-mainnet-1".to_string(), "core".to_string()); + chain_id_hrp_map.insert("cosmoshub-4".to_string(), "cosmos".to_string()); + chain_id_hrp_map.insert("coss-1".to_string(), "coss".to_string()); + chain_id_hrp_map.insert("crescent-1".to_string(), "cre".to_string()); + chain_id_hrp_map.insert("cronosmainnet_25-1".to_string(), "crc".to_string()); + chain_id_hrp_map.insert("crypto-org-chain-mainnet-1".to_string(), "cro".to_string()); + chain_id_hrp_map.insert("cudos-1".to_string(), "cudos".to_string()); + chain_id_hrp_map.insert("mainnet-3".to_string(), "decentr".to_string()); + chain_id_hrp_map.insert("desmos-mainnet".to_string(), "desmos".to_string()); + chain_id_hrp_map.insert("dhealth".to_string(), "dh".to_string()); + chain_id_hrp_map.insert("dig-1".to_string(), "dig".to_string()); + chain_id_hrp_map.insert("vota-ash".to_string(), "dora".to_string()); + chain_id_hrp_map.insert("dydx-mainnet-1".to_string(), "dydx".to_string()); + chain_id_hrp_map.insert("dymension_1100-1".to_string(), "dym".to_string()); + chain_id_hrp_map.insert("dyson-mainnet-01".to_string(), "dys".to_string()); + chain_id_hrp_map.insert("echelon_3000-3".to_string(), "echelon".to_string()); + chain_id_hrp_map.insert("emoney-3".to_string(), "emoney".to_string()); + chain_id_hrp_map.insert("empowerchain-1".to_string(), "empower".to_string()); + chain_id_hrp_map.insert("ethos_7003-1".to_string(), "ethos".to_string()); + chain_id_hrp_map.insert("evmos_9001-2".to_string(), "evmos".to_string()); + chain_id_hrp_map.insert("fetchhub-4".to_string(), "fetch".to_string()); + chain_id_hrp_map.insert("finschia-2".to_string(), "link".to_string()); + chain_id_hrp_map.insert("colosseum-1".to_string(), "firma".to_string()); + chain_id_hrp_map.insert("furya-1".to_string(), "furya".to_string()); + chain_id_hrp_map.insert("fxcore".to_string(), "fx".to_string()); + chain_id_hrp_map.insert("galaxy-1".to_string(), "galaxy".to_string()); + chain_id_hrp_map.insert("wormchain".to_string(), "wormhole".to_string()); + chain_id_hrp_map.insert("genesis_29-2".to_string(), "genesis".to_string()); + chain_id_hrp_map.insert("gitopia".to_string(), "gitopia".to_string()); + chain_id_hrp_map.insert("govgen-1".to_string(), "govgen".to_string()); + chain_id_hrp_map.insert("gravity-bridge-3".to_string(), "gravity".to_string()); + chain_id_hrp_map.insert("haqq_11235-1".to_string(), "haqq".to_string()); + chain_id_hrp_map.insert("helichain".to_string(), "heli".to_string()); + chain_id_hrp_map.insert("highbury_710-1".to_string(), "fury".to_string()); + chain_id_hrp_map.insert("humans_1089-1".to_string(), "human".to_string()); + chain_id_hrp_map.insert("Antora".to_string(), "idep".to_string()); + chain_id_hrp_map.insert("ixo-5".to_string(), "ixo".to_string()); + chain_id_hrp_map.insert("imversed_5555555-1".to_string(), "imv".to_string()); + chain_id_hrp_map.insert("injective-1".to_string(), "inj".to_string()); + chain_id_hrp_map.insert("irishub-1".to_string(), "iaa".to_string()); + chain_id_hrp_map.insert("jackal-1".to_string(), "jkl".to_string()); + chain_id_hrp_map.insert("joltify_1729-1".to_string(), "jolt".to_string()); + chain_id_hrp_map.insert("juno-1".to_string(), "juno".to_string()); + chain_id_hrp_map.insert("kava_2222-10".to_string(), "kava".to_string()); + chain_id_hrp_map.insert("kichain-2".to_string(), "ki".to_string()); + chain_id_hrp_map.insert("darchub".to_string(), "darc".to_string()); + chain_id_hrp_map.insert("kaiyo-1".to_string(), "kujira".to_string()); + chain_id_hrp_map.insert("kyve-1".to_string(), "kyve".to_string()); + chain_id_hrp_map.insert("lambda_92000-1".to_string(), "lamb".to_string()); + chain_id_hrp_map.insert("lava-mainnet-1".to_string(), "lava@".to_string()); + chain_id_hrp_map.insert("likecoin-mainnet-2".to_string(), "like".to_string()); + chain_id_hrp_map.insert("logos_7002-1".to_string(), "logos".to_string()); + chain_id_hrp_map.insert("loop-1".to_string(), "loop".to_string()); + chain_id_hrp_map.insert("loyal-main-02".to_string(), "loyal".to_string()); + chain_id_hrp_map.insert("LumenX".to_string(), "lumen".to_string()); + chain_id_hrp_map.insert("lum-network-1".to_string(), "lum".to_string()); + chain_id_hrp_map.insert("mande_18071918-1".to_string(), "mande".to_string()); + chain_id_hrp_map.insert("mars-1".to_string(), "mars".to_string()); + chain_id_hrp_map.insert("mayachain-mainnet-v1".to_string(), "maya".to_string()); + chain_id_hrp_map.insert("medasdigital-1".to_string(), "medas".to_string()); + chain_id_hrp_map.insert("meme-1".to_string(), "meme".to_string()); + chain_id_hrp_map.insert("microtick-1".to_string(), "micro".to_string()); + chain_id_hrp_map.insert("migaloo-1".to_string(), "migaloo".to_string()); + chain_id_hrp_map.insert("mainnet".to_string(), "mises".to_string()); + chain_id_hrp_map.insert("mtgbp-1".to_string(), "mtgbp".to_string()); + chain_id_hrp_map.insert("mun-1".to_string(), "mun".to_string()); + chain_id_hrp_map.insert("mythos_7001-1".to_string(), "mythos".to_string()); + chain_id_hrp_map.insert("neura_266-1".to_string(), "neura".to_string()); + chain_id_hrp_map.insert("Neutaro-1".to_string(), "neutaro".to_string()); + chain_id_hrp_map.insert("neutron-1".to_string(), "neutron".to_string()); + chain_id_hrp_map.insert("cataclysm-1".to_string(), "nibi".to_string()); + chain_id_hrp_map.insert("nim_1122-1".to_string(), "nim".to_string()); + chain_id_hrp_map.insert("noble-1".to_string(), "noble".to_string()); + chain_id_hrp_map.insert("nois-1".to_string(), "nois".to_string()); + chain_id_hrp_map.insert("pirin-1".to_string(), "nolus".to_string()); + chain_id_hrp_map.insert("nomic-stakenet-3".to_string(), "nomic".to_string()); + chain_id_hrp_map.insert("nyx".to_string(), "n".to_string()); + chain_id_hrp_map.insert("octa".to_string(), "octa".to_string()); + chain_id_hrp_map.insert("odin-mainnet-freya".to_string(), "odin".to_string()); + chain_id_hrp_map.insert("exchain-66".to_string(), "ex".to_string()); + chain_id_hrp_map.insert("omniflixhub-1".to_string(), "omniflix".to_string()); + chain_id_hrp_map.insert("onex-mainnet-1".to_string(), "onomy".to_string()); + chain_id_hrp_map.insert("onomy-mainnet-1".to_string(), "onomy".to_string()); + chain_id_hrp_map.insert("Oraichain".to_string(), "orai".to_string()); + chain_id_hrp_map.insert("osmosis-1".to_string(), "osmo".to_string()); + chain_id_hrp_map.insert("tumbler".to_string(), "paloma".to_string()); + chain_id_hrp_map.insert("panacea-3".to_string(), "panacea".to_string()); + chain_id_hrp_map.insert("passage-2".to_string(), "pasg".to_string()); + chain_id_hrp_map.insert("passage-1".to_string(), "pasg".to_string()); + chain_id_hrp_map.insert("core-1".to_string(), "persistence".to_string()); + chain_id_hrp_map.insert("planq_7070-2".to_string(), "plq".to_string()); + chain_id_hrp_map.insert("point_10687-1".to_string(), "point".to_string()); + chain_id_hrp_map.insert("pio-mainnet-1".to_string(), "pb".to_string()); + chain_id_hrp_map.insert("pryzm-1".to_string(), "pryzm".to_string()); + chain_id_hrp_map.insert("PUNDIX".to_string(), "px".to_string()); + chain_id_hrp_map.insert("pylons-mainnet-1".to_string(), "pylo".to_string()); + chain_id_hrp_map.insert("qfs-1".to_string(), "qfs".to_string()); + chain_id_hrp_map.insert("quasar-1".to_string(), "quasar".to_string()); + chain_id_hrp_map.insert("quicksilver-2".to_string(), "quick".to_string()); + chain_id_hrp_map.insert("qwoyn-1".to_string(), "qwoyn".to_string()); + chain_id_hrp_map.insert("realionetwork_3301-1".to_string(), "realio".to_string()); + chain_id_hrp_map.insert("reb_1111-1".to_string(), "rebus".to_string()); + chain_id_hrp_map.insert("regen-1".to_string(), "regen".to_string()); + chain_id_hrp_map.insert("titan-1".to_string(), "rizon".to_string()); + chain_id_hrp_map.insert("ssc-1".to_string(), "saga".to_string()); + chain_id_hrp_map.insert("scorum-1".to_string(), "scorum".to_string()); + chain_id_hrp_map.insert("secret-4".to_string(), "secret".to_string()); + chain_id_hrp_map.insert("seda-1".to_string(), "seda".to_string()); + chain_id_hrp_map.insert("pacific-1".to_string(), "sei".to_string()); + chain_id_hrp_map.insert("self-1".to_string(), "self".to_string()); + chain_id_hrp_map.insert("sentinelhub-2".to_string(), "sent".to_string()); + chain_id_hrp_map.insert("sgenet-1".to_string(), "sge".to_string()); + chain_id_hrp_map.insert( + "ShareRing-VoyagerNet".to_string(), + "shareledger".to_string(), + ); + chain_id_hrp_map.insert("shentu-2.2".to_string(), "shentu".to_string()); + chain_id_hrp_map.insert("shido_9008-1".to_string(), "shido".to_string()); + chain_id_hrp_map.insert("sifchain-1".to_string(), "sif".to_string()); + chain_id_hrp_map.insert("sixnet".to_string(), "6x".to_string()); + chain_id_hrp_map.insert("sommelier-3".to_string(), "somm".to_string()); + chain_id_hrp_map.insert("source-1".to_string(), "source".to_string()); + chain_id_hrp_map.insert("stafihub-1".to_string(), "stafi".to_string()); + chain_id_hrp_map.insert("stargaze-1".to_string(), "stars".to_string()); + chain_id_hrp_map.insert("iov-mainnet-ibc".to_string(), "star".to_string()); + chain_id_hrp_map.insert("stratos-1".to_string(), "st".to_string()); + chain_id_hrp_map.insert("stride-1".to_string(), "stride".to_string()); + chain_id_hrp_map.insert("sunrise-1".to_string(), "sunrise".to_string()); + chain_id_hrp_map.insert("taketitan-12".to_string(), "taketitan".to_string()); + chain_id_hrp_map.insert("tenet_1559-1".to_string(), "tenet".to_string()); + chain_id_hrp_map.insert("teritori-1".to_string(), "tori".to_string()); + chain_id_hrp_map.insert("columbus-5".to_string(), "terra".to_string()); + chain_id_hrp_map.insert("phoenix-1".to_string(), "terra".to_string()); + chain_id_hrp_map.insert("tgrade-mainnet-1".to_string(), "tgrade".to_string()); + chain_id_hrp_map.insert("thorchain-mainnet-v1".to_string(), "thor".to_string()); + chain_id_hrp_map.insert("titan_18888-1".to_string(), "titan".to_string()); + chain_id_hrp_map.insert("umee-1".to_string(), "umee".to_string()); + chain_id_hrp_map.insert("FUND-MainNet-2".to_string(), "und".to_string()); + chain_id_hrp_map.insert("ununifi-beta-v1".to_string(), "ununifi".to_string()); + chain_id_hrp_map.insert("uptick_117-1".to_string(), "uptick".to_string()); + chain_id_hrp_map.insert("vidulum-1".to_string(), "vdl".to_string()); + chain_id_hrp_map.insert("dimension_37-1".to_string(), "xpla".to_string()); + chain_id_hrp_map.insert("zetachain_7000-1".to_string(), "zeta".to_string()); + RwLock::new(chain_id_hrp_map) + }; +} diff --git a/token-core/tcx-atom/src/lib.rs b/token-core/tcx-atom/src/lib.rs index 13e34b68..ad718ad6 100644 --- a/token-core/tcx-atom/src/lib.rs +++ b/token-core/tcx-atom/src/lib.rs @@ -1,4 +1,5 @@ pub mod address; +mod hrps; pub mod signer; pub mod transaction; diff --git a/token-core/tcx-atom/src/signer.rs b/token-core/tcx-atom/src/signer.rs index a0b59ba5..0ceaca7f 100644 --- a/token-core/tcx-atom/src/signer.rs +++ b/token-core/tcx-atom/src/signer.rs @@ -51,7 +51,6 @@ 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 10030800..19874b93 100644 --- a/token-core/tcx-btc-kin/src/address.rs +++ b/token-core/tcx-btc-kin/src/address.rs @@ -361,7 +361,6 @@ 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); @@ -382,7 +381,6 @@ 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); @@ -475,7 +473,6 @@ 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() @@ -513,7 +510,6 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }) .unwrap(); assert_eq!(account.address, "DQ4tVEqdPWHc1aVBm4Sfwft8XyNRPMEchR"); @@ -545,7 +541,6 @@ mod tests { curve: CurveType::SECP256k1, network: network.to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }; let account = hd.derive_coin::(&coin_info).unwrap(); assert_eq!(account.ext_pub_key, xpub); @@ -567,7 +562,6 @@ 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 0eea854b..38f76ff1 100644 --- a/token-core/tcx-btc-kin/src/bch_address.rs +++ b/token-core/tcx-btc-kin/src/bch_address.rs @@ -197,7 +197,6 @@ 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"); @@ -290,7 +289,6 @@ 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 faf7fdc2..26573fc2 100644 --- a/token-core/tcx-btc-kin/src/message.rs +++ b/token-core/tcx-btc-kin/src/message.rs @@ -109,7 +109,6 @@ 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)?; @@ -160,7 +159,6 @@ 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(); @@ -185,7 +183,6 @@ 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(); @@ -222,7 +219,6 @@ 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(); @@ -260,7 +256,6 @@ 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(); @@ -297,7 +292,6 @@ 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 28a07c2b..ff1e9c7c 100644 --- a/token-core/tcx-btc-kin/src/psbt.rs +++ b/token-core/tcx-btc-kin/src/psbt.rs @@ -446,7 +446,6 @@ 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(); @@ -487,7 +486,6 @@ 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 46432cb7..63043ac4 100644 --- a/token-core/tcx-btc-kin/src/signer.rs +++ b/token-core/tcx-btc-kin/src/signer.rs @@ -254,7 +254,6 @@ 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() { diff --git a/token-core/tcx-ckb/src/address.rs b/token-core/tcx-ckb/src/address.rs index e5307662..3219466e 100644 --- a/token-core/tcx-ckb/src/address.rs +++ b/token-core/tcx-ckb/src/address.rs @@ -105,7 +105,6 @@ mod tests { curve: CurveType::SECP256k1, network: network.to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; let pub_key = TypedPublicKey::from_slice( @@ -135,7 +134,6 @@ mod tests { curve: CurveType::SECP256k1, network: network.to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; assert!(CkbAddress::is_valid(address, &coin_info)); } @@ -152,7 +150,6 @@ mod tests { curve: CurveType::SECP256k1, network: network.to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; assert!(!CkbAddress::is_valid(address, &coin_info)); } @@ -174,7 +171,6 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; assert!(!CkbAddress::is_valid(invalid_address, &coin_info)); } @@ -201,7 +197,6 @@ 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 b24c8510..3f6775f3 100644 --- a/token-core/tcx-ckb/src/signer.rs +++ b/token-core/tcx-ckb/src/signer.rs @@ -305,7 +305,6 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; let mut ks = @@ -442,7 +441,6 @@ 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(); @@ -526,7 +524,6 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; let mut ks = @@ -593,7 +590,6 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; let mut ks = @@ -664,7 +660,6 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; let mut ks = @@ -703,7 +698,6 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; let mut ks = @@ -751,7 +745,6 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; let mut ks = @@ -899,7 +892,6 @@ 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 600124cd..e8b2cab9 100644 --- a/token-core/tcx-constants/src/btc_fork_network.rs +++ b/token-core/tcx-constants/src/btc_fork_network.rs @@ -255,7 +255,6 @@ 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 db600675..ad29c989 100644 --- a/token-core/tcx-constants/src/coin_info.rs +++ b/token-core/tcx-constants/src/coin_info.rs @@ -21,7 +21,6 @@ pub struct CoinInfo { pub curve: CurveType, pub network: String, pub seg_wit: String, - pub hrp: String, pub chain_id: String, } @@ -33,7 +32,7 @@ impl Default for CoinInfo { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), + chain_id: "".to_string(), } } @@ -49,7 +48,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -58,7 +56,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -67,7 +64,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "P2WPKH".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -76,7 +72,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "P2WPKH".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -85,7 +80,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_0".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -94,7 +88,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "VERSION_0".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -103,7 +96,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_1".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -112,7 +104,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "VERSION_1".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -121,7 +112,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -130,7 +120,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -139,7 +128,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -148,7 +136,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -157,7 +144,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "P2WPKH".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -166,7 +152,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "P2WPKH".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -175,7 +160,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -184,7 +168,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -193,7 +176,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -202,7 +184,6 @@ lazy_static! { curve: CurveType::SR25519, network: "".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -211,7 +192,6 @@ lazy_static! { curve: CurveType::SR25519, network: "".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -220,7 +200,6 @@ lazy_static! { curve: CurveType::ED25519, network: "MAINNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -229,7 +208,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -238,7 +216,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -247,7 +224,6 @@ lazy_static! { curve: CurveType::BLS, network: "MAINNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -256,7 +232,6 @@ lazy_static! { curve: CurveType::BLS, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -265,7 +240,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -274,7 +248,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -283,7 +256,6 @@ lazy_static! { curve: CurveType::BLS, network: "MAINNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -292,7 +264,6 @@ lazy_static! { curve: CurveType::BLS, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -301,7 +272,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -310,7 +280,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -319,7 +288,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -328,7 +296,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -337,7 +304,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -346,7 +312,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -355,7 +320,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "P2WPKH".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -364,7 +328,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "P2WPKH".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -373,7 +336,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_0".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -382,7 +344,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "VERSION_0".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -391,7 +352,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_1".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -400,7 +360,6 @@ lazy_static! { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "VERSION_1".to_string(), - hrp: "".to_string(), }, ]; diff --git a/token-core/tcx-eth/src/address.rs b/token-core/tcx-eth/src/address.rs index 96f7c169..5f01b2ce 100644 --- a/token-core/tcx-eth/src/address.rs +++ b/token-core/tcx-eth/src/address.rs @@ -133,7 +133,6 @@ 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!( @@ -215,7 +214,6 @@ 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 9ff1a5ec..7a57b526 100644 --- a/token-core/tcx-filecoin/src/address.rs +++ b/token-core/tcx-filecoin/src/address.rs @@ -167,7 +167,6 @@ mod tests { curve: CurveType::BLS, network: "TESTNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; for (input, expected) in test_cases { @@ -264,7 +263,6 @@ 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 f17d1578..27fbab46 100644 --- a/token-core/tcx-keystore/src/keystore/hd.rs +++ b/token-core/tcx-keystore/src/keystore/hd.rs @@ -347,7 +347,6 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -356,7 +355,6 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "P2WPKH".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -365,7 +363,6 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_0".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -374,7 +371,6 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_1".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -383,7 +379,6 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -392,7 +387,6 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "P2WPKH".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -401,7 +395,6 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "VERSION_0".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -410,7 +403,6 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "VERSION_1".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -419,7 +411,6 @@ mod tests { curve: CurveType::ED25519, network: "MAINNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, ]; @@ -453,7 +444,6 @@ 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())) @@ -563,7 +553,6 @@ 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 +620,6 @@ 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())) @@ -676,7 +664,6 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }; m.iter(|| { @@ -701,7 +688,6 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -710,7 +696,6 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -719,7 +704,6 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -728,7 +712,6 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_0".to_string(), - hrp: "".to_string(), }, CoinInfo { chain_id: "".to_string(), @@ -737,7 +720,6 @@ mod tests { curve: CurveType::SECP256k1, network: "MAINNET".to_string(), seg_wit: "VERSION_1".to_string(), - hrp: "".to_string(), }, ]; @@ -770,7 +752,6 @@ 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"); @@ -782,7 +763,6 @@ 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!( @@ -806,7 +786,6 @@ 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 11326590..ab04b1b6 100644 --- a/token-core/tcx-keystore/src/keystore/mod.rs +++ b/token-core/tcx-keystore/src/keystore/mod.rs @@ -903,7 +903,6 @@ 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( @@ -977,7 +976,6 @@ 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( @@ -1023,7 +1021,6 @@ 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 b67be6bc..6a3cc333 100644 --- a/token-core/tcx-keystore/src/keystore/private.rs +++ b/token-core/tcx-keystore/src/keystore/private.rs @@ -271,7 +271,6 @@ 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 ed7992a1..256ecf5b 100644 --- a/token-core/tcx-migration/src/migration.rs +++ b/token-core/tcx-migration/src/migration.rs @@ -402,7 +402,6 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; keystore.unlock(&key).unwrap(); @@ -461,7 +460,6 @@ mod tests { curve: CurveType::SECP256k1, network: "TESTNET".to_string(), seg_wit: "NONE".to_string(), - hrp: "".to_string(), }; keystore.unlock_by_password("imtoken1").unwrap(); @@ -489,7 +487,6 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; keystore.unlock(&key).unwrap(); @@ -516,7 +513,6 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; keystore.unlock(&key).unwrap(); @@ -541,7 +537,6 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; keystore.unlock(&key).unwrap(); @@ -566,7 +561,6 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; keystore.unlock(&key).unwrap(); @@ -595,7 +589,6 @@ 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 b7ae81e9..ea672cf1 100644 --- a/token-core/tcx-proto/src/params.proto +++ b/token-core/tcx-proto/src/params.proto @@ -75,7 +75,6 @@ message DeriveAccountsParam { string segWit = 4; string chainId = 5; string curve = 6; - string hrp = 7; } repeated Derivation derivations = 4; } @@ -111,17 +110,6 @@ message ExportJsonResult { string json = 2; } -// // only support two types -// enum KeyType { -// MNEMONIC = 0; -// PRIVATE_KEY = 1; -// } - -/// Private Key Store - -// FUNCTION: import_private_key(ImportPrivateKeyParam): KeystoreResult -// -// create a new private key keystore by a private key message ImportPrivateKeyParam { string privateKey = 1; string password = 2; @@ -131,15 +119,6 @@ message ImportPrivateKeyParam { string overwriteId = 6; } -// FUNCTION: keystore_common_exists(KeystoreCommonExistsParam): ExistsKeystoreResult -// -// Check is there a keystore was generate by the special privateKey or mnemonic -// message KeystoreCommonExistsParam { -// KeyType type = 1; -// string value = 2; -// string encoding = 3; -// } - message ExistsMnemonicParam { string mnemonic = 1; } @@ -164,12 +143,7 @@ message ImportJsonParam { bool overwrite = 3; } -/// Sign Transaction -// FUNCTION: sign_tx(SignParam) -// -// Sign transaction. This api is used for sign any chain_type, you should build the right TxInput instance and -// put it in the `input` field message SignParam { string id = 1; oneof key { @@ -191,8 +165,7 @@ message DeriveSubAccountsParam { string segWit = 4; repeated string relativePaths = 5; string extendedPublicKey = 6; - string hrp = 7; - string chain_id = 8; + string chain_id = 7; } message DeriveSubAccountsResult { diff --git a/token-core/tcx-substrate/src/address.rs b/token-core/tcx-substrate/src/address.rs index 472e1990..1decc03c 100644 --- a/token-core/tcx-substrate/src/address.rs +++ b/token-core/tcx-substrate/src/address.rs @@ -77,7 +77,6 @@ mod test_super { curve: CurveType::SR25519, network: "".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, ), ( @@ -89,7 +88,6 @@ mod test_super { curve: CurveType::SR25519, network: "".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, ), ]; @@ -109,7 +107,6 @@ 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!( @@ -131,7 +128,6 @@ mod test_super { curve: CurveType::SR25519, network: "".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; let addresses = vec![ "FwMF8FdFKxPtt9enzZ2Zf7dJCxiu4HqK6GhRAsKCvbNkSqx", @@ -160,7 +156,6 @@ 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 bc844c9b..06afda5f 100644 --- a/token-core/tcx-tezos/src/address.rs +++ b/token-core/tcx-tezos/src/address.rs @@ -96,7 +96,6 @@ mod test { curve: CurveType::ED25519, network: "MAINNET".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; let pub_key = TypedPublicKey::from_slice( @@ -136,7 +135,6 @@ 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); @@ -160,7 +158,6 @@ 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 a23f1550..2158a70d 100644 --- a/token-core/tcx-tron/src/address.rs +++ b/token-core/tcx-tron/src/address.rs @@ -67,7 +67,6 @@ mod tests { curve: CurveType::SECP256k1, network: "".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }; assert_eq!( @@ -136,7 +135,6 @@ 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 5fed7ccc..f7564f28 100644 --- a/token-core/tcx/src/api.rs +++ b/token-core/tcx/src/api.rs @@ -380,8 +380,6 @@ pub mod derive_accounts_param { pub chain_id: ::prost::alloc::string::String, #[prost(string, tag = "6")] pub curve: ::prost::alloc::string::String, - #[prost(string, tag = "7")] - pub hrp: ::prost::alloc::string::String, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Oneof)] @@ -443,9 +441,6 @@ pub struct ExportJsonResult { #[prost(string, tag = "2")] pub json: ::prost::alloc::string::String, } -/// FUNCTION: import_private_key(ImportPrivateKeyParam): KeystoreResult -/// -/// create a new private key keystore by a private key #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct ImportPrivateKeyParam { @@ -500,10 +495,6 @@ pub struct ImportJsonParam { #[prost(bool, tag = "3")] pub overwrite: bool, } -/// FUNCTION: sign_tx(SignParam) -/// -/// Sign transaction. This api is used for sign any chain_type, you should build the right TxInput instance and -/// put it in the `input` field #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct SignParam { @@ -551,8 +542,6 @@ pub struct DeriveSubAccountsParam { #[prost(string, tag = "6")] pub extended_public_key: ::prost::alloc::string::String, #[prost(string, tag = "7")] - pub hrp: ::prost::alloc::string::String, - #[prost(string, tag = "8")] pub chain_id: ::prost::alloc::string::String, } #[allow(clippy::derive_partial_eq_without_eq)] diff --git a/token-core/tcx/src/handler.rs b/token-core/tcx/src/handler.rs index ce936983..f28717af 100644 --- a/token-core/tcx/src/handler.rs +++ b/token-core/tcx/src/handler.rs @@ -104,7 +104,6 @@ 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()) @@ -1298,7 +1296,6 @@ pub fn derive_sub_accounts(data: &[u8]) -> Result> { ¶m.curve, )?; coin_info.derivation_path = relative_path.to_string(); - coin_info.hrp = param.hrp.to_string(); coin_info.chain_id = param.chain_id.to_string(); let acc: Account = derive_sub_account(&xpub, &coin_info)?; diff --git a/token-core/tcx/src/reset_password.rs b/token-core/tcx/src/reset_password.rs index 85078197..3190269d 100644 --- a/token-core/tcx/src/reset_password.rs +++ b/token-core/tcx/src/reset_password.rs @@ -68,17 +68,16 @@ fn parse_coin_info_from_legacy_ks(value: Value) -> Result<(CoinInfo, String)> { }; let coin_info = CoinInfo { - chain_id: "".to_string(), + chain_id: if chain_str.eq_ignore_ascii_case("cosmos") { + "cosmoshub-4".to_string() + } else { + "".to_string() + }, 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 { @@ -149,7 +148,6 @@ 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 61484b42..80beab6c 100644 --- a/token-core/tcx/tests/derive_test.rs +++ b/token-core/tcx/tests/derive_test.rs @@ -49,7 +49,6 @@ pub fn test_derive_accounts() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "LITECOIN".to_string(), @@ -58,7 +57,6 @@ pub fn test_derive_accounts() { seg_wit: "P2WPKH".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "LITECOIN".to_string(), @@ -67,7 +65,6 @@ pub fn test_derive_accounts() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "TRON".to_string(), @@ -76,7 +73,6 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "NERVOS".to_string(), @@ -85,7 +81,6 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "KUSAMA".to_string(), @@ -94,7 +89,6 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "POLKADOT".to_string(), @@ -103,7 +97,6 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "FILECOIN".to_string(), @@ -112,7 +105,6 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "FILECOIN".to_string(), @@ -121,16 +113,14 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "bls12-381".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "COSMOS".to_string(), path: "m/44'/118'/0'/0/0".to_string(), network: "MAINNET".to_string(), seg_wit: "".to_string(), - chain_id: "".to_string(), + chain_id: "cosmoshub-4".to_string(), curve: "secp256k1".to_string(), - hrp: "cosmos".to_string(), }, Derivation { chain_type: "EOS".to_string(), @@ -139,7 +129,6 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "ETHEREUM".to_string(), @@ -148,7 +137,6 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -157,7 +145,6 @@ pub fn test_derive_accounts() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -166,7 +153,6 @@ pub fn test_derive_accounts() { seg_wit: "P2WPKH".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -175,7 +161,6 @@ pub fn test_derive_accounts() { seg_wit: "VERSION_0".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -184,7 +169,6 @@ pub fn test_derive_accounts() { seg_wit: "VERSION_1".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "TEZOS".to_string(), @@ -193,7 +177,6 @@ pub fn test_derive_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "ed25519".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "DOGECOIN".to_string(), @@ -202,7 +185,6 @@ pub fn test_derive_accounts() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "DOGECOIN".to_string(), @@ -211,7 +193,6 @@ pub fn test_derive_accounts() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "DOGECOIN".to_string(), @@ -220,7 +201,6 @@ pub fn test_derive_accounts() { seg_wit: "VERSION_1".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, ]; @@ -349,7 +329,6 @@ pub fn test_hd_store_derive_invalid_param() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "LITECOIN".to_string(), @@ -358,7 +337,6 @@ pub fn test_hd_store_derive_invalid_param() { seg_wit: "P2WPKH".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "LITECOIN".to_string(), @@ -367,7 +345,6 @@ pub fn test_hd_store_derive_invalid_param() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }, ]; for derivation in invalid_derivations { @@ -485,7 +462,6 @@ pub fn test_derive_btc_legacy_sub_accounts() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }; let (_wallet, accounts) = import_and_derive(derivation); @@ -497,7 +473,6 @@ pub fn test_derive_btc_legacy_sub_accounts() { seg_wit: "NONE".to_string(), relative_paths: vec!["0/0".to_string(), "0/1".to_string(), "1/0".to_string()], extended_public_key: accounts.accounts[0].extended_public_key.to_string(), - hrp: "".to_string(), }; let result_bytes = derive_sub_accounts(&encode_message(params).unwrap()).unwrap(); @@ -528,7 +503,6 @@ pub fn test_derive_btc_p2wpkh_sub_accounts() { seg_wit: "P2WPKH".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }; let (_wallet, accounts) = import_and_derive(derivation); @@ -540,7 +514,6 @@ pub fn test_derive_btc_p2wpkh_sub_accounts() { seg_wit: "P2WPKH".to_string(), relative_paths: vec!["0/0".to_string(), "0/1".to_string(), "1/0".to_string()], extended_public_key: accounts.accounts[0].extended_public_key.to_string(), - hrp: "".to_string(), }; let result_bytes = derive_sub_accounts(&encode_message(params).unwrap()).unwrap(); @@ -571,7 +544,6 @@ pub fn test_derive_eth_sub_accounts() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }; let (_, accounts) = import_and_derive(derivation); @@ -583,7 +555,6 @@ pub fn test_derive_eth_sub_accounts() { seg_wit: "".to_string(), relative_paths: vec!["0/0".to_string(), "0/1".to_string()], extended_public_key: accounts.accounts[0].extended_public_key.to_string(), - hrp: "".to_string(), }; let result_bytes = derive_sub_accounts(&encode_message(params).unwrap()).unwrap(); @@ -608,21 +579,19 @@ pub fn test_derive_cosmos_sub_accounts() { path: "m/44'/118'/0'/0/0".to_string(), network: "MAINNET".to_string(), seg_wit: "".to_string(), - chain_id: "".to_string(), + chain_id: "cosmoshub-4".to_string(), curve: "secp256k1".to_string(), - hrp: "cosmos".to_string(), }; let (_, accounts) = import_and_derive(derivation); let params = DeriveSubAccountsParam { - chain_id: "".to_string(), + chain_id: "cosmoshub-4".to_string(), chain_type: "COSMOS".to_string(), curve: "secp256k1".to_string(), network: "MAINNET".to_string(), seg_wit: "".to_string(), relative_paths: vec!["0/0".to_string(), "0/1".to_string()], extended_public_key: accounts.accounts[0].extended_public_key.to_string(), - hrp: "cosmos".to_string(), }; let result_bytes = derive_sub_accounts(&encode_message(params).unwrap()).unwrap(); @@ -637,14 +606,13 @@ pub fn test_derive_cosmos_sub_accounts() { ); let params = DeriveSubAccountsParam { - chain_id: "".to_string(), + chain_id: "osmosis-1".to_string(), chain_type: "COSMOS".to_string(), curve: "secp256k1".to_string(), network: "MAINNET".to_string(), seg_wit: "".to_string(), relative_paths: vec!["0/0".to_string(), "0/1".to_string()], extended_public_key: accounts.accounts[0].extended_public_key.to_string(), - hrp: "osmo".to_string(), }; let result_bytes = derive_sub_accounts(&encode_message(params).unwrap()).unwrap(); @@ -669,9 +637,8 @@ pub fn test_derive_verify_hrp() { path: "m/44'/118'/0'/0/0".to_string(), network: "MAINNET".to_string(), seg_wit: "".to_string(), - chain_id: "osmosis-1".to_string(), + chain_id: "osmosis-2".to_string(), curve: "secp256k1".to_string(), - hrp: "cosmos".to_string(), }; let wallet = import_default_wallet(); @@ -683,10 +650,7 @@ pub fn test_derive_verify_hrp() { }; let result = derive_accounts(&encode_message(derivation_param).unwrap()); - assert_eq!( - format!("{}", result.err().unwrap()), - "chain_id_and_hrp_not_match" - ); + assert_eq!(format!("{}", result.err().unwrap()), "unknown_chain_id"); let derivation = Derivation { chain_type: "COSMOS".to_string(), @@ -695,7 +659,6 @@ pub fn test_derive_verify_hrp() { seg_wit: "".to_string(), chain_id: "cosmoshub-4".to_string(), curve: "secp256k1".to_string(), - hrp: "cosmos".to_string(), }; let derivation_param = DeriveAccountsParam { @@ -707,6 +670,11 @@ pub fn test_derive_verify_hrp() { let result = derive_accounts(&encode_message(derivation_param).unwrap()).unwrap(); let account = DeriveAccountsResult::decode(result.as_slice()).unwrap(); + assert_eq!( + account.accounts[0].address, + "cosmos1ajz9y0x3wekez7tz2td2j6l2dftn28v26dd992" + ); + let params = DeriveSubAccountsParam { chain_id: "osmosis-1".to_string(), chain_type: "COSMOS".to_string(), @@ -715,13 +683,13 @@ pub fn test_derive_verify_hrp() { seg_wit: "".to_string(), relative_paths: vec!["0/0".to_string(), "0/1".to_string()], extended_public_key: account.accounts[0].extended_public_key.to_string(), - hrp: "cosmos".to_string(), }; - let result = derive_sub_accounts(&encode_message(params).unwrap()); + let result = derive_sub_accounts(&encode_message(params).unwrap()).unwrap(); + let account = DeriveAccountsResult::decode(result.as_slice()).unwrap(); assert_eq!( - format!("{}", result.err().unwrap()), - "chain_id_and_hrp_not_match" + account.accounts[0].address, + "osmo1ajz9y0x3wekez7tz2td2j6l2dftn28v2jk74nc" ); }) } @@ -807,7 +775,6 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "POLKADOT".to_string(), @@ -816,7 +783,6 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "POLKADOT".to_string(), @@ -825,7 +791,6 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "KUSAMA".to_string(), @@ -834,7 +799,6 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "KUSAMA".to_string(), @@ -843,7 +807,6 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "KUSAMA".to_string(), @@ -852,7 +815,6 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "KUSAMA".to_string(), @@ -861,7 +823,6 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "POLKADOT".to_string(), @@ -870,7 +831,6 @@ fn polkadotjs_cross_test() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - hrp: "".to_string(), }, ]; let param = DeriveAccountsParam { @@ -925,7 +885,6 @@ fn test_derive_other_curve_on_pk_keystore() { network: "".to_string(), curve: "secp256k1".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "FILECOIN".to_string(), @@ -934,7 +893,6 @@ fn test_derive_other_curve_on_pk_keystore() { network: "".to_string(), curve: "secp256k1".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }, ], key: Some(api::derive_accounts_param::Key::Password( @@ -961,7 +919,6 @@ fn test_derive_other_curve_on_pk_keystore() { network: "".to_string(), curve: "ed25519".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }], key: Some(api::derive_accounts_param::Key::Password( TEST_PASSWORD.to_string(), @@ -982,7 +939,6 @@ fn test_derive_other_curve_on_pk_keystore() { network: "".to_string(), curve: "sr25519".to_string(), seg_wit: "".to_string(), - hrp: "".to_string(), }], key: Some(api::derive_accounts_param::Key::Password( TEST_PASSWORD.to_string(), @@ -1020,7 +976,6 @@ fn test_derive_mainnet_account_on_test_wif() { network: "TESTNET".to_string(), curve: "secp256k1".to_string(), seg_wit: "VERSION_1".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 0d293f48..da1f67e9 100644 --- a/token-core/tcx/tests/export_test.rs +++ b/token-core/tcx/tests/export_test.rs @@ -85,7 +85,6 @@ pub fn test_tezos_import_private_key_export() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -166,7 +165,6 @@ pub fn test_tezos_hd_private_key_export() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "ed25519".to_string(), - hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -278,7 +276,6 @@ pub fn test_export_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOINCASH".to_string(), @@ -287,7 +284,6 @@ pub fn test_export_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "TRON".to_string(), @@ -296,7 +292,6 @@ pub fn test_export_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "ETHEREUM".to_string(), @@ -305,7 +300,6 @@ pub fn test_export_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "FILECOIN".to_string(), @@ -314,7 +308,6 @@ pub fn test_export_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -323,7 +316,6 @@ pub fn test_export_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -332,7 +324,6 @@ pub fn test_export_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -341,7 +332,6 @@ pub fn test_export_private_key() { seg_wit: "P2WPKH".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -350,7 +340,6 @@ pub fn test_export_private_key() { seg_wit: "VERSION_0".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -359,7 +348,6 @@ pub fn test_export_private_key() { seg_wit: "VERSION_1".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "EOS".to_string(), @@ -368,7 +356,6 @@ pub fn test_export_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, ]; let pks = vec![ @@ -487,9 +474,8 @@ pub fn test_chain_cannot_export_private_key() { path: "m/44'/118'/0'/0/0".to_string(), network: "MAINNET".to_string(), seg_wit: "".to_string(), - chain_id: "".to_string(), + chain_id: "cosmoshub-4".to_string(), curve: "secp256k1".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 d4fcc82c..6a73c837 100644 --- a/token-core/tcx/tests/import_test.rs +++ b/token-core/tcx/tests/import_test.rs @@ -83,7 +83,6 @@ pub fn test_import_mnemonic() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -152,7 +151,6 @@ pub fn test_import_mnemonic_ltc() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -201,7 +199,6 @@ pub fn test_import_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "LITECOIN".to_string(), @@ -210,7 +207,6 @@ pub fn test_import_private_key() { seg_wit: "P2WPKH".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "LITECOIN".to_string(), @@ -219,7 +215,6 @@ pub fn test_import_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "TRON".to_string(), @@ -228,7 +223,6 @@ pub fn test_import_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "NERVOS".to_string(), @@ -237,7 +231,6 @@ pub fn test_import_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "ETHEREUM".to_string(), @@ -246,16 +239,14 @@ pub fn test_import_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "COSMOS".to_string(), path: "pk_not_need_path".to_string(), network: "".to_string(), seg_wit: "".to_string(), - chain_id: "".to_string(), + chain_id: "cosmoshub-4".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "EOS".to_string(), @@ -264,7 +255,6 @@ pub fn test_import_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -273,7 +263,6 @@ pub fn test_import_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -282,7 +271,6 @@ pub fn test_import_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -291,7 +279,6 @@ pub fn test_import_private_key() { seg_wit: "P2WPKH".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -300,7 +287,6 @@ pub fn test_import_private_key() { seg_wit: "VERSION_0".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "BITCOIN".to_string(), @@ -309,7 +295,6 @@ pub fn test_import_private_key() { seg_wit: "VERSION_1".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, Derivation { chain_type: "DOGECOIN".to_string(), @@ -318,7 +303,6 @@ pub fn test_import_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }, ]; let param = DeriveAccountsParam { @@ -414,7 +398,6 @@ pub fn test_import_private_key() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -460,7 +443,6 @@ pub fn test_filecoin_private_key_secp256k1_import() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -527,7 +509,6 @@ pub fn test_filecoin_private_key_bls_import() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "bls12-381".to_string(), - hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -595,7 +576,6 @@ pub fn test_fil_bls_tezos_reimport() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: case.2.to_string(), - hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: hd_import_result.id.to_string(), @@ -641,7 +621,6 @@ pub fn test_fil_bls_tezos_reimport() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: case.2.to_string(), - hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: pk_import_result.id.to_string(), @@ -690,7 +669,6 @@ pub fn test_import_sr25519_private_key() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - hrp: "".to_string(), }]; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -769,7 +747,6 @@ pub fn test_import_to_pk_which_from_hd() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }; let derive_param = DeriveAccountsParam { @@ -869,7 +846,6 @@ pub fn test_import_substrate_keystore() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }; let param = DeriveAccountsParam { @@ -961,7 +937,6 @@ pub fn test_import_substrate_keystore_v3() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "sr25519".to_string(), - hrp: "".to_string(), }; let param = DeriveAccountsParam { @@ -1045,7 +1020,6 @@ pub fn test_import_multi_curve() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }; let param = DeriveAccountsParam { @@ -1071,7 +1045,6 @@ pub fn test_import_multi_curve() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }; let param = DeriveAccountsParam { @@ -1137,7 +1110,6 @@ pub fn test_import_wif() { seg_wit: "NONE".to_string(), chain_id: "".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -1449,6 +1421,7 @@ pub fn test_reset_password_mnemonic_old_tcx_ks() { password_hint: "".to_string(), overwrite_id: overwrite_id.to_string(), }; + dbg!(overwrite_id.clone()); let ret = call_api("import_mnemonic", import_param).unwrap(); let import_result: KeystoreResult = KeystoreResult::decode(ret.as_slice()).unwrap(); diff --git a/token-core/tcx/tests/sign_test.rs b/token-core/tcx/tests/sign_test.rs index 8776be55..3dda9bde 100644 --- a/token-core/tcx/tests/sign_test.rs +++ b/token-core/tcx/tests/sign_test.rs @@ -321,7 +321,6 @@ pub fn test_sign_tron_tx_by_pk() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }; let param = DeriveAccountsParam { id: import_result.id.to_string(), @@ -702,7 +701,6 @@ pub fn test_lock_after_sign() { seg_wit: "".to_string(), chain_id: "".to_string(), curve: "".to_string(), - hrp: "".to_string(), }; let (wallet, _acc_rsp) = import_and_derive(derivation); @@ -912,7 +910,6 @@ pub fn test_sign_ethereum_legacy_tx() { seg_wit: "".to_string(), chain_id: "1".to_string(), curve: "secp256k1".to_string(), - hrp: "".to_string(), }; let (wallet, acc_rsp) = import_and_derive(derivation);