Skip to content

Commit

Permalink
feat: add bitcoincash derive
Browse files Browse the repository at this point in the history
  • Loading branch information
XuNeal committed Dec 13, 2023
1 parent 9832d03 commit 259bca3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
5 changes: 3 additions & 2 deletions token-core/tcx/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ use crate::macros::use_chains;
use_chains!(
tcx_btc_kin::bitcoin,
tcx_btc_kin::omni,
tcx_btc_kin::bitcoincash,
tcx_filecoin::filecoin,
tcx_eos::eos,
tcx_ckb::nervos,
Expand Down Expand Up @@ -309,10 +310,10 @@ pub(crate) fn derive_accounts(data: &[u8]) -> Result<Vec<u8>> {
chain_type: derivation.chain_type.to_owned(),
address: account.address.to_owned(),
path: account.derivation_path.to_owned(),
curve: account.curve.as_str().to_string(),
public_key: account.public_key,
extended_public_key: account.ext_pub_key.to_string(),
encrypted_extended_public_key: enc_xpub,
public_key: account.public_key,
curve: account.curve.as_str().to_string(),
};
account_responses.push(account_rsp);
}
Expand Down
35 changes: 28 additions & 7 deletions token-core/tcx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ mod tests {
network: "MAINNET".to_string(),
seg_wit: "NONE".to_string(),
chain_id: "".to_string(),
curve: "".to_string(),
curve: "SECP256k1".to_string(),
bech32_prefix: "".to_string(),
};
let param = DeriveAccountsParam {
Expand All @@ -451,11 +451,20 @@ mod tests {
let ret = call_api("derive_accounts", param).unwrap();
let result: DeriveAccountsResult =
DeriveAccountsResult::decode(ret.as_slice()).unwrap();
assert_eq!(result.accounts.first().unwrap().chain_type, "BITCOINCASH");
let account = result.accounts.first().unwrap();
assert_eq!(account.chain_type, "BITCOINCASH");
assert_eq!(
result.accounts.first().unwrap().address,
account.address,
"qzld7dav7d2sfjdl6x9snkvf6raj8lfxjcj5fa8y2r"
);
assert_eq!(
account.extended_public_key,
"031064f6a580000000251d72997d4cf931a7e6819f7da37725166100fc7dae9ca6afc3f8fd8a3d3a7f0303f2f84851514bf2f40a46b5bb9dbf4e5913fbacde1a96968cda08f9fd882caa"
);
assert_eq!(
account.encrypted_extended_public_key,
"wAKUeR6fOGFL+vi50V+MdVSH58gLy8Jx7zSxywz0tN++l2E0UNG7zv+R1FVgnrqU6d0wl699Q/I7O618UxS7gnpFxkGuK0sID4fi7pGf9aivFxuKy/7AJJ6kOmXH1Rz6FCS6b8W7NKlzgbcZpJmDsQ=="
);
remove_created_wallet(&import_result.id);
})
}
Expand Down Expand Up @@ -2209,11 +2218,11 @@ mod tests {
run_test(|| {
let derivation = Derivation {
chain_type: "KUSAMA".to_string(),
path: "".to_string(),
network: "".to_string(),
path: "//kusama//imToken/0".to_string(),
network: "MAINNET".to_string(),
seg_wit: "".to_string(),
chain_id: "".to_string(),
curve: "".to_string(),
curve: "SubSr25519".to_string(),
bech32_prefix: "".to_string(),
};
let (wallet, acc_rsp) = import_and_derive(derivation);
Expand Down Expand Up @@ -3307,7 +3316,11 @@ mod tests {
bech32_prefix: "".to_string(),
};

let (wallet, _acc_rsp) = import_and_derive(derivation);
let (wallet, acc_rsp) = import_and_derive(derivation);

let acc = acc_rsp.accounts.first().unwrap();
assert_eq!("037b21e17e80000000f95a76bfa0d8c2e7ed0e93d8ea6022c34ae9a5813a3b794ce270f3296aab1a0c03f3175613d999d15e6fde436825a3cc2c568f8f5082275f06eb4bd6e561f503ac", acc.extended_public_key);
assert_eq!("w6s0ZvUoPPSiEi1xDMKy5X9+qwhcX4u3e3LOBosJaOSro2ny9jppDxcczZfrhe29n9H3UkmgNoecq/85xfXkGDtH8PMR9iclK5WrcUtkgjXsBcrR6JF0j58i4W9x3y539vXOsLMifCmUr2RcqknDgw==", acc.encrypted_extended_public_key);

//legacy transaction
let eth_tx_input = EthTxInput {
Expand Down Expand Up @@ -3755,4 +3768,12 @@ mod tests {
// fn test_sign_authentication_message() {
// todo!()
// }

#[test]
fn test_decode_derive_account() {
let data = Vec::<u8>::from_hex("0ab2020a08455448455245554d122a3078456332373437326434314142616464373331373932343737333345423039323761443635316338361a106d2f3434272f3630272f30272f302f302298014c795a4867657356664178796e4e425a6f5463313645536551376d463772685a334b75385152364f6f67584c614e3845387559484139574442335632533977376c333665424a4f38766470636c644e45524264634d482f544c7a6a4e7a32446b314878337939734b6c77527a41464c563931357445714f716641586e796351555770304276556a6e415a54486a764a45354954546b413d3d2a423033313564636233386135383937343832373538616266303564616335616531303465626231326234383131666134343639646433306361653736653133373339303209534543503235366b310aa4020a07424954434f494e1222334e664e354a386933706e6d44526951593550556368764441386e3566364a68556f1a0b6d2f3439272f30272f3027229801336b5a6d5a763378636756615346562b734c675050524a55344f6a6a76306c4630314e4571644e48565655687874427062485378496b4356566d53332f6e726a3743696c4b58505145657063615332575a795772722b53694b4d425859486f3658545772664978314e4f6b4569323935324e4e41736b7470796c496e71494573592f4151313761524d3350686f6f55594d7a6c4c46413d3d2a423032636561386631663766313566396534383739393338623137396636616631343961373664333334663934346137646164636136333464323865343966343964363209534543503235366b310aa9020a084c495445434f494e12224c56337570376a3877637968423347766575524e4b7157464a387864764464474c481a0f6d2f3439272f32272f30272f302f3022980144557873735951594833615878654c735266626b474479676f6972537254496e7a447133614b7178714b4b6f3269427048796e596757474a58776c5968774345334d712f696d2b4e314537504f592f52533375366779694a45614a43364533716a4c32766435396769632f2f3430305a76323675422b3657394c764954767071513357304662506a38656c4d395632655638323870773d3d2a423032653066616466396439386339656263373337643633343565353136376163303439393333396635333233343161393365643461653436613937643861306662373209534543503235366b310ab4020a06434f534d4f53122d636f736d6f7331793039396b75636570636b656a39687539337063706c387635346867303432396775307037641a116d2f3434272f313138272f30272f302f30229801334d45484d6a3263497078664833662b7a52314f6d6b45743169496453704e324670435734634d693230354a4c4f7463386e554c3241365146574e47797465624b45713765796432686754424c4b4d2f3344454d366d3672534b536f67534f3056616d4c6677442b70304375302b304452775335444f7a6c50673874364d733575372b4556763877707a6d75357a627a53326a4854513d3d2a423032333239626232346366373834633765363066376637663236393931383661656430663138656139303932306364613130363039386464303338393765303038383209534543503235366b310ab2020a0846494c45434f494e122966317a7369723576677977636b6e61716a6a653377336179666d327a72797671636c6362376f7436611a116d2f3434272f343631272f30272f302f302298012b78664f452f66342f42347070366f2b62553952433631684863383662664b732f456e78653254337569646136637432396a4738317443427150365a37564845476c33505266713479675152695137624d2f4b4d63505471334739324c67577a796a676a356e742b4e62536a55637a6b4253375879456a6345336e6637425731434c2f574662544f734f516b714e37574546667033513d3d2a423033643434633732356261663934356632356630613961633131396433313064343336333437343936353030623461336133326563633236343339366631336362653209534543503235366b310ab5020a064e4552564f53122e636b62317179717878793577796d616d68736a3076636b6a6c716b6377326e7470346c75366476716d687a6c61661a116d2f3434272f333039272f30272f302f30229801744e38717a484e484e454b5a2f674d443833526b783472304c687777723478636a6e4f646e6b526e395261695569387450336b5a6145366234595a544f4c563074647641444a715378356165675149412f6a527a526e4169774e544963576f50764d6733436e4c2f4b4c61536d374842716662665241673951567936744364306349653969614e6751737a774148536c6d4c366632413d3d2a423032333163663165666661316166396137346334613266306333376166323831643735623464383533636231626331373931353865336564336632643038666638333209534543503235366b310a9c010a064b5553414d41122f485046716e39526b4b42686f41575743765950416a5a51525935624264575775525234584338513657656f6265527a1a132f2f6b7573616d612f2f696d546f6b656e2f302a4064346264313765616138373638666662373437386433326439363039336239366634663663386338323639656437373836666661636436396431623531313234320a537562537232353531390aa1010a08504f4c4b41444f54123031346144413137543570476248366a735157714348395477664d5a41706a5a366e656874654d445843347536653779431a152f2f706f6c6b61646f742f2f696d546f6b656e2f302a4039653038623737653565306539326330643231383966653736326137663061663132386236623438396462316465326432386431333030663163323638303736320a537562537232353531390a8b010a0554455a4f531224747a3159714a584b686f43354e6e78393431794a41456a77464e786252564a7361626d451a116d2f3434272f31373239272f30272f30272a4065613835376561343365316435333164343664336234336438356538383233666165336230373533636639363539383563316164643666316534656365323733320745443235353139").unwrap();
let rsp: DeriveAccountsResult = DeriveAccountsResult::decode(data.as_slice()).unwrap();
dbg!(&rsp);
assert_eq!("ex", rsp.accounts.first().unwrap().extended_public_key);
}
}

0 comments on commit 259bca3

Please sign in to comment.