@injectivelabs/wallet-ledger 1.16.13-alpha.3 → 1.16.13-alpha.5

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.
@@ -36,7 +36,7 @@ export default class LedgerBase extends BaseConcreteStrategy implements Concrete
36
36
  }): Promise<DirectSignResponse>;
37
37
  signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
38
38
  getEthereumChainId(): Promise<string>;
39
- getEvmTransactionReceipt(txHash: string): Promise<string>;
39
+ getEvmTransactionReceipt(txHash: string, evmChainId?: EvmChainId): Promise<string>;
40
40
  getPubKey(): Promise<string>;
41
41
  private signEvmTransaction;
42
42
  private getWalletForAddress;
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("@injectivelabs/utils");
7
+ const viem_1 = require("viem");
6
8
  const ts_types_1 = require("@injectivelabs/ts-types");
7
9
  const sdk_ts_1 = require("@injectivelabs/sdk-ts");
8
- const viem_1 = require("viem");
9
10
  const alchemy_sdk_1 = require("alchemy-sdk");
10
11
  const exceptions_1 = require("@injectivelabs/exceptions");
11
12
  const wallet_base_1 = require("@injectivelabs/wallet-base");
@@ -57,8 +58,11 @@ class LedgerBase extends wallet_base_1.BaseConcreteStrategy {
57
58
  const signedTransaction = await this.signEvmTransaction(txData, args);
58
59
  try {
59
60
  const alchemy = await this.getAlchemy(args.evmChainId);
60
- const txReceipt = await alchemy.core.sendTransaction(signedTransaction);
61
- return txReceipt.hash;
61
+ const provider = await alchemy.config.getProvider();
62
+ const txHash = await provider.send('eth_sendRawTransaction', [
63
+ signedTransaction,
64
+ ]);
65
+ return txHash;
62
66
  }
63
67
  catch (e) {
64
68
  throw new exceptions_1.LedgerException(new Error(e.message), {
@@ -156,8 +160,26 @@ class LedgerBase extends wallet_base_1.BaseConcreteStrategy {
156
160
  const alchemyProvider = await alchemy.config.getProvider();
157
161
  return alchemyProvider.network.chainId.toString();
158
162
  }
159
- async getEvmTransactionReceipt(txHash) {
160
- return Promise.resolve(txHash);
163
+ async getEvmTransactionReceipt(txHash, evmChainId) {
164
+ const alchemy = await this.getAlchemy(evmChainId);
165
+ const provider = await alchemy.config.getProvider();
166
+ const interval = 3000;
167
+ const maxAttempts = 10;
168
+ let attempts = 0;
169
+ while (attempts < maxAttempts) {
170
+ attempts++;
171
+ await (0, utils_1.sleep)(interval);
172
+ try {
173
+ const receipt = await provider.send('eth_getTransactionReceipt', [
174
+ txHash,
175
+ ]);
176
+ if (receipt) {
177
+ return txHash;
178
+ }
179
+ }
180
+ catch { }
181
+ }
182
+ throw new Error(`Failed to retrieve transaction receipt for txHash: ${txHash}`);
161
183
  }
162
184
  async getPubKey() {
163
185
  throw new exceptions_1.WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
@@ -167,26 +189,34 @@ class LedgerBase extends wallet_base_1.BaseConcreteStrategy {
167
189
  const alchemy = await this.getAlchemy(args.evmChainId);
168
190
  const chainId = parseInt(args.evmChainId.toString(), 10);
169
191
  const nonce = await alchemy.core.getTransactionCount(args.address);
192
+ const parseHexValue = (value) => {
193
+ if (typeof value === 'string') {
194
+ const hexValue = value.startsWith('0x') ? value : `0x${value}`;
195
+ return BigInt(hexValue);
196
+ }
197
+ return BigInt(value);
198
+ };
170
199
  const eip1559TxData = {
171
200
  type: 'eip1559',
172
201
  chainId,
173
202
  nonce,
174
203
  to: txData.to,
175
- value: BigInt(txData.value || 0),
204
+ value: parseHexValue(txData.value || '0x0'),
176
205
  data: txData.data,
177
- gas: BigInt(txData.gas),
178
- maxFeePerGas: BigInt(txData.gasPrice || txData.maxFeePerGas),
179
- maxPriorityFeePerGas: BigInt(txData.maxPriorityFeePerGas || wallet_base_1.TIP_IN_GWEI),
206
+ gas: parseHexValue(txData.gas),
207
+ maxFeePerGas: parseHexValue(txData.maxFeePerGas),
208
+ maxPriorityFeePerGas: parseHexValue(txData.maxPriorityFeePerGas),
180
209
  };
181
- // Serialize the transaction to get the message hash for signing
210
+ // Serialize the transaction
182
211
  const serializedTx = (0, viem_1.serializeTransaction)(eip1559TxData);
183
- const messageHash = (0, viem_1.keccak256)(serializedTx);
184
- const encodedMessageHex = messageHash.slice(2); // Remove 0x prefix
212
+ const serializedTxHex = serializedTx.slice(2); // Remove 0x prefix
185
213
  try {
186
214
  const ledger = await this.ledger.getInstance();
187
215
  const { derivationPath } = await this.getWalletForAddress(args.address);
188
- const resolution = await ledgerService.resolveTransaction(encodedMessageHex, {}, {});
189
- const txSig = await ledger.signTransaction(derivationPath, encodedMessageHex, resolution);
216
+ // Resolve transaction for Ledger display
217
+ const resolution = await ledgerService.resolveTransaction(serializedTxHex, {}, {});
218
+ // Sign the transaction with Ledger
219
+ const txSig = await ledger.signTransaction(derivationPath, serializedTxHex, resolution);
190
220
  const signedTxData = {
191
221
  ...eip1559TxData,
192
222
  v: BigInt(`0x${txSig.v}`),
@@ -36,7 +36,7 @@ export default class LedgerBase extends BaseConcreteStrategy implements Concrete
36
36
  }): Promise<DirectSignResponse>;
37
37
  signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
38
38
  getEthereumChainId(): Promise<string>;
39
- getEvmTransactionReceipt(txHash: string): Promise<string>;
39
+ getEvmTransactionReceipt(txHash: string, evmChainId?: EvmChainId): Promise<string>;
40
40
  getPubKey(): Promise<string>;
41
41
  private signEvmTransaction;
42
42
  private getWalletForAddress;
@@ -1,9 +1,10 @@
1
+ import { sleep } from '@injectivelabs/utils';
2
+ import { toHex, serializeTransaction } from 'viem';
1
3
  import { EvmChainId } from '@injectivelabs/ts-types';
2
4
  import { toUtf8, TxGrpcApi } from '@injectivelabs/sdk-ts';
3
- import { toHex, keccak256, serializeTransaction } from 'viem';
4
5
  import { Alchemy, Network as AlchemyNetwork } from 'alchemy-sdk';
5
6
  import { ErrorType, LedgerException, WalletException, GeneralException, UnspecifiedErrorCode, TransactionException, } from '@injectivelabs/exceptions';
6
- import { TIP_IN_GWEI, 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, BaseConcreteStrategy, DEFAULT_BASE_DERIVATION_PATH, DEFAULT_ADDRESS_SEARCH_LIMIT, DEFAULT_NUM_ADDRESSES_TO_FETCH, } from '@injectivelabs/wallet-base';
7
8
  import LedgerHW from './hw/index.js';
8
9
  import { loadLedgerServiceType } from './../lib.js';
9
10
  import { domainHash, messageHash } from './utils.js';
@@ -52,8 +53,11 @@ export default class LedgerBase extends BaseConcreteStrategy {
52
53
  const signedTransaction = await this.signEvmTransaction(txData, args);
53
54
  try {
54
55
  const alchemy = await this.getAlchemy(args.evmChainId);
55
- const txReceipt = await alchemy.core.sendTransaction(signedTransaction);
56
- return txReceipt.hash;
56
+ const provider = await alchemy.config.getProvider();
57
+ const txHash = await provider.send('eth_sendRawTransaction', [
58
+ signedTransaction,
59
+ ]);
60
+ return txHash;
57
61
  }
58
62
  catch (e) {
59
63
  throw new LedgerException(new Error(e.message), {
@@ -151,8 +155,26 @@ export default class LedgerBase extends BaseConcreteStrategy {
151
155
  const alchemyProvider = await alchemy.config.getProvider();
152
156
  return alchemyProvider.network.chainId.toString();
153
157
  }
154
- async getEvmTransactionReceipt(txHash) {
155
- return Promise.resolve(txHash);
158
+ async getEvmTransactionReceipt(txHash, evmChainId) {
159
+ const alchemy = await this.getAlchemy(evmChainId);
160
+ const provider = await alchemy.config.getProvider();
161
+ const interval = 3000;
162
+ const maxAttempts = 10;
163
+ let attempts = 0;
164
+ while (attempts < maxAttempts) {
165
+ attempts++;
166
+ await sleep(interval);
167
+ try {
168
+ const receipt = await provider.send('eth_getTransactionReceipt', [
169
+ txHash,
170
+ ]);
171
+ if (receipt) {
172
+ return txHash;
173
+ }
174
+ }
175
+ catch { }
176
+ }
177
+ throw new Error(`Failed to retrieve transaction receipt for txHash: ${txHash}`);
156
178
  }
157
179
  async getPubKey() {
158
180
  throw new WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
@@ -162,26 +184,34 @@ export default class LedgerBase extends BaseConcreteStrategy {
162
184
  const alchemy = await this.getAlchemy(args.evmChainId);
163
185
  const chainId = parseInt(args.evmChainId.toString(), 10);
164
186
  const nonce = await alchemy.core.getTransactionCount(args.address);
187
+ const parseHexValue = (value) => {
188
+ if (typeof value === 'string') {
189
+ const hexValue = value.startsWith('0x') ? value : `0x${value}`;
190
+ return BigInt(hexValue);
191
+ }
192
+ return BigInt(value);
193
+ };
165
194
  const eip1559TxData = {
166
195
  type: 'eip1559',
167
196
  chainId,
168
197
  nonce,
169
198
  to: txData.to,
170
- value: BigInt(txData.value || 0),
199
+ value: parseHexValue(txData.value || '0x0'),
171
200
  data: txData.data,
172
- gas: BigInt(txData.gas),
173
- maxFeePerGas: BigInt(txData.gasPrice || txData.maxFeePerGas),
174
- maxPriorityFeePerGas: BigInt(txData.maxPriorityFeePerGas || TIP_IN_GWEI),
201
+ gas: parseHexValue(txData.gas),
202
+ maxFeePerGas: parseHexValue(txData.maxFeePerGas),
203
+ maxPriorityFeePerGas: parseHexValue(txData.maxPriorityFeePerGas),
175
204
  };
176
- // Serialize the transaction to get the message hash for signing
205
+ // Serialize the transaction
177
206
  const serializedTx = serializeTransaction(eip1559TxData);
178
- const messageHash = keccak256(serializedTx);
179
- const encodedMessageHex = messageHash.slice(2); // Remove 0x prefix
207
+ const serializedTxHex = serializedTx.slice(2); // Remove 0x prefix
180
208
  try {
181
209
  const ledger = await this.ledger.getInstance();
182
210
  const { derivationPath } = await this.getWalletForAddress(args.address);
183
- const resolution = await ledgerService.resolveTransaction(encodedMessageHex, {}, {});
184
- const txSig = await ledger.signTransaction(derivationPath, encodedMessageHex, resolution);
211
+ // Resolve transaction for Ledger display
212
+ const resolution = await ledgerService.resolveTransaction(serializedTxHex, {}, {});
213
+ // Sign the transaction with Ledger
214
+ const txSig = await ledger.signTransaction(derivationPath, serializedTxHex, resolution);
185
215
  const signedTxData = {
186
216
  ...eip1559TxData,
187
217
  v: BigInt(`0x${txSig.v}`),
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.13-alpha.3",
4
+ "version": "1.16.13-alpha.5",
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.13-alpha.3",
65
- "@injectivelabs/sdk-ts": "1.16.13-alpha.3",
66
- "@injectivelabs/ts-types": "1.16.13-alpha.3",
67
- "@injectivelabs/wallet-base": "1.16.13-alpha.3",
64
+ "@injectivelabs/exceptions": "1.16.13-alpha.5",
65
+ "@injectivelabs/sdk-ts": "1.16.13-alpha.5",
66
+ "@injectivelabs/ts-types": "1.16.13-alpha.5",
67
+ "@injectivelabs/wallet-base": "1.16.13-alpha.5",
68
68
  "alchemy-sdk": "^3.4.7",
69
69
  "viem": "^2.33.2"
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": "9714d8be468bec92c649fee736e797912e3d5c12"
75
+ "gitHead": "04c89e8c28d3f1144059d0d70ef712b5d8dfb803"
76
76
  }