@injectivelabs/wallet-base 1.20.8 → 1.20.9

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.
@@ -0,0 +1,473 @@
1
+ import { StdSignDoc } from "@keplr-wallet/types";
2
+ import { OfflineSigner } from "@cosmjs/proto-signing";
3
+ import { AccountAddress, ChainId, CosmosChainId, EvmChainId } from "@injectivelabs/ts-types";
4
+ import { TxClientInclusionOptions, TxResponse } from "@injectivelabs/sdk-ts/core/tx";
5
+ import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
6
+ import { EIP1193Provider } from "eip1193-provider";
7
+
8
+ //#region src/types/events.d.ts
9
+ declare const StrategyEventType: {
10
+ readonly ConnectionEnd: "connection-end";
11
+ readonly ConnectionStart: "connection-start";
12
+ readonly WalletSigningEnd: "wallet-signing-end";
13
+ readonly WalletSigningStart: "wallet-signing-start";
14
+ };
15
+ declare const WalletConnectStrategyEventType: {
16
+ readonly WalletConnectSigningWithTxTimeout: "signing-with-tx-timeout";
17
+ };
18
+ declare const WalletStrategyEmitterEventType: {
19
+ readonly TransactionFail: "transaction-fail";
20
+ readonly TransactionSigned: "transaction-signed";
21
+ readonly TransactionSignStart: "transaction-sign-start";
22
+ readonly TransactionBroadcastEnd: "transaction-broadcast-end";
23
+ readonly TransactionBroadcastStart: "transaction-broadcast-start";
24
+ readonly TransactionBroadcastSynced: "transaction-broadcast-synced";
25
+ readonly TransactionPreparationEnd: "transaction-preparation-end";
26
+ readonly TransactionPreparationStart: "transaction-preparation-start";
27
+ readonly WalletStrategyDisconnect: "wallet-strategy-disconnect";
28
+ };
29
+ type StrategyEventType = (typeof StrategyEventType)[keyof typeof StrategyEventType] | (typeof WalletConnectStrategyEventType)[keyof typeof WalletConnectStrategyEventType];
30
+ type WalletStrategyEmitterEventType = (typeof WalletStrategyEmitterEventType)[keyof typeof WalletStrategyEmitterEventType] | StrategyEventType;
31
+ type WalletStrategyEmitterEvents = { [K in WalletStrategyEmitterEventType]: Record<string, any> };
32
+ interface WalletStrategyEmitter {
33
+ on(event: WalletStrategyEmitterEventType, listener: (...args: any[]) => void): this;
34
+ off(event: WalletStrategyEmitterEventType, listener: (...args: any[]) => void): this;
35
+ emit(event: WalletStrategyEmitterEventType, ...args: any[]): boolean;
36
+ }
37
+ //#endregion
38
+ //#region src/types/enums.d.ts
39
+ declare const BroadcastMode: {
40
+ readonly Block: "block";
41
+ readonly Sync: "sync";
42
+ readonly Async: "async";
43
+ };
44
+ type BroadcastMode = (typeof BroadcastMode)[keyof typeof BroadcastMode];
45
+ declare const Wallet: {
46
+ readonly Leap: "leap";
47
+ readonly Keplr: "keplr";
48
+ readonly Ninji: "ninji";
49
+ readonly Magic: "magic";
50
+ readonly Rabby: "rabby";
51
+ readonly Ledger: "ledger";
52
+ readonly BitGet: "BitGet";
53
+ readonly OWallet: "owallet";
54
+ readonly Phantom: "phantom";
55
+ readonly Rainbow: "rainbow";
56
+ readonly Turnkey: "turnkey";
57
+ readonly Metamask: "metamask";
58
+ readonly KeplrEvm: "keplr-evm";
59
+ readonly OkxWallet: "okx-wallet";
60
+ readonly PrivateKey: "private-key";
61
+ readonly TrustWallet: "trust-wallet";
62
+ readonly TrezorBip32: "trezor-bip32";
63
+ readonly TrezorBip44: "trezor-bip44";
64
+ readonly Cosmostation: "cosmostation";
65
+ readonly LedgerCosmos: "ledger-cosmos";
66
+ readonly LedgerLegacy: "ledger-legacy";
67
+ readonly WalletConnect: "wallet-connect";
68
+ readonly CosmostationEth: "cosmostation-eth";
69
+ };
70
+ type Wallet = (typeof Wallet)[keyof typeof Wallet];
71
+ declare const MagicProvider: {
72
+ readonly Email: "email";
73
+ readonly Apple: "apple";
74
+ readonly Github: "github";
75
+ readonly Google: "google";
76
+ readonly Discord: "discord";
77
+ readonly Twitter: "twitter";
78
+ readonly Facebook: "facebook";
79
+ };
80
+ type MagicProvider = (typeof MagicProvider)[keyof typeof MagicProvider];
81
+ declare const WalletDeviceType: {
82
+ readonly Mobile: "mobile";
83
+ readonly Other: "other";
84
+ readonly Browser: "browser";
85
+ readonly Hardware: "hardware";
86
+ };
87
+ type WalletDeviceType = (typeof WalletDeviceType)[keyof typeof WalletDeviceType];
88
+ declare const WalletEventListener: {
89
+ readonly AccountChange: "account-change";
90
+ readonly ChainIdChange: "chain-id-change";
91
+ };
92
+ type WalletEventListener = (typeof WalletEventListener)[keyof typeof WalletEventListener];
93
+ declare const EvmWalletProviderErrorCode: {
94
+ readonly InternalError: -32603;
95
+ readonly UserRejectedRequest: 4001;
96
+ readonly UnrecognizedChain: 4902;
97
+ };
98
+ type EvmWalletProviderErrorCode = (typeof EvmWalletProviderErrorCode)[keyof typeof EvmWalletProviderErrorCode];
99
+ declare const WalletAction: {
100
+ GetChainId: "get-chain-id";
101
+ GetAccounts: "get-accounts";
102
+ GetNetworkId: "get-network-id";
103
+ SignArbitrary: "sign-arbitrary";
104
+ SignTransaction: "sign-transaction";
105
+ SendTransaction: "send-transaction";
106
+ SendEvmTransaction: "send-evm-transaction";
107
+ SignEvmTransaction: "sign-evm-transaction";
108
+ GetEvmTransactionReceipt: "get-evm-transaction-receipt";
109
+ };
110
+ //#endregion
111
+ //#region src/types/strategy.d.ts
112
+ interface StrategyEmitter {
113
+ emit(event: string, data?: Record<string, any>): boolean;
114
+ }
115
+ type onAccountChangeCallback = (account: string | string[]) => void;
116
+ type onChainIdChangeCallback = () => void;
117
+ type Eip1193Provider = {
118
+ request: (args: {
119
+ method: string;
120
+ params: any[];
121
+ }) => Promise<any>;
122
+ on: (event: string, listener: (...args: any[]) => void) => void;
123
+ removeListener: (event: string, listener: (...args: any[]) => void) => void;
124
+ };
125
+ type CosmosWalletAbstraction = {
126
+ enableGasCheck?(chainId: ChainId): Promise<void> | void;
127
+ disableGasCheck?(chainId: ChainId): Promise<void> | void;
128
+ signEIP712CosmosTx(args: {
129
+ signDoc: StdSignDoc;
130
+ eip712: any;
131
+ }): Promise<AminoSignResponse>;
132
+ };
133
+ type MagicMetadata = {
134
+ apiKey?: string;
135
+ rpcEndpoint?: string;
136
+ };
137
+ type PrivateKeyMetadata = {
138
+ privateKey: string;
139
+ };
140
+ type WalletConnectMetadata = {
141
+ projectId?: string;
142
+ };
143
+ interface WalletStrategyEvmOptions {
144
+ evmChainId: EvmChainId;
145
+ rpcUrl?: string;
146
+ rpcUrls?: Partial<Record<number, string>>;
147
+ }
148
+ interface SendTransactionOptions {
149
+ address: string;
150
+ chainId: ChainId;
151
+ txTimeout?: number;
152
+ txInclusion?: TxClientInclusionOptions;
153
+ onBroadcast?: (txHash: string) => void;
154
+ endpoints: {
155
+ rest: string;
156
+ grpc: string;
157
+ tm?: string;
158
+ };
159
+ }
160
+ declare const TurnkeyProvider: {
161
+ readonly Sms: "sms";
162
+ readonly Apple: "apple";
163
+ readonly Email: "email";
164
+ readonly Google: "google";
165
+ readonly Twitter: "twitter";
166
+ };
167
+ type TurnkeyProvider = (typeof TurnkeyProvider)[keyof typeof TurnkeyProvider];
168
+ type TurnkeyOAuthProvider = typeof TurnkeyProvider.Apple | typeof TurnkeyProvider.Google | typeof TurnkeyProvider.Twitter;
169
+ type TurnkeySession = {
170
+ sessionType: any;
171
+ userId: string;
172
+ organizationId: string;
173
+ expiry: number;
174
+ token: string;
175
+ };
176
+ interface TurnkeyMetadata {
177
+ apiBaseUrl: string;
178
+ otpInitPath?: string;
179
+ otpVerifyPath?: string;
180
+ googleClientId?: string;
181
+ oauthLoginPath?: string;
182
+ session?: TurnkeySession;
183
+ twitterClientId?: string;
184
+ apiServerEndpoint: string;
185
+ credentialBundle?: string;
186
+ googleRedirectUri?: string;
187
+ expirationSeconds?: string;
188
+ twitterRedirectUri?: string;
189
+ oauth2ExchangePath?: string;
190
+ defaultOrganizationId: string;
191
+ }
192
+ interface WalletMetadata {
193
+ magic?: MagicMetadata;
194
+ turnkey?: Partial<TurnkeyMetadata>;
195
+ walletConnect?: WalletConnectMetadata;
196
+ privateKey?: PrivateKeyMetadata;
197
+ derivationPath?: string;
198
+ baseDerivationPath?: string;
199
+ }
200
+ interface ConcreteWalletStrategyArgs {
201
+ chainId: ChainId;
202
+ metadata?: WalletMetadata;
203
+ emitter?: StrategyEmitter;
204
+ }
205
+ interface ConcreteEvmWalletStrategyArgs extends ConcreteWalletStrategyArgs {
206
+ evmOptions: WalletStrategyEvmOptions;
207
+ }
208
+ interface ConcreteCosmosWalletStrategyArgs extends ConcreteWalletStrategyArgs {
209
+ wallet?: Wallet;
210
+ }
211
+ interface ConcreteCosmosWalletStrategy {
212
+ metadata?: WalletMetadata;
213
+ setMetadata?(metadata?: WalletMetadata): void;
214
+ /**
215
+ * The accounts from the wallet (addresses)
216
+ */
217
+ getAddresses(args?: unknown): Promise<string[]>;
218
+ /**
219
+ * The accounts from the wallet with derivation path info (for hardware wallets)
220
+ */
221
+ getAddressesInfo(args?: unknown): Promise<{
222
+ address: string;
223
+ derivationPath: string;
224
+ baseDerivationPath: string;
225
+ }[]>;
226
+ /**
227
+ * Return the WalletDeviceType connected on the
228
+ * wallet provider (extension, mobile, hardware wallet)
229
+ */
230
+ getWalletDeviceType(): Promise<WalletDeviceType>;
231
+ /**
232
+ * Get the PubKey from the wallet
233
+ * in base64 for Cosmos native wallets
234
+ */
235
+ getPubKey(address?: string): Promise<string>;
236
+ /**
237
+ * Perform validations and checks
238
+ * for the wallet (if the chain is supported, etc)
239
+ */
240
+ enable(args?: unknown): Promise<boolean>;
241
+ /**
242
+ * Sends Cosmos transaction. Returns a transaction hash
243
+ * @param transaction should implement TransactionConfig
244
+ * @param options
245
+ */
246
+ sendTransaction(transaction: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
247
+ signCosmosTransaction(transaction: {
248
+ txRaw: TxRaw;
249
+ chainId: string;
250
+ accountNumber: number;
251
+ address: string;
252
+ }): Promise<DirectSignResponse>;
253
+ signAminoTransaction(transaction: {
254
+ stdSignDoc: StdSignDoc;
255
+ address: string;
256
+ }): Promise<AminoSignResponse>;
257
+ }
258
+ type ConcreteStrategiesArg = { [key in Wallet]?: ConcreteWalletStrategy };
259
+ interface WalletStrategyArguments {
260
+ chainId: ChainId;
261
+ metadata?: WalletMetadata;
262
+ evmOptions?: WalletStrategyEvmOptions;
263
+ disabledWallets?: Wallet[];
264
+ wallet?: Wallet;
265
+ strategies: ConcreteStrategiesArg;
266
+ }
267
+ interface ConcreteWalletStrategy extends Omit<ConcreteCosmosWalletStrategy, 'sendTransaction' | 'isChainIdSupported' | 'signAminoTransaction'> {
268
+ /**
269
+ * The accounts from the wallet with derivation path info (for hardware wallets)
270
+ */
271
+ getAddressesInfo(args?: unknown): Promise<{
272
+ address: string;
273
+ derivationPath: string;
274
+ baseDerivationPath: string;
275
+ }[]>;
276
+ /**
277
+ * Sends Cosmos transaction. Returns a transaction hash
278
+ * @param transaction should implement TransactionConfig
279
+ * @param options
280
+ */
281
+ sendTransaction(transaction: DirectSignResponse | TxRaw, options: {
282
+ address: string;
283
+ chainId: ChainId;
284
+ txTimeout?: number;
285
+ txInclusion?: TxClientInclusionOptions;
286
+ onBroadcast?: (txHash: string) => void;
287
+ endpoints?: {
288
+ rest: string;
289
+ grpc: string;
290
+ tm?: string;
291
+ };
292
+ }): Promise<TxResponse>;
293
+ /**
294
+ * Confirm the address on the wallet
295
+ * @param address address
296
+ */
297
+ getSessionOrConfirm(address?: string): Promise<string>;
298
+ /**
299
+ * Sends Ethereum transaction. Returns a transaction hash
300
+ * @param transaction should implement TransactionConfig
301
+ * @param options
302
+ */
303
+ sendEvmTransaction(transaction: unknown, options: {
304
+ address: string;
305
+ evmChainId: EvmChainId;
306
+ }): Promise<string>;
307
+ /**
308
+ * Sign a cosmos transaction using the wallet provider
309
+ *
310
+ * @param transaction
311
+ * @param address - injective address
312
+ */
313
+ signCosmosTransaction(transaction: {
314
+ txRaw: TxRaw;
315
+ accountNumber: number;
316
+ chainId: string;
317
+ address: string;
318
+ }): Promise<DirectSignResponse>;
319
+ /**
320
+ * Sign an amino sign doc using the wallet provider
321
+ *
322
+ * @param transaction
323
+ * @param address - injective address
324
+ */
325
+ signAminoCosmosTransaction(transaction: {
326
+ signDoc: StdSignDoc;
327
+ address: string;
328
+ }): Promise<AminoSignResponse>;
329
+ /**
330
+ * Sign EIP712 TypedData using the wallet provider
331
+ * @param eip712TypedData
332
+ * @param address - ethereum address
333
+ */
334
+ signEip712TypedData(eip712TypedData: string, address: string, options?: {
335
+ txTimeout?: number;
336
+ }): Promise<string>;
337
+ signArbitrary(signer: string, data: string | Uint8Array): Promise<string>;
338
+ getEthereumChainId(): Promise<string>;
339
+ getEvmTransactionReceipt(txHash: string, evmChainId?: EvmChainId): void;
340
+ onAccountChange?(callback: onAccountChangeCallback): Promise<void> | void;
341
+ onChainIdChange?(callback: onChainIdChangeCallback): Promise<void> | void;
342
+ initStrategy?(): Promise<void> | void;
343
+ disconnect?(): Promise<void> | void;
344
+ getCosmosWallet?(chainId: ChainId): CosmosWalletAbstraction;
345
+ getWalletClient?<T>(): Promise<T>;
346
+ getEip1193Provider?(): Promise<Eip1193Provider>;
347
+ getOfflineSigner?(chainId: string): Promise<OfflineSigner>;
348
+ }
349
+ interface WalletStrategy {
350
+ strategies: ConcreteStrategiesArg;
351
+ wallet: Wallet;
352
+ args: WalletStrategyArguments;
353
+ metadata?: WalletMetadata;
354
+ getWallet(): Wallet;
355
+ getWalletClient?<T>(): Promise<T>;
356
+ setWallet(wallet: Wallet): Promise<void>;
357
+ setMetadata(metadata?: WalletMetadata): void;
358
+ getStrategy(): ConcreteWalletStrategy;
359
+ getAddresses(args?: unknown): Promise<AccountAddress[]>;
360
+ getAddressesInfo(args?: unknown): Promise<{
361
+ address: string;
362
+ derivationPath: string;
363
+ baseDerivationPath: string;
364
+ }[]>;
365
+ getWalletDeviceType(): Promise<WalletDeviceType>;
366
+ getPubKey(address?: string): Promise<string>;
367
+ enable(args?: unknown): Promise<boolean>;
368
+ enableAndGetAddresses(args?: unknown): Promise<AccountAddress[]>;
369
+ getEthereumChainId(): Promise<string>;
370
+ getEvmTransactionReceipt(txHash: string, evmChainId?: EvmChainId): Promise<void>;
371
+ getSessionOrConfirm(address?: AccountAddress): Promise<string>;
372
+ sendTransaction(tx: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
373
+ sendEvmTransaction(tx: any, options: {
374
+ address: AccountAddress;
375
+ evmChainId: EvmChainId;
376
+ }): Promise<string>;
377
+ signEip712TypedData(eip712TypedData: string, address: AccountAddress, options?: {
378
+ txTimeout?: number;
379
+ }): Promise<string>;
380
+ signAminoCosmosTransaction(transaction: {
381
+ signDoc: StdSignDoc;
382
+ address: string;
383
+ }): Promise<AminoSignResponse>;
384
+ signCosmosTransaction(transaction: {
385
+ txRaw: TxRaw;
386
+ accountNumber: number;
387
+ chainId: string;
388
+ address: string;
389
+ }): Promise<DirectSignResponse>;
390
+ signArbitrary(signer: string, data: string | Uint8Array): Promise<string | void>;
391
+ onAccountChange(callback: onAccountChangeCallback): Promise<void>;
392
+ onChainIdChange(callback: onChainIdChangeCallback): Promise<void>;
393
+ disconnect(): Promise<void>;
394
+ getCosmosWallet?(chainId: ChainId): CosmosWalletAbstraction;
395
+ getEip1193Provider?(): Promise<Eip1193Provider>;
396
+ getOfflineSigner?(chainId: string): Promise<OfflineSigner>;
397
+ }
398
+ //#endregion
399
+ //#region src/types/provider.d.ts
400
+ interface BrowserEip1993Provider extends EIP1193Provider {
401
+ removeAllListeners(): void;
402
+ providers?: BrowserEip1993Provider[];
403
+ isTrust: boolean;
404
+ isKeplr: boolean;
405
+ isRabby: boolean;
406
+ isRainbow: boolean;
407
+ isPhantom: boolean;
408
+ isBitGet?: boolean;
409
+ isBitKeep?: boolean;
410
+ isMetaMask: boolean;
411
+ isOkxWallet: boolean;
412
+ isTrustWallet: boolean;
413
+ }
414
+ interface WindowWithEip1193Provider extends Omit<Window, 'ethereum' | 'keplr'> {
415
+ rainbow: BrowserEip1993Provider;
416
+ rabby: BrowserEip1993Provider;
417
+ ethereum: BrowserEip1993Provider;
418
+ okxwallet: BrowserEip1993Provider;
419
+ providers: BrowserEip1993Provider[];
420
+ trustWallet?: BrowserEip1993Provider;
421
+ bitkeep: {
422
+ ethereum: BrowserEip1993Provider;
423
+ };
424
+ phantom?: {
425
+ ethereum?: BrowserEip1993Provider;
426
+ };
427
+ keplr?: {
428
+ ethereum?: BrowserEip1993Provider;
429
+ };
430
+ }
431
+ interface EIP6963ProviderInfo {
432
+ rdns: string;
433
+ uuid: string;
434
+ name: string;
435
+ icon: string;
436
+ }
437
+ interface EIP6963ProviderDetail {
438
+ info: EIP6963ProviderInfo;
439
+ provider: BrowserEip1993Provider;
440
+ }
441
+ type EIP6963AnnounceProviderEvent = {
442
+ detail: EIP6963ProviderDetail;
443
+ };
444
+ //#endregion
445
+ //#region src/utils/wallet.d.ts
446
+ declare const isEvmWallet: (wallet: Wallet) => boolean;
447
+ declare const isCosmosWallet: (wallet: Wallet) => boolean;
448
+ declare const isEvmBrowserWallet: (wallet: Wallet) => boolean;
449
+ declare const isCosmosBrowserWallet: (wallet: Wallet) => boolean;
450
+ declare const isEip712V2OnlyWallet: (wallet: Wallet) => boolean;
451
+ declare const isCosmosAminoOnlyWallet: (wallet: Wallet) => boolean;
452
+ //#endregion
453
+ //#region src/base.d.ts
454
+ declare abstract class BaseConcreteStrategy {
455
+ protected chainId: ChainId | CosmosChainId;
456
+ protected evmChainId?: EvmChainId;
457
+ protected listeners: Partial<Record<WalletEventListener, any>>;
458
+ metadata?: WalletMetadata;
459
+ /**
460
+ * Optional emitter passed from parent WalletStrategy.
461
+ * When provided, strategies emit events directly on the parent's emitter.
462
+ */
463
+ protected emitter?: StrategyEmitter;
464
+ constructor(args: ConcreteWalletStrategyArgs | ConcreteEvmWalletStrategyArgs | ConcreteCosmosWalletStrategyArgs);
465
+ setMetadata(metadata?: WalletMetadata): void;
466
+ /**
467
+ * Emit an event from this strategy.
468
+ * If emitter was provided from parent, events go directly to parent.
469
+ */
470
+ protected emit(event: WalletStrategyEmitterEventType, data?: Record<string, any>): void;
471
+ }
472
+ //#endregion
473
+ export { WalletConnectMetadata as A, Wallet as B, SendTransactionOptions as C, TurnkeyOAuthProvider as D, TurnkeyMetadata as E, onAccountChangeCallback as F, WalletConnectStrategyEventType as G, WalletDeviceType as H, onChainIdChangeCallback as I, WalletStrategyEmitterEvents as J, WalletStrategyEmitter as K, BroadcastMode as L, WalletStrategy as M, WalletStrategyArguments as N, TurnkeyProvider as O, WalletStrategyEvmOptions as P, EvmWalletProviderErrorCode as R, PrivateKeyMetadata as S, StrategyEmitter as T, WalletEventListener as U, WalletAction as V, StrategyEventType as W, ConcreteWalletStrategy as _, isEip712V2OnlyWallet as a, Eip1193Provider as b, BrowserEip1993Provider as c, EIP6963ProviderInfo as d, WindowWithEip1193Provider as f, ConcreteStrategiesArg as g, ConcreteEvmWalletStrategyArgs as h, isCosmosWallet as i, WalletMetadata as j, TurnkeySession as k, EIP6963AnnounceProviderEvent as l, ConcreteCosmosWalletStrategyArgs as m, isCosmosAminoOnlyWallet as n, isEvmBrowserWallet as o, ConcreteCosmosWalletStrategy as p, WalletStrategyEmitterEventType as q, isCosmosBrowserWallet as r, isEvmWallet as s, BaseConcreteStrategy as t, EIP6963ProviderDetail as u, ConcreteWalletStrategyArgs as v, StdSignDoc as w, MagicMetadata as x, CosmosWalletAbstraction as y, MagicProvider as z };