rollback and remove identifier arguments in new private account wallet command

This commit is contained in:
Sergio Chouhy
2026-04-17 14:26:50 -03:00
parent f28ac0f092
commit b34e301023
6 changed files with 67 additions and 70 deletions
+22 -17
View File
@@ -2,6 +2,7 @@ use std::collections::BTreeMap;
use anyhow::Result;
use nssa::{Account, AccountId};
use nssa_core::Identifier;
use serde::{Deserialize, Serialize};
use crate::key_management::{
@@ -255,26 +256,30 @@ impl KeyTree<ChildKeysPublic> {
}
impl KeyTree<ChildKeysPrivate> {
/// Generate a new private key node, registering the identifier=0 account_id immediately.
pub fn generate_new_private_node(
&mut self,
parent_cci: &ChainIndex,
) -> Option<(nssa::AccountId, ChainIndex)> {
let cci = self.generate_new_node(parent_cci)?;
let node = self.key_map.get(&cci)?;
let account_id = nssa::AccountId::from((&node.value.0.nullifier_public_key, 0_u128));
self.account_id_map.insert(account_id, cci.clone());
Some((account_id, cci))
pub fn generate_new_private_node(&mut self, parent_cci: &ChainIndex) -> Option<ChainIndex> {
self.generate_new_node(parent_cci)
}
/// Generate a new private key node using layered placement, registering the identifier=0
/// account_id immediately.
pub fn generate_new_private_node_layered(&mut self) -> Option<(nssa::AccountId, ChainIndex)> {
let cci = self.generate_new_node_layered()?;
let node = self.key_map.get(&cci)?;
let account_id = nssa::AccountId::from((&node.value.0.nullifier_public_key, 0_u128));
pub fn generate_new_private_node_layered(&mut self) -> Option<ChainIndex> {
self.generate_new_node_layered()
}
/// Register an additional identifier on an existing private key node, inserting the derived
/// `AccountId` into `account_id_map`. Returns `None` if the node does not exist or the
/// `AccountId` is already registered.
pub fn register_identifier_on_node(
&mut self,
cci: &ChainIndex,
identifier: Identifier,
) -> Option<nssa::AccountId> {
let node = self.key_map.get(cci)?;
let account_id =
nssa::AccountId::from((&node.value.0.nullifier_public_key, identifier));
if self.account_id_map.contains_key(&account_id) {
return None;
}
self.account_id_map.insert(account_id, cci.clone());
Some((account_id, cci))
Some(account_id)
}
/// Cleanup of non-initialized accounts in a private tree.
+15 -9
View File
@@ -121,13 +121,11 @@ impl NSSAUserData {
.or_else(|| self.public_key_tree.get_node(account_id).map(Into::into))
}
/// Generated new private key for privacy preserving transactions.
///
/// Returns the `AccountId` (for identifier=0) and `ChainIndex` of the new node.
/// Generates a new private key node and returns its `ChainIndex`.
pub fn generate_new_privacy_preserving_transaction_key_chain(
&mut self,
parent_cci: Option<ChainIndex>,
) -> (nssa::AccountId, ChainIndex) {
) -> ChainIndex {
match parent_cci {
Some(parent_cci) => self
.private_key_tree
@@ -140,6 +138,18 @@ impl NSSAUserData {
}
}
/// Registers an additional identifier on an existing private key node, deriving and recording
/// the corresponding `AccountId`. Returns `None` if the node does not exist or the identifier
/// is already registered.
pub fn register_identifier_on_private_key_chain(
&mut self,
cci: ChainIndex,
identifier: Identifier,
) -> Option<nssa::AccountId> {
self.private_key_tree
.register_identifier_on_node(&cci, identifier)
}
/// Returns the key chain and account data for the given private account ID.
#[must_use]
pub fn get_private_account(
@@ -211,16 +221,12 @@ mod tests {
fn new_account() {
let mut user_data = NSSAUserData::default();
let (account_id, chain_index) = user_data
let chain_index = user_data
.generate_new_privacy_preserving_transaction_key_chain(Some(ChainIndex::root()));
let is_key_chain_generated = user_data.private_key_tree.key_map.contains_key(&chain_index);
assert!(is_key_chain_generated);
let is_account_id_registered =
user_data.private_key_tree.account_id_map.contains_key(&account_id);
assert!(is_account_id_registered);
let key_chain = &user_data.private_key_tree.key_map[&chain_index].value.0;
println!("{key_chain:#?}");
}