@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
@@ -114,7 +114,11 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
114
114
  supportedNetworks: caipSupportedNetworks
115
115
  },
116
116
  ui,
117
- debug: (_this$connectorSettin0 = this.connectorSettings) === null || _this$connectorSettin0 === void 0 ? void 0 : _this$connectorSettin0.debug
117
+ debug: (_this$connectorSettin0 = this.connectorSettings) === null || _this$connectorSettin0 === void 0 ? void 0 : _this$connectorSettin0.debug,
118
+ analytics: {
119
+ integrationType: "web3auth",
120
+ enabled: !this.coreOptions.disableAnalytics
121
+ }
118
122
  });
119
123
  // Listen for QR code URI from the multichain client (for mobile wallet connection)
120
124
  this.multichainClient.on("display_uri", uri => {
@@ -132,19 +136,27 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
132
136
  dapp,
133
137
  eventHandlers: {
134
138
  accountsChanged: _accounts => {
135
- if (_accounts.length === 0) {
139
+ if (_accounts.length === 0 && this.connected) {
136
140
  this.disconnect();
137
141
  }
138
142
  },
139
143
  chainChanged: _chainId => {},
140
144
  connect: _result => {},
141
- disconnect: () => this.disconnect()
145
+ disconnect: () => {
146
+ if (this.connected) {
147
+ this.disconnect();
148
+ }
149
+ }
142
150
  },
143
151
  api: {
144
152
  supportedNetworks: hexSupportedNetworks
145
153
  },
146
154
  ui,
147
- debug: (_this$connectorSettin1 = this.connectorSettings) === null || _this$connectorSettin1 === void 0 ? void 0 : _this$connectorSettin1.debug
155
+ debug: (_this$connectorSettin1 = this.connectorSettings) === null || _this$connectorSettin1 === void 0 ? void 0 : _this$connectorSettin1.debug,
156
+ analytics: {
157
+ integrationType: "web3auth",
158
+ enabled: !this.coreOptions.disableAnalytics
159
+ }
148
160
  });
149
161
  this.evmProvider = this.evmClient.getProvider();
150
162
  }
@@ -155,7 +167,11 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
155
167
  api: {
156
168
  supportedNetworks: solanaSupportedNetworks
157
169
  },
158
- skipAutoRegister: true
170
+ skipAutoRegister: true,
171
+ analytics: {
172
+ integrationType: "web3auth",
173
+ enabled: !this.coreOptions.disableAnalytics
174
+ }
159
175
  });
160
176
  this.solanaProvider = this.solanaClient.getWallet();
161
177
  }
@@ -170,32 +186,20 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
170
186
  return;
171
187
  }
172
188
  const coreStatus = this.multichainClient.status;
