@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.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # Wasm bundle for crisp-zk-inputs
2
+
3
+ Here we export wasm functionality for consumption in TypeScript to enable us to share code between Rust and TypeScript.
4
+
5
+ ## Usage
6
+
7
+ This package exposes an `init` subpackage default function which should be used to universally load the wasm module instead of exporting the default loader.
8
+
9
+ This is because in modern node there is no need for preloading however in the browser we still need to load the wasm bundle.
10
+
11
+ ### ❌ DONT USE THE DEFAULT INIT
12
+
13
+ ```ts
14
+ // Bad! Because this uses the raw loader which doesn't exist in node contexts
15
+ import init, { bfvEncryptNumber } from "@crisp-e3/zk-inputs";
16
+ ```
17
+
18
+ ### ✅ DO USE THE EXPORTED SUBMODULE
19
+
20
+ ```ts
21
+ // Good! Use the universal loader
22
+ import init from "@crisp-e3/zk-inputs/init";
23
+
24
+ await init();
25
+ // other package imports here
26
+ ```
@@ -1,8 +1,6 @@
1
- let wasm;
2
- export function __wbg_set_wasm(val) {
3
- wasm = val;
4
- }
5
1
 
2
+ let imports = {};
3
+ imports['__wbindgen_placeholder__'] = module.exports;
6
4
 
7
5
  function addToExternrefTable0(obj) {
8
6
  const idx = wasm.__externref_table_alloc();
@@ -32,15 +30,7 @@ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true
32
30
 
33
31
  cachedTextDecoder.decode();
34
32
 
35
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
36
- let numBytesDecoded = 0;
37
33
  function decodeText(ptr, len) {
38
- numBytesDecoded += len;
39
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
40
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
41
- cachedTextDecoder.decode();
42
- numBytesDecoded = len;
43
- }
44
34
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
45
35
  }
46
36
 
