Cryptography
All of this lives in packages/shared/src/crypto.ts. It is around 200 lines and uses four audited primitives from the @noble libraries. There are no native modules, so the same code runs on iOS, Android, web and Node, and the tests in crypto.test.ts exercise the real implementation.
Primitives
Section titled “Primitives”| Job | Primitive | Why |
|---|---|---|
| Identity and key agreement | X25519 | Small keys (32 bytes fit in a QR code), fast, the standard choice. |
| Key derivation | HKDF-SHA256 | Turns the raw shared secret into purpose-bound keys with domain separation strings. |
| Message encryption | XChaCha20-Poly1305 | Authenticated encryption with a 24 byte nonce, so random nonces are safe without counters. |
| Passphrase stretching | scrypt (N=2^15, r=8, p=1) | For sealed messages. Slow enough to blunt guessing, fast enough on a phone (~100 ms). |
Identity keypair. Generated on first launch, stored in Keychain / Keystore (expo-secure-store, WHEN_UNLOCKED_THIS_DEVICE_ONLY). The public half is uploaded to the profile and put in the pairing QR code. The private half never leaves the device.
Pair key. Both phones compute:
shared = X25519(my_secret, their_public)salt = sort(my_public, their_public) // canonical order so both agreepairKey = HKDF(shared, salt, "filocan/pair/v1", 32)Binding the two public keys into the salt means the pair key is specific to this exact pair of identities. It is stored in the secure store and is the only long-lived secret.
Message keys. Every envelope gets a fresh random 24 byte nonce and a key derived from it:
key = HKDF(pairKey, nonce, "filocan/msg/v1", 32)ct = XChaCha20-Poly1305(key, nonce, aad).encrypt(plaintext)Safety string. Six groups of five digits derived from the pair key (HKDF(pairKey, "filocan/safety/v1")). Both phones show it on the Us tab. If they match, no one sat in the middle of the pairing.
Authenticated headers
Section titled “Authenticated headers”The relay needs to see some metadata to route and sort messages: pair id, message id, sender, kind, timestamp. Those are put in the AEAD’s additional authenticated data (aadFor() in protocol.ts):
"1|<pairId>|<id>|<from>|<kind>|<ts>"So the relay can read them but cannot change them. Relabelling a chat message as a system message, swapping the sender, or moving a message to another pair makes decryption fail. The tests cover each of these.
Sealed messages
Section titled “Sealed messages”A second layer under a passphrase both people know. The passphrase is NFKC-normalised, trimmed and lowercased (so ’Cafe Roma ’ and ‘cafe roma’ match), stretched with scrypt using a random 16 byte salt, then combined with the pair key:
pw = scrypt(normalise(passphrase), salt)key = HKDF(pairKey || pw, salt, "filocan/seal/v1", 32)Both the pair key and the passphrase are needed. Someone with the phone but not the passphrase cannot open it; someone with the passphrase but not the phone cannot either.
What the relay can see
Section titled “What the relay can see”- Two user ids, two public keys, the time they paired, the time they unpaired.
- For each message: its id, sender, kind (chat, list, plan, sealed, nudge, system), sender timestamp, and the ciphertext length.
- Phone numbers, because Supabase Auth holds them for OTP. They are never exposed to the other user.
What it cannot see: any message content, list item, plan, sealed note or passphrase.
Known limits and roadmap
Section titled “Known limits and roadmap”- No forward secrecy yet. One long-lived pair key means a compromised phone can decrypt history the relay still holds. Mitigations today: history is capped, ending the pair deletes it. Roadmap: a Double Ratchet over the pair key (the pair key becomes the root key). The envelope has a version field for this.
- Web is weaker. The server serves the JavaScript, so a malicious deploy could exfiltrate keys. That is why the phone is the root of trust and the web session is a revocable linked device.
- Metadata. The relay learns timing and volume. Filocan does not try to hide that two people talk.