Skip to content

Commit

Permalink
fix: fix add eth error after upgrade (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoguang1010 committed Mar 27, 2024
1 parent cd3a2de commit 2a7bd76
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
29 changes: 25 additions & 4 deletions imkey-core/ikc/src/handler.rs
Expand Up @@ -203,11 +203,32 @@ pub(crate) fn get_extended_public_keys(data: &[u8]) -> Result<Vec<u8>> {
let mut extended_public_keys = vec![];
for public_key_derivation in param.derivations.iter() {
// if "".eq(&public_key_derivation.path) || &public_key_derivation.path.split("/") { }
let extended_public_key = match public_key_derivation.curve.as_str() {
"secp256k1" => {
if !public_key_derivation.curve.eq("secp256k1") {
return Err(anyhow!("unsupported_curve_type"));
}
let extended_public_key = match public_key_derivation.chain_type.as_str() {
"BITCOIN" | "LITCOIN" | "BITCOINCASH" => {
BtcAddress::get_xpub(Network::Bitcoin, public_key_derivation.path.as_str())?
}
_ => return Err(anyhow!("unsupported_curve_type")),
},
"ETHEREUM" => {
EthAddress::get_xpub(public_key_derivation.path.as_str())?
},
"COSMOS" => {
CosmosAddress::get_xpub(public_key_derivation.path.as_str())?
},
"FILECOIN" => {
FilecoinAddress::get_xpub("MAINNET", public_key_derivation.path.as_str())?
},
"TRON" => {
TronAddress::get_xpub(public_key_derivation.path.as_str())?
},
"EOS" => {
EosPubkey::get_xpub(public_key_derivation.path.as_str())?
},
"NERVOS" => {
CkbAddress::get_xpub("MAINNET", public_key_derivation.path.as_str())?
},
_ => return Err(anyhow!("unsupported_chain_type")),
};
extended_public_keys.push(extended_public_key);
}
Expand Down
43 changes: 43 additions & 0 deletions imkey-core/ikc/src/lib.rs
Expand Up @@ -1419,6 +1419,36 @@ mod tests {
path: "m/44'/145'/0'".to_string(),
curve: "secp256k1".to_string(),
},
PublicKeyDerivation {
chain_type: "ETHEREUM".to_string(),
path: "m/44'/60'/0'".to_string(),
curve: "secp256k1".to_string(),
},
PublicKeyDerivation {
chain_type: "COSMOS".to_string(),
path: "m/44'/118'/0'".to_string(),
curve: "secp256k1".to_string(),
},
PublicKeyDerivation {
chain_type: "FILECOIN".to_string(),
path: "m/44'/461'/0'".to_string(),
curve: "secp256k1".to_string(),
},
PublicKeyDerivation {
chain_type: "TRON".to_string(),
path: "m/44'/195'/0'".to_string(),
curve: "secp256k1".to_string(),
},
PublicKeyDerivation {
chain_type: "EOS".to_string(),
path: "m/44'/194'/0'".to_string(),
curve: "secp256k1".to_string(),
},
PublicKeyDerivation {
chain_type: "NERVOS".to_string(),
path: "m/44'/309'/0'".to_string(),
curve: "secp256k1".to_string(),
},
];
let param = GetExtendedPublicKeysParam { derivations };
let action: ImkeyAction = ImkeyAction {
Expand All @@ -1437,6 +1467,12 @@ mod tests {
assert_eq!(extended_public_key.extended_public_keys[1], "xpub6FmdMKZ36pLzf1iF7DLCzKtZms33cZ6mVjvBSy2dCPugFCH23cS3jgHfQ9PKmxs989ZyiyALuADMtLokCzpw7Fi35ap4uybfQAY5WVakan7");
assert_eq!(extended_public_key.extended_public_keys[2], "xpub6AQmexrYd5utZNmD9Gnf4CjrzJ4kuvaxacLyuSD5sA34g4oKuzBpX5rhAZrCZoxkcqWLVyWSz1rEh5ECs4PDRN16PLfNKFftxm48y6zsWX3");
assert_eq!(extended_public_key.extended_public_keys[3], "xpub6Bmkv3mmRZZWoFSBdj9vDMqR2PCPSP6DEj8u3bBuv44g3Ncnro6cPVqZAw6wTEcxHQuodkuJG4EmAinqrrRXGsN3HHnRRMtAvzfYTiBATV1");
assert_eq!(extended_public_key.extended_public_keys[4], "xpub6CZG7sArTpFs5n47cUxtbcVXuq4QfUTykGWL8t8RJdPXvnSnF2VrDwgqjuS7JvJ7DK8B4pnbMxCNtPsbHdPjuFBCcBo81cfMRWcPUXWND3e");
assert_eq!(extended_public_key.extended_public_keys[5], "xpub6CrWRZY39gj49G1ipdmcVunEnb5RoTGf9o6QnJQp8c4b84V2piN1Rdy1xWVJ4P7VXNx5Ckg6rZcvSNvJtvWz8zs3RkPayHn9vMMuK9ERrFr");
assert_eq!(extended_public_key.extended_public_keys[6], "xpub6DCc3LkXWVzLHfCFSvmxmXytMfVnxeQQ3LDiLmHwTojg3p3U6qFmNLqzPijosTwRqeC4j2TqJamUjM44GBVRcdPukxEN94Rac8WndUhfYEK");
assert_eq!(extended_public_key.extended_public_keys[7], "xpub6CaaaWKi9NRFAnRyDFZxWKWs7Sh8d9WiaCspHVpkDcaVwqQFRH2z5ygLbHZs8yWtwyR3QhJLDJzbrdSTZRC9PWaRfAMNCruoSJnWhKFFCWV");
assert_eq!(extended_public_key.extended_public_keys[8], "xpub6CUtvjXi3yjmhjaC2GxjiWE9FbQs1TrtqAgRDhB2gmDBsPzTfwqZ7MvGGYScKiVx8PBNFSmHm4mCnFDCaX23c1nJS4p8ynR2wnGne4qEEX9");
assert_eq!(extended_public_key.extended_public_keys[9], "xpub6CyvXfYwHJjJ9syYjG7qZMva1yMx93SUmqUcKHvoReUadCzqJA8mMXrrXQjRvzveuahgdQmCsdsuiCkMRsLec63DW83Wwu5UqKJQmsonKpo");
}

#[test]
Expand Down Expand Up @@ -1716,4 +1752,11 @@ mod tests {
assert_eq!("success", bind_result.bind_status);
}
}

#[test]
fn test1(){
let req_hex = "1218696d6b65795f636f6d6d616e645f646174615f6572726f72";
let res = ErrorResponse::decode(hex::decode(req_hex).unwrap().as_slice()).unwrap();
println!("{:?}",res);
}
}

0 comments on commit 2a7bd76

Please sign in to comment.