项目作者: mynameisvinn

项目描述 :
merkle merkle merkle
高级语言: Python
项目地址: git://github.com/mynameisvinn/merkle.git
创建时间: 2017-08-20T12:52:03Z
项目社区:https://github.com/mynameisvinn/merkle

开源协议:

下载


merkle

combining hash functions with graphs was ralph merkle’s big idea. merkle dags are everywhere you want data integrity through self verification: git, ipfs, blockchain.

whats a merkle tree?

we have a hashing function $h(x)$ and four records a, b, c, d. a merkle tree would be y:

  1. h_ab = h[h(a) + h(b)]
  2. h_cd = h[h(c) + h(d)]
  3. root_hash = h(h_ab + h_cd)

whats a merkle dag?

a merkle dag is an acylic collection of merkle trees. by referencing its predecessor’s root hash, a merkle dag tracks history.

  1. h_ab = h[h(a) + h(b)]
  2. h_cd = h[h(c) + h(d)]
  3. root_hash_1 = h(h_ab + h_cd)
  4. h_ef = h[h(e) + h(f)]
  5. h_gh = h[h(g) + h(h)]
  6. root_hash_2 = h(h_ef + h_gh + root_hash_1) # 2nd root hash knows its parent

usage

  1. import merkle
  2. from merkle import generate_merkle_root
  3. transactions = ['tx1', 'tx2', 'tx3', 'tx4', 'tx5']
  4. generate_merkle_root(transactions) # returns e5fb69843938b939e7f1823414b2e3aaa52c1eaa

assuming you have the hash e5fb69843938b939e7f1823414b2e3aaa52c1eaa from a trusted authority, you can download chunks of data from various sources, compare its merkle root hash with the trusted one, and be confident that it’s the same set of data.