From e3764e1911aea3b8dedb73ac1c2292d10f72149e Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Thu, 5 Mar 2026 12:35:18 +0200 Subject: [PATCH 1/6] fix: shared secret receiver fix --- .../key_management/key_tree/chain_index.rs | 4 + key_protocol/src/key_management/mod.rs | 7 +- nssa/core/src/encryption/mod.rs | 13 +- wallet/src/lib.rs | 249 ++++++++++++++++-- 4 files changed, 254 insertions(+), 19 deletions(-) diff --git a/key_protocol/src/key_management/key_tree/chain_index.rs b/key_protocol/src/key_management/key_tree/chain_index.rs index 6dbaf9a9..d5fbf401 100644 --- a/key_protocol/src/key_management/key_tree/chain_index.rs +++ b/key_protocol/src/key_management/key_tree/chain_index.rs @@ -68,6 +68,10 @@ impl ChainIndex { &self.0 } + pub fn index(&self) -> Option { + self.chain().last().copied() + } + pub fn next_in_line(&self) -> ChainIndex { let mut chain = self.0.clone(); // ToDo: Add overflow check diff --git a/key_protocol/src/key_management/mod.rs b/key_protocol/src/key_management/mod.rs index d46dcf35..31848f4c 100644 --- a/key_protocol/src/key_management/mod.rs +++ b/key_protocol/src/key_management/mod.rs @@ -62,9 +62,10 @@ impl KeyChain { pub fn calculate_shared_secret_receiver( &self, ephemeral_public_key_sender: EphemeralPublicKey, + index: Option, ) -> SharedSecretKey { SharedSecretKey::new( - &self.secret_spending_key.generate_viewing_secret_key(None), + &self.secret_spending_key.generate_viewing_secret_key(index), &ephemeral_public_key_sender, ) } @@ -101,8 +102,8 @@ mod tests { let ephemeral_public_key_sender = EphemeralPublicKey::from_scalar(scalar); // Calculate shared secret - let _shared_secret = - account_id_key_holder.calculate_shared_secret_receiver(ephemeral_public_key_sender); + let _shared_secret = account_id_key_holder + .calculate_shared_secret_receiver(ephemeral_public_key_sender, None); } #[test] diff --git a/nssa/core/src/encryption/mod.rs b/nssa/core/src/encryption/mod.rs index 9ccbf2c8..4817d3c8 100644 --- a/nssa/core/src/encryption/mod.rs +++ b/nssa/core/src/encryption/mod.rs @@ -75,6 +75,17 @@ impl EncryptionScheme { Self::symmetric_transform(&mut buffer, shared_secret, commitment, output_index); let mut cursor = Cursor::new(buffer.as_slice()); - Account::from_cursor(&mut cursor).ok() + Account::from_cursor(&mut cursor) + .inspect_err(|err| { + println!( + "Failed to decode {ciphertext:?} \n + with secret {:?} ,\n + commitment {commitment:?} ,\n + and output_index {output_index} ,\n + with error {err:?}", + shared_secret.0 + ) + }) + .ok() } } diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index 0162dcb1..f3755b0b 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -363,11 +363,24 @@ impl WalletCore { ); let tx = PrivacyPreservingTransaction::new(message, witness_set); - let shared_secrets = private_account_keys + let shared_secrets: Vec<_> = private_account_keys .into_iter() .map(|keys| keys.ssk) .collect(); + // ["dbfa57c178c287057c94f2fa8caaf78649d1dcac8d4eec0759264a22ebc788b4", + // "e3aa7298c9cc409f001e425caf139d0f5d627201fa60c0868d68f200c9044825"] + // ["dbfa57c178c287057c94f2fa8caaf78649d1dcac8d4eec0759264a22ebc788b4", + // "17a5070917903d5213db9ce9442ba472d8682af318fb5369e5c784c3980cacc9"] + + info!( + "shared secrets is {:?}", + shared_secrets + .iter() + .map(|secret| hex::encode(secret.0)) + .collect::>() + ); + Ok(( self.sequencer_client.send_tx_private(tx).await?, shared_secrets, @@ -419,18 +432,19 @@ impl WalletCore { .user_data .default_user_private_accounts .iter() - .map(|(acc_account_id, (key_chain, _))| (*acc_account_id, key_chain)) - .chain( - self.storage - .user_data - .private_key_tree - .key_map - .values() - .map(|keys_node| (keys_node.account_id(), &keys_node.value.0)), - ); + .map(|(acc_account_id, (key_chain, _))| (*acc_account_id, key_chain, None)) + .chain(self.storage.user_data.private_key_tree.key_map.iter().map( + |(chain_index, keys_node)| { + ( + keys_node.account_id(), + &keys_node.value.0, + chain_index.index(), + ) + }, + )); let affected_accounts = private_account_key_chains - .flat_map(|(acc_account_id, key_chain)| { + .flat_map(|(acc_account_id, key_chain, index)| { let view_tag = EncryptedAccountData::compute_view_tag( key_chain.nullifer_public_key.clone(), key_chain.viewing_public_key.clone(), @@ -444,17 +458,20 @@ impl WalletCore { .filter_map(|(ciph_id, encrypted_data)| { let ciphertext = &encrypted_data.ciphertext; let commitment = &tx.message.new_commitments[ciph_id]; - let shared_secret = - key_chain.calculate_shared_secret_receiver(encrypted_data.epk.clone()); + let shared_secret = key_chain + .calculate_shared_secret_receiver(encrypted_data.epk.clone(), index); - nssa_core::EncryptionScheme::decrypt( + let res = nssa_core::EncryptionScheme::decrypt( ciphertext, &shared_secret, commitment, ciph_id as u32, - ) + ); + + res }) .map(move |res_acc| (acc_account_id, res_acc)) + .collect::>() }) .collect::>(); @@ -479,3 +496,205 @@ impl WalletCore { &self.config_overrides } } + +#[cfg(test)] +mod tests { + use key_protocol::key_management::{KeyChain, ephemeral_key_holder::EphemeralKeyHolder}; + + fn account_for_tests() -> KeyChain { + let key_chain_raw = r#" + { + "secret_spending_key": [ + 208, + 155, + 82, + 128, + 101, + 206, + 20, + 95, + 241, + 147, + 159, + 231, + 207, + 78, + 152, + 28, + 114, + 111, + 61, + 69, + 254, + 51, + 242, + 28, + 28, + 195, + 170, + 242, + 160, + 24, + 47, + 189 + ], + "private_key_holder": { + "nullifier_secret_key": [ + 142, + 76, + 154, + 157, + 42, + 40, + 174, + 199, + 151, + 63, + 2, + 216, + 52, + 103, + 81, + 42, + 200, + 177, + 189, + 49, + 81, + 39, + 166, + 139, + 203, + 154, + 156, + 166, + 88, + 159, + 11, + 151 + ], + "viewing_secret_key": [ + 122, + 94, + 159, + 21, + 28, + 49, + 169, + 79, + 12, + 156, + 171, + 90, + 41, + 216, + 203, + 75, + 251, + 192, + 204, + 217, + 18, + 49, + 28, + 219, + 213, + 147, + 244, + 194, + 205, + 237, + 134, + 36 + ] + }, + "nullifer_public_key": [ + 235, + 24, + 62, + 99, + 243, + 236, + 137, + 35, + 153, + 149, + 6, + 10, + 118, + 239, + 117, + 188, + 64, + 8, + 33, + 52, + 220, + 231, + 11, + 39, + 180, + 117, + 1, + 22, + 62, + 199, + 164, + 169 + ], + "viewing_public_key": [ + 2, + 253, + 204, + 5, + 212, + 86, + 249, + 156, + 132, + 143, + 1, + 172, + 80, + 61, + 18, + 185, + 233, + 36, + 221, + 58, + 64, + 110, + 89, + 242, + 202, + 230, + 154, + 66, + 45, + 252, + 138, + 174, + 37 + ] + } + "#; + + serde_json::from_str(key_chain_raw).unwrap() + } + + #[test] + fn test_1() { + let keys = account_for_tests(); + + let eph_key_holder = EphemeralKeyHolder::new(&keys.nullifer_public_key); + + let key_sender = eph_key_holder.calculate_shared_secret_sender(&keys.viewing_public_key); + let key_receiver = keys.calculate_shared_secret_receiver( + eph_key_holder.generate_ephemeral_public_key(), + Some(2), + ); + + assert_eq!(key_sender.0, key_receiver.0); + } +} From cb57baaa36782a0910e9bd030d972a1f741ec24a Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Thu, 5 Mar 2026 14:13:13 +0200 Subject: [PATCH 2/6] fix: integartion test on claiming path for token updated --- integration_tests/tests/token.rs | 15 +++++++++++++++ wallet/src/lib.rs | 6 ++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/integration_tests/tests/token.rs b/integration_tests/tests/token.rs index 0ff6eee5..bcd63556 100644 --- a/integration_tests/tests/token.rs +++ b/integration_tests/tests/token.rs @@ -1087,6 +1087,21 @@ async fn token_claiming_path_with_private_accounts() -> Result<()> { info!("Waiting for next block creation"); tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await; + // Key Tree shift + // This way we have account with child index > 0. + // Shared secret derivation dependant of child index, so this way we can test it as well. + let result = wallet::cli::execute_subcommand( + ctx.wallet_mut(), + Command::Account(AccountSubcommand::New(NewSubcommand::Private { + cci: None, + label: None, + })), + ) + .await?; + let SubcommandReturnValue::RegisterAccount { account_id: _ } = result else { + anyhow::bail!("Expected RegisterAccount return value"); + }; + // Create new private account for claiming path let result = wallet::cli::execute_subcommand( ctx.wallet_mut(), diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index f3755b0b..486133d8 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -461,14 +461,12 @@ impl WalletCore { let shared_secret = key_chain .calculate_shared_secret_receiver(encrypted_data.epk.clone(), index); - let res = nssa_core::EncryptionScheme::decrypt( + nssa_core::EncryptionScheme::decrypt( ciphertext, &shared_secret, commitment, ciph_id as u32, - ); - - res + ) }) .map(move |res_acc| (acc_account_id, res_acc)) .collect::>() From cf921577283ef347da32328791c261d0354f5d8c Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Thu, 5 Mar 2026 14:41:52 +0200 Subject: [PATCH 3/6] fix: artifacts updates --- .../privacy_preserving_circuit.bin | Bin 512604 -> 512604 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/artifacts/program_methods/privacy_preserving_circuit.bin b/artifacts/program_methods/privacy_preserving_circuit.bin index 3a0330e6e4e26bacee2773aed5b45fa65c3ffcf3..5b854dca3b04e277e86c956034b495e17da57bdf 100644 GIT binary patch delta 225 zcmcb!ME=ea`Gyw87N!>F7M2#)Eo|Deh0IONjZ7^qjZF=W&CSe=jLj^z+s;Jrhig(+yX$X>6BS#rB#Ln{J@2`gVscY)84U$%4$DZnvL}1Dj;T Yezqyt#2J~{mD&{!ux(d3z-}W106O(M)Bpeg delta 225 zcmcb!ME=ea`Gyw87N!>F7M2#)Eo|Deg)A%#3=J(T%#6$p%?wNpj4h0|+s;Jrhig(+yX$X>6BS#rB#Ln{J@2`gVscY)84U$%4$DZnvL}1Dj;T Yezqyt#2J~{mD&{!ux(d3z-}W100X%@PXGV_ From fa406e7a864261361b147f1326f01f91ae7be60f Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Thu, 5 Mar 2026 15:20:22 +0200 Subject: [PATCH 4/6] fix: removed redundant logging --- Cargo.lock | 1 + key_protocol/Cargo.toml | 1 + key_protocol/src/key_management/mod.rs | 198 +++++++++++++++++++++++ wallet/src/lib.rs | 215 ------------------------- 4 files changed, 200 insertions(+), 215 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 33f810e0..e2340e3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4253,6 +4253,7 @@ dependencies = [ "rand 0.8.5", "secp256k1", "serde", + "serde_json", "sha2", "thiserror 2.0.18", ] diff --git a/key_protocol/Cargo.toml b/key_protocol/Cargo.toml index 0a5e9e9a..c45671aa 100644 --- a/key_protocol/Cargo.toml +++ b/key_protocol/Cargo.toml @@ -23,3 +23,4 @@ bip39.workspace = true hmac-sha512.workspace = true thiserror.workspace = true itertools.workspace = true +serde_json.workspace = true diff --git a/key_protocol/src/key_management/mod.rs b/key_protocol/src/key_management/mod.rs index 31848f4c..b99e437d 100644 --- a/key_protocol/src/key_management/mod.rs +++ b/key_protocol/src/key_management/mod.rs @@ -79,6 +79,7 @@ mod tests { use rand::RngCore; use super::*; + use crate::key_management::ephemeral_key_holder::EphemeralKeyHolder; #[test] fn test_new_os_random() { @@ -151,4 +152,201 @@ mod tests { hex::encode(viewing_public_key.to_bytes()) ); } + + fn account_with_chain_index_2_for_tests() -> KeyChain { + let key_chain_raw = r#" + { + "secret_spending_key": [ + 208, + 155, + 82, + 128, + 101, + 206, + 20, + 95, + 241, + 147, + 159, + 231, + 207, + 78, + 152, + 28, + 114, + 111, + 61, + 69, + 254, + 51, + 242, + 28, + 28, + 195, + 170, + 242, + 160, + 24, + 47, + 189 + ], + "private_key_holder": { + "nullifier_secret_key": [ + 142, + 76, + 154, + 157, + 42, + 40, + 174, + 199, + 151, + 63, + 2, + 216, + 52, + 103, + 81, + 42, + 200, + 177, + 189, + 49, + 81, + 39, + 166, + 139, + 203, + 154, + 156, + 166, + 88, + 159, + 11, + 151 + ], + "viewing_secret_key": [ + 122, + 94, + 159, + 21, + 28, + 49, + 169, + 79, + 12, + 156, + 171, + 90, + 41, + 216, + 203, + 75, + 251, + 192, + 204, + 217, + 18, + 49, + 28, + 219, + 213, + 147, + 244, + 194, + 205, + 237, + 134, + 36 + ] + }, + "nullifer_public_key": [ + 235, + 24, + 62, + 99, + 243, + 236, + 137, + 35, + 153, + 149, + 6, + 10, + 118, + 239, + 117, + 188, + 64, + 8, + 33, + 52, + 220, + 231, + 11, + 39, + 180, + 117, + 1, + 22, + 62, + 199, + 164, + 169 + ], + "viewing_public_key": [ + 2, + 253, + 204, + 5, + 212, + 86, + 249, + 156, + 132, + 143, + 1, + 172, + 80, + 61, + 18, + 185, + 233, + 36, + 221, + 58, + 64, + 110, + 89, + 242, + 202, + 230, + 154, + 66, + 45, + 252, + 138, + 174, + 37 + ] + } + "#; + + serde_json::from_str(key_chain_raw).unwrap() + } + + #[test] + fn test_non_trivial_chain_index() { + let keys = account_with_chain_index_2_for_tests(); + + let eph_key_holder = EphemeralKeyHolder::new(&keys.nullifer_public_key); + + let key_sender = eph_key_holder.calculate_shared_secret_sender(&keys.viewing_public_key); + let key_receiver = keys.calculate_shared_secret_receiver( + eph_key_holder.generate_ephemeral_public_key(), + Some(2), + ); + + assert_eq!(key_sender.0, key_receiver.0); + } } diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index 486133d8..8d8924cf 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -368,19 +368,6 @@ impl WalletCore { .map(|keys| keys.ssk) .collect(); - // ["dbfa57c178c287057c94f2fa8caaf78649d1dcac8d4eec0759264a22ebc788b4", - // "e3aa7298c9cc409f001e425caf139d0f5d627201fa60c0868d68f200c9044825"] - // ["dbfa57c178c287057c94f2fa8caaf78649d1dcac8d4eec0759264a22ebc788b4", - // "17a5070917903d5213db9ce9442ba472d8682af318fb5369e5c784c3980cacc9"] - - info!( - "shared secrets is {:?}", - shared_secrets - .iter() - .map(|secret| hex::encode(secret.0)) - .collect::>() - ); - Ok(( self.sequencer_client.send_tx_private(tx).await?, shared_secrets, @@ -494,205 +481,3 @@ impl WalletCore { &self.config_overrides } } - -#[cfg(test)] -mod tests { - use key_protocol::key_management::{KeyChain, ephemeral_key_holder::EphemeralKeyHolder}; - - fn account_for_tests() -> KeyChain { - let key_chain_raw = r#" - { - "secret_spending_key": [ - 208, - 155, - 82, - 128, - 101, - 206, - 20, - 95, - 241, - 147, - 159, - 231, - 207, - 78, - 152, - 28, - 114, - 111, - 61, - 69, - 254, - 51, - 242, - 28, - 28, - 195, - 170, - 242, - 160, - 24, - 47, - 189 - ], - "private_key_holder": { - "nullifier_secret_key": [ - 142, - 76, - 154, - 157, - 42, - 40, - 174, - 199, - 151, - 63, - 2, - 216, - 52, - 103, - 81, - 42, - 200, - 177, - 189, - 49, - 81, - 39, - 166, - 139, - 203, - 154, - 156, - 166, - 88, - 159, - 11, - 151 - ], - "viewing_secret_key": [ - 122, - 94, - 159, - 21, - 28, - 49, - 169, - 79, - 12, - 156, - 171, - 90, - 41, - 216, - 203, - 75, - 251, - 192, - 204, - 217, - 18, - 49, - 28, - 219, - 213, - 147, - 244, - 194, - 205, - 237, - 134, - 36 - ] - }, - "nullifer_public_key": [ - 235, - 24, - 62, - 99, - 243, - 236, - 137, - 35, - 153, - 149, - 6, - 10, - 118, - 239, - 117, - 188, - 64, - 8, - 33, - 52, - 220, - 231, - 11, - 39, - 180, - 117, - 1, - 22, - 62, - 199, - 164, - 169 - ], - "viewing_public_key": [ - 2, - 253, - 204, - 5, - 212, - 86, - 249, - 156, - 132, - 143, - 1, - 172, - 80, - 61, - 18, - 185, - 233, - 36, - 221, - 58, - 64, - 110, - 89, - 242, - 202, - 230, - 154, - 66, - 45, - 252, - 138, - 174, - 37 - ] - } - "#; - - serde_json::from_str(key_chain_raw).unwrap() - } - - #[test] - fn test_1() { - let keys = account_for_tests(); - - let eph_key_holder = EphemeralKeyHolder::new(&keys.nullifer_public_key); - - let key_sender = eph_key_holder.calculate_shared_secret_sender(&keys.viewing_public_key); - let key_receiver = keys.calculate_shared_secret_receiver( - eph_key_holder.generate_ephemeral_public_key(), - Some(2), - ); - - assert_eq!(key_sender.0, key_receiver.0); - } -} From 4950c1277cc3651c4c8bf73b70488d51e9e528a9 Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Thu, 5 Mar 2026 17:25:53 +0200 Subject: [PATCH 5/6] fix: suggestions fix --- integration_tests/tests/keys_restoration.rs | 93 ++++++++- integration_tests/tests/token.rs | 15 -- key_protocol/Cargo.toml | 2 + key_protocol/src/key_management/mod.rs | 199 ++------------------ 4 files changed, 112 insertions(+), 197 deletions(-) diff --git a/integration_tests/tests/keys_restoration.rs b/integration_tests/tests/keys_restoration.rs index 24299a56..1bd207be 100644 --- a/integration_tests/tests/keys_restoration.rs +++ b/integration_tests/tests/keys_restoration.rs @@ -1,9 +1,9 @@ use std::{str::FromStr, time::Duration}; -use anyhow::Result; +use anyhow::{Context, Result}; use integration_tests::{ - TIME_TO_WAIT_FOR_BLOCK_SECONDS, TestContext, format_private_account_id, - format_public_account_id, verify_commitment_is_in_state, + TIME_TO_WAIT_FOR_BLOCK_SECONDS, TestContext, fetch_privacy_preserving_tx, + format_private_account_id, format_public_account_id, verify_commitment_is_in_state, }; use key_protocol::key_management::key_tree::chain_index::ChainIndex; use log::info; @@ -15,6 +15,93 @@ use wallet::cli::{ programs::native_token_transfer::AuthTransferSubcommand, }; +#[test] +async fn sync_private_account_with_non_zero_chain_index() -> Result<()> { + let mut ctx = TestContext::new().await?; + + let from: AccountId = ctx.existing_private_accounts()[0]; + + // Create a new private account + let command = Command::Account(AccountSubcommand::New(NewSubcommand::Private { + cci: None, + label: None, + })); + + for _ in 0..3 { + // Key Tree shift + // This way we have account with child index > 0. + let result = wallet::cli::execute_subcommand( + ctx.wallet_mut(), + Command::Account(AccountSubcommand::New(NewSubcommand::Private { + cci: None, + label: None, + })), + ) + .await?; + let SubcommandReturnValue::RegisterAccount { account_id: _ } = result else { + anyhow::bail!("Expected RegisterAccount return value"); + }; + } + + let sub_ret = wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; + let SubcommandReturnValue::RegisterAccount { + account_id: to_account_id, + } = sub_ret + else { + anyhow::bail!("Expected RegisterAccount return value"); + }; + + // Get the keys for the newly created account + let (to_keys, _) = ctx + .wallet() + .storage() + .user_data + .get_private_account(to_account_id) + .cloned() + .context("Failed to get private account")?; + + // 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), + to: None, + to_npk: Some(hex::encode(to_keys.nullifer_public_key.0)), + to_vpk: Some(hex::encode(to_keys.viewing_public_key.0)), + amount: 100, + }); + + let sub_ret = wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; + let SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash } = sub_ret else { + anyhow::bail!("Expected PrivacyPreservingTransfer return value"); + }; + + let tx = fetch_privacy_preserving_tx(ctx.sequencer_client(), tx_hash).await; + + // Sync the wallet to claim the new account + let command = Command::Account(AccountSubcommand::SyncPrivate {}); + wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; + + let new_commitment1 = ctx + .wallet() + .get_private_account_commitment(from) + .context("Failed to get private account commitment for sender")?; + assert_eq!(tx.message.new_commitments[0], new_commitment1); + + assert_eq!(tx.message.new_commitments.len(), 2); + for commitment in tx.message.new_commitments.into_iter() { + assert!(verify_commitment_is_in_state(commitment, ctx.sequencer_client()).await); + } + + let to_res_acc = ctx + .wallet() + .get_account_private(to_account_id) + .context("Failed to get recipient's private account")?; + assert_eq!(to_res_acc.balance, 100); + + info!("Successfully transferred using claiming path"); + + Ok(()) +} + #[test] async fn restore_keys_from_seed() -> Result<()> { let mut ctx = TestContext::new().await?; diff --git a/integration_tests/tests/token.rs b/integration_tests/tests/token.rs index bcd63556..0ff6eee5 100644 --- a/integration_tests/tests/token.rs +++ b/integration_tests/tests/token.rs @@ -1087,21 +1087,6 @@ async fn token_claiming_path_with_private_accounts() -> Result<()> { info!("Waiting for next block creation"); tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await; - // Key Tree shift - // This way we have account with child index > 0. - // Shared secret derivation dependant of child index, so this way we can test it as well. - let result = wallet::cli::execute_subcommand( - ctx.wallet_mut(), - Command::Account(AccountSubcommand::New(NewSubcommand::Private { - cci: None, - label: None, - })), - ) - .await?; - let SubcommandReturnValue::RegisterAccount { account_id: _ } = result else { - anyhow::bail!("Expected RegisterAccount return value"); - }; - // Create new private account for claiming path let result = wallet::cli::execute_subcommand( ctx.wallet_mut(), diff --git a/key_protocol/Cargo.toml b/key_protocol/Cargo.toml index c45671aa..0f16e21b 100644 --- a/key_protocol/Cargo.toml +++ b/key_protocol/Cargo.toml @@ -23,4 +23,6 @@ bip39.workspace = true hmac-sha512.workspace = true thiserror.workspace = true itertools.workspace = true + +[dev-dependencies] serde_json.workspace = true diff --git a/key_protocol/src/key_management/mod.rs b/key_protocol/src/key_management/mod.rs index b99e437d..6e2891ce 100644 --- a/key_protocol/src/key_management/mod.rs +++ b/key_protocol/src/key_management/mod.rs @@ -79,7 +79,9 @@ mod tests { use rand::RngCore; use super::*; - use crate::key_management::ephemeral_key_holder::EphemeralKeyHolder; + use crate::key_management::{ + ephemeral_key_holder::EphemeralKeyHolder, key_tree::KeyTreePrivate, + }; #[test] fn test_new_os_random() { @@ -154,185 +156,24 @@ mod tests { } fn account_with_chain_index_2_for_tests() -> KeyChain { - let key_chain_raw = r#" - { - "secret_spending_key": [ - 208, - 155, - 82, - 128, - 101, - 206, - 20, - 95, - 241, - 147, - 159, - 231, - 207, - 78, - 152, - 28, - 114, - 111, - 61, - 69, - 254, - 51, - 242, - 28, - 28, - 195, - 170, - 242, - 160, - 24, - 47, - 189 - ], - "private_key_holder": { - "nullifier_secret_key": [ - 142, - 76, - 154, - 157, - 42, - 40, - 174, - 199, - 151, - 63, - 2, - 216, - 52, - 103, - 81, - 42, - 200, - 177, - 189, - 49, - 81, - 39, - 166, - 139, - 203, - 154, - 156, - 166, - 88, - 159, - 11, - 151 - ], - "viewing_secret_key": [ - 122, - 94, - 159, - 21, - 28, - 49, - 169, - 79, - 12, - 156, - 171, - 90, - 41, - 216, - 203, - 75, - 251, - 192, - 204, - 217, - 18, - 49, - 28, - 219, - 213, - 147, - 244, - 194, - 205, - 237, - 134, - 36 - ] - }, - "nullifer_public_key": [ - 235, - 24, - 62, - 99, - 243, - 236, - 137, - 35, - 153, - 149, - 6, - 10, - 118, - 239, - 117, - 188, - 64, - 8, - 33, - 52, - 220, - 231, - 11, - 39, - 180, - 117, - 1, - 22, - 62, - 199, - 164, - 169 - ], - "viewing_public_key": [ - 2, - 253, - 204, - 5, - 212, - 86, - 249, - 156, - 132, - 143, - 1, - 172, - 80, - 61, - 18, - 185, - 233, - 36, - 221, - 58, - 64, - 110, - 89, - 242, - 202, - 230, - 154, - 66, - 45, - 252, - 138, - 174, - 37 - ] - } - "#; + let seed = SeedHolder::new_os_random(); + let mut key_tree_private = KeyTreePrivate::new(&seed); - serde_json::from_str(key_chain_raw).unwrap() + // /0 + key_tree_private.generate_new_node_layered().unwrap(); + // /1 + key_tree_private.generate_new_node_layered().unwrap(); + // /0/0 + key_tree_private.generate_new_node_layered().unwrap(); + // /2 + let (second_child_id, _) = key_tree_private.generate_new_node_layered().unwrap(); + + key_tree_private + .get_node(second_child_id) + .unwrap() + .value + .0 + .clone() } #[test] From 0aec6028f6c90abe7f44622bd1c9de38a352caa4 Mon Sep 17 00:00:00 2001 From: Daniil Polyakov Date: Thu, 5 Mar 2026 21:14:25 +0300 Subject: [PATCH 6/6] fix: remove unused serde_json dev-dependency from key_protocol --- Cargo.lock | 1 - key_protocol/Cargo.toml | 3 --- 2 files changed, 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e2340e3d..33f810e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4253,7 +4253,6 @@ dependencies = [ "rand 0.8.5", "secp256k1", "serde", - "serde_json", "sha2", "thiserror 2.0.18", ] diff --git a/key_protocol/Cargo.toml b/key_protocol/Cargo.toml index 0f16e21b..0a5e9e9a 100644 --- a/key_protocol/Cargo.toml +++ b/key_protocol/Cargo.toml @@ -23,6 +23,3 @@ bip39.workspace = true hmac-sha512.workspace = true thiserror.workspace = true itertools.workspace = true - -[dev-dependencies] -serde_json.workspace = true