Skip to content

Commit

Permalink
feat: retur all k1 chain_types (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuNeal authored Feb 23, 2024
1 parent 443e38a commit 28121c5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
23 changes: 22 additions & 1 deletion token-core/tcx/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ fn decode_private_key(private_key: &str) -> Result<DecodedPrivateKey> {
if let Ok(decoded_data) = decoded {
if decoded_data.len() == 32 {
private_key_bytes = decoded_data;
chain_types = vec![
"BITCOIN".to_string(),
"ETHEREUM".to_string(),
"BITCOINCASH".to_string(),
"LITECOIN".to_string(),
"EOS".to_string(),
"TRON".to_string(),
"FILECOIN".to_string(),
];
curve = CurveType::SECP256k1;
} else if decoded_data.len() == 64 {
let sr25519_key = Sr25519PrivateKey::from_slice(&decoded_data)?;
private_key_bytes = sr25519_key.to_bytes();
Expand Down Expand Up @@ -1285,7 +1295,18 @@ mod tests {

let private_key = "0x43fe394358d14f2e096f4efe80894b4e51a3fdcb73c06b77e937b80deb8c746b";
let decoded = decode_private_key(&private_key).unwrap();
assert_eq!(decoded.chain_types, Vec::<String>::new());
assert_eq!(
decoded.chain_types,
vec![
"BITCOIN".to_string(),
"ETHEREUM".to_string(),
"BITCOINCASH".to_string(),
"LITECOIN".to_string(),
"EOS".to_string(),
"TRON".to_string(),
"FILECOIN".to_string(),
]
);
assert_eq!(decoded.curve, CurveType::SECP256k1);
assert_eq!(decoded.network, "".to_string());
assert_eq!(decoded.source, Source::Private);
Expand Down
13 changes: 12 additions & 1 deletion token-core/tcx/tests/import_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,18 @@ pub fn test_import_hex_private_key() {
let ret = call_api("import_private_key", param).unwrap();
let import_result: ImportPrivateKeyResult =
ImportPrivateKeyResult::decode(ret.as_slice()).unwrap();
assert_eq!(Vec::<String>::new(), import_result.identified_chain_types);
assert_eq!(
vec![
"BITCOIN".to_string(),
"ETHEREUM".to_string(),
"BITCOINCASH".to_string(),
"LITECOIN".to_string(),
"EOS".to_string(),
"TRON".to_string(),
"FILECOIN".to_string(),
],
import_result.identified_chain_types
);
assert_eq!("secp256k1", import_result.identified_curve);
assert_eq!("", import_result.identified_network);
assert_eq!("PRIVATE", import_result.source);
Expand Down

0 comments on commit 28121c5

Please sign in to comment.