@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
@@ -1,3 +1,10 @@
1
1
  import { PropsWithChildren } from "react";
2
+ import { Config, Connector, CreateConnectorFn } from "wagmi";
2
3
  import { WagmiProviderProps } from "./interface";
4
+ export declare function getWeb3authConnector(config: Config): Connector<CreateConnectorFn>;
5
+ export declare function createWeb3AuthConnectorForWagmi(provider: any): CreateConnectorFn;
6
+ export declare function setupConnector(provider: any, config: Config): Connector;
7
+ export declare function connectWeb3AuthWithWagmi(connector: Connector, config: Config): Promise<void>;
8
+ export declare function resetConnectorState(config: Config): void;
9
+ export declare function disconnectWeb3AuthFromWagmi(config: Config): Promise<void>;
3
10
  export declare function WagmiProvider({ children, ...props }: PropsWithChildren<WagmiProviderProps>): import("react").FunctionComponentElement<PropsWithChildren<import("wagmi").WagmiProviderProps>>;
@@ -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")[];
@@ -1,6 +1,12 @@
1
- import { type Config } from "@wagmi/core";
1
+ import { type Config, type Connector, type CreateConnectorFn } from "@wagmi/core";
2
2
  import { PropType } from "vue";
3
3
  import { WagmiProviderProps } from "./interface";
4
+ export declare function getWeb3authConnector(config: Config): Connector<CreateConnectorFn>;
5
+ export declare function createWeb3AuthConnectorForWagmi(provider: any): CreateConnectorFn;
6
+ export declare function setupConnector(provider: any, config: Config): Connector;
7
+ export declare function connectWeb3AuthWithWagmi(connector: Connector, config: Config): Promise<void>;
8
+ export declare function resetConnectorState(config: Config): void;
9
+ export declare function disconnectWeb3AuthFromWagmi(config: Config): Promise<void>;
4
10
  export declare const WagmiProvider: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
