merkle-tree-lib
Version:
Merkle Tree implementation with BIP340 tagged hash support.
66 lines (65 loc) • 2.4 kB
TypeScript
import { HashStrategy } from '../hash/HashStrategy';
import { MerkleProof, ProofDirection } from './MerkleProof';
/**
* MerkleProofVerifier - Class responsible for verifying Merkle proofs
*/
export declare class MerkleProofVerifier {
private leafHashStrategy;
private branchHashStrategy;
/**
* Initialize a verifier with the hash strategies
*
* @param leafHashStrategy - Strategy for hashing leaves (default: TaggedSha256 with 'MERKLE_LEAF' tag)
* @param branchHashStrategy - Strategy for hashing branches (default: TaggedSha256 with 'MERKLE_BRANCH' tag)
*/
constructor(leafHashStrategy?: HashStrategy, branchHashStrategy?: HashStrategy);
/**
* Verify a Merkle proof
*
* @param proof - The proof to verify
* @returns True if the proof is valid, false otherwise
*/
verify(proof: MerkleProof): boolean;
/**
* @deprecated Use verify() with MerkleProof objects instead
* Legacy verification method for backward compatibility
*
* @param leafData - The original leaf data
* @param proofPath - Array of {sibling, position} objects
* @param expectedRoot - The expected Merkle root as hex string
* @returns True if the proof is valid, false otherwise
*/
legacyVerify(leafData: string, proofPath: Array<{
sibling: string;
position: 'left' | 'right';
}>, expectedRoot: string): boolean;
/**
* Apply a single proof element to calculate the next hash
*
* @param currentHash - The current hash
* @param element - The proof element to apply
* @returns The next hash in the path
*/
private applyProofElement;
/**
* Verify a proof with simplified inputs
*
* @param leafData - The original leaf data
* @param proof - Array of proof elements
* @param merkleRoot - The expected Merkle root
* @returns True if valid, false otherwise
*/
verifySimple(leafData: string, proof: Array<[string, ProofDirection]>, merkleRoot: string): boolean;
/**
* Set the leaf hash strategy
*
* @param strategy - The hash strategy to use for leaf nodes
*/
setLeafHashStrategy(strategy: HashStrategy): void;
/**
* Set the branch hash strategy
*
* @param strategy - The hash strategy to use for branch nodes
*/
setBranchHashStrategy(strategy: HashStrategy): void;
}