Package: merkly
The simple and easy implementation of Python Merkle Tree.Table of ContentsCreditsDocumentationRoadmapContributingLicenseCreditsDocumentationHOW TO INSTALLpoetry add merklypip install merklyHOW TO WORKSWARNING:We use keccak-256 under-the-hood if you dont pass your hash functionThis library provides a clean and easy to use implementation of the Merkle Tree with the following features:Create LeafCreate RootCreate ProofVerify ProofHOW TO USECreating a Merkle Treefrommerkly.mtreeimportMerkleTreefromtypingimportCallable# choose any hash function that is of type (bytes, bytes) -> bytesmy_hash_function:Callable[[bytes,bytes],bytes]=lambdax,y:x+y# create a Merkle Treemtree=MerkleTree(['a','b','c','d'],my_hash_function)# show original inputassertmtree.raw_leaves==['a','b','c','d']# hashed leavesassertmtree.leaves==[b'a',b'b',b'c',b'd']# shorted hashed leavesassertmtree.short_leaves==[b'a',b'b',b'c',b'd']Creating a Default Merkle Tree (with Keccak256)frommerkly.mtreeimportMerkleTree# create a Merkle Tree with keccak256mtree=MerkleTree(['a','b','c','d'])# show original inputassertmtree.raw_leaves==['a','b','c','d']# hashed leaves (just bytes)assertmtree.leaves==[b':\xc2%\x16\x8d\xf5B\x12\xa2\\\x1c\x01\xfd5\xbe\xbf\xea@\x8f\xda\xc2\xe3\x1d\xddo\x80\xa4\xbb\xf9\xa5\xf1\xcb',b'\xb5U=\xe3\x15\xe0\xed\xf5\x04\xd9\x15\n\xf8-\xaf\xa5\xc4f\x7f\xa6\x18\xed\no\x19\xc6\x9bA\x16lU\x10',b'\x0bB\xb69<\x1fS\x06\x0f\xe3\xdd\xbf\xcdz\xad\xcc\xa8\x94FZZC\x8fi\xc8}y\x0b"\x99\xb9\xb2',b'\xf1\x91\x8e\x85b#n\xb1z\xdc\x85\x023/L\x9c\x82\xbc\x14\xe1\x9b\xfc\n\xa1\n\xb6t\xffu\xb3\xd2\xf3']# shorted hashed leavesassertmtree.short_leaves==[b':\xc2',b'\xb5U',b'\x0bB',b'\xf1\x91']######## comming soon!# human leavesassertmtree.human_leaves==["3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb","b5553de315e0edf504d9150af82dafa5c4667fa618ed0a6f19c69b41166c5510","0b42b6393c1f53060fe3ddbfcd7aadcca894465a5a438f69c87d790b2299b9b2","f1918e8562236eb17adc8502332f4c9c82bc14e19bfc0aa10ab674ff75b3d2f3",]# shorted human hashed leavesassertmtree.human_short_leaves=["3ac2","b555","0b42","f191"]Creating a Rootfrommerkly.mtreeimportMerkleTree# create a Merkle Treemtree=MerkleTree(['a','b','c','d'])# get root of tree (This is compatible with MerkleTreeJS)assertmtree.root.hex()=='68203f90e9d07dc5859259d7536e87a6ba9d345f2552b5b9de2999ddce9ce1bf'Creating Proof of a leaffrommerkly.mtreeimportMerkleTreefrommerkly.nodeimportNode,Side# create a Merkle Treemtree=MerkleTree(['a','b','c','d'])# get proof of a `raw` leafassertmtree.proof('b')==[Node(data=b"3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb",side=Side.LEFT),Node(data=b"d253a52d4cb00de2895e85f2529e2976e6aaaa5c18106b68ab66813e14415669",side=Side.RIGHT)]Checking the proof of a sheetfrommerkly.mtreeimportMerkleTreefrommerkly.nodeimportNode,Side# create a Merkle Treemtree=MerkleTree(['a','b','c','d'])# get proof of a raw leafp=[Node(data=b"3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb",side=Side.LEFT),Node(data=b"d253a52d4cb00de2895e85f2529e2976e6aaaa5c18106b68ab66813e14415669",side=Side.RIGHT)]# verify your proof of raw leafassertmtree.verify(p,'b')==TrueRoadmapFeatureStatusVersionAuto deploy PyPi✅ Deployed0.2.0Create Root✅ Deployed0.4.0Create Proof✅ Deployed0.5.0Verify Proof✅ Deployed0.6.0Use any Hash function✅ Deployed0.7.0Leafs of any size✅ Deployed0.8.0Security deprecation pysha3✅ Deployed0.8.1Compatible with MerkleTreeJs✅ Deployed1.0.0First Issue solved by community✅ Deployed1.0.0Accelerator code with Rust🏗️ Alpha1.1.0Tutorial how to use with solidity🖊️ Designx.x.xTutorial how to use with MerkleTreeJS🖊️ Designx.x.xContributingBefore read a code of conduct:CODE_OF_CONDUCTFollow the guide of development:CONTRIBUTINGLicenseMIT