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