@enclave-technologies/pqc-primitives 0.1.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.
- package/LICENSE +202 -0
- package/README.md +173 -0
- package/dist/bundler/constants.js +63 -0
- package/dist/bundler/enclave_pqc_primitives_wasm.d.ts +218 -0
- package/dist/bundler/enclave_pqc_primitives_wasm.js +9 -0
- package/dist/bundler/enclave_pqc_primitives_wasm_bg.js +838 -0
- package/dist/bundler/enclave_pqc_primitives_wasm_bg.wasm +0 -0
- package/dist/bundler/enclave_pqc_primitives_wasm_bg.wasm.d.ts +41 -0
- package/dist/bundler/index.d.ts +157 -0
- package/dist/bundler/index.js +80 -0
- package/dist/nodejs/constants.js +63 -0
- package/dist/nodejs/enclave_pqc_primitives_wasm.cjs +873 -0
- package/dist/nodejs/enclave_pqc_primitives_wasm.d.ts +218 -0
- package/dist/nodejs/enclave_pqc_primitives_wasm_bg.wasm +0 -0
- package/dist/nodejs/enclave_pqc_primitives_wasm_bg.wasm.d.ts +41 -0
- package/dist/nodejs/index.d.ts +157 -0
- package/dist/nodejs/index.js +54 -0
- package/dist/web/constants.js +63 -0
- package/dist/web/enclave_pqc_primitives_wasm.d.ts +284 -0
- package/dist/web/enclave_pqc_primitives_wasm.js +938 -0
- package/dist/web/enclave_pqc_primitives_wasm_bg.wasm +0 -0
- package/dist/web/enclave_pqc_primitives_wasm_bg.wasm.d.ts +41 -0
- package/dist/web/index.d.ts +157 -0
- package/dist/web/index.js +101 -0
- package/package.json +65 -0
|
@@ -0,0 +1,938 @@
|
|
|
1
|
+
/* @ts-self-types="./enclave_pqc_primitives_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Canonical suite identifier matching the Rust crate (Category 5 algorithms).
|
|
5
|
+
* @returns {string}
|
|
6
|
+
*/
|
|
7
|
+
export function ENCLAVE_PQ_SUITE_ID() {
|
|
8
|
+
let deferred1_0;
|
|
9
|
+
let deferred1_1;
|
|
10
|
+
try {
|
|
11
|
+
const ret = wasm.ENCLAVE_PQ_SUITE_ID();
|
|
12
|
+
deferred1_0 = ret[0];
|
|
13
|
+
deferred1_1 = ret[1];
|
|
14
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
15
|
+
} finally {
|
|
16
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Domain-separation prefix for the Enclave labeled KDF.
|
|
22
|
+
* @returns {string}
|
|
23
|
+
*/
|
|
24
|
+
export function KDF_LABEL_PREFIX() {
|
|
25
|
+
let deferred1_0;
|
|
26
|
+
let deferred1_1;
|
|
27
|
+
try {
|
|
28
|
+
const ret = wasm.KDF_LABEL_PREFIX();
|
|
29
|
+
deferred1_0 = ret[0];
|
|
30
|
+
deferred1_1 = ret[1];
|
|
31
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
32
|
+
} finally {
|
|
33
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Algorithm identifier (`"Argon2id"`).
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
export function PWHASH_ALGORITHM() {
|
|
42
|
+
let deferred1_0;
|
|
43
|
+
let deferred1_1;
|
|
44
|
+
try {
|
|
45
|
+
const ret = wasm.PWHASH_ALGORITHM();
|
|
46
|
+
deferred1_0 = ret[0];
|
|
47
|
+
deferred1_1 = ret[1];
|
|
48
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
49
|
+
} finally {
|
|
50
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Derived key length in bytes (matches AES-256-GCM key size).
|
|
56
|
+
* @returns {number}
|
|
57
|
+
*/
|
|
58
|
+
export function PWHASH_OUTPUT_BYTES() {
|
|
59
|
+
const ret = wasm.PWHASH_OUTPUT_BYTES();
|
|
60
|
+
return ret >>> 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Salt length in bytes produced by [`generate_salt`].
|
|
65
|
+
* @returns {number}
|
|
66
|
+
*/
|
|
67
|
+
export function PWHASH_SALT_BYTES() {
|
|
68
|
+
const ret = wasm.PWHASH_SALT_BYTES();
|
|
69
|
+
return ret >>> 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* OWASP baseline Argon2id params: `{ memoryCostKib, iterations, parallelism }`.
|
|
74
|
+
*
|
|
75
|
+
* Sourced from the OWASP Password Storage Cheat Sheet (19 MiB / t=2 / p=1).
|
|
76
|
+
* Slow and memory-hard by design — lowering these for login latency is a
|
|
77
|
+
* security tradeoff, not a free optimization.
|
|
78
|
+
* @returns {any}
|
|
79
|
+
*/
|
|
80
|
+
export function RECOMMENDED_PARAMS() {
|
|
81
|
+
const ret = wasm.RECOMMENDED_PARAMS();
|
|
82
|
+
if (ret[2]) {
|
|
83
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
84
|
+
}
|
|
85
|
+
return takeFromExternrefTable0(ret[0]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Decrypt AES-256-GCM ciphertext (including trailing tag).
|
|
90
|
+
*
|
|
91
|
+
* Throws on authentication failure (`AeadFailure: ...`).
|
|
92
|
+
* @param {Uint8Array} key
|
|
93
|
+
* @param {Uint8Array} nonce
|
|
94
|
+
* @param {Uint8Array} ciphertext
|
|
95
|
+
* @param {Uint8Array} aad
|
|
96
|
+
* @returns {Uint8Array}
|
|
97
|
+
*/
|
|
98
|
+
export function aeadDecrypt(key, nonce, ciphertext, aad) {
|
|
99
|
+
const ptr0 = passArray8ToWasm0(key, wasm.__wbindgen_malloc);
|
|
100
|
+
const len0 = WASM_VECTOR_LEN;
|
|
101
|
+
const ptr1 = passArray8ToWasm0(nonce, wasm.__wbindgen_malloc);
|
|
102
|
+
const len1 = WASM_VECTOR_LEN;
|
|
103
|
+
const ptr2 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
|
|
104
|
+
const len2 = WASM_VECTOR_LEN;
|
|
105
|
+
const ptr3 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
|
|
106
|
+
const len3 = WASM_VECTOR_LEN;
|
|
107
|
+
const ret = wasm.aeadDecrypt(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
108
|
+
if (ret[3]) {
|
|
109
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
110
|
+
}
|
|
111
|
+
var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
112
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
113
|
+
return v5;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Encrypt with AES-256-GCM under an explicit key and nonce.
|
|
118
|
+
*
|
|
119
|
+
* Returns `ciphertext || tag` (16-byte tag suffix). Callers must ensure
|
|
120
|
+
* `(key, nonce)` uniqueness.
|
|
121
|
+
* @param {Uint8Array} key
|
|
122
|
+
* @param {Uint8Array} nonce
|
|
123
|
+
* @param {Uint8Array} plaintext
|
|
124
|
+
* @param {Uint8Array} aad
|
|
125
|
+
* @returns {Uint8Array}
|
|
126
|
+
*/
|
|
127
|
+
export function aeadEncrypt(key, nonce, plaintext, aad) {
|
|
128
|
+
const ptr0 = passArray8ToWasm0(key, wasm.__wbindgen_malloc);
|
|
129
|
+
const len0 = WASM_VECTOR_LEN;
|
|
130
|
+
const ptr1 = passArray8ToWasm0(nonce, wasm.__wbindgen_malloc);
|
|
131
|
+
const len1 = WASM_VECTOR_LEN;
|
|
132
|
+
const ptr2 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
|
|
133
|
+
const len2 = WASM_VECTOR_LEN;
|
|
134
|
+
const ptr3 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
|
|
135
|
+
const len3 = WASM_VECTOR_LEN;
|
|
136
|
+
const ret = wasm.aeadEncrypt(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
137
|
+
if (ret[3]) {
|
|
138
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
139
|
+
}
|
|
140
|
+
var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
141
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
142
|
+
return v5;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Cryptographically random 16-byte salt for Argon2id.
|
|
147
|
+
* @returns {Uint8Array}
|
|
148
|
+
*/
|
|
149
|
+
export function generateSalt() {
|
|
150
|
+
const ret = wasm.generateSalt();
|
|
151
|
+
if (ret[3]) {
|
|
152
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
153
|
+
}
|
|
154
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
155
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
156
|
+
return v1;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Return the [`CryptoUsageRecord`] from the last WASM primitive call.
|
|
161
|
+
*
|
|
162
|
+
* Shape: `{ algorithm, suiteId, operation, crateVersion }`.
|
|
163
|
+
* Returns `undefined` if no operation has run yet in this WASM instance.
|
|
164
|
+
*
|
|
165
|
+
* This is the CBOM attach point for product layers (Encrypt, etc.). This
|
|
166
|
+
* binding does not persist or transmit the record.
|
|
167
|
+
* @returns {any}
|
|
168
|
+
*/
|
|
169
|
+
export function getLastUsageRecord() {
|
|
170
|
+
const ret = wasm.getLastUsageRecord();
|
|
171
|
+
if (ret[2]) {
|
|
172
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
173
|
+
}
|
|
174
|
+
return takeFromExternrefTable0(ret[0]);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* SHAKE256 over UTF-8 string bytes.
|
|
179
|
+
* @param {string} value
|
|
180
|
+
* @param {number} output_len
|
|
181
|
+
* @returns {Uint8Array}
|
|
182
|
+
*/
|
|
183
|
+
export function hashUtf8(value, output_len) {
|
|
184
|
+
const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
185
|
+
const len0 = WASM_VECTOR_LEN;
|
|
186
|
+
const ret = wasm.hashUtf8(ptr0, len0, output_len);
|
|
187
|
+
if (ret[3]) {
|
|
188
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
189
|
+
}
|
|
190
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
191
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
192
|
+
return v2;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Decapsulate an ML-KEM-1024 ciphertext.
|
|
197
|
+
*
|
|
198
|
+
* `secret_key` may be a 64-byte seed or a 3168-byte expanded key.
|
|
199
|
+
* @param {Uint8Array} ciphertext
|
|
200
|
+
* @param {Uint8Array} secret_key
|
|
201
|
+
* @returns {Uint8Array}
|
|
202
|
+
*/
|
|
203
|
+
export function kemDecapsulate(ciphertext, secret_key) {
|
|
204
|
+
const ptr0 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
|
|
205
|
+
const len0 = WASM_VECTOR_LEN;
|
|
206
|
+
const ptr1 = passArray8ToWasm0(secret_key, wasm.__wbindgen_malloc);
|
|
207
|
+
const len1 = WASM_VECTOR_LEN;
|
|
208
|
+
const ret = wasm.kemDecapsulate(ptr0, len0, ptr1, len1);
|
|
209
|
+
if (ret[3]) {
|
|
210
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
211
|
+
}
|
|
212
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
213
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
214
|
+
return v3;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Encapsulate a shared secret to an ML-KEM-1024 public key.
|
|
219
|
+
*
|
|
220
|
+
* Returns `{ ciphertext, sharedSecret }` (1568 / 32 bytes).
|
|
221
|
+
* @param {Uint8Array} public_key
|
|
222
|
+
* @returns {any}
|
|
223
|
+
*/
|
|
224
|
+
export function kemEncapsulate(public_key) {
|
|
225
|
+
const ptr0 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
|
|
226
|
+
const len0 = WASM_VECTOR_LEN;
|
|
227
|
+
const ret = wasm.kemEncapsulate(ptr0, len0);
|
|
228
|
+
if (ret[2]) {
|
|
229
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
230
|
+
}
|
|
231
|
+
return takeFromExternrefTable0(ret[0]);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Deterministic encapsulation for known-answer / KAT compliance.
|
|
236
|
+
*
|
|
237
|
+
* # Hazmat
|
|
238
|
+
*
|
|
239
|
+
* **KATs only.** Production code must call [`kem_encapsulate`].
|
|
240
|
+
* @param {Uint8Array} public_key
|
|
241
|
+
* @param {Uint8Array} m
|
|
242
|
+
* @returns {any}
|
|
243
|
+
*/
|
|
244
|
+
export function kemEncapsulateDeterministic(public_key, m) {
|
|
245
|
+
const ptr0 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
|
|
246
|
+
const len0 = WASM_VECTOR_LEN;
|
|
247
|
+
const ptr1 = passArray8ToWasm0(m, wasm.__wbindgen_malloc);
|
|
248
|
+
const len1 = WASM_VECTOR_LEN;
|
|
249
|
+
const ret = wasm.kemEncapsulateDeterministic(ptr0, len0, ptr1, len1);
|
|
250
|
+
if (ret[2]) {
|
|
251
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
252
|
+
}
|
|
253
|
+
return takeFromExternrefTable0(ret[0]);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Expand a 64-byte seed-form secret key to the FIPS expanded encoding
|
|
258
|
+
* ([`kem::SECRET_KEY_BYTES`] bytes).
|
|
259
|
+
* @param {Uint8Array} secret_key
|
|
260
|
+
* @returns {Uint8Array}
|
|
261
|
+
*/
|
|
262
|
+
export function kemExpandedSecretKey(secret_key) {
|
|
263
|
+
const ptr0 = passArray8ToWasm0(secret_key, wasm.__wbindgen_malloc);
|
|
264
|
+
const len0 = WASM_VECTOR_LEN;
|
|
265
|
+
const ret = wasm.kemExpandedSecretKey(ptr0, len0);
|
|
266
|
+
if (ret[3]) {
|
|
267
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
268
|
+
}
|
|
269
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
270
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
271
|
+
return v2;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Generate a fresh ML-KEM-1024 keypair (includes PCT).
|
|
276
|
+
*
|
|
277
|
+
* Returns `{ publicKey, secretKey }` where `secretKey` is the preferred
|
|
278
|
+
* seed form ([`kem::SECRET_KEY_SEED_BYTES`] = 64). Expanded size is
|
|
279
|
+
* [`kem::SECRET_KEY_BYTES`] = 3168 — use [`kem_expanded_secret_key`].
|
|
280
|
+
*
|
|
281
|
+
* Throws `PairwiseConsistencyFailureError` if the PCT fails.
|
|
282
|
+
* @returns {any}
|
|
283
|
+
*/
|
|
284
|
+
export function kemGenerateKeypair() {
|
|
285
|
+
const ret = wasm.kemGenerateKeypair();
|
|
286
|
+
if (ret[2]) {
|
|
287
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
288
|
+
}
|
|
289
|
+
return takeFromExternrefTable0(ret[0]);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Derive an ML-KEM-1024 keypair from a 64-byte seed (`d || z`). Includes PCT.
|
|
294
|
+
* @param {Uint8Array} seed
|
|
295
|
+
* @returns {any}
|
|
296
|
+
*/
|
|
297
|
+
export function kemKeypairFromSeed(seed) {
|
|
298
|
+
const ptr0 = passArray8ToWasm0(seed, wasm.__wbindgen_malloc);
|
|
299
|
+
const len0 = WASM_VECTOR_LEN;
|
|
300
|
+
const ret = wasm.kemKeypairFromSeed(ptr0, len0);
|
|
301
|
+
if (ret[2]) {
|
|
302
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
303
|
+
}
|
|
304
|
+
return takeFromExternrefTable0(ret[0]);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Derive key material with `enclave-kdf-v1` labeled SHAKE256.
|
|
309
|
+
*
|
|
310
|
+
* Throws `InvalidParameter` on empty `label` or `length == 0`.
|
|
311
|
+
* @param {string} label
|
|
312
|
+
* @param {Uint8Array} ikm
|
|
313
|
+
* @param {number} length
|
|
314
|
+
* @returns {Uint8Array}
|
|
315
|
+
*/
|
|
316
|
+
export function labeledKdf(label, ikm, length) {
|
|
317
|
+
const ptr0 = passStringToWasm0(label, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
318
|
+
const len0 = WASM_VECTOR_LEN;
|
|
319
|
+
const ptr1 = passArray8ToWasm0(ikm, wasm.__wbindgen_malloc);
|
|
320
|
+
const len1 = WASM_VECTOR_LEN;
|
|
321
|
+
const ret = wasm.labeledKdf(ptr0, len0, ptr1, len1, length);
|
|
322
|
+
if (ret[3]) {
|
|
323
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
324
|
+
}
|
|
325
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
326
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
327
|
+
return v3;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* [`labeled_kdf`] with a 32-byte output.
|
|
332
|
+
* @param {string} label
|
|
333
|
+
* @param {Uint8Array} ikm
|
|
334
|
+
* @returns {Uint8Array}
|
|
335
|
+
*/
|
|
336
|
+
export function labeledKdf32(label, ikm) {
|
|
337
|
+
const ptr0 = passStringToWasm0(label, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
338
|
+
const len0 = WASM_VECTOR_LEN;
|
|
339
|
+
const ptr1 = passArray8ToWasm0(ikm, wasm.__wbindgen_malloc);
|
|
340
|
+
const len1 = WASM_VECTOR_LEN;
|
|
341
|
+
const ret = wasm.labeledKdf32(ptr0, len0, ptr1, len1);
|
|
342
|
+
if (ret[3]) {
|
|
343
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
344
|
+
}
|
|
345
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
346
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
347
|
+
return v3;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Derive a 32-byte key from a password + salt with Argon2id.
|
|
352
|
+
*
|
|
353
|
+
* `params` must be `{ memoryCostKib, iterations, parallelism }` (see
|
|
354
|
+
* [`recommended_params`]). Throws on empty password / wrong salt length /
|
|
355
|
+
* invalid costs.
|
|
356
|
+
*
|
|
357
|
+
* This call is intentionally slow (~tens–hundreds of ms depending on host).
|
|
358
|
+
* That cost is the offline brute-force defense — do not lower params casually.
|
|
359
|
+
* @param {Uint8Array} password
|
|
360
|
+
* @param {Uint8Array} salt
|
|
361
|
+
* @param {any} params
|
|
362
|
+
* @returns {Uint8Array}
|
|
363
|
+
*/
|
|
364
|
+
export function pwhashDeriveKey(password, salt, params) {
|
|
365
|
+
const ptr0 = passArray8ToWasm0(password, wasm.__wbindgen_malloc);
|
|
366
|
+
const len0 = WASM_VECTOR_LEN;
|
|
367
|
+
const ptr1 = passArray8ToWasm0(salt, wasm.__wbindgen_malloc);
|
|
368
|
+
const len1 = WASM_VECTOR_LEN;
|
|
369
|
+
const ret = wasm.pwhashDeriveKey(ptr0, len0, ptr1, len1, params);
|
|
370
|
+
if (ret[3]) {
|
|
371
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
372
|
+
}
|
|
373
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
374
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
375
|
+
return v3;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Run known-answer CASTs for ML-KEM-1024, ML-DSA-87, and Argon2id.
|
|
380
|
+
*
|
|
381
|
+
* Throws `SelfTestFailureError` if any CAST fails. Pair-wise consistency is
|
|
382
|
+
* already enforced inside key generation — this is the power-on / module-entry
|
|
383
|
+
* known-answer path. The Argon2id CAST is slower (memory-hard by design).
|
|
384
|
+
*/
|
|
385
|
+
export function runSelfTests() {
|
|
386
|
+
const ret = wasm.runSelfTests();
|
|
387
|
+
if (ret[1]) {
|
|
388
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* One-shot SHAKE256 hash of `input` into `output_len` bytes.
|
|
394
|
+
* @param {Uint8Array} input
|
|
395
|
+
* @param {number} output_len
|
|
396
|
+
* @returns {Uint8Array}
|
|
397
|
+
*/
|
|
398
|
+
export function shake256(input, output_len) {
|
|
399
|
+
const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
|
|
400
|
+
const len0 = WASM_VECTOR_LEN;
|
|
401
|
+
const ret = wasm.shake256(ptr0, len0, output_len);
|
|
402
|
+
if (ret[3]) {
|
|
403
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
404
|
+
}
|
|
405
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
406
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
407
|
+
return v2;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Expand a 32-byte seed-form secret key to the FIPS expanded encoding
|
|
412
|
+
* ([`sig::SECRET_KEY_BYTES`] bytes).
|
|
413
|
+
* @param {Uint8Array} secret_key
|
|
414
|
+
* @returns {Uint8Array}
|
|
415
|
+
*/
|
|
416
|
+
export function sigExpandedSecretKey(secret_key) {
|
|
417
|
+
const ptr0 = passArray8ToWasm0(secret_key, wasm.__wbindgen_malloc);
|
|
418
|
+
const len0 = WASM_VECTOR_LEN;
|
|
419
|
+
const ret = wasm.sigExpandedSecretKey(ptr0, len0);
|
|
420
|
+
if (ret[3]) {
|
|
421
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
422
|
+
}
|
|
423
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
424
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
425
|
+
return v2;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Generate a fresh ML-DSA-87 keypair (includes PCT).
|
|
430
|
+
*
|
|
431
|
+
* Returns `{ publicKey, secretKey }` where `secretKey` is the preferred
|
|
432
|
+
* seed form ([`sig::SECRET_KEY_SEED_BYTES`] = 32). Expanded size is
|
|
433
|
+
* [`sig::SECRET_KEY_BYTES`] = 4896.
|
|
434
|
+
*
|
|
435
|
+
* Throws `PairwiseConsistencyFailureError` if the PCT fails.
|
|
436
|
+
* @returns {any}
|
|
437
|
+
*/
|
|
438
|
+
export function sigGenerateKeypair() {
|
|
439
|
+
const ret = wasm.sigGenerateKeypair();
|
|
440
|
+
if (ret[2]) {
|
|
441
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
442
|
+
}
|
|
443
|
+
return takeFromExternrefTable0(ret[0]);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Derive an ML-DSA-87 keypair from a 32-byte seed. Includes PCT.
|
|
448
|
+
* @param {Uint8Array} seed
|
|
449
|
+
* @returns {any}
|
|
450
|
+
*/
|
|
451
|
+
export function sigKeypairFromSeed(seed) {
|
|
452
|
+
const ptr0 = passArray8ToWasm0(seed, wasm.__wbindgen_malloc);
|
|
453
|
+
const len0 = WASM_VECTOR_LEN;
|
|
454
|
+
const ret = wasm.sigKeypairFromSeed(ptr0, len0);
|
|
455
|
+
if (ret[2]) {
|
|
456
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
457
|
+
}
|
|
458
|
+
return takeFromExternrefTable0(ret[0]);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Sign a message with empty context (deterministic ML-DSA-87).
|
|
463
|
+
*
|
|
464
|
+
* Empty `message` throws `InvalidLength` (matches Rust).
|
|
465
|
+
* @param {Uint8Array} secret_key
|
|
466
|
+
* @param {Uint8Array} message
|
|
467
|
+
* @returns {Uint8Array}
|
|
468
|
+
*/
|
|
469
|
+
export function sigSign(secret_key, message) {
|
|
470
|
+
const ptr0 = passArray8ToWasm0(secret_key, wasm.__wbindgen_malloc);
|
|
471
|
+
const len0 = WASM_VECTOR_LEN;
|
|
472
|
+
const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
|
|
473
|
+
const len1 = WASM_VECTOR_LEN;
|
|
474
|
+
const ret = wasm.sigSign(ptr0, len0, ptr1, len1);
|
|
475
|
+
if (ret[3]) {
|
|
476
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
477
|
+
}
|
|
478
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
479
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
480
|
+
return v3;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Deterministic ML-DSA.Sign with an explicit context (`context.len() <= 255`).
|
|
485
|
+
*
|
|
486
|
+
* Empty `message` or `context.len() > 255` throws (matches Rust).
|
|
487
|
+
* @param {Uint8Array} secret_key
|
|
488
|
+
* @param {Uint8Array} message
|
|
489
|
+
* @param {Uint8Array} context
|
|
490
|
+
* @returns {Uint8Array}
|
|
491
|
+
*/
|
|
492
|
+
export function sigSignWithContext(secret_key, message, context) {
|
|
493
|
+
const ptr0 = passArray8ToWasm0(secret_key, wasm.__wbindgen_malloc);
|
|
494
|
+
const len0 = WASM_VECTOR_LEN;
|
|
495
|
+
const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
|
|
496
|
+
const len1 = WASM_VECTOR_LEN;
|
|
497
|
+
const ptr2 = passArray8ToWasm0(context, wasm.__wbindgen_malloc);
|
|
498
|
+
const len2 = WASM_VECTOR_LEN;
|
|
499
|
+
const ret = wasm.sigSignWithContext(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
500
|
+
if (ret[3]) {
|
|
501
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
502
|
+
}
|
|
503
|
+
var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
504
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
505
|
+
return v4;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Verify an ML-DSA-87 signature (empty context).
|
|
510
|
+
*
|
|
511
|
+
* Returns `false` on a cryptographically invalid signature. Throws only for
|
|
512
|
+
* malformed input lengths / encodings.
|
|
513
|
+
* @param {Uint8Array} public_key
|
|
514
|
+
* @param {Uint8Array} message
|
|
515
|
+
* @param {Uint8Array} signature
|
|
516
|
+
* @returns {boolean}
|
|
517
|
+
*/
|
|
518
|
+
export function sigVerify(public_key, message, signature) {
|
|
519
|
+
const ptr0 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
|
|
520
|
+
const len0 = WASM_VECTOR_LEN;
|
|
521
|
+
const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
|
|
522
|
+
const len1 = WASM_VECTOR_LEN;
|
|
523
|
+
const ptr2 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc);
|
|
524
|
+
const len2 = WASM_VECTOR_LEN;
|
|
525
|
+
const ret = wasm.sigVerify(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
526
|
+
if (ret[2]) {
|
|
527
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
528
|
+
}
|
|
529
|
+
return ret[0] !== 0;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Verify an ML-DSA-87 signature with an explicit context.
|
|
534
|
+
*
|
|
535
|
+
* Returns `false` on cryptographic failure; throws on malformed lengths.
|
|
536
|
+
* @param {Uint8Array} public_key
|
|
537
|
+
* @param {Uint8Array} message
|
|
538
|
+
* @param {Uint8Array} signature
|
|
539
|
+
* @param {Uint8Array} context
|
|
540
|
+
* @returns {boolean}
|
|
541
|
+
*/
|
|
542
|
+
export function sigVerifyWithContext(public_key, message, signature, context) {
|
|
543
|
+
const ptr0 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
|
|
544
|
+
const len0 = WASM_VECTOR_LEN;
|
|
545
|
+
const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
|
|
546
|
+
const len1 = WASM_VECTOR_LEN;
|
|
547
|
+
const ptr2 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc);
|
|
548
|
+
const len2 = WASM_VECTOR_LEN;
|
|
549
|
+
const ptr3 = passArray8ToWasm0(context, wasm.__wbindgen_malloc);
|
|
550
|
+
const len3 = WASM_VECTOR_LEN;
|
|
551
|
+
const ret = wasm.sigVerifyWithContext(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
552
|
+
if (ret[2]) {
|
|
553
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
554
|
+
}
|
|
555
|
+
return ret[0] !== 0;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Overwrite a JS `Uint8Array` in place with zeros.
|
|
560
|
+
*
|
|
561
|
+
* # Security note
|
|
562
|
+
*
|
|
563
|
+
* Rust-side secret keys are zeroized on `Drop`, but that guarantee **does not**
|
|
564
|
+
* cross the WASM boundary. Once secret material lives in a JS `Uint8Array`, the
|
|
565
|
+
* JS garbage collector will not zero it. Call this when you are finished with
|
|
566
|
+
* long-lived secret buffers.
|
|
567
|
+
* @param {Uint8Array} buf
|
|
568
|
+
*/
|
|
569
|
+
export function zeroize(buf) {
|
|
570
|
+
wasm.zeroize(buf);
|
|
571
|
+
}
|
|
572
|
+
function __wbg_get_imports() {
|
|
573
|
+
const import0 = {
|
|
574
|
+
__proto__: null,
|
|
575
|
+
__wbg___wbindgen_is_function_1ff95bcc5517c252: function(arg0) {
|
|
576
|
+
const ret = typeof(arg0) === 'function';
|
|
577
|
+
return ret;
|
|
578
|
+
},
|
|
579
|
+
__wbg___wbindgen_is_object_a27215656b807791: function(arg0) {
|
|
580
|
+
const val = arg0;
|
|
581
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
582
|
+
return ret;
|
|
583
|
+
},
|
|
584
|
+
__wbg___wbindgen_is_string_ea5e6cc2e4141dfe: function(arg0) {
|
|
585
|
+
const ret = typeof(arg0) === 'string';
|
|
586
|
+
return ret;
|
|
587
|
+
},
|
|
588
|
+
__wbg___wbindgen_is_undefined_c05833b95a3cf397: function(arg0) {
|
|
589
|
+
const ret = arg0 === undefined;
|
|
590
|
+
return ret;
|
|
591
|
+
},
|
|
592
|
+
__wbg___wbindgen_number_get_394265ed1e1b84ee: function(arg0, arg1) {
|
|
593
|
+
const obj = arg1;
|
|
594
|
+
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
595
|
+
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
596
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
597
|
+
},
|
|
598
|
+
__wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
|
|
599
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
600
|
+
},
|
|
601
|
+
__wbg_call_a6e5c5dce5018821: function() { return handleError(function (arg0, arg1, arg2) {
|
|
602
|
+
const ret = arg0.call(arg1, arg2);
|
|
603
|
+
return ret;
|
|
604
|
+
}, arguments); },
|
|
605
|
+
__wbg_crypto_38df2bab126b63dc: function(arg0) {
|
|
606
|
+
const ret = arg0.crypto;
|
|
607
|
+
return ret;
|
|
608
|
+
},
|
|
609
|
+
__wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) {
|
|
610
|
+
arg0.getRandomValues(arg1);
|
|
611
|
+
}, arguments); },
|
|
612
|
+
__wbg_getRandomValues_cc7f052a444bb2ce: function() { return handleError(function (arg0, arg1) {
|
|
613
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
614
|
+
}, arguments); },
|
|
615
|
+
__wbg_get_78f252d074a84d0b: function() { return handleError(function (arg0, arg1) {
|
|
616
|
+
const ret = Reflect.get(arg0, arg1);
|
|
617
|
+
return ret;
|
|
618
|
+
}, arguments); },
|
|
619
|
+
__wbg_length_1f0964f4a5e2c6d8: function(arg0) {
|
|
620
|
+
const ret = arg0.length;
|
|
621
|
+
return ret;
|
|
622
|
+
},
|
|
623
|
+
__wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
|
|
624
|
+
const ret = arg0.msCrypto;
|
|
625
|
+
return ret;
|
|
626
|
+
},
|
|
627
|
+
__wbg_new_b667d279fd5aa943: function(arg0, arg1) {
|
|
628
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
629
|
+
return ret;
|
|
630
|
+
},
|
|
631
|
+
__wbg_new_da52cf8fe3429cb2: function() {
|
|
632
|
+
const ret = new Object();
|
|
633
|
+
return ret;
|
|
634
|
+
},
|
|
635
|
+
__wbg_new_from_slice_77cdfb7977362f3c: function(arg0, arg1) {
|
|
636
|
+
const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
|
|
637
|
+
return ret;
|
|
638
|
+
},
|
|
639
|
+
__wbg_new_with_length_e6785c33c8e4cce8: function(arg0) {
|
|
640
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
641
|
+
return ret;
|
|
642
|
+
},
|
|
643
|
+
__wbg_node_84ea875411254db1: function(arg0) {
|
|
644
|
+
const ret = arg0.node;
|
|
645
|
+
return ret;
|
|
646
|
+
},
|
|
647
|
+
__wbg_process_44c7a14e11e9f69e: function(arg0) {
|
|
648
|
+
const ret = arg0.process;
|
|
649
|
+
return ret;
|
|
650
|
+
},
|
|
651
|
+
__wbg_prototypesetcall_4770620bbe4688a0: function(arg0, arg1, arg2) {
|
|
652
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
653
|
+
},
|
|
654
|
+
__wbg_randomFillSync_6c25eac9869eb53c: function() { return handleError(function (arg0, arg1) {
|
|
655
|
+
arg0.randomFillSync(arg1);
|
|
656
|
+
}, arguments); },
|
|
657
|
+
__wbg_require_b4edbdcf3e2a1ef0: function() { return handleError(function () {
|
|
658
|
+
const ret = module.require;
|
|
659
|
+
return ret;
|
|
660
|
+
}, arguments); },
|
|
661
|
+
__wbg_set_8535240470bf2500: function() { return handleError(function (arg0, arg1, arg2) {
|
|
662
|
+
const ret = Reflect.set(arg0, arg1, arg2);
|
|
663
|
+
return ret;
|
|
664
|
+
}, arguments); },
|
|
665
|
+
__wbg_set_index_0a2d916cd3658df4: function(arg0, arg1, arg2) {
|
|
666
|
+
arg0[arg1 >>> 0] = arg2;
|
|
667
|
+
},
|
|
668
|
+
__wbg_static_accessor_GLOBAL_4ef717fb391d88b7: function() {
|
|
669
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
670
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
671
|
+
},
|
|
672
|
+
__wbg_static_accessor_GLOBAL_THIS_8d1badc68b5a74f4: function() {
|
|
673
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
674
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
675
|
+
},
|
|
676
|
+
__wbg_static_accessor_SELF_146583524fe1469b: function() {
|
|
677
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
678
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
679
|
+
},
|
|
680
|
+
__wbg_static_accessor_WINDOW_f2829a2234d7819e: function() {
|
|
681
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
682
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
683
|
+
},
|
|
684
|
+
__wbg_subarray_3ed232c8a6baee09: function(arg0, arg1, arg2) {
|
|
685
|
+
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
686
|
+
return ret;
|
|
687
|
+
},
|
|
688
|
+
__wbg_versions_276b2795b1c6a219: function(arg0) {
|
|
689
|
+
const ret = arg0.versions;
|
|
690
|
+
return ret;
|
|
691
|
+
},
|
|
692
|
+
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
693
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
694
|
+
const ret = arg0;
|
|
695
|
+
return ret;
|
|
696
|
+
},
|
|
697
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
698
|
+
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
699
|
+
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
700
|
+
return ret;
|
|
701
|
+
},
|
|
702
|
+
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
|
703
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
704
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
705
|
+
return ret;
|
|
706
|
+
},
|
|
707
|
+
__wbindgen_init_externref_table: function() {
|
|
708
|
+
const table = wasm.__wbindgen_externrefs;
|
|
709
|
+
const offset = table.grow(4);
|
|
710
|
+
table.set(0, undefined);
|
|
711
|
+
table.set(offset + 0, undefined);
|
|
712
|
+
table.set(offset + 1, null);
|
|
713
|
+
table.set(offset + 2, true);
|
|
714
|
+
table.set(offset + 3, false);
|
|
715
|
+
},
|
|
716
|
+
};
|
|
717
|
+
return {
|
|
718
|
+
__proto__: null,
|
|
719
|
+
"./enclave_pqc_primitives_wasm_bg.js": import0,
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
function addToExternrefTable0(obj) {
|
|
724
|
+
const idx = wasm.__externref_table_alloc();
|
|
725
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
726
|
+
return idx;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
730
|
+
ptr = ptr >>> 0;
|
|
731
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
let cachedDataViewMemory0 = null;
|
|
735
|
+
function getDataViewMemory0() {
|
|
736
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
737
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
738
|
+
}
|
|
739
|
+
return cachedDataViewMemory0;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
function getStringFromWasm0(ptr, len) {
|
|
743
|
+
return decodeText(ptr >>> 0, len);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
let cachedUint8ArrayMemory0 = null;
|
|
747
|
+
function getUint8ArrayMemory0() {
|
|
748
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
749
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
750
|
+
}
|
|
751
|
+
return cachedUint8ArrayMemory0;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
function handleError(f, args) {
|
|
755
|
+
try {
|
|
756
|
+
return f.apply(this, args);
|
|
757
|
+
} catch (e) {
|
|
758
|
+
const idx = addToExternrefTable0(e);
|
|
759
|
+
wasm.__wbindgen_exn_store(idx);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
function isLikeNone(x) {
|
|
764
|
+
return x === undefined || x === null;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
768
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
769
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
770
|
+
WASM_VECTOR_LEN = arg.length;
|
|
771
|
+
return ptr;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
775
|
+
if (realloc === undefined) {
|
|
776
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
777
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
778
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
779
|
+
WASM_VECTOR_LEN = buf.length;
|
|
780
|
+
return ptr;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
let len = arg.length;
|
|
784
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
785
|
+
|
|
786
|
+
const mem = getUint8ArrayMemory0();
|
|
787
|
+
|
|
788
|
+
let offset = 0;
|
|
789
|
+
|
|
790
|
+
for (; offset < len; offset++) {
|
|
791
|
+
const code = arg.charCodeAt(offset);
|
|
792
|
+
if (code > 0x7F) break;
|
|
793
|
+
mem[ptr + offset] = code;
|
|
794
|
+
}
|
|
795
|
+
if (offset !== len) {
|
|
796
|
+
if (offset !== 0) {
|
|
797
|
+
arg = arg.slice(offset);
|
|
798
|
+
}
|
|
799
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
800
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
801
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
802
|
+
|
|
803
|
+
offset += ret.written;
|
|
804
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
WASM_VECTOR_LEN = offset;
|
|
808
|
+
return ptr;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
function takeFromExternrefTable0(idx) {
|
|
812
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
813
|
+
wasm.__externref_table_dealloc(idx);
|
|
814
|
+
return value;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
818
|
+
cachedTextDecoder.decode();
|
|
819
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
820
|
+
let numBytesDecoded = 0;
|
|
821
|
+
function decodeText(ptr, len) {
|
|
822
|
+
numBytesDecoded += len;
|
|
823
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
824
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
825
|
+
cachedTextDecoder.decode();
|
|
826
|
+
numBytesDecoded = len;
|
|
827
|
+
}
|
|
828
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
const cachedTextEncoder = new TextEncoder();
|
|
832
|
+
|
|
833
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
834
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
835
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
836
|
+
view.set(buf);
|
|
837
|
+
return {
|
|
838
|
+
read: arg.length,
|
|
839
|
+
written: buf.length
|
|
840
|
+
};
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
let WASM_VECTOR_LEN = 0;
|
|
845
|
+
|
|
846
|
+
let wasmModule, wasmInstance, wasm;
|
|
847
|
+
function __wbg_finalize_init(instance, module) {
|
|
848
|
+
wasmInstance = instance;
|
|
849
|
+
wasm = instance.exports;
|
|
850
|
+
wasmModule = module;
|
|
851
|
+
cachedDataViewMemory0 = null;
|
|
852
|
+
cachedUint8ArrayMemory0 = null;
|
|
853
|
+
wasm.__wbindgen_start();
|
|
854
|
+
return wasm;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
async function __wbg_load(module, imports) {
|
|
858
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
859
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
860
|
+
try {
|
|
861
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
862
|
+
} catch (e) {
|
|
863
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
864
|
+
|
|
865
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
866
|
+
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);
|
|
867
|
+
|
|
868
|
+
} else { throw e; }
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
const bytes = await module.arrayBuffer();
|
|
873
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
874
|
+
} else {
|
|
875
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
876
|
+
|
|
877
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
878
|
+
return { instance, module };
|
|
879
|
+
} else {
|
|
880
|
+
return instance;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
function expectedResponseType(type) {
|
|
885
|
+
switch (type) {
|
|
886
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
887
|
+
}
|
|
888
|
+
return false;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
function initSync(module) {
|
|
893
|
+
if (wasm !== undefined) return wasm;
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
if (module !== undefined) {
|
|
897
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
898
|
+
({module} = module)
|
|
899
|
+
} else {
|
|
900
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
const imports = __wbg_get_imports();
|
|
905
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
906
|
+
module = new WebAssembly.Module(module);
|
|
907
|
+
}
|
|
908
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
909
|
+
return __wbg_finalize_init(instance, module);
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
async function __wbg_init(module_or_path) {
|
|
913
|
+
if (wasm !== undefined) return wasm;
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
if (module_or_path !== undefined) {
|
|
917
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
918
|
+
({module_or_path} = module_or_path)
|
|
919
|
+
} else {
|
|
920
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
if (module_or_path === undefined) {
|
|
925
|
+
module_or_path = '/enclave_pqc_primitives_wasm_bg.wasm';
|
|
926
|
+
}
|
|
927
|
+
const imports = __wbg_get_imports();
|
|
928
|
+
|
|
929
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
930
|
+
module_or_path = fetch(module_or_path);
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
934
|
+
|
|
935
|
+
return __wbg_finalize_init(instance, module);
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
export { initSync, __wbg_init as default };
|