mol_crypto_lib 0.1.1082 → 0.1.1084

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/node.test.js CHANGED
@@ -36,341 +36,131 @@ var $;
36
36
  "use strict";
37
37
  var $;
38
38
  (function ($) {
39
- let $mol_wire_cursor;
40
- (function ($mol_wire_cursor) {
41
- $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
42
- $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
43
- $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
44
- $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
45
- })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
39
+ function $mol_promise_like(val) {
40
+ return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
41
+ }
42
+ $.$mol_promise_like = $mol_promise_like;
46
43
  })($ || ($ = {}));
47
44
 
48
45
  ;
49
46
  "use strict";
50
47
  var $;
51
48
  (function ($) {
52
- class $mol_wire_pub extends Object {
53
- data = [];
54
- static get [Symbol.species]() {
55
- return Array;
56
- }
57
- sub_from = 0;
58
- get sub_list() {
59
- const res = [];
60
- for (let i = this.sub_from; i < this.data.length; i += 2) {
61
- res.push(this.data[i]);
62
- }
63
- return res;
64
- }
65
- get sub_empty() {
66
- return this.sub_from === this.data.length;
67
- }
68
- sub_on(sub, pub_pos) {
69
- const pos = this.data.length;
70
- this.data.push(sub, pub_pos);
71
- return pos;
72
- }
73
- sub_off(sub_pos) {
74
- if (!(sub_pos < this.data.length)) {
75
- $mol_fail(new Error(`Wrong pos ${sub_pos}`));
76
- }
77
- const end = this.data.length - 2;
78
- if (sub_pos !== end) {
79
- this.peer_move(end, sub_pos);
80
- }
81
- this.data.pop();
82
- this.data.pop();
83
- if (this.data.length === this.sub_from)
84
- this.reap();
85
- }
86
- reap() { }
87
- promote() {
88
- $mol_wire_auto()?.track_next(this);
89
- }
90
- fresh() { }
91
- complete() { }
92
- get incompleted() {
93
- return false;
94
- }
95
- emit(quant = $mol_wire_cursor.stale) {
96
- for (let i = this.sub_from; i < this.data.length; i += 2) {
97
- ;
98
- this.data[i].absorb(quant);
99
- }
100
- }
101
- peer_move(from_pos, to_pos) {
102
- const peer = this.data[from_pos];
103
- const self_pos = this.data[from_pos + 1];
104
- this.data[to_pos] = peer;
105
- this.data[to_pos + 1] = self_pos;
106
- peer.peer_repos(self_pos, to_pos);
107
- }
108
- peer_repos(peer_pos, self_pos) {
109
- this.data[peer_pos + 1] = self_pos;
110
- }
49
+ function $mol_fail_hidden(error) {
50
+ throw error;
111
51
  }
112
- $.$mol_wire_pub = $mol_wire_pub;
52
+ $.$mol_fail_hidden = $mol_fail_hidden;
113
53
  })($ || ($ = {}));
114
54
 
115
- ;
116
- "use strict";
117
-
118
55
  ;
119
56
  "use strict";
120
57
  var $;
121
58
  (function ($) {
122
- $.$mol_wire_auto_sub = null;
123
- function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
124
- return $.$mol_wire_auto_sub = next;
59
+ const catched = new WeakMap();
60
+ function $mol_fail_catch(error) {
61
+ if (typeof error !== 'object')
62
+ return false;
63
+ if ($mol_promise_like(error))
64
+ $mol_fail_hidden(error);
65
+ if (catched.get(error))
66
+ return false;
67
+ catched.set(error, true);
68
+ return true;
125
69
  }
126
- $.$mol_wire_auto = $mol_wire_auto;
127
- $.$mol_wire_affected = [];
70
+ $.$mol_fail_catch = $mol_fail_catch;
128
71
  })($ || ($ = {}));
129
72
 
130
73
  ;
131
74
  "use strict";
132
75
  var $;
133
76
  (function ($) {
134
- $['devtoolsFormatters'] ||= [];
135
- function $mol_dev_format_register(config) {
136
- $['devtoolsFormatters'].push(config);
137
- }
138
- $.$mol_dev_format_register = $mol_dev_format_register;
139
- $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
140
- $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
141
- $mol_dev_format_register({
142
- header: (val, config = false) => {
143
- if (config)
144
- return null;
145
- if (!val)
146
- return null;
147
- if ($.$mol_dev_format_head in val) {
148
- try {
149
- return val[$.$mol_dev_format_head]();
150
- }
151
- catch (error) {
152
- return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
153
- }
154
- }
155
- if (typeof val === 'function') {
156
- return $mol_dev_format_native(val);
157
- }
158
- if (Symbol.toStringTag in val) {
159
- return $mol_dev_format_native(val);
160
- }
161
- return null;
162
- },
163
- hasBody: val => val[$.$mol_dev_format_body],
164
- body: val => val[$.$mol_dev_format_body](),
165
- });
166
- function $mol_dev_format_native(obj) {
167
- if (typeof obj === 'undefined')
168
- return $.$mol_dev_format_shade('undefined');
169
- return [
170
- 'object',
171
- {
172
- object: obj,
173
- config: true,
174
- },
175
- ];
176
- }
177
- $.$mol_dev_format_native = $mol_dev_format_native;
178
- function $mol_dev_format_auto(obj) {
179
- if (obj == null)
180
- return $.$mol_dev_format_shade(String(obj));
181
- return [
182
- 'object',
183
- {
184
- object: obj,
185
- config: false,
186
- },
187
- ];
188
- }
189
- $.$mol_dev_format_auto = $mol_dev_format_auto;
190
- function $mol_dev_format_element(element, style, ...content) {
191
- const styles = [];
192
- for (let key in style)
193
- styles.push(`${key} : ${style[key]}`);
194
- return [
195
- element,
196
- {
197
- style: styles.join(' ; '),
198
- },
199
- ...content,
200
- ];
201
- }
202
- $.$mol_dev_format_element = $mol_dev_format_element;
203
- function $mol_dev_format_span(style, ...content) {
204
- return $mol_dev_format_element('span', {
205
- ...style,
206
- }, ...content);
77
+ function $mol_fail_log(error) {
78
+ if ($mol_promise_like(error))
79
+ return false;
80
+ if (!$mol_fail_catch(error))
81
+ return false;
82
+ console.error(error);
83
+ return true;
207
84
  }
208
- $.$mol_dev_format_span = $mol_dev_format_span;
209
- $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
210
- $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
211
- $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
212
- $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
213
- $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
214
- $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
215
- $.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
216
- 'color': 'magenta',
217
- });
218
- $.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
219
- 'font-weight': 'bold',
220
- });
221
- $.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
222
- 'color': 'green',
223
- });
224
- $.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
225
- 'color': 'gray',
226
- });
227
- $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
228
- 'margin-left': '13px'
229
- });
85
+ $.$mol_fail_log = $mol_fail_log;
230
86
  })($ || ($ = {}));
231
87
 
232
88
  ;
233
89
  "use strict";
