New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ledgerhq/evm-tools

Package Overview
Dependencies
Maintainers
0
Versions
165
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ledgerhq/evm-tools - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0-nightly.0

6

CHANGELOG.md
# @ledgerhq/evm-tools
## 1.4.0-nightly.0
### Minor Changes
- [#9120](https://github.com/LedgerHQ/ledger-live/pull/9120) [`551f2cc`](https://github.com/LedgerHQ/ledger-live/commit/551f2ccad6d7897a010d39110c0ba9336d407dfd) Thanks [@chrisduma-ledger](https://github.com/chrisduma-ledger)! - Fixes Lido triggering blind message
## 1.3.1

@@ -4,0 +10,0 @@

45

lib-es/message/EIP712/index.js

@@ -1,21 +0,1 @@

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import axios from "axios";

@@ -62,17 +42,18 @@ import SHA224 from "crypto-js/sha224";

*/
export const getFiltersForMessage = (message, shouldUseV1Filters, calServiceURL) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h;
export const getFiltersForMessage = async (message, shouldUseV1Filters, calServiceURL) => {
const schemaHash = getSchemaHashForMessage(message);
const verifyingContract = ((_b = (_a = message.domain) === null || _a === void 0 ? void 0 : _a.verifyingContract) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || AddressZero;
const verifyingContract = message.domain?.verifyingContract?.toLowerCase() || AddressZero;
try {
if (calServiceURL) {
const { data } = yield axios.get(`${calServiceURL}/v1/dapps`, {
const { data } = await axios.get(`${calServiceURL}/v1/dapps`, {
params: {
output: "eip712_signatures",
eip712_signatures_version: shouldUseV1Filters ? "v1" : "v2",
chain_id: (_c = message.domain) === null || _c === void 0 ? void 0 : _c.chainId,
chain_id: message.domain?.chainId,
contracts: verifyingContract,
},
});
const filters = (_f = (_e = (_d = data === null || data === void 0 ? void 0 : data[0]) === null || _d === void 0 ? void 0 : _d.eip712_signatures) === null || _e === void 0 ? void 0 : _e[verifyingContract]) === null || _f === void 0 ? void 0 : _f[schemaHash];
// Rather than relying on array indices, find the right object wherever it may be, if it exists
const targetObject = data.find(item => item?.eip712_signatures?.[verifyingContract]?.[schemaHash]);
const filters = targetObject?.eip712_signatures?.[verifyingContract]?.[schemaHash];
if (!filters) {

@@ -88,3 +69,3 @@ // Fallback to catch

catch (e) {
const messageId = `${(_h = (_g = message.domain) === null || _g === void 0 ? void 0 : _g.chainId) !== null && _h !== void 0 ? _h : 0}:${verifyingContract}:${schemaHash}`;
const messageId = `${message.domain?.chainId ?? 0}:${verifyingContract}:${schemaHash}`;
if (shouldUseV1Filters) {

@@ -95,3 +76,3 @@ return EIP712CAL[messageId];

}
});
};
/**

@@ -141,9 +122,9 @@ * Get the value at a specific path of an object and return it as a string or as an array of string

*/
export const getEIP712FieldsDisplayedOnNano = (messageData_1, ...args_1) => __awaiter(void 0, [messageData_1, ...args_1], void 0, function* (messageData, calServiceURL = getEnv("CAL_SERVICE_URL")) {
export const getEIP712FieldsDisplayedOnNano = async (messageData, calServiceURL = getEnv("CAL_SERVICE_URL")) => {
if (!isEIP712Message(messageData)) {
return null;
}
const _j = messageData.types, { EIP712Domain } = _j, otherTypes = __rest(_j, ["EIP712Domain"]);
const { EIP712Domain, ...otherTypes } = messageData.types;
const displayedInfos = [];
const filters = yield getFiltersForMessage(messageData, false, calServiceURL);
const filters = await getFiltersForMessage(messageData, false, calServiceURL);
if (!filters) {

@@ -202,3 +183,3 @@ const { types } = messageData;

return displayedInfos;
});
};
//# sourceMappingURL=index.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -71,17 +51,18 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

*/
const getFiltersForMessage = (message, shouldUseV1Filters, calServiceURL) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h;
const getFiltersForMessage = async (message, shouldUseV1Filters, calServiceURL) => {
const schemaHash = (0, exports.getSchemaHashForMessage)(message);
const verifyingContract = ((_b = (_a = message.domain) === null || _a === void 0 ? void 0 : _a.verifyingContract) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || constants_1.AddressZero;
const verifyingContract = message.domain?.verifyingContract?.toLowerCase() || constants_1.AddressZero;
try {
if (calServiceURL) {
const { data } = yield axios_1.default.get(`${calServiceURL}/v1/dapps`, {
const { data } = await axios_1.default.get(`${calServiceURL}/v1/dapps`, {
params: {
output: "eip712_signatures",
eip712_signatures_version: shouldUseV1Filters ? "v1" : "v2",
chain_id: (_c = message.domain) === null || _c === void 0 ? void 0 : _c.chainId,
chain_id: message.domain?.chainId,
contracts: verifyingContract,
},
});
const filters = (_f = (_e = (_d = data === null || data === void 0 ? void 0 : data[0]) === null || _d === void 0 ? void 0 : _d.eip712_signatures) === null || _e === void 0 ? void 0 : _e[verifyingContract]) === null || _f === void 0 ? void 0 : _f[schemaHash];
// Rather than relying on array indices, find the right object wherever it may be, if it exists
const targetObject = data.find(item => item?.eip712_signatures?.[verifyingContract]?.[schemaHash]);
const filters = targetObject?.eip712_signatures?.[verifyingContract]?.[schemaHash];
if (!filters) {

@@ -97,3 +78,3 @@ // Fallback to catch

catch (e) {
const messageId = `${(_h = (_g = message.domain) === null || _g === void 0 ? void 0 : _g.chainId) !== null && _h !== void 0 ? _h : 0}:${verifyingContract}:${schemaHash}`;
const messageId = `${message.domain?.chainId ?? 0}:${verifyingContract}:${schemaHash}`;
if (shouldUseV1Filters) {

@@ -104,3 +85,3 @@ return eip712_1.default[messageId];

}
});
};
exports.getFiltersForMessage = getFiltersForMessage;

@@ -152,9 +133,9 @@ /**

*/
const getEIP712FieldsDisplayedOnNano = (messageData_1, ...args_1) => __awaiter(void 0, [messageData_1, ...args_1], void 0, function* (messageData, calServiceURL = (0, live_env_1.getEnv)("CAL_SERVICE_URL")) {
const getEIP712FieldsDisplayedOnNano = async (messageData, calServiceURL = (0, live_env_1.getEnv)("CAL_SERVICE_URL")) => {
if (!isEIP712Message(messageData)) {
return null;
}
const _j = messageData.types, { EIP712Domain } = _j, otherTypes = __rest(_j, ["EIP712Domain"]);
const { EIP712Domain, ...otherTypes } = messageData.types;
const displayedInfos = [];
const filters = yield (0, exports.getFiltersForMessage)(messageData, false, calServiceURL);
const filters = await (0, exports.getFiltersForMessage)(messageData, false, calServiceURL);
if (!filters) {

@@ -213,4 +194,4 @@ const { types } = messageData;

return displayedInfos;
});
};
exports.getEIP712FieldsDisplayedOnNano = getEIP712FieldsDisplayedOnNano;
//# sourceMappingURL=index.js.map
{
"name": "@ledgerhq/evm-tools",
"version": "1.3.1",
"version": "1.4.0-nightly.0",
"description": "EVM tooling used for coin integrations & app bindings",

@@ -59,13 +59,13 @@ "main": "./index.ts",

"@types/jest": "^29.5.10",
"@types/node": "^20.8.10",
"@types/node": "^22.10.10",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"@ledgerhq/types-live": "^6.57.0"
"@ledgerhq/types-live": "^6.59.0"
},
"scripts": {
"clean": "rimraf lib lib-es",
"build": "tsc && tsc -m ES6 --outDir lib-es",
"build": "tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es",
"prewatch": "pnpm build",
"watch": "tsc --watch",
"watch:es": "tsc --watch -m ES6 --outDir lib-es",
"watch:es": "tsc --watch -m esnext --moduleResolution bundler --outDir lib-es",
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",

@@ -72,0 +72,0 @@ "lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",

@@ -8,3 +8,3 @@ import axios from "axios";

} from "../../../message/EIP712/index";
import { dynamicCAL, messageNotInCAL } from "../../fixtures/dynamicCAL";
import { dynamicCAL, messageNotInCAL, messageNotInCALSchemaHash } from "../../fixtures/dynamicCAL";
import complexMessage from "../../fixtures/messages/5.json";

@@ -68,2 +68,56 @@ import messageInCAL from "../../fixtures/messages/2.json";

});
it("should find filters when matching data is not in first position of array", async () => {
const dynamicCALWithMultipleItems = [
{ eip712_signatures: { "0xdifferentContract": { differentHash: "wrong" } } },
{
eip712_signatures: {
[messageNotInCAL.domain.verifyingContract.toLowerCase()]: {
[messageNotInCALSchemaHash]: "found",
},
},
},
];
(axios.get as jest.Mock).mockReturnValueOnce({
data: dynamicCALWithMultipleItems,
});
const result = await getFiltersForMessage(messageNotInCAL, false, "http://CAL-ADDRESS");
expect(result).toEqual("found");
});
it("should handle empty eip712_signatures objects in array", async () => {
const dynamicCALWithEmptyItems = [
{ eip712_signatures: {} },
{
eip712_signatures: {
[messageNotInCAL.domain.verifyingContract.toLowerCase()]: {
[messageNotInCALSchemaHash]: "found",
},
},
},
];
(axios.get as jest.Mock).mockReturnValueOnce({
data: dynamicCALWithEmptyItems,
});
const result = await getFiltersForMessage(messageNotInCAL, false, "http://CAL-ADDRESS");
expect(result).toEqual("found");
});
it("should fallback to static file when no matching data found in any array position", async () => {
const dynamicCALWithNoMatch = [
{ eip712_signatures: { "0xcontract1": { hash1: "wrong1" } } },
{ eip712_signatures: { "0xcontract2": { hash2: "wrong2" } } },
];
(axios.get as jest.Mock).mockReturnValueOnce({
data: dynamicCALWithNoMatch,
});
const result = await getFiltersForMessage(messageInCAL, false, "http://CAL-ADDRESS");
const schemaHash = "d8e4f2bd77f7562e99ea5df4adb127291a2bfbc225ae55450038f27f";
expect(result).toEqual(CAL[`1:0x7f268357a8c2552623316e2562d90e642bb538e5:${schemaHash}`]);
});
});

@@ -70,0 +124,0 @@

@@ -61,2 +61,3 @@ import axios from "axios";

const schemaHash = getSchemaHashForMessage(message);
const verifyingContract = message.domain?.verifyingContract?.toLowerCase() || AddressZero;

@@ -74,3 +75,9 @@ try {

const filters = data?.[0]?.eip712_signatures?.[verifyingContract]?.[schemaHash];
// Rather than relying on array indices, find the right object wherever it may be, if it exists
const targetObject = data.find(
item => item?.eip712_signatures?.[verifyingContract]?.[schemaHash],
);
const filters = targetObject?.eip712_signatures?.[verifyingContract]?.[schemaHash];
if (!filters) {

@@ -77,0 +84,0 @@ // Fallback to catch

@@ -6,3 +6,2 @@ {

"declarationMap": true,
"module": "commonjs",
"downlevelIteration": true,

@@ -9,0 +8,0 @@ "lib": ["es2020", "dom"],

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc