@injectivelabs/wallet-evm 1.16.38-alpha.7 → 1.16.38

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 (49) hide show
  1. package/dist/cjs/index.d.ts +3 -0
  2. package/dist/cjs/index.js +21 -0
  3. package/dist/cjs/package.json +2 -2
  4. package/dist/cjs/strategy/strategy.d.ts +43 -0
  5. package/dist/cjs/strategy/strategy.js +314 -0
  6. package/dist/cjs/strategy/utils/Okx.d.ts +4 -0
  7. package/dist/cjs/strategy/utils/Okx.js +49 -0
  8. package/dist/cjs/strategy/utils/bitget.d.ts +4 -0
  9. package/dist/cjs/strategy/utils/bitget.js +43 -0
  10. package/dist/cjs/strategy/utils/index.d.ts +7 -0
  11. package/dist/cjs/strategy/utils/index.js +17 -0
  12. package/dist/cjs/strategy/utils/metamask.d.ts +4 -0
  13. package/dist/cjs/strategy/utils/metamask.js +44 -0
  14. package/dist/cjs/strategy/utils/phantom.d.ts +4 -0
  15. package/dist/cjs/strategy/utils/phantom.js +49 -0
  16. package/dist/cjs/strategy/utils/rabby.d.ts +4 -0
  17. package/dist/cjs/strategy/utils/rabby.js +44 -0
  18. package/dist/cjs/strategy/utils/rainbow.d.ts +4 -0
  19. package/dist/cjs/strategy/utils/rainbow.js +49 -0
  20. package/dist/cjs/strategy/utils/trustWallet.d.ts +4 -0
  21. package/dist/cjs/strategy/utils/trustWallet.js +49 -0
  22. package/dist/cjs/utils/index.d.ts +5 -0
  23. package/dist/cjs/utils/index.js +73 -0
  24. package/dist/esm/index.d.ts +3 -112
  25. package/dist/esm/index.js +3 -551
  26. package/dist/esm/package.json +2 -2
  27. package/dist/esm/strategy/strategy.d.ts +43 -0
  28. package/dist/esm/strategy/strategy.js +310 -0
  29. package/dist/esm/strategy/utils/Okx.d.ts +4 -0
  30. package/dist/esm/strategy/utils/Okx.js +46 -0
  31. package/dist/esm/strategy/utils/bitget.d.ts +4 -0
  32. package/dist/esm/strategy/utils/bitget.js +40 -0
  33. package/dist/esm/strategy/utils/index.d.ts +7 -0
  34. package/dist/esm/strategy/utils/index.js +7 -0
  35. package/dist/esm/strategy/utils/metamask.d.ts +4 -0
  36. package/dist/esm/strategy/utils/metamask.js +41 -0
  37. package/dist/esm/strategy/utils/phantom.d.ts +4 -0
  38. package/dist/esm/strategy/utils/phantom.js +46 -0
  39. package/dist/esm/strategy/utils/rabby.d.ts +4 -0
  40. package/dist/esm/strategy/utils/rabby.js +41 -0
  41. package/dist/esm/strategy/utils/rainbow.d.ts +4 -0
  42. package/dist/esm/strategy/utils/rainbow.js +46 -0
  43. package/dist/esm/strategy/utils/trustWallet.d.ts +4 -0
  44. package/dist/esm/strategy/utils/trustWallet.js +46 -0
  45. package/dist/esm/utils/index.d.ts +5 -0
  46. package/dist/esm/utils/index.js +68 -0
  47. package/package.json +49 -42
  48. package/dist/cjs/index.cjs +0 -561
  49. package/dist/cjs/index.d.cts +0 -112
