@injectivelabs/wallet-trezor 1.15.30 → 1.15.32

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.
@@ -16,7 +16,7 @@ export default class TrezorBase extends BaseConcreteStrategy implements Concrete
16
16
  disconnect(): Promise<void>;
17
17
  getAddresses(): Promise<string[]>;
18
18
  getSessionOrConfirm(address: AccountAddress): Promise<string>;
19
- sendEthereumTransaction(txData: any, options: {
19
+ sendEvmTransaction(txData: any, args: {
20
20
  address: string;
21
21
  ethereumChainId: EthereumChainId;
22
22
  }): Promise<string>;
@@ -34,9 +34,9 @@ export default class TrezorBase extends BaseConcreteStrategy implements Concrete
34
34
  }): Promise<DirectSignResponse>;
35
35
  signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
36
36
  getEthereumChainId(): Promise<string>;
37
- getEthereumTransactionReceipt(txHash: string): Promise<string>;
37
+ getEvmTransactionReceipt(txHash: string): Promise<string>;
38
38
  getPubKey(): Promise<string>;
39
- private signEthereumTransaction;
39
+ private signEvmTransaction;
40
40
  private getWalletForAddress;
41
41
  private getAlchemy;
42
42
  }
@@ -66,10 +66,10 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
66
66
  async getSessionOrConfirm(address) {
67
67
  return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
68
68
  }
69
- async sendEthereumTransaction(txData, options) {
70
- const signedTransaction = await this.signEthereumTransaction(txData, options);
69
+ async sendEvmTransaction(txData, args) {
70
+ const signedTransaction = await this.signEvmTransaction(txData, args);
71
71
  try {
72
- const alchemy = await this.getAlchemy();
72
+ const alchemy = await this.getAlchemy(args.ethereumChainId);
73
73
  const txReceipt = await alchemy.core.sendTransaction((0, ethereumjs_util_1.addHexPrefix)(signedTransaction.serialize().toString('hex')));
74
74
  return txReceipt.hash;
75
75
  }
@@ -77,7 +77,7 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
77
77
  throw new exceptions_1.TrezorException(new Error(e.message), {
78
78
  code: exceptions_1.UnspecifiedErrorCode,
79
79
  type: exceptions_1.ErrorType.WalletError,
80
- contextModule: wallet_base_1.WalletAction.SendEthereumTransaction,
80
+ contextModule: wallet_base_1.WalletAction.SendEvmTransaction,
81
81
  });
82
82
  }
83
83
  }
@@ -179,17 +179,17 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
179
179
  const alchemyProvider = await alchemy.config.getProvider();
180
180
  return alchemyProvider.network.chainId.toString();
181
181
  }
