From 75a0749c36a3a45baf43d6b94f8d36c913ad6844 Mon Sep 17 00:00:00 2001 From: XuNeal Date: Thu, 18 Apr 2024 17:41:47 +0800 Subject: [PATCH] fix: metadata missing password_hint error --- token-core/tcx-migration/src/migration.rs | 35 ++++++++++++++++-- .../5991857a-2488-4546-b730-463a5f84ea6a | 4 +-- .../6f8c2912-ebe8-4359-90f4-f1d1f1af1e4d | 36 +++++++++++++++++++ 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 token-core/tcx-migration/tests/fixtures/6f8c2912-ebe8-4359-90f4-f1d1f1af1e4d diff --git a/token-core/tcx-migration/src/migration.rs b/token-core/tcx-migration/src/migration.rs index 159220bd..ab9ce083 100644 --- a/token-core/tcx-migration/src/migration.rs +++ b/token-core/tcx-migration/src/migration.rs @@ -28,7 +28,7 @@ pub struct OldMetadata { pub chain_type: Option, pub chain: Option, pub network: Option, - pub password_hint: String, + pub password_hint: Option, pub timestamp: NumberOrNumberStr, pub source: Option, pub seg_wit: Option, @@ -69,7 +69,7 @@ impl OldMetadata { Metadata { name: self.name.clone(), - password_hint: self.password_hint.clone(), + password_hint: self.password_hint.clone().unwrap_or_default(), timestamp, source, network, @@ -357,6 +357,13 @@ mod tests { ) } + fn metadata_missing_password_hint() -> (&'static str, &'static str) { + ( + include_str!("../tests/fixtures/6f8c2912-ebe8-4359-90f4-f1d1f1af1e4d"), + "3223cd3abf2422d0ad3503f73aaa6e7e36a555385c6825b383908c1e8acf5e9d9a4c751809473c75599a632fe5b1437f51a3a848e054d9c170f8c3b5c5701b8b", + ) + } + #[test] fn test_eos_private_key() { let (keystore_str, derived_key) = v3_eos_private_key(); @@ -501,6 +508,30 @@ mod tests { seg_wit: "".to_string(), }; + keystore.unlock(&key).unwrap(); + let acc = keystore.derive_coin::(&coin_info).unwrap(); + assert_eq!("0x6031564e7b2F5cc33737807b2E58DaFF870B590b", acc.address); + assert_eq!(keystore.meta().password_hint, "ios_password_hint"); + } + + #[test] + fn test_metadata_missing_password_hint() { + let (keystore_str, derived_key) = metadata_missing_password_hint(); + let ks = LegacyKeystore::from_json_str(keystore_str).unwrap(); + //password imtoken1 + let key = Key::DerivedKey(derived_key.to_owned()); + let mut keystore = ks.migrate(&key, &IdentityNetwork::Testnet).unwrap(); + + assert_eq!(keystore.derivable(), true); + assert_eq!(keystore.id(), "6f8c2912-ebe8-4359-90f4-f1d1f1af1e4d"); + let coin_info = CoinInfo { + coin: "ETHEREUM".to_string(), + derivation_path: "m/44'/60'/0'/0/0".to_string(), + curve: CurveType::SECP256k1, + network: "".to_string(), + seg_wit: "".to_string(), + }; + keystore.unlock(&key).unwrap(); let acc = keystore.derive_coin::(&coin_info).unwrap(); assert_eq!("0x6031564e7b2F5cc33737807b2E58DaFF870B590b", acc.address); diff --git a/token-core/tcx-migration/tests/fixtures/5991857a-2488-4546-b730-463a5f84ea6a b/token-core/tcx-migration/tests/fixtures/5991857a-2488-4546-b730-463a5f84ea6a index c2d312f3..def9bbf0 100644 --- a/token-core/tcx-migration/tests/fixtures/5991857a-2488-4546-b730-463a5f84ea6a +++ b/token-core/tcx-migration/tests/fixtures/5991857a-2488-4546-b730-463a5f84ea6a @@ -26,7 +26,7 @@ "mode": "normal", "chain": "ETHEREUM", "segWit": "NONE", - "passwordHint": "", + "passwordHint": "ios_password_hint", "backup": [], "source": "RECOVERED_IDENTITY", "version": "iOS-2.14.0.1742", @@ -34,4 +34,4 @@ "network": "MAINNET", "timestamp": "1695800371.215641" } -} \ No newline at end of file +} diff --git a/token-core/tcx-migration/tests/fixtures/6f8c2912-ebe8-4359-90f4-f1d1f1af1e4d b/token-core/tcx-migration/tests/fixtures/6f8c2912-ebe8-4359-90f4-f1d1f1af1e4d new file mode 100644 index 00000000..4dd2ffd1 --- /dev/null +++ b/token-core/tcx-migration/tests/fixtures/6f8c2912-ebe8-4359-90f4-f1d1f1af1e4d @@ -0,0 +1,36 @@ +{ + "id": "6f8c2912-ebe8-4359-90f4-f1d1f1af1e4d", + "crypto": { + "cipher": "aes-128-ctr", + "cipherparams": { + "iv": "3a442e8b02843edf71b8d3a9c9da2c3b" + }, + "ciphertext": "fcbcceae1d239f9575c55f4c4f81eeba44a6ad9d948f544af2ffee9efef2c038", + "kdf": "pbkdf2", + "kdfparams": { + "c": 65535, + "dklen": 32, + "prf": "hmac-sha256", + "salt": "fa141145a343d9b6c7e2f12e0e56d564bc4d1b46cd48e8f7d898779e06357f1f" + }, + "mac": "50ee3b40129c5f18f9ff6982db0eb18504ea2e8f3d96e4ac062b4eb5849cf011" + }, + "version": 3, + "address": "6031564e7b2f5cc33737807b2e58daff870b590b", + "encMnemonic": { + "encStr": "267bda938e4edbf7c420e89c59c6862f9127c7275d012b1b607f9e91ddb94574e81e94f6d8155e3c85ede03f584e09916122f03c72b67a1f96ddbf291beb46894d9a02d30170a9444692", + "nonce": "3cfe9f0b32b5d592e5fab54bd28863cd" + }, + "mnemonicPath": "m/44'/60'/0'/0/0", + "imTokenMeta": { + "mode": "normal", + "chain": "ETHEREUM", + "segWit": "NONE", + "backup": [], + "source": "RECOVERED_IDENTITY", + "version": "iOS-2.14.0.1742", + "name": "ETH", + "network": "MAINNET", + "timestamp": "1695800371.215641" + } +}