hyoo_sync_client 0.0.241 → 0.0.242

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
  }
@@ -1941,19 +2053,6 @@ var $;
1941
2053
  ;
1942
2054
  "use strict";
1943
2055
  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
2056
  (function ($) {
1958
2057
  function $mol_dom_render_children(el, childNodes) {
1959
2058
  const node_set = new Set(childNodes);
package/web.test.js CHANGED
@@ -964,24 +964,61 @@ var $;
964
964
  "use strict";
965
965
  var $;
966
966
  (function ($) {
967
+ const png = new Uint8Array([0x1a, 0x0a, 0x00, 0x49, 0x48, 0x78, 0xda]);
967
968
  $mol_test({
968
- async 'sizes'() {
969
+ 'base64 encode string'() {
970
+ $mol_assert_equal($mol_base64_encode('Hello, ΧΨΩЫ'), 'SGVsbG8sIM6nzqjOqdCr');
971
+ },
972
+ 'base64 encode binary'() {
973
+ $mol_assert_equal($mol_base64_encode(png), 'GgoASUh42g==');
974
+ },
975
+ });
976
+ })($ || ($ = {}));
977
+ //mol/base64/encode/encode.test.ts
978
+ ;
979
+ "use strict";
980
+ var $;
981
+ (function ($) {
982
+ const png = new Uint8Array([0x1a, 0x0a, 0x00, 0x49, 0x48, 0x78, 0xda]);
983
+ $mol_test({
984
+ 'base64 decode string'() {
985
+ $mol_assert_like($mol_base64_decode('SGVsbG8sIM6nzqjOqdCr'), new TextEncoder().encode('Hello, ΧΨΩЫ'));
986
+ },
987
+ 'base64 decode binary'() {
988
+ $mol_assert_like($mol_base64_decode('GgoASUh42g=='), png);
989
+ },
990
+ });
991
+ })($ || ($ = {}));
992
+ //mol/base64/decode/decode.test.ts
993
+ ;
994
+ "use strict";
995
+ var $;
996
+ (function ($) {
997
+ $mol_test({
998
+ async 'str sizes'() {
969
999
  const pair = await $$.$mol_crypto_auditor_pair();
970
1000
  const key_public = await pair.public.serial();
971
- $mol_assert_equal(key_public.length, $mol_crypto_auditor_public.size);
1001
+ $mol_assert_equal(key_public.length, $mol_crypto_auditor_public.size_str);
972
1002
  const key_private = await pair.private.serial();
973
- $mol_assert_equal(key_private.length, $mol_crypto_auditor_private.size);
1003
+ $mol_assert_equal(key_private.length, $mol_crypto_auditor_private.size_str);
974
1004
  const data = new Uint8Array([1, 2, 3]);
975
1005
  const sign = await pair.private.sign(data);
976
1006
  $mol_assert_equal(sign.byteLength, $mol_crypto_auditor_sign_size);
977
1007
  },
1008
+ async 'bin sizes'() {
1009
+ const pair = await $$.$mol_crypto_auditor_pair();
1010
+ const key_public = await pair.public.toArray();
1011
+ $mol_assert_equal(key_public.length, $mol_crypto_auditor_public.size_bin);
1012
+ const key_private = await pair.private.toArray();
1013
+ $mol_assert_equal(key_private.length, $mol_crypto_auditor_private.size_bin);
1014
+ },
978
1015
  async 'verify self signed with auto generated key'() {
979
1016
  const auditor = await $$.$mol_crypto_auditor_pair();
980
1017
  const data = new Uint8Array([1, 2, 3]);
981
1018
  const sign = await auditor.private.sign(data);
982
1019
  $mol_assert_ok(await auditor.public.verify(data, sign));
983
1020
  },
984
- async 'verify signed with exported auto generated key'() {
1021
+ async 'verify signed with str exported auto generated key'() {
985
1022
  const pair = await $$.$mol_crypto_auditor_pair();
986
1023
  const data = new Uint8Array([1, 2, 3]);
987
1024
  const Alice = await $mol_crypto_auditor_private.from(await pair.private.serial());
@@ -989,7 +1026,15 @@ var $;
989
1026
  const Bob = await $mol_crypto_auditor_public.from(await pair.public.serial());
990
1027
  $mol_assert_ok(await Bob.verify(data, sign));
991
1028
  },
992
- async 'take public key from private'() {
1029
+ async 'verify signed with bin exported auto generated key'() {
1030
+ const pair = await $$.$mol_crypto_auditor_pair();
1031
+ const data = new Uint8Array([1, 2, 3]);
1032
+ const Alice = await $mol_crypto_auditor_private.from(await pair.private.toArray());
1033
+ const sign = await Alice.sign(data);
1034
+ const Bob = await $mol_crypto_auditor_public.from(await pair.public.toArray());
1035
+ $mol_assert_ok(await Bob.verify(data, sign));
1036
+ },
1037
+ async 'take public key from private str'() {
993
1038
  const pair = await $$.$mol_crypto_auditor_pair();
994
1039
  const data = new Uint8Array([1, 2, 3]);
995
1040
  const Alice = pair.private;
@@ -999,6 +1044,16 @@ var $;
999
1044
  $mol_assert_ok(await Bob.verify(data, sign));
1000
1045
  $mol_assert_ok(await Carol.verify(data, sign));
1001
1046
  },
1047
+ async 'take public key from private bin'() {
1048
+ const pair = await $$.$mol_crypto_auditor_pair();
1049
+ const data = new Uint8Array([1, 2, 3]);
1050
+ const Alice = pair.private;
1051
+ const sign = await Alice.sign(data);
1052
+ const Bob = await pair.private.public();
1053
+ const Carol = await $mol_crypto_auditor_public.from(await pair.private.toArray());
1054
+ $mol_assert_ok(await Bob.verify(data, sign));
1055
+ $mol_assert_ok(await Carol.verify(data, sign));
1056
+ },
1002
1057
  });
1003
1058
  })($ || ($ = {}));
1004
1059
  //mol/crypto/auditor/auditor.web.test.ts