bitcoinjs-lib/ts_src/templates/multisig/input.ts

31 lines
756 B
TypeScript
Raw Normal View History

// OP_0 [signatures ...]
2019-03-06 13:38:36 +01:00
import * as bscript from '../../script';
import { OPS } from '../../script';
2019-03-06 13:38:36 +01:00
function partialSignature(value: number | Buffer): boolean {
return (
value === OPS.OP_0 || bscript.isCanonicalScriptSignature(<Buffer>value)
);
}
2019-03-06 13:38:36 +01:00
export function check(
script: Buffer | Array<number | Buffer>,
allowIncomplete?: boolean,
): boolean {
const chunks = <Array<number | Buffer>>bscript.decompile(script);
if (chunks.length < 2) return false;
if (chunks[0] !== OPS.OP_0) return false;
if (allowIncomplete) {
2019-03-06 13:38:36 +01:00
return chunks.slice(1).every(partialSignature);
}
2019-03-06 13:38:36 +01:00
return (<Array<Buffer>>chunks.slice(1)).every(
bscript.isCanonicalScriptSignature,
);
}
2019-03-06 13:38:36 +01:00
check.toJSON = function() {
return 'multisig input';
};