merkle_tree v1.4.0 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> 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 blocks and hash function or opts available options:
:hash_function - used hash in mercle tree default :sha256 from :cryto
:hash_leaves - flag says whether the leaves should be hashed, default true
:height - allows to construct tree of provided height,
empty leaves data will be taken from `:default_data_block` parameter
:default_data_block - this data will be used to supply empty
leaves in case where there isn't enough blocks provided
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)
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 | [{atom, any}]) :: t
Creates a new merkle tree. given a blocks and hash function or opts available options:
:hash_function - used hash in mercle tree default :sha256 from :cryto
:hash_leaves - flag says whether the leaves should be hashed, default true
:height - allows to construct tree of provided height,
empty leaves data will be taken from `:default_data_block` parameter
:default_data_block - this data will be used to supply empty
leaves in case where there isn't enough blocks provided
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)
.