Browse Source

Check redeem script matches witness utxo when signing PSBT input

psbt
Luke Childs 6 years ago
parent
commit
08627e65a3
  1. 14
      src/psbt.js
  2. 15
      ts_src/psbt.ts

14
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);

15
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

Loading…
Cancel
Save