Skip to main content

Python port of merkletreejs

Project description


Python port of merkletreejs. Currently unstable.


pip install merkletreepy


from merkletreepy import MerkleTree
import Web3

def hash_function(x):
    return Web3.keccak(text=x).hex()

leaves = [hash_function(leaf) for leaf in "abc"]
tree = MerkleTree(leaves, sha256)
root = tree.get_root()
leaf = sha256("a")
bad_leaf = sha256("x")
proof = tree.get_proof(leaf)
tree.verify(proof, leaf, root)      # returns True
tree.verify(proof, bad_leaf, root)  # returns False

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

merkletreepy-0.0.2.tar.gz (3.3 kB view hashes)

Uploaded source

Built Distribution

merkletreepy-0.0.2-py3-none-any.whl (3.6 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page