relabel ipk to vpk

This commit is contained in:
jonesmarvin8 2026-01-21 17:58:45 -05:00
parent d204f386bb
commit 2c9219bb0f
4 changed files with 84 additions and 84 deletions

View File

@ -13,12 +13,12 @@ pub struct EphemeralKeyHolder {
}
pub fn produce_one_sided_shared_secret_receiver(
ipk: &ViewingPublicKey,
vpk: &ViewingPublicKey,
) -> (SharedSecretKey, EphemeralPublicKey) {
let mut esk = [0; 32];
OsRng.fill_bytes(&mut esk);
(
SharedSecretKey::new(&esk, ipk),
SharedSecretKey::new(&esk, vpk),
EphemeralPublicKey::from_scalar(esk),
)
}

View File

@ -22,7 +22,7 @@ pub enum AuthTransferSubcommand {
},
/// Send native tokens from one account to another with variable privacy
///
/// If receiver is private, then `to` and (`to_npk` , `to_ipk`) is a mutually exclusive
/// If receiver is private, then `to` and (`to_npk` , `to_vpk`) is a mutually exclusive
/// patterns.
///
/// First is used for owned accounts, second otherwise.
@ -36,9 +36,9 @@ pub enum AuthTransferSubcommand {
/// to_npk - valid 32 byte hex string
#[arg(long)]
to_npk: Option<String>,
/// to_ipk - valid 33 byte hex string
/// to_vpk - valid 33 byte hex string
#[arg(long)]
to_ipk: Option<String>,
to_vpk: Option<String>,
/// amount - amount of balance to move
#[arg(long)]
amount: u128,
@ -104,10 +104,10 @@ impl WalletSubcommand for AuthTransferSubcommand {
from,
to,
to_npk,
to_ipk,
to_vpk,
amount,
} => {
let underlying_subcommand = match (to, to_npk, to_ipk) {
let underlying_subcommand = match (to, to_npk, to_vpk) {
(None, None, None) => {
anyhow::bail!(
"Provide either account account_id of receiver or their public keys"
@ -156,7 +156,7 @@ impl WalletSubcommand for AuthTransferSubcommand {
}
}
}
(None, Some(to_npk), Some(to_ipk)) => {
(None, Some(to_npk), Some(to_vpk)) => {
let (from, from_privacy) = parse_addr_with_privacy_prefix(&from)?;
match from_privacy {
@ -165,7 +165,7 @@ impl WalletSubcommand for AuthTransferSubcommand {
NativeTokenTransferProgramSubcommandPrivate::PrivateForeign {
from,
to_npk,
to_ipk,
to_vpk,
amount,
},
)
@ -175,7 +175,7 @@ impl WalletSubcommand for AuthTransferSubcommand {
NativeTokenTransferProgramSubcommandShielded::ShieldedForeign {
from,
to_npk,
to_ipk,
to_vpk,
amount,
},
)
@ -257,9 +257,9 @@ pub enum NativeTokenTransferProgramSubcommandShielded {
/// to_npk - valid 32 byte hex string
#[arg(long)]
to_npk: String,
/// to_ipk - valid 33 byte hex string
/// to_vpk - valid 33 byte hex string
#[arg(long)]
to_ipk: String,
to_vpk: String,
/// amount - amount of balance to move
#[arg(long)]
amount: u128,
@ -294,9 +294,9 @@ pub enum NativeTokenTransferProgramSubcommandPrivate {
/// to_npk - valid 32 byte hex string
#[arg(long)]
to_npk: String,
/// to_ipk - valid 33 byte hex string
/// to_vpk - valid 33 byte hex string
#[arg(long)]
to_ipk: String,
to_vpk: String,
/// amount - amount of balance to move
#[arg(long)]
amount: u128,
@ -340,7 +340,7 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandPrivate {
NativeTokenTransferProgramSubcommandPrivate::PrivateForeign {
from,
to_npk,
to_ipk,
to_vpk,
amount,
} => {
let from: AccountId = from.parse().unwrap();
@ -349,14 +349,14 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandPrivate {
to_npk.copy_from_slice(&to_npk_res);
let to_npk = nssa_core::NullifierPublicKey(to_npk);
let to_ipk_res = hex::decode(to_ipk)?;
let mut to_ipk = [0u8; 33];
to_ipk.copy_from_slice(&to_ipk_res);
let to_ipk =
nssa_core::encryption::shared_key_derivation::Secp256k1Point(to_ipk.to_vec());
let to_vpk_res = hex::decode(to_vpk)?;
let mut to_vpk = [0u8; 33];
to_vpk.copy_from_slice(&to_vpk_res);
let to_vpk =
nssa_core::encryption::shared_key_derivation::Secp256k1Point(to_vpk.to_vec());
let (res, [secret_from, _]) = NativeTokenTransfer(wallet_core)
.send_private_transfer_to_outer_account(from, to_npk, to_ipk, amount)
.send_private_transfer_to_outer_account(from, to_npk, to_vpk, amount)
.await?;
println!("Results of tx send are {res:#?}");
@ -420,7 +420,7 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandShielded {
NativeTokenTransferProgramSubcommandShielded::ShieldedForeign {
from,
to_npk,
to_ipk,
to_vpk,
amount,
} => {
let from: AccountId = from.parse().unwrap();
@ -430,14 +430,14 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandShielded {
to_npk.copy_from_slice(&to_npk_res);
let to_npk = nssa_core::NullifierPublicKey(to_npk);
let to_ipk_res = hex::decode(to_ipk)?;
let mut to_ipk = [0u8; 33];
to_ipk.copy_from_slice(&to_ipk_res);
let to_ipk =
nssa_core::encryption::shared_key_derivation::Secp256k1Point(to_ipk.to_vec());
let to_vpk_res = hex::decode(to_vpk)?;
let mut to_vpk = [0u8; 33];
to_vpk.copy_from_slice(&to_vpk_res);
let to_vpk =
nssa_core::encryption::shared_key_derivation::Secp256k1Point(to_vpk.to_vec());
let (res, _) = NativeTokenTransfer(wallet_core)
.send_shielded_transfer_to_outer_account(from, to_npk, to_ipk, amount)
.send_shielded_transfer_to_outer_account(from, to_npk, to_vpk, amount)
.await?;
println!("Results of tx send are {res:#?}");

View File

@ -29,7 +29,7 @@ pub enum TokenProgramAgnosticSubcommand {
},
/// Send tokens from one account to another with variable privacy
///
/// If receiver is private, then `to` and (`to_npk` , `to_ipk`) is a mutually exclusive
/// If receiver is private, then `to` and (`to_npk` , `to_vpk`) is a mutually exclusive
/// patterns.
///
/// First is used for owned accounts, second otherwise.
@ -43,9 +43,9 @@ pub enum TokenProgramAgnosticSubcommand {
/// to_npk - valid 32 byte hex string
#[arg(long)]
to_npk: Option<String>,
/// to_ipk - valid 33 byte hex string
/// to_vpk - valid 33 byte hex string
#[arg(long)]
to_ipk: Option<String>,
to_vpk: Option<String>,
/// amount - amount of balance to move
#[arg(long)]
amount: u128,
@ -71,7 +71,7 @@ pub enum TokenProgramAgnosticSubcommand {
///
/// `definition` is owned
///
/// If `holder` is private, then `holder` and (`holder_npk` , `holder_ipk`) is a mutually
/// If `holder` is private, then `holder` and (`holder_npk` , `holder_vpk`) is a mutually
/// exclusive patterns.
///
/// First is used for owned accounts, second otherwise.
@ -85,9 +85,9 @@ pub enum TokenProgramAgnosticSubcommand {
/// holder_npk - valid 32 byte hex string
#[arg(long)]
holder_npk: Option<String>,
/// to_ipk - valid 33 byte hex string
/// to_vpk - valid 33 byte hex string
#[arg(long)]
holder_ipk: Option<String>,
holder_vpk: Option<String>,
/// amount - amount of balance to mint
#[arg(long)]
amount: u128,
@ -160,10 +160,10 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
from,
to,
to_npk,
to_ipk,
to_vpk,
amount,
} => {
let underlying_subcommand = match (to, to_npk, to_ipk) {
let underlying_subcommand = match (to, to_npk, to_vpk) {
(None, None, None) => {
anyhow::bail!(
"Provide either account account_id of receiver or their public keys"
@ -220,7 +220,7 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
}
}
}
(None, Some(to_npk), Some(to_ipk)) => {
(None, Some(to_npk), Some(to_vpk)) => {
let (from, from_privacy) = parse_addr_with_privacy_prefix(&from)?;
match from_privacy {
@ -228,7 +228,7 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
TokenProgramSubcommandPrivate::TransferTokenPrivateForeign {
sender_account_id: from,
recipient_npk: to_npk,
recipient_ipk: to_ipk,
recipient_vpk: to_vpk,
balance_to_move: amount,
},
),
@ -236,7 +236,7 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
TokenProgramSubcommandShielded::TransferTokenShieldedForeign {
sender_account_id: from,
recipient_npk: to_npk,
recipient_ipk: to_ipk,
recipient_vpk: to_vpk,
balance_to_move: amount,
},
),
@ -302,10 +302,10 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
definition,
holder,
holder_npk,
holder_ipk,
holder_vpk,
amount,
} => {
let underlying_subcommand = match (holder, holder_npk, holder_ipk) {
let underlying_subcommand = match (holder, holder_npk, holder_vpk) {
(None, None, None) => {
anyhow::bail!(
"Provide either account account_id of holder or their public keys"
@ -363,7 +363,7 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
}
}
}
(None, Some(holder_npk), Some(holder_ipk)) => {
(None, Some(holder_npk), Some(holder_vpk)) => {
let (definition, definition_privacy) =
parse_addr_with_privacy_prefix(&definition)?;
@ -372,7 +372,7 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
TokenProgramSubcommandPrivate::MintTokenPrivateForeign {
definition_account_id: definition,
holder_npk,
holder_ipk,
holder_vpk,
amount,
},
),
@ -380,7 +380,7 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
TokenProgramSubcommandShielded::MintTokenShieldedForeign {
definition_account_id: definition,
holder_npk,
holder_ipk,
holder_vpk,
amount,
},
),
@ -465,9 +465,9 @@ pub enum TokenProgramSubcommandPrivate {
/// recipient_npk - valid 32 byte hex string
#[arg(long)]
recipient_npk: String,
/// recipient_ipk - valid 33 byte hex string
/// recipient_vpk - valid 33 byte hex string
#[arg(long)]
recipient_ipk: String,
recipient_vpk: String,
#[arg(short, long)]
balance_to_move: u128,
},
@ -496,7 +496,7 @@ pub enum TokenProgramSubcommandPrivate {
#[arg(short, long)]
holder_npk: String,
#[arg(short, long)]
holder_ipk: String,
holder_vpk: String,
#[arg(short, long)]
amount: u128,
},
@ -553,9 +553,9 @@ pub enum TokenProgramSubcommandShielded {
/// recipient_npk - valid 32 byte hex string
#[arg(long)]
recipient_npk: String,
/// recipient_ipk - valid 33 byte hex string
/// recipient_vpk - valid 33 byte hex string
#[arg(long)]
recipient_ipk: String,
recipient_vpk: String,
#[arg(short, long)]
balance_to_move: u128,
},
@ -584,7 +584,7 @@ pub enum TokenProgramSubcommandShielded {
#[arg(short, long)]
holder_npk: String,
#[arg(short, long)]
holder_ipk: String,
holder_vpk: String,
#[arg(short, long)]
amount: u128,
},
@ -747,7 +747,7 @@ impl WalletSubcommand for TokenProgramSubcommandPrivate {
TokenProgramSubcommandPrivate::TransferTokenPrivateForeign {
sender_account_id,
recipient_npk,
recipient_ipk,
recipient_vpk,
balance_to_move,
} => {
let sender_account_id: AccountId = sender_account_id.parse().unwrap();
@ -756,18 +756,18 @@ impl WalletSubcommand for TokenProgramSubcommandPrivate {
recipient_npk.copy_from_slice(&recipient_npk_res);
let recipient_npk = nssa_core::NullifierPublicKey(recipient_npk);
let recipient_ipk_res = hex::decode(recipient_ipk)?;
let mut recipient_ipk = [0u8; 33];
recipient_ipk.copy_from_slice(&recipient_ipk_res);
let recipient_ipk = nssa_core::encryption::shared_key_derivation::Secp256k1Point(
recipient_ipk.to_vec(),
let recipient_vpk_res = hex::decode(recipient_vpk)?;
let mut recipient_vpk = [0u8; 33];
recipient_vpk.copy_from_slice(&recipient_vpk_res);
let recipient_vpk = nssa_core::encryption::shared_key_derivation::Secp256k1Point(
recipient_vpk.to_vec(),
);
let (res, [secret_sender, _]) = Token(wallet_core)
.send_transfer_transaction_private_foreign_account(
sender_account_id,
recipient_npk,
recipient_ipk,
recipient_vpk,
balance_to_move,
)
.await?;
@ -873,7 +873,7 @@ impl WalletSubcommand for TokenProgramSubcommandPrivate {
TokenProgramSubcommandPrivate::MintTokenPrivateForeign {
definition_account_id,
holder_npk,
holder_ipk,
holder_vpk,
amount,
} => {
let definition_account_id: AccountId = definition_account_id.parse().unwrap();
@ -883,18 +883,18 @@ impl WalletSubcommand for TokenProgramSubcommandPrivate {
holder_npk.copy_from_slice(&holder_npk_res);
let holder_npk = nssa_core::NullifierPublicKey(holder_npk);
let holder_ipk_res = hex::decode(holder_ipk)?;
let mut holder_ipk = [0u8; 33];
holder_ipk.copy_from_slice(&holder_ipk_res);
let holder_ipk = nssa_core::encryption::shared_key_derivation::Secp256k1Point(
holder_ipk.to_vec(),
let holder_vpk_res = hex::decode(holder_vpk)?;
let mut holder_vpk = [0u8; 33];
holder_vpk.copy_from_slice(&holder_vpk_res);
let holder_vpk = nssa_core::encryption::shared_key_derivation::Secp256k1Point(
holder_vpk.to_vec(),
);
let (res, [secret_definition, _]) = Token(wallet_core)
.send_mint_transaction_private_foreign_account(
definition_account_id,
holder_npk,
holder_ipk,
holder_vpk,
amount,
)
.await?;
@ -1050,7 +1050,7 @@ impl WalletSubcommand for TokenProgramSubcommandShielded {
TokenProgramSubcommandShielded::TransferTokenShieldedForeign {
sender_account_id,
recipient_npk,
recipient_ipk,
recipient_vpk,
balance_to_move,
} => {
let sender_account_id: AccountId = sender_account_id.parse().unwrap();
@ -1059,18 +1059,18 @@ impl WalletSubcommand for TokenProgramSubcommandShielded {
recipient_npk.copy_from_slice(&recipient_npk_res);
let recipient_npk = nssa_core::NullifierPublicKey(recipient_npk);
let recipient_ipk_res = hex::decode(recipient_ipk)?;
let mut recipient_ipk = [0u8; 33];
recipient_ipk.copy_from_slice(&recipient_ipk_res);
let recipient_ipk = nssa_core::encryption::shared_key_derivation::Secp256k1Point(
recipient_ipk.to_vec(),
let recipient_vpk_res = hex::decode(recipient_vpk)?;
let mut recipient_vpk = [0u8; 33];
recipient_vpk.copy_from_slice(&recipient_vpk_res);
let recipient_vpk = nssa_core::encryption::shared_key_derivation::Secp256k1Point(
recipient_vpk.to_vec(),
);
let (res, _) = Token(wallet_core)
.send_transfer_transaction_shielded_foreign_account(
sender_account_id,
recipient_npk,
recipient_ipk,
recipient_vpk,
balance_to_move,
)
.await?;
@ -1201,7 +1201,7 @@ impl WalletSubcommand for TokenProgramSubcommandShielded {
TokenProgramSubcommandShielded::MintTokenShieldedForeign {
definition_account_id,
holder_npk,
holder_ipk,
holder_vpk,
amount,
} => {
let definition_account_id: AccountId = definition_account_id.parse().unwrap();
@ -1211,18 +1211,18 @@ impl WalletSubcommand for TokenProgramSubcommandShielded {
holder_npk.copy_from_slice(&holder_npk_res);
let holder_npk = nssa_core::NullifierPublicKey(holder_npk);
let holder_ipk_res = hex::decode(holder_ipk)?;
let mut holder_ipk = [0u8; 33];
holder_ipk.copy_from_slice(&holder_ipk_res);
let holder_ipk = nssa_core::encryption::shared_key_derivation::Secp256k1Point(
holder_ipk.to_vec(),
let holder_vpk_res = hex::decode(holder_vpk)?;
let mut holder_vpk = [0u8; 33];
holder_vpk.copy_from_slice(&holder_vpk_res);
let holder_vpk = nssa_core::encryption::shared_key_derivation::Secp256k1Point(
holder_vpk.to_vec(),
);
let (res, _) = Token(wallet_core)
.send_mint_transaction_shielded_foreign_account(
definition_account_id,
holder_npk,
holder_ipk,
holder_vpk,
amount,
)
.await?;

View File

@ -36,7 +36,7 @@ impl WalletCore {
let AccountPreparedData {
nsk: winner_nsk,
npk: winner_npk,
ipk: winner_ipk,
vpk: winner_vpk,
auth_acc: winner_pre,
proof: _,
} = self
@ -50,7 +50,7 @@ impl WalletCore {
let pinata_pre = AccountWithMetadata::new(pinata_acc.clone(), false, pinata_account_id);
let eph_holder_winner = EphemeralKeyHolder::new(&winner_npk);
let shared_secret_winner = eph_holder_winner.calculate_shared_secret_sender(&winner_ipk);
let shared_secret_winner = eph_holder_winner.calculate_shared_secret_sender(&winner_vpk);
let (output, proof) = circuit::execute_and_prove(
&[pinata_pre, winner_pre],
@ -70,7 +70,7 @@ impl WalletCore {
vec![],
vec![(
winner_npk.clone(),
winner_ipk.clone(),
winner_vpk.clone(),
eph_holder_winner.generate_ephemeral_public_key(),
)],
output,
@ -103,7 +103,7 @@ impl WalletCore {
let AccountPreparedData {
nsk: _,
npk: winner_npk,
ipk: winner_ipk,
vpk: winner_vpk,
auth_acc: winner_pre,
proof: _,
} = self
@ -117,7 +117,7 @@ impl WalletCore {
let pinata_pre = AccountWithMetadata::new(pinata_acc.clone(), false, pinata_account_id);
let eph_holder_winner = EphemeralKeyHolder::new(&winner_npk);
let shared_secret_winner = eph_holder_winner.calculate_shared_secret_sender(&winner_ipk);
let shared_secret_winner = eph_holder_winner.calculate_shared_secret_sender(&winner_vpk);
let (output, proof) = circuit::execute_and_prove(
&[pinata_pre, winner_pre],
@ -137,7 +137,7 @@ impl WalletCore {
vec![],
vec![(
winner_npk.clone(),
winner_ipk.clone(),
winner_vpk.clone(),
eph_holder_winner.generate_ephemeral_public_key(),
)],
output,