implement full dora api #473
Merged
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.
Add comprehensive v1 API endpoints with advanced authentication and rate limiting
Summary
• Add 16 new v1 API endpoints providing comprehensive access to all blockchain explorer data
• Implement JWT-based authentication system with configurable rate limiting and CORS controls
• Enable programmatic access to epochs, validators, deposits, slashings, exits, withdrawals, consolidations, and MEV blocks
• Support both authenticated and unauthenticated access with flexible security policies
API Endpoints Added
GET /api/v1/epochs- Epoch data with comprehensive filteringGET /api/v1/validators- Validator information with search and filteringGET /api/v1/validators/activity- Validator activity information with grouping & filteringGET/POST /api/v1/validator_names- Validator name lookup (supports 100 item limit)GET /api/v1/deposits/included- Deposits included in blocks with filteringGET /api/v1/deposits/transactions- Deposit transactions with comprehensive filteringGET /api/v1/deposits/queue- Queued deposits with filteringGET /api/v1/slashings- Slashing events with filteringGET /api/v1/voluntary_exits- Voluntary exit requests with filteringGET /api/v1/withdrawal_requests- Withdrawal requests with filteringGET /api/v1/consolidation_requests- Consolidation requests with filteringGET /api/v1/network/forks- Network fork information with BPO forks and digestsGET /api/v1/network/overview- Comprehensive network state overviewGET /api/v1/network/splits- Active network splits with participation metricsGET /api/v1/mev/blocks- MEV block data with offset/limit paginationAuthentication & Rate Limiting System
• JWT Token Authentication - Secure token-based API access with HMAC-256 signing
• Flexible Rate Limiting - Per-token, per-IP, or global rate limits (configurable per minute)
• IP/CIDR Whitelisting - Bypass rate limits for trusted IPv4/IPv6 addresses and ranges
• Token-Based CORS - Restrict API access to specific domains per token
• Unlimited Tokens - Special tokens with no rate limits for internal services
• Token Expiration - Configurable token lifetimes for enhanced security
Token Management Utility
• dora-utils token generate - Create JWT tokens with custom rate limits and CORS policies
• dora-utils token secret - Generate cryptographically secure JWT signing secrets
• Config File Support - Load JWT secrets from dora config files
• Flexible Token Options - Name, rate limits, CORS origins, expiration times
• Usage Examples - Built-in help and example commands
Configuration Features
• API Configuration Block - Comprehensive settings in config.yaml
• Environment Variables - Full env var support for all API settings
• Default Rate Limits - Configurable defaults for unauthenticated requests
• CORS Policies - Global and per-token CORS origin control
• Security Options - Disable rate limiting, whitelist IPs, custom secrets
Technical Implementation
• Middleware Architecture - Clean separation of rate limiting and CORS handling
• Memory Management - Automatic cleanup of unused rate limiters
• IPv6 Support - Full support for IPv6 addresses and CIDR ranges
• Standard Headers - X-RateLimit-* headers for client integration
• V1 Versioning - All handlers suffixed for future API versions
• Service Integration - Proper use of existing service methods and filters
• Comprehensive Filtering - All endpoints support frontend-equivalent filtering
• Error Handling - Consistent JSON error responses across all endpoints
• Shared Code Reuse - Common functions shared between endpoints to avoid duplication
• Caching Support - Network overview cached with SecondsPerSlot timeout for performance
• Bearer Token Authentication - Updated Swagger documentation for proper JWT token usage
Usage Examples
Configuration Example
Security Features
• JWT Signing - HMAC-256 with configurable secrets
• Rate Limit Bypass - IP-based whitelisting for internal services
• CORS Enforcement - Prevent unauthorized cross-origin access
• Token Scoping - Per-token CORS and rate limit policies
• Request Logging - Authentication failures and rate limit violations logged
Test Plan