# Hash-Based Commitment Lib API Reference Doc ## MerkleTree **MerkleTree**(hash_function: callable, automake: bool = True, number_vectors_to_commit: int, aggregate_leafs: (bool, List[type] List[callable]) = , fixed_depth: (bool, bool, int), prefilled: bool, default_vector: List[AnyImmutable], verify_transition: Callable) ## MerkleMountainRange **MerkleMountainRange**(hash_function: callable, automake: bool, aggregate_leafs: (bool, List[type] List[callable]), verify_transition: Callable) ## HashChain **HashChain**(hash_function: callable, automake: bool, aggregate_leafs: (bool, List[type] List[callable]), verify_transition: List[Callable], rehash: bool = True) ### Parameters **hash_function**: hash function used by the Merkle Tree **automake**: Compute the Merkle Tree at every commitment **number_vectors_to_commit**: provides the numbers of children to commit **aggregate_leafs**: Assuming same vector format at every leafs, commit children and the added value point-wise of the children. * First parameter give True/False if the user needs the option. * Second parameter gives the expected variable type at every position. * Third parameter gives the function to compute the children values on. **verify_transition**: Checks that the transition from previous vector and new vector is correct according to defined rules ### Merkle Tree Specific parameters **fixed_depth**: Gives the ability to define a dynamic or fixed sized tree. * First parameter give True/False if the user wants a fixed size * Second parameter gives the right to increase/decrease the size later * Third parameter gives the depth if the Tree is of fixed size **prefilled**: Gives the ability to define a tree is prefilled with a default vector **default_vector**: Provides for a prefilled tree the default vector. It can be a singleton or an Iterable of Immutables variables. ### HashChain Specific Methods **rehash**: If the hash function allows and flag at False, does incremental commitment instead of rehashing #### Nota Bene * All Peaks Are Merkle Tree objects * Could be implemented: > SpeaksCommitmentStrategy: An optimization to consider is to commit to both a Tree depending on the number of peaks: A chainhash, a merkle tree or a mix of the two > --- ### Method add(commitment: List[Hashable]) -> add a leaf and turn isReady to False addAtIndex(commitment: List[Hashable], index: int) -> add a leaf at specific index and turn isReady to False update(commitment: List[Hashable], index: int) -> modify a leaf and turn isReady to False remove(index: int) -> burn a leaf and goes to default vector and turn isReady to False size -> number of leafs reset() -> empty a tree and turn isReady to False resetSubTree(depth: int, index: int) -> empty a subtree at depth and index and turn isReady to False make() -> compute tree and turn isReady to True isReady -> Bool: MerkleTree has been constructed root -> get Merkle Root. Raise Error if not make() getPath(index: int) -> provide Path to root getBatchPaths(indexes: List[int]) -> provide path to root verifyPath(index: int, path: List[Hashable]) -> check path to root batchVerifyPaths(indexes: List[int], paths: List[List[Hashable]])-> verify multiple paths at the same time decommit(index: int) -> returns the committed vector batchDecommit(indexes: List[int]) -> returns a batch of committed vectors extractNode(depth: int, index: int) -> Get a specific node from the tree. Return an object from the same class than the parent display() -> Displey a representation of the tree serialize() -> Store an object unserialize() -> Load an object ### Merkle Tree Specific Methods **expand**(new_depth:int) -> turn a Merkle Tree into a subtree of a default vector filled tree **convertToMerkleMountainRange**() -> turn a Merkle Tree into a Merkle Mountain Range **convertToHashChain**() -> turn a Merkle Tree into a HashChain ### Merkle Mountain Range Specific Methods **extractPeaks**() -> output peak **convertToMerkleTree**(default_vector: List[AnyImmutable]) -> turn a Merkle Mountain range into a Merkle Tree **convertToHashChain**() -> turn a Merkle Tree into a HashChain ### HashChain Specific Methods **convertToMerkleTree**(default_vector: List[AnyImmutable]) -> turn a HashChain into a Merkle Tree **convertToMerkleMountainRange**() -> turn a HashChain into a Merkle Mountain Range ### Helpers **concat**(trees: List[MerkleTreesObjects]) -> Turn a list of Merkle Tree into a MerkleTree --- ## Bonus - Efficient Secret Storage ### *Elkrem* **Elkrem**(hash_function: callable, entropy: AnyImmutable = secret.token_bytes(32), depth: int = 32) ### *HashChain* **Elkrem**(hash_function: callable, entropy: AnyImmutable = secret.token_bytes(32), lenght: int = 2000, checkpoint: int) #### Parameters **entropy**: provides the seed **depth**: defined the max number of secrets as 2^depth #### Methods **getNewSecret**(): provides a new secret **getSecretAtIndex**(index: int): provides the secret at corresponding index **getBatchSecretxAtIndex**(indexes: List[int]): provides the secret at corresponding index **addSecret**(secret: Union(int,str,bytes)): accumulate a new value into storage **compressSecrets**(secrets: List[Union(int,str,bytes)]): Assuming correct sequentionality of secret, returns the values to store to recover the secrets **retrieveSecret**(seed: Union(int,str,bytes), index: int): returns the secret at corresponding index ---