@injectivelabs/wallet-core 1.20.8 → 1.20.10
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.
- package/dist/cjs/BaseWalletStrategy-Bvs5nQRI.d.cts +71 -0
- package/dist/cjs/broadcaster-CPCJe4Al.cjs +1076 -0
- package/dist/cjs/broadcaster.cjs +5 -0
- package/dist/cjs/broadcaster.d.cts +3 -0
- package/dist/cjs/defineProperty-CImP5zIM.cjs +49 -0
- package/dist/cjs/index-DLoAMD9J.d.cts +1 -0
- package/dist/cjs/index-NsR1NUse.d.cts +246 -0
- package/dist/cjs/index.cjs +8 -1260
- package/dist/cjs/index.d.cts +3 -309
- package/dist/cjs/strategy-D8mmr647.cjs +167 -0
- package/dist/cjs/strategy.cjs +4 -0
- package/dist/cjs/strategy.d.cts +3 -0
- package/dist/esm/BaseWalletStrategy-D2xNJmzo.d.ts +71 -0
- package/dist/esm/broadcaster-CA8Ix8IA.js +1059 -0
- package/dist/esm/broadcaster.d.ts +3 -0
- package/dist/esm/broadcaster.js +4 -0
- package/dist/esm/defineProperty-D4YE9KXX.js +43 -0
- package/dist/esm/index-B98CLRUl.d.ts +246 -0
- package/dist/esm/index-DRYular4.d.ts +1 -0
- package/dist/esm/index.d.ts +3 -309
- package/dist/esm/index.js +3 -1255
- package/dist/esm/strategy-DU-V-GfI.js +162 -0
- package/dist/esm/strategy.d.ts +3 -0
- package/dist/esm/strategy.js +4 -0
- package/package.json +47 -7
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,314 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { AccountAddress, ChainId, EvmChainId } from "@injectivelabs/ts-types";
|
|
5
|
-
import { TxClientInclusionOptions, TxResponse } from "@injectivelabs/sdk-ts/core/tx";
|
|
6
|
-
import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
|
|
7
|
-
import { Msgs } from "@injectivelabs/sdk-ts/core/modules";
|
|
8
|
-
import { Network, NetworkEndpoints } from "@injectivelabs/networks";
|
|
9
|
-
import { AuthBaseAccount } from "@injectivelabs/sdk-ts/client/chain";
|
|
1
|
+
import { t as BaseWalletStrategy } from "./BaseWalletStrategy-Bvs5nQRI.cjs";
|
|
2
|
+
import { a as MsgBroadcasterTxOptionsWithAddresses, i as MsgBroadcasterTxOptions, n as MsgBroadcaster, r as MsgBroadcasterOptions, t as Web3Broadcaster } from "./index-NsR1NUse.cjs";
|
|
3
|
+
import "./index-DLoAMD9J.cjs";
|
|
10
4
|
|
|
11
5
|
//#region src/utils/tx.d.ts
|
|
12
6
|
declare const checkIfTxRunOutOfGas: (e: unknown) => boolean;
|
|
13
7
|
//#endregion
|
|
14
|
-
//#region src/strategy/BaseWalletStrategy.d.ts
|
|
15
|
-
declare class BaseWalletStrategy implements WalletStrategy {
|
|
16
|
-
strategies: ConcreteStrategiesArg;
|
|
17
|
-
wallet: Wallet;
|
|
18
|
-
args: WalletStrategyArguments;
|
|
19
|
-
metadata?: WalletMetadata;
|
|
20
|
-
wallets?: Wallet[];
|
|
21
|
-
private emitter;
|
|
22
|
-
on: WalletStrategyEmitter['on'];
|
|
23
|
-
off: WalletStrategyEmitter['off'];
|
|
24
|
-
emit: WalletStrategyEmitter['emit'];
|
|
25
|
-
constructor(args: WalletStrategyArguments);
|
|
26
|
-
/**
|
|
27
|
-
* Get the emitter instance.
|
|
28
|
-
* Used to pass to strategies so they can emit events directly.
|
|
29
|
-
*/
|
|
30
|
-
getEmitter(): WalletStrategyEmitter;
|
|
31
|
-
getWallet(): Wallet;
|
|
32
|
-
setWallet(wallet: Wallet): Promise<void>;
|
|
33
|
-
setMetadata(metadata?: WalletMetadata): void;
|
|
34
|
-
getStrategy(): ConcreteWalletStrategy;
|
|
35
|
-
getAddresses(args?: unknown): Promise<AccountAddress[]>;
|
|
36
|
-
getAddressesInfo(args?: unknown): Promise<{
|
|
37
|
-
address: string;
|
|
38
|
-
derivationPath: string;
|
|
39
|
-
baseDerivationPath: string;
|
|
40
|
-
}[]>;
|
|
41
|
-
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
42
|
-
getPubKey(address?: string): Promise<string>;
|
|
43
|
-
enable(args?: unknown): Promise<boolean>;
|
|
44
|
-
enableAndGetAddresses(args?: unknown): Promise<AccountAddress[]>;
|
|
45
|
-
getEthereumChainId(): Promise<string>;
|
|
46
|
-
getEvmTransactionReceipt(txHash: string, evmChainId?: EvmChainId): Promise<void>;
|
|
47
|
-
getSessionOrConfirm(address?: AccountAddress): Promise<string>;
|
|
48
|
-
getWalletClient<T>(): Promise<T>;
|
|
49
|
-
sendTransaction(tx: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
|
|
50
|
-
sendEvmTransaction(tx: any, options: {
|
|
51
|
-
evmChainId: EvmChainId;
|
|
52
|
-
address: AccountAddress;
|
|
53
|
-
}): Promise<string>;
|
|
54
|
-
signEip712TypedData(eip712TypedData: string, address: AccountAddress, options?: {
|
|
55
|
-
txTimeout?: number;
|
|
56
|
-
}): Promise<string>;
|
|
57
|
-
signAminoCosmosTransaction(transaction: {
|
|
58
|
-
signDoc: StdSignDoc;
|
|
59
|
-
address: string;
|
|
60
|
-
}): Promise<AminoSignResponse>;
|
|
61
|
-
signCosmosTransaction(transaction: {
|
|
62
|
-
txRaw: TxRaw;
|
|
63
|
-
accountNumber: number;
|
|
64
|
-
chainId: string;
|
|
65
|
-
address: string;
|
|
66
|
-
}): Promise<DirectSignResponse>;
|
|
67
|
-
signArbitrary(signer: string, data: string | Uint8Array): Promise<string | void>;
|
|
68
|
-
onAccountChange(callback: onAccountChangeCallback): Promise<void>;
|
|
69
|
-
onChainIdChange(callback: onChainIdChangeCallback): Promise<void>;
|
|
70
|
-
disconnect(): Promise<void>;
|
|
71
|
-
getCosmosWallet(chainId: ChainId): CosmosWalletAbstraction;
|
|
72
|
-
getEip1193Provider(): Promise<Eip1193Provider>;
|
|
73
|
-
getOfflineSigner(chainId: string): Promise<OfflineSigner>;
|
|
74
|
-
}
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/broadcaster/types.d.ts
|
|
77
|
-
interface MsgBroadcasterTxOptions {
|
|
78
|
-
memo?: string;
|
|
79
|
-
msgs: Msgs | Msgs[];
|
|
80
|
-
ethereumAddress?: string;
|
|
81
|
-
injectiveAddress?: string;
|
|
82
|
-
accountDetails?: AuthBaseAccount;
|
|
83
|
-
txTimeoutInBlocks?: number;
|
|
84
|
-
txInclusion?: TxClientInclusionOptions;
|
|
85
|
-
gas?: {
|
|
86
|
-
gasPrice?: string;
|
|
87
|
-
gas?: number; /** gas limit */
|
|
88
|
-
feePayer?: string;
|
|
89
|
-
granter?: string;
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
interface MsgBroadcasterTxOptionsWithAddresses extends MsgBroadcasterTxOptions {
|
|
93
|
-
ethereumAddress: string;
|
|
94
|
-
injectiveAddress: string;
|
|
95
|
-
}
|
|
96
|
-
interface MsgBroadcasterOptions {
|
|
97
|
-
network: Network;
|
|
98
|
-
endpoints?: NetworkEndpoints;
|
|
99
|
-
chainId?: ChainId;
|
|
100
|
-
evmChainId?: EvmChainId;
|
|
101
|
-
feePayerPubKey?: string;
|
|
102
|
-
simulateTx?: boolean;
|
|
103
|
-
txTimeoutOnFeeDelegation?: boolean;
|
|
104
|
-
txTimeout?: number;
|
|
105
|
-
txInclusion?: TxClientInclusionOptions;
|
|
106
|
-
walletStrategy: BaseWalletStrategy;
|
|
107
|
-
gasBufferCoefficient?: number;
|
|
108
|
-
httpHeaders?: Record<string, string>;
|
|
109
|
-
}
|
|
110
|
-
//#endregion
|
|
111
|
-
//#region src/broadcaster/MsgBroadcaster.d.ts
|
|
112
|
-
/**
|
|
113
|
-
* This class is used to broadcast transactions
|
|
114
|
-
* using the WalletStrategy as a handler
|
|
115
|
-
* for the sign/broadcast flow of the transactions
|
|
116
|
-
*
|
|
117
|
-
* Mainly used for building UI products
|
|
118
|
-
*/
|
|
119
|
-
declare class MsgBroadcaster {
|
|
120
|
-
options: MsgBroadcasterOptions;
|
|
121
|
-
walletStrategy: BaseWalletStrategy;
|
|
122
|
-
endpoints: NetworkEndpoints;
|
|
123
|
-
chainId: ChainId;
|
|
124
|
-
txTimeout: number;
|
|
125
|
-
simulateTx: boolean;
|
|
126
|
-
txTimeoutOnFeeDelegation: boolean;
|
|
127
|
-
evmChainId?: EvmChainId;
|
|
128
|
-
gasBufferCoefficient: number;
|
|
129
|
-
retriesOnError: {
|
|
130
|
-
[x: string]: {
|
|
131
|
-
retries: number;
|
|
132
|
-
maxRetries: number;
|
|
133
|
-
timeout: number;
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
httpHeaders?: Record<string, string>;
|
|
137
|
-
txInclusion?: TxClientInclusionOptions;
|
|
138
|
-
constructor(options: MsgBroadcasterOptions);
|
|
139
|
-
setOptions(options: Partial<MsgBroadcasterOptions>): void;
|
|
140
|
-
getEvmChainId(): Promise<EvmChainId | undefined>;
|
|
141
|
-
/**
|
|
142
|
-
* Broadcasting the transaction using the client
|
|
143
|
-
* side approach for both cosmos and ethereum native wallets
|
|
144
|
-
*
|
|
145
|
-
* @param tx
|
|
146
|
-
* @returns {string} transaction hash
|
|
147
|
-
*/
|
|
148
|
-
broadcast(tx: MsgBroadcasterTxOptions): Promise<TxResponse>;
|
|
149
|
-
/**
|
|
150
|
-
* Broadcasting the transaction using the client
|
|
151
|
-
* side approach for both cosmos and ethereum native wallets
|
|
152
|
-
* Note: using EIP712_V2 for Ethereum wallets
|
|
153
|
-
*
|
|
154
|
-
* @param tx
|
|
155
|
-
* @returns {string} transaction hash
|
|
156
|
-
*/
|
|
157
|
-
broadcastV2(tx: MsgBroadcasterTxOptions): Promise<TxResponse>;
|
|
158
|
-
/**
|
|
159
|
-
* Broadcasting the transaction using the feeDelegation
|
|
160
|
-
* support approach for both cosmos and ethereum native wallets
|
|
161
|
-
*
|
|
162
|
-
* @param tx
|
|
163
|
-
* @returns {string} transaction hash
|
|
164
|
-
*/
|
|
165
|
-
broadcastWithFeeDelegation(tx: MsgBroadcasterTxOptions): Promise<TxResponse>;
|
|
166
|
-
/**
|
|
167
|
-
* Sign and broadcast a pre-built transaction whose fee payer signature
|
|
168
|
-
* is already provided (e.g. from the RFQ executor / web3-gw `prepare`
|
|
169
|
-
* endpoint). The taker is signed locally with the supplied private key.
|
|
170
|
-
*
|
|
171
|
-
* Autosign-only: the caller passes the autosign private key directly
|
|
172
|
-
* (e.g. `sharedWalletStore.autoSign.privateKey`). We don't go through
|
|
173
|
-
* `walletStrategy.signCosmosTransaction` because the PK strategy stubs
|
|
174
|
-
* that out — and going through the wallet strategy would defeat the
|
|
175
|
-
* point of autosign (no popups).
|
|
176
|
-
*
|
|
177
|
-
* @param tx Base64-encoded or raw `TxRaw` bytes returned by the prepare endpoint
|
|
178
|
-
* @param feePayerSig Hex (`0x...`) or base64 fee payer signature
|
|
179
|
-
* @param accountNumber Account number of the taker
|
|
180
|
-
* @param privateKey Taker (autosign) private key — hex, with or without `0x`
|
|
181
|
-
* @returns transaction response with txHash
|
|
182
|
-
*/
|
|
183
|
-
broadcastWithFeePayerSig({
|
|
184
|
-
tx,
|
|
185
|
-
privateKey,
|
|
186
|
-
feePayerSig,
|
|
187
|
-
accountNumber,
|
|
188
|
-
txInclusion,
|
|
189
|
-
txTimeoutInBlocks: txTimeoutInBlocksParam
|
|
190
|
-
}: {
|
|
191
|
-
privateKey: string;
|
|
192
|
-
feePayerSig: string;
|
|
193
|
-
accountNumber: number;
|
|
194
|
-
tx: Uint8Array | string;
|
|
195
|
-
txInclusion?: TxClientInclusionOptions;
|
|
196
|
-
txTimeoutInBlocks?: number;
|
|
197
|
-
}): Promise<TxResponse>;
|
|
198
|
-
/**
|
|
199
|
-
* Prepare/sign/broadcast transaction using
|
|
200
|
-
* Ethereum native wallets on the client side.
|
|
201
|
-
*
|
|
202
|
-
* Note: Gas estimation not available
|
|
203
|
-
*
|
|
204
|
-
* @param tx The transaction that needs to be broadcasted
|
|
205
|
-
* @returns transaction hash
|
|
206
|
-
*/
|
|
207
|
-
private broadcastEip712;
|
|
208
|
-
/**
|
|
209
|
-
* Prepare/sign/broadcast transaction using
|
|
210
|
-
* Ethereum native wallets on the client side.
|
|
211
|
-
*
|
|
212
|
-
* Note: Gas estimation not available
|
|
213
|
-
*
|
|
214
|
-
* @param tx The transaction that needs to be broadcasted
|
|
215
|
-
* @returns transaction hash
|
|
216
|
-
*/
|
|
217
|
-
private broadcastEip712V2;
|
|
218
|
-
/**
|
|
219
|
-
* Prepare/sign/broadcast transaction using
|
|
220
|
-
* Ethereum native wallets using the Web3Gateway.
|
|
221
|
-
*
|
|
222
|
-
* @param tx The transaction that needs to be broadcasted
|
|
223
|
-
* @returns transaction hash
|
|
224
|
-
*/
|
|
225
|
-
private broadcastEip712WithFeeDelegation;
|
|
226
|
-
/**
|
|
227
|
-
* Prepare/sign/broadcast transaction using
|
|
228
|
-
* Cosmos native wallets on the client side.
|
|
229
|
-
*
|
|
230
|
-
* @param tx The transaction that needs to be broadcasted
|
|
231
|
-
* @returns transaction hash
|
|
232
|
-
*/
|
|
233
|
-
private broadcastDirectSign;
|
|
234
|
-
/**
|
|
235
|
-
* We use this method only when we want to broadcast a transaction using Ledger on Keplr/Leap for Injective
|
|
236
|
-
*
|
|
237
|
-
* Note: Gas estimation not available
|
|
238
|
-
* @param tx the transaction that needs to be broadcasted
|
|
239
|
-
*/
|
|
240
|
-
private experimentalBroadcastWalletThroughLedger;
|
|
241
|
-
/**
|
|
242
|
-
* Prepare/sign/broadcast transaction using
|
|
243
|
-
* Cosmos native wallets using the Web3Gateway.
|
|
244
|
-
*
|
|
245
|
-
* @param tx The transaction that needs to be broadcasted
|
|
246
|
-
* @returns transaction hash
|
|
247
|
-
*/
|
|
248
|
-
private broadcastDirectSignWithFeeDelegation;
|
|
249
|
-
/**
|
|
250
|
-
* Fetch the fee payer's pub key from the web3 gateway
|
|
251
|
-
*
|
|
252
|
-
* Returns a base64 version of it
|
|
253
|
-
*/
|
|
254
|
-
private fetchFeePayerPubKey;
|
|
255
|
-
private getStdFeeWithDynamicBaseFee;
|
|
256
|
-
/**
|
|
257
|
-
* In case we don't want to simulate the transaction
|
|
258
|
-
* we get the gas limit based on the message type.
|
|
259
|
-
*
|
|
260
|
-
* If we want to simulate the transaction we set the
|
|
261
|
-
* gas limit based on the simulation and add a small multiplier
|
|
262
|
-
* to be safe (factor of 1.2 as default)
|
|
263
|
-
*/
|
|
264
|
-
private getTxWithSignersAndStdFee;
|
|
265
|
-
/**
|
|
266
|
-
* Create TxRaw and simulate it
|
|
267
|
-
*/
|
|
268
|
-
private simulateTxRaw;
|
|
269
|
-
/**
|
|
270
|
-
* Create TxRaw and simulate it
|
|
271
|
-
*/
|
|
272
|
-
private simulateTxWithSigners;
|
|
273
|
-
private retryOnException;
|
|
274
|
-
private fetchAccountAndBlockDetails;
|
|
275
|
-
private resolveTimeoutInBlocks;
|
|
276
|
-
private resolveTxInclusionOptions;
|
|
277
|
-
private createTxGrpcApi;
|
|
278
|
-
private waitForTxInclusion;
|
|
279
|
-
private prepareTxInclusionWaiter;
|
|
280
|
-
private waitForPreparedTxInclusion;
|
|
281
|
-
}
|
|
282
|
-
//#endregion
|
|
283
|
-
//#region src/broadcaster/Web3Broadcaster.d.ts
|
|
284
|
-
interface SendTransactionOptions$1 {
|
|
285
|
-
tx: {
|
|
286
|
-
from: string;
|
|
287
|
-
to: string;
|
|
288
|
-
gas: string;
|
|
289
|
-
maxFeePerGas: string;
|
|
290
|
-
maxPriorityFeePerGas: string | null;
|
|
291
|
-
data: any;
|
|
292
|
-
};
|
|
293
|
-
address: string;
|
|
294
|
-
evmChainId?: EvmChainId;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Preparing and broadcasting
|
|
298
|
-
* Ethereum transactions
|
|
299
|
-
*/
|
|
300
|
-
declare class Web3Broadcaster {
|
|
301
|
-
private walletStrategy;
|
|
302
|
-
private evmChainId;
|
|
303
|
-
constructor({
|
|
304
|
-
walletStrategy,
|
|
305
|
-
evmChainId
|
|
306
|
-
}: {
|
|
307
|
-
walletStrategy: BaseWalletStrategy;
|
|
308
|
-
evmChainId: EvmChainId;
|
|
309
|
-
network: Network;
|
|
310
|
-
});
|
|
311
|
-
sendTransaction(args: SendTransactionOptions$1): Promise<string>;
|
|
312
|
-
}
|
|
313
|
-
//#endregion
|
|
314
8
|
export { BaseWalletStrategy, MsgBroadcaster, MsgBroadcasterOptions, MsgBroadcasterTxOptions, MsgBroadcasterTxOptionsWithAddresses, Web3Broadcaster, checkIfTxRunOutOfGas };
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const require_defineProperty = require('./defineProperty-CImP5zIM.cjs');
|
|
2
|
+
let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
|
|
3
|
+
let eventemitter3 = require("eventemitter3");
|
|
4
|
+
let __injectivelabs_wallet_base_light = require("@injectivelabs/wallet-base/light");
|
|
5
|
+
|
|
6
|
+
//#region src/strategy/BaseWalletStrategy.ts
|
|
7
|
+
const getInitialWallet = (args) => {
|
|
8
|
+
if (args.wallet) return args.wallet;
|
|
9
|
+
const keys = Object.keys(args.strategies || {});
|
|
10
|
+
if (keys.length === 0) return __injectivelabs_wallet_base_light.Wallet.Metamask;
|
|
11
|
+
if (keys.includes(__injectivelabs_wallet_base_light.Wallet.Metamask) && args.evmOptions) return __injectivelabs_wallet_base_light.Wallet.Metamask;
|
|
12
|
+
if (keys.includes(__injectivelabs_wallet_base_light.Wallet.Keplr) && !args.evmOptions) return __injectivelabs_wallet_base_light.Wallet.Keplr;
|
|
13
|
+
return keys[0];
|
|
14
|
+
};
|
|
15
|
+
var BaseWalletStrategy = class {
|
|
16
|
+
constructor(args) {
|
|
17
|
+
require_defineProperty._defineProperty(this, "strategies", void 0);
|
|
18
|
+
require_defineProperty._defineProperty(this, "wallet", void 0);
|
|
19
|
+
require_defineProperty._defineProperty(this, "args", void 0);
|
|
20
|
+
require_defineProperty._defineProperty(this, "metadata", void 0);
|
|
21
|
+
require_defineProperty._defineProperty(this, "wallets", void 0);
|
|
22
|
+
require_defineProperty._defineProperty(this, "emitter", void 0);
|
|
23
|
+
require_defineProperty._defineProperty(this, "on", void 0);
|
|
24
|
+
require_defineProperty._defineProperty(this, "off", void 0);
|
|
25
|
+
require_defineProperty._defineProperty(this, "emit", void 0);
|
|
26
|
+
this.args = args;
|
|
27
|
+
this.strategies = args.strategies;
|
|
28
|
+
this.wallet = getInitialWallet(args);
|
|
29
|
+
this.metadata = args.metadata;
|
|
30
|
+
this.emitter = new eventemitter3.EventEmitter();
|
|
31
|
+
this.on = this.emitter.on.bind(this.emitter);
|
|
32
|
+
this.off = this.emitter.off.bind(this.emitter);
|
|
33
|
+
this.emit = this.emitter.emit.bind(this.emitter);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the emitter instance.
|
|
37
|
+
* Used to pass to strategies so they can emit events directly.
|
|
38
|
+
*/
|
|
39
|
+
getEmitter() {
|
|
40
|
+
return this.emitter;
|
|
41
|
+
}
|
|
42
|
+
getWallet() {
|
|
43
|
+
return this.wallet;
|
|
44
|
+
}
|
|
45
|
+
async setWallet(wallet) {
|
|
46
|
+
var _strategy$initStrateg;
|
|
47
|
+
this.wallet = wallet;
|
|
48
|
+
const strategy = this.getStrategy();
|
|
49
|
+
await (strategy === null || strategy === void 0 || (_strategy$initStrateg = strategy.initStrategy) === null || _strategy$initStrateg === void 0 ? void 0 : _strategy$initStrateg.call(strategy));
|
|
50
|
+
}
|
|
51
|
+
setMetadata(metadata) {
|
|
52
|
+
var _this$getStrategy$set, _this$getStrategy;
|
|
53
|
+
this.metadata = metadata;
|
|
54
|
+
(_this$getStrategy$set = (_this$getStrategy = this.getStrategy()).setMetadata) === null || _this$getStrategy$set === void 0 || _this$getStrategy$set.call(_this$getStrategy, metadata);
|
|
55
|
+
}
|
|
56
|
+
getStrategy() {
|
|
57
|
+
if (!this.strategies[this.wallet]) throw new __injectivelabs_exceptions.GeneralException(/* @__PURE__ */ new Error(`Wallet ${this.wallet} is not enabled/available!`));
|
|
58
|
+
return this.strategies[this.wallet];
|
|
59
|
+
}
|
|
60
|
+
getAddresses(args) {
|
|
61
|
+
return this.getStrategy().getAddresses(args);
|
|
62
|
+
}
|
|
63
|
+
getAddressesInfo(args) {
|
|
64
|
+
return this.getStrategy().getAddressesInfo(args);
|
|
65
|
+
}
|
|
66
|
+
getWalletDeviceType() {
|
|
67
|
+
return this.getStrategy().getWalletDeviceType();
|
|
68
|
+
}
|
|
69
|
+
getPubKey(address) {
|
|
70
|
+
return this.getStrategy().getPubKey(address);
|
|
71
|
+
}
|
|
72
|
+
enable(args) {
|
|
73
|
+
return this.getStrategy().enable(args);
|
|
74
|
+
}
|
|
75
|
+
async enableAndGetAddresses(args) {
|
|
76
|
+
await this.getStrategy().enable(args);
|
|
77
|
+
return this.getStrategy().getAddresses(args);
|
|
78
|
+
}
|
|
79
|
+
getEthereumChainId() {
|
|
80
|
+
return this.getStrategy().getEthereumChainId();
|
|
81
|
+
}
|
|
82
|
+
async getEvmTransactionReceipt(txHash, evmChainId) {
|
|
83
|
+
return this.getStrategy().getEvmTransactionReceipt(txHash, evmChainId);
|
|
84
|
+
}
|
|
85
|
+
async getSessionOrConfirm(address) {
|
|
86
|
+
return this.getStrategy().getSessionOrConfirm(address);
|
|
87
|
+
}
|
|
88
|
+
async getWalletClient() {
|
|
89
|
+
var _this$getStrategy2;
|
|
90
|
+
if ((_this$getStrategy2 = this.getStrategy()) === null || _this$getStrategy2 === void 0 ? void 0 : _this$getStrategy2.getWalletClient) {
|
|
91
|
+
var _this$getStrategy3, _this$getStrategy3$ge;
|
|
92
|
+
const result = (_this$getStrategy3 = this.getStrategy()) === null || _this$getStrategy3 === void 0 || (_this$getStrategy3$ge = _this$getStrategy3.getWalletClient) === null || _this$getStrategy3$ge === void 0 ? void 0 : _this$getStrategy3$ge.call(_this$getStrategy3);
|
|
93
|
+
if (result) return result;
|
|
94
|
+
}
|
|
95
|
+
throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("Wallet client not found. Please check your wallet strategy."));
|
|
96
|
+
}
|
|
97
|
+
async sendTransaction(tx, options) {
|
|
98
|
+
return this.getStrategy().sendTransaction(tx, options);
|
|
99
|
+
}
|
|
100
|
+
async sendEvmTransaction(tx, options) {
|
|
101
|
+
return this.getStrategy().sendEvmTransaction(tx, options);
|
|
102
|
+
}
|
|
103
|
+
async signEip712TypedData(eip712TypedData, address, options = {}) {
|
|
104
|
+
if ((0, __injectivelabs_wallet_base_light.isCosmosWallet)(this.wallet)) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error(`You can't sign Ethereum Transaction using ${this.wallet}`));
|
|
105
|
+
/** Phantom wallet needs enabling before signing */
|
|
106
|
+
if (this.wallet === __injectivelabs_wallet_base_light.Wallet.Phantom) await this.enable();
|
|
107
|
+
this.emit(__injectivelabs_wallet_base_light.WalletStrategyEmitterEventType.TransactionSignStart);
|
|
108
|
+
const response = await this.getStrategy().signEip712TypedData(eip712TypedData, address, options);
|
|
109
|
+
this.emit(__injectivelabs_wallet_base_light.WalletStrategyEmitterEventType.TransactionSigned);
|
|
110
|
+
return response;
|
|
111
|
+
}
|
|
112
|
+
async signAminoCosmosTransaction(transaction) {
|
|
113
|
+
if ((0, __injectivelabs_wallet_base_light.isEvmWallet)(this.wallet)) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error(`You can't sign Cosmos Transaction using ${this.wallet}`));
|
|
114
|
+
this.emit(__injectivelabs_wallet_base_light.WalletStrategyEmitterEventType.TransactionSignStart);
|
|
115
|
+
const response = await this.getStrategy().signAminoCosmosTransaction(transaction);
|
|
116
|
+
this.emit(__injectivelabs_wallet_base_light.WalletStrategyEmitterEventType.TransactionSigned);
|
|
117
|
+
return response;
|
|
118
|
+
}
|
|
119
|
+
async signCosmosTransaction(transaction) {
|
|
120
|
+
if ((0, __injectivelabs_wallet_base_light.isEvmWallet)(this.wallet)) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error(`You can't sign Cosmos Transaction using ${this.wallet}`));
|
|
121
|
+
this.emit(__injectivelabs_wallet_base_light.WalletStrategyEmitterEventType.TransactionSignStart);
|
|
122
|
+
const response = await this.getStrategy().signCosmosTransaction(transaction);
|
|
123
|
+
this.emit(__injectivelabs_wallet_base_light.WalletStrategyEmitterEventType.TransactionSigned);
|
|
124
|
+
return response;
|
|
125
|
+
}
|
|
126
|
+
async signArbitrary(signer, data) {
|
|
127
|
+
if (this.getStrategy().signArbitrary) {
|
|
128
|
+
this.emit(__injectivelabs_wallet_base_light.WalletStrategyEmitterEventType.TransactionSignStart);
|
|
129
|
+
const response = await this.getStrategy().signArbitrary(signer, data);
|
|
130
|
+
this.emit(__injectivelabs_wallet_base_light.WalletStrategyEmitterEventType.TransactionSigned);
|
|
131
|
+
return response;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async onAccountChange(callback) {
|
|
135
|
+
if (this.getStrategy().onAccountChange) return this.getStrategy().onAccountChange(callback);
|
|
136
|
+
}
|
|
137
|
+
async onChainIdChange(callback) {
|
|
138
|
+
if (this.getStrategy().onChainIdChange) return this.getStrategy().onChainIdChange(callback);
|
|
139
|
+
}
|
|
140
|
+
async disconnect() {
|
|
141
|
+
if (this.getStrategy().disconnect) {
|
|
142
|
+
await this.getStrategy().disconnect();
|
|
143
|
+
this.emit(__injectivelabs_wallet_base_light.WalletStrategyEmitterEventType.WalletStrategyDisconnect);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
getCosmosWallet(chainId) {
|
|
147
|
+
const strategy = this.getStrategy();
|
|
148
|
+
if (strategy.getCosmosWallet == void 0) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error(`This method is not available for ${this.getWallet()} wallet`));
|
|
149
|
+
return strategy.getCosmosWallet(chainId);
|
|
150
|
+
}
|
|
151
|
+
async getEip1193Provider() {
|
|
152
|
+
if (this.getStrategy().getEip1193Provider) return this.getStrategy().getEip1193Provider();
|
|
153
|
+
throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("EIP1193 provider not found. Please check your wallet strategy."));
|
|
154
|
+
}
|
|
155
|
+
async getOfflineSigner(chainId) {
|
|
156
|
+
if (this.getStrategy().getOfflineSigner) return this.getStrategy().getOfflineSigner(chainId);
|
|
157
|
+
throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("Offline signer not found. Please check your wallet strategy."));
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
//#endregion
|
|
162
|
+
Object.defineProperty(exports, 'BaseWalletStrategy', {
|
|
163
|
+
enumerable: true,
|
|
164
|
+
get: function () {
|
|
165
|
+
return BaseWalletStrategy;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ConcreteStrategiesArg, ConcreteWalletStrategy, CosmosWalletAbstraction, Eip1193Provider, SendTransactionOptions, Wallet, WalletDeviceType, WalletMetadata, WalletStrategy, WalletStrategyArguments, WalletStrategyEmitter, onAccountChangeCallback, onChainIdChangeCallback } from "@injectivelabs/wallet-base/light";
|
|
2
|
+
import { AccountAddress, ChainId, EvmChainId } from "@injectivelabs/ts-types";
|
|
3
|
+
import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
|
|
4
|
+
import { StdSignDoc } from "@keplr-wallet/types";
|
|
5
|
+
import { OfflineSigner } from "@cosmjs/proto-signing";
|
|
6
|
+
import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
|
|
7
|
+
|
|
8
|
+
//#region src/strategy/BaseWalletStrategy.d.ts
|
|
9
|
+
|
|
10
|
+
declare class BaseWalletStrategy implements WalletStrategy {
|
|
11
|
+
strategies: ConcreteStrategiesArg;
|
|
12
|
+
wallet: Wallet;
|
|
13
|
+
args: WalletStrategyArguments;
|
|
14
|
+
metadata?: WalletMetadata;
|
|
15
|
+
wallets?: Wallet[];
|
|
16
|
+
private emitter;
|
|
17
|
+
on: WalletStrategyEmitter['on'];
|
|
18
|
+
off: WalletStrategyEmitter['off'];
|
|
19
|
+
emit: WalletStrategyEmitter['emit'];
|
|
20
|
+
constructor(args: WalletStrategyArguments);
|
|
21
|
+
/**
|
|
22
|
+
* Get the emitter instance.
|
|
23
|
+
* Used to pass to strategies so they can emit events directly.
|
|
24
|
+
*/
|
|
25
|
+
getEmitter(): WalletStrategyEmitter;
|
|
26
|
+
getWallet(): Wallet;
|
|
27
|
+
setWallet(wallet: Wallet): Promise<void>;
|
|
28
|
+
setMetadata(metadata?: WalletMetadata): void;
|
|
29
|
+
getStrategy(): ConcreteWalletStrategy;
|
|
30
|
+
getAddresses(args?: unknown): Promise<AccountAddress[]>;
|
|
31
|
+
getAddressesInfo(args?: unknown): Promise<{
|
|
32
|
+
address: string;
|
|
33
|
+
derivationPath: string;
|
|
34
|
+
baseDerivationPath: string;
|
|
35
|
+
}[]>;
|
|
36
|
+
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
37
|
+
getPubKey(address?: string): Promise<string>;
|
|
38
|
+
enable(args?: unknown): Promise<boolean>;
|
|
39
|
+
enableAndGetAddresses(args?: unknown): Promise<AccountAddress[]>;
|
|
40
|
+
getEthereumChainId(): Promise<string>;
|
|
41
|
+
getEvmTransactionReceipt(txHash: string, evmChainId?: EvmChainId): Promise<void>;
|
|
42
|
+
getSessionOrConfirm(address?: AccountAddress): Promise<string>;
|
|
43
|
+
getWalletClient<T>(): Promise<T>;
|
|
44
|
+
sendTransaction(tx: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
|
|
45
|
+
sendEvmTransaction(tx: any, options: {
|
|
46
|
+
evmChainId: EvmChainId;
|
|
47
|
+
address: AccountAddress;
|
|
48
|
+
}): Promise<string>;
|
|
49
|
+
signEip712TypedData(eip712TypedData: string, address: AccountAddress, options?: {
|
|
50
|
+
txTimeout?: number;
|
|
51
|
+
}): Promise<string>;
|
|
52
|
+
signAminoCosmosTransaction(transaction: {
|
|
53
|
+
signDoc: StdSignDoc;
|
|
54
|
+
address: string;
|
|
55
|
+
}): Promise<AminoSignResponse>;
|
|
56
|
+
signCosmosTransaction(transaction: {
|
|
57
|
+
txRaw: TxRaw;
|
|
58
|
+
accountNumber: number;
|
|
59
|
+
chainId: string;
|
|
60
|
+
address: string;
|
|
61
|
+
}): Promise<DirectSignResponse>;
|
|
62
|
+
signArbitrary(signer: string, data: string | Uint8Array): Promise<string | void>;
|
|
63
|
+
onAccountChange(callback: onAccountChangeCallback): Promise<void>;
|
|
64
|
+
onChainIdChange(callback: onChainIdChangeCallback): Promise<void>;
|
|
65
|
+
disconnect(): Promise<void>;
|
|
66
|
+
getCosmosWallet(chainId: ChainId): CosmosWalletAbstraction;
|
|
67
|
+
getEip1193Provider(): Promise<Eip1193Provider>;
|
|
68
|
+
getOfflineSigner(chainId: string): Promise<OfflineSigner>;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { BaseWalletStrategy as t };
|