@injectivelabs/wallet-trezor 1.16.38-alpha.2 → 1.16.38-alpha.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.
@@ -1,6 +1,7 @@
1
1
  let viem = require("viem");
2
+ let __injectivelabs_sdk_ts_core_tx = require("@injectivelabs/sdk-ts/core/tx");
2
3
  let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
3
- let __injectivelabs_sdk_ts = require("@injectivelabs/sdk-ts");
4
+ let __injectivelabs_sdk_ts_utils = require("@injectivelabs/sdk-ts/utils");
4
5
  let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
5
6
 
6
7
  //#region src/types.ts
@@ -33,13 +34,13 @@ async function loadTrezorConnect() {
33
34
  */
34
35
  const transformTypedData = (data, metamask_v4_compat = true) => {
35
36
  if (!metamask_v4_compat) throw new __injectivelabs_exceptions.TrezorException(/* @__PURE__ */ new Error("Trezor: Only version 4 of typed data signing is supported"));
36
- const version = __injectivelabs_sdk_ts.SignTypedDataVersionV4;
37
- const { types, primaryType, domain, message } = (0, __injectivelabs_sdk_ts.TypedDataUtilsSanitizeData)(data);
38
- const domainSeparatorHash = (0, __injectivelabs_sdk_ts.TypedDataUtilsHashStruct)("EIP712Domain", (0, __injectivelabs_sdk_ts.sanitizeTypedData)(domain), types, version).toString("hex");
37
+ const version = __injectivelabs_sdk_ts_utils.SignTypedDataVersionV4;
38
+ const { types, primaryType, domain, message } = (0, __injectivelabs_sdk_ts_utils.TypedDataUtilsSanitizeData)(data);
39
+ const domainSeparatorHash = (0, __injectivelabs_sdk_ts_utils.TypedDataUtilsHashStruct)("EIP712Domain", (0, __injectivelabs_sdk_ts_utils.sanitizeTypedData)(domain), types, version).toString("hex");
39
40
  let messageHash = null;
40
- if (primaryType !== "EIP712Domain") messageHash = (0, __injectivelabs_sdk_ts.TypedDataUtilsHashStruct)(primaryType, (0, __injectivelabs_sdk_ts.sanitizeTypedData)(message), {
41
+ if (primaryType !== "EIP712Domain") messageHash = (0, __injectivelabs_sdk_ts_utils.TypedDataUtilsHashStruct)(primaryType, (0, __injectivelabs_sdk_ts_utils.sanitizeTypedData)(message), {
41
42
  ...types,
42
- domain: (0, __injectivelabs_sdk_ts.sanitizeTypedData)(domain)
43
+ domain: (0, __injectivelabs_sdk_ts_utils.sanitizeTypedData)(domain)
43
44
  }, version).toString("hex");
44
45
  return {
45
46
  domain_separator_hash: domainSeparatorHash,
@@ -95,7 +96,7 @@ function _defineProperty(e, r, t) {
95
96
  const addressOfHDKey = (hdKey) => {
96
97
  const shouldSanitizePublicKey = true;
97
98
  const derivedPublicKey = hdKey.publicKey;
98
- return (0, __injectivelabs_sdk_ts.addHexPrefix)((0, __injectivelabs_sdk_ts.uint8ArrayToHex)((0, __injectivelabs_sdk_ts.publicKeyToAddress)(derivedPublicKey, shouldSanitizePublicKey)));
99
+ return (0, __injectivelabs_sdk_ts_utils.addHexPrefix)((0, __injectivelabs_sdk_ts_utils.uint8ArrayToHex)((0, __injectivelabs_sdk_ts_utils.publicKeyToAddress)(derivedPublicKey, shouldSanitizePublicKey)));
99
100
  };
100
101
  var AccountManager = class {
101
102
  constructor() {
@@ -139,8 +140,8 @@ var AccountManager = class {
139
140
  if (!result.success) throw new __injectivelabs_exceptions.TrezorException(new Error(result.payload && result.payload.error || "Please make sure your Trezor is connected and unlocked"));
140
141
  for (const item of result.payload) {
141
142
  const hdKey = {
142
- publicKey: (0, __injectivelabs_sdk_ts.hexToUint8Array)(item.publicKey),
143
- chainCode: (0, __injectivelabs_sdk_ts.hexToUint8Array)(item.chainCode)
143
+ publicKey: (0, __injectivelabs_sdk_ts_utils.hexToUint8Array)(item.publicKey),
144
+ chainCode: (0, __injectivelabs_sdk_ts_utils.hexToUint8Array)(item.chainCode)
144
145
  };
145
146
  const address = addressOfHDKey(hdKey);
146
147
  this.wallets.push({
@@ -200,6 +201,195 @@ var BaseTrezorTransport = class {
200
201
  }
201
202
  };
202
203
 
204
+ //#endregion
205
+ //#region src/strategy/Eip1193Provider.ts
206
+ var TrezorEip1193Provider = class {
207
+ constructor(trezor, params) {
208
+ _defineProperty(this, "trezor", void 0);
209
+ _defineProperty(this, "derivationPath", void 0);
210
+ _defineProperty(this, "address", void 0);
211
+ _defineProperty(this, "chainId", void 0);
212
+ this.trezor = trezor;
213
+ this.derivationPath = params.derivationPath || "m/44'/60'/0'/0/0";
214
+ this.chainId = parseInt(params.chainId || "1");
215
+ }
216
+ async getClient() {
217
+ return (0, __injectivelabs_wallet_base.getViemWalletClient)({
218
+ chainId: this.chainId,
219
+ account: await this.getAddress()
220
+ });
221
+ }
222
+ async setChainId(chainId) {
223
+ this.chainId = parseInt(chainId.replace("0x", ""), 16);
224
+ }
225
+ async getAddress() {
226
+ if (!this.address) {
227
+ const TrezorConnect = await loadTrezorConnect();
228
+ await this.trezor.connect();
229
+ const response = await TrezorConnect.ethereumGetAddress({
230
+ path: this.derivationPath,
231
+ showOnTrezor: false
232
+ });
233
+ if (!response.success) throw new Error(response.payload && response.payload.error || "Failed to get address from Trezor");
234
+ this.address = response.payload.address;
235
+ }
236
+ return this.address;
237
+ }
238
+ async signTypedData(data) {
239
+ const TrezorConnect = await loadTrezorConnect();
240
+ await this.trezor.connect();
241
+ const object = JSON.parse(data);
242
+ const { types: { EIP712Domain = [], ...otherTypes } = {}, message = {}, domain = {}, primaryType, domain_separator_hash, message_hash } = transformTypedData({
243
+ ...object,
244
+ domain: {
245
+ ...object.domain,
246
+ chainId: object.domain.chainId,
247
+ salt: "0"
248
+ }
249
+ });
250
+ const response = await TrezorConnect.ethereumSignTypedData({
251
+ path: this.derivationPath,
252
+ data: {
253
+ types: {
254
+ EIP712Domain,
255
+ ...otherTypes
256
+ },
257
+ message,
258
+ domain,
259
+ primaryType
260
+ },
261
+ message_hash,
262
+ domain_separator_hash,
263
+ metamask_v4_compat: true
264
+ });
265
+ if ("code" in response.payload && response.payload.code === "Failure_ActionCancelled") throw new Error("Request rejected");
266
+ if (!response.success) throw new Error(response.payload && response.payload.error || "Unknown error");
267
+ return response.payload.signature;
268
+ }
269
+ async signTransaction(txData) {
270
+ const TrezorConnect = await loadTrezorConnect();
271
+ await this.trezor.connect();
272
+ const parseHexValue = (value) => {
273
+ if (typeof value === "string") {
274
+ const hexValue = value.startsWith("0x") ? value : `0x${value}`;
275
+ return BigInt(hexValue);
276
+ }
277
+ return BigInt(value);
278
+ };
279
+ const chainId = txData.chainId || this.chainId;
280
+ const valueBigInt = parseHexValue(txData.value || "0x0");
281
+ const gasBigInt = parseHexValue(txData.gas || txData.gasLimit);
282
+ const maxFeePerGasBigInt = parseHexValue(txData.maxFeePerGas);
283
+ const maxPriorityFeePerGasBigInt = parseHexValue(txData.maxPriorityFeePerGas);
284
+ const trezorTxData = {
285
+ to: txData.to,
286
+ value: (0, viem.toHex)(valueBigInt),
287
+ gasLimit: (0, viem.toHex)(gasBigInt),
288
+ nonce: (0, viem.toHex)(txData.nonce),
289
+ data: txData.data || "0x",
290
+ chainId,
291
+ maxFeePerGas: (0, viem.toHex)(maxFeePerGasBigInt),
292
+ maxPriorityFeePerGas: (0, viem.toHex)(maxPriorityFeePerGasBigInt)
293
+ };
294
+ const response = await TrezorConnect.ethereumSignTransaction({
295
+ path: this.derivationPath,
296
+ transaction: trezorTxData
297
+ });
298
+ if (!response.success) throw new Error(response.payload && response.payload.error || "Something happened while signing with Trezor");
299
+ return (0, viem.serializeTransaction)({
300
+ type: "eip1559",
301
+ chainId,
302
+ nonce: txData.nonce,
303
+ to: txData.to,
304
+ value: valueBigInt,
305
+ data: txData.data || "0x",
306
+ gas: gasBigInt,
307
+ maxFeePerGas: maxFeePerGasBigInt,
308
+ maxPriorityFeePerGas: maxPriorityFeePerGasBigInt,
309
+ v: BigInt(response.payload.v),
310
+ r: response.payload.r,
311
+ s: response.payload.s
312
+ });
313
+ }
314
+ async signMessage(message) {
315
+ const TrezorConnect = await loadTrezorConnect();
316
+ await this.trezor.connect();
317
+ const response = await TrezorConnect.ethereumSignMessage({
318
+ path: this.derivationPath,
319
+ message
320
+ });
321
+ if (!response.success) throw new Error(response.payload && response.payload.error || "Unknown error");
322
+ const signature = response.payload.signature;
323
+ return signature.startsWith("0x") ? signature : `0x${signature}`;
324
+ }
325
+ getChain() {
326
+ return (0, __injectivelabs_wallet_base.getEvmChainConfig)(this.chainId);
327
+ }
328
+ async request(args) {
329
+ if (args.method === "eth_requestAccounts") return [await this.getAddress()];
330
+ if (args.method === "eth_sign") {
331
+ if (!args.params[0]) throw new Error("Missing parameter for eth_sign");
332
+ return this.signMessage(args.params[0]);
333
+ }
334
+ if (args.method === "eth_signTransaction") {
335
+ if (!args.params[0]) throw new Error("Missing parameter for eth_signTransaction");
336
+ return this.signTransaction(args.params[0]);
337
+ }
338
+ if (args.method === "eth_signTypedData") {
339
+ if (!args.params[0]) throw new Error("Missing parameter for eth_signTypedData");
340
+ return this.signTypedData(args.params[0]);
341
+ }
342
+ if (args.method === "eth_chainId") return `0x${this.chainId.toString(16)}`;
343
+ if (args.method === "wallet_switchEthereumChain") {
344
+ var _args$params$;
345
+ return this.setChainId(((_args$params$ = args.params[0]) === null || _args$params$ === void 0 ? void 0 : _args$params$.chainId) || "0x1");
346
+ }
347
+ if (args.method === "eth_estimateGas") {
348
+ const client = (0, __injectivelabs_wallet_base.getViemPublicClient)(this.chainId);
349
+ const data = {
350
+ to: args.params[0].to,
351
+ value: args.params[0].value,
352
+ data: args.params[0].data,
353
+ account: await this.getAddress()
354
+ };
355
+ return `0x${(await client.estimateGas(data)).toString(16)}`;
356
+ }
357
+ if (args.method === "eth_getTransactionCount") {
358
+ if (!args.params) throw new Error("params is required");
359
+ return `0x${(await (0, __injectivelabs_wallet_base.getViemPublicClient)(this.chainId).getTransactionCount({
360
+ address: await this.getAddress(),
361
+ blockTag: "pending"
362
+ })).toString(16)}`;
363
+ }
364
+ if (args.method === "eth_sendTransaction") {
365
+ const address = await this.getAddress();
366
+ const walletClient = (0, __injectivelabs_wallet_base.getViemWalletClient)({
367
+ chainId: this.chainId,
368
+ account: address
369
+ });
370
+ const preparedTransaction = await walletClient.prepareTransactionRequest({ ...args.params[0] });
371
+ const signedTransaction = await this.signTransaction(preparedTransaction);
372
+ return await walletClient.sendRawTransaction({ serializedTransaction: signedTransaction });
373
+ }
374
+ return (await this.getClient()).request({
375
+ method: args.method,
376
+ params: args.params
377
+ });
378
+ }
379
+ on(_event, _listener) {
380
+ throw new Error("Method not implemented.");
381
+ }
382
+ once(_event, _listener) {
383
+ throw new Error("Method not implemented.");
384
+ }
385
+ removeListener(_event, _listener) {
386
+ throw new Error("Method not implemented.");
387
+ }
388
+ off(_event, _listener) {
389
+ throw new Error("Method not implemented.");
390
+ }
391
+ };
392
+
203
393
  //#endregion
204
394
  //#region src/strategy/Base.ts
205
395
  var TrezorBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy {
@@ -237,8 +427,25 @@ var TrezorBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
237
427
  });
238
428
  }
239
429
  }
430
+ async getAddressesInfo() {
431
+ const { baseDerivationPath, derivationPathType } = this;
432
+ try {
433
+ await this.trezor.connect();
434
+ return (await (await this.trezor.getAccountManager()).getWallets(baseDerivationPath, derivationPathType)).map((k) => ({
435
+ address: k.address,
436
+ derivationPath: k.derivationPath,
437
+ baseDerivationPath: derivationPathType
438
+ }));
439
+ } catch (e) {
440
+ throw new __injectivelabs_exceptions.TrezorException(new Error(e.message), {
441
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
442
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
443
+ contextModule: __injectivelabs_wallet_base.WalletAction.GetAccounts
444
+ });
445
+ }
446
+ }
240
447
  async getSessionOrConfirm(address) {
241
- return Promise.resolve(`0x${(0, __injectivelabs_sdk_ts.uint8ArrayToHex)((0, __injectivelabs_sdk_ts.stringToUint8Array)(`Confirmation for ${address} at time: ${Date.now()}`))}`);
448
+ return Promise.resolve(`0x${(0, __injectivelabs_sdk_ts_utils.uint8ArrayToHex)((0, __injectivelabs_sdk_ts_utils.stringToUint8Array)(`Confirmation for ${address} at time: ${Date.now()}`))}`);
242
449
  }
243
450
  async sendEvmTransaction(txData, args) {
244
451
  const signedTransaction = await this.signEvmTransaction(txData, args);
@@ -255,7 +462,7 @@ var TrezorBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
255
462
  async sendTransaction(transaction, options) {
256
463
  const { endpoints, txTimeout } = options;
257
464
  if (!endpoints) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You have to pass endpoints.grpc within the options for using Ethereum native wallets"));
258
- const response = await new __injectivelabs_sdk_ts.TxGrpcApi(endpoints.grpc).broadcast(transaction, { txTimeout });
465
+ const response = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).broadcast(transaction, { txTimeout });
259
466
  if (response.code !== 0) throw new __injectivelabs_exceptions.TransactionException(new Error(response.rawLog), {
260
467
  code: __injectivelabs_exceptions.UnspecifiedErrorCode,
261
468
  contextCode: response.code,
@@ -324,7 +531,7 @@ var TrezorBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
324
531
  const { derivationPath } = await this.getWalletForAddress(signer);
325
532
  const response = await TrezorConnect.ethereumSignMessage({
326
533
  path: derivationPath,
327
- message: (0, __injectivelabs_sdk_ts.toUtf8)(data)
534
+ message: (0, __injectivelabs_sdk_ts_utils.toUtf8)(data)
328
535
  });
329
536
  if (!response.success) throw new Error(response.payload && response.payload.error || "Unknown error");
330
537
  return response.payload.signature;
@@ -426,6 +633,13 @@ var TrezorBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
426
633
  }
427
634
  return await accountManager.getWalletForAddress(address);
428
635
  }
636
+ async getEip1193Provider() {
637
+ var _this$metadata;
638
+ return new TrezorEip1193Provider(this.trezor, {
639
+ chainId: this.evmOptions.evmChainId.toString(),
640
+ derivationPath: (_this$metadata = this.metadata) === null || _this$metadata === void 0 ? void 0 : _this$metadata.derivationPath
641
+ });
642
+ }
429
643
  async getPublicClient(evmChainId) {
430
644
  var _options$rpcUrls;
431
645
  if (this.publicClient) return this.publicClient;
@@ -1,6 +1,7 @@
1
- import { BaseConcreteStrategy, ConcreteEvmWalletStrategyArgs, ConcreteWalletStrategy, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
1
+ import { BaseConcreteStrategy, ConcreteEvmWalletStrategyArgs, ConcreteWalletStrategy, Eip1193Provider, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
2
2
  import { AccountAddress, EvmChainId } from "@injectivelabs/ts-types";
3
- import { AminoSignResponse, DirectSignResponse, TxRaw, TxResponse } from "@injectivelabs/sdk-ts";
3
+ import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
4
+ import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
4
5
 
5
6
  //#region src/types.d.ts
6
7
  interface HDNodeLike {
@@ -33,6 +34,11 @@ declare class TrezorBase extends BaseConcreteStrategy implements ConcreteWalletS
33
34
  enable(): Promise<boolean>;
34
35
  disconnect(): Promise<void>;
35
36
  getAddresses(): Promise<string[]>;
37
+ getAddressesInfo(): Promise<{
38
+ address: string;
39
+ derivationPath: string;
40
+ baseDerivationPath: string;
41
+ }[]>;
36
42
  getSessionOrConfirm(address: AccountAddress): Promise<string>;
37
43
  sendEvmTransaction(txData: any, args: {
38
44
  address: string;
@@ -56,6 +62,7 @@ declare class TrezorBase extends BaseConcreteStrategy implements ConcreteWalletS
56
62
  getPubKey(): Promise<string>;
57
63
  private signEvmTransaction;
58
64
  private getWalletForAddress;
65
+ getEip1193Provider(): Promise<Eip1193Provider>;
59
66
  private getPublicClient;
60
67
  }
61
68
  //#endregion
@@ -1,6 +1,7 @@
1
- import { BaseConcreteStrategy, ConcreteEvmWalletStrategyArgs, ConcreteWalletStrategy, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
2
- import { AminoSignResponse, DirectSignResponse, TxRaw, TxResponse } from "@injectivelabs/sdk-ts";
1
+ import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
2
+ import { BaseConcreteStrategy, ConcreteEvmWalletStrategyArgs, ConcreteWalletStrategy, Eip1193Provider, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
3
3
  import { AccountAddress, EvmChainId } from "@injectivelabs/ts-types";
4
+ import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
4
5
 
5
6
  //#region src/types.d.ts
6
7
  interface HDNodeLike {
@@ -33,6 +34,11 @@ declare class TrezorBase extends BaseConcreteStrategy implements ConcreteWalletS
33
34
  enable(): Promise<boolean>;
34
35
  disconnect(): Promise<void>;
35
36
  getAddresses(): Promise<string[]>;
37
+ getAddressesInfo(): Promise<{
38
+ address: string;
39
+ derivationPath: string;
40
+ baseDerivationPath: string;
41
+ }[]>;
36
42
  getSessionOrConfirm(address: AccountAddress): Promise<string>;
37
43
  sendEvmTransaction(txData: any, args: {
38
44
  address: string;
@@ -56,6 +62,7 @@ declare class TrezorBase extends BaseConcreteStrategy implements ConcreteWalletS
56
62
  getPubKey(): Promise<string>;
57
63
  private signEvmTransaction;
58
64
  private getWalletForAddress;
65
+ getEip1193Provider(): Promise<Eip1193Provider>;
59
66
  private getPublicClient;
60
67
  }
61
68
  //#endregion
package/dist/esm/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { serializeTransaction, toHex } from "viem";
2
- import { BaseConcreteStrategy, DEFAULT_ADDRESS_SEARCH_LIMIT, DEFAULT_BASE_DERIVATION_PATH, DEFAULT_NUM_ADDRESSES_TO_FETCH, WalletAction, WalletDeviceType, getViemPublicClient } from "@injectivelabs/wallet-base";
3
- import { SignTypedDataVersionV4, TxGrpcApi, TypedDataUtilsHashStruct, TypedDataUtilsSanitizeData, addHexPrefix, hexToUint8Array, publicKeyToAddress, sanitizeTypedData, stringToUint8Array, toUtf8, uint8ArrayToHex } from "@injectivelabs/sdk-ts";
2
+ import { TxGrpcApi } from "@injectivelabs/sdk-ts/core/tx";
3
+ import { BaseConcreteStrategy, DEFAULT_ADDRESS_SEARCH_LIMIT, DEFAULT_BASE_DERIVATION_PATH, DEFAULT_NUM_ADDRESSES_TO_FETCH, WalletAction, WalletDeviceType, getEvmChainConfig, getViemPublicClient, getViemWalletClient } from "@injectivelabs/wallet-base";
4
+ import { SignTypedDataVersionV4, TypedDataUtilsHashStruct, TypedDataUtilsSanitizeData, addHexPrefix, hexToUint8Array, publicKeyToAddress, sanitizeTypedData, stringToUint8Array, toUtf8, uint8ArrayToHex } from "@injectivelabs/sdk-ts/utils";
4
5
  import { ErrorType, GeneralException, TransactionException, TrezorException, UnspecifiedErrorCode, WalletException } from "@injectivelabs/exceptions";
5
6
 
6
7
  //#region src/types.ts
@@ -200,6 +201,195 @@ var BaseTrezorTransport = class {
200
201
  }
201
202
  };
202
203
 
204
+ //#endregion
205
+ //#region src/strategy/Eip1193Provider.ts
206
+ var TrezorEip1193Provider = class {
207
+ constructor(trezor, params) {
208
+ _defineProperty(this, "trezor", void 0);
209
+ _defineProperty(this, "derivationPath", void 0);
210
+ _defineProperty(this, "address", void 0);
211
+ _defineProperty(this, "chainId", void 0);
212
+ this.trezor = trezor;
213
+ this.derivationPath = params.derivationPath || "m/44'/60'/0'/0/0";
214
+ this.chainId = parseInt(params.chainId || "1");
215
+ }
216
+ async getClient() {
217
+ return getViemWalletClient({
218
+ chainId: this.chainId,
219
+ account: await this.getAddress()
220
+ });
221
+ }
222
+ async setChainId(chainId) {
223
+ this.chainId = parseInt(chainId.replace("0x", ""), 16);
224
+ }
225
+ async getAddress() {
226
+ if (!this.address) {
227
+ const TrezorConnect = await loadTrezorConnect();
228
+ await this.trezor.connect();
229
+ const response = await TrezorConnect.ethereumGetAddress({
230
+ path: this.derivationPath,
231
+ showOnTrezor: false
232
+ });
233
+ if (!response.success) throw new Error(response.payload && response.payload.error || "Failed to get address from Trezor");
234
+ this.address = response.payload.address;
235
+ }
236
+ return this.address;
237
+ }
238
+ async signTypedData(data) {
239
+ const TrezorConnect = await loadTrezorConnect();
240
+ await this.trezor.connect();
241
+ const object = JSON.parse(data);
242
+ const { types: { EIP712Domain = [], ...otherTypes } = {}, message = {}, domain = {}, primaryType, domain_separator_hash, message_hash } = transformTypedData({
243
+ ...object,
244
+ domain: {
245
+ ...object.domain,
246
+ chainId: object.domain.chainId,
247
+ salt: "0"
248
+ }
249
+ });
250
+ const response = await TrezorConnect.ethereumSignTypedData({
251
+ path: this.derivationPath,
252
+ data: {
253
+ types: {
254
+ EIP712Domain,
255
+ ...otherTypes
256
+ },
257
+ message,
258
+ domain,
259
+ primaryType
260
+ },
261
+ message_hash,
262
+ domain_separator_hash,
263
+ metamask_v4_compat: true
264
+ });
265
+ if ("code" in response.payload && response.payload.code === "Failure_ActionCancelled") throw new Error("Request rejected");
266
+ if (!response.success) throw new Error(response.payload && response.payload.error || "Unknown error");
267
+ return response.payload.signature;
268
+ }
269
+ async signTransaction(txData) {
270
+ const TrezorConnect = await loadTrezorConnect();
271
+ await this.trezor.connect();
272
+ const parseHexValue = (value) => {
273
+ if (typeof value === "string") {
274
+ const hexValue = value.startsWith("0x") ? value : `0x${value}`;
275
+ return BigInt(hexValue);
276
+ }
277
+ return BigInt(value);
278
+ };
279
+ const chainId = txData.chainId || this.chainId;
280
+ const valueBigInt = parseHexValue(txData.value || "0x0");
281
+ const gasBigInt = parseHexValue(txData.gas || txData.gasLimit);
282
+ const maxFeePerGasBigInt = parseHexValue(txData.maxFeePerGas);
283
+ const maxPriorityFeePerGasBigInt = parseHexValue(txData.maxPriorityFeePerGas);
284
+ const trezorTxData = {
285
+ to: txData.to,
286
+ value: toHex(valueBigInt),
287
+ gasLimit: toHex(gasBigInt),
288
+ nonce: toHex(txData.nonce),
289
+ data: txData.data || "0x",
290
+ chainId,
291
+ maxFeePerGas: toHex(maxFeePerGasBigInt),
292
+ maxPriorityFeePerGas: toHex(maxPriorityFeePerGasBigInt)
293
+ };
294
+ const response = await TrezorConnect.ethereumSignTransaction({
295
+ path: this.derivationPath,
296
+ transaction: trezorTxData
297
+ });
298
+ if (!response.success) throw new Error(response.payload && response.payload.error || "Something happened while signing with Trezor");
299
+ return serializeTransaction({
300
+ type: "eip1559",
301
+ chainId,
302
+ nonce: txData.nonce,
303
+ to: txData.to,
304
+ value: valueBigInt,
305
+ data: txData.data || "0x",
306
+ gas: gasBigInt,
307
+ maxFeePerGas: maxFeePerGasBigInt,
308
+ maxPriorityFeePerGas: maxPriorityFeePerGasBigInt,
309
+ v: BigInt(response.payload.v),
310
+ r: response.payload.r,
311
+ s: response.payload.s
312
+ });
313
+ }
314
+ async signMessage(message) {
315
+ const TrezorConnect = await loadTrezorConnect();
316
+ await this.trezor.connect();
317
+ const response = await TrezorConnect.ethereumSignMessage({
318
+ path: this.derivationPath,
319
+ message
320
+ });
321
+ if (!response.success) throw new Error(response.payload && response.payload.error || "Unknown error");
322
+ const signature = response.payload.signature;
323
+ return signature.startsWith("0x") ? signature : `0x${signature}`;
324
+ }
325
+ getChain() {
326
+ return getEvmChainConfig(this.chainId);
327
+ }
328
+ async request(args) {
329
+ if (args.method === "eth_requestAccounts") return [await this.getAddress()];
330
+ if (args.method === "eth_sign") {
331
+ if (!args.params[0]) throw new Error("Missing parameter for eth_sign");
332
+ return this.signMessage(args.params[0]);
333
+ }
334
+ if (args.method === "eth_signTransaction") {
335
+ if (!args.params[0]) throw new Error("Missing parameter for eth_signTransaction");
336
+ return this.signTransaction(args.params[0]);
337
+ }
338
+ if (args.method === "eth_signTypedData") {
339
+ if (!args.params[0]) throw new Error("Missing parameter for eth_signTypedData");
340
+ return this.signTypedData(args.params[0]);
341
+ }
342
+ if (args.method === "eth_chainId") return `0x${this.chainId.toString(16)}`;
343
+ if (args.method === "wallet_switchEthereumChain") {
344
+ var _args$params$;
345
+ return this.setChainId(((_args$params$ = args.params[0]) === null || _args$params$ === void 0 ? void 0 : _args$params$.chainId) || "0x1");
346
+ }
347
+ if (args.method === "eth_estimateGas") {
348
+ const client = getViemPublicClient(this.chainId);
349
+ const data = {
350
+ to: args.params[0].to,
351
+ value: args.params[0].value,
352
+ data: args.params[0].data,
353
+ account: await this.getAddress()
354
+ };
355
+ return `0x${(await client.estimateGas(data)).toString(16)}`;
356
+ }
357
+ if (args.method === "eth_getTransactionCount") {
358
+ if (!args.params) throw new Error("params is required");
359
+ return `0x${(await getViemPublicClient(this.chainId).getTransactionCount({
360
+ address: await this.getAddress(),
361
+ blockTag: "pending"
362
+ })).toString(16)}`;
363
+ }
364
+ if (args.method === "eth_sendTransaction") {
365
+ const address = await this.getAddress();
366
+ const walletClient = getViemWalletClient({
367
+ chainId: this.chainId,
368
+ account: address
369
+ });
370
+ const preparedTransaction = await walletClient.prepareTransactionRequest({ ...args.params[0] });
371
+ const signedTransaction = await this.signTransaction(preparedTransaction);
372
+ return await walletClient.sendRawTransaction({ serializedTransaction: signedTransaction });
373
+ }
374
+ return (await this.getClient()).request({
375
+ method: args.method,
376
+ params: args.params
377
+ });
378
+ }
379
+ on(_event, _listener) {
380
+ throw new Error("Method not implemented.");
381
+ }
382
+ once(_event, _listener) {
383
+ throw new Error("Method not implemented.");
384
+ }
385
+ removeListener(_event, _listener) {
386
+ throw new Error("Method not implemented.");
387
+ }
388
+ off(_event, _listener) {
389
+ throw new Error("Method not implemented.");
390
+ }
391
+ };
392
+
203
393
  //#endregion
204
394
  //#region src/strategy/Base.ts
205
395
  var TrezorBase = class extends BaseConcreteStrategy {
@@ -237,6 +427,23 @@ var TrezorBase = class extends BaseConcreteStrategy {
237
427
  });
238
428
  }
239
429
  }
430
+ async getAddressesInfo() {
431
+ const { baseDerivationPath, derivationPathType } = this;
432
+ try {
433
+ await this.trezor.connect();
434
+ return (await (await this.trezor.getAccountManager()).getWallets(baseDerivationPath, derivationPathType)).map((k) => ({
435
+ address: k.address,
436
+ derivationPath: k.derivationPath,
437
+ baseDerivationPath: derivationPathType
438
+ }));
439
+ } catch (e) {
440
+ throw new TrezorException(new Error(e.message), {
441
+ code: UnspecifiedErrorCode,
442
+ type: ErrorType.WalletError,
443
+ contextModule: WalletAction.GetAccounts
444
+ });
445
+ }
446
+ }
240
447
  async getSessionOrConfirm(address) {
241
448
  return Promise.resolve(`0x${uint8ArrayToHex(stringToUint8Array(`Confirmation for ${address} at time: ${Date.now()}`))}`);
242
449
  }
@@ -426,6 +633,13 @@ var TrezorBase = class extends BaseConcreteStrategy {
426
633
  }
427
634
  return await accountManager.getWalletForAddress(address);
428
635
  }
636
+ async getEip1193Provider() {
637
+ var _this$metadata;
638
+ return new TrezorEip1193Provider(this.trezor, {
639
+ chainId: this.evmOptions.evmChainId.toString(),
640
+ derivationPath: (_this$metadata = this.metadata) === null || _this$metadata === void 0 ? void 0 : _this$metadata.derivationPath
641
+ });
642
+ }
429
643
  async getPublicClient(evmChainId) {
430
644
  var _options$rpcUrls;
431
645
  if (this.publicClient) return this.publicClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-trezor",
3
- "version": "1.16.38-alpha.2",
3
+ "version": "1.16.38-alpha.4",
4
4
  "description": "Trezor wallet strategy for use with @injectivelabs/wallet-core.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -40,11 +40,11 @@
40
40
  "dependencies": {
41
41
  "@trezor/connect": "^9.6.4",
42
42
  "@trezor/connect-web": "^9.6.4",
43
- "viem": "^2.40.3",
44
- "@injectivelabs/exceptions": "1.16.38-alpha.1",
45
- "@injectivelabs/ts-types": "1.16.38-alpha.1",
46
- "@injectivelabs/sdk-ts": "1.16.38-alpha.2",
47
- "@injectivelabs/wallet-base": "1.16.38-alpha.2"
43
+ "viem": "^2.41.2",
44
+ "@injectivelabs/exceptions": "1.16.38-alpha.3",
45
+ "@injectivelabs/ts-types": "1.16.38-alpha.2",
46
+ "@injectivelabs/wallet-base": "1.16.38-alpha.4",
47
+ "@injectivelabs/sdk-ts": "1.16.38-alpha.4"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"