From d244b828c548c97bd6c8b614a81ad9d3345a533f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Wed, 20 Sep 2023 12:00:43 +0200 Subject: [PATCH] Don't return error with custom remainder address and ledger nano --- bindings/nodejs-old/examples/ledger_nano.js | 2 +- bindings/nodejs/CHANGELOG.md | 10 +++++++ .../examples/secret_manager/ledger-nano.ts | 2 +- .../lib/types/wallet/transaction-options.ts | 2 +- .../examples/secret_manager/ledger_nano.py | 2 +- sdk/CHANGELOG.md | 4 +++ sdk/examples/client/ledger_nano.rs | 2 +- .../client/ledger_nano_transaction.rs | 2 +- sdk/examples/wallet/ledger_nano.rs | 2 +- .../input_selection/core/remainder.rs | 23 ++++++++++++++-- sdk/src/client/secret/ledger_nano.rs | 26 +++++++++++-------- 11 files changed, 57 insertions(+), 20 deletions(-) diff --git a/bindings/nodejs-old/examples/ledger_nano.js b/bindings/nodejs-old/examples/ledger_nano.js index 9221724bfa..7c263beb09 100644 --- a/bindings/nodejs-old/examples/ledger_nano.js +++ b/bindings/nodejs-old/examples/ledger_nano.js @@ -3,7 +3,7 @@ require('dotenv').config({ path: path.resolve(__dirname, '.env') }); const { AccountManager, CoinType } = require('@iota/wallet'); // In this example we will create addresses with a ledger nano hardware wallet -// To use the ledger nano simulator clone https://github.com/iotaledger/ledger-shimmer-app, run `git submodule init && git submodule update --recursive`, +// To use the ledger nano simulator clone https://github.com/iotaledger/ledger-iota-app, run `git submodule init && git submodule update --recursive`, // then `./build.sh -m nanos|nanox|nanosplus -s` and use `true` for `LedgerNano`. async function run() { diff --git a/bindings/nodejs/CHANGELOG.md b/bindings/nodejs/CHANGELOG.md index 93c275a525..cdf9417403 100644 --- a/bindings/nodejs/CHANGELOG.md +++ b/bindings/nodejs/CHANGELOG.md @@ -19,6 +19,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security --> +## 1.0.12 - 2023-09-DD + +### Changed + +- Made `TransactionOptions.allowMicroAmount` optional; + +### Fixed + +- Don't error if custom remainder address is provided with ledger nano; + ## 1.0.11 - 2023-09-14 ### Fixed diff --git a/bindings/nodejs/examples/secret_manager/ledger-nano.ts b/bindings/nodejs/examples/secret_manager/ledger-nano.ts index 667cba263f..14deeafd0c 100644 --- a/bindings/nodejs/examples/secret_manager/ledger-nano.ts +++ b/bindings/nodejs/examples/secret_manager/ledger-nano.ts @@ -8,7 +8,7 @@ require('dotenv').config({ path: '.env' }); // yarn run-example ./secret_manager/ledger-nano.ts // In this example we will get the ledger status and generate an address -// To use the ledger nano simulator clone https://github.com/iotaledger/ledger-shimmer-app, run `git submodule init && git submodule update --recursive`, +// To use the ledger nano simulator clone https://github.com/iotaledger/ledger-iota-app, run `git submodule init && git submodule update --recursive`, // then `./build.sh -m nanos|nanox|nanosplus -s` and use `true` in `LedgerSecretManager::new(true)`. async function run() { initLogger(); diff --git a/bindings/nodejs/lib/types/wallet/transaction-options.ts b/bindings/nodejs/lib/types/wallet/transaction-options.ts index c79292e99c..579760bb6f 100644 --- a/bindings/nodejs/lib/types/wallet/transaction-options.ts +++ b/bindings/nodejs/lib/types/wallet/transaction-options.ts @@ -26,7 +26,7 @@ export interface TransactionOptions { /** Optional note, that is only stored locally. */ note?: string; /** Whether to allow sending a micro amount. */ - allowMicroAmount: boolean; + allowMicroAmount?: boolean; } /** The possible remainder value strategies. */ diff --git a/bindings/python/examples/secret_manager/ledger_nano.py b/bindings/python/examples/secret_manager/ledger_nano.py index 3e1f3baa35..1c76c86e66 100644 --- a/bindings/python/examples/secret_manager/ledger_nano.py +++ b/bindings/python/examples/secret_manager/ledger_nano.py @@ -5,7 +5,7 @@ load_dotenv() # In this example we will get the ledger status and generate an address -# To use the ledger nano simulator clone https://github.com/iotaledger/ledger-shimmer-app, run `git submodule init && git submodule update --recursive`, +# To use the ledger nano simulator clone https://github.com/iotaledger/ledger-iota-app, run `git submodule init && git submodule update --recursive`, # then `./build.sh -m nanos|nanox|nanosplus -s` and use `True` in # `LedgerNanoSecretManager(True)`. diff --git a/sdk/CHANGELOG.md b/sdk/CHANGELOG.md index e6bd5c18d3..c022a3c27b 100644 --- a/sdk/CHANGELOG.md +++ b/sdk/CHANGELOG.md @@ -25,6 +25,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `migrate_db_chrysalis_to_stardust()` returns an error if no chrysalis data was found; +### Fixed + +- Don't error if custom remainder address is provided with ledger nano; + ## 1.0.3 - 2023-09-07 ### Added diff --git a/sdk/examples/client/ledger_nano.rs b/sdk/examples/client/ledger_nano.rs index 3b83715854..cd0d2ea713 100644 --- a/sdk/examples/client/ledger_nano.rs +++ b/sdk/examples/client/ledger_nano.rs @@ -4,7 +4,7 @@ //! In this example we will create testnet addresses with a simulated ledger nano hardware wallet. //! //! To use the ledger nano simulator, run the following commands: -//! 1. `clone https://github.com/iotaledger/ledger-shimmer-app` +//! 1. `clone https://github.com/iotaledger/ledger-iota-app` //! 2. `cd ledger-shimmer-app` //! 3. `git submodule init && git submodule update --recursive` //! 4. `./build.sh -m nanos|nanox|nanosplus -s` diff --git a/sdk/examples/client/ledger_nano_transaction.rs b/sdk/examples/client/ledger_nano_transaction.rs index 3029286067..05ec2b0f74 100644 --- a/sdk/examples/client/ledger_nano_transaction.rs +++ b/sdk/examples/client/ledger_nano_transaction.rs @@ -4,7 +4,7 @@ //! In this example we will create a testnet transaction with a simulated ledger nano hardware wallet. //! //! To use the ledger nano simulator, run the following commands: -//! 1. `clone https://github.com/iotaledger/ledger-shimmer-app` +//! 1. `clone https://github.com/iotaledger/ledger-iota-app` //! 2. `cd ledger-shimmer-app` //! 3. `git submodule init && git submodule update --recursive` //! 4. `./build.sh -m nanos|nanox|nanosplus -s` diff --git a/sdk/examples/wallet/ledger_nano.rs b/sdk/examples/wallet/ledger_nano.rs index 820dfbdfd5..9cb09e8278 100644 --- a/sdk/examples/wallet/ledger_nano.rs +++ b/sdk/examples/wallet/ledger_nano.rs @@ -4,7 +4,7 @@ //! In this example we will create addresses with a ledger nano hardware wallet. //! //! To use the ledger nano simulator -//! * clone https://github.com/iotaledger/ledger-shimmer-app, +//! * clone https://github.com/iotaledger/ledger-iota-app, //! * run `git submodule init && git submodule update --recursive`, //! * run `./build.sh -m nanos|nanox|nanosplus -s`, and //! * use `true` in `LedgerSecretManager::new(true)`. diff --git a/sdk/src/client/api/block_builder/input_selection/core/remainder.rs b/sdk/src/client/api/block_builder/input_selection/core/remainder.rs index b4abf79145..2d1b9d1464 100644 --- a/sdk/src/client/api/block_builder/input_selection/core/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/core/remainder.rs @@ -22,8 +22,27 @@ use crate::{ impl InputSelection { // Gets the remainder address from configuration of finds one from the inputs. fn get_remainder_address(&self) -> Option<(Address, Option)> { - if self.remainder_address.is_some() { - return self.remainder_address.map(|address| (address, None)); + if let Some(remainder_address) = self.remainder_address { + // Search in inputs for the Bip44 chain for the remainder address, so the ledger can regenerate it + #[cfg(feature = "ledger_nano")] + for input in self.available_inputs.iter().chain(self.selected_inputs.iter()) { + let alias_transition = is_alias_transition( + &input.output, + *input.output_id(), + self.outputs.as_slice(), + self.burn.as_ref(), + ); + // PANIC: safe to unwrap as treasury outputs can't be used as input. + let required_address = input + .output + .required_and_unlocked_address(self.timestamp, input.output_id(), alias_transition) + .unwrap() + .0; + if remainder_address == required_address { + return Some((remainder_address, input.chain)); + } + } + return Some((remainder_address, None)); } for input in &self.selected_inputs { diff --git a/sdk/src/client/secret/ledger_nano.rs b/sdk/src/client/secret/ledger_nano.rs index 6baa8a4a1d..fcc4ef42ab 100644 --- a/sdk/src/client/secret/ledger_nano.rs +++ b/sdk/src/client/secret/ledger_nano.rs @@ -296,19 +296,23 @@ impl SecretManage for LedgerSecretManager { } else { // figure out the remainder address and bip32 index (if there is one) let (remainder_address, remainder_bip32): (Option<&Address>, LedgerBIP32Index) = - match &prepared_transaction.remainder { - Some(a) => { - let chain = a.chain.ok_or(Error::MissingBip32Chain)?; - ( - Some(&a.address), - LedgerBIP32Index { - bip32_change: chain.change.harden().into(), - bip32_index: chain.address_index.harden().into(), + prepared_transaction.remainder.as_ref().map_or_else( + || (None, LedgerBIP32Index::default()), + |a| { + a.chain.map_or_else( + || (None, LedgerBIP32Index::default()), + |chain| { + ( + Some(&a.address), + LedgerBIP32Index { + bip32_change: chain.change.harden().into(), + bip32_index: chain.address_index.harden().into(), + }, + ) }, ) - } - None => (None, LedgerBIP32Index::default()), - }; + }, + ); let mut remainder_index = 0u16; if let Some(remainder_address) = remainder_address {