diff --git a/examples/program_deployment/src/bin/run_hello_world_private.rs b/examples/program_deployment/src/bin/run_hello_world_private.rs index 27ac2079..78c11656 100644 --- a/examples/program_deployment/src/bin/run_hello_world_private.rs +++ b/examples/program_deployment/src/bin/run_hello_world_private.rs @@ -52,6 +52,8 @@ async fn main() { accounts, Program::serialize_instruction(greeting).unwrap(), &program.into(), + &None, + &None, ) .await .unwrap(); diff --git a/examples/program_deployment/src/bin/run_hello_world_through_tail_call_private.rs b/examples/program_deployment/src/bin/run_hello_world_through_tail_call_private.rs index 4fac3eec..e25c4b0e 100644 --- a/examples/program_deployment/src/bin/run_hello_world_through_tail_call_private.rs +++ b/examples/program_deployment/src/bin/run_hello_world_through_tail_call_private.rs @@ -60,6 +60,8 @@ async fn main() { accounts, Program::serialize_instruction(instruction).unwrap(), &program_with_dependencies, + &None, + &None, ) .await .unwrap(); diff --git a/examples/program_deployment/src/bin/run_hello_world_with_move_function.rs b/examples/program_deployment/src/bin/run_hello_world_with_move_function.rs index a1c2517e..89763bd7 100644 --- a/examples/program_deployment/src/bin/run_hello_world_with_move_function.rs +++ b/examples/program_deployment/src/bin/run_hello_world_with_move_function.rs @@ -106,6 +106,8 @@ async fn main() { accounts, Program::serialize_instruction(instruction).unwrap(), &program.into(), + &None, + &None, ) .await .unwrap(); @@ -147,6 +149,8 @@ async fn main() { accounts, Program::serialize_instruction(instruction).unwrap(), &program.into(), + &None, + &None, ) .await .unwrap(); diff --git a/keycard_tests.sh b/keycard_tests.sh index 6a2e065b..73a5e213 100644 --- a/keycard_tests.sh +++ b/keycard_tests.sh @@ -18,7 +18,6 @@ wallet auth-transfer init --pin 111111 --key-path "m/44'/60'/0'/0/0" echo "Test: wallet account get --pin 111111 --key-path \"m/44'/60'/0'/0/0\"" wallet account get --pin 111111 --key-path "m/44'/60'/0'/0/0" - echo "Test: wallet pinata claim --pin 111111 --key-path \"m/44'/60'/0'/0/0\"" wallet pinata claim --pin 111111 --key-path "m/44'/60'/0'/0/0" @@ -35,3 +34,29 @@ wallet account get --pin 111111 --key-path "m/44'/60'/0'/0/0" echo "Test: wallet account get --pin 111111 --key-path \"m/44'/60'/0'/0/1\"" wallet account get --pin 111111 --key-path "m/44'/60'/0'/0/1" + + + +# initialize account keys (outside of keycard) +# Eventually use for tokens and shielded +wallet account new private +wallet account new public +wallet account new public +wallet account new public +wallet account new public + +# Initialize Token A +wallet token new --definition-account-id "Public/4rXJzAEVn9Av1bK1RR4orTJP8dJDzRuoTBRsXVn1pwcK" --supply-account-id "Public/3PfkXqePVRnet5H1PbnfgeWykBrqX3KPPeMBESJt4QEd" --total-supply 1000 --name LEZT +echo "Token A" +# Initialize Token B +wallet token new --definition-account-id "Public/DjJx9ccoRyv1xxmHmpFy8mATeKq3Es1DnobjT4EZ4ab2" --supply-account-id "Public/EKgmwG9n7jMYkKaTYdZa7ELyYZq5f43oBKuCiu3t3Tm8" --total-supply 1000 --name LEET +echo "Token B" +# Send Token A to a new wallet account + +# Send from non keycard account to an account owned by keycard. +#wallet token send --from "Public/3PfkXqePVRnet5H1PbnfgeWykBrqX3KPPeMBESJt4QEd" --to "Public/6iYPF671bMDEkADFvHgcJDrYHJMqZv6cYbxVMsUU7LFE" --amount 400 +# This fails due to lack of initialization for Token Account +#echo "Transfer 1" + +wallet auth-transfer send --amount 40 --pin 111111 --from-key-path "m/44'/60'/0'/0/0" --to-npk "55204e2934045b044f06d8222b454d46b54788f33c7dec4f6733d441703bb0e6" --to-vpk "02a8626b0c0ad9383c5678dad48c3969b4174fb377cdb03a6259648032c774cec8" +echo "Transfer 2" diff --git a/wallet-ffi/src/transfer.rs b/wallet-ffi/src/transfer.rs index e65fa473..d4c6573d 100644 --- a/wallet-ffi/src/transfer.rs +++ b/wallet-ffi/src/transfer.rs @@ -1,6 +1,9 @@ //! Token transfer functions. -use std::{ffi::CString, ptr}; +use std::{ + ffi::{c_char, CStr, CString}, + ptr, +}; use nssa::AccountId; use wallet::program_facades::native_token_transfer::NativeTokenTransfer; @@ -14,6 +17,14 @@ use crate::{ FfiPrivateAccountKeys, }; +fn optional_c_str(ptr: *const c_char) -> Option { + if ptr.is_null() { + return None; + } + let c_str = unsafe { CStr::from_ptr(ptr) }; + c_str.to_str().ok().map(str::to_owned) +} + /// Send a public token transfer. /// /// Transfers tokens from one public account to another on the network. @@ -126,6 +137,8 @@ pub unsafe extern "C" fn wallet_ffi_transfer_shielded( from: *const FfiBytes32, to_keys: *const FfiPrivateAccountKeys, amount: *const [u8; 16], + pin: *const c_char, + key_path: *const c_char, out_result: *mut FfiTransferResult, ) -> WalletFfiError { let wrapper = match get_wallet(handle) { @@ -156,11 +169,15 @@ pub unsafe extern "C" fn wallet_ffi_transfer_shielded( } }; let amount = u128::from_le_bytes(unsafe { *amount }); + let pin = optional_c_str(pin); + let key_path = optional_c_str(key_path); let transfer = NativeTokenTransfer(&wallet); match block_on( - transfer.send_shielded_transfer_to_outer_account(from_id, to_npk, to_vpk, amount), + transfer.send_shielded_transfer_to_outer_account( + from_id, to_npk, to_vpk, amount, &pin, &key_path, + ), ) { Ok((tx_hash, _shared_key)) => { let tx_hash = CString::new(tx_hash.to_string()) @@ -215,6 +232,8 @@ pub unsafe extern "C" fn wallet_ffi_transfer_deshielded( from: *const FfiBytes32, to: *const FfiBytes32, amount: *const [u8; 16], + pin: *const c_char, + key_path: *const c_char, out_result: *mut FfiTransferResult, ) -> WalletFfiError { let wrapper = match get_wallet(handle) { @@ -238,10 +257,12 @@ pub unsafe extern "C" fn wallet_ffi_transfer_deshielded( let from_id = AccountId::new(unsafe { (*from).data }); let to_id = AccountId::new(unsafe { (*to).data }); let amount = u128::from_le_bytes(unsafe { *amount }); + let pin = optional_c_str(pin); + let key_path = optional_c_str(key_path); let transfer = NativeTokenTransfer(&wallet); - match block_on(transfer.send_deshielded_transfer(from_id, to_id, amount)) { + match block_on(transfer.send_deshielded_transfer(from_id, to_id, amount, &pin, &key_path)) { Ok((tx_hash, _shared_key)) => { let tx_hash = CString::new(tx_hash.to_string()) .map_or(ptr::null_mut(), std::ffi::CString::into_raw); @@ -295,6 +316,8 @@ pub unsafe extern "C" fn wallet_ffi_transfer_private( from: *const FfiBytes32, to_keys: *const FfiPrivateAccountKeys, amount: *const [u8; 16], + pin: *const c_char, + key_path: *const c_char, out_result: *mut FfiTransferResult, ) -> WalletFfiError { let wrapper = match get_wallet(handle) { @@ -325,11 +348,16 @@ pub unsafe extern "C" fn wallet_ffi_transfer_private( } }; let amount = u128::from_le_bytes(unsafe { *amount }); + let pin = optional_c_str(pin); + let key_path = optional_c_str(key_path); let transfer = NativeTokenTransfer(&wallet); - match block_on(transfer.send_private_transfer_to_outer_account(from_id, to_npk, to_vpk, amount)) - { + match block_on( + transfer.send_private_transfer_to_outer_account( + from_id, to_npk, to_vpk, amount, &pin, &key_path, + ), + ) { Ok((tx_hash, _shared_key)) => { let tx_hash = CString::new(tx_hash.to_string()) .map_or(ptr::null_mut(), std::ffi::CString::into_raw); @@ -386,6 +414,8 @@ pub unsafe extern "C" fn wallet_ffi_transfer_shielded_owned( from: *const FfiBytes32, to: *const FfiBytes32, amount: *const [u8; 16], + pin: *const c_char, + key_path: *const c_char, out_result: *mut FfiTransferResult, ) -> WalletFfiError { let wrapper = match get_wallet(handle) { @@ -409,10 +439,12 @@ pub unsafe extern "C" fn wallet_ffi_transfer_shielded_owned( let from_id = AccountId::new(unsafe { (*from).data }); let to_id = AccountId::new(unsafe { (*to).data }); let amount = u128::from_le_bytes(unsafe { *amount }); + let pin = optional_c_str(pin); + let key_path = optional_c_str(key_path); let transfer = NativeTokenTransfer(&wallet); - match block_on(transfer.send_shielded_transfer(from_id, to_id, amount)) { + match block_on(transfer.send_shielded_transfer(from_id, to_id, amount, &pin, &key_path)) { Ok((tx_hash, _shared_key)) => { let tx_hash = CString::new(tx_hash.to_string()) .map_or(ptr::null_mut(), std::ffi::CString::into_raw); @@ -469,6 +501,8 @@ pub unsafe extern "C" fn wallet_ffi_transfer_private_owned( from: *const FfiBytes32, to: *const FfiBytes32, amount: *const [u8; 16], + pin: *const c_char, + key_path: *const c_char, out_result: *mut FfiTransferResult, ) -> WalletFfiError { let wrapper = match get_wallet(handle) { @@ -492,10 +526,14 @@ pub unsafe extern "C" fn wallet_ffi_transfer_private_owned( let from_id = AccountId::new(unsafe { (*from).data }); let to_id = AccountId::new(unsafe { (*to).data }); let amount = u128::from_le_bytes(unsafe { *amount }); + let pin = optional_c_str(pin); + let key_path = optional_c_str(key_path); let transfer = NativeTokenTransfer(&wallet); - match block_on(transfer.send_private_transfer_to_owned_account(from_id, to_id, amount)) { + match block_on( + transfer.send_private_transfer_to_owned_account(from_id, to_id, amount, &pin, &key_path), + ) { Ok((tx_hash, _shared_keys)) => { let tx_hash = CString::new(tx_hash.to_string()) .map_or(ptr::null_mut(), std::ffi::CString::into_raw); @@ -613,6 +651,8 @@ pub unsafe extern "C" fn wallet_ffi_register_public_account( pub unsafe extern "C" fn wallet_ffi_register_private_account( handle: *mut WalletHandle, account_id: *const FfiBytes32, + pin: *const c_char, + key_path: *const c_char, out_result: *mut FfiTransferResult, ) -> WalletFfiError { let wrapper = match get_wallet(handle) { @@ -634,10 +674,12 @@ pub unsafe extern "C" fn wallet_ffi_register_private_account( }; let account_id = AccountId::new(unsafe { (*account_id).data }); + let pin = optional_c_str(pin); + let key_path = optional_c_str(key_path); let transfer = NativeTokenTransfer(&wallet); - match block_on(transfer.register_account_private(account_id)) { + match block_on(transfer.register_account_private(account_id, &pin, &key_path)) { Ok((tx_hash, _secret)) => { let tx_hash = CString::new(tx_hash.to_string()) .map_or(ptr::null_mut(), std::ffi::CString::into_raw); diff --git a/wallet-ffi/wallet_ffi.h b/wallet-ffi/wallet_ffi.h index 2665cd40..f5c84720 100644 --- a/wallet-ffi/wallet_ffi.h +++ b/wallet-ffi/wallet_ffi.h @@ -708,6 +708,8 @@ enum WalletFfiError wallet_ffi_transfer_shielded(struct WalletHandle *handle, const struct FfiBytes32 *from, const struct FfiPrivateAccountKeys *to_keys, const uint8_t (*amount)[16], + const char *pin, + const char *key_path, struct FfiTransferResult *out_result); /** @@ -742,6 +744,8 @@ enum WalletFfiError wallet_ffi_transfer_deshielded(struct WalletHandle *handle, const struct FfiBytes32 *from, const struct FfiBytes32 *to, const uint8_t (*amount)[16], + const char *pin, + const char *key_path, struct FfiTransferResult *out_result); /** @@ -776,6 +780,8 @@ enum WalletFfiError wallet_ffi_transfer_private(struct WalletHandle *handle, const struct FfiBytes32 *from, const struct FfiPrivateAccountKeys *to_keys, const uint8_t (*amount)[16], + const char *pin, + const char *key_path, struct FfiTransferResult *out_result); /** @@ -813,6 +819,8 @@ enum WalletFfiError wallet_ffi_transfer_shielded_owned(struct WalletHandle *hand const struct FfiBytes32 *from, const struct FfiBytes32 *to, const uint8_t (*amount)[16], + const char *pin, + const char *key_path, struct FfiTransferResult *out_result); /** @@ -850,6 +858,8 @@ enum WalletFfiError wallet_ffi_transfer_private_owned(struct WalletHandle *handl const struct FfiBytes32 *from, const struct FfiBytes32 *to, const uint8_t (*amount)[16], + const char *pin, + const char *key_path, struct FfiTransferResult *out_result); /** @@ -904,6 +914,8 @@ enum WalletFfiError wallet_ffi_register_public_account(struct WalletHandle *hand */ enum WalletFfiError wallet_ffi_register_private_account(struct WalletHandle *handle, const struct FfiBytes32 *account_id, + const char *pin, + const char *key_path, struct FfiTransferResult *out_result); /** diff --git a/wallet/src/cli/programs/native_token_transfer.rs b/wallet/src/cli/programs/native_token_transfer.rs index f63f8bae..f0497d18 100644 --- a/wallet/src/cli/programs/native_token_transfer.rs +++ b/wallet/src/cli/programs/native_token_transfer.rs @@ -115,7 +115,7 @@ impl WalletSubcommand for AuthTransferSubcommand { let account_id = account_id.parse()?; let (tx_hash, secret) = NativeTokenTransfer(wallet_core) - .register_account_private(account_id) + .register_account_private(account_id, &pin, &key_path) .await?; println!("Transaction hash is {tx_hash}"); @@ -210,6 +210,8 @@ impl WalletSubcommand for AuthTransferSubcommand { from, to, amount, + pin: pin.clone(), + key_path: from_key_path.clone(), }, ) } @@ -218,6 +220,8 @@ impl WalletSubcommand for AuthTransferSubcommand { from, to, amount, + pin: pin.clone(), + key_path: from_key_path.clone(), } } (AccountPrivacyKind::Public, AccountPrivacyKind::Private) => { @@ -244,6 +248,8 @@ impl WalletSubcommand for AuthTransferSubcommand { to_npk, to_vpk, amount, + pin: pin.clone(), + key_path: from_key_path.clone(), }, ) } @@ -306,6 +312,10 @@ pub enum NativeTokenTransferProgramSubcommand { /// amount - amount of balance to move. #[arg(long)] amount: u128, + #[arg(long)] + pin: Option, + #[arg(long)] + key_path: Option, }, /// Shielded execution. #[command(subcommand)] @@ -374,6 +384,10 @@ pub enum NativeTokenTransferProgramSubcommandPrivate { /// amount - amount of balance to move. #[arg(long)] amount: u128, + #[arg(long)] + pin: Option, + #[arg(long)] + key_path: Option, }, /// Send native token transfer from `from` to `to` for `amount`. /// @@ -391,6 +405,10 @@ pub enum NativeTokenTransferProgramSubcommandPrivate { /// amount - amount of balance to move. #[arg(long)] amount: u128, + #[arg(long)] + pin: Option, + #[arg(long)] + key_path: Option, }, } @@ -400,12 +418,18 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandPrivate { wallet_core: &mut WalletCore, ) -> Result { match self { - Self::PrivateOwned { from, to, amount } => { + Self::PrivateOwned { + from, + to, + amount, + pin, + key_path, + } => { let from: AccountId = from.parse().unwrap(); let to: AccountId = to.parse().unwrap(); let (tx_hash, [secret_from, secret_to]) = NativeTokenTransfer(wallet_core) - .send_private_transfer_to_owned_account(from, to, amount) + .send_private_transfer_to_owned_account(from, to, amount, &pin, &key_path) .await?; println!("Transaction hash is {tx_hash}"); @@ -430,6 +454,8 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandPrivate { to_npk, to_vpk, amount, + pin, + key_path, } => { let from: AccountId = from.parse().unwrap(); let to_npk_res = hex::decode(to_npk)?; @@ -444,7 +470,9 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandPrivate { nssa_core::encryption::shared_key_derivation::Secp256k1Point(to_vpk.to_vec()); let (tx_hash, [secret_from, _]) = NativeTokenTransfer(wallet_core) - .send_private_transfer_to_outer_account(from, to_npk, to_vpk, amount) + .send_private_transfer_to_outer_account( + from, to_npk, to_vpk, amount, &pin, &key_path, + ) .await?; println!("Transaction hash is {tx_hash}"); @@ -554,12 +582,18 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommand { Self::Shielded(shielded_subcommand) => { shielded_subcommand.handle_subcommand(wallet_core).await } - Self::Deshielded { from, to, amount } => { + Self::Deshielded { + from, + to, + amount, + pin, + key_path, + } => { let from: AccountId = from.parse().unwrap(); let to: AccountId = to.parse().unwrap(); let (tx_hash, secret) = NativeTokenTransfer(wallet_core) - .send_deshielded_transfer(from, to, amount) + .send_deshielded_transfer(from, to, amount, &pin, &key_path) .await?; println!("Transaction hash is {tx_hash}"); diff --git a/wallet/src/helperfunctions.rs b/wallet/src/helperfunctions.rs index f299842b..8e5e3f3e 100644 --- a/wallet/src/helperfunctions.rs +++ b/wallet/src/helperfunctions.rs @@ -70,8 +70,7 @@ pub fn resolve_id_or_label( (None, None, Some(pin)) => Ok(KeycardWallet::get_account_id_for_path_with_connect( pin, key_path.as_ref().expect("Expect a key path String."), - ) - .to_string()), + )), _ => anyhow::bail!("provide exactly one of account id, account label or keycard path"), } } diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index d00c7799..6a58ecbb 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -391,7 +391,7 @@ impl WalletCore { ) -> Result<(HashType, Vec), ExecutionFailureKind> { let acc_manager = privacy_preserving_tx::AccountManager::new(self, accounts).await?; - let pre_states = acc_manager.pre_states(); + let mut pre_states = acc_manager.pre_states(); let keycard_account = if let Some(pin) = pin.as_ref() { let account_id = KeycardWallet::get_account_id_for_path_with_connect( @@ -417,20 +417,26 @@ impl WalletCore { None }; - let nonces: Vec = acc_manager.public_account_nonces().into_iter().collect(); + let mut nonces: Vec = acc_manager.public_account_nonces().into_iter().collect(); - let account_ids: Vec = acc_manager.public_account_ids(); + let mut account_ids: Vec = acc_manager.public_account_ids(); - let visibility_mask = acc_manager.visibility_mask().to_vec(); + let mut visibility_mask = acc_manager.visibility_mask().to_vec(); if let Some(acc) = keycard_account.as_ref() { - nonces.push(acc.account.nonce); - - account_ids.push(acc.account_id); - - visibility_mask.push(0); - - pre_states.push(acc.clone()); + if acc_manager.public_account_ids().contains(&acc.account_id) { + if let Some(pre) = pre_states + .iter_mut() + .find(|p| p.account_id == acc.account_id) + { + pre.is_authorized = true; + } + } else { + nonces.push(acc.account.nonce); + account_ids.push(acc.account_id); + visibility_mask.push(0); + pre_states.push(acc.clone()); + } } tx_pre_check( @@ -467,7 +473,8 @@ impl WalletCore { ) .unwrap(); - let witness_set = Self::sign_privacy_message(&message, &proof, &acc_manager); + let witness_set = Self::sign_privacy_message(&message, &proof, &acc_manager, pin, key_path) + .expect("TODO-Marvin"); let tx = PrivacyPreservingTransaction::new(message, witness_set); let shared_secrets: Vec<_> = private_account_keys @@ -622,65 +629,67 @@ impl WalletCore { )) } - #[must_use] pub fn sign_privacy_message( message: &nssa::privacy_preserving_transaction::Message, proof: &Proof, acc_manager: &privacy_preserving_tx::AccountManager, - _pin: &Option, - _key_path: &Option, + pin: &Option, + key_path: &Option, ) -> Result { - //if pin.is_none() { - Ok( - nssa::privacy_preserving_transaction::witness_set::WitnessSet::for_message( - message, - proof.clone(), - &acc_manager.public_account_auth(), - ), - ) - /*} else { - let public_key = KeycardWallet::get_public_key_for_path_with_connect( - &pin.as_ref().expect("Expect a pin as a String."), - &key_path.as_ref().expect("Expect a key path String."), - ); - let signature = KeycardWallet::sign_message_for_path_with_connect( - &pin.as_ref().expect("Expect a pin as a String."), - &key_path.as_ref().expect("Expect a key path String."), - &message.hash_message(), - ) - .expect("Expect a valid signature"); - let mut signatures = Vec::::new(); - signatures.push(signature); - let mut public_keys = Vec::::new(); - public_keys.push(public_key); - Ok( - nssa::privacy_preserving_transaction::witness_set::WitnessSet::from_list( - proof.clone(), - &signatures, - &public_keys, - ), - ) - }*/ + pin.as_ref().map_or_else( + || { + Ok( + nssa::privacy_preserving_transaction::witness_set::WitnessSet::for_message( + message, + proof.clone(), + &acc_manager.public_account_auth(), + ), + ) + }, + |pin| { + let public_key = KeycardWallet::get_public_key_for_path_with_connect( + pin, + key_path.as_ref().expect("Expect a key path String."), + ); + let signature = KeycardWallet::sign_message_for_path_with_connect( + pin, + key_path.as_ref().expect("Expect a key path String."), + &message.hash_message(), + ) + .expect("Expect a valid signature"); + Ok( + nssa::privacy_preserving_transaction::witness_set::WitnessSet::from_list( + proof.clone(), + &[signature], + &[public_key], + ), + ) + }, + ) } pub fn sign_privacy_message_with_keycard( message: &nssa::privacy_preserving_transaction::Message, proof: Proof, - pin: &String, + pin: &str, key_paths: &[String], ) -> Result { let mut signatures = Vec::::new(); let mut public_keys = Vec::::new(); - for path in key_paths.iter() { + for path in key_paths { public_keys.push(KeycardWallet::get_public_key_for_path_with_connect( - &pin, &path, + pin, path, )); signatures.push( - KeycardWallet::sign_message_for_path_with_connect(&pin, &path, &message.hash_message()) - .expect("Expect a valid signature"), + KeycardWallet::sign_message_for_path_with_connect( + pin, + path, + &message.hash_message(), + ) + .expect("Expect a valid signature"), ); } diff --git a/wallet/src/privacy_preserving_tx.rs b/wallet/src/privacy_preserving_tx.rs index 14a805c7..b62f1c2f 100644 --- a/wallet/src/privacy_preserving_tx.rs +++ b/wallet/src/privacy_preserving_tx.rs @@ -124,7 +124,7 @@ impl AccountManager { self.states .iter() .filter_map(|state| match state { - State::Public { account, sk } => sk.as_ref().map(|_| account.account.nonce), + State::Public { account, .. } => Some(account.account.nonce), State::Private(_) => None, }) .collect() diff --git a/wallet/src/program_facades/native_token_transfer/deshielded.rs b/wallet/src/program_facades/native_token_transfer/deshielded.rs index e7abbb3e..9cd87ea9 100644 --- a/wallet/src/program_facades/native_token_transfer/deshielded.rs +++ b/wallet/src/program_facades/native_token_transfer/deshielded.rs @@ -10,6 +10,8 @@ impl NativeTokenTransfer<'_> { from: AccountId, to: AccountId, balance_to_move: u128, + pin: &Option, + key_path: &Option, ) -> Result<(HashType, nssa_core::SharedSecretKey), ExecutionFailureKind> { let (instruction_data, program, tx_pre_check) = auth_transfer_preparation(balance_to_move); @@ -22,8 +24,8 @@ impl NativeTokenTransfer<'_> { instruction_data, &program.into(), tx_pre_check, - &None, - &None, + pin, + key_path, ) .await .map(|(resp, secrets)| { diff --git a/wallet/src/program_facades/native_token_transfer/private.rs b/wallet/src/program_facades/native_token_transfer/private.rs index dbf9f5bf..5244b8cd 100644 --- a/wallet/src/program_facades/native_token_transfer/private.rs +++ b/wallet/src/program_facades/native_token_transfer/private.rs @@ -11,6 +11,8 @@ impl NativeTokenTransfer<'_> { pub async fn register_account_private( &self, from: AccountId, + pin: &Option, + key_path: &Option, ) -> Result<(HashType, SharedSecretKey), ExecutionFailureKind> { let instruction: u128 = 0; @@ -19,8 +21,8 @@ impl NativeTokenTransfer<'_> { vec![PrivacyPreservingAccount::PrivateOwned(from)], Program::serialize_instruction(instruction).unwrap(), &Program::authenticated_transfer_program().into(), - &None, - &None, + pin, + key_path, ) .await .map(|(resp, secrets)| { @@ -36,6 +38,8 @@ impl NativeTokenTransfer<'_> { to_npk: NullifierPublicKey, to_vpk: ViewingPublicKey, balance_to_move: u128, + pin: &Option, + key_path: &Option, ) -> Result<(HashType, [SharedSecretKey; 2]), ExecutionFailureKind> { let (instruction_data, program, tx_pre_check) = auth_transfer_preparation(balance_to_move); @@ -51,8 +55,8 @@ impl NativeTokenTransfer<'_> { instruction_data, &program.into(), tx_pre_check, - &None, - &None, + pin, + key_path, ) .await .map(|(resp, secrets)| { @@ -68,6 +72,8 @@ impl NativeTokenTransfer<'_> { from: AccountId, to: AccountId, balance_to_move: u128, + pin: &Option, + key_path: &Option, ) -> Result<(HashType, [SharedSecretKey; 2]), ExecutionFailureKind> { let (instruction_data, program, tx_pre_check) = auth_transfer_preparation(balance_to_move); @@ -80,8 +86,8 @@ impl NativeTokenTransfer<'_> { instruction_data, &program.into(), tx_pre_check, - &None, - &None, + pin, + key_path, ) .await .map(|(resp, secrets)| { diff --git a/wallet/src/program_facades/token.rs b/wallet/src/program_facades/token.rs index 6a5d7ee1..92ba6ec0 100644 --- a/wallet/src/program_facades/token.rs +++ b/wallet/src/program_facades/token.rs @@ -188,7 +188,19 @@ impl Token<'_> { ) .unwrap(); - let witness_set = if pin.is_none() { + let witness_set = if let Some(pin) = pin { + let sender_public_key = KeycardWallet::get_public_key_for_path_with_connect( + &pin, + sender_key_path.as_ref().expect("Expect a key path String."), + ); + let signature = KeycardWallet::sign_message_for_path_with_connect( + &pin, + sender_key_path.as_ref().expect("Expect a key path String."), + &message.hash_message(), + ) + .expect("Expect a valid signature"); + WitnessSet::from_list(&[signature], &[sender_public_key]) + } else { let mut private_keys = Vec::new(); let sender_sk = self .0 @@ -212,18 +224,6 @@ impl Token<'_> { } nssa::public_transaction::WitnessSet::for_message(&message, &private_keys) - } else { - let sender_public_key = KeycardWallet::get_public_key_for_path_with_connect( - &pin.as_ref().expect("Expect a pin as a String."), - &sender_key_path.as_ref().expect("Expect a key path String."), - ); - let signature = KeycardWallet::sign_message_for_path_with_connect( - &pin.expect("Expect a pin as a String."), - &sender_key_path.expect("Expect a key path String."), - &message.hash_message(), - ) - .expect("Expect a valid signature"); - WitnessSet::from_list(&[signature], &[sender_public_key]) }; let tx = nssa::PublicTransaction::new(message, witness_set);