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.2.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.2-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: blockdag-1.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 94c116f064da933f796b088cd9442b40107c0b4e35a96669b49620f4070fb3ac
MD5 c07061ba3438f598f4b34893c25d32a5
BLAKE2b-256 95efe8075265ee6702fec9362701625b09390fa33ee718a6260d80e40f4a8319

See more details on using hashes here.

File details

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

File metadata

  • Download URL: BlockDAG-1.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1981fcc736453ef100707d529159f70d4bd5df966edd3d9ff43b77c04ad3b1bc
MD5 13f93a76bb79acb5937f667e79db8da1
BLAKE2b-256 92d6db97fe58dd586ba54b2117576646d9c3a458f8a139105c78ad17f17a6d0f

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