templates: rm dead code
This commit is contained in:
parent
4454e2925a
commit
a9090dc0cc
12 changed files with 12 additions and 342 deletions
|
@ -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 }
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
const bscript = require('../../script')
|
||||
const types = require('../../types')
|
||||
const typeforce = require('typeforce')
|
||||
const OPS = require('bitcoin-ops')
|
||||
const OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1
|
||||
|
||||
|
@ -27,38 +26,4 @@ function check (script, allowIncomplete) {
|
|||
}
|
||||
check.toJSON = function () { return 'multi-sig output' }
|
||||
|
||||
function encode (m, pubKeys) {
|
||||
typeforce({
|
||||
m: types.Number,
|
||||
pubKeys: [bscript.isCanonicalPubKey]
|
||||
}, {
|
||||
m: m,
|
||||
pubKeys: pubKeys
|
||||
})
|
||||
|
||||
const n = pubKeys.length
|
||||
if (n < m) throw new TypeError('Not enough pubKeys provided')
|
||||
|
||||
return bscript.compile([].concat(
|
||||
OP_INT_BASE + m,
|
||||
pubKeys,
|
||||
OP_INT_BASE + n,
|
||||
OPS.OP_CHECKMULTISIG
|
||||
))
|
||||
}
|
||||
|
||||
function decode (buffer, allowIncomplete) {
|
||||
const chunks = bscript.decompile(buffer)
|
||||
typeforce(check, chunks, allowIncomplete)
|
||||
|
||||
return {
|
||||
m: chunks[0] - OP_INT_BASE,
|
||||
pubKeys: chunks.slice(1, -2)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
check: check,
|
||||
decode: decode,
|
||||
encode: encode
|
||||
}
|
||||
module.exports = { check }
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// {signature}
|
||||
|
||||
const bscript = require('../../script')
|
||||
const typeforce = require('typeforce')
|
||||
|
||||
function check (script) {
|
||||
const chunks = bscript.decompile(script)
|
||||
|
@ -11,30 +10,6 @@ function check (script) {
|
|||
}
|
||||
check.toJSON = function () { return 'pubKey input' }
|
||||
|
||||
function encodeStack (signature) {
|
||||
typeforce(bscript.isCanonicalScriptSignature, signature)
|
||||
return [signature]
|
||||
}
|
||||
|
||||
function encode (signature) {
|
||||
return bscript.compile(encodeStack(signature))
|
||||
}
|
||||
|
||||
function decodeStack (stack) {
|
||||
typeforce(typeforce.Array, stack)
|
||||
typeforce(check, stack)
|
||||
return stack[0]
|
||||
}
|
||||
|
||||
function decode (buffer) {
|
||||
const stack = bscript.decompile(buffer)
|
||||
return decodeStack(stack)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
check: check,
|
||||
decode: decode,
|
||||
decodeStack: decodeStack,
|
||||
encode: encode,
|
||||
encodeStack: encodeStack
|
||||
check: check
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// {pubKey} OP_CHECKSIG
|
||||
|
||||
const bscript = require('../../script')
|
||||
const typeforce = require('typeforce')
|
||||
const OPS = require('bitcoin-ops')
|
||||
|
||||
function check (script) {
|
||||
|
@ -13,21 +12,4 @@ function check (script) {
|
|||
}
|
||||
check.toJSON = function () { return 'pubKey output' }
|
||||
|
||||
function encode (pubKey) {
|
||||
typeforce(bscript.isCanonicalPubKey, pubKey)
|
||||
|
||||
return bscript.compile([pubKey, OPS.OP_CHECKSIG])
|
||||
}
|
||||
|
||||
function decode (buffer) {
|
||||
const chunks = bscript.decompile(buffer)
|
||||
typeforce(check, chunks)
|
||||
|
||||
return chunks[0]
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
check: check,
|
||||
decode: decode,
|
||||
encode: encode
|
||||
}
|
||||
module.exports = { check }
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// {signature} {pubKey}
|
||||
|
||||
const bscript = require('../../script')
|
||||
const typeforce = require('typeforce')
|
||||
|
||||
function check (script) {
|
||||
const chunks = bscript.decompile(script)
|
||||
|
@ -12,41 +11,4 @@ function check (script) {
|
|||
}
|
||||
check.toJSON = function () { return 'pubKeyHash input' }
|
||||
|
||||
function encodeStack (signature, pubKey) {
|
||||
typeforce({
|
||||
signature: bscript.isCanonicalScriptSignature,
|
||||
pubKey: bscript.isCanonicalPubKey
|
||||
}, {
|
||||
signature: signature,
|
||||
pubKey: pubKey
|
||||
})
|
||||
|
||||
return [signature, pubKey]
|
||||
}
|
||||
|
||||
function encode (signature, pubKey) {
|
||||
return bscript.compile(encodeStack(signature, pubKey))
|
||||
}
|
||||
|
||||
function decodeStack (stack) {
|
||||
typeforce(typeforce.Array, stack)
|
||||
typeforce(check, stack)
|
||||
|
||||
return {
|
||||
signature: stack[0],
|
||||
pubKey: stack[1]
|
||||
}
|
||||
}
|
||||
|
||||
function decode (buffer) {
|
||||
const stack = bscript.decompile(buffer)
|
||||
return decodeStack(stack)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
check: check,
|
||||
decode: decode,
|
||||
decodeStack: decodeStack,
|
||||
encode: encode,
|
||||
encodeStack: encodeStack
|
||||
}
|
||||
module.exports = { check }
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// OP_DUP OP_HASH160 {pubKeyHash} OP_EQUALVERIFY OP_CHECKSIG
|
||||
|
||||
const bscript = require('../../script')
|
||||
const types = require('../../types')
|
||||
const typeforce = require('typeforce')
|
||||
const OPS = require('bitcoin-ops')
|
||||
|
||||
function check (script) {
|
||||
|
@ -17,26 +15,4 @@ function check (script) {
|
|||
}
|
||||
check.toJSON = function () { return 'pubKeyHash output' }
|
||||
|
||||
function encode (pubKeyHash) {
|
||||
typeforce(types.Hash160bit, pubKeyHash)
|
||||
|
||||
return bscript.compile([
|
||||
OPS.OP_DUP,
|
||||
OPS.OP_HASH160,
|
||||
pubKeyHash,
|
||||
OPS.OP_EQUALVERIFY,
|
||||
OPS.OP_CHECKSIG
|
||||
])
|
||||
}
|
||||
|
||||
function decode (buffer) {
|
||||
typeforce(check, buffer)
|
||||
|
||||
return buffer.slice(3, 23)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
check: check,
|
||||
decode: decode,
|
||||
encode: encode
|
||||
}
|
||||
module.exports = { check }
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
const Buffer = require('safe-buffer').Buffer
|
||||
const bscript = require('../../script')
|
||||
const typeforce = require('typeforce')
|
||||
|
||||
const p2ms = require('../multisig/')
|
||||
const p2pk = require('../pubkey/')
|
||||
|
@ -46,40 +45,4 @@ function check (script, allowIncomplete) {
|
|||
}
|
||||
check.toJSON = function () { return 'scriptHash input' }
|
||||
|
||||
function encodeStack (redeemScriptStack, redeemScript) {
|
||||
const serializedScriptPubKey = bscript.compile(redeemScript)
|
||||
|
||||
return [].concat(redeemScriptStack, serializedScriptPubKey)
|
||||
}
|
||||
|
||||
function encode (redeemScriptSig, redeemScript) {
|
||||
const redeemScriptStack = bscript.decompile(redeemScriptSig)
|
||||
|
||||
return bscript.compile(encodeStack(redeemScriptStack, redeemScript))
|
||||
}
|
||||
|
||||
function decodeStack (stack) {
|
||||
typeforce(typeforce.Array, stack)
|
||||
typeforce(check, stack)
|
||||
|
||||
return {
|
||||
redeemScriptStack: stack.slice(0, -1),
|
||||
redeemScript: stack[stack.length - 1]
|
||||
}
|
||||
}
|
||||
|
||||
function decode (buffer) {
|
||||
const stack = bscript.decompile(buffer)
|
||||
const result = decodeStack(stack)
|
||||
result.redeemScriptSig = bscript.compile(result.redeemScriptStack)
|
||||
delete result.redeemScriptStack
|
||||
return result
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
check: check,
|
||||
decode: decode,
|
||||
decodeStack: decodeStack,
|
||||
encode: encode,
|
||||
encodeStack: encodeStack
|
||||
}
|
||||
module.exports = { check }
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// OP_HASH160 {scriptHash} OP_EQUAL
|
||||
|
||||
const bscript = require('../../script')
|
||||
const types = require('../../types')
|
||||
const typeforce = require('typeforce')
|
||||
const OPS = require('bitcoin-ops')
|
||||
|
||||
function check (script) {
|
||||
|
@ -15,20 +13,4 @@ function check (script) {
|
|||
}
|
||||
check.toJSON = function () { return 'scriptHash output' }
|
||||
|
||||
function encode (scriptHash) {
|
||||
typeforce(types.Hash160bit, scriptHash)
|
||||
|
||||
return bscript.compile([OPS.OP_HASH160, scriptHash, OPS.OP_EQUAL])
|
||||
}
|
||||
|
||||
function decode (buffer) {
|
||||
typeforce(check, buffer)
|
||||
|
||||
return buffer.slice(2, 22)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
check: check,
|
||||
decode: decode,
|
||||
encode: encode
|
||||
}
|
||||
module.exports = { check }
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// {signature} {pubKey}
|
||||
|
||||
const bscript = require('../../script')
|
||||
const typeforce = require('typeforce')
|
||||
|
||||
function isCompressedCanonicalPubKey (pubKey) {
|
||||
return bscript.isCanonicalPubKey(pubKey) && pubKey.length === 33
|
||||
|
@ -16,30 +15,4 @@ function check (script) {
|
|||
}
|
||||
check.toJSON = function () { return 'witnessPubKeyHash input' }
|
||||
|
||||
function encodeStack (signature, pubKey) {
|
||||
typeforce({
|
||||
signature: bscript.isCanonicalScriptSignature,
|
||||
pubKey: isCompressedCanonicalPubKey
|
||||
}, {
|
||||
signature: signature,
|
||||
pubKey: pubKey
|
||||
})
|
||||
|
||||
return [signature, pubKey]
|
||||
}
|
||||
|
||||
function decodeStack (stack) {
|
||||
typeforce(typeforce.Array, stack)
|
||||
typeforce(check, stack)
|
||||
|
||||
return {
|
||||
signature: stack[0],
|
||||
pubKey: stack[1]
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
check: check,
|
||||
decodeStack: decodeStack,
|
||||
encodeStack: encodeStack
|
||||
}
|
||||
module.exports = { check }
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// OP_0 {pubKeyHash}
|
||||
|
||||
const bscript = require('../../script')
|
||||
const types = require('../../types')
|
||||
const typeforce = require('typeforce')
|
||||
const OPS = require('bitcoin-ops')
|
||||
|
||||
function check (script) {
|
||||
|
@ -14,20 +12,6 @@ function check (script) {
|
|||
}
|
||||
check.toJSON = function () { return 'Witness pubKeyHash output' }
|
||||
|
||||
function encode (pubKeyHash) {
|
||||
typeforce(types.Hash160bit, pubKeyHash)
|
||||
|
||||
return bscript.compile([OPS.OP_0, pubKeyHash])
|
||||
}
|
||||
|
||||
function decode (buffer) {
|
||||
typeforce(check, buffer)
|
||||
|
||||
return buffer.slice(2)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
check: check,
|
||||
decode: decode,
|
||||
encode: encode
|
||||
check
|
||||
}
|
||||
|
|
|
@ -36,29 +36,4 @@ function check (chunks, allowIncomplete) {
|
|||
}
|
||||
check.toJSON = function () { return 'witnessScriptHash input' }
|
||||
|
||||
function encodeStack (witnessData, witnessScript) {
|
||||
typeforce({
|
||||
witnessData: [types.Buffer],
|
||||
witnessScript: types.Buffer
|
||||
}, {
|
||||
witnessData: witnessData,
|
||||
witnessScript: witnessScript
|
||||
})
|
||||
|
||||
return [].concat(witnessData, witnessScript)
|
||||
}
|
||||
|
||||
function decodeStack (stack) {
|
||||
typeforce(typeforce.Array, stack)
|
||||
typeforce(check, stack)
|
||||
return {
|
||||
witnessData: stack.slice(0, -1),
|
||||
witnessScript: stack[stack.length - 1]
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
check: check,
|
||||
decodeStack: decodeStack,
|
||||
encodeStack: encodeStack
|
||||
}
|
||||
module.exports = { check }
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// OP_0 {scriptHash}
|
||||
|
||||
const bscript = require('../../script')
|
||||
const types = require('../../types')
|
||||
const typeforce = require('typeforce')
|
||||
const OPS = require('bitcoin-ops')
|
||||
|
||||
function check (script) {
|
||||
|
@ -14,20 +12,4 @@ function check (script) {
|
|||
}
|
||||
check.toJSON = function () { return 'Witness scriptHash output' }
|
||||
|
||||
function encode (scriptHash) {
|
||||
typeforce(types.Hash256bit, scriptHash)
|
||||
|
||||
return bscript.compile([OPS.OP_0, scriptHash])
|
||||
}
|
||||
|
||||
function decode (buffer) {
|
||||
typeforce(check, buffer)
|
||||
|
||||
return buffer.slice(2)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
check: check,
|
||||
decode: decode,
|
||||
encode: encode
|
||||
}
|
||||
module.exports = { check }
|
||||
|
|
Loading…
Add table
Reference in a new issue