Skip to content

Commit

Permalink
Merge pull request #73 from KeystoneHQ/add-device-version-in-multi-ac…
Browse files Browse the repository at this point in the history
…counts-ffi

feat: add version field to crypto_multi_accounts FFI
  • Loading branch information
LiYanLance authored Oct 9, 2023
2 parents f02cf72 + 0ba3fe7 commit 1ceedf2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion libs/ur-registry-ffi/src/sync/crypto_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl Into<MultiAccounts> for CryptoAccount {
keys: hd_keys,
device: None,
device_id: None,
device_version: None
}
}
}
Expand Down Expand Up @@ -54,7 +55,7 @@ mod tests {
#[test]
fn test_parse_crypto_account() {
let hd_keys_cbor = "A2011A52006EA0028AD9012FA502F403582102FEF03A2BD3DE113F1DC1CDB1E69AA4D935DC3458D542D796F5827ABBB1A58B5E06D90130A3018A182CF5183CF500F500F400F4021A52006EA0030509684B657973746F6E650A736163636F756E742E6C65646765725F6C697665D9012FA502F4035821033F1EDDF1D1BB2762FCFA67FBC35E12DC9968CD2587ADA055210E84F780C1109A06D90130A3018A182CF5183CF501F500F400F4021A52006EA0030509684B657973746F6E650A736163636F756E742E6C65646765725F6C697665D9012FA502F403582102C5FCF766AD77A0C254834D57CE3E6120A2BE5C266E9BABE8A047D1A53CB34F9E06D90130A3018A182CF5183CF502F500F400F4021A52006EA0030509684B657973746F6E650A736163636F756E742E6C65646765725F6C697665D9012FA502F403582102CD0B648CF944CBA7E6BE97BF1F17F0EAB7B9E600D181C421B3BCE6E7F6D941F006D90130A3018A182CF5183CF503F500F400F4021A52006EA0030509684B657973746F6E650A736163636F756E742E6C65646765725F6C697665D9012FA502F40358210351F72104E737E94C7CC66E33307C74D5BBF19216800157AD34EBFE232F23C75106D90130A3018A182CF5183CF504F500F400F4021A52006EA0030509684B657973746F6E650A736163636F756E742E6C65646765725F6C697665D9012FA502F403582102037F8C5FC1074E654FF11619A8BF28DCC3DB5D037191F08EB5722252AF57A4A606D90130A3018A182CF5183CF505F500F400F4021A52006EA0030509684B657973746F6E650A736163636F756E742E6C65646765725F6C697665D9012FA502F403582103A441895DFBE9C7B3BF8EBA0CE461465A14350D902DF163A0B3F06E4F4843E54F06D90130A3018A182CF5183CF506F500F400F4021A52006EA0030509684B657973746F6E650A736163636F756E742E6C65646765725F6C697665D9012FA502F403582102A8DCDF480733A5B7FB331C9464B7E0EDF5206D8581FE3E26BFD6DE38C8063D4C06D90130A3018A182CF5183CF507F500F400F4021A52006EA0030509684B657973746F6E650A736163636F756E742E6C65646765725F6C697665D9012FA502F4035821037A1A6A48B09D4E3A01223B37C9D1212D8DA20746302009956168E1EA3BD3E0C806D90130A3018A182CF5183CF508F500F400F4021A52006EA0030509684B657973746F6E650A736163636F756E742E6C65646765725F6C697665D9012FA502F403582103C6F04A813F23799940B6FA44C6CA48ABE04DE9FBB8133B7342DBABC95B0EA48106D90130A3018A182CF5183CF509F500F400F4021A52006EA0030509684B657973746F6E650A736163636F756E742E6C65646765725F6C697665";
let expect_result = "{\"device\":null,\"device_id\":null,\"keys\":[{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/0'/0/0\",\"public_key\":\"02fef03a2bd3de113f1dc1cdb1e69aa4d935dc3458d542d796f5827abbb1a58b5e\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/1'/0/0\",\"public_key\":\"033f1eddf1d1bb2762fcfa67fbc35e12dc9968cd2587ada055210e84f780c1109a\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/2'/0/0\",\"public_key\":\"02c5fcf766ad77a0c254834d57ce3e6120a2be5c266e9babe8a047d1a53cb34f9e\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/3'/0/0\",\"public_key\":\"02cd0b648cf944cba7e6be97bf1f17f0eab7b9e600d181c421b3bce6e7f6d941f0\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/4'/0/0\",\"public_key\":\"0351f72104e737e94c7cc66e33307c74d5bbf19216800157ad34ebfe232f23c751\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/5'/0/0\",\"public_key\":\"02037f8c5fc1074e654ff11619a8bf28dcc3db5d037191f08eb5722252af57a4a6\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/6'/0/0\",\"public_key\":\"03a441895dfbe9c7b3bf8eba0ce461465a14350d902df163a0b3f06e4f4843e54f\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/7'/0/0\",\"public_key\":\"02a8dcdf480733a5b7fb331c9464b7e0edf5206d8581fe3e26bfd6de38c8063d4c\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/8'/0/0\",\"public_key\":\"037a1a6a48b09d4e3a01223b37c9d1212d8da20746302009956168e1ea3bd3e0c8\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/9'/0/0\",\"public_key\":\"03c6f04a813f23799940b6fa44c6ca48abe04de9fbb8133b7342dbabc95b0ea481\",\"xfp\":\"52006ea0\"}],\"master_fingerprint\":\"52006ea0\"}";
let expect_result = "{\"device\":null,\"device_id\":null,\"device_version\":null,\"keys\":[{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/0'/0/0\",\"public_key\":\"02fef03a2bd3de113f1dc1cdb1e69aa4d935dc3458d542d796f5827abbb1a58b5e\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/1'/0/0\",\"public_key\":\"033f1eddf1d1bb2762fcfa67fbc35e12dc9968cd2587ada055210e84f780c1109a\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/2'/0/0\",\"public_key\":\"02c5fcf766ad77a0c254834d57ce3e6120a2be5c266e9babe8a047d1a53cb34f9e\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/3'/0/0\",\"public_key\":\"02cd0b648cf944cba7e6be97bf1f17f0eab7b9e600d181c421b3bce6e7f6d941f0\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/4'/0/0\",\"public_key\":\"0351f72104e737e94c7cc66e33307c74d5bbf19216800157ad34ebfe232f23c751\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/5'/0/0\",\"public_key\":\"02037f8c5fc1074e654ff11619a8bf28dcc3db5d037191f08eb5722252af57a4a6\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/6'/0/0\",\"public_key\":\"03a441895dfbe9c7b3bf8eba0ce461465a14350d902df163a0b3f06e4f4843e54f\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/7'/0/0\",\"public_key\":\"02a8dcdf480733a5b7fb331c9464b7e0edf5206d8581fe3e26bfd6de38c8063d4c\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/8'/0/0\",\"public_key\":\"037a1a6a48b09d4e3a01223b37c9d1212d8da20746302009956168e1ea3bd3e0c8\",\"xfp\":\"52006ea0\"},{\"chain\":\"ETH\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":1}},\"name\":\"Keystone\",\"note\":\"account.ledger_live\",\"path\":\"m/44'/60'/9'/0/0\",\"public_key\":\"03c6f04a813f23799940b6fa44c6ca48abe04de9fbb8133b7342dbabc95b0ea481\",\"xfp\":\"52006ea0\"}],\"master_fingerprint\":\"52006ea0\"}";

