@dynamic-labs/ethereum 2.0.0-alpha.3 → 2.0.0-alpha.30

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 (48) hide show
  1. package/CHANGELOG.md +394 -0
  2. package/package.json +11 -12
  3. package/src/EthWalletConnector.cjs +1 -20
  4. package/src/EthWalletConnector.d.ts +9 -10
  5. package/src/EthWalletConnector.js +3 -22
  6. package/src/coinbase/client/client.cjs +14 -14
  7. package/src/coinbase/client/client.d.ts +5 -4
  8. package/src/coinbase/client/client.js +13 -13
  9. package/src/coinbase/client/types.d.ts +6 -3
  10. package/src/coinbase/coinbase.cjs +30 -14
  11. package/src/coinbase/coinbase.d.ts +20 -18
  12. package/src/coinbase/coinbase.js +31 -15
  13. package/src/ethProviderHelper.cjs +10 -5
  14. package/src/ethProviderHelper.d.ts +4 -3
  15. package/src/ethProviderHelper.js +10 -5
  16. package/src/index.cjs +7 -13
  17. package/src/index.d.ts +1 -0
  18. package/src/index.js +7 -13
  19. package/src/injected/ExodusEvm.cjs +1 -0
  20. package/src/injected/ExodusEvm.d.ts +1 -0
  21. package/src/injected/ExodusEvm.js +1 -0
  22. package/src/injected/InjectedWalletBase.cjs +27 -18
  23. package/src/injected/InjectedWalletBase.d.ts +2 -2
  24. package/src/injected/InjectedWalletBase.js +27 -18
  25. package/src/injected/PhantomEvm.cjs +4 -3
  26. package/src/injected/PhantomEvm.d.ts +2 -1
  27. package/src/injected/PhantomEvm.js +4 -3
  28. package/src/injected/Zerion.cjs +38 -0
  29. package/src/injected/Zerion.d.ts +10 -0
  30. package/src/injected/Zerion.js +34 -0
  31. package/src/injected/fetchInjectedWalletConnectors.cjs +25 -0
  32. package/src/injected/fetchInjectedWalletConnectors.d.ts +0 -1
  33. package/src/injected/fetchInjectedWalletConnectors.js +25 -0
  34. package/src/walletConnect/fetchWalletConnectWallets.cjs +14 -33
  35. package/src/walletConnect/fetchWalletConnectWallets.d.ts +2 -5
  36. package/src/walletConnect/fetchWalletConnectWallets.js +14 -33
  37. package/src/walletConnect/index.d.ts +0 -1
  38. package/src/walletConnect/walletConnect.cjs +450 -78
  39. package/src/walletConnect/walletConnect.d.ts +315 -31
  40. package/src/walletConnect/walletConnect.js +451 -80
  41. package/src/walletConnect/client/client.cjs +0 -201
  42. package/src/walletConnect/client/client.d.ts +0 -17
  43. package/src/walletConnect/client/client.js +0 -187
  44. package/src/walletConnect/client/index.d.ts +0 -1
  45. package/src/walletConnect/client/types.d.ts +0 -4
  46. package/src/walletConnect/walletConnectV2.cjs +0 -475
  47. package/src/walletConnect/walletConnectV2.d.ts +0 -333
  48. package/src/walletConnect/walletConnectV2.js +0 -466
@@ -1,52 +1,336 @@
1
- import Client from '@walletconnect/client';
2
- import { Hex, WalletClient } from 'viem';
3
- import { Chain, FetchPublicAddressOpts, DeepLinkVariant } from '@dynamic-labs/wallet-connector-core';
1
+ import type { SessionTypes } from '@walletconnect/types';
2
+ import { Hex } from 'viem';
3
+ import { Chain, GetAddressOpts, DeepLinkVariant, IWalletConnectConnector } from '@dynamic-labs/wallet-connector-core';
4
4
  import { EvmNetwork } from '@dynamic-labs/types';
