Daniel Cousens
8 years ago
committed by
Daniel Cousens
2 changed files with 43 additions and 7 deletions
@ -1,9 +1,44 @@ |
|||||
// {signature} {pubKey}
|
// {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 = { |
module.exports = { |
||||
check: pkh.check, |
check: check, |
||||
decodeStack: pkh.decodeStack, |
decodeStack: decodeStack, |
||||
encodeStack: pkh.encodeStack |
encodeStack: encodeStack |
||||
} |
} |
||||
|
Loading…
Reference in new issue