|
|
@ -1,9 +1,6 @@ |
|
|
|
// OP_0 [signatures ...]
|
|
|
|
|
|
|
|
const Buffer = require('safe-buffer').Buffer |
|
|
|
const bscript = require('../../script') |
|
|
|
const p2mso = require('./output') |
|
|
|
const typeforce = require('typeforce') |
|
|
|
const OPS = require('bitcoin-ops') |
|
|
|
|
|
|
|
function partialSignature (value) { |
|
|
@ -23,50 +20,4 @@ function check (script, allowIncomplete) { |
|
|
|
} |
|
|
|
check.toJSON = function () { return 'multisig input' } |
|
|
|
|
|
|
|
const EMPTY_BUFFER = Buffer.allocUnsafe(0) |
|
|
|
|
|
|
|
function encodeStack (signatures, scriptPubKey) { |
|
|
|
typeforce([partialSignature], signatures) |
|
|
|
|
|
|
|
if (scriptPubKey) { |
|
|
|
const scriptData = p2mso.decode(scriptPubKey) |
|
|
|
|
|
|
|
if (signatures.length < scriptData.m) { |
|
|
|
throw new TypeError('Not enough signatures provided') |
|
|
|
} |
|
|
|
|
|
|
|
if (signatures.length > scriptData.pubKeys.length) { |
|
|
|
throw new TypeError('Too many signatures provided') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return [].concat(EMPTY_BUFFER, signatures.map(function (sig) { |
|
|
|
if (sig === OPS.OP_0) { |
|
|
|
return EMPTY_BUFFER |
|
|
|
} |
|
|
|
return sig |
|
|
|
})) |
|
|
|
} |
|
|
|
|
|
|
|
function encode (signatures, scriptPubKey) { |
|
|
|
return bscript.compile(encodeStack(signatures, scriptPubKey)) |
|
|
|
} |
|
|
|
|
|
|
|
function decodeStack (stack, allowIncomplete) { |
|
|
|
typeforce(typeforce.Array, stack) |
|
|
|
typeforce(check, stack, allowIncomplete) |
|
|
|
return stack.slice(1) |
|
|
|
} |
|
|
|
|
|
|
|
function decode (buffer, allowIncomplete) { |
|
|
|
const stack = bscript.decompile(buffer) |
|
|
|
return decodeStack(stack, allowIncomplete) |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = { |
|
|
|
check: check, |
|
|
|
decode: decode, |
|
|
|
decodeStack: decodeStack, |
|
|
|
encode: encode, |
|
|
|
encodeStack: encodeStack |
|
|
|
} |
|
|
|
module.exports = { check } |
|
|
|