Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: token-core support Ton chain[R2D2-13379] #139

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build-release-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ jobs:

- name: Install Rust
run: |
rustup toolchain install nightly-2022-10-31
rustup default nightly-2022-10-31-x86_64-apple-darwin
rustup toolchain install nightly-2023-06-15
rustup default nightly-2023-06-15-x86_64-apple-darwin
rustup target add aarch64-apple-ios x86_64-apple-ios
rustup show
cargo install cargo-lipo
cargo install cbindgen
cargo install cbindgen --version 0.26.0
brew install protobuf

- name: Read VERSION file
Expand Down
62 changes: 62 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ members = [
"token-core/tcx-tester",
"token-core/tcx-eth2",
"token-core/tcx-eth",
"token-core/tcx-ton",
"token-core/tcx-common",
"token-core/tcx-migration",
"token-core/tcx-libs/ed25519-dalek-bip32",
"token-core/tcx-libs/tonlib-core",
"imkey-core/ikc",
"imkey-core/ikc-common",
"imkey-core/ikc-device",
Expand Down
6 changes: 6 additions & 0 deletions token-core/tcx-atom/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "".to_string(),
contract_code: "".to_string(),
}
}

Expand Down Expand Up @@ -166,6 +167,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
contract_code: "".to_string(),
};
let address = AtomAddress::from_public_key(&pub_key, &coin_info)
.unwrap()
Expand Down Expand Up @@ -214,6 +216,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
contract_code: "".to_string(),
};

let address = AtomAddress::from_public_key(&pub_key, &coin_info)
Expand All @@ -237,6 +240,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
contract_code: "".to_string(),
};
let address = AtomAddress::from_public_key(&pub_key, &coin_info);

Expand All @@ -252,6 +256,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
contract_code: "".to_string(),
};

let address = AtomAddress::from_public_key(&pub_key, &coin_info);
Expand All @@ -264,6 +269,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
contract_code: "".to_string(),
};

let address = AtomAddress::from_public_key(&pub_key, &coin_info);
Expand Down
10 changes: 8 additions & 2 deletions token-core/tcx-atom/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use tcx_keystore::{
Keystore, Result, SignatureParameters, Signer, TransactionSigner as TraitTransactionSigner,
};

use tcx_common::{sha256, FromHex};

use anyhow::anyhow;
use base64;
use tcx_common::{sha256, FromHex};

const SIG_LEN: usize = 64;

Expand All @@ -15,6 +15,11 @@ impl TraitTransactionSigner<AtomTxInput, AtomTxOutput> for Keystore {
params: &SignatureParameters,
tx: &AtomTxInput,
) -> Result<AtomTxOutput> {
let path_parts = params.derivation_path.split('/').collect::<Vec<_>>();
if path_parts.len() < 4 || path_parts[2] != "118'" {
return Err(anyhow!("invalid_sign_path"));
}

let data = Vec::from_hex_auto(&tx.raw_data)?;
let hash = sha256(&data);

Expand Down Expand Up @@ -51,6 +56,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "".to_string(),
seg_wit: "".to_string(),
contract_code: "".to_string(),
};
let mut guard = KeystoreGuard::unlock_by_password(&mut keystore, TEST_PASSWORD).unwrap();

