cborg 1.10.1 → 2.0.0-alpha.1

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 (140) hide show
  1. package/.github/dependabot.yml +16 -0
  2. package/.github/workflows/test-and-release.yml +63 -0
  3. package/CHANGELOG.md +332 -0
  4. package/bench/bench.js +117 -0
  5. package/bench/json.js +124 -0
  6. package/bench/package.json +8 -0
  7. package/lib/bin.js +1 -1
  8. package/package.json +29 -47
  9. package/types/lib/4array.d.ts +1 -1
  10. package/types/lib/5map.d.ts +1 -1
  11. package/types/lib/6tag.d.ts +1 -1
  12. package/types/lib/7float.d.ts +1 -1
  13. package/types/lib/bin.d.ts +1 -0
  14. package/types/lib/token.d.ts +13 -13
  15. package/cjs/browser-test/appendix_a.js +0 -643
  16. package/cjs/browser-test/common.js +0 -24
  17. package/cjs/browser-test/node-test-bin.js +0 -348
  18. package/cjs/browser-test/noop-bin-test.js +0 -4
  19. package/cjs/browser-test/test-0uint.js +0 -158
  20. package/cjs/browser-test/test-1negint.js +0 -152
  21. package/cjs/browser-test/test-2bytes.js +0 -254
  22. package/cjs/browser-test/test-3string.js +0 -144
  23. package/cjs/browser-test/test-4array.js +0 -200
  24. package/cjs/browser-test/test-5map.js +0 -667
  25. package/cjs/browser-test/test-6tag.js +0 -75
  26. package/cjs/browser-test/test-7float.js +0 -253
  27. package/cjs/browser-test/test-bl.js +0 -91
  28. package/cjs/browser-test/test-cbor-vectors.js +0 -98
  29. package/cjs/browser-test/test-decode-errors.js +0 -77
  30. package/cjs/browser-test/test-fuzz.js +0 -56
  31. package/cjs/browser-test/test-json.js +0 -281
  32. package/cjs/browser-test/test-length.js +0 -63
  33. package/cjs/cborg.js +0 -14
  34. package/cjs/lib/0uint.js +0 -163
  35. package/cjs/lib/1negint.js +0 -63
  36. package/cjs/lib/2bytes.js +0 -62
  37. package/cjs/lib/3string.js +0 -46
  38. package/cjs/lib/4array.js +0 -51
  39. package/cjs/lib/5map.js +0 -51
  40. package/cjs/lib/6tag.js +0 -36
  41. package/cjs/lib/7float.js +0 -188
  42. package/cjs/lib/bin.js +0 -139
  43. package/cjs/lib/bl.js +0 -77
  44. package/cjs/lib/byte-utils.js +0 -245
  45. package/cjs/lib/common.js +0 -22
  46. package/cjs/lib/decode.js +0 -140
  47. package/cjs/lib/diagnostic.js +0 -124
  48. package/cjs/lib/encode.js +0 -248
  49. package/cjs/lib/is.js +0 -87
  50. package/cjs/lib/json/decode.js +0 -414
  51. package/cjs/lib/json/encode.js +0 -161
  52. package/cjs/lib/json/json.js +0 -12
  53. package/cjs/lib/jump.js +0 -174
  54. package/cjs/lib/length.js +0 -36
  55. package/cjs/lib/token.js +0 -46
  56. package/cjs/node-test/appendix_a.js +0 -643
  57. package/cjs/node-test/common.js +0 -24
  58. package/cjs/node-test/node-test-bin.js +0 -348
  59. package/cjs/node-test/noop-bin-test.js +0 -4
  60. package/cjs/node-test/test-0uint.js +0 -158
  61. package/cjs/node-test/test-1negint.js +0 -152
  62. package/cjs/node-test/test-2bytes.js +0 -254
  63. package/cjs/node-test/test-3string.js +0 -144
  64. package/cjs/node-test/test-4array.js +0 -200
  65. package/cjs/node-test/test-5map.js +0 -667
  66. package/cjs/node-test/test-6tag.js +0 -75
  67. package/cjs/node-test/test-7float.js +0 -253
  68. package/cjs/node-test/test-bl.js +0 -91
  69. package/cjs/node-test/test-cbor-vectors.js +0 -98
  70. package/cjs/node-test/test-decode-errors.js +0 -77
  71. package/cjs/node-test/test-fuzz.js +0 -56
  72. package/cjs/node-test/test-json.js +0 -281
  73. package/cjs/node-test/test-length.js +0 -63
  74. package/cjs/taglib.js +0 -44
  75. package/cli.js +0 -7
  76. package/esm/browser-test/appendix_a.js +0 -640
  77. package/esm/browser-test/common.js +0 -19
  78. package/esm/browser-test/node-test-bin.js +0 -339
  79. package/esm/browser-test/noop-bin-test.js +0 -1
  80. package/esm/browser-test/test-0uint.js +0 -155
  81. package/esm/browser-test/test-1negint.js +0 -149
  82. package/esm/browser-test/test-2bytes.js +0 -252
  83. package/esm/browser-test/test-3string.js +0 -141
  84. package/esm/browser-test/test-4array.js +0 -197
  85. package/esm/browser-test/test-5map.js +0 -664
  86. package/esm/browser-test/test-6tag.js +0 -78
  87. package/esm/browser-test/test-7float.js +0 -250
  88. package/esm/browser-test/test-bl.js +0 -84
  89. package/esm/browser-test/test-cbor-vectors.js +0 -95
  90. package/esm/browser-test/test-decode-errors.js +0 -69
  91. package/esm/browser-test/test-fuzz.js +0 -50
  92. package/esm/browser-test/test-json.js +0 -279
  93. package/esm/browser-test/test-length.js +0 -55
  94. package/esm/cborg.js +0 -12
  95. package/esm/lib/0uint.js +0 -152
  96. package/esm/lib/1negint.js +0 -55
  97. package/esm/lib/2bytes.js +0 -59
  98. package/esm/lib/3string.js +0 -43
  99. package/esm/lib/4array.js +0 -41
  100. package/esm/lib/5map.js +0 -41
  101. package/esm/lib/6tag.js +0 -27
  102. package/esm/lib/7float.js +0 -179
  103. package/esm/lib/bin.js +0 -137
  104. package/esm/lib/bl.js +0 -74
  105. package/esm/lib/byte-utils.js +0 -228
  106. package/esm/lib/common.js +0 -19
  107. package/esm/lib/decode.js +0 -139
  108. package/esm/lib/diagnostic.js +0 -123
  109. package/esm/lib/encode.js +0 -246
  110. package/esm/lib/is.js +0 -81
  111. package/esm/lib/json/decode.js +0 -413
  112. package/esm/lib/json/encode.js +0 -160
  113. package/esm/lib/json/json.js +0 -10
  114. package/esm/lib/jump.js +0 -168
  115. package/esm/lib/length.js +0 -31
  116. package/esm/lib/token.js +0 -43
  117. package/esm/node-test/appendix_a.js +0 -640
  118. package/esm/node-test/common.js +0 -19
  119. package/esm/node-test/node-test-bin.js +0 -339
  120. package/esm/node-test/noop-bin-test.js +0 -1
  121. package/esm/node-test/test-0uint.js +0 -155
  122. package/esm/node-test/test-1negint.js +0 -149
  123. package/esm/node-test/test-2bytes.js +0 -252
  124. package/esm/node-test/test-3string.js +0 -141
  125. package/esm/node-test/test-4array.js +0 -197
  126. package/esm/node-test/test-5map.js +0 -664
  127. package/esm/node-test/test-6tag.js +0 -78
  128. package/esm/node-test/test-7float.js +0 -250
  129. package/esm/node-test/test-bl.js +0 -84
  130. package/esm/node-test/test-cbor-vectors.js +0 -95
  131. package/esm/node-test/test-decode-errors.js +0 -69
  132. package/esm/node-test/test-fuzz.js +0 -50
  133. package/esm/node-test/test-json.js +0 -279
  134. package/esm/node-test/test-length.js +0 -55
  135. package/esm/package.json +0 -4
  136. package/esm/taglib.js +0 -37
  137. package/index.js +0 -1
  138. package/json +0 -1
  139. package/length +0 -1
  140. package/taglib +0 -1
