{"id":13507302,"url":"https://github.com/yosriady/merkle_tree","last_synced_at":"2025-04-09T08:10:06.078Z","repository":{"id":57524893,"uuid":"59191915","full_name":"yosriady/merkle_tree","owner":"yosriady","description":":evergreen_tree: Merkle Tree implementation in pure Elixir","archived":false,"fork":false,"pushed_at":"2020-01-30T07:03:47.000Z","size":284,"stargazers_count":96,"open_issues_count":1,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-02T05:09:32.386Z","etag":null,"topics":["elixir","merkle-tree"],"latest_commit_sha":null,"homepage":"http://yos.io/2016/05/19/merkle-trees-in-elixir/","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yosriady.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-19T09:17:22.000Z","updated_at":"2024-08-13T15:37:48.000Z","dependencies_parsed_at":"2022-08-26T03:31:49.491Z","dependency_job_id":null,"html_url":"https://github.com/yosriady/merkle_tree","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yosriady%2Fmerkle_tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yosriady%2Fmerkle_tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yosriady%2Fmerkle_tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yosriady%2Fmerkle_tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yosriady","download_url":"https://codeload.github.com/yosriady/merkle_tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999861,"owners_count":21031046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","merkle-tree"],"created_at":"2024-08-01T02:00:30.599Z","updated_at":"2025-04-09T08:10:06.042Z","avatar_url":"https://github.com/yosriady.png","language":"Elixir","funding_links":[],"categories":["Algorithms and Data structures"],"sub_categories":[],"readme":"# MerkleTree\n\nMerkle Tree implementation in pure Elixir.\n\n[![Travis](https://img.shields.io/travis/yosriady/merkle_tree.svg?maxAge=2592000)](https://travis-ci.org/yosriady/merkle_tree)\n[![Coveralls](https://img.shields.io/coveralls/yosriady/merkle_tree.svg?maxAge=2592000)](https://coveralls.io/github/yosriady/merkle_tree)\n[![Hex.pm](https://img.shields.io/hexpm/v/merkle_tree.svg?maxAge=2592000)](https://hex.pm/packages/merkle_tree)\n\n### [Hex (Package Manager)](http://hex.pm/packages/merkle_tree)\n### [API Documentation](https://hexdocs.pm/merkle_tree/)\n\n## Installation\n\n* Install the [Elixir](https://elixir-lang.org/) functional language.\n\n* Create New Project with Mix\n  ```bash\n  mix new my_app; cd my_app\n  ```\n\n* Add `merkle_tree` to your list of dependencies in `mix.exs`.\n  ```elixir\n  def deps do\n    [{:merkle_tree, \"~\u003e 1.6.0\"}]\n  end\n  ```\n\n* Install Mix Dependencies\n  ```bash\n  mix deps.get\n  ```\n\n## Usage\n\n* Run [Interactive Elixir (IEx)](https://hexdocs.pm/iex/IEx.html) within context of Elixir app and dependencies injected into IEx runtime\n  ```bash\n  iex -S mix\n  ```\n\n* Try the [MerkleTree Module](https://hexdocs.pm/merkle_tree/MerkleTree.html)\n  ```elixir\n  iex\u003e MerkleTree.__info__(:functions)\n  [__struct__: 0, __struct__: 1, build: 2, new: 1, new: 2]\n  iex\u003e mt = MerkleTree.new ['a', 'b', 'c', 'd']\n  %MerkleTree{blocks: ['a', 'b', 'c', 'd'], hash_function: \u0026MerkleTree.Crypto.sha256/1,\n        root: %MerkleTree.Node{children: [%MerkleTree.Node{children: [%MerkleTree.Node{children: [],\n            value: \"ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb\"},\n            %MerkleTree.Node{children: [], value: \"3e23e8160039594a33894f6564e1b1348bbd7a0088d42c4acb73eeaed59c009d\"}],\n          value: \"62af5c3cb8da3e4f25061e829ebeea5c7513c54949115b1acc225930a90154da\"},\n          %MerkleTree.Node{children: [%MerkleTree.Node{children: [], value: \"2e7d2c03a9507ae265ecf5b5356885a53393a2029d241394997265a1a25aefc6\"},\n            %MerkleTree.Node{children: [], value: \"18ac3e7343f016890c510e93f935261169d9e3f565436429830faf0934f4f8e4\"}],\n          value: \"d3a0f1c792ccf7f1708d5422696263e35755a86917ea76ef9242bd4a8cf4891a\"}],\n        value: \"58c89d709329eb37285837b042ab6ff72c7c8f74de0446b091b6a0131c102cfd\"}}\n  $ mt.blocks()\n  ['a', 'b', 'c', 'd']\n  $ mt.hash_function()\n  \u0026MerkleTree.Crypto.sha256/1\n  $ mt.root()\n  ...\n  ```\n\n* Try the [MerkleTree.Proof Module](https://hexdocs.pm/merkle_tree/MerkleTree.Proof.html) (requires merkle_tree \u003e1.2.0)\n  ```elixir\n  iex\u003e MerkleTree.Proof.__info__(:functions)           \n  [__struct__: 0, __struct__: 1, prove: 2, proven?: 3]\n  iex\u003e proof1 = MerkleTree.Proof.prove(mt, 1)\n  iex\u003e proven1 = MerkleTree.Proof.proven?({\"b\", 1}, \"58c89d709329eb37285837b042ab6ff72c7c8f74de0446b091b6a0131c102cfd\", proof1)\n  true\n\n  iex\u003e proof3 = MerkleTree.Proof.prove(mt, 3)                                              %MerkleTree.Proof{          \n    hash_function: \u0026MerkleTree.Crypto.sha256/1,\n    hashes: [\"62af5c3cb8da3e4f25061e829ebeea5c7513c54949115b1acc225930a90154da\",\n    \"2e7d2c03a9507ae265ecf5b5356885a53393a2029d241394997265a1a25aefc6\"]\n  }\n  iex\u003e proven3 = MerkleTree.Proof.proven?({\"d\", 3}, \"58c89d709329eb37285837b042ab6ff72c7c8f74de0446b091b6a0131c102cfd\", proof3)\n  true\n  ```\n\n* Try the [MerkleTree.Crypto Module](https://hexdocs.pm/merkle_tree/MerkleTree.Crypto.html)\n  ```elixir\n  iex\u003e MerkleTree.Crypto.__info__(:functions)\n  [hash: 2, sha256: 1]\n  iex\u003e MerkleTree.Crypto.hash(\"tendermint\", :sha256)\n  \"f6c3848fc2ab9188dd2c563828019be7cee4e269f5438c19f5173f79898e9ee6\"\n  iex\u003e MerkleTree.Crypto.hash(\"tendermint\", :md5)   \n  \"bc93700bdf1d47ad28654ad93611941f\"\n  iex\u003e MerkleTree.Crypto.sha256(\"tendermint\")    \n  \"f6c3848fc2ab9188dd2c563828019be7cee4e269f5438c19f5173f79898e9ee6\"\n  ```\n\n## Background\n\nA 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. Hash trees are a generalization of hash lists and hash chains.\n\n![](https://upload.wikimedia.org/wikipedia/commons/thumb/9/90/MerkleTree1.svg/800px-MerkleTree1.svg.png)\n\nHash trees can be used to verify any kind of data stored, handled and transferred in and between computers. Currently the main use of hash trees is to make sure that data blocks received from other peers in a peer-to-peer network are received undamaged and unaltered, and even to check that the other peers do not lie and send fake blocks. Suggestions have been made to use hash trees in trusted computing systems. Hash trees are used in the IPFS and ZFS file systems,  BitTorrent protocol, Apache Wave protocol, Git distributed revision control system, the Bitcoin peer-to-peer network, the Ethereum peer-to-peer network, and a number of NoSQL systems like Apache Cassandra and Riak.\n\n## Running Type Checker\n\n```bash\nmix dialyzer\n```\n\n## Contributing\n\n1. Fork it ( http://github.com/Leventhan/merkle_tree/fork )\n2. Create your feature branch (`git checkout -b feature/my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin feature/my-new-feature`)\n5. Create a new Pull Request (Remember to squash your commits!)\n\n\u003e Kindly report any found bugs or errors using [the issue tracker](https://github.com/Leventhan/merkle_tree/issues).\n\n## Thanks\n\n**merkle_tree** © 2016+, Yos Riady. Released under the [MIT] License.\u003cbr\u003e\nAuthored and maintained by Yos Riady with help from contributors ([list][contributors]).\n\n\u003e [yos.io](http://yos.io) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e GitHub [@yosriady](https://github.com/yosriady)\n\n[MIT]: http://mit-license.org/\n[contributors]: http://github.com/yosriady/merkle_tree/contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyosriady%2Fmerkle_tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyosriady%2Fmerkle_tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyosriady%2Fmerkle_tree/lists"}