@crisp-e3/zk-inputs 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -13
- package/dist/index.d.ts +4 -4
- package/dist/index.js +15 -113
- package/dist/index_base64.js +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,29 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @crisp-e3/zk-inputs
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
WASM bindings for generating CRISP ZK proof inputs, compiled from Rust and shared between the
|
|
4
|
+
server-side Node.js environment and the browser. This package lets the CRISP SDK produce the circuit
|
|
5
|
+
witness data needed for Noir-based vote-validity proofs without duplicating the logic in TypeScript.
|
|
6
|
+
|
|
7
|
+
## What it generates
|
|
8
|
+
|
|
9
|
+
The WASM module wraps a `ZKInputsGenerator` class that performs BFV encryption and produces the
|
|
10
|
+
witness data needed for CRISP's Noir circuits. Two main proof types are supported:
|
|
11
|
+
|
|
12
|
+
- **Vote proof** (`generateInputs`) — encrypts a vote under the committee's threshold BFV public key
|
|
13
|
+
and produces a witness proving the vote is correctly encrypted and that the voter is eligible
|
|
14
|
+
(e.g. holds the required token balance, verified via a Merkle membership proof).
|
|
15
|
+
|
|
16
|
+
- **Vote update / mask proof** (`generateInputsForUpdate`) — same structure, but used for revotes or
|
|
17
|
+
masker contributions under the
|
|
18
|
+
[vote masking](https://blog.theinterfold.com/vote-masking-receipt-freeness-secret-ballots/) scheme
|
|
19
|
+
that provides receipt-freeness. Unlike the first-vote path, this preserves the real
|
|
20
|
+
`prev_ct_commitment` (rather than zeroing it) to chain updates together.
|
|
21
|
+
|
|
22
|
+
The generator also exposes `encryptVote` / `decryptVote` for standalone BFV operations and
|
|
23
|
+
`generateKeys` for key generation.
|
|
24
|
+
|
|
25
|
+
These witness objects are then passed to `@noir-lang/noir_js` and `@aztec/bb.js` to generate the
|
|
26
|
+
actual ZK proofs.
|
|
5
27
|
|
|
6
28
|
## Usage
|
|
7
29
|
|
|
8
|
-
This package
|
|
9
|
-
the wasm module instead of exporting the default loader.
|
|
30
|
+
This package requires a universal init pattern because:
|
|
10
31
|
|
|
11
|
-
|
|
12
|
-
|
|
32
|
+
- In **Node.js** (>=18) WASM can be loaded synchronously — no preloading needed.
|
|
33
|
+
- In the **browser** the WASM binary must be fetched and instantiated asynchronously.
|
|
13
34
|
|
|
14
|
-
|
|
35
|
+
The `init` subpackage handles both environments transparently.
|
|
36
|
+
|
|
37
|
+
### ❌ Don't use the default export
|
|
15
38
|
|
|
16
39
|
```ts
|
|
17
|
-
// Bad
|
|
18
|
-
import init, {
|
|
40
|
+
// Bad — the raw default loader doesn't work in Node.js contexts
|
|
41
|
+
import init, { generateVoteInputs } from '@crisp-e3/zk-inputs'
|
|
19
42
|
```
|
|
20
43
|
|
|
21
|
-
### ✅
|
|
44
|
+
### ✅ Use the universal subpackage loader
|
|
22
45
|
|
|
23
46
|
```ts
|
|
24
|
-
// Good! Use the universal loader
|
|
25
47
|
import init from '@crisp-e3/zk-inputs/init'
|
|
48
|
+
import { generateVoteInputs } from '@crisp-e3/zk-inputs'
|
|
26
49
|
|
|
27
50
|
await init()
|
|
28
|
-
|
|
51
|
+
const inputs = generateVoteInputs(/* ... */)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Call `init()` once before using any other imports from `@crisp-e3/zk-inputs`. In browser
|
|
55
|
+
environments `init()` fetches the WASM binary; in Node.js it is a no-op.
|
|
56
|
+
|
|
57
|
+
## Building
|
|
58
|
+
|
|
59
|
+
The WASM bundle is compiled from the Rust source in `crates/crisp-zk-inputs` using `wasm-pack`:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# From the CRISP root
|
|
63
|
+
pnpm build:wasm
|
|
29
64
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -55,15 +55,15 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
55
55
|
export interface InitOutput {
|
|
56
56
|
readonly memory: WebAssembly.Memory;
|
|
57
57
|
readonly __wbg_zkinputsgenerator_free: (a: number, b: number) => void;
|
|
58
|
-
readonly
|
|
59
|
-
readonly
|
|
58
|
+
readonly zkinputsgenerator_decryptVote: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
59
|
+
readonly zkinputsgenerator_encryptVote: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
60
60
|
readonly zkinputsgenerator_generateInputs: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
|
|
61
61
|
readonly zkinputsgenerator_generateInputsForUpdate: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
|
|
62
62
|
readonly zkinputsgenerator_generateKeys: (a: number) => [number, number, number];
|
|
63
|
-
readonly zkinputsgenerator_encryptVote: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
64
|
-
readonly zkinputsgenerator_decryptVote: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
65
63
|
readonly zkinputsgenerator_getBFVParams: (a: number) => [number, number, number];
|
|
64
|
+
readonly zkinputsgenerator_new: (a: number, b: bigint, c: number, d: number) => [number, number, number];
|
|
66
65
|
readonly zkinputsgenerator_version: () => [number, number];
|
|
66
|
+
readonly zkinputsgenerator_withDefaults: () => [number, number, number];
|
|
67
67
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
68
68
|
readonly __externref_table_alloc: () => number;
|
|
69
69
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export class ZKInputsGenerator {
|
|
7
7
|
static __wrap(ptr) {
|
|
8
|
-
ptr = ptr >>> 0;
|
|
9
8
|
const obj = Object.create(ZKInputsGenerator.prototype);
|
|
10
9
|
obj.__wbg_ptr = ptr;
|
|
11
10
|
ZKInputsGeneratorFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
@@ -139,7 +138,7 @@ export class ZKInputsGenerator {
|
|
|
139
138
|
if (ret[2]) {
|
|
140
139
|
throw takeFromExternrefTable0(ret[1]);
|
|
141
140
|
}
|
|
142
|
-
this.__wbg_ptr = ret[0]
|
|
141
|
+
this.__wbg_ptr = ret[0];
|
|
143
142
|
ZKInputsGeneratorFinalization.register(this, this.__wbg_ptr, this);
|
|
144
143
|
return this;
|
|
145
144
|
}
|
|
@@ -172,142 +171,49 @@ export class ZKInputsGenerator {
|
|
|
172
171
|
}
|
|
173
172
|
}
|
|
174
173
|
if (Symbol.dispose) ZKInputsGenerator.prototype[Symbol.dispose] = ZKInputsGenerator.prototype.free;
|
|
175
|
-
|
|
176
174
|
function __wbg_get_imports() {
|
|
177
175
|
const import0 = {
|
|
178
176
|
__proto__: null,
|
|
179
|
-
|
|
177
|
+
__wbg_BigInt_d576983233c6e0d1: function() { return handleError(function (arg0) {
|
|
180
178
|
const ret = BigInt(arg0);
|
|
181
179
|
return ret;
|
|
182
180
|
}, arguments); },
|
|
183
|
-
|
|
184
|
-
const ret = typeof(arg0) === 'function';
|
|
185
|
-
return ret;
|
|
186
|
-
},
|
|
187
|
-
__wbg___wbindgen_is_object_5ae8e5880f2c1fbd: function(arg0) {
|
|
188
|
-
const val = arg0;
|
|
189
|
-
const ret = typeof(val) === 'object' && val !== null;
|
|
190
|
-
return ret;
|
|
191
|
-
},
|
|
192
|
-
__wbg___wbindgen_is_string_cd444516edc5b180: function(arg0) {
|
|
193
|
-
const ret = typeof(arg0) === 'string';
|
|
194
|
-
return ret;
|
|
195
|
-
},
|
|
196
|
-
__wbg___wbindgen_is_undefined_9e4d92534c42d778: function(arg0) {
|
|
197
|
-
const ret = arg0 === undefined;
|
|
198
|
-
return ret;
|
|
199
|
-
},
|
|
200
|
-
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
181
|
+
__wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
|
|
201
182
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
202
183
|
},
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
return ret;
|
|
206
|
-
}, arguments); },
|
|
207
|
-
__wbg_call_4708e0c13bdc8e95: function() { return handleError(function (arg0, arg1, arg2) {
|
|
208
|
-
const ret = arg0.call(arg1, arg2);
|
|
209
|
-
return ret;
|
|
210
|
-
}, arguments); },
|
|
211
|
-
__wbg_crypto_86f2631e91b51511: function(arg0) {
|
|
212
|
-
const ret = arg0.crypto;
|
|
213
|
-
return ret;
|
|
214
|
-
},
|
|
215
|
-
__wbg_getRandomValues_b3f15fcbfabb0f8b: function() { return handleError(function (arg0, arg1) {
|
|
216
|
-
arg0.getRandomValues(arg1);
|
|
184
|
+
__wbg_getRandomValues_3f44b700395062e5: function() { return handleError(function (arg0, arg1) {
|
|
185
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
217
186
|
}, arguments); },
|
|
218
|
-
|
|
219
|
-
const ret = arg0.length;
|
|
220
|
-
return ret;
|
|
221
|
-
},
|
|
222
|
-
__wbg_msCrypto_d562bbe83e0d4b91: function(arg0) {
|
|
223
|
-
const ret = arg0.msCrypto;
|
|
224
|
-
return ret;
|
|
225
|
-
},
|
|
226
|
-
__wbg_new_361308b2356cecd0: function() {
|
|
187
|
+
__wbg_new_ce1ab61c1c2b300d: function() {
|
|
227
188
|
const ret = new Object();
|
|
228
189
|
return ret;
|
|
229
190
|
},
|
|
230
|
-
|
|
191
|
+
__wbg_new_d90091b82fdf5b91: function() {
|
|
231
192
|
const ret = new Array();
|
|
232
193
|
return ret;
|
|
233
194
|
},
|
|
234
|
-
|
|
195
|
+
__wbg_new_from_slice_18fa1f71286d66b8: function(arg0, arg1) {
|
|
235
196
|
const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
|
|
236
197
|
return ret;
|
|
237
198
|
},
|
|
238
|
-
|
|
239
|
-
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
240
|
-
return ret;
|
|
241
|
-
},
|
|
242
|
-
__wbg_new_with_length_a2c39cbe88fd8ff1: function(arg0) {
|
|
243
|
-
const ret = new Uint8Array(arg0 >>> 0);
|
|
244
|
-
return ret;
|
|
245
|
-
},
|
|
246
|
-
__wbg_node_e1f24f89a7336c2e: function(arg0) {
|
|
247
|
-
const ret = arg0.node;
|
|
248
|
-
return ret;
|
|
249
|
-
},
|
|
250
|
-
__wbg_parse_708461a1feddfb38: function() { return handleError(function (arg0, arg1) {
|
|
199
|
+
__wbg_parse_03863847d06c4e89: function() { return handleError(function (arg0, arg1) {
|
|
251
200
|
const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
|
|
252
201
|
return ret;
|
|
253
202
|
}, arguments); },
|
|
254
|
-
|
|
255
|
-
const ret = arg0.process;
|
|
256
|
-
return ret;
|
|
257
|
-
},
|
|
258
|
-
__wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
|
|
259
|
-
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
260
|
-
},
|
|
261
|
-
__wbg_push_8ffdcb2063340ba5: function(arg0, arg1) {
|
|
203
|
+
__wbg_push_a6822215aa43e71c: function(arg0, arg1) {
|
|
262
204
|
const ret = arg0.push(arg1);
|
|
263
205
|
return ret;
|
|
264
206
|
},
|
|
265
|
-
|
|
266
|
-
arg0.randomFillSync(arg1);
|
|
267
|
-
}, arguments); },
|
|
268
|
-
__wbg_require_b74f47fc2d022fd6: function() { return handleError(function () {
|
|
269
|
-
const ret = module.require;
|
|
270
|
-
return ret;
|
|
271
|
-
}, arguments); },
|
|
272
|
-
__wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
|
|
207
|
+
__wbg_set_6e30c9374c26414c: function() { return handleError(function (arg0, arg1, arg2) {
|
|
273
208
|
const ret = Reflect.set(arg0, arg1, arg2);
|
|
274
209
|
return ret;
|
|
275
210
|
}, arguments); },
|
|
276
|
-
__wbg_static_accessor_GLOBAL_12837167ad935116: function() {
|
|
277
|
-
const ret = typeof global === 'undefined' ? null : global;
|
|
278
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
279
|
-
},
|
|
280
|
-
__wbg_static_accessor_GLOBAL_THIS_e628e89ab3b1c95f: function() {
|
|
281
|
-
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
282
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
283
|
-
},
|
|
284
|
-
__wbg_static_accessor_SELF_a621d3dfbb60d0ce: function() {
|
|
285
|
-
const ret = typeof self === 'undefined' ? null : self;
|
|
286
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
287
|
-
},
|
|
288
|
-
__wbg_static_accessor_WINDOW_f8727f0cf888e0bd: function() {
|
|
289
|
-
const ret = typeof window === 'undefined' ? null : window;
|
|
290
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
291
|
-
},
|
|
292
|
-
__wbg_subarray_a96e1fef17ed23cb: function(arg0, arg1, arg2) {
|
|
293
|
-
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
294
|
-
return ret;
|
|
295
|
-
},
|
|
296
|
-
__wbg_versions_4e31226f5e8dc909: function(arg0) {
|
|
297
|
-
const ret = arg0.versions;
|
|
298
|
-
return ret;
|
|
299
|
-
},
|
|
300
211
|
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
301
212
|
// Cast intrinsic for `F64 -> Externref`.
|
|
302
213
|
const ret = arg0;
|
|
303
214
|
return ret;
|
|
304
215
|
},
|
|
305
216
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
306
|
-
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
307
|
-
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
308
|
-
return ret;
|
|
309
|
-
},
|
|
310
|
-
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
|
311
217
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
312
218
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
313
219
|
return ret;
|
|
@@ -330,7 +236,7 @@ function __wbg_get_imports() {
|
|
|
330
236
|
|
|
331
237
|
const ZKInputsGeneratorFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
332
238
|
? { register: () => {}, unregister: () => {} }
|
|
333
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_zkinputsgenerator_free(ptr
|
|
239
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_zkinputsgenerator_free(ptr, 1));
|
|
334
240
|
|
|
335
241
|
function addToExternrefTable0(obj) {
|
|
336
242
|
const idx = wasm.__externref_table_alloc();
|
|
@@ -365,8 +271,7 @@ function getBigUint64ArrayMemory0() {
|
|
|
365
271
|
}
|
|
366
272
|
|
|
367
273
|
function getStringFromWasm0(ptr, len) {
|
|
368
|
-
|
|
369
|
-
return decodeText(ptr, len);
|
|
274
|
+
return decodeText(ptr >>> 0, len);
|
|
370
275
|
}
|
|
371
276
|
|
|
372
277
|
let cachedUint8ArrayMemory0 = null;
|
|
@@ -386,10 +291,6 @@ function handleError(f, args) {
|
|
|
386
291
|
}
|
|
387
292
|
}
|
|
388
293
|
|
|
389
|
-
function isLikeNone(x) {
|
|
390
|
-
return x === undefined || x === null;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
294
|
function passArray64ToWasm0(arg, malloc) {
|
|
394
295
|
const ptr = malloc(arg.length * 8, 8) >>> 0;
|
|
395
296
|
getBigUint64ArrayMemory0().set(arg, ptr / 8);
|
|
@@ -426,8 +327,9 @@ function decodeText(ptr, len) {
|
|
|
426
327
|
|
|
427
328
|
let WASM_VECTOR_LEN = 0;
|
|
428
329
|
|
|
429
|
-
let wasmModule, wasm;
|
|
330
|
+
let wasmModule, wasmInstance, wasm;
|
|
430
331
|
function __wbg_finalize_init(instance, module) {
|
|
332
|
+
wasmInstance = instance;
|
|
431
333
|
wasm = instance.exports;
|
|
432
334
|
wasmModule = module;
|
|
433
335
|
cachedBigInt64ArrayMemory0 = null;
|