|
|
@ -1,19 +1,19 @@ |
|
|
|
// m [pubKeys ...] n OP_CHECKMULTISIG
|
|
|
|
|
|
|
|
const bscript = require('../../script') |
|
|
|
const types = require('../../types') |
|
|
|
import * as bscript from '../../script' |
|
|
|
import * as types from '../../types' |
|
|
|
const OPS = require('bitcoin-ops') |
|
|
|
const OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1
|
|
|
|
|
|
|
|
function check (script, allowIncomplete) { |
|
|
|
export function check (script: Buffer | Array<number | Buffer>, allowIncomplete?: boolean): boolean { |
|
|
|
const chunks = bscript.decompile(script) |
|
|
|
|
|
|
|
if (chunks.length < 4) return false |
|
|
|
if (chunks[chunks.length - 1] !== OPS.OP_CHECKMULTISIG) return false |
|
|
|
if (!types.Number(chunks[0])) return false |
|
|
|
if (!types.Number(chunks[chunks.length - 2])) return false |
|
|
|
const m = chunks[0] - OP_INT_BASE |
|
|
|
const n = chunks[chunks.length - 2] - OP_INT_BASE |
|
|
|
const m = <number>chunks[0] - OP_INT_BASE |
|
|
|
const n = <number>chunks[chunks.length - 2] - OP_INT_BASE |
|
|
|
|
|
|
|
if (m <= 0) return false |
|
|
|
if (n > 16) return false |
|
|
@ -21,10 +21,7 @@ function check (script, allowIncomplete) { |
|
|
|
if (n !== chunks.length - 3) return false |
|
|
|
if (allowIncomplete) return true |
|
|
|
|
|
|
|
const keys = chunks.slice(1, -2) |
|
|
|
const keys = <Array<Buffer>> chunks.slice(1, -2) |
|
|
|
return keys.every(bscript.isCanonicalPubKey) |
|
|
|
} |
|
|
|
check.toJSON = function () { return 'multi-sig output' } |
|
|
|
|
|
|
|
module.exports = { check } |
|
|
|
export {} |
|
|
|