@ledgerhq/hw-app-eth 6.28.2 → 6.29.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.
Files changed (106) hide show
  1. package/.turbo/turbo-build.log +5 -2
  2. package/CHANGELOG.md +13 -0
  3. package/README.md +58 -16
  4. package/jest.config.ts +6 -0
  5. package/lib/Eth.d.ts +37 -0
  6. package/lib/Eth.d.ts.map +1 -1
  7. package/lib/Eth.js +66 -72
  8. package/lib/Eth.js.map +1 -1
  9. package/lib/modules/EIP712/EIP712.types.d.ts +44 -0
  10. package/lib/modules/EIP712/EIP712.types.d.ts.map +1 -0
  11. package/lib/modules/EIP712/EIP712.types.js +3 -0
  12. package/lib/modules/EIP712/EIP712.types.js.map +1 -0
  13. package/lib/modules/EIP712/EIP712.utils.d.ts +65 -0
  14. package/lib/modules/EIP712/EIP712.utils.d.ts.map +1 -0
  15. package/lib/modules/EIP712/EIP712.utils.js +217 -0
  16. package/lib/modules/EIP712/EIP712.utils.js.map +1 -0
  17. package/lib/modules/EIP712/index.d.ts +60 -0
  18. package/lib/modules/EIP712/index.d.ts.map +1 -0
  19. package/lib/modules/EIP712/index.js +554 -0
  20. package/lib/modules/EIP712/index.js.map +1 -0
  21. package/lib/utils.d.ts +15 -1
  22. package/lib/utils.d.ts.map +1 -1
  23. package/lib/utils.js +43 -3
  24. package/lib/utils.js.map +1 -1
  25. package/lib-es/Eth.d.ts +37 -0
  26. package/lib-es/Eth.d.ts.map +1 -1
  27. package/lib-es/Eth.js +42 -48
  28. package/lib-es/Eth.js.map +1 -1
  29. package/lib-es/modules/EIP712/EIP712.types.d.ts +44 -0
  30. package/lib-es/modules/EIP712/EIP712.types.d.ts.map +1 -0
  31. package/lib-es/modules/EIP712/EIP712.types.js +2 -0
  32. package/lib-es/modules/EIP712/EIP712.types.js.map +1 -0
  33. package/lib-es/modules/EIP712/EIP712.utils.d.ts +65 -0
  34. package/lib-es/modules/EIP712/EIP712.utils.d.ts.map +1 -0
  35. package/lib-es/modules/EIP712/EIP712.utils.js +211 -0
  36. package/lib-es/modules/EIP712/EIP712.utils.js.map +1 -0
  37. package/lib-es/modules/EIP712/index.d.ts +60 -0
  38. package/lib-es/modules/EIP712/index.d.ts.map +1 -0
  39. package/lib-es/modules/EIP712/index.js +549 -0
  40. package/lib-es/modules/EIP712/index.js.map +1 -0
  41. package/lib-es/services/ledger/contracts.d.ts +0 -0
  42. package/lib-es/services/ledger/contracts.d.ts.map +0 -0
  43. package/lib-es/services/ledger/contracts.js +0 -0
  44. package/lib-es/services/ledger/contracts.js.map +0 -0
  45. package/lib-es/services/ledger/erc20.d.ts +0 -0
  46. package/lib-es/services/ledger/erc20.d.ts.map +0 -0
  47. package/lib-es/services/ledger/erc20.js +0 -0
  48. package/lib-es/services/ledger/erc20.js.map +0 -0
  49. package/lib-es/services/ledger/index.d.ts +0 -0
  50. package/lib-es/services/ledger/index.d.ts.map +0 -0
  51. package/lib-es/services/ledger/index.js +0 -0
  52. package/lib-es/services/ledger/index.js.map +0 -0
  53. package/lib-es/services/ledger/loadConfig.d.ts +0 -0
  54. package/lib-es/services/ledger/loadConfig.d.ts.map +0 -0
  55. package/lib-es/services/ledger/loadConfig.js +0 -0
  56. package/lib-es/services/ledger/loadConfig.js.map +0 -0
  57. package/lib-es/services/ledger/nfts.d.ts +0 -0
  58. package/lib-es/services/ledger/nfts.d.ts.map +0 -0
  59. package/lib-es/services/ledger/nfts.js +0 -0
  60. package/lib-es/services/ledger/nfts.js.map +0 -0
  61. package/lib-es/services/types.d.ts +0 -0
  62. package/lib-es/services/types.d.ts.map +0 -0
  63. package/lib-es/services/types.js +0 -0
  64. package/lib-es/services/types.js.map +0 -0
  65. package/lib-es/utils.d.ts +15 -1
  66. package/lib-es/utils.d.ts.map +1 -1
  67. package/lib-es/utils.js +38 -2
  68. package/lib-es/utils.js.map +1 -1
  69. package/package.json +13 -8
  70. package/src/Eth.ts +59 -56
  71. package/src/modules/EIP712/EIP712.types.ts +54 -0
  72. package/src/modules/EIP712/EIP712.utils.ts +251 -0
  73. package/src/modules/EIP712/index.ts +409 -0
  74. package/src/utils.ts +42 -2
  75. package/tests/EIP712.unit.test.ts +760 -0
  76. package/tests/sample-messages/0.apdus +58 -0
  77. package/tests/sample-messages/0.json +44 -0
  78. package/tests/sample-messages/1.apdus +66 -0
  79. package/tests/sample-messages/1.json +50 -0
  80. package/tests/sample-messages/10.apdus +30 -0
  81. package/tests/sample-messages/10.json +23 -0
  82. package/tests/sample-messages/2.apdus +126 -0
  83. package/tests/sample-messages/2.json +153 -0
  84. package/tests/sample-messages/3.apdus +42 -0
  85. package/tests/sample-messages/3.json +31 -0
  86. package/tests/sample-messages/4.apdus +84 -0
  87. package/tests/sample-messages/4.json +110 -0
  88. package/tests/sample-messages/5.apdus +112 -0
  89. package/tests/sample-messages/5.json +92 -0
  90. package/tests/sample-messages/6.apdus +94 -0
  91. package/tests/sample-messages/6.json +78 -0
  92. package/tests/sample-messages/7.apdus +70 -0
  93. package/tests/sample-messages/7.json +55 -0
  94. package/tests/sample-messages/8.apdus +68 -0
  95. package/tests/sample-messages/8.json +50 -0
  96. package/tests/sample-messages/9.apdus +68 -0
  97. package/tests/sample-messages/9.json +50 -0
  98. package/LICENSE +0 -202
  99. package/lib-es/contracts.d.ts +0 -17
  100. package/lib-es/contracts.d.ts.map +0 -1
  101. package/lib-es/contracts.js +0 -103
  102. package/lib-es/contracts.js.map +0 -1
  103. package/lib-es/erc20.d.ts +0 -22
  104. package/lib-es/erc20.d.ts.map +0 -1
  105. package/lib-es/erc20.js +0 -64
  106. package/lib-es/erc20.js.map +0 -1