173
- if (coreStatus === "connected") {
189
+ // only connect if the multichain client is connected and autoConnect is true (i.e during the rehydration)
190
+ if (coreStatus === "connected" && options.autoConnect) {
174
191
  this.status = constants.CONNECTOR_STATUS.CONNECTED;
175
192
  this.rehydrated = true;
176
- if (options.autoConnect) {
177
- this.emit(constants.CONNECTOR_EVENTS.CONNECTED, {
178
- connectorName: index.WALLET_CONNECTORS.METAMASK,
179
- reconnected: this.rehydrated,
180
- ethereumProvider: this.evmProvider,
181
- solanaWallet: this.solanaProvider
182
- });
183
- if (options.getAuthTokenInfo) {
184
- await this.getAuthTokenInfo();
185
- }
186
- }
187
- } else if (coreStatus === "loaded" || coreStatus === "disconnected") {
188
- this.status = constants.CONNECTOR_STATUS.READY;
189
- this.emit(constants.CONNECTOR_EVENTS.READY, index.WALLET_CONNECTORS.METAMASK);
190
- } else if (coreStatus === "pending") {
191
- // 'pending' implies that a transport failed to resume the connection
192
- // if (options.autoConnect) {
193
- // this.rehydrated = false;
194
- // this.emit(CONNECTOR_EVENTS.REHYDRATION_ERROR, new Error("Failed to resume existing MetaMask Connect session.") as Web3AuthError);
195
- // } else {
193
+ this.emit(constants.CONNECTOR_EVENTS.CONNECTED, {
194
+ connectorName: index.WALLET_CONNECTORS.METAMASK,
195
+ reconnected: true,
196
+ ethereumProvider: this.evmProvider,
197
+ solanaWallet: this.solanaProvider
198
+ });
199
+ if (options.getAuthTokenInfo) await this.getAuthTokenInfo();
200
+ } else if (coreStatus === "connected" || coreStatus === "loaded" || coreStatus === "disconnected" || coreStatus === "pending") {
196
201
  this.status = constants.CONNECTOR_STATUS.READY;
197
202
  this.emit(constants.CONNECTOR_EVENTS.READY, index.WALLET_CONNECTORS.METAMASK);
198
- // }
199
203
  } else {
200
204
  // Something unexpected happened
201
205
  this.status = constants.CONNECTOR_STATUS.ERRORED;
@@ -231,11 +235,15 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
231
235
  connector: index.WALLET_CONNECTORS.METAMASK
232
236
  });
233
237
  const evmConnectedPromise = new Promise(resolve => {
234
- var _this$evmProvider;
235
- // Wait for EVM provider to be ready
236
- (_this$evmProvider = this.evmProvider) === null || _this$evmProvider === void 0 || _this$evmProvider.once("connect", () => {
238
+ if (this.evmClient.status === "connected") {
237
239
  resolve();
238
- });
240
+ } else {
241
+ var _this$evmProvider;
242
+ // Wait for EVM provider to be ready
243
+ (_this$evmProvider = this.evmProvider) === null || _this$evmProvider === void 0 || _this$evmProvider.once("connect", () => {
244
+ resolve();
245
+ });
246
+ }
239
247
  });
240
248
  // Connect using the multichain client
241
249
  await this.multichainClient.connect(scopes, caipAccountIds, {
@@ -298,6 +306,7 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
298
306
  duration: Date.now() - startTime
299
307
  }));
300
308
  }
309
+ if (index$1.isUserRejectedError(error)) throw index$1.WalletOperationsError.userRejected();
301
310
  if (error instanceof index$1.Web3AuthError) throw error;
302
311
  throw index$1.WalletLoginError.connectionError("Failed to login with MetaMask wallet", error);
303
312
  }
@@ -10,13 +10,13 @@ var auth = require('@web3auth/auth');
10
10
  var utils$1 = require('./base/connector/utils.js');
11
11
  var constants$1 = require('./base/constants.js');
12
12
  var cookie = require('./base/cookie.js');
13
- var index = require('./base/errors/index.js');
13
+ var index$1 = require('./base/errors/index.js');
14
14
  var loglevel = require('./base/loglevel.js');
15
- var errors = require('./base/plugin/errors.js');
15
+ var errors$1 = require('./base/plugin/errors.js');
16
16
  var IPlugin = require('./base/plugin/IPlugin.js');
17
17
  var IProvider = require('./base/provider/IProvider.js');
18
18
  var utils$2 = require('./base/utils.js');
19
- var index$1 = require('./base/wallet/index.js');
19
+ var index = require('./base/wallet/index.js');
20
20
  var authConnector = require('./connectors/auth-connector/authConnector.js');
21
21
  var baseEvmConnector = require('./connectors/base-evm-connector/baseEvmConnector.js');
22
22
  var baseSolanaConnector = require('./connectors/base-solana-connector/baseSolanaConnector.js');
@@ -38,6 +38,7 @@ var utils = require('./providers/base-provider/utils.js');
38
38
  var ethRpcMiddlewares = require('./providers/ethereum-provider/rpc/ethRpcMiddlewares.js');
