Skip to content

Commit

Permalink
Ledger nano generate_ed25519_public_keys (iotaledger#1968)
Browse files Browse the repository at this point in the history
* Ledger nano generate_ed25519_public_keys

* Use 1.0.3

---------

Co-authored-by: Thoralf-M <[email protected]>
  • Loading branch information
thibault-martinez and Thoralf-M authored Feb 9, 2024
1 parent 1ce7d0c commit 0e1dc3e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 58 deletions.
56 changes: 31 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { version = "1.0.3", 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 }
Expand Down
65 changes: 33 additions & 32 deletions sdk/src/client/secret/ledger_nano.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,
_options: impl Into<Option<GenerateAddressOptions>> + Send,
coin_type: u32,
account_index: u32,
address_indexes: Range<u32>,
options: impl Into<Option<GenerateAddressOptions>> + Send,
) -> Result<Vec<ed25519::PublicKey>, 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::<Result<Vec<_>, _>>()?)
}

async fn generate_evm_addresses(
Expand Down

0 comments on commit 0e1dc3e

Please sign in to comment.