UNPKG

@web3auth/no-modal

Version:
42 lines (38 loc) 1.17 kB
'use strict'; var baseControllers = require('@toruslabs/base-controllers'); var auth = require('@web3auth/auth'); function createEthChainIdMiddleware(chainId) { return (req, res, next, end) => { if (req.method === "eth_chainId") { res.result = chainId; return end(); } return next(); }; } function createEthProviderConfigMiddleware(providerConfig) { return (req, res, next, end) => { if (req.method === "eth_provider_config") { res.result = providerConfig; return end(); } return next(); }; } function createEthJsonRpcClient(providerConfig) { const { chainId, rpcTarget } = providerConfig; const fetchMiddleware = baseControllers.createFetchMiddleware({ rpcTarget }); const networkMiddleware = auth.mergeMiddleware([createEthChainIdMiddleware(chainId), createEthProviderConfigMiddleware(providerConfig), fetchMiddleware]); return { networkMiddleware, fetchMiddleware }; } exports.createEthChainIdMiddleware = createEthChainIdMiddleware; exports.createEthJsonRpcClient = createEthJsonRpcClient; exports.createEthProviderConfigMiddleware = createEthProviderConfigMiddleware;