Daniel Cousens
8 years ago
committed by
Daniel Cousens
2 changed files with 43 additions and 7 deletions
@ -1,9 +1,44 @@ |
|||
// {signature} {pubKey}
|
|||
|
|||
var pkh = require('../pubkeyhash/input') |
|||
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) { |
|||
typeforce(check, stack) |
|||
|
|||
return { |
|||
signature: stack[0], |
|||
pubKey: stack[1] |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
check: pkh.check, |
|||
decodeStack: pkh.decodeStack, |
|||
encodeStack: pkh.encodeStack |
|||
check: check, |
|||
decodeStack: decodeStack, |
|||
encodeStack: encodeStack |
|||
} |
|||
|
Loading…
Reference in new issue