privacycash 1.0.16 → 1.0.17
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/utils/prover.d.ts +4 -1
- package/dist/utils/prover.js +26 -2
- package/package.json +1 -1
- package/src/utils/prover.ts +36 -3
package/dist/utils/prover.d.ts
CHANGED
|
@@ -18,9 +18,12 @@ interface Proof {
|
|
|
18
18
|
*
|
|
19
19
|
* @param input The circuit inputs to generate a proof for
|
|
20
20
|
* @param keyBasePath The base path for the circuit keys (.wasm and .zkey files)
|
|
21
|
+
* @param options Optional proof generation options (e.g., singleThread for Deno/Bun)
|
|
21
22
|
* @returns A proof object with formatted proof elements and public signals
|
|
22
23
|
*/
|
|
23
|
-
declare function prove(input: any, keyBasePath: string
|
|
24
|
+
declare function prove(input: any, keyBasePath: string, options?: {
|
|
25
|
+
singleThread?: boolean;
|
|
26
|
+
}): Promise<{
|
|
24
27
|
proof: Proof;
|
|
25
28
|
publicSignals: string[];
|
|
26
29
|
}>;
|
package/dist/utils/prover.js
CHANGED
|
@@ -21,10 +21,34 @@ const utilsTyped = utils;
|
|
|
21
21
|
*
|
|
22
22
|
* @param input The circuit inputs to generate a proof for
|
|
23
23
|
* @param keyBasePath The base path for the circuit keys (.wasm and .zkey files)
|
|
24
|
+
* @param options Optional proof generation options (e.g., singleThread for Deno/Bun)
|
|
24
25
|
* @returns A proof object with formatted proof elements and public signals
|
|
25
26
|
*/
|
|
26
|
-
async function prove(input, keyBasePath) {
|
|
27
|
-
|
|
27
|
+
async function prove(input, keyBasePath, options) {
|
|
28
|
+
// Detect if we should use single-threaded mode (for Deno/Bun compatibility)
|
|
29
|
+
const useSingleThread = options?.singleThread ?? shouldUseSingleThread();
|
|
30
|
+
// Single-thread options need to be passed to BOTH witness calculation AND proving
|
|
31
|
+
const singleThreadOpts = useSingleThread ? { singleThread: true } : undefined;
|
|
32
|
+
// Call fullProve with all parameters:
|
|
33
|
+
// 1. input, 2. wasmFile, 3. zkeyFile, 4. logger, 5. wtnsCalcOptions, 6. proverOptions
|
|
34
|
+
return await groth16Typed.fullProve(utilsTyped.stringifyBigInts(input), `${keyBasePath}.wasm`, `${keyBasePath}.zkey`, undefined, // logger parameter
|
|
35
|
+
singleThreadOpts, // wtnsCalcOptions (5th param) - for witness calculation
|
|
36
|
+
singleThreadOpts // proverOptions (6th param) - for proving
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Detect if single-threaded mode should be used
|
|
41
|
+
*/
|
|
42
|
+
function shouldUseSingleThread() {
|
|
43
|
+
// @ts-ignore - Deno global
|
|
44
|
+
if (typeof Deno !== 'undefined') {
|
|
45
|
+
return true; // Deno has worker issues
|
|
46
|
+
}
|
|
47
|
+
// @ts-ignore - Bun global
|
|
48
|
+
if (typeof Bun !== 'undefined') {
|
|
49
|
+
return true; // Bun may have worker issues
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
28
52
|
}
|
|
29
53
|
export function parseProofToBytesArray(proof, compressed = false) {
|
|
30
54
|
const proofJson = JSON.stringify(proof, null, 1);
|
package/package.json
CHANGED
package/src/utils/prover.ts
CHANGED
|
@@ -23,7 +23,14 @@ type WtnsModule = {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
type Groth16Module = {
|
|
26
|
-
fullProve: (
|
|
26
|
+
fullProve: (
|
|
27
|
+
input: any,
|
|
28
|
+
wasmFile: string,
|
|
29
|
+
zkeyFile: string,
|
|
30
|
+
logger?: any,
|
|
31
|
+
wtnsCalcOptions?: { singleThread?: boolean },
|
|
32
|
+
proverOptions?: { singleThread?: boolean }
|
|
33
|
+
) => Promise<{ proof: Proof; publicSignals: string[] }>
|
|
27
34
|
verify: (vkeyData: any, publicSignals: any, proof: Proof) => Promise<boolean>
|
|
28
35
|
}
|
|
29
36
|
|
|
@@ -53,23 +60,49 @@ interface ProofResult {
|
|
|
53
60
|
|
|
54
61
|
/**
|
|
55
62
|
* Generates a ZK proof using snarkjs and formats it for use on-chain
|
|
56
|
-
*
|
|
63
|
+
*
|
|
57
64
|
* @param input The circuit inputs to generate a proof for
|
|
58
65
|
* @param keyBasePath The base path for the circuit keys (.wasm and .zkey files)
|
|
66
|
+
* @param options Optional proof generation options (e.g., singleThread for Deno/Bun)
|
|
59
67
|
* @returns A proof object with formatted proof elements and public signals
|
|
60
68
|
*/
|
|
61
|
-
async function prove(input: any, keyBasePath: string): Promise<{
|
|
69
|
+
async function prove(input: any, keyBasePath: string, options?: { singleThread?: boolean }): Promise<{
|
|
62
70
|
proof: Proof
|
|
63
71
|
publicSignals: string[];
|
|
64
72
|
}> {
|
|
73
|
+
// Detect if we should use single-threaded mode (for Deno/Bun compatibility)
|
|
74
|
+
const useSingleThread = options?.singleThread ?? shouldUseSingleThread();
|
|
75
|
+
|
|
76
|
+
// Single-thread options need to be passed to BOTH witness calculation AND proving
|
|
77
|
+
const singleThreadOpts = useSingleThread ? { singleThread: true } : undefined;
|
|
65
78
|
|
|
79
|
+
// Call fullProve with all parameters:
|
|
80
|
+
// 1. input, 2. wasmFile, 3. zkeyFile, 4. logger, 5. wtnsCalcOptions, 6. proverOptions
|
|
66
81
|
return await groth16Typed.fullProve(
|
|
67
82
|
utilsTyped.stringifyBigInts(input),
|
|
68
83
|
`${keyBasePath}.wasm`,
|
|
69
84
|
`${keyBasePath}.zkey`,
|
|
85
|
+
undefined, // logger parameter
|
|
86
|
+
singleThreadOpts, // wtnsCalcOptions (5th param) - for witness calculation
|
|
87
|
+
singleThreadOpts // proverOptions (6th param) - for proving
|
|
70
88
|
)
|
|
71
89
|
}
|
|
72
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Detect if single-threaded mode should be used
|
|
93
|
+
*/
|
|
94
|
+
function shouldUseSingleThread(): boolean {
|
|
95
|
+
// @ts-ignore - Deno global
|
|
96
|
+
if (typeof Deno !== 'undefined') {
|
|
97
|
+
return true; // Deno has worker issues
|
|
98
|
+
}
|
|
99
|
+
// @ts-ignore - Bun global
|
|
100
|
+
if (typeof Bun !== 'undefined') {
|
|
101
|
+
return true; // Bun may have worker issues
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
73
106
|
export function parseProofToBytesArray(
|
|
74
107
|
proof: Proof,
|
|
75
108
|
compressed: boolean = false,
|