5
11
  config: {
6
12
  type: PropType<WagmiProviderProps>;
@@ -112,20 +112,27 @@ function useWeb3AuthInnerContextValue({
112
112
  };
113
113
  const authorizedListener = () => {
114
114
  status.value = web3Auth.value.status;
115
+ // on rehydration, `AUTHORIZED` event can be fired first in `CONNECT_AND_SIGN` mode, before `CONNECTED` event.
116
+ // Update the connection state here, so that clients can use the connection state immediately.
115
117
  if (web3Auth.value.status === constants.CONNECTOR_STATUS.AUTHORIZED) {
118
+ var _web3Auth$value$curre3, _web3Auth$value$curre4;
119
+ if (!isInitialized.value) isInitialized.value = true;
116
120
  isAuthorized.value = true;
117
121
  isConnected.value = true;
122
+ connection.value = web3Auth.value.connection;
123
+ chainId.value = web3Auth.value.currentChainId;
124
+ chainNamespace.value = (_web3Auth$value$curre3 = (_web3Auth$value$curre4 = web3Auth.value.currentChain) === null || _web3Auth$value$curre4 === void 0 ? void 0 : _web3Auth$value$curre4.chainNamespace) !== null && _web3Auth$value$curre3 !== void 0 ? _web3Auth$value$curre3 : null;
118
125
  }
119
126
  };
120
127
  const consentAcceptedListener = () => {
121
128
  status.value = web3Auth.value.status;
122
129
  if (web3Auth.value.status === constants.CONNECTOR_STATUS.CONNECTED || web3Auth.value.status === constants.CONNECTOR_STATUS.AUTHORIZED) {
123
- var _web3Auth$value$curre3, _web3Auth$value$curre4;
130
+ var _web3Auth$value$curre5, _web3Auth$value$curre6;
124
131
  if (!isInitialized.value) isInitialized.value = true;
125
132
  isConnected.value = true;
126
133
  connection.value = web3Auth.value.connection;
127
134
  chainId.value = web3Auth.value.currentChainId;
128
- chainNamespace.value = (_web3Auth$value$curre3 = (_web3Auth$value$curre4 = web3Auth.value.currentChain) === null || _web3Auth$value$curre4 === void 0 ? void 0 : _web3Auth$value$curre4.chainNamespace) !== null && _web3Auth$value$curre3 !== void 0 ? _web3Auth$value$curre3 : null;
135
+ chainNamespace.value = (_web3Auth$value$curre5 = (_web3Auth$value$curre6 = web3Auth.value.currentChain) === null || _web3Auth$value$curre6 === void 0 ? void 0 : _web3Auth$value$curre6.chainNamespace) !== null && _web3Auth$value$curre5 !== void 0 ? _web3Auth$value$curre5 : null;
129
136
  if (web3Auth.value.status === constants.CONNECTOR_STATUS.AUTHORIZED) {
130
137
  isAuthorized.value = true;
131
138
  }
@@ -148,11 +155,11 @@ function useWeb3AuthInnerContextValue({
148
155
  isMFAEnabled.value = true;
149
156
  };
150
157
  const connectionUpdatedListener = () => {
151
- var _web3Auth$value$curre5, _web3Auth$value$curre6;
158
+ var _web3Auth$value$curre7, _web3Auth$value$curre8;
152
159
  status.value = web3Auth.value.status;
153
160
  connection.value = web3Auth.value.connection;
154
161
  chainId.value = web3Auth.value.currentChainId;
155
- chainNamespace.value = (_web3Auth$value$curre5 = (_web3Auth$value$curre6 = web3Auth.value.currentChain) === null || _web3Auth$value$curre6 === void 0 ? void 0 : _web3Auth$value$curre6.chainNamespace) !== null && _web3Auth$value$curre5 !== void 0 ? _web3Auth$value$curre5 : null;
162
+ chainNamespace.value = (_web3Auth$value$curre7 = (_web3Auth$value$curre8 = web3Auth.value.currentChain) === null || _web3Auth$value$curre8 === void 0 ? void 0 : _web3Auth$value$curre8.chainNamespace) !== null && _web3Auth$value$curre7 !== void 0 ? _web3Auth$value$curre7 : null;
156
163
  };
157
164
  if (prevWeb3Auth && newWeb3Auth !== prevWeb3Auth) {
158
165
  prevWeb3Auth.removeListener(constants.CONNECTOR_EVENTS.NOT_READY, notReadyListener);
@@ -191,9 +198,9 @@ function useWeb3AuthInnerContextValue({
191
198
  vue.watch(connection, (newConnection, prevConnection) => {
192
199
  var _prevConnection$ether, _newConnection$ethere;
193
200
  const handleChainChange = newChainId => {
194
- var _web3Auth$value$curre7, _web3Auth$value;
201
+ var _web3Auth$value$curre9, _web3Auth$value;
195
202
  chainId.value = newChainId;
196
- chainNamespace.value = (_web3Auth$value$curre7 = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 || (_web3Auth$value = _web3Auth$value.currentChain) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.chainNamespace) !== null && _web3Auth$value$curre7 !== void 0 ? _web3Auth$value$curre7 : null;
203
+ chainNamespace.value = (_web3Auth$value$curre9 = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 || (_web3Auth$value = _web3Auth$value.currentChain) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.chainNamespace) !== null && _web3Auth$value$curre9 !== void 0 ? _web3Auth$value$curre9 : null;
197
204
  };
198
205
  const prevProvider = (_prevConnection$ether = prevConnection === null || prevConnection === void 0 ? void 0 : prevConnection.ethereumProvider) !== null && _prevConnection$ether !== void 0 ? _prevConnection$ether : null;
199
206
  const newProvider = (_newConnection$ethere = newConnection === null || newConnection === void 0 ? void 0 : newConnection.ethereumProvider) !== null && _newConnection$ethere !== void 0 ? _newConnection$ethere : null;
@@ -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;
@@ -3,7 +3,6 @@
3
3
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
4
  var core = require('@wagmi/core');
5
5
  var vue$1 = require('@wagmi/vue');
6
- var connectors = require('@wagmi/vue/connectors');
7
6
  var auth = require('@web3auth/auth');
8
7
  var viem = require('viem');
9
8
  var vue = require('vue');
@@ -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');
@@ -26,23 +25,42 @@ var useWeb3Auth = require('../composables/useWeb3Auth.js');
26
25
  var useWeb3AuthDisconnect = require('../composables/useWeb3AuthDisconnect.js');
27
26
  var constants = require('./constants.js');
28
27
 
29
- const WEB3AUTH_CONNECTOR_ID = "web3auth";
30
28
  function getWeb3authConnector(config) {
31
- return config.connectors.find(c => c.id === WEB3AUTH_CONNECTOR_ID);
29
+ return config.connectors.find(c => c.id === constants$1.WEB3AUTH_CONNECTOR_ID);
32
30
  }
33
- // Helper to initialize connectors for the given wallets
31
+ // Helper to create a Web3Auth connector to connect with wagmi
34
32
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- async function setupConnector(provider, config) {
36
- let connector = getWeb3authConnector(config);
37
- if (connector) return connector;
38
- // Create new connector if not already existing
39
- connector = connectors.injected({
33
+ function createWeb3AuthConnectorForWagmi(provider) {
34
+ const baseConnector = core.injected({
40
35
  target: {
41
36
  provider: provider,
42
- id: WEB3AUTH_CONNECTOR_ID,
37
+ id: constants$1.WEB3AUTH_CONNECTOR_ID,
43
38
  name: "Web3Auth"
44
39
  }
45
40
  });
41
+ return config => {
42
+ const connector = baseConnector(config);
43
+ const baseOnAccountsChanged = connector.onAccountsChanged.bind(connector);
44
+ connector.onAccountsChanged = accounts => {
45
+ // we need to handle the `accountsChanged` event emitted on the cross-namespace chain switch.
46
+ // on evm -> solana, the accountsChanged event is emitted with the solana address, which is not valid for evm.
47
+ // that causes the `invalid account address` error in wagmi. So, here, we're filtering out the solana addresses.
48
+ if (accounts.length > 0 && !accounts.every(account => typeof account === "string" && viem.isAddress(account))) {
49
+ loglevel.log.warn("onAccountsChanged::accountsChanged event received on non-EVM address");
50
+ return;
51
+ }
52
+ baseOnAccountsChanged(accounts);
53
+ };
54
+ return connector;
55
+ };
56
+ }
57
+ // Helper to initialize connectors for the given wallets
58
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
+ function setupConnector(provider, config) {
60
+ let connector = getWeb3authConnector(config);
61
+ if (connector) return connector;
62
+ // Create new connector if not already existing
63
+ connector = createWeb3AuthConnectorForWagmi(provider);
46
64
  const result = config._internal.connectors.setup(connector);
47
65
  config._internal.connectors.setState(current => [...current, result]);
48
66
  return result;
@@ -69,8 +87,8 @@ async function connectWeb3AuthWithWagmi(connector, config) {
69
87
  }));
70
88
  }
71
89
  function resetConnectorState(config) {
72
- config._internal.connectors.setState(prev => prev.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID));
73
- config.connectors.filter(c => c.id !== WEB3AUTH_CONNECTOR_ID);
90
+ config._internal.connectors.setState(prev => prev.filter(c => c.id !== constants$1.WEB3AUTH_CONNECTOR_ID));
91
+ config.connectors.filter(c => c.id !== constants$1.WEB3AUTH_CONNECTOR_ID);
74
92
  }
75
93
  async function disconnectWeb3AuthFromWagmi(config) {
76
94
  var _config$storage3, _config$storage4;
@@ -90,6 +108,7 @@ const Web3AuthWagmiProvider = vue.defineComponent({
90
108
  const {
91
109
  isConnected,
92
110
  connection,
111
+ web3Auth,
93
112
  chainNamespace
94
113
  } = useWeb3Auth.useWeb3Auth();
95
114
  const {
@@ -121,13 +140,15 @@ const Web3AuthWagmiProvider = vue.defineComponent({
121
140
  const newIsConnected = isConnected.value;
122
141
  const newConnection = connection.value;
123
142
  const newEth = (_newConnection$ethere = newConnection === null || newConnection === void 0 ? void 0 : newConnection.ethereumProvider) !== null && _newConnection$ethere !== void 0 ? _newConnection$ethere : null;
143
+ const w3aWagmiConnector = getWeb3authConnector(wagmiConfig);
124
144
  const shouldBindToWagmi = newIsConnected && chainNamespace.value === baseControllers.CHAIN_NAMESPACES.EIP155 && Boolean(newConnection && newEth);
125
- if (shouldBindToWagmi && newConnection && newEth) {
126
- const hasSameBinding = lastSyncedProvider.value === newEth && lastSyncedConnectorName.value === newConnection.connectorName;
127
- if (hasSameBinding && wagmiConfig.state.status === "connected") {
145
+ if (shouldBindToWagmi) {
146
+ var _web3Auth$value;
147
+ const hasSameBinding = lastSyncedProvider.value === newEth && lastSyncedConnectorName.value === newConnection.connectorName && (newConnection === null || newConnection === void 0 ? void 0 : newConnection.connectorName) === ((_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.connection.connectorName) && wagmiConfig.state.status === "connected";
148
+ if (hasSameBinding) {
128
149
  return;
129
150
  }
130
- if (!hasSameBinding && getWeb3authConnector(wagmiConfig)) {
151
+ if (!hasSameBinding && w3aWagmiConnector) {
131
152
  if (wagmiConfig.state.status === "connected") {
132
153
  suppressWagmiDisconnect.value = true;
133
154
  await disconnectWeb3AuthFromWagmi(wagmiConfig);
@@ -135,21 +156,21 @@ const Web3AuthWagmiProvider = vue.defineComponent({
135
156
  resetConnectorState(wagmiConfig);
136
157
  }
137
158
  }
138
- const connector = await setupConnector(newEth, wagmiConfig);
159
+ lastSyncedProvider.value = newEth;
160
+ lastSyncedConnectorName.value = newConnection.connectorName;
161
+ const connector = setupConnector(newEth, wagmiConfig);
139
162
  if (!connector) {
140
163
  throw new Error("Failed to setup connector");
141
164
  }
142
165
  await connectWeb3AuthWithWagmi(connector, wagmiConfig);
143
- lastSyncedProvider.value = newEth;
144
- lastSyncedConnectorName.value = newConnection.connectorName;
145
166
  reconnect();
146
- } else {
167
+ } else if (!newIsConnected || chainNamespace.value !== baseControllers.CHAIN_NAMESPACES.EIP155) {
147
168
  lastSyncedProvider.value = null;
148
169
  lastSyncedConnectorName.value = null;
149
170
  if (wagmiConfig.state.status === "connected") {
150
171
  suppressWagmiDisconnect.value = true;
151
172
  await disconnectWeb3AuthFromWagmi(wagmiConfig);
152
- } else if (getWeb3authConnector(wagmiConfig)) {
173
+ } else if (w3aWagmiConnector) {
153
174
  resetConnectorState(wagmiConfig);
154
175
  }
155
176
  }
@@ -214,7 +235,7 @@ const WagmiProvider = vue.defineComponent({
214
235
  return viem.fallback(transports);
215
236
  };
216
237
  const defineWagmiConfig = () => {
217
- var _web3Auth$value;
238
+ var _web3Auth$value2;
218
239
  const configParams = _objectSpread(_objectSpread({
219
240
  ssr: true
220
241
  }, config), {}, {
@@ -225,7 +246,7 @@ const WagmiProvider = vue.defineComponent({
225
246
  client: undefined
226
247
  });
227
248
  const wagmiChains = [];
228
- if (isInitialized.value && web3Auth !== null && web3Auth !== void 0 && (_web3Auth$value = web3Auth.value) !== null && _web3Auth$value !== void 0 && (_web3Auth$value = _web3Auth$value.coreOptions) !== null && _web3Auth$value !== void 0 && _web3Auth$value.chains) {
249
+ if (isInitialized.value && web3Auth !== null && web3Auth !== void 0 && (_web3Auth$value2 = web3Auth.value) !== null && _web3Auth$value2 !== void 0 && (_web3Auth$value2 = _web3Auth$value2.coreOptions) !== null && _web3Auth$value2 !== void 0 && _web3Auth$value2.chains) {
229
250
  var _web3Auth$value$curre;
230
251
  const defaultChainId = (_web3Auth$value$curre = web3Auth.value.currentChain) === null || _web3Auth$value$curre === void 0 ? void 0 : _web3Auth$value$curre.chainId;
231
252
  const chains = web3Auth.value.coreOptions.chains.filter(chain => chain.chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155);
@@ -273,8 +294,8 @@ const WagmiProvider = vue.defineComponent({
273
294
  }
274
295
  };
275
296
  vue.watch(isInitialized, (newIsInitialized, prevIsInitialized) => {
276
- var _web3Auth$value2;
277
- (_web3Auth$value2 = web3Auth.value) === null || _web3Auth$value2 === void 0 || _web3Auth$value2.setAnalyticsProperties({
297
+ var _web3Auth$value3;
298
+ (_web3Auth$value3 = web3Auth.value) === null || _web3Auth$value3 === void 0 || _web3Auth$value3.setAnalyticsProperties({
278
299
  wagmi_enabled: true
279
300
  });
280
301
  if (newIsInitialized && !prevIsInitialized) {
@@ -307,3 +328,9 @@ const WagmiProvider = vue.defineComponent({
307
328
  });
308
329
 
309
330
  exports.WagmiProvider = WagmiProvider;
331
+ exports.connectWeb3AuthWithWagmi = connectWeb3AuthWithWagmi;
332
+ exports.createWeb3AuthConnectorForWagmi = createWeb3AuthConnectorForWagmi;
333
+ exports.disconnectWeb3AuthFromWagmi = disconnectWeb3AuthFromWagmi;
334
+ exports.getWeb3authConnector = getWeb3authConnector;
335
+ exports.resetConnectorState = resetConnectorState;
336
+ exports.setupConnector = setupConnector;
@@ -0,0 +1,92 @@
1
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import { Web3AuthError } from '../base/errors/index.js';
3
+
4
+ class AccountLinkingError extends Web3AuthError {
5
+ constructor(code, message, cause) {
6
+ super(code, message, cause);
7
+ Object.defineProperty(this, "name", {
8
+ value: "AccountLinkingError",
9
+ configurable: true
10
+ });
11
+ }
12
+ static fromCode(code, extraMessage = "", cause) {
13
+ return new AccountLinkingError(code, `${AccountLinkingError.messages[code]}. ${extraMessage}`, cause);
14
+ }
15
+ static requestFailed(extraMessage = "", cause) {
16
+ return AccountLinkingError.fromCode(5401, extraMessage, cause);
17
+ }
18
+ static serverNotConfigured(extraMessage = "", cause) {
19
+ return AccountLinkingError.fromCode(5402, extraMessage, cause);
20
+ }
21
+ static primaryTokenNotAvailable(extraMessage = "", cause) {
22
+ return AccountLinkingError.fromCode(5403, extraMessage, cause);
23
+ }
24
+ static walletProofFailed(extraMessage = "", cause) {
25
+ return AccountLinkingError.fromCode(5404, extraMessage, cause);
26
+ }
27
+ static unsupportedConnector(extraMessage = "", cause) {
28
+ return AccountLinkingError.fromCode(5405, extraMessage, cause);
29
+ }
30
+ static cannotUnlinkActiveAccount() {
31
+ return AccountLinkingError.fromCode(5406);
32
+ }
33
+ static accountNotLinked(message = "", cause) {
34
+ return AccountLinkingError.fromCode(5407, message, cause);
35
+ }
36
+ static cannotUnlinkPrimaryAccount() {
37
+ return AccountLinkingError.fromCode(5408);
38
+ }
39
+ toString() {
40
+ return `[${this.code}] ${this.message}`;
41
+ }
42
+ }
43
+ _defineProperty(AccountLinkingError, "messages", {
44
+ 5000: "Custom",
45
+ 5401: "Account linking request failed",
46
+ 5402: "Citadel server URL is not configured",
47
+ 5403: "Primary identity token is not available",
48
+ 5404: "Failed to obtain wallet proof token",
49
+ 5405: "Connector is not supported for wallet linking",
50
+ 5406: "Cannot unlink active account",
51
+ 5407: "Account not linked",
52
+ 5408: "Cannot unlink primary account"
53
+ });
54
+ async function getAccountLinkingRequestError(error) {
55
+ if (error instanceof AccountLinkingError) {
56
+ return error;
57
+ }
58
+ if (error instanceof Response) {
59
+ if (error.status === 409) {
60
+ return AccountLinkingError.requestFailed("This wallet address is already registered on this dApp");
61
+ }
62
+ if (error.json && typeof error.json === "function") {
63
+ try {
64
+ var _json$message;
65
+ const json = await error.json();
66
+ return AccountLinkingError.requestFailed((_json$message = json.message) !== null && _json$message !== void 0 ? _json$message : "Failed to link account");
67
+ } catch {
68
+ // continue
69
+ }
70
+ }
71
+ }
72
+ return AccountLinkingError.requestFailed(error instanceof Error ? error.message : JSON.stringify(error), error);
73
+ }
74
+ function formatAccountLinkingErrorMessage(error, fallbackMessage = "Unknown error during the operation.") {
75
+ if (error instanceof AccountLinkingError) {
76
+ return error.toString();
77
+ }
78
+ if (error instanceof Web3AuthError) {
79
+ return `[${error.code}] Account linking error: ${error.message || fallbackMessage}`;
80
+ }
81
+ if (error instanceof Error) {
82
+ return `Account linking error: ${error.message || fallbackMessage}`;
83
+ }
84
+ try {
85
+ const stringifiedError = JSON.stringify(error);
86
+ return stringifiedError;
87
+ } catch {
88
+ return fallbackMessage;
89
+ }
90
+ }
91
+
92
+ export { AccountLinkingError, formatAccountLinkingErrorMessage, getAccountLinkingRequestError };
@@ -1 +1,2 @@
1
+ export { AccountLinkingError, formatAccountLinkingErrorMessage, getAccountLinkingRequestError } from './errors.js';
1
2
  export { makeAccountLinkingRequest, makeAccountUnlinkingRequest } from './rest.js';
@@ -1,5 +1,5 @@
1
1
  import { post } from '@toruslabs/http-helpers';
2
- import { AccountLinkingError } from '../base/errors/index.js';
2
+ import { getAccountLinkingRequestError, AccountLinkingError } from './errors.js';
3
3
 
4
4
  /**
5
5
  * Send both identity proofs to the Citadel account-linking endpoint and
@@ -17,8 +17,8 @@ async function makeAccountLinkingRequest(authServerUrl, accessToken, payload) {
17
17
  }
18
18
  });
19
19
  } catch (cause) {
20
- const message = cause instanceof Error ? cause.message : String(cause);
21
- throw AccountLinkingError.requestFailed(message, cause);
20
+ const accountLinkingError = await getAccountLinkingRequestError(cause);
21
+ throw accountLinkingError;
22
22
  }
23
23
  if (!result.success) {
24
24
  var _result$message;
@@ -20,7 +20,6 @@ const useLinkAccount = () => {
20
20
  linkedAccounts.value = result.linkedAccounts;
21
21
  return result;
22
22
  } catch (err) {
23
- log.error("Error linking account", err);
24
23
  error.value = err;
25
24
  } finally {
26
25
  loading.value = false;
@@ -1,5 +1,6 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
 
3
+ const WEB3AUTH_CONNECTOR_ID = "web3auth";
3
4
  const CONNECTOR_STATUS = {
4
5
  NOT_READY: "not_ready",
5
6
  READY: "ready",
@@ -31,4 +32,4 @@ const CONNECTOR_INITIAL_AUTHENTICATION_MODE = {
31
32
  CONNECT_AND_SIGN: "connect-and-sign"
32
33
  };
33
34
 
34
- export { CONNECTOR_CATEGORY, CONNECTOR_EVENTS, CONNECTOR_INITIAL_AUTHENTICATION_MODE, CONNECTOR_STATUS };
35
+ export { CONNECTOR_CATEGORY, CONNECTOR_EVENTS, CONNECTOR_INITIAL_AUTHENTICATION_MODE, CONNECTOR_STATUS, WEB3AUTH_CONNECTOR_ID };
@@ -188,7 +188,11 @@ class WalletOperationsError extends Web3AuthError {
188
188
  });
189
189
  }
190
190
  static fromCode(code, extraMessage = "", cause) {
191
- return new WalletOperationsError(code, `${WalletOperationsError.messages[code]}, ${extraMessage}`, cause);
191
+ let message = WalletOperationsError.messages[code];
192
+ if (extraMessage) {
193
+ message = `${message}, ${extraMessage}`;
194
+ }
195
+ return new WalletOperationsError(code, message, cause);
192
196
  }
193
197
 
194
198
  // Custom methods
@@ -201,58 +205,16 @@ class WalletOperationsError extends Web3AuthError {
201
205
  static chainNamespaceNotAllowed(extraMessage = "", cause) {
202
206
  return WalletOperationsError.fromCode(5203, extraMessage, cause);
203
207
  }
208
+ static userRejected(extraMessage = "", cause) {
209
+ return WalletOperationsError.fromCode(5204, extraMessage, cause);
210
+ }
204
211
  }
205
212
  _defineProperty(WalletOperationsError, "messages", {
206
213
  5000: "Custom",
207
214
  5201: "Provided chainId is not allowed",
208
- 5202: "This operation is not allowed"
209
- });
210
- class AccountLinkingError extends Web3AuthError {
211
- constructor(code, message, cause) {
212
- super(code, message, cause);
213
- Object.defineProperty(this, "name", {
214
- value: "AccountLinkingError",
215
- configurable: true
216
- });
217
- }
218
- static fromCode(code, extraMessage = "", cause) {
219
- return new AccountLinkingError(code, `${AccountLinkingError.messages[code]}. ${extraMessage}`, cause);
220
- }
221
- static requestFailed(extraMessage = "", cause) {
222
- return AccountLinkingError.fromCode(5401, extraMessage, cause);
223
- }
224
- static serverNotConfigured(extraMessage = "", cause) {
225
- return AccountLinkingError.fromCode(5402, extraMessage, cause);
226
- }
227
- static primaryTokenNotAvailable(extraMessage = "", cause) {
228
- return AccountLinkingError.fromCode(5403, extraMessage, cause);
229
- }
230
- static walletProofFailed(extraMessage = "", cause) {
231
- return AccountLinkingError.fromCode(5404, extraMessage, cause);
232
- }
233
- static unsupportedConnector(extraMessage = "", cause) {
234
- return AccountLinkingError.fromCode(5405, extraMessage, cause);
235
- }
236
- static cannotUnlinkActiveAccount() {
237
- return AccountLinkingError.fromCode(5406);
238
- }
239
- static accountNotLinked(message = "", cause) {
240
- return AccountLinkingError.fromCode(5407, message, cause);
241
- }
242
- static cannotUnlinkPrimaryAccount() {
243
- return AccountLinkingError.fromCode(5408);
244
- }
245
- }
246
- _defineProperty(AccountLinkingError, "messages", {
247
- 5000: "Custom",
248
- 5401: "Account linking request failed",
249
- 5402: "Citadel server URL is not configured",
250
- 5403: "Primary identity token is not available",
251
- 5404: "Failed to obtain wallet proof token",
252
- 5405: "Connector is not supported for wallet linking",
253
- 5406: "Cannot unlink active account",
254
- 5407: "Account not linked",
255
- 5408: "Cannot unlink primary account"
215
+ 5202: "This operation is not allowed",
216
+ 5203: "Chain namespace is not allowed",
217
+ 5204: "User rejected the request"
256
218
  });
257
219
  class WalletProviderError extends Web3AuthError {
258
220
  constructor(code, message, cause) {
@@ -286,5 +248,14 @@ _defineProperty(WalletProviderError, "messages", {
286
248
  5302: "'args.method' must be a non-empty string.",
287
249
  5303: "'args.params' must be an object or array if provided."
288
250
  });
251
+ function isUserRejectedError(error) {
252
+ if (error instanceof Web3AuthError && error.code === 5203) return true;
253
+ if (error instanceof Error) {
254
+ var _error$message;
255
+ const normalizedMessage = ((_error$message = error.message) === null || _error$message === void 0 ? void 0 : _error$message.toLowerCase()) || "";
256
+ return normalizedMessage.includes("user rejected the request");
257
+ }
258
+ return false;
259
+ }
289
260
 
290
- export { AccountLinkingError, WalletInitializationError, WalletLoginError, WalletOperationsError, WalletProviderError, Web3AuthError };
261
+ export { WalletInitializationError, WalletLoginError, WalletOperationsError, WalletProviderError, Web3AuthError, isUserRejectedError };
@@ -149,7 +149,7 @@ const getWalletServicesAnalyticsProperties = walletServicesConfig => {
149
149
  ws_default_portfolio: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig10 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig10 === void 0 ? void 0 : _walletServicesConfig10.defaultPortfolio
150
150
  };
151
151
  };
152
- const sdkVersion = "11.0.0-beta.2";
152
+ const sdkVersion = "11.0.0";
153
153
  const getErrorAnalyticsProperties = error => {
154
154
  try {
155
155
  const code = error instanceof Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
@@ -1,15 +1,15 @@
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';
6
7
  import { BUILD_ENV, UX_MODE, Auth, SDK_MODE, SUPPORTED_KEY_CURVES, generateRecordId, version, createHandler, PopupHandler, getUserId } from '@web3auth/auth';
7
8
  import { WS_EMBED_LOGIN_MODE } from '@web3auth/ws-embed';
8
9
  import deepmerge from 'deepmerge';
9
- import { numberToHex } from 'viem';
10
10
  import { generateNonce, parseToken } from '../utils.js';
11
11
  import { AuthSolanaWallet } from './authSolanaWallet.js';
12
- import { WalletLoginError, WalletInitializationError, Web3AuthError, AccountLinkingError } from '../../base/errors/index.js';
12
+ import { WalletLoginError, WalletInitializationError, Web3AuthError } from '../../base/errors/index.js';
13
13
  import { WALLET_CONNECTORS } from '../../base/wallet/index.js';
14
14
  import { BaseConnector } from '../../base/connector/baseConnector.js';
15
15
  import { CONNECTOR_NAMESPACES } from '../../base/chain/IChainInterface.js';
@@ -18,8 +18,8 @@ import { CONNECTED_STATUSES } from '../../base/connector/connectorStatus.js';
18
18
  import { log } from '../../base/loglevel.js';
19
19
  import { Analytics, ANALYTICS_EVENTS } from '../../base/analytics.js';
20
20
  import { citadelServerUrl, getErrorAnalyticsProperties, parseChainNamespaceFromCitadelResponse } from '../../base/utils.js';
21
+ import { AccountLinkingError } from '../../account-linking/errors.js';
21
22
  import { makeAccountLinkingRequest, makeAccountUnlinkingRequest } from '../../account-linking/rest.js';
22
- import { CHAIN_NAMESPACES, cloneDeep } from '@toruslabs/base-controllers';
23
23
 
24
24
  // Auth connections that have been deprecated and are no longer supported by the SDK.
25
25
  // Passing any of these as `authConnection` results in a hard error so consumers
@@ -312,6 +312,7 @@ class AuthConnector extends BaseConnector {
312
312
  });
313
313
  }
314
314
  async getLinkedAccounts() {
315
+ var _citadelUserInfo$acco, _this$solanaWallet;
315
316
  const accessToken = await this.authInstance.authSessionManager.getAccessToken();
316
317
  if (!accessToken) throw WalletLoginError.connectionError("Could not obtain an access token from the current AUTH session.");
317
318
  const citadelUserInfo = await get(`${citadelServerUrl(this.coreOptions.authBuildEnv)}/v1/user`, {
@@ -319,11 +320,28 @@ class AuthConnector extends BaseConnector {
319
320
  Authorization: `Bearer ${accessToken}`
320
321
  }
321
322
  });
322
- const linkedAccounts = (citadelUserInfo === null || citadelUserInfo === void 0 ? void 0 : citadelUserInfo.accounts) || [];
323
- return linkedAccounts.map(account => _objectSpread(_objectSpread({}, account), {}, {
324
- // by default, the primary account is the active account
325
- active: account.isPrimary
326
- }));
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;
327
345
  }
328
346
  async switchChain(params, init = false) {
329
347
  super.checkSwitchChainRequirements(params, init);
@@ -339,13 +357,11 @@ class AuthConnector extends BaseConnector {
339
357
  if (newChainConfig.chainNamespace === CHAIN_NAMESPACES.SOLANA || newChainConfig.chainNamespace === CHAIN_NAMESPACES.EIP155) {
340
358
  var _this$wsEmbedInstance;
341
359
  if (!((_this$wsEmbedInstance = this.wsEmbedInstance) !== null && _this$wsEmbedInstance !== void 0 && _this$wsEmbedInstance.provider)) throw WalletInitializationError.notReady("Wallet embed is not ready");
342
- const chainIdNum = parseInt(newChainConfig.chainId, 16);
343
- // WsEmbed expects the chainId in hex format
344
- const chainIdHex = numberToHex(chainIdNum);
360
+ const caipChainId = getCaipChainId(newChainConfig);
345
361
  await this.wsEmbedInstance.provider.request({
346
362
  method: "wallet_switchChain",
347
363
  params: {
348
- chainId: chainIdHex
364
+ chainId: caipChainId
349
365
  }
350
366
  });
351
367
  } else {
@@ -460,9 +476,7 @@ class AuthConnector extends BaseConnector {
460
476
  }
461
477
  }
462
478
  } catch (error) {
463
- if (error instanceof AccountLinkingError) {
464
- throw error;
465
- }
479
+ if (error instanceof Web3AuthError) throw error;
466
480
  throw AccountLinkingError.walletProofFailed(error instanceof Error ? error.message : String(error), error);
467
481
  }
468
482
  const trackData = {
@@ -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(_) {}