diff --git a/hardware-wallet/src/ledger.rs b/hardware-wallet/src/ledger.rs index bfed080cf9766b..d23147bc0c8528 100644 --- a/hardware-wallet/src/ledger.rs +++ b/hardware-wallet/src/ledger.rs @@ -11,13 +11,13 @@ const APDU_CLA: u8 = 0xe0; const APDU_PAYLOAD_HEADER_LEN: usize = 7; const SOL_DERIVATION_PATH_BE: [u8; 8] = [0x80, 0, 0, 44, 0x80, 0, 0x01, 0xF5]; // 44'/501', Solana -// const SOL_DERIVATION_PATH_BE: [u8; 8] = [0x80, 0, 0, 44, 0x80, 0, 0x00, 0x94]; // 44'/148', Stellar + // const SOL_DERIVATION_PATH_BE: [u8; 8] = [0x80, 0, 0, 44, 0x80, 0, 0x00, 0x94]; // 44'/148', Stellar /// Ledger vendor ID const LEDGER_VID: u16 = 0x2c97; /// Ledger product IDs: [Nano S and Nano X] // TODO: do we need to support Blue? -const LEDGER_PIDS: [u16; 2] = [0x0001, 0x0004]; +const _LEDGER_PIDS: [u16; 2] = [0x0001, 0x0004]; // TODO: Nano S pid doesn't match expected LEDGER_PIDS value... const LEDGER_TRANSPORT_HEADER_LEN: usize = 5; const MAX_CHUNK_SIZE: usize = 255; @@ -341,25 +341,24 @@ impl HardwareWallet for LedgerWallet { } /// Check if the detected device is a valid `Ledger device` by checking both the product ID and the vendor ID -pub fn is_valid_ledger(vendor_id: u16, product_id: u16) -> bool { - vendor_id == LEDGER_VID && LEDGER_PIDS.contains(&product_id) +pub fn is_valid_ledger(vendor_id: u16, _product_id: u16) -> bool { + // vendor_id == LEDGER_VID && LEDGER_PIDS.contains(&product_id) + vendor_id == LEDGER_VID } #[cfg(test)] mod tests { use super::*; - use crate::hardware_wallet::{initialize_wallet_manager, HardwareWalletManager}; - use parking_lot::Mutex; - use std::sync::Arc; + use crate::hardware_wallet::initialize_wallet_manager; + use std::collections::HashSet; /// This test can't be run without an actual ledger device connected with the `Ledger Wallet Solana application` running #[test] - fn ledger_test() { + fn ledger_pubkey_test() { let wallet_manager = initialize_wallet_manager(); // Update device list wallet_manager.update_devices().expect("No Ledger found, make sure you have a unlocked Ledger connected with the Ledger Wallet Solana running"); - assert!(wallet_manager.list_devices().len() > 0); // Fetch the base pubkey of a connected ledger device @@ -371,28 +370,42 @@ mod tests { .map(|d| d.pubkey.clone()) .expect("No ledger device detected"); - println!("{:?}", ledger_base_pubkey); - let ledger = wallet_manager .get_ledger(&ledger_base_pubkey) .expect("get device"); - for x in 0..16 { - let pubkey = ledger.get_pubkey(0, Some(x)).expect("get pubkey"); - println!("{:?}", pubkey); - } - let pubkey = ledger.get_pubkey(1, None).expect("get pubkey"); - println!("Different account: {:?}", pubkey); - - let stellar_string = "GCDOHD52HDBRH63SSIKISTH2KBRIE7YLW7L3NNSCVIUXFH73RPGS3MAC"; - let decoded = - base32::decode(base32::Alphabet::RFC4648 { padding: false }, stellar_string).unwrap(); - let maybe_pubkey = Pubkey::new(&decoded[1..33]); - println!("{:?}", maybe_pubkey); - - // // 44 bytes transaction - // let tx = FromHex::from_hex("eb018504a817c80082520894a6ca2e6707f2cc189794a9dd459d5b05ed1bcd1c8703f26fcfb7a22480018080").unwrap(); - // let signature = ledger.sign_transaction(&address, &tx); - // assert!(signature.is_ok()); + let mut pubkey_set = HashSet::new(); + pubkey_set.insert(ledger_base_pubkey); + + let pubkey_0_0 = ledger + .get_pubkey(DerivationPath { + account: 0, + change: Some(0), + }) + .expect("get pubkey"); + pubkey_set.insert(pubkey_0_0); + let pubkey_0_1 = ledger + .get_pubkey(DerivationPath { + account: 0, + change: Some(1), + }) + .expect("get pubkey"); + pubkey_set.insert(pubkey_0_1); + let pubkey_1 = ledger + .get_pubkey(DerivationPath { + account: 1, + change: None, + }) + .expect("get pubkey"); + pubkey_set.insert(pubkey_1); + let pubkey_1_0 = ledger + .get_pubkey(DerivationPath { + account: 1, + change: Some(0), + }) + .expect("get pubkey"); + pubkey_set.insert(pubkey_1_0); + + assert_eq!(pubkey_set.len(), 5); // Ensure keys at various derivation paths are unique } }