@injectivelabs/wallet-trezor 1.19.22 → 1.19.24
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.
- package/dist/cjs/index.cjs +25 -7
- package/dist/esm/index.js +25 -7
- package/package.json +5 -5
package/dist/cjs/index.cjs
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 (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
|
|
374
|
-
if (!args.params[0]) throw new Error(
|
|
375
|
-
return this.signMessage(args.params
|
|
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
|
|
382
|
-
if (!args.params[0]) throw new Error(
|
|
383
|
-
return this.signTypedData(args.params
|
|
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
|
|
374
|
-
if (!args.params[0]) throw new Error(
|
|
375
|
-
return this.signMessage(args.params
|
|
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
|
|
382
|
-
if (!args.params[0]) throw new Error(
|
|
383
|
-
return this.signTypedData(args.params
|
|
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.
|
|
3
|
+
"version": "1.19.24",
|
|
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.
|
|
49
|
-
"@injectivelabs/sdk-ts": "1.19.
|
|
50
|
-
"@injectivelabs/ts-types": "1.19.
|
|
51
|
-
"@injectivelabs/wallet-base": "1.19.
|
|
48
|
+
"@injectivelabs/exceptions": "1.19.24",
|
|
49
|
+
"@injectivelabs/sdk-ts": "1.19.24",
|
|
50
|
+
"@injectivelabs/ts-types": "1.19.24",
|
|
51
|
+
"@injectivelabs/wallet-base": "1.19.24"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|