Skip to main content

License: MIT Pylint: 10 Tests: Passing DOI

BlockDAG

BlockDAGs for structured signature generation.

A Merkle-Tree is a binary tree of hash nodes. This module implements an extension of this data-structure which differs in that:

  • Data can be included at any node in the structure
  • The structure between nodes can form a directed acyclic graph

Note, this is, in principle, a superset of a MerkleTree.

One creates a BlockDAG by providing a dictionary of vertices (id : dict()) and list of edges (id: id tuples).

For example (available in examples/EX0.py). Consider the following Graph:

Once processed, the following HashDAG is generated.

Changing the values of a single vertex, or edges the graph signature will be completely different. Moreover, the hashes of all descendent vertices will be completely different too.

The main method build_block_dag requires:

  • A dictionary of vertices, each with a unqiue key, and dictionary of fields as values
  • A list of tuples, describing the edges in the graph.
  • A hash function (returns the hex-digest of the provided data. Hashlib provides many)
  • A list of keys used to inclusively filter the data contained in each vertex. The values selected are placed in a MerkleTree, the root of which is used as the datahash for that vertex
  • A boolean, append_hashes which if True, will add the hash and graph signature to the original vertex dictionary.

bulid_block_dag returns a dictionary with the datahash, parenthashes and blockhash for each vertex in the original graph, along with a whole-graph signature.

The whole-graph signature is computed by collecting the hashes of all leaf nodes (no outgoing edges) then inserting them into a MerkleTree, and taking the root.

Usage

Install it:

pip install blockdag

or clone it.

There are several examples in examples to get started. You can compare blockdags to find differing vertices (by signature, not label) and print dags nicely.

Requirements / Assumptions

  • Vertex keys are assumed to be unique
  • The fields 'hash' and 'signature' will be overwritten if append_hashes is set to True
  • While it will not cause any issues, cycles will be ignored in the original graph.

Contributions

Feel free to help out, submit issues and make merge requests.

Metadata

Release files for BlockDAG 1.1.3

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

Source distribution (sdist)

Source distribution for BlockDAG 1.1.3
File Size Uploaded
blockdag-1.1.3.tar.gz 7.4 kB Details

Built distribution (wheel)

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

Total release size: 14.0 kB

Release files / blockdag-1.1.3.tar.gz

Download URL blockdag-1.1.3.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c72c0fd495536eaa6d2684a8545e11f31e1e61bc44fb190e67388e61cb27e496
BLAKE2b-256 checksum
How to use checksums
445f968aac7002d4ac21f226e1b10cfa2b476f39ed381974bbd6f08e25024482
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / BlockDAG-1.1.3-py3-none-any.whl

Download URL BlockDAG-1.1.3-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43c2b90b3617ceeda8032f1f46f9840abe769fd3beaa094dd312cc736724af29
BLAKE2b-256 checksum
How to use checksums
5756b6290fbe3cf386651f019b6d8bf111dd3d3a58e0b0c433546d94adac0fa6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release history Release notifications | RSS feed

This release

1.1.3 This release

2 release files

1.1.2

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

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