@crisp-e3/zk-inputs 0.4.2 → 0.5.3

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/dist/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
- /**
4
- * JavaScript-compatible CRISP ZK inputs generator.
5
- */
3
+
6
4
  export class ZKInputsGenerator {
7
5
  free(): void;
8
6
  [Symbol.dispose](): void;
@@ -20,9 +18,13 @@ export class ZKInputsGenerator {
20
18
  */
21
19
  static withDefaults(): ZKInputsGenerator;
22
20
  /**
23
- * Generate a CRISP ZK inputs from JavaScript.
21
+ * Generate CRISP ZK inputs from JavaScript.
24
22
  */
25
23
  generateInputs(prev_ciphertext: Uint8Array, public_key: Uint8Array, vote: BigInt64Array): any;
24
+ /**
25
+ * Generate CRISP ZK inputs for a vote update (either from voter or as a masker) from JavaScript.
26
+ */
27
+ generateInputsForUpdate(prev_ciphertext: Uint8Array, public_key: Uint8Array, vote: BigInt64Array): any;
26
28
  /**
27
29
  * Generate a public key from JavaScript.
28
30
  */
@@ -49,6 +51,7 @@ export interface InitOutput {
49
51
  readonly zkinputsgenerator_new: (a: number, b: bigint, c: number, d: number) => [number, number, number];
50
52
  readonly zkinputsgenerator_withDefaults: () => [number, number, number];
51
53
  readonly zkinputsgenerator_generateInputs: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
54
+ readonly zkinputsgenerator_generateInputsForUpdate: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
52
55
  readonly zkinputsgenerator_generatePublicKey: (a: number) => [number, number, number, number];
53
56
  readonly zkinputsgenerator_encryptVote: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
54
57
  readonly zkinputsgenerator_getBFVParams: (a: number) => [number, number, number];
@@ -63,6 +66,7 @@ export interface InitOutput {
63
66
  }
64
67
 
65
68
  export type SyncInitInput = BufferSource | WebAssembly.Module;
69
+
66
70
  /**
67
71
  * Instantiates the given `module`, which can either be bytes or
68
72
  * a precompiled `WebAssembly.Module`.
package/dist/index.js CHANGED
@@ -6,17 +6,25 @@ function addToExternrefTable0(obj) {
6
6
  return idx;
7
7
  }
8
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);
9
+ function getArrayU8FromWasm0(ptr, len) {
10
+ ptr = ptr >>> 0;
11
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
12
+ }
13
+
14
+ let cachedBigUint64ArrayMemory0 = null;
15
+ function getBigUint64ArrayMemory0() {
16
+ if (cachedBigUint64ArrayMemory0 === null || cachedBigUint64ArrayMemory0.byteLength === 0) {
17
+ cachedBigUint64ArrayMemory0 = new BigUint64Array(wasm.memory.buffer);
15
18
  }
19
+ return cachedBigUint64ArrayMemory0;
16
20
  }
17
21
 
18
- let cachedUint8ArrayMemory0 = null;
22
+ function getStringFromWasm0(ptr, len) {
23
+ ptr = ptr >>> 0;
24
+ return decodeText(ptr, len);
25
+ }
19
26
 
27
+ let cachedUint8ArrayMemory0 = null;
20
28
  function getUint8ArrayMemory0() {
21
29
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
22
30
  cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
@@ -24,47 +32,19 @@ function getUint8ArrayMemory0() {
24
32
  return cachedUint8ArrayMemory0;
25
33
  }
26
34
 
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;
35
+ function handleError(f, args) {
36
+ try {
37
+ return f.apply(this, args);
38
+ } catch (e) {
39
+ const idx = addToExternrefTable0(e);
40
+ wasm.__wbindgen_exn_store(idx);
39
41
  }
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
42
  }
52
43
 
53
44
  function isLikeNone(x) {
54
45
  return x === undefined || x === null;
55
46
  }
56
47
 
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
48
  function passArray64ToWasm0(arg, malloc) {
69
49
  const ptr = malloc(arg.length * 8, 8) >>> 0;
70
50
  getBigUint64ArrayMemory0().set(arg, ptr / 8);
@@ -72,27 +52,43 @@ function passArray64ToWasm0(arg, malloc) {
72
52
  return ptr;
73
53
  }
74
54
 
55
+ function passArray8ToWasm0(arg, malloc) {
56
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
57
+ getUint8ArrayMemory0().set(arg, ptr / 1);
58
+ WASM_VECTOR_LEN = arg.length;
59
+ return ptr;
60
+ }
61
+
75
62
  function takeFromExternrefTable0(idx) {
76
63
  const value = wasm.__wbindgen_externrefs.get(idx);
77
64
  wasm.__externref_table_dealloc(idx);
78
65
  return value;
79
66
  }
80
67
 
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;
68
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
69
+ cachedTextDecoder.decode();
70
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
71
+ let numBytesDecoded = 0;
72
+ function decodeText(ptr, len) {
73
+ numBytesDecoded += len;
74
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
75
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
76
+ cachedTextDecoder.decode();
77
+ numBytesDecoded = len;
78
+ }
79
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
86
80
  }
87
81
 
82
+ let WASM_VECTOR_LEN = 0;
83
+
88
84
  const ZKInputsGeneratorFinalization = (typeof FinalizationRegistry === 'undefined')
89
85
  ? { register: () => {}, unregister: () => {} }
90
86
  : new FinalizationRegistry(ptr => wasm.__wbg_zkinputsgenerator_free(ptr >>> 0, 1));
87
+
91
88
  /**
92
89
  * JavaScript-compatible CRISP ZK inputs generator.
93
90
  */
94
91
  export class ZKInputsGenerator {
95
-
96
92
  static __wrap(ptr) {
97
93
  ptr = ptr >>> 0;
98
94
  const obj = Object.create(ZKInputsGenerator.prototype);
@@ -100,14 +96,12 @@ export class ZKInputsGenerator {
100
96
  ZKInputsGeneratorFinalization.register(obj, obj.__wbg_ptr, obj);
101
97
  return obj;
102
98
  }
103
-
104
99
  __destroy_into_raw() {
105
100
  const ptr = this.__wbg_ptr;
106
101
  this.__wbg_ptr = 0;
107
102
  ZKInputsGeneratorFinalization.unregister(this);
108
103
  return ptr;
109
104
  }
110
-
111
105
  free() {
112
106
  const ptr = this.__destroy_into_raw();
113
107
  wasm.__wbg_zkinputsgenerator_free(ptr, 0);
@@ -146,7 +140,7 @@ export class ZKInputsGenerator {
146
140
  return ZKInputsGenerator.__wrap(ret[0]);
147
141
  }
148
142
  /**
149
- * Generate a CRISP ZK inputs from JavaScript.
143
+ * Generate CRISP ZK inputs from JavaScript.
150
144
  * @param {Uint8Array} prev_ciphertext
151
145
  * @param {Uint8Array} public_key
152
146
  * @param {BigInt64Array} vote
@@ -165,6 +159,26 @@ export class ZKInputsGenerator {
165
159
  }
166
160
  return takeFromExternrefTable0(ret[0]);
167
161
  }
162
+ /**
163
+ * Generate CRISP ZK inputs for a vote update (either from voter or as a masker) from JavaScript.
164
+ * @param {Uint8Array} prev_ciphertext
165
+ * @param {Uint8Array} public_key
166
+ * @param {BigInt64Array} vote
167
+ * @returns {any}
168
+ */
169
+ generateInputsForUpdate(prev_ciphertext, public_key, vote) {
170
+ const ptr0 = passArray8ToWasm0(prev_ciphertext, wasm.__wbindgen_malloc);
171
+ const len0 = WASM_VECTOR_LEN;
172
+ const ptr1 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
173
+ const len1 = WASM_VECTOR_LEN;
174
+ const ptr2 = passArray64ToWasm0(vote, wasm.__wbindgen_malloc);
175
+ const len2 = WASM_VECTOR_LEN;
176
+ const ret = wasm.zkinputsgenerator_generateInputsForUpdate(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
177
+ if (ret[2]) {
178
+ throw takeFromExternrefTable0(ret[1]);
179
+ }
180
+ return takeFromExternrefTable0(ret[0]);
181
+ }
168
182
  /**
169
183
  * Generate a public key from JavaScript.
170
184
  * @returns {Uint8Array}
@@ -234,7 +248,6 @@ async function __wbg_load(module, imports) {
234
248
  if (typeof WebAssembly.instantiateStreaming === 'function') {
235
249
  try {
236
250
  return await WebAssembly.instantiateStreaming(module, imports);
237
-
238
251
  } catch (e) {
239
252
  const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
240
253
 
@@ -249,13 +262,11 @@ async function __wbg_load(module, imports) {
249
262
 
250
263
  const bytes = await module.arrayBuffer();
251
264
  return await WebAssembly.instantiate(bytes, imports);
252
-
253
265
  } else {
254
266
  const instance = await WebAssembly.instantiate(module, imports);
255
267
 
256
268
  if (instance instanceof WebAssembly.Instance) {
257
269
  return { instance, module };
258
-
259
270
  } else {
260
271
  return instance;
261
272
  }
@@ -265,35 +276,35 @@ async function __wbg_load(module, imports) {
265
276
  function __wbg_get_imports() {
266
277
  const imports = {};
267
278
  imports.wbg = {};
268
- imports.wbg.__wbg_BigInt_7bf8b8b2f99c431a = function() { return handleError(function (arg0) {
279
+ imports.wbg.__wbg_BigInt_811579177bbea12d = function() { return handleError(function (arg0) {
269
280
  const ret = BigInt(arg0);
270
281
  return ret;
271
282
  }, arguments) };
272
- imports.wbg.__wbg___wbindgen_is_function_ee8a6c5833c90377 = function(arg0) {
283
+ imports.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd = function(arg0) {
273
284
  const ret = typeof(arg0) === 'function';
274
285
  return ret;
275
286
  };
276
- imports.wbg.__wbg___wbindgen_is_object_c818261d21f283a4 = function(arg0) {
287
+ imports.wbg.__wbg___wbindgen_is_object_ce774f3490692386 = function(arg0) {
277
288
  const val = arg0;
278
289
  const ret = typeof(val) === 'object' && val !== null;
279
290
  return ret;
280
291
  };
281
- imports.wbg.__wbg___wbindgen_is_string_fbb76cb2940daafd = function(arg0) {
292
+ imports.wbg.__wbg___wbindgen_is_string_704ef9c8fc131030 = function(arg0) {
282
293
  const ret = typeof(arg0) === 'string';
283
294
  return ret;
284
295
  };
285
- imports.wbg.__wbg___wbindgen_is_undefined_2d472862bd29a478 = function(arg0) {
296
+ imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
286
297
  const ret = arg0 === undefined;
287
298
  return ret;
288
299
  };
289
- imports.wbg.__wbg___wbindgen_throw_b855445ff6a94295 = function(arg0, arg1) {
300
+ imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
290
301
  throw new Error(getStringFromWasm0(arg0, arg1));
291
302
  };
292
- imports.wbg.__wbg_call_525440f72fbfc0ea = function() { return handleError(function (arg0, arg1, arg2) {
303
+ imports.wbg.__wbg_call_3020136f7a2d6e44 = function() { return handleError(function (arg0, arg1, arg2) {
293
304
  const ret = arg0.call(arg1, arg2);
294
305
  return ret;
295
306
  }, arguments) };
296
- imports.wbg.__wbg_call_e762c39fa8ea36bf = function() { return handleError(function (arg0, arg1) {
307
+ imports.wbg.__wbg_call_abb4ff46ce38be40 = function() { return handleError(function (arg0, arg1) {
297
308
  const ret = arg0.call(arg1);
298
309
  return ret;
299
310
  }, arguments) };
@@ -304,7 +315,7 @@ function __wbg_get_imports() {
304
315
  imports.wbg.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
305
316
  arg0.getRandomValues(arg1);
306
317
  }, arguments) };
307
- imports.wbg.__wbg_length_69bca3cb64fc8748 = function(arg0) {
318
+ imports.wbg.__wbg_length_22ac23eaec9d8053 = function(arg0) {
308
319
  const ret = arg0.length;
309
320
  return ret;
310
321
  };
@@ -312,19 +323,19 @@ function __wbg_get_imports() {
312
323
  const ret = arg0.msCrypto;
313
324
  return ret;
314
325
  };
315
- imports.wbg.__wbg_new_1acc0b6eea89d040 = function() {
326
+ imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
316
327
  const ret = new Object();
317
328
  return ret;
318
329
  };
319
- imports.wbg.__wbg_new_e17d9f43105b08be = function() {
330
+ imports.wbg.__wbg_new_25f239778d6112b9 = function() {
320
331
  const ret = new Array();
321
332
  return ret;
322
333
  };
323
- imports.wbg.__wbg_new_no_args_ee98eee5275000a4 = function(arg0, arg1) {
334
+ imports.wbg.__wbg_new_no_args_cb138f77cf6151ee = function(arg0, arg1) {
324
335
  const ret = new Function(getStringFromWasm0(arg0, arg1));
325
336
  return ret;
326
337
  };
327
- imports.wbg.__wbg_new_with_length_01aa0dc35aa13543 = function(arg0) {
338
+ imports.wbg.__wbg_new_with_length_aa5eaf41d35235e5 = function(arg0) {
328
339
  const ret = new Uint8Array(arg0 >>> 0);
329
340
  return ret;
330
341
  };
@@ -332,7 +343,7 @@ function __wbg_get_imports() {
332
343
  const ret = arg0.node;
333
344
  return ret;
334
345
  };
335
- imports.wbg.__wbg_parse_2a704d6b78abb2b8 = function() { return handleError(function (arg0, arg1) {
346
+ imports.wbg.__wbg_parse_a09a54cf72639456 = function() { return handleError(function (arg0, arg1) {
336
347
  const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
337
348
  return ret;
338
349
  }, arguments) };
@@ -340,10 +351,10 @@ function __wbg_get_imports() {
340
351
  const ret = arg0.process;
341
352
  return ret;
342
353
  };
343
- imports.wbg.__wbg_prototypesetcall_2a6620b6922694b2 = function(arg0, arg1, arg2) {
354
+ imports.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd = function(arg0, arg1, arg2) {
344
355
  Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
345
356
  };
346
- imports.wbg.__wbg_push_df81a39d04db858c = function(arg0, arg1) {
357
+ imports.wbg.__wbg_push_7d9be8f38fc13975 = function(arg0, arg1) {
347
358
  const ret = arg0.push(arg1);
348
359
  return ret;
349
360
  };
@@ -354,27 +365,27 @@ function __wbg_get_imports() {
354
365
  const ret = module.require;
355
366
  return ret;
356
367
  }, arguments) };
357
- imports.wbg.__wbg_set_c2abbebe8b9ebee1 = function() { return handleError(function (arg0, arg1, arg2) {
368
+ imports.wbg.__wbg_set_781438a03c0c3c81 = function() { return handleError(function (arg0, arg1, arg2) {
358
369
  const ret = Reflect.set(arg0, arg1, arg2);
359
370
  return ret;
360
371
  }, arguments) };
361
- imports.wbg.__wbg_static_accessor_GLOBAL_89e1d9ac6a1b250e = function() {
372
+ imports.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335 = function() {
362
373
  const ret = typeof global === 'undefined' ? null : global;
363
374
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
364
375
  };
365
- imports.wbg.__wbg_static_accessor_GLOBAL_THIS_8b530f326a9e48ac = function() {
376
+ imports.wbg.__wbg_static_accessor_GLOBAL_THIS_60cf02db4de8e1c1 = function() {
366
377
  const ret = typeof globalThis === 'undefined' ? null : globalThis;
367
378
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
368
379
  };
369
- imports.wbg.__wbg_static_accessor_SELF_6fdf4b64710cc91b = function() {
380
+ imports.wbg.__wbg_static_accessor_SELF_08f5a74c69739274 = function() {
370
381
  const ret = typeof self === 'undefined' ? null : self;
371
382
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
372
383
  };
373
- imports.wbg.__wbg_static_accessor_WINDOW_b45bfc5a37f6cfa2 = function() {
384
+ imports.wbg.__wbg_static_accessor_WINDOW_a8924b26aa92d024 = function() {
374
385
  const ret = typeof window === 'undefined' ? null : window;
375
386
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
376
387
  };
377
- imports.wbg.__wbg_subarray_480600f3d6a9f26c = function(arg0, arg1, arg2) {
388
+ imports.wbg.__wbg_subarray_845f2f5bce7d061a = function(arg0, arg1, arg2) {
378
389
  const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
379
390
  return ret;
380
391
  };
@@ -405,7 +416,6 @@ function __wbg_get_imports() {
405
416
  table.set(offset + 1, null);
406
417
  table.set(offset + 2, true);
407
418
  table.set(offset + 3, false);
408
- ;
409
419
  };
410
420
 
411
421
  return imports;
@@ -435,13 +445,10 @@ function initSync(module) {
435
445
  }
436
446
 
437
447
  const imports = __wbg_get_imports();
438
-
439
448
  if (!(module instanceof WebAssembly.Module)) {
440
449
  module = new WebAssembly.Module(module);
441
450
  }
442
-
443
451
  const instance = new WebAssembly.Instance(module, imports);
444
-
445
452
  return __wbg_finalize_init(instance, module);
446
453
  }
447
454