feat: device-aware JWT auth, prekey upload, key fingerprint endpoint, and AI agent CI#212
Open
Themancalledpg wants to merge 4 commits into
Open
Conversation
…e on every request (codebestia#158)
|
@Themancalledpg Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great 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
This PR implements device-aware authentication by extending JWTs with
deviceId, adds the prekey batch upload endpoint for end-to-end encrypted messaging, exposes a safety-number key-fingerprint endpoint for key verification, and adds a GitHub Actions CI workflow for theai_agentmodule.closes #158
closes #159
closes #162
closes #150
Changes
JWT + socket auth carry
deviceIdand validate device state #158 — JWT + socket auth carrydeviceIdand validate device state: ExtendedsignTokento includedeviceIdin the token payload. Added adevicestable to the schema (userId,identityPublicKey,isRevoked). Updated HTTP auth middleware to verify the(userId, deviceId)pair exists and is not revoked (401 otherwise). Updated Socket.IO middleware similarly — socket identity is bound from the verified token, never from event payloads. Legacy tokens missingdeviceIdare rejected with 401. ThePOST /auth/verifyendpoint now acceptsidentityPublicKeyto register or look up the device and embed its id in the returned JWT.POST /devices/:id/prekeys— upload a prekey batch #159 —POST /devices/:id/prekeys— upload a prekey batch: Implemented prekey upload endpoint accepting{ signedPreKey: { keyId, publicKey, signature }, oneTimePreKeys: [{ keyId, publicKey }] }. Validates signed prekey signature against the device'sidentityPublicKeyusing Node'sEd25519verifier (400 on bad signature). Upserts the signed prekey (one per device via unique index), inserts OTPs withonConflictDoNothingby(deviceId, keyId), caps stored OTPs per device at 200, and enforces device-owner-only access (403 otherwise).Safety-number / key-fingerprint endpoint (key verification) #162 — Safety-number / key-fingerprint endpoint: Implemented
GET /users/:id/key-fingerprint. Retrieves all active device identity public keys for a user, sorts them lexicographically, concatenates with\n, computes SHA-256, and formats as a 60-digit safety number in two 30-digit halves (matching Signal's safety number convention). Returns both the raw 60-digit string and a space-separated "groups of 5" display format. Derivation algorithm documented in code comments for client interoperability.Create GitHub Actions CI workflow for
ai_agent#150 — GitHub Actions CI forai_agent: Created.github/workflows/ai-agent-ci.ymltriggered on push/PR changes toapps/ai_agent/**or the workflow file. Usesastral-sh/setup-uv@v5withuv.lockcache, runsuv sync --extra dev, thenuv run pytest --cov=main --cov-report=xml. Uploads coverage to Codecov withcontinue-on-error: trueand posts a Markdown coverage summary to the job summary.Test plan
deviceIdin payload, legacy-token rejectionidentityPublicKeyrequired in verify, device revocation path, new-device-for-existing-user pathusers.test.tsupdated:db.query.devicesmocked,signTokencalls includedeviceIddevices.prekeys.test.ts: ownership, revocation, bad signature, OTP cap, batch trim, success pathusers.fingerprint.test.ts: determinism, 60-digit format, groups-of-5 display, empty-device 404, no-user 404