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

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.
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.
- Actors and actions come from fixed lists. Eight actors and five actions (
tambah,ubah,arsip,putuskan,ganti). Anything else is refused. - Secrets are refused at the door. Text that matches the patterns of private keys, tokens or private IP addresses is never written.
- Concurrent writers are locked. Before appending, a writer creates a lock folder (an atomic operation). Without it, two writers could read the same tail and write two rows with the same sequence number. A lock stuck for over 30 seconds is cleared, and a writer gives up after waiting 15 seconds.
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.