A stream that generates a merkle tree based on the incoming data
Go to file
Luke Murphy 83b2b2bde6
continuous-integration/drone/push Build is passing Details
Remove reference to setup file
2020-07-07 15:53:21 +02:00
merkle_tree_stream Migrate to pyproject config 2020-07-07 15:44:39 +02:00
test Migrate to pyproject config 2020-07-07 15:44:39 +02:00
.drone.yml Follow the rename and reduce boilerplate 2020-05-16 18:31:01 +02:00
.gitignore Initialise the new module boilerplate 2019-07-08 11:40:40 +02:00
CHANGELOG.md Migrate to pyproject config 2020-07-07 15:44:39 +02:00
LICENSE Follow the rename and reduce boilerplate 2020-05-16 18:31:01 +02:00
README.md Migrate to pyproject config 2020-07-07 15:44:39 +02:00
poetry.lock Migrate to pyproject config 2020-07-07 15:44:39 +02:00
pyproject.toml Remove reference to setup file 2020-07-07 15:53:21 +02:00

README.md

merkle-tree-stream

Build Status

A stream that generates a merkle tree based on the incoming data

A hash tree or merkle tree is a tree in which every leaf node is labelled with the hash of a data block and every non-leaf node is labelled with the cryptographic hash of the labels of its child nodes. Merkle trees in Dat are specialized flat trees that contain the content of the archives.

Install

$ pip install merkle-tree-stream

Example

import hashlib

def _leaf(node, roots=None):
    return hashlib.sha256(node.data).digest()

def _parent(first, second):
    sha256 = hashlib.sha256()
    sha256.update(first.data)
    sha256.update(second.data)
    return sha256.digest()

merkle = MerkleTreeGenerator(leaf=leaf, parent=parent)

merkle.write(b"a")
merkle.write(b"b")

assert len(merkle) == 2 + 1