mol_crypto2_lib 0.0.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.
package/web.test.js ADDED
@@ -0,0 +1,1993 @@
1
+ "use strict";
2
+ function require( path ){ return $node[ path ] };
3
+ "use strict";
4
+ var $;
5
+ (function ($) {
6
+ function $mol_promise_like(val) {
7
+ try {
8
+ return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
9
+ }
10
+ catch {
11
+ return false;
12
+ }
13
+ }
14
+ $.$mol_promise_like = $mol_promise_like;
15
+ })($ || ($ = {}));
16
+
17
+ ;
18
+ "use strict";
19
+ var $;
20
+ (function ($_1) {
21
+ function $mol_test(set) {
22
+ for (let name in set) {
23
+ const code = set[name];
24
+ const test = (typeof code === 'string') ? new Function('', code) : code;
25
+ $_1.$mol_test_all.push(test);
26
+ }
27
+ $mol_test_schedule();
28
+ }
29
+ $_1.$mol_test = $mol_test;
30
+ $_1.$mol_test_mocks = [];
31
+ $_1.$mol_test_all = [];
32
+ async function $mol_test_run() {
33
+ for (var test of $_1.$mol_test_all) {
34
+ let context = Object.create($$);
35
+ for (let mock of $_1.$mol_test_mocks)
36
+ await mock(context);
37
+ const res = test(context);
38
+ if ($mol_promise_like(res)) {
39
+ await new Promise((done, fail) => {
40
+ res.then(done, fail);
41
+ setTimeout(() => fail(new Error('Test timeout: ' + test.name)), 1000);
42
+ });
43
+ }
44
+ }
45
+ $$.$mol_log3_done({
46
+ place: '$mol_test',
47
+ message: 'All tests passed',
48
+ count: $_1.$mol_test_all.length,
49
+ });
50
+ }
51
+ $_1.$mol_test_run = $mol_test_run;
52
+ let scheduled = false;
53
+ function $mol_test_schedule() {
54
+ if (scheduled)
55
+ return;
56
+ scheduled = true;
57
+ setTimeout(async () => {
58
+ scheduled = false;
59
+ await $mol_test_run();
60
+ $$.$mol_test_complete();
61
+ }, 1000);
62
+ }
63
+ $_1.$mol_test_schedule = $mol_test_schedule;
64
+ $_1.$mol_test_mocks.push(context => {
65
+ let seed = 0;
66
+ context.Math = Object.create(Math);
67
+ context.Math.random = () => Math.sin(seed++);
68
+ const forbidden = ['XMLHttpRequest', 'fetch'];
69
+ for (let api of forbidden) {
70
+ context[api] = new Proxy(function () { }, {
71
+ get() {
72
+ $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
73
+ },
74
+ apply() {
75
+ $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
76
+ },
77
+ });
78
+ }
79
+ });
80
+ $mol_test({
81
+ 'mocked Math.random'($) {
82
+ console.assert($.Math.random() === 0);
83
+ console.assert($.Math.random() === Math.sin(1));
84
+ },
85
+ 'forbidden XMLHttpRequest'($) {
86
+ try {
87
+ console.assert(void new $.XMLHttpRequest);
88
+ }
89
+ catch (error) {
90
+ console.assert(error.message === 'XMLHttpRequest is forbidden in tests');
91
+ }
92
+ },
93
+ 'forbidden fetch'($) {
94
+ try {
95
+ console.assert(void $.fetch(''));
96
+ }
97
+ catch (error) {
98
+ console.assert(error.message === 'fetch is forbidden in tests');
99
+ }
100
+ },
101
+ });
102
+ })($ || ($ = {}));
103
+
104
+ ;
105
+ "use strict";
106
+ var $;
107
+ (function ($) {
108
+ function $mol_test_complete() {
109
+ }
110
+ $.$mol_test_complete = $mol_test_complete;
111
+ })($ || ($ = {}));
112
+
113
+ ;
114
+ "use strict";
115
+ var $;
116
+ (function ($) {
117
+ function $mol_dom_render_children(el, childNodes) {
118
+ const node_set = new Set(childNodes);
119
+ let nextNode = el.firstChild;
120
+ for (let view of childNodes) {
121
+ if (view == null)
122
+ continue;
123
+ if (view instanceof $mol_dom_context.Node) {
124
+ while (true) {
125
+ if (!nextNode) {
126
+ el.appendChild(view);
127
+ break;
128
+ }
129
+ if (nextNode == view) {
130
+ nextNode = nextNode.nextSibling;
131
+ break;
132
+ }
133
+ else {
134
+ if (node_set.has(nextNode)) {
135
+ el.insertBefore(view, nextNode);
136
+ break;
137
+ }
138
+ else {
139
+ const nn = nextNode.nextSibling;
140
+ el.removeChild(nextNode);
141
+ nextNode = nn;
142
+ }
143
+ }
144
+ }
145
+ }
146
+ else {
147
+ if (nextNode && nextNode.nodeName === '#text') {
148
+ const str = String(view);
149
+ if (nextNode.nodeValue !== str)
150
+ nextNode.nodeValue = str;
151
+ nextNode = nextNode.nextSibling;
152
+ }
153
+ else {
154
+ const textNode = $mol_dom_context.document.createTextNode(String(view));
155
+ el.insertBefore(textNode, nextNode);
156
+ }
157
+ }
158
+ }
159
+ while (nextNode) {
160
+ const currNode = nextNode;
161
+ nextNode = currNode.nextSibling;
162
+ el.removeChild(currNode);
163
+ }
164
+ }
165
+ $.$mol_dom_render_children = $mol_dom_render_children;
166
+ })($ || ($ = {}));
167
+
168
+ ;
169
+ "use strict";
170
+
171
+ ;
172
+ "use strict";
173
+
174
+ ;
175
+ "use strict";
176
+
177
+ ;
178
+ "use strict";
179
+
180
+ ;
181
+ "use strict";
182
+
183
+ ;
184
+ "use strict";
185
+ var $;
186
+ (function ($) {
187
+ function $mol_dom_serialize(node) {
188
+ const serializer = new $mol_dom_context.XMLSerializer;
189
+ return serializer.serializeToString(node);
190
+ }
191
+ $.$mol_dom_serialize = $mol_dom_serialize;
192
+ })($ || ($ = {}));
193
+
194
+ ;
195
+ "use strict";
196
+ var $;
197
+ (function ($) {
198
+ $.$mol_jsx_prefix = '';
199
+ $.$mol_jsx_crumbs = '';
200
+ $.$mol_jsx_booked = null;
201
+ $.$mol_jsx_document = {
202
+ getElementById: () => null,
203
+ createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
204
+ createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
205
+ };
206
+ $.$mol_jsx_frag = '';
207
+ function $mol_jsx(Elem, props, ...childNodes) {
208
+ const id = props && props.id || '';
209
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
210
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
211
+ if (Elem && $.$mol_jsx_booked) {
212
+ if ($.$mol_jsx_booked.has(id)) {
213
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
214
+ }
215
+ else {
216
+ $.$mol_jsx_booked.add(id);
217
+ }
218
+ }
219
+ let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
220
+ if ($.$mol_jsx_prefix) {
221
+ const prefix_ext = $.$mol_jsx_prefix;
222
+ const booked_ext = $.$mol_jsx_booked;
223
+ const crumbs_ext = $.$mol_jsx_crumbs;
224
+ for (const field in props) {
225
+ const func = props[field];
226
+ if (typeof func !== 'function')
227
+ continue;
228
+ const wrapper = function (...args) {
229
+ const prefix = $.$mol_jsx_prefix;
230
+ const booked = $.$mol_jsx_booked;
231
+ const crumbs = $.$mol_jsx_crumbs;
232
+ try {
233
+ $.$mol_jsx_prefix = prefix_ext;
234
+ $.$mol_jsx_booked = booked_ext;
235
+ $.$mol_jsx_crumbs = crumbs_ext;
236
+ return func.call(this, ...args);
237
+ }
238
+ finally {
239
+ $.$mol_jsx_prefix = prefix;
240
+ $.$mol_jsx_booked = booked;
241
+ $.$mol_jsx_crumbs = crumbs;
242
+ }
243
+ };
244
+ $mol_func_name_from(wrapper, func);
245
+ props[field] = wrapper;
246
+ }
247
+ }
248
+ if (typeof Elem !== 'string') {
249
+ if ('prototype' in Elem) {
250
+ const view = node && node[String(Elem)] || new Elem;
251
+ Object.assign(view, props);
252
+ view[Symbol.toStringTag] = guid;
253
+ view.childNodes = childNodes;
254
+ if (!view.ownerDocument)
255
+ view.ownerDocument = $.$mol_jsx_document;
256
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
257
+ node = view.valueOf();
258
+ node[String(Elem)] = view;
259
+ return node;
260
+ }
261
+ else {
262
+ const prefix = $.$mol_jsx_prefix;
263
+ const booked = $.$mol_jsx_booked;
264
+ const crumbs = $.$mol_jsx_crumbs;
265
+ try {
266
+ $.$mol_jsx_prefix = guid;
267
+ $.$mol_jsx_booked = new Set;
268
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
269
+ return Elem(props, ...childNodes);
270
+ }
271
+ finally {
272
+ $.$mol_jsx_prefix = prefix;
273
+ $.$mol_jsx_booked = booked;
274
+ $.$mol_jsx_crumbs = crumbs;
275
+ }
276
+ }
277
+ }
278
+ if (!node) {
279
+ node = Elem
280
+ ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
281
+ : $.$mol_jsx_document.createDocumentFragment();
282
+ }
283
+ $mol_dom_render_children(node, [].concat(...childNodes));
284
+ if (!Elem)
285
+ return node;
286
+ if (guid)
287
+ node.id = guid;
288
+ for (const key in props) {
289
+ if (key === 'id')
290
+ continue;
291
+ if (typeof props[key] === 'string') {
292
+ if (typeof node[key] === 'string')
293
+ node[key] = props[key];
294
+ node.setAttribute(key, props[key]);
295
+ }
296
+ else if (props[key] &&
297
+ typeof props[key] === 'object' &&
298
+ Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
299
+ if (typeof node[key] === 'object') {
300
+ Object.assign(node[key], props[key]);
301
+ continue;
302
+ }
303
+ }
304
+ else {
305
+ node[key] = props[key];
306
+ }
307
+ }
308
+ if ($.$mol_jsx_crumbs)
309
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
310
+ return node;
311
+ }
312
+ $.$mol_jsx = $mol_jsx;
313
+ })($ || ($ = {}));
314
+
315
+ ;
316
+ "use strict";
317
+ var $;
318
+ (function ($) {
319
+ $mol_test({
320
+ 'Make empty div'() {
321
+ $mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
322
+ },
323
+ 'Define native field'() {
324
+ const dom = $mol_jsx("input", { value: '123' });
325
+ $mol_assert_equal(dom.outerHTML, '<input value="123">');
326
+ $mol_assert_equal(dom.value, '123');
327
+ },
328
+ 'Define classes'() {
329
+ const dom = $mol_jsx("div", { class: 'foo bar' });
330
+ $mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
331
+ },
332
+ 'Define styles'() {
333
+ const dom = $mol_jsx("div", { style: { color: 'red' } });
334
+ $mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
335
+ },
336
+ 'Define dataset'() {
337
+ const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
338
+ $mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
339
+ },
340
+ 'Define attributes'() {
341
+ const dom = $mol_jsx("div", { lang: "ru", hidden: true });
342
+ $mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
343
+ },
344
+ 'Define child nodes'() {
345
+ const dom = $mol_jsx("div", null,
346
+ "hello",
347
+ $mol_jsx("strong", null, "world"),
348
+ "!");
349
+ $mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
350
+ },
351
+ 'Make fragment'() {
352
+ const dom = $mol_jsx($mol_jsx_frag, null,
353
+ $mol_jsx("br", null),
354
+ $mol_jsx("hr", null));
355
+ $mol_assert_equal($mol_dom_serialize(dom), '<br xmlns="http://www.w3.org/1999/xhtml" /><hr xmlns="http://www.w3.org/1999/xhtml" />');
356
+ },
357
+ 'Spread fragment'() {
358
+ const dom = $mol_jsx("div", null,
359
+ $mol_jsx($mol_jsx_frag, null,
360
+ $mol_jsx("br", null),
361
+ $mol_jsx("hr", null)));
362
+ $mol_assert_equal(dom.outerHTML, '<div><br><hr></div>');
363
+ },
364
+ 'Function as component'() {
365
+ const Button = (props, target) => {
366
+ return $mol_jsx("button", { title: props.hint }, target());
367
+ };
368
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
369
+ $mol_assert_equal(dom.outerHTML, '<button id="foo" title="click me" class="Button">hey!</button>');
370
+ },
371
+ 'Nested guid generation'() {
372
+ const Foo = () => {
373
+ return $mol_jsx("div", null,
374
+ $mol_jsx(Bar, { id: "bar" },
375
+ $mol_jsx("img", { id: "icon" })));
376
+ };
377
+ const Bar = (props, icon) => {
378
+ return $mol_jsx("span", null,
379
+ icon,
380
+ $mol_jsx("i", { id: "label" }));
381
+ };
382
+ const dom = $mol_jsx(Foo, { id: "foo" });
383
+ $mol_assert_equal(dom.outerHTML, '<div id="foo" class="Foo"><span id="foo/bar" class="Foo_bar Bar"><img id="foo/icon" class="Foo_icon"><i id="foo/bar/label" class="Foo_bar_label Bar_label"></i></span></div>');
384
+ },
385
+ 'Fail on non unique ids'() {
386
+ const App = () => {
387
+ return $mol_jsx("div", null,
388
+ $mol_jsx("span", { id: "bar" }),
389
+ $mol_jsx("span", { id: "bar" }));
390
+ };
391
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
392
+ },
393
+ 'Owner based guid generationn'() {
394
+ const Foo = () => {
395
+ return $mol_jsx("div", null,
396
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
397
+ };
398
+ const Bar = (props) => {
399
+ return $mol_jsx("span", null, props.icon());
400
+ };
401
+ const dom = $mol_jsx(Foo, { id: "app" });
402
+ $mol_assert_equal(dom.outerHTML, '<div id="app" class="Foo"><span id="app/middle" class="Foo_middle Bar"><img id="app/icon" class="Foo_icon"></span></div>');
403
+ },
404
+ 'Fail on same ids from different caller'() {
405
+ const Foo = () => {
406
+ return $mol_jsx("div", null,
407
+ $mol_jsx("img", { id: "icon" }),
408
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
409
+ };
410
+ const Bar = (props) => {
411
+ return $mol_jsx("span", null, props.icon());
412
+ };
413
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
414
+ },
415
+ });
416
+ })($ || ($ = {}));
417
+
418
+ ;
419
+ "use strict";
420
+ var $;
421
+ (function ($) {
422
+ function $mol_guid(length = 8, exists = () => false) {
423
+ for (;;) {
424
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
425
+ if (exists(id))
426
+ continue;
427
+ return id;
428
+ }
429
+ }
430
+ $.$mol_guid = $mol_guid;
431
+ })($ || ($ = {}));
432
+
433
+ ;
434
+ "use strict";
435
+ var $;
436
+ (function ($) {
437
+ function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
438
+ const source = typeof item === 'function' ? new $mol_range2_array() : item;
439
+ if (typeof item !== 'function') {
440
+ item = index => source[index];
441
+ size = () => source.length;
442
+ }
443
+ return new Proxy(source, {
444
+ get(target, field) {
445
+ if (typeof field === 'string') {
446
+ if (field === 'length')
447
+ return size();
448
+ const index = Number(field);
449
+ if (index < 0)
450
+ return undefined;
451
+ if (index >= size())
452
+ return undefined;
453
+ if (index === Math.trunc(index))
454
+ return item(index);
455
+ }
456
+ return $mol_range2_array.prototype[field];
457
+ },
458
+ set(target, field) {
459
+ return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
460
+ },
461
+ ownKeys(target) {
462
+ return [...Array(size())].map((v, i) => String(i)).concat('length');
463
+ },
464
+ getOwnPropertyDescriptor(target, field) {
465
+ if (field === "length")
466
+ return {
467
+ value: size(),
468
+ writable: true,
469
+ enumerable: false,
470
+ configurable: false,
471
+ };
472
+ const index = Number(field);
473
+ if (index === Math.trunc(index))
474
+ return {
475
+ get: () => this.get(target, field, this),
476
+ enumerable: true,
477
+ configurable: true,
478
+ };
479
+ return Object.getOwnPropertyDescriptor(target, field);
480
+ }
481
+ });
482
+ }
483
+ $.$mol_range2 = $mol_range2;
484
+ class $mol_range2_array extends Array {
485
+ concat(...tail) {
486
+ if (tail.length === 0)
487
+ return this;
488
+ if (tail.length > 1) {
489
+ let list = this;
490
+ for (let item of tail)
491
+ list = list.concat(item);
492
+ return list;
493
+ }
494
+ return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
495
+ }
496
+ filter(check, context) {
497
+ const filtered = [];
498
+ let cursor = -1;
499
+ return $mol_range2(index => {
500
+ while (cursor < this.length && index >= filtered.length - 1) {
501
+ const val = this[++cursor];
502
+ if (check(val, cursor, this))
503
+ filtered.push(val);
504
+ }
505
+ return filtered[index];
506
+ }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
507
+ }
508
+ forEach(proceed, context) {
509
+ for (let [key, value] of this.entries())
510
+ proceed.call(context, value, key, this);
511
+ }
512
+ map(proceed, context) {
513
+ return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
514
+ }
515
+ reduce(merge, result) {
516
+ let index = 0;
517
+ if (arguments.length === 1) {
518
+ result = this[index++];
519
+ }
520
+ for (; index < this.length; ++index) {
521
+ result = merge(result, this[index], index, this);
522
+ }
523
+ return result;
524
+ }
525
+ toReversed() {
526
+ return $mol_range2(index => this[this.length - 1 - index], () => this.length);
527
+ }
528
+ slice(from = 0, to = this.length) {
529
+ return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
530
+ }
531
+ some(check, context) {
532
+ for (let index = 0; index < this.length; ++index) {
533
+ if (check.call(context, this[index], index, this))
534
+ return true;
535
+ }
536
+ return false;
537
+ }
538
+ every(check, context) {
539
+ for (let index = 0; index < this.length; ++index) {
540
+ if (!check.call(context, this[index], index, this))
541
+ return false;
542
+ }
543
+ return true;
544
+ }
545
+ reverse() {
546
+ return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
547
+ }
548
+ sort() {
549
+ return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
550
+ }
551
+ indexOf(needle) {
552
+ return this.findIndex(item => item === needle);
553
+ }
554
+ [Symbol.toPrimitive]() {
555
+ return $mol_guid();
556
+ }
557
+ }
558
+ $.$mol_range2_array = $mol_range2_array;
559
+ })($ || ($ = {}));
560
+
561
+ ;
562
+ "use strict";
563
+ var $;
564
+ (function ($) {
565
+ $mol_test({
566
+ 'lazy calls'() {
567
+ let calls = 0;
568
+ const list = $mol_range2(index => (++calls, index), () => 10);
569
+ $mol_assert_equal(true, list instanceof Array);
570
+ $mol_assert_equal(list.length, 10);
571
+ $mol_assert_equal(list[-1], undefined);
572
+ $mol_assert_equal(list[0], 0);
573
+ $mol_assert_equal(list[9], 9);
574
+ $mol_assert_equal(list[9.5], undefined);
575
+ $mol_assert_equal(list[10], undefined);
576
+ $mol_assert_equal(calls, 2);
577
+ },
578
+ 'infinity list'() {
579
+ let calls = 0;
580
+ const list = $mol_range2(index => (++calls, index));
581
+ $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
582
+ $mol_assert_equal(list[0], 0);
583
+ $mol_assert_equal(list[4], 4);
584
+ $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
585
+ $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
586
+ $mol_assert_equal(calls, 3);
587
+ },
588
+ 'stringify'() {
589
+ const list = $mol_range2(i => i, () => 5);
590
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
591
+ $mol_assert_equal(list.join(';'), '0;1;2;3;4');
592
+ },
593
+ 'for-of'() {
594
+ let log = '';
595
+ for (let i of $mol_range2(i => i + 1, () => 5)) {
596
+ log += i;
597
+ }
598
+ $mol_assert_equal(log, '12345');
599
+ },
600
+ 'for-in'() {
601
+ let log = '';
602
+ for (let i in $mol_range2(i => i, () => 5)) {
603
+ log += i;
604
+ }
605
+ $mol_assert_equal(log, '01234');
606
+ },
607
+ 'forEach'() {
608
+ let log = '';
609
+ $mol_range2(i => i, () => 5).forEach(i => log += i);
610
+ $mol_assert_equal(log, '01234');
611
+ },
612
+ 'reduce'() {
613
+ let calls = 0;
614
+ const list = $mol_range2().slice(1, 6);
615
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
616
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
617
+ },
618
+ 'lazy concat'() {
619
+ let calls1 = 0;
620
+ let calls2 = 0;
621
+ const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
622
+ $mol_assert_equal(true, list instanceof Array);
623
+ $mol_assert_equal(list.length, 15);
624
+ $mol_assert_equal(list[0], 0);
625
+ $mol_assert_equal(list[4], 4);
626
+ $mol_assert_equal(list[5], 0);
627
+ $mol_assert_equal(list[9], 4);
628
+ $mol_assert_equal(list[10], 0);
629
+ $mol_assert_equal(list[14], 4);
630
+ $mol_assert_equal(list[15], undefined);
631
+ $mol_assert_equal(calls1, 2);
632
+ $mol_assert_equal(calls2, 2);
633
+ },
634
+ 'lazy filter'() {
635
+ let calls = 0;
636
+ const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
637
+ $mol_assert_equal(true, list instanceof Array);
638
+ $mol_assert_equal(list.length, 3);
639
+ $mol_assert_equal(list[0], 1);
640
+ $mol_assert_equal(list[2], 5);
641
+ $mol_assert_equal(list[3], undefined);
642
+ $mol_assert_equal(calls, 8);
643
+ },
644
+ 'lazy reverse'() {
645
+ let calls = 0;
646
+ const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
647
+ $mol_assert_equal(true, list instanceof Array);
648
+ $mol_assert_equal(list.length, 3);
649
+ $mol_assert_equal(list[0], 9);
650
+ $mol_assert_equal(list[2], 7);
651
+ $mol_assert_equal(list[3], undefined);
652
+ $mol_assert_equal(calls, 2);
653
+ },
654
+ 'lazy map'() {
655
+ let calls1 = 0;
656
+ let calls2 = 0;
657
+ const source = $mol_range2(index => (++calls1, index), () => 5);
658
+ const target = source.map((item, index, self) => {
659
+ ++calls2;
660
+ $mol_assert_equal(source, self);
661
+ return index + 10;
662
+ }, () => 5);
663
+ $mol_assert_equal(true, target instanceof Array);
664
+ $mol_assert_equal(target.length, 5);
665
+ $mol_assert_equal(target[0], 10);
666
+ $mol_assert_equal(target[4], 14);
667
+ $mol_assert_equal(target[5], undefined);
668
+ $mol_assert_equal(calls1, 2);
669
+ $mol_assert_equal(calls2, 2);
670
+ },
671
+ 'lazy slice'() {
672
+ let calls = 0;
673
+ const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
674
+ $mol_assert_equal(true, list instanceof Array);
675
+ $mol_assert_equal(list.length, 4);
676
+ $mol_assert_equal(list[0], 3);
677
+ $mol_assert_equal(list[3], 6);
678
+ $mol_assert_equal(list[4], undefined);
679
+ $mol_assert_equal(calls, 2);
680
+ },
681
+ 'lazy some'() {
682
+ let calls = 0;
683
+ $mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
684
+ $mol_assert_equal(calls, 3);
685
+ $mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
686
+ $mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
687
+ },
688
+ 'lazy every'() {
689
+ let calls = 0;
690
+ $mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
691
+ $mol_assert_equal(calls, 3);
692
+ $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
693
+ $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
694
+ },
695
+ 'lazyfy'() {
696
+ let calls = 0;
697
+ const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
698
+ $mol_assert_equal(true, list instanceof Array);
699
+ $mol_assert_equal(list.length, 4);
700
+ $mol_assert_equal(calls, 0);
701
+ $mol_assert_equal(list[0], 12);
702
+ $mol_assert_equal(list[3], 15);
703
+ $mol_assert_equal(list[4], undefined);
704
+ $mol_assert_equal(calls, 2);
705
+ },
706
+ 'prevent modification'() {
707
+ const list = $mol_range2(i => i, () => 5);
708
+ $mol_assert_fail(() => list.push(4), TypeError);
709
+ $mol_assert_fail(() => list.pop(), TypeError);
710
+ $mol_assert_fail(() => list.unshift(4), TypeError);
711
+ $mol_assert_fail(() => list.shift(), TypeError);
712
+ $mol_assert_fail(() => list.splice(1, 2), TypeError);
713
+ $mol_assert_fail(() => list[1] = 2, TypeError);
714
+ $mol_assert_fail(() => list.reverse(), TypeError);
715
+ $mol_assert_fail(() => list.sort(), TypeError);
716
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
717
+ }
718
+ });
719
+ })($ || ($ = {}));
720
+
721
+ ;
722
+ "use strict";
723
+ var $;
724
+ (function ($) {
725
+ $.$mol_compare_deep_cache = new WeakMap();
726
+ function $mol_compare_deep(left, right) {
727
+ if (Object.is(left, right))
728
+ return true;
729
+ if (left === null)
730
+ return false;
731
+ if (right === null)
732
+ return false;
733
+ if (typeof left !== 'object')
734
+ return false;
735
+ if (typeof right !== 'object')
736
+ return false;
737
+ const left_proto = Reflect.getPrototypeOf(left);
738
+ const right_proto = Reflect.getPrototypeOf(right);
739
+ if (left_proto !== right_proto)
740
+ return false;
741
+ if (left instanceof Boolean)
742
+ return Object.is(left.valueOf(), right['valueOf']());
743
+ if (left instanceof Number)
744
+ return Object.is(left.valueOf(), right['valueOf']());
745
+ if (left instanceof String)
746
+ return Object.is(left.valueOf(), right['valueOf']());
747
+ if (left instanceof Date)
748
+ return Object.is(left.valueOf(), right['valueOf']());
749
+ if (left instanceof RegExp)
750
+ return left.source === right.source && left.flags === right.flags;
751
+ if (left instanceof Error)
752
+ return left.message === right.message && $mol_compare_deep(left.stack, right.stack);
753
+ let left_cache = $.$mol_compare_deep_cache.get(left);
754
+ if (left_cache) {
755
+ const right_cache = left_cache.get(right);
756
+ if (typeof right_cache === 'boolean')
757
+ return right_cache;
758
+ }
759
+ else {
760
+ left_cache = new WeakMap();
761
+ $.$mol_compare_deep_cache.set(left, left_cache);
762
+ }
763
+ left_cache.set(right, true);
764
+ let result;
765
+ try {
766
+ if (!left_proto)
767
+ result = compare_pojo(left, right);
768
+ else if (!Reflect.getPrototypeOf(left_proto))
769
+ result = compare_pojo(left, right);
770
+ else if (Symbol.toPrimitive in left)
771
+ result = compare_primitive(left, right);
772
+ else if (Array.isArray(left))
773
+ result = compare_array(left, right);
774
+ else if (left instanceof Set)
775
+ result = compare_set(left, right);
776
+ else if (left instanceof Map)
777
+ result = compare_map(left, right);
778
+ else if (ArrayBuffer.isView(left))
779
+ result = compare_buffer(left, right);
780
+ else if (Symbol.iterator in left)
781
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
782
+ else
783
+ result = false;
784
+ }
785
+ finally {
786
+ left_cache.set(right, result);
787
+ }
788
+ return result;
789
+ }
790
+ $.$mol_compare_deep = $mol_compare_deep;
791
+ function compare_array(left, right) {
792
+ const len = left.length;
793
+ if (len !== right.length)
794
+ return false;
795
+ for (let i = 0; i < len; ++i) {
796
+ if (!$mol_compare_deep(left[i], right[i]))
797
+ return false;
798
+ }
799
+ return true;
800
+ }
801
+ function compare_buffer(left, right) {
802
+ const len = left.byteLength;
803
+ if (len !== right.byteLength)
804
+ return false;
805
+ if (left instanceof DataView)
806
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, right.byteOffset, right.byteLength));
807
+ for (let i = 0; i < len; ++i) {
808
+ if (left[i] !== right[i])
809
+ return false;
810
+ }
811
+ return true;
812
+ }
813
+ function compare_iterator(left, right) {
814
+ while (true) {
815
+ const left_next = left.next();
816
+ const right_next = right.next();
817
+ if (left_next.done !== right_next.done)
818
+ return false;
819
+ if (left_next.done)
820
+ break;
821
+ if (!$mol_compare_deep(left_next.value, right_next.value))
822
+ return false;
823
+ }
824
+ return true;
825
+ }
826
+ function compare_set(left, right) {
827
+ if (left.size !== right.size)
828
+ return false;
829
+ return compare_iterator(left.values(), right.values());
830
+ }
831
+ function compare_map(left, right) {
832
+ if (left.size !== right.size)
833
+ return false;
834
+ return compare_iterator(left.keys(), right.keys())
835
+ && compare_iterator(left.values(), right.values());
836
+ }
837
+ function compare_pojo(left, right) {
838
+ const left_keys = Object.getOwnPropertyNames(left);
839
+ const right_keys = Object.getOwnPropertyNames(right);
840
+ if (!compare_array(left_keys, right_keys))
841
+ return false;
842
+ for (let key of left_keys) {
843
+ if (!$mol_compare_deep(left[key], right[key]))
844
+ return false;
845
+ }
846
+ const left_syms = Object.getOwnPropertySymbols(left);
847
+ const right_syms = Object.getOwnPropertySymbols(right);
848
+ if (!compare_array(left_syms, right_syms))
849
+ return false;
850
+ for (let key of left_syms) {
851
+ if (!$mol_compare_deep(left[key], right[key]))
852
+ return false;
853
+ }
854
+ return true;
855
+ }
856
+ function compare_primitive(left, right) {
857
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
858
+ }
859
+ })($ || ($ = {}));
860
+
861
+ ;
862
+ "use strict";
863
+ var $;
864
+ (function ($) {
865
+ $mol_test({
866
+ 'nulls & undefineds'() {
867
+ $mol_assert_ok($mol_compare_deep(null, null));
868
+ $mol_assert_ok($mol_compare_deep(undefined, undefined));
869
+ $mol_assert_not($mol_compare_deep(undefined, null));
870
+ $mol_assert_not($mol_compare_deep({}, null));
871
+ },
872
+ 'number'() {
873
+ $mol_assert_ok($mol_compare_deep(1, 1));
874
+ $mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
875
+ $mol_assert_not($mol_compare_deep(1, 2));
876
+ $mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
877
+ $mol_assert_not($mol_compare_deep(Object(1), Object(2)));
878
+ },
879
+ 'POJO'() {
880
+ $mol_assert_ok($mol_compare_deep({}, {}));
881
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
882
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
883
+ $mol_assert_not($mol_compare_deep({}, { a: undefined }));
884
+ $mol_assert_not($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
885
+ $mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
886
+ $mol_assert_ok($mol_compare_deep(Object.create(null), Object.create(null)));
887
+ },
888
+ 'Array'() {
889
+ $mol_assert_ok($mol_compare_deep([], []));
890
+ $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
891
+ $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
892
+ $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
893
+ $mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
894
+ $mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
895
+ },
896
+ 'Non POJO are different'() {
897
+ class Thing extends Object {
898
+ }
899
+ $mol_assert_not($mol_compare_deep(new Thing, new Thing));
900
+ $mol_assert_not($mol_compare_deep(() => 1, () => 1));
901
+ $mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
902
+ },
903
+ 'POJO with symbols'() {
904
+ const sym = Symbol();
905
+ $mol_assert_ok($mol_compare_deep({ [sym]: true }, { [sym]: true }));
906
+ $mol_assert_not($mol_compare_deep({ [Symbol()]: true }, { [Symbol()]: true }));
907
+ },
908
+ 'same POJOs with cyclic reference'() {
909
+ const a = { foo: {} };
910
+ a['self'] = a;
911
+ const b = { foo: {} };
912
+ b['self'] = b;
913
+ $mol_assert_ok($mol_compare_deep(a, b));
914
+ },
915
+ 'same POJOs with cyclic reference with cache warmup'() {
916
+ const obj1 = { test: 1, obj3: null };
917
+ const obj1_copy = { test: 1, obj3: null };
918
+ const obj2 = { test: 2, obj1 };
919
+ const obj2_copy = { test: 2, obj1: obj1_copy };
920
+ const obj3 = { test: 3, obj2 };
921
+ const obj3_copy = { test: 3, obj2: obj2_copy };
922
+ obj1.obj3 = obj3;
923
+ obj1_copy.obj3 = obj3_copy;
924
+ $mol_assert_not($mol_compare_deep(obj1, {}));
925
+ $mol_assert_not($mol_compare_deep(obj2, {}));
926
+ $mol_assert_not($mol_compare_deep(obj3, {}));
927
+ $mol_assert_ok($mol_compare_deep(obj3, obj3_copy));
928
+ },
929
+ 'Date'() {
930
+ $mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
931
+ $mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
932
+ },
933
+ 'RegExp'() {
934
+ $mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
935
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
936
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
937
+ },
938
+ 'Error'() {
939
+ $mol_assert_not($mol_compare_deep(new Error('xxx'), new Error('xxx')));
940
+ const fail = (message) => new Error(message);
941
+ $mol_assert_ok($mol_compare_deep(...['xxx', 'xxx'].map(msg => new Error(msg))));
942
+ $mol_assert_not($mol_compare_deep(...['xxx', 'yyy'].map(msg => new Error(msg))));
943
+ },
944
+ 'Map'() {
945
+ $mol_assert_ok($mol_compare_deep(new Map, new Map));
946
+ $mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
947
+ $mol_assert_ok($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
948
+ $mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
949
+ $mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[3], 2]])));
950
+ },
951
+ 'Set'() {
952
+ $mol_assert_ok($mol_compare_deep(new Set, new Set));
953
+ $mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
954
+ $mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
955
+ },
956
+ 'Uint8Array'() {
957
+ $mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
958
+ $mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
959
+ $mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
960
+ },
961
+ 'DataView'() {
962
+ $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array().buffer), new DataView(new Uint8Array().buffer)));
963
+ $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([0]).buffer)));
964
+ $mol_assert_not($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([1]).buffer)));
965
+ },
966
+ 'Serializale'() {
967
+ class User {
968
+ name;
969
+ rand;
970
+ constructor(name, rand = Math.random()) {
971
+ this.name = name;
972
+ this.rand = rand;
973
+ }
974
+ [Symbol.toPrimitive](mode) {
975
+ return this.name;
976
+ }
977
+ }
978
+ $mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
979
+ $mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
980
+ },
981
+ 'Iterable'() {
982
+ $mol_assert_ok($mol_compare_deep(new URLSearchParams({ foo: 'bar' }), new URLSearchParams({ foo: 'bar' })));
983
+ $mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx' }), new URLSearchParams({ foo: 'yyy' })));
984
+ $mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx', bar: 'yyy' }), new URLSearchParams({ bar: 'yyy', foo: 'xxx' })));
985
+ },
986
+ });
987
+ })($ || ($ = {}));
988
+
989
+ ;
990
+ "use strict";
991
+ var $;
992
+ (function ($) {
993
+ $['devtoolsFormatters'] ||= [];
994
+ function $mol_dev_format_register(config) {
995
+ $['devtoolsFormatters'].push(config);
996
+ }
997
+ $.$mol_dev_format_register = $mol_dev_format_register;
998
+ $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
999
+ $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
1000
+ function $mol_dev_format_button(label, click) {
1001
+ return $mol_dev_format_auto({
1002
+ [$.$mol_dev_format_head]() {
1003
+ return $.$mol_dev_format_span({ color: 'cornflowerblue' }, label);
1004
+ },
1005
+ [$.$mol_dev_format_body]() {
1006
+ Promise.resolve().then(click);
1007
+ return $.$mol_dev_format_span({});
1008
+ }
1009
+ });
1010
+ }
1011
+ $mol_dev_format_register({
1012
+ header: (val, config = false) => {
1013
+ if (config)
1014
+ return null;
1015
+ if (!val)
1016
+ return null;
1017
+ if ($.$mol_dev_format_head in val) {
1018
+ try {
1019
+ return val[$.$mol_dev_format_head]();
1020
+ }
1021
+ catch (error) {
1022
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
1023
+ }
1024
+ }
1025
+ if (typeof val === 'function') {
1026
+ return $mol_dev_format_native(val);
1027
+ }
1028
+ if (val instanceof Error) {
1029
+ return $.$mol_dev_format_span({}, $mol_dev_format_native(val), ' ', $mol_dev_format_button('throw', () => $mol_fail_hidden(val)));
1030
+ }
1031
+ if (val instanceof Promise) {
1032
+ return $.$mol_dev_format_shade($mol_dev_format_native(val), ' ', val[Symbol.toStringTag] ?? '');
1033
+ }
1034
+ if (Symbol.toStringTag in val) {
1035
+ return $mol_dev_format_native(val);
1036
+ }
1037
+ return null;
1038
+ },
1039
+ hasBody: (val, config = false) => {
1040
+ if (config)
1041
+ return false;
1042
+ if (!val)
1043
+ return false;
1044
+ if (val[$.$mol_dev_format_body])
1045
+ return true;
1046
+ return false;
1047
+ },
1048
+ body: (val, config = false) => {
1049
+ if (config)
1050
+ return null;
1051
+ if (!val)
1052
+ return null;
1053
+ if ($.$mol_dev_format_body in val) {
1054
+ try {
1055
+ return val[$.$mol_dev_format_body]();
1056
+ }
1057
+ catch (error) {
1058
+ return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
1059
+ }
1060
+ }
1061
+ return null;
1062
+ },
1063
+ });
1064
+ function $mol_dev_format_native(obj) {
1065
+ if (typeof obj === 'undefined')
1066
+ return $.$mol_dev_format_shade('undefined');
1067
+ return [
1068
+ 'object',
1069
+ {
1070
+ object: obj,
1071
+ config: true,
1072
+ },
1073
+ ];
1074
+ }
1075
+ $.$mol_dev_format_native = $mol_dev_format_native;
1076
+ function $mol_dev_format_auto(obj) {
1077
+ if (obj == null)
1078
+ return $.$mol_dev_format_shade(String(obj));
1079
+ return [
1080
+ 'object',
1081
+ {
1082
+ object: obj,
1083
+ config: false,
1084
+ },
1085
+ ];
1086
+ }
1087
+ $.$mol_dev_format_auto = $mol_dev_format_auto;
1088
+ function $mol_dev_format_element(element, style, ...content) {
1089
+ const styles = [];
1090
+ for (let key in style)
1091
+ styles.push(`${key} : ${style[key]}`);
1092
+ return [
1093
+ element,
1094
+ {
1095
+ style: styles.join(' ; '),
1096
+ },
1097
+ ...content,
1098
+ ];
1099
+ }
1100
+ $.$mol_dev_format_element = $mol_dev_format_element;
1101
+ $.$mol_dev_format_span = $mol_dev_format_element.bind(null, 'span');
1102
+ $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
1103
+ $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
1104
+ $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
1105
+ $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
1106
+ $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
1107
+ $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
1108
+ $.$mol_dev_format_accent = $.$mol_dev_format_span.bind(null, {
1109
+ 'color': 'magenta',
1110
+ });
1111
+ $.$mol_dev_format_strong = $.$mol_dev_format_span.bind(null, {
1112
+ 'font-weight': 'bold',
1113
+ });
1114
+ $.$mol_dev_format_string = $.$mol_dev_format_span.bind(null, {
1115
+ 'color': 'green',
1116
+ });
1117
+ $.$mol_dev_format_shade = $.$mol_dev_format_span.bind(null, {
1118
+ 'color': 'gray',
1119
+ });
1120
+ $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
1121
+ 'margin-left': '13px'
1122
+ });
1123
+ class Stack extends Array {
1124
+ toString() {
1125
+ return this.join('\n');
1126
+ }
1127
+ }
1128
+ class Call extends Object {
1129
+ type;
1130
+ function;
1131
+ method;
1132
+ eval;
1133
+ source;
1134
+ offset;
1135
+ pos;
1136
+ object;
1137
+ flags;
1138
+ [Symbol.toStringTag];
1139
+ constructor(call) {
1140
+ super();
1141
+ this.type = call.getTypeName() ?? '';
1142
+ this.function = call.getFunctionName() ?? '';
1143
+ this.method = call.getMethodName() ?? '';
1144
+ if (this.method === this.function)
1145
+ this.method = '';
1146
+ this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
1147
+ this.eval = call.getEvalOrigin() ?? '';
1148
+ this.source = call.getScriptNameOrSourceURL() ?? '';
1149
+ this.object = call.getThis();
1150
+ this.offset = call.getPosition();
1151
+ const flags = [];
1152
+ if (call.isAsync())
1153
+ flags.push('async');
1154
+ if (call.isConstructor())
1155
+ flags.push('constructor');
1156
+ if (call.isEval())
1157
+ flags.push('eval');
1158
+ if (call.isNative())
1159
+ flags.push('native');
1160
+ if (call.isPromiseAll())
1161
+ flags.push('PromiseAll');
1162
+ if (call.isToplevel())
1163
+ flags.push('top');
1164
+ this.flags = flags;
1165
+ const type = this.type ? this.type + '.' : '';
1166
+ const func = this.function || '<anon>';
1167
+ const method = this.method ? ' [' + this.method + '] ' : '';
1168
+ this[Symbol.toStringTag] = `${type}${func}${method}`;
1169
+ }
1170
+ [Symbol.toPrimitive]() {
1171
+ return this.toString();
1172
+ }
1173
+ toString() {
1174
+ const object = this.object || '';
1175
+ const label = this[Symbol.toStringTag];
1176
+ const source = `${this.source}:${this.pos.join(':')} #${this.offset}`;
1177
+ return `\tat ${object}${label} (${source})`;
1178
+ }
1179
+ [$.$mol_dev_format_head]() {
1180
+ return $.$mol_dev_format_div({}, $mol_dev_format_native(this), $.$mol_dev_format_shade(' '), ...this.object ? [
1181
+ $mol_dev_format_native(this.object),
1182
+ ] : [], ...this.method ? [$.$mol_dev_format_shade(' ', ' [', this.method, ']')] : [], $.$mol_dev_format_shade(' ', this.flags.join(', ')));
1183
+ }
1184
+ }
1185
+ Error.prepareStackTrace ??= (error, stack) => new Stack(...stack.map(call => new Call(call)));
1186
+ })($ || ($ = {}));
1187
+
1188
+ ;
1189
+ "use strict";
1190
+ var $;
1191
+ (function ($) {
1192
+ function $mol_assert_ok(value) {
1193
+ if (value)
1194
+ return;
1195
+ $mol_fail(new Error(`${value} ≠ true`));
1196
+ }
1197
+ $.$mol_assert_ok = $mol_assert_ok;
1198
+ function $mol_assert_not(value) {
1199
+ if (!value)
1200
+ return;
1201
+ $mol_fail(new Error(`${value} ≠ false`));
1202
+ }
1203
+ $.$mol_assert_not = $mol_assert_not;
1204
+ function $mol_assert_fail(handler, ErrorRight) {
1205
+ const fail = $.$mol_fail;
1206
+ try {
1207
+ $.$mol_fail = $.$mol_fail_hidden;
1208
+ handler();
1209
+ }
1210
+ catch (error) {
1211
+ $.$mol_fail = fail;
1212
+ if (typeof ErrorRight === 'string') {
1213
+ $mol_assert_equal(error.message ?? error, ErrorRight);
1214
+ }
1215
+ else {
1216
+ $mol_assert_equal(error instanceof ErrorRight, true);
1217
+ }
1218
+ return error;
1219
+ }
1220
+ finally {
1221
+ $.$mol_fail = fail;
1222
+ }
1223
+ $mol_fail(new Error('Not failed', { cause: { expect: ErrorRight } }));
1224
+ }
1225
+ $.$mol_assert_fail = $mol_assert_fail;
1226
+ function $mol_assert_like(...args) {
1227
+ $mol_assert_equal(...args);
1228
+ }
1229
+ $.$mol_assert_like = $mol_assert_like;
1230
+ function $mol_assert_unique(...args) {
1231
+ for (let i = 0; i < args.length; ++i) {
1232
+ for (let j = 0; j < args.length; ++j) {
1233
+ if (i === j)
1234
+ continue;
1235
+ if (!$mol_compare_deep(args[i], args[j]))
1236
+ continue;
1237
+ return $mol_fail(new Error(`Uniquesess assertion failure`, { cause: { [i]: args[i], [i]: args[i] } }));
1238
+ }
1239
+ }
1240
+ }
1241
+ $.$mol_assert_unique = $mol_assert_unique;
1242
+ function $mol_assert_equal(...args) {
1243
+ for (let i = 1; i < args.length; ++i) {
1244
+ if ($mol_compare_deep(args[0], args[i]))
1245
+ continue;
1246
+ return $mol_fail(new Error(`Equality assertion failure`, { cause: { 0: args[0], [i]: args[i] } }));
1247
+ }
1248
+ }
1249
+ $.$mol_assert_equal = $mol_assert_equal;
1250
+ })($ || ($ = {}));
1251
+
1252
+ ;
1253
+ "use strict";
1254
+ var $;
1255
+ (function ($) {
1256
+ $mol_test({
1257
+ 'must be false'() {
1258
+ $mol_assert_not(0);
1259
+ },
1260
+ 'must be true'() {
1261
+ $mol_assert_ok(1);
1262
+ },
1263
+ 'two must be equal'() {
1264
+ $mol_assert_equal(2, 2);
1265
+ },
1266
+ 'three must be equal'() {
1267
+ $mol_assert_equal(2, 2, 2);
1268
+ },
1269
+ 'two must be unique'() {
1270
+ $mol_assert_unique([2], [3]);
1271
+ },
1272
+ 'three must be unique'() {
1273
+ $mol_assert_unique([1], [2], [3]);
1274
+ },
1275
+ 'two must be alike'() {
1276
+ $mol_assert_equal([3], [3]);
1277
+ },
1278
+ 'three must be alike'() {
1279
+ $mol_assert_equal([3], [3], [3]);
1280
+ },
1281
+ 'two object must be alike'() {
1282
+ $mol_assert_equal({ a: 1 }, { a: 1 });
1283
+ },
1284
+ 'three object must be alike'() {
1285
+ $mol_assert_equal({ a: 1 }, { a: 1 }, { a: 1 });
1286
+ },
1287
+ });
1288
+ })($ || ($ = {}));
1289
+
1290
+ ;
1291
+ "use strict";
1292
+ var $;
1293
+ (function ($) {
1294
+ let buf = new Uint8Array(2 ** 12);
1295
+ function $mol_charset_buffer(size) {
1296
+ if (buf.byteLength < size)
1297
+ buf = new Uint8Array(size);
1298
+ return buf;
1299
+ }
1300
+ $.$mol_charset_buffer = $mol_charset_buffer;
1301
+ })($ || ($ = {}));
1302
+
1303
+ ;
1304
+ "use strict";
1305
+ var $;
1306
+ (function ($) {
1307
+ function $mol_charset_encode(str) {
1308
+ const buf = $mol_charset_buffer(str.length * 3);
1309
+ return buf.slice(0, $mol_charset_encode_to(str, buf));
1310
+ }
1311
+ $.$mol_charset_encode = $mol_charset_encode;
1312
+ function $mol_charset_encode_to(str, buf, from = 0) {
1313
+ let pos = from;
1314
+ for (let i = 0; i < str.length; i++) {
1315
+ let code = str.charCodeAt(i);
1316
+ if (code < 0x80) {
1317
+ buf[pos++] = code;
1318
+ }
1319
+ else if (code < 0x800) {
1320
+ buf[pos++] = 0xc0 | (code >> 6);
1321
+ buf[pos++] = 0x80 | (code & 0x3f);
1322
+ }
1323
+ else if (code < 0xd800 || code >= 0xe000) {
1324
+ buf[pos++] = 0xe0 | (code >> 12);
1325
+ buf[pos++] = 0x80 | ((code >> 6) & 0x3f);
1326
+ buf[pos++] = 0x80 | (code & 0x3f);
1327
+ }
1328
+ else {
1329
+ const point = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
1330
+ buf[pos++] = 0xf0 | (point >> 18);
1331
+ buf[pos++] = 0x80 | ((point >> 12) & 0x3f);
1332
+ buf[pos++] = 0x80 | ((point >> 6) & 0x3f);
1333
+ buf[pos++] = 0x80 | (point & 0x3f);
1334
+ }
1335
+ }
1336
+ return pos - from;
1337
+ }
1338
+ $.$mol_charset_encode_to = $mol_charset_encode_to;
1339
+ function $mol_charset_encode_size(str) {
1340
+ let size = 0;
1341
+ for (let i = 0; i < str.length; i++) {
1342
+ let code = str.charCodeAt(i);
1343
+ if (code < 0x80)
1344
+ size += 1;
1345
+ else if (code < 0x800)
1346
+ size += 2;
1347
+ else if (code < 0xd800 || code >= 0xe000)
1348
+ size += 3;
1349
+ else
1350
+ size += 4;
1351
+ }
1352
+ return size;
1353
+ }
1354
+ $.$mol_charset_encode_size = $mol_charset_encode_size;
1355
+ })($ || ($ = {}));
1356
+
1357
+ ;
1358
+ "use strict";
1359
+ var $;
1360
+ (function ($) {
1361
+ $mol_test({
1362
+ 'encode empty'() {
1363
+ $mol_assert_equal($mol_charset_encode(''), new Uint8Array([]));
1364
+ },
1365
+ 'encode 1 octet'() {
1366
+ $mol_assert_equal($mol_charset_encode('F'), new Uint8Array([0x46]));
1367
+ },
1368
+ 'encode 2 octet'() {
1369
+ $mol_assert_equal($mol_charset_encode('Б'), new Uint8Array([0xd0, 0x91]));
1370
+ },
1371
+ 'encode 3 octet'() {
1372
+ $mol_assert_equal($mol_charset_encode('ह'), new Uint8Array([0xe0, 0xa4, 0xb9]));
1373
+ },
1374
+ 'encode 4 octet'() {
1375
+ $mol_assert_equal($mol_charset_encode('𐍈'), new Uint8Array([0xf0, 0x90, 0x8d, 0x88]));
1376
+ },
1377
+ 'encode surrogate pair'() {
1378
+ $mol_assert_equal($mol_charset_encode('😀'), new Uint8Array([0xf0, 0x9f, 0x98, 0x80]));
1379
+ },
1380
+ });
1381
+ })($ || ($ = {}));
1382
+
1383
+ ;
1384
+ "use strict";
1385
+ var $;
1386
+ (function ($) {
1387
+ function $mol_log3_area_lazy(event) {
1388
+ const self = this.$;
1389
+ const stack = self.$mol_log3_stack;
1390
+ const deep = stack.length;
1391
+ let logged = false;
1392
+ stack.push(() => {
1393
+ logged = true;
1394
+ self.$mol_log3_area.call(self, event);
1395
+ });
1396
+ return () => {
1397
+ if (logged)
1398
+ self.console.groupEnd();
1399
+ if (stack.length > deep)
1400
+ stack.length = deep;
1401
+ };
1402
+ }
1403
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1404
+ $.$mol_log3_stack = [];
1405
+ })($ || ($ = {}));
1406
+
1407
+ ;
1408
+ "use strict";
1409
+
1410
+ ;
1411
+ "use strict";
1412
+
1413
+ ;
1414
+ "use strict";
1415
+
1416
+ ;
1417
+ "use strict";
1418
+
1419
+ ;
1420
+ "use strict";
1421
+ var $;
1422
+ (function ($) {
1423
+ function $mol_log3_web_make(level, color) {
1424
+ return function $mol_log3_logger(event) {
1425
+ const pending = this.$mol_log3_stack.pop();
1426
+ if (pending)
1427
+ pending();
1428
+ let tpl = '%c';
1429
+ const chunks = Object.entries(event);
1430
+ for (let i = 0; i < chunks.length; ++i) {
1431
+ tpl += (typeof chunks[i][1] === 'string') ? '%s: %s\n' : '%s: %o\n';
1432
+ }
1433
+ const style = `color:${color};font-weight:bolder`;
1434
+ this.console[level](tpl.trim(), style, ...[].concat(...chunks));
1435
+ const self = this;
1436
+ return () => self.console.groupEnd();
1437
+ };
1438
+ }
1439
+ $.$mol_log3_web_make = $mol_log3_web_make;
1440
+ $.$mol_log3_come = $mol_log3_web_make('info', 'royalblue');
1441
+ $.$mol_log3_done = $mol_log3_web_make('info', 'forestgreen');
1442
+ $.$mol_log3_fail = $mol_log3_web_make('error', 'orangered');
1443
+ $.$mol_log3_warn = $mol_log3_web_make('warn', 'goldenrod');
1444
+ $.$mol_log3_rise = $mol_log3_web_make('log', 'magenta');
1445
+ $.$mol_log3_area = $mol_log3_web_make('group', 'cyan');
1446
+ })($ || ($ = {}));
1447
+
1448
+ ;
1449
+ "use strict";
1450
+ var $;
1451
+ (function ($_1) {
1452
+ $mol_test_mocks.push($ => {
1453
+ $.$mol_log3_come = () => { };
1454
+ $.$mol_log3_done = () => { };
1455
+ $.$mol_log3_fail = () => { };
1456
+ $.$mol_log3_warn = () => { };
1457
+ $.$mol_log3_rise = () => { };
1458
+ $.$mol_log3_area = () => () => { };
1459
+ });
1460
+ })($ || ($ = {}));
1461
+
1462
+ ;
1463
+ "use strict";
1464
+ var $;
1465
+ (function ($_1) {
1466
+ $mol_test({
1467
+ 'FQN of anon function'($) {
1468
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
1469
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
1470
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
1471
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
1472
+ },
1473
+ });
1474
+ })($ || ($ = {}));
1475
+
1476
+ ;
1477
+ "use strict";
1478
+ var $;
1479
+ (function ($) {
1480
+ const png = new Uint8Array([0x1a, 0x0a, 0x00, 0x49, 0x48, 0x78, 0xda]);
1481
+ $mol_test({
1482
+ 'base64 encode string'() {
1483
+ $mol_assert_equal($mol_base64_encode($mol_charset_encode('Hello, ΧΨΩЫ')), 'SGVsbG8sIM6nzqjOqdCr');
1484
+ },
1485
+ 'base64 encode binary'() {
1486
+ $mol_assert_equal($mol_base64_encode(png), 'GgoASUh42g==');
1487
+ },
1488
+ 'base64 encode string with plus'() {
1489
+ $mol_assert_equal($mol_base64_encode($mol_charset_encode('шоешпо')), '0YjQvtC10YjQv9C+');
1490
+ },
1491
+ });
1492
+ })($ || ($ = {}));
1493
+
1494
+ ;
1495
+ "use strict";
1496
+ var $;
1497
+ (function ($) {
1498
+ const png = new Uint8Array([0x1a, 0x0a, 0x00, 0x49, 0x48, 0x78, 0xda]);
1499
+ const with_plus = new TextEncoder().encode('шоешпо');
1500
+ $mol_test({
1501
+ 'base64 decode string'() {
1502
+ $mol_assert_equal($mol_base64_decode('SGVsbG8sIM6nzqjOqdCr'), new TextEncoder().encode('Hello, ΧΨΩЫ'));
1503
+ },
1504
+ 'base64 decode binary'() {
1505
+ $mol_assert_equal($mol_base64_decode('GgoASUh42g=='), png);
1506
+ },
1507
+ 'base64 decode binary - without equals'() {
1508
+ $mol_assert_equal($mol_base64_decode('GgoASUh42g'), png);
1509
+ },
1510
+ 'base64 decode with plus'() {
1511
+ $mol_assert_equal($mol_base64_decode('0YjQvtC10YjQv9C+'), with_plus);
1512
+ },
1513
+ });
1514
+ })($ || ($ = {}));
1515
+
1516
+ ;
1517
+ "use strict";
1518
+ var $;
1519
+ (function ($) {
1520
+ $mol_test({
1521
+ 'get'() {
1522
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1523
+ $mol_assert_equal(proxy.foo, 777);
1524
+ },
1525
+ 'has'() {
1526
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1527
+ $mol_assert_equal('foo' in proxy, true);
1528
+ },
1529
+ 'set'() {
1530
+ const target = { foo: 777 };
1531
+ const proxy = $mol_delegate({}, () => target);
1532
+ proxy.foo = 123;
1533
+ $mol_assert_equal(target.foo, 123);
1534
+ },
1535
+ 'getOwnPropertyDescriptor'() {
1536
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1537
+ $mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
1538
+ value: 777,
1539
+ writable: true,
1540
+ enumerable: true,
1541
+ configurable: true,
1542
+ });
1543
+ },
1544
+ 'ownKeys'() {
1545
+ const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
1546
+ $mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
1547
+ },
1548
+ 'getPrototypeOf'() {
1549
+ class Foo {
1550
+ }
1551
+ const proxy = $mol_delegate({}, () => new Foo);
1552
+ $mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
1553
+ },
1554
+ 'setPrototypeOf'() {
1555
+ class Foo {
1556
+ }
1557
+ const target = {};
1558
+ const proxy = $mol_delegate({}, () => target);
1559
+ Object.setPrototypeOf(proxy, Foo.prototype);
1560
+ $mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
1561
+ },
1562
+ 'instanceof'() {
1563
+ class Foo {
1564
+ }
1565
+ const proxy = $mol_delegate({}, () => new Foo);
1566
+ $mol_assert_ok(proxy instanceof Foo);
1567
+ $mol_assert_ok(proxy instanceof $mol_delegate);
1568
+ },
1569
+ 'autobind'() {
1570
+ class Foo {
1571
+ }
1572
+ const proxy = $mol_delegate({}, () => new Foo);
1573
+ $mol_assert_ok(proxy instanceof Foo);
1574
+ $mol_assert_ok(proxy instanceof $mol_delegate);
1575
+ },
1576
+ });
1577
+ })($ || ($ = {}));
1578
+
1579
+ ;
1580
+ "use strict";
1581
+
1582
+ ;
1583
+ "use strict";
1584
+ var $;
1585
+ (function ($) {
1586
+ $mol_test({
1587
+ 'run callback'() {
1588
+ class Plus1 extends $mol_wrapper {
1589
+ static wrap(task) {
1590
+ return function (...args) {
1591
+ return task.call(this, ...args) + 1;
1592
+ };
1593
+ }
1594
+ }
1595
+ $mol_assert_equal(Plus1.run(() => 2), 3);
1596
+ },
1597
+ 'wrap function'() {
1598
+ class Plus1 extends $mol_wrapper {
1599
+ static wrap(task) {
1600
+ return function (...args) {
1601
+ return task.call(this, ...args) + 1;
1602
+ };
1603
+ }
1604
+ }
1605
+ const obj = {
1606
+ level: 2,
1607
+ pow: Plus1.func(function (a) {
1608
+ return a ** this.level;
1609
+ })
1610
+ };
1611
+ $mol_assert_equal(obj.pow(2), 5);
1612
+ },
1613
+ 'decorate field getter'() {
1614
+ class Plus1 extends $mol_wrapper {
1615
+ static last = 0;
1616
+ static wrap(task) {
1617
+ return function (...args) {
1618
+ return Plus1.last = (task.call(this, ...args) || 0) + 1;
1619
+ };
1620
+ }
1621
+ }
1622
+ class Foo {
1623
+ static get two() {
1624
+ return 1;
1625
+ }
1626
+ static set two(next) { }
1627
+ }
1628
+ __decorate([
1629
+ Plus1.field
1630
+ ], Foo, "two", null);
1631
+ $mol_assert_equal(Foo.two, 2);
1632
+ Foo.two = 3;
1633
+ $mol_assert_equal(Plus1.last, 2);
1634
+ $mol_assert_equal(Foo.two, 2);
1635
+ },
1636
+ 'decorate instance method'() {
1637
+ class Plus1 extends $mol_wrapper {
1638
+ static wrap(task) {
1639
+ return function (...args) {
1640
+ return task.call(this, ...args) + 1;
1641
+ };
1642
+ }
1643
+ }
1644
+ class Foo1 {
1645
+ level = 2;
1646
+ pow(a) {
1647
+ return a ** this.level;
1648
+ }
1649
+ }
1650
+ __decorate([
1651
+ Plus1.method
1652
+ ], Foo1.prototype, "pow", null);
1653
+ const Foo2 = Foo1;
1654
+ const foo = new Foo2;
1655
+ $mol_assert_equal(foo.pow(2), 5);
1656
+ },
1657
+ 'decorate static method'() {
1658
+ class Plus1 extends $mol_wrapper {
1659
+ static wrap(task) {
1660
+ return function (...args) {
1661
+ return task.call(this, ...args) + 1;
1662
+ };
1663
+ }
1664
+ }
1665
+ class Foo {
1666
+ static level = 2;
1667
+ static pow(a) {
1668
+ return a ** this.level;
1669
+ }
1670
+ }
1671
+ __decorate([
1672
+ Plus1.method
1673
+ ], Foo, "pow", null);
1674
+ $mol_assert_equal(Foo.pow(2), 5);
1675
+ },
1676
+ 'decorate class'() {
1677
+ class BarInc extends $mol_wrapper {
1678
+ static wrap(task) {
1679
+ return function (...args) {
1680
+ const foo = task.call(this, ...args);
1681
+ foo.bar++;
1682
+ return foo;
1683
+ };
1684
+ }
1685
+ }
1686
+ let Foo = class Foo {
1687
+ bar;
1688
+ constructor(bar) {
1689
+ this.bar = bar;
1690
+ }
1691
+ };
1692
+ Foo = __decorate([
1693
+ BarInc.class
1694
+ ], Foo);
1695
+ $mol_assert_equal(new Foo(2).bar, 3);
1696
+ },
1697
+ });
1698
+ })($ || ($ = {}));
1699
+
1700
+ ;
1701
+ "use strict";
1702
+ var $;
1703
+ (function ($) {
1704
+ $mol_test({
1705
+ 'memoize field'() {
1706
+ class Foo {
1707
+ static one = 1;
1708
+ static get two() {
1709
+ return ++this.one;
1710
+ }
1711
+ static set two(next) { }
1712
+ }
1713
+ __decorate([
1714
+ $mol_memo.field
1715
+ ], Foo, "two", null);
1716
+ $mol_assert_equal(Foo.two, 2);
1717
+ $mol_assert_equal(Foo.two, 2);
1718
+ Foo.two = 3;
1719
+ $mol_assert_equal(Foo.two, 3);
1720
+ $mol_assert_equal(Foo.two, 3);
1721
+ },
1722
+ });
1723
+ })($ || ($ = {}));
1724
+
1725
+ ;
1726
+ "use strict";
1727
+ var $;
1728
+ (function ($) {
1729
+ $mol_test({
1730
+ async 'str & bin sizes'() {
1731
+ const signer = await $$.$mol_crypto2_signer.generate();
1732
+ const auditor = signer.auditor();
1733
+ $mol_assert_equal(signer.toStringPrivate().length, $mol_crypto2_signer.size_str);
1734
+ $mol_assert_equal(auditor.toString().length, $mol_crypto2_auditor.size_str);
1735
+ $mol_assert_equal(signer.asArrayPrivate().length, $mol_crypto2_signer.size_bin);
1736
+ $mol_assert_equal(auditor.asArray().length, $mol_crypto2_auditor.size_bin);
1737
+ const data = new Uint8Array([1, 2, 3]);
1738
+ const sign = await signer.sign(data);
1739
+ $mol_assert_equal(sign.byteLength, $mol_crypto2_signer.size_sign);
1740
+ },
1741
+ async 'verify self signed with auto generated key'() {
1742
+ const Alice = await $$.$mol_crypto2_signer.generate();
1743
+ const data = new Uint8Array([1, 2, 3]);
1744
+ const sign = await Alice.sign(data);
1745
+ $mol_assert_equal(true, await Alice.auditor().verify(data, sign));
1746
+ },
1747
+ async 'verify signed with str exported auto generated key'() {
1748
+ const Alice = await $$.$mol_crypto2_signer.generate();
1749
+ const data = new Uint8Array([1, 2, 3]);
1750
+ const Bella = $mol_crypto2_signer.from(Alice.toString() + Alice.toStringPrivate());
1751
+ const sign = await Bella.sign(data);
1752
+ const Catie = $mol_crypto2_auditor.from(Alice.auditor().toString());
1753
+ $mol_assert_equal(true, await Catie.verify(data, sign));
1754
+ const Diana = $mol_crypto2_auditor.from(Alice.toString());
1755
+ $mol_assert_equal(true, await Diana.verify(data, sign));
1756
+ },
1757
+ async 'verify signed with bin exported auto generated key'() {
1758
+ const Alice = await $$.$mol_crypto2_signer.generate();
1759
+ const data = new Uint8Array([1, 2, 3]);
1760
+ const Bella = $mol_crypto2_signer.from(new Uint8Array([...Alice.asArray(), ...Alice.asArrayPrivate()]));
1761
+ const sign = await Bella.sign(data);
1762
+ const Catie = $mol_crypto2_auditor.from(Alice.auditor().asArray());
1763
+ $mol_assert_equal(true, await Catie.verify(data, sign));
1764
+ const Diana = $mol_crypto2_auditor.from(Alice.asArray());
1765
+ $mol_assert_equal(true, await Diana.verify(data, sign));
1766
+ },
1767
+ });
1768
+ })($ || ($ = {}));
1769
+
1770
+ ;
1771
+ "use strict";
1772
+ var $;
1773
+ (function ($) {
1774
+ $mol_test({
1775
+ async 'Sizes'() {
1776
+ const secret = $mol_crypto_sacred.make();
1777
+ const key = secret.asArray();
1778
+ $mol_assert_equal(key.byteLength, $mol_crypto_sacred.size);
1779
+ const data = new Uint8Array([1, 2, 3]);
1780
+ const salt = $mol_crypto_salt();
1781
+ const closed = await secret.encrypt(data, salt);
1782
+ $mol_assert_equal(closed.byteLength, $mol_crypto_sacred.size);
1783
+ const self_closed = await secret.close(secret, salt);
1784
+ $mol_assert_equal(self_closed.byteLength, $mol_crypto_sacred.size);
1785
+ },
1786
+ async 'Decrypt self encrypted'() {
1787
+ const secret = $mol_crypto_sacred.make();
1788
+ const data = new Uint8Array([1, 2, 3]);
1789
+ const salt = $mol_crypto_salt();
1790
+ const closed = await secret.encrypt(data, salt);
1791
+ const opened = await secret.decrypt(closed, salt);
1792
+ $mol_assert_equal(data, opened);
1793
+ },
1794
+ async 'Decrypt encrypted with exported key'() {
1795
+ const data = new Uint8Array([1, 2, 3]);
1796
+ const salt = $mol_crypto_salt();
1797
+ const Alice = $mol_crypto_sacred.make();
1798
+ const closed = await Alice.encrypt(data, salt);
1799
+ const Bob = $mol_crypto_sacred.from(Alice.asArray());
1800
+ const opened = await Bob.decrypt(closed, salt);
1801
+ $mol_assert_equal(data, opened);
1802
+ },
1803
+ });
1804
+ })($ || ($ = {}));
1805
+
1806
+ ;
1807
+ "use strict";
1808
+ var $;
1809
+ (function ($) {
1810
+ $mol_test({
1811
+ async 'str & bin sizes'() {
1812
+ const cipher = await $$.$mol_crypto2_cipher.generate();
1813
+ const socket = cipher.socket();
1814
+ $mol_assert_equal(cipher.toStringPrivate().length, $mol_crypto2_cipher.size_str);
1815
+ $mol_assert_equal(socket.toString().length, $mol_crypto2_socket.size_str);
1816
+ $mol_assert_equal(cipher.asArrayPrivate().length, $mol_crypto2_cipher.size_bin);
1817
+ $mol_assert_equal(socket.asArray().length, $mol_crypto2_socket.size_bin);
1818
+ const secret = await cipher.secret(socket);
1819
+ $mol_assert_equal(secret.byteLength, $mol_crypto2_cipher.size_secret);
1820
+ },
1821
+ async 'Shared secret from public & private keys'() {
1822
+ const A = await $mol_crypto2_cipher.generate();
1823
+ const B = await $mol_crypto2_cipher.generate();
1824
+ const SA = await A.secret(B.socket());
1825
+ const SB = await B.secret(A.socket());
1826
+ $mol_assert_equal(SA.asArray(), SB.asArray());
1827
+ },
1828
+ });
1829
+ })($ || ($ = {}));
1830
+
1831
+ ;
1832
+ "use strict";
1833
+ var $;
1834
+ (function ($) {
1835
+ let sponge = new Uint32Array(80);
1836
+ function $mol_crypto_hash(input) {
1837
+ const data = input instanceof Uint8Array
1838
+ ? input
1839
+ : new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
1840
+ const bits = data.byteLength << 3;
1841
+ const kbits = bits >> 5;
1842
+ const kword = 0x80 << (24 - bits & 0b11111);
1843
+ const bytes = 16 + (bits + 64 >>> 9 << 4);
1844
+ const klens = bytes - 1;
1845
+ const words = new DataView(data.buffer, data.byteOffset, data.byteLength >> 2 << 2);
1846
+ let tail = 0;
1847
+ for (let i = words.byteLength; i < data.length; ++i) {
1848
+ tail |= data[i] << ((3 - i & 0b11) << 3);
1849
+ }
1850
+ const hash = new Int32Array([1732584193, -271733879, -1732584194, 271733878, -1009589776]);
1851
+ for (let i = 0; i < bytes; i += 16) {
1852
+ let h0 = hash[0];
1853
+ let h1 = hash[1];
1854
+ let h2 = hash[2];
1855
+ let h3 = hash[3];
1856
+ let h4 = hash[4];
1857
+ for (let j = 0; j < 16; ++j) {
1858
+ const k = i + j;
1859
+ if (k === klens) {
1860
+ sponge[j] = bits;
1861
+ }
1862
+ else {
1863
+ const pos = k << 2;
1864
+ let word = pos === words.byteLength ? tail :
1865
+ pos > words.byteLength ? 0 :
1866
+ words.getInt32(pos, false);
1867
+ if (k === kbits)
1868
+ word |= kword;
1869
+ sponge[j] = word;
1870
+ }
1871
+ const next = ((h1 & h2 | ~h1 & h3) + 1518500249 + h4 + (sponge[j] >>> 0) + ((h0 << 5) | (h0 >>> 27))) | 0;
1872
+ h4 = h3;
1873
+ h3 = h2;
1874
+ h2 = (h1 << 30) | (h1 >>> 2);
1875
+ h1 = h0;
1876
+ h0 = next;
1877
+ }
1878
+ for (let j = 16; j < 20; ++j) {
1879
+ const shuffle = sponge[j - 3] ^ sponge[j - 8] ^ sponge[j - 14] ^ sponge[j - 16];
1880
+ sponge[j] = shuffle << 1 | shuffle >>> 31;
1881
+ const next = ((h1 & h2 | ~h1 & h3) + 1518500249 + h4 + (sponge[j] >>> 0) + ((h0 << 5) | (h0 >>> 27))) | 0;
1882
+ h4 = h3;
1883
+ h3 = h2;
1884
+ h2 = (h1 << 30) | (h1 >>> 2);
1885
+ h1 = h0;
1886
+ h0 = next;
1887
+ }
1888
+ for (let j = 20; j < 40; ++j) {
1889
+ const shuffle = sponge[j - 3] ^ sponge[j - 8] ^ sponge[j - 14] ^ sponge[j - 16];
1890
+ sponge[j] = shuffle << 1 | shuffle >>> 31;
1891
+ const next = ((h1 ^ h2 ^ h3) + 1859775393 + h4 + (sponge[j] >>> 0) + ((h0 << 5) | (h0 >>> 27))) | 0;
1892
+ h4 = h3;
1893
+ h3 = h2;
1894
+ h2 = (h1 << 30) | (h1 >>> 2);
1895
+ h1 = h0;
1896
+ h0 = next;
1897
+ }
1898
+ for (let j = 40; j < 60; ++j) {
1899
+ const shuffle = sponge[j - 3] ^ sponge[j - 8] ^ sponge[j - 14] ^ sponge[j - 16];
1900
+ sponge[j] = shuffle << 1 | shuffle >>> 31;
1901
+ const next = ((h1 & h2 | h1 & h3 | h2 & h3) - 1894007588 + h4 + (sponge[j] >>> 0) + ((h0 << 5) | (h0 >>> 27))) | 0;
1902
+ h4 = h3;
1903
+ h3 = h2;
1904
+ h2 = (h1 << 30) | (h1 >>> 2);
1905
+ h1 = h0;
1906
+ h0 = next;
1907
+ }
1908
+ for (let j = 60; j < 80; ++j) {
1909
+ const shuffle = sponge[j - 3] ^ sponge[j - 8] ^ sponge[j - 14] ^ sponge[j - 16];
1910
+ sponge[j] = shuffle << 1 | shuffle >>> 31;
1911
+ const next = ((h1 ^ h2 ^ h3) - 899497514 + h4 + (sponge[j] >>> 0) + ((h0 << 5) | (h0 >>> 27))) | 0;
1912
+ h4 = h3;
1913
+ h3 = h2;
1914
+ h2 = (h1 << 30) | (h1 >>> 2);
1915
+ h1 = h0;
1916
+ h0 = next;
1917
+ }
1918
+ hash[0] += h0;
1919
+ hash[1] += h1;
1920
+ hash[2] += h2;
1921
+ hash[3] += h3;
1922
+ hash[4] += h4;
1923
+ }
1924
+ for (let i = 0; i < 20; ++i) {
1925
+ const word = hash[i];
1926
+ hash[i] = word << 24 | word << 8 & 0xFF0000 | word >>> 8 & 0xFF00 | word >>> 24 & 0xFF;
1927
+ }
1928
+ return new Uint8Array(hash.buffer);
1929
+ }
1930
+ $.$mol_crypto_hash = $mol_crypto_hash;
1931
+ })($ || ($ = {}));
1932
+
1933
+ ;
1934
+ "use strict";
1935
+ var $;
1936
+ (function ($) {
1937
+ $mol_test({
1938
+ 'empty hash'() {
1939
+ $mol_assert_equal($mol_crypto_hash(new Uint8Array([])), new Uint8Array([218, 57, 163, 238, 94, 107, 75, 13, 50, 85, 191, 239, 149, 96, 24, 144, 175, 216, 7, 9]));
1940
+ },
1941
+ 'three bytes hash'() {
1942
+ $mol_assert_equal($mol_crypto_hash(new Uint8Array([255, 254, 253])), new Uint8Array([240, 150, 38, 243, 255, 128, 96, 0, 72, 215, 207, 228, 19, 149, 113, 52, 2, 125, 27, 77]));
1943
+ },
1944
+ 'six bytes hash'() {
1945
+ $mol_assert_equal($mol_crypto_hash(new Uint8Array([0, 255, 10, 250, 32, 128])), new Uint8Array([23, 25, 155, 181, 46, 200, 221, 83, 254, 0, 166, 68, 91, 255, 67, 140, 114, 88, 218, 155]));
1946
+ },
1947
+ 'seven bytes hash'() {
1948
+ $mol_assert_equal($mol_crypto_hash(new Uint8Array([1, 2, 3, 4, 5, 6, 7])), new Uint8Array([140, 31, 40, 252, 47, 72, 194, 113, 214, 196, 152, 240, 242, 73, 205, 222, 54, 92, 84, 197]));
1949
+ },
1950
+ 'unaligned hash'() {
1951
+ const data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
1952
+ $mol_assert_equal($mol_crypto_hash(new Uint8Array(data.buffer, 1, 7)), new Uint8Array([140, 31, 40, 252, 47, 72, 194, 113, 214, 196, 152, 240, 242, 73, 205, 222, 54, 92, 84, 197]));
1953
+ },
1954
+ async 'reference'() {
1955
+ const data = new Uint8Array([255, 254, 253]);
1956
+ $mol_assert_equal($mol_crypto_hash(data), new Uint8Array(await $mol_crypto_native.subtle.digest('SHA-1', data)));
1957
+ },
1958
+ });
1959
+ })($ || ($ = {}));
1960
+
1961
+ ;
1962
+ "use strict";
1963
+ var $;
1964
+ (function ($_1) {
1965
+ var $$;
1966
+ (function ($$) {
1967
+ $mol_test({
1968
+ async "Signing & encryption"($) {
1969
+ const Alice = await $mol_crypto2_private.generate();
1970
+ const Bella = await $mol_crypto2_private.generate();
1971
+ const secretA = await Alice.cipher().secret(Bella.socket());
1972
+ const secretB = await Bella.cipher().secret(Alice.socket());
1973
+ $mol_assert_equal(secretA, secretB);
1974
+ const data = new Uint8Array([1, 2, 3]);
1975
+ const salt = $mol_crypto_salt();
1976
+ const closed = await secretA.encrypt(data, salt);
1977
+ const digest = $mol_crypto_hash(closed);
1978
+ const sign = await Alice.signer().sign(digest);
1979
+ $mol_assert_equal(true, await Alice.auditor().verify(digest, sign));
1980
+ $mol_assert_equal(data, await secretA.decrypt(closed, salt));
1981
+ },
1982
+ async "Serial & Deserial"($) {
1983
+ const orig = await $mol_crypto2_private.generate();
1984
+ const bin = new Uint8Array([...orig.asArray(), ...orig.asArrayPrivate()]);
1985
+ const str = orig.toString() + orig.toStringPrivate();
1986
+ $mol_assert_equal(orig, $mol_crypto2_private.from(bin), $mol_crypto2_private.from(str));
1987
+ },
1988
+ });
1989
+ })($$ = $_1.$$ || ($_1.$$ = {}));
1990
+ })($ || ($ = {}));
1991
+
1992
+
1993
+ //# sourceMappingURL=web.test.js.map