6006120e60
Signed-off-by: T-Hax <>
112 lines
3.6 KiB
TypeScript
112 lines
3.6 KiB
TypeScript
declare module "src/mimc" {
|
|
function _exports(left: any, right: any): any;
|
|
export = _exports;
|
|
}
|
|
declare module "fixed-merkle-tree/src/merkleTree" {
|
|
export = MerkleTree;
|
|
/**
|
|
* @callback hashFunction
|
|
* @param left Left leaf
|
|
* @param right Right leaf
|
|
*/
|
|
/**
|
|
* Merkle tree
|
|
*/
|
|
export class MerkleTree {
|
|
/**
|
|
* Deserialize data into a MerkleTree instance
|
|
* Make sure to provide the same hashFunction as was used in the source tree,
|
|
* otherwise the tree state will be invalid
|
|
*
|
|
* @param data
|
|
* @param hashFunction
|
|
* @returns {MerkleTree}
|
|
*/
|
|
static deserialize(data: any, hashFunction: any): MerkleTree;
|
|
/**
|
|
* Constructor
|
|
* @param {number} levels Number of levels in the tree
|
|
* @param {Array} [elements] Initial elements
|
|
* @param {Object} options
|
|
* @param {hashFunction} [options.hashFunction] Function used to hash 2 leaves
|
|
* @param [options.zeroElement] Value for non-existent leaves
|
|
*/
|
|
constructor(levels: number, elements?: any[], { hashFunction, zeroElement }?: {
|
|
hashFunction?: hashFunction;
|
|
zeroElement?: any;
|
|
});
|
|
levels: number;
|
|
capacity: number;
|
|
_hash: (left: any, right: any) => any;
|
|
zeroElement: any;
|
|
_zeros: any[];
|
|
_layers: any[][];
|
|
_rebuild(): void;
|
|
/**
|
|
* Get tree root
|
|
* @returns {*}
|
|
*/
|
|
root(): any;
|
|
/**
|
|
* Insert new element into the tree
|
|
* @param element Element to insert
|
|
*/
|
|
insert(element: any): void;
|
|
/**
|
|
* Insert multiple elements into the tree.
|
|
* @param {Array} elements Elements to insert
|
|
*/
|
|
bulkInsert(elements: any[]): void;
|
|
/**
|
|
* Change an element in the tree
|
|
* @param {number} index Index of element to change
|
|
* @param element Updated element value
|
|
*/
|
|
update(index: number, element: any): void;
|
|
/**
|
|
* Get merkle path to a leaf
|
|
* @param {number} index Leaf index to generate path for
|
|
* @returns {{pathElements: Object[], pathIndex: number[]}} An object containing adjacent elements and left-right index
|
|
*/
|
|
path(index: number): {
|
|
pathElements: any[];
|
|
pathIndex: number[];
|
|
};
|
|
/**
|
|
* Find an element in the tree
|
|
* @param element An element to find
|
|
* @param comparator A function that checks leaf value equality
|
|
* @returns {number} Index if element is found, otherwise -1
|
|
*/
|
|
indexOf(element: any, comparator: any): number;
|
|
/**
|
|
* Returns a copy of non-zero tree elements
|
|
* @returns {Object[]}
|
|
*/
|
|
elements(): any[];
|
|
/**
|
|
* Returns a copy of n-th zero elements array
|
|
* @returns {Object[]}
|
|
*/
|
|
zeros(): any[];
|
|
/**
|
|
* Serialize entire tree state including intermediate layers into a plain object
|
|
* Deserializing it back will not require to recompute any hashes
|
|
* Elements are not converted to a plain type, this is responsibility of the caller
|
|
*/
|
|
serialize(): {
|
|
levels: number;
|
|
_zeros: any[];
|
|
_layers: any[][];
|
|
};
|
|
}
|
|
namespace MerkleTree {
|
|
export { hashFunction };
|
|
}
|
|
type hashFunction = (left: any, right: any) => any;
|
|
}
|
|
declare module "fixed-merkle-tree" {
|
|
const _exports: typeof import("fixed-merkle-tree/src/merkleTree");
|
|
export = _exports;
|
|
}
|
|
//# sourceMappingURL=index.d.ts.map
|