
duchat
An invite-only web messenger with end-to-end encryption, messages that vanish after 12 hours and push notifications like a native app.
duchat is a closed 1:1 messenger: only the admin creates accounts, sending an invite with a temporary password that must be changed on first login. Messages and photos are encrypted on the device before leaving it, delivered in real time with "typing…" and presence (online, away, busy, invisible), and erased everywhere after 12 hours. Photos are resized and stripped of EXIF/location on the device, then encrypted. Contacts are added by exact username or a short ID (no partial search, so users can't be listed), and can be blocked. It installs as an app (PWA) on desktop, Android and iPhone, with push notifications even when closed — the push carries the message still encrypted and the device's service worker decrypts the preview. The admin panel creates, edits, resets, disables and deletes users with an audit log, and cannot read anyone's messages. Built to run at zero hosting cost. The screenshots use fictitious contacts and show no conversations.
Real end-to-end encryption in a web app, where the server delivers both the code and the public keys — with forward secrecy, several devices per person, push notifications that don't leak content, and all of it on free tiers.
Each device generates non-extractable keys with the browser's native WebCrypto (Ed25519 identity, X25519 pre-key rotated every 24h). Each message is padded, encrypted with AES-256-GCM under a random key, and that key is wrapped per device with ephemeral X25519 + HKDF-SHA256, then signed with Ed25519. Supabase stores only ciphertext behind RLS on every table, delivers it via Realtime on private channels, and pg_cron enforces the 12-hour expiry.
A working messenger in production, installable on any device, where even a full database leak reveals no content — only metadata. Covered by crypto tests (round-trip, tampering, wrong signature, rotation) and RLS tests on a disposable Postgres.
Keys per device
WebCrypto generates an Ed25519 identity key (signs messages and pre-keys) and an X25519 signed pre-key, rotated every 24h with the old private key deleted a day later — forward secrecy with a ~48h window. Keys are non-extractable and kept in IndexedDB; on Safari, which can't store Ed25519/X25519 keys natively, the private key is sealed with a non-extractable AES-256-GCM key of the device. Up to 5 devices per person.
Sending a message
The JSON body is padded to 256-byte blocks and encrypted with AES-256-GCM under a random content key, with the message id, sender, device and recipient as authenticated data. For each target device an ephemeral X25519 key + HKDF-SHA256 wraps the content key; the header and ciphertext hash are signed with Ed25519, and everything is written in one transaction by a SQL function. The recipient verifies, unwraps and decrypts in memory only.
Server that can't read
Supabase Postgres with RLS on every table and deny by default; inserts only through send_message, which checks contact and block status. Realtime Authorization keeps chat and presence channels private to the two participants. Photos go to a private bucket already encrypted, fetched by short-lived signed URLs. The service_role key lives only inside Edge Functions.
12-hour retention
expires_at is set by the database, not the client. The read policy already hides expired rows, pg_cron deletes them every 10 minutes (keys cascade), and an hourly job removes expired photos from Storage.
Push without leaking content
A database trigger calls a Deno Edge Function that sends Web Push with VAPID keys. The payload carries the sender's name and the message still end-to-end encrypted for that device, inside a push that is itself encrypted for the browser (RFC 8291) — the push service sees nothing. The service worker decrypts the preview on the device and opens the right chat on tap.
Hardening
Static SPA (no SSR) so a strict CSP is easy: default-src 'self', no third-party scripts, no unsafe-inline, frame-ancestors 'none', plus HSTS, no-referrer and a tight Permissions-Policy. Messages render only as text, and photos are re-encoded on the device (max 1600 px, no EXIF or location) before being encrypted. Admin actions go through an Edge Function that rechecks role and writes an audit log.





