This commit is contained in:
jonesmarvin8 2026-04-27 20:12:57 -04:00
parent 016d063329
commit e5eae57a5f
3 changed files with 34 additions and 62 deletions

View File

@ -1,4 +1,5 @@
use std::{env, path::PathBuf}; use std::{env, path::PathBuf};
use pyo3::{prelude::*, types::PyList}; 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.
@ -25,11 +26,9 @@ pub fn add_python_path(py: Python<'_>) -> PyResult<()> {
let path_str = path.to_str().expect("Invalid path"); let path_str = path.to_str().expect("Invalid path");
// Avoid duplicating the path // Avoid duplicating the path
let already_present = sys_path.iter().any(|p| { let already_present = sys_path
p.extract::<&str>() .iter()
.map(|s| s == path_str) .any(|p| p.extract::<&str>().map(|s| s == path_str).unwrap_or(false));
.unwrap_or(false)
});
if !already_present { if !already_present {
sys_path.insert(0, path_str)?; sys_path.insert(0, path_str)?;

View File

@ -288,8 +288,6 @@ impl WalletSubcommand for TokenProgramAgnosticSubcommand {
sender_account_id: from, sender_account_id: from,
recipient_account_id: to, recipient_account_id: to,
balance_to_move: amount, balance_to_move: amount,
pin,
sender_key_path: from_key_path,
}, },
) )
} }
@ -566,10 +564,6 @@ pub enum TokenProgramSubcommandPublic {
recipient_account_id: String, recipient_account_id: String,
#[arg(short, long)] #[arg(short, long)]
balance_to_move: u128, balance_to_move: u128,
#[arg(long)]
pin: Option<String>,
#[arg(long)]
sender_key_path: Option<String>,
}, },
// Burn tokens using the token program // Burn tokens using the token program
BurnToken { BurnToken {
@ -802,16 +796,12 @@ impl WalletSubcommand for TokenProgramSubcommandPublic {
sender_account_id, sender_account_id,
recipient_account_id, recipient_account_id,
balance_to_move, balance_to_move,
pin,
sender_key_path,
} => { } => {
Token(wallet_core) Token(wallet_core)
.send_transfer_transaction( .send_transfer_transaction(
sender_account_id.parse().unwrap(), sender_account_id.parse().unwrap(),
recipient_account_id.parse().unwrap(), recipient_account_id.parse().unwrap(),
balance_to_move, balance_to_move,
pin,
sender_key_path,
) )
.await?; .await?;
Ok(SubcommandReturnValue::Empty) Ok(SubcommandReturnValue::Empty)

View File

@ -1,6 +1,5 @@
use common::{HashType, transaction::NSSATransaction}; use common::{HashType, transaction::NSSATransaction};
use keycard_wallet::KeycardWallet; use nssa::{AccountId, program::Program};
use nssa::{AccountId, program::Program, public_transaction::WitnessSet};
use nssa_core::{NullifierPublicKey, SharedSecretKey, encryption::ViewingPublicKey}; use nssa_core::{NullifierPublicKey, SharedSecretKey, encryption::ViewingPublicKey};
use sequencer_service_rpc::RpcClient as _; use sequencer_service_rpc::RpcClient as _;
use token_core::Instruction; use token_core::Instruction;
@ -154,8 +153,6 @@ impl Token<'_> {
sender_account_id: AccountId, sender_account_id: AccountId,
recipient_account_id: AccountId, recipient_account_id: AccountId,
amount: u128, amount: u128,
pin: Option<String>,
sender_key_path: Option<String>,
) -> Result<HashType, ExecutionFailureKind> { ) -> Result<HashType, ExecutionFailureKind> {
let account_ids = vec![sender_account_id, recipient_account_id]; let account_ids = vec![sender_account_id, recipient_account_id];
let program_id = nssa::program::Program::token().id(); let program_id = nssa::program::Program::token().id();
@ -167,12 +164,34 @@ impl Token<'_> {
.get_accounts_nonces(vec![sender_account_id]) .get_accounts_nonces(vec![sender_account_id])
.await .await
.map_err(ExecutionFailureKind::SequencerError)?; .map_err(ExecutionFailureKind::SequencerError)?;
let recipient_nonces = self
let mut private_keys = Vec::new();
let sender_sk = self
.0 .0
.get_accounts_nonces(vec![recipient_account_id]) .storage
.await .user_data
.map_err(ExecutionFailureKind::SequencerError)?; .get_pub_account_signing_key(sender_account_id)
nonces.extend(recipient_nonces); .ok_or(ExecutionFailureKind::KeyNotFoundError)?;
private_keys.push(sender_sk);
if let Some(recipient_sk) = self
.0
.storage
.user_data
.get_pub_account_signing_key(recipient_account_id)
{
private_keys.push(recipient_sk);
let recipient_nonces = self
.0
.get_accounts_nonces(vec![recipient_account_id])
.await
.map_err(ExecutionFailureKind::SequencerError)?;
nonces.extend(recipient_nonces);
} else {
println!(
"Receiver's account ({recipient_account_id}) private key not found in wallet. Proceeding with only sender's key."
);
}
let message = nssa::public_transaction::Message::try_new( let message = nssa::public_transaction::Message::try_new(
program_id, program_id,
@ -181,44 +200,8 @@ impl Token<'_> {
instruction, instruction,
) )
.unwrap(); .unwrap();
let witness_set =
let witness_set = if let Some(pin) = &pin { nssa::public_transaction::WitnessSet::for_message(&message, &private_keys);
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
.storage
.user_data
.get_pub_account_signing_key(sender_account_id)
.ok_or(ExecutionFailureKind::KeyNotFoundError)?;
private_keys.push(sender_sk);
if let Some(recipient_sk) = self
.0
.storage
.user_data
.get_pub_account_signing_key(recipient_account_id)
{
private_keys.push(recipient_sk);
} else {
println!(
"Receiver's account ({recipient_account_id}) private key not found in wallet. Proceeding with only sender's key."
);
}
nssa::public_transaction::WitnessSet::for_message(&message, &private_keys)
};
let tx = nssa::PublicTransaction::new(message, witness_set); let tx = nssa::PublicTransaction::new(message, witness_set);