2016-12-14 05:52:38 +01:00
|
|
|
// {signature} {pubKey}
|
|
|
|
|
2017-08-22 01:15:53 +02:00
|
|
|
var bscript = require('../../script')
|
|
|
|
var typeforce = require('typeforce')
|
|
|
|
|
|
|
|
function isCompressedCanonicalPubKey (pubKey) {
|
|
|
|
return bscript.isCanonicalPubKey(pubKey) && pubKey.length === 33
|
|
|
|
}
|
|
|
|
|
|
|
|
function check (script) {
|
|
|
|
var chunks = bscript.decompile(script)
|
|
|
|
|
|
|
|
return chunks.length === 2 &&
|
|
|
|
bscript.isCanonicalSignature(chunks[0]) &&
|
|
|
|
isCompressedCanonicalPubKey(chunks[1])
|
|
|
|
}
|
|
|
|
check.toJSON = function () { return 'witnessPubKeyHash input' }
|
|
|
|
|
|
|
|
function encodeStack (signature, pubKey) {
|
|
|
|
typeforce({
|
|
|
|
signature: bscript.isCanonicalSignature,
|
|
|
|
pubKey: isCompressedCanonicalPubKey
|
|
|
|
}, {
|
|
|
|
signature: signature,
|
|
|
|
pubKey: pubKey
|
|
|
|
})
|
|
|
|
|
|
|
|
return [signature, pubKey]
|
|
|
|
}
|
|
|
|
|
|
|
|
function decodeStack (stack) {
|
2017-11-30 05:34:30 +01:00
|
|
|
typeforce(typeforce.Array, stack)
|
2017-08-22 01:15:53 +02:00
|
|
|
typeforce(check, stack)
|
|
|
|
|
|
|
|
return {
|
|
|
|
signature: stack[0],
|
|
|
|
pubKey: stack[1]
|
|
|
|
}
|
|
|
|
}
|
2016-12-14 05:52:38 +01:00
|
|
|
|
|
|
|
module.exports = {
|
2017-08-22 01:15:53 +02:00
|
|
|
check: check,
|
|
|
|
decodeStack: decodeStack,
|
|
|
|
encodeStack: encodeStack
|
2016-12-14 05:52:38 +01:00
|
|
|
}
|