@@ -95,7 +85,7 @@ const ZKInputsGeneratorFinalization = (typeof FinalizationRegistry === 'undefine
95
85
  /**
96
86
  * JavaScript-compatible CRISP ZK inputs generator.
97
87
  */
98
- export class ZKInputsGenerator {
88
+ class ZKInputsGenerator {
99
89
 
100
90
  static __wrap(ptr) {
101
91
  ptr = ptr >>> 0;
@@ -231,172 +221,174 @@ export class ZKInputsGenerator {
231
221
  }
232
222
  if (Symbol.dispose) ZKInputsGenerator.prototype[Symbol.dispose] = ZKInputsGenerator.prototype.free;
233
223
 
234
- export function __wbg_BigInt_7bf8b8b2f99c431a() { return handleError(function (arg0) {
224
+ exports.ZKInputsGenerator = ZKInputsGenerator;
225
+
226
+ exports.__wbg_BigInt_7bf8b8b2f99c431a = function() { return handleError(function (arg0) {
235
227
  const ret = BigInt(arg0);
236
228
  return ret;
237
229
  }, arguments) };
238
230
 
239
- export function __wbg___wbindgen_is_function_ee8a6c5833c90377(arg0) {
231
+ exports.__wbg___wbindgen_is_function_ee8a6c5833c90377 = function(arg0) {
240
232
  const ret = typeof(arg0) === 'function';
241
233
  return ret;
242
234
  };
243
235
 
244
- export function __wbg___wbindgen_is_object_c818261d21f283a4(arg0) {
236
+ exports.__wbg___wbindgen_is_object_c818261d21f283a4 = function(arg0) {
245
237
  const val = arg0;
246
238
  const ret = typeof(val) === 'object' && val !== null;
247
239
  return ret;
248
240
  };
249
241
 
250
- export function __wbg___wbindgen_is_string_fbb76cb2940daafd(arg0) {
242
+ exports.__wbg___wbindgen_is_string_fbb76cb2940daafd = function(arg0) {
251
243
  const ret = typeof(arg0) === 'string';
252
244
  return ret;
253
245
  };
254
246
 
255
- export function __wbg___wbindgen_is_undefined_2d472862bd29a478(arg0) {
247
+ exports.__wbg___wbindgen_is_undefined_2d472862bd29a478 = function(arg0) {
256
248
  const ret = arg0 === undefined;
257
249
  return ret;
258
250
  };
259
251
 
260
- export function __wbg___wbindgen_throw_b855445ff6a94295(arg0, arg1) {
252
+ exports.__wbg___wbindgen_throw_b855445ff6a94295 = function(arg0, arg1) {
261
253
  throw new Error(getStringFromWasm0(arg0, arg1));
262
254
  };
263
255
 
264
- export function __wbg_call_525440f72fbfc0ea() { return handleError(function (arg0, arg1, arg2) {
256
+ exports.__wbg_call_525440f72fbfc0ea = function() { return handleError(function (arg0, arg1, arg2) {
265
257
  const ret = arg0.call(arg1, arg2);
266
258
  return ret;
267
259
  }, arguments) };
268
260
 
269
- export function __wbg_call_e762c39fa8ea36bf() { return handleError(function (arg0, arg1) {
261
+ exports.__wbg_call_e762c39fa8ea36bf = function() { return handleError(function (arg0, arg1) {
270
262
  const ret = arg0.call(arg1);
271
263
  return ret;
272
264
  }, arguments) };
273
265
 
274
- export function __wbg_crypto_574e78ad8b13b65f(arg0) {
266
+ exports.__wbg_crypto_574e78ad8b13b65f = function(arg0) {
275
267
  const ret = arg0.crypto;
276
268
  return ret;
277
269
  };
278
270
 
279
- export function __wbg_getRandomValues_b8f5dbd5f3995a9e() { return handleError(function (arg0, arg1) {
271
+ exports.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
280
272
  arg0.getRandomValues(arg1);
281
273
  }, arguments) };
282
274
 
283
- export function __wbg_length_69bca3cb64fc8748(arg0) {
275
+ exports.__wbg_length_69bca3cb64fc8748 = function(arg0) {
284
276
  const ret = arg0.length;
285
277
  return ret;
286
278
  };
287
279
 
288
- export function __wbg_msCrypto_a61aeb35a24c1329(arg0) {
280
+ exports.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) {
289
281
  const ret = arg0.msCrypto;
290
282
  return ret;
291
283
  };
292
284
 
293
- export function __wbg_new_1acc0b6eea89d040() {
285
+ exports.__wbg_new_1acc0b6eea89d040 = function() {
294
286
  const ret = new Object();
295
287
  return ret;
296
288
  };
297
289
 
298
- export function __wbg_new_e17d9f43105b08be() {
290
+ exports.__wbg_new_e17d9f43105b08be = function() {
299
291
  const ret = new Array();
300
292
  return ret;
301
293
  };
302
294
 
303
- export function __wbg_new_no_args_ee98eee5275000a4(arg0, arg1) {
295
+ exports.__wbg_new_no_args_ee98eee5275000a4 = function(arg0, arg1) {
304
296
  const ret = new Function(getStringFromWasm0(arg0, arg1));
305
297
  return ret;
306
298
  };
307
299
 
308
- export function __wbg_new_with_length_01aa0dc35aa13543(arg0) {
300
+ exports.__wbg_new_with_length_01aa0dc35aa13543 = function(arg0) {
309
301
  const ret = new Uint8Array(arg0 >>> 0);
310
302
  return ret;
311
303
  };
312
304
 
313
- export function __wbg_node_905d3e251edff8a2(arg0) {
305
+ exports.__wbg_node_905d3e251edff8a2 = function(arg0) {
314
306
  const ret = arg0.node;
315
307
  return ret;
316
308
  };
317
309
 
318
- export function __wbg_parse_2a704d6b78abb2b8() { return handleError(function (arg0, arg1) {
310
+ exports.__wbg_parse_2a704d6b78abb2b8 = function() { return handleError(function (arg0, arg1) {
319
311
  const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
320
312
  return ret;
321
313
  }, arguments) };
322
314
 
323
- export function __wbg_process_dc0fbacc7c1c06f7(arg0) {
315
+ exports.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
324
316
  const ret = arg0.process;
325
317
  return ret;
326
318
  };
327
319
 
328
- export function __wbg_prototypesetcall_2a6620b6922694b2(arg0, arg1, arg2) {
320
+ exports.__wbg_prototypesetcall_2a6620b6922694b2 = function(arg0, arg1, arg2) {
329
321
  Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
330
322
  };
331
323
 
332
- export function __wbg_push_df81a39d04db858c(arg0, arg1) {
324
+ exports.__wbg_push_df81a39d04db858c = function(arg0, arg1) {
333
325
  const ret = arg0.push(arg1);
334
326
  return ret;
335
327
  };
336
328
 
337
- export function __wbg_randomFillSync_ac0988aba3254290() { return handleError(function (arg0, arg1) {
329
+ exports.__wbg_randomFillSync_ac0988aba3254290 = function() { return handleError(function (arg0, arg1) {
338
330
  arg0.randomFillSync(arg1);
339
331
  }, arguments) };
340
332
 
341
- export function __wbg_require_60cc747a6bc5215a() { return handleError(function () {
333
+ exports.__wbg_require_60cc747a6bc5215a = function() { return handleError(function () {
342
334
  const ret = module.require;
343
335
  return ret;
344
336
  }, arguments) };
345
337
 
346
- export function __wbg_set_c2abbebe8b9ebee1() { return handleError(function (arg0, arg1, arg2) {
338
+ exports.__wbg_set_c2abbebe8b9ebee1 = function() { return handleError(function (arg0, arg1, arg2) {
347
339
  const ret = Reflect.set(arg0, arg1, arg2);
348
340
  return ret;
349
341
  }, arguments) };
350
342
 
351
- export function __wbg_static_accessor_GLOBAL_89e1d9ac6a1b250e() {
343
+ exports.__wbg_static_accessor_GLOBAL_89e1d9ac6a1b250e = function() {
352
344
  const ret = typeof global === 'undefined' ? null : global;
353
345
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
354
346
  };
355
347
 
356
- export function __wbg_static_accessor_GLOBAL_THIS_8b530f326a9e48ac() {
348
+ exports.__wbg_static_accessor_GLOBAL_THIS_8b530f326a9e48ac = function() {
357
349
  const ret = typeof globalThis === 'undefined' ? null : globalThis;
358
350
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
359
351
  };
360
352
 
361
- export function __wbg_static_accessor_SELF_6fdf4b64710cc91b() {
353
+ exports.__wbg_static_accessor_SELF_6fdf4b64710cc91b = function() {
362
354
  const ret = typeof self === 'undefined' ? null : self;
363
355
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
364
356
  };
365
357
 
366
- export function __wbg_static_accessor_WINDOW_b45bfc5a37f6cfa2() {
358
+ exports.__wbg_static_accessor_WINDOW_b45bfc5a37f6cfa2 = function() {
367
359
  const ret = typeof window === 'undefined' ? null : window;
368
360
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
369
361
  };
370
362
 
371
- export function __wbg_subarray_480600f3d6a9f26c(arg0, arg1, arg2) {
363
+ exports.__wbg_subarray_480600f3d6a9f26c = function(arg0, arg1, arg2) {
372
364
  const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
373
365
  return ret;
374
366
  };
375
367
 
376
- export function __wbg_versions_c01dfd4722a88165(arg0) {
368
+ exports.__wbg_versions_c01dfd4722a88165 = function(arg0) {
377
369
  const ret = arg0.versions;
378
370
  return ret;
379
371
  };
380
372
 
381
- export function __wbindgen_cast_2241b6af4c4b2941(arg0, arg1) {
373
+ exports.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
382
374
  // Cast intrinsic for `Ref(String) -> Externref`.
383
375
  const ret = getStringFromWasm0(arg0, arg1);
384
376
  return ret;
385
377
  };
386
378
 
387
- export function __wbindgen_cast_cb9088102bce6b30(arg0, arg1) {
379
+ exports.__wbindgen_cast_cb9088102bce6b30 = function(arg0, arg1) {
388
380
  // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
389
381
  const ret = getArrayU8FromWasm0(arg0, arg1);
390
382
  return ret;
391
383
  };
392
384
 
393
- export function __wbindgen_cast_d6cd19b81560fd6e(arg0) {
385
+ exports.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
394
386
  // Cast intrinsic for `F64 -> Externref`.
395
387
  const ret = arg0;
396
388
  return ret;
397
389
  };
398
390
 
399
- export function __wbindgen_init_externref_table() {
391
+ exports.__wbindgen_init_externref_table = function() {
400
392
  const table = wasm.__wbindgen_externrefs;
401
393
  const offset = table.grow(4);
402
394
  table.set(0, undefined);
@@ -407,3 +399,10 @@ export function __wbindgen_init_externref_table() {
407
399
  ;
408
400
  };
409
401
 
402
+ const wasmPath = `${__dirname}/index_bg.wasm`;
403
+ const wasmBytes = require('fs').readFileSync(wasmPath);
404
+ const wasmModule = new WebAssembly.Module(wasmBytes);
405
+ const wasm = exports.__wasm = new WebAssembly.Instance(wasmModule, imports).exports;
406
+
407
+ wasm.__wbindgen_start();
408
+
Binary file
@@ -0,0 +1,18 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_zkinputsgenerator_free: (a: number, b: number) => void;
5
+ export const zkinputsgenerator_new: (a: number, b: bigint, c: number, d: number) => [number, number, number];
6
+ export const zkinputsgenerator_withDefaults: () => [number, number, number];
7
+ export const zkinputsgenerator_generateInputs: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
8
+ export const zkinputsgenerator_generatePublicKey: (a: number) => [number, number, number, number];
9
+ export const zkinputsgenerator_encryptVote: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
10
+ export const zkinputsgenerator_getBFVParams: (a: number) => [number, number, number];
11
+ export const zkinputsgenerator_version: () => [number, number];
12
+ export const __wbindgen_exn_store: (a: number) => void;
13
+ export const __externref_table_alloc: () => number;
14
+ export const __wbindgen_externrefs: WebAssembly.Table;
15
+ export const __wbindgen_malloc: (a: number, b: number) => number;
16
+ export const __externref_table_dealloc: (a: number) => void;
17
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
18
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,84 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * JavaScript-compatible CRISP ZK inputs generator.
5
+ */
6
+ export class ZKInputsGenerator {
7
+ free(): void;
8
+ [Symbol.dispose](): void;
9
+ /**
10
+ * Create a new JavaScript CRISP ZK inputs generator with the specified BFV parameters.
11
+ *
12
+ * # Arguments
13
+ * - `degree`: Polynomial degree
14
+ * - `plaintext_modulus`: Plaintext modulus (will be converted to u64)
15
+ * - `moduli`: Array of moduli (will be converted to Vec<u64>)
16
+ */
17
+ constructor(degree: number, plaintext_modulus: bigint, moduli: BigInt64Array);
18
+ /**
19
+ * Create a new JavaScript CRISP ZK inputs generator with default BFV parameters.
20
+ */
21
+ static withDefaults(): ZKInputsGenerator;
22
+ /**
23
+ * Generate a CRISP ZK inputs from JavaScript.
24
+ */
25
+ generateInputs(prev_ciphertext: Uint8Array, public_key: Uint8Array, vote: BigInt64Array): any;
26
+ /**
27
+ * Generate a public key from JavaScript.
28
+ */
29
+ generatePublicKey(): Uint8Array;
30
+ /**
31
+ * Encrypt a vote from JavaScript.
32
+ */
33
+ encryptVote(public_key: Uint8Array, vote: BigInt64Array): Uint8Array;
34
+ /**
35
+ * Get the BFV parameters used by the generator.
36
+ */
37
+ getBFVParams(): any;
38
+ /**
39
+ * Get the version of the library.
40
+ */
41
+ static version(): string;
42
+ }
43
+
44
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
45
+
46
+ export interface InitOutput {
47
+ readonly memory: WebAssembly.Memory;
48
+ readonly __wbg_zkinputsgenerator_free: (a: number, b: number) => void;
49
+ readonly zkinputsgenerator_new: (a: number, b: bigint, c: number, d: number) => [number, number, number];
50
+ readonly zkinputsgenerator_withDefaults: () => [number, number, number];
51
+ readonly zkinputsgenerator_generateInputs: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
52
+ readonly zkinputsgenerator_generatePublicKey: (a: number) => [number, number, number, number];
53
+ readonly zkinputsgenerator_encryptVote: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
54
+ readonly zkinputsgenerator_getBFVParams: (a: number) => [number, number, number];
55
+ readonly zkinputsgenerator_version: () => [number, number];
56
+ readonly __wbindgen_exn_store: (a: number) => void;
57
+ readonly __externref_table_alloc: () => number;
58
+ readonly __wbindgen_externrefs: WebAssembly.Table;
59
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
60
+ readonly __externref_table_dealloc: (a: number) => void;
61
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
62
+ readonly __wbindgen_start: () => void;
63
+ }
64
+
65
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
66
+ /**
67
+ * Instantiates the given `module`, which can either be bytes or
68
+ * a precompiled `WebAssembly.Module`.
69
+ *
70
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
71
+ *
72
+ * @returns {InitOutput}
73
+ */
74
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
75
+
76
+ /**
77
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
78
+ * for everything else, calls `WebAssembly.instantiate` directly.
79
+ *
80
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
81
+ *
82
+ * @returns {Promise<InitOutput>}
83
+ */
84
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;