From 8386d3ab17600b2a8003db14e00f0de2733048f2 Mon Sep 17 00:00:00 2001 From: jonesmarvin8 <83104039+jonesmarvin8@users.noreply.github.com> Date: Sun, 26 Apr 2026 22:50:16 -0400 Subject: [PATCH] fixes --- integration_tests/tests/amm.rs | 8 ++-- integration_tests/tests/ata.rs | 6 +-- .../tests/auth_transfer/private.rs | 24 +++++++---- .../tests/auth_transfer/public.rs | 21 ++++++--- integration_tests/tests/indexer.rs | 9 ++-- integration_tests/tests/keys_restoration.rs | 21 ++++++--- integration_tests/tests/token.rs | 12 +++--- keycard_wallet/Cargo.toml | 42 ++++++++++++++++++ .../src/lib.rs | 43 +++++++++---------- .../cli => keycard_wallet/src}/python_path.rs | 4 +- .../witness_set.rs | 6 +-- nssa/src/public_transaction/witness_set.rs | 4 +- wallet-ffi/src/transfer.rs | 4 +- wallet/src/cli/keycard.rs | 4 +- .../src/cli/programs/native_token_transfer.rs | 4 +- wallet/src/helperfunctions.rs | 2 +- wallet/src/lib.rs | 38 +++++++--------- .../native_token_transfer/public.rs | 16 +++---- wallet/src/program_facades/token.rs | 8 ++-- 19 files changed, 165 insertions(+), 111 deletions(-) create mode 100644 keycard_wallet/Cargo.toml rename wallet/src/cli/keycard_wallet.rs => keycard_wallet/src/lib.rs (75%) rename {wallet/src/cli => keycard_wallet/src}/python_path.rs (91%) diff --git a/integration_tests/tests/amm.rs b/integration_tests/tests/amm.rs index 2c3c404e..3949a495 100644 --- a/integration_tests/tests/amm.rs +++ b/integration_tests/tests/amm.rs @@ -134,7 +134,7 @@ async fn amm_public() -> Result<()> { to_npk: None, to_vpk: None, amount: 7, - from_pin: None, + pin: None, from_key_path: None, }; @@ -165,7 +165,7 @@ async fn amm_public() -> Result<()> { to_npk: None, to_vpk: None, amount: 7, - from_pin: None, + pin: None, from_key_path: None, }; @@ -555,7 +555,7 @@ async fn amm_new_pool_using_labels() -> Result<()> { to_npk: None, to_vpk: None, amount: 5, - from_pin: None, + pin: None, from_key_path: None, }; wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?; @@ -581,7 +581,7 @@ async fn amm_new_pool_using_labels() -> Result<()> { to_npk: None, to_vpk: None, amount: 5, - from_pin: None, + pin: None, from_key_path: None, }; wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?; diff --git a/integration_tests/tests/ata.rs b/integration_tests/tests/ata.rs index 608b15d4..cbde7021 100644 --- a/integration_tests/tests/ata.rs +++ b/integration_tests/tests/ata.rs @@ -269,7 +269,7 @@ async fn transfer_and_burn_via_ata() -> Result<()> { to_npk: None, to_vpk: None, amount: fund_amount, - from_pin: None, + pin: None, from_key_path: None, }), ) @@ -503,7 +503,7 @@ async fn transfer_via_ata_private_owner() -> Result<()> { to_npk: None, to_vpk: None, amount: fund_amount, - from_pin: None, + pin: None, from_key_path: None, }), ) @@ -619,7 +619,7 @@ async fn burn_via_ata_private_owner() -> Result<()> { to_npk: None, to_vpk: None, amount: fund_amount, - from_pin: None, + pin: None, from_key_path: None, }), ) diff --git a/integration_tests/tests/auth_transfer/private.rs b/integration_tests/tests/auth_transfer/private.rs index 2661084b..9e8dce2a 100644 --- a/integration_tests/tests/auth_transfer/private.rs +++ b/integration_tests/tests/auth_transfer/private.rs @@ -32,7 +32,8 @@ async fn private_transfer_to_owned_account() -> Result<()> { to_vpk: None, amount: 100, pin: None, - key_path: None, + to_key_path: None, + from_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -75,7 +76,8 @@ async fn private_transfer_to_foreign_account() -> Result<()> { to_vpk: Some(hex::encode(to_vpk.0)), amount: 100, pin: None, - key_path: None, + to_key_path: None, + from_key_path: None, }); let result = wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -127,7 +129,8 @@ async fn deshielded_transfer_to_public_account() -> Result<()> { to_vpk: None, amount: 100, pin: None, - key_path: None, + to_key_path: None, + from_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -194,7 +197,8 @@ async fn private_transfer_to_owned_account_using_claiming_path() -> Result<()> { to_vpk: Some(hex::encode(to_keys.viewing_public_key.0)), amount: 100, pin: None, - key_path: None, + to_key_path: None, + from_key_path: None, }); let sub_ret = wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -246,7 +250,8 @@ async fn shielded_transfer_to_owned_private_account() -> Result<()> { to_vpk: None, amount: 100, pin: None, - key_path: None, + to_key_path: None, + from_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -292,7 +297,8 @@ async fn shielded_transfer_to_foreign_account() -> Result<()> { to_vpk: Some(hex::encode(to_vpk.0)), amount: 100, pin: None, - key_path: None, + to_key_path: None, + from_key_path: None, }); let result = wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -366,7 +372,8 @@ async fn private_transfer_to_owned_account_continuous_run_path() -> Result<()> { to_vpk: Some(hex::encode(to_keys.viewing_public_key.0)), amount: 100, pin: None, - key_path: None, + to_key_path: None, + from_key_path: None, }); let sub_ret = wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -473,7 +480,8 @@ async fn private_transfer_using_from_label() -> Result<()> { to_vpk: None, amount: 100, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; diff --git a/integration_tests/tests/auth_transfer/public.rs b/integration_tests/tests/auth_transfer/public.rs index 617bce53..5be41c09 100644 --- a/integration_tests/tests/auth_transfer/public.rs +++ b/integration_tests/tests/auth_transfer/public.rs @@ -25,7 +25,8 @@ async fn successful_transfer_to_existing_account() -> Result<()> { to_vpk: None, amount: 100, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -85,7 +86,8 @@ pub async fn successful_transfer_to_new_account() -> Result<()> { to_vpk: None, amount: 100, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -125,7 +127,8 @@ async fn failed_transfer_with_insufficient_balance() -> Result<()> { to_vpk: None, amount: 1_000_000, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); let failed_send = wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await; @@ -167,7 +170,8 @@ async fn two_consecutive_successful_transfers() -> Result<()> { to_vpk: None, amount: 100, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -203,7 +207,8 @@ async fn two_consecutive_successful_transfers() -> Result<()> { to_vpk: None, amount: 100, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -292,7 +297,8 @@ async fn successful_transfer_using_from_label() -> Result<()> { to_vpk: None, amount: 100, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -341,7 +347,8 @@ async fn successful_transfer_using_to_label() -> Result<()> { to_vpk: None, amount: 100, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; diff --git a/integration_tests/tests/indexer.rs b/integration_tests/tests/indexer.rs index 0e3e4d4d..5d0c5b0d 100644 --- a/integration_tests/tests/indexer.rs +++ b/integration_tests/tests/indexer.rs @@ -114,7 +114,8 @@ async fn indexer_state_consistency() -> Result<()> { to_vpk: None, amount: 100, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -152,7 +153,8 @@ async fn indexer_state_consistency() -> Result<()> { to_vpk: None, amount: 100, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -240,7 +242,8 @@ async fn indexer_state_consistency_with_labels() -> Result<()> { to_vpk: None, amount: 100, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; diff --git a/integration_tests/tests/keys_restoration.rs b/integration_tests/tests/keys_restoration.rs index 60c10cbe..7b165a00 100644 --- a/integration_tests/tests/keys_restoration.rs +++ b/integration_tests/tests/keys_restoration.rs @@ -77,7 +77,8 @@ async fn sync_private_account_with_non_zero_chain_index() -> Result<()> { to_vpk: Some(hex::encode(to_keys.viewing_public_key.0)), amount: 100, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); let sub_ret = wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -155,7 +156,8 @@ async fn restore_keys_from_seed() -> Result<()> { to_vpk: None, amount: 100, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -169,7 +171,8 @@ async fn restore_keys_from_seed() -> Result<()> { to_vpk: None, amount: 101, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -211,7 +214,8 @@ async fn restore_keys_from_seed() -> Result<()> { to_vpk: None, amount: 102, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -225,7 +229,8 @@ async fn restore_keys_from_seed() -> Result<()> { to_vpk: None, amount: 103, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -292,7 +297,8 @@ async fn restore_keys_from_seed() -> Result<()> { to_vpk: None, amount: 10, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; @@ -305,7 +311,8 @@ async fn restore_keys_from_seed() -> Result<()> { to_vpk: None, amount: 11, pin: None, - key_path: None, + from_key_path: None, + to_key_path: None, }); wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; diff --git a/integration_tests/tests/token.rs b/integration_tests/tests/token.rs index 45e9a639..6a129693 100644 --- a/integration_tests/tests/token.rs +++ b/integration_tests/tests/token.rs @@ -135,7 +135,7 @@ async fn create_and_transfer_public_token() -> Result<()> { to_npk: None, to_vpk: None, amount: transfer_amount, - from_pin: None, + pin: None, from_key_path: None, }; @@ -379,7 +379,7 @@ async fn create_and_transfer_token_with_private_supply() -> Result<()> { to_npk: None, to_vpk: None, amount: transfer_amount, - from_pin: None, + pin: None, from_key_path: None, }; @@ -771,7 +771,7 @@ async fn create_token_with_private_definition_and_supply() -> Result<()> { to_npk: None, to_vpk: None, amount: transfer_amount, - from_pin: None, + pin: None, from_key_path: None, }; @@ -904,7 +904,7 @@ async fn shielded_token_transfer() -> Result<()> { to_npk: None, to_vpk: None, amount: transfer_amount, - from_pin: None, + pin: None, from_key_path: None, }; @@ -1032,7 +1032,7 @@ async fn deshielded_token_transfer() -> Result<()> { to_npk: None, to_vpk: None, amount: transfer_amount, - from_pin: None, + pin: None, from_key_path: None, }; @@ -1374,7 +1374,7 @@ async fn transfer_token_using_from_label() -> Result<()> { to_npk: None, to_vpk: None, amount: transfer_amount, - from_pin: None, + pin: None, from_key_path: None, }; wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?; diff --git a/keycard_wallet/Cargo.toml b/keycard_wallet/Cargo.toml new file mode 100644 index 00000000..03742a78 --- /dev/null +++ b/keycard_wallet/Cargo.toml @@ -0,0 +1,42 @@ +[package] +name = "keycard_wallet" +version = "0.1.0" +edition = "2024" +license = { workspace = true } + +[lints] +workspace = true + +[dependencies] +nssa_core.workspace = true +nssa.workspace = true +common.workspace = true +key_protocol.workspace = true +sequencer_service_rpc = { workspace = true, features = ["client"] } +token_core.workspace = true +amm_core.workspace = true +testnet_initial_state.workspace = true +ata_core.workspace = true +bip39.workspace = true +pyo3 = { version = "0.21", features = ["auto-initialize"] } + +anyhow.workspace = true +thiserror.workspace = true +serde_json.workspace = true +env_logger.workspace = true +log.workspace = true +serde.workspace = true +humantime-serde.workspace = true +humantime.workspace = true +tokio = { workspace = true, features = ["macros"] } +clap.workspace = true +base58.workspace = true +hex.workspace = true +rand.workspace = true +itertools.workspace = true +sha2.workspace = true +futures.workspace = true +async-stream.workspace = true +indicatif = { version = "0.18.3", features = ["improved_unicode"] } +optfield = "0.4.0" +url.workspace = true diff --git a/wallet/src/cli/keycard_wallet.rs b/keycard_wallet/src/lib.rs similarity index 75% rename from wallet/src/cli/keycard_wallet.rs rename to keycard_wallet/src/lib.rs index 0c050f76..73b5120e 100644 --- a/wallet/src/cli/keycard_wallet.rs +++ b/keycard_wallet/src/lib.rs @@ -1,16 +1,15 @@ use nssa::{AccountId, PublicKey, Signature}; use pyo3::{prelude::*, types::PyAny}; -use crate::cli::python_path; +pub mod python_path; -/// Rust wrapper around the Python KeycardWallet class. -/// Holds a persistent Python object in memory. +/// Rust wrapper around the Python `KeycardWallet` class. pub struct KeycardWallet { instance: Py, } impl KeycardWallet { - /// Create a new Python KeycardWallet instance + /// Create a new Python `KeycardWallet` instance. pub fn new(py: Python) -> PyResult { let module = py.import_bound("keycard_wallet")?; let class = module.getattr("KeycardWallet")?; @@ -22,7 +21,6 @@ impl KeycardWallet { }) } - /// Calls Python: is_unpaired_keycard_available() pub fn is_unpaired_keycard_available(&self, py: Python) -> PyResult { self.instance .bind(py) @@ -30,7 +28,7 @@ impl KeycardWallet { .extract() } - pub fn setup_communication(&self, py: Python, pin: &String) -> PyResult { + pub fn setup_communication(&self, py: Python, pin: &str) -> PyResult { let py_pin = pyo3::types::PyString::new_bound(py, pin); self.instance @@ -43,7 +41,7 @@ impl KeycardWallet { self.instance.bind(py).call_method0("disconnect")?.extract() } - pub fn get_public_key_for_path(&self, py: Python, path: &String) -> PyResult { + pub fn get_public_key_for_path(&self, py: Python, path: &str) -> PyResult { let public_key: Vec = self .instance .bind(py) @@ -55,11 +53,12 @@ impl KeycardWallet { Ok(PublicKey::try_new(public_key).expect("Expect a valid public key1")) } - pub fn get_public_key_for_path_with_connect(pin: &String, path: &String) -> PublicKey { + #[must_use] + pub fn get_public_key_for_path_with_connect(pin: &str, path: &str) -> PublicKey { let pub_key = Python::with_gil(|py| { python_path::add_python_path(py).expect("keycard_wallet.py not found"); - let wallet = KeycardWallet::new(py).expect("Expect keycard wallet"); + let wallet = Self::new(py).expect("Expect keycard wallet"); let is_connected = wallet .setup_communication(py, pin) @@ -82,7 +81,7 @@ impl KeycardWallet { pub fn sign_message_for_path( &self, py: Python, - path: &String, + path: &str, message: &[u8; 32], ) -> PyResult { let py_message = pyo3::types::PyBytes::new_bound(py, message); @@ -98,19 +97,20 @@ impl KeycardWallet { "Expected signature of exactly 64 bytes", ) })?; - println!("{:?}", signature); + println!("{signature:?}"); Ok(Signature { value: signature }) } - pub fn sign_message_for_path_with_connection( - pin: &String, - path: &String, + #[must_use] + pub fn sign_message_for_path_with_connect( + pin: &str, + path: &str, message: &[u8; 32], ) -> PyResult { - let signature = Python::with_gil(|py| { + Python::with_gil(|py| { python_path::add_python_path(py).expect("keycard_wallet.py not found"); - let wallet = KeycardWallet::new(py).expect("Expect keycard wallet"); + let wallet = Self::new(py).expect("Expect keycard wallet"); let is_connected = wallet .setup_communication(py, pin) @@ -127,9 +127,7 @@ impl KeycardWallet { let _ = wallet.disconnect(py); signature - }); - - signature + }) } pub fn load_mnemonic(&self, py: Python, mnemonic: &str) -> PyResult<()> { @@ -139,9 +137,10 @@ impl KeycardWallet { Ok(()) } - pub fn get_account_id_for_path_with_connect(pin: &String, key_path: &String) -> AccountId { - let public_key = KeycardWallet::get_public_key_for_path_with_connect(pin, key_path); + #[must_use] + pub fn get_account_id_for_path_with_connect(pin: &str, key_path: &str) -> String { + let public_key = Self::get_public_key_for_path_with_connect(pin, key_path); - AccountId::from(&public_key) + format!("Public/{}", AccountId::from(&public_key)) } } diff --git a/wallet/src/cli/python_path.rs b/keycard_wallet/src/python_path.rs similarity index 91% rename from wallet/src/cli/python_path.rs rename to keycard_wallet/src/python_path.rs index d03bffff..89d5167e 100644 --- a/wallet/src/cli/python_path.rs +++ b/keycard_wallet/src/python_path.rs @@ -2,7 +2,7 @@ use std::{env, path::PathBuf}; use pyo3::{prelude::*, types::PyList}; -/// Adds the project's `python/` directory and venv site-packages to Python's sys.path +/// Adds the project's `python/` directory and venv site-packages to Python's sys.path. pub fn add_python_path(py: Python) -> PyResult<()> { let current_dir = env::current_dir().expect("Failed to get current working directory"); @@ -14,7 +14,7 @@ pub fn add_python_path(py: Python) -> PyResult<()> { // Sanity check — warns early if a path doesn't exist for path in &paths_to_add { if !path.exists() { - eprintln!("Warning: Python path does not exist: {:?}", path); + eprintln!("Warning: Python path does not exist: {path:?}"); } } diff --git a/nssa/src/privacy_preserving_transaction/witness_set.rs b/nssa/src/privacy_preserving_transaction/witness_set.rs index 8d1ea033..9578e728 100644 --- a/nssa/src/privacy_preserving_transaction/witness_set.rs +++ b/nssa/src/privacy_preserving_transaction/witness_set.rs @@ -31,11 +31,7 @@ impl WitnessSet { } #[must_use] - pub fn from_list( - proof: Proof, - signatures: &[Signature], - public_keys: &[PublicKey], - ) -> Self { + pub fn from_list(proof: Proof, signatures: &[Signature], public_keys: &[PublicKey]) -> Self { assert_eq!(signatures.len(), public_keys.len()); let signatures_and_public_keys = signatures diff --git a/nssa/src/public_transaction/witness_set.rs b/nssa/src/public_transaction/witness_set.rs index f9692068..3f2a92f2 100644 --- a/nssa/src/public_transaction/witness_set.rs +++ b/nssa/src/public_transaction/witness_set.rs @@ -90,14 +90,14 @@ mod tests { assert_eq!(witness_set.signatures_and_public_keys.len(), 2); - let message_bytes = message.to_bytes(); + let message_hash = message.hash_message(); for ((signature, public_key), expected_public_key) in witness_set .signatures_and_public_keys .into_iter() .zip([pubkey1, pubkey2]) { assert_eq!(public_key, expected_public_key); - assert!(signature.is_valid_for(&message_bytes, &expected_public_key)); + assert!(signature.is_valid_for(&message_hash, &expected_public_key)); } } } diff --git a/wallet-ffi/src/transfer.rs b/wallet-ffi/src/transfer.rs index e65fa473..ca30ef3d 100644 --- a/wallet-ffi/src/transfer.rs +++ b/wallet-ffi/src/transfer.rs @@ -160,7 +160,7 @@ pub unsafe extern "C" fn wallet_ffi_transfer_shielded( 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, &None, &None), ) { Ok((tx_hash, _shared_key)) => { let tx_hash = CString::new(tx_hash.to_string()) @@ -412,7 +412,7 @@ pub unsafe extern "C" fn wallet_ffi_transfer_shielded_owned( 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, &None, &None)) { Ok((tx_hash, _shared_key)) => { let tx_hash = CString::new(tx_hash.to_string()) .map_or(ptr::null_mut(), std::ffi::CString::into_raw); diff --git a/wallet/src/cli/keycard.rs b/wallet/src/cli/keycard.rs index 8c825458..becc2872 100644 --- a/wallet/src/cli/keycard.rs +++ b/wallet/src/cli/keycard.rs @@ -52,7 +52,7 @@ impl WalletSubcommand for KeycardSubcommand { let wallet = KeycardWallet::new(py).expect("Expect keycard wallet"); let is_connected = wallet - .setup_communication(py, &pin.expect("TODO")) + .setup_communication(py, &pin.expect("Expect a pin as a String.")) .expect("Expect a Boolean."); if is_connected { @@ -61,7 +61,7 @@ impl WalletSubcommand for KeycardSubcommand { println!("\u{274c} Keycard is not connected to wallet."); } - let _ = wallet.load_mnemonic(py, &mnemonic.expect("TODO")); + let _ = wallet.load_mnemonic(py, &mnemonic.expect("Expect a mnemonic phrase as a string")); let _ = wallet.disconnect(py); }); diff --git a/wallet/src/cli/programs/native_token_transfer.rs b/wallet/src/cli/programs/native_token_transfer.rs index 3bd60464..2949e803 100644 --- a/wallet/src/cli/programs/native_token_transfer.rs +++ b/wallet/src/cli/programs/native_token_transfer.rs @@ -167,7 +167,7 @@ impl WalletSubcommand for AuthTransferSubcommand { )?), (None, None, Some(to_key_path)) => { Some(KeycardWallet::get_account_id_for_path_with_connect( - &pin.as_ref().expect("TODO"), + &pin.as_ref().expect("Expect a pin as a String."), &to_key_path, )) } @@ -486,7 +486,7 @@ impl WalletSubcommand for NativeTokenTransferProgramSubcommandShielded { let (tx_hash, secret) = NativeTokenTransfer(wallet_core) .send_shielded_transfer(from, to, amount, &pin, &key_path) - .await?; //TODO: here (marvin) + .await?; println!("Transaction hash is {tx_hash}"); diff --git a/wallet/src/helperfunctions.rs b/wallet/src/helperfunctions.rs index fcf19863..f299842b 100644 --- a/wallet/src/helperfunctions.rs +++ b/wallet/src/helperfunctions.rs @@ -69,7 +69,7 @@ pub fn resolve_id_or_label( (None, Some(label), None) => resolve_account_label(&label, labels, user_data), (None, None, Some(pin)) => Ok(KeycardWallet::get_account_id_for_path_with_connect( pin, - key_path.as_ref().expect("TODO"), + 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 3c82ec92..1362eed8 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -391,12 +391,12 @@ impl WalletCore { ) -> Result<(HashType, Vec), ExecutionFailureKind> { let acc_manager = privacy_preserving_tx::AccountManager::new(self, accounts).await?; - let mut pre_states = acc_manager.pre_states(); + let 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( pin, - key_path.as_ref().expect("TODO"), + key_path.as_ref().expect("Expect a key path String."), ); let (acc_id, _) = @@ -417,11 +417,11 @@ impl WalletCore { None }; - let mut nonces: Vec = acc_manager.public_account_nonces().into_iter().collect(); + let nonces: Vec = acc_manager.public_account_nonces().into_iter().collect(); - let mut account_ids: Vec = acc_manager.public_account_ids(); + let account_ids: Vec = acc_manager.public_account_ids(); - let mut visibility_mask = acc_manager.visibility_mask().to_vec(); + let visibility_mask = acc_manager.visibility_mask().to_vec(); if let Some(acc) = keycard_account.as_ref() { nonces.push(acc.account.nonce); @@ -627,11 +627,11 @@ impl WalletCore { 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() { + //if pin.is_none() { Ok( nssa::privacy_preserving_transaction::witness_set::WitnessSet::for_message( message, @@ -639,14 +639,14 @@ impl WalletCore { &acc_manager.public_account_auth(), ), ) - } else { + /*} else { let public_key = KeycardWallet::get_public_key_for_path_with_connect( - &pin.as_ref().expect("TODO"), - &key_path.as_ref().expect("TODO"), + &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("TODO"), - &key_path.as_ref().expect("TODO"), + &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"); @@ -661,7 +661,7 @@ impl WalletCore { &public_keys, ), ) - } + }*/ } pub fn sign_privacy_message_with_keycard( @@ -674,20 +674,12 @@ impl WalletCore { let mut signatures = Vec::::new(); let mut public_keys = Vec::::new(); - let message_bytes: [u8; 32] = { - let v = message.to_bytes(); - let mut bytes = [0_u8; 32]; - let len = v.len().min(32); - bytes[..len].copy_from_slice(&v[..len]); - bytes - }; - for path in key_paths.iter() { public_keys.push(KeycardWallet::get_public_key_for_path_with_connect( &pin, &path, )); signatures.push( - KeycardWallet::sign_message_for_path_with_connect(&pin, &path, &message_bytes) + KeycardWallet::sign_message_for_path_with_connect(&pin, &path, &message.hash_message()) .expect("Expect a valid signature"), ); } diff --git a/wallet/src/program_facades/native_token_transfer/public.rs b/wallet/src/program_facades/native_token_transfer/public.rs index 1ee1da6f..39f93b7d 100644 --- a/wallet/src/program_facades/native_token_transfer/public.rs +++ b/wallet/src/program_facades/native_token_transfer/public.rs @@ -60,12 +60,12 @@ impl NativeTokenTransfer<'_> { .expect("Expect a valid signature") } else { let pub_key = KeycardWallet::get_public_key_for_path_with_connect( - &pin.as_ref().expect("TODO"), - &key_path.as_ref().expect("TODO"), + &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("TODO"), - &key_path.as_ref().expect("TODO"), + &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 valid signature"); @@ -112,13 +112,13 @@ impl NativeTokenTransfer<'_> { WitnessSet::for_message(&message, &[signing_key]) } else { let pub_key = KeycardWallet::get_public_key_for_path_with_connect( - pin.as_ref().expect("TODO"), - key_path.as_ref().expect("TODO"), + 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().as_ref().expect("TODO"), - key_path.as_ref().expect("TODO"), + pin.as_ref().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."); diff --git a/wallet/src/program_facades/token.rs b/wallet/src/program_facades/token.rs index 36d7557b..6a5d7ee1 100644 --- a/wallet/src/program_facades/token.rs +++ b/wallet/src/program_facades/token.rs @@ -214,12 +214,12 @@ 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("TODO"), - &sender_key_path.as_ref().expect("TODO"), + &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("TODO"), - &sender_key_path.expect("TODO"), + &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");