hpke 0.2.1 → 0.4.0

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.
@@ -36,28 +36,24 @@ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true
36
36
 
37
37
  cachedTextDecoder.decode();
38
38
 
39
- let cachegetUint8Memory0 = null;
39
+ let cachedUint8Memory0 = new Uint8Array();
40
+
40
41
  function getUint8Memory0() {
41
- if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
42
- cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
42
+ if (cachedUint8Memory0.byteLength === 0) {
43
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
43
44
  }
44
- return cachegetUint8Memory0;
45
+ return cachedUint8Memory0;
45
46
  }
46
47
 
47
48
  function getStringFromWasm0(ptr, len) {
48
49
  return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
49
50
  }
50
51
 
51
- let cachegetInt32Memory0 = null;
52
- function getInt32Memory0() {
53
- if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
54
- cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
52
+ function _assertClass(instance, klass) {
53
+ if (!(instance instanceof klass)) {
54
+ throw new Error(`expected instance of ${klass.name}`);
55
55
  }
56
- return cachegetInt32Memory0;
57
- }
58
-
59
- function getArrayU8FromWasm0(ptr, len) {
60
- return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
56
+ return instance.ptr;
61
57
  }
62
58
 
63
59
  let WASM_VECTOR_LEN = 0;
@@ -69,57 +65,68 @@ function passArray8ToWasm0(arg, malloc) {
69
65
  return ptr;
70
66
  }
71
67
 
72
- function _assertClass(instance, klass) {
73
- if (!(instance instanceof klass)) {
74
- throw new Error(`expected instance of ${klass.name}`);
68
+ let cachedInt32Memory0 = new Int32Array();
69
+
70
+ function getInt32Memory0() {
71
+ if (cachedInt32Memory0.byteLength === 0) {
72
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
75
73
  }
76
- return instance.ptr;
74
+ return cachedInt32Memory0;
75
+ }
76
+
77
+ function getArrayU8FromWasm0(ptr, len) {
78
+ return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
77
79
  }
78
80
  /**
79
81
  *
80
- *`base_mode_seal` provides an interface to [`hpke::single_shot_seal`]
81
- *that does not require compile time selection of an
82
- *algorithm. Instead, the selected algorithm is provided through the
83
- *[`Config`] passed as the first argument.
82
+ *`base_mode_open` provides an interface to [`hpke::single_shot_open`]
83
+ *that does not require compile time selection of an algorithm. Instead,
84
+ *the selected algorithm is provided through the [`Config`] passed as
85
+ *the first argument.
84
86
  *
85
- *Requires the `base-mode-seal` crate feature to be enabled.
87
+ *Requires the `base-mode-open` crate feature to be enabled.
86
88
  *
87
89
  *# Errors
88
90
  *
89
91
  *This will return an `Result::Err` variant if:
90
92
  *
91
- ** we are unable to deserialize the recipient public key
92
- ** there is an error in key encapsultion
93
- ** there is an error in encryption
94
- *
93
+ ** we are unable to deserialize the private key or encapsulated key
94
+ ** there is an error in key decapsulation
95
+ ** there is an error in decryption
95
96
  *
96
97
  * @param {Config} config
97
- * @param {Uint8Array} recipient_public_key
98
+ * @param {Uint8Array} private_key
99
+ * @param {Uint8Array} encapped_key
98
100
  * @param {Uint8Array} info
99
- * @param {Uint8Array} plaintext
101
+ * @param {Uint8Array} ciphertext
100
102
  * @param {Uint8Array} aad
101
- * @returns {EncappedKeyAndCiphertext}
103
+ * @returns {Uint8Array}
102
104
  */
103
- module.exports.base_mode_seal = function(config, recipient_public_key, info, plaintext, aad) {
105
+ module.exports.base_mode_open = function(config, private_key, encapped_key, info, ciphertext, aad) {
104
106
  try {
105
107
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
106
108
  _assertClass(config, Config);
107
- const ptr0 = passArray8ToWasm0(recipient_public_key, wasm.__wbindgen_malloc);
109
+ const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
108
110
  const len0 = WASM_VECTOR_LEN;
109
- const ptr1 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
111
+ const ptr1 = passArray8ToWasm0(encapped_key, wasm.__wbindgen_malloc);
110
112
  const len1 = WASM_VECTOR_LEN;
111
- const ptr2 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
113
+ const ptr2 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
112
114
  const len2 = WASM_VECTOR_LEN;
113
- const ptr3 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
115
+ const ptr3 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
114
116
  const len3 = WASM_VECTOR_LEN;
115
- wasm.base_mode_seal(retptr, config.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
117
+ const ptr4 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
118
+ const len4 = WASM_VECTOR_LEN;
119
+ wasm.base_mode_open(retptr, config.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
116
120
  var r0 = getInt32Memory0()[retptr / 4 + 0];
117
121
  var r1 = getInt32Memory0()[retptr / 4 + 1];
118
122
  var r2 = getInt32Memory0()[retptr / 4 + 2];
119
- if (r2) {
120
- throw takeObject(r1);
123
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
124
+ if (r3) {
125
+ throw takeObject(r2);
121
126
  }
122
- return EncappedKeyAndCiphertext.__wrap(r0);
127
+ var v5 = getArrayU8FromWasm0(r0, r1).slice();
128
+ wasm.__wbindgen_free(r0, r1 * 1);
129
+ return v5;
123
130
  } finally {
124
131
  wasm.__wbindgen_add_to_stack_pointer(16);
125
132
  }
@@ -127,54 +134,49 @@ module.exports.base_mode_seal = function(config, recipient_public_key, info, pla
127
134
 
128
135
  /**
129
136
  *
130
- *`base_mode_open` provides an interface to [`hpke::single_shot_open`]
131
- *that does not require compile time selection of an algorithm. Instead,
132
- *the selected algorithm is provided through the [`Config`] passed as
133
- *the first argument.
137
+ *`base_mode_seal` provides an interface to [`hpke::single_shot_seal`]
138
+ *that does not require compile time selection of an
139
+ *algorithm. Instead, the selected algorithm is provided through the
140
+ *[`Config`] passed as the first argument.
134
141
  *
135
- *Requires the `base-mode-open` crate feature to be enabled.
142
+ *Requires the `base-mode-seal` crate feature to be enabled.
136
143
  *
137
144
  *# Errors
138
145
  *
139
146
  *This will return an `Result::Err` variant if:
140
147
  *
141
- ** we are unable to deserialize the private key or encapsulated key
142
- ** there is an error in key decapsulation
143
- ** there is an error in decryption
148
+ ** we are unable to deserialize the recipient public key
149
+ ** there is an error in key encapsultion
150
+ ** there is an error in encryption
151
+ *
144
152
  *
145
153
  * @param {Config} config
146
- * @param {Uint8Array} private_key
147
- * @param {Uint8Array} encapped_key
154
+ * @param {Uint8Array} recipient_public_key
148
155
  * @param {Uint8Array} info
149
- * @param {Uint8Array} ciphertext
156
+ * @param {Uint8Array} plaintext
150
157
  * @param {Uint8Array} aad
151
- * @returns {Uint8Array}
158
+ * @returns {EncappedKeyAndCiphertext}
152
159
  */
153
- module.exports.base_mode_open = function(config, private_key, encapped_key, info, ciphertext, aad) {
160
+ module.exports.base_mode_seal = function(config, recipient_public_key, info, plaintext, aad) {
154
161
  try {
155
162
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
156
163
  _assertClass(config, Config);
157
- const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
164
+ const ptr0 = passArray8ToWasm0(recipient_public_key, wasm.__wbindgen_malloc);
158
165
  const len0 = WASM_VECTOR_LEN;
159
- const ptr1 = passArray8ToWasm0(encapped_key, wasm.__wbindgen_malloc);
166
+ const ptr1 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
160
167
  const len1 = WASM_VECTOR_LEN;
161
- const ptr2 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
168
+ const ptr2 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
162
169
  const len2 = WASM_VECTOR_LEN;
163
- const ptr3 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
170
+ const ptr3 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
164
171
  const len3 = WASM_VECTOR_LEN;
165
- const ptr4 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
166
- const len4 = WASM_VECTOR_LEN;
167
- wasm.base_mode_open(retptr, config.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
172
+ wasm.base_mode_seal(retptr, config.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
168
173
  var r0 = getInt32Memory0()[retptr / 4 + 0];
169
174
  var r1 = getInt32Memory0()[retptr / 4 + 1];
170
175
  var r2 = getInt32Memory0()[retptr / 4 + 2];
171
- var r3 = getInt32Memory0()[retptr / 4 + 3];
172
- if (r3) {
173
- throw takeObject(r2);
176
+ if (r2) {
177
+ throw takeObject(r1);
174
178
  }
175
- var v5 = getArrayU8FromWasm0(r0, r1).slice();
176
- wasm.__wbindgen_free(r0, r1 * 1);
177
- return v5;
179
+ return EncappedKeyAndCiphertext.__wrap(r0);
178
180
  } finally {
179
181
  wasm.__wbindgen_add_to_stack_pointer(16);
180
182
  }
@@ -189,24 +191,6 @@ function handleError(f, args) {
189
191
  }
190
192
  /**
191
193
  *
192
- *Aead represents an authenticated encryption with additional data
193
- *encryption function, as per [RFC9180§7.3](https://www.rfc-editor.org/rfc/rfc9180.html#section-7.3)
194
- */
195
- module.exports.Aead = Object.freeze({
196
- /**
197
- * AES-128-GCM [GCM](https://doi.org/10.6028/nist.sp.800-38d)
198
- */
199
- AesGcm128:1,"1":"AesGcm128",
200
- /**
201
- * AES-256-GCM [GCM](https://doi.org/10.6028/nist.sp.800-38d)
202
- */
203
- AesGcm256:2,"2":"AesGcm256",
204
- /**
205
- * ChaCha20Poly1305 [RFC8439](https://www.rfc-editor.org/info/rfc8439)
206
- */
207
- ChaCha20Poly1305:3,"3":"ChaCha20Poly1305", });
208
- /**
209
- *
210
194
  *Kdf represents an key derivation function, as per
211
195
  *[RFC9180§7.2](https://www.rfc-editor.org/rfc/rfc9180.html#section-7.2)
212
196
  */
@@ -225,6 +209,24 @@ Sha384:2,"2":"Sha384",
225
209
  Sha512:3,"3":"Sha512", });
226
210
  /**
227
211
  *
212
+ *Aead represents an authenticated encryption with additional data
213
+ *encryption function, as per [RFC9180§7.3](https://www.rfc-editor.org/rfc/rfc9180.html#section-7.3)
214
+ */
215
+ module.exports.Aead = Object.freeze({
216
+ /**
217
+ * AES-128-GCM [GCM](https://doi.org/10.6028/nist.sp.800-38d)
218
+ */
219
+ AesGcm128:1,"1":"AesGcm128",
220
+ /**
221
+ * AES-256-GCM [GCM](https://doi.org/10.6028/nist.sp.800-38d)
222
+ */
223
+ AesGcm256:2,"2":"AesGcm256",
224
+ /**
225
+ * ChaCha20Poly1305 [RFC8439](https://www.rfc-editor.org/info/rfc8439)
226
+ */
227
+ ChaCha20Poly1305:3,"3":"ChaCha20Poly1305", });
228
+ /**
229
+ *
228
230
  *Kem represents an asymmetric key encapsulation mechanism, as per
229
231
  *[RFC9180§7.1][section-7.1]. Currently only two of options listed in
230
232
  *the hpke draft are available.
@@ -268,6 +270,7 @@ class Config {
268
270
  }
269
271
  /**
270
272
  * the [authenticated encryption with additional data encryption function](crate::Aead) to be used
273
+ * @returns {number}
271
274
  */
272
275
  get aead() {
273
276
  const ret = wasm.__wbg_get_config_aead(this.ptr);
@@ -282,6 +285,7 @@ class Config {
282
285
  }
283
286
  /**
284
287
  * the [key derivation function](crate::Kdf) to be used
288
+ * @returns {number}
285
289
  */
286
290
  get kdf() {
287
291
  const ret = wasm.__wbg_get_config_kdf(this.ptr);
@@ -296,6 +300,7 @@ class Config {
296
300
  }
297
301
  /**
298
302
  * the [asymmetric key encapsulation mechanism](crate::Kem) to be used
303
+ * @returns {number}
299
304
  */
300
305
  get kem() {
301
306
  const ret = wasm.__wbg_get_config_kem(this.ptr);
@@ -459,6 +464,7 @@ class EncappedKeyAndCiphertext {
459
464
  }
460
465
  /**
461
466
  * the encapsulated encryption key
467
+ * @returns {Uint8Array}
462
468
  */
463
469
  get encapped_key() {
464
470
  try {
@@ -484,6 +490,7 @@ class EncappedKeyAndCiphertext {
484
490
  }
485
491
  /**
486
492
  * the ciphertext, encrypted with the key
493
+ * @returns {Uint8Array}
487
494
  */
488
495
  get ciphertext() {
489
496
  try {
@@ -588,6 +595,7 @@ class Keypair {
588
595
  }
589
596
  /**
590
597
  * the public key for this keypair
598
+ * @returns {Uint8Array}
591
599
  */
592
600
  get public_key() {
593
601
  try {
@@ -613,6 +621,7 @@ class Keypair {
613
621
  }
614
622
  /**
615
623
  * the private key for this keypair,
624
+ * @returns {Uint8Array}
616
625
  */
617
626
  get private_key() {
618
627
  try {
@@ -647,17 +656,17 @@ class Keypair {
647
656
  }
648
657
  module.exports.Keypair = Keypair;
649
658
 
650
- module.exports.__wbg_idlookuperror_new = function(arg0) {
651
- const ret = IdLookupError.__wrap(arg0);
659
+ module.exports.__wbg_hpkeerror_new = function(arg0) {
660
+ const ret = HpkeError.__wrap(arg0);
652
661
  return addHeapObject(ret);
653
662
  };
654
663
 
655
- module.exports.__wbg_hpkeerror_new = function(arg0) {
656
- const ret = HpkeError.__wrap(arg0);
664
+ module.exports.__wbg_idlookuperror_new = function(arg0) {
665
+ const ret = IdLookupError.__wrap(arg0);
657
666
  return addHeapObject(ret);
658
667
  };
659
668
 
660
- module.exports.__wbg_randomFillSync_654a7797990fb8db = function() { return handleError(function (arg0, arg1, arg2) {
669
+ module.exports.__wbg_randomFillSync_065afffde01daa66 = function() { return handleError(function (arg0, arg1, arg2) {
661
670
  getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2));
662
671
  }, arguments) };
663
672
 
@@ -665,11 +674,11 @@ module.exports.__wbindgen_object_drop_ref = function(arg0) {
665
674
  takeObject(arg0);
666
675
  };
667
676
 
668
- module.exports.__wbg_getRandomValues_fb6b088efb6bead2 = function() { return handleError(function (arg0, arg1) {
677
+ module.exports.__wbg_getRandomValues_b99eec4244a475bb = function() { return handleError(function (arg0, arg1) {
669
678
  getObject(arg0).getRandomValues(getObject(arg1));
670
679
  }, arguments) };
671
680
 
672
- module.exports.__wbg_process_70251ed1291754d5 = function(arg0) {
681
+ module.exports.__wbg_process_0cc2ada8524d6f83 = function(arg0) {
673
682
  const ret = getObject(arg0).process;
674
683
  return addHeapObject(ret);
675
684
  };
@@ -680,12 +689,12 @@ module.exports.__wbindgen_is_object = function(arg0) {
680
689
  return ret;
681
690
  };
682
691
 
683
- module.exports.__wbg_versions_b23f2588cdb2ddbb = function(arg0) {
692
+ module.exports.__wbg_versions_c11acceab27a6c87 = function(arg0) {
684
693
  const ret = getObject(arg0).versions;
685
694
  return addHeapObject(ret);
686
695
  };
687
696
 
688
- module.exports.__wbg_node_61b8c9a82499895d = function(arg0) {
697
+ module.exports.__wbg_node_7ff1ce49caf23815 = function(arg0) {
689
698
  const ret = getObject(arg0).node;
690
699
  return addHeapObject(ret);
691
700
  };
@@ -695,32 +704,32 @@ module.exports.__wbindgen_is_string = function(arg0) {
695
704
  return ret;
696
705
  };
697
706
 
698
- module.exports.__wbg_static_accessor_NODE_MODULE_33b45247c55045b0 = function() {
699
- const ret = module;
707
+ module.exports.__wbg_crypto_2036bed7c44c25e7 = function(arg0) {
708
+ const ret = getObject(arg0).crypto;
700
709
  return addHeapObject(ret);
701
710
  };
702
711
 
703
- module.exports.__wbg_require_2a93bc09fee45aca = function() { return handleError(function (arg0, arg1, arg2) {
704
- const ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2));
712
+ module.exports.__wbg_msCrypto_a21fc88caf1ecdc8 = function(arg0) {
713
+ const ret = getObject(arg0).msCrypto;
705
714
  return addHeapObject(ret);
706
- }, arguments) };
715
+ };
707
716
 
708
- module.exports.__wbg_crypto_2f56257a38275dbd = function(arg0) {
709
- const ret = getObject(arg0).crypto;
717
+ module.exports.__wbg_static_accessor_NODE_MODULE_cf6401cc1091279e = function() {
718
+ const ret = module;
710
719
  return addHeapObject(ret);
711
720
  };
712
721
 
713
- module.exports.__wbg_msCrypto_d07655bf62361f21 = function(arg0) {
714
- const ret = getObject(arg0).msCrypto;
722
+ module.exports.__wbg_require_a746e79b322b9336 = function() { return handleError(function (arg0, arg1, arg2) {
723
+ const ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2));
715
724
  return addHeapObject(ret);
716
- };
725
+ }, arguments) };
717
726
 
718
- module.exports.__wbg_newnoargs_e23b458e372830de = function(arg0, arg1) {
727
+ module.exports.__wbg_newnoargs_b5b063fc6c2f0376 = function(arg0, arg1) {
719
728
  const ret = new Function(getStringFromWasm0(arg0, arg1));
720
729
  return addHeapObject(ret);
721
730
  };
722
731
 
723
- module.exports.__wbg_call_ae78342adc33730a = function() { return handleError(function (arg0, arg1) {
732
+ module.exports.__wbg_call_97ae9d8645dc388b = function() { return handleError(function (arg0, arg1) {
724
733
  const ret = getObject(arg0).call(getObject(arg1));
725
734
  return addHeapObject(ret);
726
735
  }, arguments) };
@@ -730,22 +739,22 @@ module.exports.__wbindgen_object_clone_ref = function(arg0) {
730
739
  return addHeapObject(ret);
731
740
  };
732
741
 
733
- module.exports.__wbg_self_99737b4dcdf6f0d8 = function() { return handleError(function () {
742
+ module.exports.__wbg_self_6d479506f72c6a71 = function() { return handleError(function () {
734
743
  const ret = self.self;
735
744
  return addHeapObject(ret);
736
745
  }, arguments) };
737
746
 
738
- module.exports.__wbg_window_9b61fbbf3564c4fb = function() { return handleError(function () {
747
+ module.exports.__wbg_window_f2557cc78490aceb = function() { return handleError(function () {
739
748
  const ret = window.window;
740
749
  return addHeapObject(ret);
741
750
  }, arguments) };
742
751
 
743
- module.exports.__wbg_globalThis_8e275ef40caea3a3 = function() { return handleError(function () {
752
+ module.exports.__wbg_globalThis_7f206bda628d5286 = function() { return handleError(function () {
744
753
  const ret = globalThis.globalThis;
745
754
  return addHeapObject(ret);
746
755
  }, arguments) };
747
756
 
748
- module.exports.__wbg_global_5de1e0f82bddcd27 = function() { return handleError(function () {
757
+ module.exports.__wbg_global_ba75c50d1cf384f4 = function() { return handleError(function () {
749
758
  const ret = global.global;
750
759
  return addHeapObject(ret);
751
760
  }, arguments) };
@@ -755,31 +764,31 @@ module.exports.__wbindgen_is_undefined = function(arg0) {
755
764
  return ret;
756
765
  };
757
766
 
758
- module.exports.__wbg_buffer_7af23f65f6c64548 = function(arg0) {
767
+ module.exports.__wbg_buffer_3f3d764d4747d564 = function(arg0) {
759
768
  const ret = getObject(arg0).buffer;
760
769
  return addHeapObject(ret);
761
770
  };
762
771
 
763
- module.exports.__wbg_new_cc9018bd6f283b6f = function(arg0) {
772
+ module.exports.__wbg_new_8c3f0052272a457a = function(arg0) {
764
773
  const ret = new Uint8Array(getObject(arg0));
765
774
  return addHeapObject(ret);
766
775
  };
767
776
 
768
- module.exports.__wbg_set_f25e869e4565d2a2 = function(arg0, arg1, arg2) {
777
+ module.exports.__wbg_set_83db9690f9353e79 = function(arg0, arg1, arg2) {
769
778
  getObject(arg0).set(getObject(arg1), arg2 >>> 0);
770
779
  };
771
780
 
772
- module.exports.__wbg_length_0acb1cf9bbaf8519 = function(arg0) {
781
+ module.exports.__wbg_length_9e1ae1900cb0fbd5 = function(arg0) {
773
782
  const ret = getObject(arg0).length;
774
783
  return ret;
775
784
  };
776
785
 
777
- module.exports.__wbg_newwithlength_8f0657faca9f1422 = function(arg0) {
786
+ module.exports.__wbg_newwithlength_f5933855e4f48a19 = function(arg0) {
778
787
  const ret = new Uint8Array(arg0 >>> 0);
779
788
  return addHeapObject(ret);
780
789
  };
781
790
 
782
- module.exports.__wbg_subarray_da527dbd24eafb6b = function(arg0, arg1, arg2) {
791
+ module.exports.__wbg_subarray_58ad4efbb5bcb886 = function(arg0, arg1, arg2) {
783
792
  const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
784
793
  return addHeapObject(ret);
785
794
  };
Binary file
@@ -0,0 +1,32 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export function base_mode_open(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number): void;
5
+ export function __wbg_config_free(a: number): void;
6
+ export function __wbg_get_config_aead(a: number): number;
7
+ export function __wbg_set_config_aead(a: number, b: number): void;
8
+ export function __wbg_get_config_kdf(a: number): number;
9
+ export function __wbg_set_config_kdf(a: number, b: number): void;
10
+ export function __wbg_get_config_kem(a: number): number;
11
+ export function __wbg_set_config_kem(a: number, b: number): void;
12
+ export function config_base_mode_seal(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void;
13
+ export function config_base_mode_open(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number): void;
14
+ export function config_try_from_ids(a: number, b: number, c: number, d: number): void;
15
+ export function __wbg_keypair_free(a: number): void;
16
+ export function __wbg_get_keypair_public_key(a: number, b: number): void;
17
+ export function __wbg_set_keypair_public_key(a: number, b: number, c: number): void;
18
+ export function __wbg_get_keypair_private_key(a: number, b: number): void;
19
+ export function __wbg_set_keypair_private_key(a: number, b: number, c: number): void;
20
+ export function keypair_new(a: number): number;
21
+ export function base_mode_seal(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void;
22
+ export function __wbg_encappedkeyandciphertext_free(a: number): void;
23
+ export function __wbg_get_encappedkeyandciphertext_encapped_key(a: number, b: number): void;
24
+ export function __wbg_set_encappedkeyandciphertext_encapped_key(a: number, b: number, c: number): void;
25
+ export function __wbg_get_encappedkeyandciphertext_ciphertext(a: number, b: number): void;
26
+ export function __wbg_set_encappedkeyandciphertext_ciphertext(a: number, b: number, c: number): void;
27
+ export function __wbg_idlookuperror_free(a: number): void;
28
+ export function __wbg_hpkeerror_free(a: number): void;
29
+ export function __wbindgen_add_to_stack_pointer(a: number): number;
30
+ export function __wbindgen_malloc(a: number): number;
31
+ export function __wbindgen_free(a: number, b: number): void;
32
+ export function __wbindgen_exn_store(a: number): void;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var node_exports = {};
24
+ __export(node_exports, {
25
+ __wasm: () => __wasm
26
+ });
27
+ module.exports = __toCommonJS(node_exports);
28
+ var import_hpke_dispatch_bg = __toESM(require("./hpke_dispatch_bg.wasm"));
29
+ var import_hpke_dispatch = __toESM(require("./hpke_dispatch.js"));
30
+ __reExport(node_exports, require("./hpke_dispatch.js"), module.exports);
31
+ const __wasm = (0, import_hpke_dispatch.default)(import_hpke_dispatch_bg.default);
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["index.ts"],
4
+ "sourcesContent": ["import wasm from \"./hpke_dispatch_bg.wasm\";\nimport init from \"./hpke_dispatch.js\";\n//this is exported so it doesn't get dead-code-eliminated\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\nexport const __wasm = init(wasm);\nexport * from \"./hpke_dispatch.js\";\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAiB;AACjB,2BAAiB;AAIjB,yBAAc,+BALd;AAIO,MAAM,SAAS,kCAAK,+BAAI;",
6
+ "names": []
7
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var import_chai = require("chai");
3
+ var import__ = require(".");
4
+ var import_util = require("util");
5
+ describe("HPKE", () => {
6
+ describe("Config", () => {
7
+ it("throws when the algorithms specified are invalid", () => {
8
+ const [aead, kdf, kem] = [100, 100, 100];
9
+ (0, import_chai.assert)(!(aead in import__.Aead));
10
+ (0, import_chai.assert)(!(kdf in import__.Kdf));
11
+ (0, import_chai.assert)(!(kem in import__.Kem));
12
+ import_chai.assert.throws(() => import__.Config.try_from_ids(aead, kdf, kem));
13
+ });
14
+ });
15
+ describe("Keypair", () => {
16
+ it("generates a (65, 32)-byte keypair for Kem.DhP256HkdfSha256", () => {
17
+ const keypair = new import__.Keypair(import__.Kem.DhP256HkdfSha256);
18
+ import_chai.assert.equal(keypair.public_key.length, 65);
19
+ import_chai.assert.equal(keypair.private_key.length, 32);
20
+ });
21
+ it("generates a (32, 32)-byte keypair for Kem.X25519HkdfSha256", () => {
22
+ const keypair = new import__.Keypair(import__.Kem.X25519HkdfSha256);
23
+ import_chai.assert.equal(keypair.public_key.length, 32);
24
+ import_chai.assert.equal(keypair.private_key.length, 32);
25
+ });
26
+ it("throws when provided an invalid Kem", () => {
27
+ import_chai.assert.throws(() => new import__.Keypair(1e3));
28
+ });
29
+ });
30
+ describe("Round trips", () => {
31
+ const decoder = new import_util.TextDecoder();
32
+ const encoder = new import_util.TextEncoder();
33
+ const startMessage = "plaintext message text";
34
+ const plaintext = encoder.encode(startMessage);
35
+ const info = encoder.encode("app info");
36
+ const aad = encoder.encode("associated data");
37
+ for (const aead of [
38
+ import__.Aead.AesGcm128,
39
+ import__.Aead.AesGcm256,
40
+ import__.Aead.ChaCha20Poly1305
41
+ ]) {
42
+ for (const kdf of [import__.Kdf.Sha256, import__.Kdf.Sha384, import__.Kdf.Sha512]) {
43
+ for (const kem of [import__.Kem.DhP256HkdfSha256, import__.Kem.X25519HkdfSha256]) {
44
+ it(`succeeds for ${import__.Aead[aead]}, ${import__.Kdf[kdf]}, ${import__.Kem[kem]}`, () => {
45
+ const config = import__.Config.try_from_ids(aead, kdf, kem);
46
+ import_chai.assert.equal(config.aead, aead);
47
+ import_chai.assert.equal(config.kem, kem);
48
+ import_chai.assert.equal(config.kdf, kdf);
49
+ const keypair = new import__.Keypair(config.kem);
50
+ const keyAndCiphertext = config.base_mode_seal(keypair.public_key, info, plaintext, aad);
51
+ const roundTrip = config.base_mode_open(keypair.private_key, keyAndCiphertext.encapped_key, info, keyAndCiphertext.ciphertext, aad);
52
+ import_chai.assert.equal(startMessage, decoder.decode(roundTrip));
53
+ });
54
+ }
55
+ }
56
+ }
57
+ });
58
+ });
59
+ //# sourceMappingURL=index.spec.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["index.spec.ts"],
4
+ "sourcesContent": ["import { assert } from \"chai\";\nimport { Keypair, Aead, Kdf, Kem, Config } from \".\";\nimport { TextEncoder, TextDecoder } from \"util\";\n\ndescribe(\"HPKE\", () => {\n describe(\"Config\", () => {\n it(\"throws when the algorithms specified are invalid\", () => {\n const [aead, kdf, kem] = [100, 100, 100];\n\n assert(!(aead in Aead));\n assert(!(kdf in Kdf));\n assert(!(kem in Kem));\n\n assert.throws(() => Config.try_from_ids(aead, kdf, kem));\n });\n });\n\n describe(\"Keypair\", () => {\n it(\"generates a (65, 32)-byte keypair for Kem.DhP256HkdfSha256\", () => {\n const keypair = new Keypair(Kem.DhP256HkdfSha256);\n assert.equal(keypair.public_key.length, 65);\n assert.equal(keypair.private_key.length, 32);\n });\n\n it(\"generates a (32, 32)-byte keypair for Kem.X25519HkdfSha256\", () => {\n const keypair = new Keypair(Kem.X25519HkdfSha256);\n assert.equal(keypair.public_key.length, 32);\n assert.equal(keypair.private_key.length, 32);\n });\n\n it(\"throws when provided an invalid Kem\", () => {\n assert.throws(() => new Keypair(1000));\n });\n });\n\n describe(\"Round trips\", () => {\n const decoder = new TextDecoder();\n const encoder = new TextEncoder();\n\n const startMessage = \"plaintext message text\";\n const plaintext = encoder.encode(startMessage);\n const info = encoder.encode(\"app info\");\n const aad = encoder.encode(\"associated data\");\n\n for (const aead of [\n Aead.AesGcm128,\n Aead.AesGcm256,\n Aead.ChaCha20Poly1305,\n ]) {\n for (const kdf of [Kdf.Sha256, Kdf.Sha384, Kdf.Sha512]) {\n for (const kem of [Kem.DhP256HkdfSha256, Kem.X25519HkdfSha256]) {\n it(`succeeds for ${Aead[aead]}, ${Kdf[kdf]}, ${Kem[kem]}`, () => {\n const config = Config.try_from_ids(aead, kdf, kem);\n\n assert.equal(config.aead, aead);\n assert.equal(config.kem, kem);\n assert.equal(config.kdf, kdf);\n\n const keypair = new Keypair(config.kem);\n\n const keyAndCiphertext = config.base_mode_seal(\n keypair.public_key,\n info,\n plaintext,\n aad\n );\n\n const roundTrip = config.base_mode_open(\n keypair.private_key,\n keyAndCiphertext.encapped_key,\n info,\n keyAndCiphertext.ciphertext,\n aad\n );\n\n assert.equal(startMessage, decoder.decode(roundTrip));\n });\n }\n }\n }\n });\n});\n"],
5
+ "mappings": ";AAAA,kBAAuB;AACvB,eAAgD;AAChD,kBAAyC;AAEzC,SAAS,QAAQ,MAAM;AACrB,WAAS,UAAU,MAAM;AACvB,OAAG,oDAAoD,MAAM;AAC3D,YAAM,CAAC,MAAM,KAAK,OAAO,CAAC,KAAK,KAAK,GAAG;AAEvC,8BAAO,CAAE,SAAQ,cAAK;AACtB,8BAAO,CAAE,QAAO,aAAI;AACpB,8BAAO,CAAE,QAAO,aAAI;AAEpB,yBAAO,OAAO,MAAM,gBAAO,aAAa,MAAM,KAAK,GAAG,CAAC;AAAA,IACzD,CAAC;AAAA,EACH,CAAC;AAED,WAAS,WAAW,MAAM;AACxB,OAAG,8DAA8D,MAAM;AACrE,YAAM,UAAU,IAAI,iBAAQ,aAAI,gBAAgB;AAChD,yBAAO,MAAM,QAAQ,WAAW,QAAQ,EAAE;AAC1C,yBAAO,MAAM,QAAQ,YAAY,QAAQ,EAAE;AAAA,IAC7C,CAAC;AAED,OAAG,8DAA8D,MAAM;AACrE,YAAM,UAAU,IAAI,iBAAQ,aAAI,gBAAgB;AAChD,yBAAO,MAAM,QAAQ,WAAW,QAAQ,EAAE;AAC1C,yBAAO,MAAM,QAAQ,YAAY,QAAQ,EAAE;AAAA,IAC7C,CAAC;AAED,OAAG,uCAAuC,MAAM;AAC9C,yBAAO,OAAO,MAAM,IAAI,iBAAQ,GAAI,CAAC;AAAA,IACvC,CAAC;AAAA,EACH,CAAC;AAED,WAAS,eAAe,MAAM;AAC5B,UAAM,UAAU,IAAI,wBAAY;AAChC,UAAM,UAAU,IAAI,wBAAY;AAEhC,UAAM,eAAe;AACrB,UAAM,YAAY,QAAQ,OAAO,YAAY;AAC7C,UAAM,OAAO,QAAQ,OAAO,UAAU;AACtC,UAAM,MAAM,QAAQ,OAAO,iBAAiB;AAE5C,eAAW,QAAQ;AAAA,MACjB,cAAK;AAAA,MACL,cAAK;AAAA,MACL,cAAK;AAAA,IACP,GAAG;AACD,iBAAW,OAAO,CAAC,aAAI,QAAQ,aAAI,QAAQ,aAAI,MAAM,GAAG;AACtD,mBAAW,OAAO,CAAC,aAAI,kBAAkB,aAAI,gBAAgB,GAAG;AAC9D,aAAG,gBAAgB,cAAK,UAAU,aAAI,SAAS,aAAI,QAAQ,MAAM;AAC/D,kBAAM,SAAS,gBAAO,aAAa,MAAM,KAAK,GAAG;AAEjD,+BAAO,MAAM,OAAO,MAAM,IAAI;AAC9B,+BAAO,MAAM,OAAO,KAAK,GAAG;AAC5B,+BAAO,MAAM,OAAO,KAAK,GAAG;AAE5B,kBAAM,UAAU,IAAI,iBAAQ,OAAO,GAAG;AAEtC,kBAAM,mBAAmB,OAAO,eAC9B,QAAQ,YACR,MACA,WACA,GACF;AAEA,kBAAM,YAAY,OAAO,eACvB,QAAQ,aACR,iBAAiB,cACjB,MACA,iBAAiB,YACjB,GACF;AAEA,+BAAO,MAAM,cAAc,QAAQ,OAAO,SAAS,CAAC;AAAA,UACtD,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }