• Stars
    star
    97
  • Rank 336,111 (Top 7 %)
  • Language
    Elixir
  • Created almost 8 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🌲 Merkle Tree implementation in pure Elixir

MerkleTree

Merkle Tree implementation in pure Elixir.

Travis Coveralls Hex.pm

Installation

  • Install the Elixir functional language.

  • Create New Project with Mix

    mix new my_app; cd my_app
  • Add merkle_tree to your list of dependencies in mix.exs.

    def deps do
      [{:merkle_tree, "~> 1.6.0"}]
    end
  • Install Mix Dependencies

    mix deps.get

Usage

  • Run Interactive Elixir (IEx) within context of Elixir app and dependencies injected into IEx runtime

    iex -S mix
  • Try the MerkleTree Module

    iex> MerkleTree.__info__(:functions)
    [__struct__: 0, __struct__: 1, build: 2, new: 1, new: 2]
    iex> mt = 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: [],
              value: "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb"},
              %MerkleTree.Node{children: [], value: "3e23e8160039594a33894f6564e1b1348bbd7a0088d42c4acb73eeaed59c009d"}],
            value: "62af5c3cb8da3e4f25061e829ebeea5c7513c54949115b1acc225930a90154da"},
            %MerkleTree.Node{children: [%MerkleTree.Node{children: [], value: "2e7d2c03a9507ae265ecf5b5356885a53393a2029d241394997265a1a25aefc6"},
              %MerkleTree.Node{children: [], value: "18ac3e7343f016890c510e93f935261169d9e3f565436429830faf0934f4f8e4"}],
            value: "d3a0f1c792ccf7f1708d5422696263e35755a86917ea76ef9242bd4a8cf4891a"}],
          value: "58c89d709329eb37285837b042ab6ff72c7c8f74de0446b091b6a0131c102cfd"}}
    $ mt.blocks()
    ['a', 'b', 'c', 'd']
    $ mt.hash_function()
    &MerkleTree.Crypto.sha256/1
    $ mt.root()
    ...
  • Try the MerkleTree.Proof Module (requires merkle_tree >1.2.0)

    iex> MerkleTree.Proof.__info__(:functions)           
    [__struct__: 0, __struct__: 1, prove: 2, proven?: 3]
    iex> proof1 = MerkleTree.Proof.prove(mt, 1)
    iex> proven1 = MerkleTree.Proof.proven?({"b", 1}, "58c89d709329eb37285837b042ab6ff72c7c8f74de0446b091b6a0131c102cfd", proof1)
    true
    
    iex> proof3 = MerkleTree.Proof.prove(mt, 3)                                              %MerkleTree.Proof{          
      hash_function: &MerkleTree.Crypto.sha256/1,
      hashes: ["62af5c3cb8da3e4f25061e829ebeea5c7513c54949115b1acc225930a90154da",
      "2e7d2c03a9507ae265ecf5b5356885a53393a2029d241394997265a1a25aefc6"]
    }
    iex> proven3 = MerkleTree.Proof.proven?({"d", 3}, "58c89d709329eb37285837b042ab6ff72c7c8f74de0446b091b6a0131c102cfd", proof3)
    true
  • Try the MerkleTree.Crypto Module

    iex> MerkleTree.Crypto.__info__(:functions)
    [hash: 2, sha256: 1]
    iex> MerkleTree.Crypto.hash("tendermint", :sha256)
    "f6c3848fc2ab9188dd2c563828019be7cee4e269f5438c19f5173f79898e9ee6"
    iex> MerkleTree.Crypto.hash("tendermint", :md5)   
    "bc93700bdf1d47ad28654ad93611941f"
    iex> MerkleTree.Crypto.sha256("tendermint")    
    "f6c3848fc2ab9188dd2c563828019be7cee4e269f5438c19f5173f79898e9ee6"

Background

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. Hash trees are a generalization of hash lists and hash chains.

Hash 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.

Running Type Checker

mix dialyzer

Contributing

  1. Fork it ( http://github.com/Leventhan/merkle_tree/fork )
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/my-new-feature)
  5. Create a new Pull Request (Remember to squash your commits!)

Kindly report any found bugs or errors using the issue tracker.

Thanks

merkle_tree Β© 2016+, Yos Riady. Released under the MIT License.
Authored and maintained by Yos Riady with help from contributors (list).

yos.io Β Β·Β  GitHub @yosriady

More Repositories

1

awesome-api-devtools

πŸ“š A collection of useful resources for building RESTful HTTP+JSON APIs.
3,466
star
2

serverless-auth

Serverless Authorization example with JWT and AWS Custom Authorizers
JavaScript
80
star
3

continuous-token

ERC20 token with built-in Automated Market Maker + Bonding Curve
Solidity
80
star
4

