pqbox 0.0.0-stage → 1.0.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,921 @@
1
+ /* @ts-self-types="./pqbox_wasm.d.ts" */
2
+
3
+ /**
4
+ * BLAKE3 (32 bytes).
5
+ * @param {Uint8Array} data
6
+ * @returns {Uint8Array}
7
+ */
8
+ export function blake3(data) {
9
+ try {
10
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
11
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
12
+ const len0 = WASM_VECTOR_LEN;
13
+ wasm.blake3(retptr, ptr0, len0);
14
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
15
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
16
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
17
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
18
+ return v2;
19
+ } finally {
20
+ wasm.__wbindgen_add_to_stack_pointer(16);
21
+ }
22
+ }
23
+
24
+ /**
25
+ * AEAD decryption.
26
+ *
27
+ * # Errors
28
+ * Parse errors or `Decrypt`.
29
+ * @param {Uint8Array} key
30
+ * @param {Uint8Array} data
31
+ * @param {Uint8Array} aad
32
+ * @returns {Uint8Array}
33
+ */
34
+ export function decrypt(key, data, aad) {
35
+ try {
36
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
37
+ const ptr0 = passArray8ToWasm0(key, wasm.__wbindgen_export);
38
+ const len0 = WASM_VECTOR_LEN;
39
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_export);
40
+ const len1 = WASM_VECTOR_LEN;
41
+ const ptr2 = passArray8ToWasm0(aad, wasm.__wbindgen_export);
42
+ const len2 = WASM_VECTOR_LEN;
43
+ wasm.decrypt(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
44
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
45
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
46
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
47
+ if (r2) {
48
+ throw takeObject(r1);
49
+ }
50
+ return takeObject(r0);
51
+ } finally {
52
+ wasm.__wbindgen_add_to_stack_pointer(16);
53
+ }
54
+ }
55
+
56
+ /**
57
+ * AEAD encryption with a random nonce.
58
+ *
59
+ * # Errors
60
+ * `InvalidParams` for an unknown algorithm, `InvalidLength` for a bad key.
61
+ * @param {Uint8Array} key
62
+ * @param {Uint8Array} plaintext
63
+ * @param {Uint8Array} aad
64
+ * @param {string} algorithm
65
+ * @returns {Uint8Array}
66
+ */
67
+ export function encrypt(key, plaintext, aad, algorithm) {
68
+ try {
69
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
70
+ const ptr0 = passArray8ToWasm0(key, wasm.__wbindgen_export);
71
+ const len0 = WASM_VECTOR_LEN;
72
+ const ptr1 = passArray8ToWasm0(plaintext, wasm.__wbindgen_export);
73
+ const len1 = WASM_VECTOR_LEN;
74
+ const ptr2 = passArray8ToWasm0(aad, wasm.__wbindgen_export);
75
+ const len2 = WASM_VECTOR_LEN;
76
+ const ptr3 = passStringToWasm0(algorithm, wasm.__wbindgen_export, wasm.__wbindgen_export2);
77
+ const len3 = WASM_VECTOR_LEN;
78
+ wasm.encrypt(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
79
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
80
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
81
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
82
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
83
+ if (r3) {
84
+ throw takeObject(r2);
85
+ }
86
+ var v5 = getArrayU8FromWasm0(r0, r1).slice();
87
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
88
+ return v5;
89
+ } finally {
90
+ wasm.__wbindgen_add_to_stack_pointer(16);
91
+ }
92
+ }
93
+
94
+ /**
95
+ * A fresh random 32-byte AEAD key.
96
+ * @returns {Uint8Array}
97
+ */
98
+ export function generateKey() {
99
+ const ret = wasm.generateKey();
100
+ return takeObject(ret);
101
+ }
102
+
103
+ /**
104
+ * Hashes with a named algorithm (`sha256`, `sha3-256`, `blake3`).
105
+ *
106
+ * # Errors
107
+ * `InvalidParams` for an unknown algorithm.
108
+ * @param {Uint8Array} data
109
+ * @param {string} algorithm
110
+ * @returns {Uint8Array}
111
+ */
112
+ export function hash(data, algorithm) {
113
+ try {
114
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
115
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
116
+ const len0 = WASM_VECTOR_LEN;
117
+ const ptr1 = passStringToWasm0(algorithm, wasm.__wbindgen_export, wasm.__wbindgen_export2);
118
+ const len1 = WASM_VECTOR_LEN;
119
+ wasm.hash(retptr, ptr0, len0, ptr1, len1);
120
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
121
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
122
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
123
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
124
+ if (r3) {
125
+ throw takeObject(r2);
126
+ }
127
+ var v3 = getArrayU8FromWasm0(r0, r1).slice();
128
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
129
+ return v3;
130
+ } finally {
131
+ wasm.__wbindgen_add_to_stack_pointer(16);
132
+ }
133
+ }
134
+
135
+ /**
136
+ * HKDF-SHA-256.
137
+ *
138
+ * # Errors
139
+ * `InvalidParams` when `length` is not an integer in `0..=8160`.
140
+ * @param {Uint8Array} ikm
141
+ * @param {Uint8Array} salt
142
+ * @param {Uint8Array} info
143
+ * @param {number} length
144
+ * @returns {Uint8Array}
145
+ */
146
+ export function hkdfSha256(ikm, salt, info, length) {
147
+ try {
148
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
149
+ const ptr0 = passArray8ToWasm0(ikm, wasm.__wbindgen_export);
150
+ const len0 = WASM_VECTOR_LEN;
151
+ const ptr1 = passArray8ToWasm0(salt, wasm.__wbindgen_export);
152
+ const len1 = WASM_VECTOR_LEN;
153
+ const ptr2 = passArray8ToWasm0(info, wasm.__wbindgen_export);
154
+ const len2 = WASM_VECTOR_LEN;
155
+ wasm.hkdfSha256(retptr, ptr0, len0, ptr1, len1, ptr2, len2, length);
156
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
157
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
158
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
159
+ if (r2) {
160
+ throw takeObject(r1);
161
+ }
162
+ return takeObject(r0);
163
+ } finally {
164
+ wasm.__wbindgen_add_to_stack_pointer(16);
165
+ }
166
+ }
167
+
168
+ /**
169
+ * HMAC-SHA-256.
170
+ *
171
+ * # Errors
172
+ * Never in practice.
173
+ * @param {Uint8Array} key
174
+ * @param {Uint8Array} message
175
+ * @returns {Uint8Array}
176
+ */
177
+ export function hmacSha256(key, message) {
178
+ try {
179
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
180
+ const ptr0 = passArray8ToWasm0(key, wasm.__wbindgen_export);
181
+ const len0 = WASM_VECTOR_LEN;
182
+ const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_export);
183
+ const len1 = WASM_VECTOR_LEN;
184
+ wasm.hmacSha256(retptr, ptr0, len0, ptr1, len1);
185
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
186
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
187
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
188
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
189
+ if (r3) {
190
+ throw takeObject(r2);
191
+ }
192
+ var v3 = getArrayU8FromWasm0(r0, r1).slice();
193
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
194
+ return v3;
195
+ } finally {
196
+ wasm.__wbindgen_add_to_stack_pointer(16);
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Constant-time HMAC-SHA-256 tag check.
202
+ * @param {Uint8Array} key
203
+ * @param {Uint8Array} message
204
+ * @param {Uint8Array} tag
205
+ * @returns {boolean}
206
+ */
207
+ export function hmacSha256Verify(key, message, tag) {
208
+ const ptr0 = passArray8ToWasm0(key, wasm.__wbindgen_export);
209
+ const len0 = WASM_VECTOR_LEN;
210
+ const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_export);
211
+ const len1 = WASM_VECTOR_LEN;
212
+ const ptr2 = passArray8ToWasm0(tag, wasm.__wbindgen_export);
213
+ const len2 = WASM_VECTOR_LEN;
214
+ const ret = wasm.hmacSha256Verify(ptr0, len0, ptr1, len1, ptr2, len2);
215
+ return ret !== 0;
216
+ }
217
+
218
+ /**
219
+ * Decapsulates a ciphertext into the 32-byte shared secret.
220
+ *
221
+ * # Errors
222
+ * Parse errors, `SuiteNotAllowed`, `SuiteMismatch` or `Decrypt`.
223
+ * @param {Uint8Array} secret_key
224
+ * @param {Uint8Array} ciphertext
225
+ * @param {string[]} allow_suites
226
+ * @returns {Uint8Array}
227
+ */
228
+ export function kemDecapsulate(secret_key, ciphertext, allow_suites) {
229
+ try {
230
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
231
+ const ptr0 = passArray8ToWasm0(secret_key, wasm.__wbindgen_export);
232
+ const len0 = WASM_VECTOR_LEN;
233
+ const ptr1 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_export);
234
+ const len1 = WASM_VECTOR_LEN;
235
+ const ptr2 = passArrayJsValueToWasm0(allow_suites, wasm.__wbindgen_export);
236
+ const len2 = WASM_VECTOR_LEN;
237
+ wasm.kemDecapsulate(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
238
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
239
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
240
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
241
+ if (r2) {
242
+ throw takeObject(r1);
243
+ }
244
+ return takeObject(r0);
245
+ } finally {
246
+ wasm.__wbindgen_add_to_stack_pointer(16);
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Encapsulates to a public key: `{ ciphertext, sharedSecret }`.
252
+ *
253
+ * # Errors
254
+ * Parse errors of the public key, `SuiteNotAllowed`.
255
+ * @param {Uint8Array} public_key
256
+ * @param {string[]} allow_suites
257
+ * @returns {object}
258
+ */
259
+ export function kemEncapsulate(public_key, allow_suites) {
260
+ try {
261
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
262
+ const ptr0 = passArray8ToWasm0(public_key, wasm.__wbindgen_export);
263
+ const len0 = WASM_VECTOR_LEN;
264
+ const ptr1 = passArrayJsValueToWasm0(allow_suites, wasm.__wbindgen_export);
265
+ const len1 = WASM_VECTOR_LEN;
266
+ wasm.kemEncapsulate(retptr, ptr0, len0, ptr1, len1);
267
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
268
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
269
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
270
+ if (r2) {
271
+ throw takeObject(r1);
272
+ }
273
+ return takeObject(r0);
274
+ } finally {
275
+ wasm.__wbindgen_add_to_stack_pointer(16);
276
+ }
277
+ }
278
+
279
+ /**
280
+ * Generates a KEM key pair: `{ publicKey, secretKey }`.
281
+ *
282
+ * # Errors
283
+ * `InvalidParams` for an unknown suite.
284
+ * @param {string} suite_name
285
+ * @returns {object}
286
+ */
287
+ export function kemKeygen(suite_name) {
288
+ try {
289
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
290
+ const ptr0 = passStringToWasm0(suite_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
291
+ const len0 = WASM_VECTOR_LEN;
292
+ wasm.kemKeygen(retptr, ptr0, len0);
293
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
294
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
295
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
296
+ if (r2) {
297
+ throw takeObject(r1);
298
+ }
299
+ return takeObject(r0);
300
+ } finally {
301
+ wasm.__wbindgen_add_to_stack_pointer(16);
302
+ }
303
+ }
304
+
305
+ /**
306
+ * Opens a sealed box.
307
+ *
308
+ * # Errors
309
+ * Parse errors, `SuiteNotAllowed`, `SuiteMismatch` or `Decrypt`.
310
+ * @param {Uint8Array} secret_key
311
+ * @param {Uint8Array} sealed
312
+ * @param {string[]} allow_suites
313
+ * @returns {Uint8Array}
314
+ */
315
+ export function open(secret_key, sealed, allow_suites) {
316
+ try {
317
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
318
+ const ptr0 = passArray8ToWasm0(secret_key, wasm.__wbindgen_export);
319
+ const len0 = WASM_VECTOR_LEN;
320
+ const ptr1 = passArray8ToWasm0(sealed, wasm.__wbindgen_export);
321
+ const len1 = WASM_VECTOR_LEN;
322
+ const ptr2 = passArrayJsValueToWasm0(allow_suites, wasm.__wbindgen_export);
323
+ const len2 = WASM_VECTOR_LEN;
324
+ wasm.open(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
325
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
326
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
327
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
328
+ if (r2) {
329
+ throw takeObject(r1);
330
+ }
331
+ return takeObject(r0);
332
+ } finally {
333
+ wasm.__wbindgen_add_to_stack_pointer(16);
334
+ }
335
+ }
336
+
337
+ /**
338
+ * Argon2id password hash as a PHC string.
339
+ *
340
+ * # Errors
341
+ * `InvalidParams` for out-of-range costs (including costs above the default limits: 256 MiB,
342
+ * 10 passes, 8 lanes).
343
+ * @param {Uint8Array} password
344
+ * @param {number} m_cost
345
+ * @param {number} t_cost
346
+ * @param {number} p_cost
347
+ * @returns {string}
348
+ */
349
+ export function passwordHash(password, m_cost, t_cost, p_cost) {
350
+ let deferred3_0;
351
+ let deferred3_1;
352
+ try {
353
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
354
+ const ptr0 = passArray8ToWasm0(password, wasm.__wbindgen_export);
355
+ const len0 = WASM_VECTOR_LEN;
356
+ wasm.passwordHash(retptr, ptr0, len0, m_cost, t_cost, p_cost);
357
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
358
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
359
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
360
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
361
+ var ptr2 = r0;
362
+ var len2 = r1;
363
+ if (r3) {
364
+ ptr2 = 0; len2 = 0;
365
+ throw takeObject(r2);
366
+ }
367
+ deferred3_0 = ptr2;
368
+ deferred3_1 = len2;
369
+ return getStringFromWasm0(ptr2, len2);
370
+ } finally {
371
+ wasm.__wbindgen_add_to_stack_pointer(16);
372
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
373
+ }
374
+ }
375
+
376
+ /**
377
+ * Checks a password: `false` on mismatch, an error for an invalid hash string or one whose costs
378
+ * exceed the given limits (checked before any memory is allocated).
379
+ *
380
+ * # Errors
381
+ * `InvalidPasswordHash`, or `InvalidParams` for limits that are not integers in `0..=2^32-1`.
382
+ * @param {Uint8Array} password
383
+ * @param {string} phc
384
+ * @param {number} max_m_cost
385
+ * @param {number} max_t_cost
386
+ * @param {number} max_p_cost
387
+ * @returns {boolean}
388
+ */
389
+ export function passwordVerify(password, phc, max_m_cost, max_t_cost, max_p_cost) {
390
+ try {
391
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
392
+ const ptr0 = passArray8ToWasm0(password, wasm.__wbindgen_export);
393
+ const len0 = WASM_VECTOR_LEN;
394
+ const ptr1 = passStringToWasm0(phc, wasm.__wbindgen_export, wasm.__wbindgen_export2);
395
+ const len1 = WASM_VECTOR_LEN;
396
+ wasm.passwordVerify(retptr, ptr0, len0, ptr1, len1, max_m_cost, max_t_cost, max_p_cost);
397
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
398
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
399
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
400
+ if (r2) {
401
+ throw takeObject(r1);
402
+ }
403
+ return r0 !== 0;
404
+ } finally {
405
+ wasm.__wbindgen_add_to_stack_pointer(16);
406
+ }
407
+ }
408
+
409
+ /**
410
+ * Seals a message to a KEM public key.
411
+ *
412
+ * # Errors
413
+ * Parse errors of the public key, `SuiteNotAllowed`.
414
+ * @param {Uint8Array} public_key
415
+ * @param {Uint8Array} plaintext
416
+ * @param {string[]} allow_suites
417
+ * @returns {Uint8Array}
418
+ */
419
+ export function seal(public_key, plaintext, allow_suites) {
420
+ try {
421
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
422
+ const ptr0 = passArray8ToWasm0(public_key, wasm.__wbindgen_export);
423
+ const len0 = WASM_VECTOR_LEN;
424
+ const ptr1 = passArray8ToWasm0(plaintext, wasm.__wbindgen_export);
425
+ const len1 = WASM_VECTOR_LEN;
426
+ const ptr2 = passArrayJsValueToWasm0(allow_suites, wasm.__wbindgen_export);
427
+ const len2 = WASM_VECTOR_LEN;
428
+ wasm.seal(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
429
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
430
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
431
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
432
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
433
+ if (r3) {
434
+ throw takeObject(r2);
435
+ }
436
+ var v4 = getArrayU8FromWasm0(r0, r1).slice();
437
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
438
+ return v4;
439
+ } finally {
440
+ wasm.__wbindgen_add_to_stack_pointer(16);
441
+ }
442
+ }
443
+
444
+ /**
445
+ * SHA-256.
446
+ * @param {Uint8Array} data
447
+ * @returns {Uint8Array}
448
+ */
449
+ export function sha256(data) {
450
+ try {
451
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
452
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
453
+ const len0 = WASM_VECTOR_LEN;
454
+ wasm.sha256(retptr, ptr0, len0);
455
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
456
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
457
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
458
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
459
+ return v2;
460
+ } finally {
461
+ wasm.__wbindgen_add_to_stack_pointer(16);
462
+ }
463
+ }
464
+
465
+ /**
466
+ * SHA3-256.
467
+ * @param {Uint8Array} data
468
+ * @returns {Uint8Array}
469
+ */
470
+ export function sha3_256(data) {
471
+ try {
472
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
473
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
474
+ const len0 = WASM_VECTOR_LEN;
475
+ wasm.sha3_256(retptr, ptr0, len0);
476
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
477
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
478
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
479
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
480
+ return v2;
481
+ } finally {
482
+ wasm.__wbindgen_add_to_stack_pointer(16);
483
+ }
484
+ }
485
+
486
+ /**
487
+ * Signs a message.
488
+ *
489
+ * # Errors
490
+ * Parse errors of the secret key, `SuiteNotAllowed`.
491
+ * @param {Uint8Array} secret_key
492
+ * @param {Uint8Array} message
493
+ * @param {string[]} allow_suites
494
+ * @returns {Uint8Array}
495
+ */
496
+ export function sign(secret_key, message, allow_suites) {
497
+ try {
498
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
499
+ const ptr0 = passArray8ToWasm0(secret_key, wasm.__wbindgen_export);
500
+ const len0 = WASM_VECTOR_LEN;
501
+ const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_export);
502
+ const len1 = WASM_VECTOR_LEN;
503
+ const ptr2 = passArrayJsValueToWasm0(allow_suites, wasm.__wbindgen_export);
504
+ const len2 = WASM_VECTOR_LEN;
505
+ wasm.sign(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
506
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
507
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
508
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
509
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
510
+ if (r3) {
511
+ throw takeObject(r2);
512
+ }
513
+ var v4 = getArrayU8FromWasm0(r0, r1).slice();
514
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
515
+ return v4;
516
+ } finally {
517
+ wasm.__wbindgen_add_to_stack_pointer(16);
518
+ }
519
+ }
520
+
521
+ /**
522
+ * Generates a signing key pair: `{ publicKey, secretKey }`.
523
+ *
524
+ * # Errors
525
+ * `InvalidParams` for an unknown suite.
526
+ * @param {string} suite_name
527
+ * @returns {object}
528
+ */
529
+ export function signKeygen(suite_name) {
530
+ try {
531
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
532
+ const ptr0 = passStringToWasm0(suite_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
533
+ const len0 = WASM_VECTOR_LEN;
534
+ wasm.signKeygen(retptr, ptr0, len0);
535
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
536
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
537
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
538
+ if (r2) {
539
+ throw takeObject(r1);
540
+ }
541
+ return takeObject(r0);
542
+ } finally {
543
+ wasm.__wbindgen_add_to_stack_pointer(16);
544
+ }
545
+ }
546
+
547
+ /**
548
+ * The suites compiled into this build, by name.
549
+ * @returns {string[]}
550
+ */
551
+ export function suites() {
552
+ try {
553
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
554
+ wasm.suites(retptr);
555
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
556
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
557
+ var v1 = getArrayJsValueFromWasm0(r0, r1);
558
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
559
+ return v1;
560
+ } finally {
561
+ wasm.__wbindgen_add_to_stack_pointer(16);
562
+ }
563
+ }
564
+
565
+ /**
566
+ * Verifies a signature: `false` when it does not verify, an error for malformed input.
567
+ *
568
+ * # Errors
569
+ * Parse errors, `SuiteNotAllowed` and `SuiteMismatch`.
570
+ * @param {Uint8Array} public_key
571
+ * @param {Uint8Array} message
572
+ * @param {Uint8Array} signature
573
+ * @param {string[]} allow_suites
574
+ * @returns {boolean}
575
+ */
576
+ export function verify(public_key, message, signature, allow_suites) {
577
+ try {
578
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
579
+ const ptr0 = passArray8ToWasm0(public_key, wasm.__wbindgen_export);
580
+ const len0 = WASM_VECTOR_LEN;
581
+ const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_export);
582
+ const len1 = WASM_VECTOR_LEN;
583
+ const ptr2 = passArray8ToWasm0(signature, wasm.__wbindgen_export);
584
+ const len2 = WASM_VECTOR_LEN;
585
+ const ptr3 = passArrayJsValueToWasm0(allow_suites, wasm.__wbindgen_export);
586
+ const len3 = WASM_VECTOR_LEN;
587
+ wasm.verify(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
588
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
589
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
590
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
591
+ if (r2) {
592
+ throw takeObject(r1);
593
+ }
594
+ return r0 !== 0;
595
+ } finally {
596
+ wasm.__wbindgen_add_to_stack_pointer(16);
597
+ }
598
+ }
599
+
600
+ /**
601
+ * The package version.
602
+ * @returns {string}
603
+ */
604
+ export function version() {
605
+ let deferred1_0;
606
+ let deferred1_1;
607
+ try {
608
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
609
+ wasm.version(retptr);
610
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
611
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
612
+ deferred1_0 = r0;
613
+ deferred1_1 = r1;
614
+ return getStringFromWasm0(r0, r1);
615
+ } finally {
616
+ wasm.__wbindgen_add_to_stack_pointer(16);
617
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
618
+ }
619
+ }
620
+ function __wbg_get_imports() {
621
+ const import0 = {
622
+ __proto__: null,
623
+ __wbg_Error_67e7344beaa85059: function(arg0, arg1) {
624
+ const ret = Error(getStringFromWasm0(arg0, arg1));
625
+ return addHeapObject(ret);
626
+ },
627
+ __wbg___wbindgen_string_get_92ab86bb19cbc12f: function(arg0, arg1) {
628
+ const obj = getObject(arg1);
629
+ const ret = typeof(obj) === 'string' ? obj : undefined;
630
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
631
+ var len1 = WASM_VECTOR_LEN;
632
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
633
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
634
+ },
635
+ __wbg___wbindgen_throw_5d9e815e6fdf150f: function(arg0, arg1) {
636
+ throw new Error(getStringFromWasm0(arg0, arg1));
637
+ },
638
+ __wbg_getRandomValues_436a51d0629d84e1: function() { return handleError(function (arg0, arg1) {
639
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
640
+ }, arguments); },
641
+ __wbg_new_bebc3f4757acf305: function() {
642
+ const ret = new Object();
643
+ return addHeapObject(ret);
644
+ },
645
+ __wbg_new_from_slice_4ee02165f9de919e: function(arg0, arg1) {
646
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
647
+ return addHeapObject(ret);
648
+ },
649
+ __wbg_set_a377297433dfea63: function() { return handleError(function (arg0, arg1, arg2) {
650
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
651
+ return ret;
652
+ }, arguments); },
653
+ __wbindgen_generic_0000000000000001: function(arg0, arg1) {
654
+ // Cast intrinsic for `Ref(String) -> Externref`.
655
+ const ret = getStringFromWasm0(arg0, arg1);
656
+ return addHeapObject(ret);
657
+ },
658
+ __wbindgen_object_drop_ref: function(arg0) {
659
+ takeObject(arg0);
660
+ },
661
+ };
662
+ return {
663
+ __proto__: null,
664
+ "./pqbox_wasm_bg.js": import0,
665
+ };
666
+ }
667
+
668
+ function addHeapObject(obj) {
669
+ if (heap_next === heap.length) heap.push(heap.length + 1);
670
+ const idx = heap_next;
671
+ heap_next = heap[idx];
672
+
673
+ heap[idx] = obj;
674
+ return idx;
675
+ }
676
+
677
+ function dropObject(idx) {
678
+ if (idx < 1028) return;
679
+ heap[idx] = heap_next;
680
+ heap_next = idx;
681
+ }
682
+
683
+ function getArrayJsValueFromWasm0(ptr, len) {
684
+ ptr = ptr >>> 0;
685
+ const mem = getDataViewMemory0();
686
+ const result = [];
687
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
688
+ result.push(takeObject(mem.getUint32(i, true)));
689
+ }
690
+ return result;
691
+ }
692
+
693
+ function getArrayU8FromWasm0(ptr, len) {
694
+ ptr = ptr >>> 0;
695
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
696
+ }
697
+
698
+ let cachedDataViewMemory0 = null;
699
+ function getDataViewMemory0() {
700
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
701
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
702
+ }
703
+ return cachedDataViewMemory0;
704
+ }
705
+
706
+ function getStringFromWasm0(ptr, len) {
707
+ return decodeText(ptr >>> 0, len);
708
+ }
709
+
710
+ let cachedUint8ArrayMemory0 = null;
711
+ function getUint8ArrayMemory0() {
712
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
713
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
714
+ }
715
+ return cachedUint8ArrayMemory0;
716
+ }
717
+
718
+ function getObject(idx) { return heap[idx]; }
719
+
720
+ function handleError(f, args) {
721
+ try {
722
+ return f.apply(this, args);
723
+ } catch (e) {
724
+ wasm.__wbindgen_export3(addHeapObject(e));
725
+ }
726
+ }
727
+
728
+ let heap = new Array(1024).fill(undefined);
729
+ heap.push(undefined, null, true, false);
730
+
731
+ let heap_next = heap.length;
732
+
733
+ function isLikeNone(x) {
734
+ return x === undefined || x === null;
735
+ }
736
+
737
+ function passArray8ToWasm0(arg, malloc) {
738
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
739
+ getUint8ArrayMemory0().set(arg, ptr / 1);
740
+ WASM_VECTOR_LEN = arg.length;
741
+ return ptr;
742
+ }
743
+
744
+ function passArrayJsValueToWasm0(array, malloc) {
745
+ const ptr = malloc(array.length * 4, 4) >>> 0;
746
+ const mem = getDataViewMemory0();
747
+ for (let i = 0; i < array.length; i++) {
748
+ mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
749
+ }
750
+ WASM_VECTOR_LEN = array.length;
751
+ return ptr;
752
+ }
753
+
754
+ function passStringToWasm0(arg, malloc, realloc) {
755
+ if (realloc === undefined) {
756
+ const buf = cachedTextEncoder.encode(arg);
757
+ const ptr = malloc(buf.length, 1) >>> 0;
758
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
759
+ WASM_VECTOR_LEN = buf.length;
760
+ return ptr;
761
+ }
762
+
763
+ let len = arg.length;
764
+ let ptr = malloc(len, 1) >>> 0;
765
+
766
+ const mem = getUint8ArrayMemory0();
767
+
768
+ let offset = 0;
769
+
770
+ for (; offset < len; offset++) {
771
+ const code = arg.charCodeAt(offset);
772
+ if (code > 0x7F) break;
773
+ mem[ptr + offset] = code;
774
+ }
775
+ if (offset !== len) {
776
+ if (offset !== 0) {
777
+ arg = arg.slice(offset);
778
+ }
779
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
780
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
781
+ const ret = cachedTextEncoder.encodeInto(arg, view);
782
+
783
+ offset += ret.written;
784
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
785
+ }
786
+
787
+ WASM_VECTOR_LEN = offset;
788
+ return ptr;
789
+ }
790
+
791
+ function takeObject(idx) {
792
+ const ret = getObject(idx);
793
+ dropObject(idx);
794
+ return ret;
795
+ }
796
+
797
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
798
+ cachedTextDecoder.decode();
799
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
800
+ let numBytesDecoded = 0;
801
+ function decodeText(ptr, len) {
802
+ numBytesDecoded += len;
803
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
804
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
805
+ cachedTextDecoder.decode();
806
+ numBytesDecoded = len;
807
+ }
808
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
809
+ }
810
+
811
+ const cachedTextEncoder = new TextEncoder();
812
+
813
+ if (!('encodeInto' in cachedTextEncoder)) {
814
+ cachedTextEncoder.encodeInto = function (arg, view) {
815
+ const buf = cachedTextEncoder.encode(arg);
816
+ view.set(buf);
817
+ return {
818
+ read: arg.length,
819
+ written: buf.length
820
+ };
821
+ };
822
+ }
823
+
824
+ let WASM_VECTOR_LEN = 0;
825
+
826
+ let wasmModule, wasmInstance, wasm;
827
+ function __wbg_finalize_init(instance, module) {
828
+ wasmInstance = instance;
829
+ wasm = instance.exports;
830
+ wasmModule = module;
831
+ cachedDataViewMemory0 = null;
832
+ cachedUint8ArrayMemory0 = null;
833
+ return wasm;
834
+ }
835
+
836
+ async function __wbg_load(module, imports) {
837
+ if (typeof Response === 'function' && module instanceof Response) {
838
+ if (!module.ok) {
839
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
840
+ }
841
+
842
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
843
+ try {
844
+ return await WebAssembly.instantiateStreaming(module, imports);
845
+ } catch (e) {
846
+ const validResponse = expectedResponseType(module.type);
847
+
848
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
849
+ 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);
850
+
851
+ } else { throw e; }
852
+ }
853
+ }
854
+
855
+ const bytes = await module.arrayBuffer();
856
+ return await WebAssembly.instantiate(bytes, imports);
857
+ } else {
858
+ const instance = await WebAssembly.instantiate(module, imports);
859
+
860
+ if (instance instanceof WebAssembly.Instance) {
861
+ return { instance, module };
862
+ } else {
863
+ return instance;
864
+ }
865
+ }
866
+
867
+ function expectedResponseType(type) {
868
+ switch (type) {
869
+ case 'basic': case 'cors': case 'default': return true;
870
+ }
871
+ return false;
872
+ }
873
+ }
874
+
875
+ function initSync(module) {
876
+ if (wasm !== undefined) return wasm;
877
+
878
+
879
+ if (module !== undefined) {
880
+ if (Object.getPrototypeOf(module) === Object.prototype) {
881
+ ({module} = module)
882
+ } else {
883
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
884
+ }
885
+ }
886
+
887
+ const imports = __wbg_get_imports();
888
+ if (!(module instanceof WebAssembly.Module)) {
889
+ module = new WebAssembly.Module(module);
890
+ }
891
+ const instance = new WebAssembly.Instance(module, imports);
892
+ return __wbg_finalize_init(instance, module);
893
+ }
894
+
895
+ async function __wbg_init(module_or_path) {
896
+ if (wasm !== undefined) return wasm;
897
+
898
+
899
+ if (module_or_path !== undefined) {
900
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
901
+ ({module_or_path} = module_or_path)
902
+ } else {
903
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
904
+ }
905
+ }
906
+
907
+ if (module_or_path === undefined) {
908
+ throw new Error('pqbox: the WebAssembly module is embedded; call initSync');
909
+ }
910
+ const imports = __wbg_get_imports();
911
+
912
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
913
+ module_or_path = fetch(module_or_path);
914
+ }
915
+
916
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
917
+
918
+ return __wbg_finalize_init(instance, module);
919
+ }
920
+
921
+ export { initSync, __wbg_init as default };