@web3auth/no-modal 11.0.0-beta.2 → 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 (53) 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/metamask-connector/metamaskConnector.js +40 -31
  10. package/dist/lib.cjs/index.js +21 -16
  11. package/dist/lib.cjs/noModal.js +29 -11
  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 +11 -4
  16. package/dist/lib.cjs/react/wagmi/index.js +6 -0
  17. package/dist/lib.cjs/react/wagmi/provider.js +60 -41
  18. package/dist/lib.cjs/types/account-linking/errors.d.ts +17 -0
  19. package/dist/lib.cjs/types/account-linking/index.d.ts +1 -0
  20. package/dist/lib.cjs/types/base/connector/constants.d.ts +1 -0
  21. package/dist/lib.cjs/types/base/connector/interfaces.d.ts +1 -1
  22. package/dist/lib.cjs/types/base/errors/index.d.ts +2 -13
  23. package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +2 -2
  24. package/dist/lib.cjs/types/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.d.ts +1 -0
  25. package/dist/lib.cjs/types/react/wagmi/constants.d.ts +2 -0
  26. package/dist/lib.cjs/types/react/wagmi/provider.d.ts +7 -0
  27. package/dist/lib.cjs/types/vue/wagmi/constants.d.ts +2 -0
  28. package/dist/lib.cjs/types/vue/wagmi/provider.d.ts +7 -1
  29. package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +13 -6
  30. package/dist/lib.cjs/vue/wagmi/index.js +6 -0
  31. package/dist/lib.cjs/vue/wagmi/provider.js +53 -26
  32. package/dist/lib.esm/account-linking/errors.js +92 -0
  33. package/dist/lib.esm/account-linking/index.js +1 -0
  34. package/dist/lib.esm/account-linking/rest.js +3 -3
  35. package/dist/lib.esm/account-linking/vue.js +0 -1
  36. package/dist/lib.esm/base/connector/constants.js +2 -1
  37. package/dist/lib.esm/base/errors/index.js +21 -50
  38. package/dist/lib.esm/base/utils.js +1 -1
  39. package/dist/lib.esm/connectors/auth-connector/authConnector.js +29 -15
  40. package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +1 -1
  41. package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +42 -33
  42. package/dist/lib.esm/index.js +3 -2
  43. package/dist/lib.esm/noModal.js +25 -5
  44. package/dist/lib.esm/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +10 -5
  45. package/dist/lib.esm/providers/account-abstraction-provider/providers/utils.js +0 -3
  46. package/dist/lib.esm/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +17 -3
  47. package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +11 -4
  48. package/dist/lib.esm/react/wagmi/index.js +1 -1
  49. package/dist/lib.esm/react/wagmi/provider.js +59 -42
  50. package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +11 -4
  51. package/dist/lib.esm/vue/wagmi/index.js +1 -1
  52. package/dist/lib.esm/vue/wagmi/provider.js +48 -25
  53. package/package.json +19 -19
@@ -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,9 +149,12 @@ 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);
@@ -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;
@@ -5,7 +5,6 @@ var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
5
5
  var react = require('react');
6
6
  var viem = require('viem');
7
7
  var wagmi = require('wagmi');
8
- var connectors = require('wagmi/connectors');
9
8
  require('@babel/runtime/helpers/defineProperty');
10
9
  require('@segment/analytics-next');
11
10
  var loglevel = require('../../base/loglevel.js');
@@ -18,7 +17,7 @@ require('@toruslabs/http-helpers');
18
17
  require('../../base/constants.js');
19
18
  require('../../base/wallet/index.js');
20
19
  require('../../base/connector/connectorStatus.js');
21
- require('../../base/connector/constants.js');
20
+ var constants$1 = require('../../base/connector/constants.js');
22
21
  require('jwt-decode');
23
22
  require('../../base/plugin/errors.js');
24
23
  require('../../base/plugin/IPlugin.js');
@@ -29,28 +28,46 @@ var useWeb3AuthDisconnect = require('../hooks/useWeb3AuthDisconnect.js');
29
28
  var constants = require('./constants.js');
30
29
 
31
30
  const _excluded = ["children"];
