@injectivelabs/wallet-trezor 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.
@@ -1,3 +1,4 @@
1
+ import { EvmChainId } from '@injectivelabs/ts-types';
1
2
  import { WalletDeviceType, BaseConcreteStrategy } from '@injectivelabs/wallet-base';
2
3
  import type { TrezorDerivationPathType } from '../types.js';
3
4
  import type { AccountAddress, EvmChainId as EvmChainIdType } from '@injectivelabs/ts-types';
@@ -35,7 +36,7 @@ export default class TrezorBase extends BaseConcreteStrategy implements Concrete
35
36
  }): Promise<DirectSignResponse>;
36
37
  signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
37
38
  getEthereumChainId(): Promise<string>;
38
- getEvmTransactionReceipt(txHash: string): Promise<string>;
39
+ getEvmTransactionReceipt(txHash: string, evmChainId?: EvmChainId): Promise<string>;
39
40
  getPubKey(): Promise<string>;
40
41
  private signEvmTransaction;
41
42
  private getWalletForAddress;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@injectivelabs/utils");
3
4
  const viem_1 = require("viem");
4
5
  const ts_types_1 = require("@injectivelabs/ts-types");
5
6
  const sdk_ts_1 = require("@injectivelabs/sdk-ts");
@@ -54,8 +55,11 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
54
55
  const signedTransaction = await this.signEvmTransaction(txData, args);
55
56
  try {
56
57
  const alchemy = await this.getAlchemy(args.evmChainId);
57
- const txReceipt = await alchemy.core.sendTransaction(signedTransaction);
58
- return txReceipt.hash;
58
+ const provider = await alchemy.config.getProvider();
59
+ const txHash = await provider.send('eth_sendRawTransaction', [
60
+ signedTransaction,
61
+ ]);
62
+ return txHash;
59
63
  }
