A secure, TypeScript-based REST API service for distributing wxHOPR tokens on Gnosis Chain through secret code validation with comprehensive security features and enterprise-grade logging.
- π Secret Code Validation: Validates secret codes against configured valid codes
- π° Dual Token Airdrops: Sends both wxHOPR tokens and xDai to recipients
- π« Duplicate Prevention: Prevents multiple claims with the same secret code
- π‘οΈ Enterprise Security: Multi-layer input validation, rate limiting, and threat protection
- π Real-time Monitoring: Service status, balance monitoring, and security dashboard
- π§ͺ Development Tools: Test secret code generation and comprehensive testing suite
- π Professional Logging: Winston-based logging with rotation and structured output
- π³ Docker Ready: Secure containerized deployment with hardened configuration
- π RPC Failover: Automatic failover between multiple RPC endpoints for high availability
The service implements robust RPC failover using Viem's fallback transport mechanism:
- Primary RPC: Configured via
GNOSIS_RPC_URL - Fallback RPCs: Multiple endpoints via
GNOSIS_FALLBACK_RPC_URLS - Smart Ranking: Automatically ranks endpoints by latency and stability
- Retry Logic: 3 retries with 150ms delay between attempts
- Zero Downtime: Seamless switching between endpoints
https://rpc.gnosischain.com # Primary
https://gnosis-mainnet.public.blastapi.io # Fallback 1
https://rpc.gnosis.gateway.fm # Fallback 2
https://gnosis.drpc.org # Fallback 3
# Primary endpoint (required)
GNOSIS_RPC_URL=https://rpc.gnosischain.com
# Fallback endpoints (optional, comma-separated)
GNOSIS_FALLBACK_RPC_URLS=https://gnosis-mainnet.public.blastapi.io,https://rpc.gnosis.gateway.fm,https://gnosis.drpc.orgBenefits:
- π High Availability: Service continues running even if primary RPC fails
- β‘ Performance: Automatic selection of fastest available endpoint
- π‘οΈ Resilience: Protection against single point of failure
- π Monitoring: Logs endpoint performance and failover events
# Quick development setup with hot reloading and debugging
./deploy.sh --dev
# Or use the development helper for common tasks
./dev-helper.sh start # Start development environment
./dev-helper.sh logs # Follow logs
./dev-helper.sh shell # Access container shell
./dev-helper.sh debug # Show debugger connection infoDevelopment Features:
- π Hot Reloading: Source code changes trigger automatic restart
- π Debug Port: Node.js debugger on port 9229
- π Volume Mounts: Code, logs, and data directories mounted for persistence
- π Enhanced Logging: Verbose logging for development debugging
- π Shell Access: Easy container access for troubleshooting
# Production deployment with security hardening
./deploy.sh --prodProduction Features:
- π Read-only Filesystem: Enhanced container security
- π‘οΈ Minimal Capabilities: Dropped privileges and minimal access
- π Resource Limits: CPU and memory constraints
- π Localhost Binding: Network isolation
- π Auto Restart: Automatic restart on failure
git clone <repository-url>
cd cfp-funding-tool
npm installThe application requires PostgreSQL. Choose one option:
Option 1: Using Docker (Recommended)
# Start PostgreSQL with Docker
npm run db:setup
# Wait for database to be ready, then run migrations
npm run db:migrate
# Seed with initial secret codes (optional)
npm run db:seedOption 2: Local PostgreSQL Installation
# Install PostgreSQL on your system first, then:
createdb cfp_funding_tool
psql cfp_funding_tool -f database/schema.sql
# Migrate secret codes from environment (optional)
npm run db:seed# Copy environment template
cp env.example .env
# Edit with your configuration
nano .envRequired environment variables:
# Gnosis Chain Configuration
GNOSIS_RPC_URL=https://rpc.gnosischain.com
# Optional fallback RPC endpoints for improved reliability (comma-separated)
GNOSIS_FALLBACK_RPC_URLS=https://gnosis-mainnet.public.blastapi.io,https://rpc.gnosis.gateway.fm,https://gnosis.drpc.org
WXHOPR_TOKEN_ADDRESS=0xD4fdec44DB9D44B8f2b6d529620f9C0C7066A2c1
# Security (choose one method)
PRIVATE_KEY=your_private_key_here # Basic (development only)
# Encrypted private key (RECOMMENDED for production)
# Generate with: npm run quick-encrypt
ENCRYPTED_PRIVATE_KEY=encrypted_key_here # AES-256-CBC encrypted
ENCRYPTION_PASSWORD=your_encryption_password # Strong password (12+ chars)
# Airdrop Configuration
SECRET_CODES=DontTellUncleSam,SecretCode123,HiddenTreasure
AIRDROP_AMOUNT_WEI=10000000000000000 # 0.01 wxHOPR
XDAI_AIRDROP_AMOUNT_WEI=10000000000000000 # 0.01 xDai
# Server Configuration
PORT=3000
NODE_ENV=developmentPrerequisites: Ensure database is set up (see Database Setup section above)
# Development with hot reload (local)
npm run dev
# Development with Docker (recommended)
./deploy.sh --dev
# Build for production
npm run build
# Run production build
npm start
# Run tests
npm test.env file.
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/airdrop/claim |
Claim dual airdrop (wxHOPR + xDai) |
GET |
/api/airdrop/status |
Get service status and balances |
GET |
/api/airdrop/health |
Health check endpoint |
POST |
/api/airdrop/generate-test-code |
Generate test secret code |
Claim Airdrop:
curl -X POST http://localhost:3000/api/airdrop/claim \
-H "Content-Type: application/json" \
-d '{
"secretCode": "DontTellUncleSam",
"recipientAddress": "0x742d35Cc6634C0532925a3b8D8B9B3a8d8b8B3a8"
}'Check Status:
curl http://localhost:3000/api/airdrop/statusβββ src/
β βββ controllers/ # Request handlers
β βββ services/ # Business logic
β βββ middleware/ # Express middleware (validation, security)
β βββ routes/ # API route definitions
β βββ utils/ # Utilities (logging, validation, security)
β βββ config/ # Configuration management
β βββ types/ # TypeScript type definitions
β βββ app.ts # Express app setup
βββ tests/ # Comprehensive test suite
βββ docs/ # High-level tutorials and guides
βββ scripts/ # Utility scripts
βββ logs/ # Application logs (auto-generated)
βββ frontend/ # Web frontend (optional)
The application implements multiple layers of security:
- Multi-layer validation: Joi schemas + security pattern detection
- XSS Protection: Script tags, event handlers blocked
- SQL Injection Prevention: Database query patterns blocked
- Command Injection Prevention: Shell commands blocked
- 50+ malicious patterns detected and blocked automatically
- Encrypted Storage: Support for encrypted private key storage using AES-256-CBC
- Quick Encryption: Use
npm run quick-encryptfor secure key generation - Key Rotation: Automated key management capabilities
- Hardware Security Modules: AWS KMS and HashiCorp Vault support
- CSP Headers: Content Security Policy protection
- CORS Configuration: Restricted origins for production
- Rate Limiting: Automatic IP blocking for repeated attacks
- Security Monitoring: Real-time threat detection and logging
- Read-only filesystem: Enhanced container security
- Minimal capabilities: Dropped privileges and minimal access
- Resource limits: CPU and memory constraints
- Network isolation: Localhost binding in production
# Run all tests
npm test
# Run specific test suites
npm run test:unit
npm run test:integration
npm run test:security
# Run with coverage
npm run test:coverage
# Watch mode
npm run test:watch- Unit Tests: Business logic and utilities
- Integration Tests: API endpoints and middleware
- Security Tests: Input validation and attack prevention
- Coverage Target: 70% minimum, 90% for security-critical code
- Application Logs:
logs/combined-*.log - Error Logs:
logs/error-*.log - Security Logs:
logs/security-*.log - Automatic Rotation: Daily rotation with compression
- Health Check:
GET /api/airdrop/health - Service Status:
GET /api/airdrop/status - Security Dashboard: Real-time security metrics
- API response times and error rates
- Airdrop success/failure rates
- Security events and blocked attacks
- Token balance monitoring
-
Start the development environment:
./deploy.sh --dev
-
In VS Code, go to Run and Debug (Ctrl+Shift+D)
-
Select "Attach to Docker (Development)" configuration
-
Set breakpoints in your TypeScript source files
- Start development mode:
./deploy.sh --dev - Open Chrome and navigate to:
chrome://inspect - Click "Open dedicated DevTools for Node"
- The debugger will connect to
localhost:9229
For detailed guides on specific topics, see the docs/ directory:
- Deployment Guide - Comprehensive deployment instructions for Railway, Docker, and local environments
- Security Setup - Security configuration and best practices
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
- TypeScript strict mode enabled
- ESLint and Prettier configured
- Comprehensive test coverage required
- Security-first development approach
MIT License
- Never commit private keys to version control
- Use encrypted private keys in production (
npm run quick-encrypt) - Regularly rotate secret codes
- Monitor security logs for threats
- Keep dependencies updated
Need Help?
- Check the
docs/directory for detailed guides - Review the API documentation for endpoint details
- Run security validation scripts for troubleshooting
- Open an issue for bugs or feature requests