Browse Source

Add Witness Commitment

fixTypes
junderw 6 years ago
parent
commit
5c34b4ce22
No known key found for this signature in database GPG Key ID: B256185D3A971908
  1. 7
      src/templates/witnesscommitment/index.ts
  2. 21
      src/templates/witnesscommitment/output.ts

7
src/templates/witnesscommitment/index.ts

@ -1,4 +1,5 @@
module.exports = {
output: require('./output')
import * as output from './output'
export {
output,
}
export {}

21
src/templates/witnesscommitment/output.ts

@ -1,14 +1,14 @@
// OP_RETURN {aa21a9ed} {commitment}
import * as bscript from '../../script'
import * as types from '../../types'
const Buffer = require('safe-buffer').Buffer
const bscript = require('../../script')
const types = require('../../types')
const typeforce = require('typeforce')
const OPS = require('bitcoin-ops')
const HEADER = Buffer.from('aa21a9ed', 'hex')
const HEADER: Buffer = Buffer.from('aa21a9ed', 'hex')
function check (script) {
export function check (script: Buffer | Array<number | Buffer>): boolean {
const buffer = bscript.compile(script)
return buffer.length > 37 &&
@ -19,7 +19,7 @@ function check (script) {
check.toJSON = function () { return 'Witness commitment output' }
function encode (commitment) {
export function encode (commitment: Buffer): Buffer {
typeforce(types.Hash256bit, commitment)
const buffer = Buffer.allocUnsafe(36)
@ -29,15 +29,8 @@ function encode (commitment) {
return bscript.compile([OPS.OP_RETURN, buffer])
}
function decode (buffer) {
export function decode (buffer: Buffer): Buffer {
typeforce(check, buffer)
return bscript.decompile(buffer)[1].slice(4, 36)
return (<Buffer>bscript.decompile(buffer)[1]).slice(4, 36)
}
module.exports = {
check: check,
decode: decode,
encode: encode
}
export {}

Loading…
Cancel
Save