@injectivelabs/wallet-core 1.16.18 → 1.16.20
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/broadcaster/MsgBroadcaster.js +40 -26
- package/dist/cjs/strategy/BaseWalletStrategy.d.ts +3 -1
- package/dist/cjs/strategy/BaseWalletStrategy.js +2 -2
- package/dist/esm/broadcaster/MsgBroadcaster.js +41 -27
- package/dist/esm/strategy/BaseWalletStrategy.d.ts +3 -1
- package/dist/esm/strategy/BaseWalletStrategy.js +2 -2
- package/package.json +8 -8
|
@@ -214,7 +214,7 @@ class MsgBroadcaster {
|
|
|
214
214
|
* @returns transaction hash
|
|
215
215
|
*/
|
|
216
216
|
async broadcastEip712(tx) {
|
|
217
|
-
const { chainId,
|
|
217
|
+
const { chainId, endpoints, walletStrategy, txTimeout: txTimeoutInBlocks, } = this;
|
|
218
218
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
219
219
|
const evmChainId = await this.getEvmChainId();
|
|
220
220
|
if (!evmChainId) {
|
|
@@ -222,7 +222,9 @@ class MsgBroadcaster {
|
|
|
222
222
|
}
|
|
223
223
|
/** Account Details * */
|
|
224
224
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
225
|
-
const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(
|
|
225
|
+
const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(txTimeoutInBlocks);
|
|
226
|
+
const txTimeoutTimeInSeconds = txTimeoutInBlocks * utils_1.DEFAULT_BLOCK_TIME_IN_SECONDS;
|
|
227
|
+
const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
|
|
226
228
|
const gas = (tx.gas?.gas || (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs)).toString();
|
|
227
229
|
let stdFee = (0, utils_1.getStdFee)({ ...tx.gas, gas });
|
|
228
230
|
/**
|
|
@@ -263,7 +265,7 @@ class MsgBroadcaster {
|
|
|
263
265
|
evmChainId,
|
|
264
266
|
});
|
|
265
267
|
/** Signing on Ethereum */
|
|
266
|
-
const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress);
|
|
268
|
+
const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress, { txTimeout: txTimeoutTimeInSeconds });
|
|
267
269
|
const pubKeyOrSignatureDerivedPubKey = await getEthereumWalletPubKey({
|
|
268
270
|
pubKey: baseAccount.pubKey?.key,
|
|
269
271
|
eip712TypedData,
|
|
@@ -290,11 +292,11 @@ class MsgBroadcaster {
|
|
|
290
292
|
const response = await walletStrategy.sendTransaction(txRawEip712, {
|
|
291
293
|
chainId,
|
|
292
294
|
endpoints,
|
|
293
|
-
txTimeout,
|
|
295
|
+
txTimeout: txTimeoutInBlocks,
|
|
294
296
|
address: tx.injectiveAddress,
|
|
295
297
|
});
|
|
296
298
|
walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
297
|
-
return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash);
|
|
299
|
+
return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
298
300
|
}
|
|
299
301
|
/**
|
|
300
302
|
* Prepare/sign/broadcast transaction using
|
|
@@ -306,7 +308,7 @@ class MsgBroadcaster {
|
|
|
306
308
|
* @returns transaction hash
|
|
307
309
|
*/
|
|
308
310
|
async broadcastEip712V2(tx) {
|
|
309
|
-
const { chainId, endpoints, txTimeout,
|
|
311
|
+
const { chainId, endpoints, walletStrategy, txTimeout: txTimeoutInBlocks, } = this;
|
|
310
312
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
311
313
|
const evmChainId = await this.getEvmChainId();
|
|
312
314
|
if (!evmChainId) {
|
|
@@ -314,7 +316,9 @@ class MsgBroadcaster {
|
|
|
314
316
|
}
|
|
315
317
|
/** Account Details * */
|
|
316
318
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
317
|
-
const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(
|
|
319
|
+
const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(txTimeoutInBlocks);
|
|
320
|
+
const txTimeoutTimeInSeconds = txTimeoutInBlocks * utils_1.DEFAULT_BLOCK_TIME_IN_SECONDS;
|
|
321
|
+
const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
|
|
318
322
|
const gas = (tx.gas?.gas || (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs)).toString();
|
|
319
323
|
let stdFee = (0, utils_1.getStdFee)({ ...tx.gas, gas });
|
|
320
324
|
/**
|
|
@@ -357,7 +361,7 @@ class MsgBroadcaster {
|
|
|
357
361
|
});
|
|
358
362
|
walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionPreparationEnd);
|
|
359
363
|
/** Signing on Ethereum */
|
|
360
|
-
const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress);
|
|
364
|
+
const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress, { txTimeout: txTimeoutTimeInSeconds });
|
|
361
365
|
const pubKeyOrSignatureDerivedPubKey = await getEthereumWalletPubKey({
|
|
362
366
|
pubKey: baseAccount.pubKey?.key,
|
|
363
367
|
eip712TypedData,
|
|
@@ -384,11 +388,11 @@ class MsgBroadcaster {
|
|
|
384
388
|
const response = await walletStrategy.sendTransaction(txRawEip712, {
|
|
385
389
|
chainId,
|
|
386
390
|
endpoints,
|
|
387
|
-
txTimeout,
|
|
391
|
+
txTimeout: txTimeoutInBlocks,
|
|
388
392
|
address: tx.injectiveAddress,
|
|
389
393
|
});
|
|
390
394
|
walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
391
|
-
return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash);
|
|
395
|
+
return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
392
396
|
}
|
|
393
397
|
/**
|
|
394
398
|
* Prepare/sign/broadcast transaction using
|
|
@@ -398,7 +402,7 @@ class MsgBroadcaster {
|
|
|
398
402
|
* @returns transaction hash
|
|
399
403
|
*/
|
|
400
404
|
async broadcastEip712WithFeeDelegation(tx) {
|
|
401
|
-
const {
|
|
405
|
+
const { endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation, txTimeout: txTimeoutInBlocks, } = this;
|
|
402
406
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
403
407
|
const web3Msgs = msgs.map((msg) => msg.toWeb3());
|
|
404
408
|
const evmChainId = await this.getEvmChainId();
|
|
@@ -409,11 +413,15 @@ class MsgBroadcaster {
|
|
|
409
413
|
if (httpHeaders) {
|
|
410
414
|
transactionApi.setMetadata(httpHeaders);
|
|
411
415
|
}
|
|
416
|
+
const txTimeoutTimeInSeconds = txTimeoutInBlocks * utils_1.DEFAULT_BLOCK_TIME_IN_SECONDS;
|
|
417
|
+
const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
|
|
412
418
|
let timeoutHeight = undefined;
|
|
413
419
|
if (txTimeoutOnFeeDelegation) {
|
|
414
420
|
const latestBlock = await new sdk_ts_1.ChainGrpcTendermintApi(endpoints.grpc).fetchLatestBlock();
|
|
415
421
|
const latestHeight = latestBlock.header.height;
|
|
416
|
-
timeoutHeight = (0, utils_1.toBigNumber)(latestHeight)
|
|
422
|
+
timeoutHeight = (0, utils_1.toBigNumber)(latestHeight)
|
|
423
|
+
.plus(txTimeoutInBlocks)
|
|
424
|
+
.toNumber();
|
|
417
425
|
}
|
|
418
426
|
walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionPreparationStart);
|
|
419
427
|
const prepareTxResponse = await transactionApi.prepareTxRequest({
|
|
@@ -426,7 +434,7 @@ class MsgBroadcaster {
|
|
|
426
434
|
estimateGas: simulateTx,
|
|
427
435
|
});
|
|
428
436
|
walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionPreparationEnd);
|
|
429
|
-
const signature = await walletStrategy.signEip712TypedData(prepareTxResponse.data, tx.ethereumAddress);
|
|
437
|
+
const signature = await walletStrategy.signEip712TypedData(prepareTxResponse.data, tx.ethereumAddress, { txTimeout: txTimeoutTimeInSeconds });
|
|
430
438
|
const broadcast = async () => await transactionApi.broadcastTxRequest({
|
|
431
439
|
signature,
|
|
432
440
|
message: web3Msgs,
|
|
@@ -437,7 +445,7 @@ class MsgBroadcaster {
|
|
|
437
445
|
walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
438
446
|
const response = await broadcast();
|
|
439
447
|
walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
440
|
-
return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash);
|
|
448
|
+
return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
441
449
|
}
|
|
442
450
|
catch (e) {
|
|
443
451
|
const error = e;
|
|
@@ -472,7 +480,7 @@ class MsgBroadcaster {
|
|
|
472
480
|
* @returns transaction hash
|
|
473
481
|
*/
|
|
474
482
|
async broadcastDirectSign(tx) {
|
|
475
|
-
const { walletStrategy, txTimeout
|
|
483
|
+
const { chainId, endpoints, walletStrategy, txTimeout: txTimeoutInBlocks, } = this;
|
|
476
484
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
477
485
|
/**
|
|
478
486
|
* When using Ledger with Keplr/Leap we have
|
|
@@ -486,7 +494,9 @@ class MsgBroadcaster {
|
|
|
486
494
|
}
|
|
487
495
|
}
|
|
488
496
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
489
|
-
const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(
|
|
497
|
+
const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(txTimeoutInBlocks);
|
|
498
|
+
const txTimeoutTimeInSeconds = txTimeoutInBlocks * utils_1.DEFAULT_BLOCK_TIME_IN_SECONDS;
|
|
499
|
+
const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
|
|
490
500
|
const signMode = (0, wallet_base_1.isCosmosAminoOnlyWallet)(walletStrategy.wallet)
|
|
491
501
|
? sdk_ts_1.SIGN_EIP712
|
|
492
502
|
: sdk_ts_1.SIGN_DIRECT;
|
|
@@ -529,11 +539,11 @@ class MsgBroadcaster {
|
|
|
529
539
|
const response = await walletStrategy.sendTransaction(txRaw, {
|
|
530
540
|
chainId,
|
|
531
541
|
endpoints,
|
|
532
|
-
txTimeout,
|
|
533
542
|
address: tx.injectiveAddress,
|
|
543
|
+
txTimeout: txTimeoutInBlocks,
|
|
534
544
|
});
|
|
535
545
|
walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
536
|
-
return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash);
|
|
546
|
+
return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
537
547
|
}
|
|
538
548
|
const directSignResponse = (await walletStrategy.signCosmosTransaction({
|
|
539
549
|
txRaw,
|
|
@@ -545,11 +555,11 @@ class MsgBroadcaster {
|
|
|
545
555
|
const response = await walletStrategy.sendTransaction(directSignResponse, {
|
|
546
556
|
chainId,
|
|
547
557
|
endpoints,
|
|
548
|
-
txTimeout,
|
|
558
|
+
txTimeout: txTimeoutInBlocks,
|
|
549
559
|
address: tx.injectiveAddress,
|
|
550
560
|
});
|
|
551
561
|
walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
552
|
-
return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash);
|
|
562
|
+
return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
553
563
|
}
|
|
554
564
|
/**
|
|
555
565
|
* We use this method only when we want to broadcast a transaction using Ledger on Keplr/Leap for Injective
|
|
@@ -558,7 +568,7 @@ class MsgBroadcaster {
|
|
|
558
568
|
* @param tx the transaction that needs to be broadcasted
|
|
559
569
|
*/
|
|
560
570
|
async experimentalBroadcastWalletThroughLedger(tx) {
|
|
561
|
-
const { chainId,
|
|
571
|
+
const { chainId, endpoints, evmChainId, simulateTx, walletStrategy, txTimeout: txTimeoutInBlocks, } = this;
|
|
562
572
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
563
573
|
/**
|
|
564
574
|
* We can only use this method
|
|
@@ -576,7 +586,7 @@ class MsgBroadcaster {
|
|
|
576
586
|
}
|
|
577
587
|
const cosmosWallet = walletStrategy.getCosmosWallet(chainId);
|
|
578
588
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
579
|
-
const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(
|
|
589
|
+
const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(txTimeoutInBlocks);
|
|
580
590
|
const pubKey = await walletStrategy.getPubKey();
|
|
581
591
|
const gas = (tx.gas?.gas || (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs)).toString();
|
|
582
592
|
/** EIP712 for signing on Ethereum wallets */
|
|
@@ -631,7 +641,7 @@ class MsgBroadcaster {
|
|
|
631
641
|
const signatureBuff = Buffer.from(aminoSignResponse.signature.signature, 'base64');
|
|
632
642
|
txRawEip712.signatures = [signatureBuff];
|
|
633
643
|
/** Broadcast the transaction */
|
|
634
|
-
const response = await new sdk_ts_1.TxGrpcApi(endpoints.grpc).broadcast(txRawEip712, { txTimeout });
|
|
644
|
+
const response = await new sdk_ts_1.TxGrpcApi(endpoints.grpc).broadcast(txRawEip712, { txTimeout: txTimeoutInBlocks });
|
|
635
645
|
if (response.code !== 0) {
|
|
636
646
|
throw new exceptions_1.TransactionException(new Error(response.rawLog), {
|
|
637
647
|
code: exceptions_1.UnspecifiedErrorCode,
|
|
@@ -649,7 +659,7 @@ class MsgBroadcaster {
|
|
|
649
659
|
* @returns transaction hash
|
|
650
660
|
*/
|
|
651
661
|
async broadcastDirectSignWithFeeDelegation(tx) {
|
|
652
|
-
const { options, chainId,
|
|
662
|
+
const { options, chainId, endpoints, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation, txTimeout: txTimeoutInBlocks, } = this;
|
|
653
663
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
654
664
|
/**
|
|
655
665
|
* We can only use this method when Keplr is connected
|
|
@@ -675,7 +685,11 @@ class MsgBroadcaster {
|
|
|
675
685
|
}
|
|
676
686
|
const feePayerAccountDetails = await chainGrpcAuthApi.fetchAccount(feePayer);
|
|
677
687
|
const { baseAccount: feePayerBaseAccount } = feePayerAccountDetails;
|
|
678
|
-
const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(txTimeoutOnFeeDelegation
|
|
688
|
+
const timeoutHeight = (0, utils_1.toBigNumber)(latestHeight).plus(txTimeoutOnFeeDelegation
|
|
689
|
+
? txTimeoutInBlocks
|
|
690
|
+
: utils_1.DEFAULT_BLOCK_TIMEOUT_HEIGHT);
|
|
691
|
+
const txTimeoutTimeInSeconds = txTimeoutInBlocks * utils_1.DEFAULT_BLOCK_TIME_IN_SECONDS;
|
|
692
|
+
const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
|
|
679
693
|
const pubKey = await walletStrategy.getPubKey();
|
|
680
694
|
const gas = (tx.gas?.gas || (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs)).toString();
|
|
681
695
|
/** Prepare the Transaction * */
|
|
@@ -731,7 +745,7 @@ class MsgBroadcaster {
|
|
|
731
745
|
if (canDisableCosmosGasCheck && cosmosWallet.enableGasCheck) {
|
|
732
746
|
cosmosWallet.enableGasCheck(chainId);
|
|
733
747
|
}
|
|
734
|
-
return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash);
|
|
748
|
+
return await new sdk_ts_1.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
735
749
|
}
|
|
736
750
|
catch (e) {
|
|
737
751
|
const error = e;
|
|
@@ -35,7 +35,9 @@ export default class BaseWalletStrategy implements WalletStrategyInterface {
|
|
|
35
35
|
evmChainId: EvmChainId;
|
|
36
36
|
address: AccountAddress;
|
|
37
37
|
}): Promise<string>;
|
|
38
|
-
signEip712TypedData(eip712TypedData: string, address: AccountAddress
|
|
38
|
+
signEip712TypedData(eip712TypedData: string, address: AccountAddress, options?: {
|
|
39
|
+
txTimeout?: number;
|
|
40
|
+
}): Promise<string>;
|
|
39
41
|
signAminoCosmosTransaction(transaction: {
|
|
40
42
|
signDoc: StdSignDoc;
|
|
41
43
|
address: string;
|
|
@@ -98,7 +98,7 @@ class BaseWalletStrategy {
|
|
|
98
98
|
async sendEvmTransaction(tx /* TODO */, options) {
|
|
99
99
|
return this.getStrategy().sendEvmTransaction(tx, options);
|
|
100
100
|
}
|
|
101
|
-
async signEip712TypedData(eip712TypedData, address) {
|
|
101
|
+
async signEip712TypedData(eip712TypedData, address, options = {}) {
|
|
102
102
|
if ((0, wallet_base_1.isCosmosWallet)(this.wallet)) {
|
|
103
103
|
throw new exceptions_1.WalletException(new Error(`You can't sign Ethereum Transaction using ${this.wallet}`));
|
|
104
104
|
}
|
|
@@ -107,7 +107,7 @@ class BaseWalletStrategy {
|
|
|
107
107
|
await this.enable();
|
|
108
108
|
}
|
|
109
109
|
this.emit(types_js_1.WalletStrategyEmitterEventType.TransactionSignStart);
|
|
110
|
-
const response = await this.getStrategy().signEip712TypedData(eip712TypedData, address);
|
|
110
|
+
const response = await this.getStrategy().signEip712TypedData(eip712TypedData, address, options);
|
|
111
111
|
this.emit(types_js_1.WalletStrategyEmitterEventType.TransactionSigned);
|
|
112
112
|
return response;
|
|
113
113
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EvmChainId } from '@injectivelabs/ts-types';
|
|
2
2
|
import { isTestnet, isMainnet, getNetworkInfo, getNetworkEndpoints, } from '@injectivelabs/networks';
|
|
3
|
-
import { sleep, getStdFee, toBigNumber, DEFAULT_GAS_PRICE, DEFAULT_BLOCK_TIMEOUT_HEIGHT, } from '@injectivelabs/utils';
|
|
3
|
+
import { sleep, getStdFee, toBigNumber, DEFAULT_GAS_PRICE, DEFAULT_BLOCK_TIMEOUT_HEIGHT, DEFAULT_BLOCK_TIME_IN_SECONDS, } from '@injectivelabs/utils';
|
|
4
4
|
import { WalletException, GeneralException, isThrownException, UnspecifiedErrorCode, ChainCosmosErrorCode, TransactionException, TransactionChainErrorModule, } from '@injectivelabs/exceptions';
|
|
5
5
|
import { Wallet, isCosmosWallet, WalletDeviceType, isEvmBrowserWallet, isEip712V2OnlyWallet, createEip712StdSignDoc, isCosmosAminoOnlyWallet, getEthereumSignerAddress, getInjectiveSignerAddress, } from '@injectivelabs/wallet-base';
|
|
6
6
|
import { TxGrpcApi, hexToBuff, PublicKey, SIGN_DIRECT, hexToBase64, ofacWallets, SIGN_EIP712, SIGN_EIP712_V2, ChainGrpcAuthApi, createTxRawEIP712, createTransaction, ChainGrpcTxFeesApi, getAminoStdSignDoc, getEip712TypedData, createWeb3Extension, getEip712TypedDataV2, IndexerGrpcWeb3GwApi, ChainGrpcTendermintApi, getGasPriceBasedOnMessage, createTxRawFromSigResponse, recoverTypedSignaturePubKey, createTransactionWithSigners, } from '@injectivelabs/sdk-ts';
|
|
@@ -211,7 +211,7 @@ export class MsgBroadcaster {
|
|
|
211
211
|
* @returns transaction hash
|
|
212
212
|
*/
|
|
213
213
|
async broadcastEip712(tx) {
|
|
214
|
-
const { chainId,
|
|
214
|
+
const { chainId, endpoints, walletStrategy, txTimeout: txTimeoutInBlocks, } = this;
|
|
215
215
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
216
216
|
const evmChainId = await this.getEvmChainId();
|
|
217
217
|
if (!evmChainId) {
|
|
@@ -219,7 +219,9 @@ export class MsgBroadcaster {
|
|
|
219
219
|
}
|
|
220
220
|
/** Account Details * */
|
|
221
221
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
222
|
-
const timeoutHeight = toBigNumber(latestHeight).plus(
|
|
222
|
+
const timeoutHeight = toBigNumber(latestHeight).plus(txTimeoutInBlocks);
|
|
223
|
+
const txTimeoutTimeInSeconds = txTimeoutInBlocks * DEFAULT_BLOCK_TIME_IN_SECONDS;
|
|
224
|
+
const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
|
|
223
225
|
const gas = (tx.gas?.gas || getGasPriceBasedOnMessage(msgs)).toString();
|
|
224
226
|
let stdFee = getStdFee({ ...tx.gas, gas });
|
|
225
227
|
/**
|
|
@@ -260,7 +262,7 @@ export class MsgBroadcaster {
|
|
|
260
262
|
evmChainId,
|
|
261
263
|
});
|
|
262
264
|
/** Signing on Ethereum */
|
|
263
|
-
const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress);
|
|
265
|
+
const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress, { txTimeout: txTimeoutTimeInSeconds });
|
|
264
266
|
const pubKeyOrSignatureDerivedPubKey = await getEthereumWalletPubKey({
|
|
265
267
|
pubKey: baseAccount.pubKey?.key,
|
|
266
268
|
eip712TypedData,
|
|
@@ -287,11 +289,11 @@ export class MsgBroadcaster {
|
|
|
287
289
|
const response = await walletStrategy.sendTransaction(txRawEip712, {
|
|
288
290
|
chainId,
|
|
289
291
|
endpoints,
|
|
290
|
-
txTimeout,
|
|
292
|
+
txTimeout: txTimeoutInBlocks,
|
|
291
293
|
address: tx.injectiveAddress,
|
|
292
294
|
});
|
|
293
295
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
294
|
-
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash);
|
|
296
|
+
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
295
297
|
}
|
|
296
298
|
/**
|
|
297
299
|
* Prepare/sign/broadcast transaction using
|
|
@@ -303,7 +305,7 @@ export class MsgBroadcaster {
|
|
|
303
305
|
* @returns transaction hash
|
|
304
306
|
*/
|
|
305
307
|
async broadcastEip712V2(tx) {
|
|
306
|
-
const { chainId, endpoints, txTimeout,
|
|
308
|
+
const { chainId, endpoints, walletStrategy, txTimeout: txTimeoutInBlocks, } = this;
|
|
307
309
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
308
310
|
const evmChainId = await this.getEvmChainId();
|
|
309
311
|
if (!evmChainId) {
|
|
@@ -311,7 +313,9 @@ export class MsgBroadcaster {
|
|
|
311
313
|
}
|
|
312
314
|
/** Account Details * */
|
|
313
315
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
314
|
-
const timeoutHeight = toBigNumber(latestHeight).plus(
|
|
316
|
+
const timeoutHeight = toBigNumber(latestHeight).plus(txTimeoutInBlocks);
|
|
317
|
+
const txTimeoutTimeInSeconds = txTimeoutInBlocks * DEFAULT_BLOCK_TIME_IN_SECONDS;
|
|
318
|
+
const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
|
|
315
319
|
const gas = (tx.gas?.gas || getGasPriceBasedOnMessage(msgs)).toString();
|
|
316
320
|
let stdFee = getStdFee({ ...tx.gas, gas });
|
|
317
321
|
/**
|
|
@@ -354,7 +358,7 @@ export class MsgBroadcaster {
|
|
|
354
358
|
});
|
|
355
359
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationEnd);
|
|
356
360
|
/** Signing on Ethereum */
|
|
357
|
-
const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress);
|
|
361
|
+
const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress, { txTimeout: txTimeoutTimeInSeconds });
|
|
358
362
|
const pubKeyOrSignatureDerivedPubKey = await getEthereumWalletPubKey({
|
|
359
363
|
pubKey: baseAccount.pubKey?.key,
|
|
360
364
|
eip712TypedData,
|
|
@@ -381,11 +385,11 @@ export class MsgBroadcaster {
|
|
|
381
385
|
const response = await walletStrategy.sendTransaction(txRawEip712, {
|
|
382
386
|
chainId,
|
|
383
387
|
endpoints,
|
|
384
|
-
txTimeout,
|
|
388
|
+
txTimeout: txTimeoutInBlocks,
|
|
385
389
|
address: tx.injectiveAddress,
|
|
386
390
|
});
|
|
387
391
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
388
|
-
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash);
|
|
392
|
+
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
389
393
|
}
|
|
390
394
|
/**
|
|
391
395
|
* Prepare/sign/broadcast transaction using
|
|
@@ -395,7 +399,7 @@ export class MsgBroadcaster {
|
|
|
395
399
|
* @returns transaction hash
|
|
396
400
|
*/
|
|
397
401
|
async broadcastEip712WithFeeDelegation(tx) {
|
|
398
|
-
const {
|
|
402
|
+
const { endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation, txTimeout: txTimeoutInBlocks, } = this;
|
|
399
403
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
400
404
|
const web3Msgs = msgs.map((msg) => msg.toWeb3());
|
|
401
405
|
const evmChainId = await this.getEvmChainId();
|
|
@@ -406,11 +410,15 @@ export class MsgBroadcaster {
|
|
|
406
410
|
if (httpHeaders) {
|
|
407
411
|
transactionApi.setMetadata(httpHeaders);
|
|
408
412
|
}
|
|
413
|
+
const txTimeoutTimeInSeconds = txTimeoutInBlocks * DEFAULT_BLOCK_TIME_IN_SECONDS;
|
|
414
|
+
const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
|
|
409
415
|
let timeoutHeight = undefined;
|
|
410
416
|
if (txTimeoutOnFeeDelegation) {
|
|
411
417
|
const latestBlock = await new ChainGrpcTendermintApi(endpoints.grpc).fetchLatestBlock();
|
|
412
418
|
const latestHeight = latestBlock.header.height;
|
|
413
|
-
timeoutHeight = toBigNumber(latestHeight)
|
|
419
|
+
timeoutHeight = toBigNumber(latestHeight)
|
|
420
|
+
.plus(txTimeoutInBlocks)
|
|
421
|
+
.toNumber();
|
|
414
422
|
}
|
|
415
423
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationStart);
|
|
416
424
|
const prepareTxResponse = await transactionApi.prepareTxRequest({
|
|
@@ -423,7 +431,7 @@ export class MsgBroadcaster {
|
|
|
423
431
|
estimateGas: simulateTx,
|
|
424
432
|
});
|
|
425
433
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationEnd);
|
|
426
|
-
const signature = await walletStrategy.signEip712TypedData(prepareTxResponse.data, tx.ethereumAddress);
|
|
434
|
+
const signature = await walletStrategy.signEip712TypedData(prepareTxResponse.data, tx.ethereumAddress, { txTimeout: txTimeoutTimeInSeconds });
|
|
427
435
|
const broadcast = async () => await transactionApi.broadcastTxRequest({
|
|
428
436
|
signature,
|
|
429
437
|
message: web3Msgs,
|
|
@@ -434,7 +442,7 @@ export class MsgBroadcaster {
|
|
|
434
442
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
435
443
|
const response = await broadcast();
|
|
436
444
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
437
|
-
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash);
|
|
445
|
+
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
438
446
|
}
|
|
439
447
|
catch (e) {
|
|
440
448
|
const error = e;
|
|
@@ -469,7 +477,7 @@ export class MsgBroadcaster {
|
|
|
469
477
|
* @returns transaction hash
|
|
470
478
|
*/
|
|
471
479
|
async broadcastDirectSign(tx) {
|
|
472
|
-
const { walletStrategy, txTimeout
|
|
480
|
+
const { chainId, endpoints, walletStrategy, txTimeout: txTimeoutInBlocks, } = this;
|
|
473
481
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
474
482
|
/**
|
|
475
483
|
* When using Ledger with Keplr/Leap we have
|
|
@@ -483,7 +491,9 @@ export class MsgBroadcaster {
|
|
|
483
491
|
}
|
|
484
492
|
}
|
|
485
493
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
486
|
-
const timeoutHeight = toBigNumber(latestHeight).plus(
|
|
494
|
+
const timeoutHeight = toBigNumber(latestHeight).plus(txTimeoutInBlocks);
|
|
495
|
+
const txTimeoutTimeInSeconds = txTimeoutInBlocks * DEFAULT_BLOCK_TIME_IN_SECONDS;
|
|
496
|
+
const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
|
|
487
497
|
const signMode = isCosmosAminoOnlyWallet(walletStrategy.wallet)
|
|
488
498
|
? SIGN_EIP712
|
|
489
499
|
: SIGN_DIRECT;
|
|
@@ -526,11 +536,11 @@ export class MsgBroadcaster {
|
|
|
526
536
|
const response = await walletStrategy.sendTransaction(txRaw, {
|
|
527
537
|
chainId,
|
|
528
538
|
endpoints,
|
|
529
|
-
txTimeout,
|
|
530
539
|
address: tx.injectiveAddress,
|
|
540
|
+
txTimeout: txTimeoutInBlocks,
|
|
531
541
|
});
|
|
532
542
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
533
|
-
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash);
|
|
543
|
+
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
534
544
|
}
|
|
535
545
|
const directSignResponse = (await walletStrategy.signCosmosTransaction({
|
|
536
546
|
txRaw,
|
|
@@ -542,11 +552,11 @@ export class MsgBroadcaster {
|
|
|
542
552
|
const response = await walletStrategy.sendTransaction(directSignResponse, {
|
|
543
553
|
chainId,
|
|
544
554
|
endpoints,
|
|
545
|
-
txTimeout,
|
|
555
|
+
txTimeout: txTimeoutInBlocks,
|
|
546
556
|
address: tx.injectiveAddress,
|
|
547
557
|
});
|
|
548
558
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
|
|
549
|
-
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash);
|
|
559
|
+
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
550
560
|
}
|
|
551
561
|
/**
|
|
552
562
|
* We use this method only when we want to broadcast a transaction using Ledger on Keplr/Leap for Injective
|
|
@@ -555,7 +565,7 @@ export class MsgBroadcaster {
|
|
|
555
565
|
* @param tx the transaction that needs to be broadcasted
|
|
556
566
|
*/
|
|
557
567
|
async experimentalBroadcastWalletThroughLedger(tx) {
|
|
558
|
-
const { chainId,
|
|
568
|
+
const { chainId, endpoints, evmChainId, simulateTx, walletStrategy, txTimeout: txTimeoutInBlocks, } = this;
|
|
559
569
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
560
570
|
/**
|
|
561
571
|
* We can only use this method
|
|
@@ -573,7 +583,7 @@ export class MsgBroadcaster {
|
|
|
573
583
|
}
|
|
574
584
|
const cosmosWallet = walletStrategy.getCosmosWallet(chainId);
|
|
575
585
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
576
|
-
const timeoutHeight = toBigNumber(latestHeight).plus(
|
|
586
|
+
const timeoutHeight = toBigNumber(latestHeight).plus(txTimeoutInBlocks);
|
|
577
587
|
const pubKey = await walletStrategy.getPubKey();
|
|
578
588
|
const gas = (tx.gas?.gas || getGasPriceBasedOnMessage(msgs)).toString();
|
|
579
589
|
/** EIP712 for signing on Ethereum wallets */
|
|
@@ -628,7 +638,7 @@ export class MsgBroadcaster {
|
|
|
628
638
|
const signatureBuff = Buffer.from(aminoSignResponse.signature.signature, 'base64');
|
|
629
639
|
txRawEip712.signatures = [signatureBuff];
|
|
630
640
|
/** Broadcast the transaction */
|
|
631
|
-
const response = await new TxGrpcApi(endpoints.grpc).broadcast(txRawEip712, { txTimeout });
|
|
641
|
+
const response = await new TxGrpcApi(endpoints.grpc).broadcast(txRawEip712, { txTimeout: txTimeoutInBlocks });
|
|
632
642
|
if (response.code !== 0) {
|
|
633
643
|
throw new TransactionException(new Error(response.rawLog), {
|
|
634
644
|
code: UnspecifiedErrorCode,
|
|
@@ -646,7 +656,7 @@ export class MsgBroadcaster {
|
|
|
646
656
|
* @returns transaction hash
|
|
647
657
|
*/
|
|
648
658
|
async broadcastDirectSignWithFeeDelegation(tx) {
|
|
649
|
-
const { options, chainId,
|
|
659
|
+
const { options, chainId, endpoints, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation, txTimeout: txTimeoutInBlocks, } = this;
|
|
650
660
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
651
661
|
/**
|
|
652
662
|
* We can only use this method when Keplr is connected
|
|
@@ -672,7 +682,11 @@ export class MsgBroadcaster {
|
|
|
672
682
|
}
|
|
673
683
|
const feePayerAccountDetails = await chainGrpcAuthApi.fetchAccount(feePayer);
|
|
674
684
|
const { baseAccount: feePayerBaseAccount } = feePayerAccountDetails;
|
|
675
|
-
const timeoutHeight = toBigNumber(latestHeight).plus(txTimeoutOnFeeDelegation
|
|
685
|
+
const timeoutHeight = toBigNumber(latestHeight).plus(txTimeoutOnFeeDelegation
|
|
686
|
+
? txTimeoutInBlocks
|
|
687
|
+
: DEFAULT_BLOCK_TIMEOUT_HEIGHT);
|
|
688
|
+
const txTimeoutTimeInSeconds = txTimeoutInBlocks * DEFAULT_BLOCK_TIME_IN_SECONDS;
|
|
689
|
+
const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1000;
|
|
676
690
|
const pubKey = await walletStrategy.getPubKey();
|
|
677
691
|
const gas = (tx.gas?.gas || getGasPriceBasedOnMessage(msgs)).toString();
|
|
678
692
|
/** Prepare the Transaction * */
|
|
@@ -728,7 +742,7 @@ export class MsgBroadcaster {
|
|
|
728
742
|
if (canDisableCosmosGasCheck && cosmosWallet.enableGasCheck) {
|
|
729
743
|
cosmosWallet.enableGasCheck(chainId);
|
|
730
744
|
}
|
|
731
|
-
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash);
|
|
745
|
+
return await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
|
|
732
746
|
}
|
|
733
747
|
catch (e) {
|
|
734
748
|
const error = e;
|
|
@@ -35,7 +35,9 @@ export default class BaseWalletStrategy implements WalletStrategyInterface {
|
|
|
35
35
|
evmChainId: EvmChainId;
|
|
36
36
|
address: AccountAddress;
|
|
37
37
|
}): Promise<string>;
|
|
38
|
-
signEip712TypedData(eip712TypedData: string, address: AccountAddress
|
|
38
|
+
signEip712TypedData(eip712TypedData: string, address: AccountAddress, options?: {
|
|
39
|
+
txTimeout?: number;
|
|
40
|
+
}): Promise<string>;
|
|
39
41
|
signAminoCosmosTransaction(transaction: {
|
|
40
42
|
signDoc: StdSignDoc;
|
|
41
43
|
address: string;
|
|
@@ -96,7 +96,7 @@ export default class BaseWalletStrategy {
|
|
|
96
96
|
async sendEvmTransaction(tx /* TODO */, options) {
|
|
97
97
|
return this.getStrategy().sendEvmTransaction(tx, options);
|
|
98
98
|
}
|
|
99
|
-
async signEip712TypedData(eip712TypedData, address) {
|
|
99
|
+
async signEip712TypedData(eip712TypedData, address, options = {}) {
|
|
100
100
|
if (isCosmosWallet(this.wallet)) {
|
|
101
101
|
throw new WalletException(new Error(`You can't sign Ethereum Transaction using ${this.wallet}`));
|
|
102
102
|
}
|
|
@@ -105,7 +105,7 @@ export default class BaseWalletStrategy {
|
|
|
105
105
|
await this.enable();
|
|
106
106
|
}
|
|
107
107
|
this.emit(WalletStrategyEmitterEventType.TransactionSignStart);
|
|
108
|
-
const response = await this.getStrategy().signEip712TypedData(eip712TypedData, address);
|
|
108
|
+
const response = await this.getStrategy().signEip712TypedData(eip712TypedData, address, options);
|
|
109
109
|
this.emit(WalletStrategyEmitterEventType.TransactionSigned);
|
|
110
110
|
return response;
|
|
111
111
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-core",
|
|
3
3
|
"description": "Core wallet strategy",
|
|
4
|
-
"version": "1.16.
|
|
4
|
+
"version": "1.16.20",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": {
|
|
@@ -56,17 +56,17 @@
|
|
|
56
56
|
"start": "node dist/index.js"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@injectivelabs/exceptions": "1.16.
|
|
60
|
-
"@injectivelabs/networks": "1.16.
|
|
61
|
-
"@injectivelabs/sdk-ts": "1.16.
|
|
62
|
-
"@injectivelabs/ts-types": "1.16.
|
|
63
|
-
"@injectivelabs/utils": "1.16.
|
|
64
|
-
"@injectivelabs/wallet-base": "1.16.
|
|
59
|
+
"@injectivelabs/exceptions": "1.16.20",
|
|
60
|
+
"@injectivelabs/networks": "1.16.20",
|
|
61
|
+
"@injectivelabs/sdk-ts": "1.16.20",
|
|
62
|
+
"@injectivelabs/ts-types": "1.16.20",
|
|
63
|
+
"@injectivelabs/utils": "1.16.20",
|
|
64
|
+
"@injectivelabs/wallet-base": "1.16.20",
|
|
65
65
|
"@keplr-wallet/types": "^0.12.159",
|
|
66
66
|
"eventemitter3": "^5.0.1"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"shx": "^0.3.3"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "8c378352fe865570437048d0d11110eb417bbc78"
|
|
72
72
|
}
|