Repository navigation
Post-quantum content encryption: X-Wing keys throughout auth (protocol 5) - #43
Draft
holmesworcester wants to merge 7 commits into
Draft
holmesworcester wants to merge 7 commits into
holmesworcester wants to merge 7 commits into
Conversation
… to 0.8.4 - libsodium-wrappers-sumo ^0.7.13 -> 0.8.4 (libsodium 1.0.19 -> 1.0.22), pinned exactly. Drop @types/libsodium-wrappers-sumo: 0.8 ships its own typings. - Adapt two call sites to those typings (secretstream pull, base64 variants). Runtime behaviour is unchanged; a new test pins the stream error and passes on main too. - Add `kem`: boxes made with the X-Wing KEM (ML-KEM-768 + X25519) and XChaCha20-Poly1305, random or seeded key pairs, and key pair validation. Nothing in auth uses it yet, so no wire format changes. - Tests: the three X-Wing spec vectors, a box built by hand from a spec ciphertext (pins the format), tampering with each field, malformed and X25519 input, seeded keys. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every keyset's encryption keypair is now X-Wing (ML-KEM-768 + X25519),
used through `kem`. X25519 boxes are gone from the team protocol, so
nothing recorded today can be opened later by breaking X25519 alone.
- crdx: `createKeyset` makes X-Wing keypairs. A keyset is named by
`keyId`, a 32-byte BLAKE2b hash of its encryption public key, and
keyrings are indexed by it. Graph links are encrypted with the graph
keyset's symmetric key and carry `{ encryptedBody, signature, keyId }`;
`senderPublicKey` and `recipientPublicKey` are gone. Building a link a
member will decrypt now takes the team's secret key.
- Lockboxes: the payload is a `kem` box to the recipient's X-Wing public
key; the ephemeral `encryptionKey` field is gone. Recipient and
contents manifests name keys by `keyId` (manifest version 2), and
`lockbox.create` needs the recipient's keys, not a manifest.
`lockbox.rotate` takes the recipient's keys.
- Invitations: `roleGrantPublicKey` becomes `roleGrantKeyId`;
`encryptionPublicKey` stays a full X-Wing public key.
- Invitation acceptance: encrypted with `kem` to the invitation key, and
signed by the sending device (or server) under the new
INVITATION_ACCEPTANCE context. The invitee verifies the signature
under the key the delivered graph registers for that device. The
outer payload is `{ version, senderDeviceId, encryptedAcceptance,
signature }`.
- Connection session keys: each side encrypts its seed to the other's
X-Wing public key.
- Key rotation (disabled in this release): each role's new keys go to
the admin role, whose public key only admins now hold, so only an
admin can rotate role keys. Removal producers refuse disabled actions
before rotating.
- CONNECTION_PROTOCOL_VERSION 4 -> 5, so older peers are refused at
REQUEST_IDENTITY.
- Sync server: JSON body limit raised to 10 MB; a new team's graph is
over the 100 KB default with X-Wing keys.
Breaking: no migration. Existing teams, graphs and lockboxes can't be
read by this version.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An X-Wing public key is 1,660 base58 characters, and base58 decoding is quadratic: about 1 ms with WebAssembly and about 28 ms without it (iOS). The same public keys were decoded again on every keyset validation and lockbox, which made adding a member ~10x slower than before X-Wing (26 ms vs 2.7 ms). keyToBytes now keeps recent decodings of 128 to 2,048 character strings (public keys and short ciphertexts; secret keys are at most 88 characters) and returns a copy each time. Adding a member: 9 ms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This reverts commit e3f4c17. Adding a member in 26 ms instead of 9 ms is acceptable; the cache is not worth its code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
base58 decoding takes time that grows with the square of the length. For an X-Wing public key (1,216 bytes) it took 1.6 ms, or 28.5 ms without WebAssembly (iOS), and adding a member decoded one about 15 times. base64url, through libsodium, takes 8 µs (0.18 ms without WebAssembly). Adding a member drops from 26 ms to 2.5 ms, about what it took before X-Wing. - @localfirst/crypto: new `base64` (URL-safe, no padding, strict: padding, `+`/`/` and non-zero unused bits are rejected, so each byte string has one encoding). `keyToBytes`, key pairs, `hash`, signatures and the string forms of `symmetric`, `asymmetric` and `kem` use it; `randomKey` returns base64url. Renamed: `Base58` -> `Base64`, `Base58Keypair` -> `Base64Keypair`, `keypairToBase58` -> `keypairToBase64`, `isBase58KeyOfLength` -> `isBase64KeyOfLength`. - base58 stays for strings people read or type: invitation seeds (`randomSeed`) and automerge-repo share ids, now the base58 of the team id's bytes. - auth validators check ids, nonces and signatures with `base64.detect`. Breaking: every key, id, hash and signature changes encoding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- keyId hashes the public key on every call. Hashing a base64url key is cheap, and adding a member still takes 2.6 ms without the cache. - The malformed-key tests in lockbox.test and keypairValidation.test still built their bad keys with base58. Those strings mostly failed to decode as base64url, so the tests passed without reaching the length and key-pair checks they name; and about 1 time in 8, a base58 string of 31 bytes decoded as a valid 32-byte key, which failed lockbox.test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Team registration (`POST /teams`) sent the serialized graph through JSON.stringify as a Uint8Array, which JSON writes as an object with one entry per byte: about 11 times the graph's size. With X-Wing keys a 20-member team's request was about 3.1 MB, and a team of about 65 members was over the server's 10 MB limit. As base64url the request is about 1.33 times the graph, so 10 MB fits several hundred members. - The client sends `serializedGraph` as base64url; the server decodes it with `base64.decode`. `objectToUint8Array` is gone, and `@localfirst/crypto` moves to the server's dependencies. - `registerTeam` now throws if the server refuses the registration. It used to ignore the response, so a refused registration only showed up as the client never authenticating. Breaking: a client and a sync server must both use this format. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces X25519 with X-Wing (ML-KEM-768 + X25519) everywhere auth encrypts to a public key. Today, someone who copies a team's graph, its lockboxes or a recorded invitation could open them once X25519 can be broken ("harvest now, decrypt later"). After this change they would also have to break ML-KEM-768.
This is a breaking release. The connection protocol moves from 4 to 5. Keysets, graph links, lockboxes and invitation acceptances all change format, and keys, ids, hashes and signatures are now written in base64url instead of base58. There is no migration: existing teams can't be read by this version.
What changes
@localfirst/crypto^0.7.13→0.8.4(libsodium 1.0.19 → 1.0.22), pinned exactly.@types/libsodium-wrappers-sumois removed, because 0.8 ships its own typings. Two call sites were adapted to the new typings; their behaviour is unchanged.kemmodule. It boxes a payload for an X-Wing public key, ascrypto_box_sealdoes for X25519:'lf/crypto/xwing-box/v1'.{ kemCiphertext, nonce, message }.kem.keyPair(seed)derives the X-Wing seed fromstretch(seed)under its own context.INVITATION_ACCEPTANCE.base64helper: URL-safe, no padding, through libsodium. Decoding is strict: it rejects padding,+and/, and unused bits that aren't zero, so each byte string has exactly one encoding. Key ids hash the encoded string, so this keeps one key from having two ids.keyToBytes, key pairs,hash, signatures,randomKeyand the string forms ofsymmetric,asymmetricandkemuse it.Base58→Base64,Base58Keypair→Base64Keypair,keypairToBase58→keypairToBase64,isBase58KeyOfLength→isBase64KeyOfLength.base58stays for strings people read or type: invitation seeds (randomSeed) and the automerge-repo share id, which is now the base58 of the team id's bytes.@localfirst/crdxencryptionkeypair of every keyset is now an X-Wing keypair. Its public key is 1,216 bytes and its secret key is the 32-byte X-Wing seed.keyId(keys), a 32-byte BLAKE2b hash of its encryption public key. Keyrings are indexed by key id.secretKey.{ encryptedBody, signature, keyId };senderPublicKeyandrecipientPublicKeyare gone.@localfirst/authkembox to the recipient's X-Wing public key. The ephemeralencryptionKeyfield is gone.keyId; the manifest version is now 2.lockbox.createneeds the recipient's keys and no longer accepts a manifest.lockbox.rotatetakes the recipient's keys.roleGrantPublicKeybecomesroleGrantKeyId.encryptionPublicKeystays a full X-Wing public key, because acceptances are encrypted to it.kembox as lockboxes, and the signature is the same Ed25519signatures.signused for link signatures and identity challenges, under its own context.{ version, senderDeviceId, encryptedAcceptance, signature }.POST /teams).Uint8ArrayinsideJSON.stringify, which JSON writes as one object entry per byte, about 11 times the graph's size.registerTeamnow throws if the server refuses the registration. It used to ignore the response.Cost
Team sizes and timings were measured with WebAssembly on a Linux x86-64 machine. "Before" is this PR's first commit, which added
kembut kept X25519 keysets.With base58, adding a member took 26 ms (about 0.4 s without WebAssembly), nearly all of it decoding keys. Most of the added size is the X-Wing public keys, as text. Each lockbox carries one inside its payload, as part of the keyset it delivers.
Single operations:
node --jitless, the iOS path)crypto_box_easy, for comparisonTests
The whole suite passes on Node 24.13 and Node 20.20: 881 passed and 87 skipped.
maingives 816 passed and 87 skipped.kem:@noble/post-quantum.keyIdis the same for a keyset, its public half and its public key.{ encryptedBody, keyId, signature }.+and/, non-zero unused bits, whitespace and impossible lengths are rejected.CheckedKeyStoreCheckedKeyStoretsc --noEmiton the auth test files reports 37 errors, all on lines this PR doesn't touch (for example theADD_LOCKBOXEStest actions). Vitest doesn't type-check, so they don't fail CI.Before Quiet can take this
None of this is in this PR. These changes belong in TryQuiet/quiet:
node --jitlessitsreadyrejects.resolve.aliasfromlibsodium-wrappers-sumoto the CommonJS entry. I verified it loads and runs X-Wing jitless.packages/backend/platform, pinned to 1.0.19) needs to be rebuilt at 1.0.22 with X-Wing. Otherwise iOS silently falls back to JS.kem: DM key boxes and user-scope encryption in the backend.Base58type, or checks or decodes auth keys, ids or hashes as base58, needs to change. Ids can now contain-and_. Invitation seeds stay base58.Not in this PR
quiet-sandboxdemo still calls X25519 boxes on keyset keys. Its build is already disabled ("unmaintained, not shipped, not consumed by Quiet").🤖 Generated with Claude Code