@injectivelabs/wallet-core 1.16.3 → 1.16.4
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.
|
@@ -30,6 +30,7 @@ export declare class MsgBroadcaster {
|
|
|
30
30
|
httpHeaders?: Record<string, string>;
|
|
31
31
|
constructor(options: MsgBroadcasterOptions);
|
|
32
32
|
setOptions(options: Partial<MsgBroadcasterOptions>): void;
|
|
33
|
+
getEvmChainId(): Promise<EthereumChainId | undefined>;
|
|
33
34
|
/**
|
|
34
35
|
* Broadcasting the transaction using the client
|
|
35
36
|
* side approach for both cosmos and ethereum native wallets
|
|
@@ -5,6 +5,7 @@ const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
|
5
5
|
const utils_1 = require("@injectivelabs/utils");
|
|
6
6
|
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
7
7
|
const networks_1 = require("@injectivelabs/networks");
|
|
8
|
+
const ts_types_1 = require("@injectivelabs/ts-types");
|
|
8
9
|
const types_js_1 = require("./types.js");
|
|
9
10
|
const index_js_1 = require("../utils/index.js");
|
|
10
11
|
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
@@ -64,6 +65,38 @@ class MsgBroadcaster {
|
|
|
64
65
|
this.txTimeoutOnFeeDelegation =
|
|
65
66
|
options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation;
|
|
66
67
|
}
|
|
68
|
+
async getEvmChainId() {
|
|
69
|
+
const { walletStrategy } = this;
|
|
70
|
+
if (!(0, wallet_base_1.isEvmBrowserWallet)(walletStrategy.wallet)) {
|
|
71
|
+
return this.ethereumChainId;
|
|
72
|
+
}
|
|
73
|
+
const mainnetEvmIds = [ts_types_1.EthereumChainId.Mainnet, ts_types_1.EthereumChainId.MainnetEvm];
|
|
74
|
+
const testnetEvmIds = [ts_types_1.EthereumChainId.Sepolia, ts_types_1.EthereumChainId.TestnetEvm];
|
|
75
|
+
const devnetEvmIds = [ts_types_1.EthereumChainId.Sepolia, ts_types_1.EthereumChainId.DevnetEvm];
|
|
76
|
+
try {
|
|
77
|
+
const chainId = await walletStrategy.getEthereumChainId();
|
|
78
|
+
if (!chainId) {
|
|
79
|
+
return this.ethereumChainId;
|
|
80
|
+
}
|
|
81
|
+
const evmChainId = parseInt(chainId, 16);
|
|
82
|
+
if (isNaN(evmChainId)) {
|
|
83
|
+
return this.ethereumChainId;
|
|
84
|
+
}
|
|
85
|
+
if (((0, networks_1.isMainnet)(this.options.network) &&
|
|
86
|
+
!mainnetEvmIds.includes(evmChainId)) ||
|
|
87
|
+
((0, networks_1.isTestnet)(this.options.network) &&
|
|
88
|
+
!testnetEvmIds.includes(evmChainId)) ||
|
|
89
|
+
(!(0, networks_1.isMainnet)(this.options.network) &&
|
|
90
|
+
!(0, networks_1.isTestnet)(this.options.network) &&
|
|
91
|
+
!devnetEvmIds.includes(evmChainId))) {
|
|
92
|
+
throw new exceptions_1.WalletException(new Error('Your selected network is incorrect'));
|
|
93
|
+
}
|
|
94
|
+
return evmChainId;
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
throw new exceptions_1.WalletException(e);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
67
100
|
/**
|
|
68
101
|
* Broadcasting the transaction using the client
|
|
69
102
|
* side approach for both cosmos and ethereum native wallets
|
|
@@ -170,8 +203,9 @@ class MsgBroadcaster {
|
|
|
170
203
|
* @returns transaction hash
|
|
171
204
|
*/
|
|
172
205
|
async broadcastEip712(tx) {
|
|
173
|
-
const { chainId, txTimeout, endpoints,
|
|
206
|
+
const { chainId, txTimeout, endpoints, walletStrategy } = this;
|
|
174
207
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
208
|
+
const ethereumChainId = await this.getEvmChainId();
|
|
175
209
|
if (!ethereumChainId) {
|
|
176
210
|
throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
|
|
177
211
|
}
|
|
@@ -261,8 +295,9 @@ class MsgBroadcaster {
|
|
|
261
295
|
* @returns transaction hash
|
|
262
296
|
*/
|
|
263
297
|
async broadcastEip712V2(tx) {
|
|
264
|
-
const { chainId, endpoints, txTimeout, walletStrategy
|
|
298
|
+
const { chainId, endpoints, txTimeout, walletStrategy } = this;
|
|
265
299
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
300
|
+
const ethereumChainId = await this.getEvmChainId();
|
|
266
301
|
if (!ethereumChainId) {
|
|
267
302
|
throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
|
|
268
303
|
}
|
|
@@ -352,9 +387,10 @@ class MsgBroadcaster {
|
|
|
352
387
|
* @returns transaction hash
|
|
353
388
|
*/
|
|
354
389
|
async broadcastEip712WithFeeDelegation(tx) {
|
|
355
|
-
const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy,
|
|
390
|
+
const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation, } = this;
|
|
356
391
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
357
392
|
const web3Msgs = msgs.map((msg) => msg.toWeb3());
|
|
393
|
+
const ethereumChainId = await this.getEvmChainId();
|
|
358
394
|
if (!ethereumChainId) {
|
|
359
395
|
throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
|
|
360
396
|
}
|
|
@@ -30,6 +30,7 @@ export declare class MsgBroadcaster {
|
|
|
30
30
|
httpHeaders?: Record<string, string>;
|
|
31
31
|
constructor(options: MsgBroadcasterOptions);
|
|
32
32
|
setOptions(options: Partial<MsgBroadcasterOptions>): void;
|
|
33
|
+
getEvmChainId(): Promise<EthereumChainId | undefined>;
|
|
33
34
|
/**
|
|
34
35
|
* Broadcasting the transaction using the client
|
|
35
36
|
* side approach for both cosmos and ethereum native wallets
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
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';
|
|
2
2
|
import { sleep, getStdFee, BigNumberInBase, DEFAULT_GAS_PRICE, DEFAULT_BLOCK_TIMEOUT_HEIGHT, } from '@injectivelabs/utils';
|
|
3
|
-
import { GeneralException, isThrownException, UnspecifiedErrorCode, ChainCosmosErrorCode, TransactionException, TransactionChainErrorModule, } from '@injectivelabs/exceptions';
|
|
4
|
-
import { getNetworkInfo, getNetworkEndpoints, } from '@injectivelabs/networks';
|
|
3
|
+
import { WalletException, GeneralException, isThrownException, UnspecifiedErrorCode, ChainCosmosErrorCode, TransactionException, TransactionChainErrorModule, } from '@injectivelabs/exceptions';
|
|
4
|
+
import { isTestnet, isMainnet, getNetworkInfo, getNetworkEndpoints, } from '@injectivelabs/networks';
|
|
5
|
+
import { EthereumChainId } from '@injectivelabs/ts-types';
|
|
5
6
|
import { WalletStrategyEmitterEventType, } from './types.js';
|
|
6
7
|
import { checkIfTxRunOutOfGas } from '../utils/index.js';
|
|
7
|
-
import { Wallet, isCosmosWallet, WalletDeviceType, isEip712V2OnlyWallet, createEip712StdSignDoc, isCosmosAminoOnlyWallet, getEthereumSignerAddress, getInjectiveSignerAddress, } from '@injectivelabs/wallet-base';
|
|
8
|
+
import { Wallet, isCosmosWallet, WalletDeviceType, isEvmBrowserWallet, isEip712V2OnlyWallet, createEip712StdSignDoc, isCosmosAminoOnlyWallet, getEthereumSignerAddress, getInjectiveSignerAddress, } from '@injectivelabs/wallet-base';
|
|
8
9
|
const getEthereumWalletPubKey = ({ pubKey, eip712TypedData, signature, }) => {
|
|
9
10
|
if (pubKey) {
|
|
10
11
|
return pubKey;
|
|
@@ -61,6 +62,38 @@ export class MsgBroadcaster {
|
|
|
61
62
|
this.txTimeoutOnFeeDelegation =
|
|
62
63
|
options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation;
|
|
63
64
|
}
|
|
65
|
+
async getEvmChainId() {
|
|
66
|
+
const { walletStrategy } = this;
|
|
67
|
+
if (!isEvmBrowserWallet(walletStrategy.wallet)) {
|
|
68
|
+
return this.ethereumChainId;
|
|
69
|
+
}
|
|
70
|
+
const mainnetEvmIds = [EthereumChainId.Mainnet, EthereumChainId.MainnetEvm];
|
|
71
|
+
const testnetEvmIds = [EthereumChainId.Sepolia, EthereumChainId.TestnetEvm];
|
|
72
|
+
const devnetEvmIds = [EthereumChainId.Sepolia, EthereumChainId.DevnetEvm];
|
|
73
|
+
try {
|
|
74
|
+
const chainId = await walletStrategy.getEthereumChainId();
|
|
75
|
+
if (!chainId) {
|
|
76
|
+
return this.ethereumChainId;
|
|
77
|
+
}
|
|
78
|
+
const evmChainId = parseInt(chainId, 16);
|
|
79
|
+
if (isNaN(evmChainId)) {
|
|
80
|
+
return this.ethereumChainId;
|
|
81
|
+
}
|
|
82
|
+
if ((isMainnet(this.options.network) &&
|
|
83
|
+
!mainnetEvmIds.includes(evmChainId)) ||
|
|
84
|
+
(isTestnet(this.options.network) &&
|
|
85
|
+
!testnetEvmIds.includes(evmChainId)) ||
|
|
86
|
+
(!isMainnet(this.options.network) &&
|
|
87
|
+
!isTestnet(this.options.network) &&
|
|
88
|
+
!devnetEvmIds.includes(evmChainId))) {
|
|
89
|
+
throw new WalletException(new Error('Your selected network is incorrect'));
|
|
90
|
+
}
|
|
91
|
+
return evmChainId;
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
throw new WalletException(e);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
64
97
|
/**
|
|
65
98
|
* Broadcasting the transaction using the client
|
|
66
99
|
* side approach for both cosmos and ethereum native wallets
|
|
@@ -167,8 +200,9 @@ export class MsgBroadcaster {
|
|
|
167
200
|
* @returns transaction hash
|
|
168
201
|
*/
|
|
169
202
|
async broadcastEip712(tx) {
|
|
170
|
-
const { chainId, txTimeout, endpoints,
|
|
203
|
+
const { chainId, txTimeout, endpoints, walletStrategy } = this;
|
|
171
204
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
205
|
+
const ethereumChainId = await this.getEvmChainId();
|
|
172
206
|
if (!ethereumChainId) {
|
|
173
207
|
throw new GeneralException(new Error('Please provide ethereumChainId'));
|
|
174
208
|
}
|
|
@@ -258,8 +292,9 @@ export class MsgBroadcaster {
|
|
|
258
292
|
* @returns transaction hash
|
|
259
293
|
*/
|
|
260
294
|
async broadcastEip712V2(tx) {
|
|
261
|
-
const { chainId, endpoints, txTimeout, walletStrategy
|
|
295
|
+
const { chainId, endpoints, txTimeout, walletStrategy } = this;
|
|
262
296
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
297
|
+
const ethereumChainId = await this.getEvmChainId();
|
|
263
298
|
if (!ethereumChainId) {
|
|
264
299
|
throw new GeneralException(new Error('Please provide ethereumChainId'));
|
|
265
300
|
}
|
|
@@ -349,9 +384,10 @@ export class MsgBroadcaster {
|
|
|
349
384
|
* @returns transaction hash
|
|
350
385
|
*/
|
|
351
386
|
async broadcastEip712WithFeeDelegation(tx) {
|
|
352
|
-
const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy,
|
|
387
|
+
const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation, } = this;
|
|
353
388
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
354
389
|
const web3Msgs = msgs.map((msg) => msg.toWeb3());
|
|
390
|
+
const ethereumChainId = await this.getEvmChainId();
|
|
355
391
|
if (!ethereumChainId) {
|
|
356
392
|
throw new GeneralException(new Error('Please provide ethereumChainId'));
|
|
357
393
|
}
|
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.4",
|
|
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.4",
|
|
60
|
+
"@injectivelabs/networks": "^1.16.4",
|
|
61
|
+
"@injectivelabs/sdk-ts": "^1.16.4",
|
|
62
|
+
"@injectivelabs/ts-types": "^1.16.4",
|
|
63
|
+
"@injectivelabs/utils": "^1.16.4",
|
|
64
|
+
"@injectivelabs/wallet-base": "^1.16.4",
|
|
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": "e997ae9a7255ecfd294fc0633e9da385f900fdda"
|
|
72
72
|
}
|