diff --git a/Cargo.lock b/Cargo.lock index e37eed7e..25b6a550 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6436,7 +6436,6 @@ dependencies = [ "strum 0.25.0", "tcx-atom", "tcx-btc-kin", - "tcx-chain", "tcx-ckb", "tcx-common", "tcx-constants", @@ -6445,6 +6444,7 @@ dependencies = [ "tcx-eth", "tcx-eth2", "tcx-filecoin", + "tcx-keystore", "tcx-migration", "tcx-primitive", "tcx-proto", @@ -6463,9 +6463,9 @@ dependencies = [ "bytes 1.4.0", "failure", "prost 0.11.8", - "tcx-chain", "tcx-constants", "tcx-crypto", + "tcx-keystore", "tcx-primitive", ] @@ -6491,39 +6491,10 @@ dependencies = [ "secp256k1 0.24.3", "serde", "serde_json", - "tcx-chain", - "tcx-common", - "tcx-constants", - "tcx-crypto", - "tcx-primitive", - "tiny-bip39 0.7.3", - "uuid 1.3.0", -] - -[[package]] -name = "tcx-chain" -version = "0.1.0" -dependencies = [ - "bitcoin", - "bitcoin_hashes", - "byteorder 1.4.3", - "bytes 1.4.0", - "cargo-husky", - "failure", - "hex 0.4.3", - "hmac-sha256", - "lazy_static", - "multihash 0.18.1", - "parking_lot", - "prost 0.11.8", - "regex 1.9.3", - "secp256k1 0.24.3", - "serde", - "serde_json", - "sha2 0.10.6", "tcx-common", "tcx-constants", "tcx-crypto", + "tcx-keystore", "tcx-primitive", "tiny-bip39 0.7.3", "uuid 1.3.0", @@ -6541,9 +6512,9 @@ dependencies = [ "hex 0.4.3", "lazy_static", "prost 0.11.8", - "tcx-chain", "tcx-constants", "tcx-crypto", + "tcx-keystore", "tcx-primitive", ] @@ -6613,10 +6584,10 @@ dependencies = [ "failure", "prost 0.11.8", "regex 1.9.3", - "tcx-chain", "tcx-common", "tcx-constants", "tcx-crypto", + "tcx-keystore", "tcx-primitive", ] @@ -6633,9 +6604,9 @@ dependencies = [ "prost-types 0.11.8", "regex 1.9.3", "rlp", - "tcx-chain", "tcx-common", "tcx-constants", + "tcx-keystore", "tcx-primitive", "tiny-keccak 2.0.2", ] @@ -6654,9 +6625,9 @@ dependencies = [ "regex 1.9.3", "ssz_rs", "ssz_rs_derive", - "tcx-chain", "tcx-constants", "tcx-crypto", + "tcx-keystore", "tcx-primitive", ] @@ -6683,19 +6654,21 @@ dependencies = [ "serde", "serde_cbor", "serde_json", - "tcx-chain", "tcx-constants", "tcx-crypto", + "tcx-keystore", "tcx-primitive", ] [[package]] -name = "tcx-identity" +name = "tcx-keystore" version = "0.1.0" dependencies = [ "bitcoin", + "bitcoin_hashes", "byteorder 1.4.3", - "eth-keystore", + "bytes 1.4.0", + "cargo-husky", "failure", "hex 0.4.3", "hmac-sha256", @@ -6703,7 +6676,7 @@ dependencies = [ "multihash 0.18.1", "parking_lot", "prost 0.11.8", - "prost-types 0.11.8", + "regex 1.9.3", "secp256k1 0.24.3", "serde", "serde_json", @@ -6712,7 +6685,7 @@ dependencies = [ "tcx-constants", "tcx-crypto", "tcx-primitive", - "tiny-bip39 1.0.0", + "tiny-bip39 0.7.3", "uuid 1.3.0", ] @@ -6736,14 +6709,13 @@ dependencies = [ "serde_json", "tcx-atom", "tcx-btc-kin", - "tcx-chain", "tcx-common", "tcx-constants", "tcx-crypto", "tcx-eos", "tcx-eth", "tcx-eth2", - "tcx-identity", + "tcx-keystore", "tcx-primitive", "tcx-proto", "tcx-tezos", @@ -6812,9 +6784,9 @@ dependencies = [ "sp-core", "sp-keyring", "sp-runtime", - "tcx-chain", "tcx-constants", "tcx-crypto", + "tcx-keystore", "tcx-primitive", "xsalsa20poly1305", ] @@ -6841,9 +6813,9 @@ dependencies = [ "prost 0.11.8", "prost-types 0.11.8", "ring", - "tcx-chain", "tcx-constants", "tcx-crypto", + "tcx-keystore", "tcx-primitive", ] @@ -6867,10 +6839,10 @@ dependencies = [ "secp256k1 0.24.3", "serde", "serde_json", - "tcx-chain", "tcx-common", "tcx-constants", "tcx-crypto", + "tcx-keystore", "tcx-primitive", "tiny-bip39 0.7.3", "uuid 1.3.0", diff --git a/Cargo.toml b/Cargo.toml index ae0d43c7..eba1621b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ members=[ "token-core/tcx-constants", "token-core/tcx-primitive", "token-core/tcx-crypto", - "token-core/tcx-chain", + "token-core/tcx-keystore", "token-core/tcx-tron", "token-core/tcx-btc-kin", "token-core/tcx-ckb", diff --git a/token-core/tcx-atom/Cargo.toml b/token-core/tcx-atom/Cargo.toml index 0f5de23c..ba74aec3 100644 --- a/token-core/tcx-atom/Cargo.toml +++ b/token-core/tcx-atom/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] tcx-crypto = { path = "../tcx-crypto" } -tcx-chain = { path = "../tcx-chain" } +tcx-keystore = { path = "../tcx-keystore" } tcx-primitive = { path = "../tcx-primitive" } tcx-constants = { path = "../tcx-constants" } diff --git a/token-core/tcx-atom/src/address.rs b/token-core/tcx-atom/src/address.rs index 02d9410b..7467d4b7 100644 --- a/token-core/tcx-atom/src/address.rs +++ b/token-core/tcx-atom/src/address.rs @@ -1,9 +1,9 @@ use core::str::FromStr; use bech32::{FromBase32, ToBase32, Variant}; -use tcx_chain::{Address, ChainFactory, PublicKeyEncoder, Result}; use tcx_constants::CoinInfo; use tcx_crypto::hash; +use tcx_keystore::{Address, ChainFactory, PublicKeyEncoder, Result}; use tcx_primitive::TypedPublicKey; // size of address @@ -77,7 +77,7 @@ impl ChainFactory for AtomChainFactory { mod tests { use crate::address::AtomAddress; - use tcx_chain::Address; + use tcx_keystore::Address; use tcx_constants::{CoinInfo, CurveType}; use tcx_crypto::hex; diff --git a/token-core/tcx-atom/src/lib.rs b/token-core/tcx-atom/src/lib.rs index 992a03fd..7eb6ab5a 100644 --- a/token-core/tcx-atom/src/lib.rs +++ b/token-core/tcx-atom/src/lib.rs @@ -3,8 +3,8 @@ pub mod signer; pub mod transaction; pub mod cosmos { - use tcx_chain::{Account, Keystore}; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::{Account, Keystore}; pub const CHAINS: [&'static str; 1] = ["COSMOS"]; diff --git a/token-core/tcx-atom/src/signer.rs b/token-core/tcx-atom/src/signer.rs index 7794bf0b..a65d8c54 100644 --- a/token-core/tcx-atom/src/signer.rs +++ b/token-core/tcx-atom/src/signer.rs @@ -1,5 +1,5 @@ use crate::transaction::{AtomTxInput, AtomTxOutput}; -use tcx_chain::{ChainSigner, Keystore, Result, TransactionSigner as TraitTransactionSigner}; +use tcx_keystore::{ChainSigner, Keystore, Result, TransactionSigner as TraitTransactionSigner}; use tcx_crypto::{hash, hex}; @@ -31,9 +31,9 @@ mod tests { use super::*; use crate::address::AtomAddress; - use tcx_chain::{HdKeystore, Keystore, KeystoreGuard, Metadata}; use tcx_constants::{CoinInfo, TEST_PASSWORD}; use tcx_constants::{CurveType, TEST_MNEMONIC}; + use tcx_keystore::{HdKeystore, Keystore, KeystoreGuard, Metadata}; #[test] fn sign_transaction() -> core::result::Result<(), failure::Error> { diff --git a/token-core/tcx-btc-kin/Cargo.toml b/token-core/tcx-btc-kin/Cargo.toml index d02eca34..779deb9c 100644 --- a/token-core/tcx-btc-kin/Cargo.toml +++ b/token-core/tcx-btc-kin/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] tcx-crypto = { path = "../tcx-crypto" } -tcx-chain = { path = "../tcx-chain" } +tcx-keystore = { path = "../tcx-keystore" } tcx-primitive = { path = "../tcx-primitive" } tcx-constants = { path = "../tcx-constants" } tcx-common = { path = "../tcx-common" } diff --git a/token-core/tcx-btc-kin/src/address.rs b/token-core/tcx-btc-kin/src/address.rs index bc1c7358..6ad9ac44 100644 --- a/token-core/tcx-btc-kin/src/address.rs +++ b/token-core/tcx-btc-kin/src/address.rs @@ -17,8 +17,8 @@ use bitcoin::{Address as LibAddress, Script}; use bitcoin_hashes::Hash; use secp256k1::Secp256k1; -use tcx_chain::Address; use tcx_constants::CoinInfo; +use tcx_keystore::Address; use tcx_primitive::{Ss58Codec, TypedPrivateKey, TypedPublicKey}; use crate::network::BtcKinNetwork; @@ -294,7 +294,7 @@ mod tests { use tcx_primitive::{Bip32DeterministicPrivateKey, Derive, DeterministicPrivateKey, Ss58Codec}; use crate::address::BtcKinAddress; - use crate::tcx_chain::Address; + use crate::tcx_keystore::Address; use crate::BtcKinNetwork; #[test] diff --git a/token-core/tcx-btc-kin/src/bch_address.rs b/token-core/tcx-btc-kin/src/bch_address.rs index 51903b73..67fe5b64 100644 --- a/token-core/tcx-btc-kin/src/bch_address.rs +++ b/token-core/tcx-btc-kin/src/bch_address.rs @@ -8,8 +8,8 @@ use core::result; use std::fmt::{Display, Formatter}; use std::str::FromStr; -use tcx_chain::Address; use tcx_constants::CoinInfo; +use tcx_keystore::Address; use tcx_primitive::TypedPublicKey; fn remove_bch_prefix(addr: &str) -> String { @@ -108,9 +108,9 @@ mod tests { use super::{remove_bch_prefix, BchAddress}; use crate::address::WIFDisplay; - use tcx_chain::Address; use tcx_constants::coin_info::coin_info_from_param; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::Address; use tcx_primitive::{PrivateKey, Secp256k1PrivateKey, TypedPublicKey}; use tcx_primitive::{PublicKey, TypedPrivateKey}; diff --git a/token-core/tcx-btc-kin/src/lib.rs b/token-core/tcx-btc-kin/src/lib.rs index 24be1206..d2d158ce 100644 --- a/token-core/tcx-btc-kin/src/lib.rs +++ b/token-core/tcx-btc-kin/src/lib.rs @@ -19,7 +19,7 @@ extern crate num_integer; extern crate num_traits; #[macro_use] -extern crate tcx_chain; +extern crate tcx_keystore; extern crate core; pub type Result = result::Result; @@ -27,7 +27,7 @@ pub type Result = result::Result; pub use address::{BtcKinAddress, WIFDisplay}; pub use bch_address::BchAddress; pub use network::BtcKinNetwork; -use tcx_chain::{Address, Keystore}; +use tcx_keystore::{Address, Keystore}; use tcx_primitive::{ Bip32DeterministicPublicKey, Derive, DeterministicPublicKey, FromHex, TypedPublicKey, }; @@ -64,8 +64,8 @@ pub enum Error { pub mod bitcoin { use crate::{BtcKinAddress, BITCOIN, LITECOIN}; - use tcx_chain::{Account, Keystore}; use tcx_constants::CoinInfo; + use tcx_keystore::{Account, Keystore}; pub const CHAINS: [&'static str; 2] = [BITCOIN, LITECOIN]; @@ -172,8 +172,8 @@ pub fn calc_btc_change_address( pub mod bitcoincash { use crate::BITCOINCASH; - use tcx_chain::{Account, Keystore}; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::{Account, Keystore}; pub static CHAINS: [&'static str; 1] = [BITCOINCASH]; @@ -225,10 +225,10 @@ mod tests { use serde_json::Value; - use tcx_chain::KeystoreGuard; - use tcx_chain::{HdKeystore, Keystore, Metadata}; use tcx_constants::CurveType; use tcx_constants::{CoinInfo, TEST_MNEMONIC, TEST_PASSWORD}; + use tcx_keystore::KeystoreGuard; + use tcx_keystore::{HdKeystore, Keystore, Metadata}; const BIP_PATH: &str = "m/44'/145'/0'"; diff --git a/token-core/tcx-btc-kin/src/signer.rs b/token-core/tcx-btc-kin/src/signer.rs index b3303e15..e8094058 100644 --- a/token-core/tcx-btc-kin/src/signer.rs +++ b/token-core/tcx-btc-kin/src/signer.rs @@ -19,9 +19,9 @@ use bitcoin_hashes::Hash; use byteorder::{BigEndian, WriteBytesExt}; use secp256k1::{Message, Secp256k1}; -use tcx_chain::keystore::Error as KeystoreError; -use tcx_chain::Address; -use tcx_chain::{Keystore, TransactionSigner}; +use tcx_keystore::keystore::Error as KeystoreError; +use tcx_keystore::Address; +use tcx_keystore::{Keystore, TransactionSigner}; use tcx_primitive::{Derive, PrivateKey, PublicKey, Secp256k1PrivateKey, TypedPrivateKey}; use crate::address::{BtcKinAddress, ScriptPubkey}; @@ -475,10 +475,10 @@ impl TransactionSigner for Keystore { #[cfg(test)] mod tests { - use tcx_chain::Metadata; - use tcx_chain::{Keystore, TransactionSigner}; use tcx_constants::coin_info::coin_info_from_param; use tcx_constants::{TEST_MNEMONIC, TEST_PASSWORD, TEST_WIF}; + use tcx_keystore::Metadata; + use tcx_keystore::{Keystore, TransactionSigner}; use tcx_primitive::Secp256k1PrivateKey; use crate::address::BtcKinAddress; @@ -615,8 +615,8 @@ mod tests { mod bitcoincash { use crate::{bitcoincash, BtcKinTxInput, Utxo, BITCOINCASH}; - use tcx_chain::{Keystore, Metadata, TransactionSigner}; use tcx_constants::TEST_PASSWORD; + use tcx_keystore::{Keystore, Metadata, TransactionSigner}; #[test] pub fn test_bch_signer() { diff --git a/token-core/tcx-ckb/Cargo.toml b/token-core/tcx-ckb/Cargo.toml index e171fd8a..68fd4964 100644 --- a/token-core/tcx-ckb/Cargo.toml +++ b/token-core/tcx-ckb/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] tcx-crypto = { path = "../tcx-crypto" } -tcx-chain = { path = "../tcx-chain" } +tcx-keystore = { path = "../tcx-keystore" } tcx-primitive = { path = "../tcx-primitive" } tcx-constants = { path = "../tcx-constants" } diff --git a/token-core/tcx-ckb/src/address.rs b/token-core/tcx-ckb/src/address.rs index d1f96012..d22cdf21 100644 --- a/token-core/tcx-ckb/src/address.rs +++ b/token-core/tcx-ckb/src/address.rs @@ -1,8 +1,8 @@ use crate::hash::blake2b_160; use bech32::{FromBase32, ToBase32, Variant}; use std::str::FromStr; -use tcx_chain::{Address, Result}; use tcx_constants::CoinInfo; +use tcx_keystore::{Address, Result}; use tcx_primitive::TypedPublicKey; // TYPE should be u5 @@ -82,7 +82,7 @@ impl ToString for CkbAddress { #[cfg(test)] mod tests { use crate::address::CkbAddress; - use tcx_chain::Address; + use tcx_keystore::Address; use tcx_constants::{CoinInfo, CurveType}; use tcx_primitive::TypedPublicKey; diff --git a/token-core/tcx-ckb/src/lib.rs b/token-core/tcx-ckb/src/lib.rs index a97e3e1a..33054a89 100644 --- a/token-core/tcx-ckb/src/lib.rs +++ b/token-core/tcx-ckb/src/lib.rs @@ -9,7 +9,7 @@ use failure::Fail; pub use address::CkbAddress; pub use serializer::Serializer; -use tcx_chain::Result; +use tcx_keystore::Result; pub use transaction::{CachedCell, CellInput, CkbTxInput, CkbTxOutput, OutPoint, Script, Witness}; #[derive(Fail, Debug, PartialEq)] @@ -59,8 +59,8 @@ pub fn hex_to_bytes(value: &str) -> Result> { } pub mod nervos { - use tcx_chain::{Account, Keystore}; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::{Account, Keystore}; pub const CHAINS: [&'static str; 1] = ["NERVOS"]; diff --git a/token-core/tcx-ckb/src/signer.rs b/token-core/tcx-ckb/src/signer.rs index aea47bc4..97dfe3ca 100644 --- a/token-core/tcx-ckb/src/signer.rs +++ b/token-core/tcx-ckb/src/signer.rs @@ -1,11 +1,11 @@ -use tcx_chain::{Keystore, Result, TransactionSigner}; +use tcx_keystore::{Keystore, Result, TransactionSigner}; use crate::hash::new_blake2b; use crate::serializer::Serializer; use crate::transaction::{CachedCell, CkbTxInput, CkbTxOutput, OutPoint, Witness}; use crate::{hex_to_bytes, Error}; use std::collections::HashMap; -use tcx_chain::ChainSigner; +use tcx_keystore::ChainSigner; use lazy_static::lazy_static; @@ -194,8 +194,8 @@ impl TransactionSigner for Keystore { mod tests { use crate::address::CkbAddress; use crate::transaction::{CachedCell, CellInput, CkbTxInput, OutPoint, Script, Witness}; - use tcx_chain::{Keystore, Metadata, TransactionSigner}; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::{Keystore, Metadata, TransactionSigner}; #[test] fn test_sign_transaction() { diff --git a/token-core/tcx-ckb/src/transaction_helper.rs b/token-core/tcx-ckb/src/transaction_helper.rs index afbbe7b5..6cc87bb8 100644 --- a/token-core/tcx-ckb/src/transaction_helper.rs +++ b/token-core/tcx-ckb/src/transaction_helper.rs @@ -4,7 +4,7 @@ use crate::transaction::{Script, Witness}; use super::Error; use crate::hash::blake2b_256; use crate::hex_to_bytes; -use tcx_chain::Result; +use tcx_keystore::Result; impl Script { pub fn serialize_hash_type(&self) -> Result> { diff --git a/token-core/tcx-docs/TECH.zh.md b/token-core/tcx-docs/TECH.zh.md index 9c2b0a64..a113b81a 100644 --- a/token-core/tcx-docs/TECH.zh.md +++ b/token-core/tcx-docs/TECH.zh.md @@ -291,8 +291,8 @@ fn _sign_btc_fork_transaction(json: &str, keystore: &HdKeystore, password: &str) ## 新链接入(简略版) 1. 添加一个新的package,命名为`tcx-blockchain`其中的blockchain用链的名称替换,将如下代码写入该package里面 2. 定义CoinInfo, CoinInfo可以指定你要添加的链的名称,所在的曲线以及助记词的派生路径。 -3. 可选)如果你所添加的链包含有特殊的需要保存的信息,你需要实现你自己的`tcx_chain::Extra`。该接口用于根据`CoinInfo`和`Seed`生成特定信息,最终该信息会被序列化成JSON数据存储在account中的extra字段内。 -4. 实现tcx_chain::Address,添加你所在的链的地址推导方法,分别添加判断地址是否有效,根据pub_key生成地址 -5. 实现tcx_chain::Transaction,添加你签名是需要输入的字段, 实现tcx_chain::SignedTransaction,添加你签名结束后的输出内容。如果的的签名结果比较简单,你可以使用tcx默认提供的TxSignResult结构。 -6. 实现tcx_chain::TransactionSigner,添加你所在的链特定的签名算法 +3. 可选)如果你所添加的链包含有特殊的需要保存的信息,你需要实现你自己的`tcx_keystore::Extra`。该接口用于根据`CoinInfo`和`Seed`生成特定信息,最终该信息会被序列化成JSON数据存储在account中的extra字段内。 +4. 实现tcx_keystore::Address,添加你所在的链的地址推导方法,分别添加判断地址是否有效,根据pub_key生成地址 +5. 实现tcx_keystore::Transaction,添加你签名是需要输入的字段, 实现tcx_keystore::SignedTransaction,添加你签名结束后的输出内容。如果的的签名结果比较简单,你可以使用tcx默认提供的TxSignResult结构。 +6. 实现tcx_keystore::TransactionSigner,添加你所在的链特定的签名算法 7. 在tcx层添加match pattern 指向正确的处理逻辑 diff --git a/token-core/tcx-eos/Cargo.toml b/token-core/tcx-eos/Cargo.toml index 9e582e1a..33767e25 100644 --- a/token-core/tcx-eos/Cargo.toml +++ b/token-core/tcx-eos/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] tcx-crypto = { path = "../tcx-crypto" } -tcx-chain = { path = "../tcx-chain" } +tcx-keystore = { path = "../tcx-keystore" } tcx-primitive = { path = "../tcx-primitive" } tcx-constants = { path = "../tcx-constants" } tcx-common = {path = "../tcx-common"} diff --git a/token-core/tcx-eos/src/address.rs b/token-core/tcx-eos/src/address.rs index f146ecc3..ccbf3486 100644 --- a/token-core/tcx-eos/src/address.rs +++ b/token-core/tcx-eos/src/address.rs @@ -1,10 +1,10 @@ use base58::{FromBase58, ToBase58}; use regex::Regex; use std::str::FromStr; -use tcx_chain::{Address, ChainFactory, PublicKeyEncoder, Result}; use tcx_common::CommonError; use tcx_constants::CoinInfo; use tcx_crypto::hash; +use tcx_keystore::{Address, ChainFactory, PublicKeyEncoder, Result}; use tcx_primitive::{PublicKey, TypedPublicKey}; #[derive(PartialEq, Eq, Clone)] @@ -69,7 +69,7 @@ impl ToString for EosAddress { mod tests { use crate::address::EosAddress; use std::str::FromStr; - use tcx_chain::{Address, ChainFactory, PublicKeyEncoder}; + use tcx_keystore::{Address, ChainFactory, PublicKeyEncoder}; use tcx_constants::{CoinInfo, CurveType}; use tcx_primitive::{ diff --git a/token-core/tcx-eos/src/chain_factory.rs b/token-core/tcx-eos/src/chain_factory.rs index c8e7df8a..2fc275d3 100644 --- a/token-core/tcx-eos/src/chain_factory.rs +++ b/token-core/tcx-eos/src/chain_factory.rs @@ -1,7 +1,7 @@ use base58::{FromBase58, ToBase58}; use failure::format_err; -use tcx_chain::{tcx_ensure, ChainFactory, PrivateKeyEncoder, PublicKeyEncoder, Result}; use tcx_crypto::hash; +use tcx_keystore::{tcx_ensure, ChainFactory, PrivateKeyEncoder, PublicKeyEncoder, Result}; use tcx_primitive::{PrivateKey, PublicKey, Secp256k1PrivateKey, Secp256k1PublicKey, Ss58Codec}; pub struct EosPublicKeyEncoder(); @@ -51,7 +51,7 @@ impl ChainFactory for EosChainFactory { mod tests { use crate::{address::EosAddress, EosChainFactory}; - use tcx_chain::{ + use tcx_keystore::{ ChainFactory, HdKeystore, Keystore, Metadata, PrivateKeyEncoder, PublicKeyEncoder, }; diff --git a/token-core/tcx-eos/src/lib.rs b/token-core/tcx-eos/src/lib.rs index 4e64bdf5..fd5b104c 100644 --- a/token-core/tcx-eos/src/lib.rs +++ b/token-core/tcx-eos/src/lib.rs @@ -5,8 +5,8 @@ pub mod transaction; pub use chain_factory::EosChainFactory; pub mod eos { - use tcx_chain::{Account, Keystore}; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::{Account, Keystore}; pub const CHAINS: [&'static str; 1] = ["EOS"]; diff --git a/token-core/tcx-eos/src/signer.rs b/token-core/tcx-eos/src/signer.rs index 596d07db..a8453914 100644 --- a/token-core/tcx-eos/src/signer.rs +++ b/token-core/tcx-eos/src/signer.rs @@ -1,6 +1,6 @@ use crate::transaction::{EosMessageInput, EosMessageOutput, EosTxInput, EosTxOutput, SigData}; use base58::ToBase58; -use tcx_chain::{ +use tcx_keystore::{ ChainSigner, Keystore, MessageSigner, Result, TransactionSigner as TraitTransactionSigner, }; diff --git a/token-core/tcx-eth/Cargo.toml b/token-core/tcx-eth/Cargo.toml index 3af08d4f..bd7c6754 100644 --- a/token-core/tcx-eth/Cargo.toml +++ b/token-core/tcx-eth/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tcx-chain = {path = "../tcx-chain"} +tcx-keystore = {path = "../tcx-keystore"} tcx-primitive = {path = "../tcx-primitive"} tcx-constants = {path = "../tcx-constants"} tcx-common = {path = "../tcx-common"} diff --git a/token-core/tcx-eth/src/address.rs b/token-core/tcx-eth/src/address.rs index 510ede90..5a4a9d42 100644 --- a/token-core/tcx-eth/src/address.rs +++ b/token-core/tcx-eth/src/address.rs @@ -3,9 +3,9 @@ use ethereum_types::H160; use failure::format_err; use regex::Regex; use std::str::FromStr; -use tcx_chain::Address; use tcx_common::keccak256; use tcx_constants::CoinInfo; +use tcx_keystore::Address; use tcx_primitive::TypedPublicKey; #[derive(PartialEq, Eq, Clone)] @@ -77,8 +77,8 @@ pub fn is_valid_address(address: &str) -> bool { #[cfg(test)] mod test { use crate::address::EthAddress; - use tcx_chain::Address; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::Address; use tcx_primitive::{PrivateKey, Secp256k1PrivateKey, TypedPrivateKey}; #[test] diff --git a/token-core/tcx-eth/src/lib.rs b/token-core/tcx-eth/src/lib.rs index 26e88438..3932b1d2 100644 --- a/token-core/tcx-eth/src/lib.rs +++ b/token-core/tcx-eth/src/lib.rs @@ -8,8 +8,8 @@ pub type Result = result::Result; pub mod ethereum { use crate::address::EthAddress; - use tcx_chain::{Account, Keystore}; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::{Account, Keystore}; pub const CHAINS: [&'static str; 1] = ["ETHEREUM"]; diff --git a/token-core/tcx-eth/src/signer.rs b/token-core/tcx-eth/src/signer.rs index 78cf74f2..95244f16 100644 --- a/token-core/tcx-eth/src/signer.rs +++ b/token-core/tcx-eth/src/signer.rs @@ -11,8 +11,8 @@ use ethers::types::{Bytes, Eip1559TransactionRequest, Signature, TransactionRequ use ethers::utils::{hash_message, keccak256}; use keccak_hash::keccak; use std::str::FromStr; -use tcx_chain::{Keystore, MessageSigner, TransactionSigner}; use tcx_common::{hex_to_bytes, utf8_or_hex_to_bytes}; +use tcx_keystore::{Keystore, MessageSigner, TransactionSigner}; impl TransactionSigner for Keystore { fn sign_transaction( @@ -20,7 +20,7 @@ impl TransactionSigner for Keystore { symbol: &str, address: &str, tx: &EthTxInput, - ) -> tcx_chain::Result { + ) -> tcx_keystore::Result { let private_key = self.find_private_key(symbol, address)?; tx.sign_transaction(&private_key.to_bytes()) } @@ -32,7 +32,7 @@ impl MessageSigner for Keystore { symbol: &str, address: &str, message: &EthMessageInput, - ) -> tcx_chain::Result { + ) -> tcx_keystore::Result { let private_key = self.find_private_key(symbol, address)?; if message.signature_type == SignatureType::PersonalSign as i32 { message.sign_message(&private_key.to_bytes()) @@ -174,7 +174,7 @@ mod test { use crate::transaction::{ AccessList, EthMessageInput, EthMessageOutput, EthTxInput, EthTxOutput, SignatureType, }; - use tcx_chain::{Keystore, MessageSigner, Metadata, TransactionSigner}; + use tcx_keystore::{Keystore, MessageSigner, Metadata, TransactionSigner}; fn private_key_store(key: &str) -> Keystore { let mut ks = Keystore::from_private_key(key, "imToken1", Metadata::default()); diff --git a/token-core/tcx-eth2/Cargo.toml b/token-core/tcx-eth2/Cargo.toml index bd8a51c9..cd0788c2 100644 --- a/token-core/tcx-eth2/Cargo.toml +++ b/token-core/tcx-eth2/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tcx-chain = { path = "../tcx-chain" } +tcx-keystore = { path = "../tcx-keystore" } tcx-constants = { path = "../tcx-constants" } tcx-primitive = { path = "../tcx-primitive" } tcx-crypto = { path = "../tcx-crypto" } diff --git a/token-core/tcx-eth2/src/address.rs b/token-core/tcx-eth2/src/address.rs index deb8cec2..3299ba4b 100644 --- a/token-core/tcx-eth2/src/address.rs +++ b/token-core/tcx-eth2/src/address.rs @@ -1,7 +1,7 @@ use std::str::FromStr; -use tcx_chain::Address; -use tcx_chain::Result; use tcx_constants::CoinInfo; +use tcx_keystore::Address; +use tcx_keystore::Result; use tcx_primitive::TypedPublicKey; #[derive(PartialEq, Eq, Clone)] @@ -47,8 +47,8 @@ impl FromStr for Eth2Address { #[cfg(test)] mod test { use crate::address::Eth2Address; - use tcx_chain::Address; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::Address; #[test] fn is_valid_test() { diff --git a/token-core/tcx-eth2/src/lib.rs b/token-core/tcx-eth2/src/lib.rs index f3f4543e..535fe1e6 100644 --- a/token-core/tcx-eth2/src/lib.rs +++ b/token-core/tcx-eth2/src/lib.rs @@ -5,7 +5,7 @@ mod bls_to_execution_change; pub mod signer; pub mod transaction; use failure::Fail; -use tcx_chain::Result; +use tcx_keystore::Result; #[derive(Fail, Debug, PartialEq)] pub enum Error { @@ -26,8 +26,8 @@ pub fn hex_to_bytes(value: &str) -> Result> { pub mod ethereum2 { use crate::address::Eth2Address; - use tcx_chain::{Account, Keystore}; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::{Account, Keystore}; pub const CHAINS: [&'static str; 1] = ["ETHEREUM2"]; diff --git a/token-core/tcx-eth2/src/signer.rs b/token-core/tcx-eth2/src/signer.rs index f7782567..5f53bc1c 100644 --- a/token-core/tcx-eth2/src/signer.rs +++ b/token-core/tcx-eth2/src/signer.rs @@ -6,7 +6,7 @@ use crate::transaction::{ use crate::{Error, Result}; use keccak_hash; use regex::Regex; -use tcx_chain::{ChainSigner, Keystore}; +use tcx_keystore::{ChainSigner, Keystore}; impl SignBlsToExecutionChangeParam { pub fn sign_bls_to_execution_change( diff --git a/token-core/tcx-filecoin/Cargo.toml b/token-core/tcx-filecoin/Cargo.toml index 644dcefa..ac0d2fc3 100644 --- a/token-core/tcx-filecoin/Cargo.toml +++ b/token-core/tcx-filecoin/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] tcx-crypto = { path = "../tcx-crypto" } -tcx-chain = { path = "../tcx-chain" } +tcx-keystore = { path = "../tcx-keystore" } tcx-primitive = { path = "../tcx-primitive" } tcx-constants = { path = "../tcx-constants" } diff --git a/token-core/tcx-filecoin/src/address.rs b/token-core/tcx-filecoin/src/address.rs index de198722..b4c57858 100644 --- a/token-core/tcx-filecoin/src/address.rs +++ b/token-core/tcx-filecoin/src/address.rs @@ -1,5 +1,5 @@ -use tcx_chain::{Address, Result}; use tcx_constants::CoinInfo; +use tcx_keystore::{Address, Result}; use tcx_primitive::{PublicKey, TypedPublicKey}; use forest_address::Address as ForestAddress; @@ -104,8 +104,8 @@ impl ToString for FilecoinAddress { #[cfg(test)] mod tests { use crate::address::FilecoinAddress; - use tcx_chain::{Address, Keystore, Metadata}; use tcx_constants::{coin_info_from_param, CoinInfo, CurveType}; + use tcx_keystore::{Address, Keystore, Metadata}; use tcx_primitive::TypedPublicKey; #[test] diff --git a/token-core/tcx-filecoin/src/key_info.rs b/token-core/tcx-filecoin/src/key_info.rs index a258a5bc..404723ba 100644 --- a/token-core/tcx-filecoin/src/key_info.rs +++ b/token-core/tcx-filecoin/src/key_info.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use tcx_chain::Result; use tcx_constants::CurveType; +use tcx_keystore::Result; use super::Error; diff --git a/token-core/tcx-filecoin/src/lib.rs b/token-core/tcx-filecoin/src/lib.rs index 5a202c40..e506bb24 100644 --- a/token-core/tcx-filecoin/src/lib.rs +++ b/token-core/tcx-filecoin/src/lib.rs @@ -34,8 +34,8 @@ pub enum Error { } pub mod filecoin { - use tcx_chain::{Account, Keystore}; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::{Account, Keystore}; pub static CHAINS: [&'static str; 1] = ["FILECOIN"]; diff --git a/token-core/tcx-filecoin/src/signer.rs b/token-core/tcx-filecoin/src/signer.rs index 4fa2bb32..acc7714c 100644 --- a/token-core/tcx-filecoin/src/signer.rs +++ b/token-core/tcx-filecoin/src/signer.rs @@ -9,8 +9,8 @@ use forest_vm::Serialized; use num_bigint_chainsafe::BigInt; use std::convert::TryFrom; use std::str::FromStr; -use tcx_chain::{ChainSigner, Keystore, Result, TransactionSigner}; use tcx_constants::CurveType; +use tcx_keystore::{ChainSigner, Keystore, Result, TransactionSigner}; impl TryFrom<&UnsignedMessage> for ForestUnsignedMessage { type Error = crate::Error; @@ -107,8 +107,8 @@ impl TransactionSigner for Keystore { #[cfg(test)] mod tests { use crate::{FilecoinAddress, KeyInfo, UnsignedMessage}; - use tcx_chain::{Keystore, Metadata, TransactionSigner}; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::{Keystore, Metadata, TransactionSigner}; #[test] fn test_sign_spec256k1() { diff --git a/token-core/tcx-identity/Cargo.toml b/token-core/tcx-identity/Cargo.toml index 76d405e9..274e99b1 100644 --- a/token-core/tcx-identity/Cargo.toml +++ b/token-core/tcx-identity/Cargo.toml @@ -10,7 +10,7 @@ tcx-primitive = { path = "../tcx-primitive" } tcx-crypto = { path = "../tcx-crypto"} tcx-constants = { path = "../tcx-constants"} #tcx-eth = {path = "../tcx-eth"} -# tcx-chain = {path = "../tcx-chain"} +# tcx-keystore = {path = "../tcx-keystore"} tcx-common = {path = "../tcx-common"} failure = "0.1.8" diff --git a/token-core/tcx-chain/Cargo.toml b/token-core/tcx-keystore/Cargo.toml similarity index 97% rename from token-core/tcx-chain/Cargo.toml rename to token-core/tcx-keystore/Cargo.toml index f009b7cb..21ecf387 100644 --- a/token-core/tcx-chain/Cargo.toml +++ b/token-core/tcx-keystore/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "tcx-chain" +name = "tcx-keystore" version = "0.1.0" authors = ["Neal Xu "] edition = "2021" diff --git a/token-core/tcx-chain/README.md b/token-core/tcx-keystore/README.md similarity index 100% rename from token-core/tcx-chain/README.md rename to token-core/tcx-keystore/README.md diff --git a/token-core/tcx-chain/src/identity.rs b/token-core/tcx-keystore/src/identity.rs similarity index 100% rename from token-core/tcx-chain/src/identity.rs rename to token-core/tcx-keystore/src/identity.rs diff --git a/token-core/tcx-chain/src/keystore/guard.rs b/token-core/tcx-keystore/src/keystore/guard.rs similarity index 100% rename from token-core/tcx-chain/src/keystore/guard.rs rename to token-core/tcx-keystore/src/keystore/guard.rs diff --git a/token-core/tcx-chain/src/keystore/hd.rs b/token-core/tcx-keystore/src/keystore/hd.rs similarity index 100% rename from token-core/tcx-chain/src/keystore/hd.rs rename to token-core/tcx-keystore/src/keystore/hd.rs diff --git a/token-core/tcx-chain/src/keystore/mod.rs b/token-core/tcx-keystore/src/keystore/mod.rs similarity index 100% rename from token-core/tcx-chain/src/keystore/mod.rs rename to token-core/tcx-keystore/src/keystore/mod.rs diff --git a/token-core/tcx-chain/src/keystore/private.rs b/token-core/tcx-keystore/src/keystore/private.rs similarity index 100% rename from token-core/tcx-chain/src/keystore/private.rs rename to token-core/tcx-keystore/src/keystore/private.rs diff --git a/token-core/tcx-chain/src/lib.rs b/token-core/tcx-keystore/src/lib.rs similarity index 100% rename from token-core/tcx-chain/src/lib.rs rename to token-core/tcx-keystore/src/lib.rs diff --git a/token-core/tcx-chain/src/signer.rs b/token-core/tcx-keystore/src/signer.rs similarity index 100% rename from token-core/tcx-chain/src/signer.rs rename to token-core/tcx-keystore/src/signer.rs diff --git a/token-core/tcx-migration/Cargo.toml b/token-core/tcx-migration/Cargo.toml index 7332c719..8e2d11a5 100644 --- a/token-core/tcx-migration/Cargo.toml +++ b/token-core/tcx-migration/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] tcx-proto = { path = "../tcx-proto" } tcx-crypto = { path = "../tcx-crypto", features = ["cache_dk"] } -tcx-chain = { path = "../tcx-chain", features = ["cache_dk"] } +tcx-keystore = { path = "../tcx-keystore", features = ["cache_dk"] } tcx-atom = { path = "../tcx-atom" } tcx-eos = { path = "../tcx-eos" } tcx-btc-kin = { path = "../tcx-btc-kin" } @@ -19,7 +19,6 @@ tcx-tron = { path = "../tcx-tron" } tcx-eth2 = { path = "../tcx-eth2" } tcx-eth = { path = "../tcx-eth" } tcx-common = { path = "../tcx-common" } -tcx-identity = { path = "../tcx-identity" } #zksync-crypto = { git="https://github.com/consenlabs/zksync", branch="hotfix/compatible_with_tcx" } prost = "0.11.2" diff --git a/token-core/tcx-migration/src/migration.rs b/token-core/tcx-migration/src/migration.rs index 90aa97c4..4bae8121 100644 --- a/token-core/tcx-migration/src/migration.rs +++ b/token-core/tcx-migration/src/migration.rs @@ -4,19 +4,19 @@ use std::{fs, str::FromStr}; use failure::format_err; use serde::{Deserialize, Deserializer, Serialize}; use tcx_atom::address::AtomAddress; -use tcx_chain::{ +use tcx_constants::CoinInfo; +use tcx_crypto::{Crypto, EncPair, KdfParams, Key}; +use tcx_keystore::{ key_hash_from_mnemonic, key_hash_from_private_key, Account, HdKeystore, PrivateKeystore, Result, Source, }; -use tcx_constants::CoinInfo; -use tcx_crypto::{Crypto, EncPair, KdfParams, Key}; use tcx_btc_kin::address::BtcKinAddress; use tcx_btc_kin::Error; -use tcx_chain::identity::Identity; -use tcx_chain::keystore::{Keystore, Metadata, Store}; use tcx_eos::address::EosAddress; use tcx_eth::address::EthAddress; +use tcx_keystore::identity::Identity; +use tcx_keystore::keystore::{Keystore, Metadata, Store}; use tcx_primitive::{PrivateKey, Secp256k1PrivateKey}; #[derive(Debug, Serialize, Deserialize, Clone)] @@ -270,9 +270,6 @@ impl LegacyKeystore { #[cfg(test)] mod tests { use serde_json::Value; - use tcx_chain::keystore::Store; - use tcx_chain::HdKeystore; - use tcx_chain::{Keystore, KeystoreGuard, Metadata, PrivateKeystore, Source}; use tcx_constants::TEST_PASSWORD; use tcx_constants::{CoinInfo, TEST_MNEMONIC}; use tcx_crypto::crypto::SCryptParams; @@ -280,6 +277,9 @@ mod tests { use tcx_crypto::Crypto; use tcx_crypto::Pbkdf2Params; use tcx_crypto::{EncPair, Key}; + use tcx_keystore::keystore::Store; + use tcx_keystore::HdKeystore; + use tcx_keystore::{Keystore, KeystoreGuard, Metadata, PrivateKeystore, Source}; use super::LegacyKeystore; diff --git a/token-core/tcx-proto/build.rs b/token-core/tcx-proto/build.rs index 2d00519b..c7ba83be 100644 --- a/token-core/tcx-proto/build.rs +++ b/token-core/tcx-proto/build.rs @@ -59,10 +59,6 @@ fn main() { env::set_var("OUT_DIR", "../tcx-eth2/src"); prost_build::compile_protos(&["src/eth2.proto"], &["src/"]).unwrap(); - // //tcx-identity - // env::set_var("OUT_DIR", "../tcx-identity/src"); - // prost_build::compile_protos(&["src/wallet_api.proto"], &["src/"]).unwrap(); - //tcx-eth env::set_var("OUT_DIR", "../tcx-eth/src"); prost_build::compile_protos(&["src/eth.proto"], &["src/"]).unwrap(); diff --git a/token-core/tcx-substrate/Cargo.toml b/token-core/tcx-substrate/Cargo.toml index 6780640e..90da6c48 100644 --- a/token-core/tcx-substrate/Cargo.toml +++ b/token-core/tcx-substrate/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] tcx-crypto = { path = "../tcx-crypto" } -tcx-chain = { path = "../tcx-chain" } +tcx-keystore = { path = "../tcx-keystore" } tcx-primitive = { path = "../tcx-primitive" } tcx-constants = { path = "../tcx-constants" } diff --git a/token-core/tcx-substrate/src/address.rs b/token-core/tcx-substrate/src/address.rs index ea608984..0f12c3d4 100644 --- a/token-core/tcx-substrate/src/address.rs +++ b/token-core/tcx-substrate/src/address.rs @@ -2,8 +2,8 @@ use sp_core::crypto::Ss58AddressFormat; use sp_core::crypto::Ss58Codec; use sp_core::sr25519::Public; use std::str::FromStr; -use tcx_chain::Address; use tcx_constants::{CoinInfo, Result}; +use tcx_keystore::Address; use tcx_primitive::{PublicKey, Sr25519PublicKey, TypedPublicKey}; #[derive(PartialEq, Eq, Clone)] diff --git a/token-core/tcx-substrate/src/keystore.rs b/token-core/tcx-substrate/src/keystore.rs index 92001f5f..a891a44f 100644 --- a/token-core/tcx-substrate/src/keystore.rs +++ b/token-core/tcx-substrate/src/keystore.rs @@ -2,7 +2,7 @@ use crate::SubstrateAddress; use rand::Rng; use serde::{de, Deserialize, Deserializer, Serialize}; use std::convert::TryInto; -use tcx_chain::Address; +use tcx_keystore::Address; use byteorder::LittleEndian; use byteorder::{ReadBytesExt, WriteBytesExt}; diff --git a/token-core/tcx-substrate/src/lib.rs b/token-core/tcx-substrate/src/lib.rs index 9d4db028..1ca81d46 100644 --- a/token-core/tcx-substrate/src/lib.rs +++ b/token-core/tcx-substrate/src/lib.rs @@ -17,8 +17,8 @@ extern crate failure; extern crate serde_json; pub mod polkadot { - use tcx_chain::{Account, Keystore}; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::{Account, Keystore}; pub const CHAINS: [&'static str; 2] = ["POLKADOT", "KUSAMA"]; diff --git a/token-core/tcx-substrate/src/signer.rs b/token-core/tcx-substrate/src/signer.rs index 20350689..38e57bab 100644 --- a/token-core/tcx-substrate/src/signer.rs +++ b/token-core/tcx-substrate/src/signer.rs @@ -2,8 +2,8 @@ use crate::transaction::{SubstrateRawTxIn, SubstrateTxOut}; use crate::{PAYLOAD_HASH_THRESHOLD, SIGNATURE_TYPE_SR25519}; use sp_core::blake2_256; -use tcx_chain::{ChainSigner, Keystore, TransactionSigner as TraitTransactionSigner}; use tcx_constants::Result; +use tcx_keystore::{ChainSigner, Keystore, TransactionSigner as TraitTransactionSigner}; pub(crate) fn hash_unsigned_payload(payload: &[u8]) -> Result> { if payload.len() > PAYLOAD_HASH_THRESHOLD { diff --git a/token-core/tcx-tezos/Cargo.toml b/token-core/tcx-tezos/Cargo.toml index 23f395a3..1bc8fbe4 100644 --- a/token-core/tcx-tezos/Cargo.toml +++ b/token-core/tcx-tezos/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tcx-chain = { path = "../tcx-chain" } +tcx-keystore = { path = "../tcx-keystore" } tcx-constants = { path = "../tcx-constants" } tcx-primitive = { path = "../tcx-primitive" } tcx-crypto = { path = "../tcx-crypto" } diff --git a/token-core/tcx-tezos/src/address.rs b/token-core/tcx-tezos/src/address.rs index 504e80e8..8698c885 100644 --- a/token-core/tcx-tezos/src/address.rs +++ b/token-core/tcx-tezos/src/address.rs @@ -1,9 +1,9 @@ use bitcoin::util::base58; use blake2b_simd::Params; use std::str::FromStr; -use tcx_chain::Address; -use tcx_chain::Result; use tcx_constants::CoinInfo; +use tcx_keystore::Address; +use tcx_keystore::Result; use tcx_primitive::TypedPublicKey; #[derive(PartialEq, Eq, Clone)] @@ -70,8 +70,8 @@ pub fn sha256_hash(data: &[u8]) -> Vec { #[cfg(test)] mod test { use crate::address::TezosAddress; - use tcx_chain::Address; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::Address; use tcx_primitive::TypedPublicKey; #[test] diff --git a/token-core/tcx-tezos/src/lib.rs b/token-core/tcx-tezos/src/lib.rs index 39405cf0..15e87a91 100644 --- a/token-core/tcx-tezos/src/lib.rs +++ b/token-core/tcx-tezos/src/lib.rs @@ -2,7 +2,7 @@ pub mod address; pub mod signer; pub mod transaction; use bitcoin::util::base58; -use tcx_chain::Result; +use tcx_keystore::Result; use tcx_primitive::{Ed25519PrivateKey, PrivateKey, PublicKey}; pub fn build_tezos_base58_private_key(sk: &str) -> Result { @@ -27,8 +27,8 @@ pub fn pars_tezos_private_key(private_key: &str) -> Result> { } pub mod tezos { - use tcx_chain::{Account, Keystore}; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::{Account, Keystore}; pub const CHAINS: [&'static str; 1] = ["TEZOS"]; diff --git a/token-core/tcx-tezos/src/signer.rs b/token-core/tcx-tezos/src/signer.rs index d442b117..75441d73 100644 --- a/token-core/tcx-tezos/src/signer.rs +++ b/token-core/tcx-tezos/src/signer.rs @@ -1,8 +1,8 @@ use crate::transaction::{TezosRawTxIn, TezosTxOut}; use bitcoin::util::base58; use blake2b_simd::Params; -use tcx_chain::{ChainSigner, Keystore, TransactionSigner as TraitTransactionSigner}; use tcx_constants::Result; +use tcx_keystore::{ChainSigner, Keystore, TransactionSigner as TraitTransactionSigner}; impl TraitTransactionSigner for Keystore { fn sign_transaction( diff --git a/token-core/tcx-tron/Cargo.toml b/token-core/tcx-tron/Cargo.toml index badb352a..9b871e48 100644 --- a/token-core/tcx-tron/Cargo.toml +++ b/token-core/tcx-tron/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] tcx-crypto = { path = "../tcx-crypto" } -tcx-chain = { path = "../tcx-chain" } +tcx-keystore = { path = "../tcx-keystore" } tcx-primitive = { path = "../tcx-primitive" } tcx-constants = { path = "../tcx-constants" } tcx-common = { path = "../tcx-common" } diff --git a/token-core/tcx-tron/src/address.rs b/token-core/tcx-tron/src/address.rs index 9470a37c..aba97d3a 100644 --- a/token-core/tcx-tron/src/address.rs +++ b/token-core/tcx-tron/src/address.rs @@ -3,9 +3,9 @@ use core::str::FromStr; use tcx_common::keccak256; -use tcx_chain::Address; -use tcx_chain::Result; use tcx_constants::CoinInfo; +use tcx_keystore::Address; +use tcx_keystore::Result; use tcx_primitive::TypedPublicKey; #[derive(PartialEq, Eq, Clone)] @@ -49,9 +49,9 @@ impl ToString for TronAddress { mod tests { use super::Address; use crate::TronAddress; - use tcx_chain::Address as TraitAddress; use tcx_constants::coin_info::coin_info_from_param; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::Address as TraitAddress; use tcx_primitive::TypedPublicKey; #[test] diff --git a/token-core/tcx-tron/src/lib.rs b/token-core/tcx-tron/src/lib.rs index 6fe715c5..ae32766c 100644 --- a/token-core/tcx-tron/src/lib.rs +++ b/token-core/tcx-tron/src/lib.rs @@ -5,8 +5,8 @@ pub mod transaction; pub use crate::address::TronAddress; pub mod tron { - use tcx_chain::{Account, Keystore}; use tcx_constants::{CoinInfo, CurveType}; + use tcx_keystore::{Account, Keystore}; pub const CHAINS: [&'static str; 1] = ["TRON"]; diff --git a/token-core/tcx-tron/src/signer.rs b/token-core/tcx-tron/src/signer.rs index 7a467f13..285ab832 100644 --- a/token-core/tcx-tron/src/signer.rs +++ b/token-core/tcx-tron/src/signer.rs @@ -1,5 +1,5 @@ use crate::transaction::{TronMessageInput, TronMessageOutput, TronTxInput, TronTxOutput}; -use tcx_chain::{ +use tcx_keystore::{ ChainSigner, Keystore, MessageSigner as TraitMessageSigner, Result, TransactionSigner as TraitTransactionSigner, }; @@ -90,9 +90,9 @@ mod tests { use super::*; use crate::address::TronAddress; - use tcx_chain::{HdKeystore, Keystore, KeystoreGuard, Metadata}; use tcx_constants::{CoinInfo, TEST_PASSWORD}; use tcx_constants::{CurveType, TEST_MNEMONIC}; + use tcx_keystore::{HdKeystore, Keystore, KeystoreGuard, Metadata}; use tcx_primitive::{PrivateKey, Secp256k1PrivateKey}; #[test] diff --git a/token-core/tcx/Cargo.toml b/token-core/tcx/Cargo.toml index 4bfc8b3b..b3d1c8f1 100644 --- a/token-core/tcx/Cargo.toml +++ b/token-core/tcx/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] tcx-proto = { path = "../tcx-proto" } tcx-crypto = { path = "../tcx-crypto", features = ["cache_dk"] } -tcx-chain = { path = "../tcx-chain", features = ["cache_dk"] } +tcx-keystore = { path = "../tcx-keystore", features = ["cache_dk"] } tcx-btc-kin = { path = "../tcx-btc-kin" } tcx-tron = { path = "../tcx-tron" } tcx-ckb = { path = "../tcx-ckb" } diff --git a/token-core/tcx/src/filemanager.rs b/token-core/tcx/src/filemanager.rs index 31ca3e97..8dfa7615 100644 --- a/token-core/tcx/src/filemanager.rs +++ b/token-core/tcx/src/filemanager.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use std::fs; use std::io::Write; use std::path::Path; -use tcx_chain::Keystore; +use tcx_keystore::Keystore; use crate::error_handling::Result; diff --git a/token-core/tcx/src/handler.rs b/token-core/tcx/src/handler.rs index b2b41696..850da801 100644 --- a/token-core/tcx/src/handler.rs +++ b/token-core/tcx/src/handler.rs @@ -10,10 +10,10 @@ use tcx_eos::EosChainFactory; use tcx_primitive::{get_account_path, private_key_without_version, FromHex, TypedPrivateKey}; use tcx_btc_kin::WIFDisplay; -use tcx_chain::{ +use tcx_keystore::{ key_hash_from_mnemonic, key_hash_from_private_key, ChainFactory, Keystore, KeystoreGuard, }; -use tcx_chain::{Account, HdKeystore, Metadata, PrivateKeystore, Source}; +use tcx_keystore::{Account, HdKeystore, Metadata, PrivateKeystore, Source}; use tcx_crypto::{XPUB_COMMON_IV, XPUB_COMMON_KEY_128}; use tcx_filecoin::KeyInfo; @@ -45,9 +45,8 @@ use crate::filemanager::{delete_keystore_file, KEYSTORE_MAP}; use crate::IS_DEBUG; use base58::ToBase58; -use tcx_chain::tcx_ensure; +use tcx_keystore::tcx_ensure; -use tcx_chain::{MessageSigner, TransactionSigner}; use tcx_constants::coin_info::coin_info_from_param; use tcx_constants::{CoinInfo, CurveType}; use tcx_crypto::aes::cbc::encrypt_pkcs7; @@ -55,6 +54,7 @@ use tcx_crypto::hash::dsha256; use tcx_crypto::KDF_ROUNDS; use tcx_eos::transaction::EosMessageInput; use tcx_eth::transaction::{EthRecoverAddressInput, EthRecoverAddressOutput}; +use tcx_keystore::{MessageSigner, TransactionSigner}; use tcx_eth2::transaction::{SignBlsToExecutionChangeParam, SignBlsToExecutionChangeResult}; use tcx_primitive::{Bip32DeterministicPublicKey, Ss58Codec}; @@ -63,7 +63,7 @@ use tcx_substrate::{ SubstrateKeystore, SubstrateKeystoreParam, SubstrateRawTxIn, }; -use tcx_chain::identity::Identity; +use tcx_keystore::identity::Identity; // use tcx_identity::imt_keystore::{IMTKeystore, WALLET_KEYSTORE_DIR}; // use tcx_identity::v3_keystore::import_wallet_from_keystore; // use tcx_identity::wallet_api::{ diff --git a/token-core/tcx/src/lib.rs b/token-core/tcx/src/lib.rs index be7ec002..2613264c 100644 --- a/token-core/tcx/src/lib.rs +++ b/token-core/tcx/src/lib.rs @@ -235,9 +235,9 @@ mod tests { use crate::handler::hd_store_import; use crate::handler::{encode_message, private_key_store_import}; use prost::Message; - use tcx_chain::{Keystore, Source}; use tcx_constants::sample_key; use tcx_constants::{TEST_MNEMONIC, TEST_PASSWORD}; + use tcx_keystore::{Keystore, Source}; // use tcx_identity::{constants, model}; use std::fs; diff --git a/token-core/tcx/src/macros.rs b/token-core/tcx/src/macros.rs index 28e1b9cc..4ddde7ae 100644 --- a/token-core/tcx/src/macros.rs +++ b/token-core/tcx/src/macros.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use tcx_chain::{Address, Keystore, MessageSigner, TransactionSigner}; use tcx_constants::CoinInfo; +use tcx_keystore::{Address, Keystore, MessageSigner, TransactionSigner}; use tcx_primitive::TypedPublicKey; #[allow(clippy::derive_partial_eq_without_eq)] @@ -36,7 +36,7 @@ impl MessageSigner for Keystore { symbol: &str, address: &str, message: &MockMessageInput, - ) -> tcx_chain::Result { + ) -> tcx_keystore::Result { Err(format_err!("unsupported_chain")) } } @@ -45,7 +45,10 @@ impl MessageSigner for Keystore { pub struct MockAddress(); impl Address for MockAddress { - fn from_public_key(_public_key: &TypedPublicKey, _coin: &CoinInfo) -> tcx_chain::Result { + fn from_public_key( + _public_key: &TypedPublicKey, + _coin: &CoinInfo, + ) -> tcx_keystore::Result { Err(format_err!("unsupported_chain")) }