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/web.mjs
CHANGED
|
@@ -198,6 +198,7 @@ var $;
|
|
|
198
198
|
this.setUint16(offset + 4, (value / 2 ** 32) | 0, LE);
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
+
/** 1-byte signed integer channel for offset. */
|
|
201
202
|
int8(offset, next) {
|
|
202
203
|
if (next === undefined)
|
|
203
204
|
return this.getInt8(offset);
|
|
@@ -205,6 +206,7 @@ var $;
|
|
|
205
206
|
return this.setInt8(offset, next), next;
|
|
206
207
|
$mol_fail(new Error(`Wrong int8 value ${next}`));
|
|
207
208
|
}
|
|
209
|
+
/** 1-byte unsigned integer channel for offset. */
|
|
208
210
|
uint8(offset, next) {
|
|
209
211
|
if (next === undefined)
|
|
210
212
|
return this.getUint8(offset);
|
|
@@ -212,6 +214,7 @@ var $;
|
|
|
212
214
|
return this.setUint8(offset, next), next;
|
|
213
215
|
$mol_fail(new Error(`Wrong uint8 value ${next}`));
|
|
214
216
|
}
|
|
217
|
+
/** 2-byte signed integer little-endian channel for offset. */
|
|
215
218
|
int16(offset, next) {
|
|
216
219
|
if (next === undefined)
|
|
217
220
|
return this.getInt16(offset, true);
|
|
@@ -219,6 +222,7 @@ var $;
|
|
|
219
222
|
return this.setInt16(offset, next, true), next;
|
|
220
223
|
$mol_fail(new Error(`Wrong int16 value ${next}`));
|
|
221
224
|
}
|
|
225
|
+
/** 2-byte unsigned integer little-endian channel for offset. */
|
|
222
226
|
uint16(offset, next) {
|
|
223
227
|
if (next === undefined)
|
|
224
228
|
return this.getUint16(offset, true);
|
|
@@ -226,6 +230,7 @@ var $;
|
|
|
226
230
|
return this.setUint16(offset, next, true), next;
|
|
227
231
|
$mol_fail(new Error(`Wrong uint16 value ${next}`));
|
|
228
232
|
}
|
|
233
|
+
/** 4-byte signed integer little-endian channel for offset. */
|
|
229
234
|
int32(offset, next) {
|
|
230
235
|
if (next === undefined)
|
|
231
236
|
return this.getInt32(offset, true);
|
|
@@ -233,6 +238,7 @@ var $;
|
|
|
233
238
|
return this.setInt32(offset, next, true), next;
|
|
234
239
|
$mol_fail(new Error(`Wrong int32 value ${next}`));
|
|
235
240
|
}
|
|
241
|
+
/** 4-byte unsigned integer little-endian channel for offset. */
|
|
236
242
|
uint32(offset, next) {
|
|
237
243
|
if (next === undefined)
|
|
238
244
|
return this.getUint32(offset, true);
|
|
@@ -240,6 +246,7 @@ var $;
|
|
|
240
246
|
return this.setUint32(offset, next, true), next;
|
|
241
247
|
$mol_fail(new Error(`Wrong uint32 value ${next}`));
|
|
242
248
|
}
|
|
249
|
+
/** 8-byte signed integer little-endian channel for offset. */
|
|
243
250
|
int64(offset, next) {
|
|
244
251
|
if (next === undefined)
|
|
245
252
|
return this.getBigInt64(offset, true);
|
|
@@ -247,6 +254,7 @@ var $;
|
|
|
247
254
|
return this.setBigInt64(offset, next, true), next;
|
|
248
255
|
$mol_fail(new Error(`Wrong int64 value ${next}`));
|
|
249
256
|
}
|
|
257
|
+
/** 6-byte unsigned integer little-endian channel for offset. */
|
|
250
258
|
uint48(offset, next) {
|
|
251
259
|
if (next === undefined)
|
|
252
260
|
return this.getUint48(offset, true);
|
|
@@ -254,6 +262,7 @@ var $;
|
|
|
254
262
|
return this.setUint48(offset, next, true), next;
|
|
255
263
|
$mol_fail(new Error(`Wrong uint48 value ${next}`));
|
|
256
264
|
}
|
|
265
|
+
/** 8-byte unsigned integer little-endian channel for offset. */
|
|
257
266
|
uint64(offset, next) {
|
|
258
267
|
if (next === undefined)
|
|
259
268
|
return this.getBigUint64(offset, true);
|
|
@@ -261,24 +270,29 @@ var $;
|
|
|
261
270
|
return this.setBigUint64(offset, next, true), next;
|
|
262
271
|
$mol_fail(new Error(`Wrong uint64 value ${next}`));
|
|
263
272
|
}
|
|
273
|
+
/** 2-byte float little-endian channel for offset. */
|
|
264
274
|
float16(offset, next) {
|
|
265
275
|
if (next !== undefined)
|
|
266
276
|
this.setFloat16(offset, next, true);
|
|
267
277
|
return this.getFloat16(offset, true);
|
|
268
278
|
}
|
|
279
|
+
/** 4-byte float little-endian channel for offset. */
|
|
269
280
|
float32(offset, next) {
|
|
270
281
|
if (next !== undefined)
|
|
271
282
|
this.setFloat32(offset, next, true);
|
|
272
283
|
return this.getFloat32(offset, true);
|
|
273
284
|
}
|
|
285
|
+
/** 8-byte float little-endian channel for offset. */
|
|
274
286
|
float64(offset, next) {
|
|
275
287
|
if (next !== undefined)
|
|
276
288
|
this.setFloat64(offset, next, true);
|
|
277
289
|
return this.getFloat64(offset, true);
|
|
278
290
|
}
|
|
291
|
+
/** A Uint8Array view for the same buffer. */
|
|
279
292
|
asArray() {
|
|
280
293
|
return new Uint8Array(this.buffer, this.byteOffset, this.byteLength);
|
|
281
294
|
}
|
|
295
|
+
/** base64ae string from buffer. */
|
|
282
296
|
toString() {
|
|
283
297
|
return $mol_base64_ae_encode(this.asArray());
|
|
284
298
|
}
|
|
@@ -336,6 +350,11 @@ var $;
|
|
|
336
350
|
var $;
|
|
337
351
|
(function ($) {
|
|
338
352
|
const instances = new WeakSet();
|
|
353
|
+
/**
|
|
354
|
+
* Proxy that delegates all to lazy returned target.
|
|
355
|
+
*
|
|
356
|
+
* $mol_delegate( Array.prototype , ()=> fetch_array() )
|
|
357
|
+
*/
|
|
339
358
|
function $mol_delegate(proto, target) {
|
|
340
359
|
const proxy = new Proxy(proto, {
|
|
341
360
|
get: (_, field) => {
|
|
@@ -429,7 +448,7 @@ var $;
|
|
|
429
448
|
var $;
|
|
430
449
|
(function ($) {
|
|
431
450
|
function $mol_fail_hidden(error) {
|
|
432
|
-
throw error;
|
|
451
|
+
throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
|
|
433
452
|
}
|
|
434
453
|
$.$mol_fail_hidden = $mol_fail_hidden;
|
|
435
454
|
})($ || ($ = {}));
|
|
@@ -489,6 +508,9 @@ var $;
|
|
|
489
508
|
[Symbol.dispose]() {
|
|
490
509
|
this.destructor();
|
|
491
510
|
}
|
|
511
|
+
//[ Symbol.toPrimitive ]( hint: string ) {
|
|
512
|
+
// return hint === 'number' ? this.valueOf() : this.toString()
|
|
513
|
+
//}
|
|
492
514
|
toString() {
|
|
493
515
|
return this[Symbol.toStringTag] || this.constructor.name + '<>';
|
|
494
516
|
}
|
|
@@ -559,9 +581,11 @@ var $;
|
|
|
559
581
|
"use strict";
|
|
560
582
|
var $;
|
|
561
583
|
(function ($) {
|
|
584
|
+
/** Base class for crypto keys. */
|
|
562
585
|
class $mol_crypto2_key extends $mol_buffer {
|
|
563
586
|
static size_str = 43;
|
|
564
587
|
static size_bin = 32;
|
|
588
|
+
/** Kakes key from different params. */
|
|
565
589
|
static from(serial) {
|
|
566
590
|
if (typeof serial === 'string') {
|
|
567
591
|
serial = new Uint8Array(serial.match(/.{43}/g)
|
|
@@ -573,6 +597,7 @@ var $;
|
|
|
573
597
|
}
|
|
574
598
|
return super.from(serial);
|
|
575
599
|
}
|
|
600
|
+
/** Array view of public part. */
|
|
576
601
|
asArray() {
|
|
577
602
|
const size = this.constructor.size_bin;
|
|
578
603
|
if (this.byteLength < size) {
|
|
@@ -583,6 +608,7 @@ var $;
|
|
|
583
608
|
}
|
|
584
609
|
return new Uint8Array(this.buffer, this.byteOffset, size);
|
|
585
610
|
}
|
|
611
|
+
/** String representation of public part. */
|
|
586
612
|
toString() {
|
|
587
613
|
return $mol_base64_url_encode(this.asArray());
|
|
588
614
|
}
|
|
@@ -604,6 +630,7 @@ var $;
|
|
|
604
630
|
"use strict";
|
|
605
631
|
var $;
|
|
606
632
|
(function ($) {
|
|
633
|
+
/** Derived debuggable error with stack */
|
|
607
634
|
function $mol_crypto_restack(error) {
|
|
608
635
|
error = new Error(error instanceof Error ? error.message : String(error), { cause: error });
|
|
609
636
|
$mol_fail_hidden(error);
|
|
@@ -615,7 +642,9 @@ var $;
|
|
|
615
642
|
"use strict";
|
|
616
643
|
var $;
|
|
617
644
|
(function ($) {
|
|
645
|
+
/** Ed25519 public key for sign verifying. */
|
|
618
646
|
class $mol_crypto2_auditor extends $mol_crypto2_key {
|
|
647
|
+
/** Native WebAPI public key. */
|
|
619
648
|
async native() {
|
|
620
649
|
return $mol_crypto_native.subtle.importKey('jwk', {
|
|
621
650
|
crv: "Ed25519",
|
|
@@ -625,6 +654,7 @@ var $;
|
|
|
625
654
|
x: this.toString(),
|
|
626
655
|
}, "Ed25519", Boolean('extractable'), ['verify']).catch($mol_crypto_restack);
|
|
627
656
|
}
|
|
657
|
+
/** Verifies signature of data. */
|
|
628
658
|
async verify(data, sign) {
|
|
629
659
|
return await $mol_crypto_native.subtle.verify("Ed25519", await this.native(), sign, data).catch($mol_crypto_restack);
|
|
630
660
|
}
|
|
@@ -639,13 +669,16 @@ var $;
|
|
|
639
669
|
"use strict";
|
|
640
670
|
var $;
|
|
641
671
|
(function ($) {
|
|
672
|
+
/** Ed25519 private key for data signing. */
|
|
642
673
|
class $mol_crypto2_signer extends $mol_crypto2_auditor {
|
|
643
674
|
static size_sign = 64;
|
|
675
|
+
/** Generates new Signer. */
|
|
644
676
|
static async generate() {
|
|
645
677
|
const pair = await $mol_crypto_native.subtle.generateKey("Ed25519", Boolean('extractable'), ['sign', 'verify']).catch($mol_crypto_restack);
|
|
646
678
|
const { x, d } = await $mol_crypto_native.subtle.exportKey('jwk', pair.privateKey).catch($mol_crypto_restack);
|
|
647
679
|
return this.from(x + d);
|
|
648
680
|
}
|
|
681
|
+
/** Native WebAPI private key. */
|
|
649
682
|
async nativePrivate() {
|
|
650
683
|
return await $mol_crypto_native.subtle.importKey('jwk', {
|
|
651
684
|
crv: "Ed25519",
|
|
@@ -656,15 +689,19 @@ var $;
|
|
|
656
689
|
d: this.toStringPrivate(),
|
|
657
690
|
}, "Ed25519", Boolean('extractable'), ['sign']).catch($mol_crypto_restack);
|
|
658
691
|
}
|
|
692
|
+
/** Array view of private part. */
|
|
659
693
|
asArrayPrivate() {
|
|
660
694
|
return new Uint8Array(this.buffer, this.byteOffset + 32, 32);
|
|
661
695
|
}
|
|
696
|
+
/** String representation of private part. */
|
|
662
697
|
toStringPrivate() {
|
|
663
698
|
return $mol_base64_url_encode(this.asArrayPrivate());
|
|
664
699
|
}
|
|
700
|
+
/** Returns Auditor from this Signer. */
|
|
665
701
|
auditor() {
|
|
666
702
|
return $mol_crypto2_auditor.from(this.asArray());
|
|
667
703
|
}
|
|
704
|
+
/** Makes Signature for data. */
|
|
668
705
|
async sign(data) {
|
|
669
706
|
return new Uint8Array(await $mol_crypto_native.subtle.sign("Ed25519", await this.nativePrivate(), data).catch($mol_crypto_restack));
|
|
670
707
|
}
|
|
@@ -685,7 +722,9 @@ var $;
|
|
|
685
722
|
"use strict";
|
|
686
723
|
var $;
|
|
687
724
|
(function ($) {
|
|
725
|
+
/** x25519 public key for data encryption. */
|
|
688
726
|
class $mol_crypto2_socket extends $mol_crypto2_key {
|
|
727
|
+
/** Native WebAPI public key. */
|
|
689
728
|
async native() {
|
|
690
729
|
return await $mol_crypto_native.subtle.importKey('jwk', {
|
|
691
730
|
crv: 'X25519',
|
|
@@ -706,6 +745,7 @@ var $;
|
|
|
706
745
|
"use strict";
|
|
707
746
|
var $;
|
|
708
747
|
(function ($) {
|
|
748
|
+
/** 16 unique bytes. */
|
|
709
749
|
function $mol_crypto2_nonce() {
|
|
710
750
|
return $mol_crypto_native.getRandomValues(new Uint8Array(16));
|
|
711
751
|
}
|
|
@@ -716,6 +756,7 @@ var $;
|
|
|
716
756
|
"use strict";
|
|
717
757
|
var $;
|
|
718
758
|
(function ($) {
|
|
759
|
+
/** @deprecated Use $mol_crypto2_nonce */
|
|
719
760
|
$.$mol_crypto_salt = $mol_crypto2_nonce;
|
|
720
761
|
})($ || ($ = {}));
|
|
721
762
|
|
|
@@ -723,11 +764,15 @@ var $;
|
|
|
723
764
|
"use strict";
|
|
724
765
|
var $;
|
|
725
766
|
(function ($) {
|
|
767
|
+
/** Symmetric cipher with shortest payload. */
|
|
726
768
|
class $mol_crypto_sacred extends $mol_buffer {
|
|
769
|
+
/** Key size in bytes. */
|
|
727
770
|
static size = 16;
|
|
771
|
+
/** Makes new random secret. */
|
|
728
772
|
static make() {
|
|
729
773
|
return this.from($mol_crypto_salt());
|
|
730
774
|
}
|
|
775
|
+
/** Makes from string of buffer view. */
|
|
731
776
|
static from(serial) {
|
|
732
777
|
if (typeof serial === 'string') {
|
|
733
778
|
serial = new Uint8Array([
|
|
@@ -757,12 +802,14 @@ var $;
|
|
|
757
802
|
return $mol_base64_url_encode(this.asArray());
|
|
758
803
|
}
|
|
759
804
|
_native;
|
|
805
|
+
/** Native crypto secret */
|
|
760
806
|
async native() {
|
|
761
807
|
return this._native ?? (this._native = await $mol_crypto_native.subtle.importKey('raw', this, {
|
|
762
808
|
name: 'AES-CBC',
|
|
763
809
|
length: 128,
|
|
764
810
|
}, true, ['encrypt', 'decrypt']).catch($mol_crypto_restack));
|
|
765
811
|
}
|
|
812
|
+
/** Encrypt any binary message. 16n bytes */
|
|
766
813
|
async encrypt(open, salt) {
|
|
767
814
|
return new Uint8Array(await $mol_crypto_native.subtle.encrypt({
|
|
768
815
|
name: 'AES-CBC',
|
|
@@ -771,6 +818,7 @@ var $;
|
|
|
771
818
|
iv: salt,
|
|
772
819
|
}, await this.native(), open).catch($mol_crypto_restack));
|
|
773
820
|
}
|
|
821
|
+
/** Decrypt any binary message. */
|
|
774
822
|
async decrypt(closed, salt) {
|
|
775
823
|
return new Uint8Array(await $mol_crypto_native.subtle.decrypt({
|
|
776
824
|
name: 'AES-CBC',
|
|
@@ -779,12 +827,14 @@ var $;
|
|
|
779
827
|
iv: salt,
|
|
780
828
|
}, await this.native(), closed).catch($mol_crypto_restack));
|
|
781
829
|
}
|
|
830
|
+
/** Encrypts 0xFF prefixed buffer. 16 bytes */
|
|
782
831
|
async close(opened, salt) {
|
|
783
832
|
if (opened.getUint8(0) !== 0xFF)
|
|
784
833
|
throw new Error('Closable buffer should starts with 0xFF');
|
|
785
834
|
const trimed = new Uint8Array(opened.buffer, opened.byteOffset + 1, opened.byteLength - 1);
|
|
786
835
|
return this.encrypt(trimed, salt);
|
|
787
836
|
}
|
|
837
|
+
/** Decrypts 0xFF prefixed buffer. 16 bytes */
|
|
788
838
|
async open(closed, salt) {
|
|
789
839
|
const trimed = await this.decrypt(closed, salt);
|
|
790
840
|
if (trimed.byteLength !== closed.byteLength - 1)
|
|
@@ -805,13 +855,16 @@ var $;
|
|
|
805
855
|
"use strict";
|
|
806
856
|
var $;
|
|
807
857
|
(function ($) {
|
|
858
|
+
/** x25519 private key for data encryption. */
|
|
808
859
|
class $mol_crypto2_cipher extends $mol_crypto2_socket {
|
|
809
860
|
static size_secret = 16;
|
|
861
|
+
/** Generates new Cipher. */
|
|
810
862
|
static async generate() {
|
|
811
863
|
const pair = await $mol_crypto_native.subtle.generateKey("X25519", Boolean('extractable'), ['deriveKey']).catch($mol_crypto_restack);
|
|
812
864
|
const { x, d } = await $mol_crypto_native.subtle.exportKey('jwk', pair.privateKey).catch($mol_crypto_restack);
|
|
813
865
|
return this.from(x + d);
|
|
814
866
|
}
|
|
867
|
+
/** Native WebAPI private key. */
|
|
815
868
|
async nativePrivate() {
|
|
816
869
|
return $mol_crypto_native.subtle.importKey('jwk', {
|
|
817
870
|
crv: 'X25519',
|
|
@@ -822,15 +875,19 @@ var $;
|
|
|
822
875
|
d: this.toStringPrivate(),
|
|
823
876
|
}, "X25519", Boolean('extractable'), ['deriveKey', 'deriveBits']).catch($mol_crypto_restack);
|
|
824
877
|
}
|
|
878
|
+
/** Array view of private part. */
|
|
825
879
|
asArrayPrivate() {
|
|
826
880
|
return new Uint8Array(this.buffer, this.byteOffset + 32, 32);
|
|
827
881
|
}
|
|
882
|
+
/** String representation of private part. */
|
|
828
883
|
toStringPrivate() {
|
|
829
884
|
return $mol_base64_url_encode(this.asArrayPrivate());
|
|
830
885
|
}
|
|
886
|
+
/** Returns Socket from this Chipher. */
|
|
831
887
|
socket() {
|
|
832
888
|
return $mol_crypto2_socket.from(this.asArray());
|
|
833
889
|
}
|
|
890
|
+
/** Makes shared secret for combination of Chiper and Soacket. */
|
|
834
891
|
async secret(pub) {
|
|
835
892
|
return $mol_crypto_sacred.from(new Uint8Array(await $mol_crypto_native.subtle.deriveBits({
|
|
836
893
|
name: "X25519",
|
|
@@ -854,12 +911,15 @@ var $;
|
|
|
854
911
|
"use strict";
|
|
855
912
|
var $;
|
|
856
913
|
(function ($) {
|
|
914
|
+
/** Compose public key for verifying and encryption, based on Curve25519. */
|
|
857
915
|
class $mol_crypto2_public extends $mol_crypto2_key {
|
|
858
916
|
static size_str = 86;
|
|
859
917
|
static size_bin = 64;
|
|
918
|
+
/** Return Auditor part. */
|
|
860
919
|
auditor() {
|
|
861
920
|
return $mol_crypto2_auditor.from(this.asArray().subarray(0, 32));
|
|
862
921
|
}
|
|
922
|
+
/** Return Socket part. */
|
|
863
923
|
socket() {
|
|
864
924
|
return $mol_crypto2_socket.from(this.asArray().subarray(32, 64));
|
|
865
925
|
}
|
|
@@ -883,7 +943,9 @@ var $;
|
|
|
883
943
|
"use strict";
|
|
884
944
|
var $;
|
|
885
945
|
(function ($) {
|
|
946
|
+
/** Compose private key for signing and encryption, based on Curve25519. */
|
|
886
947
|
class $mol_crypto2_private extends $mol_crypto2_public {
|
|
948
|
+
/** Generates new private key. */
|
|
887
949
|
static async generate() {
|
|
888
950
|
const [signer, cipher] = await Promise.all([
|
|
889
951
|
$mol_crypto2_signer.generate(),
|
|
@@ -896,24 +958,29 @@ var $;
|
|
|
896
958
|
key.asArrayPrivate().set(cipher.asArrayPrivate(), 32);
|
|
897
959
|
return key;
|
|
898
960
|
}
|
|
961
|
+
/** Return Signer part. */
|
|
899
962
|
signer() {
|
|
900
963
|
const signer = $mol_crypto2_signer.from($mol_crypto2_auditor.size_bin + $mol_crypto2_signer.size_bin);
|
|
901
964
|
signer.asArray().set(this.asArray().subarray(0, 32));
|
|
902
965
|
signer.asArrayPrivate().set(this.asArrayPrivate().subarray(0, 32));
|
|
903
966
|
return signer;
|
|
904
967
|
}
|
|
968
|
+
/** Return Cipher part. */
|
|
905
969
|
cipher() {
|
|
906
970
|
const cipher = $mol_crypto2_cipher.from($mol_crypto2_socket.size_bin + $mol_crypto2_cipher.size_bin);
|
|
907
971
|
cipher.asArray().set(this.asArray().subarray(32, 64));
|
|
908
972
|
cipher.asArrayPrivate().set(this.asArrayPrivate().subarray(32, 64));
|
|
909
973
|
return cipher;
|
|
910
974
|
}
|
|
975
|
+
/** Return Public part. */
|
|
911
976
|
public() {
|
|
912
977
|
return $mol_crypto2_public.from(this.asArray());
|
|
913
978
|
}
|
|
979
|
+
/** Array view of private part. */
|
|
914
980
|
asArrayPrivate() {
|
|
915
981
|
return new Uint8Array(this.buffer, this.byteOffset + 64, 64);
|
|
916
982
|
}
|
|
983
|
+
/** String representation of private part. */
|
|
917
984
|
toStringPrivate() {
|
|
918
985
|
return this.signer().toStringPrivate() + this.cipher().toStringPrivate();
|
|
919
986
|
}
|
package/web.test.js
CHANGED
|
@@ -204,6 +204,12 @@ var $;
|
|
|
204
204
|
createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
|
|
205
205
|
};
|
|
206
206
|
$.$mol_jsx_frag = '';
|
|
207
|
+
/**
|
|
208
|
+
* JSX adapter that makes DOM tree.
|
|
209
|
+
* Generates global unique ids for every DOM-element by components tree with ids.
|
|
210
|
+
* Ensures all local ids are unique.
|
|
211
|
+
* Can reuse an existing nodes by GUIDs when used inside [`mol_jsx_attach`](https://github.com/hyoo-ru/mam_mol/tree/master/jsx/attach).
|
|
212
|
+
*/
|
|
207
213
|
function $mol_jsx(Elem, props, ...childNodes) {
|
|
208
214
|
const id = props && props.id || '';
|
|
209
215
|
const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
|
|
@@ -314,6 +320,8 @@ var $;
|
|
|
314
320
|
|
|
315
321
|
;
|
|
316
322
|
"use strict";
|
|
323
|
+
/** @jsx $mol_jsx */
|
|
324
|
+
/** @jsxFrag $mol_jsx_frag */
|
|
317
325
|
var $;
|
|
318
326
|
(function ($) {
|
|
319
327
|
$mol_test({
|
|
@@ -419,6 +427,7 @@ var $;
|
|
|
419
427
|
"use strict";
|
|
420
428
|
var $;
|
|
421
429
|
(function ($) {
|
|
430
|
+
/** Generates unique identifier. */
|
|
422
431
|
function $mol_guid(length = 8, exists = () => false) {
|
|
423
432
|
for (;;) {
|
|
424
433
|
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
@@ -434,6 +443,7 @@ var $;
|
|
|
434
443
|
"use strict";
|
|
435
444
|
var $;
|
|
436
445
|
(function ($) {
|
|
446
|
+
/** Lazy computed lists with native Array interface. $mol_range2_array is mutable but all derived ranges are immutable. */
|
|
437
447
|
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
438
448
|
const source = typeof item === 'function' ? new $mol_range2_array() : item;
|
|
439
449
|
if (typeof item !== 'function') {
|
|
@@ -482,6 +492,7 @@ var $;
|
|
|
482
492
|
}
|
|
483
493
|
$.$mol_range2 = $mol_range2;
|
|
484
494
|
class $mol_range2_array extends Array {
|
|
495
|
+
// Lazy
|
|
485
496
|
concat(...tail) {
|
|
486
497
|
if (tail.length === 0)
|
|
487
498
|
return this;
|
|
@@ -493,6 +504,7 @@ var $;
|
|
|
493
504
|
}
|
|
494
505
|
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
495
506
|
}
|
|
507
|
+
// Lazy
|
|
496
508
|
filter(check, context) {
|
|
497
509
|
const filtered = [];
|
|
498
510
|
let cursor = -1;
|
|
@@ -505,13 +517,16 @@ var $;
|
|
|
505
517
|
return filtered[index];
|
|
506
518
|
}, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
|
|
507
519
|
}
|
|
520
|
+
// Diligent
|
|
508
521
|
forEach(proceed, context) {
|
|
509
522
|
for (let [key, value] of this.entries())
|
|
510
523
|
proceed.call(context, value, key, this);
|
|
511
524
|
}
|
|
525
|
+
// Lazy
|
|
512
526
|
map(proceed, context) {
|
|
513
527
|
return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
|
|
514
528
|
}
|
|
529
|
+
// Diligent
|
|
515
530
|
reduce(merge, result) {
|
|
516
531
|
let index = 0;
|
|
517
532
|
if (arguments.length === 1) {
|
|
@@ -522,12 +537,15 @@ var $;
|
|
|
522
537
|
}
|
|
523
538
|
return result;
|
|
524
539
|
}
|
|
540
|
+
// Lazy
|
|
525
541
|
toReversed() {
|
|
526
542
|
return $mol_range2(index => this[this.length - 1 - index], () => this.length);
|
|
527
543
|
}
|
|
544
|
+
// Lazy
|
|
528
545
|
slice(from = 0, to = this.length) {
|
|
529
546
|
return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
|
|
530
547
|
}
|
|
548
|
+
// Lazy
|
|
531
549
|
some(check, context) {
|
|
532
550
|
for (let index = 0; index < this.length; ++index) {
|
|
533
551
|
if (check.call(context, this[index], index, this))
|
|
@@ -723,6 +741,10 @@ var $;
|
|
|
723
741
|
var $;
|
|
724
742
|
(function ($) {
|
|
725
743
|
$.$mol_compare_deep_cache = new WeakMap();
|
|
744
|
+
/**
|
|
745
|
+
* Deeply compares two values. Returns true if equal.
|
|
746
|
+
* Define `Symbol.toPrimitive` to customize.
|
|
747
|
+
*/
|
|
726
748
|
function $mol_compare_deep(left, right) {
|
|
727
749
|
if (Object.is(left, right))
|
|
728
750
|
return true;
|
|
@@ -860,6 +882,7 @@ var $;
|
|
|
860
882
|
|
|
861
883
|
;
|
|
862
884
|
"use strict";
|
|
885
|
+
/** @jsx $mol_jsx */
|
|
863
886
|
var $;
|
|
864
887
|
(function ($) {
|
|
865
888
|
$mol_test({
|
|
@@ -921,6 +944,7 @@ var $;
|
|
|
921
944
|
const obj3_copy = { test: 3, obj2: obj2_copy };
|
|
922
945
|
obj1.obj3 = obj3;
|
|
923
946
|
obj1_copy.obj3 = obj3_copy;
|
|
947
|
+
// warmup cache
|
|
924
948
|
$mol_assert_not($mol_compare_deep(obj1, {}));
|
|
925
949
|
$mol_assert_not($mol_compare_deep(obj2, {}));
|
|
926
950
|
$mol_assert_not($mol_compare_deep(obj3, {}));
|
|
@@ -990,6 +1014,7 @@ var $;
|
|
|
990
1014
|
"use strict";
|
|
991
1015
|
var $;
|
|
992
1016
|
(function ($) {
|
|
1017
|
+
// https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview#
|
|
993
1018
|
$['devtoolsFormatters'] ||= [];
|
|
994
1019
|
function $mol_dev_format_register(config) {
|
|
995
1020
|
$['devtoolsFormatters'].push(config);
|
|
@@ -1041,6 +1066,7 @@ var $;
|
|
|
1041
1066
|
return false;
|
|
1042
1067
|
if (!val)
|
|
1043
1068
|
return false;
|
|
1069
|
+
// if( Error.isError( val ) ) true
|
|
1044
1070
|
if (val[$.$mol_dev_format_body])
|
|
1045
1071
|
return true;
|
|
1046
1072
|
return false;
|
|
@@ -1058,12 +1084,16 @@ var $;
|
|
|
1058
1084
|
return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
|
|
1059
1085
|
}
|
|
1060
1086
|
}
|
|
1087
|
+
// if( Error.isError( val ) ) {
|
|
1088
|
+
// return $mol_dev_format_native( val )
|
|
1089
|
+
// }
|
|
1061
1090
|
return null;
|
|
1062
1091
|
},
|
|
1063
1092
|
});
|
|
1064
1093
|
function $mol_dev_format_native(obj) {
|
|
1065
1094
|
if (typeof obj === 'undefined')
|
|
1066
1095
|
return $.$mol_dev_format_shade('undefined');
|
|
1096
|
+
// if( ![ 'object', 'function', 'symbol' ].includes( typeof obj ) ) return obj
|
|
1067
1097
|
return [
|
|
1068
1098
|
'object',
|
|
1069
1099
|
{
|
|
@@ -1121,6 +1151,9 @@ var $;
|
|
|
1121
1151
|
'margin-left': '13px'
|
|
1122
1152
|
});
|
|
1123
1153
|
class Stack extends Array {
|
|
1154
|
+
// [ Symbol.toPrimitive ]() {
|
|
1155
|
+
// return this.toString()
|
|
1156
|
+
// }
|
|
1124
1157
|
toString() {
|
|
1125
1158
|
return this.join('\n');
|
|
1126
1159
|
}
|
|
@@ -1143,6 +1176,7 @@ var $;
|
|
|
1143
1176
|
this.method = call.getMethodName() ?? '';
|
|
1144
1177
|
if (this.method === this.function)
|
|
1145
1178
|
this.method = '';
|
|
1179
|
+
// const func = c.getFunction()
|
|
1146
1180
|
this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
|
|
1147
1181
|
this.eval = call.getEvalOrigin() ?? '';
|
|
1148
1182
|
this.source = call.getScriptNameOrSourceURL() ?? '';
|
|
@@ -1189,18 +1223,34 @@ var $;
|
|
|
1189
1223
|
"use strict";
|
|
1190
1224
|
var $;
|
|
1191
1225
|
(function ($) {
|
|
1226
|
+
/**
|
|
1227
|
+
* Argument must be Truthy
|
|
1228
|
+
* @deprecated use $mol_assert_equal instead
|
|
1229
|
+
*/
|
|
1192
1230
|
function $mol_assert_ok(value) {
|
|
1193
1231
|
if (value)
|
|
1194
1232
|
return;
|
|
1195
1233
|
$mol_fail(new Error(`${value} ≠ true`));
|
|
1196
1234
|
}
|
|
1197
1235
|
$.$mol_assert_ok = $mol_assert_ok;
|
|
1236
|
+
/**
|
|
1237
|
+
* Argument must be Falsy
|
|
1238
|
+
* @deprecated use $mol_assert_equal instead
|
|
1239
|
+
*/
|
|
1198
1240
|
function $mol_assert_not(value) {
|
|
1199
1241
|
if (!value)
|
|
1200
1242
|
return;
|
|
1201
1243
|
$mol_fail(new Error(`${value} ≠ false`));
|
|
1202
1244
|
}
|
|
1203
1245
|
$.$mol_assert_not = $mol_assert_not;
|
|
1246
|
+
/**
|
|
1247
|
+
* Handler must throw an error.
|
|
1248
|
+
* @example
|
|
1249
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } ) // Passes because throws error
|
|
1250
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , 'Parse error' ) // Passes because throws right message
|
|
1251
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , Error ) // Passes because throws right class
|
|
1252
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
1253
|
+
*/
|
|
1204
1254
|
function $mol_assert_fail(handler, ErrorRight) {
|
|
1205
1255
|
const fail = $.$mol_fail;
|
|
1206
1256
|
try {
|
|
@@ -1223,10 +1273,18 @@ var $;
|
|
|
1223
1273
|
$mol_fail(new Error('Not failed', { cause: { expect: ErrorRight } }));
|
|
1224
1274
|
}
|
|
1225
1275
|
$.$mol_assert_fail = $mol_assert_fail;
|
|
1276
|
+
/** @deprecated Use $mol_assert_equal */
|
|
1226
1277
|
function $mol_assert_like(...args) {
|
|
1227
1278
|
$mol_assert_equal(...args);
|
|
1228
1279
|
}
|
|
1229
1280
|
$.$mol_assert_like = $mol_assert_like;
|
|
1281
|
+
/**
|
|
1282
|
+
* All arguments must not be structural equal to each other.
|
|
1283
|
+
* @example
|
|
1284
|
+
* $mol_assert_unique( 1 , 2 , 3 ) // Passes
|
|
1285
|
+
* $mol_assert_unique( 1 , 1 , 2 ) // Fails because 1 === 1
|
|
1286
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
1287
|
+
*/
|
|
1230
1288
|
function $mol_assert_unique(...args) {
|
|
1231
1289
|
for (let i = 0; i < args.length; ++i) {
|
|
1232
1290
|
for (let j = 0; j < args.length; ++j) {
|
|
@@ -1239,6 +1297,13 @@ var $;
|
|
|
1239
1297
|
}
|
|
1240
1298
|
}
|
|
1241
1299
|
$.$mol_assert_unique = $mol_assert_unique;
|
|
1300
|
+
/**
|
|
1301
|
+
* All arguments must be structural equal each other.
|
|
1302
|
+
* @example
|
|
1303
|
+
* $mol_assert_like( [1] , [1] , [1] ) // Passes
|
|
1304
|
+
* $mol_assert_like( [1] , [1] , [2] ) // Fails because 1 !== 2
|
|
1305
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
1306
|
+
*/
|
|
1242
1307
|
function $mol_assert_equal(...args) {
|
|
1243
1308
|
for (let i = 1; i < args.length; ++i) {
|
|
1244
1309
|
if ($mol_compare_deep(args[0], args[i]))
|
|
@@ -1291,7 +1356,8 @@ var $;
|
|
|
1291
1356
|
"use strict";
|
|
1292
1357
|
var $;
|
|
1293
1358
|
(function ($) {
|
|
1294
|
-
let buf = new Uint8Array(2 ** 12);
|
|
1359
|
+
let buf = new Uint8Array(2 ** 12); // 4KB Mem Page
|
|
1360
|
+
/** Temporary buffer. Recursive usage isn't supported. */
|
|
1295
1361
|
function $mol_charset_buffer(size) {
|
|
1296
1362
|
if (buf.byteLength < size)
|
|
1297
1363
|
buf = new Uint8Array(size);
|
|
@@ -1313,19 +1379,19 @@ var $;
|
|
|
1313
1379
|
let pos = from;
|
|
1314
1380
|
for (let i = 0; i < str.length; i++) {
|
|
1315
1381
|
let code = str.charCodeAt(i);
|
|
1316
|
-
if (code < 0x80) {
|
|
1382
|
+
if (code < 0x80) { // ASCII - 1 octet
|
|
1317
1383
|
buf[pos++] = code;
|
|
1318
1384
|
}
|
|
1319
|
-
else if (code < 0x800) {
|
|
1385
|
+
else if (code < 0x800) { // 2 octet
|
|
1320
1386
|
buf[pos++] = 0xc0 | (code >> 6);
|
|
1321
1387
|
buf[pos++] = 0x80 | (code & 0x3f);
|
|
1322
1388
|
}
|
|
1323
|
-
else if (code < 0xd800 || code >= 0xe000) {
|
|
1389
|
+
else if (code < 0xd800 || code >= 0xe000) { // 3 octet
|
|
1324
1390
|
buf[pos++] = 0xe0 | (code >> 12);
|
|
1325
1391
|
buf[pos++] = 0x80 | ((code >> 6) & 0x3f);
|
|
1326
1392
|
buf[pos++] = 0x80 | (code & 0x3f);
|
|
1327
1393
|
}
|
|
1328
|
-
else {
|
|
1394
|
+
else { // surrogate pair
|
|
1329
1395
|
const point = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
|
|
1330
1396
|
buf[pos++] = 0xf0 | (point >> 18);
|
|
1331
1397
|
buf[pos++] = 0x80 | ((point >> 12) & 0x3f);
|
|
@@ -1384,6 +1450,7 @@ var $;
|
|
|
1384
1450
|
"use strict";
|
|
1385
1451
|
var $;
|
|
1386
1452
|
(function ($) {
|
|
1453
|
+
/** Log begin of collapsed group only when some logged inside, returns func to close group */
|
|
1387
1454
|
function $mol_log3_area_lazy(event) {
|
|
1388
1455
|
const self = this.$;
|
|
1389
1456
|
const stack = self.$mol_log3_stack;
|
|
@@ -1833,6 +1900,7 @@ var $;
|
|
|
1833
1900
|
var $;
|
|
1834
1901
|
(function ($) {
|
|
1835
1902
|
let sponge = new Uint32Array(80);
|
|
1903
|
+
/** Fast small sync SHA-1 (20 bytes, 160 bits) */
|
|
1836
1904
|
function $mol_crypto2_hash(input) {
|
|
1837
1905
|
const data = input instanceof Uint8Array
|
|
1838
1906
|
? input
|
|
@@ -1847,7 +1915,9 @@ var $;
|
|
|
1847
1915
|
for (let i = wlen; i < data.length; ++i) {
|
|
1848
1916
|
tail |= data[i] << ((3 - i & 0b11) << 3);
|
|
1849
1917
|
}
|
|
1918
|
+
// Initial
|
|
1850
1919
|
const hash = new Int32Array([1732584193, -271733879, -1732584194, 271733878, -1009589776]);
|
|
1920
|
+
// Digest
|
|
1851
1921
|
for (let i = 0; i < bytes; i += 16) {
|
|
1852
1922
|
let h0 = hash[0];
|
|
1853
1923
|
let h1 = hash[1];
|
|
@@ -1923,7 +1993,7 @@ var $;
|
|
|
1923
1993
|
}
|
|
1924
1994
|
for (let i = 0; i < 20; ++i) {
|
|
1925
1995
|
const word = hash[i];
|
|
1926
|
-
hash[i] = word << 24 | word << 8 & 0xFF0000 | word >>> 8 & 0xFF00 | word >>> 24 & 0xFF;
|
|
1996
|
+
hash[i] = word << 24 | word << 8 & 0xFF0000 | word >>> 8 & 0xFF00 | word >>> 24 & 0xFF; // BE -> LE
|
|
1927
1997
|
}
|
|
1928
1998
|
return new Uint8Array(hash.buffer);
|
|
1929
1999
|
}
|