@@ -1,667 +0,0 @@
1
- 'use strict';
2
-
3
- var chai = require('chai');
4
- require('../cborg.js');
5
- var byteUtils = require('../lib/byte-utils.js');
6
- var decode = require('../lib/decode.js');
7
- var encode = require('../lib/encode.js');
8
-
9
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
-
11
- var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
12
-
13
- const {assert} = chai__default["default"];
14
- const fixtures = [
15
- {
16
- data: 'a0',
17
- expected: {},
18
- type: 'map empty'
19
- },
20
- {
21
- data: 'a0',
22
- expected: new Map(),
23
- type: 'map empty (useMaps)',
24
- useMaps: true
25
- },
26
- {
27
- data: 'a1616101',
28
- expected: { a: 1 },
29
- type: 'map 1 pair'
30
- },
31
- {
32
- data: 'a161316161',
33
- expected: { 1: 'a' },
34
- type: 'map 1 pair (rev)'
35
- },
36
- {
37
- data: 'a1016161',
38
- expected: toMap([[
39
- 1,
40
- 'a'
41
- ]]),
42
- type: 'map 1 pair (int key as Map w/ useMaps)',
43
- useMaps: true
44
- },
45
- {
46
- data: 'a243010203633132334302030463323334',
47
- expected: toMap([
48
- [
49
- Uint8Array.from([
50
- 1,
51
- 2,
52
- 3
53
- ]),
54
- '123'
55
- ],
56
- [
57
- Uint8Array.from([
58
- 2,
59
- 3,
60
- 4
61
- ]),
62
- '234'
63
- ]
64
- ]),
65
- type: 'map 2 pair (bytes keys Map w/ useMaps)',
66
- useMaps: true
67
- },
68
- {
69
- data: 'a1666f626a656374a16477697468a26134666e6573746564676f626a65637473a161216121',
70
- expected: {
71
- object: {
72
- with: {
73
- 4: 'nested',
74
- objects: { '!': '!' }
75
- }
76
- }
77
- },
78
- type: 'map nested'
79
- },
80
- {
81
- data: 'a1666f626a656374a16477697468a204666e6573746564676f626a65637473a161216121',
82
- expected: toMap([[
83
- 'object',
84
- toMap([[
85
- 'with',
86
- toMap([
87
- [
88
- 4,
89
- 'nested'
90
- ],
91
- [
92
- 'objects',
93
- toMap([[
94
- '!',
95
- '!'
96
- ]])
97
- ]
98
- ])
99
- ]])
100
- ]]),
101
- type: 'map nested w/ useMaps',
102
- useMaps: true
103
- },
104
- {
105
- data: 'ae636f6e651b0016db6db6db6db763736978206374656e3b0016db6db6db6db76374776f1a0001000064666976650064666f757202646e696e653aa5f702b365656967687438ff65736576656e226574687265651901f466656c6576656e426131667477656c76656fc48c6175657320c39f76c49b74652168666f75727465656ea4616664666f7572616f016174026274680368746869727465656e840203046466697665',
106
- encode: {
107
- one: Number.MAX_SAFE_INTEGER / 1.4,
108
- two: 65536,
109
- three: 500,
110
- four: 2,
111
- five: 0,
112
- six: -1,
113
- seven: -3,
114
- eight: -256,
115
- nine: -2784428724,
116
- ten: Number.MIN_SAFE_INTEGER / 1.4 - 1,
117
- eleven: new TextEncoder().encode('a1'),
118
- twelve: 'Čaues ßvěte!',
119
- thirteen: [
120
- 2,
121
- 3,
122
- 4,
123
- 'five'
124
- ],
125
- fourteen: {
126
- o: 1,
127
- t: 2,
128
- th: 3,
129
- f: 'four'
130
- }
131
- },
132
- expected: {
133
- one: Number.MAX_SAFE_INTEGER / 1.4,
134
- six: -1,
135
- ten: Number.MIN_SAFE_INTEGER / 1.4 - 1,
136
- two: 65536,
137
- five: 0,
138
- four: 2,
139
- nine: -2784428724,
140
- eight: -256,
141
- seven: -3,
142
- three: 500,
143
- eleven: new TextEncoder().encode('a1'),
144
- twelve: 'Čaues ßvěte!',
145
- fourteen: {
146
- f: 'four',
147
- o: 1,
148
- t: 2,
149
- th: 3
150
- },
151
- thirteen: [
152
- 2,
153
- 3,
154
- 4,
155
- 'five'
156
- ]
157
- },
158
- type: 'map with complex entries',
159
- label: '{}'
160
- },
161
- {
162
- data: 'ad01636f6e65026374776f1901f46c666976652068756e647265641902586b7369782068756e647265641a00010000636269671b0016db6db6db6db76662696767657220696d696e7573206f6e6521696d696e75732074776f38ff781f6d696e75732074776f2068756e6472656420616e64206669667479207369783901f4781a6d696e757820666976652068756e6472656420616e64206f6e653901f5781a6d696e757820666976652068756e6472656420616e642074776f3aa5f702b367626967206e65673b0016db6db6db6db76a626967676572206e6567',
163
- encode: toMap([
164
- [
165
- 2,
166
- 'two'
167
- ],
168
- [
169
- 1,
170
- 'one'
171
- ],
172
- [
173
- -2,
174
- 'minus two'
175
- ],
176
- [
177
- -1,
178
- 'minus one'
179
- ],
180
- [
181
- 600,
182
- 'six hundred'
183
- ],
184
- [
185
- 500,
186
- 'five hundred'
187
- ],
188
- [
189
- -256,
190
- 'minus two hundred and fifty six'
191
- ],
192
- [
193
- -502,
194
- 'minux five hundred and two'
195
- ],
196
- [
197
- -501,
198
- 'minux five hundred and one'
199
- ],
200
- [
201
- 65536,
202
- 'big'
203
- ],
204
- [
205
- -2784428724,
206
- 'big neg'
207
- ],
208
- [
209
- 6433713753386423,
210
- 'bigger'
211
- ],
212
- [
213
- -6433713753386424,
214
- 'bigger neg'
215
- ]
216
- ]),
217
- expected: toMap([
218
- [
219
- 1,
220
- 'one'
221
- ],
222
- [
223
- 2,
224
- 'two'
225
- ],
226
- [
227
- 500,
228
- 'five hundred'
229
- ],
230
- [
231
- 600,
232
- 'six hundred'
233
- ],
234
- [
235
- 65536,
236
- 'big'
237
- ],
238
- [
239
- 6433713753386423,
240
- 'bigger'
241
- ],
242
- [
243
- -1,
244
- 'minus one'
245
- ],
246
- [
247
- -2,
248
- 'minus two'
249
- ],
250
- [
251
- -256,
252
- 'minus two hundred and fifty six'
253
- ],
254
- [
255
- -501,
256
- 'minux five hundred and one'
257
- ],
258
- [
259
- -502,
260
- 'minux five hundred and two'
261
- ],
262
- [
263
- -2784428724,
264
- 'big neg'
265
- ],
266
- [
267
- -6433713753386424,
268
- 'bigger neg'
269
- ]
270
- ]),
271
- type: 'map with ints and negints',
272
- useMaps: true
273
- },
274
- {
275
- data: 'a44104636f6e65430102026374776f430102036574687265654301020464666f7572',
276
- encode: toMap([
277
- [
278
- Uint8Array.from([
279
- 1,
280
- 2,
281
- 3
282
- ]),
283
- 'three'
284
- ],
285
- [
286
- Uint8Array.from([4]),
287
- 'one'
288
- ],
289
- [
290
- Uint8Array.from([
291
- 1,
292
- 2,
293
- 4
294
- ]),
295
- 'four'
296
- ],
297
- [
298
- Uint8Array.from([
299
- 1,
300
- 2,
301
- 2
302
- ]),
303
- 'two'
304
- ]
305
- ]),
306
- expected: toMap([
307
- [
308
- Uint8Array.from([4]),
309
- 'one'
310
- ],
311
- [
312
- Uint8Array.from([
313
- 1,
314
- 2,
315
- 2
316
- ]),
317
- 'two'
318
- ],
319
- [
320
- Uint8Array.from([
321
- 1,
322
- 2,
323
- 3
324
- ]),
325
- 'three'
326
- ],
327
- [
328
- Uint8Array.from([
329
- 1,
330
- 2,
331
- 4
332
- ]),
333
- 'four'
334
- ]
335
- ]),
336
- type: 'map with bytes keys',
337
- useMaps: true
338
- },
339
- {
340
- data: 'b801616101',
341
- expected: { a: 1 },
342
- type: 'map 1 pair, length8',
343
- strict: false
344
- },
345
- {
346
- data: 'b90001616101',
347
- expected: { a: 1 },
348
- type: 'map 1 pair, length16',
349
- strict: false
350
- },
351
- {
352
- data: 'ba00000001616101',
353
- expected: { a: 1 },
354
- type: 'map 1 pair, length32',
355
- strict: false
356
- },
357
- {
358
- data: 'bb0000000000000001616101',
359
- expected: { a: 1 },
360
- type: 'map 1 pair, length64',
361
- strict: false
362
- }
363
- ];
364
- function toMap(arr) {
365
- const m = new Map();
366
- for (const [key, value] of arr) {
367
- m.set(key, value);
368
- }
369
- return m;
370
- }
371
- function entries(map) {
372
- function nest(a) {
373
- for (const e of a) {
374
- e[0] = entries(e[0]);
375
- e[1] = entries(e[1]);
376
- }
377
- return a;
378
- }
379
- if (Object.getPrototypeOf(map) === Map.prototype) {
380
- return nest([...map.entries()]);
381
- }
382
- if (typeof map === 'object') {
383
- return nest([...Object.entries(map)]);
384
- }
385
- return map;
386
- }
387
- describe('map', () => {
388
- describe('decode', () => {
389
- for (const fixture of fixtures) {
390
- const data = byteUtils.fromHex(fixture.data);
391
- it(`should decode ${ fixture.type }=${ fixture.label || JSON.stringify(fixture.expected) }`, () => {
392
- let options = fixture.useMaps ? { useMaps: true } : undefined;
393
- const decoded = decode.decode(data, options);
394
- if (fixture.useMaps) {
395
- assert.strictEqual(Object.getPrototypeOf(decoded), Map.prototype, 'is Map');
396
- } else {
397
- assert.isObject(decoded, 'is object');
398
- }
399
- assert.deepStrictEqual(entries(decoded), entries(fixture.expected), `decode ${ fixture.type }`);
400
- options = Object.assign({ strict: true }, options);
401
- if (fixture.strict === false) {
402
- assert.throws(() => decode.decode(data, options), Error, 'CBOR decode error: integer encoded in more bytes than necessary (strict decode)');
403
- } else {
404
- assert.deepStrictEqual(entries(decode.decode(data, options)), entries(fixture.expected), `decode ${ fixture.type }`);
405
- }
406
- });
407
- it('should fail to decode very large length', () => {
408
- assert.throws(() => decode.decode(byteUtils.fromHex('bba5f702b3a5f70201616101')), /CBOR decode error: 64-bit integer map lengths not supported/);
409
- });
410
- }
411
- it('errors', () => {
412
- assert.throws(() => decode.decode(byteUtils.fromHex('a1016161')), /non-string keys not supported \(got number\)/);
413
- });
414
- });
415
- describe('encode', () => {
416
- for (const fixture of fixtures) {
417
- it(`should encode ${ fixture.type }=${ fixture.label || JSON.stringify(fixture.expected) }`, () => {
418
- const toEncode = fixture.encode || fixture.expected;
419
- if (fixture.unsafe) {
420
- assert.throws(encode.encode.bind(null, toEncode), Error, /^CBOR encode error: number too large to encode \(\d+\)$/);
421
- } else if (fixture.strict === false || fixture.roundtrip === false) {
422
- assert.notDeepEqual(byteUtils.toHex(encode.encode(toEncode)), fixture.data, `encode ${ fixture.type } !strict`);
423
- } else {
424
- assert.strictEqual(byteUtils.toHex(encode.encode(toEncode)), fixture.data, `encode ${ fixture.type }`);
425
- }
426
- });
427
- }
428
- });
429
- describe('roundtrip', () => {
430
- for (const fixture of fixtures) {
431
- if (!fixture.unsafe && fixture.strict !== false && fixture.roundtrip !== false) {
432
- it(`should roundtrip ${ fixture.type }=${ fixture.label || JSON.stringify(fixture.expected) }`, () => {
433
- const toEncode = fixture.encode || fixture.expected;
434
- const options = fixture.useMaps ? { useMaps: true } : undefined;
435
- const rt = decode.decode(encode.encode(toEncode), options);
436
- if (fixture.useMaps) {
437
- assert.strictEqual(Object.getPrototypeOf(rt), Map.prototype, 'is Map');
438
- } else {
439
- assert.isObject(rt, 'is object');
440
- }
441
- assert.deepStrictEqual(entries(rt), entries(fixture.expected), `roundtrip ${ fixture.type }`);
442
- });
443
- }
444
- }
445
- });
446
- describe('specials', () => {
447
- it('can decode indefinite length items', () => {
448
- assert.deepStrictEqual(decode.decode(byteUtils.fromHex('bf616f01617402ff')), {
449
- o: 1,
450
- t: 2
451
- });
452
- });
453
- it('can switch off indefinite length support', () => {
454
- assert.throws(() => decode.decode(byteUtils.fromHex('bf616f01617402ff'), { allowIndefinite: false }), /indefinite/);
455
- });
456
- });
457
- describe('sorting', () => {
458
- it('sorts int map keys', () => {
459
- assert.strictEqual(byteUtils.toHex(encode.encode(new Map([
460
- [
461
- 1,
462
- 1
463
- ],
464
- [
465
- 2,
466
- 2
467
- ]
468
- ]))), 'a201010202');
469
- assert.strictEqual(byteUtils.toHex(encode.encode(new Map([
470
- [
471
- 2,
472
- 1
473
- ],
474
- [
475
- 1,
476
- 2
477
- ]
478
- ]))), 'a201020201');
479
- });
480
- it('sorts negint map keys', () => {
481
- assert.strictEqual(byteUtils.toHex(encode.encode(new Map([
482
- [
483
- -1,
484
- 1
485
- ],
486
- [
487
- -2,
488
- 2
489
- ]
490
- ]))), 'a220012102');
491
- assert.strictEqual(byteUtils.toHex(encode.encode(new Map([
492
- [
493
- -2,
494
- 1
495
- ],
496
- [
497
- -1,
498
- 2
499
- ]
500
- ]))), 'a220022101');
501
- });
502
- it('sorts bytes map keys', () => {
503
- assert.strictEqual(byteUtils.toHex(encode.encode(new Map([
504
- [
505
- Uint8Array.from([
506
- 1,
507
- 2
508
- ]),
509
- 1
510
- ],
511
- [
512
- Uint8Array.from([
513
- 2,
514
- 1
515
- ]),
516
- 2
517
- ]
518
- ]))), 'a24201020142020102');
519
- assert.strictEqual(byteUtils.toHex(encode.encode(new Map([
520
- [
521
- Uint8Array.from([
522
- 2,
523
- 1
524
- ]),
525
- 1
526
- ],
527
- [
528
- Uint8Array.from([
529
- 1,
530
- 2
531
- ]),
532
- 2
533
- ]
534
- ]))), 'a24201020242020101');
535
- assert.strictEqual(byteUtils.toHex(encode.encode(new Map([
536
- [
537
- Uint8Array.from([
538
- 1,
539
- 2
540
- ]),
541
- 1
542
- ],
543
- [
544
- Uint8Array.from([
545
- 2,
546
- 1
547
- ]),
548
- 2
549
- ],
550
- [
551
- Uint8Array.from([200]),
552
- 3
553
- ]
554
- ]))), 'a341c8034201020142020102');
555
- });
556
- it('sorts bytes map keys', () => {
557
- assert.strictEqual(byteUtils.toHex(encode.encode(new Map([
558
- [
559
- Uint8Array.from([
560
- 1,
561
- 2
562
- ]),
563
- 1
564
- ],
565
- [
566
- Uint8Array.from([
567
- 2,
568
- 1
569
- ]),
570
- 2
571
- ]
572
- ]))), 'a24201020142020102');
573
- assert.strictEqual(byteUtils.toHex(encode.encode(new Map([
574
- [
575
- Uint8Array.from([
576
- 2,
577
- 1
578
- ]),
579
- 1
580
- ],
581
- [
582
- Uint8Array.from([
583
- 1,
584
- 2
585
- ]),
586
- 2
587
- ]
588
- ]))), 'a24201020242020101');
589
- assert.strictEqual(byteUtils.toHex(encode.encode(new Map([
590
- [
591
- Uint8Array.from([
592
- 1,
593
- 2
594
- ]),
595
- 1
596
- ],
597
- [
598
- Uint8Array.from([
599
- 2,
600
- 1
601
- ]),
602
- 2
603
- ],
604
- [
605
- Uint8Array.from([200]),
606
- 3
607
- ]
608
- ]))), 'a341c8034201020142020102');
609
- });
610
- it('sorts array map keys (length only)', () => {
611
- assert.strictEqual(byteUtils.toHex(encode.encode(new Map([
612
- [
613
- [1],
614
- 1
615
- ],
616
- [
617
- [
618
- 1,
619
- 1
620
- ],
621
- 2
622
- ]
623
- ]))), 'a281010182010102');
624
- assert.strictEqual(byteUtils.toHex(encode.encode(new Map([
625
- [
626
- [
627
- 1,
628
- 1
629
- ],
630
- 1
631
- ],
632
- [
633
- [1],
634
- 2
635
- ]
636
- ]))), 'a281010282010101');
637
- });
638
- it('sorts map map keys (length only)', () => {
639
- assert.strictEqual(byteUtils.toHex(encode.encode(new Map([
640
- [
641
- { a: 1 },
642
- 1
643
- ],
644
- [
645
- {
646
- a: 1,
647
- b: 1
648
- },
649
- 2
650
- ]
651
- ]))), 'a2a161610101a261610161620102');
652
- assert.strictEqual(byteUtils.toHex(encode.encode(new Map([
653
- [
654
- {
655
- a: 1,
656
- b: 1
657
- },
658
- 1
659
- ],
660
- [
661
- { a: 1 },
662
- 2
663
- ]
664
- ]))), 'a2a161610102a261610161620101');
665
- });
666
- });
667
- });