serverless-stripe-backend

Serverless payments built on AWS Lambda & the Serverless framework
JavaScript
76
star
5

ecs

🐰 Entity Component System
Elixir
66
star
6

serverless-crud-go

Example CRUD Serverless Application in Go
Go
49
star
7

serverless-ethers

Serverless smart contract automation service, built on the Serverless framework.
34
star
8

serverless-stripe-frontend

Frontend application for `serverless-stripe-backend` written in Next.js & React
JavaScript
29
star
9

serverless-go-boilerplate

Boilerplate Serverless Go project
Go
25
star
10

contracts-starter

A robust smart contract development template for Ethereum and EVM chains
TypeScript
20
star
11

haiku

πŸ—» Generate memorable names similar to Xaddress or Heroku
Elixir
20
star
12

serverless-sagas

Distributed saga example with AWS Lambda and Step Functions
JavaScript
20
star
13

gravity

πŸš€ Elixir client for the Gravatar API
Elixir
20
star
14

pubsub

πŸ“£ Publish-Subscribe in Elixir
Elixir
19
star
15

node-bayes

πŸ“ˆ Naive Bayes classifier for Node
JavaScript
14
star
16

kare

πŸ› Curry functions in Elixir
Elixir
12
star
17

decision_tree

🌳 Decision Tree Learning in pure Elixir (in progress)
Elixir
10
star
18

bloom_filter

🌻 Bloom Filter implementation in pure Elixir
Elixir
10
star
19

curl-to-har

Convert curl commands to HAR request objects
JavaScript
10
star
20

testing-solidity

Example Solidity unit testing Truffle project. Includes common test scenarios and a kitchen sink of test helpers.
JavaScript
7
star
21

datatron

Hack 'n Roll 2016 - Data Analytics Platform
JavaScript
7
star
22

openresty-quickstart

Barebones OpenResty Project
Nginx
5
star
23

apidocs-gallery

Showcasing the best of API documentation
HTML
4
star
24

simple_statistics

πŸ“Š Sample Elixir library
Elixir
4
star
25

circuit-breakers

Fault tolerant smart contracts with Circuit Breakers in Solidity.
Solidity
4
star
26

dapp-boilerplate

Minimal Ethereum Decentralized Application (ÐApp) Boilerplate with Solidity and Truffle
JavaScript
3
star
27

serverless-crud-go-tf

Serverless CRUD application with Go, AWS Lambda, and Terraform
HCL
3
star
28

petstore-node-server

Autogenerated Node.js API Server Stub using Swagger Codegen
JavaScript
3
star
29

awesome-web3

A curated list of awesome Web3 tools, books, courses, and more. Launch and learn on web3 faster!
3
star
30

patronage-collectibles

Harberger-Taxed ERC721 Collectibles for Decentralized Crowdfunding
Solidity
2
star
31

Other-Java-code

Java
2
star
32

sheethub

Community marketplace for musicians
Ruby
2
star
33

pdfminer-sample

Sample of how to use pdfminer to convert PDF to txt
Python
2
star
34

ark-minter

https://trello.com/b/59noB5R1/ark-minter-mvp
JavaScript
2
star
35

sanity-check

Chakra UI + Electron React Boilerplate = ERR
TypeScript
2
star
36

orbital-leaflet

CP3108B: Independent Work (Orbital) Web Map API tutorial using Leaflet
Python
1
star
37

ytunes-2013

Hackathon '13 entry. Hacked together in less than 24 hours. All the songs you want, powered by Youtube.
JavaScript
1
star
38

exkv

Distributed key-value store in Elixir
Elixir
1
star
39

neural_network

πŸ’­ Artifical Neural Networks in Elixir (in progress)
Elixir
1
star
40

bioinformatics.rb

Computational Biology in Ruby
Ruby
1
star
41

merchant

Practice Merchant Rails application
Ruby
1
star
42

codeextremeapps

1st Prize $9000 winning entry (RUM: Realtime Ubiquitous Monitoring)
JavaScript
1
star
43

botsquad

Automated Agents as a Service
Ruby
1
star
44

paypal-rest-sample-app

Sample Rails application for PayPal REST APIs
Ruby
1
star
45

wrapped-ERC20

Turn your faulty ERC20 tokens to a compliant Wrapped ERC20 token.
JavaScript
1
star
46

geogist

Create and Share GeoJSON snippets.
Ruby
1
star
47

snapnext

Backend for a photo filter app
JavaScript
1
star
48

xdomain-ownership

TypeScript
1
star
49

serverless-kinesis

Serverless realtime processing pipeline with Kinesis Streams
JavaScript
1
star
50

pg_tags

A high performance tagging gem for Rails applications using the PostgreSQL array type. A simpler alternative to acts_as_taggable_on.
Ruby
1
star