This patch adds a production-oriented foundation for the next E2EE stage:
- prekey bundles via
UserDevice+OneTimePreKeyand/api/e2ee/prekey-bundle/[userId] - multi-device support via
/api/e2ee/devicesand/api/e2ee/devices/register - forward secrecy foundation via reserved/consumed one-time prekeys and per-session root/chain/message key references
- ratchet layer foundation via
ratchetPublicKeyand helper functions inlib/e2ee-phase4.ts - secure key lifecycle via
E2EEKeyEventaudit records and device/prekey rotation metadata
- This patch intentionally adds a server-side foundation rather than claiming full Signal-grade Double Ratchet correctness.
- Sensitive key material remains client-owned; the server only stores public bundles, key references, and lifecycle metadata.
- Session bootstrap now consumes one-time prekeys when available and records a session lifecycle event.
- Existing legacy/v2 users still work; phase4 is additive and device-first.
GET /api/e2ee/devicesPOST /api/e2ee/devices/registerGET /api/e2ee/prekey-bundle/[userId]?deviceId=POST /api/e2ee/sessions/bootstrap
Apply:
npx prisma migrate deploynpx prisma generate