Skip to main content

Perkle: A simple Python 3 implementation of Merkle Trees

Perkle provides a simple, all python, implementation of Merkle Trees.

Installation

The package can be installed via pip:

pip install perkle

or by cloning this repository.

The package pycryptodome is in the requirements. Make sure that this will not conflict with an installation of the (deprecated) package pycrypto.

Example

Here is how to create a Merkle Tree of numbers from 0 to 9:

from Crypto.Hash import SHA256
from perkle import MerkleTree
from binascii import hexlify
data_list = [b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9']
sha256 = lambda x : SHA256.new(x).digest() 
mt = MerkleTree(data_list, sha256, random_padding=False, padding_byte=b'0')
print(hexlify(mt.root()))
#70cc27c03c0444d1dfc63f58e373a2882a7b9f4f7f6ed1a4dfc1a94a5ac5875c

By default, we add a random padding to the data to have a power of two leaves. You can make the padding non-random with the random_padding parameter to make the results consistent.

New data can be inserted in the Merkle Tree:

data = b'10'
mt.insert(data)
print(hexlify(mt.root()))
#3e32b51c76de4b124f1fedfbb4d5a30d117274bf04b538ca7f10434e2f8a35b9

And existing data can be updated:

new_data = b'zero'
mt.update(0,new_data)
print(hexlify(mt.root()))
#d485ca0c92d339d2e8495216cdb420f0e215003fffdb62d09da56d8739c94a11

Proofs can be easily generated:

index, proof_hashes = mt.proof(b'7')

and verified:

print(MerkleTree.verify(b'7',index,proof_hashes,mt.root(),sha256))
#True

Metadata

Release files for perkle 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for perkle 0.0.5
File Size Uploaded
perkle-0.0.5.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for perkle 0.0.5
File Interpreter ABI Platform
perkle-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 11.7 kB

Release files / perkle-0.0.5.tar.gz

Download URL perkle-0.0.5.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
72ab02b13ec786e0a42ca257d773a403b7ce363c6374ebd14bb679997ad3dad9
BLAKE2b-256 checksum
How to use checksums
3d9cbec9e9b4f04b4dffc04943abd653e30e191df2742775464c3887da7a2b4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

Release files / perkle-0.0.5-py3-none-any.whl

Download URL perkle-0.0.5-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f971e7b51100acb60f34cafcf5f69ca0f68c601a1bbee92c31356d4035f8936c
BLAKE2b-256 checksum
How to use checksums
21bcda977aceb9fc5a7e4e8293b36cf74a5860882d6af9f72db4fc68ab96955f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page