Skip to content

Commit

Permalink
add: human readable leaves in merkly and test
Browse files Browse the repository at this point in the history
  • Loading branch information
olivmath committed Dec 31, 2023
1 parent edcaf8f commit fef5290
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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**
Expand All @@ -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
)
]
```

Expand Down Expand Up @@ -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 |

Expand Down
8 changes: 8 additions & 0 deletions merkly/mtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
repository = "https://github.com/olivmath/merkly.git"
Expand Down
9 changes: 9 additions & 0 deletions test/merkle_root/test_merkle_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit fef5290

Please sign in to comment.