@@ -0,0 +1,3 @@
1
+ export { EvmWallet as EvmWalletStrategy } from './strategy/strategy.js';
2
+ export * from './strategy/utils/index.js';
3
+ export * from './utils/index.js';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.EvmWalletStrategy = void 0;
18
+ var strategy_js_1 = require("./strategy/strategy.js");
19
+ Object.defineProperty(exports, "EvmWalletStrategy", { enumerable: true, get: function () { return strategy_js_1.EvmWallet; } });
20
+ __exportStar(require("./strategy/utils/index.js"), exports);
21
+ __exportStar(require("./utils/index.js"), exports);
@@ -1,3 +1,3 @@
1
1
  {
2
- "type": "commonjs"
3
- }
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,43 @@
1
+ import { Wallet, WalletDeviceType, BaseConcreteStrategy } from '@injectivelabs/wallet-base';
2
+ import type { AccountAddress, EvmChainId } from '@injectivelabs/ts-types';
3
+ import type { ErrorContext, ThrownException } from '@injectivelabs/exceptions';
4
+ import type { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
5
+ import type { StdSignDoc, Eip1193Provider, SendTransactionOptions, BrowserEip1993Provider, ConcreteWalletStrategy, ConcreteWalletStrategyArgs, ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
6
+ export declare class EvmWallet extends BaseConcreteStrategy implements ConcreteWalletStrategy {
7
+ wallet?: Wallet;
8
+ evmProviders: Partial<Record<Wallet, BrowserEip1993Provider>>;
9
+ constructor(args: (ConcreteWalletStrategyArgs | ConcreteEvmWalletStrategyArgs) & {
10
+ wallet: Wallet;
11
+ });
12
+ EvmWalletException(error: Error, context?: ErrorContext): ThrownException;
13
+ getWalletDeviceType(): Promise<WalletDeviceType>;
14
+ enable(): Promise<boolean>;
15
+ disconnect(): Promise<void>;
16
+ getAddresses(): Promise<string[]>;
17
+ getSessionOrConfirm(address: AccountAddress): Promise<string>;
18
+ sendEvmTransaction(transaction: unknown, _options: {
19
+ address: AccountAddress;
20
+ evmChainId: EvmChainId;
21
+ }): Promise<string>;
22
+ sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
23
+ signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
24
+ signAminoCosmosTransaction(_transaction: {
25
+ address: string;
26
+ signDoc: StdSignDoc;
27
+ }): Promise<AminoSignResponse>;
28
+ signCosmosTransaction(_transaction: {
29
+ txRaw: TxRaw;
30
+ accountNumber: number;
31
+ chainId: string;
32
+ address: string;
33
+ }): Promise<DirectSignResponse>;
34
+ signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
35
+ getEthereumChainId(): Promise<string>;
36
+ getEvmTransactionReceipt(txHash: string): Promise<string>;
37
+ getPubKey(): Promise<string>;
38
+ onChainIdChanged(callback: (chain: string) => void): Promise<void>;
39
+ onAccountChange(callback: (account: AccountAddress | string[]) => void): Promise<void>;
40
+ getEip1193Provider(): Promise<Eip1193Provider>;
41
+ addEvmNetwork(chainId: EvmChainId): Promise<void>;
42
+ private getEthereum;
43
+ }
@@ -0,0 +1,314 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EvmWallet = void 0;
4
+ const utils_1 = require("@injectivelabs/utils");
5
+ const sdk_ts_1 = require("@injectivelabs/sdk-ts");
6
+ const wallet_base_1 = require("@injectivelabs/wallet-base");
7
+ const exceptions_1 = require("@injectivelabs/exceptions");
8
+ const index_js_1 = require("./utils/index.js");
9
+ class EvmWallet extends wallet_base_1.BaseConcreteStrategy {
10
+ wallet;
11
+ evmProviders = {};
12
+ constructor(args) {
13
+ super(args);
14
+ if (!(0, wallet_base_1.isEvmBrowserWallet)(args.wallet)) {
15
+ throw new exceptions_1.WalletException(new Error(`Evm Wallet for ${(0, utils_1.capitalize)(args.wallet)} is not supported.`));
16
+ }
17
+ if (!(0, sdk_ts_1.isServerSide)()) {
18
+ window.addEventListener('eip6963:announceProvider', (announcement) => {
19
+ const event = announcement;
20
+ const walletName = event.detail.info.name.toLowerCase();
21
+ if (walletName === wallet_base_1.Wallet.Metamask.toLowerCase()) {
22
+ this.evmProviders[wallet_base_1.Wallet.Metamask] = event.detail.provider;
23
+ }
24
+ if (walletName === wallet_base_1.Wallet.Rabby.toLowerCase()) {
25
+ this.evmProviders[wallet_base_1.Wallet.Rabby] = event.detail.provider;
26
+ }
27
+ if (walletName === wallet_base_1.Wallet.Rainbow.toLowerCase()) {
28
+ this.evmProviders[wallet_base_1.Wallet.Rainbow] = event.detail.provider;
29
+ }
30
+ if (walletName === wallet_base_1.Wallet.Phantom.toLowerCase()) {
31
+ this.evmProviders[wallet_base_1.Wallet.Phantom] = event.detail.provider;
32
+ }
33
+ if (walletName === wallet_base_1.Wallet.OkxWallet.toLowerCase()) {
34
+ this.evmProviders[wallet_base_1.Wallet.OkxWallet] = event.detail.provider;
35
+ }
36
+ if (walletName === wallet_base_1.Wallet.BitGet.toLowerCase()) {
37
+ this.evmProviders[wallet_base_1.Wallet.BitGet] = event.detail.provider;
38
+ }
39
+ if (walletName === wallet_base_1.Wallet.TrustWallet.toLowerCase()) {
40
+ this.evmProviders[wallet_base_1.Wallet.TrustWallet] = event.detail.provider;
41
+ }
42
+ });
43
+ window.dispatchEvent(new Event('eip6963:requestProvider'));
44
+ }
45
+ this.wallet = args.wallet;
46
+ }
47
+ EvmWalletException(error, context) {
48
+ if (this.wallet === wallet_base_1.Wallet.Metamask) {
49
+ return new exceptions_1.MetamaskException(error, context);
50
+ }
51
+ if (this.wallet === wallet_base_1.Wallet.BitGet) {
52
+ return new exceptions_1.BitGetException(error, context);
53
+ }
54
+ if (this.wallet === wallet_base_1.Wallet.OkxWallet) {
55
+ return new exceptions_1.OkxWalletException(error, context);
56
+ }
57
+ if (this.wallet === wallet_base_1.Wallet.Phantom) {
58
+ return new exceptions_1.MetamaskException(error, context);
59
+ }
60
+ if (this.wallet === wallet_base_1.Wallet.TrustWallet) {
61
+ return new exceptions_1.TrustWalletException(error, context);
62
+ }
63
+ if (this.wallet === wallet_base_1.Wallet.Rainbow) {
64
+ return new exceptions_1.RainbowWalletException(error, context);
65
+ }
66
+ return new exceptions_1.WalletException(error, context);
67
+ }
68
+ async getWalletDeviceType() {
69
+ return Promise.resolve(wallet_base_1.WalletDeviceType.Browser);
70
+ }
71
+ async enable() {
72
+ return Promise.resolve(true);
73
+ }
74
+ async disconnect() {
75
+ if (this.listeners[wallet_base_1.WalletEventListener.AccountChange]) {
76
+ const ethereum = await this.getEthereum();
77
+ ethereum.removeListener('accountsChanged', this.listeners[wallet_base_1.WalletEventListener.AccountChange]);
78
+ }
79
+ if (this.listeners[wallet_base_1.WalletEventListener.ChainIdChange]) {
80
+ const ethereum = await this.getEthereum();
81
+ ethereum.removeListener('chainChanged', this.listeners[wallet_base_1.WalletEventListener.ChainIdChange]);
82
+ }
83
+ this.listeners = {};
84
+ }
85
+ async getAddresses() {
86
+ const ethereum = await this.getEthereum();
87
+ try {
88
+ return (await ethereum.request({
89
+ method: 'eth_requestAccounts',
90
+ }));
91
+ }
92
+ catch (e) {
93
+ throw this.EvmWalletException(new Error(e.message), {
94
+ code: exceptions_1.UnspecifiedErrorCode,
95
+ type: exceptions_1.ErrorType.WalletError,
96
+ contextModule: wallet_base_1.WalletAction.GetAccounts,
97
+ });
98
+ }
99
+ }
100
+ async getSessionOrConfirm(address) {
101
+ return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
102
+ }
103
+ async sendEvmTransaction(transaction, _options) {
104
+ const ethereum = await this.getEthereum();
105
+ try {
106
+ return (await ethereum.request({
107
+ method: 'eth_sendTransaction',
108
+ params: [transaction],
109
+ }));
110
+ }
111
+ catch (e) {
112
+ throw this.EvmWalletException(new Error(e.message), {
113
+ code: exceptions_1.UnspecifiedErrorCode,
114
+ type: exceptions_1.ErrorType.WalletError,
115
+ contextModule: wallet_base_1.WalletAction.SendEvmTransaction,
116
+ });
117
+ }
118
+ }
119
+ async sendTransaction(transaction, options) {
120
+ const { endpoints, txTimeout } = options;
121
+ if (!endpoints) {
122
+ throw new exceptions_1.WalletException(new Error('You have to pass endpoints within the options for using Ethereum native wallets'));
123
+ }
124
+ const txApi = new sdk_ts_1.TxGrpcApi(endpoints.grpc);
125
+ const response = await txApi.broadcast(transaction, { txTimeout });
126
+ if (response.code !== 0) {
127
+ throw new exceptions_1.TransactionException(new Error(response.rawLog), {
128
+ code: exceptions_1.UnspecifiedErrorCode,
129
+ contextCode: response.code,
130
+ contextModule: response.codespace,
131
+ });
132
+ }
133
+ return response;
134
+ }
135
+ async signEip712TypedData(eip712json, address) {
136
+ const ethereum = await this.getEthereum();
137
+ try {
138
+ return (await ethereum.request({
139
+ method: 'eth_signTypedData_v4',
140
+ params: [address, eip712json],
141
+ }));
142
+ }
143
+ catch (e) {
144
+ if (e.message.includes('Ledger: The signature doesnt match the right address')) {
145
+ throw new exceptions_1.MetamaskException(new Error('Please connect directly with Ledger to sign this transaction'), {
146
+ code: exceptions_1.UnspecifiedErrorCode,
147
+ type: exceptions_1.ErrorType.WalletError,
148
+ contextModule: wallet_base_1.WalletAction.SignTransaction,
149
+ });
150
+ }
151
+ throw new exceptions_1.MetamaskException(new Error(e.message), {
152
+ code: exceptions_1.UnspecifiedErrorCode,
153
+ type: exceptions_1.ErrorType.WalletError,
154
+ contextModule: wallet_base_1.WalletAction.SignTransaction,
155
+ });
156
+ }
157
+ }
158
+ async signAminoCosmosTransaction(_transaction) {
159
+ throw new exceptions_1.WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
160
+ code: exceptions_1.UnspecifiedErrorCode,
161
+ type: exceptions_1.ErrorType.WalletError,
162
+ contextModule: wallet_base_1.WalletAction.SignTransaction,
163
+ });
164
+ }
165
+ async signCosmosTransaction(_transaction) {
166
+ throw new exceptions_1.WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
167
+ code: exceptions_1.UnspecifiedErrorCode,
168
+ type: exceptions_1.ErrorType.WalletError,
169
+ contextModule: wallet_base_1.WalletAction.SignTransaction,
170
+ });
171
+ }
172
+ async signArbitrary(signer, data) {
173
+ const ethereum = await this.getEthereum();
174
+ try {
175
+ const signature = await ethereum.request({
176
+ method: 'personal_sign',
177
+ params: [(0, sdk_ts_1.toUtf8)(data), signer],
178
+ });
179
+ return signature;
180
+ }
181
+ catch (e) {
182
+ throw this.EvmWalletException(new Error(e.message), {
183
+ code: exceptions_1.UnspecifiedErrorCode,
184
+ type: exceptions_1.ErrorType.WalletError,
185
+ contextModule: wallet_base_1.WalletAction.SignArbitrary,
186
+ });
187
+ }
188
+ }
189
+ async getEthereumChainId() {
190
+ const ethereum = await this.getEthereum();
191
+ try {
192
+ return ethereum.request({ method: 'eth_chainId' });
193
+ }
194
+ catch (e) {
195
+ throw this.EvmWalletException(new Error(e.message), {
196
+ code: exceptions_1.UnspecifiedErrorCode,
197
+ type: exceptions_1.ErrorType.WalletError,
198
+ contextModule: wallet_base_1.WalletAction.GetChainId,
199
+ });
200
+ }
201
+ }
202
+ async getEvmTransactionReceipt(txHash) {
203
+ const ethereum = await this.getEthereum();
204
+ const interval = 3000;
205
+ const maxAttempts = 10;
206
+ let attempts = 0;
207
+ while (attempts < maxAttempts) {
208
+ attempts++;
209
+ await (0, utils_1.sleep)(interval);
210
+ try {
211
+ const receipt = await ethereum.request({
212
+ method: 'eth_getTransactionReceipt',
213
+ params: [txHash],
214
+ });
215
+ if (receipt) {
216
+ return txHash;
217
+ }
218
+ }
219
+ catch { }
220
+ }
221
+ throw new Error(`Failed to retrieve transaction receipt for txHash: ${txHash}`);
222
+ }
223
+ async getPubKey() {
224
+ throw new exceptions_1.WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
225
+ }
226
+ async onChainIdChanged(callback) {
227
+ const ethereum = await this.getEthereum();
228
+ this.listeners = {
229
+ [wallet_base_1.WalletEventListener.ChainIdChange]: callback,
230
+ };
231
+ ethereum.on('chainChanged', callback);
232
+ }
233
+ async onAccountChange(callback) {
234
+ const ethereum = await this.getEthereum();
235
+ this.listeners = {
236
+ [wallet_base_1.WalletEventListener.AccountChange]: callback,
237
+ };
238
+ ethereum.on('accountsChanged', callback);
239
+ }
240
+ async getEip1193Provider() {
241
+ return this.getEthereum();
242
+ }
243
+ async addEvmNetwork(chainId) {
244
+ const ethereum = await this.getEthereum();
245
+ const chainIdToHex = chainId.toString(16);
246
+ const chain = (0, wallet_base_1.getEvmChainConfig)(chainId);
247
+ const params = {
248
+ chainId: `0x${chainIdToHex}`,
249
+ chainName: chain.name,
250
+ rpcUrls: [...(chain.rpcUrls?.default?.http || [])],
251
+ blockExplorerUrls: chain.blockExplorers?.default?.url
252
+ ? [chain.blockExplorers.default.url]
253
+ : [],
254
+ nativeCurrency: chain.nativeCurrency,
255
+ };
256
+ try {
257
+ await Promise.race([
258
+ ethereum.request({
259
+ method: 'wallet_switchEthereumChain',
260
+ params: [{ chainId: `0x${chainIdToHex}` }],
261
+ }),
262
+ new Promise((resolve) => ethereum.on('chainChanged', ({ chain }) => {
263
+ if (chain?.id === chainIdToHex) {
264
+ resolve();
265
+ }
266
+ })),
267
+ ]);
268
+ }
269
+ catch (error) {
270
+ if (error.code === 4902) {
271
+ await ethereum.request({
272
+ method: 'wallet_addEthereumChain',
273
+ params: [params],
274
+ });
275
+ return;
276
+ }
277
+ throw this.EvmWalletException(new Error(`Something went wrong while adding ${(0, utils_1.capitalize)(this.wallet || 'wallet')} network`), {
278
+ code: exceptions_1.UnspecifiedErrorCode,
279
+ type: exceptions_1.ErrorType.WalletError,
280
+ contextModule: wallet_base_1.WalletAction.GetChainId,
281
+ });
282
+ }
283
+ }
284
+ async getEthereum() {
285
+ const evmProvider = this.evmProviders[this.wallet];
286
+ if (evmProvider) {
287
+ return evmProvider;
288
+ }
289
+ const backUpProvider = this.wallet === wallet_base_1.Wallet.Metamask
290
+ ? await (0, index_js_1.getMetamaskProvider)()
291
+ : this.wallet === wallet_base_1.Wallet.Rabby
292
+ ? await (0, index_js_1.getRabbyProvider)()
293
+ : this.wallet === wallet_base_1.Wallet.Phantom
294
+ ? await (0, index_js_1.getPhantomProvider)()
295
+ : this.wallet === wallet_base_1.Wallet.BitGet
296
+ ? await (0, index_js_1.getBitGetProvider)()
297
+ : this.wallet === wallet_base_1.Wallet.OkxWallet
298
+ ? await (0, index_js_1.getOkxWalletProvider)()
299
+ : this.wallet === wallet_base_1.Wallet.TrustWallet
300
+ ? await (0, index_js_1.getTrustWalletProvider)()
301
+ : this.wallet === wallet_base_1.Wallet.Rainbow
302
+ ? await (0, index_js_1.getRainbowProvider)()
303
+ : undefined;
304
+ if (!backUpProvider) {
305
+ throw this.EvmWalletException(new Error(`Please install the ${this.wallet} wallet extension.`), {
306
+ code: exceptions_1.UnspecifiedErrorCode,
307
+ type: exceptions_1.ErrorType.WalletNotInstalledError,
308
+ contextModule: wallet_base_1.WalletAction.GetAccounts,
309
+ });
310
+ }
311
+ return backUpProvider;
312
+ }
313
+ }
314
+ exports.EvmWallet = EvmWallet;
@@ -0,0 +1,4 @@
1
+ import type { BrowserEip1993Provider } from '@injectivelabs/wallet-base';
2
+ export declare function getOkxWalletProvider({ timeout }?: {
3
+ timeout: number;
4
+ }): Promise<BrowserEip1993Provider>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOkxWalletProvider = getOkxWalletProvider;
4
+ const sdk_ts_1 = require("@injectivelabs/sdk-ts");
5
+ const $window = ((0, sdk_ts_1.isServerSide)()
6
+ ? {}
7
+ : window);
8
+ async function getOkxWalletProvider({ timeout } = { timeout: 3000 }) {
9
+ const provider = getOkxWalletFromWindow();
10
+ if (provider) {
11
+ return provider;
12
+ }
13
+ return listenForOkxWalletInitialized({
14
+ timeout,
15
+ });
16
+ }
17
+ async function listenForOkxWalletInitialized({ timeout } = { timeout: 3000 }) {
18
+ return new Promise((resolve) => {
19
+ const handleInitialization = () => {
20
+ resolve(getOkxWalletFromWindow());
21
+ };
22
+ $window.addEventListener('okxwallet#initialized', handleInitialization, {
23
+ once: true,
24
+ });
25
+ setTimeout(() => {
26
+ $window.removeEventListener('okxwallet#initialized', handleInitialization);
27
+ resolve(null);
28
+ }, timeout);
29
+ });
30
+ }
31
+ function getOkxWalletFromWindow() {
32
+ const injectedProviderExist = typeof window !== 'undefined' &&
33
+ (typeof $window.ethereum !== 'undefined' ||
34
+ typeof $window.okxwallet !== 'undefined');
35
+ // No injected providers exist.
36
+ if (!injectedProviderExist) {
37
+ return;
38
+ }
39
+ if ($window.okxwallet) {
40
+ return $window.okxwallet;
41
+ }
42
+ if ($window.ethereum.isOkxWallet) {
43
+ return $window.ethereum;
44
+ }
45
+ if ($window.providers) {
46
+ return $window.providers.find((p) => p.isOkxWallet);
47
+ }
48
+ return;
49
+ }
@@ -0,0 +1,4 @@
1
+ import type { BrowserEip1993Provider } from '@injectivelabs/wallet-base';
2
+ export declare function getBitGetProvider({ timeout }?: {
3
+ timeout: number;
4
+ }): Promise<BrowserEip1993Provider>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBitGetProvider = getBitGetProvider;
4
+ const sdk_ts_1 = require("@injectivelabs/sdk-ts");
5
+ const $window = ((0, sdk_ts_1.isServerSide)()
6
+ ? {}
7
+ : window);
8
+ async function getBitGetProvider({ timeout } = { timeout: 3000 }) {
9
+ const provider = getBitGetFromWindow();
10
+ if (provider) {
11
+ return provider;
12
+ }
13
+ return listenForBitGetInitialized({
14
+ timeout,
15
+ });
16
+ }
17
+ async function listenForBitGetInitialized({ timeout } = { timeout: 3000 }) {
18
+ return new Promise((resolve) => {
19
+ const handleInitialization = () => {
20
+ resolve(getBitGetFromWindow());
21
+ };
22
+ $window.addEventListener('bitkeep#initialized', handleInitialization, {
23
+ once: true,
24
+ });
25
+ setTimeout(() => {
26
+ $window.removeEventListener('bitkeep#initialized', handleInitialization);
27
+ resolve(null);
28
+ }, timeout);
29
+ });
30
+ }
31
+ function getBitGetFromWindow() {
32
+ const injectedProviderExist = typeof window !== 'undefined' &&
33
+ (typeof $window.ethereum !== 'undefined' ||
34
+ typeof $window.bitkeep !== 'undefined');
35
+ // No injected providers exist.
36
+ if (!injectedProviderExist) {
37
+ return;
38
+ }
39
+ if ($window.bitkeep && $window.bitkeep.ethereum) {
40
+ return $window.bitkeep.ethereum;
41
+ }
42
+ return;
43
+ }
@@ -0,0 +1,7 @@
1
+ export { getRabbyProvider } from './rabby.js';
2
+ export { getBitGetProvider } from './bitget.js';
3
+ export { getOkxWalletProvider } from './Okx.js';
4
+ export { getPhantomProvider } from './phantom.js';
5
+ export { getRainbowProvider } from './rainbow.js';
6
+ export { getMetamaskProvider } from './metamask.js';
7
+ export { getTrustWalletProvider } from './trustWallet.js';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTrustWalletProvider = exports.getMetamaskProvider = exports.getRainbowProvider = exports.getPhantomProvider = exports.getOkxWalletProvider = exports.getBitGetProvider = exports.getRabbyProvider = void 0;
4
+ var rabby_js_1 = require("./rabby.js");
5
+ Object.defineProperty(exports, "getRabbyProvider", { enumerable: true, get: function () { return rabby_js_1.getRabbyProvider; } });
6
+ var bitget_js_1 = require("./bitget.js");
7
+ Object.defineProperty(exports, "getBitGetProvider", { enumerable: true, get: function () { return bitget_js_1.getBitGetProvider; } });
8
+ var Okx_js_1 = require("./Okx.js");
9
+ Object.defineProperty(exports, "getOkxWalletProvider", { enumerable: true, get: function () { return Okx_js_1.getOkxWalletProvider; } });
10
+ var phantom_js_1 = require("./phantom.js");
11
+ Object.defineProperty(exports, "getPhantomProvider", { enumerable: true, get: function () { return phantom_js_1.getPhantomProvider; } });
12
+ var rainbow_js_1 = require("./rainbow.js");
13
+ Object.defineProperty(exports, "getRainbowProvider", { enumerable: true, get: function () { return rainbow_js_1.getRainbowProvider; } });
14
+ var metamask_js_1 = require("./metamask.js");
15
+ Object.defineProperty(exports, "getMetamaskProvider", { enumerable: true, get: function () { return metamask_js_1.getMetamaskProvider; } });
16
+ var trustWallet_js_1 = require("./trustWallet.js");
17
+ Object.defineProperty(exports, "getTrustWalletProvider", { enumerable: true, get: function () { return trustWallet_js_1.getTrustWalletProvider; } });
@@ -0,0 +1,4 @@
1
+ import type { BrowserEip1993Provider } from '@injectivelabs/wallet-base';
2
+ export declare function getMetamaskProvider({ timeout }?: {
3
+ timeout: number;
4
+ }): Promise<BrowserEip1993Provider>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMetamaskProvider = getMetamaskProvider;
4
+ const sdk_ts_1 = require("@injectivelabs/sdk-ts");
5
+ const $window = ((0, sdk_ts_1.isServerSide)()
6
+ ? {}
7
+ : window);
8
+ async function getMetamaskProvider({ timeout } = { timeout: 3000 }) {
9
+ const provider = getMetamaskFromWindow();
10
+ if (provider) {
11
+ return provider;
12
+ }
13
+ return listenForMetamaskInitialized({
14
+ timeout,
15
+ });
16
+ }
17
+ async function listenForMetamaskInitialized({ timeout } = { timeout: 3000 }) {
18
+ return new Promise((resolve) => {
19
+ const handleInitialization = () => {
20
+ resolve(getMetamaskFromWindow());
21
+ };
22
+ $window.addEventListener('ethereum#initialized', handleInitialization, {
23
+ once: true,
24
+ });
25
+ setTimeout(() => {
26
+ $window.removeEventListener('ethereum#initialized', handleInitialization);
27
+ resolve(null);
28
+ }, timeout);
29
+ });
30
+ }
31
+ function getMetamaskFromWindow() {
32
+ const injectedProviderExist = typeof window !== 'undefined' && typeof $window.ethereum !== 'undefined';
33
+ // No injected providers exist.
34
+ if (!injectedProviderExist) {
35
+ return;
36
+ }
37
+ if ($window.ethereum.isMetaMask) {
38
+ return $window.ethereum;
39
+ }
40
+ if ($window.providers) {
41
+ return $window.providers.find((p) => p.isMetaMask);
42
+ }
43
+ return;
44
+ }
@@ -0,0 +1,4 @@
1
+ import type { BrowserEip1993Provider } from '@injectivelabs/wallet-base';
2
+ export declare function getPhantomProvider({ timeout }?: {
3
+ timeout: number;
4
+ }): Promise<BrowserEip1993Provider>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPhantomProvider = getPhantomProvider;
4
+ const sdk_ts_1 = require("@injectivelabs/sdk-ts");
5
+ const $window = ((0, sdk_ts_1.isServerSide)()
6
+ ? {}
7
+ : window);
8
+ async function getPhantomProvider({ timeout } = { timeout: 3000 }) {
9
+ const provider = getPhantomFromWindow();
10
+ if (provider) {
11
+ return provider;
12
+ }
13
+ return listenForPhantomInitialized({
14
+ timeout,
15
+ });
16
+ }
17
+ async function listenForPhantomInitialized({ timeout } = { timeout: 3000 }) {
18
+ return new Promise((resolve) => {
19
+ const handleInitialization = () => {
20
+ resolve(getPhantomFromWindow());
21
+ };
22
+ $window.addEventListener('phantom#initialized', handleInitialization, {
23
+ once: true,
24
+ });
25
+ setTimeout(() => {
26
+ $window.removeEventListener('phantom#initialized', handleInitialization);
27
+ resolve(null);
28
+ }, timeout);
29
+ });
30
+ }
31
+ function getPhantomFromWindow() {
32
+ const injectedProviderExist = typeof window !== 'undefined' &&
33
+ (typeof $window.ethereum !== 'undefined' ||
34
+ typeof $window.phantom !== 'undefined');
35
+ // No injected providers exist.
36
+ if (!injectedProviderExist) {
37
+ return;
38
+ }
39
+ if ($window.phantom) {
40
+ return $window.phantom.ethereum;
41
+ }
42
+ if ($window.ethereum.isPhantom) {
43
+ return $window.ethereum;
44
+ }
45
+ if ($window.providers) {
46
+ return $window.providers.find((p) => p.isPhantom);
47
+ }
48
+ return;
49
+ }
@@ -0,0 +1,4 @@
1
+ import type { BrowserEip1993Provider } from '@injectivelabs/wallet-base';
2
+ export declare function getRabbyProvider({ timeout }?: {
3
+ timeout: number;
4
+ }): Promise<BrowserEip1993Provider>;