2016-12-14 05:15:01 +01:00
|
|
|
// {signature} {pubKey}
|
2016-11-02 02:30:37 +01:00
|
|
|
|
2018-06-25 08:25:12 +02:00
|
|
|
const bscript = require('../../script')
|
|
|
|
const typeforce = require('typeforce')
|
2016-11-02 02:30:37 +01:00
|
|
|
|
|
|
|
function check (script) {
|
|
|
|
var chunks = bscript.decompile(script)
|
|
|
|
|
|
|
|
return chunks.length === 2 &&
|
2018-06-05 09:17:40 +02:00
|
|
|
bscript.isCanonicalScriptSignature(chunks[0]) &&
|
2016-11-02 02:30:37 +01:00
|
|
|
bscript.isCanonicalPubKey(chunks[1])
|
|
|
|
}
|
2016-11-02 04:33:46 +01:00
|
|
|
check.toJSON = function () { return 'pubKeyHash input' }
|
2016-11-02 02:30:37 +01:00
|
|
|
|
2016-12-14 05:52:38 +01:00
|
|
|
function encodeStack (signature, pubKey) {
|
2016-11-02 02:30:37 +01:00
|
|
|
typeforce({
|
2018-06-05 09:17:40 +02:00
|
|
|
signature: bscript.isCanonicalScriptSignature,
|
2017-08-22 01:15:53 +02:00
|
|
|
pubKey: bscript.isCanonicalPubKey
|
2016-11-02 02:30:37 +01:00
|
|
|
}, {
|
2017-08-22 01:15:53 +02:00
|
|
|
signature: signature,
|
|
|
|
pubKey: pubKey
|
2016-11-02 02:30:37 +01:00
|
|
|
})
|
|
|
|
|
2016-12-14 05:52:38 +01:00
|
|
|
return [signature, pubKey]
|
2016-11-02 02:30:37 +01:00
|
|
|
}
|
|
|
|
|
2016-12-14 05:52:38 +01:00
|
|
|
function encode (signature, pubKey) {
|
|
|
|
return bscript.compile(encodeStack(signature, pubKey))
|
|
|
|
}
|
|
|
|
|
|
|
|
function decodeStack (stack) {
|
2017-11-30 05:34:30 +01:00
|
|
|
typeforce(typeforce.Array, stack)
|
2016-12-14 05:52:38 +01:00
|
|
|
typeforce(check, stack)
|
2016-11-02 02:30:37 +01:00
|
|
|
|
|
|
|
return {
|
2016-12-14 05:52:38 +01:00
|
|
|
signature: stack[0],
|
|
|
|
pubKey: stack[1]
|
2016-11-02 02:30:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-14 05:52:38 +01:00
|
|
|
function decode (buffer) {
|
|
|
|
var stack = bscript.decompile(buffer)
|
|
|
|
return decodeStack(stack)
|
|
|
|
}
|
|
|
|
|
2016-11-02 02:30:37 +01:00
|
|
|
module.exports = {
|
|
|
|
check: check,
|
|
|
|
decode: decode,
|
2016-12-14 05:52:38 +01:00
|
|
|
decodeStack: decodeStack,
|
|
|
|
encode: encode,
|
|
|
|
encodeStack: encodeStack
|
2016-11-02 02:30:37 +01:00
|
|
|
}
|