Expand Down
8 changes: 7 additions & 1 deletion token-core/tcx-btc-kin/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn bech32_network(bech32: &str) -> Option<&BtcKinNetwork> {

if bech32_prefix.is_some() {
let prefix = bech32_prefix.unwrap();
if (!prefix.is_empty()) {
if !prefix.is_empty() {
return BtcKinNetwork::find_by_hrp(prefix);
}
}
Expand Down Expand Up @@ -361,6 +361,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
contract_code: "".to_string(),
};
let ltc_xprv_str = BtcKinAddress::extended_private_key(&anprv, &coin_info).unwrap();
assert_eq!("xprv9yrdwPSRnvomqFK4u1y5uW2SaXS2Vnr3pAYTjJjbyRZR8p9BwoadRsCxtgUFdAKeRPbwvGRcCSYMV69nNK4N2kadevJ6L5iQVy1SwGKDTHQ", ltc_xprv_str);
Expand All @@ -381,6 +382,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
contract_code: "".to_string(),
};
let ltc_xprv_str = BtcKinAddress::extended_public_key(&anpub, &coin_info).unwrap();
assert_eq!("xpub6JeaAjhtvtjCDnEo4Bjr7uEbGccaHnJtLY4aBnMaAYGjkBRB3fP9XvjcCbNjMiU1n5tt7dYKVgHPGzh3t3W6eLBxavxABTaoQ2jhbiQrfe4", ltc_xprv_str);
Expand Down Expand Up @@ -473,6 +475,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
contract_code: "".to_string(),
};
let address = BtcKinAddress::from_public_key(&pub_key, &coin_info)
.unwrap()
Expand Down Expand Up @@ -510,6 +513,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
contract_code: "".to_string(),
})
.unwrap();
assert_eq!(account.address, "DQ4tVEqdPWHc1aVBm4Sfwft8XyNRPMEchR");
Expand Down Expand Up @@ -541,6 +545,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: network.to_string(),
seg_wit: "NONE".to_string(),
contract_code: "".to_string(),
};
let account = hd.derive_coin::<BtcKinAddress>(&coin_info).unwrap();
assert_eq!(account.ext_pub_key, xpub);
Expand All @@ -562,6 +567,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "VERSION_0".to_string(),
contract_code: "".to_string(),
};
let address = BtcKinAddress::from_public_key(&pub_key, &coin_info)
.unwrap()
Expand Down
2 changes: 2 additions & 0 deletions token-core/tcx-btc-kin/src/bch_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "".to_string(),
seg_wit: "".to_string(),
contract_code: "".to_string(),
};
let ret = BchAddress::from_public_key(&pk, &wrong_coin_info);
assert_eq!(format!("{}", ret.err().unwrap()), "missing_network");
Expand Down Expand Up @@ -289,6 +290,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
contract_code: "".to_string(),
};
let address = BchAddress::from_public_key(&pub_key, &coin_info)
.unwrap()
Expand Down
6 changes: 6 additions & 0 deletions token-core/tcx-btc-kin/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl MessageSigner<BtcMessageInput, BtcMessageOutput> for Keystore {
curve: CurveType::SECP256k1,
network: params.network.to_string(),
seg_wit: params.seg_wit.to_string(),
contract_code: "".to_string(),
};

let address = BtcKinAddress::from_public_key(&public_key, &coin_info)?;
Expand Down Expand Up @@ -159,6 +160,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "VERSION_0".to_string(),
contract_code: "".to_string(),
};

let account = ks.derive_coin::<BtcKinAddress>(&coin_info).unwrap();
Expand All @@ -183,6 +185,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "P2WPKH".to_string(),
contract_code: "".to_string(),
};

let account = ks.derive_coin::<BtcKinAddress>(&coin_info).unwrap();
Expand Down Expand Up @@ -219,6 +222,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
contract_code: "".to_string(),
};

let account = ks.derive_coin::<BtcKinAddress>(&coin_info).unwrap();
Expand Down Expand Up @@ -256,6 +260,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "VERSION_0".to_string(),
contract_code: "".to_string(),
};

let account = ks.derive_coin::<BtcKinAddress>(&coin_info).unwrap();
Expand Down Expand Up @@ -292,6 +297,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "MAINNET".to_string(),
seg_wit: "VERSION_1".to_string(),
contract_code: "".to_string(),
};

let account = ks.derive_coin::<BtcKinAddress>(&coin_info).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions token-core/tcx-btc-kin/src/psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "TESTNET".to_string(),
seg_wit: "VERSION_1".to_string(),
contract_code: "".to_string(),
};

let account = hd.derive_coin::<BtcKinAddress>(&coin_info).unwrap();
Expand Down Expand Up @@ -486,6 +487,7 @@ mod tests {
curve: CurveType::SECP256k1,
network: "TESTNET".to_string(),
seg_wit: "VERSION_1".to_string(),
contract_code: "".to_string(),
};

let account = hd.derive_coin::<BtcKinAddress>(&coin_info).unwrap();
Expand Down
1 change: 1 addition & 0 deletions token-core/tcx-btc-kin/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ impl<T: Address + ScriptPubkey + FromStr<Err = anyhow::Error>> KinTransaction<T>
curve: params.curve,
network: params.network.clone(),
seg_wit: params.seg_wit.clone(),
contract_code: "".to_string(),
};

let change_script = if let Some(change_address_index) = self.change_address_index && keystore.derivable() {
Expand Down
Loading
Loading