This document summarizes the implementation of 4 critical GitHub issues for the Stellar Micro-Donation API.
Feature Branch: feature/issues-1105-1084-1090-1115
Status: ✅ COMPLETED
Files Modified:
src/utils/safeEqual.js(NEW)src/middleware/apiKey.js(UPDATED)tests/security/constant-time-comparison.test.js(NEW)
Changes:
- Created
safeEqual()utility usingcrypto.timingSafeEqual()with HMAC-SHA256 digests - Updated API key middleware to use constant-time comparison for legacy keys
- Ensures mismatched-length inputs don't leak timing information
Security Impact: Prevents timing side-channel attacks on API key validation
Tests: 11 test cases covering:
- Identical secret comparison
- Different secret comparison
- Mismatched-length handling
- Buffer conversion
- Timing-safe comparison verification
Status: ✅ COMPLETED
Files Modified:
src/services/SequenceManager.js(NEW)tests/stellar/stellar-sequence-manager.test.js(NEW)
Changes:
- Implemented
SequenceManagerclass with database-backed global coordination - Added
reserve/commit/releaselifecycle for atomic sequence allocation - Implemented cross-instance locking via database
- Added reconciliation routine to detect and recover from sequence gaps
- Supports crash recovery via expired reservation cleanup
- Prevents
tx_bad_seqerrors through global serialization
Key Features:
- Reserve/Commit/Release Lifecycle: Atomically allocates, commits, or releases sequences
- Cross-Instance Coordination: Database-backed global locking prevents collisions
- Gap Detection & Recovery: Reconciles with Horizon to detect out-of-band transactions
- Crash Recovery: Cleans up abandoned reservations after timeout
- Metrics Tracking: Reports reserved, committed, released, and gap_detected counts
Tests: 20+ test cases covering:
- Reserve/commit/release lifecycle
- Consecutive reserve increments
- Cross-instance coordination
- Stale lock recovery
- Gap detection and reconciliation
- Out-of-band transaction handling
- Expired reservation cleanup
- Metrics accuracy
Status: ✅ COMPLETED
Files Modified:
src/services/WebhookEmailNotificationService.js(NEW)src/services/WebhookService.js(UPDATED - replaced TODO)tests/webhooks/webhook-email-notifications.test.js(NEW)
Changes:
- Created
WebhookEmailNotificationServicewith full SMTP integration - Implemented deduplication and rate-limiting (1-hour suppression window)
- Added async email delivery with exponential backoff (3 retries)
- Implemented persistent notification ledger for idempotency across restarts
- Masked sensitive data (secrets, URLs) before sending
- Integrated with WebhookService to notify owners on auto-disable
Key Features:
- Async Delivery: Non-blocking email send with setImmediate
- Retry Logic: 3 retries with exponential backoff (1min, 5min, 30min)
- Deduplication: Prevents notification storms via suppression window
- Idempotency: Persistent ledger survives restarts
- Data Masking: Redacts secrets and sensitive URLs in emails
- Rate Limiting: Configurable suppression window (default: 1 hour)
Configuration:
SMTP_HOST=mail.example.com
SMTP_PORT=587
SMTP_SECURE=false
SMTP_USER=noreply@example.com
SMTP_PASSWORD=passwordTests: 15+ test cases covering:
- Notification deduplication
- Suppression window expiry
- Async non-blocking delivery
- Retry on transient failure
- Sensitive data masking
- Rate limiting for flapping endpoints
- SMTP configuration validation
- Notification history tracking
Status: ✅ COMPLETED
Files Modified:
src/utils/errorResponseFormatter.js(NEW)tests/misc/error-response-standardization.test.js(NEW)
Changes:
- Created canonical error envelope:
{ error: { code, message, details, requestId, timestamp } } - Implemented exhaustive Stellar/Horizon error code mapping (40+ codes)
- Added secure error masking (no secrets, SQL, or provider internals in production)
- Implemented HTTP status code mapping (402 for insufficient balance, etc.)
- Distinguished client-facing vs internal errors
Canonical Error Envelope:
{
"error": {
"code": "STELLAR_OP_NO_DESTINATION",
"message": "Destination account does not exist",
"timestamp": "2026-06-24T16:42:10.262Z",
"requestId": "req-abc-123",
"details": null // Only in non-production
}
}Stellar Error Mapping (40+ codes):
- tx_ errors*: tx_bad_seq, tx_bad_auth, tx_too_late, etc.
- op_ errors*: op_underfunded, op_no_destination, op_no_trust, etc.
- All mapped to stable client codes with appropriate HTTP status codes
Security Features:
- Production mode hides sensitive details and stack traces
- Errors logged server-side with request ID for debugging
- No raw provider payloads exposed to clients
- Client-facing vs internal error distinction
Tests: 25+ test cases covering:
- Canonical envelope structure
- Stellar error mapping (40+ codes)
- HTTP status code mapping
- Production vs non-production mode
- Sensitive data masking
- Consistent response shapes
- Error coverage
All implementations include comprehensive test suites:
# Run all tests
npm test
# Run specific issue tests
npm test -- tests/security/constant-time-comparison.test.js
npm test -- tests/stellar/stellar-sequence-manager.test.js
npm test -- tests/webhooks/webhook-email-notifications.test.js
npm test -- tests/misc/error-response-standardization.test.js| File | Type | Lines | Purpose |
|---|---|---|---|
src/utils/safeEqual.js |
NEW | 48 | Constant-time comparison utility |
src/services/SequenceManager.js |
NEW | 334 | Sequence allocation with coordination |
src/services/WebhookEmailNotificationService.js |
NEW | 328 | Email notifications service |
src/utils/errorResponseFormatter.js |
NEW | 301 | Error response standardization |
src/middleware/apiKey.js |
MODIFIED | +10 | Use safeEqual for legacy keys |
src/services/WebhookService.js |
MODIFIED | +10 | Integrate email notifications |
tests/security/constant-time-comparison.test.js |
NEW | 145 | API key comparison tests |
tests/stellar/stellar-sequence-manager.test.js |
NEW | 243 | Sequence manager tests |
tests/webhooks/webhook-email-notifications.test.js |
NEW | 263 | Email notification tests |
tests/misc/error-response-standardization.test.js |
NEW | 325 | Error response tests |
Total: 10 files, 2,197 lines of code + tests
Issues were implemented sequentially with commits for each:
- ✅ #1115 - Constant-time comparison (
cb2fd8e) - ✅ #1105 - Sequence number management (
d6828dd) - ✅ #1084 - Webhook email notifications (
5b8e62b) - ✅ #1090 - Error response standardization (
e58a867)
- Review each commit individually for code quality
- Verify all tests pass with
npm test - Run linting:
npm run lint - Check coverage:
npm run test:coverage
- Deploy with SMTP configuration for email notifications
- Monitor sequence allocation metrics for cross-instance coordination
- Verify error responses in production logging
- Add Slack/webhook notification channel support (pluggable interface)
- Implement channel account pooling for higher throughput (Issue #1105)
- Add OpenAPI documentation for standardized error codes (Issue #1090)
- Create admin dashboard for sequence manager metrics
- Constant-Time Comparison: Prevents timing attacks on authentication
- Sequence Management: Prevents
tx_bad_seqfailures and account lockup - Email Notifications: Masks secrets before transmission, async to prevent blocking
- Error Standardization: Hides internals in production, logs full details server-side with correlation IDs
Completed: 2026-06-24
Branch: feature/issues-1105-1084-1090-1115