From 9f1c8bdf291d1aac1c18343e21d3406582c3d8d1 Mon Sep 17 00:00:00 2001 From: jonesmarvin8 <83104039+jonesmarvin8@users.noreply.github.com> Date: Thu, 23 Apr 2026 09:47:09 -0400 Subject: [PATCH] fixed load for non continuous run --- python/keycard_wallet.py | 10 +++------ wallet/src/cli/keycard.rs | 37 ++++++++++++++------------------ wallet/src/cli/keycard_wallet.rs | 7 +++--- 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/python/keycard_wallet.py b/python/keycard_wallet.py index df968aec..e2214462 100644 --- a/python/keycard_wallet.py +++ b/python/keycard_wallet.py @@ -71,15 +71,10 @@ class KeycardWallet: mnemo = Mnemonic("english") seed = mnemo.to_seed(mnemonic, passphrase) - print(f"PIN verified: {self.card.is_pin_verified}") - print(f"Secure channel open: {self.card.is_secure_channel_open}") - print(f"Card initialized: {self.card.status.get('initialized', False)}") - print(f"Seed length: {len(seed)}") - # Load the LEE seed onto the card result = self.card.load_key( key_type = constants.LoadKeyType.BIP39_SEED, - bip39_seed = seed + lee_seed = seed ) return True @@ -125,7 +120,8 @@ class KeycardWallet: signature = self.card.sign_with_path( digest = message, - path= path, + path = path, + algorithm = constants.SigningAlgorithm.SCHNORR_BIP340, make_current = False ) diff --git a/wallet/src/cli/keycard.rs b/wallet/src/cli/keycard.rs index bc76763f..38137713 100644 --- a/wallet/src/cli/keycard.rs +++ b/wallet/src/cli/keycard.rs @@ -11,19 +11,17 @@ use crate::{ #[derive(Subcommand, Debug, Clone)] pub enum KeycardSubcommand { Available, - Connect { - #[arg( - short, - long, - )] - pin: Option, - }, Load { #[arg( short, long, )] mnemonic: Option, + #[arg( + short, + long, + )] + pin: Option }, } @@ -49,7 +47,7 @@ impl WalletSubcommand for KeycardSubcommand { }); Ok(SubcommandReturnValue::Empty) - }, + },/* Self::Connect { pin } => { // TODO This should be persistent. Python::with_gil(|py| { @@ -67,27 +65,24 @@ impl WalletSubcommand for KeycardSubcommand { }); Ok(SubcommandReturnValue::Empty) - }, - Self::Load { mnemonic } => { - // TODO This should be persistent. + },*/ + Self::Load { mnemonic, pin } => { 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.load_account_keys(py, &mnemonic.expect("TODO")); - }); + let is_connected = wallet.setup_communication(py, pin.expect("TODO")).expect("Expect a Boolean."); - Ok(SubcommandReturnValue::Empty) - }, - Self::Remove => { - // TODO This should be persistent. - Python::with_gil(|py| { - python_path::add_python_path(py).expect("keycard_wallet.py not found"); + if is_connected { + println!("\u{2705} Keycard is now connected to wallet."); + } else { + println!("\u{274c} Keycard is not connected to wallet."); + } - let wallet = KeycardWallet::new(py).expect("Expect keycard wallet"); + let _ = wallet.load_mnemonic(py, &mnemonic.expect("TODO")); - let _ = wallet.remove_account_keys(py); + let _ = wallet.disconnect(py); }); Ok(SubcommandReturnValue::Empty) diff --git a/wallet/src/cli/keycard_wallet.rs b/wallet/src/cli/keycard_wallet.rs index f70495c0..b08483b1 100644 --- a/wallet/src/cli/keycard_wallet.rs +++ b/wallet/src/cli/keycard_wallet.rs @@ -57,15 +57,16 @@ impl KeycardWallet { pub fn get_public_key_for_path( &self, py: Python, - path: &str, + path: Vec, ) -> PyResult> { + let py_path = Self::convert_path_to_string(path); let public_key: Vec = self.instance .bind(py) - .call_method1("get_public_key_for_path", (py_message, path))? + .call_method1("get_public_key_for_path", (py_path,))? .getattr("public_key")? .extract()?; - Ok(Some(public_key.bytes())) + Ok(Some(public_key.try_into().expect("TODO"))) } pub fn sign_message_with_path(&self, py: Python, path: Vec, message: &[u8; 32]) -> PyResult<[u8; 64]> {