From 95c2d65092911f334c6b692410e466ca25b8ca38 Mon Sep 17 00:00:00 2001 From: Murisi Tarusenga Date: Fri, 30 Aug 2024 09:46:50 +0200 Subject: [PATCH 1/3] Enable the signing logic to fall back to the hardware wallet if secret key is not found. --- crates/sdk/src/signing.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/sdk/src/signing.rs b/crates/sdk/src/signing.rs index 8d10bef5f7..cda90116ca 100644 --- a/crates/sdk/src/signing.rs +++ b/crates/sdk/src/signing.rs @@ -232,7 +232,13 @@ where for public_key in &signing_data.public_keys { if !used_pubkeys.contains(public_key) { - let secret_key = find_key_by_pk(&mut wallet, args, public_key)?; + let Ok(secret_key) = + find_key_by_pk(&mut wallet, args, public_key) + else { + // If the secret key is not found, continue because the + // hardware wallet may still be able to sign this + continue; + }; used_pubkeys.insert(public_key.clone()); signing_tx_keypairs.push(secret_key); } From 389e47cbd2e7b8b3b18d169b6e274bc6f3505183 Mon Sep 17 00:00:00 2001 From: Murisi Tarusenga Date: Fri, 30 Aug 2024 09:56:39 +0200 Subject: [PATCH 2/3] Added changelog entry. --- .changelog/unreleased/bug-fixes/3730-enable-hw-fallback.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/unreleased/bug-fixes/3730-enable-hw-fallback.md diff --git a/.changelog/unreleased/bug-fixes/3730-enable-hw-fallback.md b/.changelog/unreleased/bug-fixes/3730-enable-hw-fallback.md new file mode 100644 index 0000000000..f6d75791c5 --- /dev/null +++ b/.changelog/unreleased/bug-fixes/3730-enable-hw-fallback.md @@ -0,0 +1,3 @@ +- Enable the signing logic to fall back to the hardware wallet + if a secret key is not found in software wallet store. + ([\#3730](https://github.com/anoma/namada/pull/3730)) \ No newline at end of file From 24e790afed11d9fdfa231f3aa8e077e2dba5d3d7 Mon Sep 17 00:00:00 2001 From: Murisi Tarusenga Date: Mon, 2 Sep 2024 08:00:39 +0200 Subject: [PATCH 3/3] Ensure that the number of used public keys exceeds the account threshold. --- crates/sdk/src/signing.rs | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/crates/sdk/src/signing.rs b/crates/sdk/src/signing.rs index cda90116ca..4b5bd1f42c 100644 --- a/crates/sdk/src/signing.rs +++ b/crates/sdk/src/signing.rs @@ -254,8 +254,8 @@ where } // Then try to sign the raw header using the hardware wallet - for pubkey in signing_data.public_keys { - if !used_pubkeys.contains(&pubkey) && pubkey != signing_data.fee_payer { + for pubkey in &signing_data.public_keys { + if !used_pubkeys.contains(pubkey) && *pubkey != signing_data.fee_payer { if let Ok(ntx) = sign( tx.clone(), pubkey.clone(), @@ -282,7 +282,10 @@ where Ok(fee_payer_keypair) => { tx.sign_wrapper(fee_payer_keypair); } - Err(_) => { + // The case where tge fee payer also signs the inner transaction + Err(_) + if signing_data.public_keys.contains(&signing_data.fee_payer) => + { *tx = sign( tx.clone(), signing_data.fee_payer.clone(), @@ -290,9 +293,32 @@ where user_data, ) .await?; + used_pubkeys.insert(signing_data.fee_payer.clone()); + } + // The case where the fee payer does not sign the inner transaction + Err(_) => { + *tx = sign( + tx.clone(), + signing_data.fee_payer.clone(), + HashSet::from([Signable::FeeHeader]), + user_data, + ) + .await?; } } - Ok(()) + // Then make sure that the number of public keys used exceeds the threshold + let used_pubkeys_len = used_pubkeys + .len() + .try_into() + .expect("Public keys associated with account exceed 127"); + if used_pubkeys_len < signing_data.threshold { + Err(Error::from(TxSubmitError::MissingSigningKeys( + signing_data.threshold, + used_pubkeys_len, + ))) + } else { + Ok(()) + } } /// Return the necessary data regarding an account to be able to generate a