@web3auth/no-modal 11.0.0-beta.2 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/lib.cjs/account-linking/errors.js +111 -0
  2. package/dist/lib.cjs/account-linking/index.js +4 -0
  3. package/dist/lib.cjs/account-linking/rest.js +6 -6
  4. package/dist/lib.cjs/account-linking/vue.js +0 -1
  5. package/dist/lib.cjs/base/connector/constants.js +2 -0
  6. package/dist/lib.cjs/base/errors/index.js +21 -50
  7. package/dist/lib.cjs/base/utils.js +1 -1
  8. package/dist/lib.cjs/connectors/auth-connector/authConnector.js +47 -34
  9. package/dist/lib.cjs/connectors/base-evm-connector/baseEvmConnector.js +3 -2
  10. package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +40 -31
  11. package/dist/lib.cjs/index.js +21 -16
  12. package/dist/lib.cjs/noModal.js +29 -11
  13. package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +20 -6
  14. package/dist/lib.cjs/providers/account-abstraction-provider/providers/utils.js +0 -17
  15. package/dist/lib.cjs/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +15 -0
  16. package/dist/lib.cjs/react/context/useWeb3AuthInnerContextValue.js +11 -4
  17. package/dist/lib.cjs/react/wagmi/index.js +6 -0
  18. package/dist/lib.cjs/react/wagmi/provider.js +60 -41
  19. package/dist/lib.cjs/types/account-linking/errors.d.ts +17 -0
  20. package/dist/lib.cjs/types/account-linking/index.d.ts +1 -0
  21. package/dist/lib.cjs/types/base/connector/constants.d.ts +1 -0
  22. package/dist/lib.cjs/types/base/connector/interfaces.d.ts +1 -1
  23. package/dist/lib.cjs/types/base/errors/index.d.ts +2 -13
  24. package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +2 -2
  25. package/dist/lib.cjs/types/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.d.ts +1 -0
  26. package/dist/lib.cjs/types/react/wagmi/constants.d.ts +2 -0
  27. package/dist/lib.cjs/types/react/wagmi/provider.d.ts +7 -0
  28. package/dist/lib.cjs/types/vue/wagmi/constants.d.ts +2 -0
  29. package/dist/lib.cjs/types/vue/wagmi/provider.d.ts +7 -1
  30. package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +13 -6
  31. package/dist/lib.cjs/vue/wagmi/index.js +6 -0
  32. package/dist/lib.cjs/vue/wagmi/provider.js +53 -26
  33. package/dist/lib.esm/account-linking/errors.js +92 -0
  34. package/dist/lib.esm/account-linking/index.js +1 -0
  35. package/dist/lib.esm/account-linking/rest.js +3 -3
  36. package/dist/lib.esm/account-linking/vue.js +0 -1
  37. package/dist/lib.esm/base/connector/constants.js +2 -1
  38. package/dist/lib.esm/base/errors/index.js +21 -50
  39. package/dist/lib.esm/base/utils.js +1 -1
  40. package/dist/lib.esm/connectors/auth-connector/authConnector.js +29 -15
  41. package/dist/lib.esm/connectors/base-evm-connector/baseEvmConnector.js +3 -2
  42. package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +1 -1
  43. package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +42 -33
  44. package/dist/lib.esm/index.js +3 -2
  45. package/dist/lib.esm/noModal.js +25 -5
  46. package/dist/lib.esm/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +22 -7
  47. package/dist/lib.esm/providers/account-abstraction-provider/providers/utils.js +0 -3
  48. package/dist/lib.esm/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +17 -3
  49. package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +11 -4
  50. package/dist/lib.esm/react/wagmi/index.js +1 -1
  51. package/dist/lib.esm/react/wagmi/provider.js +59 -42
  52. package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +11 -4
  53. package/dist/lib.esm/vue/wagmi/index.js +1 -1
  54. package/dist/lib.esm/vue/wagmi/provider.js +48 -25
  55. package/package.json +19 -19
@@ -5,7 +5,7 @@ export { SMART_ACCOUNT } from '@toruslabs/ethereum-controllers';
5
5
  import { JRPCEngineV2, providerFromEngineV2, providerErrors } from '@web3auth/auth';
6
6
  import { defineChain, createPublicClient, http, createWalletClient, custom } from 'viem';
7
7
  import { createPaymasterClient, createBundlerClient } from 'viem/account-abstraction';
8
- import { createEoaMiddleware, providerAsMiddleware, createAaMiddleware } from '../rpc/ethRpcMiddlewares.js';
8
+ import { createEoaMiddleware, providerAsMiddleware, createAaMiddleware, createEip7702And5792MiddlewareForAaProvider } from '../rpc/ethRpcMiddlewares.js';
9
9
  import { getProviderHandlers } from './utils.js';
10
10
  import { BaseProvider } from '../../base-provider/baseProvider.js';
11
11
  import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
@@ -55,9 +55,10 @@ class AccountAbstractionProvider extends BaseProvider {
55
55
  }
