Yeaply protocol v1 (draft 3, 2026-11-25)
The contract between a service (anything that asks a person for a decision) and Yeaply (the phone app and its courier server at https://yeaply.com). Yeaply never holds a readable notice or decision: everything a person reads or answers is sealed end to end between the service and the person's phones.
The reference implementation of the server side is testing/mock-courier in the yeaply-sdk repo (in-memory courier plus a fake phone); the SDKs in that repo are the reference client side. Where this text and the mock disagree, fix one of them.
0. Conventions
- Binary values (keys, sealed boxes, signatures, hashes) are base64url without padding.
- Canonical JSON (for signing): object keys sorted by code point, no whitespace, UTF-8, strings escaped as by
JSON.stringify. Keys are ASCII only; numbers are integers only. (Equal to JSJSON.stringifyover a key-sorted copy and to Pythonjson.dumps(sort_keys=True, separators=(",", ":"), ensure_ascii=False).) - Times are ISO 8601 UTC with milliseconds (
2026-11-25T10:00:00.000Z). - Errors: HTTP 4xx/5xx with body
{ "error": { "code", "message" } }. Codes:bad_request,unauthorized,not_found,pairing_expired,invalid_signature,unknown_device,too_large,rate_limited,connection_revoked,expired,withdrawn,already_answered. Client-side refusals (raised by the SDKs, never sent by the server):device_list_rejected,pairing_rejected,answer_rejected. - Auth: a service authenticates with
Authorization: Bearer <serviceToken>; a phone with the signed-in person's session. - Long polls:
?wait=N(seconds, at most 25) holds the request until there is something to return or N seconds pass.
Keys
- Phone: each phone (device) has an X25519 key pair for opening packets, kept in the device's secure storage and never leaving it. A person can have several phones; each has its own key and a
deviceId(string, at most 64 characters). - Person identity key: each person has one Ed25519 key pair (
personKey), made on their first phone and kept in secure storage. It signs the person's device list (section 1a) and the pairing confirm. It leaves a phone only sealed to a new phone the person approved, or as the recovery code the person saved. Its person fingerprint is the first 8 bytes ofsha256(personKey)in the same 4 x 4 hex format. - Service: each service has an Ed25519 key pair for signing (
signKey, 32-byte public key) and an X25519 key pair for receiving sealed answers (boxKey, 32-byte public key). The SDK creates both and stores them locally (a 0600 file, or an environment variable for servers). - Encryption: libsodium sealed boxes (
crypto_box_seal: X25519 + XSalsa20-Poly1305), one per recipient key. Signatures: libsodiumcrypto_sign_detached(Ed25519). - Key fingerprint of a service: the first 8 bytes of
sha256(signKey || boxKey)(raw key bytes), shown as 16 lower-case hex digits in four groups of four (a1b2 c3d4 e5f6 a7b8).
1. Pairing (connect a service to a person)
POST /api/v1/pair(service, unauthenticated, rate-limited). Body:{ service: { name, url?, iconUrl? }, signKey, boxKey }.nameis 1 to 80 characters. Answer 201:{ pairingId, code, qr, expiresAt }.codeis 8 characters from the alphabet23456789ABCDEFGHJKLMNPQRSTUVWXYZ(no 0/O/1/I), shown asABCD-EFGH; the phone accepts it with or without the dash and in any case.qrisyeaply://pair?c=<code>. Valid 10 minutes.pairingIdis at least 128 random bits and is only ever given to the service (it is what lets the service collect its token).- The SDK shows the code, the fingerprint, and a QR of
yeaply://pair?c=<code>&f=<fingerprint without spaces>. The person types the code (or scans the QR) in the Yeaply app; the phone sendsPOST /api/v1/pair/claimwith{ code }and the server answers{ service: { name, url?, iconUrl? }, signKey, boxKey, fingerprint, expiresAt }. The phone shows the service's name, URL and fingerprint; if the QR carriedf, the phone compares it with the fingerprint it computes from the keys and refuses on a mismatch (so the server cannot swap the service's keys). The person taps Connect. - The phone sends
POST /api/v1/pair/confirmwith{ code, personKey, deviceList, confirmSignature }: the person's current signed device list (section 1a) andconfirmSignature = Ed25519(personKey, "yeaply-pair-v1\n" + canonical JSON of { code: <8 characters, upper case, no dash>, serviceFingerprint: <16 hex digits, no spaces>, deviceListHash: <base64url sha256 of the canonical JSON of deviceList.statement> }). The server checks it (400invalid_signature). Answer{ connectionId }. A code can be confirmed once. - The service polls
GET /api/v1/pair/{pairingId}(long poll with?wait=25). Answers:{ state: "waiting", expiresAt }, then once{ state: "confirmed", connectionId, serviceToken, personKey, deviceList, confirmSignature }. The token is shown once: later polls answer 404not_found. After 10 minutes without a confirm: 410pairing_expired. - The service pins the person. It accepts the pairing only if
confirmSignatureverifies underpersonKeyfor its own code, its own fingerprint and the hash of thedeviceListit received, and the device list verifies (section 1a). Otherwise it refuses (pairing_rejected) and stores nothing. It then storespersonKeyfor good: every later device list must verify under it. The SDK shows the person fingerprint (status()); the app shows the same one, so a person can check that the server did not stand in for them at pairing. - Devices:
GET /api/v1/connections/{connectionId}/devices(Bearer) answers{ deviceList }. The SDK fetches it before a send when its copy is older than 5 minutes, and again once when a send is refused withunknown_device, and seals only to the devices of a list it accepted (section 1a). - The person can disconnect a service in the app at any time; its token stops working (401
connection_revoked) and its packets are deleted.
1a. The person's device list
The phones a service seals to come from a statement signed by the person's identity key, never from the server's word:
{ "statement": { "v": 1, "kind": "yeaply-devices", "personKeyFingerprint": "a1b2 c3d4 e5f6 a7b8", "seq": 3,
"devices": [{ "deviceId": "...", "boxKey": "<X25519 public key>", "addedAt": "ISO" }] },
"signature": "<Ed25519(personKey, \"yeaply-devices-v1\n\" + canonical JSON of statement)>" }- A service accepts a list only if: it is well formed (
v1,kind, integerseq>= 1, at least one device, unique deviceIds, 32-byte box keys);personKeyFingerprintis the fingerprint of the pinnedpersonKey; the signature verifies under the pinnedpersonKey; andseqis higher than the list it accepted last, or equal with an identical statement. Otherwise it refuses withdevice_list_rejected, keeps its last accepted list, and seals nothing. So a server that adds a phone of its own, signs with another key, or serves an older list (for example one that still holds a lost phone) is refused. - The server stores the current list per person and also checks signature and
seqon every change (defence in depth, not the guarantee). - First phone (setup): the app makes the identity key, signs
seq: 1with itself, sendsPOST /api/v1/phone/identity { personKey, deviceList }(409 if the person already has one), and shows the recovery code once: the 32-byte identity seed in RFC 4648 base32 (52 characters, groups of 4 joined by-). The person writes it down; it is never sent anywhere. - Adding a phone (approval): the new phone signs in, sends
POST /api/v1/phone/joins { deviceId, boxKey }(answer{ joinId, expiresAt }, valid 10 minutes) and shows a 6-digit code: the first 4 bytes ofsha256("yeaply-join-v1\n" + joinId + "\n" + boxKey)as a big-endian integer mod 1,000,000, zero padded. An existing phone listsGET /api/v1/phone/joins({ joins: [{ joinId, deviceId, boxKey, expiresAt }] }), computes the same code from the request and shows it; the person confirms the two codes match and taps Approve (a mismatch means the request was altered: refuse). The approving phone signs a list withseq + 1that adds{ deviceId, boxKey }, seals the identity seed for the new phone'sboxKey(crypto_box_seal), and sendsPOST /api/v1/phone/joins/{joinId}/approve { deviceList, sealedIdentity }. The new phone collects it withGET /api/v1/phone/joins/{joinId}({ state: "waiting" | "approved", sealedIdentity? }; deleted once collected), opens the seed, and checks it is on the signed list. - Adding a phone (recovery): the person types the recovery code on the new phone; the phone derives the identity key, checks it matches
GET /api/v1/phone/identity({ personKey, deviceList }), and sendsPUT /api/v1/phone/device-list { deviceList }withseq + 1, adding itself (and usually dropping lost phones). - Removing a phone: any phone holding the identity key signs a list with
seq + 1without it and sendsPUT /api/v1/phone/device-list. Services pick it up on their next refresh; the server refuses answers from a phone not on the current list.
2. Ask (a notice in)
POST /api/v1/packets (Bearer serviceToken). Body:
{ "envelope": { "v": 1, "packetId": "<uuid v4 from the service>", "connectionId": "...", "createdAt": "ISO",
"expiresAt": "ISO",
"kind": "decision", "passkey": false },
"sealed": { "<deviceId>": "<sealed box of the payload for that device>" },
"signature": "<Ed25519, see below>" }- Signature:
crypto_sign_detached(message, serviceSignSecretKey)wheremessageis the UTF-8 bytes of"yeaply-packet-v1\n"followed by the canonical JSON of{ "envelope": <envelope>, "sealed": { "<deviceId>": "<base64url sha256 of the sealed box bytes>" } }. The server checks it with the connection'ssignKey(400invalid_signature) and the phone checks it again before showing anything. sealedmust hold a box for every device on the person's current list (400unknown_deviceif a deviceId is unknown or one is missing, so the SDK refreshes and verifies the list and retries once).expiresAt: default 7 days aftercreatedAt, at most 30 days; the server refuses later (400bad_request).createdAtmust be within 5 minutes of the server's clock.- Answer 201
{ packetId, state: "waiting" }. A repeatedpacketIdanswers 409bad_request.
The payload (only readable on the phone) is UTF-8 JSON:
{ "v": 1, "packetId": "<same as the envelope>", "nonce": "<16 random bytes>",
"title": "...", "body": "...", "facts": [{ "label": "...", "value": "..." }],
"options": [{ "id": "yes", "label": "Yes", "style": "primary" }],
"allowNote": false, "link": "https://..." }title1 to 200 characters;bodyat most 4000; 1 to 8options,idmatching^[a-z0-9_-]{1,32}$, unique,label1 to 60 characters,style"primary"or"danger"(optional); at most 20facts;linkhttps only. Plain text only; no HTML, no scripts. Each sealed box at most 16 KB.- The phone refuses a payload whose
packetIddiffers from the envelope's. noncemakes the payload unguessable, so that its hash (below) works as proof that an answer came from a phone that opened it.
Yeaply stores the envelope and the sealed boxes, sends an ids-only push to the person's phones, and deletes everything when the answer is collected or the packet expires.
3. Answer (a decision out)
The phone fetches GET /api/v1/phone/packets/{packetId} (person's session) which answers { envelope, sealed: <box for this device>, signature, sealedHashes: { deviceId: hash }, service: { name, url?, signKey } }; it checks the signature (over the envelope and all sealedHashes, after checking its own box hashes to its entry), opens its box, checks payload.packetId, and shows the payload with the service's name. The person picks an option (with a passkey check on the phone if passkey: true) and may add a note (at most 1000 characters) if allowNote.
The phone posts POST /api/v1/packets/{packetId}/answer with { deviceId, sealedAnswer, answeredAt }, where sealedAnswer is a sealed box for the service's boxKey of the UTF-8 JSON { v: 1, packetId, optionId, note?, answeredAt, deviceId, payloadHash }. payloadHash is base64url sha256 of the exact payload bytes the phone opened. The first answer wins: later ones answer 409 already_answered; after a withdraw 409 withdrawn; after expiry 410 expired.
The service opens the answer and accepts it only if packetId matches, optionId is one of the options it sent, and payloadHash equals the hash of the payload it sealed. Since only the service and the person's phones know the payload (it carries a random nonce), the server cannot forge or alter an answer, and nobody can show one thing and act on another.
4. Collect
GET /api/v1/packets/{packetId}?wait=25(Bearer) answers{ packetId, state: "waiting" | "answered" | "expired" | "withdrawn", answeredAt?, sealedAnswer? }(sealedAnswerwhen answered). Long-polls while waiting.GET /api/v1/answers?wait=25(Bearer) answers{ answers: [{ packetId, sealedAnswer, answeredAt }] }: every answered packet of the connection not yet acknowledged.POST /api/v1/answers/ack(Bearer) with{ packetIds: [...] }answers{ acked: n }and deletes those packets and their answers on the server (later reads answer 404not_found). Answers are only deleted on ack (or at expiry), so an answer is never lost to a dropped response.DELETE /api/v1/packets/{packetId}(Bearer) withdraws a waiting question: answers{ packetId, state: "withdrawn" }; the phones drop it. Withdrawing an answered packet answers 409already_answered.- An optional
callbackUrlper connection receivesPOST { packetId }(ids only) when an answer is ready; the service then collects as above. (How Yeaply signs callbacks is open, see below.)
5. What Yeaply sees
Who sent a packet to whom and when, the envelope (no title, body or options), and the sizes. Never the content and never the decision.
6. Limits
60 packets/minute per connection (429 rate_limited); 500 open packets per connection.
Open questions (draft 2)
- First pairing. A server that stands in for the person at the very first pairing (its own identity key and phone) is only caught by comparing person fingerprints (SDK
status()and the app). An optionexpectPersonKeyfor services that know the fingerprint ahead of time would close it. - Recovery code is the identity seed itself: whoever holds it can add a phone. A later version could wrap it with a passphrase (libsodium
crypto_pwhash). - Callback signing. Key and header for signed callbacks (for example an Ed25519 Yeaply key published at
/.well-known/yeaply.jsonand aYeaply-Signatureheader). - Token rotation. No endpoint yet to rotate a
serviceTokenwithout pairing again.