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