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

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 (101) hide show
  1. package/dist/lib.cjs/account-linking/index.js +8 -0
  2. package/dist/lib.cjs/account-linking/react.js +95 -0
  3. package/dist/lib.cjs/account-linking/rest.js +54 -0
  4. package/dist/lib.cjs/account-linking/vue.js +98 -0
  5. package/dist/lib.cjs/base/analytics.js +17 -2
  6. package/dist/lib.cjs/base/connector/constants.js +2 -0
  7. package/dist/lib.cjs/base/errors/index.js +48 -0
  8. package/dist/lib.cjs/base/utils.js +15 -3
  9. package/dist/lib.cjs/connectors/auth-connector/authConnector.js +501 -70
  10. package/dist/lib.cjs/connectors/base-evm-connector/baseEvmConnector.js +42 -23
  11. package/dist/lib.cjs/connectors/base-solana-connector/baseSolanaConnector.js +41 -24
  12. package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +76 -45
  13. package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +41 -13
  14. package/dist/lib.cjs/index.js +20 -13
  15. package/dist/lib.cjs/noModal.js +834 -117
  16. package/dist/lib.cjs/plugins/wallet-services-plugin/plugin.js +1 -1
  17. package/dist/lib.cjs/providers/base-provider/baseProvider.js +65 -33
  18. package/dist/lib.cjs/react/context/useWeb3AuthInnerContextValue.js +43 -20
  19. package/dist/lib.cjs/react/hooks/useWallets.js +51 -0
  20. package/dist/lib.cjs/react/hooks/useWeb3AuthConnect.js +2 -2
  21. package/dist/lib.cjs/react/index.js +2 -0
  22. package/dist/lib.cjs/react/solana/hooks/useSolanaWallet.js +2 -2
  23. package/dist/lib.cjs/react/solana/provider.js +7 -1
  24. package/dist/lib.cjs/react/wagmi/provider.js +37 -5
  25. package/dist/lib.cjs/types/account-linking/index.d.ts +2 -0
  26. package/dist/lib.cjs/types/account-linking/interfaces.d.ts +90 -0
  27. package/dist/lib.cjs/types/account-linking/react.d.ts +19 -0
  28. package/dist/lib.cjs/types/account-linking/rest.d.ts +9 -0
  29. package/dist/lib.cjs/types/account-linking/vue.d.ts +20 -0
  30. package/dist/lib.cjs/types/base/analytics.d.ts +9 -0
  31. package/dist/lib.cjs/types/base/connector/baseConnector.d.ts +5 -0
  32. package/dist/lib.cjs/types/base/connector/constants.d.ts +2 -0
  33. package/dist/lib.cjs/types/base/connector/interfaces.d.ts +51 -6
  34. package/dist/lib.cjs/types/base/core/IWeb3Auth.d.ts +39 -2
  35. package/dist/lib.cjs/types/base/errors/index.d.ts +13 -0
  36. package/dist/lib.cjs/types/base/interfaces.d.ts +3 -1
  37. package/dist/lib.cjs/types/base/utils.d.ts +7 -1
  38. package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +33 -3
  39. package/dist/lib.cjs/types/connectors/auth-connector/interface.d.ts +77 -2
  40. package/dist/lib.cjs/types/connectors/base-evm-connector/baseEvmConnector.d.ts +6 -0
  41. package/dist/lib.cjs/types/connectors/base-solana-connector/baseSolanaConnector.d.ts +6 -0
  42. package/dist/lib.cjs/types/index.d.ts +1 -0
  43. package/dist/lib.cjs/types/noModal.d.ts +104 -5
  44. package/dist/lib.cjs/types/providers/base-provider/baseProvider.d.ts +7 -0
  45. package/dist/lib.cjs/types/react/hooks/index.d.ts +1 -0
  46. package/dist/lib.cjs/types/react/hooks/useWallets.d.ts +8 -0
  47. package/dist/lib.cjs/types/vue/composables/index.d.ts +1 -0
  48. package/dist/lib.cjs/types/vue/composables/useWallets.d.ts +9 -0
  49. package/dist/lib.cjs/vue/composables/useWallets.js +52 -0
  50. package/dist/lib.cjs/vue/composables/useWeb3AuthConnect.js +2 -2
  51. package/dist/lib.cjs/vue/index.js +2 -0
  52. package/dist/lib.cjs/vue/solana/composables/useSolanaWallet.js +2 -2
  53. package/dist/lib.cjs/vue/solana/provider.js +50 -23
  54. package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +13 -4
  55. package/dist/lib.cjs/vue/wagmi/provider.js +35 -7
  56. package/dist/lib.esm/account-linking/index.js +1 -0
  57. package/dist/lib.esm/account-linking/react.js +74 -0
  58. package/dist/lib.esm/account-linking/rest.js +51 -0
  59. package/dist/lib.esm/account-linking/vue.js +78 -0
  60. package/dist/lib.esm/base/analytics.js +17 -2
  61. package/dist/lib.esm/base/connector/constants.js +2 -0
  62. package/dist/lib.esm/base/errors/index.js +48 -1
  63. package/dist/lib.esm/base/utils.js +16 -4
  64. package/dist/lib.esm/connectors/auth-connector/authConnector.js +462 -31
  65. package/dist/lib.esm/connectors/base-evm-connector/baseEvmConnector.js +43 -24
  66. package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +43 -26
  67. package/dist/lib.esm/connectors/coinbase-connector/coinbaseConnector.js +2 -2
  68. package/dist/lib.esm/connectors/injected-evm-connector/injectedEvmConnector.js +2 -2
  69. package/dist/lib.esm/connectors/injected-solana-connector/walletStandardConnector.js +3 -3
  70. package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +80 -49
  71. package/dist/lib.esm/connectors/wallet-connect-v2-connector/WalletConnectV2Provider.js +2 -2
  72. package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +43 -15
  73. package/dist/lib.esm/connectors/wallet-connect-v2-connector/wcSolanaWallet.js +1 -1
  74. package/dist/lib.esm/index.js +4 -3
  75. package/dist/lib.esm/noModal.js +851 -126
  76. package/dist/lib.esm/plugins/wallet-services-plugin/plugin.js +3 -3
  77. package/dist/lib.esm/providers/base-provider/baseProvider.js +68 -38
  78. package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +45 -21
  79. package/dist/lib.esm/react/hooks/useWallets.js +33 -0
  80. package/dist/lib.esm/react/hooks/useWeb3AuthConnect.js +2 -2
  81. package/dist/lib.esm/react/index.js +1 -0
  82. package/dist/lib.esm/react/solana/hooks/useSolanaWallet.js +2 -2
  83. package/dist/lib.esm/react/solana/provider.js +9 -2
  84. package/dist/lib.esm/react/wagmi/provider.js +39 -7
  85. package/dist/lib.esm/vue/composables/useCheckout.js +1 -1
  86. package/dist/lib.esm/vue/composables/useFunding.js +1 -1
  87. package/dist/lib.esm/vue/composables/useReceive.js +1 -1
  88. package/dist/lib.esm/vue/composables/useSwap.js +1 -1
  89. package/dist/lib.esm/vue/composables/useWalletConnectScanner.js +1 -1
  90. package/dist/lib.esm/vue/composables/useWalletUI.js +1 -1
  91. package/dist/lib.esm/vue/composables/useWallets.js +35 -0
  92. package/dist/lib.esm/vue/composables/useWeb3AuthConnect.js +2 -2
  93. package/dist/lib.esm/vue/index.js +1 -0
  94. package/dist/lib.esm/vue/solana/composables/useSignAndSendTransaction.js +1 -1
  95. package/dist/lib.esm/vue/solana/composables/useSignMessage.js +1 -1
  96. package/dist/lib.esm/vue/solana/composables/useSignTransaction.js +1 -1
  97. package/dist/lib.esm/vue/solana/composables/useSolanaWallet.js +2 -2
  98. package/dist/lib.esm/vue/solana/provider.js +51 -24
  99. package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +12 -3
  100. package/dist/lib.esm/vue/wagmi/provider.js +36 -8
  101. package/package.json +44 -20
