UNPKG

@0xcert/merkle

Version:

Implementation of basic functions of binary Merkle tree.

37 lines (36 loc) 1.32 kB
export declare enum MerkleHasherPosition { VALUE = 0, LEAF = 1, NODE = 2 } export declare type MerkleHasher = ((value: any, path: (string | number)[], position: MerkleHasherPosition) => string) | ((value: any, path: (string | number)[], position: MerkleHasherPosition) => Promise<string>); export declare type MerkleNoncer = ((path: (string | number)[]) => string) | ((path: (string | number)[]) => Promise<string>); export interface MerkleValue { index: number; value: any; nonce: string; } export interface MerkleNode { index: number; hash: string; } export interface MerkleRecipe { values: MerkleValue[]; nodes: MerkleNode[]; } export interface MerkleOptions { hasher?: MerkleHasher; noncer?: MerkleNoncer; } export declare class Merkle { protected _options: MerkleOptions; constructor(options?: MerkleOptions); hash(value: any, path: (string | number)[], position: MerkleHasherPosition): string | Promise<string>; nonce(path: (string | number)[]): string | Promise<string>; notarize(data: (string | number | boolean)[], prepend?: (string | number)[]): Promise<MerkleRecipe>; disclose(recipe: MerkleRecipe, expose: number[]): Promise<{ values: any[]; nodes: MerkleNode[]; }>; imprint(recipe: MerkleRecipe): Promise<string>; }