@web3auth/no-modal 11.0.0-beta.1 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/lib.cjs/account-linking/errors.js +111 -0
  2. package/dist/lib.cjs/account-linking/index.js +4 -0
  3. package/dist/lib.cjs/account-linking/rest.js +6 -6
  4. package/dist/lib.cjs/account-linking/vue.js +0 -1
  5. package/dist/lib.cjs/base/connector/constants.js +2 -0
  6. package/dist/lib.cjs/base/errors/index.js +21 -50
  7. package/dist/lib.cjs/base/utils.js +1 -1
  8. package/dist/lib.cjs/connectors/auth-connector/authConnector.js +125 -58
  9. package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +40 -31
  10. package/dist/lib.cjs/index.js +24 -19
  11. package/dist/lib.cjs/noModal.js +60 -26
  12. package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +8 -4
  13. package/dist/lib.cjs/providers/account-abstraction-provider/providers/utils.js +0 -17
  14. package/dist/lib.cjs/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +15 -0
  15. package/dist/lib.cjs/react/context/useWeb3AuthInnerContextValue.js +18 -2
  16. package/dist/lib.cjs/react/solana/provider.js +6 -2
  17. package/dist/lib.cjs/react/wagmi/index.js +6 -0
  18. package/dist/lib.cjs/react/wagmi/provider.js +74 -23
  19. package/dist/lib.cjs/types/account-linking/errors.d.ts +17 -0
  20. package/dist/lib.cjs/types/account-linking/index.d.ts +1 -0
  21. package/dist/lib.cjs/types/base/connector/constants.d.ts +1 -0
  22. package/dist/lib.cjs/types/base/connector/interfaces.d.ts +1 -1
  23. package/dist/lib.cjs/types/base/errors/index.d.ts +2 -13
  24. package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +8 -2
  25. package/dist/lib.cjs/types/connectors/auth-connector/interface.d.ts +1 -1
  26. package/dist/lib.cjs/types/noModal.d.ts +1 -1
  27. package/dist/lib.cjs/types/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.d.ts +1 -0
  28. package/dist/lib.cjs/types/react/wagmi/constants.d.ts +2 -0
  29. package/dist/lib.cjs/types/react/wagmi/provider.d.ts +7 -0
  30. package/dist/lib.cjs/types/vue/wagmi/constants.d.ts +2 -0
  31. package/dist/lib.cjs/types/vue/wagmi/provider.d.ts +7 -1
  32. package/dist/lib.cjs/vue/solana/provider.js +50 -26
  33. package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +13 -6
  34. package/dist/lib.cjs/vue/wagmi/index.js +6 -0
  35. package/dist/lib.cjs/vue/wagmi/provider.js +78 -35
  36. package/dist/lib.esm/account-linking/errors.js +92 -0
  37. package/dist/lib.esm/account-linking/index.js +1 -0
  38. package/dist/lib.esm/account-linking/rest.js +3 -3
  39. package/dist/lib.esm/account-linking/vue.js +0 -1
  40. package/dist/lib.esm/base/connector/constants.js +2 -1
  41. package/dist/lib.esm/base/errors/index.js +21 -50
  42. package/dist/lib.esm/base/utils.js +1 -1
  43. package/dist/lib.esm/connectors/auth-connector/authConnector.js +109 -41
  44. package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +1 -1
  45. package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +42 -33
  46. package/dist/lib.esm/index.js +3 -2
  47. package/dist/lib.esm/noModal.js +56 -20
  48. package/dist/lib.esm/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +10 -5
  49. package/dist/lib.esm/providers/account-abstraction-provider/providers/utils.js +0 -3
  50. package/dist/lib.esm/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +17 -3
  51. package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +18 -2
  52. package/dist/lib.esm/react/solana/provider.js +6 -2
  53. package/dist/lib.esm/react/wagmi/index.js +1 -1
  54. package/dist/lib.esm/react/wagmi/provider.js +74 -25
  55. package/dist/lib.esm/vue/solana/provider.js +51 -28
  56. package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +11 -4
  57. package/dist/lib.esm/vue/wagmi/index.js +1 -1
  58. package/dist/lib.esm/vue/wagmi/provider.js +73 -34
  59. package/package.json +20 -20
