@maatara/core-pqc-wasm 0.1.0 → 0.1.1

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/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # @maatara/core-pqc-wasm
2
+
3
+ WASM bindings for Ma'atara's Post-Quantum Cryptography toolkit. Exposes Kyber ML‑KEM‑768, Dilithium (ML‑DSA‑65), HKDF‑SHA256, AES‑256‑GCM, and base64url helpers.
4
+
5
+ - Targets: `web` (browsers) and `bundler` (modern bundlers)
6
+ - Typings: included via wasm-pack generated `.d.ts`
7
+ - Size: ~238 KB `.wasm` (0.1.0), under 500 KB budget
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @maatara/core-pqc-wasm
13
+ ```
14
+
15
+ ## Usage (direct)
16
+
17
+ Most projects should depend on the higher-level wrapper `@maatara/core-pqc`. If you need the raw WASM exports:
18
+
19
+ ```js
20
+ import init, {
21
+ kyber_keygen,
22
+ kyber_encaps,
23
+ kyber_decaps,
24
+ hkdf_sha256,
25
+ aes_gcm_wrap,
26
+ aes_gcm_unwrap,
27
+ dilithium_keygen,
28
+ dilithium_sign,
29
+ dilithium_verify,
30
+ } from '@maatara/core-pqc-wasm';
31
+
32
+ await init();
33
+ const { public_b64u, secret_b64u } = JSON.parse(kyber_keygen());
34
+ ```
35
+
36
+ ## Security notes
37
+
38
+ - Zero‑knowledge: intended for client‑side use; servers should only perform verification.
39
+ - Constant‑time: uses vetted crates (`subtle`, `aes-gcm`).
40
+ - RNG: `getrandom` with `js` feature uses Web Crypto / Node WebCrypto.
41
+ - Provenance: WASM uses pure‑Rust `ml-kem` and `ml-dsa` crates; native builds (not used here) rely on `pqcrypto` (PQClean).
42
+
43
+ ## Build targets
44
+
45
+ - `wasm-pack build --target web`
46
+ - `wasm-pack build --target bundler`
@@ -10,47 +10,3 @@ export function dilithium_keygen(): string;
10
10
  export function dilithium_sign(message_b64u: string, secret_b64u: string): string;
11
11
  export function dilithium_verify(message_b64u: string, signature_b64u: string, public_b64u: string): string;
12
12
  export function start(): void;
13
-
14
- export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
15
-
16
- export interface InitOutput {
17
- readonly memory: WebAssembly.Memory;
18
- readonly kyber_keygen: () => [number, number];
19
- readonly kyber_encaps: (a: number, b: number) => [number, number];
20
- readonly kyber_decaps: (a: number, b: number, c: number, d: number) => [number, number];
21
- readonly hkdf_sha256: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
22
- readonly aes_gcm_wrap: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
23
- readonly aes_gcm_unwrap: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number];
24
- readonly dilithium_keygen: () => [number, number];
25
- readonly dilithium_sign: (a: number, b: number, c: number, d: number) => [number, number];
26
- readonly dilithium_verify: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
27
- readonly start: () => void;
28
- readonly __wbindgen_exn_store: (a: number) => void;
29
- readonly __externref_table_alloc: () => number;
30
- readonly __wbindgen_export_2: WebAssembly.Table;
31
- readonly __wbindgen_free: (a: number, b: number, c: number) => void;
32
- readonly __wbindgen_malloc: (a: number, b: number) => number;
33
- readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
34
- readonly __wbindgen_start: () => void;
35
- }
36
-
37
- export type SyncInitInput = BufferSource | WebAssembly.Module;
38
- /**
39
- * Instantiates the given `module`, which can either be bytes or
40
- * a precompiled `WebAssembly.Module`.
41
- *
42
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
43
- *
44
- * @returns {InitOutput}
45
- */
46
- export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
47
-
48
- /**
49
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
50
- * for everything else, calls `WebAssembly.instantiate` directly.
51
- *
52
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
53
- *
54
- * @returns {Promise<InitOutput>}
55
- */
56
- export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/core_pqc_wasm.js CHANGED
@@ -1,541 +1,5 @@
1
- let wasm;
2
-
3
- function addToExternrefTable0(obj) {
4
- const idx = wasm.__externref_table_alloc();
5
- wasm.__wbindgen_export_2.set(idx, obj);
6
- return idx;
7
- }
8
-
9
- function handleError(f, args) {
10
- try {
11
- return f.apply(this, args);
12
- } catch (e) {
13
- const idx = addToExternrefTable0(e);
14
- wasm.__wbindgen_exn_store(idx);
15
- }
16
- }
17
-
18
- let cachedUint8ArrayMemory0 = null;
19
-
20
- function getUint8ArrayMemory0() {
21
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
22
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
23
- }
24
- return cachedUint8ArrayMemory0;
25
- }
26
-
27
- let cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
28
-
29
- if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
30
-
31
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
32
- let numBytesDecoded = 0;
33
- function decodeText(ptr, len) {
34
- numBytesDecoded += len;
35
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
36
- cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
37
- cachedTextDecoder.decode();
38
- numBytesDecoded = len;
39
- }
40
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
41
- }
42
-
43
- function getStringFromWasm0(ptr, len) {
44
- ptr = ptr >>> 0;
45
- return decodeText(ptr, len);
46
- }
47
-
48
- function isLikeNone(x) {
49
- return x === undefined || x === null;
50
- }
51
- /**
52
- * @returns {string}
53
- */
54
- export function kyber_keygen() {
55
- let deferred1_0;
56
- let deferred1_1;
57
- try {
58
- const ret = wasm.kyber_keygen();
59
- deferred1_0 = ret[0];
60
- deferred1_1 = ret[1];
61
- return getStringFromWasm0(ret[0], ret[1]);
62
- } finally {
63
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
64
- }
65
- }
66
-
67
- let WASM_VECTOR_LEN = 0;
68
-
69
- const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
70
-
71
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
72
- ? function (arg, view) {
73
- return cachedTextEncoder.encodeInto(arg, view);
74
- }
75
- : function (arg, view) {
76
- const buf = cachedTextEncoder.encode(arg);
77
- view.set(buf);
78
- return {
79
- read: arg.length,
80
- written: buf.length
81
- };
82
- });
83
-
84
- function passStringToWasm0(arg, malloc, realloc) {
85
-
86
- if (realloc === undefined) {
87
- const buf = cachedTextEncoder.encode(arg);
88
- const ptr = malloc(buf.length, 1) >>> 0;
89
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
90
- WASM_VECTOR_LEN = buf.length;
91
- return ptr;
92
- }
93
-
94
- let len = arg.length;
95
- let ptr = malloc(len, 1) >>> 0;
96
-
97
- const mem = getUint8ArrayMemory0();
98
-
99
- let offset = 0;
100
-
101
- for (; offset < len; offset++) {
102
- const code = arg.charCodeAt(offset);
103
- if (code > 0x7F) break;
104
- mem[ptr + offset] = code;
105
- }
106
-
107
- if (offset !== len) {
108
- if (offset !== 0) {
109
- arg = arg.slice(offset);
110
- }
111
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
112
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
113
- const ret = encodeString(arg, view);
114
-
115
- offset += ret.written;
116
- ptr = realloc(ptr, len, offset, 1) >>> 0;
117
- }
118
-
119
- WASM_VECTOR_LEN = offset;
120
- return ptr;
121
- }
122
- /**
123
- * @param {string} public_b64u
124
- * @returns {string}
125
- */
126
- export function kyber_encaps(public_b64u) {
127
- let deferred2_0;
128
- let deferred2_1;
129
- try {
130
- const ptr0 = passStringToWasm0(public_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
131
- const len0 = WASM_VECTOR_LEN;
132
- const ret = wasm.kyber_encaps(ptr0, len0);
133
- deferred2_0 = ret[0];
134
- deferred2_1 = ret[1];
135
- return getStringFromWasm0(ret[0], ret[1]);
136
- } finally {
137
- wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
138
- }
139
- }
140
-
141
- /**
142
- * @param {string} secret_b64u
143
- * @param {string} kem_ct_b64u
144
- * @returns {string}
145
- */
146
- export function kyber_decaps(secret_b64u, kem_ct_b64u) {
147
- let deferred3_0;
148
- let deferred3_1;
149
- try {
150
- const ptr0 = passStringToWasm0(secret_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
151
- const len0 = WASM_VECTOR_LEN;
152
- const ptr1 = passStringToWasm0(kem_ct_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
153
- const len1 = WASM_VECTOR_LEN;
154
- const ret = wasm.kyber_decaps(ptr0, len0, ptr1, len1);
155
- deferred3_0 = ret[0];
156
- deferred3_1 = ret[1];
157
- return getStringFromWasm0(ret[0], ret[1]);
158
- } finally {
159
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
160
- }
161
- }
162
-
163
- /**
164
- * @param {string} secret_b64u
165
- * @param {string} info_b64u
166
- * @param {string | null | undefined} salt_b64u
167
- * @param {number} len
168
- * @returns {string}
169
- */
170
- export function hkdf_sha256(secret_b64u, info_b64u, salt_b64u, len) {
171
- let deferred4_0;
172
- let deferred4_1;
173
- try {
174
- const ptr0 = passStringToWasm0(secret_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
175
- const len0 = WASM_VECTOR_LEN;
176
- const ptr1 = passStringToWasm0(info_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
177
- const len1 = WASM_VECTOR_LEN;
178
- var ptr2 = isLikeNone(salt_b64u) ? 0 : passStringToWasm0(salt_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
179
- var len2 = WASM_VECTOR_LEN;
180
- const ret = wasm.hkdf_sha256(ptr0, len0, ptr1, len1, ptr2, len2, len);
181
- deferred4_0 = ret[0];
182
- deferred4_1 = ret[1];
183
- return getStringFromWasm0(ret[0], ret[1]);
184
- } finally {
185
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
186
- }
187
- }
188
-
189
- /**
190
- * @param {string} key_b64u
191
- * @param {string} dek_b64u
192
- * @param {string} aad_b64u
193
- * @returns {string}
194
- */
195
- export function aes_gcm_wrap(key_b64u, dek_b64u, aad_b64u) {
196
- let deferred4_0;
197
- let deferred4_1;
198
- try {
199
- const ptr0 = passStringToWasm0(key_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
200
- const len0 = WASM_VECTOR_LEN;
201
- const ptr1 = passStringToWasm0(dek_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
202
- const len1 = WASM_VECTOR_LEN;
203
- const ptr2 = passStringToWasm0(aad_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
204
- const len2 = WASM_VECTOR_LEN;
205
- const ret = wasm.aes_gcm_wrap(ptr0, len0, ptr1, len1, ptr2, len2);
206
- deferred4_0 = ret[0];
207
- deferred4_1 = ret[1];
208
- return getStringFromWasm0(ret[0], ret[1]);
209
- } finally {
210
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
211
- }
212
- }
213
-
214
- /**
215
- * @param {string} key_b64u
216
- * @param {string} iv_b64u
217
- * @param {string} ct_b64u
218
- * @param {string} aad_b64u
219
- * @returns {string}
220
- */
221
- export function aes_gcm_unwrap(key_b64u, iv_b64u, ct_b64u, aad_b64u) {
222
- let deferred5_0;
223
- let deferred5_1;
224
- try {
225
- const ptr0 = passStringToWasm0(key_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
226
- const len0 = WASM_VECTOR_LEN;
227
- const ptr1 = passStringToWasm0(iv_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
228
- const len1 = WASM_VECTOR_LEN;
229
- const ptr2 = passStringToWasm0(ct_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
230
- const len2 = WASM_VECTOR_LEN;
231
- const ptr3 = passStringToWasm0(aad_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
232
- const len3 = WASM_VECTOR_LEN;
233
- const ret = wasm.aes_gcm_unwrap(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
234
- deferred5_0 = ret[0];
235
- deferred5_1 = ret[1];
236
- return getStringFromWasm0(ret[0], ret[1]);
237
- } finally {
238
- wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
239
- }
240
- }
241
-
242
- /**
243
- * @returns {string}
244
- */
245
- export function dilithium_keygen() {
246
- let deferred1_0;
247
- let deferred1_1;
248
- try {
249
- const ret = wasm.dilithium_keygen();
250
- deferred1_0 = ret[0];
251
- deferred1_1 = ret[1];
252
- return getStringFromWasm0(ret[0], ret[1]);
253
- } finally {
254
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
255
- }
256
- }
257
-
258
- /**
259
- * @param {string} message_b64u
260
- * @param {string} secret_b64u
261
- * @returns {string}
262
- */
263
- export function dilithium_sign(message_b64u, secret_b64u) {
264
- let deferred3_0;
265
- let deferred3_1;
266
- try {
267
- const ptr0 = passStringToWasm0(message_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
268
- const len0 = WASM_VECTOR_LEN;
269
- const ptr1 = passStringToWasm0(secret_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
270
- const len1 = WASM_VECTOR_LEN;
271
- const ret = wasm.dilithium_sign(ptr0, len0, ptr1, len1);
272
- deferred3_0 = ret[0];
273
- deferred3_1 = ret[1];
274
- return getStringFromWasm0(ret[0], ret[1]);
275
- } finally {
276
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
277
- }
278
- }
279
-
280
- /**
281
- * @param {string} message_b64u
282
- * @param {string} signature_b64u
283
- * @param {string} public_b64u
284
- * @returns {string}
285
- */
286
- export function dilithium_verify(message_b64u, signature_b64u, public_b64u) {
287
- let deferred4_0;
288
- let deferred4_1;
289
- try {
290
- const ptr0 = passStringToWasm0(message_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
291
- const len0 = WASM_VECTOR_LEN;
292
- const ptr1 = passStringToWasm0(signature_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
293
- const len1 = WASM_VECTOR_LEN;
294
- const ptr2 = passStringToWasm0(public_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
295
- const len2 = WASM_VECTOR_LEN;
296
- const ret = wasm.dilithium_verify(ptr0, len0, ptr1, len1, ptr2, len2);
297
- deferred4_0 = ret[0];
298
- deferred4_1 = ret[1];
299
- return getStringFromWasm0(ret[0], ret[1]);
300
- } finally {
301
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
302
- }
303
- }
304
-
305
- export function start() {
306
- wasm.start();
307
- }
308
-
309
- const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
310
-
311
- async function __wbg_load(module, imports) {
312
- if (typeof Response === 'function' && module instanceof Response) {
313
- if (typeof WebAssembly.instantiateStreaming === 'function') {
314
- try {
315
- return await WebAssembly.instantiateStreaming(module, imports);
316
-
317
- } catch (e) {
318
- const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
319
-
320
- if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
321
- 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);
322
-
323
- } else {
324
- throw e;
325
- }
326
- }
327
- }
328
-
329
- const bytes = await module.arrayBuffer();
330
- return await WebAssembly.instantiate(bytes, imports);
331
-
332
- } else {
333
- const instance = await WebAssembly.instantiate(module, imports);
334
-
335
- if (instance instanceof WebAssembly.Instance) {
336
- return { instance, module };
337
-
338
- } else {
339
- return instance;
340
- }
341
- }
342
- }
343
-
344
- function __wbg_get_imports() {
345
- const imports = {};
346
- imports.wbg = {};
347
- imports.wbg.__wbg_buffer_a1a27a0dfa70165d = function(arg0) {
348
- const ret = arg0.buffer;
349
- return ret;
350
- };
351
- imports.wbg.__wbg_call_f2db6205e5c51dc8 = function() { return handleError(function (arg0, arg1, arg2) {
352
- const ret = arg0.call(arg1, arg2);
353
- return ret;
354
- }, arguments) };
355
- imports.wbg.__wbg_call_fbe8be8bf6436ce5 = function() { return handleError(function (arg0, arg1) {
356
- const ret = arg0.call(arg1);
357
- return ret;
358
- }, arguments) };
359
- imports.wbg.__wbg_crypto_574e78ad8b13b65f = function(arg0) {
360
- const ret = arg0.crypto;
361
- return ret;
362
- };
363
- imports.wbg.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
364
- arg0.getRandomValues(arg1);
365
- }, arguments) };
366
- imports.wbg.__wbg_log_8bc1206392c556f3 = function(arg0, arg1) {
367
- console.log(getStringFromWasm0(arg0, arg1));
368
- };
369
- imports.wbg.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) {
370
- const ret = arg0.msCrypto;
371
- return ret;
372
- };
373
- imports.wbg.__wbg_new_e52b3efaaa774f96 = function(arg0) {
374
- const ret = new Uint8Array(arg0);
375
- return ret;
376
- };
377
- imports.wbg.__wbg_newnoargs_ff528e72d35de39a = function(arg0, arg1) {
378
- const ret = new Function(getStringFromWasm0(arg0, arg1));
379
- return ret;
380
- };
381
- imports.wbg.__wbg_newwithbyteoffsetandlength_3b01ecda099177e8 = function(arg0, arg1, arg2) {
382
- const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
383
- return ret;
384
- };
385
- imports.wbg.__wbg_newwithlength_08f872dc1e3ada2e = function(arg0) {
386
- const ret = new Uint8Array(arg0 >>> 0);
387
- return ret;
388
- };
389
- imports.wbg.__wbg_node_905d3e251edff8a2 = function(arg0) {
390
- const ret = arg0.node;
391
- return ret;
392
- };
393
- imports.wbg.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
394
- const ret = arg0.process;
395
- return ret;
396
- };
397
- imports.wbg.__wbg_randomFillSync_ac0988aba3254290 = function() { return handleError(function (arg0, arg1) {
398
- arg0.randomFillSync(arg1);
399
- }, arguments) };
400
- imports.wbg.__wbg_require_60cc747a6bc5215a = function() { return handleError(function () {
401
- const ret = module.require;
402
- return ret;
403
- }, arguments) };
404
- imports.wbg.__wbg_set_fe4e79d1ed3b0e9b = function(arg0, arg1, arg2) {
405
- arg0.set(arg1, arg2 >>> 0);
406
- };
407
- imports.wbg.__wbg_static_accessor_GLOBAL_487c52c58d65314d = function() {
408
- const ret = typeof global === 'undefined' ? null : global;
409
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
410
- };
411
- imports.wbg.__wbg_static_accessor_GLOBAL_THIS_ee9704f328b6b291 = function() {
412
- const ret = typeof globalThis === 'undefined' ? null : globalThis;
413
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
414
- };
415
- imports.wbg.__wbg_static_accessor_SELF_78c9e3071b912620 = function() {
416
- const ret = typeof self === 'undefined' ? null : self;
417
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
418
- };
419
- imports.wbg.__wbg_static_accessor_WINDOW_a093d21393777366 = function() {
420
- const ret = typeof window === 'undefined' ? null : window;
421
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
422
- };
423
- imports.wbg.__wbg_subarray_dd4ade7d53bd8e26 = function(arg0, arg1, arg2) {
424
- const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
425
- return ret;
426
- };
427
- imports.wbg.__wbg_versions_c01dfd4722a88165 = function(arg0) {
428
- const ret = arg0.versions;
429
- return ret;
430
- };
431
- imports.wbg.__wbindgen_init_externref_table = function() {
432
- const table = wasm.__wbindgen_export_2;
433
- const offset = table.grow(4);
434
- table.set(0, undefined);
435
- table.set(offset + 0, undefined);
436
- table.set(offset + 1, null);
437
- table.set(offset + 2, true);
438
- table.set(offset + 3, false);
439
- ;
440
- };
441
- imports.wbg.__wbindgen_is_function = function(arg0) {
442
- const ret = typeof(arg0) === 'function';
443
- return ret;
444
- };
445
- imports.wbg.__wbindgen_is_object = function(arg0) {
446
- const val = arg0;
447
- const ret = typeof(val) === 'object' && val !== null;
448
- return ret;
449
- };
450
- imports.wbg.__wbindgen_is_string = function(arg0) {
451
- const ret = typeof(arg0) === 'string';
452
- return ret;
453
- };
454
- imports.wbg.__wbindgen_is_undefined = function(arg0) {
455
- const ret = arg0 === undefined;
456
- return ret;
457
- };
458
- imports.wbg.__wbindgen_memory = function() {
459
- const ret = wasm.memory;
460
- return ret;
461
- };
462
- imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
463
- const ret = getStringFromWasm0(arg0, arg1);
464
- return ret;
465
- };
466
- imports.wbg.__wbindgen_throw = function(arg0, arg1) {
467
- throw new Error(getStringFromWasm0(arg0, arg1));
468
- };
469
-
470
- return imports;
471
- }
472
-
473
- function __wbg_init_memory(imports, memory) {
474
-
475
- }
476
-
477
- function __wbg_finalize_init(instance, module) {
478
- wasm = instance.exports;
479
- __wbg_init.__wbindgen_wasm_module = module;
480
- cachedUint8ArrayMemory0 = null;
481
-
482
-
483
- wasm.__wbindgen_start();
484
- return wasm;
485
- }
486
-
487
- function initSync(module) {
488
- if (wasm !== undefined) return wasm;
489
-
490
-
491
- if (typeof module !== 'undefined') {
492
- if (Object.getPrototypeOf(module) === Object.prototype) {
493
- ({module} = module)
494
- } else {
495
- console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
496
- }
497
- }
498
-
499
- const imports = __wbg_get_imports();
500
-
501
- __wbg_init_memory(imports);
502
-
503
- if (!(module instanceof WebAssembly.Module)) {
504
- module = new WebAssembly.Module(module);
505
- }
506
-
507
- const instance = new WebAssembly.Instance(module, imports);
508
-
509
- return __wbg_finalize_init(instance, module);
510
- }
511
-
512
- async function __wbg_init(module_or_path) {
513
- if (wasm !== undefined) return wasm;
514
-
515
-
516
- if (typeof module_or_path !== 'undefined') {
517
- if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
518
- ({module_or_path} = module_or_path)
519
- } else {
520
- console.warn('using deprecated parameters for the initialization function; pass a single object instead')
521
- }
522
- }
523
-
524
- if (typeof module_or_path === 'undefined') {
525
- module_or_path = new URL('core_pqc_wasm_bg.wasm', import.meta.url);
526
- }
527
- const imports = __wbg_get_imports();
528
-
529
- if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
530
- module_or_path = fetch(module_or_path);
531
- }
532
-
533
- __wbg_init_memory(imports);
534
-
535
- const { instance, module } = await __wbg_load(await module_or_path, imports);
536
-
537
- return __wbg_finalize_init(instance, module);
538
- }
539
-
540
- export { initSync };
541
- export default __wbg_init;
1
+ import * as wasm from "./core_pqc_wasm_bg.wasm";
2
+ export * from "./core_pqc_wasm_bg.js";
3
+ import { __wbg_set_wasm } from "./core_pqc_wasm_bg.js";
4
+ __wbg_set_wasm(wasm);
5
+ wasm.__wbindgen_start();
@@ -0,0 +1,468 @@
1
+ let wasm;
2
+ export function __wbg_set_wasm(val) {
3
+ wasm = val;
4
+ }
5
+
6
+
7
+ function addToExternrefTable0(obj) {
8
+ const idx = wasm.__externref_table_alloc();
9
+ wasm.__wbindgen_export_2.set(idx, obj);
10
+ return idx;
11
+ }
12
+
13
+ function handleError(f, args) {
14
+ try {
15
+ return f.apply(this, args);
16
+ } catch (e) {
17
+ const idx = addToExternrefTable0(e);
18
+ wasm.__wbindgen_exn_store(idx);
19
+ }
20
+ }
21
+
22
+ let cachedUint8ArrayMemory0 = null;
23
+
24
+ function getUint8ArrayMemory0() {
25
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
26
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
27
+ }
28
+ return cachedUint8ArrayMemory0;
29
+ }
30
+
31
+ const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
32
+
33
+ let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
34
+
35
+ cachedTextDecoder.decode();
36
+
37
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
38
+ let numBytesDecoded = 0;
39
+ function decodeText(ptr, len) {
40
+ numBytesDecoded += len;
41
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
42
+ cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
43
+ cachedTextDecoder.decode();
44
+ numBytesDecoded = len;
45
+ }
46
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
47
+ }
48
+
49
+ function getStringFromWasm0(ptr, len) {
50
+ ptr = ptr >>> 0;
51
+ return decodeText(ptr, len);
52
+ }
53
+
54
+ function isLikeNone(x) {
55
+ return x === undefined || x === null;
56
+ }
57
+ /**
58
+ * @returns {string}
59
+ */
60
+ export function kyber_keygen() {
61
+ let deferred1_0;
62
+ let deferred1_1;
63
+ try {
64
+ const ret = wasm.kyber_keygen();
65
+ deferred1_0 = ret[0];
66
+ deferred1_1 = ret[1];
67
+ return getStringFromWasm0(ret[0], ret[1]);
68
+ } finally {
69
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
70
+ }
71
+ }
72
+
73
+ let WASM_VECTOR_LEN = 0;
74
+
75
+ const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
76
+
77
+ const cachedTextEncoder = new lTextEncoder('utf-8');
78
+
79
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
80
+ ? function (arg, view) {
81
+ return cachedTextEncoder.encodeInto(arg, view);
82
+ }
83
+ : function (arg, view) {
84
+ const buf = cachedTextEncoder.encode(arg);
85
+ view.set(buf);
86
+ return {
87
+ read: arg.length,
88
+ written: buf.length
89
+ };
90
+ });
91
+
92
+ function passStringToWasm0(arg, malloc, realloc) {
93
+
94
+ if (realloc === undefined) {
95
+ const buf = cachedTextEncoder.encode(arg);
96
+ const ptr = malloc(buf.length, 1) >>> 0;
97
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
98
+ WASM_VECTOR_LEN = buf.length;
99
+ return ptr;
100
+ }
101
+
102
+ let len = arg.length;
103
+ let ptr = malloc(len, 1) >>> 0;
104
+
105
+ const mem = getUint8ArrayMemory0();
106
+
107
+ let offset = 0;
108
+
109
+ for (; offset < len; offset++) {
110
+ const code = arg.charCodeAt(offset);
111
+ if (code > 0x7F) break;
112
+ mem[ptr + offset] = code;
113
+ }
114
+
115
+ if (offset !== len) {
116
+ if (offset !== 0) {
117
+ arg = arg.slice(offset);
118
+ }
119
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
120
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
121
+ const ret = encodeString(arg, view);
122
+
123
+ offset += ret.written;
124
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
125
+ }
126
+
127
+ WASM_VECTOR_LEN = offset;
128
+ return ptr;
129
+ }
130
+ /**
131
+ * @param {string} public_b64u
132
+ * @returns {string}
133
+ */
134
+ export function kyber_encaps(public_b64u) {
135
+ let deferred2_0;
136
+ let deferred2_1;
137
+ try {
138
+ const ptr0 = passStringToWasm0(public_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
139
+ const len0 = WASM_VECTOR_LEN;
140
+ const ret = wasm.kyber_encaps(ptr0, len0);
141
+ deferred2_0 = ret[0];
142
+ deferred2_1 = ret[1];
143
+ return getStringFromWasm0(ret[0], ret[1]);
144
+ } finally {
145
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
146
+ }
147
+ }
148
+
149
+ /**
150
+ * @param {string} secret_b64u
151
+ * @param {string} kem_ct_b64u
152
+ * @returns {string}
153
+ */
154
+ export function kyber_decaps(secret_b64u, kem_ct_b64u) {
155
+ let deferred3_0;
156
+ let deferred3_1;
157
+ try {
158
+ const ptr0 = passStringToWasm0(secret_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
159
+ const len0 = WASM_VECTOR_LEN;
160
+ const ptr1 = passStringToWasm0(kem_ct_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
161
+ const len1 = WASM_VECTOR_LEN;
162
+ const ret = wasm.kyber_decaps(ptr0, len0, ptr1, len1);
163
+ deferred3_0 = ret[0];
164
+ deferred3_1 = ret[1];
165
+ return getStringFromWasm0(ret[0], ret[1]);
166
+ } finally {
167
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
168
+ }
169
+ }
170
+
171
+ /**
172
+ * @param {string} secret_b64u
173
+ * @param {string} info_b64u
174
+ * @param {string | null | undefined} salt_b64u
175
+ * @param {number} len
176
+ * @returns {string}
177
+ */
178
+ export function hkdf_sha256(secret_b64u, info_b64u, salt_b64u, len) {
179
+ let deferred4_0;
180
+ let deferred4_1;
181
+ try {
182
+ const ptr0 = passStringToWasm0(secret_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
183
+ const len0 = WASM_VECTOR_LEN;
184
+ const ptr1 = passStringToWasm0(info_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
185
+ const len1 = WASM_VECTOR_LEN;
186
+ var ptr2 = isLikeNone(salt_b64u) ? 0 : passStringToWasm0(salt_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
187
+ var len2 = WASM_VECTOR_LEN;
188
+ const ret = wasm.hkdf_sha256(ptr0, len0, ptr1, len1, ptr2, len2, len);
189
+ deferred4_0 = ret[0];
190
+ deferred4_1 = ret[1];
191
+ return getStringFromWasm0(ret[0], ret[1]);
192
+ } finally {
193
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
194
+ }
195
+ }
196
+
197
+ /**
198
+ * @param {string} key_b64u
199
+ * @param {string} dek_b64u
200
+ * @param {string} aad_b64u
201
+ * @returns {string}
202
+ */
203
+ export function aes_gcm_wrap(key_b64u, dek_b64u, aad_b64u) {
204
+ let deferred4_0;
205
+ let deferred4_1;
206
+ try {
207
+ const ptr0 = passStringToWasm0(key_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
208
+ const len0 = WASM_VECTOR_LEN;
209
+ const ptr1 = passStringToWasm0(dek_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
210
+ const len1 = WASM_VECTOR_LEN;
211
+ const ptr2 = passStringToWasm0(aad_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
212
+ const len2 = WASM_VECTOR_LEN;
213
+ const ret = wasm.aes_gcm_wrap(ptr0, len0, ptr1, len1, ptr2, len2);
214
+ deferred4_0 = ret[0];
215
+ deferred4_1 = ret[1];
216
+ return getStringFromWasm0(ret[0], ret[1]);
217
+ } finally {
218
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
219
+ }
220
+ }
221
+
222
+ /**
223
+ * @param {string} key_b64u
224
+ * @param {string} iv_b64u
225
+ * @param {string} ct_b64u
226
+ * @param {string} aad_b64u
227
+ * @returns {string}
228
+ */
229
+ export function aes_gcm_unwrap(key_b64u, iv_b64u, ct_b64u, aad_b64u) {
230
+ let deferred5_0;
231
+ let deferred5_1;
232
+ try {
233
+ const ptr0 = passStringToWasm0(key_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
234
+ const len0 = WASM_VECTOR_LEN;
235
+ const ptr1 = passStringToWasm0(iv_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
236
+ const len1 = WASM_VECTOR_LEN;
237
+ const ptr2 = passStringToWasm0(ct_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
238
+ const len2 = WASM_VECTOR_LEN;
239
+ const ptr3 = passStringToWasm0(aad_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
240
+ const len3 = WASM_VECTOR_LEN;
241
+ const ret = wasm.aes_gcm_unwrap(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
242
+ deferred5_0 = ret[0];
243
+ deferred5_1 = ret[1];
244
+ return getStringFromWasm0(ret[0], ret[1]);
245
+ } finally {
246
+ wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
247
+ }
248
+ }
249
+
250
+ /**
251
+ * @returns {string}
252
+ */
253
+ export function dilithium_keygen() {
254
+ let deferred1_0;
255
+ let deferred1_1;
256
+ try {
257
+ const ret = wasm.dilithium_keygen();
258
+ deferred1_0 = ret[0];
259
+ deferred1_1 = ret[1];
260
+ return getStringFromWasm0(ret[0], ret[1]);
261
+ } finally {
262
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
263
+ }
264
+ }
265
+
266
+ /**
267
+ * @param {string} message_b64u
268
+ * @param {string} secret_b64u
269
+ * @returns {string}
270
+ */
271
+ export function dilithium_sign(message_b64u, secret_b64u) {
272
+ let deferred3_0;
273
+ let deferred3_1;
274
+ try {
275
+ const ptr0 = passStringToWasm0(message_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
276
+ const len0 = WASM_VECTOR_LEN;
277
+ const ptr1 = passStringToWasm0(secret_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
278
+ const len1 = WASM_VECTOR_LEN;
279
+ const ret = wasm.dilithium_sign(ptr0, len0, ptr1, len1);
280
+ deferred3_0 = ret[0];
281
+ deferred3_1 = ret[1];
282
+ return getStringFromWasm0(ret[0], ret[1]);
283
+ } finally {
284
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
285
+ }
286
+ }
287
+
288
+ /**
289
+ * @param {string} message_b64u
290
+ * @param {string} signature_b64u
291
+ * @param {string} public_b64u
292
+ * @returns {string}
293
+ */
294
+ export function dilithium_verify(message_b64u, signature_b64u, public_b64u) {
295
+ let deferred4_0;
296
+ let deferred4_1;
297
+ try {
298
+ const ptr0 = passStringToWasm0(message_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
299
+ const len0 = WASM_VECTOR_LEN;
300
+ const ptr1 = passStringToWasm0(signature_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
301
+ const len1 = WASM_VECTOR_LEN;
302
+ const ptr2 = passStringToWasm0(public_b64u, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
303
+ const len2 = WASM_VECTOR_LEN;
304
+ const ret = wasm.dilithium_verify(ptr0, len0, ptr1, len1, ptr2, len2);
305
+ deferred4_0 = ret[0];
306
+ deferred4_1 = ret[1];
307
+ return getStringFromWasm0(ret[0], ret[1]);
308
+ } finally {
309
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
310
+ }
311
+ }
312
+
313
+ export function start() {
314
+ wasm.start();
315
+ }
316
+
317
+ export function __wbg_buffer_a1a27a0dfa70165d(arg0) {
318
+ const ret = arg0.buffer;
319
+ return ret;
320
+ };
321
+
322
+ export function __wbg_call_f2db6205e5c51dc8() { return handleError(function (arg0, arg1, arg2) {
323
+ const ret = arg0.call(arg1, arg2);
324
+ return ret;
325
+ }, arguments) };
326
+
327
+ export function __wbg_call_fbe8be8bf6436ce5() { return handleError(function (arg0, arg1) {
328
+ const ret = arg0.call(arg1);
329
+ return ret;
330
+ }, arguments) };
331
+
332
+ export function __wbg_crypto_574e78ad8b13b65f(arg0) {
333
+ const ret = arg0.crypto;
334
+ return ret;
335
+ };
336
+
337
+ export function __wbg_getRandomValues_b8f5dbd5f3995a9e() { return handleError(function (arg0, arg1) {
338
+ arg0.getRandomValues(arg1);
339
+ }, arguments) };
340
+
341
+ export function __wbg_log_8bc1206392c556f3(arg0, arg1) {
342
+ console.log(getStringFromWasm0(arg0, arg1));
343
+ };
344
+
345
+ export function __wbg_msCrypto_a61aeb35a24c1329(arg0) {
346
+ const ret = arg0.msCrypto;
347
+ return ret;
348
+ };
349
+
350
+ export function __wbg_new_e52b3efaaa774f96(arg0) {
351
+ const ret = new Uint8Array(arg0);
352
+ return ret;
353
+ };
354
+
355
+ export function __wbg_newnoargs_ff528e72d35de39a(arg0, arg1) {
356
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
357
+ return ret;
358
+ };
359
+
360
+ export function __wbg_newwithbyteoffsetandlength_3b01ecda099177e8(arg0, arg1, arg2) {
361
+ const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
362
+ return ret;
363
+ };
364
+
365
+ export function __wbg_newwithlength_08f872dc1e3ada2e(arg0) {
366
+ const ret = new Uint8Array(arg0 >>> 0);
367
+ return ret;
368
+ };
369
+
370
+ export function __wbg_node_905d3e251edff8a2(arg0) {
371
+ const ret = arg0.node;
372
+ return ret;
373
+ };
374
+
375
+ export function __wbg_process_dc0fbacc7c1c06f7(arg0) {
376
+ const ret = arg0.process;
377
+ return ret;
378
+ };
379
+
380
+ export function __wbg_randomFillSync_ac0988aba3254290() { return handleError(function (arg0, arg1) {
381
+ arg0.randomFillSync(arg1);
382
+ }, arguments) };
383
+
384
+ export function __wbg_require_60cc747a6bc5215a() { return handleError(function () {
385
+ const ret = module.require;
386
+ return ret;
387
+ }, arguments) };
388
+
389
+ export function __wbg_set_fe4e79d1ed3b0e9b(arg0, arg1, arg2) {
390
+ arg0.set(arg1, arg2 >>> 0);
391
+ };
392
+
393
+ export function __wbg_static_accessor_GLOBAL_487c52c58d65314d() {
394
+ const ret = typeof global === 'undefined' ? null : global;
395
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
396
+ };
397
+
398
+ export function __wbg_static_accessor_GLOBAL_THIS_ee9704f328b6b291() {
399
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
400
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
401
+ };
402
+
403
+ export function __wbg_static_accessor_SELF_78c9e3071b912620() {
404
+ const ret = typeof self === 'undefined' ? null : self;
405
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
406
+ };
407
+
408
+ export function __wbg_static_accessor_WINDOW_a093d21393777366() {
409
+ const ret = typeof window === 'undefined' ? null : window;
410
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
411
+ };
412
+
413
+ export function __wbg_subarray_dd4ade7d53bd8e26(arg0, arg1, arg2) {
414
+ const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
415
+ return ret;
416
+ };
417
+
418
+ export function __wbg_versions_c01dfd4722a88165(arg0) {
419
+ const ret = arg0.versions;
420
+ return ret;
421
+ };
422
+
423
+ export function __wbindgen_init_externref_table() {
424
+ const table = wasm.__wbindgen_export_2;
425
+ const offset = table.grow(4);
426
+ table.set(0, undefined);
427
+ table.set(offset + 0, undefined);
428
+ table.set(offset + 1, null);
429
+ table.set(offset + 2, true);
430
+ table.set(offset + 3, false);
431
+ ;
432
+ };
433
+
434
+ export function __wbindgen_is_function(arg0) {
435
+ const ret = typeof(arg0) === 'function';
436
+ return ret;
437
+ };
438
+
439
+ export function __wbindgen_is_object(arg0) {
440
+ const val = arg0;
441
+ const ret = typeof(val) === 'object' && val !== null;
442
+ return ret;
443
+ };
444
+
445
+ export function __wbindgen_is_string(arg0) {
446
+ const ret = typeof(arg0) === 'string';
447
+ return ret;
448
+ };
449
+
450
+ export function __wbindgen_is_undefined(arg0) {
451
+ const ret = arg0 === undefined;
452
+ return ret;
453
+ };
454
+
455
+ export function __wbindgen_memory() {
456
+ const ret = wasm.memory;
457
+ return ret;
458
+ };
459
+
460
+ export function __wbindgen_string_new(arg0, arg1) {
461
+ const ret = getStringFromWasm0(arg0, arg1);
462
+ return ret;
463
+ };
464
+
465
+ export function __wbindgen_throw(arg0, arg1) {
466
+ throw new Error(getStringFromWasm0(arg0, arg1));
467
+ };
468
+
Binary file
package/node.js ADDED
@@ -0,0 +1,29 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import url from 'node:url';
4
+
5
+ // Node-friendly loader: read the .wasm file bytes and initialize the wasm module explicitly.
6
+ import initWasm, * as wasmExports from './core_pqc_wasm.js';
7
+
8
+ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
9
+ const wasmPath = path.join(__dirname, 'core_pqc_wasm_bg.wasm');
10
+
11
+ let ready;
12
+ async function ensureInit() {
13
+ if (!ready) {
14
+ const bytes = await fs.readFile(wasmPath);
15
+ // initWasm accepts BufferSource in Node 18 via WebAssembly.Module path
16
+ ready = initWasm(bytes);
17
+ }
18
+ return ready;
19
+ }
20
+
21
+ // Re-export all bindings, but ensure initialization is performed first when needed.
22
+ // Consumers can call default() to ensure ready, or functions will work after a top-level init in their lib.
23
+ export default async function() {
24
+ await ensureInit();
25
+ }
26
+
27
+ // Named exports: wrap the start/init-sensitive functions to ensure init has happened when called.
28
+ // For simplicity, re-export everything and rely on consumers to call default() or our higher-level wrapper does it.
29
+ export * from './core_pqc_wasm.js';
package/package.json CHANGED
@@ -2,19 +2,28 @@
2
2
  "name": "@maatara/core-pqc-wasm",
3
3
  "type": "module",
4
4
  "description": "Ma'atara PQC WASM bindings",
5
- "version": "0.1.0",
5
+ "version": "0.1.1",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/your-org/maatara"
9
+ "url": "https://github.com/maatara/Maatara"
10
10
  },
11
11
  "files": [
12
12
  "core_pqc_wasm_bg.wasm",
13
13
  "core_pqc_wasm.js",
14
- "core_pqc_wasm.d.ts"
14
+ "core_pqc_wasm_bg.js",
15
+ "core_pqc_wasm.d.ts",
16
+ "node.js"
15
17
  ],
16
18
  "main": "core_pqc_wasm.js",
17
19
  "types": "core_pqc_wasm.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./core_pqc_wasm.d.ts",
23
+ "node": "./node.js",
24
+ "default": "./core_pqc_wasm.js"
25
+ }
26
+ },
18
27
  "sideEffects": [
19
28
  "./snippets/*"
20
29
  ]
package/LICENSE DELETED
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [2025] [Ma'atara Contributors]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.