From 4719b1265a79b80cabf7bedd222b73723ff40705 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Thu, 23 Apr 2026 23:44:31 -0300 Subject: [PATCH] replace typedef with struct --- key_protocol/src/key_protocol_core/mod.rs | 29 +++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/key_protocol/src/key_protocol_core/mod.rs b/key_protocol/src/key_protocol_core/mod.rs index e8901860..e189a37d 100644 --- a/key_protocol/src/key_protocol_core/mod.rs +++ b/key_protocol/src/key_protocol_core/mod.rs @@ -2,6 +2,7 @@ use std::collections::BTreeMap; use anyhow::Result; use k256::AffinePoint; +use nssa::{Account, AccountId}; use nssa_core::Identifier; use serde::{Deserialize, Serialize}; @@ -12,15 +13,19 @@ use crate::key_management::{ }; pub type PublicKey = AffinePoint; -pub type DefaultPrivateAccountsMap = - BTreeMap)>; + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct UserPrivateAccountData { + pub key_chain: KeyChain, + pub accounts: Vec<(Identifier, Account)> +} #[derive(Clone, Debug, Serialize, Deserialize)] pub struct NSSAUserData { /// Default public accounts. pub default_pub_account_signing_keys: BTreeMap, /// Default private accounts. - pub default_user_private_accounts: DefaultPrivateAccountsMap, + pub default_user_private_accounts: BTreeMap, /// Tree of public keys. pub public_key_tree: KeyTreePublic, /// Tree of private keys. @@ -44,12 +49,12 @@ impl NSSAUserData { } fn valid_private_key_transaction_pairing_check( - accounts_keys_map: &DefaultPrivateAccountsMap, + accounts_keys_map: &BTreeMap, ) -> bool { let mut check_res = true; - for (account_id, (key, entries)) in accounts_keys_map { - let any_match = entries.iter().any(|(identifier, _)| { - nssa::AccountId::from((&key.nullifier_public_key, *identifier)) == *account_id + for (account_id, entry) in accounts_keys_map { + let any_match = entry.accounts.iter().any(|(identifier, _)| { + nssa::AccountId::from((&entry.key_chain.nullifier_public_key, *identifier)) == *account_id }); if !any_match { println!("No matching entry found for account_id {account_id}"); @@ -61,7 +66,7 @@ impl NSSAUserData { pub fn new_with_accounts( default_accounts_keys: BTreeMap, - default_accounts_key_chains: DefaultPrivateAccountsMap, + default_accounts_key_chains: BTreeMap, public_key_tree: KeyTreePublic, private_key_tree: KeyTreePrivate, ) -> Result { @@ -148,12 +153,12 @@ impl NSSAUserData { account_id: nssa::AccountId, ) -> Option<(KeyChain, nssa_core::account::Account, Identifier)> { // Check default accounts - if let Some((key_chain, entries)) = self.default_user_private_accounts.get(&account_id) { - for (identifier, account) in entries { + if let Some(entry) = self.default_user_private_accounts.get(&account_id) { + for (identifier, account) in &entry.accounts { let expected_id = - nssa::AccountId::from((&key_chain.nullifier_public_key, *identifier)); + nssa::AccountId::from((&entry.key_chain.nullifier_public_key, *identifier)); if expected_id == account_id { - return Some((key_chain.clone(), account.clone(), *identifier)); + return Some((entry.key_chain.clone(), account.clone(), *identifier)); } } return None;