@injectivelabs/wallet-ledger 1.16.35 → 1.16.37

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.
@@ -55,7 +55,29 @@ class LedgerBase extends wallet_base_1.BaseConcreteStrategy {
55
55
  return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
56
56
  }
57
57
  async sendEvmTransaction(txData, args) {
58
+ const evmChainId = args.evmChainId;
59
+ const injectiveEvmChainIds = [
60
+ ts_types_1.EvmChainId.MainnetEvm,
61
+ ts_types_1.EvmChainId.TestnetEvm,
62
+ ts_types_1.EvmChainId.DevnetEvm,
63
+ ];
58
64
  const signedTransaction = await this.signEvmTransaction(txData, args);
65
+ if (injectiveEvmChainIds.includes(evmChainId)) {
66
+ try {
67
+ const publicClient = (0, wallet_base_1.getViemPublicClient)(evmChainId);
68
+ const txHash = await publicClient.sendRawTransaction({
69
+ serializedTransaction: signedTransaction,
70
+ });
71
+ return txHash;
72
+ }
73
+ catch (e) {
74
+ throw new exceptions_1.LedgerException(new Error(e.message), {
75
+ code: exceptions_1.UnspecifiedErrorCode,
76
+ type: exceptions_1.ErrorType.WalletError,
77
+ contextModule: wallet_base_1.WalletAction.SendEvmTransaction,
78
+ });
79
+ }
80
+ }
59
81
  try {
60
82
  const alchemy = await this.getAlchemy(args.evmChainId);
61
83
  const provider = await alchemy.config.getProvider();
@@ -161,11 +183,34 @@ class LedgerBase extends wallet_base_1.BaseConcreteStrategy {
161
183
  return alchemyProvider.network.chainId.toString();
162
184
  }
163
185
  async getEvmTransactionReceipt(txHash, evmChainId) {
164
- const alchemy = await this.getAlchemy(evmChainId);
165
- const provider = await alchemy.config.getProvider();
186
+ const chainId = evmChainId || this.evmOptions.evmChainId;
187
+ const injectiveEvmChainIds = [
188
+ ts_types_1.EvmChainId.MainnetEvm,
189
+ ts_types_1.EvmChainId.TestnetEvm,
190
+ ts_types_1.EvmChainId.DevnetEvm,
191
+ ];
166
192
  const interval = 3000;
167
193
  const maxAttempts = 10;
168
194
  let attempts = 0;
195
+ if (injectiveEvmChainIds.includes(chainId)) {
196
+ const publicClient = (0, wallet_base_1.getViemPublicClient)(chainId);
197
+ while (attempts < maxAttempts) {
198
+ attempts++;
199
+ await (0, utils_1.sleep)(interval);
200
+ try {
201
+ const receipt = await publicClient.getTransactionReceipt({
202
+ hash: txHash,
203
+ });
204
+ if (receipt) {
205
+ return txHash;
206
+ }
207
+ }
208
+ catch { }
209
+ }
210
+ throw new Error(`Failed to retrieve transaction receipt for txHash: ${txHash}`);
211
+ }
212
+ const alchemy = await this.getAlchemy(evmChainId);
213
+ const provider = await alchemy.config.getProvider();
169
214
  while (attempts < maxAttempts) {
170
215
  attempts++;
171
216
  await (0, utils_1.sleep)(interval);
@@ -186,9 +231,23 @@ class LedgerBase extends wallet_base_1.BaseConcreteStrategy {
186
231
  }
187
232
  async signEvmTransaction(txData, args) {
188
233
  const ledgerService = await (0, lib_js_1.loadLedgerServiceType)();
189
- const alchemy = await this.getAlchemy(args.evmChainId);
190
234
  const chainId = parseInt(args.evmChainId.toString(), 10);
191
- const nonce = await alchemy.core.getTransactionCount(args.address);
235
+ const injectiveEvmChainIds = [
236
+ ts_types_1.EvmChainId.MainnetEvm,
237
+ ts_types_1.EvmChainId.TestnetEvm,
238
+ ts_types_1.EvmChainId.DevnetEvm,
239
+ ];
240
+ let nonce;
241
+ if (injectiveEvmChainIds.includes(args.evmChainId)) {
242
+ const publicClient = (0, wallet_base_1.getViemPublicClient)(args.evmChainId);
243
+ nonce = await publicClient.getTransactionCount({
244
+ address: args.address,
245
+ });
246
+ }
247
+ else {
248
+ const alchemy = await this.getAlchemy(args.evmChainId);
249
+ nonce = await alchemy.core.getTransactionCount(args.address);
250
+ }
192
251
  const parseHexValue = (value) => {
193
252
  if (typeof value === 'string') {
194
253
  const hexValue = value.startsWith('0x') ? value : `0x${value}`;
@@ -4,7 +4,7 @@ import { EvmChainId } from '@injectivelabs/ts-types';
4
4
  import { toUtf8, TxGrpcApi } from '@injectivelabs/sdk-ts';
5
5
  import { Alchemy, Network as AlchemyNetwork } from 'alchemy-sdk';
6
6
  import { ErrorType, LedgerException, WalletException, GeneralException, UnspecifiedErrorCode, TransactionException, } from '@injectivelabs/exceptions';
7
- import { WalletAction, getKeyFromRpcUrl, WalletDeviceType, BaseConcreteStrategy, DEFAULT_BASE_DERIVATION_PATH, DEFAULT_ADDRESS_SEARCH_LIMIT, DEFAULT_NUM_ADDRESSES_TO_FETCH, } from '@injectivelabs/wallet-base';
7
+ import { WalletAction, getKeyFromRpcUrl, WalletDeviceType, getViemPublicClient, BaseConcreteStrategy, DEFAULT_BASE_DERIVATION_PATH, DEFAULT_ADDRESS_SEARCH_LIMIT, DEFAULT_NUM_ADDRESSES_TO_FETCH, } from '@injectivelabs/wallet-base';
8
8
  import LedgerHW from './hw/index.js';
9
9
  import { loadLedgerServiceType } from './../lib.js';
10
10
  import { domainHash, messageHash } from './utils.js';
@@ -50,7 +50,29 @@ export default class LedgerBase extends BaseConcreteStrategy {
50
50
  return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
51
51
  }
52
52
  async sendEvmTransaction(txData, args) {
53
+ const evmChainId = args.evmChainId;
54
+ const injectiveEvmChainIds = [
55
+ EvmChainId.MainnetEvm,
56
+ EvmChainId.TestnetEvm,
57
+ EvmChainId.DevnetEvm,
58
+ ];
53
59
  const signedTransaction = await this.signEvmTransaction(txData, args);
60
+ if (injectiveEvmChainIds.includes(evmChainId)) {
61
+ try {
62
+ const publicClient = getViemPublicClient(evmChainId);
63
+ const txHash = await publicClient.sendRawTransaction({
64
+ serializedTransaction: signedTransaction,
65
+ });
66
+ return txHash;
67
+ }
68
+ catch (e) {
69
+ throw new LedgerException(new Error(e.message), {
70
+ code: UnspecifiedErrorCode,
71
+ type: ErrorType.WalletError,
72
+ contextModule: WalletAction.SendEvmTransaction,
73
+ });
74
+ }
75
+ }
54
76
  try {
55
77
  const alchemy = await this.getAlchemy(args.evmChainId);
56
78
  const provider = await alchemy.config.getProvider();
@@ -156,11 +178,34 @@ export default class LedgerBase extends BaseConcreteStrategy {
156
178
  return alchemyProvider.network.chainId.toString();
157
179
  }
158
180
  async getEvmTransactionReceipt(txHash, evmChainId) {
159
- const alchemy = await this.getAlchemy(evmChainId);
160
- const provider = await alchemy.config.getProvider();
181
+ const chainId = evmChainId || this.evmOptions.evmChainId;
182
+ const injectiveEvmChainIds = [
183
+ EvmChainId.MainnetEvm,
184
+ EvmChainId.TestnetEvm,
185
+ EvmChainId.DevnetEvm,
186
+ ];
161
187
  const interval = 3000;
162
188
  const maxAttempts = 10;
163
189
  let attempts = 0;
190
+ if (injectiveEvmChainIds.includes(chainId)) {
191
+ const publicClient = getViemPublicClient(chainId);
192
+ while (attempts < maxAttempts) {
193
+ attempts++;
194
+ await sleep(interval);
195
+ try {
196
+ const receipt = await publicClient.getTransactionReceipt({
197
+ hash: txHash,
198
+ });
199
+ if (receipt) {
200
+ return txHash;
201
+ }
202
+ }
203
+ catch { }
204
+ }
205
+ throw new Error(`Failed to retrieve transaction receipt for txHash: ${txHash}`);
206
+ }
207
+ const alchemy = await this.getAlchemy(evmChainId);
208
+ const provider = await alchemy.config.getProvider();
164
209
  while (attempts < maxAttempts) {
165
210
  attempts++;
166
211
  await sleep(interval);
@@ -181,9 +226,23 @@ export default class LedgerBase extends BaseConcreteStrategy {
181
226
  }
182
227
  async signEvmTransaction(txData, args) {
183
228
  const ledgerService = await loadLedgerServiceType();
184
- const alchemy = await this.getAlchemy(args.evmChainId);
185
229
  const chainId = parseInt(args.evmChainId.toString(), 10);
186
- const nonce = await alchemy.core.getTransactionCount(args.address);
230
+ const injectiveEvmChainIds = [
231
+ EvmChainId.MainnetEvm,
232
+ EvmChainId.TestnetEvm,
233
+ EvmChainId.DevnetEvm,
234
+ ];
235
+ let nonce;
236
+ if (injectiveEvmChainIds.includes(args.evmChainId)) {
237
+ const publicClient = getViemPublicClient(args.evmChainId);
238
+ nonce = await publicClient.getTransactionCount({
239
+ address: args.address,
240
+ });
241
+ }
242
+ else {
243
+ const alchemy = await this.getAlchemy(args.evmChainId);
244
+ nonce = await alchemy.core.getTransactionCount(args.address);
245
+ }
187
246
  const parseHexValue = (value) => {
188
247
  if (typeof value === 'string') {
189
248
  const hexValue = value.startsWith('0x') ? value : `0x${value}`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-ledger",
3
3
  "description": "Ledger wallet strategy for use with @injectivelabs/wallet-core.",
4
- "version": "1.16.35",
4
+ "version": "1.16.37",
5
5
  "sideEffects": false,
6
6
  "type": "module",
7
7
  "author": {
@@ -61,10 +61,10 @@
61
61
  "@bangjelkoski/ledgerhq-hw-transport": "6.31.4-beta.0",
62
62
  "@bangjelkoski/ledgerhq-hw-transport-webhid": "6.30.0-beta.0",
63
63
  "@bangjelkoski/ledgerhq-hw-transport-webusb": "6.29.4-beta.0",
64
- "@injectivelabs/exceptions": "1.16.35",
65
- "@injectivelabs/sdk-ts": "1.16.35",
66
- "@injectivelabs/ts-types": "1.16.35",
67
- "@injectivelabs/wallet-base": "1.16.35",
64
+ "@injectivelabs/exceptions": "1.16.37",
65
+ "@injectivelabs/sdk-ts": "1.16.37",
66
+ "@injectivelabs/ts-types": "1.16.37",
67
+ "@injectivelabs/wallet-base": "1.16.37",
68
68
  "alchemy-sdk": "^3.4.7",
69
69
  "viem": "^2.40.3"
70
70
  },
@@ -72,5 +72,5 @@
72
72
  "@types/ledgerhq__hw-transport-webusb": "^4.70.1",
73
73
  "shx": "^0.3.4"
74
74
  },
75
- "gitHead": "e23004af8be1d324867bea4f80c7df986fcfc908"
75
+ "gitHead": "19aba0ded5503dc870cf17028e9cb04e6cc4409a"
76
76
  }