Skip to content

jjyr/mmr.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MMR.py

Merkle Mountain Range

Install

pip3 install -U git+https://github.com/jjyr/mmr.py.git

Example

from mmr import MMR

def test_mmr():
    def serialize(i):
        return i.to_bytes(4, 'little')

    mmr = MMR()
    # push 0..11 into MMR, and record MMR positions
    positions = [mmr.add(serialize(i)) for i in range(0, 11)]
    merkle_root = mmr.get_root()
    # proof
    elem = 5
    pos = positions[elem]
    # generate proof for 5
    proof = mmr.gen_proof(pos)
    # verify proof
    result = proof.verify(root=merkle_root, pos=pos,
                          elem=serialize(elem))
    assert(result)
    print("Ok")

test_mmr()

See tests to learn more.

License

MIT

Releases

No releases published

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy