Check redeem script matches witness utxo when signing PSBT input

This commit is contained in:
Luke Childs 2019-06-28 18:14:37 +07:00
parent 6562ee96a4
commit 08627e65a3
2 changed files with 29 additions and 0 deletions

View file

@ -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 // TODO: Get hash to sign
const hash = Buffer.alloc(32); const hash = Buffer.alloc(32);

View file

@ -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 // TODO: Get hash to sign