I am trying to add support for Kevlar(github_com/shresthagrawal/kevlar) to MetaMask. Kevlar is a light client-based RPC proxy for Ethereum.
I figured out that this can be easily done by creating a custom RPC middleware and replacing it with the fetchMiddleware here(github_com/MetaMask/MetaMask-extension/blob/develop/app/scripts/controllers/network/createJsonRpcClient.js#L20). I went ahead and implemented the custom middleware, here (github_com/shresthagrawal/kevlar/blob/feat/support-MetaMask/src/rpc-bundle/rpc-lightclient-middleware.ts#L9). I am currently stuck because the Kevlar is ESModule while MetaMask is CommonJs.
I cannot compile Kevlar to CommonJs using Babel because it depends on ChainSafe/Lodestar packages which are ESModules (Lodestar can’t be compiled to CommonJs because it depends on Libp2p which are ESModules and so on).
I tried using a proxy CommonJs library which dynamically imports Kevlar in runtime and import this library into MetaMask. This didn’t work out as LavaMoat transformed the
__import__ . I also tried manually commenting on the code which disables the transformation but then lavamoat still didn’t allow me to resolve the package. Is there a way to whitelist the package, and not do the transformation from the
policy-overide.json? Is there a quick way to disable LavaMoat to at least try the Kevlar-MetaMask extension?
Any suggestions or help would be highly appreciated