@injectivelabs/wallet-trezor 1.19.21 → 1.19.23

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.
@@ -237,6 +237,24 @@ _defineProperty(BaseTrezorTransport, "initPromise", null);
237
237
 
238
238
  //#endregion
239
239
  //#region src/strategy/Eip1193Provider.ts
240
+ const signTypedDataMethods = new Set([
241
+ "eth_signTypedData",
242
+ "eth_signTypedData_v3",
243
+ "eth_signTypedData_v4"
244
+ ]);
245
+ const signMessageMethods = new Set(["eth_sign", "personal_sign"]);
246
+ const isEthAddress = (value) => typeof value === "string" && /^0x[a-fA-F0-9]{40}$/.test(value);
247
+ const getTypedDataParam = (method, params) => {
248
+ const typedData = isEthAddress(params[0]) ? params[1] : params[0];
249
+ if (typedData == null || typeof typedData === "string" && typedData.length === 0) throw new Error(`Missing typed data parameter for ${method}`);
250
+ return typeof typedData === "string" ? typedData : JSON.stringify(typedData);
251
+ };
252
+ const getMessageParam = (method, params) => {
253
+ let message = params[0];
254
+ if (method === "eth_sign" || isEthAddress(params[0])) message = params[1];
255
+ if (typeof message !== "string" || message.length === 0) throw new Error(`Missing message parameter for ${method}`);
256
+ return message;
257
+ };
240
258
  var TrezorEip1193Provider = class {
241
259
  constructor(trezor, params) {
242
260
  _defineProperty(this, "trezor", void 0);
@@ -369,18 +387,18 @@ var TrezorEip1193Provider = class {
369
387
  return (0, __injectivelabs_wallet_base.getEvmChainConfig)(this.chainId);
370
388
  }
371
389
  async request(args) {
372
- if (args.method === "eth_requestAccounts") return [await this.getAddress()];
373
- if (args.method === "eth_sign") {
374
- if (!args.params[0]) throw new Error("Missing parameter for eth_sign");
375
- return this.signMessage(args.params[0]);
390
+ if (args.method === "eth_requestAccounts" || args.method === "eth_accounts") return [await this.getAddress()];
391
+ if (signMessageMethods.has(args.method)) {
392
+ if (!args.params[0]) throw new Error(`Missing parameter for ${args.method}`);
393
+ return this.signMessage(getMessageParam(args.method, args.params));
376
394
  }
377
395
  if (args.method === "eth_signTransaction") {
378
396
  if (!args.params[0]) throw new Error("Missing parameter for eth_signTransaction");
379
397
  return this.signTransaction(args.params[0]);
380
398
  }
381
- if (args.method === "eth_signTypedData") {
382
- if (!args.params[0]) throw new Error("Missing parameter for eth_signTypedData");
383
- return this.signTypedData(args.params[0]);
399
+ if (signTypedDataMethods.has(args.method)) {
400
+ if (!args.params[0]) throw new Error(`Missing parameter for ${args.method}`);
401
+ return this.signTypedData(getTypedDataParam(args.method, args.params));
384
402
  }
385
403
  if (args.method === "eth_chainId") return `0x${this.chainId.toString(16)}`;
386
404
  if (args.method === "wallet_switchEthereumChain") {
package/dist/esm/index.js CHANGED
@@ -237,6 +237,24 @@ _defineProperty(BaseTrezorTransport, "initPromise", null);
237
237
 
238
238
  //#endregion
239
239
  //#region src/strategy/Eip1193Provider.ts
240
+ const signTypedDataMethods = new Set([
241
+ "eth_signTypedData",
242
+ "eth_signTypedData_v3",
243
+ "eth_signTypedData_v4"
244
+ ]);
245
+ const signMessageMethods = new Set(["eth_sign", "personal_sign"]);
246
+ const isEthAddress = (value) => typeof value === "string" && /^0x[a-fA-F0-9]{40}$/.test(value);
247
+ const getTypedDataParam = (method, params) => {
248
+ const typedData = isEthAddress(params[0]) ? params[1] : params[0];
249
+ if (typedData == null || typeof typedData === "string" && typedData.length === 0) throw new Error(`Missing typed data parameter for ${method}`);
250
+ return typeof typedData === "string" ? typedData : JSON.stringify(typedData);
251
+ };
252
+ const getMessageParam = (method, params) => {
253
+ let message = params[0];
254
+ if (method === "eth_sign" || isEthAddress(params[0])) message = params[1];
255
+ if (typeof message !== "string" || message.length === 0) throw new Error(`Missing message parameter for ${method}`);
256
+ return message;
257
+ };
240
258
  var TrezorEip1193Provider = class {
241
259
  constructor(trezor, params) {
242
260
  _defineProperty(this, "trezor", void 0);
@@ -369,18 +387,18 @@ var TrezorEip1193Provider = class {
369
387
  return getEvmChainConfig(this.chainId);
370
388
  }
371
389
  async request(args) {
372
- if (args.method === "eth_requestAccounts") return [await this.getAddress()];
373
- if (args.method === "eth_sign") {
374
- if (!args.params[0]) throw new Error("Missing parameter for eth_sign");
375
- return this.signMessage(args.params[0]);
390
+ if (args.method === "eth_requestAccounts" || args.method === "eth_accounts") return [await this.getAddress()];
391
+ if (signMessageMethods.has(args.method)) {
392
+ if (!args.params[0]) throw new Error(`Missing parameter for ${args.method}`);
393
+ return this.signMessage(getMessageParam(args.method, args.params));
376
394
  }
377
395
  if (args.method === "eth_signTransaction") {
378
396
  if (!args.params[0]) throw new Error("Missing parameter for eth_signTransaction");
379
397
  return this.signTransaction(args.params[0]);
380
398
  }
381
- if (args.method === "eth_signTypedData") {
382
- if (!args.params[0]) throw new Error("Missing parameter for eth_signTypedData");
383
- return this.signTypedData(args.params[0]);
399
+ if (signTypedDataMethods.has(args.method)) {
400
+ if (!args.params[0]) throw new Error(`Missing parameter for ${args.method}`);
401
+ return this.signTypedData(getTypedDataParam(args.method, args.params));
384
402
  }
385
403
  if (args.method === "eth_chainId") return `0x${this.chainId.toString(16)}`;
386
404
  if (args.method === "wallet_switchEthereumChain") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-trezor",
3
- "version": "1.19.21",
3
+ "version": "1.19.23",
4
4
  "description": "Trezor wallet strategy for use with @injectivelabs/wallet-core.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -45,10 +45,10 @@
45
45
  "@trezor/connect": "^9.6.4",
46
46
  "@trezor/connect-web": "^9.6.4",
47
47
  "viem": "^2.41.2",
48
- "@injectivelabs/exceptions": "1.19.21",
49
- "@injectivelabs/sdk-ts": "1.19.21",
50
- "@injectivelabs/ts-types": "1.19.21",
51
- "@injectivelabs/wallet-base": "1.19.21"
48
+ "@injectivelabs/exceptions": "1.19.23",
49
+ "@injectivelabs/sdk-ts": "1.19.23",
50
+ "@injectivelabs/wallet-base": "1.19.23",
51
+ "@injectivelabs/ts-types": "1.19.23"
52
52
  },
53
53
  "publishConfig": {
54
54
  "access": "public"