@@ -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,9 +107,11 @@ 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
- connection
113
+ connection,
114
+ chainNamespace
96
115
  } = useWeb3Auth.useWeb3Auth();
97
116
  const {
98
117
  disconnect
@@ -101,34 +120,60 @@ function Web3AuthWagmiProvider({
101
120
  const {
102
121
  mutate: reconnect
103
122
  } = wagmi.useReconnect();
123
+ const suppressWagmiDisconnect = react.useRef(false);
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);
104
126
  wagmi.useConnectionEffect({
105
127
  onDisconnect: async () => {
106
128
  loglevel.log.info("Disconnected from wagmi");
107
- if (isConnected) await disconnect();
108
- const connector = getWeb3authConnector(wagmiConfig);
129
+ const isSuppressed = suppressWagmiDisconnect.current;
130
+ suppressWagmiDisconnect.current = false;
131
+ if (!isSuppressed && isConnected) await disconnect();
109
132
  // reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
110
133
  // from the connected provider
111
- if (connector) {
134
+ if (getWeb3authConnector(wagmiConfig)) {
112
135
  resetConnectorState(wagmiConfig);
113
136
  }
114
137
  }
115
138
  });
116
139
  react.useEffect(() => {
117
- (async () => {
118
- if (isConnected && connection !== null && connection !== void 0 && connection.ethereumProvider) {
119
- const connector = await setupConnector(connection.ethereumProvider, wagmiConfig);
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);
145
+ if (shouldBindToWagmi) {
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
149
+ return;
150
+ }
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);
155
+ }
156
+ lastSyncedProvider.current = newEth;
157
+ lastSyncedConnectorName.current = newConnection.connectorName;
158
+ const connector = setupConnector(newEth, wagmiConfig);
120
159
  if (!connector) {
160
+ loglevel.log.error("Failed to setup react wagmi connector");
121
161
  throw new Error("Failed to setup connector");
122
162
  }
123
163
  await connectWeb3AuthWithWagmi(connector, wagmiConfig);
124
164
  reconnect();
125
- } else if (!isConnected) {
165
+ } else {
166
+ lastSyncedProvider.current = null;
167
+ lastSyncedConnectorName.current = null;
126
168
  if (wagmiConfig.state.status === "connected") {
169
+ suppressWagmiDisconnect.current = true;
127
170
  await disconnectWeb3AuthFromWagmi(wagmiConfig);
171
+ } else if (w3aWagmiConnector) {
172
+ resetConnectorState(wagmiConfig);
128
173
  }
129
174
  }
130
175
  })();
131
- }, [isConnected, wagmiConfig, connection, reconnect]);
176
+ }, [chainNamespace, connection, isConnected, reconnect, wagmiConfig]);
132
177
  return react.createElement(react.Fragment, null, children);
133
178
  }
134
179
  function WagmiProvider(_ref) {
@@ -223,3 +268,9 @@ function WagmiProvider(_ref) {
223
268
  }
224
269
 
225
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;
@@ -18,6 +18,7 @@ declare class AuthConnector extends BaseConnector<AuthLoginParams> implements IA
18
18
  private wsEmbedInstance;
19
19
  private authConnectionConfig;
20
20
  private wsEmbedInstancePromise;
21
+ private wsEmbedProviderListenerTarget;
21
22
  private _solanaWallet;
22
23
  private analytics;
23
24
  constructor(params: AuthConnectorOptions);
@@ -60,6 +61,9 @@ declare class AuthConnector extends BaseConnector<AuthLoginParams> implements IA
60
61
  private getNetworkForUnlinkAddress;
61
62
  private createWalletLinkingProof;
62
63
  private getLinkingWalletAddress;
64
+ private getWsEmbedProvider;
65
+ private bindWsEmbedProviderEvents;
66
+ private unbindWsEmbedProviderEvents;
63
67
  private setupSolanaWallet;
64
68
  private _getFinalPrivKey;
65
69
  private connectWithProvider;
@@ -69,6 +73,8 @@ declare class AuthConnector extends BaseConnector<AuthLoginParams> implements IA
69
73
  private getOriginData;
70
74
  private connectWithJwtLogin;
71
75
  private auditOAuditProgress;
76
+ private reportFailedOauthAudit;
77
+ private readonly handleWsEmbedAccountsChanged;
72
78
  }
