@f0rest8/metamorphic-crypto 0.3.2

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,1094 @@
1
+ /* @ts-self-types="./metamorphic_crypto.d.ts" */
2
+
3
+ /**
4
+ * Seal plaintext (base64) to a recipient's public key. Returns base64 ciphertext.
5
+ * @param {string} plaintext_b64
6
+ * @param {string} public_key_b64
7
+ * @returns {string}
8
+ */
9
+ export function boxSeal(plaintext_b64, public_key_b64) {
10
+ let deferred4_0;
11
+ let deferred4_1;
12
+ try {
13
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
14
+ const ptr0 = passStringToWasm0(plaintext_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
15
+ const len0 = WASM_VECTOR_LEN;
16
+ const ptr1 = passStringToWasm0(public_key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
17
+ const len1 = WASM_VECTOR_LEN;
18
+ wasm.boxSeal(retptr, ptr0, len0, ptr1, len1);
19
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
20
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
21
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
22
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
23
+ var ptr3 = r0;
24
+ var len3 = r1;
25
+ if (r3) {
26
+ ptr3 = 0; len3 = 0;
27
+ throw takeObject(r2);
28
+ }
29
+ deferred4_0 = ptr3;
30
+ deferred4_1 = len3;
31
+ return getStringFromWasm0(ptr3, len3);
32
+ } finally {
33
+ wasm.__wbindgen_add_to_stack_pointer(16);
34
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Open a sealed box. Returns base64-encoded plaintext.
40
+ * @param {string} ciphertext_b64
41
+ * @param {string} public_key_b64
42
+ * @param {string} private_key_b64
43
+ * @returns {string}
44
+ */
45
+ export function boxSealOpen(ciphertext_b64, public_key_b64, private_key_b64) {
46
+ let deferred5_0;
47
+ let deferred5_1;
48
+ try {
49
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
50
+ const ptr0 = passStringToWasm0(ciphertext_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
51
+ const len0 = WASM_VECTOR_LEN;
52
+ const ptr1 = passStringToWasm0(public_key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
53
+ const len1 = WASM_VECTOR_LEN;
54
+ const ptr2 = passStringToWasm0(private_key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
55
+ const len2 = WASM_VECTOR_LEN;
56
+ wasm.boxSealOpen(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
57
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
58
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
59
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
60
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
61
+ var ptr4 = r0;
62
+ var len4 = r1;
63
+ if (r3) {
64
+ ptr4 = 0; len4 = 0;
65
+ throw takeObject(r2);
66
+ }
67
+ deferred5_0 = ptr4;
68
+ deferred5_1 = len4;
69
+ return getStringFromWasm0(ptr4, len4);
70
+ } finally {
71
+ wasm.__wbindgen_add_to_stack_pointer(16);
72
+ wasm.__wbindgen_export4(deferred5_0, deferred5_1, 1);
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Decrypt an encrypted private key with a session key. Returns base64 private key.
78
+ * @param {string} ciphertext_b64
79
+ * @param {string} session_key_b64
80
+ * @returns {string}
81
+ */
82
+ export function decryptPrivateKey(ciphertext_b64, session_key_b64) {
83
+ let deferred4_0;
84
+ let deferred4_1;
85
+ try {
86
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
87
+ const ptr0 = passStringToWasm0(ciphertext_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
88
+ const len0 = WASM_VECTOR_LEN;
89
+ const ptr1 = passStringToWasm0(session_key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
90
+ const len1 = WASM_VECTOR_LEN;
91
+ wasm.decryptPrivateKey(retptr, ptr0, len0, ptr1, len1);
92
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
93
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
94
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
95
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
96
+ var ptr3 = r0;
97
+ var len3 = r1;
98
+ if (r3) {
99
+ ptr3 = 0; len3 = 0;
100
+ throw takeObject(r2);
101
+ }
102
+ deferred4_0 = ptr3;
103
+ deferred4_1 = len3;
104
+ return getStringFromWasm0(ptr3, len3);
105
+ } finally {
106
+ wasm.__wbindgen_add_to_stack_pointer(16);
107
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Decrypt private key from recovery backup. Returns base64 private key.
113
+ * @param {string} ciphertext_b64
114
+ * @param {string} recovery_secret_b64
115
+ * @returns {string}
116
+ */
117
+ export function decryptPrivateKeyWithRecovery(ciphertext_b64, recovery_secret_b64) {
118
+ let deferred4_0;
119
+ let deferred4_1;
120
+ try {
121
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
122
+ const ptr0 = passStringToWasm0(ciphertext_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
123
+ const len0 = WASM_VECTOR_LEN;
124
+ const ptr1 = passStringToWasm0(recovery_secret_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
125
+ const len1 = WASM_VECTOR_LEN;
126
+ wasm.decryptPrivateKeyWithRecovery(retptr, ptr0, len0, ptr1, len1);
127
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
128
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
129
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
130
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
131
+ var ptr3 = r0;
132
+ var len3 = r1;
133
+ if (r3) {
134
+ ptr3 = 0; len3 = 0;
135
+ throw takeObject(r2);
136
+ }
137
+ deferred4_0 = ptr3;
138
+ deferred4_1 = len3;
139
+ return getStringFromWasm0(ptr3, len3);
140
+ } finally {
141
+ wasm.__wbindgen_add_to_stack_pointer(16);
142
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Decrypt base64 ciphertext, returning plaintext as base64.
148
+ * @param {string} ciphertext_b64
149
+ * @param {string} key_b64
150
+ * @returns {string}
151
+ */
152
+ export function decryptSecretbox(ciphertext_b64, key_b64) {
153
+ let deferred4_0;
154
+ let deferred4_1;
155
+ try {
156
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
157
+ const ptr0 = passStringToWasm0(ciphertext_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
158
+ const len0 = WASM_VECTOR_LEN;
159
+ const ptr1 = passStringToWasm0(key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
160
+ const len1 = WASM_VECTOR_LEN;
161
+ wasm.decryptSecretbox(retptr, ptr0, len0, ptr1, len1);
162
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
163
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
164
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
165
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
166
+ var ptr3 = r0;
167
+ var len3 = r1;
168
+ if (r3) {
169
+ ptr3 = 0; len3 = 0;
170
+ throw takeObject(r2);
171
+ }
172
+ deferred4_0 = ptr3;
173
+ deferred4_1 = len3;
174
+ return getStringFromWasm0(ptr3, len3);
175
+ } finally {
176
+ wasm.__wbindgen_add_to_stack_pointer(16);
177
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Decrypt base64 ciphertext to a UTF-8 string.
183
+ * @param {string} ciphertext_b64
184
+ * @param {string} key_b64
185
+ * @returns {string}
186
+ */
187
+ export function decryptSecretboxToString(ciphertext_b64, key_b64) {
188
+ let deferred4_0;
189
+ let deferred4_1;
190
+ try {
191
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
192
+ const ptr0 = passStringToWasm0(ciphertext_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
193
+ const len0 = WASM_VECTOR_LEN;
194
+ const ptr1 = passStringToWasm0(key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
195
+ const len1 = WASM_VECTOR_LEN;
196
+ wasm.decryptSecretboxToString(retptr, ptr0, len0, ptr1, len1);
197
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
198
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
199
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
200
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
201
+ var ptr3 = r0;
202
+ var len3 = r1;
203
+ if (r3) {
204
+ ptr3 = 0; len3 = 0;
205
+ throw takeObject(r2);
206
+ }
207
+ deferred4_0 = ptr3;
208
+ deferred4_1 = len3;
209
+ return getStringFromWasm0(ptr3, len3);
210
+ } finally {
211
+ wasm.__wbindgen_add_to_stack_pointer(16);
212
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
213
+ }
214
+ }
215
+
216
+ /**
217
+ * Derive a 32-byte session key from password + base64-encoded salt.
218
+ * Returns base64-encoded key.
219
+ * @param {string} password
220
+ * @param {string} salt_b64
221
+ * @returns {string}
222
+ */
223
+ export function deriveSessionKey(password, salt_b64) {
224
+ let deferred4_0;
225
+ let deferred4_1;
226
+ try {
227
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
228
+ const ptr0 = passStringToWasm0(password, wasm.__wbindgen_export, wasm.__wbindgen_export2);
229
+ const len0 = WASM_VECTOR_LEN;
230
+ const ptr1 = passStringToWasm0(salt_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
231
+ const len1 = WASM_VECTOR_LEN;
232
+ wasm.deriveSessionKey(retptr, ptr0, len0, ptr1, len1);
233
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
234
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
235
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
236
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
237
+ var ptr3 = r0;
238
+ var len3 = r1;
239
+ if (r3) {
240
+ ptr3 = 0; len3 = 0;
241
+ throw takeObject(r2);
242
+ }
243
+ deferred4_0 = ptr3;
244
+ deferred4_1 = len3;
245
+ return getStringFromWasm0(ptr3, len3);
246
+ } finally {
247
+ wasm.__wbindgen_add_to_stack_pointer(16);
248
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
249
+ }
250
+ }
251
+
252
+ /**
253
+ * Encrypt a base64 private key with a session key. Returns base64 ciphertext.
254
+ * @param {string} private_key_b64
255
+ * @param {string} session_key_b64
256
+ * @returns {string}
257
+ */
258
+ export function encryptPrivateKey(private_key_b64, session_key_b64) {
259
+ let deferred4_0;
260
+ let deferred4_1;
261
+ try {
262
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
263
+ const ptr0 = passStringToWasm0(private_key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
264
+ const len0 = WASM_VECTOR_LEN;
265
+ const ptr1 = passStringToWasm0(session_key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
266
+ const len1 = WASM_VECTOR_LEN;
267
+ wasm.encryptPrivateKey(retptr, ptr0, len0, ptr1, len1);
268
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
269
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
270
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
271
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
272
+ var ptr3 = r0;
273
+ var len3 = r1;
274
+ if (r3) {
275
+ ptr3 = 0; len3 = 0;
276
+ throw takeObject(r2);
277
+ }
278
+ deferred4_0 = ptr3;
279
+ deferred4_1 = len3;
280
+ return getStringFromWasm0(ptr3, len3);
281
+ } finally {
282
+ wasm.__wbindgen_add_to_stack_pointer(16);
283
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
284
+ }
285
+ }
286
+
287
+ /**
288
+ * Encrypt private key for recovery backup. Returns base64 ciphertext.
289
+ * @param {string} private_key_b64
290
+ * @param {string} recovery_secret_b64
291
+ * @returns {string}
292
+ */
293
+ export function encryptPrivateKeyForRecovery(private_key_b64, recovery_secret_b64) {
294
+ let deferred4_0;
295
+ let deferred4_1;
296
+ try {
297
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
298
+ const ptr0 = passStringToWasm0(private_key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
299
+ const len0 = WASM_VECTOR_LEN;
300
+ const ptr1 = passStringToWasm0(recovery_secret_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
301
+ const len1 = WASM_VECTOR_LEN;
302
+ wasm.encryptPrivateKeyForRecovery(retptr, ptr0, len0, ptr1, len1);
303
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
304
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
305
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
306
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
307
+ var ptr3 = r0;
308
+ var len3 = r1;
309
+ if (r3) {
310
+ ptr3 = 0; len3 = 0;
311
+ throw takeObject(r2);
312
+ }
313
+ deferred4_0 = ptr3;
314
+ deferred4_1 = len3;
315
+ return getStringFromWasm0(ptr3, len3);
316
+ } finally {
317
+ wasm.__wbindgen_add_to_stack_pointer(16);
318
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
319
+ }
320
+ }
321
+
322
+ /**
323
+ * Encrypt raw bytes (as base64) with a base64 key. Returns base64 ciphertext.
324
+ * @param {string} plaintext_b64
325
+ * @param {string} key_b64
326
+ * @returns {string}
327
+ */
328
+ export function encryptSecretbox(plaintext_b64, key_b64) {
329
+ let deferred4_0;
330
+ let deferred4_1;
331
+ try {
332
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
333
+ const ptr0 = passStringToWasm0(plaintext_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
334
+ const len0 = WASM_VECTOR_LEN;
335
+ const ptr1 = passStringToWasm0(key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
336
+ const len1 = WASM_VECTOR_LEN;
337
+ wasm.encryptSecretbox(retptr, ptr0, len0, ptr1, len1);
338
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
339
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
340
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
341
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
342
+ var ptr3 = r0;
343
+ var len3 = r1;
344
+ if (r3) {
345
+ ptr3 = 0; len3 = 0;
346
+ throw takeObject(r2);
347
+ }
348
+ deferred4_0 = ptr3;
349
+ deferred4_1 = len3;
350
+ return getStringFromWasm0(ptr3, len3);
351
+ } finally {
352
+ wasm.__wbindgen_add_to_stack_pointer(16);
353
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
354
+ }
355
+ }
356
+
357
+ /**
358
+ * Encrypt a UTF-8 string with a base64 key. Returns base64 ciphertext.
359
+ * @param {string} plaintext
360
+ * @param {string} key_b64
361
+ * @returns {string}
362
+ */
363
+ export function encryptSecretboxString(plaintext, key_b64) {
364
+ let deferred4_0;
365
+ let deferred4_1;
366
+ try {
367
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
368
+ const ptr0 = passStringToWasm0(plaintext, wasm.__wbindgen_export, wasm.__wbindgen_export2);
369
+ const len0 = WASM_VECTOR_LEN;
370
+ const ptr1 = passStringToWasm0(key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
371
+ const len1 = WASM_VECTOR_LEN;
372
+ wasm.encryptSecretboxString(retptr, ptr0, len0, ptr1, len1);
373
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
374
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
375
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
376
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
377
+ var ptr3 = r0;
378
+ var len3 = r1;
379
+ if (r3) {
380
+ ptr3 = 0; len3 = 0;
381
+ throw takeObject(r2);
382
+ }
383
+ deferred4_0 = ptr3;
384
+ deferred4_1 = len3;
385
+ return getStringFromWasm0(ptr3, len3);
386
+ } finally {
387
+ wasm.__wbindgen_add_to_stack_pointer(16);
388
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
389
+ }
390
+ }
391
+
392
+ /**
393
+ * Generate a ML-KEM-768 keypair. Returns JSON: `{ publicKey, secretKey }`.
394
+ * @returns {any}
395
+ */
396
+ export function generateHybridKeyPair() {
397
+ const ret = wasm.generateHybridKeyPair();
398
+ return takeObject(ret);
399
+ }
400
+
401
+ /**
402
+ * Generate a ML-KEM-1024 + X25519 keypair (Cat-5). Returns JSON: `{ publicKey, secretKey }`.
403
+ * @returns {any}
404
+ */
405
+ export function generateHybridKeyPair1024() {
406
+ const ret = wasm.generateHybridKeyPair1024();
407
+ return takeObject(ret);
408
+ }
409
+
410
+ /**
411
+ * Generate a random 32-byte symmetric key (base64).
412
+ * @returns {string}
413
+ */
414
+ export function generateKey() {
415
+ let deferred1_0;
416
+ let deferred1_1;
417
+ try {
418
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
419
+ wasm.generateKey(retptr);
420
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
421
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
422
+ deferred1_0 = r0;
423
+ deferred1_1 = r1;
424
+ return getStringFromWasm0(r0, r1);
425
+ } finally {
426
+ wasm.__wbindgen_add_to_stack_pointer(16);
427
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
428
+ }
429
+ }
430
+
431
+ /**
432
+ * Generate a random X25519 keypair. Returns JSON: `{ publicKey, privateKey }`.
433
+ * @returns {any}
434
+ */
435
+ export function generateKeyPair() {
436
+ const ret = wasm.generateKeyPair();
437
+ return takeObject(ret);
438
+ }
439
+
440
+ /**
441
+ * Generate a recovery key. Returns JSON: `{ recoveryKey, recoverySecretBase64 }`.
442
+ * @returns {any}
443
+ */
444
+ export function generateRecoveryKey() {
445
+ try {
446
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
447
+ wasm.generateRecoveryKey(retptr);
448
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
449
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
450
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
451
+ if (r2) {
452
+ throw takeObject(r1);
453
+ }
454
+ return takeObject(r0);
455
+ } finally {
456
+ wasm.__wbindgen_add_to_stack_pointer(16);
457
+ }
458
+ }
459
+
460
+ /**
461
+ * Generate a random 16-byte salt (base64).
462
+ * @returns {string}
463
+ */
464
+ export function generateSalt() {
465
+ let deferred1_0;
466
+ let deferred1_1;
467
+ try {
468
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
469
+ wasm.generateSalt(retptr);
470
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
471
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
472
+ deferred1_0 = r0;
473
+ deferred1_1 = r1;
474
+ return getStringFromWasm0(r0, r1);
475
+ } finally {
476
+ wasm.__wbindgen_add_to_stack_pointer(16);
477
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
478
+ }
479
+ }
480
+
481
+ /**
482
+ * Check if a base64 ciphertext is hybrid (v2/v3) format.
483
+ * @param {string} ciphertext_b64
484
+ * @returns {boolean}
485
+ */
486
+ export function isHybridCiphertext(ciphertext_b64) {
487
+ const ptr0 = passStringToWasm0(ciphertext_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
488
+ const len0 = WASM_VECTOR_LEN;
489
+ const ret = wasm.isHybridCiphertext(ptr0, len0);
490
+ return ret !== 0;
491
+ }
492
+
493
+ /**
494
+ * Parse the salt (base64) from a key_hash string (`salt$argon2id`).
495
+ * @param {string} key_hash
496
+ * @returns {string}
497
+ */
498
+ export function parseSaltFromKeyHash(key_hash) {
499
+ let deferred3_0;
500
+ let deferred3_1;
501
+ try {
502
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
503
+ const ptr0 = passStringToWasm0(key_hash, wasm.__wbindgen_export, wasm.__wbindgen_export2);
504
+ const len0 = WASM_VECTOR_LEN;
505
+ wasm.parseSaltFromKeyHash(retptr, ptr0, len0);
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
+ var ptr2 = r0;
511
+ var len2 = r1;
512
+ if (r3) {
513
+ ptr2 = 0; len2 = 0;
514
+ throw takeObject(r2);
515
+ }
516
+ deferred3_0 = ptr2;
517
+ deferred3_1 = len2;
518
+ return getStringFromWasm0(ptr2, len2);
519
+ } finally {
520
+ wasm.__wbindgen_add_to_stack_pointer(16);
521
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
522
+ }
523
+ }
524
+
525
+ /**
526
+ * Derive the 32-byte secret (base64) from a human-readable recovery key.
527
+ * @param {string} recovery_key
528
+ * @returns {string}
529
+ */
530
+ export function recoveryKeyToSecret(recovery_key) {
531
+ let deferred3_0;
532
+ let deferred3_1;
533
+ try {
534
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
535
+ const ptr0 = passStringToWasm0(recovery_key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
536
+ const len0 = WASM_VECTOR_LEN;
537
+ wasm.recoveryKeyToSecret(retptr, ptr0, len0);
538
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
539
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
540
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
541
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
542
+ var ptr2 = r0;
543
+ var len2 = r1;
544
+ if (r3) {
545
+ ptr2 = 0; len2 = 0;
546
+ throw takeObject(r2);
547
+ }
548
+ deferred3_0 = ptr2;
549
+ deferred3_1 = len2;
550
+ return getStringFromWasm0(ptr2, len2);
551
+ } finally {
552
+ wasm.__wbindgen_add_to_stack_pointer(16);
553
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
554
+ }
555
+ }
556
+
557
+ /**
558
+ * Seal plaintext bytes (base64) to a user's key(s). Uses hybrid PQ if pq_pk is provided.
559
+ * @param {string} plaintext_b64
560
+ * @param {string} public_key_b64
561
+ * @param {string | null} [pq_public_key_b64]
562
+ * @returns {string}
563
+ */
564
+ export function sealForUser(plaintext_b64, public_key_b64, pq_public_key_b64) {
565
+ let deferred5_0;
566
+ let deferred5_1;
567
+ try {
568
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
569
+ const ptr0 = passStringToWasm0(plaintext_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
570
+ const len0 = WASM_VECTOR_LEN;
571
+ const ptr1 = passStringToWasm0(public_key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
572
+ const len1 = WASM_VECTOR_LEN;
573
+ var ptr2 = isLikeNone(pq_public_key_b64) ? 0 : passStringToWasm0(pq_public_key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
574
+ var len2 = WASM_VECTOR_LEN;
575
+ wasm.sealForUser(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
576
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
577
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
578
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
579
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
580
+ var ptr4 = r0;
581
+ var len4 = r1;
582
+ if (r3) {
583
+ ptr4 = 0; len4 = 0;
584
+ throw takeObject(r2);
585
+ }
586
+ deferred5_0 = ptr4;
587
+ deferred5_1 = len4;
588
+ return getStringFromWasm0(ptr4, len4);
589
+ } finally {
590
+ wasm.__wbindgen_add_to_stack_pointer(16);
591
+ wasm.__wbindgen_export4(deferred5_0, deferred5_1, 1);
592
+ }
593
+ }
594
+
595
+ /**
596
+ * Seal plaintext bytes (base64) to a user's key(s) at a specific security level.
597
+ *
598
+ * `level` must be `"cat3"` (ML-KEM-768, default) or `"cat5"` (ML-KEM-1024).
599
+ * If `pq_public_key_b64` is absent or empty, falls back to legacy X25519.
600
+ * @param {string} plaintext_b64
601
+ * @param {string} public_key_b64
602
+ * @param {string | null | undefined} pq_public_key_b64
603
+ * @param {string} level
604
+ * @returns {string}
605
+ */
606
+ export function sealForUserWithLevel(plaintext_b64, public_key_b64, pq_public_key_b64, level) {
607
+ let deferred6_0;
608
+ let deferred6_1;
609
+ try {
610
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
611
+ const ptr0 = passStringToWasm0(plaintext_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
612
+ const len0 = WASM_VECTOR_LEN;
613
+ const ptr1 = passStringToWasm0(public_key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
614
+ const len1 = WASM_VECTOR_LEN;
615
+ var ptr2 = isLikeNone(pq_public_key_b64) ? 0 : passStringToWasm0(pq_public_key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
616
+ var len2 = WASM_VECTOR_LEN;
617
+ const ptr3 = passStringToWasm0(level, wasm.__wbindgen_export, wasm.__wbindgen_export2);
618
+ const len3 = WASM_VECTOR_LEN;
619
+ wasm.sealForUserWithLevel(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
620
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
621
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
622
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
623
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
624
+ var ptr5 = r0;
625
+ var len5 = r1;
626
+ if (r3) {
627
+ ptr5 = 0; len5 = 0;
628
+ throw takeObject(r2);
629
+ }
630
+ deferred6_0 = ptr5;
631
+ deferred6_1 = len5;
632
+ return getStringFromWasm0(ptr5, len5);
633
+ } finally {
634
+ wasm.__wbindgen_add_to_stack_pointer(16);
635
+ wasm.__wbindgen_export4(deferred6_0, deferred6_1, 1);
636
+ }
637
+ }
638
+
639
+ /**
640
+ * Unseal ciphertext using the user's keys. Auto-detects format.
641
+ * Returns base64-encoded plaintext.
642
+ * @param {string} ciphertext_b64
643
+ * @param {string} public_key_b64
644
+ * @param {string} private_key_b64
645
+ * @param {string | null} [pq_secret_key_b64]
646
+ * @returns {string}
647
+ */
648
+ export function unsealFromUser(ciphertext_b64, public_key_b64, private_key_b64, pq_secret_key_b64) {
649
+ let deferred6_0;
650
+ let deferred6_1;
651
+ try {
652
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
653
+ const ptr0 = passStringToWasm0(ciphertext_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
654
+ const len0 = WASM_VECTOR_LEN;
655
+ const ptr1 = passStringToWasm0(public_key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
656
+ const len1 = WASM_VECTOR_LEN;
657
+ const ptr2 = passStringToWasm0(private_key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
658
+ const len2 = WASM_VECTOR_LEN;
659
+ var ptr3 = isLikeNone(pq_secret_key_b64) ? 0 : passStringToWasm0(pq_secret_key_b64, wasm.__wbindgen_export, wasm.__wbindgen_export2);
660
+ var len3 = WASM_VECTOR_LEN;
661
+ wasm.unsealFromUser(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
662
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
663
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
664
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
665
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
666
+ var ptr5 = r0;
667
+ var len5 = r1;
668
+ if (r3) {
669
+ ptr5 = 0; len5 = 0;
670
+ throw takeObject(r2);
671
+ }
672
+ deferred6_0 = ptr5;
673
+ deferred6_1 = len5;
674
+ return getStringFromWasm0(ptr5, len5);
675
+ } finally {
676
+ wasm.__wbindgen_add_to_stack_pointer(16);
677
+ wasm.__wbindgen_export4(deferred6_0, deferred6_1, 1);
678
+ }
679
+ }
680
+ function __wbg_get_imports() {
681
+ const import0 = {
682
+ __proto__: null,
683
+ __wbg___wbindgen_debug_string_0accd80f45e5faa2: function(arg0, arg1) {
684
+ const ret = debugString(getObject(arg1));
685
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
686
+ const len1 = WASM_VECTOR_LEN;
687
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
688
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
689
+ },
690
+ __wbg___wbindgen_is_function_754e9f305ff6029e: function(arg0) {
691
+ const ret = typeof(getObject(arg0)) === 'function';
692
+ return ret;
693
+ },
694
+ __wbg___wbindgen_is_object_56732c2bc353f41d: function(arg0) {
695
+ const val = getObject(arg0);
696
+ const ret = typeof(val) === 'object' && val !== null;
697
+ return ret;
698
+ },
699
+ __wbg___wbindgen_is_string_c236cabd84a4d769: function(arg0) {
700
+ const ret = typeof(getObject(arg0)) === 'string';
701
+ return ret;
702
+ },
703
+ __wbg___wbindgen_is_undefined_67b456be8673d3d7: function(arg0) {
704
+ const ret = getObject(arg0) === undefined;
705
+ return ret;
706
+ },
707
+ __wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
708
+ throw new Error(getStringFromWasm0(arg0, arg1));
709
+ },
710
+ __wbg_call_9c758de292015997: function() { return handleError(function (arg0, arg1, arg2) {
711
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
712
+ return addHeapObject(ret);
713
+ }, arguments); },
714
+ __wbg_crypto_38df2bab126b63dc: function(arg0) {
715
+ const ret = getObject(arg0).crypto;
716
+ return addHeapObject(ret);
717
+ },
718
+ __wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) {
719
+ getObject(arg0).getRandomValues(getObject(arg1));
720
+ }, arguments); },
721
+ __wbg_length_4a591ecaa01354d9: function(arg0) {
722
+ const ret = getObject(arg0).length;
723
+ return ret;
724
+ },
725
+ __wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
726
+ const ret = getObject(arg0).msCrypto;
727
+ return addHeapObject(ret);
728
+ },
729
+ __wbg_new_ce1ab61c1c2b300d: function() {
730
+ const ret = new Object();
731
+ return addHeapObject(ret);
732
+ },
733
+ __wbg_new_with_length_36a4998e27b014c5: function(arg0) {
734
+ const ret = new Uint8Array(arg0 >>> 0);
735
+ return addHeapObject(ret);
736
+ },
737
+ __wbg_node_84ea875411254db1: function(arg0) {
738
+ const ret = getObject(arg0).node;
739
+ return addHeapObject(ret);
740
+ },
741
+ __wbg_process_44c7a14e11e9f69e: function(arg0) {
742
+ const ret = getObject(arg0).process;
743
+ return addHeapObject(ret);
744
+ },
745
+ __wbg_prototypesetcall_3249fc62a0fafa30: function(arg0, arg1, arg2) {
746
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
747
+ },
748
+ __wbg_randomFillSync_6c25eac9869eb53c: function() { return handleError(function (arg0, arg1) {
749
+ getObject(arg0).randomFillSync(takeObject(arg1));
750
+ }, arguments); },
751
+ __wbg_require_b4edbdcf3e2a1ef0: function() { return handleError(function () {
752
+ const ret = module.require;
753
+ return addHeapObject(ret);
754
+ }, arguments); },
755
+ __wbg_set_6e30c9374c26414c: function() { return handleError(function (arg0, arg1, arg2) {
756
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
757
+ return ret;
758
+ }, arguments); },
759
+ __wbg_static_accessor_GLOBAL_9d53f2689e622ca1: function() {
760
+ const ret = typeof global === 'undefined' ? null : global;
761
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
762
+ },
763
+ __wbg_static_accessor_GLOBAL_THIS_a1a35cec07001a8a: function() {
764
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
765
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
766
+ },
767
+ __wbg_static_accessor_SELF_4c59f6c7ea29a144: function() {
768
+ const ret = typeof self === 'undefined' ? null : self;
769
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
770
+ },
771
+ __wbg_static_accessor_WINDOW_e70ae9f2eb052253: function() {
772
+ const ret = typeof window === 'undefined' ? null : window;
773
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
774
+ },
775
+ __wbg_subarray_4aa221f6a4f5ab22: function(arg0, arg1, arg2) {
776
+ const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
777
+ return addHeapObject(ret);
778
+ },
779
+ __wbg_versions_276b2795b1c6a219: function(arg0) {
780
+ const ret = getObject(arg0).versions;
781
+ return addHeapObject(ret);
782
+ },
783
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
784
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
785
+ const ret = getArrayU8FromWasm0(arg0, arg1);
786
+ return addHeapObject(ret);
787
+ },
788
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
789
+ // Cast intrinsic for `Ref(String) -> Externref`.
790
+ const ret = getStringFromWasm0(arg0, arg1);
791
+ return addHeapObject(ret);
792
+ },
793
+ __wbindgen_object_clone_ref: function(arg0) {
794
+ const ret = getObject(arg0);
795
+ return addHeapObject(ret);
796
+ },
797
+ __wbindgen_object_drop_ref: function(arg0) {
798
+ takeObject(arg0);
799
+ },
800
+ };
801
+ return {
802
+ __proto__: null,
803
+ "./metamorphic_crypto_bg.js": import0,
804
+ };
805
+ }
806
+
807
+ function addHeapObject(obj) {
808
+ if (heap_next === heap.length) heap.push(heap.length + 1);
809
+ const idx = heap_next;
810
+ heap_next = heap[idx];
811
+
812
+ heap[idx] = obj;
813
+ return idx;
814
+ }
815
+
816
+ function debugString(val) {
817
+ // primitive types
818
+ const type = typeof val;
819
+ if (type == 'number' || type == 'boolean' || val == null) {
820
+ return `${val}`;
821
+ }
822
+ if (type == 'string') {
823
+ return `"${val}"`;
824
+ }
825
+ if (type == 'symbol') {
826
+ const description = val.description;
827
+ if (description == null) {
828
+ return 'Symbol';
829
+ } else {
830
+ return `Symbol(${description})`;
831
+ }
832
+ }
833
+ if (type == 'function') {
834
+ const name = val.name;
835
+ if (typeof name == 'string' && name.length > 0) {
836
+ return `Function(${name})`;
837
+ } else {
838
+ return 'Function';
839
+ }
840
+ }
841
+ // objects
842
+ if (Array.isArray(val)) {
843
+ const length = val.length;
844
+ let debug = '[';
845
+ if (length > 0) {
846
+ debug += debugString(val[0]);
847
+ }
848
+ for(let i = 1; i < length; i++) {
849
+ debug += ', ' + debugString(val[i]);
850
+ }
851
+ debug += ']';
852
+ return debug;
853
+ }
854
+ // Test for built-in
855
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
856
+ let className;
857
+ if (builtInMatches && builtInMatches.length > 1) {
858
+ className = builtInMatches[1];
859
+ } else {
860
+ // Failed to match the standard '[object ClassName]'
861
+ return toString.call(val);
862
+ }
863
+ if (className == 'Object') {
864
+ // we're a user defined class or Object
865
+ // JSON.stringify avoids problems with cycles, and is generally much
866
+ // easier than looping through ownProperties of `val`.
867
+ try {
868
+ return 'Object(' + JSON.stringify(val) + ')';
869
+ } catch (_) {
870
+ return 'Object';
871
+ }
872
+ }
873
+ // errors
874
+ if (val instanceof Error) {
875
+ return `${val.name}: ${val.message}\n${val.stack}`;
876
+ }
877
+ // TODO we could test for more things here, like `Set`s and `Map`s.
878
+ return className;
879
+ }
880
+
881
+ function dropObject(idx) {
882
+ if (idx < 1028) return;
883
+ heap[idx] = heap_next;
884
+ heap_next = idx;
885
+ }
886
+
887
+ function getArrayU8FromWasm0(ptr, len) {
888
+ ptr = ptr >>> 0;
889
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
890
+ }
891
+
892
+ let cachedDataViewMemory0 = null;
893
+ function getDataViewMemory0() {
894
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
895
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
896
+ }
897
+ return cachedDataViewMemory0;
898
+ }
899
+
900
+ function getStringFromWasm0(ptr, len) {
901
+ return decodeText(ptr >>> 0, len);
902
+ }
903
+
904
+ let cachedUint8ArrayMemory0 = null;
905
+ function getUint8ArrayMemory0() {
906
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
907
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
908
+ }
909
+ return cachedUint8ArrayMemory0;
910
+ }
911
+
912
+ function getObject(idx) { return heap[idx]; }
913
+
914
+ function handleError(f, args) {
915
+ try {
916
+ return f.apply(this, args);
917
+ } catch (e) {
918
+ wasm.__wbindgen_export3(addHeapObject(e));
919
+ }
920
+ }
921
+
922
+ let heap = new Array(1024).fill(undefined);
923
+ heap.push(undefined, null, true, false);
924
+
925
+ let heap_next = heap.length;
926
+
927
+ function isLikeNone(x) {
928
+ return x === undefined || x === null;
929
+ }
930
+
931
+ function passStringToWasm0(arg, malloc, realloc) {
932
+ if (realloc === undefined) {
933
+ const buf = cachedTextEncoder.encode(arg);
934
+ const ptr = malloc(buf.length, 1) >>> 0;
935
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
936
+ WASM_VECTOR_LEN = buf.length;
937
+ return ptr;
938
+ }
939
+
940
+ let len = arg.length;
941
+ let ptr = malloc(len, 1) >>> 0;
942
+
943
+ const mem = getUint8ArrayMemory0();
944
+
945
+ let offset = 0;
946
+
947
+ for (; offset < len; offset++) {
948
+ const code = arg.charCodeAt(offset);
949
+ if (code > 0x7F) break;
950
+ mem[ptr + offset] = code;
951
+ }
952
+ if (offset !== len) {
953
+ if (offset !== 0) {
954
+ arg = arg.slice(offset);
955
+ }
956
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
957
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
958
+ const ret = cachedTextEncoder.encodeInto(arg, view);
959
+
960
+ offset += ret.written;
961
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
962
+ }
963
+
964
+ WASM_VECTOR_LEN = offset;
965
+ return ptr;
966
+ }
967
+
968
+ function takeObject(idx) {
969
+ const ret = getObject(idx);
970
+ dropObject(idx);
971
+ return ret;
972
+ }
973
+
974
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
975
+ cachedTextDecoder.decode();
976
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
977
+ let numBytesDecoded = 0;
978
+ function decodeText(ptr, len) {
979
+ numBytesDecoded += len;
980
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
981
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
982
+ cachedTextDecoder.decode();
983
+ numBytesDecoded = len;
984
+ }
985
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
986
+ }
987
+
988
+ const cachedTextEncoder = new TextEncoder();
989
+
990
+ if (!('encodeInto' in cachedTextEncoder)) {
991
+ cachedTextEncoder.encodeInto = function (arg, view) {
992
+ const buf = cachedTextEncoder.encode(arg);
993
+ view.set(buf);
994
+ return {
995
+ read: arg.length,
996
+ written: buf.length
997
+ };
998
+ };
999
+ }
1000
+
1001
+ let WASM_VECTOR_LEN = 0;
1002
+
1003
+ let wasmModule, wasmInstance, wasm;
1004
+ function __wbg_finalize_init(instance, module) {
1005
+ wasmInstance = instance;
1006
+ wasm = instance.exports;
1007
+ wasmModule = module;
1008
+ cachedDataViewMemory0 = null;
1009
+ cachedUint8ArrayMemory0 = null;
1010
+ return wasm;
1011
+ }
1012
+
1013
+ async function __wbg_load(module, imports) {
1014
+ if (typeof Response === 'function' && module instanceof Response) {
1015
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
1016
+ try {
1017
+ return await WebAssembly.instantiateStreaming(module, imports);
1018
+ } catch (e) {
1019
+ const validResponse = module.ok && expectedResponseType(module.type);
1020
+
1021
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
1022
+ 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);
1023
+
1024
+ } else { throw e; }
1025
+ }
1026
+ }
1027
+
1028
+ const bytes = await module.arrayBuffer();
1029
+ return await WebAssembly.instantiate(bytes, imports);
1030
+ } else {
1031
+ const instance = await WebAssembly.instantiate(module, imports);
1032
+
1033
+ if (instance instanceof WebAssembly.Instance) {
1034
+ return { instance, module };
1035
+ } else {
1036
+ return instance;
1037
+ }
1038
+ }
1039
+
1040
+ function expectedResponseType(type) {
1041
+ switch (type) {
1042
+ case 'basic': case 'cors': case 'default': return true;
1043
+ }
1044
+ return false;
1045
+ }
1046
+ }
1047
+
1048
+ function initSync(module) {
1049
+ if (wasm !== undefined) return wasm;
1050
+
1051
+
1052
+ if (module !== undefined) {
1053
+ if (Object.getPrototypeOf(module) === Object.prototype) {
1054
+ ({module} = module)
1055
+ } else {
1056
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
1057
+ }
1058
+ }
1059
+
1060
+ const imports = __wbg_get_imports();
1061
+ if (!(module instanceof WebAssembly.Module)) {
1062
+ module = new WebAssembly.Module(module);
1063
+ }
1064
+ const instance = new WebAssembly.Instance(module, imports);
1065
+ return __wbg_finalize_init(instance, module);
1066
+ }
1067
+
1068
+ async function __wbg_init(module_or_path) {
1069
+ if (wasm !== undefined) return wasm;
1070
+
1071
+
1072
+ if (module_or_path !== undefined) {
1073
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1074
+ ({module_or_path} = module_or_path)
1075
+ } else {
1076
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1077
+ }
1078
+ }
1079
+
1080
+ if (module_or_path === undefined) {
1081
+ module_or_path = new URL('metamorphic_crypto_bg.wasm', import.meta.url);
1082
+ }
1083
+ const imports = __wbg_get_imports();
1084
+
1085
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1086
+ module_or_path = fetch(module_or_path);
1087
+ }
1088
+
1089
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1090
+
1091
+ return __wbg_finalize_init(instance, module);
1092
+ }
1093
+
1094
+ export { initSync, __wbg_init as default };