Building a client
Developers · Building a clientBuilding a client
This is the shortest path from zero to a working Extrovert client. It assumes
the server is reachable at EXTROVERT_URL (for example http://localhost:3000).
1. Pick an authentication path
| Situation | Use | Why |
|---|---|---|
| Native desktop/mobile app | Device pairing → personal access token (ext_pat_…) |
No webview, no redirect URI, no PKCE plumbing. |
| CLI, script, bot | Personal access token | Same credential, created once. |
| First-party web app | Password login + TOTP | Tokens are issued by POST /api/v1/auth/login. |
| Third-party web app acting for a user | OAuth 2.0 authorization code + PKCE | Consent screen, revocable per app. |
All four produce a Bearer credential accepted by every surface, including the
E2EE routes under /api/v1/mls and the /ws gateway. That is the important
part: there is one credential model, not an OAuth-only one.
Pair a device
POST /api/v1/auth/pair/init (Bearer: any token) -> { data: { code, pairing_url, expires_in } }
POST /api/v1/auth/pair/claim (no auth) -> { token, data: { token, scopes, user } }
The claim returns a permanent personal access token. Show the code as text and a QR code; the new device exchanges it and stores the token. Codes are single-use and expire after 5 minutes.
Check what you are
GET /api/v1/auth/me -> { data: { user, credential: { kind, scopes, expires_at, token_id } } }
kind is session, oauth, pat, or bot. Use it to decide whether a
feature is available before calling it.
2. Bootstrap
GET /api/v1/client/bootstrap?include=user,rooms,timeline,notifications,conversations,mls
One call returns the account, unread counts, initial_seq, rooms, the first
timeline page, the first notification page, conversations, MLS devices /
KeyPackage status / welcomes / groups, ICE servers, and server limits.
include is optional; omitting it returns every section.
GET /api/v1/instance is public and tells you limits, feature flags, the
gateway URL, the gateway protocol version and the E2EE engine. Read it instead
of hardcoding values.
3. Realtime
Connect to /ws (see Realtime):
helloarrives immediately withprotocol_version,ring_size,latest_seq.?auto_subscribe=1subscribes you to timeline, notifications, presence, MLS epoch signals, and every room you belong to.- Track
seqongateway_eventframes. On reconnect, send{ "action": "resume", "seq": <last_seq>, "auto_subscribe": true }. - The
resumedframe reportsreplayed,last_seq,oldest_seqandtruncated. Iftruncatedis true the 500-event ring wrapped: bootstrap again instead of assuming a contiguous replay.
For notifications only, GET /api/v1/notifications/stream is SSE with
id: on every event and Last-Event-ID replay.
4. SDKs in this repository
| Language | Location | Install |
|---|---|---|
| TypeScript / JavaScript | packages/client-ts |
npm install file:…/packages/client-ts |
| Rust | packages/client-rust |
extrovert-client = { path = "…/packages/client-rust" } |
| Types only | packages/protocol |
Generated TS + Rust from the OpenAPI document |
Both clients cover pairing, login, bootstrap, typed errors, paginated iteration, the reconnecting gateway, and SSE replay. They are committed source, not published registries, so they work on a fully self-hosted setup.
Minimal runnable examples:
examples/client-ts-min and examples/client-rust-min.
5. E2EE (MLS)
Group ids are server-authored; never invent them:
- DM:
dm:<lowerUserId>_<higherUserId> - Room:
room:<roomId>
GET /api/v1/mls/groups lists the groups you belong to and
GET /api/v1/mls/groups/:groupId/members lists members and devices.
The critical flow:
- Register a device with a real Ed25519 public key
(
POST /api/v1/mls/device/register). - Publish KeyPackages and keep the pool above 10.
GET /api/v1/mls/keypackages/:userIdpeeks by default and returns row ids without consuming. Claim what you actually used withPOST /api/v1/mls/keypackages/consume.?claim=1keeps the legacy one-step consume.- Process a Welcome once.
POST /api/v1/mls/welcomes/claimleases it to one device for 5 minutes, andPOST /api/v1/mls/welcomes/ackdeletes it. - Submit commits with the epoch you based them on. A stale epoch returns
409 EpochConflictwithserver_epoch; callGET /api/v1/mls/groups/:groupId/commits?since=<epoch>and retry. - Subscribe to the
mlstopic (automatic withauto_subscribe=1) and react tomls_epochinstead of discovering drift through a failed decrypt.
Backups are a client-defined wrapped envelope; store it with
POST /api/v1/mls/backup and keep the ETag it returns.
Detailed endpoint tables: endpoints.md.
6. Local sandbox
Without Docker:
npm install
EXTV_API_PASSWORD_LOGIN=on npm start
npm run seed:client # deterministic alice / bob / charlie + PATs + a room
scripts/seed-client-test.js prints the base URL and tokens to paste into your
client. Use a scratch database for anything destructive:
EXTV_DB_PATH=/tmp/extrovert-client.db EXTV_SESSION_DB_PATH=/tmp/extrovert-sessions.db npm start
With Docker:
docker compose -f docker-compose.client-dev.yml up --build
That profile seeds the same fixtures on first start and exposes port 3000.
7. Check your instance
npm run conformance is a black-box contract check. Point it at any deployment:
node scripts/conformance.js --url=http://localhost:3000 --token=ext_pat_…
node scripts/conformance.js --url=… --token=… --write # also tests idempotent creates
It verifies the instance version, credential introspection, bootstrap shape,
pagination envelope, problem-document shape, gateway hello + auto-subscribe,
SSE connect, MLS group discovery, and (with --write) idempotency replay.
Exit code is non-zero on any failure, so it can run in deployment CI.
8. Contracts and drift
npm run test:contractwalks the Express routers and fails when a route is undocumented or a documented path is not registered.npm run genregeneratespackages/protocol/generated/*; CI fails when the committed output is stale (npm run check:gen).- The OpenAPI document is served at
/developers/openapi.jsonand Swagger UI at/developers/docs.