# Isolink protocol

This document says what Isolink's code does, byte for byte where it matters. It was written from
`packages/isolink_core/lib/src/crypto`, `net/connection.dart`, `net/transport.dart`,
`net/relay_protocol.dart`, `engine/pair_keys.dart` and `engine/messenger.dart` as of November 2026.
Where this document and the code disagree, the code is what runs and this document has a bug.

It also covers three changes going out with the next release, each with its own design note:
hybrid post-quantum key agreement ([post-quantum.md](post-quantum.md), PR #1030), one-time
prekeys ([one-time-prekeys.md](one-time-prekeys.md), PR #1037), and sealed sender with hidden
recipients for relay mail ([sealed-sender.md](sealed-sender.md), PR #1043). Older apps keep the
behaviour described first in each section, and both kinds of app talk to each other.

The known-answer vectors in `packages/isolink_core/test/vectors/protocol_vectors.json` come from an
independent reference implementation of this document (`tool/security/protocol_reference.py`,
pyca/cryptography). `packages/isolink_core/test/protocol_vectors_test.dart` runs Isolink's own
code against them. A section with a **Vectors** line is checked that way.

The threat model, and what the design does not protect, is in [threat-model.md](threat-model.md).
Bots that use a computer have their own: [bot-threat-model.md](bot-threat-model.md).

## Contents

1. [Notation and primitives](#notation-and-primitives)
2. [Identities and devices](#identities-and-devices)
3. [Sessions (X3DH, PQXDH)](#sessions-x3dh-pqxdh)
4. [Double Ratchet](#double-ratchet)
5. [Envelopes](#envelopes)
6. [Links](#links)
7. [Discovery and tags](#discovery-and-tags)
8. [Carrying](#carrying)
9. [Relay servers](#relay-servers)
10. [Groups](#groups)
11. [Multi-device](#multi-device)
12. [Files](#files)
13. [Verification](#verification)
14. [Storage, backups and recovery](#storage-backups-and-recovery)
15. [Updates](#updates)
16. [Delivery proofs](#delivery-proofs)
17. [How this compares with Signal](#how-this-compares-with-signal)

## Notation and primitives

| | |
| --- | --- |
| `‖` | concatenation |
| `u32(n)` | 4-byte big-endian unsigned integer |
| `"text"` | the ASCII bytes of the text, no terminator |
| `X[a..b]` | bytes `a` up to, not including, `b` |
| `b64` | base64url without padding, used for every key and ciphertext in JSON |
| `DH(a, B)` | X25519 (RFC 7748) of private key `a` and public key `B`. An all-zero result is rejected. |
| `Sig(k, m)` | Ed25519 (RFC 8032) signature by `k` |
| `HKDF(ikm, salt, info, L)` | HKDF-SHA256 (RFC 5869), `L` bytes |
| `HMAC(k, m)` | HMAC-SHA256 |
| `AEAD(k, n, p, ad)` | AES-256-GCM, 12-byte nonce, ciphertext followed by its 16-byte tag |

All primitives come from the Dart `cryptography` package (2.x), which uses the platform's AES
where it has one. Where it doesn't (desktops without native AES, the relay server), payloads of
16 KB or more go through Isolink's own constant-table GCM (`crypto/gcm.dart`, `FastGcm`). Random
bytes come from `Random.secure()`.

**Vectors:** RFC 7748 §6.1, RFC 8032 §7.1 tests 1 and 2, RFC 5869 case 1, RFC 4231 case 2, and
AES-256-GCM against OpenSSL for a short and a 20 KB message (the second goes through `FastGcm`).

### Padding

Two paddings, both ISO/IEC 7816-4 (a `0x80` byte, then zeros):

- `pad(m)`: to the next multiple of 128 bytes, at least one byte added. Used on ratchet plaintexts
  and raw-bytes link frames.
- `padToBucket(m)`: to 256 bytes, or past that to the next of `1, 1.25, 1.5, 1.75 × 2^k × 256`.
  Lengths then show at most a 25% size class. Used on link frames, carried envelopes and blobs.

**Vectors:** `padding`.

## Identities and devices

An **account** is a chain of Ed25519 account keys `A0, A1, …`.

```
accountId   = hex(SHA-256("isolink-account" ‖ A0)[0..16])
link i      = Sig(A(i-1), "isolink-rotate-v1" ‖ accountId ‖ u32(i) ‖ Ai)
```

`accountId` is the 32-character hex string, so its ASCII bytes are what the rotation signs. The
last key is the **current** account key. A chain is valid when every link verifies.

Every linked device holds the current account private key. It is sent to a new device when it is
linked, and to the remaining devices when the account rotates.

A **device** has:

- an Ed25519 signing key `IKsig`
- an X25519 identity key `IKdh`, a separate key (no XEdDSA conversion)
- a signed X25519 prekey `SPK` with a numeric id, made every 7 days. The last 4 are kept, so a
  prekey's private key lives about 4 weeks.

```
deviceId    = hex(SHA-256(IKsig ‖ IKdh)[0..16])
spkSig      = Sig(IKsig, "isolink-bundle-v3" ‖ IKdh ‖ u32(spkId) ‖ SPK ‖ utf8(name))
certificate = Sig(currentAccountKey, "isolink-device-v1" ‖ IKsig ‖ IKdh)
```

The display name is covered by `spkSig`, so renaming re-signs the prekey.

A **bundle** is one device's public half, as JSON:

```json
{ "name": "Bob", "ik": IKsig, "dh": IKdh, "spkId": 7, "spk": SPK, "sig": spkSig,
  "acct": [[A0], [A1, link1], …], "cert": certificate, "kind": { "k", "l", "s" } }
```

A bundle **verifies** when `spkSig` verifies, `kind` (if present) verifies under `IKsig`, and,
if it has a chain, the chain is valid and the certificate verifies under its current key. A
bundle with neither chain nor certificate is an unlinked device; one with only one of the two
fails.

`kind` is the device's own word on what it is: `Sig(IKsig, "isolink-device-info-v1" ‖
u32(len(kind)) ‖ kind ‖ utf8(label))`. It is outside `spkSig` so older apps ignore it.

A **contact card** (contact code `isolink:` + b64 of JSON or of the compact binary form in
`crypto/compact_card.dart`) lists every device of one account, each certified by the same current
key, with optional signed relay addresses (`r`) and an optional one-time in-person secret (`m`).

**Compact codes carry a chain summary.** A compact code carries only `A0`, the current key and
the chain's length. Its devices' certificates are checked against the current key, but nothing
in the code proves the current key descends from `A0`. Isolink accepts the contact on that basis
(`verify(allowSummary: true)`) and replaces the summary when the account sends its whole chain.
If the whole chain doesn't lead to the code's current key, the code's devices are dropped and
the chat says so (`Messenger._promote`). See [threat-model.md](threat-model.md#compact-codes).

**Vectors:** `identity` (device and account ids, bundles a device builds from its own keys
byte for byte, certificates, a two-key chain, a rotation signature, a changed byte in each
signed field failing).

## Sessions (X3DH, PQXDH)

Sessions are per pair of devices. They use X3DH without one-time prekeys
(`crypto/session.dart`).

The initiator `a`, with the responder's verified bundle `b`, makes an ephemeral X25519 key `EK`:

```
DH1 = DH(IKdh_a, SPK_b)
DH2 = DH(EK,     IKdh_b)
DH3 = DH(EK,     SPK_b)
SK  = HKDF(0xFF×32 ‖ DH1 ‖ DH2 ‖ DH3, salt = 0×32, info = "IsolinkX3DH", 32)
AD  = IKsig_a ‖ IKdh_a ‖ IKsig_b ‖ IKdh_b
```

The session id is `hex(EK)`. The initiator starts the ratchet with `SK` and `SPK_b` as the
responder's first ratchet key, and attaches a **prekey header** to every message until the first
reply decrypts:

```json
"pk": { "from": <a's bundle>, "ek": EK, "spkId": <b's prekey id> }
```

The responder looks up `spkId` among its kept prekeys, checks `from` verifies, computes the same
three DHs, and starts its ratchet with `SK` and that prekey as its first ratchet key.

Rules when a message arrives (`Cipher.decrypt`):

1. If it has a prekey header and the sender is a known contact device, the header's `IKsig` and
   `IKdh` must equal the known ones, or it is refused (`sender identity key changed`).
2. Every existing session with that device is tried, newest first. The one that decrypts moves
   to the front and is used for sending. Up to 5 are kept, so two devices that start a session at
   the same moment converge.
3. Only if none decrypts and it has a prekey header: a session whose id is `hex(ek)` already
   existing means a replay, and it is refused. Otherwise a new session is made.
4. With no prekey header, it is `NoSessionError`. The receiver then starts a fresh session by
   sending a `session` note naming the envelope, and the sender resends its last few messages
   to that device over the new session. See [threat-model.md](threat-model.md#resent-messages).

### Post-quantum (PQXDH)

A newer device's bundle also carries `pq: {k, s}`: an ML-KEM-768 public key `PQSPK` for prekey
`spkId`, and `s = Sig(IKsig, "isolink-pq-prekey-v1" ‖ u32(spkId) ‖ k)`. It sits outside `spkSig`,
so device ids and older verification are unchanged; a `pq` that doesn't verify fails the whole
bundle. When the responder's bundle has a valid `pq`, the initiator also encapsulates to it and the
prekey header gains `kct` (the 1,088-byte ciphertext) and `pq: 1` (the sender has a key of its own;
its `from` bundle then leaves `pq` out):

```
(ct, SS) = ML-KEM-768.Encaps(PQSPK_b)
SK = HKDF(0xFF×32 ‖ DH1 ‖ DH2 ‖ DH3 ‖ SS ‖ SHA-256(PQSPK_b) ‖ SHA-256(ct),
          salt = 0×32, info = "IsolinkPQXDH", 32)
```

Without `kct` it is X3DH as above. An X3DH-only session moves to a hybrid one at the next message
once the peer's bundle has `pq`. A header for the same `spkId` without `pq: 1` (a device back on an
older app) makes the receiver drop that device's `pq` and stay on X3DH with it. A device that
receives a prekey message with `kct` answers at once with an empty session note
(`{k: "session", eids: []}`, a no-op for older apps), so the initiator stops attaching the
1.5 KB header after one round trip. ML-KEM is
`pqcrypto` 0.4.4 (pure Dart, pinned). The ratchet steps stay X25519 only, as in Signal's PQXDH.

### One-time prekeys

Newer devices also use one-time prekeys `OPK`, each an X25519 key and (usually) an ML-KEM-768 key
`OPQK` under a random 31-bit id. They come from three places:

- **Inside a session.** Each device gives each peer device three keys addressed to it alone, in a
  control payload `{k: "otk", keys: [{i, x, k?}], new?}`. A peer short of keys adds `oh: <count>`
  to what it sends. These are unsigned: they arrive inside an authenticated session.
- **From relays, for first chats.** A device keeps 20 keys on each relay it is a member of, each
  signed `Sig(IKsig, "isolink-one-time-prekey-v1" ‖ u32(id) ‖ x ‖ k)`, so the relay can't swap
  one in (see [Relay servers](#relay-servers)).
- **In an in-person QR code.** `meet` is now `secret16 ‖ u32(id) ‖ X25519 key` (52 bytes): an
  X25519-only key for whoever scans it.

The prekey header gains `o` (the id spent) and `ot: 1` (the sender takes one-time prekeys). With
`o`, `DH4 = DH(EK, OPK_b)` follows `DH3` in the secret, and the one-time ML-KEM key, if it has one,
replaces `PQSPK_b`:

```
SK = HKDF(0xFF×32 ‖ DH1 ‖ DH2 ‖ DH3 ‖ DH4 ‖ SS ‖ SHA-256(PQ key used) ‖ SHA-256(ct),
          salt = 0×32, info = "IsolinkPQXDH", 32)
SK = HKDF(0xFF×32 ‖ DH1 ‖ DH2 ‖ DH3 ‖ DH4, salt = 0×32, info = "IsolinkX3DH", 32)   with no ML-KEM
```

The responder deletes the private half once the first message opens and remembers the spent id
and the ephemeral that spent it for 30 days, so a replay that spends an `OPK` is refused. An
unknown or twice-spent id starts a new session and a fresh set of keys.

### Admission of new senders

The messenger also requires that a new sender's bundle is certified, and that its account is a
contact, our own, or a stranger within the stranger limits (see [Links](#links)).

**Vectors:** `session.x3dh` and the whole of `session` below.

## Double Ratchet

`crypto/ratchet.dart` follows the Signal Double Ratchet specification with these choices:

```
KDF_RK(rk, dh)  = HKDF(dh, salt = rk, info = "IsolinkRatchet", 64)        → (rk', ck)
KDF_CK(ck)      = (HMAC(ck, 0x02), HMAC(ck, 0x01))                        → (ck', mk)
message keys    = HKDF(mk, salt = 0×32, info = "IsolinkMessageKeys", 44)  → key[0..32], nonce[32..44]
header          = DHs ‖ u32(pn) ‖ u32(n)
ciphertext      = AEAD(key, nonce, plaintext, AD ‖ header)
```

- The initiator's first sending chain is `KDF_RK(SK, DH(DHs, SPK_b))`. The responder starts with
  `rk = SK`, `DHs = SPK_b` and no chains, and does a full DH step on the first message.
- Headers are not encrypted (no header encryption). On every path a header travels, it is inside
  a link's encryption or a carrier seal, so only the two ends see it.
- At most 1000 message keys are skipped in one chain step, and at most 2000 skipped keys are kept,
  oldest dropped first. A skipped key is deleted once used.
- Decryption runs on a copy of the state, which replaces the state only if the message opened. A
  bad message leaves the session as it was.
- The messenger writes ratchet state and the outbox to disk before any ciphertext is sent, so a
  crash can't reuse a message key.
- The plaintext the messenger gives the ratchet is the payload JSON, `pad`ded to 128 bytes.

**Vectors:** `session`. A Python Alice sends three messages; Isolink's Bob reads them out of order
(3rd before 2nd) from a fresh identity. A replay, a changed byte and a changed header fail and
leave the state alone. Isolink's code encrypts from a reference state and gets the reference
ciphertext byte for byte in both directions. Two DH steps follow: Alice reads Bob's two replies
out of order, then Bob reads Alice's next step.

## Envelopes

What a device queues for another device:

```json
{ "t": "env", "id": <random 16-byte hex>, "m": { "pk"?: …, "h": { "dh", "pn", "n" }, "c": … }, "p"?: <pod hash> }
```

`m` is the ratchet message. Inside it, the payload JSON's `k` names the kind: `text`,
`receipt`, `delivered`, `group`, `devices`, `sync-*` (only accepted from our own account), and
others. A chat message for someone else also carries `pod`, a random secret for
[delivery proofs](#delivery-proofs).

The sending device is known from the link the envelope arrived on (direct) or from the mailbox
tag it came under (carried). Envelope ids are de-duplicated (the last 5000 are remembered), so
the same envelope arriving directly and through a carrier is handled once.

## Links

Every transport (TCP on the LAN, Nearby Connections, Bluetooth GATT, a relay server circuit,
memory in tests) gives a reliable byte channel. Frames on it are `u32(length) ‖ body`, at most
4 MB plus 64 KB (`net/connection.dart`).

1. Each side sends `{"t":"hello","v":3,"eph":EPH}` with a fresh X25519 key. This is the only
   cleartext.
2. Both derive

   ```
   transcript = SHA-256("isolink-link-v3" ‖ EPH_initiator ‖ EPH_responder)
   (i2r, r2i) = HKDF(DH(eph, EPH_peer), salt = transcript, info = "isolink-link-keys", 64)
   nonce(n)   = 0×4 ‖ u64(n)        n counts frames in that direction from 0
   frame      = AEAD(key, nonce(n), padToBucket(utf8(json)), "")
   ```

   A frame carrying raw file bytes (when the peer said `bulk: 1`) is
   `0x00 ‖ u32(len(head)) ‖ head ‖ bytes`, padded with `pad` instead.
3. The dialler sends `{"t":"id","bundle","port","sig","bulk"}` with
   `sig = Sig(IKsig, "isolink-auth-v3" ‖ transcript ‖ "I")`.
4. The listener verifies the bundle and signature, then asks its admission policy. Only if the
   dialler is accepted does it send its own `id` with role `"R"`. A device turned away learns
   nothing about who it dialled. A device removed from our account is told so with a `removed`
   note first, because nothing else of ours will reach it any more.
5. The dialler checks the listener is the device it meant to dial (`expectedId`).

Admission (`Messenger._acceptInbound`):

- blocked accounts: never
- our own devices: unless removed
- contacts and group members: yes
- strangers: only while we are visible to everyone, or over our own relay server, and at most
  20 new strangers a day. A stranger may only say hello: at most 5 messages until added.
- an unlinked device waiting to be linked: anyone

Limits: 64 links, 12 handshakes at once, 12 attempts per host a minute, a 10-second handshake
timeout. Each link is rate-limited (300 frames/s and 24 MB/s with bursts of 600 frames and
48 MB) and closed if it floods; links between devices of one account, and a big file a person
tapped Get on over a local path, are not limited.

A device may be linked over several transports at once. Frames up to 16 KB go over every path
(over Bluetooth up to 2 KB while a faster path is open), and the far side keeps the first copy.

**Vectors:** `link` (transcript, both keys, both auth messages signed, nonces up to past 2^32,
a sealed `ping` each way).

## Discovery and tags

Every pair of devices that talk (our own devices, and every device of every contact who isn't
blocked) shares two static keys (`engine/pair_keys.dart`):

```
shared     = DH(IKdh_me, IKdh_them)
ids        = sorted(deviceId_me, deviceId_them) joined with ":"
beaconKey  = HKDF(shared, salt = "isolink-beacon",  info = ids, 32)
mailboxKey = HKDF(shared, salt = "isolink-mailbox", info = ids, 32)
beacon tag = hex(HMAC(beaconKey,  "beacon"  ‖ u32(⌊ms / 10 min⌋))[0..16])
mailbox tag= hex(HMAC(mailboxKey, "mailbox" ‖ u32(⌊ms / 6 h⌋))[0..16])
```

Both ends compute the same tags, in both directions.

- **Visible** devices announce their bundle on the LAN every 3 seconds, so anyone nearby sees
  their name and keys.
- **Hidden** devices (the default) announce only beacon tags, one per contact device, up to 40 a
  packet, and a mark `hex(HMAC(IKdh_priv, "isolink-beacon-mark" ‖ u32(period))[0..12])` that
  lets the device ignore its own packets. Over Nearby, a hidden device advertises a random name.
  A contact recognises a tag from this period or the last.
- An announcement only adds a *candidate* address. Only a completed handshake confirms one.

**Vectors:** `pairKeys` (both keys, the beacon and mailbox tag at a fixed time, the same from both
ends).

## Carrying

A device can hand envelopes for someone out of reach to any device it is linked to that agrees
to carry them (`Messenger._handToRelays`, `_acceptRelay`). That carrier passes them on when the
recipient comes into range.

Each envelope is sealed again, to the recipient device's identity key, so the carrier sees no
ratchet header or prekey bundle (`crypto/sealed_box.dart`):

```
E    = fresh X25519 key
k    = HKDF(DH(E, IKdh_recipient), salt = E, info = "isolink-relay-seal", 32)
s    = AEAD(k, 0×12, padToBucket(utf8(json(m))), ad = E)
item = { "t":"relay", "id", "tag": mailbox tag, "e": E, "s": s, "exp", "p"?: pod hash, "ack"? }
```

For mail posted to a relay box (see [Relay servers](#relay-servers)), the seal instead holds
`{tag, m, ack?}`, so nothing outside it names the pair either.

The seal does not authenticate the sender. The ratchet inside does, and the receiver only tries
the sessions of the device the mailbox tag belongs to.

When two devices link, each lists the tags it holds (`held`). A device recognises its own tags
(32 windows back, 8 days, and one ahead) and asks for them together with 3 decoy tags
(`fetch`), in random order. It acks what it takes; the carrier drops it.

| Who carries | Up to | For |
| --- | --- | --- |
| Our own devices and contacts | 1000 items and 64 MB in all, 200 items and 24 MB per holder | 7 days |
| Strangers, if *Carry for strangers* is on (default on) | 200 items and 20 MB in all, 20 items and 2 MB per holder, 60 hand-overs and 60 fetches an hour, 20 items a fetch | 48 hours |

A message goes to at most 3 trusted carriers and, if *Strangers may carry* is on (default on),
to at most 2 linked strangers as well, trusted ones first. A device stops taking items on when
its battery is low. What a relay server already holds for a recipient who uses it isn't given
to phones too.

**Vectors:** `relaySeal` (a seal to Bob's key with a fixed ephemeral, opened by Bob, refused by
Alice).

## Relay servers

A relay server (`server/`, and the one Isolink runs at `relay.isolink.app`) is reached over a
WebSocket over TLS, or with a pinned self-signed certificate (`p`, SHA-256 of its DER).

- **Sign-in.** The server sends a nonce. The device answers with its bundle and
  `Sig(IKsig, "isolink-relay-auth-v1" ‖ 0x00 ‖ nonce ‖ 0x00 ‖ lowercase(host))`. The host in it
  stops a malicious relay passing an answer on to another. The server checks the bundle
  verifies too. So **a relay server knows every signed-in device's bundle**: its keys, account,
  display name and kind.
- **Circuits.** `{"t":"open","c","to": deviceId}` opens a circuit to another signed-in device.
  An ordinary [link](#links) runs over it, so the server sees only that two devices talk, when,
  and how much.
- **Mail by device id.** `{"t":"drop","id","to": deviceId,"item","exp"}` leaves a
  [carried](#carrying) item for a device. Older apps and relays always do this; newer ones use
  boxes (below) where they can. The server holds it, sealed, until that device signs in and acks it, or for at
  most 7 days. Unlike a phone carrier, **a relay server is told the recipient's device id** and
  knows the sending device from its sign-in.
- **Boxes (sealed sender and hidden recipients).** On relays whose challenge says `boxes: 1`,
  newer devices post mail to a daily **box** over a connection that never signs in, so the relay
  is told neither the sender nor the recipient. Each device has a secret 32-byte `boxSeed`:

  ```
  key_w = HMAC(boxSeed, "isolink-box" ‖ u32(⌊ms / 1 day⌋))
  box_w = hex(SHA-256("isolink-box-id" ‖ key_w)[0..16])
  ```

  A device shares its box ids for yesterday to 15 days ahead inside session payloads
  (`bx: {w, b}`). Over an unsigned connection it opens its boxes with `{t: "boxes", id, pass,
  keys: [{w, k}], wake?}`, where `pass = hex(HMAC(relaySecret, "isolink-box-pass" ‖
  u32(⌊ms / 7 days⌋))[0..16])` is the members' pass every member's `welcome` carries (`bp`). A
  sender posts `{t: "post", id, box, item, exp}` with `item = {t: "sealed", id, e, s, exp, p?, wk}`,
  and can take it back with `unpost`, showing `secret = hex(HMAC(boxSeed, "isolink-box-withdraw|"
  ‖ id)[0..16])` where `wk = hex(SHA-256(secret)[0..16])`. Mail goes by device id (`drop`) only to
  a device that has given no boxes, at a relay without boxes, or to a box that isn't open.
- **One-time prekeys.** `{t: "otkPut", keys?, drop?}` from a member's own device stores signed
  one-time prekeys (up to 25 per device, 30 days). `{t: "otkTake", to}` from anyone hands out the
  oldest and deletes it: 3 per account per device per 10 minutes, 60 per connection an hour. The
  relay's `welcome` says `otk: 1`.
- **Pushes.** A phone may register a push token, so the server can wake it. A wake carries no
  content. With *Messages in notifications* on (off by default), a small sealed item rides in
  the push itself, so the push service sees its size.
- Relays can be self-hosted; an invite (`isolink-relay:`) carries the URL, an optional pin, a
  one-time token and optionally the relay's own key.

**Vectors:** `relayAuth`.

## Groups

There is no group key. A group message is encrypted separately, over each pairwise session, to
every device of every member who is a contact (`_enqueueToUser` per member). A group is
`{g: id, name, members: [contact cards], admins: [accountIds], v: version}`.

- A member accepts a group update only from an admin of the group as it knows it, and only with a
  higher version. A first update for a group it doesn't have must come from one of the update's
  own admins.
- Every member card in an update must verify with its whole chain. Members who aren't contacts
  are added as unsaved contacts from those cards, so **the admin vouches for every member's
  keys** to every other member.
- A message from someone who isn't a member, as this device knows the group, is held and the
  device asks the sender for the group's latest state.
- If no admin is left, every member picks the same successor: the longest-standing member.
- An update may carry `bots: {accountId: [hosts]}`: the members the admin knows as a community's
  bots, each with the hosts outside the community it passes messages to (an AI service). Members
  outside that community learn from it that a member is a bot. When someone adds one, the app tells
  the other members already in the group, once each, that what it reads leaves end-to-end
  encryption there. An update without
  it keeps what was known. It's the admin's word, informational only.

## Multi-device

- **Linking.** The new device shows a code with its unlinked bundle, a random 16-byte secret and
  its addresses. An existing device scans it, links to it, and sends `provision`:
  `AEAD(HKDF(DH(E, IKdh_new), salt = secret, info = "IsolinkProvision", 32), random nonce, json,
  ad = E)`. Inside: the current account key, a certificate for the new device, contacts, groups
  and settings. Every contact then gets the new device list (`devices`).
- **New devices of a contact.** A `devices` message, or any bundle seen on a link, adds a
  contact's device if it is certified by the account's current key, with no prompt and no change
  to the safety number.
- **Removing a device** rotates the account: a new account key, the chain extended, every
  remaining device re-certified and sent the new key (`sync-account`). Contacts that get the
  longer chain drop any device the new key doesn't certify, clear the verified mark, and show
  "safety number changed". Two chains that differ after a common start (a fork) are never
  accepted; the contact is warned.
- A removed device that dials one of the account's devices is turned away with a `removed` note
  carrying the newer chain, and erases itself only if that proves it.

## Files

- Up to 25 MB, a file is one **blob**: a fresh key and nonce, `AEAD(key, nonce,
  padToBucket(bytes), "isolink-blob")`. The key, nonce and SHA-256 travel inside the envelope;
  the ciphertext travels separately, in chunks, with `id = SHA-256(ciphertext)`.
- Bigger files are sealed in 256 KB **chunks** under one key used for that file alone
  (`crypto/chunks.dart`):

  ```
  nonce_i = nonce with u32(i) XORed into its last 4 bytes
  ad_i    = "isolink-chunk" ‖ u32(i) ‖ u32(count) ‖ (i == count-1 ? 0x01 : 0x00)
  chunk_i = AEAD(key, nonce_i, chunk padded with zeros to 256 KB, ad_i)
  ```

  A chunk moved, swapped, or offered as the end of a shorter file fails to open.

**Vectors:** `chunks`, `blob`.

## Verification

- **Safety numbers** (`crypto/safety_number.dart`), from the two current account keys:

  ```
  fp(K)  = iterate 5200 times: h = SHA-512(h ‖ K), from h = 0x00 0x01 ‖ K ‖ accountId(K)
  digits = for each of 6 five-byte pieces of fp: big-endian value mod 100000, 5 digits
  number = the two 30-digit halves, the lower accountId(K) first
  ```

  Note `accountId(K)` here is of the current key `K`, not the genesis key. The number stays the
  same when either person links a device, and changes when either removes one.
- **Scanning a code in person** carries a one-time `meet` secret only the showing screen knows,
  so both sides mark each other verified. Newer codes add a one-time prekey to it (52 bytes in
  all), and the proof HMAC is keyed by all 52 bytes.
- **Phone-to-phone check** (`engine/verify.dart`): a commit-then-reveal of a nonce from each side,
  turned into five emoji words from both account keys.

**Vectors:** `safetyNumber`.

## Storage, backups and recovery

- **At rest.** Each stored value is a file `AEAD(storeKey, random nonce, json, ad = key name)`,
  named by `SHA-256(storeKey ‖ key name)`. `storeKey` is 32 random bytes in the OS keychain
  (Keychain, Keystore, Credential Manager, Secret Service), or a 0600 key file where there is
  none. The web app keeps its state in IndexedDB **unencrypted**, protected by the browser
  profile.
- **Backups** (`storage/backup_file.dart`): Argon2id (46 MiB, 2 passes by default) from the
  passphrase, HKDF into a frame key, then sealed frames with a counter-and-last-flag nonce.
- **Relay backups** keep that file on a relay. Without a chosen passphrase, it is 192 random bits.
  It can also be opened by a **passkey** (WebAuthn PRF output → HKDF → a key that wraps the
  passphrase, kept beside the backup) or a password-manager entry.
- **Account recovery**, if turned on, also seals the account private key under a random recovery
  key, itself sealed under the passkey's PRF output, and keeps both on the relay.

## Updates

Release builds are signed with Ed25519 (`crypto/update_statement.dart`). Each download's
statement is `"isolink-update-v1\n" version "\n" file "\n" lowercase(sha256) "\n" size`. An app
takes an update from isolink.app or a relay only if that statement verifies under the built-in
release key, so no feed can pass an old build off as a newer one.

**Vectors:** `update`.

## Delivery proofs

A chat message carries a random secret `pod` inside the encryption, and its envelope's copies
carry `hex(SHA-256("isolink-pod|" ‖ pod)[0..8])`. When the recipient opens it, it hands the secret
to the carrier, which can then prove to anyone holding a copy that it arrived, so they drop it.
Carriers sign a pickup note (`"isolink-pickup|" id "|" fingerprint`) with their device key for the
relay the sender named.

**Vectors:** `deliveryPod`.

## How this compares with Signal

The README used to say "the same design as Signal". For the apps on main in November 2026 it is
closer to say: **Signal's 2016-era X3DH and Double Ratchet, without one-time prekeys, with Isolink's
own multi-device, transport and metadata design around them.** The next release brings key
agreement close to Signal's today (PQXDH with one-time prekeys) and sealed sender for relay mail.
The differences:

| | Signal today | Isolink |
| --- | --- | --- |
| Key agreement | PQXDH (X25519 + ML-KEM), with one-time prekeys | Main: X3DH, X25519 only, **no one-time prekeys**. Next release: PQXDH with one-time prekeys from sessions, relays and QR codes; a first chat with none of those still has no one-time prekey |
| Identity key | One key, XEdDSA for signatures | Separate Ed25519 signing and X25519 DH keys |
| Message encryption | AES-256-CBC + HMAC-SHA256 | AES-256-GCM, key and nonce from HKDF of the message key |
| Header encryption | No (sealed sender hides the sender from the server) | No, but headers only travel inside link or carrier encryption |
| Sender privacy from the server | Sealed sender; the server knows the recipient | Main: none, a relay server knows both device ids. Next release: sealed sender and hidden recipients for box mail, except that a relay can match a woken phone's push token to its box. Live circuits still name both devices. Phone carriers see only tags. |
| Multi-device | Linked devices, one identity key per account | An account key chain that certifies each device, shared by every device |
| Groups | Sender keys / group credentials | Pairwise fan-out, admin-signed membership |
| Prekey server | Signal's servers | None: bundles travel in contact codes, links and messages |
| Outside review | Formal analyses and audits | **None yet** |

None of these is necessarily a weakness for Isolink's setting; what each one costs is in
[threat-model.md](threat-model.md).
