Ankit Sinha

Selected work / 02

GateKeep

Encrypted, expiring notes with passphrase gates, atomic read limits, private file access, and signed webhooks.

TypeScript · Node.js · Express · PostgreSQL · Drizzle · Supabase Storage · Docker · Render

The problem #

Self-destructing notes fail when two viewers grab the last read simultaneously, a bad passphrase guess burns a view, or attached files stay reachable after expiry. GateKeep enforces every gate atomically in PostgreSQL.

Architecture #

Browser (JWT + rotating refresh)
  ▼
Express API ─────── PostgreSQL
  │                 ├─ notes, expiry, analytics
  │                 ├─ refresh_tokens (hashed)
  │                 └─ webhook_deliveries
  │
  ├── AES-256-GCM encrypted note body
  ├── Supabase Storage → signed URLs
  └── resolve: exists → burn → expiry → pass → consume
Note state machine: active, partly read, burned, with an expired terminal state active partly read burned expired READ LAST READ EXPIRY BURNED AND EXPIRED ARE TERMINAL

Each read is an atomic Postgres update; wrong passphrases reject before consume so guessing never burns a read.

Select a scenario above to step through live state transitions.

Key decisions #

Atomic read limits in SQL

Read consumption is a single conditional database update, preventing two concurrent viewers from both claiming the final view.

Passphrase verified before consume

Passphrases stay off the URL and are checked server-side before decryption and read decrement, protecting valid views from brute-force attempts.

Encrypted bodies & private files

Notes are encrypted with AES-256-GCM at rest; uploads stay in a private Supabase bucket and mint short-lived signed URLs only after access checks pass.

Transactional webhooks & token rotation

Events enqueue into a webhook_deliveries outbox (drained with FOR UPDATE SKIP LOCKED, HMAC-signed). Refresh tokens rotate in one transaction and revoke their family on replay.

Numbers #

32unit + integration
tests
AES-256GCM note encryption
5resolve stages to
atomic burn
HMACsigned, retried
webhooks

The read limit lives in the database transaction, never in UI state.