Skip to main content

helixhash

A tamper-evident append-only log. Proves a sequence of bytestrings existed in this order at these times and has not been altered.

Institution role (Node 34539544): integrity protocol library used by geniusflow-engine Granth / helix chain. Sister: witnessfield. Full map: sangat-architecture/INSTITUTION_REPOSITORY_MAP.md.

v1.0 is a clean rewrite. In v0.x, scoring and priors were baked into the protocol, which created circular dependencies between the two libraries (HelixHash was a high-trust witness class inside witnessfield, and witnessfield-style credibility values leaked into HelixHash entries). v1.0 separates the protocol (what the library guarantees) from policy (opinions about how to weight things). HelixHash now only guarantees order and non-tampering. witnessfield now only describes witness structure. Scoring is a separate, swappable policy layer.

Install

pip install helixhash

# Optional: Ed25519 signing support
pip install helixhash cryptography

What it guarantees

HelixHash proves a sequence of bytestrings existed in this order at these times and has not been altered. It makes no claim about whether the bytestrings are true, meaningful, or correct. Evaluating the content is the job of a witness layer — see witnessfield.

Quickstart

from helixhash import HelixHash

h = HelixHash()
h.append(b"first event")
h.append(b"second event")
h.append(b"third event")

print(h.length)   # 3
print(h.head)     # SHA-256 of the last entry (64-char hex)
print(h.verify()) # True — chain is intact

Hash formula

Each entry's hash commits to: its index, its payload, its timestamp, its signer's public key (if signed), and the previous entry's hash.

SHA-256(
    index            (8 bytes, big-endian)
  | payload_length   (8 bytes, big-endian)
  | payload          (variable)
  | timestamp        (8 bytes, big-endian double)
  | pubkey_length    (2 bytes, big-endian; 0 if unsigned)
  | signer_pubkey    (0 or 32 bytes)
  | prev_hash        (64 ASCII bytes)
)

signer_pubkey is in the hash so that swapping an entry's public key breaks the chain immediately. verify() catches it.

Tamper detection

verify() replays the full chain in O(n). It catches:

  • Any change to a payload
  • Any change to a timestamp
  • Any change to a signer pubkey
  • Any reordering of entries
  • Any inserted or deleted entry
# Mutate a payload — verify() returns False
h._entries[1] = Entry(
    index=1, payload=b"tampered", timestamp=h._entries[1].timestamp,
    prev_hash=h._entries[1].prev_hash, hash=h._entries[1].hash,
    signature=None, signer_pubkey=None,
)
print(h.verify())  # False

Optional signing

Pass an Ed25519PrivateKey from the cryptography library to sign entries. The signature covers the entry hash. The signer's public key is stored in the entry and included in the hash.

from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey

key = Ed25519PrivateKey.generate()

h = HelixHash()
h.append(b"signed payload", signer=key)
print(h.verify())  # True — signature checks out

# Forge the signer key: replace pubkey in export
exported = h.export()
from base64 import b64encode
other_key = Ed25519PrivateKey.generate()
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
exported[0]["signer_pubkey"] = b64encode(
    other_key.public_key().public_bytes(Encoding.Raw, PublicFormat.Raw)
).decode()
h2 = HelixHash.from_export(exported)
print(h2.verify())  # False — pubkey swap breaks the hash

Export and import

import json

# Export to JSON-serialisable list
data = h.export()
json_str = json.dumps(data)

# Reconstruct from export
h2 = HelixHash.from_export(json.loads(json_str))
print(h2.head == h.head)   # True
print(h2.verify())         # True

from_export validates structural integrity (index order, timestamp monotonicity, prev_hash chain) before loading. Call verify() to additionally confirm hash integrity.

API reference

class HelixHash:
    def append(self, payload: bytes, signer=None) -> Entry
    def verify(self) -> bool
    def export(self) -> list[dict]

    @classmethod
    def from_export(cls, entries: list[dict]) -> "HelixHash"

    @property
    def head(self) -> str     # tip hash, or GENESIS_HASH if empty
    @property
    def length(self) -> int

@dataclass(frozen=True)
class Entry:
    index:         int
    payload:       bytes
    timestamp:     float          # unix seconds, monotonically increasing
    prev_hash:     str
    hash:          str
    signature:     Optional[bytes]
    signer_pubkey: Optional[bytes]

GENESIS_HASH: str = "0" * 64    # sentinel for first entry's prev_hash

Tests

pytest tests/test_helixhash.py -v

Honest limitations

  • time.time() is used for timestamps. If two appends happen within 1 microsecond, the second timestamp is bumped to previous + 1µs. Sub-microsecond ordering is not guaranteed.
  • Signing requires the cryptography package. Without it, signer=None works but signed entries cannot be verified.
  • from_export does not recompute hashes on load; call verify() to do the full integrity check.

License

MIT — Kirandeep Kaur, 2026

Release files for helixhash 1.0.0

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

Source distribution (sdist)

Source distribution for helixhash 1.0.0
File Size Uploaded
helixhash-1.0.0.tar.gz 12.4 kB Details

Built distribution (wheel)

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

Total release size: 20.9 kB

Release files / helixhash-1.0.0.tar.gz

Download URL helixhash-1.0.0.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f5c79891626d75caa4907fd209a72c5a2a19bbc7ecc9ad3392c0ef56adee1ca6
BLAKE2b-256 checksum
How to use checksums
32d752ffb324d5653df1112ae5ebe1d2318f2ff2f3b69db760437bb2bbcdce28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / helixhash-1.0.0-py3-none-any.whl

Download URL helixhash-1.0.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5675413f1cdade47ea69ae9a11cc60e9ec583529543b908c68e77bc941e888ba
BLAKE2b-256 checksum
How to use checksums
562d550577ce57f3ee6a13cf4ab4a87403eb9c955d4574ae44b324e48cc02027
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

1.0.1

2 release files

This release

1.0.0 This release

2 release files

0.1.1

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