56
56
  async setupProvider(eoaProvider) {
57
57
  var _bundlerConfig$transp;
58
- const {
59
- currentChain
60
- } = this;
58
+ const currentChain = this.currentChain;
59
+ if (!currentChain) {
60
+ throw WalletInitializationError.invalidProviderConfigError(`AA chain config not found for chain ${this.chainId}`);
61
+ }
61
62
  const {
62
63
  chainNamespace
63
64
  } = currentChain;
@@ -134,19 +135,33 @@ class AccountAbstractionProvider extends BaseProvider {
134
135
  eoaProvider,
135
136
  handlers: providerHandlers
136
137
  });
138
+
139
+ // middleware to handle EIP-7702 and EIP-5792 methods,
140
+ // currently, we do not support EIP-7702 and EIP-5792 methods for account abstraction provider
141
+ const eip7702And5792Middleware = await createEip7702And5792MiddlewareForAaProvider();
137
142
  const eoaMiddleware = providerAsMiddleware(eoaProvider);
138
143
  const engine = JRPCEngineV2.create({
139
- middleware: [aaMiddleware, eoaMiddleware]
144
+ middleware: [aaMiddleware, eip7702And5792Middleware, eoaMiddleware]
140
145
  });
141
146
  const provider = providerFromEngineV2(engine);
142
147
  this.updateProviderEngineProxy(provider);
143
- eoaProvider.once("chainChanged", chainId => {
148
+ const chainChangedHandler = chainId => {
144
149
  this.update({
145
150
  chainId
146
151
  });
147
152
  this.setupChainSwitchMiddleware();
148
153
  this.emit("chainChanged", chainId);
149
- });
154
+ if (eoaProvider !== null && eoaProvider !== void 0 && eoaProvider.removeListener && typeof eoaProvider.removeListener === "function") {
155
+ eoaProvider.removeListener("chainChanged", chainChangedHandler);
156
+ }
157
+ };
158
+ if (eoaProvider !== null && eoaProvider !== void 0 && eoaProvider.once && typeof eoaProvider.once === "function") {
159
+ eoaProvider.once("chainChanged", chainChangedHandler);
160
+ } else {
161
+ // some providers like trust wallet does not have `once` method, so we use `on` instead
162
+ // and cleanup the listener after the event triggers once
163
+ eoaProvider.on("chainChanged", chainChangedHandler);
164
+ }
150
165
  }
