Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word count #83

Merged
merged 6 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions wallet/core/src/compat/gen1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn decrypt_mnemonic<T: AsRef<[u8]>>(
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) })
}

Expand All @@ -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]
Expand Down
20 changes: 14 additions & 6 deletions wallet/core/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -796,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::<Vec<_>>().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::<Vec<_>>()
.len() as u64
};

let xpub_key = prv_key_data.create_xpub(payment_secret, BIP32_ACCOUNT_KIND.into(), account_index).await?;
Expand Down Expand Up @@ -862,6 +864,12 @@ impl Wallet {
.ok_or_else(|| Error::PrivateKeyNotFound(prv_key_data_id))?;

let account: Arc<dyn Account> = 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()));
Expand Down
2 changes: 1 addition & 1 deletion wallet/keys/src/derivation/gen0/hd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Address> {
Expand Down