Check signatures for sighash type before finalize
This commit is contained in:
parent
0d9fa87943
commit
fa897cf78e
2 changed files with 24 additions and 0 deletions
ts_src
|
@ -269,6 +269,8 @@ export class Psbt extends PsbtBase {
|
|||
if (!canFinalize(input, script, scriptType))
|
||||
throw new Error(`Can not finalize input #${inputIndex}`);
|
||||
|
||||
checkPartialSigSighashes(input);
|
||||
|
||||
const { finalScriptSig, finalScriptWitness } = getFinalScripts(
|
||||
script,
|
||||
scriptType,
|
||||
|
@ -547,6 +549,17 @@ function checkInputsForPartialSig(inputs: PsbtInput[], action: string): void {
|
|||
});
|
||||
}
|
||||
|
||||
function checkPartialSigSighashes(input: PsbtInput): void {
|
||||
if (!input.sighashType || !input.partialSig) return;
|
||||
const { partialSig, sighashType } = input;
|
||||
partialSig.forEach(pSig => {
|
||||
const { hashType } = bscript.signature.decode(pSig.signature);
|
||||
if (sighashType !== hashType) {
|
||||
throw new Error('Signature sighash does not match input sighash type');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkScriptForPubkey(
|
||||
pubkey: Buffer,
|
||||
script: Buffer,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue