diff --git a/README.md b/README.md index 6649a1a..a189cb8 100644 --- a/README.md +++ b/README.md @@ -110,8 +110,6 @@ assert mtree.leaves == [ assert mtree.short_leaves == [b':\xc2', b'\xb5U', b'\x0bB', b'\xf1\x91'] -######## comming soon! - # human leaves assert mtree.human_leaves == [ "3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb", @@ -120,7 +118,7 @@ assert mtree.human_leaves == [ "f1918e8562236eb17adc8502332f4c9c82bc14e19bfc0aa10ab674ff75b3d2f3", ] # shorted human hashed leaves -assert mtree.human_short_leaves = ["3ac2", "b555", "0b42", "f191"] +assert mtree.human_short_leaves == ["3ac2", "b555", "0b42", "f191"] ``` **Creating a Root** @@ -146,8 +144,14 @@ mtree = MerkleTree(['a', 'b', 'c', 'd']) # get proof of a `raw` leaf assert mtree.proof('b') == [ - Node(data=b"3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb", side=Side.LEFT), - Node(data=b"d253a52d4cb00de2895e85f2529e2976e6aaaa5c18106b68ab66813e14415669", side=Side.RIGHT) + Node( + data=b"3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb", + side=Side.LEFT + ), + Node( + data=b"d253a52d4cb00de2895e85f2529e2976e6aaaa5c18106b68ab66813e14415669", + side=Side.RIGHT + ) ] ``` @@ -190,7 +194,8 @@ assert mtree.verify(p, 'b') == True | Security deprecation pysha3 | ✅ Deployed | 0.8.1 | | Compatible with MerkleTreeJs | ✅ Deployed | 1.0.0 | | First Issue solved by community | ✅ Deployed | 1.0.0 | -| Accelerator code with Rust | 🏗️ Alpha | 1.1.0 | +| Human readable leaves | ✅ Deployed | 1.1.0 | +| Accelerator code with Rust | 🏗️ Alpha | 1.2.0 | | Tutorial how to use with solidity | 🖊️ Design | x.x.x | | Tutorial how to use with MerkleTreeJS | 🖊️ Design | x.x.x | diff --git a/merkly/mtree.py b/merkly/mtree.py index 49309f6..997d21b 100644 --- a/merkly/mtree.py +++ b/merkly/mtree.py @@ -165,3 +165,11 @@ def up_layer(self, leaves: List[bytes]) -> List[bytes]: data = self.hash_function(pair[0], pair[1]) new_layer.append(data) return new_layer + + @property + def human_leaves(self) -> list[str]: + return [leaf.hex() for leaf in self.leaves] + + @property + def human_short_leaves(self) -> list[str]: + return [leaf.hex() for leaf in self.short_leaves] diff --git a/pyproject.toml b/pyproject.toml index 0425846..a87b8bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "merkly" -version = "1.0.2" +version = "1.1.0" description = "🌳 The simple and easy implementation of Merkle Tree" authors = ["Lucas Oliveira "] repository = "https://github.com/olivmath/merkly.git" diff --git a/test/merkle_root/test_merkle_root.py b/test/merkle_root/test_merkle_root.py index 153ce53..19cd35b 100644 --- a/test/merkle_root/test_merkle_root.py +++ b/test/merkle_root/test_merkle_root.py @@ -39,6 +39,15 @@ def test_simple_merkle_tree_constructor(): == "68203f90e9d07dc5859259d7536e87a6ba9d345f2552b5b9de2999ddce9ce1bf" ) + assert tree.human_leaves == [ + "3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb", + "b5553de315e0edf504d9150af82dafa5c4667fa618ed0a6f19c69b41166c5510", + "0b42b6393c1f53060fe3ddbfcd7aadcca894465a5a438f69c87d790b2299b9b2", + "f1918e8562236eb17adc8502332f4c9c82bc14e19bfc0aa10ab674ff75b3d2f3", + ] + + assert tree.human_short_leaves == ["3ac2", "b555", "0b42", "f191"] + @mark.parametrize( "leaves, root",