merkle_tree v1.1.1 MerkleTree
A hash tree or Merkle tree is a tree in which every non-leaf node is labelled with the hash of the labels or values (in case of leaves) of its child nodes. Hash trees are useful because they allow efficient and secure verification of the contents of large data structures.
## Usage Example
iex> f = MerkleTree.new ['a', 'b', 'c', 'd']
%MerkleTree{blocks: ['a', 'b', 'c', 'd'], hash_function: &MerkleTree.Crypto.sha256/1,
root: %MerkleTree.Node{children: [%MerkleTree.Node{children: [%MerkleTree.Node{children: [], height: 0,
value: "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"},
%MerkleTree.Node{children: [], height: 0, value: "3e23e8160039594a33894f6564e1b1348bbd7a0088d42c4acb73eeaed59c009d"}], height: 1,
value: "62af5c3cb8da3e4f25061e829ebeea5c7513c54949115b1acc225930a90154da"},
%MerkleTree.Node{children: [%MerkleTree.Node{children: [], height: 0,
value: "2e7d2c03a9507ae265ecf5b5356885a53393a2029d241394997265a1a25aefc6"},
%MerkleTree.Node{children: [], height: 0, value: "18ac3e7343f016890c510e93f935261169d9e3f565436429830faf0934f4f8e4"}], height: 1,
value: "d3a0f1c792ccf7f1708d5422696263e35755a86917ea76ef9242bd4a8cf4891a"}], height: 2,
value: "58c89d709329eb37285837b042ab6ff72c7c8f74de0446b091b6a0131c102cfd"}}
Summary
Functions
Builds a new binary merkle tree
Creates a new merkle tree, given a 2^N
number of string blocks and an
optional hash function
Types
hash_function :: (String.t -> String.t)
t :: %MerkleTree{blocks: blocks, hash_function: hash_function, root: root}
Functions
Specs
build(blocks, hash_function) :: root
Builds a new binary merkle tree.
Specs
new(blocks, hash_function) :: t
Creates a new merkle tree, given a 2^N
number of string blocks and an
optional hash function.
By default, merkle_tree
uses :sha256
from :crypto.
Check out MerkleTree.Crypto
for other available cryptographic hashes.
Alternatively, you can supply your own hash function that has the spec
(String.t -> String.t)
.