32
- const WEB3AUTH_CONNECTOR_ID = "web3auth";
33
31
  function getWeb3authConnector(config) {
34
- return config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
32
+ return config.connectors.find(c => c.id === constants$1.WEB3AUTH_CONNECTOR_ID);
35
33
  }
36
- // Helper to initialize connectors for the given wallets
34
+ // Helper to create a Web3Auth connector to connect with wagmi
37
35
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- async function setupConnector(provider, config) {
39
- let connector = getWeb3authConnector(config);
40
- if (connector) return connector;
41
- // Create new connector if not already existing
42
- connector = connectors.injected({
36
+ function createWeb3AuthConnectorForWagmi(provider) {
37
+ const baseConnector = wagmi.injected({
43
38
  target: {
44
39
  provider: provider,
45
- id: WEB3AUTH_CONNECTOR_ID,
40
+ id: constants$1.WEB3AUTH_CONNECTOR_ID,
46
41
  name: "Web3Auth"
47
42
  }
48
43
  });
44
+ return config => {
45
+ const connector = baseConnector(config);
46
+ const baseOnAccountsChanged = connector.onAccountsChanged.bind(connector);
47
+ // we need to handle the `accountsChanged` event emitted on the cross-namespace chain switch.
48
+ // on evm -> solana, the accountsChanged event is emitted with the solana address, which is not valid for evm.
49
+ // that causes the `invalid account address` error in wagmi. So, here, we're filtering out the solana addresses.
50
+ connector.onAccountsChanged = accounts => {
51
+ if (accounts.length > 0 && !accounts.every(account => typeof account === "string" && viem.isAddress(account))) {
52
+ loglevel.log.warn("onAccountsChanged::accountsChanged event received on non-EVM address");
53
+ return;
54
+ }
55
+ baseOnAccountsChanged(accounts);
56
+ };
57
+ return connector;
58
+ };
59
+ }
60
+ // Helper to initialize connectors for the given wallets
61
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
+ function setupConnector(provider, config) {
63
+ let connector = getWeb3authConnector(config);
64
+ if (connector) return connector;
65
+ // Create new connector if not already existing
66
+ connector = createWeb3AuthConnectorForWagmi(provider);
49
67
  const result = config._internal.connectors.setup(connector);
50
68
  config._internal.connectors.setState(current => [...current, result]);
51
69
  return result;
52
70
  }
53
- // Helper to connect a wallet and update wagmi state
54
71
  async function connectWeb3AuthWithWagmi(connector, config) {
55
72
  var _config$storage, _config$storage2;
56
73
  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)]);
@@ -72,8 +89,8 @@ async function connectWeb3AuthWithWagmi(connector, config) {
72
89
  }));
73
90
  }
74
91
  function resetConnectorState(config) {
75
- config._internal.connectors.setState(prev => prev.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID));
76
- config.connectors.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID);
92
+ config._internal.connectors.setState(prev => prev.filter(c => c.id !== constants$1.WEB3AUTH_CONNECTOR_ID));
93
+ config.connectors.filter(c => c.id !== constants$1.WEB3AUTH_CONNECTOR_ID);
77
94
  }