@@ -33,7 +33,7 @@ class WalletServicesPlugin extends auth.SafeEventEmitter {
33
33
  async initWithWeb3Auth(web3auth, _whiteLabel, analytics) {
34
34
  if (this.isInitialized) return;
35
35
  if (!web3auth) throw errors.WalletServicesPluginError.web3authRequired();
36
- if (web3auth.connection && !this.SUPPORTED_CONNECTORS.includes(web3auth.connectedConnectorName)) throw errors.WalletServicesPluginError.notInitialized();
36
+ if (web3auth.connection && !this.SUPPORTED_CONNECTORS.includes(web3auth.primaryConnectorName)) throw errors.WalletServicesPluginError.notInitialized();
37
37
  const currentChainConfig = web3auth.currentChain;
38
38
  if (![baseControllers.CHAIN_NAMESPACES.EIP155, baseControllers.CHAIN_NAMESPACES.SOLANA].includes(currentChainConfig === null || currentChainConfig === void 0 ? void 0 : currentChainConfig.chainNamespace)) throw errors.WalletServicesPluginError.unsupportedChainNamespace();
39
39
  this.web3auth = web3auth;
@@ -33,6 +33,8 @@ class BaseProvider extends baseControllers.BaseController {
33
33
  // set to true when the keyExportEnabled flag is set by code.
34
34
  // This is to prevent the flag from being overridden by the dashboard config.
35
35
  _defineProperty(this, "keyExportFlagSetByCode", false);
36
+ _defineProperty(this, "providerEventBridges", new Map());
37
+ _defineProperty(this, "providerListenerBridgeRegistered", false);
36
38
  const {
37
39
  chain
38
40
  } = config;
@@ -104,41 +106,18 @@ class BaseProvider extends baseControllers.BaseController {
104
106
  })).catch(err => callback(err, null));
105
107
  }
106
108
  updateProviderEngineProxy(provider) {
109
+ if (this._providerEngineProxy === provider) return;
107
110
  if (this._providerEngineProxy) {
108
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
109
- this._providerEngineProxy.setTarget(provider);
110
- // we want events to propagate from Ethereum provider -> wrapper provider (e.g. CommonJRPC provider) -> SDK -> dapp
111
- // ensure that only one handler is added for each event
112
- const reEmitHandler = event => {
113
- // skip newListener event
114
- if (event === "newListener") return;
115
- // listen to the event from the Ethereum provider
116
- provider.on(event, (...args) => {
117
- // handle chainChanged event: update chainId state
118
- if (event === utils.EIP1193_EVENTS.CHAIN_CHANGED) {
119
- const chainId = args[0];
120
- this.update({
121
- chainId
122
- });
123
- }
124
- // re-emit the event
125
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
126
- this.emit(event, ...args);
127
- });
128
- };
129
- // handle existing events
130
- this.eventNames().forEach(event => {
131
- reEmitHandler(event);
132
- });
133
- // handle when a new listener is added
134
- this.on("newListener", event => {
135
- // skip if the event already exists
136
- if (this.listenerCount(event) > 0) return;
137
- reEmitHandler(event);
138
- });
139
- } else {
140
- this._providerEngineProxy = baseControllers.createEventEmitterProxy(provider);
111
+ // remove all event bridges from the previous provider
112
+ this.detachProviderEventBridges(this._providerEngineProxy);
141
113
  }
114
+ // attach all event bridges to the new provider
115
+ this._providerEngineProxy = provider;
116
+ this.ensureProviderListenerBridge();
117
+ this.eventNames().forEach(event => {
118
+ this.ensureProviderEventBridge(event);
119
+ });
120
+ this.attachProviderEventBridges(provider);
142
121
  }
