Skip to content

Commit

Permalink
chore: additional checks before adding tapInternalKey, ref #4125
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Feb 15, 2024
1 parent 5a87a5d commit 09a17bf
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/app/store/accounts/blockchain/bitcoin/bitcoin.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,21 @@ export function useAddTapInternalKeysIfMissing() {
const witnessOutputScript =
input.witnessUtxo?.script && btc.OutScript.decode(input.witnessUtxo.script);

if (taprootSigner && witnessOutputScript?.type === 'tr' && !input.tapInternalKey) {
// Original implementation supports auto-adding of tapInternalKey if
// missing. This functionality helps some developers who don't form their
// tx correctly, however neglects certain alternate use cases, e.g. script
// spends. We should consider removing this functionality in the future.
function shouldAssumeTxNeedsTaprootInternalKeyAdded() {
if (!taprootSigner) return false;
if (witnessOutputScript?.type !== 'tr') return false;
// Already has it, doesn't need
if (input.tapInternalKey) return false;
// Is a script spend, doesn't need `tapInternalKey`
if (input.tapLeafScript) return false;
return true;
}

if (shouldAssumeTxNeedsTaprootInternalKeyAdded()) {
void analytics.track('psbt_sign_request_p2tr_missing_taproot_internal_key');
tx.updateInput(index, { ...input, tapInternalKey: taprootSigner.payment.tapInternalKey });
}
Expand Down

0 comments on commit 09a17bf

Please sign in to comment.