Skip to main content

BlockDAGs for structured signature generation.

Project description

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.

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

blockdag-1.1.3.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

BlockDAG-1.1.3-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file blockdag-1.1.3.tar.gz.

File metadata

  • Download URL: blockdag-1.1.3.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for blockdag-1.1.3.tar.gz
Algorithm Hash digest
SHA256 c72c0fd495536eaa6d2684a8545e11f31e1e61bc44fb190e67388e61cb27e496
MD5 1b591edc0ec8b7cfa03dadab8c6e63cb
BLAKE2b-256 445f968aac7002d4ac21f226e1b10cfa2b476f39ed381974bbd6f08e25024482

See more details on using hashes here.

File details

Details for the file BlockDAG-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: BlockDAG-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for BlockDAG-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 43c2b90b3617ceeda8032f1f46f9840abe769fd3beaa094dd312cc736724af29
MD5 afb6b17c3fe4ea9a7f47e383f56cfd1a
BLAKE2b-256 5756b6290fbe3cf386651f019b6d8bf111dd3d3a58e0b0c433546d94adac0fa6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page