Notes · · Method

A hash-chained ledger: a work log nobody can edit quietly

A hash-chained ledger: a work log nobody can edit quietly
Illustration made with AI.

When several AI agents and a human write to one work log, one question always comes up: who changed what, and how do we know nobody tampered with it? My answer is simple: an append-only ledger with a hash chain.

Three chained blocks, each storing the hash of the previous one. The second block is marked red because its content was edited, so its hash no longer matches and the chain is rejected.
Diagram drawn in code for this note.

The problem

An ordinary log can be edited without a trace. In a project worked on by many agents that is dangerous: a "done" report can change, a decision can vanish, and nobody notices. I wanted one file that gives itself away when it is altered.

How it works

Every row holds a sequence number, a timestamp, the actor, the action, the entity, the text, the evidence, and hash_prev, the hash of the previous row. A row’s hash is the SHA-256 of its canonical form: keys sorted and no whitespace, so a verifier written in another language gets the same digest. The first row points at 64 zeros.

hash(n) = SHA-256( row(n) without hash, including hash(n-1) )

Verification walks the file from the top. Three things fail it: a sequence jump (a row is missing), a hash_prev mismatch (the chain is broken), or a hash that does not match the content (the content was edited). Each has its own test.

What it does not guarantee

The chain is tamper-evident, not tamper-proof. Someone who rewrites the entire chain from row one still produces a valid chain. That is why the head hash should be copied somewhere else, and that is not automatic here yet.

The lesson

Integrity does not need a database or a blockchain. About a hundred lines of dependency-free JavaScript are enough to make quiet edits expensive.

Source: packages/ledger/ledger.mjs, test.mjs and test-konkuren.mjs in the private MiganExp repository (not yet public), 16 Oct 2026. Line counts and time limits are read from those files; readers cannot check them yet.

NextMeet Migan in the room