minauth-erc721-timelock-plugin
Version:
This package contains an implementation of a MinAuth plugin that combines zero-knowledge Merkle "membership" proofs with the ability to register into to a Merkle tree with locking an Ethereum NFT.
50 lines (49 loc) • 1.99 kB
TypeScript
/**
* @module MerkleTree
* This module provides an implementation of a Merkle Tree, a fundamental component
* in blockchain and cryptographic applications. It leverages the 'o1js' library for
* efficient Merkle Tree operations and is tailored for managing leaves represented as `Field` elements.
*/
import { Field } from 'o1js';
import { TreeWitness } from './merkle-membership-program.js';
import { Logger } from 'minauth/dist/plugin/logger.js';
/**
* A wrapper class for the Merkle Tree implementation from 'o1js' library.
* Non-unique leaves will be discarded.
*/
export declare class MerkleTree {
private readonly logger?;
/** Set of indexes of occupied leaves */
private leafMap;
/** Internal representation of the Merkle Tree using 'o1js' library */
private merkleTree;
private readonly leaves;
/**
* Constructs a Merkle Tree from a given array of leaves.
* @param leaves An array of `Field` elements to be used as leaves in the tree.
*/
constructor(leaves: Field[], logger?: Logger | undefined);
/**
* Creates a mapping from leaves to their corresponding indices in the tree.
* @param leaves An array of `Field` elements representing the leaves.
* @returns A Map object mapping each leaf to its index.
*/
private mkLeafToIndexMap;
/**
* Returns the root of the Merkle Tree.
* @returns The `Field` element representing the root of the tree.
*/
get root(): Field;
/**
* Returns the number of leaves in the Merkle Tree.
* @returns The count of leaves as a bigint.
*/
get leafCount(): number;
/**
* Generates a witness for a given leaf in the Merkle Tree.
* @param leaf The `Field` element for which the witness is to be generated.
* @returns A `TreeWitness` object representing the proof of the leaf's inclusion in the tree.
* @throws Error if the leaf is not found in the tree.
*/
getWitness(leaf: Field): TreeWitness;
}