merkle-tree-lib
Version:
Merkle Tree implementation with BIP340 tagged hash support.
76 lines (75 loc) • 2.3 kB
TypeScript
/**
* Direction enum for which side the sibling is on in a Merkle proof
*/
export declare enum ProofDirection {
LEFT = 0,
RIGHT = 1
}
/**
* MerkleProofElement - A single element in a Merkle proof
*/
export interface MerkleProofElement {
/** The hash of the sibling node */
siblingHash: Buffer;
/** Direction (left or right) indicating which side the sibling is on */
direction: ProofDirection;
}
/**
* MerkleProof - Class representing a Merkle proof for a specific leaf
*/
export declare class MerkleProof {
/** The original leaf data */
private readonly leafData;
/** The index of the leaf in the tree */
private readonly leafIndex;
/** Array of proof elements */
private readonly elements;
/** Merkle root hash (expected result after applying proof) */
private readonly rootHash;
/**
* Create a new Merkle proof
*
* @param leafData - The original data for the leaf
* @param leafIndex - The index of the leaf in the original data array
* @param elements - Array of proof elements
* @param rootHash - The Merkle root hash
*/
constructor(leafData: string, leafIndex: number, elements: MerkleProofElement[], rootHash: Buffer);
/**
* Get the leaf data
* @returns The original leaf data
*/
getLeafData(): string;
/**
* Get the leaf index
* @returns The index of the leaf in the original tree
*/
getLeafIndex(): number;
/**
* Get the proof elements
* @returns Array of proof elements
*/
getElements(): MerkleProofElement[];
/**
* Get the Merkle root hash
* @returns The root hash
*/
getRootHash(): Buffer;
/**
* Convert a proof from the library format to our standard format
*
* @param libProof - Proof from merkle-tree-lib's old format
* @returns MerkleProofElement array
*/
static fromLibraryFormat(libProof: Array<{
siblingHash: Buffer;
side: 0 | 1;
}>): MerkleProofElement[];
/**
* Convert a standard proof to a format suitable for API responses
*
* @param proof - MerkleProofElement array
* @returns Array of [hashHex, direction] tuples
*/
static toApiFormat(proof: MerkleProofElement[]): [string, ProofDirection][];
}