2016-11-02 02:30:37 +01:00
|
|
|
// {pubKey} OP_CHECKSIG
|
|
|
|
|
|
|
|
var bscript = require('../../script')
|
|
|
|
var typeforce = require('typeforce')
|
2016-12-17 15:24:00 +01:00
|
|
|
var OPS = require('bitcoin-ops')
|
2016-11-02 02:30:37 +01:00
|
|
|
|
|
|
|
function check (script) {
|
|
|
|
var chunks = bscript.decompile(script)
|
|
|
|
|
|
|
|
return chunks.length === 2 &&
|
|
|
|
bscript.isCanonicalPubKey(chunks[0]) &&
|
|
|
|
chunks[1] === OPS.OP_CHECKSIG
|
|
|
|
}
|
2016-11-02 04:33:46 +01:00
|
|
|
check.toJSON = function () { return 'pubKey output' }
|
2016-11-02 02:30:37 +01:00
|
|
|
|
|
|
|
function encode (pubKey) {
|
|
|
|
typeforce(bscript.isCanonicalPubKey, pubKey)
|
|
|
|
|
|
|
|
return bscript.compile([pubKey, OPS.OP_CHECKSIG])
|
|
|
|
}
|
|
|
|
|
|
|
|
function decode (buffer) {
|
|
|
|
var chunks = bscript.decompile(buffer)
|
|
|
|
typeforce(check, chunks)
|
|
|
|
|
|
|
|
return chunks[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
check: check,
|
|
|
|
decode: decode,
|
|
|
|
encode: encode
|
|
|
|
}
|