Check redeem script matches witness utxo when signing PSBT input
This commit is contained in:
parent
6562ee96a4
commit
08627e65a3
2 changed files with 29 additions and 0 deletions
14
src/psbt.js
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
|
// TODO: Get hash to sign
|
||||||
const hash = Buffer.alloc(32);
|
const hash = Buffer.alloc(32);
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Reference in a new issue