Skip to content

Commit

Permalink
fix: metadata missing password_hint error
Browse files Browse the repository at this point in the history
  • Loading branch information
XuNeal committed Apr 18, 2024
1 parent 8e76d89 commit 75a0749
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
35 changes: 33 additions & 2 deletions token-core/tcx-migration/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct OldMetadata {
pub chain_type: Option<String>,
pub chain: Option<String>,
pub network: Option<String>,
pub password_hint: String,
pub password_hint: Option<String>,
pub timestamp: NumberOrNumberStr,
pub source: Option<String>,
pub seg_wit: Option<String>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -501,6 +508,30 @@ mod tests {
seg_wit: "".to_string(),
};

keystore.unlock(&key).unwrap();
let acc = keystore.derive_coin::<EthAddress>(&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::<EthAddress>(&coin_info).unwrap();
assert_eq!("0x6031564e7b2F5cc33737807b2E58DaFF870B590b", acc.address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
"mode": "normal",
"chain": "ETHEREUM",
"segWit": "NONE",
"passwordHint": "",
"passwordHint": "ios_password_hint",
"backup": [],
"source": "RECOVERED_IDENTITY",
"version": "iOS-2.14.0.1742",
"name": "ETH",
"network": "MAINNET",
"timestamp": "1695800371.215641"
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 75a0749

Please sign in to comment.