@web3auth/no-modal 11.0.0-beta.1 → 11.0.0

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 (59) 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 +125 -58
  9. package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +40 -31
  10. package/dist/lib.cjs/index.js +24 -19
  11. package/dist/lib.cjs/noModal.js +60 -26
  12. package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +8 -4
  13. package/dist/lib.cjs/providers/account-abstraction-provider/providers/utils.js +0 -17
  14. package/dist/lib.cjs/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +15 -0
  15. package/dist/lib.cjs/react/context/useWeb3AuthInnerContextValue.js +18 -2
  16. package/dist/lib.cjs/react/solana/provider.js +6 -2
  17. package/dist/lib.cjs/react/wagmi/index.js +6 -0
  18. package/dist/lib.cjs/react/wagmi/provider.js +74 -23
  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 +8 -2
  25. package/dist/lib.cjs/types/connectors/auth-connector/interface.d.ts +1 -1
  26. package/dist/lib.cjs/types/noModal.d.ts +1 -1
  27. package/dist/lib.cjs/types/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.d.ts +1 -0
  28. package/dist/lib.cjs/types/react/wagmi/constants.d.ts +2 -0
  29. package/dist/lib.cjs/types/react/wagmi/provider.d.ts +7 -0
  30. package/dist/lib.cjs/types/vue/wagmi/constants.d.ts +2 -0
  31. package/dist/lib.cjs/types/vue/wagmi/provider.d.ts +7 -1
  32. package/dist/lib.cjs/vue/solana/provider.js +50 -26
  33. package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +13 -6
  34. package/dist/lib.cjs/vue/wagmi/index.js +6 -0
  35. package/dist/lib.cjs/vue/wagmi/provider.js +78 -35
  36. package/dist/lib.esm/account-linking/errors.js +92 -0
  37. package/dist/lib.esm/account-linking/index.js +1 -0
  38. package/dist/lib.esm/account-linking/rest.js +3 -3
  39. package/dist/lib.esm/account-linking/vue.js +0 -1
  40. package/dist/lib.esm/base/connector/constants.js +2 -1
  41. package/dist/lib.esm/base/errors/index.js +21 -50
  42. package/dist/lib.esm/base/utils.js +1 -1
  43. package/dist/lib.esm/connectors/auth-connector/authConnector.js +109 -41
  44. package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +1 -1
  45. package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +42 -33
  46. package/dist/lib.esm/index.js +3 -2
  47. package/dist/lib.esm/noModal.js +56 -20
  48. package/dist/lib.esm/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +10 -5
  49. package/dist/lib.esm/providers/account-abstraction-provider/providers/utils.js +0 -3
  50. package/dist/lib.esm/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +17 -3
  51. package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +18 -2
  52. package/dist/lib.esm/react/solana/provider.js +6 -2
  53. package/dist/lib.esm/react/wagmi/index.js +1 -1
  54. package/dist/lib.esm/react/wagmi/provider.js +74 -25
  55. package/dist/lib.esm/vue/solana/provider.js +51 -28
  56. package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +11 -4
  57. package/dist/lib.esm/vue/wagmi/index.js +1 -1
  58. package/dist/lib.esm/vue/wagmi/provider.js +73 -34
  59. package/package.json +20 -20
