diff --git a/Cargo.lock b/Cargo.lock index 787d40e0e5..c3a8e40469 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1362,9 +1362,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hidapi" -version = "2.5.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830eccace7c861211d0ad04288e5dad690d6711b0db152084da58882ee7a840a" +checksum = "9a722fb137d008dbf264f54612457f8eb6a299efbcb0138178964a0809035d74" dependencies = [ "cc", "cfg-if", @@ -1592,8 +1592,7 @@ dependencies = [ [[package]] name = "iota-ledger-nano" version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fef85d9f5e9cf947d8a4f6aabb74f38ef970aade7d60112c8b8637596f07f93" +source = "git+https://github.com/iotaledger/ledger.rs?branch=feat/generate-pubkeys#68bf82dbf350060e12897d0531718b5c9065a8bd" dependencies = [ "arrayref", "byteorder", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 834d3e5c77..1070adf5c8 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -69,7 +69,7 @@ futures = { version = "0.3.30", default-features = false, features = [ "thread-pool", ], optional = true } instant = { version = "0.1.12", default-features = false, optional = true } -iota-ledger-nano = { version = "1.0.1", default-features = false, optional = true } +iota-ledger-nano = { git = "https://github.com/iotaledger/ledger.rs", branch = "feat/generate-pubkeys", default-features = false, optional = true } iota_stronghold = { version = "2.0.0", default-features = false, optional = true } log = { version = "0.4.20", default-features = false, optional = true } once_cell = { version = "1.19.0", default-features = false, optional = true } diff --git a/sdk/src/client/secret/ledger_nano.rs b/sdk/src/client/secret/ledger_nano.rs index 8daff56bb2..07f9f6a754 100644 --- a/sdk/src/client/secret/ledger_nano.rs +++ b/sdk/src/client/secret/ledger_nano.rs @@ -142,39 +142,40 @@ impl SecretManage for LedgerSecretManager { &self, // https://github.com/satoshilabs/slips/blob/master/slip-0044.md // current ledger app only supports IOTA_COIN_TYPE, SHIMMER_COIN_TYPE and TESTNET_COIN_TYPE - _coin_type: u32, - _account_index: u32, - _address_indexes: Range, - _options: impl Into> + Send, + coin_type: u32, + account_index: u32, + address_indexes: Range, + options: impl Into> + Send, ) -> Result, Self::Error> { - // need an update on the ledger C lib - todo!(); - // let options = options.into().unwrap_or_default(); - // let bip32_account = account_index.harden().into(); - - // let bip32 = LedgerBIP32Index { - // bip32_index: address_indexes.start.harden().into(), - // bip32_change: u32::from(options.internal).harden().into(), - // }; - - // // lock the mutex to prevent multiple simultaneous requests to a ledger - // let lock = self.mutex.lock().await; - - // // get ledger - // let ledger = get_ledger(coin_type, bip32_account, self.is_simulator).map_err(Error::from)?; - // if ledger.is_debug_app() { - // ledger - // .set_non_interactive_mode(self.non_interactive) - // .map_err(Error::from)?; - // } - - // let addresses = ledger - // .get_addresses(options.ledger_nano_prompt, bip32, address_indexes.len()) - // .map_err(Error::from)?; - - // drop(lock); - - // Ok(addresses.into_iter().map(Ed25519Address::new).collect()) + let options = options.into().unwrap_or_default(); + let bip32_account = account_index.harden().into(); + + let bip32 = LedgerBIP32Index { + bip32_index: address_indexes.start.harden().into(), + bip32_change: u32::from(options.internal).harden().into(), + }; + + // lock the mutex to prevent multiple simultaneous requests to a ledger + let lock = self.mutex.lock().await; + + // get ledger + let ledger = get_ledger(coin_type, bip32_account, self.is_simulator).map_err(Error::from)?; + if ledger.is_debug_app() { + ledger + .set_non_interactive_mode(self.non_interactive) + .map_err(Error::from)?; + } + + let public_keys = ledger + .get_public_keys(options.ledger_nano_prompt, bip32, address_indexes.len()) + .map_err(Error::from)?; + + drop(lock); + + Ok(public_keys + .into_iter() + .map(ed25519::PublicKey::try_from_bytes) + .collect::, _>>()?) } async fn generate_evm_addresses(