Skip to content

Commit f5ee927

Browse files
committed
refactor: add Taptree interface
1 parent 408e073 commit f5ee927

File tree

7 files changed

+18
-15
lines changed

7 files changed

+18
-15
lines changed

src/payments/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="node" />
22
import { Network } from '../networks';
3-
import { TinySecp256k1Interface, TaprootLeaf } from '../types';
3+
import { TinySecp256k1Interface, Taptree } from '../types';
44
import { p2data as embed } from './embed';
55
import { p2ms } from './p2ms';
66
import { p2pk } from './p2pk';
@@ -26,7 +26,7 @@ export interface Payment {
2626
hash?: Buffer;
2727
redeem?: Payment;
2828
redeemVersion?: number;
29-
scriptTree?: TaprootLeaf[];
29+
scriptTree?: Taptree;
3030
witness?: Buffer[];
3131
}
3232
export declare type PaymentCreator = (a: Payment, opts?: PaymentOpts) => Payment;

src/payments/taprootutils.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// <reference types="node" />
2-
import { TaprootLeaf } from '../types';
2+
import { Taptree } from '../types';
33
export declare const LEAF_VERSION_TAPSCRIPT = 192;
44
export declare function rootHashFromPath(controlBlock: Buffer, tapLeafMsg: Buffer): Buffer;
55
export interface HashTree {
@@ -15,11 +15,11 @@ export interface HashTree {
1515
* - a pair of two taproot leafs [(output, version), (output, version)], or
1616
* - one taproot leaf and a list of elements
1717
*/
18-
export declare function toHashTree(scriptTree: TaprootLeaf[]): HashTree;
18+
export declare function toHashTree(scriptTree: Taptree): HashTree;
1919
/**
20-
* Check if the tree is a binary tree with leafs of type TaprootLeaf
20+
* Check if the tree is a binary tree with leafs of type Tapleaf
2121
*/
22-
export declare function isTapTree(scriptTree: TaprootLeaf[]): boolean;
22+
export declare function isTapTree(scriptTree: Taptree): boolean;
2323
/**
2424
* Given a MAST tree, it finds the path of a particular hash.
2525
* @param node - the root of the tree

src/payments/taprootutils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function toHashTree(scriptTree) {
5555
}
5656
exports.toHashTree = toHashTree;
5757
/**
58-
* Check if the tree is a binary tree with leafs of type TaprootLeaf
58+
* Check if the tree is a binary tree with leafs of type Tapleaf
5959
*/
6060
function isTapTree(scriptTree) {
6161
if (scriptTree.length > 2) return false;

src/types.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ export interface XOnlyPointAddTweakResult {
1414
parity: 1 | 0;
1515
xOnlyPubkey: Uint8Array;
1616
}
17-
export interface TaprootLeaf {
17+
export interface Tapleaf {
1818
output: Buffer;
1919
version?: number;
2020
}
21+
export declare type Taptree = Array<[Tapleaf, Tapleaf] | Tapleaf>;
2122
export interface TinySecp256k1Interface {
2223
isXOnlyPoint(p: Uint8Array): boolean;
2324
xOnlyPointAddTweak(p: Uint8Array, tweak: Uint8Array): XOnlyPointAddTweakResult | null;

ts_src/payments/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Network } from '../networks';
2-
import { TinySecp256k1Interface, TaprootLeaf } from '../types';
2+
import { TinySecp256k1Interface, Taptree } from '../types';
33
import { p2data as embed } from './embed';
44
import { p2ms } from './p2ms';
55
import { p2pk } from './p2pk';
@@ -26,7 +26,7 @@ export interface Payment {
2626
hash?: Buffer;
2727
redeem?: Payment;
2828
redeemVersion?: number;
29-
scriptTree?: TaprootLeaf[];
29+
scriptTree?: Taptree;
3030
witness?: Buffer[];
3131
}
3232

ts_src/payments/taprootutils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Buffer as NBuffer } from 'buffer';
22
import * as bcrypto from '../crypto';
33

44
import { varuint } from '../bufferutils';
5-
import { TaprootLeaf } from '../types';
5+
import { Taptree } from '../types';
66

77
const TAP_LEAF_TAG = 'TapLeaf';
88
const TAP_BRANCH_TAG = 'TapBranch';
@@ -45,7 +45,7 @@ export interface HashTree {
4545
* - a pair of two taproot leafs [(output, version), (output, version)], or
4646
* - one taproot leaf and a list of elements
4747
*/
48-
export function toHashTree(scriptTree: TaprootLeaf[]): HashTree {
48+
export function toHashTree(scriptTree: Taptree): HashTree {
4949
if (scriptTree.length === 1) {
5050
const script = scriptTree[0];
5151
if (Array.isArray(script)) {
@@ -71,9 +71,9 @@ export function toHashTree(scriptTree: TaprootLeaf[]): HashTree {
7171
};
7272
}
7373
/**
74-
* Check if the tree is a binary tree with leafs of type TaprootLeaf
74+
* Check if the tree is a binary tree with leafs of type Tapleaf
7575
*/
76-
export function isTapTree(scriptTree: TaprootLeaf[]): boolean {
76+
export function isTapTree(scriptTree: Taptree): boolean {
7777
if (scriptTree.length > 2) return false;
7878
if (scriptTree.length === 1) {
7979
const script = scriptTree[0];

ts_src/types.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ export interface XOnlyPointAddTweakResult {
7272
xOnlyPubkey: Uint8Array;
7373
}
7474

75-
export interface TaprootLeaf {
75+
export interface Tapleaf {
7676
output: Buffer;
7777
version?: number;
7878
}
7979

80+
export type Taptree = Array<[Tapleaf, Tapleaf] | Tapleaf>;
81+
8082
export interface TinySecp256k1Interface {
8183
isXOnlyPoint(p: Uint8Array): boolean;
8284
xOnlyPointAddTweak(

0 commit comments

Comments
 (0)