39
39
  var jrpcClient = require('./providers/ethereum-provider/rpc/jrpcClient.js');
40
40
  var walletMiddleware = require('./providers/ethereum-provider/rpc/walletMiddleware.js');
41
+ var errors = require('./account-linking/errors.js');
41
42
  var wsEmbed = require('@web3auth/ws-embed');
42
43
  var baseControllers = require('@toruslabs/base-controllers');
43
44
  var app = require('@wallet-standard/app');
@@ -61,6 +62,7 @@ exports.CONNECTOR_CATEGORY = constants.CONNECTOR_CATEGORY;
61
62
  exports.CONNECTOR_EVENTS = constants.CONNECTOR_EVENTS;
62
63
  exports.CONNECTOR_INITIAL_AUTHENTICATION_MODE = constants.CONNECTOR_INITIAL_AUTHENTICATION_MODE;
63
64
  exports.CONNECTOR_STATUS = constants.CONNECTOR_STATUS;
65
+ exports.WEB3AUTH_CONNECTOR_ID = constants.WEB3AUTH_CONNECTOR_ID;
64
66
  Object.defineProperty(exports, "AUTH_CONNECTION", {
65
67
  enumerable: true,
66
68
  get: function () { return auth.AUTH_CONNECTION; }
@@ -96,14 +98,14 @@ exports.WALLET_REGISTRY_URL = constants$1.WALLET_REGISTRY_URL;
96
98
  exports.WEB3AUTH_STATE_STORAGE_KEY = constants$1.WEB3AUTH_STATE_STORAGE_KEY;
97
99
  exports.WIDGET_TYPE = constants$1.WIDGET_TYPE;
98
100
  exports.cookieToWeb3AuthState = cookie.cookieToWeb3AuthState;
99
- exports.AccountLinkingError = index.AccountLinkingError;
100
- exports.WalletInitializationError = index.WalletInitializationError;
101
- exports.WalletLoginError = index.WalletLoginError;
102
- exports.WalletOperationsError = index.WalletOperationsError;
103
- exports.WalletProviderError = index.WalletProviderError;
104
- exports.Web3AuthError = index.Web3AuthError;
101
+ exports.WalletInitializationError = index$1.WalletInitializationError;
102
+ exports.WalletLoginError = index$1.WalletLoginError;
103
+ exports.WalletOperationsError = index$1.WalletOperationsError;
104
+ exports.WalletProviderError = index$1.WalletProviderError;
105
+ exports.Web3AuthError = index$1.Web3AuthError;
106
+ exports.isUserRejectedError = index$1.isUserRejectedError;
105
107
  exports.log = loglevel.log;
106
- exports.WalletServicesPluginError = errors.WalletServicesPluginError;
108
+ exports.WalletServicesPluginError = errors$1.WalletServicesPluginError;
107
109
  exports.EVM_PLUGINS = IPlugin.EVM_PLUGINS;
108
110
  exports.PLUGIN_EVENTS = IPlugin.PLUGIN_EVENTS;
109
111
  exports.PLUGIN_NAMESPACES = IPlugin.PLUGIN_NAMESPACES;
@@ -129,12 +131,12 @@ exports.normalizeWalletName = utils$2.normalizeWalletName;
129
131
  exports.parseChainNamespaceFromCitadelResponse = utils$2.parseChainNamespaceFromCitadelResponse;
130
132
  exports.sdkVersion = utils$2.sdkVersion;
131
133
  exports.withAbort = utils$2.withAbort;
132
- exports.CONNECTOR_NAMES = index$1.CONNECTOR_NAMES;
133
- exports.EVM_CONNECTORS = index$1.EVM_CONNECTORS;
134
- exports.MULTI_CHAIN_CONNECTORS = index$1.MULTI_CHAIN_CONNECTORS;
135
- exports.SOLANA_CONNECTORS = index$1.SOLANA_CONNECTORS;
136
- exports.WALLET_CONNECTORS = index$1.WALLET_CONNECTORS;
137
- exports.WEB3AUTH_ICON = index$1.WEB3AUTH_ICON;
134
+ exports.CONNECTOR_NAMES = index.CONNECTOR_NAMES;
135
+ exports.EVM_CONNECTORS = index.EVM_CONNECTORS;
136
+ exports.MULTI_CHAIN_CONNECTORS = index.MULTI_CHAIN_CONNECTORS;
137
+ exports.SOLANA_CONNECTORS = index.SOLANA_CONNECTORS;
138
+ exports.WALLET_CONNECTORS = index.WALLET_CONNECTORS;
139
+ exports.WEB3AUTH_ICON = index.WEB3AUTH_ICON;
138
140
  exports.assertAuthConnector = authConnector.assertAuthConnector;
139
141
  exports.authConnector = authConnector.authConnector;
140
142
  exports.isAuthConnector = authConnector.isAuthConnector;
@@ -213,6 +215,9 @@ exports.createEthChainSwitchMiddleware = ethRpcMiddlewares.createEthChainSwitchM
213
215
  exports.createEthMiddleware = ethRpcMiddlewares.createEthMiddleware;
214
216
  exports.createEthJsonRpcClient = jrpcClient.createEthJsonRpcClient;
215
217
  exports.createWalletMiddlewareV2 = walletMiddleware.createWalletMiddlewareV2;
218
+ exports.AccountLinkingError = errors.AccountLinkingError;
219
+ exports.formatAccountLinkingErrorMessage = errors.formatAccountLinkingErrorMessage;
220
+ exports.getAccountLinkingRequestError = errors.getAccountLinkingRequestError;
216
221
  Object.defineProperty(exports, "BUTTON_POSITION", {
217
222
  enumerable: true,
218
223
  get: function () { return wsEmbed.BUTTON_POSITION; }
@@ -27,6 +27,7 @@ var plugin = require('./plugins/wallet-services-plugin/plugin.js');
27
27
  require('./providers/base-provider/utils.js');
28
28
  var CommonJRPCProvider = require('./providers/base-provider/CommonJRPCProvider.js');
29
29
  require('./providers/base-provider/commonPrivateKeyProvider.js');
30
+ var errors = require('./account-linking/errors.js');
30
31
 
31
32
  const _excluded = ["walletScope", "eipStandard"];
32
33
  const PRIMARY_CONNECTED_WALLET_KEY = "__primary__";
@@ -60,7 +61,9 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
60
61
  if (!options.clientId) throw index.WalletInitializationError.invalidParams("Please provide a valid clientId in constructor");
61
62
  if (options.enableLogging) loglevel.log.enableAll();else loglevel.log.setLevel("error");
62
63
  if (!options.initialAuthenticationMode) options.initialAuthenticationMode = constants.CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN;
63
- this.coreOptions = options;
64
+ this.coreOptions = _objectSpread(_objectSpread({}, options), {}, {
65
+ authBuildEnv: options.authBuildEnv || auth.BUILD_ENV.PRODUCTION
66
+ });
64
67
  this.storage = this.getStorageMethod();
65
68
  this.analytics = new analytics.Analytics();
66
69
  if (options.disableAnalytics) {
@@ -526,13 +529,13 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
526
529
  const linkedAccounts = (_await$authConnector$ = (await authConnector.getUserInfo()).linkedAccounts) !== null && _await$authConnector$ !== void 0 ? _await$authConnector$ : [];
527
530
  const targetAccount = this.findLinkedAccountByAddress(linkedAccounts, address);
528
531
  if (!targetAccount) {
529
- throw index.AccountLinkingError.accountNotLinked(`Account with address "${address}" is not linked`);
532
+ throw errors.AccountLinkingError.accountNotLinked(`Account with address "${address}" is not linked`);
530
533
  }
531
534
  if (targetAccount.connector === index$1.WALLET_CONNECTORS.AUTH || targetAccount.isPrimary) {
532
- throw index.AccountLinkingError.cannotUnlinkPrimaryAccount();
535
+ throw errors.AccountLinkingError.cannotUnlinkPrimaryAccount();
533
536
  }
534
537
  if (((_this$state$activeAcc = this.state.activeAccount) === null || _this$state$activeAcc === void 0 ? void 0 : _this$state$activeAcc.id) === targetAccount.id) {
535
- throw index.AccountLinkingError.cannotUnlinkActiveAccount();
538
+ throw errors.AccountLinkingError.cannotUnlinkActiveAccount();
536
539
  }
537
540
  const result = await authConnector.unlinkAccount({
538
541
  address,
@@ -933,7 +936,8 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
933
936
  activeAccount,
934
937
  currentChainId
935
938
  } = this.state;
936
- // if the active account is not the primary account, i.e. not `null`, create an isolated connector and connect to the chain
939
+ let rehydrateWithLinkedAccount = false;
940
+ // for rehydration, if the active account is not the primary account, i.e. not `null`, create an isolated connector and connect to the chain
937
941
  if (activeAccount && !activeAccount.isPrimary && activeAccount.connector !== index$1.WALLET_CONNECTORS.AUTH) {
938
942
  var _ref3, _walletConnector$prov, _linkedAccountConnect, _ref4, _walletConnector$sola, _linkedAccountConnect2;
939
943
  const accountLinkingConnector = authConnector.isAuthConnector(connector) ? connector : this.getConnector(index$1.WALLET_CONNECTORS.AUTH);
@@ -946,7 +950,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
946
950
  chainId: targetChainId
947
951
  });
948
952
  if (!linkedAccountConnection) {
949
- throw index.AccountLinkingError.requestFailed(`Failed to connect isolated connector "${activeAccount.connector}" for account switch.`);
953
+ throw errors.AccountLinkingError.requestFailed(`Failed to connect isolated connector "${activeAccount.connector}" for account switch.`);
950
954
  }
951
955
  }
952
956
  const connectedWalletState = await this.resolveConnectedWalletConnectorState({
@@ -958,6 +962,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
958
962
  });
959
963
  this.setConnectedWalletConnectorState(connectedWalletState, activeAccount);
960
964
  this.setActiveWalletConnectorKey(activeAccount);
965
+ rehydrateWithLinkedAccount = true;
961
966
  }
962
967
  if (ethereumProvider) {
963
968
  await this.bindPrimaryEthereumSigningProxy(ethereumProvider, data.connectorName);
@@ -1001,6 +1006,11 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
1001
1006
  loginMode: this.loginMode,
1002
1007
  pendingUserConsent
1003
1008
  }));
1009
+ // if we're rehydrating with a linked account, we need to emit a CONNECTION_UPDATED event
1010
+ // so that upstream listeners and context are updated with the linked connection.
1011
+ if (rehydrateWithLinkedAccount) {
1012
+ this.emit(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, this.connection);
1013
+ }
1004
1014
  }