234
- var $;
235
- (function ($) {
236
- class $mol_wire_pub_sub extends $mol_wire_pub {
237
- pub_from = 0;
238
- cursor = $mol_wire_cursor.stale;
239
- get temp() {
240
- return false;
241
- }
242
- get pub_list() {
243
- const res = [];
244
- const max = this.cursor >= 0 ? this.cursor : this.sub_from;
245
- for (let i = this.pub_from; i < max; i += 2) {
246
- if (this.data[i])
247
- res.push(this.data[i]);
248
- }
249
- return res;
250
- }
251
- track_on() {
252
- this.cursor = this.pub_from;
253
- const sub = $mol_wire_auto();
254
- $mol_wire_auto(this);
255
- return sub;
256
- }
257
- promote() {
258
- if (this.cursor >= this.pub_from) {
259
- $mol_fail(new Error('Circular subscription'));
260
- }
261
- super.promote();
262
- }
263
- track_next(pub) {
264
- if (this.cursor < 0)
265
- $mol_fail(new Error('Promo to non begun sub'));
266
- if (this.cursor < this.sub_from) {
267
- const next = this.data[this.cursor];
268
- if (pub === undefined)
269
- return next ?? null;
270
- if (next === pub) {
271
- this.cursor += 2;
272
- return next;
273
- }
274
- if (next) {
275
- if (this.sub_from < this.data.length) {
276
- this.peer_move(this.sub_from, this.data.length);
277
- }
278
- this.peer_move(this.cursor, this.sub_from);
279
- this.sub_from += 2;
90
+ var $node = new Proxy({ require }, {
91
+ get(target, name, wrapper) {
92
+ if (target[name])
93
+ return target[name];
94
+ const mod = target.require('module');
95
+ if (mod.builtinModules.indexOf(name) >= 0)
96
+ return target.require(name);
97
+ if (name[0] === '.')
98
+ return target.require(name);
99
+ const path = target.require('path');
100
+ const fs = target.require('fs');
101
+ let dir = path.resolve('.');
102
+ const suffix = `./node_modules/${name}`;
103
+ const $$ = $;
104
+ while (!fs.existsSync(path.join(dir, suffix))) {
105
+ const parent = path.resolve(dir, '..');
106
+ if (parent === dir) {
107
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
108
+ try {
109
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
280
110
  }
111
+ catch { }
112
+ break;
281
113
  }
282
114
  else {
283
- if (pub === undefined)
284
- return null;
285
- if (this.sub_from < this.data.length) {
286
- this.peer_move(this.sub_from, this.data.length);
287
- }
288
- this.sub_from += 2;
289
- }
290
- this.data[this.cursor] = pub;
291
- this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
292
- this.cursor += 2;
293
- return pub;
294
- }
295
- track_off(sub) {
296
- $mol_wire_auto(sub);
297
- if (this.cursor < 0) {
298
- $mol_fail(new Error('End of non begun sub'));
299
- }
300
- for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
301
- const pub = this.data[cursor];
302
- pub.fresh();
303
- }
304
- this.cursor = $mol_wire_cursor.fresh;
305
- }
306
- pub_off(sub_pos) {
307
- this.data[sub_pos] = undefined;
308
- this.data[sub_pos + 1] = undefined;
309
- }
310
- destructor() {
311
- for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
312
- const sub = this.data[cursor];
313
- const pos = this.data[cursor + 1];
314
- sub.pub_off(pos);
315
- this.data.pop();
316
- this.data.pop();
317
- }
318
- this.cursor = this.pub_from;
319
- this.track_cut();
320
- this.cursor = $mol_wire_cursor.final;
321
- }
322
- track_cut() {
323
- if (this.cursor < this.pub_from) {
324
- $mol_fail(new Error('Cut of non begun sub'));
325
- }
326
- let tail = 0;
327
- for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
328
- const pub = this.data[cursor];
329
- pub?.sub_off(this.data[cursor + 1]);
330
- if (this.sub_from < this.data.length) {
331
- this.peer_move(this.data.length - 2, cursor);
332
- this.data.pop();
333
- this.data.pop();
334
- }
335
- else {
336
- ++tail;
337
- }
338
- }
339
- for (; tail; --tail) {
340
- this.data.pop();
341
- this.data.pop();
342
- }
343
- this.sub_from = this.cursor;
344
- }
345
- complete() { }
346
- complete_pubs() {
347
- const limit = this.cursor < 0 ? this.sub_from : this.cursor;
348
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
349
- const pub = this.data[cursor];
350
- if (pub?.incompleted)
351
- return;
352
- }
353
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
354
- const pub = this.data[cursor];
355
- pub?.complete();
115
+ dir = parent;
356
116
  }
357
117
  }
358
- absorb(quant = $mol_wire_cursor.stale) {
359
- if (this.cursor === $mol_wire_cursor.final)
360
- return;
361
- if (this.cursor >= quant)
362
- return;
363
- this.cursor = quant;
364
- this.emit($mol_wire_cursor.doubt);
365
- }
366
- [$mol_dev_format_head]() {
367
- return $mol_dev_format_native(this);
118
+ try {
119
+ return target.require(name);
368
120
  }
369
- get pub_empty() {
370
- return this.sub_from === this.pub_from;
121
+ catch (error) {
122
+ if (error.code === 'ERR_REQUIRE_ESM') {
123
+ const module = cache.get(name);
124
+ if (module)
125
+ return module;
126
+ throw import(name).then(module => cache.set(name, module));
127
+ }
128
+ $.$mol_fail_log(error);
129
+ return null;
371
130
  }
131
+ },
132
+ set(target, name, value) {
133
+ target[name] = value;
134
+ return true;
135
+ },
136
+ });
137
+ const cache = new Map();
138
+ require = (req => Object.assign(function require(name) {
139
+ return $node[name];
140
+ }, req))(require);
141
+
142
+ ;
143
+ "use strict";
144
+ var $;
145
+ (function ($) {
146
+ function $mol_log3_area_lazy(event) {
147
+ const self = this;
148
+ const stack = self.$mol_log3_stack;
149
+ const deep = stack.length;
150
+ let logged = false;
151
+ stack.push(() => {
152
+ logged = true;
153
+ self.$mol_log3_area.call(self, event);
154
+ });
155
+ return () => {
156
+ if (logged)
157
+ self.console.groupEnd();
158
+ if (stack.length > deep)
159
+ stack.length = deep;
160
+ };
372
161
  }
373
- $.$mol_wire_pub_sub = $mol_wire_pub_sub;
162
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
163
+ $.$mol_log3_stack = [];
374
164
  })($ || ($ = {}));
375
165
 
376
166
  ;
@@ -477,525 +267,82 @@ var $;
477
267
  $.$mol_owning_catch = $mol_owning_catch;
478
268
  })($ || ($ = {}));
479
269
 
480
- ;
481
- "use strict";
482
- var $;
483
- (function ($) {
484
- function $mol_fail_hidden(error) {
485
- throw error;
486
- }
487
- $.$mol_fail_hidden = $mol_fail_hidden;
488
- })($ || ($ = {}));
489
-
490
- ;
491
- "use strict";
492
-
493
- ;
494
- "use strict";
495
- var $;
496
- (function ($) {
497
- const named = new WeakSet();
498
- function $mol_func_name(func) {
499
- let name = func.name;
500
- if (name?.length > 1)
501
- return name;
502
- if (named.has(func))
503
- return name;
504
- for (let key in this) {
505
- try {
506
- if (this[key] !== func)
507
- continue;
508
- name = key;
509
- Object.defineProperty(func, 'name', { value: name });
510
- break;
511
- }
512
- catch { }
513
- }
514
- named.add(func);
515
- return name;
516
- }
517
- $.$mol_func_name = $mol_func_name;
518
- function $mol_func_name_from(target, source) {
519
- Object.defineProperty(target, 'name', { value: source.name });
520
- return target;
521
- }
522
- $.$mol_func_name_from = $mol_func_name_from;
523
- })($ || ($ = {}));
524
-
525
- ;
526
- "use strict";
527
- var $;
528
- (function ($) {
529
- class $mol_object2 {
530
- static $ = $;
531
- [Symbol.toStringTag];
532
- [$mol_ambient_ref] = null;
533
- get $() {
534
- if (this[$mol_ambient_ref])
535
- return this[$mol_ambient_ref];
536
- const owner = $mol_owning_get(this);
537
- return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
538
- }
539
- set $(next) {
540
- if (this[$mol_ambient_ref])
541
- $mol_fail_hidden(new Error('Context already defined'));
542
- this[$mol_ambient_ref] = next;
543
- }
544
- static create(init) {
545
- const obj = new this;
546
- if (init)
547
- init(obj);
548
- return obj;
549
- }
550
- static [Symbol.toPrimitive]() {
551
- return this.toString();
552
- }
553
- static toString() {
554
- return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
555
- }
556
- static toJSON() {
557
- return this.toString();
558
- }
559
- destructor() { }
560
- static destructor() { }
561
- toString() {
562
- return this[Symbol.toStringTag] || this.constructor.name + '<>';
563
- }
564
- }
565
- $.$mol_object2 = $mol_object2;
566
- })($ || ($ = {}));
567
-
568
- ;
569
- "use strict";
570
- var $;
571
- (function ($) {
572
- class $mol_after_timeout extends $mol_object2 {
573
- delay;
574
- task;
575
- id;
576
- constructor(delay, task) {
577
- super();
578
- this.delay = delay;
579
- this.task = task;
580
- this.id = setTimeout(task, delay);
581
- }
582
- destructor() {
583
- clearTimeout(this.id);
584
- }
585
- }
586
- $.$mol_after_timeout = $mol_after_timeout;
587
- })($ || ($ = {}));
588
-
589
- ;
590
- "use strict";
591
- var $;
592
- (function ($) {
593
- class $mol_after_frame extends $mol_after_timeout {
594
- task;
595
- constructor(task) {
596
- super(16, task);
597
- this.task = task;
598
- }
599
- }
600
- $.$mol_after_frame = $mol_after_frame;
601
- })($ || ($ = {}));
602
-
603
- ;
604
- "use strict";
605
- var $;
606
- (function ($) {
607
- function $mol_promise_like(val) {
608
- return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
609
- }
610
- $.$mol_promise_like = $mol_promise_like;
611
- })($ || ($ = {}));
612
-
613
- ;
614
- "use strict";
615
- var $;
616
- (function ($) {
617
- const handled = new WeakSet();
618
- class $mol_wire_fiber extends $mol_wire_pub_sub {
619
- task;
620
- host;
621
- static warm = true;
622
- static planning = new Set();
623
- static reaping = new Set();
624
- static plan_task = null;
625
- static plan() {
626
- if (this.plan_task)
627
- return;
628
- this.plan_task = new $mol_after_frame(() => {
629
- try {
630
- this.sync();
631
- }
632
- finally {
633
- $mol_wire_fiber.plan_task = null;
634
- }
635
- });
636
- }
637
- static sync() {
638
- while (this.planning.size) {
639
- for (const fiber of this.planning) {
640
- this.planning.delete(fiber);
641
- if (fiber.cursor >= 0)
642
- continue;
643
- if (fiber.cursor === $mol_wire_cursor.final)
644
- continue;
645
- fiber.fresh();
646
- }
647
- }
648
- while (this.reaping.size) {
649
- const fibers = this.reaping;
650
- this.reaping = new Set;
651
- for (const fiber of fibers) {
652
- if (!fiber.sub_empty)
653
- continue;
654
- fiber.destructor();
655
- }
656
- }
657
- }
658
- [Symbol.toStringTag];
659
- cache = undefined;
660
- get args() {
661
- return this.data.slice(0, this.pub_from);
662
- }
663
- result() {
664
- if ($mol_promise_like(this.cache))
665
- return;
666
- if (this.cache instanceof Error)
667
- return;
668
- return this.cache;
669
- }
670
- get incompleted() {
671
- return $mol_promise_like(this.cache);
672
- }
673
- field() {
674
- return this.task.name + '<>';
675
- }
676
- constructor(id, task, host, args) {
677
- super();
678
- this.task = task;
679
- this.host = host;
680
- if (args)
681
- this.data.push(...args);
682
- this.pub_from = this.sub_from = args?.length ?? 0;
683
- this[Symbol.toStringTag] = id;
684
- }
685
- plan() {
686
- $mol_wire_fiber.planning.add(this);
687
- $mol_wire_fiber.plan();
688
- }
689
- reap() {
690
- $mol_wire_fiber.reaping.add(this);
691
- $mol_wire_fiber.plan();
692
- }
693
- toString() {
694
- return this[Symbol.toStringTag];
695
- }
696
- toJSON() {
697
- return this[Symbol.toStringTag];
698
- }
699
- [$mol_dev_format_head]() {
700
- const cursor = {
701
- [$mol_wire_cursor.stale]: '🔴',
702
- [$mol_wire_cursor.doubt]: '🟡',
703
- [$mol_wire_cursor.fresh]: '🟢',
704
- [$mol_wire_cursor.final]: '🔵',
705
- }[this.cursor] ?? this.cursor.toString();
706
- return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
707
- ? $mol_dev_format_auto({
708
- [$mol_dev_format_head]: () => $mol_dev_format_shade(cursor),
709
- [$mol_dev_format_body]: () => $mol_dev_format_native(this),
710
- })
711
- : $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
712
- }
713
- get $() {
714
- return (this.host ?? this.task)['$'];
715
- }
716
- emit(quant = $mol_wire_cursor.stale) {
717
- if (this.sub_empty)
718
- this.plan();
719
- else
720
- super.emit(quant);
721
- }
722
- fresh() {
723
- if (this.cursor === $mol_wire_cursor.fresh)
724
- return;
725
- if (this.cursor === $mol_wire_cursor.final)
726
- return;
727
- check: if (this.cursor === $mol_wire_cursor.doubt) {
728
- for (let i = this.pub_from; i < this.sub_from; i += 2) {
729
- ;
730
- this.data[i]?.fresh();
731
- if (this.cursor !== $mol_wire_cursor.doubt)
732
- break check;
733
- }
734
- this.cursor = $mol_wire_cursor.fresh;
735
- return;
736
- }
737
- const bu = this.track_on();
738
- let result;
739
- try {
740
- switch (this.pub_from) {
741
- case 0:
742
- result = this.task.call(this.host);
743
- break;
744
- case 1:
745
- result = this.task.call(this.host, this.data[0]);
746
- break;
747
- default:
748
- result = this.task.call(this.host, ...this.args);
749
- break;
750
- }
751
- if ($mol_promise_like(result) && !handled.has(result)) {
752
- const put = (res) => {
753
- if (this.cache === result)
754
- this.put(res);
755
- return res;
756
- };
757
- result = result.then(put, put);
758
- }
759
- }
760
- catch (error) {
761
- if (error instanceof Error || $mol_promise_like(error)) {
762
- result = error;
763
- }
764
- else {
765
- result = new Error(String(error), { cause: error });
766
- }
767
- if ($mol_promise_like(result) && !handled.has(result)) {
768
- result = result.finally(() => {
769
- if (this.cache === result)
770
- this.absorb();
771
- });
772
- }
773
- }
774
- if ($mol_promise_like(result) && !handled.has(result)) {
775
- result = Object.assign(result, {
776
- destructor: result['destructor'] ?? (() => { })
777
- });
778
- handled.add(result);
779
- const error = new Error(`Promise in ${this}`);
780
- Object.defineProperty(result, 'stack', { get: () => error.stack });
781
- }
782
- if (!$mol_promise_like(result)) {
783
- this.track_cut();
784
- }
785
- this.track_off(bu);
786
- this.put(result);
787
- }
788
- refresh() {
789
- this.cursor = $mol_wire_cursor.stale;
790
- this.fresh();
791
- }
792
- sync() {
793
- if (!$mol_wire_fiber.warm) {
794
- return this.result();
795
- }
796
- this.promote();
797
- this.fresh();
798
- if (this.cache instanceof Error) {
799
- return $mol_fail_hidden(this.cache);
800
- }
801
- if ($mol_promise_like(this.cache)) {
802
- return $mol_fail_hidden(this.cache);
803
- }
804
- return this.cache;
805
- }
806
- async async() {
807
- while (true) {
808
- this.fresh();
809
- if (this.cache instanceof Error) {
810
- $mol_fail_hidden(this.cache);
811
- }
812
- if (!$mol_promise_like(this.cache))
813
- return this.cache;
814
- await Promise.race([this.cache, this.step()]);
815
- if (!$mol_promise_like(this.cache))
816
- return this.cache;
817
- if (this.cursor === $mol_wire_cursor.final) {
818
- await new Promise(() => { });
819
- }
820
- }
821
- }
822
- step() {
823
- return new Promise(done => {
824
- const sub = new $mol_wire_pub_sub;
825
- const prev = sub.track_on();
826
- sub.track_next(this);
827
- sub.track_off(prev);
828
- sub.absorb = () => {
829
- done(null);
830
- sub.destructor();
831
- };
832
- });
833
- }
834
- }
835
- $.$mol_wire_fiber = $mol_wire_fiber;
836
- })($ || ($ = {}));
837
-
838
- ;
839
- "use strict";
840
- var $;
841
- (function ($) {
842
- $.$mol_compare_deep_cache = new WeakMap();
843
- function $mol_compare_deep(left, right) {
844
- if (Object.is(left, right))
845
- return true;
846
- if (left === null)
847
- return false;
848
- if (right === null)
849
- return false;
850
- if (typeof left !== 'object')
851
- return false;
852
- if (typeof right !== 'object')
853
- return false;
854
- const left_proto = Reflect.getPrototypeOf(left);
855
- const right_proto = Reflect.getPrototypeOf(right);
856
- if (left_proto !== right_proto)
857
- return false;
858
- if (left instanceof Boolean)
859
- return Object.is(left.valueOf(), right['valueOf']());
860
- if (left instanceof Number)
861
- return Object.is(left.valueOf(), right['valueOf']());
862
- if (left instanceof String)
863
- return Object.is(left.valueOf(), right['valueOf']());
864
- if (left instanceof Date)
865
- return Object.is(left.valueOf(), right['valueOf']());
866
- if (left instanceof RegExp)
867
- return left.source === right.source && left.flags === right.flags;
868
- if (left instanceof Error)
869
- return left.message === right.message && left.stack === right.stack;
870
- let left_cache = $.$mol_compare_deep_cache.get(left);
871
- if (left_cache) {
872
- const right_cache = left_cache.get(right);
873
- if (typeof right_cache === 'boolean')
874
- return right_cache;
875
- }
876
- else {
877
- left_cache = new WeakMap([[right, true]]);
878
- $.$mol_compare_deep_cache.set(left, left_cache);
879
- }
880
- let result;
881
- try {
882
- if (!left_proto)
883
- result = compare_pojo(left, right);
884
- else if (!Reflect.getPrototypeOf(left_proto))
885
- result = compare_pojo(left, right);
886
- else if (Symbol.toPrimitive in left)
887
- result = compare_primitive(left, right);
888
- else if (Array.isArray(left))
889
- result = compare_array(left, right);
890
- else if (left instanceof Set)
891
- result = compare_set(left, right);
892
- else if (left instanceof Map)
893
- result = compare_map(left, right);
894
- else if (ArrayBuffer.isView(left))
895
- result = compare_buffer(left, right);
896
- else if (Symbol.iterator in left)
897
- result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
898
- else
899
- result = false;
900
- }
901
- finally {
902
- left_cache.set(right, result);
903
- }
904
- return result;
905
- }
906
- $.$mol_compare_deep = $mol_compare_deep;
907
- function compare_array(left, right) {
908
- const len = left.length;
909
- if (len !== right.length)
910
- return false;
911
- for (let i = 0; i < len; ++i) {
912
- if (!$mol_compare_deep(left[i], right[i]))
913
- return false;
914
- }
915
- return true;
916
- }
917
- function compare_buffer(left, right) {
918
- const len = left.byteLength;
919
- if (len !== right.byteLength)
920
- return false;
921
- if (left instanceof DataView)
922
- return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
923
- for (let i = 0; i < len; ++i) {
924
- if (left[i] !== right[i])
925
- return false;
926
- }
927
- return true;
928
- }
929
- function compare_iterator(left, right) {
930
- while (true) {
931
- const left_next = left.next();
932
- const right_next = right.next();
933
- if (left_next.done !== right_next.done)
934
- return false;
935
- if (left_next.done)
936
- break;
937
- if (!$mol_compare_deep(left_next.value, right_next.value))
938
- return false;
939
- }
940
- return true;
941
- }
942
- function compare_set(left, right) {
943
- if (left.size !== right.size)
944
- return false;
945
- return compare_iterator(left.values(), right.values());
946
- }
947
- function compare_map(left, right) {
948
- if (left.size !== right.size)
949
- return false;
950
- return compare_iterator(left.keys(), right.keys())
951
- && compare_iterator(left.values(), right.values());
952
- }
953
- function compare_pojo(left, right) {
954
- const left_keys = Object.getOwnPropertyNames(left);
955
- const right_keys = Object.getOwnPropertyNames(right);
956
- if (!compare_array(left_keys, right_keys))
957
- return false;
958
- for (let key of left_keys) {
959
- if (!$mol_compare_deep(left[key], right[key]))
960
- return false;
961
- }
962
- const left_syms = Object.getOwnPropertySymbols(left);
963
- const right_syms = Object.getOwnPropertySymbols(right);
964
- if (!compare_array(left_syms, right_syms))
965
- return false;
966
- for (let key of left_syms) {
967
- if (!$mol_compare_deep(left[key], right[key]))
968
- return false;
270
+ ;
271
+ "use strict";
272
+
273
+ ;
274
+ "use strict";
275
+ var $;
276
+ (function ($) {
277
+ const named = new WeakSet();
278
+ function $mol_func_name(func) {
279
+ let name = func.name;
280
+ if (name?.length > 1)
281
+ return name;
282
+ if (named.has(func))
283
+ return name;
284
+ for (let key in this) {
285
+ try {
286
+ if (this[key] !== func)
287
+ continue;
288
+ name = key;
289
+ Object.defineProperty(func, 'name', { value: name });
290
+ break;
291
+ }
292
+ catch { }
969
293
  }
970
- return true;
294
+ named.add(func);
295
+ return name;
971
296
  }
972
- function compare_primitive(left, right) {
973
- return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
297
+ $.$mol_func_name = $mol_func_name;
298
+ function $mol_func_name_from(target, source) {
299
+ Object.defineProperty(target, 'name', { value: source.name });
300
+ return target;
974
301
  }
302
+ $.$mol_func_name_from = $mol_func_name_from;
975
303
  })($ || ($ = {}));
976
304
 
977
305
  ;
978
306
  "use strict";
979
307
  var $;
980
308
  (function ($) {
981
- function $mol_log3_area_lazy(event) {
982
- const self = this;
983
- const stack = self.$mol_log3_stack;
984
- const deep = stack.length;
985
- let logged = false;
986
- stack.push(() => {
987
- logged = true;
988
- self.$mol_log3_area.call(self, event);
989
- });
990
- return () => {
991
- if (logged)
992
- self.console.groupEnd();
993
- if (stack.length > deep)
994
- stack.length = deep;
995
- };
309
+ class $mol_object2 {
310
+ static $ = $;
311
+ [Symbol.toStringTag];
312
+ [$mol_ambient_ref] = null;
313
+ get $() {
314
+ if (this[$mol_ambient_ref])
315
+ return this[$mol_ambient_ref];
316
+ const owner = $mol_owning_get(this);
317
+ return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
318
+ }
319
+ set $(next) {
320
+ if (this[$mol_ambient_ref])
321
+ $mol_fail_hidden(new Error('Context already defined'));
322
+ this[$mol_ambient_ref] = next;
323
+ }
324
+ static create(init) {
325
+ const obj = new this;
326
+ if (init)
327
+ init(obj);
328
+ return obj;
329
+ }
330
+ static [Symbol.toPrimitive]() {
331
+ return this.toString();
332
+ }
333
+ static toString() {
334
+ return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
335
+ }
336
+ static toJSON() {
337
+ return this.toString();
338
+ }
339
+ destructor() { }
340
+ static destructor() { }
341
+ toString() {
342
+ return this[Symbol.toStringTag] || this.constructor.name + '<>';
343
+ }
996
344
  }
997
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
998
- $.$mol_log3_stack = [];
345
+ $.$mol_object2 = $mol_object2;
999
346
  })($ || ($ = {}));
1000
347
 
1001
348
  ;
@@ -1491,180 +838,6 @@ var $;
1491
838
  $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1492
839
  })($ || ($ = {}));
1493
840
 
1494
- ;
1495
- "use strict";
1496
- var $;
1497
- (function ($) {
1498
- class $mol_wire_task extends $mol_wire_fiber {
1499
- static getter(task) {
1500
- return function $mol_wire_task_get(host, args) {
1501
- const sub = $mol_wire_auto();
1502
- const existen = sub?.track_next();
1503
- reuse: if (existen) {
1504
- if (!existen.temp)
1505
- break reuse;
1506
- if (existen.host !== host)
1507
- break reuse;
1508
- if (existen.task !== task)
1509
- break reuse;
1510
- if (!$mol_compare_deep(existen.args, args))
1511
- break reuse;
1512
- return existen;
1513
- }
1514
- const next = new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}<#>`, task, host, args);
1515
- if (existen?.temp) {
1516
- $$.$mol_log3_warn({
1517
- place: '$mol_wire_task',
1518
- message: `Non idempotency`,
1519
- existen,
1520
- next,
1521
- hint: 'Ignore it',
1522
- });
1523
- }
1524
- return next;
1525
- };
1526
- }
1527
- get temp() {
1528
- return true;
1529
- }
1530
- complete() {
1531
- if ($mol_promise_like(this.cache))
1532
- return;
1533
- this.destructor();
1534
- }
1535
- put(next) {
1536
- const prev = this.cache;
1537
- this.cache = next;
1538
- if ($mol_promise_like(next)) {
1539
- this.cursor = $mol_wire_cursor.fresh;
1540
- if (next !== prev)
1541
- this.emit();
1542
- return next;
1543
- }
1544
- this.cursor = $mol_wire_cursor.final;
1545
- if (this.sub_empty)
1546
- this.destructor();
1547
- else if (next !== prev)
1548
- this.emit();
1549
- return next;
1550
- }
1551
- }
1552
- $.$mol_wire_task = $mol_wire_task;
1553
- })($ || ($ = {}));
1554
-
1555
- ;
1556
- "use strict";
1557
- var $;
1558
- (function ($) {
1559
- function $mol_wire_sync(obj) {
1560
- return new Proxy(obj, {
1561
- get(obj, field) {
1562
- const val = obj[field];
1563
- if (typeof val !== 'function')
1564
- return val;
1565
- const temp = $mol_wire_task.getter(val);
1566
- return function $mol_wire_sync(...args) {
1567
- const fiber = temp(obj, args);
1568
- return fiber.sync();
1569
- };
1570
- },
1571
- apply(obj, self, args) {
1572
- const temp = $mol_wire_task.getter(obj);
1573
- const fiber = temp(self, args);
1574
- return fiber.sync();
1575
- },
1576
- });
1577
- }
1578
- $.$mol_wire_sync = $mol_wire_sync;
1579
- })($ || ($ = {}));
1580
-
1581
- ;
1582
- "use strict";
1583
- var $;
1584
- (function ($) {
1585
- const catched = new WeakMap();
1586
- function $mol_fail_catch(error) {
1587
- if (typeof error !== 'object')
1588
- return false;
1589
- if ($mol_promise_like(error))
1590
- $mol_fail_hidden(error);
1591
- if (catched.get(error))
1592
- return false;
1593
- catched.set(error, true);
1594
- return true;
1595
- }
1596
- $.$mol_fail_catch = $mol_fail_catch;
1597
- })($ || ($ = {}));
1598
-
1599
- ;
1600
- "use strict";
1601
- var $;
1602
- (function ($) {
1603
- function $mol_fail_log(error) {
1604
- if ($mol_promise_like(error))
1605
- return false;
1606
- if (!$mol_fail_catch(error))
1607
- return false;
1608
- console.error(error);
1609
- return true;
1610
- }
1611
- $.$mol_fail_log = $mol_fail_log;
1612
- })($ || ($ = {}));
1613
-
1614
- ;
1615
- "use strict";
1616
- var $node = new Proxy({ require }, {
1617
- get(target, name, wrapper) {
1618
- if (target[name])
1619
- return target[name];
1620
- const mod = target.require('module');
1621
- if (mod.builtinModules.indexOf(name) >= 0)
1622
- return target.require(name);
1623
- if (name[0] === '.')
1624
- return target.require(name);
1625
- const path = target.require('path');
1626
- const fs = target.require('fs');
1627
- let dir = path.resolve('.');
1628
- const suffix = `./node_modules/${name}`;
1629
- const $$ = $;
1630
- while (!fs.existsSync(path.join(dir, suffix))) {
1631
- const parent = path.resolve(dir, '..');
1632
- if (parent === dir) {
1633
- $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
1634
- try {
1635
- $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
1636
- }
1637
- catch { }
1638
- break;
1639
- }
1640
- else {
1641
- dir = parent;
1642
- }
1643
- }
1644
- try {
1645
- return $.$mol_wire_sync(target).require(name);
1646
- }
1647
- catch (error) {
1648
- if (error.code === 'ERR_REQUIRE_ESM') {
1649
- const module = cache.get(name);
1650
- if (module)
1651
- return module;
1652
- throw import(name).then(module => cache.set(name, module));
1653
- }
1654
- $.$mol_fail_log(error);
1655
- return null;
1656
- }
1657
- },
1658
- set(target, name, value) {
1659
- target[name] = value;
1660
- return true;
1661
- },
1662
- });
1663
- const cache = new Map();
1664
- require = (req => Object.assign(function require(name) {
1665
- return $node[name];
1666
- }, req))(require);
1667
-
1668
841
  ;
1669
842
  "use strict";
1670
843
  var $;
@@ -1751,12 +924,16 @@ var $;
1751
924
  return new this(await $mol_crypto_native.subtle.generateKey(algorithm, true, ['encrypt', 'decrypt']));
1752
925
  }
1753
926
  static async from(serial) {
1754
- if (typeof serial === 'string') {
1755
- serial = $mol_charset_encode(serial);
1756
- serial = await $mol_crypto_native.subtle.digest('SHA-256', serial);
1757
- }
1758
927
  return new this(await $mol_crypto_native.subtle.importKey('raw', serial, algorithm, true, ['encrypt', 'decrypt']));
1759
928
  }
929
+ static async pass(pass, salt) {
930
+ return new this(await $mol_crypto_native.subtle.deriveKey({
931
+ name: "PBKDF2",
932
+ salt,
933
+ iterations: 10_000,
934
+ hash: "SHA-256",
935
+ }, await $mol_crypto_native.subtle.importKey("raw", $mol_charset_encode(pass), "PBKDF2", false, ["deriveKey"]), algorithm, true, ['encrypt', 'decrypt']));
936
+ }
1760
937
  static async derive(private_serial, public_serial) {
1761
938
  const ecdh = { name: "ECDH", namedCurve: "P-256" };
1762
939
  const jwk = { crv: 'P-256', ext: true, kty: 'EC' };
@@ -2380,33 +1557,6 @@ var $;
2380
1557
  $.$mol_test_complete = $mol_test_complete;
2381
1558
  })($ || ($ = {}));
2382
1559
 
2383
- ;
2384
- "use strict";
2385
-
2386
- ;
2387
- "use strict";
2388
-
2389
- ;
2390
- "use strict";
2391
-
2392
- ;
2393
- "use strict";
2394
- var $;
2395
- (function ($_1) {
2396
- $mol_test({
2397
- 'test types'($) {
2398
- class A {
2399
- static a() {
2400
- return Promise.resolve('');
2401
- }
2402
- static b() {
2403
- return $mol_wire_sync(this).a();
2404
- }
2405
- }
2406
- },
2407
- });
2408
- })($ || ($ = {}));
2409
-
2410
1560
  ;
2411
1561
  "use strict";
2412
1562
  var $;
@@ -2437,6 +1587,15 @@ var $;
2437
1587
  ;
2438
1588
  "use strict";
2439
1589
 
1590
+ ;
1591
+ "use strict";
1592
+
1593
+ ;
1594
+ "use strict";
1595
+
1596
+ ;
1597
+ "use strict";
1598
+
2440
1599
  ;
2441
1600
  "use strict";
2442
1601
  var $;
@@ -3006,7 +2165,146 @@ var $;
3006
2165
  $mol_assert_fail(() => list.sort(), TypeError);
3007
2166
  $mol_assert_equal(list.toString(), '0,1,2,3,4');
3008
2167
  }
3009
- });
2168
+ });
2169
+ })($ || ($ = {}));
2170
+
2171
+ ;
2172
+ "use strict";
2173
+ var $;
2174
+ (function ($) {
2175
+ $.$mol_compare_deep_cache = new WeakMap();
2176
+ function $mol_compare_deep(left, right) {
2177
+ if (Object.is(left, right))
2178
+ return true;
2179
+ if (left === null)
2180
+ return false;
2181
+ if (right === null)
2182
+ return false;
2183
+ if (typeof left !== 'object')
2184
+ return false;
2185
+ if (typeof right !== 'object')
2186
+ return false;
2187
+ const left_proto = Reflect.getPrototypeOf(left);
2188
+ const right_proto = Reflect.getPrototypeOf(right);
2189
+ if (left_proto !== right_proto)
2190
+ return false;
2191
+ if (left instanceof Boolean)
2192
+ return Object.is(left.valueOf(), right['valueOf']());
2193
+ if (left instanceof Number)
2194
+ return Object.is(left.valueOf(), right['valueOf']());
2195
+ if (left instanceof String)
2196
+ return Object.is(left.valueOf(), right['valueOf']());
2197
+ if (left instanceof Date)
2198
+ return Object.is(left.valueOf(), right['valueOf']());
2199
+ if (left instanceof RegExp)
2200
+ return left.source === right.source && left.flags === right.flags;
2201
+ if (left instanceof Error)
2202
+ return left.message === right.message && left.stack === right.stack;
2203
+ let left_cache = $.$mol_compare_deep_cache.get(left);
2204
+ if (left_cache) {
2205
+ const right_cache = left_cache.get(right);
2206
+ if (typeof right_cache === 'boolean')
2207
+ return right_cache;
2208
+ }
2209
+ else {
2210
+ left_cache = new WeakMap([[right, true]]);
2211
+ $.$mol_compare_deep_cache.set(left, left_cache);
2212
+ }
2213
+ let result;
2214
+ try {
2215
+ if (!left_proto)
2216
+ result = compare_pojo(left, right);
2217
+ else if (!Reflect.getPrototypeOf(left_proto))
2218
+ result = compare_pojo(left, right);
2219
+ else if (Symbol.toPrimitive in left)
2220
+ result = compare_primitive(left, right);
2221
+ else if (Array.isArray(left))
2222
+ result = compare_array(left, right);
2223
+ else if (left instanceof Set)
2224
+ result = compare_set(left, right);
2225
+ else if (left instanceof Map)
2226
+ result = compare_map(left, right);
2227
+ else if (ArrayBuffer.isView(left))
2228
+ result = compare_buffer(left, right);
2229
+ else if (Symbol.iterator in left)
2230
+ result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
2231
+ else
2232
+ result = false;
2233
+ }
2234
+ finally {
2235
+ left_cache.set(right, result);
2236
+ }
2237
+ return result;
2238
+ }
2239
+ $.$mol_compare_deep = $mol_compare_deep;
2240
+ function compare_array(left, right) {
2241
+ const len = left.length;
2242
+ if (len !== right.length)
2243
+ return false;
2244
+ for (let i = 0; i < len; ++i) {
2245
+ if (!$mol_compare_deep(left[i], right[i]))
2246
+ return false;
2247
+ }
2248
+ return true;
2249
+ }
2250
+ function compare_buffer(left, right) {
2251
+ const len = left.byteLength;
2252
+ if (len !== right.byteLength)
2253
+ return false;
2254
+ if (left instanceof DataView)
2255
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
2256
+ for (let i = 0; i < len; ++i) {
2257
+ if (left[i] !== right[i])
2258
+ return false;
2259
+ }
2260
+ return true;
2261
+ }
2262
+ function compare_iterator(left, right) {
2263
+ while (true) {
2264
+ const left_next = left.next();
2265
+ const right_next = right.next();
2266
+ if (left_next.done !== right_next.done)
2267
+ return false;
2268
+ if (left_next.done)
2269
+ break;
2270
+ if (!$mol_compare_deep(left_next.value, right_next.value))
2271
+ return false;
2272
+ }
2273
+ return true;
2274
+ }
2275
+ function compare_set(left, right) {
2276
+ if (left.size !== right.size)
2277
+ return false;
2278
+ return compare_iterator(left.values(), right.values());
2279
+ }
2280
+ function compare_map(left, right) {
2281
+ if (left.size !== right.size)
2282
+ return false;
2283
+ return compare_iterator(left.keys(), right.keys())
2284
+ && compare_iterator(left.values(), right.values());
2285
+ }
2286
+ function compare_pojo(left, right) {
2287
+ const left_keys = Object.getOwnPropertyNames(left);
2288
+ const right_keys = Object.getOwnPropertyNames(right);
2289
+ if (!compare_array(left_keys, right_keys))
2290
+ return false;
2291
+ for (let key of left_keys) {
2292
+ if (!$mol_compare_deep(left[key], right[key]))
2293
+ return false;
2294
+ }
2295
+ const left_syms = Object.getOwnPropertySymbols(left);
2296
+ const right_syms = Object.getOwnPropertySymbols(right);
2297
+ if (!compare_array(left_syms, right_syms))
2298
+ return false;
2299
+ for (let key of left_syms) {
2300
+ if (!$mol_compare_deep(left[key], right[key]))
2301
+ return false;
2302
+ }
2303
+ return true;
2304
+ }
2305
+ function compare_primitive(left, right) {
2306
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
2307
+ }
3010
2308
  })($ || ($ = {}));
