@injectivelabs/wallet-core 1.16.2 → 1.16.4-alpha.0

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
+ verifyEvmChainId(): Promise<void>;
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,32 @@ class MsgBroadcaster {
64
65
  this.txTimeoutOnFeeDelegation =
65
66
  options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation;
66
67
  }
68
+ async verifyEvmChainId() {
69
+ const { walletStrategy } = this;
70
+ if (!(0, wallet_base_1.isEvmBrowserWallet)(walletStrategy.wallet)) {
71
+ return;
72
+ }
73
+ const mainnetEvmIds = [ts_types_1.EthereumChainId.Mainnet];
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
+ const evmChainId = parseInt(chainId, 16);
79
+ if (((0, networks_1.isMainnet)(this.options.network) &&
80
+ !mainnetEvmIds.includes(evmChainId)) ||
81
+ ((0, networks_1.isTestnet)(this.options.network) &&
82
+ !testnetEvmIds.includes(evmChainId)) ||
83
+ (!(0, networks_1.isMainnet)(this.options.network) &&
84
+ !(0, networks_1.isTestnet)(this.options.network) &&
85
+ !devnetEvmIds.includes(evmChainId))) {
86
+ throw new exceptions_1.WalletException(new Error('Your selected network is incorrect'));
87
+ }
88
+ if (this.ethereumChainId !== evmChainId) {
89
+ this.ethereumChainId = evmChainId;
90
+ }
91
+ }
92
+ catch { }
93
+ }
67
94
  /**
68
95
  * Broadcasting the transaction using the client
69
96
  * side approach for both cosmos and ethereum native wallets
@@ -175,6 +202,7 @@ class MsgBroadcaster {
175
202
  if (!ethereumChainId) {
176
203
  throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
177
204
  }
205
+ await this.verifyEvmChainId();
178
206
  /** Account Details * */
179
207
  const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
180
208
  const timeoutHeight = new utils_1.BigNumberInBase(latestHeight).plus(txTimeout);
@@ -266,6 +294,7 @@ class MsgBroadcaster {
266
294
  if (!ethereumChainId) {
267
295
  throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
268
296
  }
297
+ await this.verifyEvmChainId();
269
298
  /** Account Details * */
270
299
  const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
271
300
  const timeoutHeight = new utils_1.BigNumberInBase(latestHeight).plus(txTimeout);
@@ -358,6 +387,7 @@ class MsgBroadcaster {
358
387
  if (!ethereumChainId) {
359
388
  throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
360
389
  }
390
+ await this.verifyEvmChainId();
361
391
  const transactionApi = new sdk_ts_1.IndexerGrpcWeb3GwApi(endpoints.web3gw || endpoints.indexer);
362
392
  if (httpHeaders) {
363
393
  transactionApi.setMetadata(httpHeaders);
@@ -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
+ verifyEvmChainId(): Promise<void>;
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,32 @@ export class MsgBroadcaster {
61
62
  this.txTimeoutOnFeeDelegation =
62
63
  options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation;
63
64
  }
65
+ async verifyEvmChainId() {
66
+ const { walletStrategy } = this;
67
+ if (!isEvmBrowserWallet(walletStrategy.wallet)) {
68
+ return;
69
+ }
70
+ const mainnetEvmIds = [EthereumChainId.Mainnet];
71
+ const testnetEvmIds = [EthereumChainId.Sepolia, EthereumChainId.TestnetEvm];
72
+ const devnetEvmIds = [EthereumChainId.Sepolia, EthereumChainId.DevnetEvm];
73
+ try {
74
+ const chainId = await walletStrategy.getEthereumChainId();
75
+ const evmChainId = parseInt(chainId, 16);
76
+ if ((isMainnet(this.options.network) &&
77
+ !mainnetEvmIds.includes(evmChainId)) ||
78
+ (isTestnet(this.options.network) &&
79
+ !testnetEvmIds.includes(evmChainId)) ||
80
+ (!isMainnet(this.options.network) &&
81
+ !isTestnet(this.options.network) &&
82
+ !devnetEvmIds.includes(evmChainId))) {
83
+ throw new WalletException(new Error('Your selected network is incorrect'));
84
+ }
85
+ if (this.ethereumChainId !== evmChainId) {
86
+ this.ethereumChainId = evmChainId;
87
+ }
88
+ }
89
+ catch { }
90
+ }
64
91
  /**
65
92
  * Broadcasting the transaction using the client
66
93
  * side approach for both cosmos and ethereum native wallets
@@ -172,6 +199,7 @@ export class MsgBroadcaster {
172
199
  if (!ethereumChainId) {
173
200
  throw new GeneralException(new Error('Please provide ethereumChainId'));
174
201
  }
202
+ await this.verifyEvmChainId();
175
203
  /** Account Details * */
176
204
  const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
177
205
  const timeoutHeight = new BigNumberInBase(latestHeight).plus(txTimeout);
@@ -263,6 +291,7 @@ export class MsgBroadcaster {
263
291
  if (!ethereumChainId) {
264
292
  throw new GeneralException(new Error('Please provide ethereumChainId'));
265
293
  }
294
+ await this.verifyEvmChainId();
266
295
  /** Account Details * */
267
296
  const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
268
297
  const timeoutHeight = new BigNumberInBase(latestHeight).plus(txTimeout);
@@ -355,6 +384,7 @@ export class MsgBroadcaster {
355
384
  if (!ethereumChainId) {
356
385
  throw new GeneralException(new Error('Please provide ethereumChainId'));
357
386
  }
387
+ await this.verifyEvmChainId();
358
388
  const transactionApi = new IndexerGrpcWeb3GwApi(endpoints.web3gw || endpoints.indexer);
359
389
  if (httpHeaders) {
360
390
  transactionApi.setMetadata(httpHeaders);
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.2",
4
+ "version": "1.16.4-alpha.0",
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.2",
60
- "@injectivelabs/networks": "^1.16.2",
61
- "@injectivelabs/sdk-ts": "^1.16.2",
62
- "@injectivelabs/ts-types": "^1.16.2",
63
- "@injectivelabs/utils": "^1.16.2",
64
- "@injectivelabs/wallet-base": "^1.16.2",
59
+ "@injectivelabs/exceptions": "^1.16.4-alpha.0",
60
+ "@injectivelabs/networks": "^1.16.4-alpha.0",
61
+ "@injectivelabs/sdk-ts": "^1.16.4-alpha.0",
62
+ "@injectivelabs/ts-types": "^1.16.4-alpha.0",
63
+ "@injectivelabs/utils": "^1.16.4-alpha.0",
64
+ "@injectivelabs/wallet-base": "^1.16.4-alpha.0",
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": "56e3f6c8f399c2d881a65858e8e0b1b39828a917"
71
+ "gitHead": "5022bb7556b861f334ed66d0a72d93dbaf24ad6b"
72
72
  }