1005
1015
  });
1006
1016
  connector.on(constants.CONNECTOR_EVENTS.DISCONNECTED, async data => {
@@ -1194,7 +1204,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
1194
1204
  resolveLinkAccountChainId(chainId) {
1195
1205
  const finalChainId = chainId || this.state.currentChainId;
1196
1206
  if (!finalChainId) {
1197
- throw index.AccountLinkingError.walletProofFailed("No chainId is available. Please specify chainId in LinkAccountParams or ensure the SDK has an active chain.");
1207
+ throw errors.AccountLinkingError.walletProofFailed("No chainId is available. Please specify chainId in LinkAccountParams or ensure the SDK has an active chain.");
1198
1208
  }
1199
1209
  return finalChainId;
1200
1210
  }
@@ -1215,7 +1225,15 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
1215
1225
  return activeChainId;
1216
1226
  }
1217
1227
  async createLinkingWalletConnector(connectorName, chainId, config) {
1218
- return this.createIsolatedWalletConnector(connectorName, chainId, config);
1228
+ try {
1229
+ const linkingConnector = await this.createIsolatedWalletConnector(connectorName, chainId, config);
1230
+ return linkingConnector;
1231
+ } catch (error) {
1232
+ if (error instanceof errors.AccountLinkingError && error.code === 5405) {
1233
+ throw error;
1234
+ }
1235
+ throw errors.AccountLinkingError.walletProofFailed(error instanceof Error ? error.message : String(error), error);
1236
+ }
1219
1237
  }
1220
1238
  async createSwitchingWalletConnector(connectorName, chainId, config) {
1221
1239
  return this.createIsolatedWalletConnector(connectorName, chainId, config);
@@ -1443,7 +1461,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
1443
1461
  caipAccountIds: [caipAccountId]
1444
1462
  });
