hyoo_sync_client 0.0.241 → 0.0.243

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/web.mjs CHANGED
@@ -400,6 +400,92 @@ var $;
400
400
  ;
401
401
  "use strict";
402
402
  var $;
403
+ (function ($) {
404
+ function $mol_base64_encode(src) {
405
+ throw new Error('Not implemented');
406
+ }
407
+ $.$mol_base64_encode = $mol_base64_encode;
408
+ })($ || ($ = {}));
409
+ //mol/base64/encode/encode.ts
410
+ ;
411
+ "use strict";
412
+ var $;
413
+ (function ($) {
414
+ })($ || ($ = {}));
415
+ //mol/dom/context/context.ts
416
+ ;
417
+ "use strict";
418
+ var $;
419
+ (function ($) {
420
+ $.$mol_dom_context = self;
421
+ })($ || ($ = {}));
422
+ //mol/dom/context/context.web.ts
423
+ ;
424
+ "use strict";
425
+ var $;
426
+ (function ($) {
427
+ function binary_string(bytes) {
428
+ let binary = '';
429
+ if (typeof bytes !== 'string') {
430
+ for (const byte of bytes)
431
+ binary += String.fromCharCode(byte);
432
+ }
433
+ else {
434
+ binary = unescape(encodeURIComponent(bytes));
435
+ }
436
+ return binary;
437
+ }
438
+ function $mol_base64_encode_web(str) {
439
+ return $mol_dom_context.btoa(binary_string(str));
440
+ }
441
+ $.$mol_base64_encode_web = $mol_base64_encode_web;
442
+ $.$mol_base64_encode = $mol_base64_encode_web;
443
+ })($ || ($ = {}));
444
+ //mol/base64/encode/encode.web.ts
445
+ ;
446
+ "use strict";
447
+ var $;
448
+ (function ($) {
449
+ function $mol_base64_encode_safe(buffer) {
450
+ return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/, '');
451
+ }
452
+ $.$mol_base64_encode_safe = $mol_base64_encode_safe;
453
+ })($ || ($ = {}));
454
+ //mol/base64/encode/safe/safe.ts
455
+ ;
456
+ "use strict";
457
+ var $;
458
+ (function ($) {
459
+ function $mol_base64_decode(base64) {
460
+ throw new Error('Not implemented');
461
+ }
462
+ $.$mol_base64_decode = $mol_base64_decode;
463
+ })($ || ($ = {}));
464
+ //mol/base64/decode/decode.ts
465
+ ;
466
+ "use strict";
467
+ var $;
468
+ (function ($) {
469
+ function $mol_base64_decode_web(base64Str) {
470
+ return new Uint8Array($mol_dom_context.atob(base64Str).split('').map(c => c.charCodeAt(0)));
471
+ }
472
+ $.$mol_base64_decode_web = $mol_base64_decode_web;
473
+ $.$mol_base64_decode = $mol_base64_decode_web;
474
+ })($ || ($ = {}));
475
+ //mol/base64/decode/decode.web.ts
476
+ ;
477
+ "use strict";
478
+ var $;
479
+ (function ($) {
480
+ function $mol_base64_decode_safe(str) {
481
+ return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
482
+ }
483
+ $.$mol_base64_decode_safe = $mol_base64_decode_safe;
484
+ })($ || ($ = {}));
485
+ //mol/base64/decode/safe/safe.ts
486
+ ;
487
+ "use strict";
488
+ var $;
403
489
  (function ($) {
404
490
  const algorithm = {
405
491
  name: 'ECDSA',
@@ -416,12 +502,17 @@ var $;
416
502
  $.$mol_crypto_auditor_pair = $mol_crypto_auditor_pair;
417
503
  class $mol_crypto_auditor_public extends Object {
418
504
  native;
419
- static size = 86;
505
+ static size_str = 86;
506
+ static size_bin = 64;
420
507
  constructor(native) {
421
508
  super();
422
509
  this.native = native;
423
510
  }
424
511
  static async from(serial) {
512
+ if (typeof serial !== 'string') {
513
+ serial = $mol_base64_encode_safe(serial.subarray(0, 32))
514
+ + $mol_base64_encode_safe(serial.subarray(32, 64));
515
+ }
425
516
  return new this(await $mol_crypto_native.subtle.importKey('jwk', {
426
517
  crv: "P-256",
427
518
  ext: true,
@@ -435,6 +526,13 @@ var $;
435
526
  const { x, y } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
436
527
  return x + y;
437
528
  }
529
+ async toArray() {
530
+ const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
531
+ return new Uint8Array([
532
+ ...$mol_base64_decode_safe(x),
533
+ ...$mol_base64_decode_safe(y),
534
+ ]);
535
+ }
438
536
  async verify(data, sign) {
439
537
  return await $mol_crypto_native.subtle.verify(algorithm, this.native, sign, data);
440
538
  }
@@ -442,12 +540,18 @@ var $;
442
540
  $.$mol_crypto_auditor_public = $mol_crypto_auditor_public;
443
541
  class $mol_crypto_auditor_private extends Object {
444
542
  native;
445
- static size = 129;
543
+ static size_str = 129;
544
+ static size_bin = 96;
446
545
  constructor(native) {
447
546
  super();
448
547
  this.native = native;
449
548
  }
450
549
  static async from(serial) {
550
+ if (typeof serial !== 'string') {
551
+ serial = $mol_base64_encode_safe(serial.subarray(0, 32))
552
+ + $mol_base64_encode_safe(serial.subarray(32, 64))
553
+ + $mol_base64_encode_safe(serial.subarray(64));
554
+ }
451
555
  return new this(await $mol_crypto_native.subtle.importKey('jwk', {
452
556
  crv: "P-256",
453
557
  ext: true,
@@ -462,6 +566,14 @@ var $;
462
566
  const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
463
567
  return x + y + d;
464
568
  }
569
+ async toArray() {
570
+ const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
571
+ return new Uint8Array([
572
+ ...$mol_base64_decode_safe(x),
573
+ ...$mol_base64_decode_safe(y),
574
+ ...$mol_base64_decode_safe(d),
575
+ ]);
576
+ }
465
577
  async sign(data) {
466
578
  return await $mol_crypto_native.subtle.sign(algorithm, this.native, data);
467
579
  }
@@ -586,7 +698,6 @@ var $;
586
698
  $.$mol_dev_format_element = $mol_dev_format_element;
587
699
  function $mol_dev_format_span(style, ...content) {
588
700
  return $mol_dev_format_element('span', {
589
- 'vertical-align': '8%',
590
701
  ...style,
591
702
  }, ...content);
592
703
  }
@@ -1526,6 +1637,8 @@ var $;
1526
1637
  return true;
1527
1638
  }
1528
1639
  function compare_buffer(left, right) {
1640
+ if (left instanceof DataView)
1641
+ return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, left.byteOffset, left.byteLength));
1529
1642
  const len = left.byteLength;
1530
1643
  if (len !== right.byteLength)
1531
1644
  return false;
@@ -1941,19 +2054,6 @@ var $;
1941
2054
  ;
1942
2055
  "use strict";
1943
2056
  var $;
1944
- (function ($) {
1945
- })($ || ($ = {}));
1946
- //mol/dom/context/context.ts
1947
- ;
1948
- "use strict";
1949
- var $;
1950
- (function ($) {
1951
- $.$mol_dom_context = self;
1952
- })($ || ($ = {}));
1953
- //mol/dom/context/context.web.ts
1954
- ;
1955
- "use strict";
1956
- var $;
1957
2057
  (function ($) {
1958
2058
  function $mol_dom_render_children(el, childNodes) {
1959
2059
  const node_set = new Set(childNodes);
package/web.test.js CHANGED
@@ -560,6 +560,11 @@ var $;
560
560
  $mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
561
561
  $mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
562
562
  },
563
+ 'DataView'() {
564
+ $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array().buffer), new DataView(new Uint8Array().buffer)));
565
+ $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([0]).buffer)));
566
+ $mol_assert_not($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([1]).buffer)));
567
+ },
563
568
  'Serializale'() {
564
569
  class User {
565
570
  name;
@@ -670,7 +675,7 @@ var $;
670
675
  if ('outerHTML' in val)
671
676
  return val.outerHTML;
672
677
  try {
673
- return JSON.stringify(val, null, '\t');
678
+ return JSON.stringify(val, (k, v) => typeof v === 'bigint' ? String(v) : v, '\t');
674
679
  }
675
680
  catch (error) {
676
681
  console.error(error);
@@ -963,25 +968,62 @@ var $;
963
968
  ;
964
969
  "use strict";
965
970
  var $;
971
+ (function ($) {
972
+ const png = new Uint8Array([0x1a, 0x0a, 0x00, 0x49, 0x48, 0x78, 0xda]);
973
+ $mol_test({
974
+ 'base64 encode string'() {
975
+ $mol_assert_equal($mol_base64_encode('Hello, ΧΨΩЫ'), 'SGVsbG8sIM6nzqjOqdCr');
976
+ },
977
+ 'base64 encode binary'() {
978
+ $mol_assert_equal($mol_base64_encode(png), 'GgoASUh42g==');
979
+ },
980
+ });
981
+ })($ || ($ = {}));
982
+ //mol/base64/encode/encode.test.ts
983
+ ;
984
+ "use strict";
985
+ var $;
986
+ (function ($) {
987
+ const png = new Uint8Array([0x1a, 0x0a, 0x00, 0x49, 0x48, 0x78, 0xda]);
988
+ $mol_test({
989
+ 'base64 decode string'() {
990
+ $mol_assert_like($mol_base64_decode('SGVsbG8sIM6nzqjOqdCr'), new TextEncoder().encode('Hello, ΧΨΩЫ'));
991
+ },
992
+ 'base64 decode binary'() {
993
+ $mol_assert_like($mol_base64_decode('GgoASUh42g=='), png);
994
+ },
995
+ });
996
+ })($ || ($ = {}));
997
+ //mol/base64/decode/decode.test.ts
998
+ ;
999
+ "use strict";
1000
+ var $;
966
1001
  (function ($) {
967
1002
  $mol_test({
968
- async 'sizes'() {
1003
+ async 'str sizes'() {
969
1004
  const pair = await $$.$mol_crypto_auditor_pair();
970
1005
  const key_public = await pair.public.serial();
971
- $mol_assert_equal(key_public.length, $mol_crypto_auditor_public.size);
1006
+ $mol_assert_equal(key_public.length, $mol_crypto_auditor_public.size_str);
972
1007
  const key_private = await pair.private.serial();
973
- $mol_assert_equal(key_private.length, $mol_crypto_auditor_private.size);
1008
+ $mol_assert_equal(key_private.length, $mol_crypto_auditor_private.size_str);
974
1009
  const data = new Uint8Array([1, 2, 3]);
975
1010
  const sign = await pair.private.sign(data);
976
1011
  $mol_assert_equal(sign.byteLength, $mol_crypto_auditor_sign_size);
977
1012
  },
1013
+ async 'bin sizes'() {
1014
+ const pair = await $$.$mol_crypto_auditor_pair();
1015
+ const key_public = await pair.public.toArray();
1016
+ $mol_assert_equal(key_public.length, $mol_crypto_auditor_public.size_bin);
1017
+ const key_private = await pair.private.toArray();
1018
+ $mol_assert_equal(key_private.length, $mol_crypto_auditor_private.size_bin);
1019
+ },
978
1020
  async 'verify self signed with auto generated key'() {
979
1021
  const auditor = await $$.$mol_crypto_auditor_pair();
980
1022
  const data = new Uint8Array([1, 2, 3]);
981
1023
  const sign = await auditor.private.sign(data);
982
1024
  $mol_assert_ok(await auditor.public.verify(data, sign));
983
1025
  },
984
- async 'verify signed with exported auto generated key'() {
1026
+ async 'verify signed with str exported auto generated key'() {
985
1027
  const pair = await $$.$mol_crypto_auditor_pair();
986
1028
  const data = new Uint8Array([1, 2, 3]);
987
1029
  const Alice = await $mol_crypto_auditor_private.from(await pair.private.serial());
@@ -989,7 +1031,15 @@ var $;
989
1031
  const Bob = await $mol_crypto_auditor_public.from(await pair.public.serial());
990
1032
  $mol_assert_ok(await Bob.verify(data, sign));
991
1033
  },
992
- async 'take public key from private'() {
1034
+ async 'verify signed with bin exported auto generated key'() {
1035
+ const pair = await $$.$mol_crypto_auditor_pair();
1036
+ const data = new Uint8Array([1, 2, 3]);
1037
+ const Alice = await $mol_crypto_auditor_private.from(await pair.private.toArray());
1038
+ const sign = await Alice.sign(data);
1039
+ const Bob = await $mol_crypto_auditor_public.from(await pair.public.toArray());
1040
+ $mol_assert_ok(await Bob.verify(data, sign));
1041
+ },
1042
+ async 'take public key from private str'() {
993
1043
  const pair = await $$.$mol_crypto_auditor_pair();
994
1044
  const data = new Uint8Array([1, 2, 3]);
995
1045
  const Alice = pair.private;
@@ -999,6 +1049,16 @@ var $;
999
1049
  $mol_assert_ok(await Bob.verify(data, sign));
1000
1050
  $mol_assert_ok(await Carol.verify(data, sign));
1001
1051
  },
1052
+ async 'take public key from private bin'() {
1053
+ const pair = await $$.$mol_crypto_auditor_pair();
1054
+ const data = new Uint8Array([1, 2, 3]);
1055
+ const Alice = pair.private;
1056
+ const sign = await Alice.sign(data);
1057
+ const Bob = await pair.private.public();
1058
+ const Carol = await $mol_crypto_auditor_public.from(await pair.private.toArray());
1059
+ $mol_assert_ok(await Bob.verify(data, sign));
1060
+ $mol_assert_ok(await Carol.verify(data, sign));
1061
+ },
1002
1062
  });
1003
1063
  })($ || ($ = {}));
1004
1064
  //mol/crypto/auditor/auditor.web.test.ts