@@ -0,0 +1,554 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __read = (this && this.__read) || function (o, n) {
50
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
51
+ if (!m) return o;
52
+ var i = m.call(o), r, ar = [], e;
53
+ try {
54
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
55
+ }
56
+ catch (error) { e = { error: error }; }
57
+ finally {
58
+ try {
59
+ if (r && !r.done && (m = i["return"])) m.call(i);
60
+ }
61
+ finally { if (e) throw e.error; }
62
+ }
63
+ return ar;
64
+ };
65
+ var __values = (this && this.__values) || function(o) {
66
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
67
+ if (m) return m.call(o);
68
+ if (o && typeof o.length === "number") return {
69
+ next: function () {
70
+ if (o && i >= o.length) o = void 0;
71
+ return { value: o && o[i++], done: !o };
72
+ }
73
+ };
74
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
75
+ };
76
+ exports.__esModule = true;
77
+ exports.signEIP712HashedMessage = exports.signEIP712Message = void 0;
78
+ var utils_1 = require("../../utils");
79
+ var EIP712_utils_1 = require("./EIP712.utils");
80
+ /**
81
+ * @ignore for the README
82
+ *
83
+ * Factory to create the recursive function that will pass on each
84
+ * field level and APDUs to describe its structure implementation
85
+ *
86
+ * @param {Eth["EIP712SendStructImplem"]} EIP712SendStructImplem
87
+ * @param {EIP712MessageTypes} types
88
+ * @returns {void}
89
+ */
90
+ var makeRecursiveFieldStructImplem = function (transport, types) {
91
+ var _a;
92
+ var typesMap = {};
93
+ for (var type in types) {
94
+ typesMap[type] = (_a = types[type]) === null || _a === void 0 ? void 0 : _a.reduce(function (acc, curr) {
95
+ var _a;
96
+ return (__assign(__assign({}, acc), (_a = {}, _a[curr.name] = curr.type, _a)));
97
+ }, {});
98
+ }
99
+ // This recursion will call itself to handle each level of each field
100
+ // in order to send APDUs for each of them
101
+ var recursiveFieldStructImplem = function (destructedType, data) { return __awaiter(void 0, void 0, void 0, function () {
102
+ var _a, typeDescription, arrSizes, _b, currSize, restSizes, isCustomType, data_1, data_1_1, entry, e_1_1, _c, _d, _e, fieldName, fieldValue, fieldType, e_2_1;
103
+ var e_1, _f, e_2, _g;
104
+ var _h;
105
+ return __generator(this, function (_j) {
106
+ switch (_j.label) {
107
+ case 0:
108
+ _a = __read(destructedType, 2), typeDescription = _a[0], arrSizes = _a[1];
109
+ _b = __read(arrSizes), currSize = _b[0], restSizes = _b.slice(1);
110
+ isCustomType = !EIP712_utils_1.EIP712_TYPE_PROPERTIES[((_h = typeDescription === null || typeDescription === void 0 ? void 0 : typeDescription.name) === null || _h === void 0 ? void 0 : _h.toUpperCase()) || ""];
111
+ if (!(Array.isArray(data) && typeof currSize !== "undefined")) return [3 /*break*/, 10];
112
+ return [4 /*yield*/, EIP712SendStructImplem(transport, {
113
+ structType: "array",
114
+ value: data.length
115
+ })];
116
+ case 1:
117
+ _j.sent();
118
+ _j.label = 2;
119
+ case 2:
120
+ _j.trys.push([2, 7, 8, 9]);
121
+ data_1 = __values(data), data_1_1 = data_1.next();
122
+ _j.label = 3;
123
+ case 3:
124
+ if (!!data_1_1.done) return [3 /*break*/, 6];
125
+ entry = data_1_1.value;
126
+ return [4 /*yield*/, recursiveFieldStructImplem([typeDescription, restSizes], entry)];
127
+ case 4:
128
+ _j.sent();
129
+ _j.label = 5;
130
+ case 5:
131
+ data_1_1 = data_1.next();
132
+ return [3 /*break*/, 3];
133
+ case 6: return [3 /*break*/, 9];
134
+ case 7:
135
+ e_1_1 = _j.sent();
136
+ e_1 = { error: e_1_1 };
137
+ return [3 /*break*/, 9];
138
+ case 8:
139
+ try {
140
+ if (data_1_1 && !data_1_1.done && (_f = data_1["return"])) _f.call(data_1);
141
+ }
142
+ finally { if (e_1) throw e_1.error; }
143
+ return [7 /*endfinally*/];
144
+ case 9: return [3 /*break*/, 21];
145
+ case 10:
146
+ if (!isCustomType) return [3 /*break*/, 19];
147
+ _j.label = 11;
148
+ case 11:
149
+ _j.trys.push([11, 16, 17, 18]);
150
+ _c = __values(Object.entries(data)), _d = _c.next();
151
+ _j.label = 12;
152
+ case 12:
153
+ if (!!_d.done) return [3 /*break*/, 15];
154
+ _e = __read(_d.value, 2), fieldName = _e[0], fieldValue = _e[1];
155
+ fieldType = typesMap === null || typesMap === void 0 ? void 0 : typesMap[(typeDescription === null || typeDescription === void 0 ? void 0 : typeDescription.name) || ""][fieldName];
156
+ if (!fieldType) return [3 /*break*/, 14];
157
+ return [4 /*yield*/, recursiveFieldStructImplem((0, EIP712_utils_1.destructTypeFromString)(fieldType), fieldValue)];
158
+ case 13:
159
+ _j.sent();
160
+ _j.label = 14;
161
+ case 14:
162
+ _d = _c.next();
163
+ return [3 /*break*/, 12];
164
+ case 15: return [3 /*break*/, 18];
165
+ case 16:
166
+ e_2_1 = _j.sent();
167
+ e_2 = { error: e_2_1 };
168
+ return [3 /*break*/, 18];
169
+ case 17:
170
+ try {
171
+ if (_d && !_d.done && (_g = _c["return"])) _g.call(_c);
172
+ }
173
+ finally { if (e_2) throw e_2.error; }
174
+ return [7 /*endfinally*/];
175
+ case 18: return [3 /*break*/, 21];
176
+ case 19: return [4 /*yield*/, EIP712SendStructImplem(transport, {
177
+ structType: "field",
178
+ value: {
179
+ data: data,
180
+ type: (typeDescription === null || typeDescription === void 0 ? void 0 : typeDescription.name) || "",
181
+ sizeInBits: typeDescription === null || typeDescription === void 0 ? void 0 : typeDescription.bits
182
+ }
183
+ })];
184
+ case 20:
185
+ _j.sent();
186
+ _j.label = 21;
187
+ case 21: return [2 /*return*/];
188
+ }
189
+ });
190
+ }); };
191
+ return recursiveFieldStructImplem;
192
+ };
193
+ /**
194
+ * @ignore for the README
195
+ *
196
+ * This method is used to send the message definition with all its types.
197
+ * This method should be used before the EIP712SendStructImplem one
198
+ *
199
+ * @param {String} structType
200
+ * @param {String|Buffer} value
201
+ * @returns {Promise<void>}
202
+ */
203
+ var EIP712SendStructDef = function (transport, structDef) {
204
+ var APDU_FIELDS;
205
+ (function (APDU_FIELDS) {
206
+ APDU_FIELDS[APDU_FIELDS["CLA"] = 224] = "CLA";
207
+ APDU_FIELDS[APDU_FIELDS["INS"] = 26] = "INS";
208
+ APDU_FIELDS[APDU_FIELDS["P1_complete"] = 0] = "P1_complete";
209
+ APDU_FIELDS[APDU_FIELDS["P1_partial"] = 1] = "P1_partial";
210
+ APDU_FIELDS[APDU_FIELDS["P2_name"] = 0] = "P2_name";
211
+ APDU_FIELDS[APDU_FIELDS["P2_field"] = 255] = "P2_field";
212
+ })(APDU_FIELDS || (APDU_FIELDS = {}));
213
+ var structType = structDef.structType, value = structDef.value;
214
+ var data = structType === "name" && typeof value === "string"
215
+ ? Buffer.from(value, "utf-8")
216
+ : value;
217
+ return transport.send(APDU_FIELDS.CLA, APDU_FIELDS.INS, APDU_FIELDS.P1_complete, structType === "name" ? APDU_FIELDS.P2_name : APDU_FIELDS.P2_field, data);
218
+ };
219
+ /**
220
+ * @ignore for the README
221
+ *
222
+ * This method provides a trusted new display name to use for the upcoming field.
223
+ * This method should be used after the EIP712SendStructDef one.
224
+ *
225
+ * If the method describes an empty name (length of 0), the upcoming field will be taken
226
+ * into account but won’t be shown on the device.
227
+ *
228
+ * The signature is computed on :
229
+ * json key length || json key || display name length || display name
230
+ *
231
+ * signed by the following secp256k1 public key:
232
+ * 0482bbf2f34f367b2e5bc21847b6566f21f0976b22d3388a9a5e446ac62d25cf725b62a2555b2dd464a4da0ab2f4d506820543af1d242470b1b1a969a27578f353
233
+ *
234
+ * @param {String} structType "root" | "array" | "field"
235
+ * @param {string | number | StructFieldData} value
236
+ * @returns {Promise<Buffer | void>}
237
+ */
238
+ var EIP712SendStructImplem = function (transport, structImplem) { return __awaiter(void 0, void 0, void 0, function () {
239
+ var APDU_FIELDS, structType, value, rawData, type, sizeInBits, encodedData, dataLengthPer16Bits, dataLengthModulo16Bits, data_2, bufferSlices, bufferSlices_1, bufferSlices_1_1, bufferSlice, e_3_1;
240
+ var e_3, _a;
241
+ var _b;
242
+ return __generator(this, function (_c) {
243
+ switch (_c.label) {
244
+ case 0:
245
+ (function (APDU_FIELDS) {
246
+ APDU_FIELDS[APDU_FIELDS["CLA"] = 224] = "CLA";
247
+ APDU_FIELDS[APDU_FIELDS["INS"] = 28] = "INS";
248
+ APDU_FIELDS[APDU_FIELDS["P1_complete"] = 0] = "P1_complete";
249
+ APDU_FIELDS[APDU_FIELDS["P1_partial"] = 1] = "P1_partial";
250
+ APDU_FIELDS[APDU_FIELDS["P2_root"] = 0] = "P2_root";
251
+ APDU_FIELDS[APDU_FIELDS["P2_array"] = 15] = "P2_array";
252
+ APDU_FIELDS[APDU_FIELDS["P2_field"] = 255] = "P2_field";
253
+ })(APDU_FIELDS || (APDU_FIELDS = {}));
254
+ structType = structImplem.structType, value = structImplem.value;
255
+ if (structType === "root") {
256
+ return [2 /*return*/, transport.send(APDU_FIELDS.CLA, APDU_FIELDS.INS, APDU_FIELDS.P1_complete, APDU_FIELDS.P2_root, Buffer.from(value, "utf-8"))];
257
+ }
258
+ if (structType === "array") {
259
+ return [2 /*return*/, transport.send(APDU_FIELDS.CLA, APDU_FIELDS.INS, APDU_FIELDS.P1_complete, APDU_FIELDS.P2_array, Buffer.from((0, utils_1.intAsHexBytes)(value, 1), "hex"))];
260
+ }
261
+ if (!(structType === "field")) return [3 /*break*/, 8];
262
+ rawData = value.data, type = value.type, sizeInBits = value.sizeInBits;
263
+ encodedData = (_b = EIP712_utils_1.EIP712_TYPE_ENCODERS[type.toUpperCase()]) === null || _b === void 0 ? void 0 : _b.call(EIP712_utils_1.EIP712_TYPE_ENCODERS, rawData, sizeInBits);
264
+ if (!encodedData) return [3 /*break*/, 8];
265
+ dataLengthPer16Bits = Math.floor(encodedData.length / 256);
266
+ dataLengthModulo16Bits = encodedData.length % 256;
267
+ data_2 = Buffer.concat([
268
+ Buffer.from((0, utils_1.intAsHexBytes)(dataLengthPer16Bits, 1), "hex"),
269
+ Buffer.from((0, utils_1.intAsHexBytes)(dataLengthModulo16Bits, 1), "hex"),
270
+ encodedData,
271
+ ]);
272
+ bufferSlices = new Array(Math.ceil(data_2.length / 256))
273
+ .fill(null)
274
+ .map(function (_, i) { return data_2.slice(i * 255, (i + 1) * 255); });
275
+ _c.label = 1;
276
+ case 1:
277
+ _c.trys.push([1, 6, 7, 8]);
278
+ bufferSlices_1 = __values(bufferSlices), bufferSlices_1_1 = bufferSlices_1.next();
279
+ _c.label = 2;
280
+ case 2:
281
+ if (!!bufferSlices_1_1.done) return [3 /*break*/, 5];
282
+ bufferSlice = bufferSlices_1_1.value;
283
+ return [4 /*yield*/, transport.send(APDU_FIELDS.CLA, APDU_FIELDS.INS, bufferSlice !== bufferSlices[bufferSlices.length - 1]
284
+ ? APDU_FIELDS.P1_partial
285
+ : APDU_FIELDS.P1_complete, APDU_FIELDS.P2_field, bufferSlice)];
286
+ case 3:
287
+ _c.sent();
288
+ _c.label = 4;
289
+ case 4:
290
+ bufferSlices_1_1 = bufferSlices_1.next();
291
+ return [3 /*break*/, 2];
292
+ case 5: return [3 /*break*/, 8];
293
+ case 6:
294
+ e_3_1 = _c.sent();
295
+ e_3 = { error: e_3_1 };
296
+ return [3 /*break*/, 8];
297
+ case 7:
298
+ try {
299
+ if (bufferSlices_1_1 && !bufferSlices_1_1.done && (_a = bufferSlices_1["return"])) _a.call(bufferSlices_1);
300
+ }
301
+ finally { if (e_3) throw e_3.error; }
302
+ return [7 /*endfinally*/];
303
+ case 8: return [2 /*return*/, Promise.resolve()];
304
+ }
305
+ });
306
+ }); };
307
+ /**
308
+ * @ignore for the README
309
+ *
310
+ * Sign an EIP-721 formatted message following the specification here:
311
+ * https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.asc#sign-eth-eip-712
312
+ * @example
313
+ eth.signEIP721Message("44'/60'/0'/0/0", {
314
+ domain: {
315
+ chainId: 69,
316
+ name: "Da Domain",
317
+ verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
318
+ version: "1"
319
+ },
320
+ types: {
321
+ "EIP712Domain": [
322
+ { name: "name", type: "string" },
323
+ { name: "version", type: "string" },
324
+ { name: "chainId", type: "uint256" },
325
+ { name: "verifyingContract", type: "address" }
326
+ ],
327
+ "Test": [
328
+ { name: "contents", type: "string" }
329
+ ]
330
+ },
331
+ primaryType: "Test",
332
+ message: {contents: "Hello, Bob!"},
333
+ })
334
+ *
335
+ * @param {String} path derivationPath
336
+ * @param {Object} jsonMessage message to sign
337
+ * @param {Boolean} fullImplem use the legacy implementation
338
+ * @returns {Promise}
339
+ */
340
+ var signEIP712Message = function (transport, path, jsonMessage, fullImplem) {
341
+ if (fullImplem === void 0) { fullImplem = false; }
342
+ return __awaiter(void 0, void 0, void 0, function () {
343
+ var APDU_FIELDS, primaryType, types, domain, message, typeEntries, typeEntries_1, typeEntries_1_1, _a, typeName, entries, entries_1, entries_1_1, _b, name_1, type, typeEntryBuffer, e_4_1, e_5_1, recursiveFieldStructImplem, domainName, domainTypeFields, domainTypeFields_1, domainTypeFields_1_1, _c, name_2, type, domainFieldValue, e_6_1, primaryTypeFields, primaryTypeFields_1, primaryTypeFields_1_1, _d, name_3, type, primaryTypeValue, e_7_1, paths, signatureBuffer;
344
+ var e_5, _e, e_4, _f, e_6, _g, e_7, _h;
345
+ return __generator(this, function (_j) {
346
+ switch (_j.label) {
347
+ case 0:
348
+ (function (APDU_FIELDS) {
349
+ APDU_FIELDS[APDU_FIELDS["CLA"] = 224] = "CLA";
350
+ APDU_FIELDS[APDU_FIELDS["INS"] = 12] = "INS";
351
+ APDU_FIELDS[APDU_FIELDS["P1"] = 0] = "P1";
352
+ APDU_FIELDS[APDU_FIELDS["P2_v0"] = 0] = "P2_v0";
353
+ APDU_FIELDS[APDU_FIELDS["P2_full"] = 1] = "P2_full";
354
+ })(APDU_FIELDS || (APDU_FIELDS = {}));
355
+ primaryType = jsonMessage.primaryType, types = jsonMessage.types, domain = jsonMessage.domain, message = jsonMessage.message;
356
+ typeEntries = Object.entries(types);
357
+ _j.label = 1;
358
+ case 1:
359
+ _j.trys.push([1, 13, 14, 15]);
360
+ typeEntries_1 = __values(typeEntries), typeEntries_1_1 = typeEntries_1.next();
361
+ _j.label = 2;
362
+ case 2:
363
+ if (!!typeEntries_1_1.done) return [3 /*break*/, 12];
364
+ _a = __read(typeEntries_1_1.value, 2), typeName = _a[0], entries = _a[1];
365
+ return [4 /*yield*/, EIP712SendStructDef(transport, {
366
+ structType: "name",
367
+ value: typeName
368
+ })];
369
+ case 3:
370
+ _j.sent();
371
+ _j.label = 4;
372
+ case 4:
373
+ _j.trys.push([4, 9, 10, 11]);
374
+ entries_1 = (e_4 = void 0, __values(entries)), entries_1_1 = entries_1.next();
375
+ _j.label = 5;
376
+ case 5:
377
+ if (!!entries_1_1.done) return [3 /*break*/, 8];
378
+ _b = entries_1_1.value, name_1 = _b.name, type = _b.type;
379
+ typeEntryBuffer = (0, EIP712_utils_1.makeTypeEntryStructBuffer)({ name: name_1, type: type });
380
+ return [4 /*yield*/, EIP712SendStructDef(transport, {
381
+ structType: "field",
382
+ value: typeEntryBuffer
383
+ })];
384
+ case 6:
385
+ _j.sent();
386
+ _j.label = 7;
387
+ case 7:
388
+ entries_1_1 = entries_1.next();
389
+ return [3 /*break*/, 5];
390
+ case 8: return [3 /*break*/, 11];
391
+ case 9:
392
+ e_4_1 = _j.sent();
393
+ e_4 = { error: e_4_1 };
394
+ return [3 /*break*/, 11];
395
+ case 10:
396
+ try {
397
+ if (entries_1_1 && !entries_1_1.done && (_f = entries_1["return"])) _f.call(entries_1);
398
+ }
399
+ finally { if (e_4) throw e_4.error; }
400
+ return [7 /*endfinally*/];
401
+ case 11:
402
+ typeEntries_1_1 = typeEntries_1.next();
403
+ return [3 /*break*/, 2];
404
+ case 12: return [3 /*break*/, 15];
405
+ case 13:
406
+ e_5_1 = _j.sent();
407
+ e_5 = { error: e_5_1 };
408
+ return [3 /*break*/, 15];
409
+ case 14:
410
+ try {
411
+ if (typeEntries_1_1 && !typeEntries_1_1.done && (_e = typeEntries_1["return"])) _e.call(typeEntries_1);
412
+ }
413
+ finally { if (e_5) throw e_5.error; }
414
+ return [7 /*endfinally*/];
415
+ case 15:
416
+ recursiveFieldStructImplem = makeRecursiveFieldStructImplem(transport, types);
417
+ domainName = "EIP712Domain";
418
+ return [4 /*yield*/, EIP712SendStructImplem(transport, {
419
+ structType: "root",
420
+ value: domainName
421
+ })];
422
+ case 16:
423
+ _j.sent();
424
+ domainTypeFields = types[domainName];
425
+ _j.label = 17;
426
+ case 17:
427
+ _j.trys.push([17, 22, 23, 24]);
428
+ domainTypeFields_1 = __values(domainTypeFields), domainTypeFields_1_1 = domainTypeFields_1.next();
429
+ _j.label = 18;
430
+ case 18:
431
+ if (!!domainTypeFields_1_1.done) return [3 /*break*/, 21];
432
+ _c = domainTypeFields_1_1.value, name_2 = _c.name, type = _c.type;
433
+ domainFieldValue = domain[name_2];
434
+ return [4 /*yield*/, recursiveFieldStructImplem((0, EIP712_utils_1.destructTypeFromString)(type), domainFieldValue)];
435
+ case 19:
436
+ _j.sent();
437
+ _j.label = 20;
438
+ case 20:
439
+ domainTypeFields_1_1 = domainTypeFields_1.next();
440
+ return [3 /*break*/, 18];
441
+ case 21: return [3 /*break*/, 24];
442
+ case 22:
443
+ e_6_1 = _j.sent();
444
+ e_6 = { error: e_6_1 };
445
+ return [3 /*break*/, 24];
446
+ case 23:
447
+ try {
448
+ if (domainTypeFields_1_1 && !domainTypeFields_1_1.done && (_g = domainTypeFields_1["return"])) _g.call(domainTypeFields_1);
449
+ }
450
+ finally { if (e_6) throw e_6.error; }
451
+ return [7 /*endfinally*/];
452
+ case 24:
453
+ // Looping on all primaryType type entries and fields to send
454
+ // structures' implementations
455
+ return [4 /*yield*/, EIP712SendStructImplem(transport, {
456
+ structType: "root",
457
+ value: primaryType
458
+ })];
459
+ case 25:
460
+ // Looping on all primaryType type entries and fields to send
461
+ // structures' implementations
462
+ _j.sent();
463
+ primaryTypeFields = types[primaryType];
464
+ _j.label = 26;
465
+ case 26:
466
+ _j.trys.push([26, 31, 32, 33]);
467
+ primaryTypeFields_1 = __values(primaryTypeFields), primaryTypeFields_1_1 = primaryTypeFields_1.next();
468
+ _j.label = 27;
469
+ case 27:
470
+ if (!!primaryTypeFields_1_1.done) return [3 /*break*/, 30];
471
+ _d = primaryTypeFields_1_1.value, name_3 = _d.name, type = _d.type;
472
+ primaryTypeValue = message[name_3];
473
+ return [4 /*yield*/, recursiveFieldStructImplem((0, EIP712_utils_1.destructTypeFromString)(type), primaryTypeValue)];
474
+ case 28:
475
+ _j.sent();
476
+ _j.label = 29;
477
+ case 29:
478
+ primaryTypeFields_1_1 = primaryTypeFields_1.next();
479
+ return [3 /*break*/, 27];
480
+ case 30: return [3 /*break*/, 33];
481
+ case 31:
482
+ e_7_1 = _j.sent();
483
+ e_7 = { error: e_7_1 };
484
+ return [3 /*break*/, 33];
485
+ case 32:
486
+ try {
487
+ if (primaryTypeFields_1_1 && !primaryTypeFields_1_1.done && (_h = primaryTypeFields_1["return"])) _h.call(primaryTypeFields_1);
488
+ }
489
+ finally { if (e_7) throw e_7.error; }
490
+ return [7 /*endfinally*/];
491
+ case 33:
492
+ paths = (0, utils_1.splitPath)(path);
493
+ signatureBuffer = Buffer.alloc(1 + paths.length * 4);
494
+ signatureBuffer[0] = paths.length;
495
+ paths.forEach(function (element, index) {
496
+ signatureBuffer.writeUInt32BE(element, 1 + 4 * index);
497
+ });
498
+ return [2 /*return*/, transport
499
+ .send(APDU_FIELDS.CLA, APDU_FIELDS.INS, APDU_FIELDS.P1, fullImplem ? APDU_FIELDS.P2_v0 : APDU_FIELDS.P2_full, signatureBuffer)
500
+ .then(function (response) {
501
+ var v = response[0];
502
+ var r = response.slice(1, 1 + 32).toString("hex");
503
+ var s = response.slice(1 + 32, 1 + 32 + 32).toString("hex");
504
+ return {
505
+ v: v,
506
+ r: r,
507
+ s: s
508
+ };
509
+ })];
510
+ }
511
+ });
512
+ });
513
+ };
514
+ exports.signEIP712Message = signEIP712Message;
515
+ /**
516
+ * @ignore for the README
517
+ * Sign a prepared message following web3.eth.signTypedData specification. The host computes the domain separator and hashStruct(message)
518
+ * @example
519
+ eth.signEIP712HashedMessage("44'/60'/0'/0/0", Buffer.from("0101010101010101010101010101010101010101010101010101010101010101").toString("hex"), Buffer.from("0202020202020202020202020202020202020202020202020202020202020202").toString("hex")).then(result => {
520
+ var v = result['v'] - 27;
521
+ v = v.toString(16);
522
+ if (v.length < 2) {
523
+ v = "0" + v;
524
+ }
525
+ console.log("Signature 0x" + result['r'] + result['s'] + v);
526
+ })
527
+ */
528
+ var signEIP712HashedMessage = function (transport, path, domainSeparatorHex, hashStructMessageHex) {
529
+ var domainSeparator = (0, utils_1.hexBuffer)(domainSeparatorHex);
530
+ var hashStruct = (0, utils_1.hexBuffer)(hashStructMessageHex);
531
+ var paths = (0, utils_1.splitPath)(path);
532
+ var buffer = Buffer.alloc(1 + paths.length * 4 + 32 + 32, 0);
533
+ var offset = 0;
534
+ buffer[0] = paths.length;
535
+ paths.forEach(function (element, index) {
536
+ buffer.writeUInt32BE(element, 1 + 4 * index);
537
+ });
538
+ offset = 1 + 4 * paths.length;
539
+ domainSeparator.copy(buffer, offset);
540
+ offset += 32;
541
+ hashStruct.copy(buffer, offset);
542
+ return transport.send(0xe0, 0x0c, 0x00, 0x00, buffer).then(function (response) {
543
+ var v = response[0];
544
+ var r = response.slice(1, 1 + 32).toString("hex");
545
+ var s = response.slice(1 + 32, 1 + 32 + 32).toString("hex");
546
+ return {
547
+ v: v,
548
+ r: r,
549
+ s: s
550
+ };
551
+ });
552
+ };
553
+ exports.signEIP712HashedMessage = signEIP712HashedMessage;
554
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../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AAC;QAC9D,OAAO;YACL,CAAC,GAAA;YACD,CAAC,GAAA;YACD,CAAC,GAAA;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAlCW,QAAA,uBAAuB,2BAkClC"}
package/lib/utils.d.ts CHANGED
@@ -1,10 +1,24 @@
1
1
  /// <reference types="node" />
