The Lab · interactive explainer

Ghosts of Departed Proofs

Your authorization check is a line of code sitting next to the dangerous call — and nothing connects them. One missed await, one stale rule, and the hole is silent. This is an interactive tour of gdp-ts, the tiny TypeScript library that makes the dangerous function demand proof — a compile-time token only a trusted checker can mint. No proof, no compile.

The verdict

Stop checking authorization near the call. Make the call impossible without the check. Proofs are ghosts: they do everything at compile time and nothing at runtime — about 0.3 ms of typechecking per call site, zero extra queries, zero dependencies.

01The bug

Walk through the exact failure, one tap at a time. This is the code the library's README opens with — an Express-style handler, paraphrased.

02The trick, in three moves

The fix isn't a bigger check. It's a connection the compiler can see.

Move 1 — Name it

Give the runtime value a compile-time-only name. Two project IDs that are both string at runtime become distinguishable to the compiler — it can now tell which project you mean, not just what kind of value it is.

name(viewer.id, ProjectId(req.params.id), async (user, project) => {
  // inside here, `user` and `project` carry unique compile-time names.
  // project-A and project-B are no longer interchangeable.
});

Move 2 — Prove it

One trusted module does the check and mints the proof — or returns null. Nobody else can mint one. At runtime a proof is a frozen { kind } object: a ghost.

// proofs/user-is-project-admin.ts — the ONLY place that can mint this proof
export async function userIsProjectAdmin(user, project) {
  const role = await db.roleInProjectTeam(user.value, project.value);
  return (role === "owner" || role === "member")
    ? UserIsProjectAdmin.prove(user, project)
    : null;
}

Move 3 — Demand it

The sensitive function takes the proof as a parameter. Call it with the wrong proof, a proof about a different project, or no proof at all — compile error. The data layer never performs the check; it just demands the receipt.

export function disablePasswordProtection(
  project,                          // Named<P, ProjectId>
  _proof: UserIsProjectAdmin<U, P>  // proof about THIS user, THIS project
) { ... }

03Try to break it

Pick a way to call the sensitive function. The simulated compiler rules on each one — this is the whole idea, compressed into a button.


    
    

Simulated verdicts, but the rules are the library's real ones: the type checker rejects wrong/missing proofs; the lint preset rejects forgeries. Real thing: rauchg/gdp-ts (MIT).

04Why they're called ghosts

Flip between the two layers. The proofs are real to the compiler — and gone by the time your code runs.

compile time — proofs exist

project: Named<P, ProjectId> proof: UserIsProjectAdmin<U, P>
disablePasswordProtection(project, proof) ✓ compiles

The proofs evaporated. What shipped is just the values and one tiny wrapper — no extra queries, no dependencies, no runtime checks to forget.

Right now you're looking at what the compiler sees: every value carries its name, every sensitive call carries its proof. The ghosts do all their work here.

05How much proof do you need?

Rigor is a slider, not a switch. The library is built to be adopted one sensitive function at a time — you choose how much gets exhaustively proven.

55% of sensitive call sites carry proofs

06What it doesn't promise

Every sharp tool has an edge. The library is honest about its limits — so is this page.

Proofs are only as honest as the code around them.
  • Forged proofs — nothing in TypeScript stops {} as UserIsProjectAdmin<U,P>. That's what the bundled ESLint/oxlint preset is for: it bans forging and bans minting outside proofs/. The type system is half the system; the linter is the other half.
  • Stale proofs — a proof says the check passed when it ran. If the user's role changes a millisecond later, the proof doesn't know. Keep proof lifetimes short and checks close to use.
  • TypeScript's ceiling — this is the pragmatic version of an idea from Haskell and Rust, languages with stronger guarantees. In TS, discipline + linting get you most of the way, not all of it.