@ledgerhq/evm-tools 1.1.3-nightly.0 → 1.2.0-next.0
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/CHANGELOG.md +8 -3
- package/lib/message/EIP712/index.d.ts +7 -2
- package/lib/message/EIP712/index.d.ts.map +1 -1
- package/lib/message/EIP712/index.js +33 -15
- package/lib/message/EIP712/index.js.map +1 -1
- package/lib/message/EIP712/types.d.ts +27 -5
- package/lib/message/EIP712/types.d.ts.map +1 -1
- package/lib/selectors/index.d.ts.map +1 -1
- package/lib/selectors/index.js +1 -0
- package/lib/selectors/index.js.map +1 -1
- package/lib-es/message/EIP712/index.d.ts +7 -2
- package/lib-es/message/EIP712/index.d.ts.map +1 -1
- package/lib-es/message/EIP712/index.js +31 -14
- package/lib-es/message/EIP712/index.js.map +1 -1
- package/lib-es/message/EIP712/types.d.ts +27 -5
- package/lib-es/message/EIP712/types.d.ts.map +1 -1
- package/lib-es/selectors/index.d.ts.map +1 -1
- package/lib-es/selectors/index.js +1 -0
- package/lib-es/selectors/index.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/fixtures/dynamicCAL.ts +9 -3
- package/src/__tests__/messages/EIP712/index.unit.test.ts +4 -3
- package/src/message/EIP712/index.ts +34 -19
- package/src/message/EIP712/types.ts +31 -5
- package/src/selectors/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
# @ledgerhq/evm-tools
|
|
2
2
|
|
|
3
|
-
## 1.
|
|
3
|
+
## 1.2.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#7494](https://github.com/LedgerHQ/ledger-live/pull/7494) [`60f1b5c`](https://github.com/LedgerHQ/ledger-live/commit/60f1b5c6cab125f5281468bb3e36f1abfae2d70c) Thanks [@lambertkevin](https://github.com/lambertkevin)! - Fetching filters for EIP712 messages is now done using the CAL service instead of the CDN
|
|
4
8
|
|
|
5
9
|
### Patch Changes
|
|
6
10
|
|
|
7
|
-
- Updated dependencies [[`8553b3e`](https://github.com/LedgerHQ/ledger-live/commit/8553b3eef10132396ec580a2d5f20b616f5b18a0)]:
|
|
8
|
-
- @ledgerhq/cryptoassets@13.
|
|
11
|
+
- Updated dependencies [[`db9c2d7`](https://github.com/LedgerHQ/ledger-live/commit/db9c2d78fb74df586c3ea1b9fb75ce3b014a0f4b), [`4bd91de`](https://github.com/LedgerHQ/ledger-live/commit/4bd91de13442d12acce3ee83d5f2fd5f087570cf), [`8553b3e`](https://github.com/LedgerHQ/ledger-live/commit/8553b3eef10132396ec580a2d5f20b616f5b18a0), [`52daa39`](https://github.com/LedgerHQ/ledger-live/commit/52daa3998709ac3538afd447fe771faa3e3441be), [`60f1b5c`](https://github.com/LedgerHQ/ledger-live/commit/60f1b5c6cab125f5281468bb3e36f1abfae2d70c), [`60f1b5c`](https://github.com/LedgerHQ/ledger-live/commit/60f1b5c6cab125f5281468bb3e36f1abfae2d70c)]:
|
|
12
|
+
- @ledgerhq/cryptoassets@13.3.0-next.0
|
|
13
|
+
- @ledgerhq/live-env@2.2.0-next.0
|
|
9
14
|
|
|
10
15
|
## 1.1.2
|
|
11
16
|
|
|
@@ -10,11 +10,16 @@ export declare const getSchemaHashForMessage: (message: EIP712Message) => string
|
|
|
10
10
|
* @param {EIP712Message} message
|
|
11
11
|
* @returns {MessageFilters | undefined}
|
|
12
12
|
*/
|
|
13
|
-
export declare const getFiltersForMessage: (message: EIP712Message,
|
|
13
|
+
export declare const getFiltersForMessage: (message: EIP712Message, shouldUseV1Filters?: boolean, calServiceURL?: string | null) => Promise<MessageFilters | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* Using a path as a string, returns the value(s) of a json key without worrying about depth or arrays
|
|
16
|
+
* (e.g: 'to.wallets.[]' => ["0x123", "0x456"])
|
|
17
|
+
*/
|
|
18
|
+
export declare const getValueFromPath: (path: string, eip721Message: EIP712Message) => string | string[];
|
|
14
19
|
/**
|
|
15
20
|
* Gets the fields visible on the nano for a specific EIP712 message
|
|
16
21
|
*/
|
|
17
|
-
export declare const getEIP712FieldsDisplayedOnNano: (messageData: EIP712Message,
|
|
22
|
+
export declare const getEIP712FieldsDisplayedOnNano: (messageData: EIP712Message, calServiceURL?: string) => Promise<{
|
|
18
23
|
label: string;
|
|
19
24
|
value: string | string[];
|
|
20
25
|
}[] | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/message/EIP712/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/message/EIP712/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,EAA4B,cAAc,EAAE,MAAM,SAAS,CAAC;AAGnE,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,aAAa,CAS1E;AAED,eAAO,MAAM,wBAAwB,QAAS,OAAO,MAAM,EAAE,OAAO,CAAC,KAAG,OAAO,MAAM,EAAE,OAAO,CAgB7F,CAAC;AAEF,eAAO,MAAM,uBAAuB,YAAa,aAAa,KAAG,MAKhE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,YACtB,aAAa,uBACD,OAAO,kBACZ,MAAM,GAAG,IAAI,KAC5B,QAAQ,cAAc,GAAG,SAAS,CAiCpC,CAAC;AA4BF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,SAAU,MAAM,iBAAiB,aAAa,KAAG,MAAM,GAAG,MAAM,EAmB5F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,8BAA8B,gBAC5B,aAAa,kBACX,MAAM,KACpB,QAAQ;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE,EAAE,GAAG,IAAI,CA4E9D,CAAC"}
|
|
@@ -23,13 +23,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getEIP712FieldsDisplayedOnNano = exports.getFiltersForMessage = exports.getSchemaHashForMessage = exports.sortObjectAlphabetically = exports.isEIP712Message = void 0;
|
|
26
|
+
exports.getEIP712FieldsDisplayedOnNano = exports.getValueFromPath = exports.getFiltersForMessage = exports.getSchemaHashForMessage = exports.sortObjectAlphabetically = exports.isEIP712Message = void 0;
|
|
27
27
|
const ethers_1 = require("ethers");
|
|
28
28
|
const axios_1 = __importDefault(require("axios"));
|
|
29
29
|
const sha224_1 = __importDefault(require("crypto-js/sha224"));
|
|
30
30
|
const live_env_1 = require("@ledgerhq/live-env");
|
|
31
31
|
const eip712_1 = __importDefault(require("@ledgerhq/cryptoassets/data/eip712"));
|
|
32
|
-
const
|
|
32
|
+
const eip712_v2_1 = __importDefault(require("@ledgerhq/cryptoassets/data/eip712_v2"));
|
|
33
33
|
// As defined in [spec](https://eips.ethereum.org/EIPS/eip-712), the properties below are all required.
|
|
34
34
|
function isEIP712Message(message) {
|
|
35
35
|
return (!!message &&
|
|
@@ -67,19 +67,36 @@ exports.getSchemaHashForMessage = getSchemaHashForMessage;
|
|
|
67
67
|
* @param {EIP712Message} message
|
|
68
68
|
* @returns {MessageFilters | undefined}
|
|
69
69
|
*/
|
|
70
|
-
const getFiltersForMessage = (message,
|
|
71
|
-
var _a, _b, _c, _d;
|
|
70
|
+
const getFiltersForMessage = (message, shouldUseV1Filters, calServiceURL) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
72
72
|
const schemaHash = (0, exports.getSchemaHashForMessage)(message);
|
|
73
|
-
const
|
|
73
|
+
const verifyingContract = ((_b = (_a = message.domain) === null || _a === void 0 ? void 0 : _a.verifyingContract) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || ethers_1.ethers.constants.AddressZero;
|
|
74
74
|
try {
|
|
75
|
-
if (
|
|
76
|
-
const { data
|
|
77
|
-
|
|
75
|
+
if (calServiceURL) {
|
|
76
|
+
const { data } = yield axios_1.default.get(`${calServiceURL}/v1/dapps`, {
|
|
77
|
+
params: {
|
|
78
|
+
output: "eip712_signatures",
|
|
79
|
+
eip712_signatures_version: shouldUseV1Filters ? "v1" : "v2",
|
|
80
|
+
chain_id: (_c = message.domain) === null || _c === void 0 ? void 0 : _c.chainId,
|
|
81
|
+
contracts: verifyingContract,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
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];
|
|
85
|
+
if (!filters) {
|
|
86
|
+
// Fallback to catch
|
|
87
|
+
throw new Error("Fallback to static file");
|
|
88
|
+
}
|
|
89
|
+
return filters;
|
|
78
90
|
}
|
|
79
|
-
|
|
91
|
+
// Fallback to catch
|
|
92
|
+
throw new Error("Fallback to static file");
|
|
80
93
|
}
|
|
81
94
|
catch (e) {
|
|
82
|
-
|
|
95
|
+
const messageId = `${(_h = (_g = message.domain) === null || _g === void 0 ? void 0 : _g.chainId) !== null && _h !== void 0 ? _h : 0}:${verifyingContract}:${schemaHash}`;
|
|
96
|
+
if (shouldUseV1Filters) {
|
|
97
|
+
return eip712_1.default[messageId];
|
|
98
|
+
}
|
|
99
|
+
return eip712_v2_1.default[messageId];
|
|
83
100
|
}
|
|
84
101
|
});
|
|
85
102
|
exports.getFiltersForMessage = getFiltersForMessage;
|
|
@@ -96,7 +113,7 @@ const getValue = (path, value) => {
|
|
|
96
113
|
}
|
|
97
114
|
/* istanbul ignore if : unecessary test of a throw */
|
|
98
115
|
if (!(path in value)) {
|
|
99
|
-
throw new Error(`Could not find key ${
|
|
116
|
+
throw new Error(`Could not find key ${path} in ${JSON.stringify(value)} `);
|
|
100
117
|
}
|
|
101
118
|
const result = value[path];
|
|
102
119
|
return typeof result === "object" ? result : result.toString();
|
|
@@ -124,16 +141,17 @@ const getValueFromPath = (path, eip721Message) => {
|
|
|
124
141
|
}
|
|
125
142
|
return value;
|
|
126
143
|
};
|
|
144
|
+
exports.getValueFromPath = getValueFromPath;
|
|
127
145
|
/**
|
|
128
146
|
* Gets the fields visible on the nano for a specific EIP712 message
|
|
129
147
|
*/
|
|
130
|
-
const getEIP712FieldsDisplayedOnNano = (messageData_1, ...args_1) => __awaiter(void 0, [messageData_1, ...args_1], void 0, function* (messageData,
|
|
148
|
+
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")) {
|
|
131
149
|
if (!isEIP712Message(messageData)) {
|
|
132
150
|
return null;
|
|
133
151
|
}
|
|
134
|
-
const
|
|
152
|
+
const _j = messageData.types, { EIP712Domain } = _j, otherTypes = __rest(_j, ["EIP712Domain"]);
|
|
135
153
|
const displayedInfos = [];
|
|
136
|
-
const filters = yield (0, exports.getFiltersForMessage)(messageData,
|
|
154
|
+
const filters = yield (0, exports.getFiltersForMessage)(messageData, false, calServiceURL);
|
|
137
155
|
if (!filters) {
|
|
138
156
|
const { types } = messageData;
|
|
139
157
|
const domainFields = types["EIP712Domain"].map(({ name }) => name);
|
|
@@ -183,7 +201,7 @@ const getEIP712FieldsDisplayedOnNano = (messageData_1, ...args_1) => __awaiter(v
|
|
|
183
201
|
for (const field of fields) {
|
|
184
202
|
displayedInfos.push({
|
|
185
203
|
label: field.label,
|
|
186
|
-
value: getValueFromPath(field.path, messageData),
|
|
204
|
+
value: (0, exports.getValueFromPath)(field.path, messageData),
|
|
187
205
|
});
|
|
188
206
|
}
|
|
189
207
|
return displayedInfos;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/message/EIP712/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAgC;AAChC,kDAA0B;AAC1B,8DAAsC;AACtC,iDAA4C;AAE5C,gFAA2D;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/message/EIP712/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAgC;AAChC,kDAA0B;AAC1B,8DAAsC;AACtC,iDAA4C;AAE5C,gFAA2D;AAC3D,sFAAgE;AAGhE,uGAAuG;AACvG,SAAgB,eAAe,CAAC,OAAgB;IAC9C,OAAO,CACL,CAAC,CAAC,OAAO;QACT,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,IAAI,OAAO;QAClB,aAAa,IAAI,OAAO;QACxB,QAAQ,IAAI,OAAO;QACnB,SAAS,IAAI,OAAO,CACrB,CAAC;AACJ,CAAC;AATD,0CASC;AAEM,MAAM,wBAAwB,GAAG,CAAC,GAA4B,EAA2B,EAAE;IAChG,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAErC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QAC/B,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE;YAClB,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;gBAC7B,OAAQ,GAAG,CAAC,IAAI,CAAe,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAC1C,IAAA,gCAAwB,EAAC,KAAgC,CAAC,CAC3D,CAAC;YACJ,CAAC;YACD,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC,CAAC,EAA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|
|
1
|
+
export type FieldFiltersV1 = {
|
|
2
|
+
label: string;
|
|
3
|
+
path: string;
|
|
4
|
+
signature: string;
|
|
5
|
+
format?: never;
|
|
6
|
+
coin_ref?: never;
|
|
7
|
+
};
|
|
8
|
+
export type FieldFiltersV2 = {
|
|
9
|
+
format: "raw" | "token" | "amount" | "datetime";
|
|
10
|
+
label: string;
|
|
11
|
+
path: string;
|
|
12
|
+
signature: string;
|
|
13
|
+
} & ({
|
|
14
|
+
format: "raw" | "datetime";
|
|
15
|
+
coin_ref?: never;
|
|
16
|
+
} | {
|
|
17
|
+
format: "token" | "amount";
|
|
18
|
+
coin_ref: number;
|
|
19
|
+
});
|
|
1
20
|
export type MessageFilters = {
|
|
2
21
|
contractName: {
|
|
3
22
|
label: string;
|
|
4
23
|
signature: string;
|
|
5
24
|
};
|
|
6
|
-
fields:
|
|
7
|
-
label: string;
|
|
8
|
-
path: string;
|
|
9
|
-
signature: string;
|
|
10
|
-
}[];
|
|
25
|
+
fields: FieldFiltersV1[] | FieldFiltersV2[];
|
|
11
26
|
};
|
|
27
|
+
export type CALServiceEIP712Response = {
|
|
28
|
+
eip712_signatures: {
|
|
29
|
+
[contractAddress: string]: {
|
|
30
|
+
[schemaHash: string]: MessageFilters;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}[];
|
|
12
34
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/message/EIP712/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/message/EIP712/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,CACA;IACE,MAAM,EAAE,KAAK,GAAG,UAAU,CAAC;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB,GACD;IACE,MAAM,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;CAClB,CACJ,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,YAAY,EAAE;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,MAAM,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,iBAAiB,EAAE;QACjB,CAAC,eAAe,EAAE,MAAM,GAAG;YAAE,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,CAAA;SAAE,CAAC;KACrE,CAAC;CACH,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/selectors/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/selectors/index.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAEH,oBAAY,4BAA4B;IACtC,OAAO,eAAe;IACtB,QAAQ,eAAe;CACxB;AAED,oBAAY,6BAA6B;IACvC,OAAO,eAAe;IACtB,oBAAoB,eAAe;IACnC,aAAa,eAAe;IAC5B,kBAAkB,eAAe;IACjC,4BAA4B,eAAe;CAC5C;AAED,oBAAY,8BAA8B;IACxC,oBAAoB,eAAe;IACnC,kBAAkB,eAAe;IACjC,wBAAwB,eAAe;CACxC;;;;;;AAED,wBAIE"}
|
package/lib/selectors/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/selectors/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,IAAY,4BAGX;AAHD,WAAY,4BAA4B;IACtC,sDAAsB,CAAA;IACtB,uDAAuB,CAAA;AACzB,CAAC,EAHW,4BAA4B,4CAA5B,4BAA4B,QAGvC;AAED,IAAY,6BAMX;AAND,WAAY,6BAA6B;IACvC,uDAAsB,CAAA;IACtB,oEAAmC,CAAA;IACnC,6DAA4B,CAAA;IAC5B,kEAAiC,CAAA;IACjC,4EAA2C,CAAA;AAC7C,CAAC,EANW,6BAA6B,6CAA7B,6BAA6B,QAMxC;AAED,IAAY,8BAIX;AAJD,WAAY,8BAA8B;IACxC,qEAAmC,CAAA;IACnC,mEAAiC,CAAA;IACjC,yEAAuC,CAAA;AACzC,CAAC,EAJW,8BAA8B,8CAA9B,8BAA8B,QAIzC;AAED,kBAAe;IACb,4BAA4B;IAC5B,6BAA6B;IAC7B,8BAA8B;CAC/B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/selectors/index.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC;;;;GAIG;;;AAEH,IAAY,4BAGX;AAHD,WAAY,4BAA4B;IACtC,sDAAsB,CAAA;IACtB,uDAAuB,CAAA;AACzB,CAAC,EAHW,4BAA4B,4CAA5B,4BAA4B,QAGvC;AAED,IAAY,6BAMX;AAND,WAAY,6BAA6B;IACvC,uDAAsB,CAAA;IACtB,oEAAmC,CAAA;IACnC,6DAA4B,CAAA;IAC5B,kEAAiC,CAAA;IACjC,4EAA2C,CAAA;AAC7C,CAAC,EANW,6BAA6B,6CAA7B,6BAA6B,QAMxC;AAED,IAAY,8BAIX;AAJD,WAAY,8BAA8B;IACxC,qEAAmC,CAAA;IACnC,mEAAiC,CAAA;IACjC,yEAAuC,CAAA;AACzC,CAAC,EAJW,8BAA8B,8CAA9B,8BAA8B,QAIzC;AAED,kBAAe;IACb,4BAA4B;IAC5B,6BAA6B;IAC7B,8BAA8B;CAC/B,CAAC"}
|
|
@@ -10,11 +10,16 @@ export declare const getSchemaHashForMessage: (message: EIP712Message) => string
|
|
|
10
10
|
* @param {EIP712Message} message
|
|
11
11
|
* @returns {MessageFilters | undefined}
|
|
12
12
|
*/
|
|
13
|
-
export declare const getFiltersForMessage: (message: EIP712Message,
|
|
13
|
+
export declare const getFiltersForMessage: (message: EIP712Message, shouldUseV1Filters?: boolean, calServiceURL?: string | null) => Promise<MessageFilters | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* Using a path as a string, returns the value(s) of a json key without worrying about depth or arrays
|
|
16
|
+
* (e.g: 'to.wallets.[]' => ["0x123", "0x456"])
|
|
17
|
+
*/
|
|
18
|
+
export declare const getValueFromPath: (path: string, eip721Message: EIP712Message) => string | string[];
|
|
14
19
|
/**
|
|
15
20
|
* Gets the fields visible on the nano for a specific EIP712 message
|
|
16
21
|
*/
|
|
17
|
-
export declare const getEIP712FieldsDisplayedOnNano: (messageData: EIP712Message,
|
|
22
|
+
export declare const getEIP712FieldsDisplayedOnNano: (messageData: EIP712Message, calServiceURL?: string) => Promise<{
|
|
18
23
|
label: string;
|
|
19
24
|
value: string | string[];
|
|
20
25
|
}[] | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/message/EIP712/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/message/EIP712/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,EAA4B,cAAc,EAAE,MAAM,SAAS,CAAC;AAGnE,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,aAAa,CAS1E;AAED,eAAO,MAAM,wBAAwB,QAAS,OAAO,MAAM,EAAE,OAAO,CAAC,KAAG,OAAO,MAAM,EAAE,OAAO,CAgB7F,CAAC;AAEF,eAAO,MAAM,uBAAuB,YAAa,aAAa,KAAG,MAKhE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,YACtB,aAAa,uBACD,OAAO,kBACZ,MAAM,GAAG,IAAI,KAC5B,QAAQ,cAAc,GAAG,SAAS,CAiCpC,CAAC;AA4BF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,SAAU,MAAM,iBAAiB,aAAa,KAAG,MAAM,GAAG,MAAM,EAmB5F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,8BAA8B,gBAC5B,aAAa,kBACX,MAAM,KACpB,QAAQ;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE,EAAE,GAAG,IAAI,CA4E9D,CAAC"}
|
|
@@ -23,7 +23,7 @@ import axios from "axios";
|
|
|
23
23
|
import SHA224 from "crypto-js/sha224";
|
|
24
24
|
import { getEnv } from "@ledgerhq/live-env";
|
|
25
25
|
import EIP712CAL from "@ledgerhq/cryptoassets/data/eip712";
|
|
26
|
-
|
|
26
|
+
import EIP712CALV2 from "@ledgerhq/cryptoassets/data/eip712_v2";
|
|
27
27
|
// As defined in [spec](https://eips.ethereum.org/EIPS/eip-712), the properties below are all required.
|
|
28
28
|
export function isEIP712Message(message) {
|
|
29
29
|
return (!!message &&
|
|
@@ -58,19 +58,36 @@ export const getSchemaHashForMessage = (message) => {
|
|
|
58
58
|
* @param {EIP712Message} message
|
|
59
59
|
* @returns {MessageFilters | undefined}
|
|
60
60
|
*/
|
|
61
|
-
export const getFiltersForMessage = (message,
|
|
62
|
-
var _a, _b, _c, _d;
|
|
61
|
+
export const getFiltersForMessage = (message, shouldUseV1Filters, calServiceURL) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
63
63
|
const schemaHash = getSchemaHashForMessage(message);
|
|
64
|
-
const
|
|
64
|
+
const verifyingContract = ((_b = (_a = message.domain) === null || _a === void 0 ? void 0 : _a.verifyingContract) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || ethers.constants.AddressZero;
|
|
65
65
|
try {
|
|
66
|
-
if (
|
|
67
|
-
const { data
|
|
68
|
-
|
|
66
|
+
if (calServiceURL) {
|
|
67
|
+
const { data } = yield axios.get(`${calServiceURL}/v1/dapps`, {
|
|
68
|
+
params: {
|
|
69
|
+
output: "eip712_signatures",
|
|
70
|
+
eip712_signatures_version: shouldUseV1Filters ? "v1" : "v2",
|
|
71
|
+
chain_id: (_c = message.domain) === null || _c === void 0 ? void 0 : _c.chainId,
|
|
72
|
+
contracts: verifyingContract,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
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];
|
|
76
|
+
if (!filters) {
|
|
77
|
+
// Fallback to catch
|
|
78
|
+
throw new Error("Fallback to static file");
|
|
79
|
+
}
|
|
80
|
+
return filters;
|
|
69
81
|
}
|
|
70
|
-
|
|
82
|
+
// Fallback to catch
|
|
83
|
+
throw new Error("Fallback to static file");
|
|
71
84
|
}
|
|
72
85
|
catch (e) {
|
|
73
|
-
|
|
86
|
+
const messageId = `${(_h = (_g = message.domain) === null || _g === void 0 ? void 0 : _g.chainId) !== null && _h !== void 0 ? _h : 0}:${verifyingContract}:${schemaHash}`;
|
|
87
|
+
if (shouldUseV1Filters) {
|
|
88
|
+
return EIP712CAL[messageId];
|
|
89
|
+
}
|
|
90
|
+
return EIP712CALV2[messageId];
|
|
74
91
|
}
|
|
75
92
|
});
|
|
76
93
|
/**
|
|
@@ -86,7 +103,7 @@ const getValue = (path, value) => {
|
|
|
86
103
|
}
|
|
87
104
|
/* istanbul ignore if : unecessary test of a throw */
|
|
88
105
|
if (!(path in value)) {
|
|
89
|
-
throw new Error(`Could not find key ${
|
|
106
|
+
throw new Error(`Could not find key ${path} in ${JSON.stringify(value)} `);
|
|
90
107
|
}
|
|
91
108
|
const result = value[path];
|
|
92
109
|
return typeof result === "object" ? result : result.toString();
|
|
@@ -97,7 +114,7 @@ const getValue = (path, value) => {
|
|
|
97
114
|
* Using a path as a string, returns the value(s) of a json key without worrying about depth or arrays
|
|
98
115
|
* (e.g: 'to.wallets.[]' => ["0x123", "0x456"])
|
|
99
116
|
*/
|
|
100
|
-
const getValueFromPath = (path, eip721Message) => {
|
|
117
|
+
export const getValueFromPath = (path, eip721Message) => {
|
|
101
118
|
const splittedPath = path.split(".");
|
|
102
119
|
const { message } = eip721Message;
|
|
103
120
|
let value = message;
|
|
@@ -117,13 +134,13 @@ const getValueFromPath = (path, eip721Message) => {
|
|
|
117
134
|
/**
|
|
118
135
|
* Gets the fields visible on the nano for a specific EIP712 message
|
|
119
136
|
*/
|
|
120
|
-
export const getEIP712FieldsDisplayedOnNano = (messageData_1, ...args_1) => __awaiter(void 0, [messageData_1, ...args_1], void 0, function* (messageData,
|
|
137
|
+
export const getEIP712FieldsDisplayedOnNano = (messageData_1, ...args_1) => __awaiter(void 0, [messageData_1, ...args_1], void 0, function* (messageData, calServiceURL = getEnv("CAL_SERVICE_URL")) {
|
|
121
138
|
if (!isEIP712Message(messageData)) {
|
|
122
139
|
return null;
|
|
123
140
|
}
|
|
124
|
-
const
|
|
141
|
+
const _j = messageData.types, { EIP712Domain } = _j, otherTypes = __rest(_j, ["EIP712Domain"]);
|
|
125
142
|
const displayedInfos = [];
|
|
126
|
-
const filters = yield getFiltersForMessage(messageData,
|
|
143
|
+
const filters = yield getFiltersForMessage(messageData, false, calServiceURL);
|
|
127
144
|
if (!filters) {
|
|
128
145
|
const { types } = messageData;
|
|
129
146
|
const domainFields = types["EIP712Domain"].map(({ name }) => name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/message/EIP712/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,SAAS,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/message/EIP712/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,SAAS,MAAM,oCAAoC,CAAC;AAC3D,OAAO,WAAW,MAAM,uCAAuC,CAAC;AAGhE,uGAAuG;AACvG,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,OAAO,CACL,CAAC,CAAC,OAAO;QACT,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,IAAI,OAAO;QAClB,aAAa,IAAI,OAAO;QACxB,QAAQ,IAAI,OAAO;QACnB,SAAS,IAAI,OAAO,CACrB,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,GAA4B,EAA2B,EAAE;IAChG,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAErC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GA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KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC;SACjD,CAAC,CAAC;IACL,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC,CAAA,CAAC"}
|
|
@@ -1,12 +1,34 @@
|
|
|
1
|
+
export type FieldFiltersV1 = {
|
|
2
|
+
label: string;
|
|
3
|
+
path: string;
|
|
4
|
+
signature: string;
|
|
5
|
+
format?: never;
|
|
6
|
+
coin_ref?: never;
|
|
7
|
+
};
|
|
8
|
+
export type FieldFiltersV2 = {
|
|
9
|
+
format: "raw" | "token" | "amount" | "datetime";
|
|
10
|
+
label: string;
|
|
11
|
+
path: string;
|
|
12
|
+
signature: string;
|
|
13
|
+
} & ({
|
|
14
|
+
format: "raw" | "datetime";
|
|
15
|
+
coin_ref?: never;
|
|
16
|
+
} | {
|
|
17
|
+
format: "token" | "amount";
|
|
18
|
+
coin_ref: number;
|
|
19
|
+
});
|
|
1
20
|
export type MessageFilters = {
|
|
2
21
|
contractName: {
|
|
3
22
|
label: string;
|
|
4
23
|
signature: string;
|
|
5
24
|
};
|
|
6
|
-
fields:
|
|
7
|
-
label: string;
|
|
8
|
-
path: string;
|
|
9
|
-
signature: string;
|
|
10
|
-
}[];
|
|
25
|
+
fields: FieldFiltersV1[] | FieldFiltersV2[];
|
|
11
26
|
};
|
|
27
|
+
export type CALServiceEIP712Response = {
|
|
28
|
+
eip712_signatures: {
|
|
29
|
+
[contractAddress: string]: {
|
|
30
|
+
[schemaHash: string]: MessageFilters;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}[];
|
|
12
34
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/message/EIP712/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/message/EIP712/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,CACA;IACE,MAAM,EAAE,KAAK,GAAG,UAAU,CAAC;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB,GACD;IACE,MAAM,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;CAClB,CACJ,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,YAAY,EAAE;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,MAAM,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,iBAAiB,EAAE;QACjB,CAAC,eAAe,EAAE,MAAM,GAAG;YAAE,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,CAAA;SAAE,CAAC;KACrE,CAAC;CACH,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/selectors/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/selectors/index.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAEH,oBAAY,4BAA4B;IACtC,OAAO,eAAe;IACtB,QAAQ,eAAe;CACxB;AAED,oBAAY,6BAA6B;IACvC,OAAO,eAAe;IACtB,oBAAoB,eAAe;IACnC,aAAa,eAAe;IAC5B,kBAAkB,eAAe;IACjC,4BAA4B,eAAe;CAC5C;AAED,oBAAY,8BAA8B;IACxC,oBAAoB,eAAe;IACnC,kBAAkB,eAAe;IACjC,wBAAwB,eAAe;CACxC;;;;;;AAED,wBAIE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/selectors/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAN,IAAY,4BAGX;AAHD,WAAY,4BAA4B;IACtC,sDAAsB,CAAA;IACtB,uDAAuB,CAAA;AACzB,CAAC,EAHW,4BAA4B,KAA5B,4BAA4B,QAGvC;AAED,MAAM,CAAN,IAAY,6BAMX;AAND,WAAY,6BAA6B;IACvC,uDAAsB,CAAA;IACtB,oEAAmC,CAAA;IACnC,6DAA4B,CAAA;IAC5B,kEAAiC,CAAA;IACjC,4EAA2C,CAAA;AAC7C,CAAC,EANW,6BAA6B,KAA7B,6BAA6B,QAMxC;AAED,MAAM,CAAN,IAAY,8BAIX;AAJD,WAAY,8BAA8B;IACxC,qEAAmC,CAAA;IACnC,mEAAiC,CAAA;IACjC,yEAAuC,CAAA;AACzC,CAAC,EAJW,8BAA8B,KAA9B,8BAA8B,QAIzC;AAED,eAAe;IACb,4BAA4B;IAC5B,6BAA6B;IAC7B,8BAA8B;CAC/B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/selectors/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC;;;;GAIG;AAEH,MAAM,CAAN,IAAY,4BAGX;AAHD,WAAY,4BAA4B;IACtC,sDAAsB,CAAA;IACtB,uDAAuB,CAAA;AACzB,CAAC,EAHW,4BAA4B,KAA5B,4BAA4B,QAGvC;AAED,MAAM,CAAN,IAAY,6BAMX;AAND,WAAY,6BAA6B;IACvC,uDAAsB,CAAA;IACtB,oEAAmC,CAAA;IACnC,6DAA4B,CAAA;IAC5B,kEAAiC,CAAA;IACjC,4EAA2C,CAAA;AAC7C,CAAC,EANW,6BAA6B,KAA7B,6BAA6B,QAMxC;AAED,MAAM,CAAN,IAAY,8BAIX;AAJD,WAAY,8BAA8B;IACxC,qEAAmC,CAAA;IACnC,mEAAiC,CAAA;IACjC,yEAAuC,CAAA;AACzC,CAAC,EAJW,8BAA8B,KAA9B,8BAA8B,QAIzC;AAED,eAAe;IACb,4BAA4B;IAC5B,6BAA6B;IAC7B,8BAA8B;CAC/B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/evm-tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-next.0",
|
|
4
4
|
"description": "EVM tooling used for coin integrations & app bindings",
|
|
5
5
|
"main": "./index.ts",
|
|
6
6
|
"keywords": [
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"axios": "^1.6.5",
|
|
49
49
|
"crypto-js": "4.2.0",
|
|
50
50
|
"ethers": "5.7.2",
|
|
51
|
-
"@ledgerhq/cryptoassets": "^13.
|
|
52
|
-
"@ledgerhq/live-env": "^2.
|
|
51
|
+
"@ledgerhq/cryptoassets": "^13.3.0-next.0",
|
|
52
|
+
"@ledgerhq/live-env": "^2.2.0-next.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/axios": "^0.14.0",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@types/node": "^20.8.10",
|
|
59
59
|
"jest": "^29.7.0",
|
|
60
60
|
"ts-jest": "^29.1.1",
|
|
61
|
-
"@ledgerhq/types-live": "^6.
|
|
61
|
+
"@ledgerhq/types-live": "^6.50.0-next.0"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"clean": "rimraf lib lib-es",
|
|
@@ -24,6 +24,12 @@ export const messageNotInCAL = {
|
|
|
24
24
|
|
|
25
25
|
export const messageNotInCALSchemaHash = "7f5ab7ce66fbfb21beb6189a02b44bb141b5fb2008e3d0c1e83351e7";
|
|
26
26
|
|
|
27
|
-
export const dynamicCAL =
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
export const dynamicCAL = [
|
|
28
|
+
{
|
|
29
|
+
eip712_signatures: {
|
|
30
|
+
["0xd007d007a0d06d4fbbf627410eade051fd66fc59"]: {
|
|
31
|
+
[messageNotInCALSchemaHash]: "found",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
];
|
|
@@ -13,6 +13,7 @@ const CAL = jest.requireActual("../../fixtures/CAL").default;
|
|
|
13
13
|
|
|
14
14
|
jest.mock("axios");
|
|
15
15
|
jest.mock("@ledgerhq/cryptoassets/data/eip712", () => require("../../fixtures/CAL"));
|
|
16
|
+
jest.mock("@ledgerhq/cryptoassets/data/eip712_v2", () => require("../../fixtures/CAL"));
|
|
16
17
|
|
|
17
18
|
describe("evm-tools", () => {
|
|
18
19
|
describe("message", () => {
|
|
@@ -128,13 +129,13 @@ describe("evm-tools", () => {
|
|
|
128
129
|
data: dynamicCAL,
|
|
129
130
|
});
|
|
130
131
|
|
|
131
|
-
const result = await getFiltersForMessage(messageNotInCAL, "http://CAL-ADDRESS");
|
|
132
|
+
const result = await getFiltersForMessage(messageNotInCAL, false, "http://CAL-ADDRESS");
|
|
132
133
|
expect(result).toEqual("found");
|
|
133
134
|
});
|
|
134
135
|
|
|
135
136
|
it("should find the filters for a message in static CAL if the message is not in dynamic CAL return", async () => {
|
|
136
137
|
(axios.get as jest.Mock).mockReturnValueOnce({
|
|
137
|
-
data:
|
|
138
|
+
data: [],
|
|
138
139
|
});
|
|
139
140
|
const schemaHash = "d8e4f2bd77f7562e99ea5df4adb127291a2bfbc225ae55450038f27f";
|
|
140
141
|
|
|
@@ -153,7 +154,7 @@ describe("evm-tools", () => {
|
|
|
153
154
|
(axios.get as jest.Mock).mockRejectedValue(new Error());
|
|
154
155
|
const schemaHash = "d8e4f2bd77f7562e99ea5df4adb127291a2bfbc225ae55450038f27f";
|
|
155
156
|
|
|
156
|
-
const result = await getFiltersForMessage(messageInCAL, "http://CAL-ADDRESS");
|
|
157
|
+
const result = await getFiltersForMessage(messageInCAL, false, "http://CAL-ADDRESS");
|
|
157
158
|
expect(result).toEqual(CAL[`1:0x7f268357a8c2552623316e2562d90e642bb538e5:${schemaHash}`]);
|
|
158
159
|
});
|
|
159
160
|
});
|
|
@@ -4,9 +4,8 @@ import SHA224 from "crypto-js/sha224";
|
|
|
4
4
|
import { getEnv } from "@ledgerhq/live-env";
|
|
5
5
|
import { EIP712Message } from "@ledgerhq/types-live";
|
|
6
6
|
import EIP712CAL from "@ledgerhq/cryptoassets/data/eip712";
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
const NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
7
|
+
import EIP712CALV2 from "@ledgerhq/cryptoassets/data/eip712_v2";
|
|
8
|
+
import { CALServiceEIP712Response, MessageFilters } from "./types";
|
|
10
9
|
|
|
11
10
|
// As defined in [spec](https://eips.ethereum.org/EIPS/eip-712), the properties below are all required.
|
|
12
11
|
export function isEIP712Message(message: unknown): message is EIP712Message {
|
|
@@ -54,24 +53,40 @@ export const getSchemaHashForMessage = (message: EIP712Message): string => {
|
|
|
54
53
|
*/
|
|
55
54
|
export const getFiltersForMessage = async (
|
|
56
55
|
message: EIP712Message,
|
|
57
|
-
|
|
56
|
+
shouldUseV1Filters?: boolean,
|
|
57
|
+
calServiceURL?: string | null,
|
|
58
58
|
): Promise<MessageFilters | undefined> => {
|
|
59
59
|
const schemaHash = getSchemaHashForMessage(message);
|
|
60
|
-
const
|
|
61
|
-
message.domain?.verifyingContract
|
|
62
|
-
}:${schemaHash}`;
|
|
63
|
-
|
|
60
|
+
const verifyingContract =
|
|
61
|
+
message.domain?.verifyingContract?.toLowerCase() || ethers.constants.AddressZero;
|
|
64
62
|
try {
|
|
65
|
-
if (
|
|
66
|
-
const { data
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
if (calServiceURL) {
|
|
64
|
+
const { data } = await axios.get<CALServiceEIP712Response>(`${calServiceURL}/v1/dapps`, {
|
|
65
|
+
params: {
|
|
66
|
+
output: "eip712_signatures",
|
|
67
|
+
eip712_signatures_version: shouldUseV1Filters ? "v1" : "v2",
|
|
68
|
+
chain_id: message.domain?.chainId,
|
|
69
|
+
contracts: verifyingContract,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
69
72
|
|
|
70
|
-
|
|
73
|
+
const filters = data?.[0]?.eip712_signatures?.[verifyingContract]?.[schemaHash];
|
|
74
|
+
if (!filters) {
|
|
75
|
+
// Fallback to catch
|
|
76
|
+
throw new Error("Fallback to static file");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return filters;
|
|
71
80
|
}
|
|
72
|
-
|
|
81
|
+
// Fallback to catch
|
|
82
|
+
throw new Error("Fallback to static file");
|
|
73
83
|
} catch (e) {
|
|
74
|
-
|
|
84
|
+
const messageId = `${message.domain?.chainId ?? 0}:${verifyingContract}:${schemaHash}`;
|
|
85
|
+
|
|
86
|
+
if (shouldUseV1Filters) {
|
|
87
|
+
return EIP712CAL[messageId as keyof typeof EIP712CAL];
|
|
88
|
+
}
|
|
89
|
+
return EIP712CALV2[messageId as keyof typeof EIP712CALV2] as MessageFilters;
|
|
75
90
|
}
|
|
76
91
|
};
|
|
77
92
|
|
|
@@ -92,7 +107,7 @@ const getValue = (
|
|
|
92
107
|
|
|
93
108
|
/* istanbul ignore if : unecessary test of a throw */
|
|
94
109
|
if (!(path in value)) {
|
|
95
|
-
throw new Error(`Could not find key ${
|
|
110
|
+
throw new Error(`Could not find key ${path} in ${JSON.stringify(value)} `);
|
|
96
111
|
}
|
|
97
112
|
const result = value[path];
|
|
98
113
|
return typeof result === "object" ? result : result.toString();
|
|
@@ -105,7 +120,7 @@ const getValue = (
|
|
|
105
120
|
* Using a path as a string, returns the value(s) of a json key without worrying about depth or arrays
|
|
106
121
|
* (e.g: 'to.wallets.[]' => ["0x123", "0x456"])
|
|
107
122
|
*/
|
|
108
|
-
const getValueFromPath = (path: string, eip721Message: EIP712Message): string | string[] => {
|
|
123
|
+
export const getValueFromPath = (path: string, eip721Message: EIP712Message): string | string[] => {
|
|
109
124
|
const splittedPath = path.split(".");
|
|
110
125
|
const { message } = eip721Message;
|
|
111
126
|
|
|
@@ -131,7 +146,7 @@ const getValueFromPath = (path: string, eip721Message: EIP712Message): string |
|
|
|
131
146
|
*/
|
|
132
147
|
export const getEIP712FieldsDisplayedOnNano = async (
|
|
133
148
|
messageData: EIP712Message,
|
|
134
|
-
|
|
149
|
+
calServiceURL: string = getEnv("CAL_SERVICE_URL"),
|
|
135
150
|
): Promise<{ label: string; value: string | string[] }[] | null> => {
|
|
136
151
|
if (!isEIP712Message(messageData)) {
|
|
137
152
|
return null;
|
|
@@ -139,7 +154,7 @@ export const getEIP712FieldsDisplayedOnNano = async (
|
|
|
139
154
|
|
|
140
155
|
const { EIP712Domain, ...otherTypes } = messageData.types;
|
|
141
156
|
const displayedInfos: { label: string; value: string | string[] }[] = [];
|
|
142
|
-
const filters = await getFiltersForMessage(messageData,
|
|
157
|
+
const filters = await getFiltersForMessage(messageData, false, calServiceURL);
|
|
143
158
|
|
|
144
159
|
if (!filters) {
|
|
145
160
|
const { types } = messageData;
|
|
@@ -1,11 +1,37 @@
|
|
|
1
|
+
export type FieldFiltersV1 = {
|
|
2
|
+
label: string;
|
|
3
|
+
path: string;
|
|
4
|
+
signature: string;
|
|
5
|
+
format?: never;
|
|
6
|
+
coin_ref?: never;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type FieldFiltersV2 = {
|
|
10
|
+
format: "raw" | "token" | "amount" | "datetime";
|
|
11
|
+
label: string;
|
|
12
|
+
path: string;
|
|
13
|
+
signature: string;
|
|
14
|
+
} & (
|
|
15
|
+
| {
|
|
16
|
+
format: "raw" | "datetime";
|
|
17
|
+
coin_ref?: never;
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
format: "token" | "amount";
|
|
21
|
+
coin_ref: number;
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
|
|
1
25
|
export type MessageFilters = {
|
|
2
26
|
contractName: {
|
|
3
27
|
label: string;
|
|
4
28
|
signature: string;
|
|
5
29
|
};
|
|
6
|
-
fields:
|
|
7
|
-
label: string;
|
|
8
|
-
path: string;
|
|
9
|
-
signature: string;
|
|
10
|
-
}[];
|
|
30
|
+
fields: FieldFiltersV1[] | FieldFiltersV2[];
|
|
11
31
|
};
|
|
32
|
+
|
|
33
|
+
export type CALServiceEIP712Response = {
|
|
34
|
+
eip712_signatures: {
|
|
35
|
+
[contractAddress: string]: { [schemaHash: string]: MessageFilters };
|
|
36
|
+
};
|
|
37
|
+
}[];
|
package/src/selectors/index.ts
CHANGED