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

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