MLS protocol (E2EE)
Developers · MLS protocol (E2EE)MLS protocol (E2EE)
Normative reference for a client implementing Extrovert's end-to-end encryption.
The cipher is RFC 9420 (MLS) with ciphersuite
MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519.
Transport and auth
Base path: /api/v1/mls (the legacy /mls alias remains).
The same Bearer credential model as the REST API applies: OAuth access tokens,
personal access tokens (ext_pat_…), and bot tokens. A browser session cookie
also works. Reads require read:direct; mutations require write:direct.
KeyPackage lookups are additionally limited to 30/minute per user+IP.
Group ids
Group ids are server-authored and authorization-critical:
| Kind | Format | Example |
|---|---|---|
| Direct message | dm:<lowerUserId>_<higherUserId> |
dm:1_2 |
| Room | room:<roomId> |
room:7 |
Never invent another format: the server rejects it with 400 Invalid group id.
Discover groups with GET /api/v1/mls/groups:
{ "ok": true, "groups": [
{ "group_id": "dm:1_2", "kind": "dm", "epoch": 3,
"member_count": 2, "room_id": null, "peer_id": "2" }
] }
GET /api/v1/mls/groups/:groupId/members lists user, device, leaf index and
role for members.
Devices
POST /api/v1/mls/device/register
{ "device_id": "dev_ab12cd34", "device_name": "Desktop",
"signing_key_pub": "<base64url Ed25519 public key>" }
- Maximum 10 active devices per account. Over the cap returns
429 QUOTA_EXCEEDED; new clients should list devices and revoke one deliberately rather than silently evicting the oldest. device_idis globally unique and cannot change owner.- New clients must send a real Ed25519 public key. The server stores it and
returns it in
/devicesand group member listings. It cannot cryptographically attest the key; peers must verify the credential identityuser:<userId>:dev:<deviceId>themselves. - Legacy
ed25519_<deviceId>placeholder values are still accepted so the bundled web client keeps working. Do not emulate them.
KeyPackages
Publish:
POST /api/v1/mls/keypackages
{ "device_id": "dev_ab12cd34",
"keypackages": [ { "data": "<base64 MLSMessage>", "ciphersuite": 1,
"keypackage_ref": "<64 hex>" } ] }
The server verifies the MLSMessage framing (00 01 00 05) and recomputes the
KeyPackageRef (RFC 9420 §5.2, varint-prefixed label hash). A mismatch returns
400 KeyPackageRefMismatch with expected and received.
Keep at least 10 packages per device. GET /keypackages/status?device_id=…
reports the pool.
Claiming
GET /api/v1/mls/keypackages/:userId peeks by default: it returns one
candidate package per device with row ids and consumes nothing. Claim what you
actually used with:
POST /api/v1/mls/keypackages/consume
{ "keypackage_ids": [12, 13] }
?claim=1 (or ?consume=1) keeps the legacy one-step behaviour and consumes
one package per device. ?exclude_device= skips a device (typically your own).
Access is limited to self, mutual followers, and shared-room members.
Welcomes
GET /api/v1/mls/welcomes?device_id=… returns unacknowledged rows. A Welcome
blob is identical for every recipient device; match your KeyPackageRef inside
welcome.secrets before calling joinGroup.
Exactly-once processing:
POST /api/v1/mls/welcomes/claim { welcome_id, device_id }leases it to one device for 5 minutes. A second device gets409 WelcomeClaimedwithretry_after_ms.- Process the Welcome with the private KeyPackage you stored locally.
POST /api/v1/mls/welcomes/ack { welcome_id, device_id }deletes it.- Keep a local tombstone for the KeyPackageRef and delete the consumed private KeyPackage. The server re-serves unacked Welcomes indefinitely by design.
Commits and epochs
POST /api/v1/mls/groups/:groupId/commit is compare-and-swap on the epoch:
{ "current_epoch": 3, "commit_message": "<base64 MLSMessage>",
"idempotency_key": "<stable uuid>",
"welcomes": [ { "user_id": 2, "device_id": "dev_x", "welcome_data": "…" } ],
"members_added": [ { "user_id": 2, "device_id": "dev_x", "role": "member" } ],
"members_removed": [], "proposals_consumed": [] }
- Stale epoch →
409 EpochConflictwithexpected_epochandserver_epoch. FetchGET /groups/:groupId/commits?since=<your epoch>and retry. - Recipients in
welcomes/members_addedmust be reachable (self, mutual follower, shared room), otherwise403. - Supply a stable
idempotency_key. The server deduplicates within 24 h; retrying a timed-out commit must not double-apply it. - The server enforces authorization, epoch CAS, and recipient sanity. It does not cryptographically verify the commit's parent hash or tree hash — it does not hold group secrets. Clients must validate commits locally.
POST /groups/init creates a group; reset_existing: true with
expected_epoch performs a CAS reset for stale DM groups.
Epoch notifications
After a successful init or commit, members receive a gateway event:
{ "seq": 42, "type": "gateway_event", "topic": "mls",
"event": "mls_epoch", "data": { "group_id": "room:7", "epoch": 4 } }
Subscribe to mls (automatic with ?auto_subscribe=1). On receipt, call the
commits endpoint and advance local state instead of waiting for a decrypt
failure.
Backup
GET /api/v1/mls/backup returns { ok, backup } and an ETag when a backup
exists. Send If-None-Match: <etag> for 304.
POST /api/v1/mls/backup stores { backup_data, salt }. The blob format is
client-defined; the server treats it as opaque. Optimistic concurrency is
optional:
- Send
If-Match: <etag>to refuse clobbering a newer backup written by another device; mismatch returns412 PreconditionFailedwithcurrent_etag. ?force=1bypasses the check.- The response returns the new
etag.
A self-describing envelope is recommended (and what the bundled web client
uses): { v, bk_id, wrappedBk, payload }, where bk_id identifies the backup
key and payload contains per-device group state and a message cache. Keep the
KDF parameters inside the envelope so rotation does not need a protocol change.
Local state
Persist one record per group:
{ v: 1, group_id, epoch, ciphersuite, engine, data }
data is the engine's opaque group state (encodeGroupState in ts-mls,
mls-rs export in Rust). Rules:
- Never delete state because a decode failed; quarantine it and re-join with a Welcome. Deleting state loses history permanently.
- Re-inject engine defaults after decoding; both ts-mls and some Rust builds drop configuration objects on a round-trip.
- A backup restores history decryption only. Sending again requires a fresh Welcome from a peer.
Attachments
Encrypted attachments are not part of MLS itself. Seal the file with
AES-256-GCM, upload it with POST /drive/upload?sealed=1, and put the file key
inside the MLS application message. The URL is a capability; without the key the
bytes are opaque.
Message limits
| Surface | Max plaintext payload |
|---|---|
Room channel message (proto: "mls") |
20,000 chars of ciphertext |
Direct message (proto: "mls") |
65,536 chars of ciphertext |
Base64 MLS messages are padded; large inline attachments will exceed the room cap, which is why files go through Drive.
Client implementations
| Language | Location | Notes |
|---|---|---|
| JavaScript / browser | packages/mls-core (loaded by public/mls-client.js) |
The reference implementation; IndexedDB-backed encrypted state and password backups. |
| Rust | packages/client-rust with --features e2ee |
mls-rs-based MlsClient: device, KeyPackages, groups, DMs, rooms. Group state is in memory; a restart needs a fresh Welcome. |
The Rust engine uses ciphersuite MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519
and the same group-id grammar, so the two interoperate. The repository's
scripts/interop-mls-rs harness certifies the engine layer against ts-mls.
History
Room history is filtered by the caller's joined_at: a device cannot backfill
messages from before it joined. DMs have no such gate, but only ciphertext
available to your device can be decrypted.