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.
@@ -0,0 +1,852 @@
1
+
2
+ let wasm;
3
+
4
+ const heap = new Array(32).fill(undefined);
5
+
6
+ heap.push(undefined, null, true, false);
7
+
8
+ function getObject(idx) { return heap[idx]; }
9
+
10
+ let heap_next = heap.length;
11
+
12
+ function dropObject(idx) {
13
+ if (idx < 36) return;
14
+ heap[idx] = heap_next;
15
+ heap_next = idx;
16
+ }
17
+
18
+ function takeObject(idx) {
19
+ const ret = getObject(idx);
20
+ dropObject(idx);
21
+ return ret;
22
+ }
23
+
24
+ function addHeapObject(obj) {
25
+ if (heap_next === heap.length) heap.push(heap.length + 1);
26
+ const idx = heap_next;
27
+ heap_next = heap[idx];
28
+
29
+ heap[idx] = obj;
30
+ return idx;
31
+ }
32
+
33
+ const cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
34
+
35
+ cachedTextDecoder.decode();
36
+
37
+ let cachedUint8Memory0 = new Uint8Array();
38
+
39
+ function getUint8Memory0() {
40
+ if (cachedUint8Memory0.byteLength === 0) {
41
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
42
+ }
43
+ return cachedUint8Memory0;
44
+ }
45
+
46
+ function getStringFromWasm0(ptr, len) {
47
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
48
+ }
49
+
50
+ function _assertClass(instance, klass) {
51
+ if (!(instance instanceof klass)) {
52
+ throw new Error(`expected instance of ${klass.name}`);
53
+ }
54
+ return instance.ptr;
55
+ }
56
+
57
+ let WASM_VECTOR_LEN = 0;
58
+
59
+ function passArray8ToWasm0(arg, malloc) {
60
+ const ptr = malloc(arg.length * 1);
61
+ getUint8Memory0().set(arg, ptr / 1);
62
+ WASM_VECTOR_LEN = arg.length;
63
+ return ptr;
64
+ }
65
+
66
+ let cachedInt32Memory0 = new Int32Array();
67
+
68
+ function getInt32Memory0() {
69
+ if (cachedInt32Memory0.byteLength === 0) {
70
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
71
+ }
72
+ return cachedInt32Memory0;
73
+ }
74
+
75
+ function getArrayU8FromWasm0(ptr, len) {
76
+ return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
77
+ }
78
+ /**
79
+ *
80
+ *`base_mode_open` provides an interface to [`hpke::single_shot_open`]
81
+ *that does not require compile time selection of an algorithm. Instead,
82
+ *the selected algorithm is provided through the [`Config`] passed as
83
+ *the first argument.
84
+ *
85
+ *Requires the `base-mode-open` crate feature to be enabled.
86
+ *
87
+ *# Errors
88
+ *
89
+ *This will return an `Result::Err` variant if:
90
+ *
91
+ ** we are unable to deserialize the private key or encapsulated key
92
+ ** there is an error in key decapsulation
93
+ ** there is an error in decryption
94
+ *
95
+ * @param {Config} config
96
+ * @param {Uint8Array} private_key
97
+ * @param {Uint8Array} encapped_key
98
+ * @param {Uint8Array} info
99
+ * @param {Uint8Array} ciphertext
100
+ * @param {Uint8Array} aad
101
+ * @returns {Uint8Array}
102
+ */
103
+ export function base_mode_open(config, private_key, encapped_key, info, ciphertext, aad) {
104
+ try {
105
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
106
+ _assertClass(config, Config);
107
+ const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
108
+ const len0 = WASM_VECTOR_LEN;
109
+ const ptr1 = passArray8ToWasm0(encapped_key, wasm.__wbindgen_malloc);
110
+ const len1 = WASM_VECTOR_LEN;
111
+ const ptr2 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
112
+ const len2 = WASM_VECTOR_LEN;
113
+ const ptr3 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
114
+ const len3 = WASM_VECTOR_LEN;
115
+ const ptr4 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
116
+ const len4 = WASM_VECTOR_LEN;
117
+ wasm.base_mode_open(retptr, config.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
118
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
119
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
120
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
121
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
122
+ if (r3) {
123
+ throw takeObject(r2);
124
+ }
125
+ var v5 = getArrayU8FromWasm0(r0, r1).slice();
126
+ wasm.__wbindgen_free(r0, r1 * 1);
127
+ return v5;
128
+ } finally {
129
+ wasm.__wbindgen_add_to_stack_pointer(16);
130
+ }
131
+ }
132
+
133
+ /**
134
+ *
135
+ *`base_mode_seal` provides an interface to [`hpke::single_shot_seal`]
136
+ *that does not require compile time selection of an
137
+ *algorithm. Instead, the selected algorithm is provided through the
138
+ *[`Config`] passed as the first argument.
139
+ *
140
+ *Requires the `base-mode-seal` crate feature to be enabled.
141
+ *
142
+ *# Errors
143
+ *
144
+ *This will return an `Result::Err` variant if:
145
+ *
146
+ ** we are unable to deserialize the recipient public key
147
+ ** there is an error in key encapsultion
148
+ ** there is an error in encryption
149
+ *
150
+ *
151
+ * @param {Config} config
152
+ * @param {Uint8Array} recipient_public_key
153
+ * @param {Uint8Array} info
154
+ * @param {Uint8Array} plaintext
155
+ * @param {Uint8Array} aad
156
+ * @returns {EncappedKeyAndCiphertext}
157
+ */
158
+ export function base_mode_seal(config, recipient_public_key, info, plaintext, aad) {
159
+ try {
160
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
161
+ _assertClass(config, Config);
162
+ const ptr0 = passArray8ToWasm0(recipient_public_key, wasm.__wbindgen_malloc);
163
+ const len0 = WASM_VECTOR_LEN;
164
+ const ptr1 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
165
+ const len1 = WASM_VECTOR_LEN;
166
+ const ptr2 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
167
+ const len2 = WASM_VECTOR_LEN;
168
+ const ptr3 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
169
+ const len3 = WASM_VECTOR_LEN;
170
+ wasm.base_mode_seal(retptr, config.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
171
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
172
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
173
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
174
+ if (r2) {
175
+ throw takeObject(r1);
176
+ }
177
+ return EncappedKeyAndCiphertext.__wrap(r0);
178
+ } finally {
179
+ wasm.__wbindgen_add_to_stack_pointer(16);
180
+ }
181
+ }
182
+
183
+ function handleError(f, args) {
184
+ try {
185
+ return f.apply(this, args);
186
+ } catch (e) {
187
+ wasm.__wbindgen_exn_store(addHeapObject(e));
188
+ }
189
+ }
190
+ /**
191
+ *
192
+ *Kdf represents an key derivation function, as per
193
+ *[RFC9180§7.2](https://www.rfc-editor.org/rfc/rfc9180.html#section-7.2)
194
+ */
195
+ export const Kdf = Object.freeze({
196
+ /**
197
+ * Sha256 [RFC5869](https://www.rfc-editor.org/info/rfc5869)
198
+ */
199
+ Sha256:1,"1":"Sha256",
200
+ /**
201
+ * Sha384 [RFC5869](https://www.rfc-editor.org/info/rfc5869)
202
+ */
203
+ Sha384:2,"2":"Sha384",
204
+ /**
205
+ * Sha512 [RFC5869](https://www.rfc-editor.org/info/rfc5869)
206
+ */
207
+ Sha512:3,"3":"Sha512", });
208
+ /**
209
+ *
210
+ *Aead represents an authenticated encryption with additional data
211
+ *encryption function, as per [RFC9180§7.3](https://www.rfc-editor.org/rfc/rfc9180.html#section-7.3)
212
+ */
213
+ export const Aead = Object.freeze({
214
+ /**
215
+ * AES-128-GCM [GCM](https://doi.org/10.6028/nist.sp.800-38d)
216
+ */
217
+ AesGcm128:1,"1":"AesGcm128",
218
+ /**
219
+ * AES-256-GCM [GCM](https://doi.org/10.6028/nist.sp.800-38d)
220
+ */
221
+ AesGcm256:2,"2":"AesGcm256",
222
+ /**
223
+ * ChaCha20Poly1305 [RFC8439](https://www.rfc-editor.org/info/rfc8439)
224
+ */
225
+ ChaCha20Poly1305:3,"3":"ChaCha20Poly1305", });
226
+ /**
227
+ *
228
+ *Kem represents an asymmetric key encapsulation mechanism, as per
229
+ *[RFC9180§7.1][section-7.1]. Currently only two of options listed in
230
+ *the hpke draft are available.
231
+ *
232
+ *[section-7.1]: https://www.rfc-editor.org/rfc/rfc9180.html#section-7.1
233
+ */
234
+ export const Kem = Object.freeze({
235
+ /**
236
+ * DHKEM(P-256, HKDF-SHA256) [NISTCurves](https://doi.org/10.6028/nist.fips.186-4)
237
+ */
238
+ DhP256HkdfSha256:16,"16":"DhP256HkdfSha256",
239
+ /**
240
+ * DHKEM(X25519, HKDF-SHA256) [RFC7748](https://www.rfc-editor.org/info/rfc7748)
241
+ */
242
+ X25519HkdfSha256:32,"32":"X25519HkdfSha256", });
243
+ /**
244
+ *
245
+ *Config is an open struct that contains an ([`Aead`], [`Kdf`], [`Kem`])
246
+ *algorithmic triple. This can be used with [`Config::base_mode_seal`],
247
+ *[`Config::base_mode_open`], [`base_mode_seal`], or [`base_mode_open`].
248
+ */
249
+ export class Config {
250
+
251
+ static __wrap(ptr) {
252
+ const obj = Object.create(Config.prototype);
253
+ obj.ptr = ptr;
254
+
255
+ return obj;
256
+ }
257
+
258
+ __destroy_into_raw() {
259
+ const ptr = this.ptr;
260
+ this.ptr = 0;
261
+
262
+ return ptr;
263
+ }
264
+
265
+ free() {
266
+ const ptr = this.__destroy_into_raw();
267
+ wasm.__wbg_config_free(ptr);
268
+ }
269
+ /**
270
+ * the [authenticated encryption with additional data encryption function](crate::Aead) to be used
271
+ * @returns {number}
272
+ */
273
+ get aead() {
274
+ const ret = wasm.__wbg_get_config_aead(this.ptr);
275
+ return ret >>> 0;
276
+ }
277
+ /**
278
+ * the [authenticated encryption with additional data encryption function](crate::Aead) to be used
279
+ * @param {number} arg0
280
+ */
281
+ set aead(arg0) {
282
+ wasm.__wbg_set_config_aead(this.ptr, arg0);
283
+ }
284
+ /**
285
+ * the [key derivation function](crate::Kdf) to be used
286
+ * @returns {number}
287
+ */
288
+ get kdf() {
289
+ const ret = wasm.__wbg_get_config_kdf(this.ptr);
290
+ return ret >>> 0;
291
+ }
292
+ /**
293
+ * the [key derivation function](crate::Kdf) to be used
294
+ * @param {number} arg0
295
+ */
296
+ set kdf(arg0) {
297
+ wasm.__wbg_set_config_kdf(this.ptr, arg0);
298
+ }
299
+ /**
300
+ * the [asymmetric key encapsulation mechanism](crate::Kem) to be used
301
+ * @returns {number}
302
+ */
303
+ get kem() {
304
+ const ret = wasm.__wbg_get_config_kem(this.ptr);
305
+ return ret >>> 0;
306
+ }
307
+ /**
308
+ * the [asymmetric key encapsulation mechanism](crate::Kem) to be used
309
+ * @param {number} arg0
310
+ */
311
+ set kem(arg0) {
312
+ wasm.__wbg_set_config_kem(this.ptr, arg0);
313
+ }
314
+ /**
315
+ *
316
+ * base_mode_seal provides an interface to [`hpke::single_shot_seal`] that does
317
+ * not require compile time selection of an algorithm. Instead, the
318
+ * selected algorithm is provided through the [`Config`] that this
319
+ * method is called on.
320
+ *
321
+ * Requires the `base-mode-seal` crate feature to be enabled.
322
+ *
323
+ * # Errors
324
+ *
325
+ * This will return an `Result::Err` variant if:
326
+ *
327
+ * * we are unable to deserialize the recipient public key
328
+ * * there is an error in key encapsultion
329
+ * * there is an error in encryption
330
+ *
331
+ *
332
+ * @param {Uint8Array} recipient_public_key
333
+ * @param {Uint8Array} info
334
+ * @param {Uint8Array} plaintext
335
+ * @param {Uint8Array} aad
336
+ * @returns {EncappedKeyAndCiphertext}
337
+ */
338
+ base_mode_seal(recipient_public_key, info, plaintext, aad) {
339
+ try {
340
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
341
+ const ptr0 = passArray8ToWasm0(recipient_public_key, wasm.__wbindgen_malloc);
342
+ const len0 = WASM_VECTOR_LEN;
343
+ const ptr1 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
344
+ const len1 = WASM_VECTOR_LEN;
345
+ const ptr2 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
346
+ const len2 = WASM_VECTOR_LEN;
347
+ const ptr3 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
348
+ const len3 = WASM_VECTOR_LEN;
349
+ wasm.config_base_mode_seal(retptr, this.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
350
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
351
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
352
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
353
+ if (r2) {
354
+ throw takeObject(r1);
355
+ }
356
+ return EncappedKeyAndCiphertext.__wrap(r0);
357
+ } finally {
358
+ wasm.__wbindgen_add_to_stack_pointer(16);
359
+ }
360
+ }
361
+ /**
362
+ *
363
+ * base_mode_open provides an interface to [`hpke::single_shot_open`]
364
+ * that does not require compile time selection of an
365
+ * algorithm. Instead, the selected algorithm is provided through the
366
+ * [`Config`] that this method is called on.
367
+ *
368
+ * Requires the `base-mode-open` crate feature to be enabled.
369
+ *
370
+ * # Errors
371
+ *
372
+ * This will return an `Result::Err` variant if:
373
+ *
374
+ * * we are unable to deserialize the private key or encapsulated key
375
+ * * there is an error in key decapsulation
376
+ * * there is an error in decryption
377
+ *
378
+ *
379
+ * @param {Uint8Array} private_key
380
+ * @param {Uint8Array} encapped_key
381
+ * @param {Uint8Array} info
382
+ * @param {Uint8Array} ciphertext
383
+ * @param {Uint8Array} aad
384
+ * @returns {Uint8Array}
385
+ */
386
+ base_mode_open(private_key, encapped_key, info, ciphertext, aad) {
387
+ try {
388
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
389
+ const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
390
+ const len0 = WASM_VECTOR_LEN;
391
+ const ptr1 = passArray8ToWasm0(encapped_key, wasm.__wbindgen_malloc);
392
+ const len1 = WASM_VECTOR_LEN;
393
+ const ptr2 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
394
+ const len2 = WASM_VECTOR_LEN;
395
+ const ptr3 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
396
+ const len3 = WASM_VECTOR_LEN;
397
+ const ptr4 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
398
+ const len4 = WASM_VECTOR_LEN;
399
+ wasm.config_base_mode_open(retptr, this.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
400
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
401
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
402
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
403
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
404
+ if (r3) {
405
+ throw takeObject(r2);
406
+ }
407
+ var v5 = getArrayU8FromWasm0(r0, r1).slice();
408
+ wasm.__wbindgen_free(r0, r1 * 1);
409
+ return v5;
410
+ } finally {
411
+ wasm.__wbindgen_add_to_stack_pointer(16);
412
+ }
413
+ }
414
+ /**
415
+ * Attempt to convert three u16 ids into a valid config. The id mappings are defined in the draft.
416
+ * @param {number} aead_id
417
+ * @param {number} kdf_id
418
+ * @param {number} kem_id
419
+ * @returns {Config}
420
+ */
421
+ static try_from_ids(aead_id, kdf_id, kem_id) {
422
+ try {
423
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
424
+ wasm.config_try_from_ids(retptr, aead_id, kdf_id, kem_id);
425
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
426
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
427
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
428
+ if (r2) {
429
+ throw takeObject(r1);
430
+ }
431
+ return Config.__wrap(r0);
432
+ } finally {
433
+ wasm.__wbindgen_add_to_stack_pointer(16);
434
+ }
435
+ }
436
+ }
437
+ /**
438
+ *
439
+ *a simple struct to return the combined encapsulated key
440
+ *and ciphertext from seal
441
+ */
442
+ export class EncappedKeyAndCiphertext {
443
+
444
+ static __wrap(ptr) {
445
+ const obj = Object.create(EncappedKeyAndCiphertext.prototype);
446
+ obj.ptr = ptr;
447
+
448
+ return obj;
449
+ }
450
+
451
+ __destroy_into_raw() {
452
+ const ptr = this.ptr;
453
+ this.ptr = 0;
454
+
455
+ return ptr;
456
+ }
457
+
458
+ free() {
459
+ const ptr = this.__destroy_into_raw();
460
+ wasm.__wbg_encappedkeyandciphertext_free(ptr);
461
+ }
462
+ /**
463
+ * the encapsulated encryption key
464
+ * @returns {Uint8Array}
465
+ */
466
+ get encapped_key() {
467
+ try {
468
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
469
+ wasm.__wbg_get_encappedkeyandciphertext_encapped_key(retptr, this.ptr);
470
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
471
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
472
+ var v0 = getArrayU8FromWasm0(r0, r1).slice();
473
+ wasm.__wbindgen_free(r0, r1 * 1);
474
+ return v0;
475
+ } finally {
476
+ wasm.__wbindgen_add_to_stack_pointer(16);
477
+ }
478
+ }
479
+ /**
480
+ * the encapsulated encryption key
481
+ * @param {Uint8Array} arg0
482
+ */
483
+ set encapped_key(arg0) {
484
+ const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
485
+ const len0 = WASM_VECTOR_LEN;
486
+ wasm.__wbg_set_encappedkeyandciphertext_encapped_key(this.ptr, ptr0, len0);
487
+ }
488
+ /**
489
+ * the ciphertext, encrypted with the key
490
+ * @returns {Uint8Array}
491
+ */
492
+ get ciphertext() {
493
+ try {
494
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
495
+ wasm.__wbg_get_encappedkeyandciphertext_ciphertext(retptr, this.ptr);
496
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
497
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
498
+ var v0 = getArrayU8FromWasm0(r0, r1).slice();
499
+ wasm.__wbindgen_free(r0, r1 * 1);
500
+ return v0;
501
+ } finally {
502
+ wasm.__wbindgen_add_to_stack_pointer(16);
503
+ }
504
+ }
505
+ /**
506
+ * the ciphertext, encrypted with the key
507
+ * @param {Uint8Array} arg0
508
+ */
509
+ set ciphertext(arg0) {
510
+ const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
511
+ const len0 = WASM_VECTOR_LEN;
512
+ wasm.__wbg_set_encappedkeyandciphertext_ciphertext(this.ptr, ptr0, len0);
513
+ }
514
+ }
515
+ /**
516
+ *r"
517
+ * a newtype wrapper for HpkeError so we can use it in wasm_bindgen
518
+ *
519
+ */
520
+ export class HpkeError {
521
+
522
+ static __wrap(ptr) {
523
+ const obj = Object.create(HpkeError.prototype);
524
+ obj.ptr = ptr;
525
+
526
+ return obj;
527
+ }
528
+
529
+ __destroy_into_raw() {
530
+ const ptr = this.ptr;
531
+ this.ptr = 0;
532
+
533
+ return ptr;
534
+ }
535
+
536
+ free() {
537
+ const ptr = this.__destroy_into_raw();
538
+ wasm.__wbg_hpkeerror_free(ptr);
539
+ }
540
+ }
541
+ /**
542
+ *
543
+ *A simple error type for failed id lookups
544
+ *
545
+ */
546
+ export class IdLookupError {
547
+
548
+ static __wrap(ptr) {
549
+ const obj = Object.create(IdLookupError.prototype);
550
+ obj.ptr = ptr;
551
+
552
+ return obj;
553
+ }
554
+
555
+ __destroy_into_raw() {
556
+ const ptr = this.ptr;
557
+ this.ptr = 0;
558
+
559
+ return ptr;
560
+ }
561
+
562
+ free() {
563
+ const ptr = this.__destroy_into_raw();
564
+ wasm.__wbg_idlookuperror_free(ptr);
565
+ }
566
+ }
567
+ /**
568
+ * An encoded keypair
569
+ */
570
+ export class Keypair {
571
+
572
+ static __wrap(ptr) {
573
+ const obj = Object.create(Keypair.prototype);
574
+ obj.ptr = ptr;
575
+
576
+ return obj;
577
+ }
578
+
579
+ __destroy_into_raw() {
580
+ const ptr = this.ptr;
581
+ this.ptr = 0;
582
+
583
+ return ptr;
584
+ }
585
+
586
+ free() {
587
+ const ptr = this.__destroy_into_raw();
588
+ wasm.__wbg_keypair_free(ptr);
589
+ }
590
+ /**
591
+ * the public key for this keypair
592
+ * @returns {Uint8Array}
593
+ */
594
+ get public_key() {
595
+ try {
596
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
597
+ wasm.__wbg_get_keypair_public_key(retptr, this.ptr);
598
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
599
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
600
+ var v0 = getArrayU8FromWasm0(r0, r1).slice();
601
+ wasm.__wbindgen_free(r0, r1 * 1);
602
+ return v0;
603
+ } finally {
604
+ wasm.__wbindgen_add_to_stack_pointer(16);
605
+ }
606
+ }
607
+ /**
608
+ * the public key for this keypair
609
+ * @param {Uint8Array} arg0
610
+ */
611
+ set public_key(arg0) {
612
+ const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
613
+ const len0 = WASM_VECTOR_LEN;
614
+ wasm.__wbg_set_keypair_public_key(this.ptr, ptr0, len0);
615
+ }
616
+ /**
617
+ * the private key for this keypair,
618
+ * @returns {Uint8Array}
619
+ */
620
+ get private_key() {
621
+ try {
622
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
623
+ wasm.__wbg_get_keypair_private_key(retptr, this.ptr);
624
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
625
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
626
+ var v0 = getArrayU8FromWasm0(r0, r1).slice();
627
+ wasm.__wbindgen_free(r0, r1 * 1);
628
+ return v0;
629
+ } finally {
630
+ wasm.__wbindgen_add_to_stack_pointer(16);
631
+ }
632
+ }
633
+ /**
634
+ * the private key for this keypair,
635
+ * @param {Uint8Array} arg0
636
+ */
637
+ set private_key(arg0) {
638
+ const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
639
+ const len0 = WASM_VECTOR_LEN;
640
+ wasm.__wbg_set_keypair_private_key(this.ptr, ptr0, len0);
641
+ }
642
+ /**
643
+ * generate a keypair from a [`Kem`]
644
+ * @param {number} kem
645
+ */
646
+ constructor(kem) {
647
+ const ret = wasm.keypair_new(kem);
648
+ return Keypair.__wrap(ret);
649
+ }
650
+ }
651
+
652
+ async function load(module, imports) {
653
+ if (typeof Response === 'function' && module instanceof Response) {
654
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
655
+ try {
656
+ return await WebAssembly.instantiateStreaming(module, imports);
657
+
658
+ } catch (e) {
659
+ if (module.headers.get('Content-Type') != 'application/wasm') {
660
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
661
+
662
+ } else {
663
+ throw e;
664
+ }
665
+ }
666
+ }
667
+
668
+ const bytes = await module.arrayBuffer();
669
+ return await WebAssembly.instantiate(bytes, imports);
670
+
671
+ } else {
672
+ const instance = await WebAssembly.instantiate(module, imports);
673
+
674
+ if (instance instanceof WebAssembly.Instance) {
675
+ return { instance, module };
676
+
677
+ } else {
678
+ return instance;
679
+ }
680
+ }
681
+ }
682
+
683
+ function getImports() {
684
+ const imports = {};
685
+ imports.wbg = {};
686
+ imports.wbg.__wbg_hpkeerror_new = function(arg0) {
687
+ const ret = HpkeError.__wrap(arg0);
688
+ return addHeapObject(ret);
689
+ };
690
+ imports.wbg.__wbg_idlookuperror_new = function(arg0) {
691
+ const ret = IdLookupError.__wrap(arg0);
692
+ return addHeapObject(ret);
693
+ };
694
+ imports.wbg.__wbg_randomFillSync_065afffde01daa66 = function() { return handleError(function (arg0, arg1, arg2) {
695
+ getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2));
696
+ }, arguments) };
697
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
698
+ takeObject(arg0);
699
+ };
700
+ imports.wbg.__wbg_getRandomValues_b99eec4244a475bb = function() { return handleError(function (arg0, arg1) {
701
+ getObject(arg0).getRandomValues(getObject(arg1));
702
+ }, arguments) };
703
+ imports.wbg.__wbg_process_0cc2ada8524d6f83 = function(arg0) {
704
+ const ret = getObject(arg0).process;
705
+ return addHeapObject(ret);
706
+ };
707
+ imports.wbg.__wbindgen_is_object = function(arg0) {
708
+ const val = getObject(arg0);
709
+ const ret = typeof(val) === 'object' && val !== null;
710
+ return ret;
711
+ };
712
+ imports.wbg.__wbg_versions_c11acceab27a6c87 = function(arg0) {
713
+ const ret = getObject(arg0).versions;
714
+ return addHeapObject(ret);
715
+ };
716
+ imports.wbg.__wbg_node_7ff1ce49caf23815 = function(arg0) {
717
+ const ret = getObject(arg0).node;
718
+ return addHeapObject(ret);
719
+ };
720
+ imports.wbg.__wbindgen_is_string = function(arg0) {
721
+ const ret = typeof(getObject(arg0)) === 'string';
722
+ return ret;
723
+ };
724
+ imports.wbg.__wbg_crypto_2036bed7c44c25e7 = function(arg0) {
725
+ const ret = getObject(arg0).crypto;
726
+ return addHeapObject(ret);
727
+ };
728
+ imports.wbg.__wbg_msCrypto_a21fc88caf1ecdc8 = function(arg0) {
729
+ const ret = getObject(arg0).msCrypto;
730
+ return addHeapObject(ret);
731
+ };
732
+ imports.wbg.__wbg_static_accessor_NODE_MODULE_cf6401cc1091279e = function() {
733
+ const ret = module;
734
+ return addHeapObject(ret);
735
+ };
736
+ imports.wbg.__wbg_require_a746e79b322b9336 = function() { return handleError(function (arg0, arg1, arg2) {
737
+ const ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2));
738
+ return addHeapObject(ret);
739
+ }, arguments) };
740
+ imports.wbg.__wbg_newnoargs_b5b063fc6c2f0376 = function(arg0, arg1) {
741
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
742
+ return addHeapObject(ret);
743
+ };
744
+ imports.wbg.__wbg_call_97ae9d8645dc388b = function() { return handleError(function (arg0, arg1) {
745
+ const ret = getObject(arg0).call(getObject(arg1));
746
+ return addHeapObject(ret);
747
+ }, arguments) };
748
+ imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
749
+ const ret = getObject(arg0);
750
+ return addHeapObject(ret);
751
+ };
752
+ imports.wbg.__wbg_self_6d479506f72c6a71 = function() { return handleError(function () {
753
+ const ret = self.self;
754
+ return addHeapObject(ret);
755
+ }, arguments) };
756
+ imports.wbg.__wbg_window_f2557cc78490aceb = function() { return handleError(function () {
757
+ const ret = window.window;
758
+ return addHeapObject(ret);
759
+ }, arguments) };
760
+ imports.wbg.__wbg_globalThis_7f206bda628d5286 = function() { return handleError(function () {
761
+ const ret = globalThis.globalThis;
762
+ return addHeapObject(ret);
763
+ }, arguments) };
764
+ imports.wbg.__wbg_global_ba75c50d1cf384f4 = function() { return handleError(function () {
765
+ const ret = global.global;
766
+ return addHeapObject(ret);
767
+ }, arguments) };
768
+ imports.wbg.__wbindgen_is_undefined = function(arg0) {
769
+ const ret = getObject(arg0) === undefined;
770
+ return ret;
771
+ };
772
+ imports.wbg.__wbg_buffer_3f3d764d4747d564 = function(arg0) {
773
+ const ret = getObject(arg0).buffer;
774
+ return addHeapObject(ret);
775
+ };
776
+ imports.wbg.__wbg_new_8c3f0052272a457a = function(arg0) {
777
+ const ret = new Uint8Array(getObject(arg0));
778
+ return addHeapObject(ret);
779
+ };
780
+ imports.wbg.__wbg_set_83db9690f9353e79 = function(arg0, arg1, arg2) {
781
+ getObject(arg0).set(getObject(arg1), arg2 >>> 0);
782
+ };
783
+ imports.wbg.__wbg_length_9e1ae1900cb0fbd5 = function(arg0) {
784
+ const ret = getObject(arg0).length;
785
+ return ret;
786
+ };
787
+ imports.wbg.__wbg_newwithlength_f5933855e4f48a19 = function(arg0) {
788
+ const ret = new Uint8Array(arg0 >>> 0);
789
+ return addHeapObject(ret);
790
+ };
791
+ imports.wbg.__wbg_subarray_58ad4efbb5bcb886 = function(arg0, arg1, arg2) {
792
+ const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
793
+ return addHeapObject(ret);
794
+ };
795
+ imports.wbg.__wbindgen_throw = function(arg0, arg1) {
796
+ throw new Error(getStringFromWasm0(arg0, arg1));
797
+ };
798
+ imports.wbg.__wbindgen_memory = function() {
799
+ const ret = wasm.memory;
800
+ return addHeapObject(ret);
801
+ };
802
+
803
+ return imports;
804
+ }
805
+
806
+ function initMemory(imports, maybe_memory) {
807
+
808
+ }
809
+
810
+ function finalizeInit(instance, module) {
811
+ wasm = instance.exports;
812
+ init.__wbindgen_wasm_module = module;
813
+ cachedInt32Memory0 = new Int32Array();
814
+ cachedUint8Memory0 = new Uint8Array();
815
+
816
+
817
+ return wasm;
818
+ }
819
+
820
+ function initSync(module) {
821
+ const imports = getImports();
822
+
823
+ initMemory(imports);
824
+
825
+ if (!(module instanceof WebAssembly.Module)) {
826
+ module = new WebAssembly.Module(module);
827
+ }
828
+
829
+ const instance = new WebAssembly.Instance(module, imports);
830
+
831
+ return finalizeInit(instance, module);
832
+ }
833
+
834
+ async function init(input) {
835
+ if (typeof input === 'undefined') {
836
+ input = new URL('hpke_dispatch_bg.wasm', import.meta.url);
837
+ }
838
+ const imports = getImports();
839
+
840
+ if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
841
+ input = fetch(input);
842
+ }
843
+
844
+ initMemory(imports);
845
+
846
+ const { instance, module } = await load(await input, imports);
847
+
848
+ return finalizeInit(instance, module);
849
+ }
850
+
851
+ export { initSync }
852
+ export default init;