diff --git a/integration_tests/tests/shared_accounts.rs b/integration_tests/tests/shared_accounts.rs index ecf3a4b4..c5d937e0 100644 --- a/integration_tests/tests/shared_accounts.rs +++ b/integration_tests/tests/shared_accounts.rs @@ -55,6 +55,7 @@ async fn group_create_and_shared_account_registration() -> Result<()> { pda: false, seed: None, program_id: None, + identifier: None, })); let result = wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -170,6 +171,7 @@ async fn fund_shared_account_from_public() -> Result<()> { pda: false, seed: None, program_id: None, + identifier: None, })); let result = wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; let SubcommandReturnValue::RegisterAccount { diff --git a/wallet/src/cli/account.rs b/wallet/src/cli/account.rs index 0e12e9a5..cb8f28b0 100644 --- a/wallet/src/cli/account.rs +++ b/wallet/src/cli/account.rs @@ -108,6 +108,10 @@ pub enum NewSubcommand { #[arg(long, requires = "pda")] /// Program ID as hex string. program_id: Option, + #[arg(long, requires = "pda")] + /// Identifier that diversifies this PDA within the (program_id, seed, npk) family. + /// Defaults to a random value if not specified. + identifier: Option, }, /// Recommended for receiving from multiple senders: creates a key node (npk + vpk) without /// registering any account. @@ -208,6 +212,7 @@ impl WalletSubcommand for NewSubcommand { pda, seed, program_id, + identifier, } => { if let Some(label) = &label && wallet_core @@ -239,7 +244,12 @@ impl WalletSubcommand for NewSubcommand { pid[i] = u32::from_le_bytes(chunk.try_into().unwrap()); } - wallet_core.create_shared_pda_account(&group, pda_seed, pid)? + wallet_core.create_shared_pda_account( + &group, + pda_seed, + pid, + identifier.unwrap_or_else(rand::random), + )? } else { wallet_core.create_shared_regular_account(&group)? }; diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index 3f36126a..24ac19b9 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -409,6 +409,7 @@ impl WalletCore { group_name: &str, pda_seed: nssa_core::program::PdaSeed, program_id: nssa_core::program::ProgramId, + identifier: nssa_core::Identifier, ) -> Result { let holder = self .storage @@ -419,12 +420,12 @@ impl WalletCore { let keys = holder.derive_keys_for_pda(&program_id, &pda_seed); let npk = keys.generate_nullifier_public_key(); let vpk = keys.generate_viewing_public_key(); - let account_id = AccountId::for_private_pda(&program_id, &pda_seed, &npk, u128::MAX); + let account_id = AccountId::for_private_pda(&program_id, &pda_seed, &npk, identifier); self.register_shared_account( account_id, String::from(group_name), - u128::MAX, + identifier, Some(pda_seed), Some(program_id), ); @@ -793,7 +794,7 @@ impl WalletCore { let shared_secret = SharedSecretKey::new(&vsk, &encrypted_data.epk); let commitment = &tx.message.new_commitments[ciph_id]; - if let Some((_decrypted_identifier, new_acc)) = nssa_core::EncryptionScheme::decrypt( + if let Some((_kind, new_acc)) = nssa_core::EncryptionScheme::decrypt( &encrypted_data.ciphertext, &shared_secret, commitment,