@crisp-e3/zk-inputs 0.2.0-test → 0.2.1-test

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,475 @@
1
+ let wasm;
2
+
3
+ function addToExternrefTable0(obj) {
4
+ const idx = wasm.__externref_table_alloc();
5
+ wasm.__wbindgen_externrefs.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 = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
28
+
29
+ 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 = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
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 getArrayU8FromWasm0(ptr, len) {
49
+ ptr = ptr >>> 0;
50
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
51
+ }
52
+
53
+ function isLikeNone(x) {
54
+ return x === undefined || x === null;
55
+ }
56
+
57
+ let cachedBigUint64ArrayMemory0 = null;
58
+
59
+ function getBigUint64ArrayMemory0() {
60
+ if (cachedBigUint64ArrayMemory0 === null || cachedBigUint64ArrayMemory0.byteLength === 0) {
61
+ cachedBigUint64ArrayMemory0 = new BigUint64Array(wasm.memory.buffer);
62
+ }
63
+ return cachedBigUint64ArrayMemory0;
64
+ }
65
+
66
+ let WASM_VECTOR_LEN = 0;
67
+
68
+ function passArray64ToWasm0(arg, malloc) {
69
+ const ptr = malloc(arg.length * 8, 8) >>> 0;
70
+ getBigUint64ArrayMemory0().set(arg, ptr / 8);
71
+ WASM_VECTOR_LEN = arg.length;
72
+ return ptr;
73
+ }
74
+
75
+ function takeFromExternrefTable0(idx) {
76
+ const value = wasm.__wbindgen_externrefs.get(idx);
77
+ wasm.__externref_table_dealloc(idx);
78
+ return value;
79
+ }
80
+
81
+ function passArray8ToWasm0(arg, malloc) {
82
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
83
+ getUint8ArrayMemory0().set(arg, ptr / 1);
84
+ WASM_VECTOR_LEN = arg.length;
85
+ return ptr;
86
+ }
87
+
88
+ const ZKInputsGeneratorFinalization = (typeof FinalizationRegistry === 'undefined')
89
+ ? { register: () => {}, unregister: () => {} }
90
+ : new FinalizationRegistry(ptr => wasm.__wbg_zkinputsgenerator_free(ptr >>> 0, 1));
91
+ /**
92
+ * JavaScript-compatible CRISP ZK inputs generator.
93
+ */
94
+ export class ZKInputsGenerator {
95
+
96
+ static __wrap(ptr) {
97
+ ptr = ptr >>> 0;
98
+ const obj = Object.create(ZKInputsGenerator.prototype);
99
+ obj.__wbg_ptr = ptr;
100
+ ZKInputsGeneratorFinalization.register(obj, obj.__wbg_ptr, obj);
101
+ return obj;
102
+ }
103
+
104
+ __destroy_into_raw() {
105
+ const ptr = this.__wbg_ptr;
106
+ this.__wbg_ptr = 0;
107
+ ZKInputsGeneratorFinalization.unregister(this);
108
+ return ptr;
109
+ }
110
+
111
+ free() {
112
+ const ptr = this.__destroy_into_raw();
113
+ wasm.__wbg_zkinputsgenerator_free(ptr, 0);
114
+ }
115
+ /**
116
+ * Create a new JavaScript CRISP ZK inputs generator with the specified BFV parameters.
117
+ *
118
+ * # Arguments
119
+ * - `degree`: Polynomial degree
120
+ * - `plaintext_modulus`: Plaintext modulus (will be converted to u64)
121
+ * - `moduli`: Array of moduli (will be converted to Vec<u64>)
122
+ * @param {number} degree
123
+ * @param {bigint} plaintext_modulus
124
+ * @param {BigInt64Array} moduli
125
+ */
126
+ constructor(degree, plaintext_modulus, moduli) {
127
+ const ptr0 = passArray64ToWasm0(moduli, wasm.__wbindgen_malloc);
128
+ const len0 = WASM_VECTOR_LEN;
129
+ const ret = wasm.zkinputsgenerator_new(degree, plaintext_modulus, ptr0, len0);
130
+ if (ret[2]) {
131
+ throw takeFromExternrefTable0(ret[1]);
132
+ }
133
+ this.__wbg_ptr = ret[0] >>> 0;
134
+ ZKInputsGeneratorFinalization.register(this, this.__wbg_ptr, this);
135
+ return this;
136
+ }
137
+ /**
138
+ * Create a new JavaScript CRISP ZK inputs generator with default BFV parameters.
139
+ * @returns {ZKInputsGenerator}
140
+ */
141
+ static withDefaults() {
142
+ const ret = wasm.zkinputsgenerator_withDefaults();
143
+ if (ret[2]) {
144
+ throw takeFromExternrefTable0(ret[1]);
145
+ }
146
+ return ZKInputsGenerator.__wrap(ret[0]);
147
+ }
148
+ /**
149
+ * Generate a CRISP ZK inputs from JavaScript.
150
+ * @param {Uint8Array} prev_ciphertext
151
+ * @param {Uint8Array} public_key
152
+ * @param {BigInt64Array} vote
153
+ * @returns {any}
154
+ */
155
+ generateInputs(prev_ciphertext, public_key, vote) {
156
+ const ptr0 = passArray8ToWasm0(prev_ciphertext, wasm.__wbindgen_malloc);
157
+ const len0 = WASM_VECTOR_LEN;
158
+ const ptr1 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
159
+ const len1 = WASM_VECTOR_LEN;
160
+ const ptr2 = passArray64ToWasm0(vote, wasm.__wbindgen_malloc);
161
+ const len2 = WASM_VECTOR_LEN;
162
+ const ret = wasm.zkinputsgenerator_generateInputs(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
163
+ if (ret[2]) {
164
+ throw takeFromExternrefTable0(ret[1]);
165
+ }
166
+ return takeFromExternrefTable0(ret[0]);
167
+ }
168
+ /**
169
+ * Generate a public key from JavaScript.
170
+ * @returns {Uint8Array}
171
+ */
172
+ generatePublicKey() {
173
+ const ret = wasm.zkinputsgenerator_generatePublicKey(this.__wbg_ptr);
174
+ if (ret[3]) {
175
+ throw takeFromExternrefTable0(ret[2]);
176
+ }
177
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
178
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
179
+ return v1;
180
+ }
181
+ /**
182
+ * Encrypt a vote from JavaScript.
183
+ * @param {Uint8Array} public_key
184
+ * @param {BigInt64Array} vote
185
+ * @returns {Uint8Array}
186
+ */
187
+ encryptVote(public_key, vote) {
188
+ const ptr0 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
189
+ const len0 = WASM_VECTOR_LEN;
190
+ const ptr1 = passArray64ToWasm0(vote, wasm.__wbindgen_malloc);
191
+ const len1 = WASM_VECTOR_LEN;
192
+ const ret = wasm.zkinputsgenerator_encryptVote(this.__wbg_ptr, ptr0, len0, ptr1, len1);
193
+ if (ret[3]) {
194
+ throw takeFromExternrefTable0(ret[2]);
195
+ }
196
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
197
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
198
+ return v3;
199
+ }
200
+ /**
201
+ * Get the BFV parameters used by the generator.
202
+ * @returns {any}
203
+ */
204
+ getBFVParams() {
205
+ const ret = wasm.zkinputsgenerator_getBFVParams(this.__wbg_ptr);
206
+ if (ret[2]) {
207
+ throw takeFromExternrefTable0(ret[1]);
208
+ }
209
+ return takeFromExternrefTable0(ret[0]);
210
+ }
211
+ /**
212
+ * Get the version of the library.
213
+ * @returns {string}
214
+ */
215
+ static version() {
216
+ let deferred1_0;
217
+ let deferred1_1;
218
+ try {
219
+ const ret = wasm.zkinputsgenerator_version();
220
+ deferred1_0 = ret[0];
221
+ deferred1_1 = ret[1];
222
+ return getStringFromWasm0(ret[0], ret[1]);
223
+ } finally {
224
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
225
+ }
226
+ }
227
+ }
228
+ if (Symbol.dispose) ZKInputsGenerator.prototype[Symbol.dispose] = ZKInputsGenerator.prototype.free;
229
+
230
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
231
+
232
+ async function __wbg_load(module, imports) {
233
+ if (typeof Response === 'function' && module instanceof Response) {
234
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
235
+ try {
236
+ return await WebAssembly.instantiateStreaming(module, imports);
237
+
238
+ } catch (e) {
239
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
240
+
241
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
242
+ 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);
243
+
244
+ } else {
245
+ throw e;
246
+ }
247
+ }
248
+ }
249
+
250
+ const bytes = await module.arrayBuffer();
251
+ return await WebAssembly.instantiate(bytes, imports);
252
+
253
+ } else {
254
+ const instance = await WebAssembly.instantiate(module, imports);
255
+
256
+ if (instance instanceof WebAssembly.Instance) {
257
+ return { instance, module };
258
+
259
+ } else {
260
+ return instance;
261
+ }
262
+ }
263
+ }
264
+
265
+ function __wbg_get_imports() {
266
+ const imports = {};
267
+ imports.wbg = {};
268
+ imports.wbg.__wbg_BigInt_7bf8b8b2f99c431a = function() { return handleError(function (arg0) {
269
+ const ret = BigInt(arg0);
270
+ return ret;
271
+ }, arguments) };
272
+ imports.wbg.__wbg___wbindgen_is_function_ee8a6c5833c90377 = function(arg0) {
273
+ const ret = typeof(arg0) === 'function';
274
+ return ret;
275
+ };
276
+ imports.wbg.__wbg___wbindgen_is_object_c818261d21f283a4 = function(arg0) {
277
+ const val = arg0;
278
+ const ret = typeof(val) === 'object' && val !== null;
279
+ return ret;
280
+ };
281
+ imports.wbg.__wbg___wbindgen_is_string_fbb76cb2940daafd = function(arg0) {
282
+ const ret = typeof(arg0) === 'string';
283
+ return ret;
284
+ };
285
+ imports.wbg.__wbg___wbindgen_is_undefined_2d472862bd29a478 = function(arg0) {
286
+ const ret = arg0 === undefined;
287
+ return ret;
288
+ };
289
+ imports.wbg.__wbg___wbindgen_throw_b855445ff6a94295 = function(arg0, arg1) {
290
+ throw new Error(getStringFromWasm0(arg0, arg1));
291
+ };
292
+ imports.wbg.__wbg_call_525440f72fbfc0ea = function() { return handleError(function (arg0, arg1, arg2) {
293
+ const ret = arg0.call(arg1, arg2);
294
+ return ret;
295
+ }, arguments) };
296
+ imports.wbg.__wbg_call_e762c39fa8ea36bf = function() { return handleError(function (arg0, arg1) {
297
+ const ret = arg0.call(arg1);
298
+ return ret;
299
+ }, arguments) };
300
+ imports.wbg.__wbg_crypto_574e78ad8b13b65f = function(arg0) {
301
+ const ret = arg0.crypto;
302
+ return ret;
303
+ };
304
+ imports.wbg.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
305
+ arg0.getRandomValues(arg1);
306
+ }, arguments) };
307
+ imports.wbg.__wbg_length_69bca3cb64fc8748 = function(arg0) {
308
+ const ret = arg0.length;
309
+ return ret;
310
+ };
311
+ imports.wbg.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) {
312
+ const ret = arg0.msCrypto;
313
+ return ret;
314
+ };
315
+ imports.wbg.__wbg_new_1acc0b6eea89d040 = function() {
316
+ const ret = new Object();
317
+ return ret;
318
+ };
319
+ imports.wbg.__wbg_new_e17d9f43105b08be = function() {
320
+ const ret = new Array();
321
+ return ret;
322
+ };
323
+ imports.wbg.__wbg_new_no_args_ee98eee5275000a4 = function(arg0, arg1) {
324
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
325
+ return ret;
326
+ };
327
+ imports.wbg.__wbg_new_with_length_01aa0dc35aa13543 = function(arg0) {
328
+ const ret = new Uint8Array(arg0 >>> 0);
329
+ return ret;
330
+ };
331
+ imports.wbg.__wbg_node_905d3e251edff8a2 = function(arg0) {
332
+ const ret = arg0.node;
333
+ return ret;
334
+ };
335
+ imports.wbg.__wbg_parse_2a704d6b78abb2b8 = function() { return handleError(function (arg0, arg1) {
336
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
337
+ return ret;
338
+ }, arguments) };
339
+ imports.wbg.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
340
+ const ret = arg0.process;
341
+ return ret;
342
+ };
343
+ imports.wbg.__wbg_prototypesetcall_2a6620b6922694b2 = function(arg0, arg1, arg2) {
344
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
345
+ };
346
+ imports.wbg.__wbg_push_df81a39d04db858c = function(arg0, arg1) {
347
+ const ret = arg0.push(arg1);
348
+ return ret;
349
+ };
350
+ imports.wbg.__wbg_randomFillSync_ac0988aba3254290 = function() { return handleError(function (arg0, arg1) {
351
+ arg0.randomFillSync(arg1);
352
+ }, arguments) };
353
+ imports.wbg.__wbg_require_60cc747a6bc5215a = function() { return handleError(function () {
354
+ const ret = module.require;
355
+ return ret;
356
+ }, arguments) };
357
+ imports.wbg.__wbg_set_c2abbebe8b9ebee1 = function() { return handleError(function (arg0, arg1, arg2) {
358
+ const ret = Reflect.set(arg0, arg1, arg2);
359
+ return ret;
360
+ }, arguments) };
361
+ imports.wbg.__wbg_static_accessor_GLOBAL_89e1d9ac6a1b250e = function() {
362
+ const ret = typeof global === 'undefined' ? null : global;
363
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
364
+ };
365
+ imports.wbg.__wbg_static_accessor_GLOBAL_THIS_8b530f326a9e48ac = function() {
366
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
367
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
368
+ };
369
+ imports.wbg.__wbg_static_accessor_SELF_6fdf4b64710cc91b = function() {
370
+ const ret = typeof self === 'undefined' ? null : self;
371
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
372
+ };
373
+ imports.wbg.__wbg_static_accessor_WINDOW_b45bfc5a37f6cfa2 = function() {
374
+ const ret = typeof window === 'undefined' ? null : window;
375
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
376
+ };
377
+ imports.wbg.__wbg_subarray_480600f3d6a9f26c = function(arg0, arg1, arg2) {
378
+ const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
379
+ return ret;
380
+ };
381
+ imports.wbg.__wbg_versions_c01dfd4722a88165 = function(arg0) {
382
+ const ret = arg0.versions;
383
+ return ret;
384
+ };
385
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
386
+ // Cast intrinsic for `Ref(String) -> Externref`.
387
+ const ret = getStringFromWasm0(arg0, arg1);
388
+ return ret;
389
+ };
390
+ imports.wbg.__wbindgen_cast_cb9088102bce6b30 = function(arg0, arg1) {
391
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
392
+ const ret = getArrayU8FromWasm0(arg0, arg1);
393
+ return ret;
394
+ };
395
+ imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
396
+ // Cast intrinsic for `F64 -> Externref`.
397
+ const ret = arg0;
398
+ return ret;
399
+ };
400
+ imports.wbg.__wbindgen_init_externref_table = function() {
401
+ const table = wasm.__wbindgen_externrefs;
402
+ const offset = table.grow(4);
403
+ table.set(0, undefined);
404
+ table.set(offset + 0, undefined);
405
+ table.set(offset + 1, null);
406
+ table.set(offset + 2, true);
407
+ table.set(offset + 3, false);
408
+ ;
409
+ };
410
+
411
+ return imports;
412
+ }
413
+
414
+ function __wbg_finalize_init(instance, module) {
415
+ wasm = instance.exports;
416
+ __wbg_init.__wbindgen_wasm_module = module;
417
+ cachedBigUint64ArrayMemory0 = null;
418
+ cachedUint8ArrayMemory0 = null;
419
+
420
+
421
+ wasm.__wbindgen_start();
422
+ return wasm;
423
+ }
424
+
425
+ function initSync(module) {
426
+ if (wasm !== undefined) return wasm;
427
+
428
+
429
+ if (typeof module !== 'undefined') {
430
+ if (Object.getPrototypeOf(module) === Object.prototype) {
431
+ ({module} = module)
432
+ } else {
433
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
434
+ }
435
+ }
436
+
437
+ const imports = __wbg_get_imports();
438
+
439
+ if (!(module instanceof WebAssembly.Module)) {
440
+ module = new WebAssembly.Module(module);
441
+ }
442
+
443
+ const instance = new WebAssembly.Instance(module, imports);
444
+
445
+ return __wbg_finalize_init(instance, module);
446
+ }
447
+
448
+ async function __wbg_init(module_or_path) {
449
+ if (wasm !== undefined) return wasm;
450
+
451
+
452
+ if (typeof module_or_path !== 'undefined') {
453
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
454
+ ({module_or_path} = module_or_path)
455
+ } else {
456
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
457
+ }
458
+ }
459
+
460
+ if (typeof module_or_path === 'undefined') {
461
+ /* wasm URL disabled: load via @crisp-e3/zk-inputs/init */
462
+ }
463
+ const imports = __wbg_get_imports();
464
+
465
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
466
+ module_or_path = fetch(module_or_path);
467
+ }
468
+
469
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
470
+
471
+ return __wbg_finalize_init(instance, module);
472
+ }
473
+
474
+ export { initSync };
475
+ export default __wbg_init;