@@ -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;
@@ -78,7 +98,9 @@ const Web3AuthWagmiProvider = defineComponent({
78
98
  setup() {
79
99
  const {
80
100
  isConnected,
81
- connection
101
+ connection,
102
+ web3Auth,
103
+ chainNamespace
82
104
  } = useWeb3Auth();
83
105
  const {
84
106
  disconnect
@@ -87,11 +109,15 @@ const Web3AuthWagmiProvider = defineComponent({
87
109
  const {
88
110
  mutate: reconnect
89
111
  } = useReconnect();
90
- const lastSyncedWeb3AuthConnection = shallowRef(null);
112
+ const lastSyncedProvider = shallowRef(null);
113
+ const lastSyncedConnectorName = ref(null);
114
+ const suppressWagmiDisconnect = ref(false);
91
115
  useConnectionEffect({
92
116
  onDisconnect: async () => {
93
117
  log.info("Disconnected from wagmi");
94
- if (isConnected.value) await disconnect();
118
+ const isSuppressed = suppressWagmiDisconnect.value;
119
+ suppressWagmiDisconnect.value = false;
120
+ if (!isSuppressed && isConnected.value) await disconnect();
95
121
  const connector = getWeb3authConnector(wagmiConfig);
96
122
  // reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
97
123
  // from the connected provider
@@ -100,30 +126,43 @@ const Web3AuthWagmiProvider = defineComponent({
100
126
  }
101
127
  }
102
128
  });
103
- watch([isConnected, connection], async () => {
129
+ watch([isConnected, connection, chainNamespace], async () => {
104
130
  var _newConnection$ethere;
105
131
  const newIsConnected = isConnected.value;
106
132
  const newConnection = connection.value;
107
133
  const newEth = (_newConnection$ethere = newConnection === null || newConnection === void 0 ? void 0 : newConnection.ethereumProvider) !== null && _newConnection$ethere !== void 0 ? _newConnection$ethere : null;
108
- if (newIsConnected && newConnection && newEth) {
109
- // Linked-account switches can reuse or replace the underlying wallet provider,
110
- // so key wagmi resyncs off the Web3Auth connection object instead of provider identity.
111
- if (lastSyncedWeb3AuthConnection.value !== newConnection) {
112
- if (getWeb3authConnector(wagmiConfig)) {
134
+ const w3aWagmiConnector = getWeb3authConnector(wagmiConfig);
135
+ const shouldBindToWagmi = newIsConnected && chainNamespace.value === CHAIN_NAMESPACES.EIP155 && Boolean(newConnection && newEth);
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) {
140
+ return;
141
+ }
142
+ if (!hasSameBinding && w3aWagmiConnector) {
143
+ if (wagmiConfig.state.status === "connected") {
144
+ suppressWagmiDisconnect.value = true;
145
+ await disconnectWeb3AuthFromWagmi(wagmiConfig);
146
+ } else {
113
147
  resetConnectorState(wagmiConfig);
114
148
  }
115
- lastSyncedWeb3AuthConnection.value = newConnection;
116
- const connector = await setupConnector(newEth, wagmiConfig);
117
- if (!connector) {
118
- throw new Error("Failed to setup connector");
119
- }
120
- await connectWeb3AuthWithWagmi(connector, wagmiConfig);
121
- reconnect();
122
149
  }
123
- } else if (!newIsConnected) {
124
- lastSyncedWeb3AuthConnection.value = null;
150
+ lastSyncedProvider.value = newEth;
151
+ lastSyncedConnectorName.value = newConnection.connectorName;
152
+ const connector = setupConnector(newEth, wagmiConfig);
153
+ if (!connector) {
154
+ throw new Error("Failed to setup connector");
155
+ }
156
+ await connectWeb3AuthWithWagmi(connector, wagmiConfig);
157
+ reconnect();
158
+ } else if (!newIsConnected || chainNamespace.value !== CHAIN_NAMESPACES.EIP155) {
159
+ lastSyncedProvider.value = null;
160
+ lastSyncedConnectorName.value = null;
125
161
  if (wagmiConfig.state.status === "connected") {
162
+ suppressWagmiDisconnect.value = true;
126
163
  await disconnectWeb3AuthFromWagmi(wagmiConfig);
164
+ } else if (w3aWagmiConnector) {
165
+ resetConnectorState(wagmiConfig);
127
166
  }
128
167
  }
129
168
  }, {
@@ -187,7 +226,7 @@ const WagmiProvider = defineComponent({
187
226
  return fallback(transports);
188
227
  };
189
228
  const defineWagmiConfig = () => {
190
- var _web3Auth$value;
229
+ var _web3Auth$value2;
191
230
  const configParams = _objectSpread(_objectSpread({
192
231
  ssr: true
193
232
  }, config), {}, {
@@ -198,7 +237,7 @@ const WagmiProvider = defineComponent({
198
237
  client: undefined
199
238
  });
200
239
  const wagmiChains = [];
201
- 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) {
202
241
  var _web3Auth$value$curre;
203
242
  const defaultChainId = (_web3Auth$value$curre = web3Auth.value.currentChain) === null || _web3Auth$value$curre === void 0 ? void 0 : _web3Auth$value$curre.chainId;
204
243
  const chains = web3Auth.value.coreOptions.chains.filter(chain => chain.chainNamespace === CHAIN_NAMESPACES.EIP155);
@@ -246,8 +285,8 @@ const WagmiProvider = defineComponent({
246
285
  }
247
286
  };
248
287
  watch(isInitialized, (newIsInitialized, prevIsInitialized) => {
249
- var _web3Auth$value2;
250
- (_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({
251
290
  wagmi_enabled: true
252
291
  });
253
292
  if (newIsInitialized && !prevIsInitialized) {
@@ -279,4 +318,4 @@ const WagmiProvider = defineComponent({
279
318
  }
280
319
  });
281
320
 
282
- 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.1",
3
+ "version": "11.0.0",
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,8 +87,8 @@
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",
91
- "@web3auth/ws-embed": "^6.0.0",
90
+ "@web3auth/auth": "^11.8.1",
91
+ "@web3auth/ws-embed": "^6.0.4",
92
92
  "bignumber.js": "~9.3.1",
93
93
  "deepmerge": "^4.3.1",
94
94
  "ethers": "^6.16.0",
@@ -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": "a15a4f552ee844c7b743f48f4b725c52b6b7316d"
255
+ "gitHead": "84b5f0c887209f24f098b7eea634747193bc1f2c"
256
256
  }