assert_eq!(
expect_result,
Expand Down
19 changes: 16 additions & 3 deletions libs/ur-registry-ffi/src/sync/crypto_multi_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct MultiAccounts {
pub keys: Vec<Account>,
pub device: Option<String>,
pub device_id: Option<String>,
pub device_version: Option<String>,
}

impl Into<MultiAccounts> for CryptoMultiAccounts {
Expand All @@ -31,6 +32,7 @@ impl Into<MultiAccounts> for CryptoMultiAccounts {
.collect(),
device: self.get_device(),
device_id: self.get_device_id(),
device_version: self.get_device_version(),
}
}
}
Expand Down Expand Up @@ -62,7 +64,7 @@ mod tests {
#[test]
fn test_parse_crypto_multi_accounts() {
let multi_accounts_cbor = "a3011ae9181cf30281d9012fa203582102eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b06d90130a10188182cf51901f5f500f500f503686b657973746f6e65";
let expect_result = "{\"device\":\"keystone\",\"device_id\":null,\"keys\":[{\"chain\":\"SOL\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":501}},\"name\":\"\",\"path\":\"m/44'/501'/0'/0'\",\"public_key\":\"02eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b\"}],\"master_fingerprint\":\"e9181cf3\"}";
let expect_result = "{\"device\":\"keystone\",\"device_id\":null,\"device_version\":null,\"keys\":[{\"chain\":\"SOL\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":501}},\"name\":\"\",\"path\":\"m/44'/501'/0'/0'\",\"public_key\":\"02eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b\"}],\"master_fingerprint\":\"e9181cf3\"}";

