From b9bd512f25a269bef14284a9dd784b7608571f38 Mon Sep 17 00:00:00 2001 From: Surinder Singh Matoo Date: Sat, 20 Jul 2024 05:34:17 +0530 Subject: [PATCH 1/4] Update phrase.rs --- wallet/bip32/src/mnemonic/phrase.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wallet/bip32/src/mnemonic/phrase.rs b/wallet/bip32/src/mnemonic/phrase.rs index 76450590a..56693002d 100644 --- a/wallet/bip32/src/mnemonic/phrase.rs +++ b/wallet/bip32/src/mnemonic/phrase.rs @@ -23,7 +23,7 @@ pub type Entropy32 = [u8; KEY_SIZE]; pub type Entropy16 = [u8; 16]; /// Word count for a BIP39 mnemonic phrase. Identifies mnemonic as 12 or 24 word variants. -#[derive(Default, Clone, Copy, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] +#[derive(Default, PartialEq, Eq, Clone, Copy, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] #[serde(rename_all = "kebab-case")] pub enum WordCount { #[default] From 85d861aeb1d2360cce6635006474d6b59b908043 Mon Sep 17 00:00:00 2001 From: Surinder Singh Matoo Date: Wed, 24 Jul 2024 06:38:47 +0530 Subject: [PATCH 2/4] private context issue for importing legacy wallet --- wallet/core/src/wallet/mod.rs | 12 +++++++----- wallet/keys/src/derivation/gen0/hd.rs | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/wallet/core/src/wallet/mod.rs b/wallet/core/src/wallet/mod.rs index c905d368a..c70d70105 100644 --- a/wallet/core/src/wallet/mod.rs +++ b/wallet/core/src/wallet/mod.rs @@ -378,12 +378,8 @@ impl Wallet { if let Some(accounts) = &accounts { for account in accounts.iter() { if let Ok(legacy_account) = account.clone().as_legacy_account() { - // if let Ok(descriptor) = account.descriptor(){ - // legacy_account.create_private_context(wallet_secret, None, index) - // } - legacy_account.create_private_context(wallet_secret, None, None).await?; - log_info!("create_private_context: receive_address: {:?}", account.receive_address()); + log_info!("create_private_context, open_impl: receive_address: {:?}", account.receive_address()); self.legacy_accounts().insert(account.clone()); } } @@ -862,6 +858,12 @@ impl Wallet { .ok_or_else(|| Error::PrivateKeyNotFound(prv_key_data_id))?; let account: Arc = Arc::new(legacy::Legacy::try_new(self, account_name, prv_key_data.id).await?); + if let Ok(legacy_account) = account.clone().as_legacy_account() { + legacy_account.create_private_context(wallet_secret, None, None).await?; + log_info!("create_private_context: create_account_legacy, receive_address: {:?}", account.receive_address()); + self.legacy_accounts().insert(account.clone()); + //legacy_account.clear_private_context().await?; + } if account_store.load_single(account.id()).await?.is_some() { return Err(Error::AccountAlreadyExists(*account.id())); diff --git a/wallet/keys/src/derivation/gen0/hd.rs b/wallet/keys/src/derivation/gen0/hd.rs index dd85f8fe5..3b7da0e75 100644 --- a/wallet/keys/src/derivation/gen0/hd.rs +++ b/wallet/keys/src/derivation/gen0/hd.rs @@ -176,7 +176,7 @@ impl PubkeyDerivationManagerV0 { return Ok(*key); } - Err(crate::error::Error::Custom("PubkeyDerivationManagerV0 initialization is pending (Error: 102).".into())) + Err(crate::error::Error::Custom("PubkeyDerivationManagerV0 initialization is pending (Error: 105).".into())) } pub fn create_address(key: &secp256k1::PublicKey, prefix: AddressPrefix, _ecdsa: bool) -> Result
{ From 883aecba1435ca5a1dc2be1801e42fb35ec88cc3 Mon Sep 17 00:00:00 2001 From: Surinder Singh Matoo Date: Thu, 25 Jul 2024 03:08:43 +0530 Subject: [PATCH 3/4] account filter updated for calculating account_index --- wallet/core/src/wallet/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/wallet/core/src/wallet/mod.rs b/wallet/core/src/wallet/mod.rs index c70d70105..d5f4dfadd 100644 --- a/wallet/core/src/wallet/mod.rs +++ b/wallet/core/src/wallet/mod.rs @@ -792,7 +792,13 @@ impl Wallet { let account_index = if let Some(account_index) = account_index { account_index } else { - account_store.clone().len(Some(prv_key_data_id)).await? as u64 + let accounts = account_store.clone().iter(Some(prv_key_data_id)).await?.collect::>().await; + + accounts + .into_iter() + .filter(|a| a.as_ref().ok().and_then(|(a, _)| (a.kind == BIP32_ACCOUNT_KIND).then_some(true)).unwrap_or(false)) + .collect::>() + .len() as u64 }; let xpub_key = prv_key_data.create_xpub(payment_secret, BIP32_ACCOUNT_KIND.into(), account_index).await?; From b2c81864375b7800c4d2997f2e1097ade518cda1 Mon Sep 17 00:00:00 2001 From: Surinder Singh Matoo Date: Sun, 28 Jul 2024 04:05:42 +0530 Subject: [PATCH 4/4] gen1 decrypt_mnemonic updated for error unwraping --- wallet/core/src/compat/gen1.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wallet/core/src/compat/gen1.rs b/wallet/core/src/compat/gen1.rs index cd66b1016..5bf5554f5 100644 --- a/wallet/core/src/compat/gen1.rs +++ b/wallet/core/src/compat/gen1.rs @@ -14,7 +14,7 @@ pub fn decrypt_mnemonic>( let mut aead = chacha20poly1305::XChaCha20Poly1305::new(Key::from_slice(&key)); let (nonce, ciphertext) = cipher.as_ref().split_at(24); - let decrypted = aead.decrypt(nonce.into(), ciphertext).unwrap(); + let decrypted = aead.decrypt(nonce.into(), ciphertext)?; Ok(unsafe { String::from_utf8_unchecked(decrypted) }) } @@ -36,8 +36,10 @@ mod test { ecdsa: false, }; - let decrypted = decrypt_mnemonic(8, file.encrypted_mnemonic, b"").unwrap(); - assert_eq!("dizzy uncover funny time weapon chat volume squirrel comic motion until diamond response remind hurt spider door strategy entire oyster hawk marriage soon fabric", decrypted); + let decrypted = decrypt_mnemonic(8, file.encrypted_mnemonic, b""); + log_info!("decrypted: {decrypted:?}"); + assert!(decrypted.is_ok(), "decrypt error"); + assert_eq!("dizzy uncover funny time weapon chat volume squirrel comic motion until diamond response remind hurt spider door strategy entire oyster hawk marriage soon fabric", decrypted.unwrap()); } #[tokio::test]