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