ledger-verify
A tiny, dependency-free hash-chained append-only log, a verifier that names the first broken entry, and a crypto-shredding demo for GDPR-style erasure. Under 200 lines of library code.
It is a teaching/reference implementation of a general pattern, not a production audit system.
$ ledger-verify demo
intact: True
tampered: first broken entry = 2 (entry content does not match its hash)
tail removed, no anchor : verifies -> True (undetected without an anchored head)
tail removed, with anchor: verifies -> False (head differs from the anchored head (tail removed or replaced?))
Install and run
git clone https://github.com/aben-consulting/ledger-verify.git && cd ledger-verify
pip install -e ".[shred]" # [shred] adds `cryptography` for the erasure demo
ledger-verify demo
python examples/audit_demo.py
pytest -q # pip install -e ".[test]" first
Python 3.9+. The core (ledgerverify.chain) has no dependencies.
How it works
Every entry stores hash = SHA-256(prev_hash | seq | canonical_json(payload)). Change, reorder or delete an entry in the middle and every later hash stops matching. verify() reports the first entry that fails and why.
from ledgerverify import Ledger
l = Ledger()
l.append({"event": "finding.created", "id": "F-1"})
anchor = l.head # store this OUTSIDE the log (another system, signed checkpoint…)
l.append({"event": "finding.approved", "id": "F-1"})
print(l.verify(expected_head=l.head).ok) # later: l.verify(expected_head=anchor)
CLI on a JSON Lines file (one entry per line, as written by Ledger.dump_jsonl):
ledger-verify verify ledger.jsonl [--head <hash stored elsewhere>]
Crypto-shredding (ledgerverify.shred)
Seal personal fields with a per-subject AES-256-GCM key and put only the ciphertext in the log. To erase a person, destroy their key: the log is unchanged, still verifies, and the data is unreadable.
Threat model — read this
| Attack | Detected? |
|---|---|
| Edit an entry's content | Yes — names the entry |
| Delete or reorder an entry in the middle | Yes |
| Delete the tail of the log | Only if you pass an externally stored head (expected_head) |
| Rewrite the whole chain consistently | No — anchor the head somewhere the attacker can't write |
| Record a false event in the first place | No — the chain proves immutability, not truth |
Not included: persistence beyond JSONL, concurrency/locking, signatures, external timestamping, key wrapping under a KMS/HSM, key backup, rotation. KeyStore keeps keys in memory. Data derived from the plaintext (indexes, logs, backups) is outside the protection. Whether crypto-shredding satisfies erasure obligations for you is a question for your legal and compliance advisers.
Contributing & security
Issues and pull requests are welcome. If you find a flaw in the threat model above, please open an issue — that is the most useful feedback.
Licence
Apache License 2.0 — see LICENSE. © Áben Consulting Kft., Budapest. https://aben.ch
Metadata
Release files for ledger-verify 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ledger_verify-0.1.0.tar.gz | 11.6 kB | Without provenance | Details for ledger_verify-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ledger_verify-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for ledger_verify-0.1.0-py3-none-any.whl |
Total release size: 22.9 kB
Release files / ledger_verify-0.1.0.tar.gz
| Download URL | ledger_verify-0.1.0.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
803e1c34a4b2c9a62684d76670fa227b9d2e5ad15b5d240cc80188fe05fa5080
|
|
BLAKE2b-256 checksum How to use checksums |
208794e83c5b7334e7aca0aefe5231e4b394380fc8259c35b70142962618e2a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Release files / ledger_verify-0.1.0-py3-none-any.whl
| Download URL | ledger_verify-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
699f9283a65ef0603ddd626caa5479dc3c54069df58be74b21239e39f56825d6
|
|
BLAKE2b-256 checksum How to use checksums |
d5fdfdbff7b20402c105cbd238de0522eec2e6d52c39c487011c2a20b516ad3d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Security for ledger-verify 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.