WHIM Protocol Specification (1.0)

WHIM (Wormhole Instant Messenger) is an open standard for a messaging software with message and file payloads carried over Magic Wormhole–compatible encrypted transfers. The control plane (accounts, friends, presence, signaling) is a small HTTP/WebSocket API. The data plane (message bodies and files) is Magic Wormhole; files and messages never transit the control plane server.

This document describes the WHIM 1.0 behavior implemented by the reference stack, agum (whim-server + WHIM desktop client + whim-wormhole sidecar). It is published so operators and developers can build and self-host a compatible server and/or build a compatible client in any language or UI, without requiring access to the reference source code.

The reference WHIM desktop app and hosted server are not open source. This specification is the open standard: interoperability is defined here, not by reading reference implementation sources.



1. Goals and non-goals

Goals

Non-goals


2. Architecture

+-------------+     HTTPS + WSS      +------------------+
| WHIM client | <------------------> |  WHIM server     |
|             |   (control plane)    |  (whim-server)   |
+------+------+                      +------------------+
       |
       | spawn / IPC
       v
+--------------+     WSS rendezvous    +------------------+
| whim-wormhole| <-------------------> | Magic Wormhole   |
| sidecar      |     + TCP transit     | rendezvous/relay |
+------+-------+                       +------------------+
       |
       | encrypted wormhole session
       v
+-------------+
| Peer client |
+-------------+
PlaneResponsibility
Control planeAuth, profiles, device public keys, friends, presence, transfer offers, encrypted signaling envelopes
Data planeWormhole pairing (SPAKE2 + transit). Text and files as wormhole payloads
LocalChat history, settings, device private key (never sent to server)

3. Terminology

