@injectivelabs/wallet-core 1.16.4-alpha.0 → 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,7 +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
|
-
|
|
33
|
+
getEvmChainId(): Promise<EthereumChainId | undefined>;
|
|
34
34
|
/**
|
|
35
35
|
* Broadcasting the transaction using the client
|
|
36
36
|
* side approach for both cosmos and ethereum native wallets
|
|
@@ -65,17 +65,23 @@ class MsgBroadcaster {
|
|
|
65
65
|
this.txTimeoutOnFeeDelegation =
|
|
66
66
|
options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation;
|
|
67
67
|
}
|
|
68
|
-
async
|
|
68
|
+
async getEvmChainId() {
|
|
69
69
|
const { walletStrategy } = this;
|
|
70
70
|
if (!(0, wallet_base_1.isEvmBrowserWallet)(walletStrategy.wallet)) {
|
|
71
|
-
return;
|
|
71
|
+
return this.ethereumChainId;
|
|
72
72
|
}
|
|
73
|
-
const mainnetEvmIds = [ts_types_1.EthereumChainId.Mainnet];
|
|
73
|
+
const mainnetEvmIds = [ts_types_1.EthereumChainId.Mainnet, ts_types_1.EthereumChainId.MainnetEvm];
|
|
74
74
|
const testnetEvmIds = [ts_types_1.EthereumChainId.Sepolia, ts_types_1.EthereumChainId.TestnetEvm];
|
|
75
75
|
const devnetEvmIds = [ts_types_1.EthereumChainId.Sepolia, ts_types_1.EthereumChainId.DevnetEvm];
|
|
76
76
|
try {
|
|
77
77
|
const chainId = await walletStrategy.getEthereumChainId();
|
|
78
|
+
if (!chainId) {
|
|
79
|
+
return this.ethereumChainId;
|
|
80
|
+
}
|
|
78
81
|
const evmChainId = parseInt(chainId, 16);
|
|
82
|
+
if (isNaN(evmChainId)) {
|
|
83
|
+
return this.ethereumChainId;
|
|
84
|
+
}
|
|
79
85
|
if (((0, networks_1.isMainnet)(this.options.network) &&
|
|
80
86
|
!mainnetEvmIds.includes(evmChainId)) ||
|
|
81
87
|
((0, networks_1.isTestnet)(this.options.network) &&
|
|
@@ -85,11 +91,11 @@ class MsgBroadcaster {
|
|
|
85
91
|
!devnetEvmIds.includes(evmChainId))) {
|
|
86
92
|
throw new exceptions_1.WalletException(new Error('Your selected network is incorrect'));
|
|
87
93
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
return evmChainId;
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
throw new exceptions_1.WalletException(e);
|
|
91
98
|
}
|
|
92
|
-
catch { }
|
|
93
99
|
}
|
|
94
100
|
/**
|
|
95
101
|
* Broadcasting the transaction using the client
|
|
@@ -197,12 +203,12 @@ class MsgBroadcaster {
|
|
|
197
203
|
* @returns transaction hash
|
|
198
204
|
*/
|
|
199
205
|
async broadcastEip712(tx) {
|
|
200
|
-
const { chainId, txTimeout, endpoints,
|
|
206
|
+
const { chainId, txTimeout, endpoints, walletStrategy } = this;
|
|
201
207
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
208
|
+
const ethereumChainId = await this.getEvmChainId();
|
|
202
209
|
if (!ethereumChainId) {
|
|
203
210
|
throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
|
|
204
211
|
}
|
|
205
|
-
await this.verifyEvmChainId();
|
|
206
212
|
/** Account Details * */
|
|
207
213
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
208
214
|
const timeoutHeight = new utils_1.BigNumberInBase(latestHeight).plus(txTimeout);
|
|
@@ -289,12 +295,12 @@ class MsgBroadcaster {
|
|
|
289
295
|
* @returns transaction hash
|
|
290
296
|
*/
|
|
291
297
|
async broadcastEip712V2(tx) {
|
|
292
|
-
const { chainId, endpoints, txTimeout, walletStrategy
|
|
298
|
+
const { chainId, endpoints, txTimeout, walletStrategy } = this;
|
|
293
299
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
300
|
+
const ethereumChainId = await this.getEvmChainId();
|
|
294
301
|
if (!ethereumChainId) {
|
|
295
302
|
throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
|
|
296
303
|
}
|
|
297
|
-
await this.verifyEvmChainId();
|
|
298
304
|
/** Account Details * */
|
|
299
305
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
300
306
|
const timeoutHeight = new utils_1.BigNumberInBase(latestHeight).plus(txTimeout);
|
|
@@ -381,13 +387,13 @@ class MsgBroadcaster {
|
|
|
381
387
|
* @returns transaction hash
|
|
382
388
|
*/
|
|
383
389
|
async broadcastEip712WithFeeDelegation(tx) {
|
|
384
|
-
const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy,
|
|
390
|
+
const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation, } = this;
|
|
385
391
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
386
392
|
const web3Msgs = msgs.map((msg) => msg.toWeb3());
|
|
393
|
+
const ethereumChainId = await this.getEvmChainId();
|
|
387
394
|
if (!ethereumChainId) {
|
|
388
395
|
throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
|
|
389
396
|
}
|
|
390
|
-
await this.verifyEvmChainId();
|
|
391
397
|
const transactionApi = new sdk_ts_1.IndexerGrpcWeb3GwApi(endpoints.web3gw || endpoints.indexer);
|
|
392
398
|
if (httpHeaders) {
|
|
393
399
|
transactionApi.setMetadata(httpHeaders);
|
|
@@ -30,7 +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
|
-
|
|
33
|
+
getEvmChainId(): Promise<EthereumChainId | undefined>;
|
|
34
34
|
/**
|
|
35
35
|
* Broadcasting the transaction using the client
|
|
36
36
|
* side approach for both cosmos and ethereum native wallets
|
|
@@ -62,17 +62,23 @@ export class MsgBroadcaster {
|
|
|
62
62
|
this.txTimeoutOnFeeDelegation =
|
|
63
63
|
options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation;
|
|
64
64
|
}
|
|
65
|
-
async
|
|
65
|
+
async getEvmChainId() {
|
|
66
66
|
const { walletStrategy } = this;
|
|
67
67
|
if (!isEvmBrowserWallet(walletStrategy.wallet)) {
|
|
68
|
-
return;
|
|
68
|
+
return this.ethereumChainId;
|
|
69
69
|
}
|
|
70
|
-
const mainnetEvmIds = [EthereumChainId.Mainnet];
|
|
70
|
+
const mainnetEvmIds = [EthereumChainId.Mainnet, EthereumChainId.MainnetEvm];
|
|
71
71
|
const testnetEvmIds = [EthereumChainId.Sepolia, EthereumChainId.TestnetEvm];
|
|
72
72
|
const devnetEvmIds = [EthereumChainId.Sepolia, EthereumChainId.DevnetEvm];
|
|
73
73
|
try {
|
|
74
74
|
const chainId = await walletStrategy.getEthereumChainId();
|
|
75
|
+
if (!chainId) {
|
|
76
|
+
return this.ethereumChainId;
|
|
77
|
+
}
|
|
75
78
|
const evmChainId = parseInt(chainId, 16);
|
|
79
|
+
if (isNaN(evmChainId)) {
|
|
80
|
+
return this.ethereumChainId;
|
|
81
|
+
}
|
|
76
82
|
if ((isMainnet(this.options.network) &&
|
|
77
83
|
!mainnetEvmIds.includes(evmChainId)) ||
|
|
78
84
|
(isTestnet(this.options.network) &&
|
|
@@ -82,11 +88,11 @@ export class MsgBroadcaster {
|
|
|
82
88
|
!devnetEvmIds.includes(evmChainId))) {
|
|
83
89
|
throw new WalletException(new Error('Your selected network is incorrect'));
|
|
84
90
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
return evmChainId;
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
throw new WalletException(e);
|
|
88
95
|
}
|
|
89
|
-
catch { }
|
|
90
96
|
}
|
|
91
97
|
/**
|
|
92
98
|
* Broadcasting the transaction using the client
|
|
@@ -194,12 +200,12 @@ export class MsgBroadcaster {
|
|
|
194
200
|
* @returns transaction hash
|
|
195
201
|
*/
|
|
196
202
|
async broadcastEip712(tx) {
|
|
197
|
-
const { chainId, txTimeout, endpoints,
|
|
203
|
+
const { chainId, txTimeout, endpoints, walletStrategy } = this;
|
|
198
204
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
205
|
+
const ethereumChainId = await this.getEvmChainId();
|
|
199
206
|
if (!ethereumChainId) {
|
|
200
207
|
throw new GeneralException(new Error('Please provide ethereumChainId'));
|
|
201
208
|
}
|
|
202
|
-
await this.verifyEvmChainId();
|
|
203
209
|
/** Account Details * */
|
|
204
210
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
205
211
|
const timeoutHeight = new BigNumberInBase(latestHeight).plus(txTimeout);
|
|
@@ -286,12 +292,12 @@ export class MsgBroadcaster {
|
|
|
286
292
|
* @returns transaction hash
|
|
287
293
|
*/
|
|
288
294
|
async broadcastEip712V2(tx) {
|
|
289
|
-
const { chainId, endpoints, txTimeout, walletStrategy
|
|
295
|
+
const { chainId, endpoints, txTimeout, walletStrategy } = this;
|
|
290
296
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
297
|
+
const ethereumChainId = await this.getEvmChainId();
|
|
291
298
|
if (!ethereumChainId) {
|
|
292
299
|
throw new GeneralException(new Error('Please provide ethereumChainId'));
|
|
293
300
|
}
|
|
294
|
-
await this.verifyEvmChainId();
|
|
295
301
|
/** Account Details * */
|
|
296
302
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
297
303
|
const timeoutHeight = new BigNumberInBase(latestHeight).plus(txTimeout);
|
|
@@ -378,13 +384,13 @@ export class MsgBroadcaster {
|
|
|
378
384
|
* @returns transaction hash
|
|
379
385
|
*/
|
|
380
386
|
async broadcastEip712WithFeeDelegation(tx) {
|
|
381
|
-
const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy,
|
|
387
|
+
const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation, } = this;
|
|
382
388
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
383
389
|
const web3Msgs = msgs.map((msg) => msg.toWeb3());
|
|
390
|
+
const ethereumChainId = await this.getEvmChainId();
|
|
384
391
|
if (!ethereumChainId) {
|
|
385
392
|
throw new GeneralException(new Error('Please provide ethereumChainId'));
|
|
386
393
|
}
|
|
387
|
-
await this.verifyEvmChainId();
|
|
388
394
|
const transactionApi = new IndexerGrpcWeb3GwApi(endpoints.web3gw || endpoints.indexer);
|
|
389
395
|
if (httpHeaders) {
|
|
390
396
|
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.4
|
|
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.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
|
|
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
|
}
|