India's Digital Personal Data Protection Act (DPDP, 2023) says a company must be able to show that a person consented before it processed their data. Most consent tools answer that with a database row: visitor 7f3a, analytics = granted, 09:14. The trouble is who can edit that row. Anyone with admin access to the database, including the company being audited, can change it later, and nothing in the row would show it.
I'm the primary developer of PrivacySuraksha, a DPDP compliance platform that is live in production. One of the problems I had to solve was this one: how do you prove a consent record is genuine without asking the auditor to trust our database?
The answer we shipped is a ledger nobody can quietly edit. Every consent event is hashed. Every day, all of that day's hashes are sealed into one SHA-256 Merkle root. The root is signed with Ed25519 and timestamped on Bitcoin with OpenTimestamps. An auditor can then verify any single record without trusting us.
Here is how the pieces fit, and why each one is there.
1. Hash every event
A consent event is a small, canonical string: record id, a pseudonymous visitor id, the purpose, the decision and a timestamp.
cs_0142 visitor 1c9e marketing=denied 2026-11-30T09:20Z
Its SHA-256 hash becomes a leaf of the day's tree. In the browser or on Cloudflare Workers, WebCrypto does this in a few lines:
const enc = new TextEncoder();
async function sha256(data: Uint8Array): Promise<Uint8Array> {
return new Uint8Array(await crypto.subtle.digest("SHA-256", data));
}
// a 0x00 prefix for leaves and 0x01 for inner nodes (as in RFC 6962), so a leaf can never pass as a node
const leaf = (record: string) => sha256(new Uint8Array([0, ...enc.encode(record)]));
const node = (l: Uint8Array, r: Uint8Array) => sha256(new Uint8Array([1, ...l, ...r]));
Change one character of the record and the hash changes completely. That property is what everything else builds on.
2. Seal a day into one Merkle root
Storing thousands of hashes does not help an auditor much on its own. A Merkle tree turns them into a single 32-byte value: hash leaves in pairs, then hash those results in pairs, until one hash is left.
async function merkleRoot(leaves: Uint8Array[]): Promise<Uint8Array> {
let level = leaves;
while (level.length > 1) {
const next: Uint8Array[] = [];
for (let i = 0; i < level.length; i += 2) {
const right = level[i + 1] ?? level[i]; // odd count: pair the last node with itself
next.push(await node(level[i], right));
}
level = next;
}
return level[0];
}
If any record from that day is edited, added or removed, the root changes. So instead of protecting every row, we only have to protect one value per day.
3. Sign the root
A root on its own proves the data has not changed since the root was computed. It does not say who computed it. Signing the daily root with an Ed25519 key ties it to us: an auditor can check the signature with our public key, and a forged root will not verify.
4. Anchor it on Bitcoin
A signature still leaves one gap: we hold the key, so in theory we could rebuild a day's tree with an edited record, sign the new root and backdate it. Timestamping closes that gap. We submit the signed root to OpenTimestamps, which commits it into a Bitcoin transaction. Once that transaction is in a block, anyone can show the root existed at that time, and no one, including us, can change it afterwards without the mismatch showing.
5. Verify one record without the rest
An auditor who wants to check one consent does not need the whole day's data. They need the record, the sibling hashes on its path to the root (an inclusion proof, about log2(n) hashes), and the signed, anchored root.
type Step = { hash: Uint8Array; left: boolean };
async function verify(record: string, proof: Step[], root: Uint8Array) {
let h = await leaf(record);
for (const s of proof) {
h = s.left ? await node(s.hash, h) : await node(h, s.hash);
}
return h.every((b, i) => b === root[i]);
}
If the recomputed root matches the signed, Bitcoin-anchored root, the record is exactly what was there on that day. If one letter changed, it will not match. That is the whole point: the check does not depend on trusting our database, our servers or us.
What I would tell someone building this
- Keep personal data out of the leaves. Use pseudonymous ids. The ledger proves what happened; it should not become another copy of the personal data you are trying to protect.
- Prefix leaves and nodes differently. Without the 0x00 / 0x01 prefixes, an attacker can present an inner node as if it were a leaf. It is a one-byte fix.
- Make the record format canonical. If two services serialise the same event differently, their hashes differ and proofs fail. Pick one exact format and test it.
- Batch, then anchor. One root per day keeps signing and anchoring cheap no matter how many events there are.
- Show the failure. On my portfolio, the hero is a live Merkle tree: change one letter of a consent record and you can watch the proof fail. It explains the idea faster than any diagram.
You can try that demo at sparshprajapati.com.
I'm Sparsh Prajapati, a full-stack engineer at Cloudzent in Gurugram, India. I build product interfaces and the systems underneath them. More of my work: sparshprajapati.com · LinkedIn · GitHub
Top comments (0)