2
2
  import { BigNumber } from "bignumber.js";
3
- export declare function decodeTxInfo(rawTx: Buffer): {
3
+ export declare function splitPath(path: string): number[];
4
+ export declare function hexBuffer(str: string): Buffer;
5
+ export declare function maybeHexBuffer(str: string | null | undefined): Buffer | null | undefined;
6
+ export declare const decodeTxInfo: (rawTx: Buffer) => {
4
7
  decodedTx: any;
5
8
  txType: number | null;
6
9
  chainId: BigNumber;
7
10
  chainIdTruncated: number;
8
11
  vrsOffset: number;
9
12
  };
13
+ /**
14
+ * @ignore for the README
15
+ *
16
+ * Helper to convert an integer as a hexadecimal string with the right amount of digits
17
+ * to respect the number of bytes given as parameter
18
+ *
19
+ * @param int Integer
20
+ * @param bytes Number of bytes it should be represented as (1 byte = 2 caraters)
21
+ * @returns The given integer as an hexa string padded with the right number of 0
22
+ */
23
+ export declare const intAsHexBytes: (int: number, bytes: number) => string;
10
24
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM;;;;;;EAyEzC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAchD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC7B,MAAM,GAAG,IAAI,GAAG,SAAS,CAG3B;AAED,eAAO,MAAM,YAAY,UAAW,MAAM;;;;;;CAyEzC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,QAAS,MAAM,SAAS,MAAM,KAAG,MAChB,CAAC"}
package/lib/utils.js CHANGED
@@ -1,9 +1,35 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
- exports.decodeTxInfo = void 0;
3
+ exports.intAsHexBytes = exports.decodeTxInfo = exports.maybeHexBuffer = exports.hexBuffer = exports.splitPath = void 0;
4
4
  var rlp_1 = require("@ethersproject/rlp");
5
5
  var bignumber_js_1 = require("bignumber.js");
6
- function decodeTxInfo(rawTx) {
6
+ function splitPath(path) {
7
+ var result = [];
8
+ var components = path.split("/");
9
+ components.forEach(function (element) {
10
+ var number = parseInt(element, 10);
11
+ if (isNaN(number)) {
12
+ return; // FIXME shouldn't it throws instead?
13
+ }
14
+ if (element.length > 1 && element[element.length - 1] === "'") {
15
+ number += 0x80000000;
16
+ }
17
+ result.push(number);
18
+ });
19
+ return result;
20
+ }
21
+ exports.splitPath = splitPath;
22
+ function hexBuffer(str) {
23
+ return Buffer.from(str.startsWith("0x") ? str.slice(2) : str, "hex");
24
+ }
25
+ exports.hexBuffer = hexBuffer;
26
+ function maybeHexBuffer(str) {
27
+ if (!str)
28
+ return null;
29
+ return hexBuffer(str);
30
+ }
31
+ exports.maybeHexBuffer = maybeHexBuffer;
32
+ var decodeTxInfo = function (rawTx) {
7
33
  var VALID_TYPES = [1, 2];
8
34
  var txType = VALID_TYPES.includes(rawTx[0]) ? rawTx[0] : null;
9
35
  var rlpData = txType === null ? rawTx : rawTx.slice(1);
@@ -71,6 +97,20 @@ function decodeTxInfo(rawTx) {
71
97
  chainIdTruncated: chainIdTruncated,
72
98
  vrsOffset: vrsOffset
73
99
  };
74
- }
100
+ };
75
101
  exports.decodeTxInfo = decodeTxInfo;
102
+ /**
103
+ * @ignore for the README
104
+ *
105
+ * Helper to convert an integer as a hexadecimal string with the right amount of digits
106
+ * to respect the number of bytes given as parameter
107
+ *
108
+ * @param int Integer
109
+ * @param bytes Number of bytes it should be represented as (1 byte = 2 caraters)
110
+ * @returns The given integer as an hexa string padded with the right number of 0
111
+ */
112
+ var intAsHexBytes = function (int, bytes) {
113
+ return int.toString(16).padStart(2 * bytes, "0");
114
+ };
115
+ exports.intAsHexBytes = intAsHexBytes;
76
116
  //# sourceMappingURL=utils.js.map