5
5
  import { EthWalletConnector, EthWalletConnectorOpts } from '../EthWalletConnector';
6
- type ConnectorSession = {
7
- connected: boolean;
8
- accounts: string[];
9
- chainId: number;
10
- bridge: string;
11
- key: string;
12
- clientId: string;
13
- clientMeta: any;
14
- peerId: string;
15
- peerMeta: any;
16
- handshakeId: number;
17
- handshakeTopic: string;
18
- };
19
6
  export type WalletConnectOpts = EthWalletConnectorOpts & {
20
- walletConnectV1Bridge: string;
7
+ projectId?: string;
21
8
  walletName: string;
22
9
  deepLinkPreference?: DeepLinkVariant;
10
+ walletConnectPreferredChains?: `eip155:${number}`[];
23
11
  };
24
- export declare class WalletConnect extends EthWalletConnector {
12
+ export declare class WalletConnect extends EthWalletConnector implements IWalletConnectConnector {
25
13
  supportedChains: Chain[];
26
14
  connectedChain: Chain;
27
15
  name: string;
28
- bridge: string;
16
+ session: SessionTypes.Struct | undefined;
17
+ activeAccount: Hex | undefined;
18
+ isInitialized: boolean;
19
+ initializePromise: Promise<void> | undefined;
29
20
  canConnectViaQrCode: boolean;
30
21
  isWalletConnect: boolean;
31
- switchNetworkOnlyFromWallet: boolean;
22
+ private static provider;
23
+ private projectId?;
32
24
  private deepLinkPreference;
33
- client?: Client;
34
- clientOptions?: any;
35
- constructor({ walletConnectV1Bridge, walletName, ...props }: WalletConnectOpts);
36
- getClient(): Client;
25
+ private preferredChains;
26
+ private _currentChainId;
27
+ private _hasSwitchedNetwork;
28
+ constructor(opts: WalletConnectOpts);
29
+ private getMappedChains;
30
+ private getMappedChainsByPreferredOrder;
31
+ private initConnection;
32
+ private createProvider;
33
+ private getWalletClientFromInitializedProvider;
34
+ private createInitProviderPromise;
35
+ private initProvider;
36
+ private refreshSession;
37
+ init(): Promise<void>;
38
+ get sessionTopicKey(): string;
39
+ get activeAccountKey(): string;
40
+ get swicthedNetworkKey(): string;
41
+ get currentChainKey(): string;
42
+ private set currentChainId(value);
43
+ private get currentChainId();
44
+ private set hasSwitchedNetwork(value);
45
+ private get hasSwitchedNetwork();
37
46
  supportsNetworkSwitching(): boolean;
47
+ private sessionEventHandler;
48
+ private sessionDeleteHandler;
38
49
  setupEventListeners(): void;
39
50
  teardownEventListeners(): void;
40
- getWalletClient(): WalletClient | undefined;
41
- fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
51
+ getWalletClient(chainId?: string): {
52
+ account: import("viem").JsonRpcAccount | undefined;
53
+ batch?: {
54
+ multicall?: boolean | {
55
+ batchSize?: number | undefined;
56
+ wait?: number | undefined;
57
+ } | undefined;
58
+ } | undefined;
59
+ cacheTime: number;
60
+ chain: import("viem").Chain;
61
+ key: string;
62
+ name: string;
63
+ pollingInterval: number;
64
+ request: import("viem").EIP1193RequestFn<import("viem").WalletRpcSchema>;
65
+ transport: import("viem").TransportConfig<"custom", import("viem").EIP1193RequestFn>;
66
+ type: string;
67
+ uid: string;
68
+ addChain: (args: import("viem").AddChainParameters) => Promise<void>;
69
+ deployContract: <const abi extends import("viem").Abi | readonly unknown[], chainOverride extends import("viem").Chain | undefined>(args: import("viem").DeployContractParameters<abi, import("viem").Chain, import("viem").JsonRpcAccount | undefined, chainOverride>) => Promise<`0x${string}`>;
70
+ getAddresses: () => Promise<import("viem").GetAddressesReturnType>;
71
+ getChainId: () => Promise<number>;
72
+ getPermissions: () => Promise<import("viem").GetPermissionsReturnType>;
73
+ prepareTransactionRequest: <TParameterType extends import("viem").PrepareTransactionRequestParameterType, TChainOverride extends import("viem").Chain | undefined = undefined, TAccountOverride extends `0x${string}` | import("viem").Account | undefined = undefined>(args: import("viem").PrepareTransactionRequestParameters<import("viem").Chain, import("viem").JsonRpcAccount | undefined, TChainOverride, TAccountOverride, TParameterType>) => Promise<import("viem").PrepareTransactionRequestReturnType<import("viem").Chain, import("viem").JsonRpcAccount | undefined, TChainOverride, TAccountOverride, TParameterType>>;
74
+ requestAddresses: () => Promise<import("viem").RequestAddressesReturnType>;
75
+ requestPermissions: (args: {
76
+ [x: string]: Record<string, any>;
77
+ eth_accounts: Record<string, any>;
78
+ }) => Promise<import("viem").RequestPermissionsReturnType>;
79
+ sendRawTransaction: (args: import("viem").SendRawTransactionParameters) => Promise<`0x${string}`>;
80
+ sendTransaction: <TChainOverride_1 extends import("viem").Chain | undefined = undefined>(args: import("viem").SendTransactionParameters<import("viem").Chain, import("viem").JsonRpcAccount | undefined, TChainOverride_1>) => Promise<`0x${string}`>;
81
+ signMessage: (args: import("viem").SignMessageParameters<import("viem").JsonRpcAccount | undefined>) => Promise<`0x${string}`>;
82
+ signTransaction: <TChainOverride_2 extends import("viem").Chain | undefined>(args: import("viem").SignTransactionParameters<import("viem").Chain, import("viem").JsonRpcAccount | undefined, TChainOverride_2>) => Promise<`0x${string}`>;
83
+ signTypedData: <const TTypedData extends {
84
+ [x: string]: readonly import("viem").TypedDataParameter[];
85
+ [x: `string[${string}]`]: undefined;
86
+ [x: `function[${string}]`]: undefined;
87
+ [x: `address[${string}]`]: undefined;
88
+ [x: `bool[${string}]`]: undefined;
89
+ [x: `bytes[${string}]`]: undefined;
90
+ [x: `bytes16[${string}]`]: undefined;
91
+ [x: `bytes1[${string}]`]: undefined;
92
+ [x: `bytes2[${string}]`]: undefined;
93
+ [x: `bytes3[${string}]`]: undefined;
94
+ [x: `bytes4[${string}]`]: undefined;
95
+ [x: `bytes5[${string}]`]: undefined;
96
+ [x: `bytes6[${string}]`]: undefined;
97
+ [x: `bytes7[${string}]`]: undefined;
98
+ [x: `bytes8[${string}]`]: undefined;
99
+ [x: `bytes9[${string}]`]: undefined;
100
+ [x: `bytes10[${string}]`]: undefined;
101
+ [x: `bytes11[${string}]`]: undefined;
102
+ [x: `bytes12[${string}]`]: undefined;
103
+ [x: `bytes13[${string}]`]: undefined;
104
+ [x: `bytes14[${string}]`]: undefined;
105
+ [x: `bytes15[${string}]`]: undefined;
106
+ [x: `bytes17[${string}]`]: undefined;
107
+ [x: `bytes18[${string}]`]: undefined;
108
+ [x: `bytes19[${string}]`]: undefined;
109
+ [x: `bytes20[${string}]`]: undefined;
110
+ [x: `bytes21[${string}]`]: undefined;
111
+ [x: `bytes22[${string}]`]: undefined;
112
+ [x: `bytes23[${string}]`]: undefined;
113
+ [x: `bytes24[${string}]`]: undefined;
114
+ [x: `bytes25[${string}]`]: undefined;
115
+ [x: `bytes26[${string}]`]: undefined;
116
+ [x: `bytes27[${string}]`]: undefined;
117
+ [x: `bytes28[${string}]`]: undefined;
118
+ [x: `bytes29[${string}]`]: undefined;
119
+ [x: `bytes30[${string}]`]: undefined;
120
+ [x: `bytes31[${string}]`]: undefined;
121
+ [x: `bytes32[${string}]`]: undefined;
122
+ [x: `int[${string}]`]: undefined;
123
+ [x: `int16[${string}]`]: undefined;
124
+ [x: `int8[${string}]`]: undefined;
125
+ [x: `int24[${string}]`]: undefined;
126
+ [x: `int32[${string}]`]: undefined;
127
+ [x: `int40[${string}]`]: undefined;
128
+ [x: `int48[${string}]`]: undefined;
129
+ [x: `int56[${string}]`]: undefined;
130
+ [x: `int64[${string}]`]: undefined;
131
+ [x: `int72[${string}]`]: undefined;
132
+ [x: `int80[${string}]`]: undefined;
133
+ [x: `int88[${string}]`]: undefined;
134
+ [x: `int96[${string}]`]: undefined;
135
+ [x: `int104[${string}]`]: undefined;
136
+ [x: `int112[${string}]`]: undefined;
137
+ [x: `int120[${string}]`]: undefined;
138
+ [x: `int128[${string}]`]: undefined;
139
+ [x: `int136[${string}]`]: undefined;
140
+ [x: `int144[${string}]`]: undefined;
141
+ [x: `int152[${string}]`]: undefined;
142
+ [x: `int160[${string}]`]: undefined;
143
+ [x: `int168[${string}]`]: undefined;
144
+ [x: `int176[${string}]`]: undefined;
145
+ [x: `int184[${string}]`]: undefined;
146
+ [x: `int192[${string}]`]: undefined;
147
+ [x: `int200[${string}]`]: undefined;
148
+ [x: `int208[${string}]`]: undefined;
149
+ [x: `int216[${string}]`]: undefined;
150
+ [x: `int224[${string}]`]: undefined;
151
+ [x: `int232[${string}]`]: undefined;
152
+ [x: `int240[${string}]`]: undefined;
153
+ [x: `int248[${string}]`]: undefined;
154
+ [x: `int256[${string}]`]: undefined;
155
+ [x: `uint[${string}]`]: undefined;
156
+ [x: `uint16[${string}]`]: undefined;
157
+ [x: `uint8[${string}]`]: undefined;
158
+ [x: `uint24[${string}]`]: undefined;
159
+ [x: `uint32[${string}]`]: undefined;
160
+ [x: `uint40[${string}]`]: undefined;
161
+ [x: `uint48[${string}]`]: undefined;
162
+ [x: `uint56[${string}]`]: undefined;
163
+ [x: `uint64[${string}]`]: undefined;
164
+ [x: `uint72[${string}]`]: undefined;
165
+ [x: `uint80[${string}]`]: undefined;
166
+ [x: `uint88[${string}]`]: undefined;
167
+ [x: `uint96[${string}]`]: undefined;
168
+ [x: `uint104[${string}]`]: undefined;
169
+ [x: `uint112[${string}]`]: undefined;
170
+ [x: `uint120[${string}]`]: undefined;
171
+ [x: `uint128[${string}]`]: undefined;
172
+ [x: `uint136[${string}]`]: undefined;
173
+ [x: `uint144[${string}]`]: undefined;
174
+ [x: `uint152[${string}]`]: undefined;
175
+ [x: `uint160[${string}]`]: undefined;
176
+ [x: `uint168[${string}]`]: undefined;
177
+ [x: `uint176[${string}]`]: undefined;
178
+ [x: `uint184[${string}]`]: undefined;
179
+ [x: `uint192[${string}]`]: undefined;
180
+ [x: `uint200[${string}]`]: undefined;
181
+ [x: `uint208[${string}]`]: undefined;
182
+ [x: `uint216[${string}]`]: undefined;
183
+ [x: `uint224[${string}]`]: undefined;
184
+ [x: `uint232[${string}]`]: undefined;
185
+ [x: `uint240[${string}]`]: undefined;
186
+ [x: `uint248[${string}]`]: undefined;
187
+ [x: `uint256[${string}]`]: undefined;
188
+ string?: undefined;
189
+ address?: undefined;
190
+ bool?: undefined;
191
+ bytes?: undefined;
192
+ bytes16?: undefined;
193
+ bytes1?: undefined;
194
+ bytes2?: undefined;
195
+ bytes3?: undefined;
196
+ bytes4?: undefined;
197
+ bytes5?: undefined;
198
+ bytes6?: undefined;
199
+ bytes7?: undefined;
200
+ bytes8?: undefined;
201
+ bytes9?: undefined;
202
+ bytes10?: undefined;
203
+ bytes11?: undefined;
204
+ bytes12?: undefined;
205
+ bytes13?: undefined;
206
+ bytes14?: undefined;
207
+ bytes15?: undefined;
208
+ bytes17?: undefined;
209
+ bytes18?: undefined;
210
+ bytes19?: undefined;
211
+ bytes20?: undefined;
212
+ bytes21?: undefined;
213
+ bytes22?: undefined;
214
+ bytes23?: undefined;
215
+ bytes24?: undefined;
216
+ bytes25?: undefined;
217
+ bytes26?: undefined;
218
+ bytes27?: undefined;
219
+ bytes28?: undefined;
220
+ bytes29?: undefined;
221
+ bytes30?: undefined;
222
+ bytes31?: undefined;
223
+ bytes32?: undefined;
224
+ int16?: undefined;
225
+ int8?: undefined;
226
+ int24?: undefined;
227
+ int32?: undefined;
228
+ int40?: undefined;
229
+ int48?: undefined;
230
+ int56?: undefined;
231
+ int64?: undefined;
232
+ int72?: undefined;
233
+ int80?: undefined;
234
+ int88?: undefined;
235
+ int96?: undefined;
236
+ int104?: undefined;
237
+ int112?: undefined;
238
+ int120?: undefined;
239
+ int128?: undefined;
240
+ int136?: undefined;
241
+ int144?: undefined;
242
+ int152?: undefined;
243
+ int160?: undefined;
244
+ int168?: undefined;
245
+ int176?: undefined;
246
+ int184?: undefined;
247
+ int192?: undefined;
248
+ int200?: undefined;
249
+ int208?: undefined;
250
+ int216?: undefined;
251
+ int224?: undefined;
252
+ int232?: undefined;
253
+ int240?: undefined;
254
+ int248?: undefined;
255
+ int256?: undefined;
256
+ uint16?: undefined;
257
+ uint8?: undefined;
258
+ uint24?: undefined;
259
+ uint32?: undefined;
260
+ uint40?: undefined;
261
+ uint48?: undefined;
262
+ uint56?: undefined;
263
+ uint64?: undefined;
264
+ uint72?: undefined;
265
+ uint80?: undefined;
266
+ uint88?: undefined;
267
+ uint96?: undefined;
268
+ uint104?: undefined;
269
+ uint112?: undefined;
270
+ uint120?: undefined;
271
+ uint128?: undefined;
272
+ uint136?: undefined;
273
+ uint144?: undefined;
274
+ uint152?: undefined;
275
+ uint160?: undefined;
276
+ uint168?: undefined;
277
+ uint176?: undefined;
278
+ uint184?: undefined;
279
+ uint192?: undefined;
280
+ uint200?: undefined;
281
+ uint208?: undefined;
282
+ uint216?: undefined;
283
+ uint224?: undefined;
284
+ uint232?: undefined;
285
+ uint240?: undefined;
286
+ uint248?: undefined;
287
+ uint256?: undefined;
288
+ } | {
289
+ [key: string]: unknown;
290
+ }, TPrimaryType extends string>(args: import("viem").SignTypedDataParameters<TTypedData, TPrimaryType, import("viem").JsonRpcAccount | undefined>) => Promise<`0x${string}`>;
291
+ switchChain: (args: import("viem").SwitchChainParameters) => Promise<void>;
292
+ watchAsset: (args: import("viem").WatchAssetParams) => Promise<boolean>;
293
+ writeContract: <const abi_1 extends import("viem").Abi | readonly unknown[], functionName extends import("viem").ContractFunctionName<abi_1, "nonpayable" | "payable">, args extends import("viem").ContractFunctionArgs<abi_1, "pure" | "view", functionName>, TChainOverride_3 extends import("viem").Chain | undefined = undefined>(args: import("viem").WriteContractParameters<abi_1, functionName, args, import("viem").Chain, import("viem").JsonRpcAccount | undefined, TChainOverride_3>) => Promise<`0x${string}`>;
294
+ extend: <const client extends {
295
+ [x: string]: unknown;
296
+ account?: undefined;
297
+ batch?: undefined;
298
+ cacheTime?: undefined;
299
+ chain?: undefined;
300
+ key?: undefined;
301
+ name?: undefined;
302
+ pollingInterval?: undefined;
303
+ request?: undefined;
304
+ transport?: undefined;
305
+ type?: undefined;
306
+ uid?: undefined;
307
+ } & Partial<Pick<import("viem").PublicActions<import("viem").CustomTransport, import("viem").Chain, import("viem").JsonRpcAccount | undefined>, "getChainId" | "prepareTransactionRequest" | "sendRawTransaction" | "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "readContract" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<import("viem").WalletActions<import("viem").Chain, import("viem").JsonRpcAccount | undefined>, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<import("viem").CustomTransport, import("viem").Chain, import("viem").JsonRpcAccount | undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<import("viem").Chain, import("viem").JsonRpcAccount | undefined>>) => client) => import("viem").Client<import("viem").CustomTransport, import("viem").Chain, import("viem").JsonRpcAccount | undefined, import("viem").WalletRpcSchema, { [K in keyof client]: client[K]; } & import("viem").WalletActions<import("viem").Chain, import("viem").JsonRpcAccount | undefined>>;
308
+ } | undefined;
309
+ getAddress(opts?: GetAddressOpts): Promise<string | undefined>;
310
+ /**
311
+ * WalletConnect V2 will fail to send the sign message request if the chainId
312
+ * is not the same as the one in the session. This method will wait for the
313
+ * chainId to change and then retry the sign message request.
314
+ *
315
+ * Otherwise it will just return the result of the sign message request.
316
+ *
317
+ * @param signMessageFn - Function to sign message with provider
318
+ * @param messageToSign - Message to sign
319
+ * @returns
320
+ */
321
+ protected waitForSignMessage(signMessageFn: (messageToSign: string) => Promise<string | undefined>, messageToSign: string): Promise<string | undefined>;
42
322
  getDeepLink(): string | undefined;
43
323
  signMessage(messageToSign: string): Promise<string | undefined>;
324
+ private clearActiveAccount;
325
+ private clearSession;
326
+ private setActiveAccount;
327
+ private setSession;
44
328
  endSession(): Promise<void>;
45
- providerSwitchNetwork({ network, provider, }: {
329
+ getNetwork(): Promise<number | undefined>;
330
+ providerSwitchNetwork({ network, }: {
46
331
  network: EvmNetwork;
47
- provider: WalletClient;
48
332
  }): Promise<void>;
49
- getConnectedAccounts(): Promise<Hex[]>;
50
- getSession(): Promise<ConnectorSession | undefined>;
333
+ getConnectedAccounts(): Promise<string[]>;
334
+ private isMetaMask;
335
+ getSupportedNetworks(): Promise<string[]>;
51
336
  }
52
- export {};