hash() = binary()
abstract datatype: merkle()
abstract datatype: proof()
tree() = #leaf{hash = hash(), value = any()} | #empty{hash = hash()} | #node{hash = hash(), height = non_neg_integer(), left = tree(), right = tree()}
count/1 | get the number of leaves int he merkle tree. |
fold/3 | Fold over the leaves of the merkle tree. |
gen_proof/2 | Generate a merkle proof for a given hash in the tree. |
hash_value/1 | A commonly used hash value for merkle trees. |
height/1 | Get the height of the given merkle tree. |
leaves/1 | Get a list of values and their hashes from the tree. |
new/2 | Construct a merkle tree given a list of values and a hash function. |
proof_hashes/1 | Get just the hashes from a given proof. |
root_hash/1 | Gets the root hash of the given merkle tree. |
values/1 | Get the values of the merkle tree. |
verify_proof/3 | Verifies that a given hash of a value is in a given merkle tree using the provided proof. |
count(Merkle::merkle()) -> non_neg_integer()
get the number of leaves int he merkle tree.
fold(FoldFun, Acc, Merkle::tree() | merkle()) -> Acc
Fold over the leaves of the merkle tree. The given function
will take the a {hash, value}
tuple, and a given accumulator to
fold over the merkle tree with and returns the resulting
accumulator.
Generate a merkle proof for a given hash in the tree. Note that the resulting proof does not include the value hash itself, which saves space in the proof.
hash_value(Value) -> any()
A commonly used hash value for merkle trees. This function will SHA256 hash the given value when it is binary. A convenience form detects non-binary forms and uses term_to_binary/1 to convert other erlang terms to a binary form. It is not recommended to use the non-binary form if the resulting trees or proofs are to be sent over a network.
height(Merkle::merkle()) -> non_neg_integer()
Get the height of the given merkle tree. This is a fast operation since the hash was calculated on construction of the tree.
Get a list of values and their hashes from the tree. The resulting list retains the same order as the list that was passed in on merkle construction.
Construct a merkle tree given a list of values and a hash function. The hash function is used to calculate the hash of the leaf value. A simple one hash_value/1 is provided in this module. The resulting merkle tree retains the order of the values but duplicate values (as determined by the result of the hash function) are skipped, so only the first found element counts.
Get just the hashes from a given proof.
Gets the root hash of the given merkle tree. This is a fast operation since the hash was calculated on construction of the tree.
values(M::merkle()) -> [term()]
Get the values of the merkle tree. This returns the values in the same order as the list that was passed in on merkle construction.
verify_proof(ValueHash::hash(), Merkle::merkle() | hash(), Proof::proof() | {error, any()}) -> ok | {error, Reason}
Verifies that a given hash of a value is in a given merkle tree using the provided proof.
Generated by EDoc