feat(auth): implement SEP-10 wallet authentication (#778) - #1087
Open
ogbemercyada-sketch wants to merge 1 commit into
Open
ogbemercyada-sketch wants to merge 1 commit into
ogbemercyada-sketch wants to merge 1 commit into
Conversation
Add a full SEP-10 challenge-response authentication flow for the
Stellar Bounty Board backend, replacing ad-hoc header-based address
trust on protected routes.
Changes:
- backend/src/services/sep10Auth.ts: SEP-10 challenge builder and
verifier using @stellar/stellar-sdk WebAuth API, plus a zero-
dependency HMAC-SHA256 JWT implementation for session tokens.
- backend/src/routes/auth.ts: new router mounted at /api/auth
GET /api/auth/challenge?account=G... — issues a signed challenge
POST /api/auth/verify — verifies signed challenge,
returns JWT
- backend/src/middleware/sep10Session.ts: requireSep10Auth() middleware
that validates Bearer JWTs and sets req.signerPublicKey on success.
- backend/src/app.ts: mount /api/auth router; replace all uses of
createStellarSignatureAuthMiddleware() with requireSep10Auth() on
release, refund, cancel, dispute, notes, and extend-deadline routes.
- backend/test/sep10Auth.test.ts: 27 tests covering challenge build,
verify, replay prevention, expiry, JWT helpers, HTTP endpoints, and
the full end-to-end flow.
- backend/test/authMiddleware.test.ts: update release/refund tests to
use Bearer JWT auth instead of legacy x-stellar-signature headers.
- backend/.env.example: document SERVER_SIGNING_SECRET, JWT_SECRET,
HOME_DOMAIN, and WEB_AUTH_DOMAIN.
Security properties:
- Expired challenges rejected (time-bound enforced by stellar-sdk)
- Replayed challenges rejected via SHA-256 nonce cache
- Wrong-key signatures rejected by verifyChallengeTxSigners
- JWT tampering rejected via timing-safe HMAC comparison
- JWT expiry enforced (24 h TTL)
Closes ritik4ever#778
|
@ogbemercyada-sketch is attempting to deploy a commit to the ritik4ever's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@ogbemercyada-sketch 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 branch has not been deployed
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
Replaces ad-hoc x-stellar-signature header trust on protected routes with a proper SEP-10
Stellar Web Authentication (https://stellar.org/protocol/sep-10) challenge-response flow backed
by short-lived JWTs.
What changed
New endpoints
┌────────┬───────────────────────────┬─────────────────────────────────────────────────────┐
│ Method │ Path │ Description │
├────────┼───────────────────────────┼─────────────────────────────────────────────────────┤
│ GET │ /api/auth/challenge?accou │ Issues a signed SEP-10 challenge transaction the │
│ │ nt=G... │ wallet must sign │
├────────┼───────────────────────────┼─────────────────────────────────────────────────────┤
│ POST │ /api/auth/verify │ Verifies the signed challenge and returns a JWT │
└────────┴───────────────────────────┴─────────────────────────────────────────────────────┘
New files
┌────────────────────────────────────────┬──────────────────────────────────────────────────┐
│ File │ Purpose │
├────────────────────────────────────────┼──────────────────────────────────────────────────┤
│ backend/src/services/sep10Auth.ts │ Core SEP-10 service — challenge build/verify, │
│ │ HMAC-SHA256 JWT (no external deps) │
├────────────────────────────────────────┼──────────────────────────────────────────────────┤
│ backend/src/routes/auth.ts │ Express router for GET /api/auth/challenge and │
│ │ POST /api/auth/verify │
├────────────────────────────────────────┼──────────────────────────────────────────────────┤
│ backend/src/middleware/sep10Session.ts │ requireSep10Auth() middleware — validates │
│ │ Authorization: Bearer │
└────────────────────────────────────────┴──────────────────────────────────────────────────┘
Modified files
createStellarSignatureAuthMiddleware() calls (release, refund, cancel, dispute, notes,
extend-deadline) with requireSep10Auth()
WEB_AUTH_DOMAIN
Authentication flow
GET /api/auth/challenge?account=GABC...
← { transaction: "", network_passphrase: "..." }
Client signs the transaction with its wallet keypair
POST /api/auth/verify { transaction: "", account: "GABC..." }
← { token: "", account: "GABC..." }
Protected route:
Authorization: Bearer
Security properties
Environment variables
SERVER_SIGNING_SECRET=S... # Stellar secret key for signing challenges (required in prod)
JWT_SECRET=... # HMAC secret for JWT signing (derived from SERVER_SIGNING_SECRET
if unset)
HOME_DOMAIN=your-domain.com # Appears in SEP-10 ManageData operation keys
WEB_AUTH_DOMAIN=... # Defaults to HOME_DOMAIN
Testing
wrong-key, JWT round-trip, tamper, expiry, all HTTP endpoints, and the full end-to-end flow
npm test
Closes
Closes #778