assert_eq!(
expect_result,
Expand All @@ -73,7 +75,18 @@ mod tests {
#[test]
fn test_parse_crypto_multi_accounts_with_device_id() {
let multi_accounts_cbor = "a4011ae9181cf30281d9012fa203582102eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b06d90130a10188182cf51901f5f500f500f503686b657973746f6e6504782832383437356338643830663663303662616662653436613764313735306633666366323536356637";
let expect_result = "{\"device\":\"keystone\",\"device_id\":\"28475c8d80f6c06bafbe46a7d1750f3fcf2565f7\",\"keys\":[{\"chain\":\"SOL\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":501}},\"name\":\"\",\"path\":\"m/44'/501'/0'/0'\",\"public_key\":\"02eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b\"}],\"master_fingerprint\":\"e9181cf3\"}";
let expect_result = "{\"device\":\"keystone\",\"device_id\":\"28475c8d80f6c06bafbe46a7d1750f3fcf2565f7\",\"device_version\":null,\"keys\":[{\"chain\":\"SOL\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":501}},\"name\":\"\",\"path\":\"m/44'/501'/0'/0'\",\"public_key\":\"02eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b\"}],\"master_fingerprint\":\"e9181cf3\"}";

assert_eq!(
expect_result,
parse_crypto_multi_accounts("crypto-multi-accounts", multi_accounts_cbor)
);
}

#[test]
fn test_parse_crypto_multi_accounts_with_device_version() {
let multi_accounts_cbor = "a5011ae9181cf30281d9012fa203582102eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b06d90130a10188182cf51901f5f500f500f503686b657973746f6e65047828323834373563386438306636633036626166626534366137643137353066336663663235363566370565312e302e30";
let expect_result = "{\"device\":\"keystone\",\"device_id\":\"28475c8d80f6c06bafbe46a7d1750f3fcf2565f7\",\"device_version\":\"1.0.0\",\"keys\":[{\"chain\":\"SOL\",\"chain_code\":\"\",\"extended_public_key\":\"\",\"extra\":{\"okx\":{\"chain_id\":501}},\"name\":\"\",\"path\":\"m/44'/501'/0'/0'\",\"public_key\":\"02eae4b876a8696134b868f88cc2f51f715f2dbedb7446b8e6edf3d4541c4eb67b\"}],\"master_fingerprint\":\"e9181cf3\"}";

assert_eq!(
expect_result,
Expand All @@ -86,7 +99,7 @@ mod tests {
// feed illegal large weekend demand typical brick bid dilemma between gasp art

let multi_accounts_cbor = "a3011aa424853c0281d9012fa4035821034af544244d31619d773521a1a366373c485ff89de50bea543c2b14cccfbb6a500458208dc2427d8ab23caab07729f88f089a3cfa2cfffcd7d1e507f983c0d44a5dbd3506d90130a10186182cf500f500f5081a149439dc03686b657973746f6e65";
let expect_result = "{\"device\":\"keystone\",\"device_id\":null,\"keys\":[{\"chain\":\"BTC\",\"chain_code\":\"8dc2427d8ab23caab07729f88f089a3cfa2cfffcd7d1e507f983c0d44a5dbd35\",\"extended_public_key\":\"xpub6BoYPFH1MivLdh2BWZuRu6LfuaVSkVak5wsDxjjkAWcUM2QPKyeCHXMgDfRJFvKZhqA4vM5vsgcD6C5ot9eThnFHstgPntNzBLUdLeKS7Zt\",\"extra\":{\"okx\":{\"chain_id\":0}},\"name\":\"\",\"path\":\"m/44'/0'/0'\",\"public_key\":\"034af544244d31619d773521a1a366373c485ff89de50bea543c2b14cccfbb6a50\"}],\"master_fingerprint\":\"a424853c\"}";
let expect_result = "{\"device\":\"keystone\",\"device_id\":null,\"device_version\":null,\"keys\":[{\"chain\":\"BTC\",\"chain_code\":\"8dc2427d8ab23caab07729f88f089a3cfa2cfffcd7d1e507f983c0d44a5dbd35\",\"extended_public_key\":\"xpub6BoYPFH1MivLdh2BWZuRu6LfuaVSkVak5wsDxjjkAWcUM2QPKyeCHXMgDfRJFvKZhqA4vM5vsgcD6C5ot9eThnFHstgPntNzBLUdLeKS7Zt\",\"extra\":{\"okx\":{\"chain_id\":0}},\"name\":\"\",\"path\":\"m/44'/0'/0'\",\"public_key\":\"034af544244d31619d773521a1a366373c485ff89de50bea543c2b14cccfbb6a50\"}],\"master_fingerprint\":\"a424853c\"}";

assert_eq!(
expect_result,
Expand Down

0 comments on commit 1ceedf2

Please sign in to comment.