182
- async getEthereumTransactionReceipt(txHash) {
182
+ async getEvmTransactionReceipt(txHash) {
183
183
  return Promise.resolve(txHash);
184
184
  }
185
185
  // eslint-disable-next-line class-methods-use-this
186
186
  async getPubKey() {
187
187
  throw new exceptions_1.WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
188
188
  }
189
- async signEthereumTransaction(txData, options) {
190
- const chainId = parseInt(options.ethereumChainId.toString(), 10);
191
- const alchemy = await this.getAlchemy();
192
- const nonce = await alchemy.core.getTransactionCount(options.address);
189
+ async signEvmTransaction(txData, args) {
190
+ const chainId = parseInt(args.ethereumChainId.toString(), 10);
191
+ const alchemy = await this.getAlchemy(args.ethereumChainId);
192
+ const nonce = await alchemy.core.getTransactionCount(args.address);
193
193
  const common = new common_1.Common({
194
194
  chain: getNetworkFromChainId(chainId),
195
195
  hardfork: common_1.Hardfork.London,
@@ -213,7 +213,7 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
213
213
  };
214
214
  try {
215
215
  await this.trezor.connect();
216
- const { derivationPath } = await this.getWalletForAddress(options.address);
216
+ const { derivationPath } = await this.getWalletForAddress(args.address);
217
217
  const response = await trezor_connect_web_1.TrezorConnect.ethereumSignTransaction({
218
218
  path: derivationPath,
219
219
  transaction,
@@ -223,7 +223,7 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
223
223
  'Something happened while signing with Trezor'), {
224
224
  code: exceptions_1.UnspecifiedErrorCode,
225
225
  type: exceptions_1.ErrorType.WalletError,
226
- contextModule: wallet_base_1.WalletAction.SignEthereumTransaction,
226
+ contextModule: wallet_base_1.WalletAction.SignEvmTransaction,
227
227
  });
228
228
  }
229
229
  const signedTxData = {
@@ -243,7 +243,7 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
243
243
  throw new exceptions_1.TrezorException(new Error(e.message), {
244
244
  code: exceptions_1.UnspecifiedErrorCode,
245
245
  type: exceptions_1.ErrorType.WalletError,
246
- contextModule: wallet_base_1.WalletAction.SignEthereumTransaction,
246
+ contextModule: wallet_base_1.WalletAction.SignEvmTransaction,
247
247
  });
248
248
  }
249
249
  }
@@ -260,17 +260,19 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
260
260
  }
261
261
  return (await accountManager.getWalletForAddress(address));
262
262
  }
263
- async getAlchemy() {
263
+ async getAlchemy(ethereumChainId) {
264
264
  if (this.alchemy) {
265
265
  return this.alchemy;
266
266
  }
267
- const { rpcUrl, ethereumChainId } = this.ethereumOptions;
268
- if (!rpcUrl) {
267
+ const options = this.ethereumOptions;
268
+ const chainId = ethereumChainId || options.ethereumChainId;
269
+ const url = options.rpcUrl || options.rpcUrls?.[chainId];
270
+ if (!url) {
269
271
  throw new exceptions_1.GeneralException(new Error('Please pass rpcUrl within the ethereumOptions'));
270
272
  }
271
273
  this.alchemy = new alchemy_sdk_1.Alchemy({
272
- apiKey: (0, wallet_base_1.getKeyFromRpcUrl)(rpcUrl),
273
- network: ethereumChainId === ts_types_1.EthereumChainId.Mainnet
274
+ apiKey: (0, wallet_base_1.getKeyFromRpcUrl)(url),
275
+ network: chainId === ts_types_1.EthereumChainId.Mainnet
274
276
  ? alchemy_sdk_1.Network.ETH_MAINNET
275
277
  : alchemy_sdk_1.Network.ETH_SEPOLIA,
276
278
  });
@@ -16,7 +16,7 @@ export default class TrezorBase extends BaseConcreteStrategy implements Concrete
16
16
  disconnect(): Promise<void>;
17
17
  getAddresses(): Promise<string[]>;
18
18
  getSessionOrConfirm(address: AccountAddress): Promise<string>;
19
- sendEthereumTransaction(txData: any, options: {
19
+ sendEvmTransaction(txData: any, args: {
20
20
  address: string;
21
21
  ethereumChainId: EthereumChainId;
22
22
  }): Promise<string>;
@@ -34,9 +34,9 @@ export default class TrezorBase extends BaseConcreteStrategy implements Concrete
34
34
  }): Promise<DirectSignResponse>;
35
35
  signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
36
36
  getEthereumChainId(): Promise<string>;
37
- getEthereumTransactionReceipt(txHash: string): Promise<string>;
37
+ getEvmTransactionReceipt(txHash: string): Promise<string>;
38
38
  getPubKey(): Promise<string>;
39
- private signEthereumTransaction;
39
+ private signEvmTransaction;
40
40
  private getWalletForAddress;
41
41
  private getAlchemy;
42
42
  }
@@ -64,10 +64,10 @@ export default class TrezorBase extends BaseConcreteStrategy {
64
64
  async getSessionOrConfirm(address) {
65
65
  return Promise.resolve(`0x${Buffer.from(`Confirmation for ${address} at time: ${Date.now()}`).toString('hex')}`);
66
66
  }
67
- async sendEthereumTransaction(txData, options) {
68
- const signedTransaction = await this.signEthereumTransaction(txData, options);
67
+ async sendEvmTransaction(txData, args) {
68
+ const signedTransaction = await this.signEvmTransaction(txData, args);
69
69
  try {
70
- const alchemy = await this.getAlchemy();
70
+ const alchemy = await this.getAlchemy(args.ethereumChainId);
71
71
  const txReceipt = await alchemy.core.sendTransaction(addHexPrefix(signedTransaction.serialize().toString('hex')));
72
72
  return txReceipt.hash;
73
73
  }
@@ -75,7 +75,7 @@ export default class TrezorBase extends BaseConcreteStrategy {
75
75
  throw new TrezorException(new Error(e.message), {
76
76
  code: UnspecifiedErrorCode,
77
77
  type: ErrorType.WalletError,
78
- contextModule: WalletAction.SendEthereumTransaction,
78
+ contextModule: WalletAction.SendEvmTransaction,
79
79
  });
80
80
  }
81
81
  }
@@ -177,17 +177,17 @@ export default class TrezorBase extends BaseConcreteStrategy {
177
177
  const alchemyProvider = await alchemy.config.getProvider();
178
178
  return alchemyProvider.network.chainId.toString();
179
179
  }
180
- async getEthereumTransactionReceipt(txHash) {
180
+ async getEvmTransactionReceipt(txHash) {
181
181
  return Promise.resolve(txHash);
182
182
  }
183
183
  // eslint-disable-next-line class-methods-use-this
184
184
  async getPubKey() {
185
185
  throw new WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
186
186
  }
187
- async signEthereumTransaction(txData, options) {
188
- const chainId = parseInt(options.ethereumChainId.toString(), 10);
189
- const alchemy = await this.getAlchemy();
190
- const nonce = await alchemy.core.getTransactionCount(options.address);
187
+ async signEvmTransaction(txData, args) {
188
+ const chainId = parseInt(args.ethereumChainId.toString(), 10);
189
+ const alchemy = await this.getAlchemy(args.ethereumChainId);
190
+ const nonce = await alchemy.core.getTransactionCount(args.address);
191
191
  const common = new Common({
192
192
  chain: getNetworkFromChainId(chainId),
193
193
  hardfork: Hardfork.London,
@@ -211,7 +211,7 @@ export default class TrezorBase extends BaseConcreteStrategy {
211
211
  };
212
212
  try {
213
213
  await this.trezor.connect();
214
- const { derivationPath } = await this.getWalletForAddress(options.address);
214
+ const { derivationPath } = await this.getWalletForAddress(args.address);
215
215
  const response = await TrezorConnect.ethereumSignTransaction({
216
216
  path: derivationPath,
217
217
  transaction,
@@ -221,7 +221,7 @@ export default class TrezorBase extends BaseConcreteStrategy {
221
221
  'Something happened while signing with Trezor'), {
222
222
  code: UnspecifiedErrorCode,
223
223
  type: ErrorType.WalletError,
224
- contextModule: WalletAction.SignEthereumTransaction,
224
+ contextModule: WalletAction.SignEvmTransaction,
225
225
  });
226
226
  }
227
227
  const signedTxData = {
@@ -241,7 +241,7 @@ export default class TrezorBase extends BaseConcreteStrategy {
241
241
  throw new TrezorException(new Error(e.message), {
242
242
  code: UnspecifiedErrorCode,
243
243
  type: ErrorType.WalletError,
244
- contextModule: WalletAction.SignEthereumTransaction,
244
+ contextModule: WalletAction.SignEvmTransaction,
245
245
  });
246
246
  }
247
247
  }
@@ -258,17 +258,19 @@ export default class TrezorBase extends BaseConcreteStrategy {
258
258
  }
259
259
  return (await accountManager.getWalletForAddress(address));
260
260
  }
261
- async getAlchemy() {
261
+ async getAlchemy(ethereumChainId) {
262
262
  if (this.alchemy) {
263
263
  return this.alchemy;
264
264
  }
265
- const { rpcUrl, ethereumChainId } = this.ethereumOptions;
266
- if (!rpcUrl) {
265
+ const options = this.ethereumOptions;
266
+ const chainId = ethereumChainId || options.ethereumChainId;
267
+ const url = options.rpcUrl || options.rpcUrls?.[chainId];
268
+ if (!url) {
267
269
  throw new GeneralException(new Error('Please pass rpcUrl within the ethereumOptions'));
268
270
  }
269
271
  this.alchemy = new Alchemy({
270
- apiKey: getKeyFromRpcUrl(rpcUrl),
271
- network: ethereumChainId === EthereumChainId.Mainnet
272
+ apiKey: getKeyFromRpcUrl(url),
273
+ network: chainId === EthereumChainId.Mainnet
272
274
  ? AlchemyNetwork.ETH_MAINNET
273
275
  : AlchemyNetwork.ETH_SEPOLIA,
274
276
  });
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.15.30",
4
+ "version": "1.15.32",
5
5
  "sideEffects": false,
6
6
  "type": "module",
7
7
  "author": {
@@ -59,10 +59,10 @@
59
59
  "@bangjelkoski/trezor-connect-web": "^9.4.7-beta.1",
60
60
  "@ethereumjs/common": "3.1.1",
61
61
  "@ethereumjs/tx": "^4.1.1",
62
- "@injectivelabs/exceptions": "^1.15.27",
63
- "@injectivelabs/sdk-ts": "^1.15.30",
64
- "@injectivelabs/ts-types": "^1.15.28",
65
- "@injectivelabs/wallet-base": "^1.15.30",
62
+ "@injectivelabs/exceptions": "^1.15.29",
63
+ "@injectivelabs/sdk-ts": "^1.15.32",
64
+ "@injectivelabs/ts-types": "^1.15.30",
65
+ "@injectivelabs/wallet-base": "^1.15.32",
66
66
  "alchemy-sdk": "^3.4.7",
67
67
  "hdkey": "^2.1.0"
68
68
  },
@@ -72,5 +72,5 @@
72
72
  "resolutions": {
73
73
  "@ethereumjs/common": "3.1.1"
74
74
  },
75
- "gitHead": "2c2a365b27e08ad2e0eb06efe3c490c88888fee4"
75
+ "gitHead": "e8fa12c489c4b3432579c5df30fd6f939d57b442"
76
76
  }