@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
@@ -1,5 +1,6 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
+ import { CHAIN_NAMESPACES, getCaipChainId, cloneDeep } from '@toruslabs/base-controllers';
3
4
  import { CITADEL_SERVER_MAP } from '@toruslabs/constants';
4
5
  import { get, put } from '@toruslabs/http-helpers';
5
6
  import { SecurePubSub } from '@toruslabs/secure-pub-sub';
@@ -8,18 +9,27 @@ import { WS_EMBED_LOGIN_MODE } from '@web3auth/ws-embed';
8
9
  import deepmerge from 'deepmerge';
9
10
  import { generateNonce, parseToken } from '../utils.js';
10
11
  import { AuthSolanaWallet } from './authSolanaWallet.js';
11
- import { WalletLoginError, WalletInitializationError, Web3AuthError, AccountLinkingError } from '../../base/errors/index.js';
12
+ import { WalletLoginError, WalletInitializationError, Web3AuthError } from '../../base/errors/index.js';
12
13
  import { WALLET_CONNECTORS } from '../../base/wallet/index.js';
13
14
  import { BaseConnector } from '../../base/connector/baseConnector.js';
14
15
  import { CONNECTOR_NAMESPACES } from '../../base/chain/IChainInterface.js';
15
16
  import { CONNECTOR_CATEGORY, CONNECTOR_STATUS, CONNECTOR_EVENTS } from '../../base/connector/constants.js';
16
- import { Analytics, ANALYTICS_EVENTS } from '../../base/analytics.js';
17
- import { log } from '../../base/loglevel.js';
18
- import { citadelServerUrl, getCaipChainId, getErrorAnalyticsProperties, parseChainNamespaceFromCitadelResponse } from '../../base/utils.js';
19
17
  import { CONNECTED_STATUSES } from '../../base/connector/connectorStatus.js';
18
+ import { log } from '../../base/loglevel.js';
19
+ import { Analytics, ANALYTICS_EVENTS } from '../../base/analytics.js';
20
+ import { citadelServerUrl, getErrorAnalyticsProperties, parseChainNamespaceFromCitadelResponse } from '../../base/utils.js';
21
+ import { AccountLinkingError } from '../../account-linking/errors.js';
20
22
  import { makeAccountLinkingRequest, makeAccountUnlinkingRequest } from '../../account-linking/rest.js';
21
- import { CHAIN_NAMESPACES, cloneDeep } from '@toruslabs/base-controllers';
22
23
 