78
95
  async function disconnectWeb3AuthFromWagmi(config) {
79
96
  var _config$storage3, _config$storage4;
@@ -90,6 +107,7 @@ async function disconnectWeb3AuthFromWagmi(config) {
90
107
  function Web3AuthWagmiProvider({
91
108
  children
92
109
  }) {
110
+ var _connection$ethereumP, _connection$connector;
93
111
  const {
94
112
  isConnected,
95
113
  connection,
@@ -103,59 +121,54 @@ function Web3AuthWagmiProvider({
103
121
  mutate: reconnect
104
122
  } = wagmi.useReconnect();
105
123
  const suppressWagmiDisconnect = react.useRef(false);
106
- const lastSyncedBinding = react.useRef({
107
- provider: null,
108
- connectorName: null
109
- });
124
+ const lastSyncedProvider = react.useRef((_connection$ethereumP = connection === null || connection === void 0 ? void 0 : connection.ethereumProvider) !== null && _connection$ethereumP !== void 0 ? _connection$ethereumP : null);
125
+ const lastSyncedConnectorName = react.useRef((_connection$connector = connection === null || connection === void 0 ? void 0 : connection.connectorName) !== null && _connection$connector !== void 0 ? _connection$connector : null);
110
126
  wagmi.useConnectionEffect({
111
127
  onDisconnect: async () => {
112
128
  loglevel.log.info("Disconnected from wagmi");
113
129
  const isSuppressed = suppressWagmiDisconnect.current;
114
130
  suppressWagmiDisconnect.current = false;
115
131
  if (!isSuppressed && isConnected) await disconnect();
116
- const connector = getWeb3authConnector(wagmiConfig);
117
132
  // reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
118
133
  // from the connected provider
119
- if (connector) {
134
+ if (getWeb3authConnector(wagmiConfig)) {
120
135
  resetConnectorState(wagmiConfig);
121
136
  }
122
137
  }
123
138
  });
124
139
  react.useEffect(() => {
125
- (async () => {
126
- const shouldBindToWagmi = isConnected && chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155 && Boolean(connection === null || connection === void 0 ? void 0 : connection.ethereumProvider);
140
+ (async _connection$ethereumP2 => {
141
+ const newConnection = connection !== null && connection !== void 0 ? connection : null;
142
+ const newEth = (_connection$ethereumP2 = connection === null || connection === void 0 ? void 0 : connection.ethereumProvider) !== null && _connection$ethereumP2 !== void 0 ? _connection$ethereumP2 : null;
143
+ const w3aWagmiConnector = getWeb3authConnector(wagmiConfig);
144
+ const shouldBindToWagmi = isConnected && chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155 && Boolean(newConnection && newEth);
127
145
  if (shouldBindToWagmi) {
128
- const hasSameBinding = lastSyncedBinding.current.provider === connection.ethereumProvider && lastSyncedBinding.current.connectorName === connection.connectorName;
129
- if (hasSameBinding && wagmiConfig.state.status === "connected") {
146
+ const hasSameBinding = lastSyncedProvider.current === newEth && lastSyncedConnectorName.current === newConnection.connectorName && wagmiConfig.state.status === "connected";
147
+ if (hasSameBinding) {
148
+ // rehydration: already connected to the same provider, so no need to reconnect
130
149
  return;
131
150
  }
132
- if (!hasSameBinding && getWeb3authConnector(wagmiConfig)) {
133
- if (wagmiConfig.state.status === "connected") {
134
- suppressWagmiDisconnect.current = true;
135
- await disconnectWeb3AuthFromWagmi(wagmiConfig);
136
- } else {
137
- resetConnectorState(wagmiConfig);
138
- }
151
+ // `ethereumProvider` is a stable proxy (`commonJRPCProvider`) across account switches,
152
+ // so key wagmi resyncs off the Web3Auth connection object instead of provider identity.
153
+ if (w3aWagmiConnector) {
154
+ resetConnectorState(wagmiConfig);
139
155
  }
140
- const connector = await setupConnector(connection.ethereumProvider, wagmiConfig);
156
+ lastSyncedProvider.current = newEth;
157
+ lastSyncedConnectorName.current = newConnection.connectorName;
158
+ const connector = setupConnector(newEth, wagmiConfig);
141
159
  if (!connector) {
160
+ loglevel.log.error("Failed to setup react wagmi connector");
142
161
  throw new Error("Failed to setup connector");
143
162
  }
144
163
  await connectWeb3AuthWithWagmi(connector, wagmiConfig);
145
- lastSyncedBinding.current = {
146
- provider: connection.ethereumProvider,
147
- connectorName: connection.connectorName
148
- };
149
164
  reconnect();
150
165
  } else {
151
- lastSyncedBinding.current = {
152
- provider: null,
153
- connectorName: null
154
- };
166
+ lastSyncedProvider.current = null;
167
+ lastSyncedConnectorName.current = null;
155
168
  if (wagmiConfig.state.status === "connected") {
156
169
  suppressWagmiDisconnect.current = true;
157
170
  await disconnectWeb3AuthFromWagmi(wagmiConfig);
158
- } else if (getWeb3authConnector(wagmiConfig)) {
171
+ } else if (w3aWagmiConnector) {
159
172
  resetConnectorState(wagmiConfig);
160
173
  }
161
174
  }
@@ -255,3 +268,9 @@ function WagmiProvider(_ref) {
255
268
  }
256
269
 
257
270
  exports.WagmiProvider = WagmiProvider;
271
+ exports.connectWeb3AuthWithWagmi = connectWeb3AuthWithWagmi;
272
+ exports.createWeb3AuthConnectorForWagmi = createWeb3AuthConnectorForWagmi;
273
+ exports.disconnectWeb3AuthFromWagmi = disconnectWeb3AuthFromWagmi;
274
+ exports.getWeb3authConnector = getWeb3authConnector;
275
+ exports.resetConnectorState = resetConnectorState;
276
+ exports.setupConnector = setupConnector;
@@ -0,0 +1,17 @@
1
+ import { ErrorCodes, Web3AuthError } from "../base";
2
+ export declare class AccountLinkingError extends Web3AuthError {
3
+ protected static messages: ErrorCodes;
4
+ constructor(code: number, message?: string, cause?: unknown);
5
+ static fromCode(code: number, extraMessage?: string, cause?: unknown): AccountLinkingError;
6
+ static requestFailed(extraMessage?: string, cause?: unknown): AccountLinkingError;
7
+ static serverNotConfigured(extraMessage?: string, cause?: unknown): AccountLinkingError;
8
+ static primaryTokenNotAvailable(extraMessage?: string, cause?: unknown): AccountLinkingError;
9
+ static walletProofFailed(extraMessage?: string, cause?: unknown): AccountLinkingError;
10
+ static unsupportedConnector(extraMessage?: string, cause?: unknown): AccountLinkingError;
11
+ static cannotUnlinkActiveAccount(): AccountLinkingError;
12
+ static accountNotLinked(message?: string, cause?: unknown): AccountLinkingError;
13
+ static cannotUnlinkPrimaryAccount(): AccountLinkingError;
14
+ toString(): string;
15
+ }
16
+ export declare function getAccountLinkingRequestError(error: unknown): Promise<AccountLinkingError>;
17
+ export declare function formatAccountLinkingErrorMessage(error: unknown, fallbackMessage?: string): string;
@@ -1,2 +1,3 @@
1
+ export * from "./errors";
1
2
  export * from "./interfaces";
2
3
  export * from "./rest";
@@ -1,3 +1,4 @@
1
+ export declare const WEB3AUTH_CONNECTOR_ID = "web3auth";
1
2
  export declare const CONNECTOR_STATUS: {
2
3
  readonly NOT_READY: "not_ready";
3
4
  readonly READY: "ready";
@@ -1,4 +1,4 @@
1
- import { CaipAccountId } from "@metamask/connect-evm";
1
+ import { type CaipAccountId } from "@metamask/connect-evm";
2
2
  import type { Wallet } from "@wallet-standard/base";
3
3
  import { AUTH_CONNECTION_TYPE, AuthUserInfo, ExtraLoginOptions, JRPCRequest, JRPCResponse, Maybe, RequestArguments, SafeEventEmitter, SendCallBack, UX_MODE, type UX_MODE_TYPE, WEB3AUTH_NETWORK, type WEB3AUTH_NETWORK_TYPE } from "@web3auth/auth";
4
4
  import { BaseLinkedAccountInfo } from "../../account-linking/interfaces";
@@ -56,19 +56,7 @@ export declare class WalletOperationsError extends Web3AuthError {
56
56
  static chainIDNotAllowed(extraMessage?: string, cause?: unknown): IWeb3AuthError;
57
57
  static operationNotAllowed(extraMessage?: string, cause?: unknown): IWeb3AuthError;
58
58
  static chainNamespaceNotAllowed(extraMessage?: string, cause?: unknown): IWeb3AuthError;
59
- }
60
- export declare class AccountLinkingError extends Web3AuthError {
61
- protected static messages: ErrorCodes;
62
- constructor(code: number, message?: string, cause?: unknown);
63
- static fromCode(code: number, extraMessage?: string, cause?: unknown): AccountLinkingError;
64
- static requestFailed(extraMessage?: string, cause?: unknown): AccountLinkingError;
65
- static serverNotConfigured(extraMessage?: string, cause?: unknown): AccountLinkingError;
66
- static primaryTokenNotAvailable(extraMessage?: string, cause?: unknown): AccountLinkingError;
67
- static walletProofFailed(extraMessage?: string, cause?: unknown): AccountLinkingError;
68
- static unsupportedConnector(extraMessage?: string, cause?: unknown): AccountLinkingError;
69
- static cannotUnlinkActiveAccount(): AccountLinkingError;
70
- static accountNotLinked(message?: string, cause?: unknown): AccountLinkingError;
71
- static cannotUnlinkPrimaryAccount(): AccountLinkingError;
59
+ static userRejected(extraMessage?: string, cause?: unknown): IWeb3AuthError;
72
60
  }
73
61
  export declare class WalletProviderError extends Web3AuthError {
74
62
  protected static messages: ErrorCodes;
@@ -78,3 +66,4 @@ export declare class WalletProviderError extends Web3AuthError {
78
66
  static invalidRequestMethod(extraMessage?: string, cause?: unknown): IWeb3AuthError;
79
67
  static invalidRequestParams(extraMessage?: string, cause?: unknown): IWeb3AuthError;
80
68
  }
69
+ export declare function isUserRejectedError(error: unknown): boolean;
@@ -2,8 +2,8 @@ import { ChainNamespaceType } from "@toruslabs/base-controllers";
2
2
  import type { Wallet } from "@wallet-standard/base";
3
3
  import { Auth, AuthConnectionConfigItem } from "@web3auth/auth";
4
4
  import { type default as WsEmbed } from "@web3auth/ws-embed";
5
- import { LinkAccountResult, UnlinkAccountResult } from "../../account-linking";
6
- import { AccountLinkingError, AuthLoginParams, AuthTokenInfo, BaseConnector, BaseConnectorLoginParams, type Connection, CONNECTOR_CATEGORY_TYPE, CONNECTOR_STATUS_TYPE, ConnectorFn, ConnectorInitOptions, ConnectorNamespaceType, IConnector, IProvider, LinkedAccountInfo, UserInfo, WALLET_CONNECTOR_TYPE } from "../../base";
5
+ import { AccountLinkingError, LinkAccountResult, UnlinkAccountResult } from "../../account-linking";
6
+ import { AuthLoginParams, AuthTokenInfo, BaseConnector, BaseConnectorLoginParams, type Connection, CONNECTOR_CATEGORY_TYPE, CONNECTOR_STATUS_TYPE, ConnectorFn, ConnectorInitOptions, ConnectorNamespaceType, IConnector, IProvider, LinkedAccountInfo, UserInfo, WALLET_CONNECTOR_TYPE } from "../../base";
7
7
  import { type AuthConnectorLinkAccountParams, type AuthConnectorOptions, type AuthConnectorSwitchAccountContext, type AuthConnectorSwitchAccountResult, type AuthConnectorUnlinkAccountParams, IAuthConnector, type PrivateKeyProvider } from "./interface";
8
8
  declare class AuthConnector extends BaseConnector<AuthLoginParams> implements IAuthConnector {
9
9
  readonly name: WALLET_CONNECTOR_TYPE;
@@ -8,4 +8,5 @@ export declare function createAaMiddleware({ eoaProvider, handlers, }: {
8
8
  export declare function createEoaMiddleware({ aaProvider }: {
9
9
  aaProvider: IProvider;
10
10
  }): Promise<MiddlewareConstraint>;
11
+ export declare function createEip7702And5792MiddlewareForAaProvider(): Promise<MiddlewareConstraint>;
11
12
  export declare function providerAsMiddleware(provider: IProvider): MiddlewareConstraint;
@@ -38,8 +38,10 @@ export declare const defaultWagmiConfig: import("wagmi").Config<readonly [{
38
38
  fees?: import("viem").ChainFees<undefined> | undefined;
39
39
  formatters?: undefined;
40
40
  prepareTransactionRequest?: ((args: import("viem").PrepareTransactionRequestParameters, options: {
41
+ client: import("viem").Client;
41
42
  phase: "beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters";
42
43
  }) => Promise<import("viem").PrepareTransactionRequestParameters>) | [fn: ((args: import("viem").PrepareTransactionRequestParameters, options: {
44
+ client: import("viem").Client;
43
45
  phase: "beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters";
44
46
  }) => Promise<import("viem").PrepareTransactionRequestParameters>) | undefined, options: {
45
47
  runAt: readonly ("beforeFillTransaction" | "beforeFillParameters" | "afterFillParameters")[];