@wagmi/connectors 2.3.0 → 2.4.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.
@@ -19,6 +19,7 @@ type InjectedProviderFlags = {
19
19
  isFrame?: true;
20
20
  isFrontier?: true;
21
21
  isGamestop?: true;
22
+ isHaqqWallet?: true;
22
23
  isHyperPay?: true;
23
24
  isImToken?: true;
24
25
  isKuCoinWallet?: true;
@@ -61,6 +61,8 @@ function getInjectedName(ethereum) {
61
61
  return "Frontier Wallet";
62
62
  if (provider.isGamestop)
63
63
  return "GameStop Wallet";
64
+ if (provider.isHaqqWallet)
65
+ return "HAQQ Wallet";
64
66
  if (provider.isHyperPay)
65
67
  return "HyperPay Wallet";
66
68
  if (provider.isImToken)
@@ -2,7 +2,7 @@ import * as viem from 'viem';
2
2
  import { CoinbaseWalletProvider } from '@coinbase/wallet-sdk';
3
3
  import { CoinbaseWalletSDKOptions } from '@coinbase/wallet-sdk/dist/CoinbaseWalletSDK';
4
4
  import { Chain } from '@wagmi/chains';
5
- import { C as Connector } from './base-0473abd3.js';
5
+ import { C as Connector } from './base-2dd7facf.js';
6
6
  import 'eventemitter3';
7
7
 
8
8
  type Options = Omit<CoinbaseWalletSDKOptions, 'reloadOnDisconnect'> & {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { C as Connector, a as ConnectorData, b as ConnectorEvents, W as WindowProvider } from './base-0473abd3.js';
1
+ export { C as Connector, a as ConnectorData, b as ConnectorEvents, W as WindowProvider } from './base-2dd7facf.js';
2
2
  import '@wagmi/chains';
3
3
  import 'eventemitter3';
4
4
  import 'viem';
@@ -15,4 +15,6 @@ declare class ConnectorNotFoundError extends Error {
15
15
  message: string;
16
16
  }
17
17
 
18
- export { ChainNotConfiguredForConnectorError, ConnectorNotFoundError };
18
+ declare function normalizeChainId(chainId: string | number | bigint): number;
19
+
20
+ export { ChainNotConfiguredForConnectorError, ConnectorNotFoundError, normalizeChainId };
package/dist/index.js CHANGED
@@ -2,11 +2,15 @@ import {
2
2
  ChainNotConfiguredForConnectorError,
3
3
  ConnectorNotFoundError
4
4
  } from "./chunk-ZCAPXGBX.js";
5
+ import {
6
+ normalizeChainId
7
+ } from "./chunk-OQILYQDO.js";
5
8
  import {
6
9
  Connector
7
10
  } from "./chunk-QYMCVNHT.js";
8
11
  export {
9
12
  ChainNotConfiguredForConnectorError,
10
13
  Connector,
11
- ConnectorNotFoundError
14
+ ConnectorNotFoundError,
15
+ normalizeChainId
12
16
  };
@@ -1,7 +1,7 @@
1
1
  import * as viem from 'viem';
2
2
  import { Address } from 'viem';
3
3
  import { Chain } from '@wagmi/chains';
4
- import { W as WindowProvider, C as Connector } from './base-0473abd3.js';
4
+ import { W as WindowProvider, C as Connector } from './base-2dd7facf.js';
5
5
  import 'eventemitter3';
6
6
 
7
7
  type InjectedConnectorOptions = {
package/dist/injected.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InjectedConnector
3
- } from "./chunk-4BSCIAHY.js";
3
+ } from "./chunk-Z2P63ELM.js";
4
4
  import "./chunk-ZCAPXGBX.js";
5
5
  import "./chunk-OQILYQDO.js";
6
6
  import "./chunk-QYMCVNHT.js";
package/dist/ledger.d.ts CHANGED
@@ -1,27 +1,52 @@
1
1
  import * as viem from 'viem';
2
2
  import { EthereumProvider } from '@ledgerhq/connect-kit-loader';
3
3
  import { Chain } from '@wagmi/chains';
4
- import { C as Connector, a as ConnectorData } from './base-0473abd3.js';
4
+ import { EthereumProviderOptions } from '@walletconnect/ethereum-provider/dist/types/EthereumProvider';
5
+ import { C as Connector } from './base-2dd7facf.js';
5
6
  import 'eventemitter3';
6
7
 
7
- type LedgerConnectorOptions = {
8
+ type LedgerConnectorWcV1Options = {
9
+ walletConnectVersion?: 1;
8
10
  bridge?: string;
9
11
  chainId?: number;
10
- enableDebugLogs?: boolean;
11
12
  rpc?: {
12
13
  [chainId: number]: string;
13
14
  };
14
15
  };
16
+ type LedgerConnectorWcV2Options = {
17
+ walletConnectVersion?: 2;
18
+ projectId?: EthereumProviderOptions['projectId'];
19
+ requiredChains?: number[];
20
+ requiredMethods?: string[];
21
+ optionalMethods?: string[];
22
+ requiredEvents?: string[];
23
+ optionalEvents?: string[];
24
+ };
25
+ type LedgerConnectorOptions = {
26
+ enableDebugLogs?: boolean;
27
+ } & (LedgerConnectorWcV1Options | LedgerConnectorWcV2Options);
28
+ type ConnectConfig = {
29
+ /** Target chain to connect to. */
30
+ chainId?: number;
31
+ };
15
32
  declare class LedgerConnector extends Connector<EthereumProvider, LedgerConnectorOptions> {
16
33
  #private;
17
34
  readonly id = "ledger";
18
35
  readonly name = "Ledger";
19
36
  readonly ready = true;
20
- constructor({ chains, options, }?: {
37
+ get walletConnectVersion(): 1 | 2;
38
+ constructor(config: {
21
39
  chains?: Chain[];
22
- options?: LedgerConnectorOptions;
40
+ options: LedgerConnectorOptions;
23
41
  });
24
- connect(): Promise<Required<ConnectorData>>;
42
+ connect({ chainId }?: ConnectConfig): Promise<{
43
+ account: `0x${string}`;
44
+ chain: {
45
+ id: number;
46
+ unsupported: boolean;
47
+ };
48
+ provider: EthereumProvider;
49
+ }>;
25
50
  disconnect(): Promise<void>;
26
51
  getAccount(): Promise<`0x${string}`>;
27
52
  getChainId(): Promise<number>;
@@ -284,9 +309,11 @@ declare class LedgerConnector extends Connector<EthereumProvider, LedgerConnecto
284
309
  };
285
310
  }>;
286
311
  isAuthorized(): Promise<boolean>;
312
+ switchChain(chainId: number): Promise<Chain>;
287
313
  protected onAccountsChanged: (accounts: string[]) => void;
288
314
  protected onChainChanged: (chainId: number | string) => void;
289
315
  protected onDisconnect: () => void;
316
+ protected onConnect: () => void;
290
317
  }
291
318
 
292
319
  export { LedgerConnector };
package/dist/ledger.js CHANGED
@@ -23,18 +23,23 @@ import {
23
23
  getAddress,
24
24
  numberToHex
25
25
  } from "viem";
26
- var _provider, _switchChain, switchChain_fn;
26
+ var _provider, _initProviderPromise, _isV1, _createProvider, createProvider_fn, _initProvider, initProvider_fn, _setupListeners, setupListeners_fn, _removeListeners, removeListeners_fn;
27
27
  var LedgerConnector = class extends Connector {
28
- constructor({
29
- chains,
30
- options = { enableDebugLogs: false }
31
- } = {}) {
32
- super({ chains, options });
33
- __privateAdd(this, _switchChain);
28
+ constructor(config) {
29
+ super({
30
+ ...config,
31
+ options: { ...config.options }
32
+ });
33
+ __privateAdd(this, _createProvider);
34
+ __privateAdd(this, _initProvider);
35
+ __privateAdd(this, _setupListeners);
36
+ __privateAdd(this, _removeListeners);
34
37
  __publicField(this, "id", "ledger");
35
38
  __publicField(this, "name", "Ledger");
36
39
  __publicField(this, "ready", true);
37
40
  __privateAdd(this, _provider, void 0);
41
+ __privateAdd(this, _initProviderPromise, void 0);
42
+ __privateAdd(this, _isV1, void 0);
38
43
  __publicField(this, "onAccountsChanged", (accounts) => {
39
44
  if (accounts.length === 0)
40
45
  this.emit("disconnect");
@@ -49,48 +54,60 @@ var LedgerConnector = class extends Connector {
49
54
  __publicField(this, "onDisconnect", () => {
50
55
  this.emit("disconnect");
51
56
  });
57
+ __publicField(this, "onConnect", () => {
58
+ this.emit("connect", {});
59
+ });
60
+ __privateSet(this, _isV1, this.walletConnectVersion === 1);
52
61
  }
53
- async connect() {
62
+ get walletConnectVersion() {
63
+ if (this.options.walletConnectVersion)
64
+ return this.options.walletConnectVersion;
65
+ else if (this.options.projectId)
66
+ return 2;
67
+ return 1;
68
+ }
69
+ async connect({ chainId } = {}) {
54
70
  try {
55
71
  const provider = await this.getProvider({ create: true });
56
- if (provider.on) {
57
- provider.on("accountsChanged", this.onAccountsChanged);
58
- provider.on("chainChanged", this.onChainChanged);
59
- provider.on("disconnect", this.onDisconnect);
72
+ __privateMethod(this, _setupListeners, setupListeners_fn).call(this);
73
+ if (!provider.session) {
74
+ this.emit("message", { type: "connecting" });
75
+ await provider.request({
76
+ method: "eth_requestAccounts"
77
+ });
78
+ }
79
+ const account = await this.getAccount();
80
+ let id = await this.getChainId();
81
+ let unsupported = this.isChainUnsupported(id);
82
+ if (chainId && id !== chainId) {
83
+ const chain = await this.switchChain(chainId);
84
+ id = chain.id;
85
+ unsupported = this.isChainUnsupported(id);
60
86
  }
61
- this.emit("message", { type: "connecting" });
62
- const accounts = await provider.request({
63
- method: "eth_requestAccounts"
64
- });
65
- const account = getAddress(accounts[0]);
66
- const id = await this.getChainId();
67
- const unsupported = this.isChainUnsupported(id);
68
- this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
69
87
  return {
70
88
  account,
71
- chain: { id, unsupported }
89
+ chain: { id, unsupported },
90
+ provider
72
91
  };
73
92
  } catch (error) {
74
- if (error.code === 4001) {
93
+ if (/user rejected/i.test(error?.message)) {
75
94
  throw new UserRejectedRequestError(error);
76
95
  }
77
- if (error.code === -32002) {
78
- throw error instanceof Error ? error : new Error(String(error));
79
- }
80
96
  throw error;
81
97
  }
82
98
  }
83
99
  async disconnect() {
84
100
  const provider = await this.getProvider();
85
- if (provider?.disconnect) {
86
- await provider.disconnect();
87
- }
88
- if (provider?.removeListener) {
89
- provider.removeListener("accountsChanged", this.onAccountsChanged);
90
- provider.removeListener("chainChanged", this.onChainChanged);
91
- provider.removeListener("disconnect", this.onDisconnect);
101
+ try {
102
+ if (provider?.disconnect)
103
+ await provider.disconnect();
104
+ } catch (error) {
105
+ if (!/No matching key/i.test(error.message))
106
+ throw error;
107
+ } finally {
108
+ __privateMethod(this, _removeListeners, removeListeners_fn).call(this);
109
+ __privateGet(this, _isV1) && typeof localStorage !== "undefined" && localStorage.removeItem("walletconnect");
92
110
  }
93
- typeof localStorage !== "undefined" && localStorage.removeItem("walletconnect");
94
111
  }
95
112
  async getAccount() {
96
113
  const provider = await this.getProvider();
@@ -110,26 +127,11 @@ var LedgerConnector = class extends Connector {
110
127
  async getProvider({ chainId, create } = {
111
128
  create: false
112
129
  }) {
113
- if (!__privateGet(this, _provider) || chainId || create) {
114
- const connectKit = await loadConnectKit();
115
- if (this.options.enableDebugLogs) {
116
- connectKit.enableDebugLogs();
117
- }
118
- const rpc = this.chains.reduce(
119
- (rpc2, chain) => ({
120
- ...rpc2,
121
- [chain.id]: chain.rpcUrls.default.http[0]
122
- }),
123
- {}
124
- );
125
- connectKit.checkSupport({
126
- bridge: this.options.bridge,
127
- providerType: SupportedProviders.Ethereum,
128
- chainId: chainId || this.options.chainId,
129
- rpc: { ...rpc, ...this.options?.rpc }
130
- });
131
- __privateSet(this, _provider, await connectKit.getProvider());
130
+ if (!__privateGet(this, _provider) || __privateGet(this, _isV1) && create) {
131
+ await __privateMethod(this, _createProvider, createProvider_fn).call(this);
132
132
  }
133
+ if (chainId)
134
+ await this.switchChain(chainId);
133
135
  return __privateGet(this, _provider);
134
136
  }
135
137
  async getWalletClient({ chainId } = {}) {
@@ -140,11 +142,7 @@ var LedgerConnector = class extends Connector {
140
142
  const chain = this.chains.find((x) => x.id === chainId);
141
143
  if (!provider)
142
144
  throw new Error("provider is required.");
143
- return createWalletClient({
144
- account,
145
- chain,
146
- transport: custom(provider)
147
- });
145
+ return createWalletClient({ account, chain, transport: custom(provider) });
148
146
  }
149
147
  async isAuthorized() {
150
148
  try {
@@ -154,38 +152,108 @@ var LedgerConnector = class extends Connector {
154
152
  return false;
155
153
  }
156
154
  }
155
+ async switchChain(chainId) {
156
+ const chain = this.chains.find((chain2) => chain2.id === chainId);
157
+ if (!chain)
158
+ throw new SwitchChainError(new Error("chain not found on connector."));
159
+ try {
160
+ const provider = await this.getProvider();
161
+ await provider.request({
162
+ method: "wallet_switchEthereumChain",
163
+ params: [{ chainId: numberToHex(chainId) }]
164
+ });
165
+ return chain;
166
+ } catch (error) {
167
+ const message = typeof error === "string" ? error : error?.message;
168
+ if (/user rejected request/i.test(message)) {
169
+ throw new UserRejectedRequestError(error);
170
+ }
171
+ throw new SwitchChainError(error);
172
+ }
173
+ }
157
174
  };
158
175
  _provider = new WeakMap();
159
- _switchChain = new WeakSet();
160
- switchChain_fn = async function(chainId) {
161
- const provider = await this.getProvider();
162
- const id = numberToHex(chainId);
163
- try {
164
- await Promise.race([
165
- provider.request({
166
- method: "wallet_switchEthereumChain",
167
- params: [{ chainId: id }]
168
- }),
169
- new Promise(
170
- (res) => this.on("change", ({ chain }) => {
171
- if (chain?.id === chainId)
172
- res(chainId);
173
- })
176
+ _initProviderPromise = new WeakMap();
177
+ _isV1 = new WeakMap();
178
+ _createProvider = new WeakSet();
179
+ createProvider_fn = async function() {
180
+ if (!__privateGet(this, _initProviderPromise) && typeof window !== "undefined") {
181
+ __privateSet(this, _initProviderPromise, __privateMethod(this, _initProvider, initProvider_fn).call(this));
182
+ }
183
+ return __privateGet(this, _initProviderPromise);
184
+ };
185
+ _initProvider = new WeakSet();
186
+ initProvider_fn = async function() {
187
+ const connectKit = await loadConnectKit();
188
+ if (this.options.enableDebugLogs) {
189
+ connectKit.enableDebugLogs();
190
+ }
191
+ let checkSupportOptions;
192
+ if (__privateGet(this, _isV1)) {
193
+ const { chainId, bridge } = this.options;
194
+ checkSupportOptions = {
195
+ providerType: SupportedProviders.Ethereum,
196
+ walletConnectVersion: 1,
197
+ chainId,
198
+ bridge,
199
+ rpc: Object.fromEntries(
200
+ this.chains.map((chain) => [
201
+ chain.id,
202
+ chain.rpcUrls.default.http[0]
203
+ ])
204
+ )
205
+ };
206
+ } else {
207
+ const {
208
+ projectId,
209
+ requiredChains,
210
+ requiredMethods,
211
+ optionalMethods,
212
+ requiredEvents,
213
+ optionalEvents
214
+ } = this.options;
215
+ const optionalChains = this.chains.map(({ id }) => id);
216
+ checkSupportOptions = {
217
+ providerType: SupportedProviders.Ethereum,
218
+ walletConnectVersion: 2,
219
+ projectId,
220
+ chains: requiredChains,
221
+ optionalChains,
222
+ methods: requiredMethods,
223
+ optionalMethods,
224
+ events: requiredEvents,
225
+ optionalEvents,
226
+ rpcMap: Object.fromEntries(
227
+ this.chains.map((chain) => [
228
+ chain.id,
229
+ chain.rpcUrls.default.http[0]
230
+ ])
174
231
  )
175
- ]);
176
- return this.chains.find((x) => x.id === chainId) ?? {
177
- id: chainId,
178
- name: `Chain ${id}`,
179
- network: `${id}`,
180
- nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
181
- rpcUrls: { default: { http: [""] }, public: { http: [""] } }
182
232
  };
183
- } catch (error) {
184
- const message = typeof error === "string" ? error : error?.message;
185
- if (/user rejected request/i.test(message))
186
- throw new UserRejectedRequestError(error);
187
- throw new SwitchChainError(error);
188
233
  }
234
+ connectKit.checkSupport(checkSupportOptions);
235
+ __privateSet(this, _provider, await connectKit.getProvider());
236
+ };
237
+ _setupListeners = new WeakSet();
238
+ setupListeners_fn = function() {
239
+ if (!__privateGet(this, _provider))
240
+ return;
241
+ __privateMethod(this, _removeListeners, removeListeners_fn).call(this);
242
+ __privateGet(this, _provider).on("accountsChanged", this.onAccountsChanged);
243
+ __privateGet(this, _provider).on("chainChanged", this.onChainChanged);
244
+ __privateGet(this, _provider).on("disconnect", this.onDisconnect);
245
+ __privateGet(this, _provider).on("session_delete", this.onDisconnect);
246
+ __privateGet(this, _provider).on("connect", this.onConnect);
247
+ };
248
+ _removeListeners = new WeakSet();
249
+ removeListeners_fn = function() {
250
+ if (!__privateGet(this, _provider))
251
+ return;
252
+ __privateGet(this, _provider).removeListener("accountsChanged", this.onAccountsChanged);
253
+ __privateGet(this, _provider).removeListener("chainChanged", this.onChainChanged);
254
+ __privateGet(this, _provider).removeListener("disconnect", this.onDisconnect);
255
+ __privateGet(this, _provider).removeListener("session_delete", this.onDisconnect);
256
+ __privateGet(this, _provider).removeListener("connect", this.onConnect);
189
257
  };
190
258
  export {
191
259
  LedgerConnector
@@ -1,6 +1,6 @@
1
1
  import { Chain } from '@wagmi/chains';
2
2
  import { InjectedConnectorOptions, InjectedConnector } from './injected.js';
3
- import { W as WindowProvider } from './base-0473abd3.js';
3
+ import { W as WindowProvider } from './base-2dd7facf.js';
4
4
  import 'viem';
5
5
  import 'eventemitter3';
6
6
 
package/dist/metaMask.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InjectedConnector
3
- } from "./chunk-4BSCIAHY.js";
3
+ } from "./chunk-Z2P63ELM.js";
4
4
  import {
5
5
  ConnectorNotFoundError
6
6
  } from "./chunk-ZCAPXGBX.js";
@@ -1,6 +1,6 @@
1
1
  import * as viem from 'viem';
2
2
  import { Chain } from '@wagmi/chains';
3
- import { c as WalletClient, C as Connector, a as ConnectorData } from '../base-0473abd3.js';
3
+ import { c as WalletClient, C as Connector, a as ConnectorData } from '../base-2dd7facf.js';
4
4
  import EventEmitter from 'eventemitter3';
5
5
 
6
6
  type MockProviderOptions = {
package/dist/safe.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as viem from 'viem';
2
2
  import { SafeAppProvider } from '@safe-global/safe-apps-provider';
3
3
  import { Opts } from '@safe-global/safe-apps-sdk';
4
4
  import { Chain } from '@wagmi/chains';
5
- import { C as Connector } from './base-0473abd3.js';
5
+ import { C as Connector } from './base-2dd7facf.js';
6
6
  import 'eventemitter3';
7
7
 
8
8
  type SafeConnectorProvider = SafeAppProvider;
@@ -2,7 +2,7 @@ import * as viem from 'viem';
2
2
  import { Chain } from '@wagmi/chains';
3
3
  import WalletConnectProvider from '@walletconnect/ethereum-provider';
4
4
  import { EthereumProviderOptions } from '@walletconnect/ethereum-provider/dist/types/EthereumProvider';
5
- import { C as Connector } from './base-0473abd3.js';
5
+ import { C as Connector } from './base-2dd7facf.js';
6
6
  import 'eventemitter3';
7
7
 
8
8
  type WalletConnectOptions = {
@@ -1,7 +1,7 @@
1
1
  import * as viem from 'viem';
2
2
  import { Chain } from '@wagmi/chains';
3
3
  import WalletConnectProvider from '@walletconnect/legacy-provider';
4
- import { C as Connector } from './base-0473abd3.js';
4
+ import { C as Connector } from './base-2dd7facf.js';
5
5
  import 'eventemitter3';
6
6
 
7
7
  type WalletConnectOptions = ConstructorParameters<typeof WalletConnectProvider>[0];
package/package.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "name": "@wagmi/connectors",
3
3
  "description": "A collection of connectors for wagmi",
4
4
  "license": "MIT",
5
- "version": "2.3.0",
5
+ "version": "2.4.0",
6
6
  "peerDependencies": {
7
- "@wagmi/chains": ">=1.2.0",
7
+ "@wagmi/chains": ">=1.3.0",
8
8
  "typescript": ">=5.0.4",
9
9
  "viem": ">=0.3.35"
10
10
  },
@@ -18,18 +18,18 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@coinbase/wallet-sdk": "^3.6.6",
21
- "@ledgerhq/connect-kit-loader": "^1.0.1",
21
+ "@ledgerhq/connect-kit-loader": "^1.1.0",
22
+ "@safe-global/safe-apps-provider": "^0.15.2",
23
+ "@safe-global/safe-apps-sdk": "^7.9.0",
22
24
  "@walletconnect/ethereum-provider": "2.8.1",
23
25
  "@walletconnect/legacy-provider": "^2.0.0",
24
26
  "@walletconnect/modal": "^2.4.6",
25
- "@safe-global/safe-apps-provider": "^0.15.2",
26
- "@safe-global/safe-apps-sdk": "^7.9.0",
27
27
  "abitype": "0.8.7",
28
28
  "eventemitter3": "^4.0.7"
29
29
  },
30
30
  "devDependencies": {
31
31
  "viem": "^1.0.0",
32
- "@wagmi/chains": "1.2.0"
32
+ "@wagmi/chains": "1.3.0"
33
33
  },
34
34
  "type": "module",
35
35
  "main": "dist/index.js",