1445
1463
  if (!linkedAccountConnection) {
1446
- throw index.AccountLinkingError.requestFailed(`Failed to connect isolated connector "${switchResult.targetAccount.connector}" for account switch.`);
1464
+ throw errors.AccountLinkingError.requestFailed(`Failed to connect isolated connector "${switchResult.targetAccount.connector}" for account switch.`);
1447
1465
  }
1448
1466
  }
1449
1467
  await authConnector.assertSwitchAccountConnectorMatchesTarget(walletConnector, switchResult.targetAccount);
@@ -1692,7 +1710,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
1692
1710
  } = await Promise.resolve().then(function () { return require('./connectors/wallet-connect-v2-connector/index.js'); });
1693
1711
  return walletConnectV2Connector()(config);
1694
1712
  }
1695
- throw index.AccountLinkingError.unsupportedConnector(`Connector "${connectorName}" does not support automatic wallet linking. ` + `Use ${index$1.WALLET_CONNECTORS.METAMASK}, ${index$1.WALLET_CONNECTORS.WALLET_CONNECT_V2}, or an installed compatible wallet.`);
1713
+ throw errors.AccountLinkingError.unsupportedConnector(`Connector "${connectorName}" does not support automatic wallet linking. ` + `Use ${index$1.WALLET_CONNECTORS.METAMASK}, ${index$1.WALLET_CONNECTORS.WALLET_CONNECT_V2}, or an installed compatible wallet.`);
1696
1714
  }
