mol_crypto_lib 0.1.1403 → 0.1.1405

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
@@ -28,6 +28,26 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
28
28
  var $ = ( typeof module === 'object' ) ? ( module['export'+'s'] = globalThis ) : globalThis
29
29
  $.$$ = $
30
30
 
31
+ ;
32
+ "use strict";
33
+ var $;
34
+ (function ($) {
35
+ function $mol_fail(error) {
36
+ throw error;
37
+ }
38
+ $.$mol_fail = $mol_fail;
39
+ })($ || ($ = {}));
40
+
41
+ ;
42
+ "use strict";
43
+ var $;
44
+ (function ($) {
45
+ function $mol_fail_hidden(error) {
46
+ throw error;
47
+ }
48
+ $.$mol_fail_hidden = $mol_fail_hidden;
49
+ })($ || ($ = {}));
50
+
31
51
  ;
32
52
  "use strict";
33
53
  var $;
@@ -147,16 +167,6 @@ var $;
147
167
  $.$mol_func_name_from = $mol_func_name_from;
148
168
  })($ || ($ = {}));
149
169
 
150
- ;
151
- "use strict";
152
- var $;
153
- (function ($) {
154
- function $mol_fail(error) {
155
- throw error;
156
- }
157
- $.$mol_fail = $mol_fail;
158
- })($ || ($ = {}));
159
-
160
170
  ;
161
171
  "use strict";
162
172
  var $;
@@ -409,16 +419,6 @@ var $;
409
419
  $.$mol_owning_catch = $mol_owning_catch;
410
420
  })($ || ($ = {}));
411
421
 
412
- ;
413
- "use strict";
414
- var $;
415
- (function ($) {
416
- function $mol_fail_hidden(error) {
417
- throw error;
418
- }
419
- $.$mol_fail_hidden = $mol_fail_hidden;
420
- })($ || ($ = {}));
421
-
422
422
  ;
423
423
  "use strict";
424
424
 
@@ -528,6 +528,10 @@ var $;
528
528
  "use strict";
529
529
  var $;
530
530
  (function ($) {
531
+ function restack(error) {
532
+ error = new Error(error instanceof Error ? error.message : String(error), { cause: error });
533
+ $mol_fail_hidden(error);
534
+ }
531
535
  class $mol_crypto_sacred extends $mol_buffer {
532
536
  static size = 16;
533
537
  static make() {
@@ -548,7 +552,7 @@ var $;
548
552
  return sacred;
549
553
  }
550
554
  static async from_native(native) {
551
- const buf = await $mol_crypto_native.subtle.exportKey('raw', native);
555
+ const buf = await $mol_crypto_native.subtle.exportKey('raw', native).catch(restack);
552
556
  const sacred = this.from(new Uint8Array(buf));
553
557
  sacred._native = native;
554
558
  return sacred;
@@ -566,7 +570,7 @@ var $;
566
570
  return this._native ?? (this._native = await $mol_crypto_native.subtle.importKey('raw', this, {
567
571
  name: 'AES-CBC',
568
572
  length: 128,
569
- }, true, ['encrypt', 'decrypt']));
573
+ }, true, ['encrypt', 'decrypt']).catch(restack));
570
574
  }
571
575
  async encrypt(open, salt) {
572
576
  return new Uint8Array(await $mol_crypto_native.subtle.encrypt({
@@ -574,7 +578,7 @@ var $;
574
578
  length: 128,
575
579
  tagLength: 32,
576
580
  iv: salt,
577
- }, await this.native(), open));
581
+ }, await this.native(), open).catch(restack));
578
582
  }
579
583
  async decrypt(closed, salt) {
580
584
  return new Uint8Array(await $mol_crypto_native.subtle.decrypt({
@@ -582,11 +586,16 @@ var $;
582
586
  length: 128,
583
587
  tagLength: 32,
584
588
  iv: salt,
585
- }, await this.native(), closed));
589
+ }, await this.native(), closed).catch(restack));
586
590
  }
587
591
  async close(sacred, salt) {
588
- const buf = new Uint8Array(this.buffer, this.byteOffset + 1, this.byteLength - 1);
589
- return sacred.encrypt(buf, salt);
592
+ const buf = new Uint8Array(sacred.buffer, sacred.byteOffset + 1, sacred.byteLength - 1);
593
+ return this.encrypt(buf, salt);
594
+ }
595
+ async open(buf, salt) {
596
+ const buf2 = new Uint8Array(16);
597
+ buf2.set(await this.decrypt(buf, salt), 1);
598
+ return new $mol_crypto_sacred(buf2.buffer);
590
599
  }
591
600
  }
592
601
  __decorate([
@@ -811,7 +820,7 @@ var $;
811
820
  return $mol_crypto_sacred.from(new Uint8Array(await $mol_crypto_native.subtle.deriveBits({
812
821
  name: "ECDH",
813
822
  public: await pub.native_derive(),
814
- }, await priv.native_derive(), $mol_crypto_sacred.size)));
823
+ }, await priv.native_derive(), $mol_crypto_sacred.size * 8)));
815
824
  }
816
825
  $.$mol_crypto_sacred_shared = $mol_crypto_sacred_shared;
817
826
  })($ || ($ = {}));