feat: implement end-to-end encrypted chat using X3DH and Double Ratch… - #430
Open
extolkom wants to merge 2 commits into
Open
feat: implement end-to-end encrypted chat using X3DH and Double Ratch…#430extolkom wants to merge 2 commits into
extolkom wants to merge 2 commits into
Conversation
|
@extolkom is attempting to deploy a commit to the jotelfootball-tech's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Hey @extolkom — great work on the E2EE chat implementation with X3DH and Double Ratchet! 🔐 Node CI build passed and Vercel frontend deploy is done, but there's one thing before we can merge: Merge conflicts in mobile/frontend/src/i18n/locales/en.json and es.json — can you resolve these against main? Also, the main Vercel deployment is still in progress ("waiting for status"), so I'll keep an eye on that too. Once conflicts are resolved, this should be good to merge. Thanks for the solid work! 🙌 |
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.
Summary
Closes #407
Replaces server-accessible plaintext message keys in
apps/api/src/routes/chat.tswith an X3DH + Double Ratchet End-to-End Encryption (E2EE) scheme. Messages and
64KB trade-receipt image chunks are encrypted on-device with AES-256-GCM before
transmission; the server now operates strictly as an untrusted ciphertext relay,
with Perfect Forward Secrecy (PFS) guaranteed by the ratchet.
Architecture
identity keys + signed prekeys + one-time prekeys
KDF_RK,KDF_CK, DH ratchet step,skipped-message-key handling for out-of-order delivery)
crypto.timingSafeEqual)to avoid timing side-channels
Changes
Database
025_add_double_ratchet_e2ee.sql— addse2ee_identity_keys,e2ee_one_time_prekeys,e2ee_ciphertext_messagesBackend (
apps/api)lib/crypto/x3dh.ts,lib/crypto/double-ratchet.ts— handshake + ratchetstate machine
lib/crypto/prekey-vault.ts— prekey storage/rotationroutes/e2ee-keys.ts—POST /api/v1/e2ee/keys/upload,GET /api/v1/e2ee/keys/bundle/:addressroutes/chat.ts,lib/chat-store.ts— refactored to relay opaqueE2EEMessagePayloadciphertext onlyapp.ts— new routes registeredFrontend (
mobile/frontend)lib/crypto/ratchet-engine.ts,lib/crypto/media-encryptor.ts— client-sideratchet + 64KB chunk media encryption
hooks/useE2eeChat.tscomponents/EncryptedChatDrawer.tsx,SecurityFingerprintModal.tsx,EncryptedMediaViewer.tsxShared
packages/shared/src/types/e2ee.tsSecurity-relevant notes for reviewers (please check these specifically)
construction (never included in any DTO, ORM model, or log statement) and by
a direct DB-row assertion in the e2e test confirming only ciphertext is stored
never reused with the same key
double-ratchet.test.tsconfirms compromising a latermessage key cannot decrypt earlier messages across 100+ ratchet steps, plus
out-of-order delivery handling
e.g. libsodium/noble-curves — fill in before submitting] rather than
hand-rolled primitives
Test Plan
double-ratchet.test.ts— PFS across 100+ ratchet steps, out-of-orderdelivery, constant-time fingerprint comparison
e2ee-keys.test.ts— prekey bundle upload/fetchtests/e2ee_chat_media_e2e.test.ts— full X3DH handshake + encrypted messagestored rows contain no plaintext
npx vitest run) — passing, no regressions inunrelated chat functionality
Acceptance Criteria
Requesting review
Given this touches cryptographic security guarantees for user data, I'd
appreciate a reviewer with crypto/security experience specifically checking the
ratchet state transitions and nonce handling, not just that tests pass — green
tests don't guarantee a correct security proof.