@wagmi/connectors 3.1.1-cjs → 4.0.0-alpha.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 (73) hide show
  1. package/dist/esm/coinbaseWallet.js +141 -0
  2. package/dist/esm/coinbaseWallet.js.map +1 -0
  3. package/dist/esm/index.js +7 -0
  4. package/dist/esm/index.js.map +1 -0
  5. package/dist/esm/index.test-d.js +4 -0
  6. package/dist/esm/index.test-d.js.map +1 -0
  7. package/dist/esm/injected.js +372 -0
  8. package/dist/esm/injected.js.map +1 -0
  9. package/dist/esm/ledger.js +162 -0
  10. package/dist/esm/ledger.js.map +1 -0
  11. package/dist/esm/safe.js +88 -0
  12. package/dist/esm/safe.js.map +1 -0
  13. package/dist/esm/tsconfig.build.tsbuildinfo +1 -0
  14. package/dist/esm/version.js +2 -0
  15. package/dist/esm/version.js.map +1 -0
  16. package/dist/esm/walletConnect.js +280 -0
  17. package/dist/esm/walletConnect.js.map +1 -0
  18. package/dist/types/coinbaseWallet.d.ts +21 -0
  19. package/dist/types/coinbaseWallet.d.ts.map +1 -0
  20. package/dist/types/index.d.ts +7 -0
  21. package/dist/types/index.d.ts.map +1 -0
  22. package/dist/types/index.test-d.d.ts +2 -0
  23. package/dist/types/index.test-d.d.ts.map +1 -0
  24. package/dist/types/injected.d.ts +382 -0
  25. package/dist/types/injected.d.ts.map +1 -0
  26. package/dist/types/ledger.d.ts +18 -0
  27. package/dist/types/ledger.d.ts.map +1 -0
  28. package/dist/types/safe.d.ts +18 -0
  29. package/dist/types/safe.d.ts.map +1 -0
  30. package/dist/types/version.d.ts +2 -0
  31. package/dist/types/version.d.ts.map +1 -0
  32. package/dist/types/walletConnect.d.ts +63 -0
  33. package/dist/types/walletConnect.d.ts.map +1 -0
  34. package/package.json +44 -82
  35. package/src/coinbaseWallet.ts +207 -0
  36. package/src/index.ts +17 -0
  37. package/src/injected.ts +535 -0
  38. package/src/ledger.ts +210 -0
  39. package/src/safe.ts +114 -0
  40. package/src/version.ts +1 -0
  41. package/src/walletConnect.ts +394 -0
  42. package/README.md +0 -46
  43. package/coinbaseWallet/package.json +0 -4
  44. package/dist/base-70e3a8a9.d.ts +0 -142
  45. package/dist/chunk-2UFLHRLT.js +0 -391
  46. package/dist/chunk-OQILYQDO.js +0 -15
  47. package/dist/chunk-UGBGYVBH.js +0 -22
  48. package/dist/chunk-W65LBPLT.js +0 -58
  49. package/dist/coinbaseWallet.d.ts +0 -62
  50. package/dist/coinbaseWallet.js +0 -216
  51. package/dist/index.d.ts +0 -20
  52. package/dist/index.js +0 -16
  53. package/dist/injected.d.ts +0 -64
  54. package/dist/injected.js +0 -9
  55. package/dist/ledger.d.ts +0 -69
  56. package/dist/ledger.js +0 -261
  57. package/dist/metaMask.d.ts +0 -33
  58. package/dist/metaMask.js +0 -144
  59. package/dist/mock/index.d.ts +0 -80
  60. package/dist/mock/index.js +0 -200
  61. package/dist/safe.d.ts +0 -53
  62. package/dist/safe.js +0 -129
  63. package/dist/walletConnect.d.ts +0 -109
  64. package/dist/walletConnect.js +0 -325
  65. package/dist/walletConnectLegacy.d.ts +0 -38
  66. package/dist/walletConnectLegacy.js +0 -179
  67. package/injected/package.json +0 -4
  68. package/ledger/package.json +0 -4
  69. package/metaMask/package.json +0 -4
  70. package/mock/package.json +0 -4
  71. package/safe/package.json +0 -4
  72. package/walletConnect/package.json +0 -4
  73. package/walletConnectLegacy/package.json +0 -4
