Skip to content

RFC 0029 — encryption at rest for tiers 2–3

Status: adopted · written 2026-10-01 as a draft, decided 2026-10-02, numbered with ADR 0020 and SPEC v0.3 on 2026-10-03 (0029: 0025 to 0028 were taken by the shared page, weather, reflection and story while this was a draft). The questions of §13 are answered there, by the captain; the body reflects the answers. The benchmark of §14 step 1 ran on 2026-10-02 (bench-encryption-2026-10.md); §9 carries its numbers. The reference implementation of §14 step 3 landed with this number; §15 says where the implementation and this text part.

Summary

SPEC §4 promises that tiers 2 and 3 are "encrypted with the owner's key (a later version)" and names the tool: age, X25519, the recipient being the owner's key. SECURITY.md promises a key that never leaves the owner's machine. This draft works out how to keep those two promises without breaking the ones the format already keeps: files are the truth (ADR 0001), the chain is mandatory and verify reads files only (ADR 0006), one canonicalisation (ADR 0014), attachments content-addressed and outside the hash (ADR 0015), a crossing package made of verbatim lines (RFC 0005), one mapping for backfill and live so a re-import appends nothing twice (ADR 0017), and a second implementation that fits in an afternoon.

The one question everything else hangs on is what the hash chain covers once a payload is ciphertext: the plaintext, the ciphertext, or something in between. Three options are laid out with what each breaks; the recommendation is the third, the chain over a salted digest of the plaintext, with the ciphertext beside the chain the way attachment bytes already are. Then key handling, attachments, the SQLite index, performance on a record of millions of lines, migration of a record that exists today, and what logbook-ts has to implement. The questions that were open, and their answers, at the end. Every example is synthetic: the Oslo persona, who does not exist, and the fixture key pair published in conformance/identity.txt.

A word used throughout: a line whose payload is encrypted is sealed; reading it back is opening it. Plain English, as the code's names are.

1. What must keep holding

Whatever the design, these stay true, or the design is wrong:

  1. The files are the record. A folder copied to another disk is the whole record. No key material that the record needs for integrity lives outside it; key material the record needs for reading is the owner's and lives outside it on purpose.
  2. Nothing is rewritten. Logbook.append is the only way a line is written. A sealed line is appended sealed. A change to how lines are stored (adopting encryption, changing recipients) is a migration in the ADR 0014 sense: a temporary folder, a verify, a swap, a line in the chain that says it happened, never an edit in place.
  3. verify reads files, never the index, and prints the head. Whether it may also need a key is the question of §4.
  4. One canonicalisation, RFC 8785, no version switch. The hash rule of SPEC §3 is not changed by this RFC; what goes into the payload slot of the pre-image is.
  5. Attachments are content-addressed by the bytes a line names, and outside the chain.
  6. A crossing package carries lines whose hashes the recipient can recompute, even though it cannot replay the chain.
  7. Backfill and live produce the same line and dedupe on (source, raw_id). raw_id is inside the payload, so sealing it has consequences for the index (§8) and for performance (§9).
  8. No network in any default path. age needs none. An age plugin (a hardware key) is a local process.
  9. Two implementations agree on the conformance fixture, and the fixture is regenerated by a script. A design under which the sample record cannot be regenerated to the same head fails this on its own (§4.2).
  10. The owner is never locked out of the chain. A lost key loses the words of tiers 2–3, never the proof that the record is intact: verify must still say valid on a record whose key is gone.

2. Threat model, and what stays visible

SECURITY.md: the record lives on a machine the owner controls; the adversary is anyone who obtains the files. That is a stolen laptop, a cloud backup, a sync folder, a disk sold second-hand, a copy a tool left behind. It is not an adversary on the running machine while the owner is logged in: that adversary has the key, and no at-rest design helps. It is not the circle either: what a circle member may see is RFC 0005 and ADR 0016, and this RFC only changes how a package is carried (§7).

The envelope stays plain. id, seq, at, end, tz, source, kind, tier, recorded_at, prev, hash are readable without any key, for every line. This is deliberate: placement by month, listing a day, the index, stats, dedupe of tier-1 lines, and verify itself all read the envelope and nothing else, and sealing it would make every one of them need the key. The price is stated plainly so nobody expects more: an adversary with the files learns the shape of the owner's life at tiers 2–3 (a message from whatsapp at 23:14, a health-sample every fifteen minutes, a transaction on the first of the month) and none of the words, names, numbers or amounts. A design that also seals kind and source is in the open questions (§13.2); it is a different trade, not a refinement of this one.

What a hash gives away. SHA-256 is not hiding for a low-entropy input. A content hash computed over the plaintext of {"schema":"health-sample/v1","type":"steps","value":312,…} lets an adversary who holds the envelope (visible) and can enumerate step counts confirm the value: hash each guess, compare. The same holds for a short note ("had lunch"), a yes/no confirmation, a transaction amount. So any option that puts the plaintext under a hash the adversary can see must salt it. This is why §4 is not simply "hash the plaintext, as today".

Old copies. Encryption at rest protects copies made after it is turned on. A backup taken before the migration (§10) holds the plaintext for as long as it exists; the migration says so and cannot do anything about it.

3. The building block: age

age (age-encryption.org/v1) is a small, fixed file format with reference implementations in Go (age), Rust (rage), Python bindings (pyrage, wheels for macOS, Linux and Windows) and TypeScript (age-encryption on npm, pure TypeScript over Web Crypto, by the same author). It has no modes, no negotiation and no versions to choose between, which is the whole reason to use it rather than a library of primitives.

What one age file is, as this RFC relies on it:

  • A header: the line age-encryption.org/v1, one stanza per recipient, a MAC over the header. For an X25519 recipient the stanza is an ephemeral public share and the file key (16 random bytes, fresh for every file) wrapped to that recipient. Then a 16-byte nonce.
  • A body: the plaintext in 64 KiB chunks, each ChaCha20-Poly1305 under a key derived from the file key and the nonce. The last chunk is marked, so truncation is detected. Streaming in both directions; a 100 MB recording is never held whole.
  • Sizes, for the estimates in §9: the header is 168 bytes with one X25519 recipient and 98 bytes more per further recipient; the body adds 16 (nonce) + 16 (tag) bytes per 64 KiB chunk. A 161-byte plaintext sealed to one recipient is 361 bytes, 484 as standard base64; to two recipients, 459 and 612. In practice rage (and so pyrage) adds a random grease stanza to every header, about 100 bytes more; the benchmark (§9) measured 466 and 564 bytes for a 171-byte plaintext.
  • The recipient is the public half, a bech32 string age1…; the identity is the private half, AGE-SECRET-KEY-1…. The pair below is the conformance fixture's, published in conformance/identity.txt on purpose: it opens the sealed sample and nothing else, and is used in every example here (§11):
