This commit is contained in:
Sergio Chouhy 2025-10-03 08:08:54 -03:00
parent 9141fbf06c
commit 46f899ac95
9 changed files with 15 additions and 29 deletions

View File

@ -3,11 +3,9 @@ use nssa_core::{
NullifierPublicKey, SharedSecretKey,
encryption::{EphemeralPublicKey, EphemeralSecretKey, IncomingViewingPublicKey},
};
use rand::{rngs::OsRng, RngCore};
use rand::{RngCore, rngs::OsRng};
use sha2::Digest;
use crate::key_management::secret_holders::OutgoingViewingSecretKey;
#[derive(Debug)]
///Ephemeral secret key holder. Non-clonable as intended for one-time use. Produces ephemeral public keys. Can produce shared secret for sender.
pub struct EphemeralKeyHolder {
@ -26,9 +24,7 @@ pub fn produce_one_sided_shared_secret_receiver(
}
impl EphemeralKeyHolder {
pub fn new(
receiver_nullifier_public_key: &NullifierPublicKey,
) -> Self {
pub fn new(receiver_nullifier_public_key: &NullifierPublicKey) -> Self {
let mut nonce_bytes = [0; 16];
OsRng.fill_bytes(&mut nonce_bytes);
let mut hasher = sha2::Sha256::new();

View File

@ -20,7 +20,6 @@ pub struct KeyChain {
pub incoming_viewing_public_key: IncomingViewingPublicKey,
}
impl KeyChain {
pub fn new_os_random() -> Self {
//Currently dropping SeedHolder at the end of initialization.

View File

@ -89,8 +89,7 @@ mod tests {
nonce: 0xdeadbeef,
};
let fingerprint = AccountId::new([8; 32]);
let new_acc_with_metadata =
AccountWithMetadata::new(account.clone(), true, fingerprint);
let new_acc_with_metadata = AccountWithMetadata::new(account.clone(), true, fingerprint);
assert_eq!(new_acc_with_metadata.account, account);
assert!(new_acc_with_metadata.is_authorized);
assert_eq!(new_acc_with_metadata.account_id, fingerprint);

View File

@ -3,10 +3,10 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "host")]
use std::{fmt::Display, str::FromStr};
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(
any(feature = "host", test),
derive(Debug, Copy, PartialOrd, Ord, Hash, Default)
derive(Debug, Copy, PartialOrd, Ord, Default)
)]
pub struct Address {
value: [u8; 32],
@ -60,7 +60,6 @@ impl Display for Address {
#[cfg(test)]
mod tests {
use super::{Address, AddressError};

View File

@ -87,10 +87,7 @@ pub fn produce_data_for_storage(user_data: &NSSAUserData) -> Vec<PersistentAccou
pub(crate) fn produce_random_nonces(size: usize) -> Vec<Nonce> {
let mut result = vec![[0; 16]; size];
result.iter_mut().for_each(|bytes| OsRng.fill_bytes(bytes));
result
.into_iter()
.map(Nonce::from_le_bytes)
.collect()
result.into_iter().map(Nonce::from_le_bytes).collect()
}
/// Human-readable representation of an account.

View File

@ -712,7 +712,7 @@ pub async fn execute_subcommand(command: Command) -> Result<SubcommandReturnValu
Command::RegisterAccountPrivate {} => {
let addr = wallet_core.create_new_account_private();
let (key, account) = wallet_core
let (key, _) = wallet_core
.storage
.user_data
.get_private_account(&addr)
@ -722,7 +722,7 @@ pub async fn execute_subcommand(command: Command) -> Result<SubcommandReturnValu
println!("With npk {}", hex::encode(&key.nullifer_public_key));
println!(
"With ipk {}",
hex::encode(&key.incoming_viewing_public_key.to_bytes())
hex::encode(key.incoming_viewing_public_key.to_bytes())
);
let path = wallet_core.store_persistent_accounts()?;

View File

@ -1,10 +1,8 @@
use common::{ExecutionFailureKind, sequencer_client::json::SendTxResponse};
use k256::elliptic_curve::rand_core::{OsRng, RngCore};
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
use nssa::Address;
use nssa_core::{SharedSecretKey, encryption::EphemeralPublicKey};
use crate::{helperfunctions::produce_random_nonces, WalletCore};
use crate::{WalletCore, helperfunctions::produce_random_nonces};
impl WalletCore {
pub async fn send_deshielded_native_token_transfer(
@ -13,7 +11,7 @@ impl WalletCore {
to: Address,
balance_to_move: u128,
) -> Result<(SendTxResponse, nssa_core::SharedSecretKey), ExecutionFailureKind> {
let Some((from_keys, mut from_acc)) =
let Some((from_keys, from_acc)) =
self.storage.user_data.get_private_account(&from).cloned()
else {
return Err(ExecutionFailureKind::KeyNotFoundError);

View File

@ -12,7 +12,7 @@ impl WalletCore {
to_ipk: nssa_core::encryption::IncomingViewingPublicKey,
balance_to_move: u128,
) -> Result<(SendTxResponse, [nssa_core::SharedSecretKey; 2]), ExecutionFailureKind> {
let Some((from_keys, mut from_acc)) =
let Some((from_keys, from_acc)) =
self.storage.user_data.get_private_account(&from).cloned()
else {
return Err(ExecutionFailureKind::KeyNotFoundError);
@ -107,13 +107,13 @@ impl WalletCore {
to: Address,
balance_to_move: u128,
) -> Result<(SendTxResponse, [nssa_core::SharedSecretKey; 2]), ExecutionFailureKind> {
let Some((from_keys, mut from_acc)) =
let Some((from_keys, from_acc)) =
self.storage.user_data.get_private_account(&from).cloned()
else {
return Err(ExecutionFailureKind::KeyNotFoundError);
};
let Some((to_keys, mut to_acc)) = self.storage.user_data.get_private_account(&to).cloned()
let Some((to_keys, to_acc)) = self.storage.user_data.get_private_account(&to).cloned()
else {
return Err(ExecutionFailureKind::KeyNotFoundError);
};

View File

@ -1,7 +1,5 @@
use common::{ExecutionFailureKind, sequencer_client::json::SendTxResponse};
use key_protocol::key_management::ephemeral_key_holder::{
EphemeralKeyHolder, produce_one_sided_shared_secret_receiver,
};
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
use nssa::Address;
use crate::{WalletCore, helperfunctions::produce_random_nonces};
@ -17,7 +15,7 @@ impl WalletCore {
return Err(ExecutionFailureKind::KeyNotFoundError);
};
let Some((to_keys, mut to_acc)) = self.storage.user_data.get_private_account(&to).cloned()
let Some((to_keys, to_acc)) = self.storage.user_data.get_private_account(&to).cloned()
else {
return Err(ExecutionFailureKind::KeyNotFoundError);
};