A Merkle tree supporting append, update, remove operations.
Project description
Mutable Merkle
mutable_merkle
provides a merkle tree with append, update and remove leaf functionality. This
is intended to support solutions that are not just append only.
m1 = mutable_merkle.tree.MerkleTree.new([b"a", b"b", b"c", b"e", b"f"], hash_type="sha256")
m2 = mutable_merkle.tree.MerkleTree.new([b"a", b"b", b"c", b"d", b"e", b"f"], hash_type="sha256")
m3 = mutable_merkle.tree.MerkleTree(hash_type="sha256")
m2.remove_leaf(3)
for value in [b"a", b"b", b"c", b"e", b"f"]:
m3.add_leaf(value)
assert m1.root == m2.root
assert m1.root == m3.root
Serialization
Along with update and remove leaf functionality, mutable_merkle
has been designed
around being serializable as well. This supports storage of the merkle tree as well
as transmission of the proofs.
mt = mutable_merkle.tree.MerkleTree.new(
[b"a", b"b", b"c", b"d", b"e", b"f", b"g", b"h", b"i", b"j"],
hash_type=hash_type,
)
payload = mt.marshal()
mt_reload = mutable_merkle.tree.MerkleTree.unmarshal(payload)
assert mt == mt_reload
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
mutable_merkle-0.1.1.tar.gz
(8.0 kB
view hashes)
Built Distribution
Close
Hashes for mutable_merkle-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c31c574d4708a8ff8c86d8688c43bff21034223f90946bf3b8c9b45ac5fb4a3 |
|
MD5 | 30c41d71b766f6429bbf706618c4a6cd |
|
BLAKE2b-256 | 5f8beac3b7345f34ad7326799d85b643b84e7a449456e94373d5fa4c179b459d |