Skip to content

Commit d840ab6

Browse files
committed
feat: add simple type for TaprootLeaf and TaprootNode
1 parent 91ccef3 commit d840ab6

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export interface TweakedPublicKey {
1616
isOdd: boolean;
1717
x: Buffer;
1818
}
19+
export declare const TaprootLeaf: any;
20+
export declare const TaprootNode: any;
1921
export declare const Buffer256bit: any;
2022
export declare const Hash160bit: any;
2123
export declare const Hash256bit: any;

src/types.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
Object.defineProperty(exports, '__esModule', { value: true });
3-
exports.oneOf = exports.Null = exports.BufferN = exports.Function = exports.UInt32 = exports.UInt8 = exports.tuple = exports.maybe = exports.Hex = exports.Buffer = exports.String = exports.Boolean = exports.Array = exports.Number = exports.Hash256bit = exports.Hash160bit = exports.Buffer256bit = exports.Network = exports.ECPoint = exports.Satoshi = exports.Signer = exports.BIP32Path = exports.UInt31 = exports.tweakPublicKey = exports.liftX = exports.isPoint = exports.typeforce = void 0;
3+
exports.oneOf = exports.Null = exports.BufferN = exports.Function = exports.UInt32 = exports.UInt8 = exports.tuple = exports.maybe = exports.Hex = exports.Buffer = exports.String = exports.Boolean = exports.Array = exports.Number = exports.Hash256bit = exports.Hash160bit = exports.Buffer256bit = exports.TaprootNode = exports.TaprootLeaf = exports.Network = exports.ECPoint = exports.Satoshi = exports.Signer = exports.BIP32Path = exports.UInt31 = exports.tweakPublicKey = exports.liftX = exports.isPoint = exports.typeforce = void 0;
44
const buffer_1 = require('buffer');
55
const bcrypto = require('./crypto');
66
// Temp, to be replaced
@@ -136,6 +136,17 @@ exports.Network = exports.typeforce.compile({
136136
scriptHash: exports.typeforce.UInt8,
137137
wif: exports.typeforce.UInt8,
138138
});
139+
exports.TaprootLeaf = exports.typeforce.compile({
140+
output: exports.typeforce.BufferN(34),
141+
version: exports.typeforce.maybe(exports.typeforce.UInt8), // todo: recheck
142+
});
143+
// / todo: revisit
144+
exports.TaprootNode = exports.typeforce.arrayOf(
145+
exports.typeforce.oneOf(
146+
exports.TaprootLeaf,
147+
exports.typeforce.arrayOf(exports.TaprootLeaf),
148+
),
149+
);
139150
exports.Buffer256bit = exports.typeforce.BufferN(32);
140151
exports.Hash160bit = exports.typeforce.BufferN(20);
141152
exports.Hash256bit = exports.typeforce.BufferN(32);

ts_src/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ export interface TweakedPublicKey {
155155
isOdd: boolean;
156156
x: Buffer;
157157
}
158+
159+
export const TaprootLeaf = typeforce.compile({
160+
output: typeforce.BufferN(34),
161+
version: typeforce.maybe(typeforce.UInt8) // todo: recheck
162+
})
163+
164+
// / todo: revisit
165+
export const TaprootNode = typeforce.arrayOf(typeforce.oneOf(TaprootLeaf, typeforce.arrayOf(TaprootLeaf)))
166+
167+
158168
export const Buffer256bit = typeforce.BufferN(32);
159169
export const Hash160bit = typeforce.BufferN(20);
160170
export const Hash256bit = typeforce.BufferN(32);

0 commit comments

Comments
 (0)