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
11
src/psbt.js
11
src/psbt.js
|
@ -216,6 +216,7 @@ class Psbt extends bip174_1.Psbt {
|
||||||
const scriptType = classifyScript(script);
|
const scriptType = classifyScript(script);
|
||||||
if (!canFinalize(input, script, scriptType))
|
if (!canFinalize(input, script, scriptType))
|
||||||
throw new Error(`Can not finalize input #${inputIndex}`);
|
throw new Error(`Can not finalize input #${inputIndex}`);
|
||||||
|
checkPartialSigSighashes(input);
|
||||||
const { finalScriptSig, finalScriptWitness } = getFinalScripts(
|
const { finalScriptSig, finalScriptWitness } = getFinalScripts(
|
||||||
script,
|
script,
|
||||||
scriptType,
|
scriptType,
|
||||||
|
@ -446,6 +447,16 @@ function checkInputsForPartialSig(inputs, action) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function checkPartialSigSighashes(input) {
|
||||||
|
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, script, action) {
|
function checkScriptForPubkey(pubkey, script, action) {
|
||||||
const pubkeyHash = crypto_1.hash160(pubkey);
|
const pubkeyHash = crypto_1.hash160(pubkey);
|
||||||
const decompiled = bscript.decompile(script);
|
const decompiled = bscript.decompile(script);
|
||||||
|
|
|
@ -269,6 +269,8 @@ export class Psbt extends PsbtBase {
|
||||||
if (!canFinalize(input, script, scriptType))
|
if (!canFinalize(input, script, scriptType))
|
||||||
throw new Error(`Can not finalize input #${inputIndex}`);
|
throw new Error(`Can not finalize input #${inputIndex}`);
|
||||||
|
|
||||||
|
checkPartialSigSighashes(input);
|
||||||
|
|
||||||
const { finalScriptSig, finalScriptWitness } = getFinalScripts(
|
const { finalScriptSig, finalScriptWitness } = getFinalScripts(
|
||||||
script,
|
script,
|
||||||
scriptType,
|
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(
|
function checkScriptForPubkey(
|
||||||
pubkey: Buffer,
|
pubkey: Buffer,
|
||||||
script: Buffer,
|
script: Buffer,
|
||||||
|
|
Loading…
Add table
Reference in a new issue