diff --git a/integration_tests/tests/auth_transfer/private.rs b/integration_tests/tests/auth_transfer/private.rs index 22396ebc..396fa6cc 100644 --- a/integration_tests/tests/auth_transfer/private.rs +++ b/integration_tests/tests/auth_transfer/private.rs @@ -164,15 +164,15 @@ async fn private_transfer_to_owned_account_using_claiming_path() -> Result<()> { }; // Get the keys for the newly created account - let (to_keys, _) = ctx + let bundle = ctx .wallet() .storage() .user_data .get_private_account(to_account_id) - .unwrap() - .key_chain .context("Failed to get private account")?; + let to_keys = bundle.key_chain; + // Send to this account using claiming path (using npk and vpk instead of account ID) let command = Command::AuthTransfer(AuthTransferSubcommand::Send { from: format_private_account_id(from), @@ -325,15 +325,15 @@ async fn private_transfer_to_owned_account_continuous_run_path() -> Result<()> { }; // Get the newly created account's keys - let (to_keys, _) = ctx + let bundle = ctx .wallet() .storage() .user_data .get_private_account(to_account_id) - .unwrap() - .key_chain .context("Failed to get private account")?; + let to_keys = bundle.key_chain; + // Send transfer using nullifier and viewing public keys let command = Command::AuthTransfer(AuthTransferSubcommand::Send { from: format_private_account_id(from), diff --git a/integration_tests/tests/keys_restoration.rs b/integration_tests/tests/keys_restoration.rs index 7706e108..6b9401fe 100644 --- a/integration_tests/tests/keys_restoration.rs +++ b/integration_tests/tests/keys_restoration.rs @@ -58,16 +58,15 @@ async fn sync_private_account_with_non_zero_chain_index() -> Result<()> { anyhow::bail!("Expected RegisterAccount return value"); }; - // Get the keys for the newly created account - let (to_keys, _) = ctx + let bundle = ctx .wallet() .storage() .user_data .get_private_account(to_account_id) - .unwrap() - .key_chain .context("Failed to get private account")?; + let to_keys = bundle.key_chain; + // Send to this account using claiming path (using npk and vpk instead of account ID) let command = Command::AuthTransfer(AuthTransferSubcommand::Send { from: format_private_account_id(from), diff --git a/integration_tests/tests/token.rs b/integration_tests/tests/token.rs index 683f7ebe..56af38b9 100644 --- a/integration_tests/tests/token.rs +++ b/integration_tests/tests/token.rs @@ -1097,14 +1097,14 @@ async fn token_claiming_path_with_private_accounts() -> Result<()> { }; // Get keys for foreign mint (claiming path) - let (holder_keys, _) = ctx + let holder_keys = ctx .wallet() .storage() .user_data .get_private_account(recipient_account_id) .unwrap() - .key_chain - .context("Failed to get private account keys")?; + .key_chain; + // .context("Failed to get private account keys")?; // Mint using claiming path (foreign account) let mint_amount = 9; diff --git a/key_protocol/src/key_management/key_tree/keys_private.rs b/key_protocol/src/key_management/key_tree/keys_private.rs index c08f9e70..53ff223e 100644 --- a/key_protocol/src/key_management/key_tree/keys_private.rs +++ b/key_protocol/src/key_management/key_tree/keys_private.rs @@ -2,11 +2,14 @@ use k256::{Scalar, elliptic_curve::PrimeField as _}; use nssa_core::{NullifierPublicKey, encryption::ViewingPublicKey}; use serde::{Deserialize, Serialize}; -use crate::{key_management::{ - KeyChain, - key_tree::traits::KeyNode, - secret_holders::{PrivateKeyHolder, SecretSpendingKey}, -}, key_protocol_core::PrivateBundle}; +use crate::{ + key_management::{ + KeyChain, + key_tree::traits::KeyNode, + secret_holders::{PrivateKeyHolder, SecretSpendingKey}, + }, + key_protocol_core::PrivateBundle, +}; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct ChildKeysPrivate { @@ -131,8 +134,10 @@ impl<'a> From<&'a ChildKeysPrivate> for &'a (KeyChain, nssa::Account) { )] impl<'a> From<&'a mut ChildKeysPrivate> for PrivateBundle { fn from(value: &'a mut ChildKeysPrivate) -> Self { - PrivateBundle { key_chain: value.value.0.clone(), - account: value.value.1.clone(), } + Self { + key_chain: value.value.0.clone(), + account: value.value.1.clone(), + } } } diff --git a/key_protocol/src/key_protocol_core/mod.rs b/key_protocol/src/key_protocol_core/mod.rs index 6403ec9a..bb771331 100644 --- a/key_protocol/src/key_protocol_core/mod.rs +++ b/key_protocol/src/key_protocol_core/mod.rs @@ -69,10 +69,7 @@ impl NSSAUserData { pub fn new_with_accounts( default_accounts_keys: BTreeMap, - default_accounts_key_chains: BTreeMap< - nssa::AccountId, - PrivateBundle, - >, + default_accounts_key_chains: BTreeMap, public_key_tree: KeyTreePublic, private_key_tree: KeyTreePrivate, ) -> Result { @@ -147,11 +144,8 @@ impl NSSAUserData { } /// Returns the signing key for public transaction signatures. - #[must_use] //Marvin: double check TODO + #[must_use] pub fn get_private_account(&self, account_id: nssa::AccountId) -> Option { - // self.default_user_private_accounts - // .get(&account_id) - // .or_else(|| self.private_key_tree.get_node(account_id).map(Into::into)) self.default_user_private_accounts .get(&account_id) .cloned() @@ -166,7 +160,6 @@ impl NSSAUserData { } /// Returns the signing key for public transaction signatures. - /// TODO: fix this comment (Marvin) pub fn get_private_account_mut( &mut self, account_id: &nssa::AccountId, @@ -231,7 +224,10 @@ mod tests { let account_id_private_str = account_id_private.to_string(); println!("{account_id_private_str:#?}"); - let key_chain = &user_data.get_private_account(account_id_private).unwrap().key_chain; + let key_chain = &user_data + .get_private_account(account_id_private) + .unwrap() + .key_chain; println!("{key_chain:#?}"); } } diff --git a/wallet-ffi/src/keys.rs b/wallet-ffi/src/keys.rs index 16e152b5..b8c95c55 100644 --- a/wallet-ffi/src/keys.rs +++ b/wallet-ffi/src/keys.rs @@ -116,8 +116,7 @@ pub unsafe extern "C" fn wallet_ffi_get_private_account_keys( let account_id = AccountId::new(unsafe { (*account_id).data }); - let Some(bundle) = wallet.storage().user_data.get_private_account(account_id) - else { + let Some(bundle) = wallet.storage().user_data.get_private_account(account_id) else { print_error("Private account not found in wallet"); return WalletFfiError::AccountNotFound; }; diff --git a/wallet/src/chain_storage.rs b/wallet/src/chain_storage.rs index c5fc7d80..c9d07d08 100644 --- a/wallet/src/chain_storage.rs +++ b/wallet/src/chain_storage.rs @@ -82,8 +82,13 @@ impl WalletChainStore { ); } InitialAccountData::Private(data) => { - private_init_acc_map - .insert(data.account_id, PrivateBundle {key_chain: data.key_chain, account: data.account}); + private_init_acc_map.insert( + data.account_id, + PrivateBundle { + key_chain: data.key_chain, + account: data.account, + }, + ); } }, } @@ -127,7 +132,13 @@ impl WalletChainStore { // startup. Fix this when program id can be fetched // from the node and queried from the wallet. account.program_owner = Program::authenticated_transfer_program().id(); - private_init_acc_map.insert(data.account_id, PrivateBundle{ key_chain: data.key_chain, account: account}); + private_init_acc_map.insert( + data.account_id, + PrivateBundle { + key_chain: data.key_chain, + account, + }, + ); } } } diff --git a/wallet/src/cli/account.rs b/wallet/src/cli/account.rs index 1bb6ec74..19e27847 100644 --- a/wallet/src/cli/account.rs +++ b/wallet/src/cli/account.rs @@ -137,7 +137,7 @@ impl WalletSubcommand for NewSubcommand { .insert(account_id.to_string(), Label::new(label)); } - let bundle= wallet_core + let bundle = wallet_core .storage .user_data .get_private_account(account_id) @@ -146,7 +146,10 @@ impl WalletSubcommand for NewSubcommand { println!( "Generated new account with account_id Private/{account_id} at path {chain_index}", ); - println!("With npk {}", hex::encode(bundle.key_chain.nullifier_public_key.0)); + println!( + "With npk {}", + hex::encode(bundle.key_chain.nullifier_public_key.0) + ); println!( "With vpk {}", hex::encode(bundle.key_chain.viewing_public_key.to_bytes()) @@ -203,14 +206,20 @@ impl WalletSubcommand for AccountSubcommand { println!("pk {}", hex::encode(public_key.value())); } AccountPrivacyKind::Private => { - let bundle= wallet_core + let bundle = wallet_core .storage .user_data .get_private_account(account_id) .context("Private account not found in storage")?; - println!("npk {}", hex::encode(bundle.key_chain.nullifier_public_key.0)); - println!("vpk {}", hex::encode(bundle.key_chain.viewing_public_key.to_bytes())); + println!( + "npk {}", + hex::encode(bundle.key_chain.nullifier_public_key.0) + ); + println!( + "vpk {}", + hex::encode(bundle.key_chain.viewing_public_key.to_bytes()) + ); } } Ok(()) diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index 0a01f185..f4fdf2da 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -15,7 +15,10 @@ use bip39::Mnemonic; use chain_storage::WalletChainStore; use common::{HashType, transaction::NSSATransaction}; use config::WalletConfig; -use key_protocol::{key_management::key_tree::{chain_index::ChainIndex, traits::KeyNode as _}, key_protocol_core::PrivateBundle}; +use key_protocol::{ + key_management::key_tree::{chain_index::ChainIndex, traits::KeyNode as _}, + key_protocol_core::PrivateBundle, +}; use log::info; use nssa::{ Account, AccountId, PrivacyPreservingTransaction, @@ -295,13 +298,16 @@ impl WalletCore { self.storage .user_data .get_private_account(account_id) - .map(|bundle| bundle.account.clone()) + .map(|bundle| bundle.account) } #[must_use] pub fn get_private_account_commitment(&self, account_id: AccountId) -> Option { - let bundle= self.storage.user_data.get_private_account(account_id)?; - Some(Commitment::new(&bundle.key_chain.nullifier_public_key, &bundle.account)) + let bundle = self.storage.user_data.get_private_account(account_id)?; + Some(Commitment::new( + &bundle.key_chain.nullifier_public_key, + &bundle.account, + )) } /// Poll transactions. @@ -484,7 +490,15 @@ impl WalletCore { .user_data .default_user_private_accounts .iter() - .map(|(acc_account_id, PrivateBundle{key_chain,account: _ })| (*acc_account_id, key_chain, None)) + .map( + |( + acc_account_id, + PrivateBundle { + key_chain, + account: _, + }, + )| (*acc_account_id, key_chain, None), + ) .chain(self.storage.user_data.private_key_tree.key_map.iter().map( |(chain_index, keys_node)| { ( diff --git a/wallet/src/privacy_preserving_tx.rs b/wallet/src/privacy_preserving_tx.rs index 5b7ce373..e70c928e 100644 --- a/wallet/src/privacy_preserving_tx.rs +++ b/wallet/src/privacy_preserving_tx.rs @@ -202,12 +202,7 @@ async fn private_acc_preparation( wallet: &WalletCore, account_id: AccountId, ) -> Result { - let Some(from_bundle) = wallet - .storage - .user_data - .get_private_account(account_id) - .clone() - else { + let Some(from_bundle) = wallet.storage.user_data.get_private_account(account_id) else { return Err(ExecutionFailureKind::KeyNotFoundError); };