UNPKG

1.69 kBTypeScriptView Raw
1/// <reference types="node" />
2import { Tapleaf, Taptree } from '../types';
3export declare const LEAF_VERSION_TAPSCRIPT = 192;
4export declare const MAX_TAPTREE_DEPTH = 128;
5interface HashLeaf {
6 hash: Buffer;
7}
8interface HashBranch {
9 hash: Buffer;
10 left: HashTree;
11 right: HashTree;
12}
13interface TweakedPublicKey {
14 parity: number;
15 x: Buffer;
16}
17/**
18 * Binary tree representing leaf, branch, and root node hashes of a Taptree.
19 * Each node contains a hash, and potentially left and right branch hashes.
20 * This tree is used for 2 purposes: Providing the root hash for tweaking,
21 * and calculating merkle inclusion proofs when constructing a control block.
22 */
23export type HashTree = HashLeaf | HashBranch;
24export declare function rootHashFromPath(controlBlock: Buffer, leafHash: Buffer): Buffer;
25/**
26 * Build a hash tree of merkle nodes from the scripts binary tree.
27 * @param scriptTree - the tree of scripts to pairwise hash.
28 */
29export declare function toHashTree(scriptTree: Taptree): HashTree;
30/**
31 * Given a HashTree, finds the path from a particular hash to the root.
32 * @param node - the root of the tree
33 * @param hash - the hash to search for
34 * @returns - array of sibling hashes, from leaf (inclusive) to root
35 * (exclusive) needed to prove inclusion of the specified hash. undefined if no
36 * path is found
37 */
38export declare function findScriptPath(node: HashTree, hash: Buffer): Buffer[] | undefined;
39export declare function tapleafHash(leaf: Tapleaf): Buffer;
40export declare function tapTweakHash(pubKey: Buffer, h: Buffer | undefined): Buffer;
41export declare function tweakKey(pubKey: Buffer, h: Buffer | undefined): TweakedPublicKey | null;
42export {};