60
64
  catch (e) {
61
65
  throw new exceptions_1.TrezorException(new Error(e.message), {
@@ -164,8 +168,26 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
164
168
  const alchemyProvider = await alchemy.config.getProvider();
165
169
  return alchemyProvider.network.chainId.toString();
166
170
  }
167
- async getEvmTransactionReceipt(txHash) {
168
- return Promise.resolve(txHash);
171
+ async getEvmTransactionReceipt(txHash, evmChainId) {
172
+ const alchemy = await this.getAlchemy(evmChainId);
173
+ const provider = await alchemy.config.getProvider();
174
+ const interval = 3000;
175
+ const maxAttempts = 10;
176
+ let attempts = 0;
177
+ while (attempts < maxAttempts) {
178
+ attempts++;
179
+ await (0, utils_1.sleep)(interval);
180
+ try {
181
+ const receipt = await provider.send('eth_getTransactionReceipt', [
182
+ txHash,
183
+ ]);
184
+ if (receipt) {
185
+ return txHash;
186
+ }
187
+ }
188
+ catch { }
189
+ }
190
+ throw new Error(`Failed to retrieve transaction receipt for txHash: ${txHash}`);
169
191
  }
170
192
  async getPubKey() {
171
193
  throw new exceptions_1.WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
@@ -175,16 +197,29 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
175
197
  const chainId = parseInt(args.evmChainId.toString(), 10);
176
198
  const alchemy = await this.getAlchemy(args.evmChainId);
177
199
  const nonce = await alchemy.core.getTransactionCount(args.address);
178
- // Create transaction data for Trezor API (still needs hex strings)
200
+ // Handle hex string values properly (with or without 0x prefix)
201
+ const parseHexValue = (value) => {
202
+ if (typeof value === 'string') {
203
+ const hexValue = value.startsWith('0x') ? value : `0x${value}`;
204
+ return BigInt(hexValue);
205
+ }
206
+ return BigInt(value);
207
+ };
208
+ // Convert to BigInt first, then to hex for Trezor
209
+ const valueBigInt = parseHexValue(txData.value || '0x0');
210
+ const gasBigInt = parseHexValue(txData.gas);
211
+ const maxFeePerGasBigInt = parseHexValue(txData.maxFeePerGas);
212
+ const maxPriorityFeePerGasBigInt = parseHexValue(txData.maxPriorityFeePerGas);
213
+ // Create transaction data for Trezor API (needs hex strings)
179
214
  const trezorTxData = {
180
215
  to: txData.to,
181
- value: (0, viem_1.toHex)(txData.value || 0),
182
- gasLimit: (0, viem_1.toHex)(txData.gas),
216
+ value: (0, viem_1.toHex)(valueBigInt),
217
+ gasLimit: (0, viem_1.toHex)(gasBigInt),
183
218
  nonce: (0, viem_1.toHex)(nonce),
184
219
  data: txData.data || '0x',
185
220
  chainId,
186
- maxFeePerGas: (0, viem_1.toHex)(txData.gasPrice || txData.maxFeePerGas),
187
- maxPriorityFeePerGas: (0, viem_1.toHex)(txData.maxPriorityFeePerGas || wallet_base_1.TIP_IN_GWEI),
221
+ maxFeePerGas: (0, viem_1.toHex)(maxFeePerGasBigInt),
222
+ maxPriorityFeePerGas: (0, viem_1.toHex)(maxPriorityFeePerGasBigInt),
188
223
  };
189
224
  try {
190
225
  await this.trezor.connect();
@@ -207,11 +242,11 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
207
242
  chainId,
208
243
  nonce,
209
244
  to: txData.to,
210
- value: BigInt(txData.value || 0),
245
+ value: valueBigInt,
211
246
  data: (txData.data || '0x'),
212
- gas: BigInt(txData.gas),
213
- maxFeePerGas: BigInt(txData.gasPrice || txData.maxFeePerGas),
214
- maxPriorityFeePerGas: BigInt(txData.maxPriorityFeePerGas || wallet_base_1.TIP_IN_GWEI),
247
+ gas: gasBigInt,
248
+ maxFeePerGas: maxFeePerGasBigInt,
249
+ maxPriorityFeePerGas: maxPriorityFeePerGasBigInt,
215
250
  v: BigInt(response.payload.v),
216
251
  r: response.payload.r,
217
252
  s: response.payload.s,
@@ -1,3 +1,4 @@
1
+ import { EvmChainId } from '@injectivelabs/ts-types';
1
2
  import { WalletDeviceType, BaseConcreteStrategy } from '@injectivelabs/wallet-base';
2
3
  import type { TrezorDerivationPathType } from '../types.js';
3
4
  import type { AccountAddress, EvmChainId as EvmChainIdType } from '@injectivelabs/ts-types';
@@ -35,7 +36,7 @@ export default class TrezorBase extends BaseConcreteStrategy implements Concrete
35
36
  }): Promise<DirectSignResponse>;
36
37
  signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
37
38
  getEthereumChainId(): Promise<string>;
38
- getEvmTransactionReceipt(txHash: string): Promise<string>;
39
+ getEvmTransactionReceipt(txHash: string, evmChainId?: EvmChainId): Promise<string>;
39
40
  getPubKey(): Promise<string>;
40
41
  private signEvmTransaction;
41
42
  private getWalletForAddress;
@@ -1,9 +1,10 @@
1
+ import { sleep } from '@injectivelabs/utils';
1
2
  import { toHex, serializeTransaction } from 'viem';
2
3
  import { EvmChainId } from '@injectivelabs/ts-types';
3
4
  import { toUtf8, TxGrpcApi } from '@injectivelabs/sdk-ts';
4
5
  import { Alchemy, Network as AlchemyNetwork } from 'alchemy-sdk';
5
6
  import { ErrorType, WalletException, TrezorException, 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 { loadTrezorConnect } from './lib.js';
8
9
  import { transformTypedData } from '../utils.js';
9
10
  import { BaseTrezorTransport } from './hw/index.js';
@@ -52,8 +53,11 @@ export default class TrezorBase 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 TrezorException(new Error(e.message), {
@@ -162,8 +166,26 @@ export default class TrezorBase extends BaseConcreteStrategy {
162
166
  const alchemyProvider = await alchemy.config.getProvider();
163
167
  return alchemyProvider.network.chainId.toString();
164
168
  }
165
- async getEvmTransactionReceipt(txHash) {
166
- return Promise.resolve(txHash);
169
+ async getEvmTransactionReceipt(txHash, evmChainId) {
170
+ const alchemy = await this.getAlchemy(evmChainId);
171
+ const provider = await alchemy.config.getProvider();
172
+ const interval = 3000;
173
+ const maxAttempts = 10;
174
+ let attempts = 0;
175
+ while (attempts < maxAttempts) {
176
+ attempts++;
177
+ await sleep(interval);
178
+ try {
179
+ const receipt = await provider.send('eth_getTransactionReceipt', [
180
+ txHash,
181
+ ]);
182
+ if (receipt) {
183
+ return txHash;
184
+ }
185
+ }
186
+ catch { }
187
+ }
188
+ throw new Error(`Failed to retrieve transaction receipt for txHash: ${txHash}`);
167
189
  }
168
190
  async getPubKey() {
169
191
  throw new WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
@@ -173,16 +195,29 @@ export default class TrezorBase extends BaseConcreteStrategy {
173
195
  const chainId = parseInt(args.evmChainId.toString(), 10);
174
196
  const alchemy = await this.getAlchemy(args.evmChainId);
175
197
  const nonce = await alchemy.core.getTransactionCount(args.address);
176
- // Create transaction data for Trezor API (still needs hex strings)
198
+ // Handle hex string values properly (with or without 0x prefix)
199
+ const parseHexValue = (value) => {
200
+ if (typeof value === 'string') {
201
+ const hexValue = value.startsWith('0x') ? value : `0x${value}`;
202
+ return BigInt(hexValue);
203
+ }
204
+ return BigInt(value);
205
+ };
206
+ // Convert to BigInt first, then to hex for Trezor
207
+ const valueBigInt = parseHexValue(txData.value || '0x0');
208
+ const gasBigInt = parseHexValue(txData.gas);
209
+ const maxFeePerGasBigInt = parseHexValue(txData.maxFeePerGas);
210
+ const maxPriorityFeePerGasBigInt = parseHexValue(txData.maxPriorityFeePerGas);
211
+ // Create transaction data for Trezor API (needs hex strings)
177
212
  const trezorTxData = {
178
213
  to: txData.to,
179
- value: toHex(txData.value || 0),
180
- gasLimit: toHex(txData.gas),
214
+ value: toHex(valueBigInt),
215
+ gasLimit: toHex(gasBigInt),
181
216
  nonce: toHex(nonce),
182
217
  data: txData.data || '0x',
183
218
  chainId,
184
- maxFeePerGas: toHex(txData.gasPrice || txData.maxFeePerGas),
185
- maxPriorityFeePerGas: toHex(txData.maxPriorityFeePerGas || TIP_IN_GWEI),
219
+ maxFeePerGas: toHex(maxFeePerGasBigInt),
220
+ maxPriorityFeePerGas: toHex(maxPriorityFeePerGasBigInt),
186
221
  };
187
222
  try {
188
223
  await this.trezor.connect();
@@ -205,11 +240,11 @@ export default class TrezorBase extends BaseConcreteStrategy {
205
240
  chainId,
206
241
  nonce,
207
242
  to: txData.to,
208
- value: BigInt(txData.value || 0),
243
+ value: valueBigInt,
209
244
  data: (txData.data || '0x'),
210
- gas: BigInt(txData.gas),
211
- maxFeePerGas: BigInt(txData.gasPrice || txData.maxFeePerGas),
212
- maxPriorityFeePerGas: BigInt(txData.maxPriorityFeePerGas || TIP_IN_GWEI),
245
+ gas: gasBigInt,
246
+ maxFeePerGas: maxFeePerGasBigInt,
247
+ maxPriorityFeePerGas: maxPriorityFeePerGasBigInt,
213
248
  v: BigInt(response.payload.v),
214
249
  r: response.payload.r,
215
250
  s: response.payload.s,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-trezor",
3
3
  "description": "Trezor 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": {
@@ -57,15 +57,15 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "@bangjelkoski/trezor-connect-web": "^9.4.7-beta.1",
60
- "@injectivelabs/exceptions": "1.16.13-alpha.3",
61
- "@injectivelabs/sdk-ts": "1.16.13-alpha.3",
62
- "@injectivelabs/ts-types": "1.16.13-alpha.3",
63
- "@injectivelabs/wallet-base": "1.16.13-alpha.3",
60
+ "@injectivelabs/exceptions": "1.16.13-alpha.5",
61
+ "@injectivelabs/sdk-ts": "1.16.13-alpha.5",
62
+ "@injectivelabs/ts-types": "1.16.13-alpha.5",
63
+ "@injectivelabs/wallet-base": "1.16.13-alpha.5",
64
64
  "alchemy-sdk": "^3.4.7",
65
65
  "viem": "^2.33.2"
66
66
  },
67
67
  "devDependencies": {
68
68
  "shx": "^0.3.3"
69
69
  },
70
- "gitHead": "9714d8be468bec92c649fee736e797912e3d5c12"
70
+ "gitHead": "04c89e8c28d3f1144059d0d70ef712b5d8dfb803"
71
71
  }