TermMeaning
WHIM IDPublic account handle: three lowercase words from a server wordlist, joined with hyphens (e.g. copper-lantern-orbit). Assigned at registration.
Control plane URLBase HTTPS URL of a WHIM server (e.g. https://whim.example.com). No trailing slash required.
Access tokenJWT returned by register/login; sent as Authorization: Bearer … on protected HTTP routes and as access_token query param on WebSockets.
Device keyP-256 ECDH key pair generated on the client. Public JWK stored on the server; private JWK kept locally. Used to encrypt wormhole codes for friends.
Transfer sessionUUID created by POST /v1/transfers/start; correlates signaling, sidecar jobs, and optional history rows.
Wormhole codeHuman wormhole pairing string produced by the sidecar (code event). Must not be sent to the control plane in plaintext in WHIM 1.0 clients.
AppIDMagic Wormhole application id (default agum.com/wormhole-im/v1). Both peers must use the same AppID for a session.
Rendezvous URLWebSocket URL of a Magic Wormhole mailbox server (default public relay).
Transit relayHost:port for wormhole transit when direct TCP fails. Empty / direct-only disables relay.

4. HTTP conventions

4.1 Base URL and paths

4.2 Authentication

Protected routes require:

Authorization: Bearer <access_token>

JWT properties (WHIM 1.0 reference profile):

Alternate servers may use other signing keys or token formats only if they do not need to interoperate with the reference desktop client's login flow.

4.3 Errors

Failed requests return JSON:

{ "error": "human-readable message" }

Common status codes: 400 validation, 401 auth, 403 forbidden, 404 not found, 409 conflict, 402 Payment Required when account activation is required but not satisfied.

4.4 CORS

Reference server allows all origins for browser-based tooling. Production deployments may restrict this; clients using native HTTP are unaffected.

4.5 UUIDs and timestamps


5. Public HTTP endpoints

5.1 GET /health

Liveness probe.

Response 200:

{ "status": "ok" }

5.2 GET /v1/client-info

Optional client metadata for About screens and update checks. No authentication. Fields are omitted when not configured on the server.

Response 200:

{
  "latest_version": "1.0.1",
  "update_url": "https://example.com/download",
  "support_email": "[email protected]",
}

6. Authentication and profile

6.1 POST /v1/auth/register

Create an account. Server assigns a unique WHIM ID.

Request:

{
  "email": "[email protected]",
  "password": "string",
  "display_name": "string"
}

Response 200:

{
  "access_token": "<jwt>",
  "user": { /* UserPublic */ }
}

UserPublic:

FieldTypeNotes
idUUIDInternal user id
whim_idstringThree-word public id
emailstring | nullIf registered with email
display_namestringShown name
device_public_keyobject | nullJWK after first publish
account_statusstringe.g. active, pending_activation
activation_requiredbooleanServer policy flag

When activation_required is true on the user object, new accounts may start as pending_activation until the operator enables the account (see §7).

6.2 POST /v1/auth/login

Request:

{
  "identifier": "word-word-word or [email protected]",
  "password": "string"
}

identifier matches WHIM ID (normalized, see §3) or email (case-insensitive).

Response 200: same shape as register.

6.3 GET /v1/me

Auth required. Returns current UserPublic.

6.4 POST /v1/me/device-key

Auth required. Publish or replace the device public key.

Request:

{
  "public_key": { /* JWK object, ECDH P-256 */ }
}

Response 200: updated UserPublic.

WHIM 1.0 clients generate a long-lived P-256 key pair locally, publish the public JWK after login, and use the private key to decrypt incoming signaling.


7. Billing (optional activation)

Some deployments may require paid or manual activation before social features work. Others leave every account active. These endpoints expose that policy to the client.

7.1 GET /v1/billing/status

Auth required.

Example response:

{
  "required": false,
  "provider": "stripe",
  "account_status": "active",
  "checkout_available": false
}

7.2 POST /v1/billing/checkout

Auth required. Placeholder for Stripe Checkout URL when activation is enabled.

Example response:

{
  "enabled": false,
  "checkout_url": null,
  "message": "…"
}

Many friend, presence, and transfer routes return 402 Payment Required when account_status is not "active" and the deployment requires activation. Logging in should return 402 if the deployment requires activation and the user account is not activated


8. Friends and requests

All routes in this section require active account unless noted.

8.1 GET /v1/friends

Returns accepted friends with live presence projection.

Response 200: array of FriendPublic:

FieldTypeNotes
idUUIDFriend user id
whim_idstring
display_namestring
onlinebooleantrue iff friend has an open presence WebSocket
availabilitystringonline, away, or offline
status_messagestring | nullAway message; only when availability is away and friend is connected
device_public_keyJWK | nullFor encrypting signals
friends_sincestringISO timestamp

Presence rules:

8.2 POST /v1/friends/request

Send a friend request by WHIM ID (not display name).

Request:

{
  "target_whim_id": "word-word-word",
  "note": "optional string"
}

Response 200:

{ "request_id": "<uuid>" }

Errors: unknown WHIM ID (404), already friends (409), self-add (400).

Target user receives a friend_request event on their presence WebSocket if connected.

8.3 GET /v1/friends/requests

Response 200: array of FriendRequestPublic:

FieldType
idUUID
direction"incoming" | "outgoing" (relative to caller)
statuse.g. pending, accepted, declined
notestring | null
requesterUserLite
addresseeUserLite
created_at, updated_atISO strings

UserLite: { "id", "whim_id", "display_name" }.

8.4 POST /v1/friends/requests/:request_id/respond

Request:

{ "accept": true }

Only the addressee may respond while status is pending.

Response 200: updated FriendRequestPublic.

Requester receives friend_accepted or friend_declined on presence WebSocket.


9. Transfers and signaling

9.1 POST /v1/transfers/start

Initiator creates a transfer session and notifies the friend.

Request:

{
  "friend_id": "<uuid>",
  "kind": "message",
  "appid": "agum.com/wormhole-im/v1",
  "rendezvous_url": "ws://relay.magic-wormhole.io:4000/v1",
  "transit_relay": "transit.magic-wormhole.io:4001"
}
FieldNotes
kind"message" or "file". If omitted, treat as "message".
appidWormhole AppID for this session. If omitted, server chooses a default and echoes it in the response.
rendezvous_urlWormhole rendezvous WebSocket URL. If omitted, server chooses a default and echoes it.
transit_relayTransit relay host:port, or omit/empty for direct-only. Server echoes resolved value (may be null).

Response 200:

{
  "session_id": "<uuid>",
  "appid": "…",
  "rendezvous_url": "…",
  "transit_relay": "…"
}

transit_relay may be null if empty.

Friend receives transfer_offer on presence WebSocket (metadata only). WHIM 1.0 reference client does not require accepting offers separately for messages; file flows use encrypted code + accept/decline signals (§10).

9.2 POST /v1/signaling/send

Deliver an arbitrary signal to a friend if they have an active presence socket.

Request:

{
  "friend_id": "<uuid>",
  "signal_type": "wormhole_code_encrypted",
  "payload": { }
}

Response 200:

{ "delivered": true }

delivered: false means the friend is not connected; the server does not queue signals for later delivery.

WHIM 1.0 signal types (see §10): wormhole_code_encrypted, wormhole_code_ack, file_transfer_response.

The same Signal shape is also delivered as a presence WebSocket event (§11).

9.3 GET /v1/pairing/pending

Auth required. Returns session ids for pending pairing sessions where this user is the target.

{ "session_ids": ["<uuid>", …] }

The reference 1.0 desktop client does not use this for chat/file delivery (wormhole codes use encrypted signaling instead). Reserved for alternate pairing experiments and mailbox WebSocket (§12).


10. Client data plane (normative for WHIM 1.0)

This section defines what a compatible client must implement. The server only sees encrypted envelopes and opaque wormhole metadata in transfer offers.

10.1 Preconditions

10.2 Device-key encrypted wormhole code

Plaintext wormhole codes must not be posted to /v1/signaling/send in WHIM 1.0.

Envelope (signal_type: wormhole_code_encrypted, payload):

{
  "v": 1,
  "alg": "ECDH-P256-AES-GCM",
  "epk": { /* ephemeral P-256 public JWK */ },
  "iv": "<base64, 12 bytes>",
  "ciphertext": "<base64>"
}

Ciphertext decrypts to UTF-8 JSON WormholeCodeSignal:

{
  "session_id": "<uuid>",
  "kind": "message",
  "code": "wormhole-code-string",
  "appid": "…",
  "rendezvous_url": "…",
  "transit_relay": "…",
  "direct_only": false,
  "file_name": "optional-for-file-kind"
}

Encryption steps (normative):

  1. Generate ephemeral ECDH P-256 key pair.
  2. ECDH with friend's published device_public_key → AES-256-GCM key.
  3. Encrypt JSON signal with random 12-byte IV.
  4. Send envelope via signaling (HTTP or presence WS).

Decryption: reverse with local private device key and sender's epk.

On successful decrypt, receiver should send wormhole_code_ack:

{
  "signal_type": "wormhole_code_ack",
  "payload": { "session_id": "<uuid>" }
}

Sender should wait for ack (reference client ~12s timeout) before treating an outgoing message send as delivered.

10.3 Message transfer flow

  1. Initiator: POST /v1/transfers/start with kind: "message" and wormhole endpoints.
  2. Initiator: start sidecar send-text with --message body (WHIM markup string, §13).
  3. Sidecar emits code → initiator sends wormhole_code_encrypted to friend; waits wormhole_code_ack.
  4. Receiver: on decrypt, start sidecar recv-text with --code.
  5. Sidecar emits message then complete → receiver stores plaintext in local history.

Message bytes travel only through wormhole; control plane sees session ids and encrypted codes only.

10.4 File transfer flow

  1. Initiator: transfers/start with kind: "file".
  2. Initiator: start send-file (sidecar holds file open; may emit code before transfer completes).
  3. Initiator sends encrypted code with kind: "file" and file_name.
  4. Receiver: shows accept/decline UI. On decline, send file_transfer_response { "session_id", "accepted": false }.
  5. On accept, receiver sends "accepted": true, runs recv with --code and --out directory.
  6. Initiator: on "accepted": true, sidecar completes send-file transfer (reference client already started send-file and waits for peer).

Only one outstanding incoming file request per friend is recommended (reference client auto-declines extras).

file_transfer_response payload:

{
  "session_id": "<uuid>",
  "accepted": true
}

11. Presence WebSocket

11.1 Connection

GET /v1/ws/presence?access_token=<jwt>

Upgrade to WebSocket. Invalid or expired JWT closes the connection.

On connect, server sends hello, then may send presence, status, friend events, transfer_offer, and signal events. Servers should use WebSocket ping frames for keepalive; clients must respond with pong or risk being disconnected.

11.2 Server → client events

JSON objects with "type" in snake_case:

typePurpose
helloInitial snapshot: { user, friends[], presence_status, status_message }
presenceFriend online/away/offline change: { user, online, availability, status_message? }
statusOwn status persisted: { presence_status, status_message? }
friend_request{ request_id, from: UserLite }
friend_accepted{ by: UserLite }
friend_declined{ by: UserLite }
transfer_offer{ session_id, from, kind, appid, rendezvous_url, transit_relay? }
signal{ from, signal_type, payload }

11.3 Client → server messages

Set availability (online / away):

{
  "type": "status",
  "availability": "online",
  "status_message": "optional away markup"
}

Relay signal (optional): clients may send { "type": "signal", "friend_id", "signal_type", "payload" } on the same socket instead of HTTP signaling. Reference client uses HTTP signaling/send.

Offline: reference client closes the WebSocket and stops reconnecting until the user chooses Online again.


12. Mailbox WebSocket (optional / legacy)

GET /v1/ws/mailbox/:session_id?access_token=<jwt>

Authenticates the initiator or target of a known pairing session_id and bridges two WebSocket peers. WHIM 1.0 chat/file delivery does not require this endpoint; peers use Magic Wormhole rendezvous via the sidecar. Optional for alternate pairing or relay designs.


13. WHIM message markup

Message bodies and away status_message values are a single UTF-8 string with BBCode-style tags. Tags are interpreted by clients for display; the wire format through wormhole is plain text including tags.

13.1 Tags

TagMeaning
[b]…[/b]Bold
[i]…[/i]Italic
[u]…[/u]Underline
[color=#rrggbb]…[/color]Foreground color (6 hex digits)
[size=n]…[/size]Relative size n = 0–4 (2 = normal; composers should omit tag for normal on save)

13.2 Autolinks

Clients should linkify http:// and https:// substrings in plain text when rendering. No [url] tag in 1.0.

13.3 Line breaks

Composer serializes line breaks as \n in the stored string. Renderers map \n to visual line breaks.


14. whim-wormhole sidecar protocol

Compatible clients may embed wormhole-william directly; the reference app spawns a whim-wormhole binary with a stable CLI and newline-delimited JSON on stdout.

14.1 Commands

CommandPurpose
send-textSend UTF-8 text (--message)
recv-textReceive text (--code)
send-fileSend file (--path)
recvReceive file or text (--code, --out dir)

Shared flags:

FlagDefault
--appidagum.com/wormhole-im/v1
--rendezvousws://relay.magic-wormhole.io:4000/v1
--transittransit.magic-wormhole.io:4001
--direct-onlyfalse (clears transit)
--timeout30m

Passphrase component length is 2 (wormhole-william client setting in reference sidecar).

14.2 stdout events (one JSON object per line)

typeFields
codecode; optional name, path for file send
messagemessage, bytes (recv-text)
filename, path, bytes (recv file)
completesuccess
errorerror (also non-zero exit)

Parent process should parse lines incrementally and support cancel/kill of long-running recv/send jobs.


15. WHIM ID normalization

When accepting user input for WHIM IDs (login, friend add), servers and clients should normalize:

Validation for friend requests: at least three hyphen-separated alphanumeric segments (e.g. word-word-word).


16. Security and trust notes (1.0)


17. Compatibility

LayerVersion
This documentWHIM 1.0
Reference desktop app1.0.0 (check GET /v1/client-info / About for deployed builds)
API path prefix/v1/

Future versions should introduce new optional JSON fields or new /v2/ routes rather than breaking 1.0 clients silently.


18. Reference behavior summary (checklist for alternate clients)

A minimal WHIM 1.0–compatible desktop client should:

  1. Register/login against control plane; store JWT.
  2. Generate P-256 device key; POST /v1/me/device-key.
  3. Open presence WebSocket while "online"; handle hello/presence/signal events.
  4. List friends; send/accept friend requests by WHIM ID.
  5. For chat: transfers/start → sidecar send-text → encrypt code → signal → wait ack → complete on sidecar complete.
  6. For chat receive: decrypt signal → recv-text → display with WHIM markup.
  7. For files: encrypted code + accept/decline + send-file/recv coordination (§10.4).
  8. Store history locally only.
  9. Fetch GET /v1/client-info on launch for optional About/update UI.

A minimal compatible server must implement §5–§11 and enforce friend-only signaling and transfer rules as described.


WHIM Protocol Specification 1.0 — published for interoperability and self-hosting. Reference implementations may differ in UI and local storage; behavior on the wire should match this document.