@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,760 @@
1
+ import path from "path";
2
+ import fs from "fs/promises";
3
+ import {
4
+ openTransportReplayer,
5
+ RecordStore,
6
+ } from "@ledgerhq/hw-transport-mocker";
7
+ import Eth from "../src/Eth";
8
+ import {
9
+ constructTypeDescByteString,
10
+ destructTypeFromString,
11
+ EIP712_TYPE_ENCODERS,
12
+ makeTypeEntryStructBuffer,
13
+ } from "../src/modules/EIP712/EIP712.utils";
14
+
15
+ const getFilePath = (filename: string): string =>
16
+ path.resolve(`./tests/sample-messages/${filename}`);
17
+
18
+ describe("EIP712", () => {
19
+ describe("Utils", () => {
20
+ describe("destructTypeFromString", () => {
21
+ test("'string[]' should return [{name: 'string', bits: undefined}, [null]]", () => {
22
+ expect(destructTypeFromString("string[]")).toEqual([
23
+ { name: "string", bits: undefined },
24
+ [null],
25
+ ]);
26
+ });
27
+
28
+ test("'uint8[2][][4]' should return [{name: 'uint', bits: 8}, [2, null, 4]]", () => {
29
+ expect(destructTypeFromString("uint8[2][][4]")).toEqual([
30
+ { name: "uint", bits: 8 },
31
+ [2, null, 4],
32
+ ]);
33
+ });
34
+
35
+ test("'bytes64' should return [{ name: 'bytes', bits: 64 }, []]", () => {
36
+ expect(destructTypeFromString("bytes64")).toEqual([
37
+ { name: "bytes", bits: 64 },
38
+ [],
39
+ ]);
40
+ });
41
+
42
+ test("'bool' should return [{ name: 'bool', bits: undefined }, []]", () => {
43
+ expect(destructTypeFromString("bool")).toEqual([
44
+ { name: "bool", bits: undefined },
45
+ [],
46
+ ]);
47
+ });
48
+
49
+ test("'bool[any]' should not throw and return ['bool', []]", () => {
50
+ expect(destructTypeFromString("bool[any]")).toEqual([
51
+ { name: "bool", bits: undefined },
52
+ [],
53
+ ]);
54
+ });
55
+
56
+ test("should not throw with undefined", () => {
57
+ expect(destructTypeFromString(undefined)).toEqual([null, []]);
58
+ });
59
+ });
60
+
61
+ describe("constructTypeDescByteString", () => {
62
+ const bitwiseImplem = (
63
+ isArray: boolean,
64
+ typeSize: number | null,
65
+ typeValue
66
+ ) =>
67
+ (Number(isArray) << 7) | (Number(typeSize !== null) << 6) | typeValue;
68
+
69
+ test("should return 1 as hex int and 01 as hexa string", () => {
70
+ expect(
71
+ parseInt(constructTypeDescByteString(false, null, 1), 16)
72
+ ).toEqual(1);
73
+ expect(constructTypeDescByteString(false, null, 1)).toEqual("01");
74
+ });
75
+
76
+ test("should return 129 as hex int and 81 as hexa string", () => {
77
+ expect(
78
+ parseInt(constructTypeDescByteString(true, null, 1), 16)
79
+ ).toEqual(129);
80
+ expect(constructTypeDescByteString(true, null, 1)).toEqual("81");
81
+ });
82
+
83
+ test("should return 193 as hex int and c1 as hexa string", () => {
84
+ expect(parseInt(constructTypeDescByteString(true, 64, 1), 16)).toEqual(
85
+ 193
86
+ );
87
+ expect(constructTypeDescByteString(true, 64, 1)).toEqual("c1");
88
+ });
89
+
90
+ test("should return 207 as hex int and cf as hexa string", () => {
91
+ expect(parseInt(constructTypeDescByteString(true, 64, 15), 16)).toEqual(
92
+ 207
93
+ );
94
+ expect(constructTypeDescByteString(true, 64, 15)).toEqual("cf");
95
+ });
96
+
97
+ test("should return 143 as hex int and 8f as hexa string", () => {
98
+ expect(
99
+ parseInt(constructTypeDescByteString(true, null, 15), 16)
100
+ ).toEqual(143);
101
+ expect(constructTypeDescByteString(true, null, 15)).toEqual("8f");
102
+ });
103
+
104
+ test("should return 15 as hex int and ", () => {
105
+ expect(
106
+ parseInt(constructTypeDescByteString(false, null, 15), 16)
107
+ ).toEqual(15);
108
+ expect(constructTypeDescByteString(false, null, 15)).toEqual("0f");
109
+ });
110
+
111
+ test("should throw if typeValue >= 16", () => {
112
+ expect(() => constructTypeDescByteString(false, null, 16)).toThrow();
113
+ });
114
+
115
+ test("should return the same as the bitewise implementation", () => {
116
+ expect(
117
+ parseInt(constructTypeDescByteString(false, null, 1), 16)
118
+ ).toEqual(bitwiseImplem(false, null, 1));
119
+
120
+ expect(
121
+ parseInt(constructTypeDescByteString(true, null, 1), 16)
122
+ ).toEqual(bitwiseImplem(true, null, 1));
123
+
124
+ expect(parseInt(constructTypeDescByteString(true, 64, 1), 16)).toEqual(
125
+ bitwiseImplem(true, 64, 1)
126
+ );
127
+
128
+ expect(parseInt(constructTypeDescByteString(true, 64, 15), 16)).toEqual(
129
+ bitwiseImplem(true, 64, 15)
130
+ );
131
+
132
+ expect(
133
+ parseInt(constructTypeDescByteString(true, null, 15), 16)
134
+ ).toEqual(bitwiseImplem(true, null, 15));
135
+
136
+ expect(
137
+ parseInt(constructTypeDescByteString(false, null, 15), 16)
138
+ ).toEqual(bitwiseImplem(false, null, 15));
139
+ });
140
+ });
141
+
142
+ describe("makeTypeEntryStructBuffer", () => {
143
+ test("should return the correct buffer for entry type `int`", () => {
144
+ expect(
145
+ makeTypeEntryStructBuffer({
146
+ name: "nameForInt",
147
+ type: "int",
148
+ }).toString("hex")
149
+ ).toEqual("410a6e616d65466f72496e74");
150
+ });
151
+
152
+ test("should return the correct buffer for entry type `int8`", () => {
153
+ expect(
154
+ makeTypeEntryStructBuffer({
155
+ name: "nameForInt",
156
+ type: "int8",
157
+ }).toString("hex")
158
+ ).toEqual("41010a6e616d65466f72496e74");
159
+ });
160
+
161
+ test("should return the correct buffer for entry type `uint`", () => {
162
+ expect(
163
+ makeTypeEntryStructBuffer({
164
+ name: "nameForUint",
165
+ type: "uint",
166
+ }).toString("hex")
167
+ ).toEqual("420b6e616d65466f7255696e74");
168
+ });
169
+
170
+ test("should return the correct buffer for entry type `uint64`", () => {
171
+ expect(
172
+ makeTypeEntryStructBuffer({
173
+ name: "nameForUint",
174
+ type: "uint64",
175
+ }).toString("hex")
176
+ ).toEqual("42080b6e616d65466f7255696e74");
177
+ });
178
+
179
+ test("should return the correct buffer for entry type `address`", () => {
180
+ expect(
181
+ makeTypeEntryStructBuffer({
182
+ name: "nameForAddress",
183
+ type: "address",
184
+ }).toString("hex")
185
+ ).toEqual("030e6e616d65466f7241646472657373");
186
+ });
187
+
188
+ test("should return the correct buffer for entry type `bool`", () => {
189
+ expect(
190
+ makeTypeEntryStructBuffer({
191
+ name: "nameForBool",
192
+ type: "bool",
193
+ }).toString("hex")
194
+ ).toEqual("040b6e616d65466f72426f6f6c");
195
+ });
196
+
197
+ test("should return the correct buffer for entry type `string`", () => {
198
+ expect(
199
+ makeTypeEntryStructBuffer({
200
+ name: "nameForString",
201
+ type: "string",
202
+ }).toString("hex")
203
+ ).toEqual("050d6e616d65466f72537472696e67");
204
+ });
205
+
206
+ test("should return the correct buffer for entry type `string[3][]`", () => {
207
+ expect(
208
+ makeTypeEntryStructBuffer({
209
+ name: "document",
210
+ type: "string[3][]",
211
+ }).toString("hex")
212
+ ).toEqual("850201030008646f63756d656e74");
213
+ });
214
+
215
+ test("should return the correct buffer for entry type `bytes`", () => {
216
+ expect(
217
+ makeTypeEntryStructBuffer({
218
+ name: "nameForBytes",
219
+ type: "bytes",
220
+ }).toString("hex")
221
+ ).toEqual("070c6e616d65466f724279746573");
222
+ });
223
+
224
+ test("should return the correct buffer for entry type `bytes32`", () => {
225
+ expect(
226
+ makeTypeEntryStructBuffer({
227
+ name: "nameForBytes",
228
+ type: "bytes32",
229
+ }).toString("hex")
230
+ ).toEqual("46200c6e616d65466f724279746573");
231
+ });
232
+
233
+ test("should return the correct buffer for entry type `bytes32[4]`", () => {
234
+ expect(
235
+ makeTypeEntryStructBuffer({
236
+ name: "nameForBytes",
237
+ type: "bytes32[4]",
238
+ }).toString("hex")
239
+ ).toEqual("c6200101040c6e616d65466f724279746573");
240
+ });
241
+
242
+ test("should return the correct buffer for entry type `bytes32[4][]`", () => {
243
+ expect(
244
+ makeTypeEntryStructBuffer({
245
+ name: "nameForBytes",
246
+ type: "bytes32[4][]",
247
+ }).toString("hex")
248
+ ).toEqual("c620020104000c6e616d65466f724279746573");
249
+ });
250
+ test("should return the correct buffer for entry type `bytes32[4][][256]`", () => {
251
+ expect(
252
+ makeTypeEntryStructBuffer({
253
+ name: "nameForBytes",
254
+ type: "bytes32[4][][256]",
255
+ }).toString("hex")
256
+ ).toEqual("c6200301040001100c6e616d65466f724279746573");
257
+ });
258
+ });
259
+
260
+ describe("EIP712_TYPE_ENCODERS", () => {
261
+ describe("INT", () => {
262
+ describe("from string", () => {
263
+ test("should return 00", () => {
264
+ expect(EIP712_TYPE_ENCODERS.INT("0").toString("hex")).toEqual("00");
265
+ });
266
+ test("should return 01", () => {
267
+ expect(EIP712_TYPE_ENCODERS.INT("1").toString("hex")).toEqual("01");
268
+ });
269
+ test("should return 0a", () => {
270
+ expect(EIP712_TYPE_ENCODERS.INT("10").toString("hex")).toEqual(
271
+ "0a"
272
+ );
273
+ });
274
+ test("should return 64", () => {
275
+ expect(EIP712_TYPE_ENCODERS.INT("100").toString("hex")).toEqual(
276
+ "64"
277
+ );
278
+ });
279
+ test("should return 0101", () => {
280
+ expect(EIP712_TYPE_ENCODERS.INT("257").toString("hex")).toEqual(
281
+ "0101"
282
+ );
283
+ });
284
+ });
285
+
286
+ describe("from number", () => {
287
+ test("should return 00", () => {
288
+ expect(EIP712_TYPE_ENCODERS.INT(0).toString("hex")).toEqual("00");
289
+ });
290
+ test("should return 01", () => {
291
+ expect(EIP712_TYPE_ENCODERS.INT(1).toString("hex")).toEqual("01");
292
+ });
293
+ test("should return 0a", () => {
294
+ expect(EIP712_TYPE_ENCODERS.INT(10).toString("hex")).toEqual("0a");
295
+ });
296
+ test("should return 64", () => {
297
+ expect(EIP712_TYPE_ENCODERS.INT(100).toString("hex")).toEqual("64");
298
+ });
299
+ test("should return 0101", () => {
300
+ expect(EIP712_TYPE_ENCODERS.INT(257).toString("hex")).toEqual(
301
+ "0101"
302
+ );
303
+ });
304
+ });
305
+
306
+ describe("from hex", () => {
307
+ test("should return 00", () => {
308
+ expect(EIP712_TYPE_ENCODERS.INT("0x00").toString("hex")).toEqual(
309
+ "00"
310
+ );
311
+ });
312
+ test("should return 01", () => {
313
+ expect(EIP712_TYPE_ENCODERS.INT("0x01").toString("hex")).toEqual(
314
+ "01"
315
+ );
316
+ });
317
+ test("should return 0a", () => {
318
+ expect(EIP712_TYPE_ENCODERS.INT("0x0a").toString("hex")).toEqual(
319
+ "0a"
320
+ );
321
+ });
322
+ test("should return 64", () => {
323
+ expect(EIP712_TYPE_ENCODERS.INT("0x64").toString("hex")).toEqual(
324
+ "64"
325
+ );
326
+ });
327
+ test("should return 0101", () => {
328
+ expect(EIP712_TYPE_ENCODERS.INT("0x0101").toString("hex")).toEqual(
329
+ "0101"
330
+ );
331
+ });
332
+ });
333
+ });
334
+
335
+ describe("UINT", () => {
336
+ describe("from string", () => {
337
+ test("should return 00", () => {
338
+ expect(EIP712_TYPE_ENCODERS.UINT("0").toString("hex")).toEqual(
339
+ "00"
340
+ );
341
+ });
342
+ test("should return 01", () => {
343
+ expect(EIP712_TYPE_ENCODERS.UINT("1").toString("hex")).toEqual(
344
+ "01"
345
+ );
346
+ });
347
+ test("should return 0a", () => {
348
+ expect(EIP712_TYPE_ENCODERS.UINT("10").toString("hex")).toEqual(
349
+ "0a"
350
+ );
351
+ });
352
+ test("should return 64", () => {
353
+ expect(EIP712_TYPE_ENCODERS.UINT("100").toString("hex")).toEqual(
354
+ "64"
355
+ );
356
+ });
357
+ test("should return 0101", () => {
358
+ expect(EIP712_TYPE_ENCODERS.UINT("257").toString("hex")).toEqual(
359
+ "0101"
360
+ );
361
+ });
362
+ });
363
+
364
+ describe("from number", () => {
365
+ test("should return 00", () => {
366
+ expect(EIP712_TYPE_ENCODERS.UINT(0).toString("hex")).toEqual("00");
367
+ });
368
+ test("should return 01", () => {
369
+ expect(EIP712_TYPE_ENCODERS.UINT(1).toString("hex")).toEqual("01");
370
+ });
371
+ test("should return 0a", () => {
372
+ expect(EIP712_TYPE_ENCODERS.UINT(10).toString("hex")).toEqual("0a");
373
+ });
374
+ test("should return 64", () => {
375
+ expect(EIP712_TYPE_ENCODERS.UINT(100).toString("hex")).toEqual(
376
+ "64"
377
+ );
378
+ });
379
+ test("should return 0101", () => {
380
+ expect(EIP712_TYPE_ENCODERS.UINT(257).toString("hex")).toEqual(
381
+ "0101"
382
+ );
383
+ });
384
+ });
385
+
386
+ describe("from hex", () => {
387
+ test("should return 00", () => {
388
+ expect(EIP712_TYPE_ENCODERS.UINT("0x00").toString("hex")).toEqual(
389
+ "00"
390
+ );
391
+ });
392
+ test("should return 01", () => {
393
+ expect(EIP712_TYPE_ENCODERS.UINT("0x01").toString("hex")).toEqual(
394
+ "01"
395
+ );
396
+ });
397
+ test("should return 0a", () => {
398
+ expect(EIP712_TYPE_ENCODERS.UINT("0x0a").toString("hex")).toEqual(
399
+ "0a"
400
+ );
401
+ });
402
+ test("should return 64", () => {
403
+ expect(EIP712_TYPE_ENCODERS.UINT("0x64").toString("hex")).toEqual(
404
+ "64"
405
+ );
406
+ });
407
+ test("should return 0101", () => {
408
+ expect(EIP712_TYPE_ENCODERS.UINT("0x0101").toString("hex")).toEqual(
409
+ "0101"
410
+ );
411
+ });
412
+ });
413
+ });
414
+
415
+ describe("BOOL", () => {
416
+ test("should not break from null", () => {
417
+ expect(EIP712_TYPE_ENCODERS.BOOL(null).toString("hex")).toEqual("00");
418
+ });
419
+
420
+ describe("from string", () => {
421
+ test("should return 00", () => {
422
+ expect(EIP712_TYPE_ENCODERS.BOOL("0").toString("hex")).toEqual(
423
+ "00"
424
+ );
425
+ });
426
+
427
+ test("should return 00", () => {
428
+ expect(EIP712_TYPE_ENCODERS.BOOL("0x00").toString("hex")).toEqual(
429
+ "00"
430
+ );
431
+ });
432
+
433
+ test("should return 01", () => {
434
+ expect(EIP712_TYPE_ENCODERS.BOOL("1").toString("hex")).toEqual(
435
+ "01"
436
+ );
437
+ });
438
+
439
+ test("should return 01", () => {
440
+ expect(EIP712_TYPE_ENCODERS.BOOL("0x01").toString("hex")).toEqual(
441
+ "01"
442
+ );
443
+ });
444
+ });
445
+
446
+ describe("from boolean", () => {
447
+ test("should return 00", () => {
448
+ expect(EIP712_TYPE_ENCODERS.BOOL(false).toString("hex")).toEqual(
449
+ "00"
450
+ );
451
+ });
452
+
453
+ test("should return 01", () => {
454
+ expect(EIP712_TYPE_ENCODERS.BOOL(true).toString("hex")).toEqual(
455
+ "01"
456
+ );
457
+ });
458
+ });
459
+
460
+ describe("from number", () => {
461
+ test("should return 00", () => {
462
+ expect(EIP712_TYPE_ENCODERS.BOOL(0).toString("hex")).toEqual("00");
463
+ });
464
+
465
+ test("should return 01", () => {
466
+ expect(EIP712_TYPE_ENCODERS.BOOL(1).toString("hex")).toEqual("01");
467
+ });
468
+ });
469
+ });
470
+
471
+ describe("ADDRESS", () => {
472
+ test("should not break from null", () => {
473
+ expect(EIP712_TYPE_ENCODERS.ADDRESS(null).toString("hex")).toEqual(
474
+ ""
475
+ );
476
+ });
477
+
478
+ test("should return 183c938611642ae18790db0A1eFC21Dfe009aA1c", () => {
479
+ expect(
480
+ EIP712_TYPE_ENCODERS.ADDRESS(
481
+ "0x183c938611642ae18790db0A1eFC21Dfe009aA1c"
482
+ ).toString("hex")
483
+ ).toEqual("183c938611642ae18790db0a1efc21dfe009aa1c");
484
+ });
485
+
486
+ test("should return 03d7be9a073d7ed9ac0ccb2558d7f7c6a43d3c0aa993e00f2c03424fff0a80f3", () => {
487
+ expect(
488
+ EIP712_TYPE_ENCODERS.ADDRESS(
489
+ // Starknet address are longer, yet the address type is supposed to be 20 characters only
490
+ "0x03d7be9a073d7ed9ac0ccb2558d7f7c6a43d3c0aa993e00f2c03424fff0a80f3"
491
+ ).toString("hex")
492
+ ).toEqual("03d7be9a073d7ed9ac0ccb2558d7f7c6a43d3c0a");
493
+ });
494
+ });
495
+
496
+ describe("STRING", () => {
497
+ test("should not break from null", () => {
498
+ expect(EIP712_TYPE_ENCODERS.STRING(null).toString("hex")).toEqual("");
499
+ });
500
+
501
+ test("should not break from empty string", () => {
502
+ expect(EIP712_TYPE_ENCODERS.STRING("").toString("hex")).toEqual("");
503
+ });
504
+
505
+ test("should return 6b766e49734147656e697573", () => {
506
+ expect(
507
+ EIP712_TYPE_ENCODERS.STRING("kvnIsAGenius").toString("hex")
508
+ ).toEqual("6b766e49734147656e697573");
509
+ });
510
+ });
511
+
512
+ describe("BYTES", () => {
513
+ describe("from fixed size bytes", () => {
514
+ test("should not break from null", () => {
515
+ expect(EIP712_TYPE_ENCODERS.BYTES(null).toString("hex")).toEqual(
516
+ ""
517
+ );
518
+ });
519
+
520
+ test("should return 973bb640", () => {
521
+ expect(
522
+ EIP712_TYPE_ENCODERS.BYTES("0x973bb640", 4).toString("hex")
523
+ ).toEqual("973bb640");
524
+ });
525
+ test("should return 973bb640", () => {
526
+ expect(
527
+ EIP712_TYPE_ENCODERS.BYTES(
528
+ "0x000000000000000000000000495f947276749ce646f68ac8c248420045cb7b5ebdf2657ffc1fadfd73cf0a8cde95d50b62d3df8c000000000000070000000032"
529
+ ).toString("hex")
530
+ ).toEqual(
531
+ "000000000000000000000000495f947276749ce646f68ac8c248420045cb7b5ebdf2657ffc1fadfd73cf0a8cde95d50b62d3df8c000000000000070000000032"
532
+ );
533
+ });
534
+ });
535
+ });
536
+ });
537
+ });
538
+
539
+ describe("SignEIP712Message mocked", () => {
540
+ test("should sign correctly the 0.json sample message", async () => {
541
+ const apdusBuffer = await fs.readFile(getFilePath("0.apdus"), "utf-8");
542
+ const message = await fs
543
+ .readFile(getFilePath("0.json"), "utf-8")
544
+ .then(JSON.parse);
545
+
546
+ const transport = await openTransportReplayer(
547
+ RecordStore.fromString(`${apdusBuffer}`)
548
+ );
549
+
550
+ const eth = new Eth(transport);
551
+ const result = await eth.signEIP712Message("44'/60'/0'/0/0", message);
552
+
553
+ expect(result).toEqual({
554
+ r: "8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788",
555
+ s: "64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513",
556
+ v: 28,
557
+ });
558
+ });
559
+
560
+ test("should sign correctly the 1.json sample message", async () => {
561
+ const apdusBuffer = await fs.readFile(getFilePath("1.apdus"), "utf-8");
562
+ const message = await fs
563
+ .readFile(getFilePath("1.json"), "utf-8")
564
+ .then(JSON.parse);
565
+
566
+ const transport = await openTransportReplayer(
567
+ RecordStore.fromString(`${apdusBuffer}`)
568
+ );
569
+
570
+ const eth = new Eth(transport);
571
+ const result = await eth.signEIP712Message("44'/60'/0'/0/0", message);
572
+
573
+ expect(result).toEqual({
574
+ r: "a7cd8fdac8707487908988d6111c2accdcaed9c43d6e993e8760ec8096cb2051",
575
+ s: "394fc2a9b1a5107b28aa601b767a740761920c86797918365ac2460f6444ab98",
576
+ v: 28,
577
+ });
578
+ });
579
+
580
+ test("should sign correctly the 2.json sample message", async () => {
581
+ const apdusBuffer = await fs.readFile(getFilePath("2.apdus"), "utf-8");
582
+ const message = await fs
583
+ .readFile(getFilePath("2.json"), "utf-8")
584
+ .then(JSON.parse);
585
+
586
+ const transport = await openTransportReplayer(
587
+ RecordStore.fromString(`${apdusBuffer}`)
588
+ );
589
+
590
+ const eth = new Eth(transport);
591
+ const result = await eth.signEIP712Message("44'/60'/0'/0/0", message);
592
+
593
+ expect(result).toEqual({
594
+ r: "bee323485a7138784ec593146955255b1290eac0c9959fbe57f01b7e3e8e2dfe",
595
+ s: "5f489023947c1d7cc4a8bba5c96e0717236f635d97c79203f56d57f3727cb5d1",
596
+ v: 28,
597
+ });
598
+ });
599
+
600
+ test("should sign correctly the 3.json sample message", async () => {
601
+ const apdusBuffer = await fs.readFile(getFilePath("3.apdus"), "utf-8");
602
+ const message = await fs
603
+ .readFile(getFilePath("3.json"), "utf-8")
604
+ .then(JSON.parse);
605
+
606
+ const transport = await openTransportReplayer(
607
+ RecordStore.fromString(`${apdusBuffer}`)
608
+ );
609
+
610
+ const eth = new Eth(transport);
611
+ const result = await eth.signEIP712Message("44'/60'/0'/0/0", message);
612
+
613
+ expect(result).toEqual({
614
+ r: "a032f358f76041e239d34a449d859742d79ede0705e294552e68c6f6345cd9a6",
615
+ s: "5d14e1607eca346db7a1b4ded81c8dcc82821a8f2ceb24803b611095cf68d320",
616
+ v: 28,
617
+ });
618
+ });
619
+
620
+ test("should sign correctly the 4.json sample message", async () => {
621
+ const apdusBuffer = await fs.readFile(getFilePath("4.apdus"), "utf-8");
622
+ const message = await fs
623
+ .readFile(getFilePath("4.json"), "utf-8")
624
+ .then(JSON.parse);
625
+
626
+ const transport = await openTransportReplayer(
627
+ RecordStore.fromString(`${apdusBuffer}`)
628
+ );
629
+
630
+ const eth = new Eth(transport);
631
+ const result = await eth.signEIP712Message("44'/60'/0'/0/0", message);
632
+
633
+ expect(result).toEqual({
634
+ r: "cda73aa5e40061499b7faee1f85d6cefc371bb8f38bf407d6ab747aaaf1b047d",
635
+ s: "702f036a1941e85f124f961e44c55fafe44533abd34aea8a5c4dba0df836925f",
636
+ v: 27,
637
+ });
638
+ });
639
+
640
+ test("should sign correctly the 5.json sample message", async () => {
641
+ const apdusBuffer = await fs.readFile(getFilePath("5.apdus"), "utf-8");
642
+ const message = await fs
643
+ .readFile(getFilePath("5.json"), "utf-8")
644
+ .then(JSON.parse);
645
+
646
+ const transport = await openTransportReplayer(
647
+ RecordStore.fromString(`${apdusBuffer}`)
648
+ );
649
+
650
+ const eth = new Eth(transport);
651
+ const result = await eth.signEIP712Message("44'/60'/0'/0/0", message);
652
+
653
+ expect(result).toEqual({
654
+ r: "7b6a345381330b91ee63d05c83ecc2fa1bc7cd5871da3f45341827b09fd44036",
655
+ s: "7660f31b2cae89bc1826fbe153209b059968264b6387936551f2a5d80931490c",
656
+ v: 27,
657
+ });
658
+ });
659
+
660
+ test("should sign correctly the 6.json sample message", async () => {
661
+ const apdusBuffer = await fs.readFile(getFilePath("6.apdus"), "utf-8");
662
+ const message = await fs
663
+ .readFile(getFilePath("6.json"), "utf-8")
664
+ .then(JSON.parse);
665
+
666
+ const transport = await openTransportReplayer(
667
+ RecordStore.fromString(`${apdusBuffer}`)
668
+ );
669
+
670
+ const eth = new Eth(transport);
671
+ const result = await eth.signEIP712Message("44'/60'/0'/0/0", message);
672
+
673
+ expect(result).toEqual({
674
+ r: "ab0071346cd7ab388c7b4fa71d9634f5f3e3445acbe900874b7594890404d14c",
675
+ s: "35a8e8d682652915e9afc0c684fc8d5a5b00e87e43a478dc0d9eb639b43d29f5",
676
+ v: 27,
677
+ });
678
+ });
679
+
680
+ test("should sign correctly the 7.json sample message", async () => {
681
+ const apdusBuffer = await fs.readFile(getFilePath("7.apdus"), "utf-8");
682
+ const message = await fs
683
+ .readFile(getFilePath("7.json"), "utf-8")
684
+ .then(JSON.parse);
685
+
686
+ const transport = await openTransportReplayer(
687
+ RecordStore.fromString(`${apdusBuffer}`)
688
+ );
689
+
690
+ const eth = new Eth(transport);
691
+ const result = await eth.signEIP712Message("44'/60'/0'/0/0", message);
692
+
693
+ expect(result).toEqual({
694
+ r: "5059ff4b6e0e4ccc8f7bcf233da23618a1f0be05b88d70b068dbe187d6b35955",
695
+ s: "06d7d716d3b9b351856d656a7d58e47f8d8922411cc3c68aa9a2d32d1f188f26",
696
+ v: 27,
697
+ });
698
+ });
699
+
700
+ test("should sign correctly the 8.json sample message", async () => {
701
+ const apdusBuffer = await fs.readFile(getFilePath("8.apdus"), "utf-8");
702
+ const message = await fs
703
+ .readFile(getFilePath("8.json"), "utf-8")
704
+ .then(JSON.parse);
705
+
706
+ const transport = await openTransportReplayer(
707
+ RecordStore.fromString(`${apdusBuffer}`)
708
+ );
709
+
710
+ const eth = new Eth(transport);
711
+ const result = await eth.signEIP712Message("44'/60'/0'/0/0", message);
712
+
713
+ expect(result).toEqual({
714
+ r: "d6de64452d9a826ba639b736117d2a91ae04539577cb5a2a2445361ee9158034",
715
+ s: "246339bfeba70f9dc2a9167b0da5169acc598797897d64cee52b3dbb998122cb",
716
+ v: 28,
717
+ });
718
+ });
719
+
720
+ test("should sign correctly the 9.json sample message", async () => {
721
+ const apdusBuffer = await fs.readFile(getFilePath("9.apdus"), "utf-8");
722
+ const message = await fs
723
+ .readFile(getFilePath("9.json"), "utf-8")
724
+ .then(JSON.parse);
725
+
726
+ const transport = await openTransportReplayer(
727
+ RecordStore.fromString(`${apdusBuffer}`)
728
+ );
729
+
730
+ const eth = new Eth(transport);
731
+ const result = await eth.signEIP712Message("44'/60'/0'/0/0", message);
732
+
733
+ expect(result).toEqual({
734
+ r: "6f5490a5f227b0a77eb59ebc9b51dad97759930a71692bb868b0b796245c57dd",
735
+ s: "177634a3bada7e155beb1f79dc68bce7daf1a7931642a08aa2e82eb35c9546ec",
736
+ v: 28,
737
+ });
738
+ });
739
+
740
+ test("should sign correctly the 10.json sample message", async () => {
741
+ const apdusBuffer = await fs.readFile(getFilePath("10.apdus"), "utf-8");
742
+ const message = await fs
743
+ .readFile(getFilePath("10.json"), "utf-8")
744
+ .then(JSON.parse);
745
+
746
+ const transport = await openTransportReplayer(
747
+ RecordStore.fromString(`${apdusBuffer}`)
748
+ );
749
+
750
+ const eth = new Eth(transport);
751
+ const result = await eth.signEIP712Message("44'/60'/0'/0/0", message);
752
+
753
+ expect(result).toEqual({
754
+ r: "e71d7f114d3fc431f988e359bbea47c7ab81e755482201d3acd66557d7d611a4",
755
+ s: "4b3fb9d06c08ff11764f7f296af9b2e17c50aa9776581485a0284d4e66ea70c4",
756
+ v: 28,
757
+ });
758
+ });
759
+ });
760
+ });