recipient: age1x5ut7lplvtgkzcnvtjux674z32mu5q72r6ffaxemxtg9g08p7g5qa8ytxl
identity:  AGE-SECRET-KEY-1…  (the whole line is in conformance/identity.txt; not repeated here, so no secret scanner has to be taught that it is public)
  • An identity file may itself be sealed with a passphrase (age's scrypt recipient, age -p). Plugins (age-plugin-yubikey, age-plugin-se) put the private half in hardware; the record sees only another recipient string.

Two properties matter for the chain question. Sealing is randomised: the same plaintext sealed twice is two different byte strings (fresh file key, fresh ephemeral share). Adding a recipient changes the header, and therefore the file. Anything that hashes the ciphertext inherits both.

The binary age file is carried inside a JSON line as standard base64 with padding (RFC 4648 §4), one string, no line breaks. age's ASCII armor is not used: it is a second encoding of the same bytes and the second implementation would have to carry both.

4. The hash chain: three options

Today, SPEC §3:

content = canonical_json({at, end, tz, source, kind, tier, payload})
hash    = sha256( prev + "|" + seq + "|" + sha256(content) + "|" + recorded_at )

The payload slot is the question. Each option below says what goes there for a sealed line, what the stored line looks like, and what it does to: verify without the key and with it; show and every other reader; the second implementation; crossing packages; ADR 0017 re-imports and dedupe; changing recipients; adopting encryption on a record that exists; the conformance fixture.

4.1 Option A — the chain over the plaintext

The pre-image is unchanged: payload in content is the real payload. The stored line replaces payload with payload_enc, the base64 age file of canonical_json(payload). Nothing else is added; the content hash is not stored.

  • verify without the key can check seq, prev links and recorded_at as text, and nothing else: it cannot recompute a single hash past the first sealed line, because the content hash it needs is inside the ciphertext. A backup host, a CI job, a stranger holding the folder cannot say whether the record is intact. This alone breaks promise 10 for a lost key: the record becomes unverifiable, not just unreadable.
  • verify with the key is exactly today's code after one decryption per line.
  • Readers need the key, as under every option.
  • The second implementation must implement age before it can verify anything, so Level 1 conformance (chain only) and Level 2 (encryption) collapse into one; the conformance sample must ship with an identity.
  • Crossing packages ship opened lines and the recipient recomputes the owner's hashes exactly as today. Best of the three here.
  • Re-imports: the same observation sealed twice has the same content hash, so a content-hash dedupe would even be possible; the (source, raw_id) dedupe needs the index or a decryption pass, as under every option.
  • Recipients can be added or rotated by resealing the stored form; no hash changes.
  • Adoption on an existing record changes no hash either: today's lines already hash the plaintext. No migration, no lineage.
  • The fixture regenerates to the same head.
  • The leak of §2: the content hash is confirmable from the visible line hash (prev, seq, recorded_at are visible). Fixing it means a salt in the pre-image, which is a pre-image change for new lines, which gives back most of the migration advantage and all of its simplicity.

Option A is the design that keeps the most and verifies the least. Its defining cost, a record that nobody can verify without the owner's key, is the one this project cannot pay: a chain nobody can check is not a chain.

4.2 Option B — the chain over the ciphertext

The payload slot holds the sealed object itself: {"schema": "encrypted/v1", "age": "<base64>"}. Verify is today's code, byte for byte.

  • verify without the key is complete: every hash recomputes, the chain is as checkable as it is today. With the key it can additionally open each line and report the ones that do not open.
  • The second implementation verifies with no cryptography at all. Level 1 is untouched.
  • Crossing packages break. The line is verbatim ciphertext sealed to the owner; the circle member cannot open it. The exporter must ship an opened payload beside the verbatim line, and the recipient has no way to bind the opened payload to the hashed one: the binding is the age file key, which the libraries do not hand out. Provenance becomes "trust the exporter", which RFC 0005 was written to avoid.
  • Re-imports are fine for dedupe (by raw_id, after opening) and meaningless for the hash: two sealings of one observation are two different hashes, always.
  • Recipients cannot change without a chain rewrite. Adding a recovery key, a new laptop, a hardware key: each is a new header on every sealed line, a new content hash, a new chain from that line on, with a lineage entry (ADR 0014) every time. A record that cannot afford to lose its key cannot afford that either. This is the decisive failure.
  • Adoption rewrites every tier 2–3 line's hash: a migration with lineage.
  • The fixture cannot be regenerated to the same head, because sealing is randomised. make_sample.py would have to check in the ciphertext as a fixture and never regenerate it, and the cross-implementation test could not seal in one implementation and verify in the other against a known head.

Option B is the one that looks like no change and costs the most.

4.3 Option C — the chain over a sealed digest; the ciphertext beside the chain

The stored line keeps a plain payload, which is a reference to the sealed content, and gains one top-level field payload_enc that is outside the hash, as id is:

plain    = canonical_json({"payload": <the real payload>, "salt": <32 hex chars, 16 random bytes>})
digest   = sha256(plain)                                    lowercase hex
payload  = {"schema": "sealed/v1", "of": <inner schema>, "digest": digest}   hashed, as any payload is
payload_enc = base64( age_seal(plain, recipients) )         stored, not hashed

The pre-image definition is untouched. payload.schema is present, so SPEC §3's envelope rule holds without a special case. The salt is inside the sealed bytes and inside the digest, so the digest confirms nothing to anyone who cannot open the line (§2). The sealed bytes are the canonical text, so an opener hashes what it decrypted and compares, with no re-canonicalisation.

  • verify without the key checks the whole chain as today, and additionally that every sealed/v1 line carries a payload_enc that is well-formed (base64 of bytes beginning age-encryption.org/v1\n). It reports the count of sealed lines it did not open and exits 0 when the chain holds. It cannot tell a genuine ciphertext from one an adversary sealed to the owner's public recipient and swapped in; that is the one thing the key adds.
  • verify with the key opens every sealed line and requires sha256(plain) == payload.digest. A mismatch is an error, exit non-zero, exactly as a present attachment whose bytes do not match its name is an error (SPEC §1.1). It then also follows attachment references inside opened payloads (§7).
  • The second implementation verifies the chain with no cryptography (Level 1) and adds age for Level 2 (§11).
  • Crossing packages: the ciphertext is outside the chain, so the exporter may reseal every crossed line to the destination's own recipient, or ship it opened, and in both cases the line's payload, hash and every other hashed field are the owner's, verbatim; the recipient recomputes the digest from what it opened and the line hash from the envelope. RFC 0005's promise is kept, and a package in transit is sealed to its reader (§7).
  • Re-imports: dedupe by (source, raw_id) after opening, through the index (§8). Two sealings of one observation have different salts and different digests, as two recorded_at already give them different line hashes today; identity is raw_id, as ADR 0017 says.
  • Recipients change by resealing payload_enc: a stored-form change, "re-serialising a line changes nothing" (SPEC §2) made literal. Done the migration way (temporary folder, verify, swap) and recorded by one line in the chain (§6.4), but no hash moves and no lineage entry is needed.
  • Adoption on an existing record changes the content hash of every tier 2–3 line, because the real payload leaves the pre-image and the reference enters it. One migration, once, with lineage (§10). An owner may also seal forward only and never rewrite (§10.1).
  • The fixture regenerates to the same head: the salts are data in the sample, the ciphertext is not hashed, and a run with the published identity opens every line.
  • What it does not give: an adversary can replace a sealed line's payload_enc with garbage and a keyless verify says valid. The record is still intact in the sense the chain promises (nothing added, removed or reordered; every hashed field as written) and the owner's next keyed verify, show or day finds the line does not open and says which. This is the same position attachments are in today, chosen for the same reason (ADR 0015): the chain covers what the owner wrote, the bytes that carry it are checked by whoever can read them.

4.4 Side by side

A: plaintext B: ciphertext C: sealed digest
verify without the key links and seq only; no hash complete complete chain; sealed bytes unchecked
verify with the key complete complete + "opens" complete + digest of every opened line
Second implementation, Level 1 needs age no change one new field outside the hash, one payload shape
Crossing package (RFC 0005) opened lines, hashes verbatim ciphertext the member cannot open, or unbound plaintext resealed to the member or opened; hashes verbatim
ADR 0017 re-import dedupe by raw_id; same hash too dedupe by raw_id dedupe by raw_id
Add or rotate a recipient reseal, no hash change chain rewrite, lineage, every time reseal, no hash change, one line says so
Adopt on an existing record no hash change chain rewrite, lineage chain rewrite once, lineage; or seal forward only
Conformance fixture regenerates yes no yes
Guess confirmation (§2) yes, unless salted no no
Lost key words lost and chain unverifiable words lost, chain verifiable words lost, chain verifiable

4.5 Recommendation

Option C. It is the only one that keeps verify keyless and keeps keys out of the chain, and it is the one that treats sealed bytes the way the format already treats attachment bytes, so the spec gains a shape it already has rather than a new idea. Its cost, that a keyless verifier cannot vouch for the sealed bytes, is paid in the same coin as ADR 0015 and reported the same way: a separate count, never a silent pass and never a false failure.

The rest of this draft assumes Option C. Where another option would do differently, it says so.

5. The sealed line

A synthetic example: the Oslo persona's note, written at the command line, sealed to one recipient. The envelope is as today; payload is the reference; payload_enc is the age file, shortened here.

{"id": "0199a1c0-5e2a-7c31-9a0b-3d4e5f607182", "seq": 32,
 "at": "2026-10-01T18:42:00Z", "end": null, "tz": "Europe/Oslo", "source": "manual", "kind": "note", "tier": 2,
 "payload": {"schema": "sealed/v1", "of": "note/v1", "digest": "6f61103210f69c83f179c8adf6d928182bc8e6b6a57327c007baa8aafe253a91"},
 "payload_enc": "YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA…",
 "recorded_at": "2026-10-01T18:42:03Z",
 "prev": "035a74e0027faa6872580c3c7b5f7a0efec92f15bb29cee400a6593814fd345c",
 "hash": "06fdc5af319cdaecc3cfc63d4636407bf4452b590fb399461d3b75def7c0fcad"}

What the owner's identity opens payload_enc to, byte for byte (161 bytes; its SHA-256 is the digest above):

{"payload":{"schema":"note/v1","text":"Dinner with Kari at the marina; Solvind needs a new impeller before Saturday."},"salt":"3b9f0c2e7d1a4f6b8c0d2e4f6a8b0c1d"}

The prev is the v0.5.0 conformance head, so the hash above is what a line with this envelope would carry as line 32 of the sample; both recompute from the text shown.

Rules:

  1. A line is sealed when its tier is 2 or 3 and logbook.json names recipients (§6.1: two at least, or none). A tier-1 line is never sealed. A tier 2–3 line in a record with no recipients is written plain, as today, and verify counts such lines (plain at tier 2–3: n) so the owner sees them.
  2. payload of a sealed line is exactly {"schema": "sealed/v1", "of": "<the inner schema>", "digest": "<64 lowercase hex>"}. No other key. of is the sealed payload's own schema (note/v1) in clear, so stats can count by profile and a reader can decide whether to open a line before it does; it reveals little beyond kind (decided, §13.3). A keyed opener MUST check that the inner schema equals of.
  3. payload_enc is present on a sealed line and absent on a plain one. A sealed/v1 payload without payload_enc, or a payload_enc beside a payload that is not sealed/v1, makes the line invalid to any verifier, with or without the key.
  4. payload_enc is outside the hash, with id. SPEC §2's "unknown fields MUST be preserved by readers" already covers it for a reader that predates this RFC; SPEC §6's "a change to id … is not detected" extends to it.
  5. The sealed bytes are canonical_json({"payload": …, "salt": …}) in UTF-8, nothing else: no trailing newline, no other keys. The salt is 16 bytes from the operating system's random source, as 32 lowercase hex characters, fresh per line. The digest is the SHA-256 of those bytes.
  6. A keyed opener MUST compare the digest before it parses the plaintext, and MUST treat a mismatch as an error of the record, not a warning.
  7. Retraction and supersedes work by id, which is plain, and are not affected. A retraction's own payload (the reason) is tier 2 and is sealed. Readers already have to open a retraction to show its reason; they need nothing but its supersedes to apply it, and that is inside too, so the index carries it (§8).
  8. Derived data inherits the highest tier of its evidence (SPEC §4), so a resolution/v1 or commitment/v1 line over tier-2 evidence is tier 2 and sealed. Engines (ARCHITECTURE layer 3) therefore need the identity to run, as readers do.

6. Key handling

6.1 One identity per record; recipients in the record

The long-term secret is one X25519 identity per record, the owner's. There is no symmetric record key to wrap, store or rotate: age makes a fresh file key for every line and wraps it in the line's own header, so the only key anybody keeps is the identity. (The variant with a record data key is in §9.1, for the case where the measurements demand it.)

logbook.json gains one key, public material only:

{"format": "logbook/0.3", "owner_id": "<uuid>", "created_at": "…", "timezone": "Europe/Oslo",
 "seq": 4182, "head": "<hex>",
 "recipients": ["age1x5ut7lplvtgkzcnvtjux674z32mu5q72r6ffaxemxtg9g08p7g5qa8ytxl"]}

Every sealed line is sealed to every recipient listed at the time it is written. Writers preserve the key as they preserve lineage (SPEC §1). A record with the key absent or empty seals nothing (§5 rule 1).

Why a list and not one string: a record MUST have at least two recipients before it seals anything, the identity on this machine and a recovery identity generated once, printed, and kept on paper somewhere else (logbook key recovery prints it and never stores it). init writes recipients only when the second exists and refuses to seal until then; a record with one recipient is a record with none (decided, §13.10). A hardware recipient (an age plugin) is a third. Losing the laptop then loses nothing; losing every recipient loses the words of tiers 2–3 and nothing else (promise 10).

6.2 Where the identity lives, and where it never does

  • Never in the record. Not under <root>, not in logbook.json, not in a dotfile beside it. The record is the folder that gets copied, synced and backed up; a key inside it travels with every copy and the encryption protects nothing.
  • Never in an environment variable that is on disk. No LOGBOOK_IDENTITY=AGE-SECRET-KEY-… in a shell profile, a .env, a launchd plist, a Docker compose file or a CI secret store that writes to the container's environment. The variable the CLI reads, if any, names a path (LOGBOOK_IDENTITY_FILE), as import-backup already takes a password in a variable set for one command and never a flag. An identity passed as a flag would land in shell history; there is no such flag.
  • Default location: ~/.config/logbook/identities/<owner_id>.txt (%APPDATA%\logbook\identities\ on Windows, via pathlib, never by string), mode 0600, one age identity file as age-keygen writes it. Several records on one machine, several files. logbook init creates it, prints the recipient, writes recipients and says in one sentence that the recovery identity is the next thing to do.
  • Lookup order when a command needs to open: --identity-file PATH; LOGBOOK_IDENTITY_FILE; the default location; a plugin recipient's own mechanism. The first that exists is used; a file that does not open the line (wrong record) is one clear error naming the path, never a traceback.
  • A passphrase on the identity file (age's scrypt recipient) is the owner's choice at init, off by default: full-disk encryption and the recovery recipient cover the copied-file case, and a prompt breaks every unattended read (decided, §13.9). When chosen, it is prompted on the terminal, never read from a flag, a variable or a file.
  • The operating system keychain (macOS Keychain, the Windows credential store, the Secret Service on Linux) is a later option, not required: it is one more place the second implementation would have to read.

6.3 Who needs what

Operation Needs the recipient (public) Needs the identity (secret)
add, sync, append_many: seal new tier 2–3 lines yes yes, to dedupe by raw_id (§8); the CLI refuses without it
add, sync: tier-1 lines no no
verify, keyless no no
verify, keyed yes
show, day, trips, engines, export (opened, the default) yes
export --sealed (lines verbatim, still sealed) no no
export crossing (reseal to a destination) the destination's yes
index rebuild (the raw_id, supersedes, entity, media columns) yes
key add-recipient, key rotate (reseal) the new ones yes

Sealing without the secret is a property of the format worth keeping, and the CLI does not use it: a writer that holds only the recipients cannot dedupe against sealed lines (§8), so sync and add refuse to write tier 2–3 lines without the identity, in one sentence naming what is missing, rather than append what the next keyed run would have to retract (decided, §13.6). Tier-1 sources (ais, a location tracker) need neither key and run unattended as before.

6.4 Changing recipients

Adding a recipient (a new laptop, a hardware key, a recovery identity made late) and rotating the identity (a laptop stolen while unlocked, an identity file found in a backup) are the same operation: reseal every sealed line and every sealed attachment to the new list. It runs the way migrate runs (ADR 0014): into a temporary folder, verified keyed and keyless, then swapped; an interrupted run leaves the record as it was. No hash changes; logbook.json recipients is replaced; and one line is appended so the chain records that it happened:

{"at": "2026-10-01T19:00:00Z", "end": null, "tz": "Europe/Oslo", "source": "logbook", "kind": "rekey", "tier": 1,
 "payload": {"schema": "rekey/v1", "recipients_before": 1, "recipients_after": 2,
  "recipients": ["age1x5ut7lplvtgkzcnvtjux674z32mu5q72r6ffaxemxtg9g08p7g5qa8ytxl", "age1…"],
  "sealed_lines": 4100, "sealed_attachments": 212}}

The recipients are public and go in the line; the removed one is not named, because naming it is pointless once nothing is sealed to it. Rotation does not unlock the past for whoever took the old identity and an old copy of the files; the owner is told that in the command's output, once.

7. Attachments

ADR 0015 left this to "the version that defines the encryption envelope". The store is <root>/attachments/<sha256>, named by the plaintext's digest, write-once, outside the chain, de-duplicated across lines.

Rule: an attachment is sealed when any line that references it is tier 2 or 3, and the file keeps its name. attachments/<sha256 of the plaintext> holds the age file of the plaintext, sealed to the record's recipients. The reference inside the payload ({sha256, path, bytes, media_type}) is unchanged and still names the plaintext: sha256 the plaintext digest, bytes the plaintext length. The reference lives inside a sealed payload, so nobody without the key can read it anyway; the file's own first 22 bytes (age-encryption.org/v1\n) say it is sealed.

Why the plaintext digest and not the ciphertext's: de-duplication is by content, and a ciphertext digest is random per sealing (§3), so two lines attaching the same recording would be two files and the same file attached from two sources would never meet. Why not a suffix or a second directory: SPEC §1.1 says no extension and no subdirectories, and the age header is a better marker than a name.

  • verify, keyless: a file in the store that does not begin with the age header is checked against its name as today; one that does is counted as sealed, not checked and is not an error. A plain file in the store whose digest does not match its name is an error, as today.
  • verify, keyed: opens each sealed line, follows its references, opens the file, streams it through SHA-256, requires the plaintext digest to equal the name. A mismatch is an error; a missing file is reported separately and is not (SPEC §1.1).
  • Tier 1 and tier 2 sharing one file: the photo a tier-1 photo/v1 line names and a tier-2 note/v1 line attaches is the same bytes under the same name. The higher tier wins: the file is sealed. A writer that attaches bytes already present plain from a tier 2–3 line seals the file in place (temporary name, rename), which raises the file's protection and never lowers it; write-once is a rule about content, and the content did not change. The reverse (a tier-1 line attaching bytes present sealed) leaves the file sealed; the tier-1 reader opens it with the identity like anything else.
  • Streaming: age chunks at 64 KiB, so attach_file seals a voice memo of a hundred megabytes in one pass without holding it, and an opener streams it to a player. Overhead is 32 bytes per 64 KiB; nothing to measure.
  • Crossing packages (RFC 0005) ship copies "under the same names". The exporter opens each crossed file and reseals it to the destination's recipient (or ships it plain when the destination has none and the owner said --open); the name is the plaintext digest, so a crossed line's content.path resolves inside the bundle as before, and the consumer checks the file by opening it and hashing, as it must already hash. policy/crossing.json gains the destination's recipient: {"hermes": {"max_tier": 2, "recipient": "age1…"}}. A destination without one receives a package only with --open, typed.
  • The day-package/v1 never carries payloads or files and is unaffected.

8. The SQLite index

index.sqlite is a disposable locator (ADR 0007): seq, id, at, day_local, kind, source, tier, raw_id, file, offset, supersedes, entity, media. Nine of those columns are the envelope and are plain whatever this RFC does. Four come from the payload and, for a sealed line, exist only after opening: raw_id (dedupe, ADR 0017), supersedes (readers apply corrections and retractions), entity (resolution counts), media (attachment counts). raw_id is the one that talks: a WhatsApp raw_id is <chat jid>:<stanza id> and the jid is a phone number; a mail raw_id is a Message-ID naming a domain. An index with that column in clear undoes a good part of the sealing for anyone who copies the folder.

Three ways, as asked:

  1. An encrypted index. SQLite has no encryption of its own; SQLCipher and SEE are different builds, and Python's sqlite3 and Node's modules cannot open their files without being rebuilt against them, on three operating systems. Decrypting an index to a temporary file on open is a multi-gigabyte plaintext in /tmp on a record of millions of lines, which is the thing being prevented. Rejected.
  2. Rebuilt, never persisted. Build the index in memory per process, from the files, opening every sealed line each time. show on a three-million-line record would open a million lines before printing a day: minutes per command. The reason the index exists is that this does not happen. Rejected as the default; as --no-index for a one-off on a machine the owner does not trust with a cache it is fine, and already nearly what verify does.
  3. Plain, with a warning. Keep the index as it is, say in the README and in logbook index that it is a plaintext locator, and tell the owner not to copy it. Honest, cheap, and the warning will be ignored by the first sync client.

Recommendation: 3, hardened in two ways, so the warning has little to protect.

  • Blind raw_id. For a sealed line the index stores HMAC-SHA256(k, raw_id) as hex, not the raw_id, with k a 32-byte index key generated when the index is first built and stored in the index's own meta table sealed to the record's recipients. The index is self-contained and disposable as before; an adversary with the folder has HMACs under a key they cannot open, and a phone number cannot be confirmed by guessing. Dedupe compares HMACs: deterministic, so (source, raw_id) lookups are unchanged in cost. supersedes, entity and media are ids this record minted and digests already visible as file names; they stay plain. Tier-1 lines keep raw_id plain; nothing about them is sealed.
  • Move the index out of the record root. <root>/index.sqlite is listed in SPEC §1 as optional and disposable. Put it in the user's cache directory instead (~/.cache/logbook/<owner_id>/index.sqlite; the platform equivalent on macOS and Windows, via pathlib), so a copy of the record folder, by any tool, never carries the locator at all. The Docker image keeps its index inside the container, where it is rebuilt on first use, as now. verify never opens it (unchanged), and a record whose cache is gone is a record whose index is rebuilt (unchanged).

Building and rebuilding the index on a record with sealed lines needs the identity, for the four payload columns. Without it, the index is built with those columns NULL for sealed lines and meta says so (opened: false); readers that only list a day work, writers of tier 2–3 lines refuse (§6.3), and the next command run with the identity fills the columns in place of a rebuild. Both hardenings, the blinded raw_id and the move to the cache directory, are adopted (decided, §13.8).

9. Performance on a record of millions of lines

The project's floors today: append_many at 20,000 lines a second or better; verify and dedupe in flat memory on three million lines; show of a day in under a second after indexing. Sealing touches the first and adds a per-line public-key operation that today's code does not have. The draft estimated the cost; the benchmark bench-encryption-2026-10.md (scripts/bench_seal.py, 2026-10-02) measured it, on a 3,000,000-line record of the stress tests' shape with 2,000,000 sealed lines (1,000,000 health-sized at tier 3, 1,000,000 message-sized at tier 2), Option C exactly as §4.3 and §5 say it, pyrage 1.4.0, one machine: a 4-vCPU cloud container with a slow core (7,300 lines a second on the stress suite's own append_many test, against the 20,000 floor), so the ratios carry over and the absolute times are a ceiling. The three CI runners have the same workflow under workflow_dispatch and had not been run when this was written.

Per sealed line age, 1 recipient age, 2 recipients plain, for comparison
Seal (the age call alone) 88 µs 167 µs —
Seal step in the writer (canonical JSON, salt, SHA-256, age, base64) 128 µs · 7,800 lines/s 214 µs · 4,700 lines/s —
Open (decode, decrypt, digest, parse) 145 µs · 6,900 lines/s 194 µs · 5,100 lines/s —
Stored line, health-sized (payload ≈ 110 B) 1,127 B (2.20×) 1,258 B (2.45×) 513 B
Stored line, message-sized (payload ≈ 600 B) 1,786 B (1.77×) 1,917 B (1.90×) 1,010 B
Whole record, 3,000,000 lines age, 1 recipient age, 2 recipients plain
Write, end to end 589 s · peak 110 MB 785 s · peak 115 MB 339 s · peak 81 MB
Keyless verify 154 s · 27 MB 160 s · 27 MB 175 s · 27 MB
Keyed verify 460 s · 27 MB 583 s · 27 MB —
Index rebuild with opening 382 s · 35 MB 481 s · 35 MB 69 s · 33 MB (plain rebuild)
Month files on disk 3.37 GB (+1.39) 3.63 GB (+1.65) 1.98 GB

The size of the plaintext does not matter at these lengths; the cost is the key agreement, and in pyrage opening costs more than sealing. What it means for the floors:

  • Who is sealed. Tier-1 lines (location points, the bulk of most records) cost nothing: 460 bytes, unchanged. Tier-3 health-sample/v1 lines are the problem case: steps every quarter hour, heart rate by the minute, sleep stages; a few years of Apple Health is one to five million tier-3 lines. Messages and mail are hundreds of thousands. The benchmark's shape is a realistic one.
  • The 20,000 lines a second floor is tier-1-only (decided, §13.1). It is 50 µs a line, and the age call alone is 88 µs to one recipient and 167 to two, so no core holds it for sealed lines. Sealed lines get a floor of their own: 4,000 lines a second at two recipients, which this slow core meets at 4,683 and a laptop core should beat two or three times over (an estimate, not measured). A backfill of 1,000,000 health samples therefore seals in 2 to 4 minutes over the 2 it takes to write, once.
  • Keyed verify of the whole record: 7.7 minutes at one recipient, 9.7 at two, against 2.6–2.9 keyless, once a night, in 27 MB. The draft allowed three to seven minutes; two recipients is at the edge of that and accepted. Keyless verify is unchanged or a little faster, because a sealed/v1 reference canonicalises in fewer bytes than a message.
  • Index rebuild pays the same opening pass once (6.4 or 8 minutes against 1.2 plain); thereafter incremental on append, as now.
  • show, day: a day of a few thousand sealed lines opens in a few tenths of a second; the under-a-second floor holds. A day of 5,000 or more sealed lines (heart rate by the minute plus steps by the quarter hour) is at the edge; if real health records show such days, §9.1's middle road for health-sample/v1 alone is the thing to measure next.
  • Dedupe of a 100,000-draft re-import against three million lines through the blinded index: 100,000 HMACs (microseconds each) and the same SQLite lookups as today. Unchanged in shape.
  • Size on disk. 1.39 GB more at one recipient for the 2,000,000 sealed lines, 1.65 GB at two. Per further recipient, 131 base64 characters a line, 261 MB over two million lines, 85 µs more to seal and 50 to open. Two recipients is the default (§6.1); five is a decision.
  • Memory: unchanged, 27–41 MB in every reading phase against 27–33 plain. Nothing holds more than one line per month file, or one 64 KiB attachment chunk, at a time.

9.1 The variant: a record data key

Not adopted; measured and recorded so the reason is on file. The variant is one 32-byte record data key, generated at init, sealed by age to the recipients and stored at <root>/keys/record.age, with each line sealed by ChaCha20-Poly1305 under it with a fresh nonce instead of by age. The benchmark ran it beside age: 40 µs a line to seal (3 of them the cipher, the rest the Option C wrapper every variant pays), 10 µs to open, keyed verify of the record in 3 minutes, 0.68 GB more on disk. A real gain, one-time for a backfill and nightly for verify, bought with everything the draft listed: a long-term key in the record (wrapped, but there, and "never in the record" was a line this RFC drew); a line that the age CLI alone cannot open, so the format gains a construction of its own where it had a file format everyone can check; a writer that needs the identity to seal (it must unwrap the record key), losing the seal-without-the-secret property of §6.3; and rotation of the record key being a reseal of every line, where age's per-line file keys make rotation a reseal of headers only. None of that is worth four minutes on a backfill (decided, §13.1). The middle road, the record key for health-sample/v1 alone and age for everything else, stays unmeasured and unadopted; it is the next measurement only if real records show days of 5,000 or more sealed lines.

10. Migration of an existing record

Every record today is logbook/0.2 with tiers 2–3 in plain, hashed over the plaintext. Two paths, the owner's choice at logbook key init (the command that creates the identity and writes recipients into an existing record). The maintainer's own record takes the second, after the benchmark (decided, §13.1 and the closing note of §13).

10.1 Seal forward

Add the recipients, seal every tier 2–3 line from now on, leave the past as it is. No rewrite, no hash changes, no lineage. verify reports plain at tier 2–3: n so the number is always in view, and the owner may take the second path any later day. A record is allowed to be mixed indefinitely; readers open what is sealed and read what is not.

10.2 Seal the past

logbook seal --all: the ADR 0014 road. Into a temporary folder: every tier 2–3 line gets a fresh salt, its payload becomes the sealed reference and the age file, prev and hash are recomputed in seq order from the first sealed line; every attachment such a line references is sealed in place under its name; format becomes logbook/0.3; lineage gains {from_format: "logbook/0.2", from_head, migrated_at}; the index is rebuilt (into the cache directory, §8); keyed and keyless verify both pass; the folder is swapped in. Then one line is appended:

{"at": "2026-10-01T20:00:00Z", "end": null, "tz": "Europe/Oslo", "source": "manual", "kind": "migration", "tier": 1,
 "payload": {"schema": "migration/v1", "from_format": "logbook/0.2",
  "from_head": "035a74e0027faa6872580c3c7b5f7a0efec92f15bb29cee400a6593814fd345c",
  "sealed_lines": 4100, "sealed_attachments": 212}}

Two things differ from ADR 0014's migration. The old files are not kept beside the record. Keeping a plaintext copy next to the sealed one would defeat the point; the command replaces the folder and prints, once, that any backup taken before this moment still holds the plaintext, and that it does not and cannot shred anything. The old head stays reproducible, but only with the identity: open every sealed line, put its payload back in the pre-image, recompute under the same rule, and the from_head falls out. That is enough for lineage to mean what it means.

Time: one read of the record plus one sealing per tier 2–3 line (§9): a few minutes for a record of a million such lines. An interrupted run leaves the record as it was, by construction.

10.3 What the format name says

ADR 0014 made format name the hash rule, and the rule does not change here. What changes is the envelope (one new top-level field) and the pre-image's content for sealed lines, and SPEC §4 said "a later version will define the encryption envelope". This draft bumps to logbook/0.3 because §2 changes shape, and because a 0.2 implementation that meets a sealed line will preserve payload_enc as an unknown field and verify the chain correctly but cannot open anything, so the record should say it needs another version of the code. A 0.3 implementation reads and verifies a 0.2 record without migration (decided, §13.4): the hash rule is the same, so ADR 0014's reason for refusal does not apply, and forcing every owner through §10 before reading would be wrong. The code carries two format names for the first time; it still carries one canonicalisation. Writing to a 0.2 record seals nothing, since it has no recipients, and key init is what moves it to 0.3.

11. What logbook-ts must implement

The second implementation reproduces the conformance head and agrees with the Python CLI on verify and append across a record the other wrote. This RFC splits conformance into two levels, as SPEC §6 anticipated, and the split is the point: Level 1 stays an afternoon.

Level 1 (the chain), changes:

  1. payload_enc at the top level is outside the hash, as id is. Preserve it; never hash it.
  2. A payload {"schema": "sealed/v1", "of": <schema>, "digest": <hex>} is a payload like any other; payload.schema is present. Validity rule 3 of §5: sealed/v1 without payload_enc, or payload_enc without sealed/v1, is invalid.
  3. verify checks that each payload_enc is standard base64 whose decoded bytes start with age-encryption.org/v1\n, and prints a count of sealed lines it did not open. Exit 0 when the chain holds.
  4. logbook.json: preserve recipients (already required by SPEC §1's preserve-unknown-keys rule). Accept format logbook/0.2 and logbook/0.3 both (§10.3).
  5. Attachments: a file in the store beginning with the age header is counted as sealed, not checked.

Level 2 (encryption):

  1. age X25519 seal and open, through age-encryption (npm) or an equivalent; binary age files, standard base64 with padding, no armor.
  2. The sealed bytes: canonical_json({"payload": …, "salt": …}) under the RFC 8785 implementation it already has; a 16-byte salt from crypto.getRandomValues; SHA-256 of the bytes as digest; compare before parse.
  3. append seals a tier 2–3 line when recipients is non-empty, to every recipient; writes plain otherwise. export emits opened payloads by default (the ADR 0017 interchange form) and the lines verbatim, still sealed, under a flag.
  4. Keyed verify: open every sealed line, compare digests, follow attachment references, stream each sealed file through SHA-256 against its name.
  5. Identity discovery in the same order and from the same places as §6.2 (--identity-file, LOGBOOK_IDENTITY_FILE, the default path), so one identity file serves both implementations on one machine.
  6. Attachments: seal and open streaming; the higher-tier-wins rule of §7.
  7. Resealing (key add-recipient) is optional for Level 2; it is a stored-form rewrite and either implementation's command works on a record the other wrote.
  8. An index, if it has one, blinds raw_id as §8 says, or does not persist that column; this is a recommendation for interoperability of a cache, not conformance.

Fixture. conformance/sample-logbook grows a sealed sibling, conformance/sample-logbook-sealed, made by make_sample.py from the same lines with the published fixture identity of §3 (conformance/identity.txt) and a second recipient (conformance/recovery-recipient.txt), and salts from a seeded generator, so its expected-sealed.json head is reproducible by anyone. The cross-impl CI job gains two steps: Python seals an appended note and TypeScript opens and verifies it keyed; TypeScript seals, Python opens. Level 2 conformance is: keyless verify prints the head; keyed verify with the published identity prints the head and reports zero digest mismatches; changing any byte of a payload_enc makes keyed verify fail and keyless verify not.

12. Spec changes this draft asks for

None of these happen in this PR. They land together in one PR after the benchmark, as CLAUDE.md requires of any envelope change: a spec version bump, the regenerated fixtures, an ADR. The order of everything is in §14.

  • §1 logbook.json: recipients; format logbook/0.3; index.sqlite moves out of the folder listing or is marked "or in the cache directory".
  • §1.1: a sealed file keeps its name and begins with the age header; keyless verify counts it; keyed verify checks it.
  • §2: payload_enc, present on a sealed line, outside the hash; the sealed/v1 payload shape; the validity rule tying the two.
  • §3: the pre-image unchanged; what a keyless and a keyed verifier each check and report; a digest mismatch is an error.
  • §3.1: logbook/0.3 row; a 0.3 implementation reads 0.2; the two migration paths; migration/v1 gains the two counts.
  • §4: the table's "a later version" becomes this; the sentence "payload_enc replacing payload" is replaced by what §5 says, since payload stays and holds the reference.
  • §6: Level 2 conformance, the sealed fixture, the published identity.
  • init: two recipients or none; export --sealed; sync and add refuse tier 2–3 without the identity.
  • A rekey/v1 profile RFC (§6.4) and a one-paragraph sealed/v1 entry in rfcs/README.md.
  • ADR 0020, the decision of §4.5, superseding nothing and extending ADR 0015.
  • policy/crossing.json: a destination's recipient (ADR 0016's file, one key more).

13. The questions that were open, and the answers

Asked 2026-10-01; answered by the captain 2026-10-02. The question stands as asked, the answer follows it.

  1. The budget, and the record data key. What does per-line age actually cost in pyrage on the three-million-line stress record, sealing and opening, on the three CI platforms? Does the 20,000 lines a second floor become tier-1-only, or is §9.1's record data key adopted for the hot path? Nothing below is worth deciding until this is measured.

Decided: measure first; bench/encryption ran on 2026-10-02 and its numbers are in §9 and in bench-encryption-2026-10.md. Per-line age stays. The record data key is not adopted: a key inside the record and a construction the age CLI cannot open are both costs not worth paying, and the numbers did not force it (it saves four minutes on a backfill of a million lines). The 20,000 lines a second floor becomes a tier-1 floor; sealed lines get a floor of 4,000 a second at two recipients. 2. Sealing the envelope. Should a tier-3 line be allowed to seal kind and source too (a kind of sealed with the real kind inside), accepting that such a line is on no reader's day and in no stats without the key? This RFC says no for v0.3; the owner who needs it has a different threat model than §2 and the design should be its own RFC.

Decided: no for 0.3. A separate RFC, if ever. 3. The inner schema in clear. Should the sealed/v1 reference carry "of": "note/v1"? It helps stats and a reader deciding whether to open, and it reveals little beyond kind; it also makes the reference a place where things accumulate.

Decided: yes. The reference carries of (§5 rule 2). 4. 0.3 and 0.2. Must a 0.3 implementation refuse a 0.2 record, as 0.2 refuses 0.1? The hash rule is the same, so ADR 0014's reason does not apply; refusing would force every owner through §10 before reading, which seems wrong; not refusing means two formats in the code for the first time.

Decided: yes, 0.3 reads 0.2 records without migration. Two formats in the code is the lesser cost (§10.3). 5. The salt. 16 bytes is enough against guessing and keeps the sealed bytes short; 32 would match every other digest-sized field in the format. Is there a reason beyond tidiness to go to 32?

Decided: 16 bytes. 6. A writer with only the recipient. A sync on a machine without the identity can seal but cannot dedupe against sealed lines (§8). Does it append and leave duplicates for the next keyed run to retract, refuse to run, or does the blinded index key live in a second place the writer can read? The last leaks HMACs under a guessable key to anyone with the folder, which is to say it does not work.

Decided: it refuses to sync tiers 2–3 (§6.3). Tier-1 writers (ais) need nothing. 7. notes/ and inbox/. notes/<YYYY>/<date>.md is free text at tier 2 by nature and outside the chain; inbox/ holds raw exports, the most sensitive bytes in the folder. Both are outside this RFC. Should the inbox at least be sealed on arrival, or documented as "delete after import"?

Decided: inbox/ gets a logbook inbox clean after a verified import, and "delete after import" in the docs; that is independent of this RFC and has since landed (#164). notes/ stays outside for now. 8. The index out of the root. Moving index.sqlite to the cache directory changes a line of SPEC §1 and the Docker layout; is the sync-folder argument strong enough, or is the blinded raw_id with the file left in place enough?

Decided: both. The index moves to the cache directory and raw_id is blinded (§8). 9. A passphrase on the identity by default? It protects against a copied identity file and costs a prompt on every read; an unattended reader (a nightly day page) then needs an agent or the keychain, which §6.2 deferred.

Decided: not by default. Full-disk encryption and the recovery key cover the copied-file case; a prompt breaks unattended reads (§6.2). 10. The recovery ceremony. init prints the recipient and suggests a recovery identity; should it refuse to seal until a second recipient exists, or is one recipient and a warning the right default for the first day?

**Decided:** `init` refuses to seal until a second recipient exists. Mandatory, not a warning (§6.1).
  1. Export for re-entry (ADR 0017). logbook export of sealed lines emits opened payloads, so the interchange JSON stays "a line minus the chain fields" and can be re-added. Should it also be able to emit sealed lines verbatim, for a copy of the record that stays sealed?

    Decided: both. Opened for re-entry is the default; sealed verbatim under a flag (§6.3, §11). 12. The sealed fixture's identity. A published identity makes the fixture reproducible and obviously synthetic; is there any objection to a published private key in conformance/, given it unlocks only a fixture?

    Decided: fine.

Migration of the existing record: seal the past (§10.2), after the benchmark, with the warning about older copies printed once.

14. Sequence

  1. The benchmark (bench/encryption, bench-encryption-2026-10.md): per-line age on the stress record, sealing and opening. Done on one machine, 2026-10-02; the three CI runners can be dispatched from the Actions tab for confirmation, and nothing in §9 waits on them.
  2. ADR 0020 and the spec changes of §12 in one PR: version bump, regenerated fixtures, the sealed fixture with the published identity.
  3. The implementation in the reference CLI: key init, sealing on append, keyed and keyless verify, the index changes, seal --all, export --sealed. (inbox clean has landed on its own, #164.)
  4. logbook-ts Level 2.

Not before the readers have settled.

15. Where the implementation parts from this text

The reference implementation landed with this number (v0.6, logbook/core/sealing.py and the changes around it). Where it decided something this text left open, or chose differently, the implementation is the rule and this section says so:

  • The search table (logbook search, which landed after the draft) holds no words of a sealed line: the index is a plaintext locator in the cache directory, and a full-text table of tier 2–3 words would undo the sealing for anyone who copied it. A sealed record is searched by its plain lines only, until a design for a sealed search table exists.
  • An attachment whose line's tier the writer does not know is sealed. Adapters hand bytes to the store before they yield the draft that points at them, so Logbook.attach seals whenever the record names recipients unless the caller says tier=1; the photo adapters do not say so yet, so a sealing record seals its photos too. §7's "higher tier wins" is kept; the default sits on the safe side.
  • A sealed line shipped opened in a crossing package carries payload_open, the {payload, salt} pre-image, in place of payload_enc; the manifest's sealing says resealed (with the recipient) or opened. RFC 0005 gains that section.
  • rekey/v1 is defined by this RFC (§6.4) rather than an RFC of its own, and carries recipients_before, recipients_after, recipients, sealed_lines and sealed_attachments.
  • The index's blinding key lives in the index's own meta, sealed to the recipients; an index built without the identity records opened: false and the first keyed reader rebuilds it. The index records the recipients it was built for, so a reseal rebuilds it.
  • A 0.1 record migrates to 0.3 directly: the same rule, one hop.
  • The identity file holds one identity, in age's own format, with the recipient in a comment; LOGBOOK_IDENTITY_FILE names a path; --identity-file sets that variable for the one process.
  • verify --keyless exists so a keyed machine can show what a keyless one sees.
  • The shared page (RFC 0025, shared-page/v1) carries a day's lines verbatim, as a crossing package did before §7: a sealed line in a shared page is ciphertext the receiver cannot open. Resealing to the receiver's key, or refusing to share a day with sealed lines, is the follow-up; until then share day at tier 1 is unaffected, since tier 1 is never sealed.