3011
2309
 
3012
2310
  ;
@@ -3504,348 +2802,6 @@ var $;
3504
2802
  });
3505
2803
  })($ || ($ = {}));
3506
2804
 
3507
- ;
3508
- "use strict";
3509
- var $;
3510
- (function ($_1) {
3511
- $mol_test({
3512
- 'Collect deps'() {
3513
- const pub1 = new $mol_wire_pub;
3514
- const pub2 = new $mol_wire_pub;
3515
- const sub = new $mol_wire_pub_sub;
3516
- const bu1 = sub.track_on();
3517
- try {
3518
- pub1.promote();
3519
- pub2.promote();
3520
- pub2.promote();
3521
- }
3522
- finally {
3523
- sub.track_cut();
3524
- sub.track_off(bu1);
3525
- }
3526
- pub1.emit();
3527
- pub2.emit();
3528
- $mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
3529
- const bu2 = sub.track_on();
3530
- try {
3531
- pub1.promote();
3532
- pub1.promote();
3533
- pub2.promote();
3534
- }
3535
- finally {
3536
- sub.track_cut();
3537
- sub.track_off(bu2);
3538
- }
3539
- pub1.emit();
3540
- pub2.emit();
3541
- $mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
3542
- },
3543
- 'cyclic detection'($) {
3544
- const sub1 = new $mol_wire_pub_sub;
3545
- const sub2 = new $mol_wire_pub_sub;
3546
- const bu1 = sub1.track_on();
3547
- try {
3548
- const bu2 = sub2.track_on();
3549
- try {
3550
- $mol_assert_fail(() => sub1.promote(), 'Circular subscription');
3551
- }
3552
- finally {
3553
- sub2.track_cut();
3554
- sub2.track_off(bu2);
3555
- }
3556
- }
3557
- finally {
3558
- sub1.track_cut();
3559
- sub1.track_off(bu1);
3560
- }
3561
- },
3562
- });
3563
- })($ || ($ = {}));
3564
-
3565
- ;
3566
- "use strict";
3567
- var $;
3568
- (function ($) {
3569
- $.$mol_after_mock_queue = [];
3570
- function $mol_after_mock_warp() {
3571
- const queue = $.$mol_after_mock_queue.splice(0);
3572
- for (const task of queue)
3573
- task();
3574
- }
3575
- $.$mol_after_mock_warp = $mol_after_mock_warp;
3576
- class $mol_after_mock_commmon extends $mol_object2 {
3577
- task;
3578
- promise = Promise.resolve();
3579
- cancelled = false;
3580
- id;
3581
- constructor(task) {
3582
- super();
3583
- this.task = task;
3584
- $.$mol_after_mock_queue.push(task);
3585
- }
3586
- destructor() {
3587
- const index = $.$mol_after_mock_queue.indexOf(this.task);
3588
- if (index >= 0)
3589
- $.$mol_after_mock_queue.splice(index, 1);
3590
- }
3591
- }
3592
- $.$mol_after_mock_commmon = $mol_after_mock_commmon;
3593
- class $mol_after_mock_timeout extends $mol_after_mock_commmon {
3594
- delay;
3595
- constructor(delay, task) {
3596
- super(task);
3597
- this.delay = delay;
3598
- }
3599
- }
3600
- $.$mol_after_mock_timeout = $mol_after_mock_timeout;
3601
- })($ || ($ = {}));
3602
-
3603
- ;
3604
- "use strict";
3605
- var $;
3606
- (function ($_1) {
3607
- $mol_test_mocks.push($ => {
3608
- $.$mol_after_timeout = $mol_after_mock_timeout;
3609
- });
3610
- })($ || ($ = {}));
3611
-
3612
- ;
3613
- "use strict";
3614
- var $;
3615
- (function ($_1) {
3616
- $mol_test_mocks.push($ => {
3617
- $.$mol_after_frame = $mol_after_mock_commmon;
3618
- });
3619
- })($ || ($ = {}));
3620
-
3621
- ;
3622
- "use strict";
3623
- var $;
3624
- (function ($) {
3625
- $mol_test({
3626
- 'Sync execution'() {
3627
- class Sync extends $mol_object2 {
3628
- static calc(a, b) {
3629
- return a + b;
3630
- }
3631
- }
3632
- __decorate([
3633
- $mol_wire_method
3634
- ], Sync, "calc", null);
3635
- $mol_assert_equal(Sync.calc(1, 2), 3);
3636
- },
3637
- async 'async <=> sync'() {
3638
- class SyncAsync extends $mol_object2 {
3639
- static async val(a) {
3640
- return a;
3641
- }
3642
- static sum(a, b) {
3643
- const syn = $mol_wire_sync(this);
3644
- return syn.val(a) + syn.val(b);
3645
- }
3646
- static async calc(a, b) {
3647
- return 5 + await $mol_wire_async(this).sum(a, b);
3648
- }
3649
- }
3650
- $mol_assert_equal(await SyncAsync.calc(1, 2), 8);
3651
- },
3652
- async 'Idempotence control'() {
3653
- class Idempotence extends $mol_object2 {
3654
- static logs_idemp = 0;
3655
- static logs_unidemp = 0;
3656
- static log_idemp() {
3657
- this.logs_idemp += 1;
3658
- }
3659
- static log_unidemp() {
3660
- this.logs_unidemp += 1;
3661
- }
3662
- static async val(a) {
3663
- return a;
3664
- }
3665
- static sum(a, b) {
3666
- this.log_idemp();
3667
- this.log_unidemp();
3668
- const syn = $mol_wire_sync(this);
3669
- return syn.val(a) + syn.val(b);
3670
- }
3671
- static async calc(a, b) {
3672
- return 5 + await $mol_wire_async(this).sum(a, b);
3673
- }
3674
- }
3675
- __decorate([
3676
- $mol_wire_method
3677
- ], Idempotence, "log_idemp", null);
3678
- $mol_assert_equal(await Idempotence.calc(1, 2), 8);
3679
- $mol_assert_equal(Idempotence.logs_idemp, 1);
3680
- $mol_assert_equal(Idempotence.logs_unidemp, 3);
3681
- },
3682
- async 'Error handling'() {
3683
- class Handle extends $mol_object2 {
3684
- static async sum(a, b) {
3685
- $mol_fail(new Error('test error ' + (a + b)));
3686
- }
3687
- static check() {
3688
- try {
3689
- return $mol_wire_sync(Handle).sum(1, 2);
3690
- }
3691
- catch (error) {
3692
- if ($mol_promise_like(error))
3693
- $mol_fail_hidden(error);
3694
- $mol_assert_equal(error.message, 'test error 3');
3695
- }
3696
- }
3697
- }
3698
- await $mol_wire_async(Handle).check();
3699
- },
3700
- });
3701
- })($ || ($ = {}));
3702
-
3703
- ;
3704
- "use strict";
3705
- var $;
3706
- (function ($) {
3707
- function $mol_wire_method(host, field, descr) {
3708
- if (!descr)
3709
- descr = Reflect.getOwnPropertyDescriptor(host, field);
3710
- const orig = descr?.value ?? host[field];
3711
- const sup = Reflect.getPrototypeOf(host);
3712
- if (typeof sup[field] === 'function') {
3713
- Object.defineProperty(orig, 'name', { value: sup[field].name });
3714
- }
3715
- const temp = $mol_wire_task.getter(orig);
3716
- const value = function (...args) {
3717
- const fiber = temp(this ?? null, args);
3718
- return fiber.sync();
3719
- };
3720
- Object.defineProperty(value, 'name', { value: orig.name + ' ' });
3721
- Object.assign(value, { orig });
3722
- const descr2 = { ...descr, value };
3723
- Reflect.defineProperty(host, field, descr2);
3724
- return descr2;
3725
- }
3726
- $.$mol_wire_method = $mol_wire_method;
3727
- })($ || ($ = {}));
3728
-
3729
- ;
3730
- "use strict";
3731
- var $;
3732
- (function ($) {
3733
- function $mol_promise() {
3734
- let done;
3735
- let fail;
3736
- const promise = new Promise((d, f) => {
3737
- done = d;
3738
- fail = f;
3739
- });
3740
- return Object.assign(promise, {
3741
- done,
3742
- fail,
3743
- });
3744
- }
3745
- $.$mol_promise = $mol_promise;
3746
- })($ || ($ = {}));
3747
-
3748
- ;
3749
- "use strict";
3750
- var $;
3751
- (function ($) {
3752
- function $mol_wait_timeout_async(timeout) {
3753
- const promise = $mol_promise();
3754
- const task = new this.$mol_after_timeout(timeout, () => promise.done());
3755
- return Object.assign(promise, {
3756
- destructor: () => task.destructor()
3757
- });
3758
- }
3759
- $.$mol_wait_timeout_async = $mol_wait_timeout_async;
3760
- function $mol_wait_timeout(timeout) {
3761
- return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
3762
- }
3763
- $.$mol_wait_timeout = $mol_wait_timeout;
3764
- })($ || ($ = {}));
3765
-
3766
- ;
3767
- "use strict";
3768
- var $;
3769
- (function ($) {
3770
- function $mol_wire_async(obj) {
3771
- let fiber;
3772
- const temp = $mol_wire_task.getter(obj);
3773
- return new Proxy(obj, {
3774
- get(obj, field) {
3775
- const val = obj[field];
3776
- if (typeof val !== 'function')
3777
- return val;
3778
- let fiber;
3779
- const temp = $mol_wire_task.getter(val);
3780
- return function $mol_wire_async(...args) {
3781
- fiber?.destructor();
3782
- fiber = temp(obj, args);
3783
- return fiber.async();
3784
- };
3785
- },
3786
- apply(obj, self, args) {
3787
- fiber?.destructor();
3788
- fiber = temp(self, args);
3789
- return fiber.async();
3790
- },
3791
- });
3792
- }
3793
- $.$mol_wire_async = $mol_wire_async;
3794
- })($ || ($ = {}));
3795
-
3796
- ;
3797
- "use strict";
3798
- var $;
3799
- (function ($_1) {
3800
- $mol_test({
3801
- 'test types'($) {
3802
- class A {
3803
- static a() {
3804
- return '';
3805
- }
3806
- static b() {
3807
- return $mol_wire_async(this).a();
3808
- }
3809
- }
3810
- },
3811
- async 'Latest method calls wins'($) {
3812
- class NameLogger extends $mol_object2 {
3813
- static $ = $;
3814
- static first = [];
3815
- static last = [];
3816
- static send(next) {
3817
- $mol_wire_sync(this.first).push(next);
3818
- this.$.$mol_wait_timeout(0);
3819
- this.last.push(next);
3820
- }
3821
- }
3822
- const name = $mol_wire_async(NameLogger).send;
3823
- name('john');
3824
- const promise = name('jin');
3825
- $.$mol_after_mock_warp();
3826
- await promise;
3827
- $mol_assert_like(NameLogger.first, ['john', 'jin']);
3828
- $mol_assert_like(NameLogger.last, ['jin']);
3829
- },
3830
- async 'Latest function calls wins'($) {
3831
- const first = [];
3832
- const last = [];
3833
- function send_name(next) {
3834
- $mol_wire_sync(first).push(next);
3835
- $.$mol_wait_timeout(0);
3836
- last.push(next);
3837
- }
3838
- const name = $mol_wire_async(send_name);
3839
- name('john');
3840
- const promise = name('jin');
3841
- $.$mol_after_mock_warp();
3842
- await promise;
3843
- $mol_assert_like(first, ['john', 'jin']);
3844
- $mol_assert_like(last, ['jin']);
3845
- },
3846
- });
3847
- })($ || ($ = {}));
3848
-
3849
2805
  ;
3850
2806
  "use strict";
3851
2807
  var $;
@@ -4038,21 +2994,21 @@ var $;
4038
2994
  (function ($) {
4039
2995
  $mol_test({
4040
2996
  async 'sizes'() {
4041
- const cipher = await $mol_crypto_secret.generate();
4042
- const key = await cipher.serial();
2997
+ const secret = await $mol_crypto_secret.generate();
2998
+ const key = await secret.serial();
4043
2999
  $mol_assert_equal(key.byteLength, $mol_crypto_secret.size);
4044
3000
  const data = new Uint8Array([1, 2, 3]);
4045
3001
  const salt = $mol_crypto_salt();
4046
- const closed = await cipher.encrypt(data, salt);
3002
+ const closed = await secret.encrypt(data, salt);
4047
3003
  $mol_assert_equal(closed.byteLength, 16);
4048
3004
  },
4049
3005
  async 'decrypt self encrypted with auto generated key'() {
4050
- const cipher = await $mol_crypto_secret.generate();
3006
+ const secret = await $mol_crypto_secret.generate();
4051
3007
  const data = new Uint8Array([1, 2, 3]);
4052
3008
  const salt = $mol_crypto_salt();
4053
- const closed = await cipher.encrypt(data, salt);
4054
- const opened = await cipher.decrypt(closed, salt);
4055
- $mol_assert_like(data, new Uint8Array(opened));
3009
+ const closed = await secret.encrypt(data, salt);
3010
+ const opened = await secret.decrypt(closed, salt);
3011
+ $mol_assert_equal(data, opened);
4056
3012
  },
4057
3013
  async 'decrypt encrypted with exported auto generated key'() {
4058
3014
  const data = new Uint8Array([1, 2, 3]);
@@ -4061,14 +3017,23 @@ var $;
4061
3017
  const closed = await Alice.encrypt(data, salt);
4062
3018
  const Bob = await $mol_crypto_secret.from(await Alice.serial());
4063
3019
  const opened = await Bob.decrypt(closed, salt);
4064
- $mol_assert_like(data, new Uint8Array(opened));
3020
+ $mol_assert_equal(data, opened);
4065
3021
  },
4066
3022
  async 'derivation from public & private keys'() {
4067
3023
  const A = await $mol_crypto_key_private.generate();
4068
3024
  const B = await $mol_crypto_key_private.generate();
4069
3025
  const AK = await $mol_crypto_secret.derive(A.toString(), B.public().toString());
4070
3026
  const BK = await $mol_crypto_secret.derive(B.toString(), A.public().toString());
4071
- $mol_assert_like(new Uint8Array(await AK.serial()), new Uint8Array(await BK.serial()));
3027
+ $mol_assert_equal(await AK.serial(), await BK.serial());
3028
+ },
3029
+ async 'derivation from passwod'() {
3030
+ const data = new Uint8Array([1, 2, 3]);
3031
+ const salt1 = $mol_crypto_salt();
3032
+ const secret = await $mol_crypto_secret.pass('hello', salt1);
3033
+ const salt2 = $mol_crypto_salt();
3034
+ const closed = await secret.encrypt(data, salt2);
3035
+ const opened = await secret.decrypt(closed, salt2);
3036
+ $mol_assert_equal(data, opened);
4072
3037
  },
4073
3038
  });
4074
3039
  })($ || ($ = {}));