Skip to content

feat(auth): implement SEP-10 wallet authentication (#778) - #1087

Open
ogbemercyada-sketch wants to merge 1 commit into
ritik4ever:mainfrom
ogbemercyada-sketch:feat/sep10-wallet-auth
Open

ogbemercyada-sketch wants to merge 1 commit into
ritik4ever:mainfrom
ogbemercyada-sketch:feat/sep10-wallet-auth

Conversation

@ogbemercyada-sketch

Copy link
Copy Markdown

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

  • backend/src/app.ts — mounts /api/auth; replaces all six
    createStellarSignatureAuthMiddleware() calls (release, refund, cancel, dispute, notes,
    extend-deadline) with requireSep10Auth()
  • backend/test/authMiddleware.test.ts — updated release/refund tests to use Bearer JWT auth
  • backend/.env.example — documents SERVER_SIGNING_SECRET, JWT_SECRET, HOME_DOMAIN,
    WEB_AUTH_DOMAIN

Authentication flow

  1. GET /api/auth/challenge?account=GABC...
    ← { transaction: "", network_passphrase: "..." }

  2. Client signs the transaction with its wallet keypair

  3. POST /api/auth/verify { transaction: "", account: "GABC..." }
    ← { token: "", account: "GABC..." }

  4. Protected route:
    Authorization: Bearer

Security properties

  • Expired challenges — rejected via WebAuth.readChallengeTx time-bound check
  • Replayed challenges — rejected via SHA-256 nonce cache (TTL = 2× challenge window)
  • Wrong-key signatures — rejected by WebAuth.verifyChallengeTxSigners
  • JWT tampering — rejected via timing-safe HMAC-SHA256 comparison
  • JWT expiry — 24 h TTL, enforced on every request

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

  • 27 new tests in test/sep10Auth.test.ts covering: challenge build, verify, expired, replayed,
    wrong-key, JWT round-trip, tamper, expiry, all HTTP endpoints, and the full end-to-end flow
  • Updated test/authMiddleware.test.ts — 7/7 passing with new SEP-10 JWT auth

npm test

Closes

Closes #778

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
@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

@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.

@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SECURITY] Add SEP-10 challenge/response wallet authentication flow

1 participant