# Data in the ledger

> Generated from the SDK's own source (`packages/durable-core/README.md`) at build; edit there.

The ledger is immutable by design, which makes it the wrong place for
anything a person may later have the right to erase. The rule, and what
enforces it:

- **Images carry ids and versions, never subject data.** A ledger row says
  `StockReservation 8f3a:SKU-1 { qty: 2, version: 4 }` or
  `Appointment a91 { status: "confirmed" }`; the patient's name, the
  customer's address, the card's last four live in your tables, which you
  can delete. A step's `read` returns the row it compares; the engine
  stores that row as the before image, so **`read` must project**, not
  `select *`.
- **No `Pii<T>` marker** (ADR-0046 §O's amendment, 2026-10-01: not
  taken). What stands is the projection rule above, held by review, and
  the redaction policy below, which drops a host's named keys at every
  depth and a value by its shape (an email address under any key, for one)
  before anything is stored.
- **The redaction policy is yours**: `withPolicy(DEFAULT_POLICY, …)` adds
  your secret key names (`secretKeys`), the names the suffix rule must
  leave alone (`keepKeys`), keys dropped at every depth
  (`omitEverywhere`), your credential shapes by value (`isSecretValue`) and
  your client's shape (`isClient`) on top of the default: the key names any
  host has (`password`, `token`, `secret`, `apiKey`, `authorization`,
  `cookie`, `pin`, …), any key ending in a secret suffix (`secret`,
  `token`, `password`, `passwd`, `passphrase`, `apiKey`, `privateKey`,
  `secretKey`, `signingKey`, `accessKey`, `credential(s)`: so
  `webhookSecret`, `STRIPE_SECRET_KEY`, `secretAccessKey` and
  `GITHUB_TOKEN` are secrets with no list naming them) unless `keepKeys`
  names it (the core keeps the pagination cursors `nextToken`,
  `pageToken` and `continuationToken`), a credential inside a URL's query
  or userinfo (`?token=…` and `postgres://u:p@host` store with the
  credential blanked in place, the rest byte for byte), an HTTP
  `Bearer`/`Basic` credential by value, and the engine's own client slots
  (`client`, `admin`) dropped at every depth. A redacted step output
  cannot be replayed from its row (a `read` step re-invokes every
  attempt; a non-read step is refused), so an identifier that ends in a
  secret suffix is kept by name, never stored redacted. The core knows no
  vendor's token and no client shape; the host does:

  ```ts fragment
  redaction: withPolicy(DEFAULT_POLICY, {
    secretKeys: ["deviceToken", "insuranceMemberId"],
    keepKeys: ["qrToken"],
    omitEverywhere: ["patient", "dob"],
    isSecretValue: (_key, v) => typeof v === "string" && /^shpat_/.test(v),
    isClient: (v) =>
      typeof (v as { graphql?: unknown })?.graphql === "function",
  });
  ```

  Redaction by key name is a safety net, not the design; a field that
  should never be stored should be marked or projected out.

- **Erasure.** A subject's data is erased by deleting it from your tables;
  the ledger keeps the ids and the fact that a write happened. A host that
  must put subject data into an image (a regulated audit that needs the
  value itself) brings its own encryption: per-subject envelope
  encryption with a key the host can destroy (crypto-shredding), the image
  storing ciphertext and the key id, and `verify` hashing the ciphertext
  as it hashes any image. — `ADR-0046` §O records the design (a
  `RedactionPolicy.envelope(subjectId)` hook) and its amendment of
  2026-10-01 says it is not built: no marker and no hook exist in the
  packages or the app; what stands is the projection rule and the
  redaction policy above.
- **What `scrub` can and cannot do.** `scrub` (ADR-0041 wave 1) is an
  operator workflow that rewrites the **outputs and logs of
  runs** after a token leaked into them. It cannot touch a ledger image and
  never will; that is the point of the chain. Since ADR-0076 FP-039 every
  image walks the redaction policy before the hash, as every other stored
  copy does, so a key the policy names never reaches a row in clear (the
  hash over the stored form, a row written before verifying as it was);
  what the policy admits and still reached the ledger is the envelope
  key's remedy, not an edit. Its one step is
  irreversible by declaration (FW-016): the plaintext the rewrite removed
  is gone, so nothing restores it and a failure after the step lands
  FAILED, never COMPENSATED.
- **Peers receive payloads.** A published fact's payload lands in every
  peer you published it to, redacted by the receiver's policy on landing,
  visible in that peer's console with its origin, retained 7 days after
  dispatch. Publish by name per peer and
  keep subject data out of payloads the same way you keep it out of images.

HIPAA and SOC 2 are answered under this section, not by "compliance is the
host's": the controls the engine implements (redaction at every write, an
immutable ledger with verification, an actor on every run, no credential
crossing apps, a person in the loop for every failed run, no subject data in
the ledger) are listed with their evidence on
[the compliance page](https://durablesdk.com/docs/operate/compliance.md). What the library
does not give you: a BAA, access control on your console, encryption at
rest; those are the host's and the platform's.

---

Prompt for an agent:

```text
Read https://durablesdk.com/docs/concepts/ledger-and-data.md, then apply what it says to this app; run durable-sdk doctor --host before and after; a refused line is a refusal id: durable-sdk explain <id>
```
