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