24
+ // Auth connections that have been deprecated and are no longer supported by the SDK.
25
+ // Passing any of these as `authConnection` results in a hard error so consumers
26
+ // migrate off the removed providers instead of silently continuing.
27
+ const DEPRECATED_AUTH_CONNECTIONS = new Set(["farcaster"]);
28
+ function assertAuthConnectionSupported(authConnection) {
29
+ if (DEPRECATED_AUTH_CONNECTIONS.has(authConnection)) {
30
+ throw WalletInitializationError.invalidParams(`Auth connection "${authConnection}" has been deprecated and is no longer supported by the Web3Auth SDKs. ` + `Please use a different authConnection value.`);
31
+ }
32
+ }
23
33
  class AuthConnector extends BaseConnector {
24
34
  constructor(params) {
25
35
  super(params);
@@ -37,8 +47,22 @@ class AuthConnector extends BaseConnector {
37
47
  _defineProperty(this, "wsEmbedInstance", null);
38
48
  _defineProperty(this, "authConnectionConfig", []);
39
49
  _defineProperty(this, "wsEmbedInstancePromise", null);
50
+ _defineProperty(this, "wsEmbedProviderListenerTarget", null);
40
51
  _defineProperty(this, "_solanaWallet", null);
41
52
  _defineProperty(this, "analytics", void 0);
53
+ _defineProperty(this, "handleWsEmbedAccountsChanged", accounts => {
54
+ if (accounts.length === 0) {
55
+ if (!CONNECTED_STATUSES.includes(this.status)) {
56
+ return;
57
+ }
58
+ log.info("No accounts found in the wallet, disconnecting");
59
+ void this.disconnect({
60
+ cleanup: true
61
+ }).catch(error => {
62
+ log.error("Failed to disconnect auth connector after wallet accounts changed", error);
63
+ });
64
+ }
65
+ });
42
66
  this.authOptions = params.connectorSettings;
43
67
  this.loginSettings = params.loginSettings || {
44
68
  authConnection: ""
@@ -51,10 +75,8 @@ class AuthConnector extends BaseConnector {
51
75
  }
52
76
  get provider() {
53
77
  if (this.status !== CONNECTOR_STATUS.NOT_READY) {
54
- var _this$wsEmbedInstance;
55
- if ((_this$wsEmbedInstance = this.wsEmbedInstance) !== null && _this$wsEmbedInstance !== void 0 && _this$wsEmbedInstance.provider) {
56
- return this.wsEmbedInstance.provider;
57
- } else if (this.privateKeyProvider) return this.privateKeyProvider;
78
+ const wsEmbedProvider = this.getWsEmbedProvider();
79
+ return wsEmbedProvider || this.privateKeyProvider;
58
80
  }
59
81
  return null;
60
82
  }
@@ -123,6 +145,7 @@ class AuthConnector extends BaseConnector {
123
145
  buildEnv: this.authOptions.buildEnv,
124
146
  whiteLabel: _objectSpread(_objectSpread({}, this.authOptions.whiteLabel), this.wsSettings.whiteLabel)
125
147
  })).then(() => {
148
+ this.bindWsEmbedProviderEvents();
126
149
  this.wsEmbedInstancePromise = null;
127
150
  return;
128
151
  });
@@ -172,6 +195,7 @@ class AuthConnector extends BaseConnector {
172
195
  }
173
196
  }
174
197
  async connect(params) {
198
+ assertAuthConnectionSupported(params === null || params === void 0 ? void 0 : params.authConnection);
175
199
  super.checkConnectionRequirements();
176
200
  this.status = CONNECTOR_STATUS.CONNECTING;
177
201
  this.emit(CONNECTOR_EVENTS.CONNECTING, _objectSpread(_objectSpread({}, params), {}, {
@@ -201,6 +225,7 @@ class AuthConnector extends BaseConnector {
201
225
  async enableMFA(params = {
202
226
  authConnection: ""
203
227
  }) {
228
+ assertAuthConnectionSupported(params === null || params === void 0 ? void 0 : params.authConnection);
204
229
  if (!this.connected) throw WalletLoginError.notConnectedError("Not connected with wallet");
205
230
  if (!this.authInstance) throw WalletInitializationError.notReady("authInstance is not ready");
206
231
  try {
@@ -218,6 +243,7 @@ class AuthConnector extends BaseConnector {
218
243
  async manageMFA(params = {
219
244
  authConnection: ""
220
245
  }) {
246
+ assertAuthConnectionSupported(params === null || params === void 0 ? void 0 : params.authConnection);
221
247
  if (!this.connected) throw WalletLoginError.notConnectedError("Not connected with wallet");
222
248
  if (!this.authInstance) throw WalletInitializationError.notReady("authInstance is not ready");
223
249
  try {
@@ -249,6 +275,7 @@ class AuthConnector extends BaseConnector {
249
275
  }
250
276
  this.rehydrated = false;
251
277
  this._solanaWallet = null;
278
+ this.unbindWsEmbedProviderEvents();
252
279
  this.emit(CONNECTOR_EVENTS.DISCONNECTED, {
253
280
  connector: WALLET_CONNECTORS.AUTH
254
281
  });
@@ -285,6 +312,7 @@ class AuthConnector extends BaseConnector {
285
312
  });
286
313
  }
287
314
  async getLinkedAccounts() {
315
+ var _citadelUserInfo$acco, _this$solanaWallet;
288
316
  const accessToken = await this.authInstance.authSessionManager.getAccessToken();
289
317
  if (!accessToken) throw WalletLoginError.connectionError("Could not obtain an access token from the current AUTH session.");
290
318
  const citadelUserInfo = await get(`${citadelServerUrl(this.coreOptions.authBuildEnv)}/v1/user`, {
@@ -292,11 +320,28 @@ class AuthConnector extends BaseConnector {
292
320
  Authorization: `Bearer ${accessToken}`
293
321
  }
294
322
  });
295
- const linkedAccounts = (citadelUserInfo === null || citadelUserInfo === void 0 ? void 0 : citadelUserInfo.accounts) || [];
296
- return linkedAccounts.map(account => _objectSpread(_objectSpread({}, account), {}, {
297
- // by default, the primary account is the active account
298
- active: account.isPrimary
299
- }));
323
+ if (!(citadelUserInfo !== null && citadelUserInfo !== void 0 && (_citadelUserInfo$acco = citadelUserInfo.accounts) !== null && _citadelUserInfo$acco !== void 0 && _citadelUserInfo$acco.length)) return [];
324
+ const currentChainNamespace = ((_this$solanaWallet = this.solanaWallet) === null || _this$solanaWallet === void 0 ? void 0 : _this$solanaWallet.accounts.length) > 0 ? CHAIN_NAMESPACES.SOLANA : "evm"; // Note: citadel chain namespace is "evm" for EVM chains
325
+ const filteredLinkedAccounts = [];
326
+ for (const account of citadelUserInfo.accounts) {
327
+ const {
328
+ chainNamespace,
329
+ isPrimary,
330
+ accountType
331
+ } = account;
332
+
333
+ // for now, we will take all primary accounts as a **SINGLE** linked account
334
+ // we don't wanna populate the multiple primary accounts as different linked accounts
335
+ // so, we hide the primary accounts for other chain namespaces
336
+ // also, linked `account_abstraction` accounts are derived from the primary account, so we don't need to show them separately
337
+ // TODO: revisit this logic once we have a concrete plan for handling multiple primary accounts
338
+ if (isPrimary && chainNamespace && chainNamespace !== currentChainNamespace || accountType === "account_abstraction") continue;
339
+ filteredLinkedAccounts.push(_objectSpread(_objectSpread({}, account), {}, {
340
+ // by default, the primary account is the active account
341
+ active: isPrimary
342
+ }));
343
+ }
344
+ return filteredLinkedAccounts;
300
345
  }
301
346
  async switchChain(params, init = false) {
302
347
  super.checkSwitchChainRequirements(params, init);
@@ -310,13 +355,13 @@ class AuthConnector extends BaseConnector {
310
355
  const newChainConfig = this.coreOptions.chains.find(c => c.chainId === newChainId);
311
356
  if (!newChainConfig) throw WalletInitializationError.invalidParams("Chain config is not available");
312
357
  if (newChainConfig.chainNamespace === CHAIN_NAMESPACES.SOLANA || newChainConfig.chainNamespace === CHAIN_NAMESPACES.EIP155) {
313
- var _this$wsEmbedInstance2;
314
- if (!((_this$wsEmbedInstance2 = this.wsEmbedInstance) !== null && _this$wsEmbedInstance2 !== void 0 && _this$wsEmbedInstance2.provider)) throw WalletInitializationError.notReady("Wallet embed is not ready");
315
- const fullChainId = getCaipChainId(newChainConfig);
358
+ var _this$wsEmbedInstance;
359
+ if (!((_this$wsEmbedInstance = this.wsEmbedInstance) !== null && _this$wsEmbedInstance !== void 0 && _this$wsEmbedInstance.provider)) throw WalletInitializationError.notReady("Wallet embed is not ready");
360
+ const caipChainId = getCaipChainId(newChainConfig);
316
361
  await this.wsEmbedInstance.provider.request({
317
362
  method: "wallet_switchChain",
318
363
  params: {
319
- chainId: fullChainId
364
+ chainId: caipChainId
320
365
  }
321
366
  });
322
367
  } else {
@@ -330,6 +375,8 @@ class AuthConnector extends BaseConnector {
330
375
  if (this.wsEmbedInstance) {
331
376
  this.wsEmbedInstance.clearInit();
332
377
  }
378
+ this._solanaWallet = null;
379
+ this.unbindWsEmbedProviderEvents();
333
380
  }
334
381
  getOAuthProviderConfig(params) {
335
382
  const {
@@ -416,11 +463,11 @@ class AuthConnector extends BaseConnector {
416
463
  const {
417
464
  connectorName,
418
465
  chainId,
419
- walletConnector
466
+ connectorToLink
420
467
  } = params;
421
468
  try {
422
- if (!walletConnector.connected) {
423
- const connection = await walletConnector.connect({
469
+ if (!connectorToLink.connected) {
470
+ const connection = await connectorToLink.connect({
424
471
  chainId,
425
472
  isAccountLinking: true
426
473
  });
@@ -429,9 +476,7 @@ class AuthConnector extends BaseConnector {
429
476
  }
430
477
  }
431
478
  } catch (error) {
432
- if (error instanceof AccountLinkingError) {
433
- throw error;
434
- }
479
+ if (error instanceof Web3AuthError) throw error;
435
480
  throw AccountLinkingError.walletProofFailed(error instanceof Error ? error.message : String(error), error);
436
481
  }
437
482
  const trackData = {
@@ -445,7 +490,7 @@ class AuthConnector extends BaseConnector {
445
490
  accessToken,
446
491
  idToken
447
492
  } = await this.getPrimaryAuthSession(params.authSessionTokens);
448
- const walletProof = await this.createWalletLinkingProof(params.walletConnector);
493
+ const walletProof = await this.createWalletLinkingProof(params.connectorToLink);
449
494
  const authServerUrl = citadelServerUrl(this.coreOptions.authBuildEnv);
450
495
  const result = await makeAccountLinkingRequest(authServerUrl, accessToken, {
451
496
  idToken,
@@ -466,9 +511,11 @@ class AuthConnector extends BaseConnector {
466
511
 
467
512
  // disconnect the wallet connector to avoid any leftover state
468
513
  try {
469
- await walletConnector.disconnect({
470
- cleanup: true
471
- });
514
+ if (connectorToLink.connected) {
515
+ await connectorToLink.disconnect({
516
+ cleanup: true
517
+ });
518
+ }
472
519
  } catch (disconnectError) {
473
520
  log.debug("Failed to disconnect wallet connector after linking failure", disconnectError);
474
521
  }
@@ -690,9 +737,35 @@ class AuthConnector extends BaseConnector {
690
737
  }
691
738
  return accounts[0];
692
739
  }
740
+ getWsEmbedProvider() {
741
+ var _ref, _this$wsEmbedInstance2;
742
+ return (_ref = (_this$wsEmbedInstance2 = this.wsEmbedInstance) === null || _this$wsEmbedInstance2 === void 0 ? void 0 : _this$wsEmbedInstance2.provider) !== null && _ref !== void 0 ? _ref : null;
743
+ }
744
+ bindWsEmbedProviderEvents() {
745
+ const rawProvider = this.getWsEmbedProvider();
746
+ if (this.wsEmbedProviderListenerTarget === rawProvider) {
747
+ return;
748
+ }
749
+ this.unbindWsEmbedProviderEvents();
750
+ if (!rawProvider) {
751
+ return;
752
+ }
753
+ rawProvider.on("accountsChanged", this.handleWsEmbedAccountsChanged);
754
+ this.wsEmbedProviderListenerTarget = rawProvider;
755
+ }
756
+ unbindWsEmbedProviderEvents() {
757
+ if (!this.wsEmbedProviderListenerTarget) {
758
+ return;
759
+ }
760
+ this.wsEmbedProviderListenerTarget.removeListener("accountsChanged", this.handleWsEmbedAccountsChanged);
761
+ this.wsEmbedProviderListenerTarget = null;
762
+ }
693
763
  setupSolanaWallet() {
694
764
  const solanaChains = this.coreOptions.chains.filter(c => c.chainNamespace === CHAIN_NAMESPACES.SOLANA);
695
765
  if (solanaChains.length === 0 || !this.provider) return;
766
+ if (this._solanaWallet instanceof AuthSolanaWallet) {
767
+ return;
768
+ }
696
769
  this._solanaWallet = new AuthSolanaWallet(this.provider, solanaChains);
697
770
  }
698
771
  _getFinalPrivKey() {
@@ -755,13 +828,13 @@ class AuthConnector extends BaseConnector {
755
828
  } = this.authInstance || {};
756
829
  if (sessionId) {
757
830
  this.wsEmbedInstance.setAccessTokenProvider(this.accessTokenProvider.bind(this));
831
+ this.bindWsEmbedProviderEvents();
758
832
  const isLoggedIn = await this.wsEmbedInstance.connectWithSession({
759
833
  sessionId,
760
834
  sessionNamespace,
761
835
  idToken: await this.getIdToken()
762
836
  });
763
837
  if (isLoggedIn) {
764
- var _this$wsEmbedInstance3;
765
838
  this.setupSolanaWallet();
766
839
  // if getAuthTokenInfo is true, then get auth token info
767
840
  // No need to get auth token info for auth connector as it is already handled
@@ -775,12 +848,6 @@ class AuthConnector extends BaseConnector {
775
848
  if (params.getAuthTokenInfo) {
776
849
  await this.getAuthTokenInfo();
777
850
  }
778
- // handle disconnect from ws embed
779
- (_this$wsEmbedInstance3 = this.wsEmbedInstance) === null || _this$wsEmbedInstance3 === void 0 || _this$wsEmbedInstance3.provider.on("accountsChanged", (accounts = []) => {
780
- if (accounts.length === 0 && CONNECTED_STATUSES.includes(this.status)) this.disconnect({
781
- cleanup: false
782
- });
783
- });
784
851
  }
785
852
  }
786
853
  } else {
@@ -882,9 +949,7 @@ class AuthConnector extends BaseConnector {
882
949
  }).catch(error => {
883
950
  // swallow the error, dont need to throw.
884
951
  log.error("Error during login with social", error);
885
- this.auditOAuditProgress(loginParams, "failed").catch(error => {
886
- log.error("Error reporting `oauthFailed` audit progress", error);
887
- });
952
+ this.reportFailedOauthAudit(loginParams);
888
953
  });
889
954
  verifierWindow.once("close", () => {
890
955
  if (!isClosedWindow) {
@@ -894,9 +959,7 @@ class AuthConnector extends BaseConnector {
894
959
  }
895
960
  });
896
961
  this.authInstance.postLoginInitiatedMessage(loginParams, nonce).then(resolve).catch(error => {
897
- this.auditOAuditProgress(loginParams, "failed").catch(error => {
898
- log.error("Error reporting `oauthFailed` audit progress", error);
899
- });
962
+ this.reportFailedOauthAudit(loginParams);
900
963
  if (error instanceof Web3AuthError) {
901
964
  throw error;
902
965
  }
@@ -1012,6 +1075,11 @@ class AuthConnector extends BaseConnector {
1012
1075
  }
1013
1076
  await put(auditServerUrl, auditPayload);
1014
1077
  }
1078
+ reportFailedOauthAudit(loginParams) {
1079
+ void this.auditOAuditProgress(loginParams, "failed").catch(error => {
1080
+ log.error("Error reporting `oauthFailed` audit progress", error);
1081
+ });
1082
+ }
1015
1083
  }
1016
1084
  const authConnector = params => {
1017
1085
  return ({
@@ -2,9 +2,9 @@ import { CHAIN_NAMESPACES, signChallenge } from '@toruslabs/base-controllers';
2
2
  import { generateSiweNonce } from 'viem/siwe';
3
3
  import { WalletLoginError, WalletInitializationError } from '../../base/errors/index.js';
4
4
  import { citadelServerUrl } from '../../base/utils.js';
5
- import { getSolanaChainByChainConfig, walletSignMessage } from '../../base/wallet/solana.js';
6
5
  import { BaseConnector } from '../../base/connector/baseConnector.js';
7
6
  import { CONNECTOR_STATUS, CONNECTOR_EVENTS } from '../../base/connector/constants.js';
7
+ import { getSolanaChainByChainConfig, walletSignMessage } from '../../base/wallet/solana.js';
8
8
 
9
9
  class BaseSolanaConnector extends BaseConnector {
10
10
  async init(_) {}
@@ -12,11 +12,11 @@ import { getSiteName } from '../utils.js';
12
12
  import { CONNECTOR_NAMESPACES } from '../../base/chain/IChainInterface.js';
13
13
  import { WALLET_CONNECTORS } from '../../base/wallet/index.js';
14
14
  import { getCaipChainId, citadelServerUrl } from '../../base/utils.js';
15
- import { WalletLoginError, Web3AuthError } from '../../base/errors/index.js';
15
+ import { WalletLoginError, isUserRejectedError, WalletOperationsError, Web3AuthError } from '../../base/errors/index.js';
16
16
  import { ANALYTICS_EVENTS } from '../../base/analytics.js';
17
+ import { getSolanaChainByChainConfig, walletSignMessage } from '../../base/wallet/solana.js';
17
18
  import { BaseConnector } from '../../base/connector/baseConnector.js';
18
19
  import { CONNECTOR_CATEGORY, CONNECTOR_STATUS, CONNECTOR_EVENTS } from '../../base/connector/constants.js';
19
- import { getSolanaChainByChainConfig, walletSignMessage } from '../../base/wallet/solana.js';
20
20
 
21
21
  /**
22
22
  * Configuration options for the MetaMask connector using \@metamask/connect-evm
@@ -113,7 +113,11 @@ class MetaMaskConnector extends BaseConnector {
113
113
  supportedNetworks: caipSupportedNetworks
114
114
  },
115
115
  ui,
116
- debug: (_this$connectorSettin0 = this.connectorSettings) === null || _this$connectorSettin0 === void 0 ? void 0 : _this$connectorSettin0.debug
116
+ debug: (_this$connectorSettin0 = this.connectorSettings) === null || _this$connectorSettin0 === void 0 ? void 0 : _this$connectorSettin0.debug,
117
+ analytics: {
118
+ integrationType: "web3auth",
119
+ enabled: !this.coreOptions.disableAnalytics
120
+ }
117
121
  });
118
122
 
119
123
  // Listen for QR code URI from the multichain client (for mobile wallet connection)
@@ -133,19 +137,27 @@ class MetaMaskConnector extends BaseConnector {
133
137
  dapp,
134
138
  eventHandlers: {
135
139
  accountsChanged: _accounts => {
136
- if (_accounts.length === 0) {
140
+ if (_accounts.length === 0 && this.connected) {
137
141
  this.disconnect();
138
142
  }
139
143
  },
140
144
  chainChanged: _chainId => {},
141
145
  connect: _result => {},
142
- disconnect: () => this.disconnect()
146
+ disconnect: () => {
147
+ if (this.connected) {
148
+ this.disconnect();
149
+ }
150
+ }
143
151
  },
144
152
  api: {
145
153
  supportedNetworks: hexSupportedNetworks
146
154
  },
147
155
  ui,
148
- debug: (_this$connectorSettin1 = this.connectorSettings) === null || _this$connectorSettin1 === void 0 ? void 0 : _this$connectorSettin1.debug
156
+ debug: (_this$connectorSettin1 = this.connectorSettings) === null || _this$connectorSettin1 === void 0 ? void 0 : _this$connectorSettin1.debug,
157
+ analytics: {
158
+ integrationType: "web3auth",
159
+ enabled: !this.coreOptions.disableAnalytics
160
+ }
149
161
  });
150
162
  this.evmProvider = this.evmClient.getProvider();
151
163
  }
@@ -157,7 +169,11 @@ class MetaMaskConnector extends BaseConnector {
157
169
  api: {
158
170
  supportedNetworks: solanaSupportedNetworks
159
171
  },
160
- skipAutoRegister: true
172
+ skipAutoRegister: true,
173
+ analytics: {
174
+ integrationType: "web3auth",
175
+ enabled: !this.coreOptions.disableAnalytics
176
+ }
161
177
  });
162
178
  this.solanaProvider = this.solanaClient.getWallet();
163
179
  }
@@ -172,32 +188,20 @@ class MetaMaskConnector extends BaseConnector {
172
188
  return;
173
189
  }
174
190
  const coreStatus = this.multichainClient.status;
175
- if (coreStatus === "connected") {
191
+ // only connect if the multichain client is connected and autoConnect is true (i.e during the rehydration)
192
+ if (coreStatus === "connected" && options.autoConnect) {
176
193
  this.status = CONNECTOR_STATUS.CONNECTED;
177
194
  this.rehydrated = true;
178
- if (options.autoConnect) {
179
- this.emit(CONNECTOR_EVENTS.CONNECTED, {
180
- connectorName: WALLET_CONNECTORS.METAMASK,
181
- reconnected: this.rehydrated,
182
- ethereumProvider: this.evmProvider,
183
- solanaWallet: this.solanaProvider
184
- });
185
- if (options.getAuthTokenInfo) {
186
- await this.getAuthTokenInfo();
187
- }
188
- }
189
- } else if (coreStatus === "loaded" || coreStatus === "disconnected") {
190
- this.status = CONNECTOR_STATUS.READY;
191
- this.emit(CONNECTOR_EVENTS.READY, WALLET_CONNECTORS.METAMASK);
192
- } else if (coreStatus === "pending") {
193
- // 'pending' implies that a transport failed to resume the connection
194
- // if (options.autoConnect) {
195
- // this.rehydrated = false;
196
- // this.emit(CONNECTOR_EVENTS.REHYDRATION_ERROR, new Error("Failed to resume existing MetaMask Connect session.") as Web3AuthError);
197
- // } else {
195
+ this.emit(CONNECTOR_EVENTS.CONNECTED, {
196
+ connectorName: WALLET_CONNECTORS.METAMASK,
197
+ reconnected: true,
198
+ ethereumProvider: this.evmProvider,
199
+ solanaWallet: this.solanaProvider
200
+ });
201
+ if (options.getAuthTokenInfo) await this.getAuthTokenInfo();
202
+ } else if (coreStatus === "connected" || coreStatus === "loaded" || coreStatus === "disconnected" || coreStatus === "pending") {
198
203
  this.status = CONNECTOR_STATUS.READY;
199
204
  this.emit(CONNECTOR_EVENTS.READY, WALLET_CONNECTORS.METAMASK);
200
- // }
201
205
  } else {
202
206
  // Something unexpected happened
203
207
  this.status = CONNECTOR_STATUS.ERRORED;
@@ -234,11 +238,15 @@ class MetaMaskConnector extends BaseConnector {
234
238
  connector: WALLET_CONNECTORS.METAMASK
235
239
  });
236
240
  const evmConnectedPromise = new Promise(resolve => {
237
- var _this$evmProvider;
238
- // Wait for EVM provider to be ready
239
- (_this$evmProvider = this.evmProvider) === null || _this$evmProvider === void 0 || _this$evmProvider.once("connect", () => {
241
+ if (this.evmClient.status === "connected") {
240
242
  resolve();
241
- });
243
+ } else {
244
+ var _this$evmProvider;
245
+ // Wait for EVM provider to be ready
246
+ (_this$evmProvider = this.evmProvider) === null || _this$evmProvider === void 0 || _this$evmProvider.once("connect", () => {
247
+ resolve();
248
+ });
249
+ }
242
250
  });
243
251
 
244
252
  // Connect using the multichain client
@@ -308,6 +316,7 @@ class MetaMaskConnector extends BaseConnector {
308
316
  duration: Date.now() - startTime
309
317
  }));
310
318
  }
319
+ if (isUserRejectedError(error)) throw WalletOperationsError.userRejected();
311
320
  if (error instanceof Web3AuthError) throw error;
312
321
  throw WalletLoginError.connectionError("Failed to login with MetaMask wallet", error);
313
322
  }
@@ -1,7 +1,7 @@
1
1
  export { Web3AuthNoModal } from './noModal.js';
2
2
  export { ANALYTICS_EVENTS, ANALYTICS_INTEGRATION_TYPE, ANALYTICS_SDK_TYPE, Analytics } from './base/analytics.js';
3
3
  export { AUTH_CONNECTION, MFA_FACTOR, MFA_LEVELS, UX_MODE, WEB3AUTH_NETWORK, getED25519Key } from '@web3auth/auth';
4
- export { AccountLinkingError, WalletInitializationError, WalletLoginError, WalletOperationsError, WalletProviderError, Web3AuthError } from './base/errors/index.js';
4
+ export { AccountLinkingError, formatAccountLinkingErrorMessage, getAccountLinkingRequestError } from './account-linking/errors.js';
5
5
  export { BUTTON_POSITION, CONFIRMATION_STRATEGY } from '@web3auth/ws-embed';
6
6
  export { BaseConnector } from './base/connector/baseConnector.js';
7
7
  export { BaseEvmConnector } from './connectors/base-evm-connector/baseEvmConnector.js';
@@ -10,7 +10,7 @@ export { BaseSolanaConnector } from './connectors/base-solana-connector/baseSola
10
10
  export { BiconomySmartAccount, KernelSmartAccount, MetamaskSmartAccount, NexusSmartAccount, SMART_ACCOUNT, SafeSmartAccount, TrustSmartAccount } from '@toruslabs/ethereum-controllers';
11
11
  export { CAN_AUTHORIZE_STATUSES, CAN_LOGOUT_STATUSES, CONNECTED_STATUSES } from './base/connector/connectorStatus.js';
12
12
  export { CHAIN_NAMESPACES, cloneDeep } from '@toruslabs/base-controllers';
13
- export { CONNECTOR_CATEGORY, CONNECTOR_EVENTS, CONNECTOR_INITIAL_AUTHENTICATION_MODE, CONNECTOR_STATUS } from './base/connector/constants.js';
13
+ export { CONNECTOR_CATEGORY, CONNECTOR_EVENTS, CONNECTOR_INITIAL_AUTHENTICATION_MODE, CONNECTOR_STATUS, WEB3AUTH_CONNECTOR_ID } from './base/connector/constants.js';
14
14
  export { CONNECTOR_NAMES, EVM_CONNECTORS, MULTI_CHAIN_CONNECTORS, SOLANA_CONNECTORS, WALLET_CONNECTORS, WEB3AUTH_ICON } from './base/wallet/index.js';
15
15
  export { CONNECTOR_NAMESPACES } from './base/chain/IChainInterface.js';
16
16
  export { CommonJRPCProvider } from './providers/base-provider/CommonJRPCProvider.js';
@@ -21,6 +21,7 @@ export { EIP_7702_SUPPORTED_SMART_ACCOUNTS, LOGIN_MODE, MODAL_SIGN_IN_METHODS, S
21
21
  export { EVM_PLUGINS, PLUGIN_EVENTS, PLUGIN_NAMESPACES, PLUGIN_STATUS, SOLANA_PLUGINS, WALLET_PLUGINS } from './base/plugin/IPlugin.js';
22
22
  export { PROVIDER_EVENTS } from './base/provider/IProvider.js';
23
23
  export { WalletConnectV2Provider } from './connectors/wallet-connect-v2-connector/WalletConnectV2Provider.js';
24
+ export { WalletInitializationError, WalletLoginError, WalletOperationsError, WalletProviderError, Web3AuthError, isUserRejectedError } from './base/errors/index.js';
24
25
  export { WalletServicesPluginError } from './base/plugin/errors.js';
25
26
  export { Web3AuthContextKey } from './base/composables/index.js';
26
27
  export { accountAbstractionProvider, toEoaProvider } from './providers/account-abstraction-provider/providers/AccountAbstractionProvider.js';