1697
1715
  /**
1698
1716
  * Create a new connector instance that is NOT registered in this.connectors and NOT
@@ -1721,7 +1739,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
1721
1739
  break;
1722
1740
  }
1723
1741
  case index$1.WALLET_CONNECTORS.AUTH:
1724
- throw index.AccountLinkingError.unsupportedConnector(`Connector "${connectorName}" does not support automatic wallet linking.`);
1742
+ throw errors.AccountLinkingError.unsupportedConnector(`Connector "${connectorName}" does not support automatic wallet linking.`);
1725
1743
  default:
1726
1744
  {
1727
1745
  connector = await this.resolveDiscoveredWalletConnector(connectorName, chainId, config, effectiveProjectConfig);
@@ -71,9 +71,10 @@ class AccountAbstractionProvider extends baseProvider.BaseProvider {
71
71
  }
72
72
  async setupProvider(eoaProvider) {
73
73
  var _bundlerConfig$transp;
74
- const {
75
- currentChain
76
- } = this;
74
+ const currentChain = this.currentChain;
75
+ if (!currentChain) {
76
+ throw index.WalletInitializationError.invalidProviderConfigError(`AA chain config not found for chain ${this.chainId}`);
77
+ }
77
78
  const {
78
79
  chainNamespace
79
80
  } = currentChain;
@@ -148,19 +149,32 @@ class AccountAbstractionProvider extends baseProvider.BaseProvider {
148
149
  eoaProvider,
149
150
  handlers: providerHandlers
150
151
  });
152
+ // middleware to handle EIP-7702 and EIP-5792 methods,
153
+ // currently, we do not support EIP-7702 and EIP-5792 methods for account abstraction provider
154
+ const eip7702And5792Middleware = await ethRpcMiddlewares.createEip7702And5792MiddlewareForAaProvider();
151
155
  const eoaMiddleware = ethRpcMiddlewares.providerAsMiddleware(eoaProvider);
152
156
  const engine = auth.JRPCEngineV2.create({
153
- middleware: [aaMiddleware, eoaMiddleware]
157
+ middleware: [aaMiddleware, eip7702And5792Middleware, eoaMiddleware]
154
158
  });
155
159
  const provider = auth.providerFromEngineV2(engine);
156
160
  this.updateProviderEngineProxy(provider);
157
- eoaProvider.once("chainChanged", chainId => {
161
+ const chainChangedHandler = chainId => {
158
162
  this.update({
159
163
  chainId
160
164
  });
161
165
  this.setupChainSwitchMiddleware();
162
166
  this.emit("chainChanged", chainId);
163
- });
167
+ if (eoaProvider !== null && eoaProvider !== void 0 && eoaProvider.removeListener && typeof eoaProvider.removeListener === "function") {
168
+ eoaProvider.removeListener("chainChanged", chainChangedHandler);
169
+ }
170
+ };
171
+ if (eoaProvider !== null && eoaProvider !== void 0 && eoaProvider.once && typeof eoaProvider.once === "function") {
172
+ eoaProvider.once("chainChanged", chainChangedHandler);
173
+ } else {
174
+ // some providers like trust wallet does not have `once` method, so we use `on` instead
175
+ // and cleanup the listener after the event triggers once
176
+ eoaProvider.on("chainChanged", chainChangedHandler);
177
+ }
164
178
  }
165
179
  async updateAccount(_params) {
166
180
  throw auth.providerErrors.unsupportedMethod("updateAccount. Please call it on eoaProvider");
@@ -4,21 +4,6 @@ var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
4
  var metadataHelpers = require('@toruslabs/metadata-helpers');
5
5
  var auth = require('@web3auth/auth');
6
6
  var viem = require('viem');
7
- require('@babel/runtime/helpers/defineProperty');
8
- require('@segment/analytics-next');
9
- var loglevel = require('../../../base/loglevel.js');
10
- require('@toruslabs/base-controllers');
11
- require('@toruslabs/session-manager');
12
- require('../../../base/errors/index.js');
13
- require('@toruslabs/constants');
14
- require('@toruslabs/http-helpers');
15
- require('../../../base/constants.js');
16
- require('../../../base/wallet/index.js');
17
- require('../../../base/connector/connectorStatus.js');
18
- require('../../../base/connector/constants.js');
19
- require('jwt-decode');
20
- require('../../../base/plugin/errors.js');
21
- require('../../../base/plugin/IPlugin.js');
22
7
 
23
8
  function getProviderHandlers({
24
9
  bundlerClient,
@@ -36,8 +21,6 @@ function getProviderHandlers({
36
21
  const [smartAccounts, eoaAccounts] = await Promise.all([smartAccount.getAddress(), eoaProvider.request({
37
22
  method: "eth_accounts"
38
23
  })]);
39
- loglevel.log.info("smartAccounts", smartAccounts);
40
- loglevel.log.info("eoaAccounts", eoaAccounts);
41
24
  return [smartAccounts, ...eoaAccounts];
42
25
  },
43
26
  getPrivateKey: async _ => {
@@ -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(ethereumControllers.EIP_5792_METHODS);
186
+ const eip7702Methods = Object.values(ethereumControllers.EIP_7702_METHODS);
187
+ const eip7702And5792Methods = [...eip5792Methods, ...eip7702Methods];
188
+ return async ({
189
+ request,
190
+ next
191
+ }) => {
192
+ if (eip7702And5792Methods.includes(request.method)) {
193
+ throw auth.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
@@ -193,5 +207,6 @@ function providerAsMiddleware(provider) {
193
207
  }
194
208
 
195
209
  exports.createAaMiddleware = createAaMiddleware;
210
+ exports.createEip7702And5792MiddlewareForAaProvider = createEip7702And5792MiddlewareForAaProvider;
196
211
  exports.createEoaMiddleware = createEoaMiddleware;
197
212
  exports.providerAsMiddleware = providerAsMiddleware;
@@ -140,19 +140,26 @@ function useWeb3AuthInnerContextValue({
140
140
  const authorizedListener = () => {
141
141
  setStatus(web3Auth.status);
142
142
  if (web3Auth.status === constants.CONNECTOR_STATUS.AUTHORIZED) {
143
+ var _web3Auth$currentChai7, _web3Auth$currentChai8;
144
+ setIsInitialized(true);
143
145
  setIsConnected(true);
146
+ // on rehydration, `AUTHORIZED` event can be fired first in `CONNECT_AND_SIGN` mode, before `CONNECTED` event.
147
+ // Update the connection state here, so that clients can use the connection state immediately.
148
+ setConnection(web3Auth.connection);
149
+ setChainId(web3Auth.currentChainId);
150
+ 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);
144
151
  setIsAuthorized(true);
145
152
  }
146
153
  };
147
154
  const consentAcceptedListener = () => {
148
155
  setStatus(web3Auth.status);
149
156
  if (web3Auth.status === constants.CONNECTOR_STATUS.CONNECTED || web3Auth.status === constants.CONNECTOR_STATUS.AUTHORIZED) {
150
- var _web3Auth$currentChai7, _web3Auth$currentChai8;
157
+ var _web3Auth$currentChai9, _web3Auth$currentChai0;
151
158
  setIsInitialized(true);
152
159
  setIsConnected(true);
153
160
  setConnection(web3Auth.connection);
154
161
  setChainId(web3Auth.currentChainId);
155
- 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);
162
+ 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);
156
163
  if (web3Auth.status === constants.CONNECTOR_STATUS.AUTHORIZED) {
157
164
  setIsAuthorized(true);
158
165
  }
@@ -162,11 +169,11 @@ function useWeb3AuthInnerContextValue({
162
169
  if (typeof nextIsMFAEnabled === "boolean") setIsMFAEnabled(nextIsMFAEnabled);
163
170
  };
164
171
  const connectionUpdatedListener = () => {
165
- var _web3Auth$currentChai9, _web3Auth$currentChai0;
172
+ var _web3Auth$currentChai1, _web3Auth$currentChai10;
166
173
  setStatus(web3Auth.status);
167
174
  setConnection(web3Auth.connection);
168
175
  setChainId(web3Auth.currentChainId);
169
- 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);
176
+ 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);
170
177
  };
171
178
  if (web3Auth) {
172
179
  web3Auth.on(constants.CONNECTOR_EVENTS.NOT_READY, notReadyListener);
@@ -5,3 +5,9 @@ var provider = require('./provider.js');
5
5
 
6
6
 
7
7
  exports.WagmiProvider = provider.WagmiProvider;
8
+ exports.connectWeb3AuthWithWagmi = provider.connectWeb3AuthWithWagmi;
9
+ exports.createWeb3AuthConnectorForWagmi = provider.createWeb3AuthConnectorForWagmi;
10
+ exports.disconnectWeb3AuthFromWagmi = provider.disconnectWeb3AuthFromWagmi;
11
+ exports.getWeb3authConnector = provider.getWeb3authConnector;
12
+ exports.resetConnectorState = provider.resetConnectorState;
13
+ exports.setupConnector = provider.setupConnector;