143
122
  setKeyExportFlag(flag) {
144
123
  if (!this.keyExportFlagSetByCode) {
@@ -153,6 +132,59 @@ class BaseProvider extends baseControllers.BaseController {
153
132
  getChain(chainId) {
154
133
  return this.config.chains.find(chain => chain.chainId === chainId);
155
134
  }
135
+ ensureProviderListenerBridge() {
136
+ if (this.providerListenerBridgeRegistered) return;
137
+ this.providerListenerBridgeRegistered = true;
138
+ this.on("newListener", event => {
139
+ this.ensureProviderEventBridge(event);
140
+ });
141
+ }
142
+ ensureProviderEventBridge(event) {
143
+ if (event === "newListener" || event === "removeListener" || this.providerEventBridges.has(event)) return;
144
+ const bridge = {
145
+ handler: (...args) => {
146
+ if (event === utils.EIP1193_EVENTS.CHAIN_CHANGED) {
147
+ const chainId = args[0];
148
+ this.update({
149
+ chainId
150
+ });
151
+ }
152
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
153
+ this.emit(event, ...args);
154
+ }
155
+ };
156
+ this.providerEventBridges.set(event, bridge);
157
+ if (!this._providerEngineProxy) return;
158
+ bridge.detach = this.attachProviderEventBridge(this._providerEngineProxy, event, bridge.handler);
159
+ }
160
+ attachProviderEventBridges(provider) {
161
+ this.providerEventBridges.forEach((bridge, event) => {
162
+ if (bridge.detach) return;
163
+ bridge.detach = this.attachProviderEventBridge(provider, event, bridge.handler);
164
+ });
165
+ }
166
+ attachProviderEventBridge(provider, event, handler) {
167
+ const removableProvider = provider;
168
+ const maybeDetach = removableProvider.on(event, handler);
169
+ return typeof maybeDetach === "function" ? () => {
170
+ maybeDetach();
171
+ } : undefined;
172
+ }
173
+ detachProviderEventBridges(provider) {
174
+ this.providerEventBridges.forEach((bridge, event) => {
175
+ if (bridge.detach) {
176
+ bridge.detach();
177
+ } else {
178
+ const removableProvider = provider;
179
+ if (typeof removableProvider.removeListener === "function") {
180
+ removableProvider.removeListener(event, bridge.handler);
181
+ } else if (typeof removableProvider.off === "function") {
182
+ removableProvider.off(event, bridge.handler);
183
+ }
184
+ }
185
+ bridge.detach = undefined;
186
+ });
187
+ }
156
188
  }
157
189
 
158
190
  exports.BaseProvider = BaseProvider;
@@ -12,12 +12,26 @@ require('@toruslabs/constants');
12
12
  require('@toruslabs/http-helpers');
13
13
  var constants$1 = require('../../base/constants.js');
14
14
  require('../../base/wallet/index.js');
15
- require('../../base/connector/connectorStatus.js');
15
+ var connectorStatus = require('../../base/connector/connectorStatus.js');
16
16
  var constants = require('../../base/connector/constants.js');
17
17
  require('jwt-decode');
18
18
  require('../../base/plugin/errors.js');
19
19
  require('../../base/plugin/IPlugin.js');
20
20
 
21
+ function getInitialState(web3Auth) {
22
+ var _web3Auth$currentChai, _web3Auth$currentChai2;
23
+ const isConnected = connectorStatus.CONNECTED_STATUSES.includes(web3Auth.status);
24
+ const isAuthorized = web3Auth.status === constants.CONNECTOR_STATUS.AUTHORIZED;
25
+ return {
26
+ chainId: isConnected ? web3Auth.currentChainId : null,
27
+ chainNamespace: isConnected ? (_web3Auth$currentChai = (_web3Auth$currentChai2 = web3Auth.currentChain) === null || _web3Auth$currentChai2 === void 0 ? void 0 : _web3Auth$currentChai2.chainNamespace) !== null && _web3Auth$currentChai !== void 0 ? _web3Auth$currentChai : null : null,
28
+ connection: isConnected ? web3Auth.connection : null,
29
+ isAuthorized,
30
+ isConnected,
31
+ isInitialized: isConnected,
32
+ status: web3Auth.status
33
+ };
34
+ }
21
35
  function useWeb3AuthInnerContextValue({
22
36
  Web3AuthConstructor,
23
37
  web3AuthOptions,
@@ -26,20 +40,20 @@ function useWeb3AuthInnerContextValue({
26
40
  cleanupOnUnmount = false,
27
41
  initEffectDependency
28
42
  }) {
29
- const [chainId, setChainId] = react.useState(null);
30
- const [chainNamespace, setChainNamespace] = react.useState(null);
31
- const [isInitializing, setIsInitializing] = react.useState(false);
32
- const [initError, setInitError] = react.useState(null);
33
- const [connection, setConnection] = react.useState(null);
34
- const [isInitialized, setIsInitialized] = react.useState(false);
35
- const [isMFAEnabled, setIsMFAEnabled] = react.useState(false);
36
43
  const web3Auth = react.useMemo(() => {
37
- setConnection(null);
38
44
  return new Web3AuthConstructor(web3AuthOptions, initialState);
39
45
  }, [Web3AuthConstructor, web3AuthOptions, initialState]);
40
- const [isConnected, setIsConnected] = react.useState(false);
41
- const [status, setStatus] = react.useState(null);
42
- const [isAuthorized, setIsAuthorized] = react.useState(false);
46
+ const initialWeb3AuthState = getInitialState(web3Auth);
47
+ const [chainId, setChainId] = react.useState(() => initialWeb3AuthState.chainId);
48
+ const [chainNamespace, setChainNamespace] = react.useState(() => initialWeb3AuthState.chainNamespace);
49
+ const [isInitializing, setIsInitializing] = react.useState(false);
50
+ const [initError, setInitError] = react.useState(null);
51
+ const [connection, setConnection] = react.useState(() => initialWeb3AuthState.connection);
52
+ const [isInitialized, setIsInitialized] = react.useState(initialWeb3AuthState.isInitialized);
53
+ const [isMFAEnabled, setIsMFAEnabled] = react.useState(false);
54
+ const [isConnected, setIsConnected] = react.useState(initialWeb3AuthState.isConnected);
55
+ const [status, setStatus] = react.useState(initialWeb3AuthState.status);
56
+ const [isAuthorized, setIsAuthorized] = react.useState(initialWeb3AuthState.isAuthorized);
43
57
  const getPlugin = react.useCallback(name => {
44
58
  if (!web3Auth) throw index.WalletInitializationError.notReady();
45
59
  return web3Auth.getPlugin(name);
@@ -48,7 +62,7 @@ function useWeb3AuthInnerContextValue({
48
62
  const controller = new AbortController();
49
63
  async function init() {
50
64
  try {
51
- var _web3Auth$currentChai;
65
+ var _web3Auth$currentChai3;
52
66
  setInitError(null);
53
67
  setIsInitializing(true);
54
68
  web3Auth.setAnalyticsProperties({
@@ -58,7 +72,7 @@ function useWeb3AuthInnerContextValue({
58
72
  signal: controller.signal
59
73
  });
60
74
  setChainId(web3Auth.currentChainId);
61
- setChainNamespace((_web3Auth$currentChai = web3Auth.currentChain) === null || _web3Auth$currentChai === void 0 ? void 0 : _web3Auth$currentChai.chainNamespace);
75
+ setChainNamespace((_web3Auth$currentChai3 = web3Auth.currentChain) === null || _web3Auth$currentChai3 === void 0 ? void 0 : _web3Auth$currentChai3.chainNamespace);
62
76
  } catch (error) {
63
77
  setInitError(error);
64
78
  } finally {
@@ -73,9 +87,9 @@ function useWeb3AuthInnerContextValue({
73
87
  react.useEffect(() => {
74
88
  var _connection$ethereumP;
75
89
  const handleChainChange = async nextChainId => {
76
- var _web3Auth$currentChai2;
90
+ var _web3Auth$currentChai4;
77
91
  setChainId(nextChainId);
78
- setChainNamespace((_web3Auth$currentChai2 = web3Auth.currentChain) === null || _web3Auth$currentChai2 === void 0 ? void 0 : _web3Auth$currentChai2.chainNamespace);
92
+ setChainNamespace((_web3Auth$currentChai4 = web3Auth.currentChain) === null || _web3Auth$currentChai4 === void 0 ? void 0 : _web3Auth$currentChai4.chainNamespace);
79
93
  };
80
94
  const provider = (_connection$ethereumP = connection === null || connection === void 0 ? void 0 : connection.ethereumProvider) !== null && _connection$ethereumP !== void 0 ? _connection$ethereumP : null;
81
95
  if (!provider) return undefined;
@@ -97,12 +111,12 @@ function useWeb3AuthInnerContextValue({
97
111
  setStatus(web3Auth.status);
98
112
  // we do this because of rehydration issues. status connected is fired first but web3auth sdk is not ready yet.
99
113
  if (web3Auth.status === constants.CONNECTOR_STATUS.CONNECTED) {
100
- var _web3Auth$currentChai3, _web3Auth$currentChai4;
114
+ var _web3Auth$currentChai5, _web3Auth$currentChai6;
101
115
  setIsInitialized(true);
102
116
  setIsConnected(true);
103
117
  setConnection(web3Auth.connection);
104
118
  setChainId(web3Auth.currentChainId);
105
- setChainNamespace((_web3Auth$currentChai3 = (_web3Auth$currentChai4 = web3Auth.currentChain) === null || _web3Auth$currentChai4 === void 0 ? void 0 : _web3Auth$currentChai4.chainNamespace) !== null && _web3Auth$currentChai3 !== void 0 ? _web3Auth$currentChai3 : null);
119
+ setChainNamespace((_web3Auth$currentChai5 = (_web3Auth$currentChai6 = web3Auth.currentChain) === null || _web3Auth$currentChai6 === void 0 ? void 0 : _web3Auth$currentChai6.chainNamespace) !== null && _web3Auth$currentChai5 !== void 0 ? _web3Auth$currentChai5 : null);
106
120
  }
107
121
  };
108
122
  const disconnectedListener = () => {
@@ -133,12 +147,12 @@ function useWeb3AuthInnerContextValue({
133
147
  const consentAcceptedListener = () => {
134
148
  setStatus(web3Auth.status);
135
149
  if (web3Auth.status === constants.CONNECTOR_STATUS.CONNECTED || web3Auth.status === constants.CONNECTOR_STATUS.AUTHORIZED) {
136
- var _web3Auth$currentChai5, _web3Auth$currentChai6;
150
+ var _web3Auth$currentChai7, _web3Auth$currentChai8;
137
151
  setIsInitialized(true);
138
152
  setIsConnected(true);
139
153
  setConnection(web3Auth.connection);
140
154
  setChainId(web3Auth.currentChainId);
141
- setChainNamespace((_web3Auth$currentChai5 = (_web3Auth$currentChai6 = web3Auth.currentChain) === null || _web3Auth$currentChai6 === void 0 ? void 0 : _web3Auth$currentChai6.chainNamespace) !== null && _web3Auth$currentChai5 !== void 0 ? _web3Auth$currentChai5 : null);
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);
142
156
  if (web3Auth.status === constants.CONNECTOR_STATUS.AUTHORIZED) {
143
157
  setIsAuthorized(true);
144
158
  }
@@ -147,6 +161,13 @@ function useWeb3AuthInnerContextValue({
147
161
  const mfaEnabledListener = nextIsMFAEnabled => {
148
162
  if (typeof nextIsMFAEnabled === "boolean") setIsMFAEnabled(nextIsMFAEnabled);
149
163
  };
164
+ const connectionUpdatedListener = () => {
165
+ var _web3Auth$currentChai9, _web3Auth$currentChai0;
166
+ setStatus(web3Auth.status);
167
+ setConnection(web3Auth.connection);
168
+ 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);
170
+ };
150
171
  if (web3Auth) {
151
172
  web3Auth.on(constants.CONNECTOR_EVENTS.NOT_READY, notReadyListener);
152
173
  web3Auth.on(constants.CONNECTOR_EVENTS.READY, readyListener);
@@ -157,6 +178,7 @@ function useWeb3AuthInnerContextValue({
157
178
  web3Auth.on(constants.CONNECTOR_EVENTS.ERRORED, errorListener);
158
179
  web3Auth.on(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, rehydrationErrorListener);
159
180
  web3Auth.on(constants.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
181
+ web3Auth.on(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
160
182
  if (web3Auth.loginMode === constants$1.LOGIN_MODE.MODAL) {
161
183
  web3Auth.on(constants.CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
162
184
  }
@@ -172,6 +194,7 @@ function useWeb3AuthInnerContextValue({
172
194
  web3Auth.removeListener(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, rehydrationErrorListener);
173
195
  web3Auth.removeListener(constants.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
174
196
  web3Auth.removeListener(constants.CONNECTOR_EVENTS.AUTHORIZED, authorizedListener);
197
+ web3Auth.removeListener(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
175
198
  if (web3Auth.loginMode === constants$1.LOGIN_MODE.MODAL) {
176
199
  web3Auth.removeListener(constants.CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
177
200
  }
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ require('@babel/runtime/helpers/objectSpread2');
5
+ require('@babel/runtime/helpers/defineProperty');
6
+ require('@segment/analytics-next');
7
+ require('../../base/loglevel.js');
8
+ require('@toruslabs/base-controllers');
9
+ require('@toruslabs/session-manager');
10
+ require('@web3auth/auth');
11
+ var index = require('../../base/errors/index.js');
12
+ require('@toruslabs/constants');
13
+ require('@toruslabs/http-helpers');
14
+ require('../../base/constants.js');
15
+ require('../../base/wallet/index.js');
16
+ require('../../base/connector/connectorStatus.js');
17
+ require('../../base/connector/constants.js');
18
+ require('jwt-decode');
19
+ require('../../base/plugin/errors.js');
20
+ require('../../base/plugin/IPlugin.js');
21
+ var useWeb3AuthInner = require('./useWeb3AuthInner.js');
22
+
23
+ const useWallets = () => {
24
+ const {
25
+ web3Auth
26
+ } = useWeb3AuthInner.useWeb3AuthInner();
27
+ const [loading, setLoading] = react.useState(false);
28
+ const [error, setError] = react.useState(null);
29
+ const [wallets, setWallets] = react.useState([]);
30
+ const syncWallets = react.useCallback(async () => {
31
+ if (!web3Auth) throw index.WalletInitializationError.notReady();
32
+ setLoading(true);
33
+ setError(null);
34
+ try {
35
+ const result = await web3Auth.getConnectedAccountsWithProviders();
36
+ setWallets(result);
37
+ } catch (err) {
38
+ setError(err);
39
+ } finally {
40
+ setLoading(false);
41
+ }
42
+ }, [web3Auth]);
43
+ return {
44
+ loading,
45
+ error,
46
+ wallets,
47
+ syncWallets
48
+ };
49
+ };
50
+
51
+ exports.useWallets = useWallets;
@@ -18,7 +18,7 @@ const useWeb3AuthConnect = () => {
18
18
  setConnectorName(null);
19
19
  }
20
20
  if (isConnected && !connectorName) {
21
- setConnectorName(web3Auth.connectedConnectorName);
21
+ setConnectorName(web3Auth.primaryConnectorName);
22
22
  }
23
23
  }, [isConnected, connectorName, web3Auth]);
24
24
  const connect = react.useCallback(async (connector, params) => {
@@ -27,7 +27,7 @@ const useWeb3AuthConnect = () => {
27
27
  try {
28
28
  const provider = await web3Auth.connectTo(connector, params);
29
29
  if (provider) {
30
- setConnectorName(web3Auth.connectedConnectorName);
30
+ setConnectorName(web3Auth.primaryConnectorName);
31
31
  }
32
32
  return provider;
33
33
  } catch (error) {
@@ -14,6 +14,7 @@ var useReceive = require('./hooks/useReceive.js');
14
14
  var useSwap = require('./hooks/useSwap.js');
15
15
  var useSwitchChain = require('./hooks/useSwitchChain.js');
16
16
  var useWalletConnectScanner = require('./hooks/useWalletConnectScanner.js');
17
+ var useWallets = require('./hooks/useWallets.js');
17
18
  var useWalletServicesPlugin = require('./hooks/useWalletServicesPlugin.js');
18
19
  var useWalletUI = require('./hooks/useWalletUI.js');
19
20
  var useWeb3Auth = require('./hooks/useWeb3Auth.js');
@@ -38,6 +39,7 @@ exports.useReceive = useReceive.useReceive;
38
39
  exports.useSwap = useSwap.useSwap;
39
40
  exports.useSwitchChain = useSwitchChain.useSwitchChain;
40
41
  exports.useWalletConnectScanner = useWalletConnectScanner.useWalletConnectScanner;
42
+ exports.useWallets = useWallets.useWallets;
41
43
  exports.useWalletServicesPlugin = useWalletServicesPlugin.useWalletServicesPlugin;
42
44
  exports.useWalletUI = useWalletUI.useWalletUI;
43
45
  exports.useWeb3Auth = useWeb3Auth.useWeb3Auth;
@@ -30,12 +30,12 @@ const useSolanaWallet = () => {
30
30
  return kit.createSolanaRpc(web3Auth.currentChain.rpcTarget);
31
31
  }, [web3Auth, solanaWallet, chainNamespace]);
32
32
  const getPrivateKey = react.useCallback(async () => {
33
- var _web3Auth$connectedCo;
33
+ var _web3Auth$primaryConn;
34
34
  if (!web3Auth) throw new Error("Web3Auth not initialized");
35
35
  if ((connection === null || connection === void 0 ? void 0 : connection.connectorName) !== index.WALLET_CONNECTORS.AUTH) {
36
36
  throw new Error("getPrivateKey is only supported with the Auth connector");
37
37
  }
38
- const provider = (_web3Auth$connectedCo = web3Auth.connectedConnector) === null || _web3Auth$connectedCo === void 0 ? void 0 : _web3Auth$connectedCo.provider;
38
+ const provider = (_web3Auth$primaryConn = web3Auth.primaryConnector) === null || _web3Auth$primaryConn === void 0 ? void 0 : _web3Auth$primaryConn.provider;
39
39
  if (!provider) throw new Error("Provider not available");
40
40
  const privateKey = await provider.request({
41
41
  method: wsEmbed.SOLANA_METHOD_TYPES.SOLANA_PRIVATE_KEY
@@ -69,6 +69,7 @@ function useFrameworkKitSolanaClient() {
69
69
  isInitialized
70
70
  } = useWeb3Auth.useWeb3Auth();
71
71
  const {
72
+ chainId,
72
73
  chainNamespace
73
74
  } = useChain.useChain();
74
75
  const ref = react.useRef(null);
@@ -117,6 +118,11 @@ function useFrameworkKitSolanaClient() {
117
118
  adopt(makePlaceholder(rpc));
118
119
  return;
119
120
  }
121
+ // only reconnect for the primary connector
122
+ if (conn.connectorName !== (web3Auth === null || web3Auth === void 0 ? void 0 : web3Auth.primaryConnectorName)) {
123
+ adopt(makePlaceholder(rpc));
124
+ return;
125
+ }
120
126
  try {
121
127
  const solanaWalletId = "wallet-standard:" + conn.connectorName;
122
128
  const connector = client.createWalletStandardConnector(solanaWallet, {
@@ -148,7 +154,7 @@ function useFrameworkKitSolanaClient() {
148
154
  return () => {
149
155
  stale = true;
150
156
  };
151
- }, [isConnected, connection === null || connection === void 0 ? void 0 : connection.solanaWallet, chainNamespace, web3Auth, isInitialized, connection === null || connection === void 0 ? void 0 : connection.connectorName]);
157
+ }, [isConnected, connection === null || connection === void 0 ? void 0 : connection.solanaWallet, chainId, chainNamespace, web3Auth, isInitialized, connection === null || connection === void 0 ? void 0 : connection.connectorName]);
152
158
  return client$1;
153
159
  }
154
160
  function SolanaProvider(_ref) {
@@ -92,7 +92,8 @@ function Web3AuthWagmiProvider({
92
92
  }) {
93
93
  const {
94
94
  isConnected,
95
- connection
95
+ connection,
96
+ chainNamespace
96
97
  } = useWeb3Auth.useWeb3Auth();
97
98
  const {
98
99
  disconnect
@@ -101,10 +102,17 @@ function Web3AuthWagmiProvider({
101
102
  const {
102
103
  mutate: reconnect
103
104
  } = wagmi.useReconnect();
105
+ const suppressWagmiDisconnect = react.useRef(false);
106
+ const lastSyncedBinding = react.useRef({
107
+ provider: null,
108
+ connectorName: null
109
+ });
104
110
  wagmi.useConnectionEffect({
105
111
  onDisconnect: async () => {
106
112
  loglevel.log.info("Disconnected from wagmi");
107
- if (isConnected) await disconnect();
113
+ const isSuppressed = suppressWagmiDisconnect.current;
114
+ suppressWagmiDisconnect.current = false;
115
+ if (!isSuppressed && isConnected) await disconnect();
108
116
  const connector = getWeb3authConnector(wagmiConfig);
109
117
  // reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
110
118
  // from the connected provider
@@ -115,20 +123,44 @@ function Web3AuthWagmiProvider({
115
123
  });
116
124
  react.useEffect(() => {
117
125
  (async () => {
118
- if (isConnected && connection !== null && connection !== void 0 && connection.ethereumProvider) {
126
+ const shouldBindToWagmi = isConnected && chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155 && Boolean(connection === null || connection === void 0 ? void 0 : connection.ethereumProvider);
127
+ if (shouldBindToWagmi) {
128
+ const hasSameBinding = lastSyncedBinding.current.provider === connection.ethereumProvider && lastSyncedBinding.current.connectorName === connection.connectorName;
129
+ if (hasSameBinding && wagmiConfig.state.status === "connected") {
130
+ return;
131
+ }
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
+ }
139
+ }
119
140
  const connector = await setupConnector(connection.ethereumProvider, wagmiConfig);
120
141
  if (!connector) {
121
142
  throw new Error("Failed to setup connector");
122
143
  }
123
144
  await connectWeb3AuthWithWagmi(connector, wagmiConfig);
145
+ lastSyncedBinding.current = {
146
+ provider: connection.ethereumProvider,
147
+ connectorName: connection.connectorName
148
+ };
124
149
  reconnect();
125
- } else if (!isConnected) {
150
+ } else {
151
+ lastSyncedBinding.current = {
152
+ provider: null,
153
+ connectorName: null
154
+ };
126
155
  if (wagmiConfig.state.status === "connected") {
156
+ suppressWagmiDisconnect.current = true;
127
157
  await disconnectWeb3AuthFromWagmi(wagmiConfig);
158
+ } else if (getWeb3authConnector(wagmiConfig)) {
159
+ resetConnectorState(wagmiConfig);
128
160
  }
129
161
  }
130
162
  })();
131
- }, [isConnected, wagmiConfig, connection, reconnect]);
163
+ }, [chainNamespace, connection, isConnected, reconnect, wagmiConfig]);
132
164
  return react.createElement(react.Fragment, null, children);
133
165
  }
134
166
  function WagmiProvider(_ref) {
@@ -0,0 +1,2 @@
1
+ export * from "./interfaces";
2
+ export * from "./rest";
@@ -0,0 +1,90 @@
1
+ import type { WALLET_CONNECTOR_TYPE } from "../base/wallet";
2
+ export type CITADEL_NETWORK = "ethereum" | "solana";
3
+ export interface LinkAccountParams {
4
+ /**
5
+ * Name of the external wallet connector to link.
6
+ * Example: WALLET_CONNECTORS.METAMASK, WALLET_CONNECTORS.WALLET_CONNECT_V2.
7
+ *
8
+ * Optional in the modal SDK (`@web3auth/modal`): when omitted, the modal opens
9
+ * a wallet picker dedicated to account linking and uses the wallet selected by
10
+ * the user. Required in the no-modal SDK (`@web3auth/no-modal`).
11
+ */
12
+ connectorName: WALLET_CONNECTOR_TYPE | string;
13
+ /**
14
+ * Chain ID to use when generating the wallet identity proof.
15
+ * Defaults to the currently active chain if not specified.
16
+ */
17
+ chainId?: string;
18
+ }
19
+ /**
20
+ * Linked account info returned from the Citadel server
21
+ */
22
+ export interface BaseLinkedAccountInfo {
23
+ /** Type of the account (e.g. "social", "external_wallet", "account_abstraction") */
24
+ accountType: string;
25
+ /** Address of the account */
26
+ address: string | null;
27
+ /** Auth connection id of the account */
28
+ authConnectionId: string | null;
29
+ /** Grouped auth connection id of the account */
30
+ groupedAuthConnectionId?: string | null;
31
+ /** Chain namespace of the account */
32
+ chainNamespace: string | null;
33
+ }
34
+ /**
35
+ * Result returned after a successful account-linking operation.
36
+ */
37
+ export interface LinkAccountResult {
38
+ /** Whether the Citadel server accepted the linking request. */
39
+ success: boolean;
40
+ /** Refreshed id token for the user */
41
+ idToken: string;
42
+ /** Linked account info */
43
+ linkedAccounts: BaseLinkedAccountInfo[];
44
+ /** Error message from the Citadel server */
45
+ message?: string;
46
+ }
47
+ /**
48
+ * Result returned after a successful account-unlinking operation.
49
+ */
50
+ export interface UnlinkAccountResult {
51
+ /** Whether the Citadel server accepted the linking request. */
52
+ success: boolean;
53
+ /** Refreshed id token for the user */
54
+ idToken: string;
55
+ /** Remaining linked account info */
56
+ linkedAccounts: BaseLinkedAccountInfo[];
57
+ /** Error message from the Citadel server */
58
+ message?: string;
59
+ }
60
+ /**
61
+ * Payload sent to the Citadel account-linking endpoint.
62
+ */
63
+ export interface CitadelLinkAccountPayload {
64
+ /** Current idToken to refresh with updated linked accounts */
65
+ idToken: string;
66
+ /** Network of the account being linked */
67
+ network: CITADEL_NETWORK;
68
+ /** Name of the connector being linked */
69
+ connector: string;
70
+ /** Challenge message to be signed by the user */
71
+ message: string;
72
+ /** Sign In with Web3 signature object */
73
+ signature: {
74
+ /** signature value */
75
+ s: string;
76
+ /** signature type (e.g. "eip191", "sip99") */
77
+ t: string;
78
+ };
79
+ }
80
+ /**
81
+ * Payload sent to the Citadel account-unlinking endpoint.
82
+ */
83
+ export interface UnlinkAccountPayload {
84
+ /** Current idToken to refresh with updated linked accounts */
85
+ idToken: string;
86
+ /** Address of the account to unlink */
87
+ address: string;
88
+ /** Network of the account being unlinked */
89
+ network: CITADEL_NETWORK;
90
+ }
@@ -0,0 +1,19 @@
1
+ import { type LinkedAccountInfo, Web3AuthError } from "../base";
2
+ import { makeAccountLinkingRequest, makeAccountUnlinkingRequest } from "./index";
3
+ import type { BaseLinkedAccountInfo, LinkAccountParams, LinkAccountResult, UnlinkAccountResult } from "./interfaces";
4
+ export { makeAccountLinkingRequest, makeAccountUnlinkingRequest };
5
+ export type { CITADEL_NETWORK, CitadelLinkAccountPayload, LinkAccountParams, LinkAccountResult, BaseLinkedAccountInfo as LinkedAccountInfo, UnlinkAccountPayload, UnlinkAccountResult, } from "./interfaces";
6
+ export interface IUseLinkAccount {
7
+ loading: boolean;
8
+ error: Web3AuthError | null;
9
+ linkedAccounts: BaseLinkedAccountInfo[];
10
+ linkAccount(params?: LinkAccountParams): Promise<LinkAccountResult | void>;
11
+ unlinkAccount(address: string): Promise<UnlinkAccountResult | void>;
12
+ }
13
+ export interface IUseSwitchAccount {
14
+ loading: boolean;
15
+ error: Web3AuthError | null;
16
+ switchAccount(account: LinkedAccountInfo): Promise<void>;
17
+ }
18
+ export declare const useLinkAccount: () => IUseLinkAccount;
19
+ export declare const useSwitchAccount: () => IUseSwitchAccount;
@@ -0,0 +1,9 @@
1
+ import { CitadelLinkAccountPayload, LinkAccountResult, UnlinkAccountPayload, UnlinkAccountResult } from "./interfaces";
2
+ /**
3
+ * Send both identity proofs to the Citadel account-linking endpoint and
4
+ * return a normalized result.
5
+ *
6
+ * Throws AccountLinkingError when the server returns an error or the request itself fails.
7
+ */
8
+ export declare function makeAccountLinkingRequest(authServerUrl: string, accessToken: string, payload: CitadelLinkAccountPayload): Promise<LinkAccountResult>;
9
+ export declare function makeAccountUnlinkingRequest(authServerUrl: string, accessToken: string, payload: UnlinkAccountPayload): Promise<UnlinkAccountResult>;
@@ -0,0 +1,20 @@
1
+ import { Ref } from "vue";
2
+ import { type LinkedAccountInfo, Web3AuthError } from "../base";
3
+ import { makeAccountLinkingRequest, makeAccountUnlinkingRequest } from "./index";
4
+ import type { BaseLinkedAccountInfo, LinkAccountParams, LinkAccountResult, UnlinkAccountResult } from "./interfaces";
5
+ export { makeAccountLinkingRequest, makeAccountUnlinkingRequest };
6
+ export type { CITADEL_NETWORK, CitadelLinkAccountPayload, LinkAccountParams, LinkAccountResult, BaseLinkedAccountInfo as LinkedAccountInfo, UnlinkAccountPayload, UnlinkAccountResult, } from "./interfaces";
7
+ export interface IUseLinkAccount {
8
+ loading: Ref<boolean>;
9
+ error: Ref<Web3AuthError | null>;
10
+ linkedAccounts: Ref<BaseLinkedAccountInfo[]>;
11
+ linkAccount(params?: LinkAccountParams): Promise<LinkAccountResult | void>;
12
+ unlinkAccount(address: string): Promise<UnlinkAccountResult | void>;
13
+ }
14
+ export interface IUseSwitchAccount {
15
+ loading: Ref<boolean>;
16
+ error: Ref<Web3AuthError | null>;
17
+ switchAccount(account: LinkedAccountInfo): Promise<void>;
18
+ }
19
+ export declare const useLinkAccount: () => IUseLinkAccount;
20
+ export declare const useSwitchAccount: () => IUseSwitchAccount;
@@ -37,6 +37,15 @@ export declare const ANALYTICS_EVENTS: {
37
37
  WALLET_CHECKOUT_CLICKED: string;
38
38
  WALLET_RECEIVE_CLICKED: string;
39
39
  WALLET_SWAP_CLICKED: string;
40
+ ACCOUNT_LINKING_STARTED: string;
41
+ ACCOUNT_LINKING_COMPLETED: string;
42
+ ACCOUNT_LINKING_FAILED: string;
43
+ ACCOUNT_UNLINKING_STARTED: string;
44
+ ACCOUNT_UNLINKING_COMPLETED: string;
45
+ ACCOUNT_UNLINKING_FAILED: string;
46
+ ACCOUNT_SWITCH_STARTED: string;
47
+ ACCOUNT_SWITCH_COMPLETED: string;
48
+ ACCOUNT_SWITCH_FAILED: string;
40
49
  };
41
50
  export declare const ANALYTICS_INTEGRATION_TYPE: {
42
51
  REACT_HOOKS: string;