73
79
  type AuthConnectorFuncParams = Omit<AuthConnectorOptions, "coreOptions" | "authConnectionConfig" | "connectorSettings"> & {
74
80
  connectorSettings?: Omit<AuthConnectorOptions["connectorSettings"], "buildEnv">;
@@ -14,7 +14,7 @@ export interface AuthConnectorSessionTokens {
14
14
  }
15
15
  export interface AuthConnectorLinkAccountParams {
16
16
  authSessionTokens: AuthConnectorSessionTokens;
17
- walletConnector: IConnector<unknown>;
17
+ connectorToLink: IConnector<unknown>;
18
18
  connectorName: WALLET_CONNECTOR_TYPE | string;
19
19
  chainId?: string;
20
20
  }
@@ -139,7 +139,7 @@ export declare class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEve
139
139
  usePrimaryProxy: boolean;
140
140
  account?: ConnectedWalletAccountRef;
141
141
  }): Promise<ConnectedAccountsWithProviders>;
142
- protected linkAccountWithConnector(connectorName: WALLET_CONNECTOR_TYPE | string, chainId: string, walletConnector: IConnector<unknown>): Promise<LinkAccountResult>;
142
+ protected linkAccountWithConnector(connectorName: WALLET_CONNECTOR_TYPE | string, chainId: string, connectorToLink: IConnector<unknown>): Promise<LinkAccountResult>;
143
143
  protected getMainAuthConnector(): AuthConnectorType;
