Check for input empty on parse
This commit is contained in:
parent
5b5daf84dd
commit
3e7f490093
2 changed files with 29 additions and 0 deletions
14
src/psbt.js
14
src/psbt.js
|
@ -13,6 +13,7 @@ const varuint = require('varuint-bitcoin');
|
|||
class Psbt extends bip174_1.Psbt {
|
||||
static fromTransaction(txBuf) {
|
||||
const tx = transaction_1.Transaction.fromBuffer(txBuf);
|
||||
checkTxEmpty(tx);
|
||||
const psbt = new this();
|
||||
psbt.__TX = tx;
|
||||
let inputCount = tx.ins.length;
|
||||
|
@ -35,6 +36,7 @@ class Psbt extends bip174_1.Psbt {
|
|||
let tx;
|
||||
const txCountGetter = txBuf => {
|
||||
tx = transaction_1.Transaction.fromBuffer(txBuf);
|
||||
checkTxEmpty(tx);
|
||||
return {
|
||||
inputCount: tx.ins.length,
|
||||
outputCount: tx.outs.length,
|
||||
|
@ -564,3 +566,15 @@ function scriptWitnessToWitnessStack(buffer) {
|
|||
return readVector();
|
||||
}
|
||||
const range = n => [...Array(n).keys()];
|
||||
function checkTxEmpty(tx) {
|
||||
const isEmpty = tx.ins.every(
|
||||
input =>
|
||||
input.script &&
|
||||
input.script.length === 0 &&
|
||||
input.witness &&
|
||||
input.witness.length === 0,
|
||||
);
|
||||
if (!isEmpty) {
|
||||
throw new Error('Format Error: Transaction ScriptSigs are not empty');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ export class Psbt extends PsbtBase {
|
|||
txBuf: Buffer,
|
||||
): InstanceType<T> {
|
||||
const tx = Transaction.fromBuffer(txBuf);
|
||||
checkTxEmpty(tx);
|
||||
const psbt = new this() as Psbt;
|
||||
psbt.__TX = tx;
|
||||
let inputCount = tx.ins.length;
|
||||
|
@ -52,6 +53,7 @@ export class Psbt extends PsbtBase {
|
|||
outputCount: number;
|
||||
} => {
|
||||
tx = Transaction.fromBuffer(txBuf);
|
||||
checkTxEmpty(tx);
|
||||
return {
|
||||
inputCount: tx.ins.length,
|
||||
outputCount: tx.outs.length,
|
||||
|
@ -719,3 +721,16 @@ function scriptWitnessToWitnessStack(buffer: Buffer): Buffer[] {
|
|||
}
|
||||
|
||||
const range = (n: number): number[] => [...Array(n).keys()];
|
||||
|
||||
function checkTxEmpty(tx: Transaction): void {
|
||||
const isEmpty = tx.ins.every(
|
||||
input =>
|
||||
input.script &&
|
||||
input.script.length === 0 &&
|
||||
input.witness &&
|
||||
input.witness.length === 0,
|
||||
);
|
||||
if (!isEmpty) {
|
||||
throw new Error('Format Error: Transaction ScriptSigs are not empty');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue