From 41898ea8c4456e1166c04b811937ce230d2c4c0d Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Wed, 7 Feb 2024 18:34:38 +0100 Subject: [PATCH 1/2] Ledger nano generate_ed25519_public_keys --- Cargo.lock | 7 ++- sdk/Cargo.toml | 2 +- sdk/src/client/secret/ledger_nano.rs | 65 ++++++++++++++-------------- 3 files changed, 37 insertions(+), 37 deletions(-) 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 e0d3f2ff51..34ca5c0ddf 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( From 2dfb9fa8c94d3fd7094e5565e61e8008724dc6a6 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 9 Feb 2024 10:01:22 +0100 Subject: [PATCH 2/2] Use 1.0.3 --- Cargo.lock | 53 ++++++++++++++++++++++++++++---------------------- sdk/Cargo.toml | 2 +- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c3a8e40469..0c3dc48122 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -456,9 +456,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.18" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" +checksum = "80c21025abd42669a92efc996ef13cfb2c5c627858421ea58d5c3b331a6c134f" dependencies = [ "clap_builder", "clap_derive", @@ -466,21 +466,21 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.18" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" +checksum = "458bf1f341769dfcf849846f65dffdf9146daa56bcd2a47cb4e1de9915567c99" dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim", + "strsim 0.11.0", ] [[package]] name = "clap_derive" -version = "4.4.7" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" dependencies = [ "heck", "proc-macro2", @@ -490,9 +490,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "cli-wallet" @@ -742,7 +742,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn 2.0.48", ] @@ -1591,8 +1591,9 @@ dependencies = [ [[package]] name = "iota-ledger-nano" -version = "1.0.1" -source = "git+https://github.com/iotaledger/ledger.rs?branch=feat/generate-pubkeys#68bf82dbf350060e12897d0531718b5c9065a8bd" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "434abd10cd26c00345c19290f87d0e66104c6ce3069a5b7e1eb6c09a47ea18ca" dependencies = [ "arrayref", "byteorder", @@ -1749,12 +1750,12 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "is-terminal" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" +checksum = "fe8f25ce1159c7740ff0b9b2f5cdf4a8428742ba7c112b9f20f22cd5219c7dab" dependencies = [ "hermit-abi", - "rustix", + "libc", "windows-sys 0.52.0", ] @@ -1778,9 +1779,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "jobserver" -version = "0.1.27" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" +checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" dependencies = [ "libc", ] @@ -1998,9 +1999,9 @@ checksum = "d4b4532cf86bfef556348ac65e561e3123879f0e7566cca6d43a6ff5326f13df" [[package]] name = "napi-derive" -version = "2.15.0" +version = "2.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7622f0dbe0968af2dacdd64870eee6dee94f93c989c841f1ad8f300cf1abd514" +checksum = "8d56bb899c164ab1be5e542ae7db8b26750c864bf2eef07295f17754e6358777" dependencies = [ "cfg-if", "convert_case", @@ -2012,9 +2013,9 @@ dependencies = [ [[package]] name = "napi-derive-backend" -version = "1.0.59" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ec514d65fce18a959be55e7f683ac89c6cb850fb59b09e25ab777fd5a4a8d9e" +checksum = "6cf2d74ac66fd1cccb646be75fdd1c1dce8acfe20a68f61566a31da0d3eb9786" dependencies = [ "convert_case", "proc-macro2", @@ -2081,9 +2082,9 @@ checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", ] @@ -3149,6 +3150,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strsim" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" + [[package]] name = "strum" version = "0.25.0" diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 1070adf5c8..e83dd06b95 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 = { git = "https://github.com/iotaledger/ledger.rs", branch = "feat/generate-pubkeys", 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 }