From deccbc3ac03088cb42f124ebb97db54f5ed7d788 Mon Sep 17 00:00:00 2001 From: jonesmarvin8 <83104039+jonesmarvin8@users.noreply.github.com> Date: Mon, 20 Apr 2026 17:33:55 -0400 Subject: [PATCH] initialize changes --- key_protocol/src/key_protocol_core/mod.rs | 8 +++++--- .../witness_set.rs | 2 ++ nssa/src/public_transaction/witness_set.rs | 19 +++++++++++++++++++ wallet/src/chain_storage.rs | 6 +++--- wallet/src/config.rs | 2 +- wallet/src/helperfunctions.rs | 2 +- 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/key_protocol/src/key_protocol_core/mod.rs b/key_protocol/src/key_protocol_core/mod.rs index 8186865f..58d2d15a 100644 --- a/key_protocol/src/key_protocol_core/mod.rs +++ b/key_protocol/src/key_protocol_core/mod.rs @@ -15,6 +15,7 @@ pub type PublicKey = AffinePoint; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct NSSAUserData { /// Default public accounts. + /// TODO: it appears this is unnecessary pub default_pub_account_signing_keys: BTreeMap, /// Default private accounts. pub default_user_private_accounts: @@ -32,7 +33,7 @@ impl NSSAUserData { let mut check_res = true; for (account_id, key) in accounts_keys_map { let expected_account_id = - nssa::AccountId::from(&nssa::PublicKey::new_from_private_key(key)); + nssa::AccountId::from(&nssa::PublicKey::new_from_private_key(&key)); if &expected_account_id != account_id { println!("{expected_account_id}, {account_id}"); check_res = false; @@ -55,6 +56,7 @@ impl NSSAUserData { check_res } + // Default only? (Marvin) pub fn new_with_accounts( default_accounts_keys: BTreeMap, default_accounts_key_chains: BTreeMap< @@ -64,7 +66,7 @@ impl NSSAUserData { public_key_tree: KeyTreePublic, private_key_tree: KeyTreePrivate, ) -> Result { - if !Self::valid_public_key_transaction_pairing_check(&default_accounts_keys) { + if !Self::valid_public_key_transaction_pairing_check(&default_accounts_keys) { // TODO: modified not to use default_pub... (Marvin) anyhow::bail!( "Key transaction pairing check not satisfied, there are public account_ids, which are not derived from keys" ); @@ -112,7 +114,7 @@ impl NSSAUserData { self.default_pub_account_signing_keys .get(&account_id) .or_else(|| self.public_key_tree.get_node(account_id).map(Into::into)) - } + } // TODO: dependent on whether keycard is not; part I care about is get-node() (Marvin) /// Generated new private key for privacy preserving transactions. /// diff --git a/nssa/src/privacy_preserving_transaction/witness_set.rs b/nssa/src/privacy_preserving_transaction/witness_set.rs index 373bbc9c..cdd57f88 100644 --- a/nssa/src/privacy_preserving_transaction/witness_set.rs +++ b/nssa/src/privacy_preserving_transaction/witness_set.rs @@ -13,6 +13,8 @@ pub struct WitnessSet { impl WitnessSet { #[must_use] + // TODO: this generates signatures. + // However. we may need to get signatures from Keycard. pub fn for_message(message: &Message, proof: Proof, private_keys: &[&PrivateKey]) -> Self { let message_bytes = message.to_bytes(); let signatures_and_public_keys = private_keys diff --git a/nssa/src/public_transaction/witness_set.rs b/nssa/src/public_transaction/witness_set.rs index d6b32891..03ecc905 100644 --- a/nssa/src/public_transaction/witness_set.rs +++ b/nssa/src/public_transaction/witness_set.rs @@ -8,6 +8,25 @@ pub struct WitnessSet { } impl WitnessSet { + #[must_use] + pub fn from_list(signatures: &[Signature], pub_keys: &[PublicKey]) -> Self { + assert_eq!(signatures.len(), pub_keys.len()); + + let signatures_and_public_keys = signatures + .iter() + .zip( pub_keys.iter()) + .map(|(sig,key)| { + ( + sig.clone(), key.clone() + ) + }) + .collect(); + + Self { + signatures_and_public_keys, + } + } + #[must_use] pub fn for_message(message: &Message, private_keys: &[&PrivateKey]) -> Self { let message_bytes = message.to_bytes(); diff --git a/wallet/src/chain_storage.rs b/wallet/src/chain_storage.rs index 3699609b..a7bc3dab 100644 --- a/wallet/src/chain_storage.rs +++ b/wallet/src/chain_storage.rs @@ -56,7 +56,7 @@ impl WalletChainStore { .expect("Malformed persistent account data, must have private root"); let mut public_tree = KeyTreePublic::new_from_root(match public_root { - PersistentAccountData::Public(data) => data.data, + PersistentAccountData::Public(data) => data.data.expect("Expect valid public account keys"), //TODO: Marvin _ => unreachable!(), }); let mut private_tree = KeyTreePrivate::new_from_root(match private_root { @@ -67,7 +67,7 @@ impl WalletChainStore { for pers_acc_data in persistent_accounts { match pers_acc_data { PersistentAccountData::Public(data) => { - public_tree.insert(data.account_id, data.chain_index, data.data); + public_tree.insert(data.account_id, data.chain_index, data.data.expect("Expect valid public account keys")); //TODO: Marvin } PersistentAccountData::Private(data) => { private_tree.insert(data.account_id, data.chain_index, data.data); @@ -225,7 +225,7 @@ mod tests { PersistentAccountData::Public(PersistentAccountDataPublic { account_id: public_data.account_id(), chain_index: ChainIndex::root(), - data: public_data, + data: Some(public_data), }), PersistentAccountData::Private(Box::new(PersistentAccountDataPrivate { account_id: private_data.account_id(), diff --git a/wallet/src/config.rs b/wallet/src/config.rs index 33527009..4c008979 100644 --- a/wallet/src/config.rs +++ b/wallet/src/config.rs @@ -23,7 +23,7 @@ use url::Url; pub struct PersistentAccountDataPublic { pub account_id: nssa::AccountId, pub chain_index: ChainIndex, - pub data: ChildKeysPublic, + pub data: Option, // `None` when Keycard is used. } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/wallet/src/helperfunctions.rs b/wallet/src/helperfunctions.rs index 37a27409..3e304253 100644 --- a/wallet/src/helperfunctions.rs +++ b/wallet/src/helperfunctions.rs @@ -158,7 +158,7 @@ pub fn produce_data_for_storage( PersistentAccountDataPublic { account_id: *account_id, chain_index: key.clone(), - data: data.clone(), + data: Some(data.clone()), } .into(), );