TypeScript · 2026
Matrix Workers
A Matrix homeserver running entirely on Cloudflare Workers — Hono, D1, R2 and Durable Objects — taken from a proof of concept that failed the Matrix Federation Tester to verified two-way federation with matrix.org: invites, joins, messages, E2EE key exchange and media, across room versions 1–12. Live at codebam.ca.

The problem
Meet the Matrix server-to-server specification well enough that the network’s largest homeserver accepts this one as a peer — signed events, room-version-specific redaction rules, E2EE key exchange — on a runtime with no TCP sockets and no persistent process.
Architecture
- Hono routes the client and federation APIs inside one Cloudflare Worker; D1 is the event store, R2 holds media, and Durable Objects own per-room ordering and long-poll /sync.
- Every event is signed and reference-hashed under its own room version’s redaction rules, then sent in the federation v4 wire format — no event ID on the wire, the receiver derives it.
- Peers that only listen on port 8448 — the runtime’s fetch() ignores non-standard ports — are reached by an HTTP/1.1 client hand-rolled over cloudflare:sockets with TLS.
Highlights
- Verified two-way federation with matrix.org: invites, joins, messages, E2EE key exchange and media, across room versions 1–12
- Passes the Matrix Federation Tester, and the inherited 45,000-test vitest suite stayed green through every change
- Security work: removed a login flow that issued access tokens without credentials, closed an unauthenticated federation v2 join path, and moved registration behind single-use hashed invite tokens
- Stock Element clients get working E2EE against it — OIDC discovery metadata, recovery-key rotation and cross-server device keys included
- Live at codebam.ca, answering for @codebam:codebam.ca
Technology
TypeScript · cloudflare · matrix · federation
Need something like this?
Let’s scope it.
Custom websites and Telegram bots, scoped per project and quoted by email.