feat(worker): add proxy routes for Beacon API, Bitcoin RPC and EVM RPC#335
feat(worker): add proxy routes for Beacon API, Bitcoin RPC and EVM RPC#335AugustoL wants to merge 7 commits intoopenscan-explorer:devfrom
Conversation
Add per-provider proxy routes to the OpenScan worker to hide API keys for Alchemy (Beacon, BTC, EVM) and Infura (EVM). Includes rate limiting, request validation with method allowlists, and CORS support for GET. Routes: - GET /beacon/alchemy/:networkId/blob_sidecars/:slot - POST /btc/alchemy - POST /evm/alchemy/:networkId - POST /evm/infura/:networkId Frontend changes: - Extract shared OPENSCAN_WORKER_URL into src/config/workerConfig.ts - Add BeaconService and useBeaconBlobs hook for blob sidecar fetching - Add worker BTC and EVM URLs to BUILTIN_RPC_DEFAULTS as fallbacks - Recognize worker-proxied URLs in settings RPC tag labels Closes openscan-explorer#334
|
🚀 Preview: https://pr-335--openscan.netlify.app |
Add dRPC routes reusing existing rate limiting and validation middleware. dRPC supports all EVM networks plus Bitcoin via authenticated query params. Routes: - POST /evm/drpc/:networkId - POST /btc/drpc
Rename from openscan-groq-ai-proxy to reflect broader scope. Old worker remains live until all frontend builds use the new URL.
Route: POST /btc/onfinality/:networkId Supports bip122:000000000019d6689c085ae165831e93 (mainnet) and bip122:000000000933ea01ad0ee984209779ba (testnet).
Routes: - POST /evm/ankr/:networkId (all 8 EVM networks) - POST /btc/ankr
josealoha666
left a comment
There was a problem hiding this comment.
Nice direction overall, but I don't think this is ready to merge yet.
The main issue is that the new /evm/* proxy exposes a shared-key JSON-RPC gateway with no EVM method allowlist at all. validateEvmMiddleware only checks that method is a non-empty string, so any public caller can send arbitrary methods through our Alchemy/Infura/dRPC/Ankr keys. That makes the worker much easier to abuse for expensive or unintended calls than the BTC routes, which at least have an explicit allowlist.
Before merging, I'd lock the EVM proxy down to the subset of read-only methods the app actually needs (and ideally add payload/range guards for expensive methods like log scans).
Also worth keeping an eye on the red E2E jobs before landing this.
- Input Data is now a tab in TX Analyser, not an inline section - Nonce/Position fields are in the details grid, no "Other Attributes:" header - Gas Price label uses FieldLabel with tooltip, breaking exact text match - Invalid address may show timeout or redirect to home - ERC1155 token image may show loading timeout for slow metadata - Blocks header test waits for table data before checking info text
Description
Add per-provider proxy routes to the OpenScan worker to hide API keys for multiple RPC providers. This enables built-in fallback RPC endpoints for all supported networks without exposing API keys to users.
Providers: Alchemy, Infura, dRPC, Ankr, OnFinality
Related Issue
Closes #334
Type of Change
Changes Made
Worker (15 new files + 4 modified)
worker/src/types.ts): Added env bindings forALCHEMY_API_KEY,INFURA_API_KEY,DRPC_API_KEY,ONFINALITY_BTC_API_KEY,ANKR_API_KEY. AddedALLOWED_BEACON_NETWORKS,ALLOWED_BTC_METHODS,ALLOWED_EVM_NETWORKSmaps with per-provider chain slugs, and request body typesbeaconBlobSidecars.ts,btcRpc.ts,evmRpc.ts,drpcRpc.ts,ankrRpc.ts,onfinalityRpc.tsworker/src/index.ts): Registered all new routesworker/src/middleware/cors.ts): AddedGETto allowed methodsworker/wrangler.toml): Renamed worker toopenscan-worker-proxy, documented all new secretsRoutes
/beacon/alchemy/:networkId/blob_sidecars/:slot/btc/alchemy/btc/drpc/btc/ankr/btc/onfinality/:networkId/evm/alchemy/:networkId/evm/infura/:networkId/evm/drpc/:networkId/evm/ankr/:networkIdFrontend (3 new files + 4 modified)
src/config/workerConfig.ts(new): SharedOPENSCAN_WORKER_URLconstant, updated to new worker URLsrc/services/BeaconService.ts(new):getBlobSidecarsViaWorker()for fetching blob sidecars via workersrc/hooks/useBeaconBlobs.ts(new): React hook for beacon blob datasrc/utils/rpcStorage.ts: Added worker URLs toBUILTIN_RPC_DEFAULTSfor all supported networks (BTC + EVM, all providers)src/components/pages/settings/index.tsx: Worker-proxied URLs labeled as "OpenScan Alchemy/Infura/dRPC/Ankr/OnFinality" withrpc-opensourcetagsrc/hooks/useEtherscan.ts+src/utils/contractLookup.ts: Refactored to import fromworkerConfig.tsScreenshots (if applicable)
N/A — backend/infra changes
Checklist
npm run format:fixandnpm run lint:fixnpm run typecheckwith no errorsnpm run test:runAdditional Notes
openscan-groq-ai-proxytoopenscan-worker-proxy— old worker remains live until frontend is deployedwrangler secret put:ALCHEMY_API_KEY,INFURA_API_KEY,DRPC_API_KEY,ANKR_API_KEY,ONFINALITY_BTC_API_KEYbitcoin-mainnet.g.alchemy.com(not the deprecatedalchemy-blast.com)