diff --git a/src/psbt.js b/src/psbt.js index 9f29525..4dc72ff 100644 --- a/src/psbt.js +++ b/src/psbt.js @@ -61,6 +61,20 @@ class Psbt extends bip174_1.Psbt { ); } } + } else if (input.witnessUtxo) { + if (input.redeemScript) { + const redeemScriptOutput = payments.p2sh({ + redeem: { output: input.redeemScript }, + }).output; + // If a redeemScript is provided, the scriptPubKey must be for that redeemScript + if ( + Buffer.compare(input.witnessUtxo.script, redeemScriptOutput) !== 0 + ) { + throw new Error( + `Redeem script for input #${inputIndex} doesn't match the scriptPubKey in the prevout`, + ); + } + } } // TODO: Get hash to sign const hash = Buffer.alloc(32); diff --git a/ts_src/psbt.ts b/ts_src/psbt.ts index 75a90d7..ab1fd7b 100644 --- a/ts_src/psbt.ts +++ b/ts_src/psbt.ts @@ -65,6 +65,21 @@ export class Psbt extends PsbtBase { ); } } + } else if (input.witnessUtxo) { + if (input.redeemScript) { + const redeemScriptOutput = payments.p2sh({ + redeem: { output: input.redeemScript }, + }).output as Buffer; + + // If a redeemScript is provided, the scriptPubKey must be for that redeemScript + if ( + Buffer.compare(input.witnessUtxo.script, redeemScriptOutput) !== 0 + ) { + throw new Error( + `Redeem script for input #${inputIndex} doesn't match the scriptPubKey in the prevout`, + ); + } + } } // TODO: Get hash to sign