Implement SEP-10 authentication middleware#175
Conversation
12854e8 to
c65f1e6
Compare
ogazboiz
left a comment
There was a problem hiding this comment.
hey! thanks for the solid implementation of the SEP-10 auth middleware. the documentation looks great and the logic seems sound for a first pass.
however, the CI checks are currently failing on several fronts (Backend, Frontend, and Dependency Scan). could you take a look at the logs in the "Checks" tab and see what's causing the break?
also, it looks like there might be some unrelated changes or conflicts in the package-lock.json. it would be great if you could clean that up while you're at it!
let us know once CI is green and we'll do a final review.
- Add authMiddleware to verify Stellar signed messages - Extract Bearer token from Authorization header - Verify signature against public key using stellar-sdk - Attach req.user object to authenticated requests - Support both testnet and mainnet configurations - Add optionalAuthMiddleware for endpoints with optional auth - Create /v1/users/me protected endpoint as example - Return in-memory user if database record doesn't exist - Add BearerAuth security scheme to Swagger - Create comprehensive AUTHENTICATION.md documentation Implements issue LabsCrypt#74 acceptance criteria: ✅ Extract token from Bearer header ✅ Verify signature against public key ✅ Attach req.user object to request ✅ Independent of database (creates in-memory user if missing)
- Fix type error in auth.middleware.ts (Bearer token extraction) - Fix Prisma import in error.middleware.ts (use generated client) - Fix ZodError.errors to ZodError.issues - Fix req.params type safety in user.controller.ts - Add missing vitest and supertest dependencies
- Fix sandbox.ts: Use conditional property assignment for optional databaseUrl - Fix stream.controller.ts: Add explicit type assertion for req.params - Fix sandbox.middleware.ts: Fix void return type by splitting return statements - Fix prisma-sandbox.ts: Remove unsupported datasources config (Prisma 7) All TypeScript errors resolved - build passes successfully.
Regenerated package-lock.json cleanly from upstream/main to remove merge conflicts and unrelated dependency changes. Only includes Stellar SDK dependencies needed for auth middleware: - @stellar/stellar-sdk - stellar-sdk (legacy) - vitest and supertest (test dependencies)
17abc35 to
3b6a279
Compare
The project uses npm workspaces with a single root package-lock.json, but the CI was looking for workspace-specific package-lock.json files that don't exist (frontend/package-lock.json, backend/package-lock.json). Changes: - Remove cache-dependency-path (uses root package-lock.json by default) - Run 'npm ci' from root (installs all workspaces) - Keep working-directory for build/lint/test commands This fixes the 'Some specified paths were not resolved' cache error.
Add --include=optional flag to npm ci to ensure rollup's platform-specific binaries are installed correctly on Linux. This fixes the 'Cannot find module @rollup/rollup-linux-x64-gnu' error that occurs when vitest tries to run tests.
Frontend build was failing with missing lightningcss native binaries. Adding --include=optional ensures platform-specific optional dependencies like @next/swc-linux-x64-gnu and lightningcss.linux-x64-gnu.node are properly installed on CI runners.
- Install lightningcss platform-specific binaries (darwin-arm64, linux-x64-gnu) - Fix dashboard-view.tsx: Replace getMockDashboardStats with fetchDashboardData - Add proper state management for dashboard data loading - Fix dashboard.ts: Import WalletId type and update mock data structure - Update DashboardSnapshot to use outgoingStreams/incomingStreams
Resolve conflicts by: - Keeping SEP-10 auth middleware implementation - Keeping updated Stellar SDK v14.5.0 for auth support - Merging both getUserEvents (from upstream) and getCurrentUser (from auth) - Accepting upstream frontend changes (stream details, cancel, top-up flows) - Accepting upstream backend changes (Soroban event worker, activity history)
ogazboiz
left a comment
There was a problem hiding this comment.
hey, thanks for the contribution!
just had a look at this — the backend and frontend CI checks are currently failing and there are merge conflicts with main.
could you pull the latest changes, resolve the conflicts, and take a look at the workflow logs under the "Checks" tab to fix the failing steps?
once that's sorted let us know and we'll take another look — happy to help if you get stuck! if you want to contribute more or follow up if issues are open, join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0
- Fix stream.controller.ts: Use proper parameter validation from upstream - Fix user.controller.ts: Add type assertion for publicKey parameter - Fix soroban-event-worker.ts: Use stellar-sdk v13 for RPC compatibility - Auth middleware uses @stellar/stellar-sdk v14 for SEP-10 support
Description
Implements Stellar-based authentication middleware using signed transactions (SEP-10 pattern) to verify wallet ownership and secure API endpoints. The middleware extracts Bearer tokens from request headers, verifies Stellar signatures using stellar-sdk, and attaches authenticated user information to requests.
Type of Change
Related Issues
Closes #74
Changes Made
New Files
src/middleware/auth.middleware.ts- Core authentication middleware with signature verification logicauthMiddleware- Requires valid authentication (returns 401 if missing/invalid)optionalAuthMiddleware- Allows requests with or without authenticationsrc/types/auth.types.ts- TypeScript type definitions for authenticationAuthUserinterface - Authenticated user shapeAuthenticatedRequestinterface - Express request with user attacheddocs/AUTHENTICATION.md- Comprehensive authentication documentation with examplesModified Files
src/routes/v1/user.routes.ts- Added protectedGET /v1/users/meendpoint as examplesrc/controllers/user.controller.ts- AddedgetCurrentUsercontrollersrc/config/swagger.ts- Added BearerAuth security scheme to OpenAPI specpackage.json- Added@stellar/stellar-sdkdependency for signature verificationKey Implementation Details
✅ Extract token from Bearer header - Validates
Authorization: Bearer <xdr>format✅ Verify signature against public key - Uses stellar-sdk to cryptographically verify transaction signatures
✅ Attach req.user object - Adds
{ publicKey, id? }to request for downstream use✅ Database independence - Creates in-memory user if DB lookup fails (never blocks on missing DB record)
Additional Features
STELLAR_NETWORKenvironment variableTesting
Test Coverage
Test Steps
Manual Testing Performed:
Valid Authentication
GET /v1/users/mewithAuthorization: Bearer <xdr>Missing Token
Invalid Signature
Database Independence
Network Configuration
STELLAR_NETWORK=testnetTo Test This PR:
npm run devcurl -X GET http://localhost:3001/v1/users/me \ -H "Authorization: Bearer <your_signed_transaction_xdr>"Breaking Changes
None - This is a new feature that adds authentication capabilities without modifying existing endpoints.
Screenshots/Demo
N/A - Backend API feature
Checklist
Additional Notes
Security Considerations
Documentation
Complete usage guide available in docs/AUTHENTICATION.md including:
Future Work