Skip to content

Commit d6a7b6a

Browse files
committed
psbt: avoid a redundant keypath search for p2tr input signing
1 parent 5b4da6c commit d6a7b6a

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/psbt.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4642,19 +4642,14 @@ int wally_psbt_sign_input_bip32(struct wally_psbt *psbt,
46424642
return WALLY_EINVAL;
46434643

46444644
/* Find the public key this signature is for */
4645-
ret = wally_map_find_bip32_public_key_from(&inp->keypaths, subindex,
4646-
hdkey, &pubkey_idx);
4647-
if (ret != WALLY_OK || !pubkey_idx) {
4648-
/* Try again with the taproot public key */
4645+
if (is_taproot)
46494646
ret = wally_map_find_bip32_public_key_from(&inp->taproot_leaf_hashes,
46504647
subindex, hdkey,
46514648
&pubkey_idx);
4652-
if (ret == WALLY_OK && pubkey_idx && !is_taproot)
4653-
return WALLY_EINVAL; /* Must be tr if we have a tr key */
4654-
} else if (ret == WALLY_OK && pubkey_idx && is_taproot) {
4655-
return WALLY_EINVAL; /* Must not be tr if we have a non-tr key */
4656-
}
4657-
4649+
else
4650+
ret = wally_map_find_bip32_public_key_from(&inp->keypaths,
4651+
subindex, hdkey,
4652+
&pubkey_idx);
46584653
if (ret != WALLY_OK || !pubkey_idx)
46594654
return WALLY_EINVAL; /* Signing pubkey key not found */
46604655

0 commit comments

Comments
 (0)