144
144
  /**
145
145
  * Processes the result of a switch account operation.
@@ -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>;
@@ -19,6 +19,7 @@ require('../../base/connector/constants.js');
19
19
  require('jwt-decode');
20
20
  require('../../base/plugin/errors.js');
21
21
  require('../../base/plugin/IPlugin.js');
22
+ var useChain = require('../composables/useChain.js');
22
23
  var useWeb3Auth = require('../composables/useWeb3Auth.js');
23
24
  var constants = require('./constants.js');
24
25
 
@@ -45,58 +46,81 @@ const SolanaProvider = vue.defineComponent({
45
46
  connection,
46
47
  web3Auth
47
48
  } = useWeb3Auth.useWeb3Auth();
49
+ const {
50
+ chainId
51
+ } = useChain.useChain();
48
52
  const clientRef = vue.ref(null);
53
+ // Holds the token for the newest requested sync run. Older async runs compare against it
54
+ // before publishing results so a slower reconnect cannot overwrite a newer chain/account update.
55
+ let activeSyncToken = null;
49
56
  // provide the client to the app
50
57
  vue.provide(constants.SOLANA_CLIENT_KEY, clientRef);
51
- // watch for changes in the connection and chain namespace
52
- vue.watch([isConnected, connection], async ([newIsConnected, newConnection]) => {
53
- var _web3Auth$value;
54
- if (!newIsConnected || !(newConnection !== null && newConnection !== void 0 && newConnection.solanaWallet)) {
55
- if (clientRef.value) {
56
- await disposeClient(clientRef.value);
57
- clientRef.value = null;
58
+ const syncClient = async () => {
59
+ var _web3Auth$value, _web3Auth$value2;
60
+ // Only the latest async, `syncing` run should be allowed to attach its client.
61
+ // A fresh Symbol gives each run a unique identity without relying on counters.
62
+ const syncToken = Symbol("solana-client-sync");
63
+ activeSyncToken = syncToken;
64
+ const newIsConnected = isConnected.value;
65
+ const newConnection = connection.value;
66
+ const currentChain = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.currentChain;
67
+ if (!newIsConnected || !(newConnection !== null && newConnection !== void 0 && newConnection.solanaWallet) || (currentChain === null || currentChain === void 0 ? void 0 : currentChain.chainNamespace) !== baseControllers.CHAIN_NAMESPACES.SOLANA ||
68
+ // only reconnect for the primary connector
69
+ newConnection.connectorName !== ((_web3Auth$value2 = web3Auth.value) === null || _web3Auth$value2 === void 0 ? void 0 : _web3Auth$value2.primaryConnectorName)) {
70
+ const prevClient = clientRef.value;
71
+ clientRef.value = null;
72
+ if (prevClient) {
73
+ await disposeClient(prevClient);
58
74
  }
59
75
  return;
60
76
  }
61
- const currentChain = web3Auth.value.currentChain;
62
- let chainConfig;
63
- if ((currentChain === null || currentChain === void 0 ? void 0 : currentChain.chainNamespace) === baseControllers.CHAIN_NAMESPACES.SOLANA) {
64
- chainConfig = currentChain;
65
- } else {
66
- // use the 1st Solana chain if current chain is not solana
67
- chainConfig = web3Auth.value.coreOptions.chains.find(c => c.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA);
68
- if (!chainConfig) return;
69
- }
70
- // only reconnect for the primary connector
71
- if (newConnection.connectorName !== ((_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.primaryConnectorName)) return;
72
77
  const prevClient = clientRef.value;
78
+ clientRef.value = null;
79
+ if (prevClient) {
80
+ await disposeClient(prevClient);
81
+ }
82
+ let client$1 = null;
73
83
  try {
74
84
  // create a wallet standard connector from connected wallet
75
- const solanaWalletId = "wallet-standard:" + connection.value.connectorName;
76
- const connector = client.createWalletStandardConnector(connection.value.solanaWallet, {
85
+ const solanaWalletId = "wallet-standard:" + newConnection.connectorName;
86
+ const connector = client.createWalletStandardConnector(newConnection.solanaWallet, {
77
87
  id: solanaWalletId,
78
- name: connection.value.connectorName
88
+ name: newConnection.connectorName
79
89
  });
80
90
  // create a solana client
81
91
  const {
82
92
  rpcTarget,
83
93
  wsTarget
84
- } = chainConfig;
85
- const client$1 = client.createClient({
94
+ } = currentChain;
95
+ client$1 = client.createClient({
86
96
  endpoint: rpcTarget,
87
97
  websocketEndpoint: wsTarget,
88
98
  walletConnectors: [connector]
89
99
  });
90
- clientRef.value = client$1;
91
- if (prevClient) await disposeClient(prevClient);
92
100
  // connect the client to the wallet
93
101
  await client$1.actions.connectWallet(solanaWalletId, {
94
102
  autoConnect: true
95
103
  });
104
+ // If another sync started while connectWallet was in flight, this client is stale.
105
+ if (activeSyncToken !== syncToken) {
106
+ await disposeClient(client$1);
107
+ return;
108
+ }
109
+ clientRef.value = client$1;
96
110
  } catch (err) {
111
+ if (client$1) {
112
+ await disposeClient(client$1);
113
+ }
97
114
  loglevel.log.error("Failed to create or connect Solana client", err);
98
- clientRef.value = null;
115
+ // Only clear the shared ref when this failing run is still the newest one.
116
+ if (activeSyncToken === syncToken) {
117
+ clientRef.value = null;
118
+ }
99
119
  }
120
+ };
121
+ // watch for changes in the connection and active chain
122
+ vue.watch([isConnected, connection, chainId], () => {
123
+ void syncClient();
100
124
  }, {
101
125
  immediate: true
102
126
  });
@@ -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;