@@ -1,109 +0,0 @@
1
- import WalletConnectProvider from '@walletconnect/ethereum-provider';
2
- import { EthereumProviderOptions } from '@walletconnect/ethereum-provider/dist/types/EthereumProvider';
3
- import { Chain } from 'viem/chains';
4
- import { C as Connector, c as WalletClient } from './base-70e3a8a9.js';
5
- import 'eventemitter3';
6
- import 'viem';
7
-
8
- type WalletConnectOptions = {
9
- /**
10
- * WalletConnect Cloud Project ID.
11
- * @link https://cloud.walletconnect.com/sign-in.
12
- */
13
- projectId: EthereumProviderOptions['projectId'];
14
- /**
15
- * If a new chain is added to a previously existing configured connector `chains`, this flag
16
- * will determine if that chain should be considered as stale. A stale chain is a chain that
17
- * WalletConnect has yet to establish a relationship with (ie. the user has not approved or
18
- * rejected the chain).
19
- *
20
- * Preface: Whereas WalletConnect v1 supported dynamic chain switching, WalletConnect v2 requires
21
- * the user to pre-approve a set of chains up-front. This comes with consequent UX nuances (see below) when
22
- * a user tries to switch to a chain that they have not approved.
23
- *
24
- * This flag mainly affects the behavior when a wallet does not support dynamic chain authorization
25
- * with WalletConnect v2.
26
- *
27
- * If `true` (default), the new chain will be treated as a stale chain. If the user
28
- * has yet to establish a relationship (approved/rejected) with this chain in their WalletConnect
29
- * session, the connector will disconnect upon the dapp auto-connecting, and the user will have to
30
- * reconnect to the dapp (revalidate the chain) in order to approve the newly added chain.
31
- * This is the default behavior to avoid an unexpected error upon switching chains which may
32
- * be a confusing user experience (ie. the user will not know they have to reconnect
33
- * unless the dapp handles these types of errors).
34
- *
35
- * If `false`, the new chain will be treated as a validated chain. This means that if the user
36
- * has yet to establish a relationship with the chain in their WalletConnect session, wagmi will successfully
37
- * auto-connect the user. This comes with the trade-off that the connector will throw an error
38
- * when attempting to switch to the unapproved chain. This may be useful in cases where a dapp constantly
39
- * modifies their configured chains, and they do not want to disconnect the user upon
40
- * auto-connecting. If the user decides to switch to the unapproved chain, it is important that the
41
- * dapp handles this error and prompts the user to reconnect to the dapp in order to approve
42
- * the newly added chain.
43
- *
44
- * @default true
45
- */
46
- isNewChainsStale?: boolean;
47
- /**
48
- * Metadata for your app.
49
- * @link https://docs.walletconnect.com/2.0/javascript/providers/ethereum#initialization
50
- */
51
- metadata?: EthereumProviderOptions['metadata'];
52
- /**
53
- * Whether or not to show the QR code modal.
54
- * @default true
55
- * @link https://docs.walletconnect.com/2.0/javascript/providers/ethereum#initialization
56
- */
57
- showQrModal?: EthereumProviderOptions['showQrModal'];
58
- /**
59
- * Options of QR code modal.
60
- * @link https://docs.walletconnect.com/2.0/web/walletConnectModal/modal/options
61
- */
62
- qrModalOptions?: EthereumProviderOptions['qrModalOptions'];
63
- /**
64
- * Option to override default relay url.
65
- * @link https://docs.walletconnect.com/2.0/web/providers/ethereum
66
- */
67
- relayUrl?: string;
68
- };
69
- type ConnectConfig = {
70
- /** Target chain to connect to. */
71
- chainId?: number;
72
- /** If provided, will attempt to connect to an existing pairing. */
73
- pairingTopic?: string;
74
- };
75
- declare class WalletConnectConnector extends Connector<WalletConnectProvider, WalletConnectOptions> {
76
- #private;
77
- readonly id = "walletConnect";
78
- readonly name = "WalletConnect";
79
- readonly ready = true;
80
- constructor(config: {
81
- chains?: Chain[];
82
- options: WalletConnectOptions;
83
- });
84
- connect({ chainId, pairingTopic }?: ConnectConfig): Promise<{
85
- account: `0x${string}`;
86
- chain: {
87
- id: number;
88
- unsupported: boolean;
89
- };
90
- }>;
91
- disconnect(): Promise<void>;
92
- getAccount(): Promise<`0x${string}`>;
93
- getChainId(): Promise<number>;
94
- getProvider({ chainId }?: {
95
- chainId?: number;
96
- }): Promise<WalletConnectProvider>;
97
- getWalletClient({ chainId, }?: {
98
- chainId?: number;
99
- }): Promise<WalletClient>;
100
- isAuthorized(): Promise<boolean>;
101
- switchChain(chainId: number): Promise<Chain>;
102
- protected onAccountsChanged: (accounts: string[]) => void;
103
- protected onChainChanged: (chainId: number | string) => void;
104
- protected onDisconnect: () => void;
105
- protected onDisplayUri: (uri: string) => void;
106
- protected onConnect: () => void;
107
- }
108
-
109
- export { WalletConnectConnector };
@@ -1,325 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
-
4
-
5
-
6
-
7
- var _chunkW65LBPLTjs = require('./chunk-W65LBPLT.js');
8
-
9
- // src/walletConnect.ts
10
- var _utils = require('@walletconnect/utils');
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
- var _viem = require('viem');
19
- var NAMESPACE = "eip155";
20
- var STORE_KEY = "store";
21
- var REQUESTED_CHAINS_KEY = "requestedChains";
22
- var ADD_ETH_CHAIN_METHOD = "wallet_addEthereumChain";
23
- var _provider, _initProviderPromise, _createProvider, createProvider_fn, _initProvider, initProvider_fn, _isChainsStale, isChainsStale_fn, _setupListeners, setupListeners_fn, _removeListeners, removeListeners_fn, _setRequestedChainsIds, setRequestedChainsIds_fn, _getRequestedChainsIds, getRequestedChainsIds_fn, _getNamespaceChainsIds, getNamespaceChainsIds_fn, _getNamespaceMethods, getNamespaceMethods_fn;
24
- var WalletConnectConnector = class extends _chunkW65LBPLTjs.Connector {
25
- constructor(config) {
26
- super({
27
- ...config,
28
- options: { isNewChainsStale: true, ...config.options }
29
- });
30
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _createProvider);
31
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _initProvider);
32
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _isChainsStale);
33
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _setupListeners);
34
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _removeListeners);
35
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _setRequestedChainsIds);
36
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _getRequestedChainsIds);
37
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _getNamespaceChainsIds);
38
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _getNamespaceMethods);
39
- this.id = "walletConnect";
40
- this.name = "WalletConnect";
41
- this.ready = true;
42
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _provider, void 0);
43
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _initProviderPromise, void 0);
44
- this.onAccountsChanged = (accounts) => {
45
- if (accounts.length === 0)
46
- this.emit("disconnect");
47
- else
48
- this.emit("change", { account: _viem.getAddress.call(void 0, accounts[0]) });
49
- };
50
- this.onChainChanged = (chainId) => {
51
- const id = Number(chainId);
52
- const unsupported = this.isChainUnsupported(id);
53
- this.emit("change", { chain: { id, unsupported } });
54
- };
55
- this.onDisconnect = () => {
56
- _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, []);
57
- this.emit("disconnect");
58
- };
59
- this.onDisplayUri = (uri) => {
60
- this.emit("message", { type: "display_uri", data: uri });
61
- };
62
- this.onConnect = () => {
63
- this.emit("connect", {});
64
- };
65
- _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _createProvider, createProvider_fn).call(this);
66
- }
67
- async connect({ chainId, pairingTopic } = {}) {
68
- try {
69
- let targetChainId = chainId;
70
- if (!targetChainId) {
71
- const store = _optionalChain([this, 'access', _ => _.storage, 'optionalAccess', _2 => _2.getItem, 'call', _3 => _3(STORE_KEY)]);
72
- const lastUsedChainId = _optionalChain([store, 'optionalAccess', _4 => _4.state, 'optionalAccess', _5 => _5.data, 'optionalAccess', _6 => _6.chain, 'optionalAccess', _7 => _7.id]);
73
- if (lastUsedChainId && !this.isChainUnsupported(lastUsedChainId))
74
- targetChainId = lastUsedChainId;
75
- else
76
- targetChainId = _optionalChain([this, 'access', _8 => _8.chains, 'access', _9 => _9[0], 'optionalAccess', _10 => _10.id]);
77
- }
78
- if (!targetChainId)
79
- throw new Error("No chains found on connector.");
80
- const provider = await this.getProvider();
81
- _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _setupListeners, setupListeners_fn).call(this);
82
- const isChainsStale = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _isChainsStale, isChainsStale_fn).call(this);
83
- if (provider.session && isChainsStale)
84
- await provider.disconnect();
85
- if (!provider.session || isChainsStale) {
86
- const optionalChains = this.chains.filter((chain) => chain.id !== targetChainId).map((optionalChain) => optionalChain.id);
87
- this.emit("message", { type: "connecting" });
88
- await provider.connect({
89
- pairingTopic,
90
- chains: [targetChainId],
91
- optionalChains: optionalChains.length ? optionalChains : void 0
92
- });
93
- _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, this.chains.map(({ id: id2 }) => id2));
94
- }
95
- const accounts = await provider.enable();
96
- const account = _viem.getAddress.call(void 0, accounts[0]);
97
- const id = await this.getChainId();
98
- const unsupported = this.isChainUnsupported(id);
99
- return {
100
- account,
101
- chain: { id, unsupported }
102
- };
103
- } catch (error) {
104
- if (/user rejected/i.test(_optionalChain([error, 'optionalAccess', _11 => _11.message]))) {
105
- throw new (0, _viem.UserRejectedRequestError)(error);
106
- }
107
- throw error;
108
- }
109
- }
110
- async disconnect() {
111
- const provider = await this.getProvider();
112
- try {
113
- await provider.disconnect();
114
- } catch (error) {
115
- if (!/No matching key/i.test(error.message))
116
- throw error;
117
- } finally {
118
- _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _removeListeners, removeListeners_fn).call(this);
119
- _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, []);
120
- }
121
- }
122
- async getAccount() {
123
- const { accounts } = await this.getProvider();
124
- return _viem.getAddress.call(void 0, accounts[0]);
125
- }
126
- async getChainId() {
127
- const { chainId } = await this.getProvider();
128
- return chainId;
129
- }
130
- async getProvider({ chainId } = {}) {
131
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider))
132
- await _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _createProvider, createProvider_fn).call(this);
133
- if (chainId)
134
- await this.switchChain(chainId);
135
- return _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider);
136
- }
137
- async getWalletClient({
138
- chainId
139
- } = {}) {
140
- const [provider, account] = await Promise.all([
141
- this.getProvider({ chainId }),
142
- this.getAccount()
143
- ]);
144
- const chain = this.chains.find((x) => x.id === chainId);
145
- if (!provider)
146
- throw new Error("provider is required.");
147
- return _viem.createWalletClient.call(void 0, {
148
- account,
149
- chain,
150
- transport: _viem.custom.call(void 0, provider)
151
- });
152
- }
153
- async isAuthorized() {
154
- try {
155
- const [account, provider] = await Promise.all([
156
- this.getAccount(),
157
- this.getProvider()
158
- ]);
159
- const isChainsStale = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _isChainsStale, isChainsStale_fn).call(this);
160
- if (!account)
161
- return false;
162
- if (isChainsStale && provider.session) {
163
- try {
164
- await provider.disconnect();
165
- } catch (e) {
166
- }
167
- return false;
168
- }
169
- return true;
170
- } catch (e2) {
171
- return false;
172
- }
173
- }
174
- async switchChain(chainId) {
175
- const chain = this.chains.find((chain2) => chain2.id === chainId);
176
- if (!chain)
177
- throw new (0, _viem.SwitchChainError)(new Error("chain not found on connector."));
178
- try {
179
- const provider = await this.getProvider();
180
- const namespaceChains = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
181
- const namespaceMethods = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _getNamespaceMethods, getNamespaceMethods_fn).call(this);
182
- const isChainApproved = namespaceChains.includes(chainId);
183
- if (!isChainApproved && namespaceMethods.includes(ADD_ETH_CHAIN_METHOD)) {
184
- await provider.request({
185
- method: ADD_ETH_CHAIN_METHOD,
186
- params: [
187
- {
188
- chainId: _viem.numberToHex.call(void 0, chain.id),
189
- blockExplorerUrls: [_optionalChain([chain, 'access', _12 => _12.blockExplorers, 'optionalAccess', _13 => _13.default, 'optionalAccess', _14 => _14.url])],
190
- chainName: chain.name,
191
- nativeCurrency: chain.nativeCurrency,
192
- rpcUrls: [...chain.rpcUrls.default.http]
193
- }
194
- ]
195
- });
196
- const requestedChains = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
197
- requestedChains.push(chainId);
198
- _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _setRequestedChainsIds, setRequestedChainsIds_fn).call(this, requestedChains);
199
- }
200
- await provider.request({
201
- method: "wallet_switchEthereumChain",
202
- params: [{ chainId: _viem.numberToHex.call(void 0, chainId) }]
203
- });
204
- return chain;
205
- } catch (error) {
206
- const message = typeof error === "string" ? error : _optionalChain([error, 'optionalAccess', _15 => _15.message]);
207
- if (/user rejected request/i.test(message)) {
208
- throw new (0, _viem.UserRejectedRequestError)(error);
209
- }
210
- throw new (0, _viem.SwitchChainError)(error);
211
- }
212
- }
213
- };
214
- _provider = new WeakMap();
215
- _initProviderPromise = new WeakMap();
216
- _createProvider = new WeakSet();
217
- createProvider_fn = async function() {
218
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _initProviderPromise) && typeof window !== "undefined") {
219
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _initProviderPromise, _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _initProvider, initProvider_fn).call(this));
220
- }
221
- return _chunkW65LBPLTjs.__privateGet.call(void 0, this, _initProviderPromise);
222
- };
223
- _initProvider = new WeakSet();
224
- initProvider_fn = async function() {
225
- const { EthereumProvider, OPTIONAL_EVENTS, OPTIONAL_METHODS } = await Promise.resolve().then(() => _interopRequireWildcard(require("@walletconnect/ethereum-provider")));
226
- const [defaultChain, ...optionalChains] = this.chains.map(({ id }) => id);
227
- if (defaultChain) {
228
- const {
229
- projectId,
230
- showQrModal = true,
231
- qrModalOptions,
232
- metadata,
233
- relayUrl
234
- } = this.options;
235
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _provider, await EthereumProvider.init({
236
- showQrModal,
237
- qrModalOptions,
238
- projectId,
239
- optionalMethods: OPTIONAL_METHODS,
240
- optionalEvents: OPTIONAL_EVENTS,
241
- chains: [defaultChain],
242
- optionalChains: optionalChains.length ? optionalChains : void 0,
243
- rpcMap: Object.fromEntries(
244
- this.chains.map((chain) => [
245
- chain.id,
246
- chain.rpcUrls.default.http[0]
247
- ])
248
- ),
249
- metadata,
250
- relayUrl
251
- }));
252
- }
253
- };
254
- _isChainsStale = new WeakSet();
255
- isChainsStale_fn = function() {
256
- const namespaceMethods = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _getNamespaceMethods, getNamespaceMethods_fn).call(this);
257
- if (namespaceMethods.includes(ADD_ETH_CHAIN_METHOD))
258
- return false;
259
- if (!this.options.isNewChainsStale)
260
- return false;
261
- const requestedChains = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _getRequestedChainsIds, getRequestedChainsIds_fn).call(this);
262
- const connectorChains = this.chains.map(({ id }) => id);
263
- const namespaceChains = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _getNamespaceChainsIds, getNamespaceChainsIds_fn).call(this);
264
- if (namespaceChains.length && !namespaceChains.some((id) => connectorChains.includes(id)))
265
- return false;
266
- return !connectorChains.every((id) => requestedChains.includes(id));
267
- };
268
- _setupListeners = new WeakSet();
269
- setupListeners_fn = function() {
270
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider))
271
- return;
272
- _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _removeListeners, removeListeners_fn).call(this);
273
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("accountsChanged", this.onAccountsChanged);
274
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("chainChanged", this.onChainChanged);
275
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("disconnect", this.onDisconnect);
276
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("session_delete", this.onDisconnect);
277
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("display_uri", this.onDisplayUri);
278
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).on("connect", this.onConnect);
279
- };
280
- _removeListeners = new WeakSet();
281
- removeListeners_fn = function() {
282
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider))
283
- return;
284
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("accountsChanged", this.onAccountsChanged);
285
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("chainChanged", this.onChainChanged);
286
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("disconnect", this.onDisconnect);
287
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("session_delete", this.onDisconnect);
288
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("display_uri", this.onDisplayUri);
289
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).removeListener("connect", this.onConnect);
290
- };
291
- _setRequestedChainsIds = new WeakSet();
292
- setRequestedChainsIds_fn = function(chains) {
293
- _optionalChain([this, 'access', _16 => _16.storage, 'optionalAccess', _17 => _17.setItem, 'call', _18 => _18(REQUESTED_CHAINS_KEY, chains)]);
294
- };
295
- _getRequestedChainsIds = new WeakSet();
296
- getRequestedChainsIds_fn = function() {
297
- return _nullishCoalesce(_optionalChain([this, 'access', _19 => _19.storage, 'optionalAccess', _20 => _20.getItem, 'call', _21 => _21(REQUESTED_CHAINS_KEY)]), () => ( []));
298
- };
299
- _getNamespaceChainsIds = new WeakSet();
300
- getNamespaceChainsIds_fn = function() {
301
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider))
302
- return [];
303
- const namespaces = _optionalChain([_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider), 'access', _22 => _22.session, 'optionalAccess', _23 => _23.namespaces]);
304
- if (!namespaces)
305
- return [];
306
- const normalizedNamespaces = _utils.normalizeNamespaces.call(void 0, namespaces);
307
- const chainIds = _optionalChain([normalizedNamespaces, 'access', _24 => _24[NAMESPACE], 'optionalAccess', _25 => _25.chains, 'optionalAccess', _26 => _26.map, 'call', _27 => _27(
308
- (chain) => parseInt(chain.split(":")[1] || "")
309
- )]);
310
- return _nullishCoalesce(chainIds, () => ( []));
311
- };
312
- _getNamespaceMethods = new WeakSet();
313
- getNamespaceMethods_fn = function() {
314
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider))
315
- return [];
316
- const namespaces = _optionalChain([_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider), 'access', _28 => _28.session, 'optionalAccess', _29 => _29.namespaces]);
317
- if (!namespaces)
318
- return [];
319
- const normalizedNamespaces = _utils.normalizeNamespaces.call(void 0, namespaces);
320
- const methods = _optionalChain([normalizedNamespaces, 'access', _30 => _30[NAMESPACE], 'optionalAccess', _31 => _31.methods]);
321
- return _nullishCoalesce(methods, () => ( []));
322
- };
323
-
324
-
325
- exports.WalletConnectConnector = WalletConnectConnector;
@@ -1,38 +0,0 @@
1
- import WalletConnectProvider from '@walletconnect/legacy-provider';
2
- import { C as Connector, c as WalletClient } from './base-70e3a8a9.js';
3
- import 'eventemitter3';
4
- import 'viem';
5
- import 'viem/chains';
6
-
7
- type WalletConnectOptions = ConstructorParameters<typeof WalletConnectProvider>[0];
8
- declare class WalletConnectLegacyConnector extends Connector<WalletConnectProvider, WalletConnectOptions> {
9
- #private;
10
- readonly id = "walletConnectLegacy";
11
- readonly name = "WalletConnectLegacy";
12
- readonly ready = true;
13
- connect({ chainId }?: {
14
- chainId?: number;
15
- }): Promise<{
16
- account: `0x${string}`;
17
- chain: {
18
- id: number;
19
- unsupported: boolean;
20
- };
21
- }>;
22
- disconnect(): Promise<void>;
23
- getAccount(): Promise<`0x${string}`>;
24
- getChainId(): Promise<number>;
25
- getProvider({ chainId, create, }?: {
26
- chainId?: number;
27
- create?: boolean;
28
- }): Promise<WalletConnectProvider>;
29
- getWalletClient({ chainId, }?: {
30
- chainId?: number;
31
- }): Promise<WalletClient>;
32
- isAuthorized(): Promise<boolean>;
33
- protected onAccountsChanged: (accounts: string[]) => void;
34
- protected onChainChanged: (chainId: number | string) => void;
35
- protected onDisconnect: () => void;
36
- }
37
-
38
- export { WalletConnectLegacyConnector };
@@ -1,179 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
- var _chunkOQILYQDOjs = require('./chunk-OQILYQDO.js');
4
-
5
-
6
-
7
-
8
-
9
-
10
- var _chunkW65LBPLTjs = require('./chunk-W65LBPLT.js');
11
-
12
- // src/walletConnectLegacy.ts
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
- var _viem = require('viem');
21
- var switchChainAllowedRegex = /(imtoken|metamask|rainbow|trust wallet|uniswap wallet|ledger)/i;
22
- var _provider, _switchChain, switchChain_fn;
23
- var WalletConnectLegacyConnector = class extends _chunkW65LBPLTjs.Connector {
24
- constructor() {
25
- super(...arguments);
26
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _switchChain);
27
- this.id = "walletConnectLegacy";
28
- this.name = "WalletConnectLegacy";
29
- this.ready = true;
30
- _chunkW65LBPLTjs.__privateAdd.call(void 0, this, _provider, void 0);
31
- this.onAccountsChanged = (accounts) => {
32
- if (accounts.length === 0)
33
- this.emit("disconnect");
34
- else
35
- this.emit("change", { account: _viem.getAddress.call(void 0, accounts[0]) });
36
- };
37
- this.onChainChanged = (chainId) => {
38
- const id = _chunkOQILYQDOjs.normalizeChainId.call(void 0, chainId);
39
- const unsupported = this.isChainUnsupported(id);
40
- this.emit("change", { chain: { id, unsupported } });
41
- };
42
- this.onDisconnect = () => {
43
- this.emit("disconnect");
44
- };
45
- }
46
- async connect({ chainId } = {}) {
47
- try {
48
- let targetChainId = chainId;
49
- if (!targetChainId) {
50
- const store = _optionalChain([this, 'access', _ => _.storage, 'optionalAccess', _2 => _2.getItem, 'call', _3 => _3("store")]);
51
- const lastUsedChainId = _optionalChain([store, 'optionalAccess', _4 => _4.state, 'optionalAccess', _5 => _5.data, 'optionalAccess', _6 => _6.chain, 'optionalAccess', _7 => _7.id]);
52
- if (lastUsedChainId && !this.isChainUnsupported(lastUsedChainId))
53
- targetChainId = lastUsedChainId;
54
- }
55
- const provider = await this.getProvider({
56
- chainId: targetChainId,
57
- create: true
58
- });
59
- provider.on("accountsChanged", this.onAccountsChanged);
60
- provider.on("chainChanged", this.onChainChanged);
61
- provider.on("disconnect", this.onDisconnect);
62
- setTimeout(() => this.emit("message", { type: "connecting" }), 0);
63
- const accounts = await provider.enable();
64
- const account = _viem.getAddress.call(void 0, accounts[0]);
65
- const id = await this.getChainId();
66
- const unsupported = this.isChainUnsupported(id);
67
- const walletName = _nullishCoalesce(_optionalChain([provider, 'access', _8 => _8.connector, 'optionalAccess', _9 => _9.peerMeta, 'optionalAccess', _10 => _10.name]), () => ( ""));
68
- if (switchChainAllowedRegex.test(walletName))
69
- this.switchChain = _chunkW65LBPLTjs.__privateMethod.call(void 0, this, _switchChain, switchChain_fn);
70
- return {
71
- account,
72
- chain: { id, unsupported }
73
- };
74
- } catch (error) {
75
- if (/user closed modal/i.test(error.message))
76
- throw new (0, _viem.UserRejectedRequestError)(error);
77
- throw error;
78
- }
79
- }
80
- async disconnect() {
81
- const provider = await this.getProvider();
82
- await provider.disconnect();
83
- provider.removeListener("accountsChanged", this.onAccountsChanged);
84
- provider.removeListener("chainChanged", this.onChainChanged);
85
- provider.removeListener("disconnect", this.onDisconnect);
86
- typeof localStorage !== "undefined" && localStorage.removeItem("walletconnect");
87
- }
88
- async getAccount() {
89
- const provider = await this.getProvider();
90
- const accounts = provider.accounts;
91
- return _viem.getAddress.call(void 0, accounts[0]);
92
- }
93
- async getChainId() {
94
- const provider = await this.getProvider();
95
- const chainId = _chunkOQILYQDOjs.normalizeChainId.call(void 0, provider.chainId);
96
- return chainId;
97
- }
98
- async getProvider({
99
- chainId,
100
- create
101
- } = {}) {
102
- if (!_chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider) || chainId || create) {
103
- const rpc = !_optionalChain([this, 'access', _11 => _11.options, 'optionalAccess', _12 => _12.infuraId]) ? this.chains.reduce(
104
- (rpc2, chain) => ({
105
- ...rpc2,
106
- [chain.id]: chain.rpcUrls.default.http[0]
107
- }),
108
- {}
109
- ) : {};
110
- const WalletConnectProvider = (await Promise.resolve().then(() => _interopRequireWildcard(require("@walletconnect/legacy-provider")))).default;
111
- _chunkW65LBPLTjs.__privateSet.call(void 0, this, _provider, new WalletConnectProvider({
112
- ...this.options,
113
- chainId,
114
- rpc: { ...rpc, ..._optionalChain([this, 'access', _13 => _13.options, 'optionalAccess', _14 => _14.rpc]) }
115
- }));
116
- _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).http = await _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider).setHttpProvider(chainId);
117
- }
118
- return _chunkW65LBPLTjs.__privateGet.call(void 0, this, _provider);
119
- }
120
- async getWalletClient({
121
- chainId
122
- } = {}) {
123
- const [provider, account] = await Promise.all([
124
- this.getProvider({ chainId }),
125
- this.getAccount()
126
- ]);
127
- const chain = this.chains.find((x) => x.id === chainId);
128
- if (!provider)
129
- throw new Error("provider is required.");
130
- return _viem.createWalletClient.call(void 0, {
131
- account,
132
- chain,
133
- transport: _viem.custom.call(void 0, provider)
134
- });
135
- }
136
- async isAuthorized() {
137
- try {
138
- const account = await this.getAccount();
139
- return !!account;
140
- } catch (e) {
141
- return false;
142
- }
143
- }
144
- };
145
- _provider = new WeakMap();
146
- _switchChain = new WeakSet();
147
- switchChain_fn = async function(chainId) {
148
- const provider = await this.getProvider();
149
- const id = _viem.numberToHex.call(void 0, chainId);
150
- try {
151
- await Promise.race([
152
- provider.request({
153
- method: "wallet_switchEthereumChain",
154
- params: [{ chainId: id }]
155
- }),
156
- new Promise(
157
- (res) => this.on("change", ({ chain }) => {
158
- if (_optionalChain([chain, 'optionalAccess', _15 => _15.id]) === chainId)
159
- res(chainId);
160
- })
161
- )
162
- ]);
163
- return _nullishCoalesce(this.chains.find((x) => x.id === chainId), () => ( {
164
- id: chainId,
165
- name: `Chain ${id}`,
166
- network: `${id}`,
167
- nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
168
- rpcUrls: { default: { http: [""] }, public: { http: [""] } }
169
- }));
170
- } catch (error) {
171
- const message = typeof error === "string" ? error : _optionalChain([error, 'optionalAccess', _16 => _16.message]);
172
- if (/user rejected request/i.test(message))
173
- throw new (0, _viem.UserRejectedRequestError)(error);
174
- throw new (0, _viem.SwitchChainError)(error);
175
- }
176
- };
177
-
178
-
179
- exports.WalletConnectLegacyConnector = WalletConnectLegacyConnector;
@@ -1,4 +0,0 @@
1
- {
2
- "type": "module",
3
- "main": "../dist/injected.js"
4
- }
@@ -1,4 +0,0 @@
1
- {
2
- "type": "module",
3
- "main": "../dist/ledger.js"
4
- }
@@ -1,4 +0,0 @@
1
- {
2
- "type": "module",
3
- "main": "../dist/metaMask.js"
4
- }
package/mock/package.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "type": "module",
3
- "main": "../dist/mock/index.js"
4
- }