-
Notifications
You must be signed in to change notification settings - Fork 262
fix: do not support 7702/5792 for 4337 AA accounts #2507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
242a67f
e48f76f
0f8553a
ce3efcb
3725c90
b199357
c4980ae
e9312b1
3de8499
23bdef6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,15 @@ import { getErrorAnalyticsProperties, signChallenge } from "@toruslabs/base-cont | |
| import { bytesToHexPrefixedString, utf8ToBytes } from "@toruslabs/metadata-helpers"; | ||
| import type { Wallet } from "@wallet-standard/base"; | ||
| import { StandardConnect, StandardConnectFeature } from "@wallet-standard/features"; | ||
| import { | ||
| createScaffoldMiddlewareV2, | ||
| JRPCEngineV2, | ||
| type JRPCRequest, | ||
| type MiddlewareConstraint, | ||
| type MiddlewareParams, | ||
| providerFromEngineV2, | ||
| rpcErrors, | ||
| } from "@web3auth/auth"; | ||
| import { EVM_METHOD_TYPES } from "@web3auth/ws-embed"; | ||
| import { generateSiweNonce } from "viem/siwe"; | ||
|
|
||
|
|
@@ -214,7 +223,7 @@ class MetaMaskConnector extends BaseConnector<void> { | |
| }, | ||
| }); | ||
|
|
||
| this.evmProvider = this.evmClient.getProvider() as unknown as IProvider; | ||
| this.evmProvider = this.createEvmProviderBridge(this.evmClient.getProvider() as unknown as IProvider); | ||
|
chaitanyapotti marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| // Create the Solana client only when Solana chains are configured | ||
|
|
@@ -457,24 +466,7 @@ class MetaMaskConnector extends BaseConnector<void> { | |
| throw WalletLoginError.unsupportedOperation("switchChain requires an EVM client, but no EVM chains are configured."); | ||
| } | ||
|
|
||
| const chainConfig = this.coreOptions.chains.find( | ||
| (x) => x.chainId === params.chainId && ([CHAIN_NAMESPACES.EIP155] as ChainNamespaceType[]).includes(x.chainNamespace) | ||
| ); | ||
|
|
||
| const chainConfiguration = chainConfig | ||
| ? { | ||
| chainId: params.chainId, | ||
| chainName: chainConfig.displayName, | ||
| rpcUrls: [chainConfig.rpcTarget], | ||
| blockExplorerUrls: chainConfig.blockExplorerUrl ? [chainConfig.blockExplorerUrl] : undefined, | ||
| nativeCurrency: { | ||
| name: chainConfig.tickerName, | ||
| symbol: chainConfig.ticker, | ||
| decimals: chainConfig.decimals || 18, | ||
| }, | ||
| iconUrls: chainConfig.logo ? [chainConfig.logo] : undefined, | ||
| } | ||
| : undefined; | ||
| const chainConfiguration = this.getEvmChainConfiguration(params.chainId); | ||
|
|
||
| await this.evmClient.switchChain({ chainId: params.chainId as Hex, chainConfiguration }); | ||
| } | ||
|
|
@@ -550,6 +542,60 @@ class MetaMaskConnector extends BaseConnector<void> { | |
| } | ||
| await this.initializationPromise; | ||
| } | ||
|
|
||
| private getEvmChainConfiguration(chainId: string) { | ||
| const chainConfig = this.coreOptions.chains.find( | ||
| (x) => x.chainId === chainId && ([CHAIN_NAMESPACES.EIP155] as ChainNamespaceType[]).includes(x.chainNamespace) | ||
| ); | ||
|
|
||
| return chainConfig | ||
| ? { | ||
| chainId, | ||
| chainName: chainConfig.displayName, | ||
| rpcUrls: [chainConfig.rpcTarget], | ||
| blockExplorerUrls: chainConfig.blockExplorerUrl ? [chainConfig.blockExplorerUrl] : undefined, | ||
| nativeCurrency: { | ||
| name: chainConfig.tickerName, | ||
| symbol: chainConfig.ticker, | ||
| decimals: chainConfig.decimals || 18, | ||
| }, | ||
| iconUrls: chainConfig.logo ? [chainConfig.logo] : undefined, | ||
| } | ||
| : undefined; | ||
| } | ||
|
|
||
| private createEvmProviderBridge(provider: IProvider): IProvider { | ||
| const switchChainMiddleware = createScaffoldMiddlewareV2({ | ||
| wallet_switchEthereumChain: async (params: MiddlewareParams<JRPCRequest<{ chainId: string }[]>>): Promise<null> => { | ||
| const chainParams = params.request.params?.length ? params.request.params[0] : undefined; | ||
| const chainId = chainParams?.chainId; | ||
|
|
||
| if (!chainId) throw rpcErrors.invalidParams("Missing chainId"); | ||
| if (!this.evmClient) throw WalletLoginError.unsupportedOperation("MetaMask EVM client is not initialized"); | ||
|
|
||
| const chainConfiguration = this.getEvmChainConfiguration(chainId); | ||
| await this.evmClient.switchChain({ chainId: chainId as Hex, chainConfiguration }); | ||
| return null; | ||
| }, | ||
| }); | ||
| const forwardMiddleware: MiddlewareConstraint = async ({ request }) => { | ||
| return provider.request({ method: request.method, params: request.params }); | ||
| }; | ||
| const engine = JRPCEngineV2.create({ middleware: [switchChainMiddleware, forwardMiddleware] }); | ||
| const engineProvider = providerFromEngineV2(engine) as IProvider; | ||
|
|
||
| return { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so that metamaskConnector can handle provider requests from the dapp
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we wrapped the |
||
| ...engineProvider, | ||
| // bind the provider events to the engine provider | ||
| // without the binding, the engine provider could not forward events to the original provider | ||
| on: provider.on.bind(provider), | ||
| once: provider.once.bind(provider), | ||
| removeListener: provider.removeListener.bind(provider), | ||
| off: typeof provider.off === "function" ? provider.off.bind(provider) : undefined, | ||
| emit: typeof provider.emit === "function" ? provider.emit.bind(provider) : undefined, | ||
| removeAllListeners: typeof provider.removeAllListeners === "function" ? provider.removeAllListeners.bind(provider) : undefined, | ||
| } as IProvider; | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.