2016-12-14 05:15:01 +01:00
|
|
|
// {signature} {pubKey}
|
2016-11-02 02:30:37 +01:00
|
|
|
|
|
|
|
var bscript = require('../../script')
|
|
|
|
var types = require('../../types')
|
|
|
|
var typeforce = require('typeforce')
|
|
|
|
|
|
|
|
function check (script) {
|
|
|
|
var chunks = bscript.decompile(script)
|
|
|
|
|
|
|
|
return chunks.length === 2 &&
|
|
|
|
bscript.isCanonicalSignature(chunks[0]) &&
|
|
|
|
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({
|
|
|
|
signature: types.Buffer, pubKey: types.Buffer
|
|
|
|
}, {
|
|
|
|
signature: signature, pubKey: pubKey
|
|
|
|
})
|
|
|
|
|
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) {
|
|
|
|
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
|
|
|
}
|