🔴 Priority: Critical
Difficulty: Hard
Estimated Effort: 3-4 days
Relevant Files: src/services/stellar.service.ts, src/controllers/bot.controller.ts, src/routes/bot.routes.ts
Labels: security, enhancement, priority:critical, stellar
Requirements
-
SEP-10 Challenge-Response Implementation
Implement the full SEP-10 authentication flow to cryptographically prove wallet ownership before any financial operation:
-
Clock Skew Tolerance
- Handle up to 60 seconds of clock skew between the server and the Stellar ledger
- Log a warning if clock skew exceeds 30 seconds
- Reject challenges where
now - threshold > tx.timeBounds.min or tx.timeBounds.max > now + threshold
-
Network Resilience
- Circuit breaker pattern for Horizon API calls: if Horizon returns 5xx or times out 3 times consecutively, stop making requests for 30 seconds
- Timeout handling: Horizon calls must timeout after 5 seconds. Return
503 Service Unavailable if Horizon is unreachable
- Retry logic: Retry failed Horizon signature verification up to 2 times with exponential backoff (1s, 2s)
-
Network Awareness
- Support both testnet and mainnet network passphrases via
config.STELLAR_NETWORK
- The auth server account must be different for testnet vs mainnet
- Network passphrase must come from config, not hardcoded
-
Security Hardening
- Challenge nonces must be at least 32 bytes of
crypto.randomBytes() entropy
- Nonces expire after 5 minutes (configurable via
CHALLENGE_TTL_SECONDS)
- Used nonces are deleted immediately after verification (single-use)
- Failed verification attempts are logged with the attempting wallet address
- Implement rate limiting on the verify endpoint: max 10 failed attempts per wallet per minute
-
Testing Requirements
- Unit tests: Mock
@stellar/stellar-sdk — test challenge generation, signature verification, nonce lifecycle
- Integration tests using
supertest with mocked Horizon responses for:
- Valid login flow (challenge → sign → verify → link wallet)
- Expired challenge (should reject)
- Already-used nonce (should reject)
- Wrong network passphrase (should reject)
- Forged signature (should reject)
- Horizon timeout (should return 503)
- Target: >80% code coverage on auth module
🔴 Priority: Critical
Difficulty: Hard
Estimated Effort: 3-4 days
Relevant Files:
src/services/stellar.service.ts,src/controllers/bot.controller.ts,src/routes/bot.routes.tsLabels:
security,enhancement,priority:critical,stellarRequirements
SEP-10 Challenge-Response Implementation
Implement the full SEP-10 authentication flow to cryptographically prove wallet ownership before any financial operation:
Challenge Phase (
POST /auth/challenge)crypto.randomBytes()entropy)timeBoundswithmin = now - thresholdandmax = now + threshold(threshold defaults to 300 seconds)Verify Phase (
POST /auth/verify)@stellar/stellar-sdktimeBoundswindowUserrecordClock Skew Tolerance
now - threshold > tx.timeBounds.minortx.timeBounds.max > now + thresholdNetwork Resilience
503 Service Unavailableif Horizon is unreachableNetwork Awareness
config.STELLAR_NETWORKSecurity Hardening
crypto.randomBytes()entropyCHALLENGE_TTL_SECONDS)Testing Requirements
@stellar/stellar-sdk— test challenge generation, signature verification, nonce lifecyclesupertestwith mocked Horizon responses for: