mol_crypto2_lib 0.0.37 → 0.0.39
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.d.ts +235 -1
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +246 -9
- package/node.js.map +1 -1
- package/node.mjs +246 -9
- package/node.test.js +317 -15
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.d.ts +65 -0
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +68 -1
- package/web.js.map +1 -1
- package/web.mjs +68 -1
- package/web.test.js +76 -6
- package/web.test.js.map +1 -1
package/node.test.js
CHANGED
|
@@ -60,6 +60,7 @@ var $;
|
|
|
60
60
|
var $;
|
|
61
61
|
(function ($) {
|
|
62
62
|
function $mol_base64_decode_node(base64Str) {
|
|
63
|
+
// without Uint8Array breaks $mol_compare_deep
|
|
63
64
|
const buffer = Buffer.from(base64Str, 'base64');
|
|
64
65
|
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
65
66
|
}
|
|
@@ -161,6 +162,7 @@ var $;
|
|
|
161
162
|
this.setUint16(offset + 4, (value / 2 ** 32) | 0, LE);
|
|
162
163
|
}
|
|
163
164
|
}
|
|
165
|
+
/** 1-byte signed integer channel for offset. */
|
|
164
166
|
int8(offset, next) {
|
|
165
167
|
if (next === undefined)
|
|
166
168
|
return this.getInt8(offset);
|
|
@@ -168,6 +170,7 @@ var $;
|
|
|
168
170
|
return this.setInt8(offset, next), next;
|
|
169
171
|
$mol_fail(new Error(`Wrong int8 value ${next}`));
|
|
170
172
|
}
|
|
173
|
+
/** 1-byte unsigned integer channel for offset. */
|
|
171
174
|
uint8(offset, next) {
|
|
172
175
|
if (next === undefined)
|
|
173
176
|
return this.getUint8(offset);
|
|
@@ -175,6 +178,7 @@ var $;
|
|
|
175
178
|
return this.setUint8(offset, next), next;
|
|
176
179
|
$mol_fail(new Error(`Wrong uint8 value ${next}`));
|
|
177
180
|
}
|
|
181
|
+
/** 2-byte signed integer little-endian channel for offset. */
|
|
178
182
|
int16(offset, next) {
|
|
179
183
|
if (next === undefined)
|
|
180
184
|
return this.getInt16(offset, true);
|
|
@@ -182,6 +186,7 @@ var $;
|
|
|
182
186
|
return this.setInt16(offset, next, true), next;
|
|
183
187
|
$mol_fail(new Error(`Wrong int16 value ${next}`));
|
|
184
188
|
}
|
|
189
|
+
/** 2-byte unsigned integer little-endian channel for offset. */
|
|
185
190
|
uint16(offset, next) {
|
|
186
191
|
if (next === undefined)
|
|
187
192
|
return this.getUint16(offset, true);
|
|
@@ -189,6 +194,7 @@ var $;
|
|
|
189
194
|
return this.setUint16(offset, next, true), next;
|
|
190
195
|
$mol_fail(new Error(`Wrong uint16 value ${next}`));
|
|
191
196
|
}
|
|
197
|
+
/** 4-byte signed integer little-endian channel for offset. */
|
|
192
198
|
int32(offset, next) {
|
|
193
199
|
if (next === undefined)
|
|
194
200
|
return this.getInt32(offset, true);
|
|
@@ -196,6 +202,7 @@ var $;
|
|
|
196
202
|
return this.setInt32(offset, next, true), next;
|
|
197
203
|
$mol_fail(new Error(`Wrong int32 value ${next}`));
|
|
198
204
|
}
|
|
205
|
+
/** 4-byte unsigned integer little-endian channel for offset. */
|
|
199
206
|
uint32(offset, next) {
|
|
200
207
|
if (next === undefined)
|
|
201
208
|
return this.getUint32(offset, true);
|
|
@@ -203,6 +210,7 @@ var $;
|
|
|
203
210
|
return this.setUint32(offset, next, true), next;
|
|
204
211
|
$mol_fail(new Error(`Wrong uint32 value ${next}`));
|
|
205
212
|
}
|
|
213
|
+
/** 8-byte signed integer little-endian channel for offset. */
|
|
206
214
|
int64(offset, next) {
|
|
207
215
|
if (next === undefined)
|
|
208
216
|
return this.getBigInt64(offset, true);
|
|
@@ -210,6 +218,7 @@ var $;
|
|
|
210
218
|
return this.setBigInt64(offset, next, true), next;
|
|
211
219
|
$mol_fail(new Error(`Wrong int64 value ${next}`));
|
|
212
220
|
}
|
|
221
|
+
/** 6-byte unsigned integer little-endian channel for offset. */
|
|
213
222
|
uint48(offset, next) {
|
|
214
223
|
if (next === undefined)
|
|
215
224
|
return this.getUint48(offset, true);
|
|
@@ -217,6 +226,7 @@ var $;
|
|
|
217
226
|
return this.setUint48(offset, next, true), next;
|
|
218
227
|
$mol_fail(new Error(`Wrong uint48 value ${next}`));
|
|
219
228
|
}
|
|
229
|
+
/** 8-byte unsigned integer little-endian channel for offset. */
|
|
220
230
|
uint64(offset, next) {
|
|
221
231
|
if (next === undefined)
|
|
222
232
|
return this.getBigUint64(offset, true);
|
|
@@ -224,24 +234,29 @@ var $;
|
|
|
224
234
|
return this.setBigUint64(offset, next, true), next;
|
|
225
235
|
$mol_fail(new Error(`Wrong uint64 value ${next}`));
|
|
226
236
|
}
|
|
237
|
+
/** 2-byte float little-endian channel for offset. */
|
|
227
238
|
float16(offset, next) {
|
|
228
239
|
if (next !== undefined)
|
|
229
240
|
this.setFloat16(offset, next, true);
|
|
230
241
|
return this.getFloat16(offset, true);
|
|
231
242
|
}
|
|
243
|
+
/** 4-byte float little-endian channel for offset. */
|
|
232
244
|
float32(offset, next) {
|
|
233
245
|
if (next !== undefined)
|
|
234
246
|
this.setFloat32(offset, next, true);
|
|
235
247
|
return this.getFloat32(offset, true);
|
|
236
248
|
}
|
|
249
|
+
/** 8-byte float little-endian channel for offset. */
|
|
237
250
|
float64(offset, next) {
|
|
238
251
|
if (next !== undefined)
|
|
239
252
|
this.setFloat64(offset, next, true);
|
|
240
253
|
return this.getFloat64(offset, true);
|
|
241
254
|
}
|
|
255
|
+
/** A Uint8Array view for the same buffer. */
|
|
242
256
|
asArray() {
|
|
243
257
|
return new Uint8Array(this.buffer, this.byteOffset, this.byteLength);
|
|
244
258
|
}
|
|
259
|
+
/** base64ae string from buffer. */
|
|
245
260
|
toString() {
|
|
246
261
|
return $mol_base64_ae_encode(this.asArray());
|
|
247
262
|
}
|
|
@@ -278,6 +293,7 @@ var $;
|
|
|
278
293
|
$.$mol_base64_url_encode = $mol_base64_url_encode_node;
|
|
279
294
|
}
|
|
280
295
|
function $mol_base64_url_decode_node(str) {
|
|
296
|
+
// without Uint8Array breaks $mol_compare_deep
|
|
281
297
|
const buffer = Buffer.from(str, 'base64url');
|
|
282
298
|
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
283
299
|
}
|
|
@@ -303,6 +319,11 @@ var $;
|
|
|
303
319
|
var $;
|
|
304
320
|
(function ($) {
|
|
305
321
|
const instances = new WeakSet();
|
|
322
|
+
/**
|
|
323
|
+
* Proxy that delegates all to lazy returned target.
|
|
324
|
+
*
|
|
325
|
+
* $mol_delegate( Array.prototype , ()=> fetch_array() )
|
|
326
|
+
*/
|
|
306
327
|
function $mol_delegate(proto, target) {
|
|
307
328
|
const proxy = new Proxy(proto, {
|
|
308
329
|
get: (_, field) => {
|
|
@@ -396,7 +417,7 @@ var $;
|
|
|
396
417
|
var $;
|
|
397
418
|
(function ($) {
|
|
398
419
|
function $mol_fail_hidden(error) {
|
|
399
|
-
throw error;
|
|
420
|
+
throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
|
|
400
421
|
}
|
|
401
422
|
$.$mol_fail_hidden = $mol_fail_hidden;
|
|
402
423
|
})($ || ($ = {}));
|
|
@@ -456,6 +477,9 @@ var $;
|
|
|
456
477
|
[Symbol.dispose]() {
|
|
457
478
|
this.destructor();
|
|
458
479
|
}
|
|
480
|
+
//[ Symbol.toPrimitive ]( hint: string ) {
|
|
481
|
+
// return hint === 'number' ? this.valueOf() : this.toString()
|
|
482
|
+
//}
|
|
459
483
|
toString() {
|
|
460
484
|
return this[Symbol.toStringTag] || this.constructor.name + '<>';
|
|
461
485
|
}
|
|
@@ -526,9 +550,11 @@ var $;
|
|
|
526
550
|
"use strict";
|
|
527
551
|
var $;
|
|
528
552
|
(function ($) {
|
|
553
|
+
/** Base class for crypto keys. */
|
|
529
554
|
class $mol_crypto2_key extends $mol_buffer {
|
|
530
555
|
static size_str = 43;
|
|
531
556
|
static size_bin = 32;
|
|
557
|
+
/** Kakes key from different params. */
|
|
532
558
|
static from(serial) {
|
|
533
559
|
if (typeof serial === 'string') {
|
|
534
560
|
serial = new Uint8Array(serial.match(/.{43}/g)
|
|
@@ -540,6 +566,7 @@ var $;
|
|
|
540
566
|
}
|
|
541
567
|
return super.from(serial);
|
|
542
568
|
}
|
|
569
|
+
/** Array view of public part. */
|
|
543
570
|
asArray() {
|
|
544
571
|
const size = this.constructor.size_bin;
|
|
545
572
|
if (this.byteLength < size) {
|
|
@@ -550,6 +577,7 @@ var $;
|
|
|
550
577
|
}
|
|
551
578
|
return new Uint8Array(this.buffer, this.byteOffset, size);
|
|
552
579
|
}
|
|
580
|
+
/** String representation of public part. */
|
|
553
581
|
toString() {
|
|
554
582
|
return $mol_base64_url_encode(this.asArray());
|
|
555
583
|
}
|
|
@@ -567,7 +595,7 @@ var $;
|
|
|
567
595
|
"use strict";
|
|
568
596
|
var $;
|
|
569
597
|
(function ($) {
|
|
570
|
-
const mod = require('module');
|
|
598
|
+
const mod = require /****/('module');
|
|
571
599
|
const internals = mod.builtinModules;
|
|
572
600
|
function $node_internal_check(name) {
|
|
573
601
|
if (name.startsWith('node:'))
|
|
@@ -645,8 +673,8 @@ var $;
|
|
|
645
673
|
"use strict";
|
|
646
674
|
var $;
|
|
647
675
|
(function ($) {
|
|
648
|
-
const path = require('path');
|
|
649
|
-
const mod = require('module');
|
|
676
|
+
const path = require /****/('path');
|
|
677
|
+
const mod = require /****/('module');
|
|
650
678
|
const localRequire = mod.createRequire(path.join(process.cwd(), 'package.json'));
|
|
651
679
|
function $node_autoinstall(name) {
|
|
652
680
|
try {
|
|
@@ -721,6 +749,7 @@ var $;
|
|
|
721
749
|
])
|
|
722
750
|
].map(frame_normalize).join('\n')
|
|
723
751
|
});
|
|
752
|
+
// в nodejs, что б не дублировалось cause в консоли
|
|
724
753
|
Object.defineProperty(this, 'cause', {
|
|
725
754
|
get: () => cause
|
|
726
755
|
});
|
|
@@ -781,6 +810,7 @@ var $;
|
|
|
781
810
|
"use strict";
|
|
782
811
|
var $;
|
|
783
812
|
(function ($) {
|
|
813
|
+
/** Generates unique identifier. */
|
|
784
814
|
function $mol_guid(length = 8, exists = () => false) {
|
|
785
815
|
for (;;) {
|
|
786
816
|
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
@@ -796,11 +826,16 @@ var $;
|
|
|
796
826
|
"use strict";
|
|
797
827
|
var $;
|
|
798
828
|
(function ($) {
|
|
829
|
+
/** Special status statuses. */
|
|
799
830
|
let $mol_wire_cursor;
|
|
800
831
|
(function ($mol_wire_cursor) {
|
|
832
|
+
/** Update required. */
|
|
801
833
|
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
834
|
+
/** Some of (transitive) pub update required. */
|
|
802
835
|
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
836
|
+
/** Actual state but may be dropped. */
|
|
803
837
|
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
|
838
|
+
/** State will never be changed. */
|
|
804
839
|
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
|
805
840
|
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
806
841
|
})($ || ($ = {}));
|
|
@@ -809,6 +844,9 @@ var $;
|
|
|
809
844
|
"use strict";
|
|
810
845
|
var $;
|
|
811
846
|
(function ($) {
|
|
847
|
+
/**
|
|
848
|
+
* Collects subscribers in compact array. 28B
|
|
849
|
+
*/
|
|
812
850
|
class $mol_wire_pub extends Object {
|
|
813
851
|
constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
|
|
814
852
|
super();
|
|
@@ -816,10 +854,17 @@ var $;
|
|
|
816
854
|
}
|
|
817
855
|
[Symbol.toStringTag];
|
|
818
856
|
data = [];
|
|
857
|
+
// Derived objects should be Arrays.
|
|
819
858
|
static get [Symbol.species]() {
|
|
820
859
|
return Array;
|
|
821
860
|
}
|
|
822
|
-
|
|
861
|
+
/**
|
|
862
|
+
* Index of first subscriber.
|
|
863
|
+
*/
|
|
864
|
+
sub_from = 0; // 4B
|
|
865
|
+
/**
|
|
866
|
+
* All current subscribers.
|
|
867
|
+
*/
|
|
823
868
|
get sub_list() {
|
|
824
869
|
const res = [];
|
|
825
870
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
@@ -827,14 +872,23 @@ var $;
|
|
|
827
872
|
}
|
|
828
873
|
return res;
|
|
829
874
|
}
|
|
875
|
+
/**
|
|
876
|
+
* Has any subscribers or not.
|
|
877
|
+
*/
|
|
830
878
|
get sub_empty() {
|
|
831
879
|
return this.sub_from === this.data.length;
|
|
832
880
|
}
|
|
881
|
+
/**
|
|
882
|
+
* Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
|
|
883
|
+
*/
|
|
833
884
|
sub_on(sub, pub_pos) {
|
|
834
885
|
const pos = this.data.length;
|
|
835
886
|
this.data.push(sub, pub_pos);
|
|
836
887
|
return pos;
|
|
837
888
|
}
|
|
889
|
+
/**
|
|
890
|
+
* Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
|
|
891
|
+
*/
|
|
838
892
|
sub_off(sub_pos) {
|
|
839
893
|
if (!(sub_pos < this.data.length)) {
|
|
840
894
|
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
|
@@ -847,21 +901,39 @@ var $;
|
|
|
847
901
|
if (end === this.sub_from)
|
|
848
902
|
this.reap();
|
|
849
903
|
}
|
|
904
|
+
/**
|
|
905
|
+
* Called when last sub was unsubscribed.
|
|
906
|
+
**/
|
|
850
907
|
reap() { }
|
|
908
|
+
/**
|
|
909
|
+
* Autowire this publisher with current subscriber.
|
|
910
|
+
**/
|
|
851
911
|
promote() {
|
|
852
912
|
$mol_wire_auto()?.track_next(this);
|
|
853
913
|
}
|
|
914
|
+
/**
|
|
915
|
+
* Enforce actualization. Should not throw errors.
|
|
916
|
+
*/
|
|
854
917
|
fresh() { }
|
|
918
|
+
/**
|
|
919
|
+
* Allow to put data to caches in the subtree.
|
|
920
|
+
*/
|
|
855
921
|
complete() { }
|
|
856
922
|
get incompleted() {
|
|
857
923
|
return false;
|
|
858
924
|
}
|
|
925
|
+
/**
|
|
926
|
+
* Notify subscribers about self changes.
|
|
927
|
+
*/
|
|
859
928
|
emit(quant = $mol_wire_cursor.stale) {
|
|
860
929
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
861
930
|
;
|
|
862
931
|
this.data[i].absorb(quant, this.data[i + 1]);
|
|
863
932
|
}
|
|
864
933
|
}
|
|
934
|
+
/**
|
|
935
|
+
* Moves peer from one position to another. Doesn't clear data at old position!
|
|
936
|
+
*/
|
|
865
937
|
peer_move(from_pos, to_pos) {
|
|
866
938
|
const peer = this.data[from_pos];
|
|
867
939
|
const self_pos = this.data[from_pos + 1];
|
|
@@ -869,6 +941,9 @@ var $;
|
|
|
869
941
|
this.data[to_pos + 1] = self_pos;
|
|
870
942
|
peer.peer_repos(self_pos, to_pos);
|
|
871
943
|
}
|
|
944
|
+
/**
|
|
945
|
+
* Updates self position in the peer.
|
|
946
|
+
*/
|
|
872
947
|
peer_repos(peer_pos, self_pos) {
|
|
873
948
|
this.data[peer_pos + 1] = self_pos;
|
|
874
949
|
}
|
|
@@ -884,10 +959,16 @@ var $;
|
|
|
884
959
|
var $;
|
|
885
960
|
(function ($) {
|
|
886
961
|
$.$mol_wire_auto_sub = null;
|
|
962
|
+
/**
|
|
963
|
+
* When fulfilled, all publishers are promoted to this subscriber on access to its.
|
|
964
|
+
*/
|
|
887
965
|
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
|
888
966
|
return $.$mol_wire_auto_sub = next;
|
|
889
967
|
}
|
|
890
968
|
$.$mol_wire_auto = $mol_wire_auto;
|
|
969
|
+
/**
|
|
970
|
+
* Affection queue. Used to prevent accidental stack overflow on emit.
|
|
971
|
+
*/
|
|
891
972
|
$.$mol_wire_affected = [];
|
|
892
973
|
})($ || ($ = {}));
|
|
893
974
|
|
|
@@ -895,6 +976,7 @@ var $;
|
|
|
895
976
|
"use strict";
|
|
896
977
|
var $;
|
|
897
978
|
(function ($) {
|
|
979
|
+
// https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview#
|
|
898
980
|
$['devtoolsFormatters'] ||= [];
|
|
899
981
|
function $mol_dev_format_register(config) {
|
|
900
982
|
$['devtoolsFormatters'].push(config);
|
|
@@ -946,6 +1028,7 @@ var $;
|
|
|
946
1028
|
return false;
|
|
947
1029
|
if (!val)
|
|
948
1030
|
return false;
|
|
1031
|
+
// if( Error.isError( val ) ) true
|
|
949
1032
|
if (val[$.$mol_dev_format_body])
|
|
950
1033
|
return true;
|
|
951
1034
|
return false;
|
|
@@ -963,12 +1046,16 @@ var $;
|
|
|
963
1046
|
return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
|
|
964
1047
|
}
|
|
965
1048
|
}
|
|
1049
|
+
// if( Error.isError( val ) ) {
|
|
1050
|
+
// return $mol_dev_format_native( val )
|
|
1051
|
+
// }
|
|
966
1052
|
return null;
|
|
967
1053
|
},
|
|
968
1054
|
});
|
|
969
1055
|
function $mol_dev_format_native(obj) {
|
|
970
1056
|
if (typeof obj === 'undefined')
|
|
971
1057
|
return $.$mol_dev_format_shade('undefined');
|
|
1058
|
+
// if( ![ 'object', 'function', 'symbol' ].includes( typeof obj ) ) return obj
|
|
972
1059
|
return [
|
|
973
1060
|
'object',
|
|
974
1061
|
{
|
|
@@ -1026,6 +1113,9 @@ var $;
|
|
|
1026
1113
|
'margin-left': '13px'
|
|
1027
1114
|
});
|
|
1028
1115
|
class Stack extends Array {
|
|
1116
|
+
// [ Symbol.toPrimitive ]() {
|
|
1117
|
+
// return this.toString()
|
|
1118
|
+
// }
|
|
1029
1119
|
toString() {
|
|
1030
1120
|
return this.join('\n');
|
|
1031
1121
|
}
|
|
@@ -1048,6 +1138,7 @@ var $;
|
|
|
1048
1138
|
this.method = call.getMethodName() ?? '';
|
|
1049
1139
|
if (this.method === this.function)
|
|
1050
1140
|
this.method = '';
|
|
1141
|
+
// const func = c.getFunction()
|
|
1051
1142
|
this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
|
|
1052
1143
|
this.eval = call.getEvalOrigin() ?? '';
|
|
1053
1144
|
this.source = call.getScriptNameOrSourceURL() ?? '';
|
|
@@ -1094,9 +1185,16 @@ var $;
|
|
|
1094
1185
|
"use strict";
|
|
1095
1186
|
var $;
|
|
1096
1187
|
(function ($) {
|
|
1188
|
+
/**
|
|
1189
|
+
* Publisher that can auto collect other publishers. 32B
|
|
1190
|
+
*
|
|
1191
|
+
* P1 P2 P3 P4 S1 S2 S3
|
|
1192
|
+
* ^ ^
|
|
1193
|
+
* pubs_from subs_from
|
|
1194
|
+
*/
|
|
1097
1195
|
class $mol_wire_pub_sub extends $mol_wire_pub {
|
|
1098
|
-
pub_from = 0;
|
|
1099
|
-
cursor = $mol_wire_cursor.stale;
|
|
1196
|
+
pub_from = 0; // 4B
|
|
1197
|
+
cursor = $mol_wire_cursor.stale; // 4B
|
|
1100
1198
|
get temp() {
|
|
1101
1199
|
return false;
|
|
1102
1200
|
}
|
|
@@ -1214,10 +1312,27 @@ var $;
|
|
|
1214
1312
|
return;
|
|
1215
1313
|
this.cursor = quant;
|
|
1216
1314
|
this.emit($mol_wire_cursor.doubt);
|
|
1315
|
+
// if( pos >= 0 && pos < this.sub_from - 2 ) {
|
|
1316
|
+
// const pub = this.data[ pos ] as $mol_wire_pub
|
|
1317
|
+
// if( pub instanceof $mol_wire_task ) return
|
|
1318
|
+
// for(
|
|
1319
|
+
// let cursor = this.pub_from;
|
|
1320
|
+
// cursor < this.sub_from;
|
|
1321
|
+
// cursor += 2
|
|
1322
|
+
// ) {
|
|
1323
|
+
// const pub = this.data[ cursor ] as $mol_wire_pub
|
|
1324
|
+
// if( pub instanceof $mol_wire_task ) {
|
|
1325
|
+
// pub.destructor()
|
|
1326
|
+
// }
|
|
1327
|
+
// }
|
|
1328
|
+
// }
|
|
1217
1329
|
}
|
|
1218
1330
|
[$mol_dev_format_head]() {
|
|
1219
1331
|
return $mol_dev_format_native(this);
|
|
1220
1332
|
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Is subscribed to any publisher or not.
|
|
1335
|
+
*/
|
|
1221
1336
|
get pub_empty() {
|
|
1222
1337
|
return this.sub_from === this.pub_from;
|
|
1223
1338
|
}
|
|
@@ -1258,6 +1373,13 @@ var $;
|
|
|
1258
1373
|
var $;
|
|
1259
1374
|
(function ($) {
|
|
1260
1375
|
const wrappers = new WeakMap();
|
|
1376
|
+
/**
|
|
1377
|
+
* Suspendable task with support both sync/async api.
|
|
1378
|
+
*
|
|
1379
|
+
* A1 A2 A3 A4 P1 P2 P3 P4 S1 S2 S3
|
|
1380
|
+
* ^ ^ ^
|
|
1381
|
+
* args_from pubs_from subs_from
|
|
1382
|
+
**/
|
|
1261
1383
|
class $mol_wire_fiber extends $mol_wire_pub_sub {
|
|
1262
1384
|
task;
|
|
1263
1385
|
host;
|
|
@@ -1278,6 +1400,7 @@ var $;
|
|
|
1278
1400
|
});
|
|
1279
1401
|
}
|
|
1280
1402
|
static sync() {
|
|
1403
|
+
// Sync whole fiber graph
|
|
1281
1404
|
while (this.planning.size) {
|
|
1282
1405
|
for (const fiber of this.planning) {
|
|
1283
1406
|
this.planning.delete(fiber);
|
|
@@ -1288,6 +1411,7 @@ var $;
|
|
|
1288
1411
|
fiber.fresh();
|
|
1289
1412
|
}
|
|
1290
1413
|
}
|
|
1414
|
+
// Collect garbage
|
|
1291
1415
|
while (this.reaping.size) {
|
|
1292
1416
|
const fibers = this.reaping;
|
|
1293
1417
|
this.reaping = new Set;
|
|
@@ -1439,6 +1563,10 @@ var $;
|
|
|
1439
1563
|
this.cursor = $mol_wire_cursor.stale;
|
|
1440
1564
|
this.fresh();
|
|
1441
1565
|
}
|
|
1566
|
+
/**
|
|
1567
|
+
* Synchronous execution. Throws Promise when waits async task (SuspenseAPI provider).
|
|
1568
|
+
* Should be called inside SuspenseAPI consumer (ie fiber).
|
|
1569
|
+
*/
|
|
1442
1570
|
sync() {
|
|
1443
1571
|
if (!$mol_wire_fiber.warm) {
|
|
1444
1572
|
return this.result();
|
|
@@ -1453,6 +1581,10 @@ var $;
|
|
|
1453
1581
|
}
|
|
1454
1582
|
return this.cache;
|
|
1455
1583
|
}
|
|
1584
|
+
/**
|
|
1585
|
+
* Asynchronous execution.
|
|
1586
|
+
* It's SuspenseAPI consumer. So SuspenseAPI providers can be called inside.
|
|
1587
|
+
*/
|
|
1456
1588
|
async async_raw() {
|
|
1457
1589
|
while (true) {
|
|
1458
1590
|
this.fresh();
|
|
@@ -1465,6 +1597,7 @@ var $;
|
|
|
1465
1597
|
if (!$mol_promise_like(this.cache))
|
|
1466
1598
|
return this.cache;
|
|
1467
1599
|
if (this.cursor === $mol_wire_cursor.final) {
|
|
1600
|
+
// never ends on destructed fiber
|
|
1468
1601
|
await new Promise(() => { });
|
|
1469
1602
|
}
|
|
1470
1603
|
}
|
|
@@ -1512,6 +1645,10 @@ var $;
|
|
|
1512
1645
|
var $;
|
|
1513
1646
|
(function ($) {
|
|
1514
1647
|
$.$mol_compare_deep_cache = new WeakMap();
|
|
1648
|
+
/**
|
|
1649
|
+
* Deeply compares two values. Returns true if equal.
|
|
1650
|
+
* Define `Symbol.toPrimitive` to customize.
|
|
1651
|
+
*/
|
|
1515
1652
|
function $mol_compare_deep(left, right) {
|
|
1516
1653
|
if (Object.is(left, right))
|
|
1517
1654
|
return true;
|
|
@@ -1651,6 +1788,7 @@ var $;
|
|
|
1651
1788
|
"use strict";
|
|
1652
1789
|
var $;
|
|
1653
1790
|
(function ($) {
|
|
1791
|
+
/** Log begin of collapsed group only when some logged inside, returns func to close group */
|
|
1654
1792
|
function $mol_log3_area_lazy(event) {
|
|
1655
1793
|
const self = this.$;
|
|
1656
1794
|
const stack = self.$mol_log3_stack;
|
|
@@ -1675,6 +1813,7 @@ var $;
|
|
|
1675
1813
|
"use strict";
|
|
1676
1814
|
var $;
|
|
1677
1815
|
(function ($) {
|
|
1816
|
+
/** Position in any resource. */
|
|
1678
1817
|
class $mol_span extends $mol_object2 {
|
|
1679
1818
|
uri;
|
|
1680
1819
|
source;
|
|
@@ -1690,13 +1829,17 @@ var $;
|
|
|
1690
1829
|
this.length = length;
|
|
1691
1830
|
this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
|
|
1692
1831
|
}
|
|
1832
|
+
/** Span for begin of unknown resource */
|
|
1693
1833
|
static unknown = $mol_span.begin('?');
|
|
1834
|
+
/** Makes new span for begin of resource. */
|
|
1694
1835
|
static begin(uri, source = '') {
|
|
1695
1836
|
return new $mol_span(uri, source, 1, 1, 0);
|
|
1696
1837
|
}
|
|
1838
|
+
/** Makes new span for end of resource. */
|
|
1697
1839
|
static end(uri, source) {
|
|
1698
1840
|
return new $mol_span(uri, source, 1, source.length + 1, 0);
|
|
1699
1841
|
}
|
|
1842
|
+
/** Makes new span for entire resource. */
|
|
1700
1843
|
static entire(uri, source) {
|
|
1701
1844
|
return new $mol_span(uri, source, 1, 1, source.length);
|
|
1702
1845
|
}
|
|
@@ -1711,15 +1854,19 @@ var $;
|
|
|
1711
1854
|
length: this.length
|
|
1712
1855
|
};
|
|
1713
1856
|
}
|
|
1857
|
+
/** Makes new error for this span. */
|
|
1714
1858
|
error(message, Class = Error) {
|
|
1715
1859
|
return new Class(`${message} (${this})`);
|
|
1716
1860
|
}
|
|
1861
|
+
/** Makes new span for same uri. */
|
|
1717
1862
|
span(row, col, length) {
|
|
1718
1863
|
return new $mol_span(this.uri, this.source, row, col, length);
|
|
1719
1864
|
}
|
|
1865
|
+
/** Makes new span after end of this. */
|
|
1720
1866
|
after(length = 0) {
|
|
1721
1867
|
return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
|
|
1722
1868
|
}
|
|
1869
|
+
/** Makes new span between begin and end. */
|
|
1723
1870
|
slice(begin, end = -1) {
|
|
1724
1871
|
let len = this.length;
|
|
1725
1872
|
if (begin < 0)
|
|
@@ -1742,6 +1889,7 @@ var $;
|
|
|
1742
1889
|
"use strict";
|
|
1743
1890
|
var $;
|
|
1744
1891
|
(function ($) {
|
|
1892
|
+
/** Serializes tree to string in tree format. */
|
|
1745
1893
|
function $mol_tree2_to_string(tree) {
|
|
1746
1894
|
let output = [];
|
|
1747
1895
|
function dump(tree, prefix = '') {
|
|
@@ -1785,12 +1933,25 @@ var $;
|
|
|
1785
1933
|
"use strict";
|
|
1786
1934
|
var $;
|
|
1787
1935
|
(function ($) {
|
|
1936
|
+
/**
|
|
1937
|
+
* Abstract Syntax Tree with human readable serialization.
|
|
1938
|
+
* Avoid direct instantiation. Use static factories instead.
|
|
1939
|
+
* @see https://github.com/nin-jin/tree.d
|
|
1940
|
+
*/
|
|
1788
1941
|
class $mol_tree2 extends Object {
|
|
1789
1942
|
type;
|
|
1790
1943
|
value;
|
|
1791
1944
|
kids;
|
|
1792
1945
|
span;
|
|
1793
|
-
constructor(
|
|
1946
|
+
constructor(
|
|
1947
|
+
/** Type of structural node, `value` should be empty */
|
|
1948
|
+
type,
|
|
1949
|
+
/** Content of data node, `type` should be empty */
|
|
1950
|
+
value,
|
|
1951
|
+
/** Child nodes */
|
|
1952
|
+
kids,
|
|
1953
|
+
/** Position in most far source resource */
|
|
1954
|
+
span) {
|
|
1794
1955
|
super();
|
|
1795
1956
|
this.type = type;
|
|
1796
1957
|
this.value = value;
|
|
@@ -1798,12 +1959,15 @@ var $;
|
|
|
1798
1959
|
this.span = span;
|
|
1799
1960
|
this[Symbol.toStringTag] = type || '\\' + value;
|
|
1800
1961
|
}
|
|
1962
|
+
/** Makes collection node. */
|
|
1801
1963
|
static list(kids, span = $mol_span.unknown) {
|
|
1802
1964
|
return new $mol_tree2('', '', kids, span);
|
|
1803
1965
|
}
|
|
1966
|
+
/** Makes new derived collection node. */
|
|
1804
1967
|
list(kids) {
|
|
1805
1968
|
return $mol_tree2.list(kids, this.span);
|
|
1806
1969
|
}
|
|
1970
|
+
/** Makes data node for any string. */
|
|
1807
1971
|
static data(value, kids = [], span = $mol_span.unknown) {
|
|
1808
1972
|
const chunks = value.split('\n');
|
|
1809
1973
|
if (chunks.length > 1) {
|
|
@@ -1817,21 +1981,26 @@ var $;
|
|
|
1817
1981
|
}
|
|
1818
1982
|
return new $mol_tree2('', value, kids, span);
|
|
1819
1983
|
}
|
|
1984
|
+
/** Makes new derived data node. */
|
|
1820
1985
|
data(value, kids = []) {
|
|
1821
1986
|
return $mol_tree2.data(value, kids, this.span);
|
|
1822
1987
|
}
|
|
1988
|
+
/** Makes struct node. */
|
|
1823
1989
|
static struct(type, kids = [], span = $mol_span.unknown) {
|
|
1824
1990
|
if (/[ \n\t\\]/.test(type)) {
|
|
1825
1991
|
$$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
|
|
1826
1992
|
}
|
|
1827
1993
|
return new $mol_tree2(type, '', kids, span);
|
|
1828
1994
|
}
|
|
1995
|
+
/** Makes new derived structural node. */
|
|
1829
1996
|
struct(type, kids = []) {
|
|
1830
1997
|
return $mol_tree2.struct(type, kids, this.span);
|
|
1831
1998
|
}
|
|
1999
|
+
/** Makes new derived node with different kids id defined. */
|
|
1832
2000
|
clone(kids, span = this.span) {
|
|
1833
2001
|
return new $mol_tree2(this.type, this.value, kids, span);
|
|
1834
2002
|
}
|
|
2003
|
+
/** Returns multiline text content. */
|
|
1835
2004
|
text() {
|
|
1836
2005
|
var values = [];
|
|
1837
2006
|
for (var kid of this.kids) {
|
|
@@ -1841,15 +2010,20 @@ var $;
|
|
|
1841
2010
|
}
|
|
1842
2011
|
return this.value + values.join('\n');
|
|
1843
2012
|
}
|
|
2013
|
+
/** Parses tree format. */
|
|
2014
|
+
/** @deprecated Use $mol_tree2_from_string */
|
|
1844
2015
|
static fromString(str, uri = 'unknown') {
|
|
1845
2016
|
return $$.$mol_tree2_from_string(str, uri);
|
|
1846
2017
|
}
|
|
2018
|
+
/** Serializes to tree format. */
|
|
1847
2019
|
toString() {
|
|
1848
2020
|
return $$.$mol_tree2_to_string(this);
|
|
1849
2021
|
}
|
|
2022
|
+
/** Makes new tree with node overrided by path. */
|
|
1850
2023
|
insert(value, ...path) {
|
|
1851
2024
|
return this.update($mol_maybe(value), ...path)[0];
|
|
1852
2025
|
}
|
|
2026
|
+
/** Makes new tree with node overrided by path. */
|
|
1853
2027
|
update(value, ...path) {
|
|
1854
2028
|
if (path.length === 0)
|
|
1855
2029
|
return value;
|
|
@@ -1882,6 +2056,7 @@ var $;
|
|
|
1882
2056
|
return [this.clone(kids)];
|
|
1883
2057
|
}
|
|
1884
2058
|
}
|
|
2059
|
+
/** Query nodes by path. */
|
|
1885
2060
|
select(...path) {
|
|
1886
2061
|
let next = [this];
|
|
1887
2062
|
for (const type of path) {
|
|
@@ -1908,6 +2083,7 @@ var $;
|
|
|
1908
2083
|
}
|
|
1909
2084
|
return this.list(next);
|
|
1910
2085
|
}
|
|
2086
|
+
/** Filter kids by path or value. */
|
|
1911
2087
|
filter(path, value) {
|
|
1912
2088
|
const sub = this.kids.filter(item => {
|
|
1913
2089
|
var found = item.select(...path);
|
|
@@ -1935,9 +2111,11 @@ var $;
|
|
|
1935
2111
|
$mol_fail_hidden(error);
|
|
1936
2112
|
}
|
|
1937
2113
|
}
|
|
2114
|
+
/** Transform tree through context with transformers */
|
|
1938
2115
|
hack(belt, context = {}) {
|
|
1939
2116
|
return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
|
|
1940
2117
|
}
|
|
2118
|
+
/** Makes Error with node coordinates. */
|
|
1941
2119
|
error(message, Class = Error) {
|
|
1942
2120
|
return this.span.error(`${message}\n${this.clone([])}`, Class);
|
|
1943
2121
|
}
|
|
@@ -1955,6 +2133,7 @@ var $;
|
|
|
1955
2133
|
"use strict";
|
|
1956
2134
|
var $;
|
|
1957
2135
|
(function ($) {
|
|
2136
|
+
/** Syntax error with cordinates and source line snippet. */
|
|
1958
2137
|
class $mol_error_syntax extends SyntaxError {
|
|
1959
2138
|
reason;
|
|
1960
2139
|
line;
|
|
@@ -1973,6 +2152,7 @@ var $;
|
|
|
1973
2152
|
"use strict";
|
|
1974
2153
|
var $;
|
|
1975
2154
|
(function ($) {
|
|
2155
|
+
/** Parses tree format from string. */
|
|
1976
2156
|
function $mol_tree2_from_string(str, uri = '?') {
|
|
1977
2157
|
const span = $mol_span.entire(uri, str);
|
|
1978
2158
|
var root = $mol_tree2.list([], span);
|
|
@@ -1982,6 +2162,7 @@ var $;
|
|
|
1982
2162
|
var indent = 0;
|
|
1983
2163
|
var line_start = pos;
|
|
1984
2164
|
row++;
|
|
2165
|
+
// read indent
|
|
1985
2166
|
while (str.length > pos && str[pos] == '\t') {
|
|
1986
2167
|
indent++;
|
|
1987
2168
|
pos++;
|
|
@@ -1990,8 +2171,10 @@ var $;
|
|
|
1990
2171
|
min_indent = indent;
|
|
1991
2172
|
}
|
|
1992
2173
|
indent -= min_indent;
|
|
2174
|
+
// invalid tab size
|
|
1993
2175
|
if (indent < 0 || indent >= stack.length) {
|
|
1994
2176
|
const sp = span.span(row, 1, pos - line_start);
|
|
2177
|
+
// skip error line
|
|
1995
2178
|
while (str.length > pos && str[pos] != '\n') {
|
|
1996
2179
|
pos++;
|
|
1997
2180
|
}
|
|
@@ -2006,7 +2189,9 @@ var $;
|
|
|
2006
2189
|
}
|
|
2007
2190
|
stack.length = indent + 1;
|
|
2008
2191
|
var parent = stack[indent];
|
|
2192
|
+
// parse types
|
|
2009
2193
|
while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
|
|
2194
|
+
// type can not contain space and tab
|
|
2010
2195
|
var error_start = pos;
|
|
2011
2196
|
while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
|
|
2012
2197
|
pos++;
|
|
@@ -2018,6 +2203,7 @@ var $;
|
|
|
2018
2203
|
const sp = span.span(row, error_start - line_start + 1, pos - error_start);
|
|
2019
2204
|
this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
|
|
2020
2205
|
}
|
|
2206
|
+
// read type
|
|
2021
2207
|
var type_start = pos;
|
|
2022
2208
|
while (str.length > pos &&
|
|
2023
2209
|
str[pos] != '\\' &&
|
|
@@ -2032,10 +2218,12 @@ var $;
|
|
|
2032
2218
|
parent_kids.push(next);
|
|
2033
2219
|
parent = next;
|
|
2034
2220
|
}
|
|
2221
|
+
// read one space if exists
|
|
2035
2222
|
if (str.length > pos && str[pos] == ' ') {
|
|
2036
2223
|
pos++;
|
|
2037
2224
|
}
|
|
2038
2225
|
}
|
|
2226
|
+
// read data
|
|
2039
2227
|
if (str.length > pos && str[pos] == '\\') {
|
|
2040
2228
|
var data_start = pos;
|
|
2041
2229
|
while (str.length > pos && str[pos] != '\n') {
|
|
@@ -2046,6 +2234,7 @@ var $;
|
|
|
2046
2234
|
parent_kids.push(next);
|
|
2047
2235
|
parent = next;
|
|
2048
2236
|
}
|
|
2237
|
+
// now must be end of text
|
|
2049
2238
|
if (str.length === pos && stack.length > 0) {
|
|
2050
2239
|
const sp = span.span(row, pos - line_start + 1, 1);
|
|
2051
2240
|
this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
|
|
@@ -2138,6 +2327,7 @@ var $;
|
|
|
2138
2327
|
"use strict";
|
|
2139
2328
|
var $;
|
|
2140
2329
|
(function ($) {
|
|
2330
|
+
/** Module for working with terminal. Text coloring when output in terminal */
|
|
2141
2331
|
class $mol_term_color {
|
|
2142
2332
|
static reset = this.ansi(0, 0);
|
|
2143
2333
|
static bold = this.ansi(1, 22);
|
|
@@ -2209,6 +2399,7 @@ var $;
|
|
|
2209
2399
|
"use strict";
|
|
2210
2400
|
var $;
|
|
2211
2401
|
(function ($) {
|
|
2402
|
+
/** One-shot fiber */
|
|
2212
2403
|
class $mol_wire_task extends $mol_wire_fiber {
|
|
2213
2404
|
static getter(task) {
|
|
2214
2405
|
return function $mol_wire_task_get(host, args) {
|
|
@@ -2234,6 +2425,7 @@ var $;
|
|
|
2234
2425
|
}
|
|
2235
2426
|
const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
|
|
2236
2427
|
const next = new $mol_wire_task(key, task, host, args);
|
|
2428
|
+
// Disabled because non-idempotency is required for try-catch
|
|
2237
2429
|
if (existen?.temp) {
|
|
2238
2430
|
$$.$mol_log3_warn({
|
|
2239
2431
|
place: '$mol_wire_task',
|
|
@@ -2266,7 +2458,7 @@ var $;
|
|
|
2266
2458
|
try {
|
|
2267
2459
|
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
2268
2460
|
}
|
|
2269
|
-
catch {
|
|
2461
|
+
catch { // Promises throw in strict mode
|
|
2270
2462
|
Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
|
|
2271
2463
|
}
|
|
2272
2464
|
}
|
|
@@ -2319,6 +2511,10 @@ var $;
|
|
|
2319
2511
|
props[field] = get_val;
|
|
2320
2512
|
return get_val;
|
|
2321
2513
|
}
|
|
2514
|
+
/**
|
|
2515
|
+
* Convert asynchronous (promise-based) API to synchronous by wrapping function and method calls in a fiber.
|
|
2516
|
+
* @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
|
|
2517
|
+
*/
|
|
2322
2518
|
function $mol_wire_sync(obj) {
|
|
2323
2519
|
return new Proxy(obj, {
|
|
2324
2520
|
get(obj, field) {
|
|
@@ -2480,6 +2676,7 @@ var $;
|
|
|
2480
2676
|
"use strict";
|
|
2481
2677
|
var $;
|
|
2482
2678
|
(function ($) {
|
|
2679
|
+
/** Derived debuggable error with stack */
|
|
2483
2680
|
function $mol_crypto_restack(error) {
|
|
2484
2681
|
error = new Error(error instanceof Error ? error.message : String(error), { cause: error });
|
|
2485
2682
|
$mol_fail_hidden(error);
|
|
@@ -2491,7 +2688,9 @@ var $;
|
|
|
2491
2688
|
"use strict";
|
|
2492
2689
|
var $;
|
|
2493
2690
|
(function ($) {
|
|
2691
|
+
/** Ed25519 public key for sign verifying. */
|
|
2494
2692
|
class $mol_crypto2_auditor extends $mol_crypto2_key {
|
|
2693
|
+
/** Native WebAPI public key. */
|
|
2495
2694
|
async native() {
|
|
2496
2695
|
return $mol_crypto_native.subtle.importKey('jwk', {
|
|
2497
2696
|
crv: "Ed25519",
|
|
@@ -2501,6 +2700,7 @@ var $;
|
|
|
2501
2700
|
x: this.toString(),
|
|
2502
2701
|
}, "Ed25519", Boolean('extractable'), ['verify']).catch($mol_crypto_restack);
|
|
2503
2702
|
}
|
|
2703
|
+
/** Verifies signature of data. */
|
|
2504
2704
|
async verify(data, sign) {
|
|
2505
2705
|
return await $mol_crypto_native.subtle.verify("Ed25519", await this.native(), sign, data).catch($mol_crypto_restack);
|
|
2506
2706
|
}
|
|
@@ -2515,13 +2715,16 @@ var $;
|
|
|
2515
2715
|
"use strict";
|
|
2516
2716
|
var $;
|
|
2517
2717
|
(function ($) {
|
|
2718
|
+
/** Ed25519 private key for data signing. */
|
|
2518
2719
|
class $mol_crypto2_signer extends $mol_crypto2_auditor {
|
|
2519
2720
|
static size_sign = 64;
|
|
2721
|
+
/** Generates new Signer. */
|
|
2520
2722
|
static async generate() {
|
|
2521
2723
|
const pair = await $mol_crypto_native.subtle.generateKey("Ed25519", Boolean('extractable'), ['sign', 'verify']).catch($mol_crypto_restack);
|
|
2522
2724
|
const { x, d } = await $mol_crypto_native.subtle.exportKey('jwk', pair.privateKey).catch($mol_crypto_restack);
|
|
2523
2725
|
return this.from(x + d);
|
|
2524
2726
|
}
|
|
2727
|
+
/** Native WebAPI private key. */
|
|
2525
2728
|
async nativePrivate() {
|
|
2526
2729
|
return await $mol_crypto_native.subtle.importKey('jwk', {
|
|
2527
2730
|
crv: "Ed25519",
|
|
@@ -2532,15 +2735,19 @@ var $;
|
|
|
2532
2735
|
d: this.toStringPrivate(),
|
|
2533
2736
|
}, "Ed25519", Boolean('extractable'), ['sign']).catch($mol_crypto_restack);
|
|
2534
2737
|
}
|
|
2738
|
+
/** Array view of private part. */
|
|
2535
2739
|
asArrayPrivate() {
|
|
2536
2740
|
return new Uint8Array(this.buffer, this.byteOffset + 32, 32);
|
|
2537
2741
|
}
|
|
2742
|
+
/** String representation of private part. */
|
|
2538
2743
|
toStringPrivate() {
|
|
2539
2744
|
return $mol_base64_url_encode(this.asArrayPrivate());
|
|
2540
2745
|
}
|
|
2746
|
+
/** Returns Auditor from this Signer. */
|
|
2541
2747
|
auditor() {
|
|
2542
2748
|
return $mol_crypto2_auditor.from(this.asArray());
|
|
2543
2749
|
}
|
|
2750
|
+
/** Makes Signature for data. */
|
|
2544
2751
|
async sign(data) {
|
|
2545
2752
|
return new Uint8Array(await $mol_crypto_native.subtle.sign("Ed25519", await this.nativePrivate(), data).catch($mol_crypto_restack));
|
|
2546
2753
|
}
|
|
@@ -2561,7 +2768,9 @@ var $;
|
|
|
2561
2768
|
"use strict";
|
|
2562
2769
|
var $;
|
|
2563
2770
|
(function ($) {
|
|
2771
|
+
/** x25519 public key for data encryption. */
|
|
2564
2772
|
class $mol_crypto2_socket extends $mol_crypto2_key {
|
|
2773
|
+
/** Native WebAPI public key. */
|
|
2565
2774
|
async native() {
|
|
2566
2775
|
return await $mol_crypto_native.subtle.importKey('jwk', {
|
|
2567
2776
|
crv: 'X25519',
|
|
@@ -2582,6 +2791,7 @@ var $;
|
|
|
2582
2791
|
"use strict";
|
|
2583
2792
|
var $;
|
|
2584
2793
|
(function ($) {
|
|
2794
|
+
/** 16 unique bytes. */
|
|
2585
2795
|
function $mol_crypto2_nonce() {
|
|
2586
2796
|
return $mol_crypto_native.getRandomValues(new Uint8Array(16));
|
|
2587
2797
|
}
|
|
@@ -2592,6 +2802,7 @@ var $;
|
|
|
2592
2802
|
"use strict";
|
|
2593
2803
|
var $;
|
|
2594
2804
|
(function ($) {
|
|
2805
|
+
/** @deprecated Use $mol_crypto2_nonce */
|
|
2595
2806
|
$.$mol_crypto_salt = $mol_crypto2_nonce;
|
|
2596
2807
|
})($ || ($ = {}));
|
|
2597
2808
|
|
|
@@ -2599,11 +2810,15 @@ var $;
|
|
|
2599
2810
|
"use strict";
|
|
2600
2811
|
var $;
|
|
2601
2812
|
(function ($) {
|
|
2813
|
+
/** Symmetric cipher with shortest payload. */
|
|
2602
2814
|
class $mol_crypto_sacred extends $mol_buffer {
|
|
2815
|
+
/** Key size in bytes. */
|
|
2603
2816
|
static size = 16;
|
|
2817
|
+
/** Makes new random secret. */
|
|
2604
2818
|
static make() {
|
|
2605
2819
|
return this.from($mol_crypto_salt());
|
|
2606
2820
|
}
|
|
2821
|
+
/** Makes from string of buffer view. */
|
|
2607
2822
|
static from(serial) {
|
|
2608
2823
|
if (typeof serial === 'string') {
|
|
2609
2824
|
serial = new Uint8Array([
|
|
@@ -2633,12 +2848,14 @@ var $;
|
|
|
2633
2848
|
return $mol_base64_url_encode(this.asArray());
|
|
2634
2849
|
}
|
|
2635
2850
|
_native;
|
|
2851
|
+
/** Native crypto secret */
|
|
2636
2852
|
async native() {
|
|
2637
2853
|
return this._native ?? (this._native = await $mol_crypto_native.subtle.importKey('raw', this, {
|
|
2638
2854
|
name: 'AES-CBC',
|
|
2639
2855
|
length: 128,
|
|
2640
2856
|
}, true, ['encrypt', 'decrypt']).catch($mol_crypto_restack));
|
|
2641
2857
|
}
|
|
2858
|
+
/** Encrypt any binary message. 16n bytes */
|
|
2642
2859
|
async encrypt(open, salt) {
|
|
2643
2860
|
return new Uint8Array(await $mol_crypto_native.subtle.encrypt({
|
|
2644
2861
|
name: 'AES-CBC',
|
|
@@ -2647,6 +2864,7 @@ var $;
|
|
|
2647
2864
|
iv: salt,
|
|
2648
2865
|
}, await this.native(), open).catch($mol_crypto_restack));
|
|
2649
2866
|
}
|
|
2867
|
+
/** Decrypt any binary message. */
|
|
2650
2868
|
async decrypt(closed, salt) {
|
|
2651
2869
|
return new Uint8Array(await $mol_crypto_native.subtle.decrypt({
|
|
2652
2870
|
name: 'AES-CBC',
|
|
@@ -2655,12 +2873,14 @@ var $;
|
|
|
2655
2873
|
iv: salt,
|
|
2656
2874
|
}, await this.native(), closed).catch($mol_crypto_restack));
|
|
2657
2875
|
}
|
|
2876
|
+
/** Encrypts 0xFF prefixed buffer. 16 bytes */
|
|
2658
2877
|
async close(opened, salt) {
|
|
2659
2878
|
if (opened.getUint8(0) !== 0xFF)
|
|
2660
2879
|
throw new Error('Closable buffer should starts with 0xFF');
|
|
2661
2880
|
const trimed = new Uint8Array(opened.buffer, opened.byteOffset + 1, opened.byteLength - 1);
|
|
2662
2881
|
return this.encrypt(trimed, salt);
|
|
2663
2882
|
}
|
|
2883
|
+
/** Decrypts 0xFF prefixed buffer. 16 bytes */
|
|
2664
2884
|
async open(closed, salt) {
|
|
2665
2885
|
const trimed = await this.decrypt(closed, salt);
|
|
2666
2886
|
if (trimed.byteLength !== closed.byteLength - 1)
|
|
@@ -2681,13 +2901,16 @@ var $;
|
|
|
2681
2901
|
"use strict";
|
|
2682
2902
|
var $;
|
|
2683
2903
|
(function ($) {
|
|
2904
|
+
/** x25519 private key for data encryption. */
|
|
2684
2905
|
class $mol_crypto2_cipher extends $mol_crypto2_socket {
|
|
2685
2906
|
static size_secret = 16;
|
|
2907
|
+
/** Generates new Cipher. */
|
|
2686
2908
|
static async generate() {
|
|
2687
2909
|
const pair = await $mol_crypto_native.subtle.generateKey("X25519", Boolean('extractable'), ['deriveKey']).catch($mol_crypto_restack);
|
|
2688
2910
|
const { x, d } = await $mol_crypto_native.subtle.exportKey('jwk', pair.privateKey).catch($mol_crypto_restack);
|
|
2689
2911
|
return this.from(x + d);
|
|
2690
2912
|
}
|
|
2913
|
+
/** Native WebAPI private key. */
|
|
2691
2914
|
async nativePrivate() {
|
|
2692
2915
|
return $mol_crypto_native.subtle.importKey('jwk', {
|
|
2693
2916
|
crv: 'X25519',
|
|
@@ -2698,15 +2921,19 @@ var $;
|
|
|
2698
2921
|
d: this.toStringPrivate(),
|
|
2699
2922
|
}, "X25519", Boolean('extractable'), ['deriveKey', 'deriveBits']).catch($mol_crypto_restack);
|
|
2700
2923
|
}
|
|
2924
|
+
/** Array view of private part. */
|
|
2701
2925
|
asArrayPrivate() {
|
|
2702
2926
|
return new Uint8Array(this.buffer, this.byteOffset + 32, 32);
|
|
2703
2927
|
}
|
|
2928
|
+
/** String representation of private part. */
|
|
2704
2929
|
toStringPrivate() {
|
|
2705
2930
|
return $mol_base64_url_encode(this.asArrayPrivate());
|
|
2706
2931
|
}
|
|
2932
|
+
/** Returns Socket from this Chipher. */
|
|
2707
2933
|
socket() {
|
|
2708
2934
|
return $mol_crypto2_socket.from(this.asArray());
|
|
2709
2935
|
}
|
|
2936
|
+
/** Makes shared secret for combination of Chiper and Soacket. */
|
|
2710
2937
|
async secret(pub) {
|
|
2711
2938
|
return $mol_crypto_sacred.from(new Uint8Array(await $mol_crypto_native.subtle.deriveBits({
|
|
2712
2939
|
name: "X25519",
|
|
@@ -2730,12 +2957,15 @@ var $;
|
|
|
2730
2957
|
"use strict";
|
|
2731
2958
|
var $;
|
|
2732
2959
|
(function ($) {
|
|
2960
|
+
/** Compose public key for verifying and encryption, based on Curve25519. */
|
|
2733
2961
|
class $mol_crypto2_public extends $mol_crypto2_key {
|
|
2734
2962
|
static size_str = 86;
|
|
2735
2963
|
static size_bin = 64;
|
|
2964
|
+
/** Return Auditor part. */
|
|
2736
2965
|
auditor() {
|
|
2737
2966
|
return $mol_crypto2_auditor.from(this.asArray().subarray(0, 32));
|
|
2738
2967
|
}
|
|
2968
|
+
/** Return Socket part. */
|
|
2739
2969
|
socket() {
|
|
2740
2970
|
return $mol_crypto2_socket.from(this.asArray().subarray(32, 64));
|
|
2741
2971
|
}
|
|
@@ -2759,7 +2989,9 @@ var $;
|
|
|
2759
2989
|
"use strict";
|
|
2760
2990
|
var $;
|
|
2761
2991
|
(function ($) {
|
|
2992
|
+
/** Compose private key for signing and encryption, based on Curve25519. */
|
|
2762
2993
|
class $mol_crypto2_private extends $mol_crypto2_public {
|
|
2994
|
+
/** Generates new private key. */
|
|
2763
2995
|
static async generate() {
|
|
2764
2996
|
const [signer, cipher] = await Promise.all([
|
|
2765
2997
|
$mol_crypto2_signer.generate(),
|
|
@@ -2772,24 +3004,29 @@ var $;
|
|
|
2772
3004
|
key.asArrayPrivate().set(cipher.asArrayPrivate(), 32);
|
|
2773
3005
|
return key;
|
|
2774
3006
|
}
|
|
3007
|
+
/** Return Signer part. */
|
|
2775
3008
|
signer() {
|
|
2776
3009
|
const signer = $mol_crypto2_signer.from($mol_crypto2_auditor.size_bin + $mol_crypto2_signer.size_bin);
|
|
2777
3010
|
signer.asArray().set(this.asArray().subarray(0, 32));
|
|
2778
3011
|
signer.asArrayPrivate().set(this.asArrayPrivate().subarray(0, 32));
|
|
2779
3012
|
return signer;
|
|
2780
3013
|
}
|
|
3014
|
+
/** Return Cipher part. */
|
|
2781
3015
|
cipher() {
|
|
2782
3016
|
const cipher = $mol_crypto2_cipher.from($mol_crypto2_socket.size_bin + $mol_crypto2_cipher.size_bin);
|
|
2783
3017
|
cipher.asArray().set(this.asArray().subarray(32, 64));
|
|
2784
3018
|
cipher.asArrayPrivate().set(this.asArrayPrivate().subarray(32, 64));
|
|
2785
3019
|
return cipher;
|
|
2786
3020
|
}
|
|
3021
|
+
/** Return Public part. */
|
|
2787
3022
|
public() {
|
|
2788
3023
|
return $mol_crypto2_public.from(this.asArray());
|
|
2789
3024
|
}
|
|
3025
|
+
/** Array view of private part. */
|
|
2790
3026
|
asArrayPrivate() {
|
|
2791
3027
|
return new Uint8Array(this.buffer, this.byteOffset + 64, 64);
|
|
2792
3028
|
}
|
|
3029
|
+
/** String representation of private part. */
|
|
2793
3030
|
toStringPrivate() {
|
|
2794
3031
|
return this.signer().toStringPrivate() + this.cipher().toStringPrivate();
|
|
2795
3032
|
}
|
|
@@ -3065,6 +3302,7 @@ var $;
|
|
|
3065
3302
|
"use strict";
|
|
3066
3303
|
var $;
|
|
3067
3304
|
(function ($) {
|
|
3305
|
+
/// @todo right orderinng
|
|
3068
3306
|
$.$mol_after_mock_queue = [];
|
|
3069
3307
|
function $mol_after_mock_warp() {
|
|
3070
3308
|
const queue = $.$mol_after_mock_queue.splice(0);
|
|
@@ -3208,6 +3446,9 @@ var $;
|
|
|
3208
3446
|
"use strict";
|
|
3209
3447
|
var $;
|
|
3210
3448
|
(function ($) {
|
|
3449
|
+
/**
|
|
3450
|
+
* Decorates method to fiber to ensure it is executed only once inside other fiber.
|
|
3451
|
+
*/
|
|
3211
3452
|
function $mol_wire_method(host, field, descr) {
|
|
3212
3453
|
if (!descr)
|
|
3213
3454
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -3234,6 +3475,7 @@ var $;
|
|
|
3234
3475
|
"use strict";
|
|
3235
3476
|
var $;
|
|
3236
3477
|
(function ($) {
|
|
3478
|
+
/** Convert a pseudo-synchronous (Suspense API) API to an explicit asynchronous one (for integrating with external systems). */
|
|
3237
3479
|
function $mol_wire_async(obj) {
|
|
3238
3480
|
let fiber;
|
|
3239
3481
|
const temp = $mol_wire_task.getter(obj);
|
|
@@ -3664,6 +3906,12 @@ var $;
|
|
|
3664
3906
|
createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
|
|
3665
3907
|
};
|
|
3666
3908
|
$.$mol_jsx_frag = '';
|
|
3909
|
+
/**
|
|
3910
|
+
* JSX adapter that makes DOM tree.
|
|
3911
|
+
* Generates global unique ids for every DOM-element by components tree with ids.
|
|
3912
|
+
* Ensures all local ids are unique.
|
|
3913
|
+
* Can reuse an existing nodes by GUIDs when used inside [`mol_jsx_attach`](https://github.com/hyoo-ru/mam_mol/tree/master/jsx/attach).
|
|
3914
|
+
*/
|
|
3667
3915
|
function $mol_jsx(Elem, props, ...childNodes) {
|
|
3668
3916
|
const id = props && props.id || '';
|
|
3669
3917
|
const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
|
|
@@ -3774,6 +4022,8 @@ var $;
|
|
|
3774
4022
|
|
|
3775
4023
|
;
|
|
3776
4024
|
"use strict";
|
|
4025
|
+
/** @jsx $mol_jsx */
|
|
4026
|
+
/** @jsxFrag $mol_jsx_frag */
|
|
3777
4027
|
var $;
|
|
3778
4028
|
(function ($) {
|
|
3779
4029
|
$mol_test({
|
|
@@ -3879,6 +4129,7 @@ var $;
|
|
|
3879
4129
|
"use strict";
|
|
3880
4130
|
var $;
|
|
3881
4131
|
(function ($) {
|
|
4132
|
+
/** Lazy computed lists with native Array interface. $mol_range2_array is mutable but all derived ranges are immutable. */
|
|
3882
4133
|
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
3883
4134
|
const source = typeof item === 'function' ? new $mol_range2_array() : item;
|
|
3884
4135
|
if (typeof item !== 'function') {
|
|
@@ -3927,6 +4178,7 @@ var $;
|
|
|
3927
4178
|
}
|
|
3928
4179
|
$.$mol_range2 = $mol_range2;
|
|
3929
4180
|
class $mol_range2_array extends Array {
|
|
4181
|
+
// Lazy
|
|
3930
4182
|
concat(...tail) {
|
|
3931
4183
|
if (tail.length === 0)
|
|
3932
4184
|
return this;
|
|
@@ -3938,6 +4190,7 @@ var $;
|
|
|
3938
4190
|
}
|
|
3939
4191
|
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
3940
4192
|
}
|
|
4193
|
+
// Lazy
|
|
3941
4194
|
filter(check, context) {
|
|
3942
4195
|
const filtered = [];
|
|
3943
4196
|
let cursor = -1;
|
|
@@ -3950,13 +4203,16 @@ var $;
|
|
|
3950
4203
|
return filtered[index];
|
|
3951
4204
|
}, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
|
|
3952
4205
|
}
|
|
4206
|
+
// Diligent
|
|
3953
4207
|
forEach(proceed, context) {
|
|
3954
4208
|
for (let [key, value] of this.entries())
|
|
3955
4209
|
proceed.call(context, value, key, this);
|
|
3956
4210
|
}
|
|
4211
|
+
// Lazy
|
|
3957
4212
|
map(proceed, context) {
|
|
3958
4213
|
return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
|
|
3959
4214
|
}
|
|
4215
|
+
// Diligent
|
|
3960
4216
|
reduce(merge, result) {
|
|
3961
4217
|
let index = 0;
|
|
3962
4218
|
if (arguments.length === 1) {
|
|
@@ -3967,12 +4223,15 @@ var $;
|
|
|
3967
4223
|
}
|
|
3968
4224
|
return result;
|
|
3969
4225
|
}
|
|
4226
|
+
// Lazy
|
|
3970
4227
|
toReversed() {
|
|
3971
4228
|
return $mol_range2(index => this[this.length - 1 - index], () => this.length);
|
|
3972
4229
|
}
|
|
4230
|
+
// Lazy
|
|
3973
4231
|
slice(from = 0, to = this.length) {
|
|
3974
4232
|
return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
|
|
3975
4233
|
}
|
|
4234
|
+
// Lazy
|
|
3976
4235
|
some(check, context) {
|
|
3977
4236
|
for (let index = 0; index < this.length; ++index) {
|
|
3978
4237
|
if (check.call(context, this[index], index, this))
|
|
@@ -4165,6 +4424,7 @@ var $;
|
|
|
4165
4424
|
|
|
4166
4425
|
;
|
|
4167
4426
|
"use strict";
|
|
4427
|
+
/** @jsx $mol_jsx */
|
|
4168
4428
|
var $;
|
|
4169
4429
|
(function ($) {
|
|
4170
4430
|
$mol_test({
|
|
@@ -4226,6 +4486,7 @@ var $;
|
|
|
4226
4486
|
const obj3_copy = { test: 3, obj2: obj2_copy };
|
|
4227
4487
|
obj1.obj3 = obj3;
|
|
4228
4488
|
obj1_copy.obj3 = obj3_copy;
|
|
4489
|
+
// warmup cache
|
|
4229
4490
|
$mol_assert_not($mol_compare_deep(obj1, {}));
|
|
4230
4491
|
$mol_assert_not($mol_compare_deep(obj2, {}));
|
|
4231
4492
|
$mol_assert_not($mol_compare_deep(obj3, {}));
|
|
@@ -4295,18 +4556,34 @@ var $;
|
|
|
4295
4556
|
"use strict";
|
|
4296
4557
|
var $;
|
|
4297
4558
|
(function ($) {
|
|
4559
|
+
/**
|
|
4560
|
+
* Argument must be Truthy
|
|
4561
|
+
* @deprecated use $mol_assert_equal instead
|
|
4562
|
+
*/
|
|
4298
4563
|
function $mol_assert_ok(value) {
|
|
4299
4564
|
if (value)
|
|
4300
4565
|
return;
|
|
4301
4566
|
$mol_fail(new Error(`${value} ≠ true`));
|
|
4302
4567
|
}
|
|
4303
4568
|
$.$mol_assert_ok = $mol_assert_ok;
|
|
4569
|
+
/**
|
|
4570
|
+
* Argument must be Falsy
|
|
4571
|
+
* @deprecated use $mol_assert_equal instead
|
|
4572
|
+
*/
|
|
4304
4573
|
function $mol_assert_not(value) {
|
|
4305
4574
|
if (!value)
|
|
4306
4575
|
return;
|
|
4307
4576
|
$mol_fail(new Error(`${value} ≠ false`));
|
|
4308
4577
|
}
|
|
4309
4578
|
$.$mol_assert_not = $mol_assert_not;
|
|
4579
|
+
/**
|
|
4580
|
+
* Handler must throw an error.
|
|
4581
|
+
* @example
|
|
4582
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } ) // Passes because throws error
|
|
4583
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , 'Parse error' ) // Passes because throws right message
|
|
4584
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , Error ) // Passes because throws right class
|
|
4585
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
4586
|
+
*/
|
|
4310
4587
|
function $mol_assert_fail(handler, ErrorRight) {
|
|
4311
4588
|
const fail = $.$mol_fail;
|
|
4312
4589
|
try {
|
|
@@ -4329,10 +4606,18 @@ var $;
|
|
|
4329
4606
|
$mol_fail(new Error('Not failed', { cause: { expect: ErrorRight } }));
|
|
4330
4607
|
}
|
|
4331
4608
|
$.$mol_assert_fail = $mol_assert_fail;
|
|
4609
|
+
/** @deprecated Use $mol_assert_equal */
|
|
4332
4610
|
function $mol_assert_like(...args) {
|
|
4333
4611
|
$mol_assert_equal(...args);
|
|
4334
4612
|
}
|
|
4335
4613
|
$.$mol_assert_like = $mol_assert_like;
|
|
4614
|
+
/**
|
|
4615
|
+
* All arguments must not be structural equal to each other.
|
|
4616
|
+
* @example
|
|
4617
|
+
* $mol_assert_unique( 1 , 2 , 3 ) // Passes
|
|
4618
|
+
* $mol_assert_unique( 1 , 1 , 2 ) // Fails because 1 === 1
|
|
4619
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
4620
|
+
*/
|
|
4336
4621
|
function $mol_assert_unique(...args) {
|
|
4337
4622
|
for (let i = 0; i < args.length; ++i) {
|
|
4338
4623
|
for (let j = 0; j < args.length; ++j) {
|
|
@@ -4345,6 +4630,13 @@ var $;
|
|
|
4345
4630
|
}
|
|
4346
4631
|
}
|
|
4347
4632
|
$.$mol_assert_unique = $mol_assert_unique;
|
|
4633
|
+
/**
|
|
4634
|
+
* All arguments must be structural equal each other.
|
|
4635
|
+
* @example
|
|
4636
|
+
* $mol_assert_like( [1] , [1] , [1] ) // Passes
|
|
4637
|
+
* $mol_assert_like( [1] , [1] , [2] ) // Fails because 1 !== 2
|
|
4638
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
4639
|
+
*/
|
|
4348
4640
|
function $mol_assert_equal(...args) {
|
|
4349
4641
|
for (let i = 1; i < args.length; ++i) {
|
|
4350
4642
|
if ($mol_compare_deep(args[0], args[i]))
|
|
@@ -4397,7 +4689,8 @@ var $;
|
|
|
4397
4689
|
"use strict";
|
|
4398
4690
|
var $;
|
|
4399
4691
|
(function ($) {
|
|
4400
|
-
let buf = new Uint8Array(2 ** 12);
|
|
4692
|
+
let buf = new Uint8Array(2 ** 12); // 4KB Mem Page
|
|
4693
|
+
/** Temporary buffer. Recursive usage isn't supported. */
|
|
4401
4694
|
function $mol_charset_buffer(size) {
|
|
4402
4695
|
if (buf.byteLength < size)
|
|
4403
4696
|
buf = new Uint8Array(size);
|
|
@@ -4419,19 +4712,19 @@ var $;
|
|
|
4419
4712
|
let pos = from;
|
|
4420
4713
|
for (let i = 0; i < str.length; i++) {
|
|
4421
4714
|
let code = str.charCodeAt(i);
|
|
4422
|
-
if (code < 0x80) {
|
|
4715
|
+
if (code < 0x80) { // ASCII - 1 octet
|
|
4423
4716
|
buf[pos++] = code;
|
|
4424
4717
|
}
|
|
4425
|
-
else if (code < 0x800) {
|
|
4718
|
+
else if (code < 0x800) { // 2 octet
|
|
4426
4719
|
buf[pos++] = 0xc0 | (code >> 6);
|
|
4427
4720
|
buf[pos++] = 0x80 | (code & 0x3f);
|
|
4428
4721
|
}
|
|
4429
|
-
else if (code < 0xd800 || code >= 0xe000) {
|
|
4722
|
+
else if (code < 0xd800 || code >= 0xe000) { // 3 octet
|
|
4430
4723
|
buf[pos++] = 0xe0 | (code >> 12);
|
|
4431
4724
|
buf[pos++] = 0x80 | ((code >> 6) & 0x3f);
|
|
4432
4725
|
buf[pos++] = 0x80 | (code & 0x3f);
|
|
4433
4726
|
}
|
|
4434
|
-
else {
|
|
4727
|
+
else { // surrogate pair
|
|
4435
4728
|
const point = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
|
|
4436
4729
|
buf[pos++] = 0xf0 | (point >> 18);
|
|
4437
4730
|
buf[pos++] = 0x80 | ((point >> 12) & 0x3f);
|
|
@@ -4825,6 +5118,12 @@ var $;
|
|
|
4825
5118
|
'return result without errors'() {
|
|
4826
5119
|
$mol_assert_equal($mol_try(() => false), false);
|
|
4827
5120
|
},
|
|
5121
|
+
//'return error if thrown'() {
|
|
5122
|
+
//
|
|
5123
|
+
// const error = new Error( '$mol_try test error' )
|
|
5124
|
+
// $mol_assert_equal( $mol_try( ()=> { throw error } ) , error )
|
|
5125
|
+
//
|
|
5126
|
+
//} ,
|
|
4828
5127
|
});
|
|
4829
5128
|
})($ || ($ = {}));
|
|
4830
5129
|
|
|
@@ -5129,6 +5428,7 @@ var $;
|
|
|
5129
5428
|
var $;
|
|
5130
5429
|
(function ($) {
|
|
5131
5430
|
let sponge = new Uint32Array(80);
|
|
5431
|
+
/** Fast small sync SHA-1 (20 bytes, 160 bits) */
|
|
5132
5432
|
function $mol_crypto2_hash(input) {
|
|
5133
5433
|
const data = input instanceof Uint8Array
|
|
5134
5434
|
? input
|
|
@@ -5143,7 +5443,9 @@ var $;
|
|
|
5143
5443
|
for (let i = wlen; i < data.length; ++i) {
|
|
5144
5444
|
tail |= data[i] << ((3 - i & 0b11) << 3);
|
|
5145
5445
|
}
|
|
5446
|
+
// Initial
|
|
5146
5447
|
const hash = new Int32Array([1732584193, -271733879, -1732584194, 271733878, -1009589776]);
|
|
5448
|
+
// Digest
|
|
5147
5449
|
for (let i = 0; i < bytes; i += 16) {
|
|
5148
5450
|
let h0 = hash[0];
|
|
5149
5451
|
let h1 = hash[1];
|
|
@@ -5219,7 +5521,7 @@ var $;
|
|
|
5219
5521
|
}
|
|
5220
5522
|
for (let i = 0; i < 20; ++i) {
|
|
5221
5523
|
const word = hash[i];
|
|
5222
|
-
hash[i] = word << 24 | word << 8 & 0xFF0000 | word >>> 8 & 0xFF00 | word >>> 24 & 0xFF;
|
|
5524
|
+
hash[i] = word << 24 | word << 8 & 0xFF0000 | word >>> 8 & 0xFF00 | word >>> 24 & 0xFF; // BE -> LE
|
|
5223
5525
|
}
|
|
5224
5526
|
return new Uint8Array(hash.buffer);
|
|
5225
5527
|
}
|