Browse Source

add witnessPubKeyHash compressed policy

hk-custom-address
Daniel Cousens 8 years ago
committed by Daniel Cousens
parent
commit
3ffac6cd39
  1. 7
      src/templates/pubkeyhash/input.js
  2. 43
      src/templates/witnesspubkeyhash/input.js

7
src/templates/pubkeyhash/input.js

@ -1,7 +1,6 @@
// {signature} {pubKey}
var bscript = require('../../script')
var types = require('../../types')
var typeforce = require('typeforce')
function check (script) {
@ -15,9 +14,11 @@ check.toJSON = function () { return 'pubKeyHash input' }
function encodeStack (signature, pubKey) {
typeforce({
signature: types.Buffer, pubKey: types.Buffer
signature: bscript.isCanonicalSignature,
pubKey: bscript.isCanonicalPubKey
}, {
signature: signature, pubKey: pubKey
signature: signature,
pubKey: pubKey
})
return [signature, pubKey]

43
src/templates/witnesspubkeyhash/input.js

@ -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…
Cancel
Save