151
166
  async updateAccount(_params) {
152
167
  throw providerErrors.unsupportedMethod("updateAccount. Please call it on eoaProvider");
@@ -2,7 +2,6 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import { isHexString, add0x } from '@toruslabs/metadata-helpers';
3
3
  import { providerErrors } from '@web3auth/auth';
4
4
  import { createWalletClient, http } from 'viem';
5
- import { log } from '../../../base/loglevel.js';
6
5
 
7
6
  function getProviderHandlers({
8
7
  bundlerClient,
@@ -20,8 +19,6 @@ function getProviderHandlers({
20
19
  const [smartAccounts, eoaAccounts] = await Promise.all([smartAccount.getAddress(), eoaProvider.request({
21
20
  method: "eth_accounts"
22
21
  })]);
23
- log.info("smartAccounts", smartAccounts);
24
- log.info("eoaAccounts", eoaAccounts);
25
22
  return [smartAccounts, ...eoaAccounts];
26
23
  },
27
24
  getPrivateKey: async _ => {
@@ -1,6 +1,6 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
- import { METHOD_TYPES } from '@toruslabs/ethereum-controllers';
3
- import { createScaffoldMiddlewareV2, rpcErrors } from '@web3auth/auth';
2
+ import { METHOD_TYPES, EIP_5792_METHODS, EIP_7702_METHODS } from '@toruslabs/ethereum-controllers';
3
+ import { createScaffoldMiddlewareV2, providerErrors, rpcErrors } from '@web3auth/auth';
4
4
 
5
5
  async function createAaMiddleware({
6
6
  eoaProvider,
@@ -181,6 +181,20 @@ async function createEoaMiddleware({
181
181
  eth_requestAccounts: requestAccounts
182
182
  });
183
183
  }
184
+ async function createEip7702And5792MiddlewareForAaProvider() {
185
+ const eip5792Methods = Object.values(EIP_5792_METHODS);
186
+ const eip7702Methods = Object.values(EIP_7702_METHODS);
187
+ const eip7702And5792Methods = [...eip5792Methods, ...eip7702Methods];
188
+ return async ({
189
+ request,
190
+ next
191
+ }) => {
192
+ if (eip7702And5792Methods.includes(request.method)) {
193
+ throw providerErrors.unsupportedMethod(`${request.method} is not supported for account abstraction provider`);
194
+ }
195
+ return next(request);
196
+ };
197
+ }
184
198
  function providerAsMiddleware(provider) {
185
199
  return async ({
186
200
  request
@@ -192,4 +206,4 @@ function providerAsMiddleware(provider) {
192
206
  };
193
207
  }
194
208
 
195
- export { createAaMiddleware, createEoaMiddleware, providerAsMiddleware };
209
+ export { createAaMiddleware, createEip7702And5792MiddlewareForAaProvider, createEoaMiddleware, providerAsMiddleware };
@@ -127,19 +127,26 @@ function useWeb3AuthInnerContextValue({
127
127
  const authorizedListener = () => {
128
128
  setStatus(web3Auth.status);
129
129
  if (web3Auth.status === CONNECTOR_STATUS.AUTHORIZED) {
130
+ var _web3Auth$currentChai7, _web3Auth$currentChai8;
131
+ setIsInitialized(true);
130
132
  setIsConnected(true);
133
+ // on rehydration, `AUTHORIZED` event can be fired first in `CONNECT_AND_SIGN` mode, before `CONNECTED` event.
134
+ // Update the connection state here, so that clients can use the connection state immediately.
135
+ setConnection(web3Auth.connection);
136
+ setChainId(web3Auth.currentChainId);
137
+ setChainNamespace((_web3Auth$currentChai7 = (_web3Auth$currentChai8 = web3Auth.currentChain) === null || _web3Auth$currentChai8 === void 0 ? void 0 : _web3Auth$currentChai8.chainNamespace) !== null && _web3Auth$currentChai7 !== void 0 ? _web3Auth$currentChai7 : null);
131
138
  setIsAuthorized(true);
132
139
  }
133
140
  };
134
141
  const consentAcceptedListener = () => {
135
142
  setStatus(web3Auth.status);
136
143
  if (web3Auth.status === CONNECTOR_STATUS.CONNECTED || web3Auth.status === CONNECTOR_STATUS.AUTHORIZED) {
137
- var _web3Auth$currentChai7, _web3Auth$currentChai8;
144
+ var _web3Auth$currentChai9, _web3Auth$currentChai0;
138
145
  setIsInitialized(true);
139
146
  setIsConnected(true);
140
147
  setConnection(web3Auth.connection);
141
148
  setChainId(web3Auth.currentChainId);
142
- setChainNamespace((_web3Auth$currentChai7 = (_web3Auth$currentChai8 = web3Auth.currentChain) === null || _web3Auth$currentChai8 === void 0 ? void 0 : _web3Auth$currentChai8.chainNamespace) !== null && _web3Auth$currentChai7 !== void 0 ? _web3Auth$currentChai7 : null);
149
+ setChainNamespace((_web3Auth$currentChai9 = (_web3Auth$currentChai0 = web3Auth.currentChain) === null || _web3Auth$currentChai0 === void 0 ? void 0 : _web3Auth$currentChai0.chainNamespace) !== null && _web3Auth$currentChai9 !== void 0 ? _web3Auth$currentChai9 : null);
143
150
  if (web3Auth.status === CONNECTOR_STATUS.AUTHORIZED) {
144
151
  setIsAuthorized(true);
145
152
  }
@@ -149,11 +156,11 @@ function useWeb3AuthInnerContextValue({
149
156
  if (typeof nextIsMFAEnabled === "boolean") setIsMFAEnabled(nextIsMFAEnabled);
150
157
  };
151
158
  const connectionUpdatedListener = () => {
152
- var _web3Auth$currentChai9, _web3Auth$currentChai0;
159
+ var _web3Auth$currentChai1, _web3Auth$currentChai10;
153
160
  setStatus(web3Auth.status);
154
161
  setConnection(web3Auth.connection);
155
162
  setChainId(web3Auth.currentChainId);
156
- setChainNamespace((_web3Auth$currentChai9 = (_web3Auth$currentChai0 = web3Auth.currentChain) === null || _web3Auth$currentChai0 === void 0 ? void 0 : _web3Auth$currentChai0.chainNamespace) !== null && _web3Auth$currentChai9 !== void 0 ? _web3Auth$currentChai9 : null);
163
+ setChainNamespace((_web3Auth$currentChai1 = (_web3Auth$currentChai10 = web3Auth.currentChain) === null || _web3Auth$currentChai10 === void 0 ? void 0 : _web3Auth$currentChai10.chainNamespace) !== null && _web3Auth$currentChai1 !== void 0 ? _web3Auth$currentChai1 : null);
157
164
  };
158
165
  if (web3Auth) {
159
166
  web3Auth.on(CONNECTOR_EVENTS.NOT_READY, notReadyListener);
@@ -1 +1 @@
1
- export { WagmiProvider } from './provider.js';
1
+ export { WagmiProvider, connectWeb3AuthWithWagmi, createWeb3AuthConnectorForWagmi, disconnectWeb3AuthFromWagmi, getWeb3authConnector, resetConnectorState, setupConnector } from './provider.js';
@@ -1,42 +1,61 @@
1
1
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
2
2
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
3
3
  import { useMemo, createElement, useRef, useEffect, Fragment } from 'react';
4
- import { defineChain } from 'viem';
5
- import { createConfig, WagmiProvider as WagmiProvider$1, webSocket, http, fallback, useConfig, useReconnect, useConnectionEffect } from 'wagmi';
6
- import { injected } from 'wagmi/connectors';
4
+ import { defineChain, isAddress } from 'viem';
5
+ import { createConfig, WagmiProvider as WagmiProvider$1, injected, webSocket, http, fallback, useConfig, useReconnect, useConnectionEffect } from 'wagmi';
7
6
  import { defaultWagmiConfig } from './constants.js';
8
7
  import { useWeb3Auth } from '../hooks/useWeb3Auth.js';
9
8
  import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
10
9
  import { WalletInitializationError } from '../../base/errors/index.js';
11
- import { useWeb3AuthDisconnect } from '../hooks/useWeb3AuthDisconnect.js';
10
+ import { WEB3AUTH_CONNECTOR_ID } from '../../base/connector/constants.js';
12
11
  import { log } from '../../base/loglevel.js';
12
+ import { useWeb3AuthDisconnect } from '../hooks/useWeb3AuthDisconnect.js';
13
13
 
14
14
  const _excluded = ["children"];
15
- const WEB3AUTH_CONNECTOR_ID = "web3auth";
16
15
  function getWeb3authConnector(config) {
17
16
  return config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
18
17
  }
19
18
 
20
- // Helper to initialize connectors for the given wallets
19
+ // Helper to create a Web3Auth connector to connect with wagmi
21
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- async function setupConnector(provider, config) {
23
- let connector = getWeb3authConnector(config);
24
- if (connector) return connector;
25
-
26
- // Create new connector if not already existing
27
- connector = injected({
21
+ function createWeb3AuthConnectorForWagmi(provider) {
22
+ const baseConnector = injected({
28
23
  target: {
29
24
  provider: provider,
30
25
  id: WEB3AUTH_CONNECTOR_ID,
31
26
  name: "Web3Auth"
32
27
  }
33
28
  });
29
+ return config => {
30
+ const connector = baseConnector(config);
31
+ const baseOnAccountsChanged = connector.onAccountsChanged.bind(connector);
32
+
33
+ // we need to handle the `accountsChanged` event emitted on the cross-namespace chain switch.
34
+ // on evm -> solana, the accountsChanged event is emitted with the solana address, which is not valid for evm.
35
+ // that causes the `invalid account address` error in wagmi. So, here, we're filtering out the solana addresses.
36
+ connector.onAccountsChanged = accounts => {
37
+ if (accounts.length > 0 && !accounts.every(account => typeof account === "string" && isAddress(account))) {
38
+ log.warn("onAccountsChanged::accountsChanged event received on non-EVM address");
39
+ return;
40
+ }
41
+ baseOnAccountsChanged(accounts);
42
+ };
43
+ return connector;
44
+ };
45
+ }
46
+
47
+ // Helper to initialize connectors for the given wallets
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
+ function setupConnector(provider, config) {
50
+ let connector = getWeb3authConnector(config);
51
+ if (connector) return connector;
52
+
53
+ // Create new connector if not already existing
54
+ connector = createWeb3AuthConnectorForWagmi(provider);
34
55
  const result = config._internal.connectors.setup(connector);
35
56
  config._internal.connectors.setState(current => [...current, result]);
36
57
  return result;
37
58
  }
38
-
39
- // Helper to connect a wallet and update wagmi state
40
59
  async function connectWeb3AuthWithWagmi(connector, config) {
41
60
  var _config$storage, _config$storage2;
42
61
  await Promise.all([(_config$storage = config.storage) === null || _config$storage === void 0 ? void 0 : _config$storage.removeItem(`${connector.id}.disconnected`), (_config$storage2 = config.storage) === null || _config$storage2 === void 0 ? void 0 : _config$storage2.setItem("recentConnectorId", connector.id)]);
@@ -76,6 +95,7 @@ async function disconnectWeb3AuthFromWagmi(config) {
76
95
  function Web3AuthWagmiProvider({
77
96
  children
78
97
  }) {
98
+ var _connection$ethereumP, _connection$connector;
79
99
  const {
80
100
  isConnected,
81
101
  connection,
@@ -89,59 +109,56 @@ function Web3AuthWagmiProvider({
89
109
  mutate: reconnect
90
110
  } = useReconnect();
91
111
  const suppressWagmiDisconnect = useRef(false);
92
- const lastSyncedBinding = useRef({
93
- provider: null,
94
- connectorName: null
95
- });
112
+ const lastSyncedProvider = useRef((_connection$ethereumP = connection === null || connection === void 0 ? void 0 : connection.ethereumProvider) !== null && _connection$ethereumP !== void 0 ? _connection$ethereumP : null);
113
+ const lastSyncedConnectorName = useRef((_connection$connector = connection === null || connection === void 0 ? void 0 : connection.connectorName) !== null && _connection$connector !== void 0 ? _connection$connector : null);
96
114
  useConnectionEffect({
97
115
  onDisconnect: async () => {
98
116
  log.info("Disconnected from wagmi");
99
117
  const isSuppressed = suppressWagmiDisconnect.current;
100
118
  suppressWagmiDisconnect.current = false;
101
119
  if (!isSuppressed && isConnected) await disconnect();
102
- const connector = getWeb3authConnector(wagmiConfig);
120
+
103
121
  // reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
104
122
  // from the connected provider
105
- if (connector) {
123
+ if (getWeb3authConnector(wagmiConfig)) {
106
124
  resetConnectorState(wagmiConfig);
107
125
  }
108
126
  }
109
127
  });
110
128
  useEffect(() => {
111
- (async () => {
112
- const shouldBindToWagmi = isConnected && chainNamespace === CHAIN_NAMESPACES.EIP155 && Boolean(connection === null || connection === void 0 ? void 0 : connection.ethereumProvider);
129
+ (async _connection$ethereumP2 => {
130
+ const newConnection = connection !== null && connection !== void 0 ? connection : null;
131
+ const newEth = (_connection$ethereumP2 = connection === null || connection === void 0 ? void 0 : connection.ethereumProvider) !== null && _connection$ethereumP2 !== void 0 ? _connection$ethereumP2 : null;
132
+ const w3aWagmiConnector = getWeb3authConnector(wagmiConfig);
133
+ const shouldBindToWagmi = isConnected && chainNamespace === CHAIN_NAMESPACES.EIP155 && Boolean(newConnection && newEth);
113
134
  if (shouldBindToWagmi) {
114
- const hasSameBinding = lastSyncedBinding.current.provider === connection.ethereumProvider && lastSyncedBinding.current.connectorName === connection.connectorName;
115
- if (hasSameBinding && wagmiConfig.state.status === "connected") {
135
+ const hasSameBinding = lastSyncedProvider.current === newEth && lastSyncedConnectorName.current === newConnection.connectorName && wagmiConfig.state.status === "connected";
136
+ if (hasSameBinding) {
137
+ // rehydration: already connected to the same provider, so no need to reconnect
116
138
  return;
117
139
  }
118
- if (!hasSameBinding && getWeb3authConnector(wagmiConfig)) {
119
- if (wagmiConfig.state.status === "connected") {
120
- suppressWagmiDisconnect.current = true;
121
- await disconnectWeb3AuthFromWagmi(wagmiConfig);
122
- } else {
123
- resetConnectorState(wagmiConfig);
124
- }
140
+
141
+ // `ethereumProvider` is a stable proxy (`commonJRPCProvider`) across account switches,
142
+ // so key wagmi resyncs off the Web3Auth connection object instead of provider identity.
143
+ if (w3aWagmiConnector) {
144
+ resetConnectorState(wagmiConfig);
125
145
  }
126
- const connector = await setupConnector(connection.ethereumProvider, wagmiConfig);
146
+ lastSyncedProvider.current = newEth;
147
+ lastSyncedConnectorName.current = newConnection.connectorName;
148
+ const connector = setupConnector(newEth, wagmiConfig);
127
149
  if (!connector) {
150
+ log.error("Failed to setup react wagmi connector");
128
151
  throw new Error("Failed to setup connector");
129
152
  }
130
153
  await connectWeb3AuthWithWagmi(connector, wagmiConfig);
131
- lastSyncedBinding.current = {
132
- provider: connection.ethereumProvider,
133
- connectorName: connection.connectorName
134
- };
135
154
  reconnect();
136
155
  } else {
137
- lastSyncedBinding.current = {
138
- provider: null,
139
- connectorName: null
140
- };
156
+ lastSyncedProvider.current = null;
157
+ lastSyncedConnectorName.current = null;
141
158
  if (wagmiConfig.state.status === "connected") {
142
159
  suppressWagmiDisconnect.current = true;
143
160
  await disconnectWeb3AuthFromWagmi(wagmiConfig);
144
- } else if (getWeb3authConnector(wagmiConfig)) {
161
+ } else if (w3aWagmiConnector) {
145
162
  resetConnectorState(wagmiConfig);
146
163
  }
147
164
  }
@@ -240,4 +257,4 @@ function WagmiProvider(_ref) {
240
257
  }), createElement(Web3AuthWagmiProvider, null, children));
241
258
  }
242
259
 
243
- export { WagmiProvider };
260
+ export { WagmiProvider, connectWeb3AuthWithWagmi, createWeb3AuthConnectorForWagmi, disconnectWeb3AuthFromWagmi, getWeb3authConnector, resetConnectorState, setupConnector };
@@ -99,20 +99,27 @@ function useWeb3AuthInnerContextValue({
99
99
  };
100
100
  const authorizedListener = () => {
101
101
  status.value = web3Auth.value.status;
102
+ // on rehydration, `AUTHORIZED` event can be fired first in `CONNECT_AND_SIGN` mode, before `CONNECTED` event.
103
+ // Update the connection state here, so that clients can use the connection state immediately.
102
104
  if (web3Auth.value.status === CONNECTOR_STATUS.AUTHORIZED) {
105
+ var _currentChain$chainNa2, _currentChain2;
106
+ if (!isInitialized.value) isInitialized.value = true;
103
107
  isAuthorized.value = true;
104
108
  isConnected.value = true;
109
+ connection.value = web3Auth.value.connection;
110
+ chainId.value = web3Auth.value.currentChainId;
111
+ chainNamespace.value = (_currentChain$chainNa2 = (_currentChain2 = web3Auth.value.currentChain) === null || _currentChain2 === void 0 ? void 0 : _currentChain2.chainNamespace) !== null && _currentChain$chainNa2 !== void 0 ? _currentChain$chainNa2 : null;
105
112
  }
106
113
  };
107
114
  const consentAcceptedListener = () => {
108
115
  status.value = web3Auth.value.status;
109
116
  if (web3Auth.value.status === CONNECTOR_STATUS.CONNECTED || web3Auth.value.status === CONNECTOR_STATUS.AUTHORIZED) {
110
- var _currentChain$chainNa2, _currentChain2;
117
+ var _currentChain$chainNa3, _currentChain3;
111
118
  if (!isInitialized.value) isInitialized.value = true;
112
119
  isConnected.value = true;
113
120
  connection.value = web3Auth.value.connection;
114
121
  chainId.value = web3Auth.value.currentChainId;
115
- chainNamespace.value = (_currentChain$chainNa2 = (_currentChain2 = web3Auth.value.currentChain) === null || _currentChain2 === void 0 ? void 0 : _currentChain2.chainNamespace) !== null && _currentChain$chainNa2 !== void 0 ? _currentChain$chainNa2 : null;
122
+ chainNamespace.value = (_currentChain$chainNa3 = (_currentChain3 = web3Auth.value.currentChain) === null || _currentChain3 === void 0 ? void 0 : _currentChain3.chainNamespace) !== null && _currentChain$chainNa3 !== void 0 ? _currentChain$chainNa3 : null;
116
123
  if (web3Auth.value.status === CONNECTOR_STATUS.AUTHORIZED) {
117
124
  isAuthorized.value = true;
118
125
  }
@@ -135,11 +142,11 @@ function useWeb3AuthInnerContextValue({
135
142
  isMFAEnabled.value = true;
136
143
  };
137
144
  const connectionUpdatedListener = () => {
138
- var _currentChain$chainNa3, _currentChain3;
145
+ var _currentChain$chainNa4, _currentChain4;
139
146
  status.value = web3Auth.value.status;
140
147
  connection.value = web3Auth.value.connection;
141
148
  chainId.value = web3Auth.value.currentChainId;
142
- chainNamespace.value = (_currentChain$chainNa3 = (_currentChain3 = web3Auth.value.currentChain) === null || _currentChain3 === void 0 ? void 0 : _currentChain3.chainNamespace) !== null && _currentChain$chainNa3 !== void 0 ? _currentChain$chainNa3 : null;
149
+ chainNamespace.value = (_currentChain$chainNa4 = (_currentChain4 = web3Auth.value.currentChain) === null || _currentChain4 === void 0 ? void 0 : _currentChain4.chainNamespace) !== null && _currentChain$chainNa4 !== void 0 ? _currentChain$chainNa4 : null;
143
150
  };
144
151
  if (prevWeb3Auth && newWeb3Auth !== prevWeb3Auth) {
145
152
  prevWeb3Auth.removeListener(CONNECTOR_EVENTS.NOT_READY, notReadyListener);
@@ -1 +1 @@
1
- export { WagmiProvider } from './provider.js';
1
+ export { WagmiProvider, connectWeb3AuthWithWagmi, createWeb3AuthConnectorForWagmi, disconnectWeb3AuthFromWagmi, getWeb3authConnector, resetConnectorState, setupConnector } from './provider.js';
@@ -1,9 +1,8 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
- import { hydrate } from '@wagmi/core';
2
+ import { injected, hydrate } from '@wagmi/core';
3
3
  import { configKey, createConfig, useConfig, useReconnect, useConnectionEffect } from '@wagmi/vue';
4
- import { injected } from '@wagmi/vue/connectors';
5
4
  import { randomId } from '@web3auth/auth';
6
- import { defineChain, webSocket, http, fallback } from 'viem';
5
+ import { isAddress, defineChain, webSocket, http, fallback } from 'viem';
7
6
  import { defineComponent, h, shallowRef, ref, watch, provide } from 'vue';
8
7
  import { log } from '../../base/loglevel.js';
9
8
  import { defaultWagmiConfig } from './constants.js';
@@ -11,26 +10,47 @@ import { useWeb3Auth } from '../composables/useWeb3Auth.js';
11
10
  import { useWeb3AuthDisconnect } from '../composables/useWeb3AuthDisconnect.js';
12
11
  import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
13
12
  import { WalletInitializationError } from '../../base/errors/index.js';
13
+ import { WEB3AUTH_CONNECTOR_ID } from '../../base/connector/constants.js';
14
14
 
15
- const WEB3AUTH_CONNECTOR_ID = "web3auth";
16
15
  function getWeb3authConnector(config) {
17
16
  return config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
18
17
  }
19
18
 
20
- // Helper to initialize connectors for the given wallets
19
+ // Helper to create a Web3Auth connector to connect with wagmi
21
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- async function setupConnector(provider, config) {
23
- let connector = getWeb3authConnector(config);
24
- if (connector) return connector;
25
-
26
- // Create new connector if not already existing
27
- connector = injected({
21
+ function createWeb3AuthConnectorForWagmi(provider) {
22
+ const baseConnector = injected({
28
23
  target: {
29
24
  provider: provider,
30
25
  id: WEB3AUTH_CONNECTOR_ID,
31
26
  name: "Web3Auth"
32
27
  }
33
28
  });
29
+ return config => {
30
+ const connector = baseConnector(config);
31
+ const baseOnAccountsChanged = connector.onAccountsChanged.bind(connector);
32
+ connector.onAccountsChanged = accounts => {
33
+ // we need to handle the `accountsChanged` event emitted on the cross-namespace chain switch.
34
+ // on evm -> solana, the accountsChanged event is emitted with the solana address, which is not valid for evm.
35
+ // that causes the `invalid account address` error in wagmi. So, here, we're filtering out the solana addresses.
36
+ if (accounts.length > 0 && !accounts.every(account => typeof account === "string" && isAddress(account))) {
37
+ log.warn("onAccountsChanged::accountsChanged event received on non-EVM address");
38
+ return;
39
+ }
40
+ baseOnAccountsChanged(accounts);
41
+ };
42
+ return connector;
43
+ };
44
+ }
45
+
46
+ // Helper to initialize connectors for the given wallets
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ function setupConnector(provider, config) {
49
+ let connector = getWeb3authConnector(config);
50
+ if (connector) return connector;
51
+
52
+ // Create new connector if not already existing
53
+ connector = createWeb3AuthConnectorForWagmi(provider);
34
54
  const result = config._internal.connectors.setup(connector);
35
55
  config._internal.connectors.setState(current => [...current, result]);
36
56
  return result;
@@ -79,6 +99,7 @@ const Web3AuthWagmiProvider = defineComponent({
79
99
  const {
80
100
  isConnected,
81
101
  connection,
102
+ web3Auth,
82
103
  chainNamespace
83
104
  } = useWeb3Auth();
84
105
  const {
@@ -110,13 +131,15 @@ const Web3AuthWagmiProvider = defineComponent({
110
131
  const newIsConnected = isConnected.value;
111
132
  const newConnection = connection.value;
112
133
  const newEth = (_newConnection$ethere = newConnection === null || newConnection === void 0 ? void 0 : newConnection.ethereumProvider) !== null && _newConnection$ethere !== void 0 ? _newConnection$ethere : null;
134
+ const w3aWagmiConnector = getWeb3authConnector(wagmiConfig);
113
135
  const shouldBindToWagmi = newIsConnected && chainNamespace.value === CHAIN_NAMESPACES.EIP155 && Boolean(newConnection && newEth);
114
- if (shouldBindToWagmi && newConnection && newEth) {
115
- const hasSameBinding = lastSyncedProvider.value === newEth && lastSyncedConnectorName.value === newConnection.connectorName;
116
- if (hasSameBinding && wagmiConfig.state.status === "connected") {
136
+ if (shouldBindToWagmi) {
137
+ var _web3Auth$value;
138
+ const hasSameBinding = lastSyncedProvider.value === newEth && lastSyncedConnectorName.value === newConnection.connectorName && (newConnection === null || newConnection === void 0 ? void 0 : newConnection.connectorName) === ((_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.connection.connectorName) && wagmiConfig.state.status === "connected";
139
+ if (hasSameBinding) {
117
140
  return;
118
141
  }
119
- if (!hasSameBinding && getWeb3authConnector(wagmiConfig)) {
142
+ if (!hasSameBinding && w3aWagmiConnector) {
120
143
  if (wagmiConfig.state.status === "connected") {
121
144
  suppressWagmiDisconnect.value = true;
122
145
  await disconnectWeb3AuthFromWagmi(wagmiConfig);
@@ -124,21 +147,21 @@ const Web3AuthWagmiProvider = defineComponent({
124
147
  resetConnectorState(wagmiConfig);
125
148
  }
126
149
  }
127
- const connector = await setupConnector(newEth, wagmiConfig);
150
+ lastSyncedProvider.value = newEth;
151
+ lastSyncedConnectorName.value = newConnection.connectorName;
152
+ const connector = setupConnector(newEth, wagmiConfig);
128
153
  if (!connector) {
129
154
  throw new Error("Failed to setup connector");
130
155
  }
131
156
  await connectWeb3AuthWithWagmi(connector, wagmiConfig);
132
- lastSyncedProvider.value = newEth;
133
- lastSyncedConnectorName.value = newConnection.connectorName;
134
157
  reconnect();
135
- } else {
158
+ } else if (!newIsConnected || chainNamespace.value !== CHAIN_NAMESPACES.EIP155) {
136
159
  lastSyncedProvider.value = null;
137
160
  lastSyncedConnectorName.value = null;
138
161
  if (wagmiConfig.state.status === "connected") {
139
162
  suppressWagmiDisconnect.value = true;
140
163
  await disconnectWeb3AuthFromWagmi(wagmiConfig);
141
- } else if (getWeb3authConnector(wagmiConfig)) {
164
+ } else if (w3aWagmiConnector) {
142
165
  resetConnectorState(wagmiConfig);
143
166
  }
144
167
  }
@@ -203,7 +226,7 @@ const WagmiProvider = defineComponent({
203
226
  return fallback(transports);
204
227
  };
205
228
  const defineWagmiConfig = () => {
206
- var _web3Auth$value;
229
+ var _web3Auth$value2;
207
230
  const configParams = _objectSpread(_objectSpread({
208
231
  ssr: true
209
232
  }, config), {}, {
@@ -214,7 +237,7 @@ const WagmiProvider = defineComponent({
214
237
  client: undefined
215
238
  });
216
239
  const wagmiChains = [];
217
- if (isInitialized.value && web3Auth !== null && web3Auth !== void 0 && (_web3Auth$value = web3Auth.value) !== null && _web3Auth$value !== void 0 && (_web3Auth$value = _web3Auth$value.coreOptions) !== null && _web3Auth$value !== void 0 && _web3Auth$value.chains) {
240
+ if (isInitialized.value && web3Auth !== null && web3Auth !== void 0 && (_web3Auth$value2 = web3Auth.value) !== null && _web3Auth$value2 !== void 0 && (_web3Auth$value2 = _web3Auth$value2.coreOptions) !== null && _web3Auth$value2 !== void 0 && _web3Auth$value2.chains) {
218
241
  var _web3Auth$value$curre;
219
242
  const defaultChainId = (_web3Auth$value$curre = web3Auth.value.currentChain) === null || _web3Auth$value$curre === void 0 ? void 0 : _web3Auth$value$curre.chainId;
220
243
  const chains = web3Auth.value.coreOptions.chains.filter(chain => chain.chainNamespace === CHAIN_NAMESPACES.EIP155);
@@ -262,8 +285,8 @@ const WagmiProvider = defineComponent({
262
285
  }
263
286
  };
264
287
  watch(isInitialized, (newIsInitialized, prevIsInitialized) => {
265
- var _web3Auth$value2;
266
- (_web3Auth$value2 = web3Auth.value) === null || _web3Auth$value2 === void 0 || _web3Auth$value2.setAnalyticsProperties({
288
+ var _web3Auth$value3;
289
+ (_web3Auth$value3 = web3Auth.value) === null || _web3Auth$value3 === void 0 || _web3Auth$value3.setAnalyticsProperties({
267
290
  wagmi_enabled: true
268
291
  });
269
292
  if (newIsInitialized && !prevIsInitialized) {
@@ -295,4 +318,4 @@ const WagmiProvider = defineComponent({
295
318
  }
296
319
  });
297
320
 
298
- export { WagmiProvider };
321
+ export { WagmiProvider, connectWeb3AuthWithWagmi, createWeb3AuthConnectorForWagmi, disconnectWeb3AuthFromWagmi, getWeb3authConnector, resetConnectorState, setupConnector };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@web3auth/no-modal",
3
- "version": "11.0.0-beta.2",
3
+ "version": "11.0.1",
4
4
  "description": "Multi chain wallet aggregator for web3Auth",
5
5
  "keywords": [
6
6
  "web3Auth/no-modal",
@@ -65,17 +65,17 @@
65
65
  }
66
66
  },
67
67
  "dependencies": {
68
- "@metamask/connect-evm": "^1.3.0",
69
- "@metamask/connect-multichain": "^0.14.0",
70
- "@metamask/connect-solana": "^1.1.0",
71
- "@segment/analytics-next": "^1.83.0",
68
+ "@metamask/connect-evm": "^1.4.0",
69
+ "@metamask/connect-multichain": "^0.15.0",
70
+ "@metamask/connect-solana": "^1.2.0",
71
+ "@segment/analytics-next": "^1.84.0",
72
72
  "@solana/client": "^1.7.0",
73
- "@solana/kit": "^6.8.0",
73
+ "@solana/kit": "^6.9.0",
74
74
  "@solana/wallet-standard-features": "^1.3.0",
75
- "@toruslabs/base-controllers": "^9.5.0",
75
+ "@toruslabs/base-controllers": "^9.10.0",
76
76
  "@toruslabs/constants": "^16.1.1",
77
77
  "@toruslabs/eccrypto": "^7.0.0",
78
- "@toruslabs/ethereum-controllers": "^9.5.0",
78
+ "@toruslabs/ethereum-controllers": "^9.10.0",
79
79
  "@toruslabs/http-helpers": "^9.0.0",
80
80
  "@toruslabs/loglevel-sentry": "^9.0.0",
81
81
  "@toruslabs/metadata-helpers": "^8.2.0",
@@ -87,7 +87,7 @@
87
87
  "@walletconnect/sign-client": "^2.23.9",
88
88
  "@walletconnect/types": "^2.23.9",
89
89
  "@walletconnect/utils": "^2.23.9",
90
- "@web3auth/auth": "^11.8.0",
90
+ "@web3auth/auth": "^11.8.1",
91
91
  "@web3auth/ws-embed": "^6.0.4",
92
92
  "bignumber.js": "~9.3.1",
93
93
  "deepmerge": "^4.3.1",
@@ -101,16 +101,16 @@
101
101
  "devDependencies": {
102
102
  "@coinbase/wallet-sdk": "^4.3.7",
103
103
  "@solana/react-hooks": "^1.4.1",
104
- "@types/react": "^19.2.14",
105
- "@wagmi/core": "^3.4.7",
106
- "@wagmi/vue": "^0.5.9",
107
- "@x402/evm": "^2.11.0",
108
- "@x402/fetch": "^2.11.0",
109
- "@x402/svm": "^2.11.0",
110
- "react": "^19.2.5",
111
- "viem": "^2.48.4",
104
+ "@types/react": "^19.2.16",
105
+ "@wagmi/core": "^3.5.0",
106
+ "@wagmi/vue": "^0.5.17",
107
+ "@x402/evm": "^2.14.0",
108
+ "@x402/fetch": "^2.14.0",
109
+ "@x402/svm": "^2.14.0",
110
+ "react": "^19.2.7",
111
+ "viem": "^2.52.0",
112
112
  "vue": "^3.x",
113
- "wagmi": "^3.6.8"
113
+ "wagmi": "^3.6.16"
114
114
  },
115
115
  "exports": {
116
116
  ".": {
@@ -252,5 +252,5 @@
252
252
  "node": ">=22.x",
253
253
  "npm": ">=10.x"
254
254
  },
255
- "gitHead": "05577130ae9ced90ed412c1597681672074d8d2a"
255
+ "gitHead": "83f7a5e2ead574c15f74b63f19e83ea13098da61"
256
256
  }