Merge branch 'Pravdyvy/token-program-private' into Pravdyvy/various-updates

This commit is contained in:
Oleksandr Pravdyvyi 2025-10-15 15:32:15 +03:00
commit 5f00c89c0a
No known key found for this signature in database
GPG Key ID: 9F8955C63C443871
5 changed files with 35 additions and 40 deletions

View File

@ -92,16 +92,17 @@ impl WalletSubcommand for PinataProgramSubcommandPrivate {
let pinata_addr = pinata_addr.parse().unwrap();
let winner_addr = winner_addr.parse().unwrap();
let winner_intialized = wallet_core
let winner_initialization = wallet_core
.check_private_account_initialized(&winner_addr)
.await;
.await?;
let (res, [secret_winner]) = if winner_intialized {
let (res, [secret_winner]) = if let Some(winner_proof) = winner_initialization {
wallet_core
.claim_pinata_private_owned_account_already_initialized(
pinata_addr,
winner_addr,
solution,
winner_proof
)
.await?
} else {

View File

@ -188,27 +188,29 @@ impl WalletSubcommand for TokenProgramSubcommandPrivate {
let sender_addr: Address = sender_addr.parse().unwrap();
let recipient_addr: Address = recipient_addr.parse().unwrap();
let recipient_initialized = wallet_core
let recipient_initialization = wallet_core
.check_private_account_initialized(&recipient_addr)
.await;
.await?;
let (res, [secret_sender, secret_recipient]) = if recipient_initialized {
wallet_core
let (res, [secret_sender, secret_recipient]) =
if let Some(recipient_proof) = recipient_initialization {
wallet_core
.send_transfer_token_transaction_private_owned_account_already_initialized(
sender_addr,
recipient_addr,
balance_to_move,
recipient_proof,
)
.await?
} else {
wallet_core
.send_transfer_token_transaction_private_owned_account_not_initialized(
sender_addr,
recipient_addr,
balance_to_move,
)
.await?
};
} else {
wallet_core
.send_transfer_token_transaction_private_owned_account_not_initialized(
sender_addr,
recipient_addr,
balance_to_move,
)
.await?
};
println!("Results of tx send is {res:#?}");

View File

@ -14,7 +14,7 @@ use log::info;
use nssa::{Account, Address, privacy_preserving_transaction::message::EncryptedAccountData};
use clap::{Parser, Subcommand};
use nssa_core::Commitment;
use nssa_core::{Commitment, MembershipProof};
use crate::cli::{
WalletSubcommand, chain::ChainSubcommand,
@ -139,16 +139,17 @@ impl WalletCore {
Ok(NSSATransaction::try_from(&pub_tx)?)
}
pub async fn check_private_account_initialized(&self, addr: &Address) -> bool {
pub async fn check_private_account_initialized(
&self,
addr: &Address,
) -> Result<Option<MembershipProof>> {
if let Some(acc_comm) = self.get_private_account_commitment(addr) {
matches!(
self.sequencer_client
.get_proof_for_commitment(acc_comm)
.await,
Ok(Some(_))
)
self.sequencer_client
.get_proof_for_commitment(acc_comm)
.await
.map_err(anyhow::Error::from)
} else {
false
Ok(None)
}
}

View File

@ -1,7 +1,7 @@
use common::{ExecutionFailureKind, sequencer_client::json::SendTxResponse};
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
use nssa::{Address, privacy_preserving_transaction::circuit};
use nssa_core::{Commitment, SharedSecretKey, account::AccountWithMetadata};
use nssa_core::{MembershipProof, SharedSecretKey, account::AccountWithMetadata};
use crate::{WalletCore, helperfunctions::produce_random_nonces};
@ -29,6 +29,7 @@ impl WalletCore {
pinata_addr: Address,
winner_addr: Address,
solution: u128,
winner_proof: MembershipProof,
) -> Result<(SendTxResponse, [SharedSecretKey; 1]), ExecutionFailureKind> {
let Some((winner_keys, winner_acc)) = self
.storage
@ -46,8 +47,6 @@ impl WalletCore {
let program = nssa::program::Program::pinata();
let winner_commitment = Commitment::new(&winner_npk, &winner_acc);
let pinata_pre = AccountWithMetadata::new(pinata_acc.clone(), false, pinata_addr);
let winner_pre = AccountWithMetadata::new(winner_acc.clone(), true, &winner_npk);
@ -62,11 +61,7 @@ impl WalletCore {
&[(winner_npk.clone(), shared_secret_winner.clone())],
&[(
winner_keys.private_key_holder.nullifier_secret_key,
self.sequencer_client
.get_proof_for_commitment(winner_commitment)
.await
.unwrap()
.unwrap(),
winner_proof,
)],
&program,
)

View File

@ -2,7 +2,7 @@ use common::{ExecutionFailureKind, sequencer_client::json::SendTxResponse};
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
use nssa::{Address, privacy_preserving_transaction::circuit, program::Program};
use nssa_core::{
Commitment, NullifierPublicKey, SharedSecretKey, account::AccountWithMetadata,
Commitment, MembershipProof, NullifierPublicKey, SharedSecretKey, account::AccountWithMetadata,
encryption::IncomingViewingPublicKey,
};
@ -146,6 +146,7 @@ impl WalletCore {
sender_address: Address,
recipient_address: Address,
amount: u128,
recipient_proof: MembershipProof,
) -> Result<(SendTxResponse, [SharedSecretKey; 2]), ExecutionFailureKind> {
let Some((sender_keys, sender_acc)) = self
.storage
@ -173,7 +174,6 @@ impl WalletCore {
let program = Program::token();
let sender_commitment = Commitment::new(&sender_npk, &sender_acc);
let receiver_commitment = Commitment::new(&recipient_npk, &recipient_acc);
let sender_pre = AccountWithMetadata::new(sender_acc.clone(), true, &sender_npk);
let recipient_pre = AccountWithMetadata::new(recipient_acc.clone(), true, &recipient_npk);
@ -210,11 +210,7 @@ impl WalletCore {
),
(
recipient_keys.private_key_holder.nullifier_secret_key,
self.sequencer_client
.get_proof_for_commitment(receiver_commitment)
.await
.unwrap()
.unwrap(),
recipient_proof,
),
],
&program,