@izi-noir/sdk 0.1.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/LICENSE +21 -0
- package/README.md +458 -0
- package/dist/IProvingSystem-D9TnEig0.d.ts +140 -0
- package/dist/IProvingSystem-TKNofoo8.d.cts +140 -0
- package/dist/index.cjs +2793 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1196 -0
- package/dist/index.d.ts +1196 -0
- package/dist/index.js +2730 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/arkworks.cjs +824 -0
- package/dist/providers/arkworks.cjs.map +1 -0
- package/dist/providers/arkworks.d.cts +121 -0
- package/dist/providers/arkworks.d.ts +121 -0
- package/dist/providers/arkworks.js +791 -0
- package/dist/providers/arkworks.js.map +1 -0
- package/dist/providers/barretenberg.cjs +822 -0
- package/dist/providers/barretenberg.cjs.map +1 -0
- package/dist/providers/barretenberg.d.cts +18 -0
- package/dist/providers/barretenberg.d.ts +18 -0
- package/dist/providers/barretenberg.js +790 -0
- package/dist/providers/barretenberg.js.map +1 -0
- package/dist/providers/solana.cjs +262 -0
- package/dist/providers/solana.cjs.map +1 -0
- package/dist/providers/solana.d.cts +223 -0
- package/dist/providers/solana.d.ts +223 -0
- package/dist/providers/solana.js +222 -0
- package/dist/providers/solana.js.map +1 -0
- package/dist/providers/sunspot.cjs +475 -0
- package/dist/providers/sunspot.cjs.map +1 -0
- package/dist/providers/sunspot.d.cts +210 -0
- package/dist/providers/sunspot.d.ts +210 -0
- package/dist/providers/sunspot.js +443 -0
- package/dist/providers/sunspot.js.map +1 -0
- package/dist/types-CaaigonG.d.cts +93 -0
- package/dist/types-CaaigonG.d.ts +93 -0
- package/dist/wasm/nodejs/arkworks_groth16_wasm.js +448 -0
- package/dist/wasm/nodejs/arkworks_groth16_wasm_bg.wasm +0 -0
- package/dist/wasm/web/arkworks_groth16_wasm.js +536 -0
- package/dist/wasm/web/arkworks_groth16_wasm_bg.wasm +0 -0
- package/dist/wasmInit-KV6DTj4J.d.ts +282 -0
- package/dist/wasmInit-iEYiiB8M.d.cts +282 -0
- package/package.json +87 -0
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
// src/infra/provingSystems/Sunspot.ts
|
|
2
|
+
import { readFile, writeFile, rm, mkdtemp, mkdir } from "fs/promises";
|
|
3
|
+
import { join, dirname } from "path";
|
|
4
|
+
import { tmpdir } from "os";
|
|
5
|
+
|
|
6
|
+
// src/infra/sunspot/types.ts
|
|
7
|
+
var DEFAULT_SUNSPOT_CONFIG = {
|
|
8
|
+
nargoBinaryPath: process.env.NARGO_PATH || "nargo",
|
|
9
|
+
sunspotBinaryPath: process.env.SUNSPOT_PATH || "sunspot",
|
|
10
|
+
keepArtifacts: process.env.SUNSPOT_KEEP_ARTIFACTS === "true",
|
|
11
|
+
timeoutMs: 12e4
|
|
12
|
+
};
|
|
13
|
+
function isSunspotCircuit(circuit) {
|
|
14
|
+
return "__sunspot" in circuit && circuit.__sunspot === true;
|
|
15
|
+
}
|
|
16
|
+
var SunspotCliError = class extends Error {
|
|
17
|
+
constructor(message, command, exitCode, stderr) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.command = command;
|
|
20
|
+
this.exitCode = exitCode;
|
|
21
|
+
this.stderr = stderr;
|
|
22
|
+
this.name = "SunspotCliError";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/infra/sunspot/SunspotCliExecutor.ts
|
|
27
|
+
import { spawn } from "child_process";
|
|
28
|
+
var SunspotCliExecutor = class {
|
|
29
|
+
constructor(config) {
|
|
30
|
+
this.config = config;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Execute a CLI command and return the result
|
|
34
|
+
*/
|
|
35
|
+
async execute(command, args, cwd) {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const proc = spawn(command, args, {
|
|
38
|
+
cwd,
|
|
39
|
+
timeout: this.config.timeoutMs,
|
|
40
|
+
env: { ...process.env }
|
|
41
|
+
});
|
|
42
|
+
let stdout = "";
|
|
43
|
+
let stderr = "";
|
|
44
|
+
proc.stdout.on("data", (data) => {
|
|
45
|
+
stdout += data.toString();
|
|
46
|
+
});
|
|
47
|
+
proc.stderr.on("data", (data) => {
|
|
48
|
+
stderr += data.toString();
|
|
49
|
+
});
|
|
50
|
+
proc.on("close", (exitCode) => {
|
|
51
|
+
const result = {
|
|
52
|
+
stdout,
|
|
53
|
+
stderr,
|
|
54
|
+
exitCode: exitCode ?? 1
|
|
55
|
+
};
|
|
56
|
+
if (exitCode !== 0) {
|
|
57
|
+
reject(new SunspotCliError(
|
|
58
|
+
`Command failed: ${command} ${args.join(" ")}
|
|
59
|
+
${stderr || stdout}`,
|
|
60
|
+
`${command} ${args.join(" ")}`,
|
|
61
|
+
exitCode ?? 1,
|
|
62
|
+
stderr || stdout
|
|
63
|
+
));
|
|
64
|
+
} else {
|
|
65
|
+
resolve(result);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
proc.on("error", (error) => {
|
|
69
|
+
const message = error.message.includes("ENOENT") ? `Binary not found: ${command}. Ensure it is installed and in PATH.` : `Failed to execute ${command}: ${error.message}`;
|
|
70
|
+
reject(new SunspotCliError(
|
|
71
|
+
message,
|
|
72
|
+
`${command} ${args.join(" ")}`,
|
|
73
|
+
1,
|
|
74
|
+
error.message
|
|
75
|
+
));
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Run nargo compile in the project directory
|
|
81
|
+
* Output: target/circuit.json
|
|
82
|
+
*/
|
|
83
|
+
async nargoCompile(projectDir) {
|
|
84
|
+
return this.execute(this.config.nargoBinaryPath, ["compile"], projectDir);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Run nargo execute to generate witness
|
|
88
|
+
* Output: target/circuit.gz
|
|
89
|
+
*/
|
|
90
|
+
async nargoExecute(projectDir) {
|
|
91
|
+
return this.execute(this.config.nargoBinaryPath, ["execute"], projectDir);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Run sunspot compile to generate CCS
|
|
95
|
+
* Input: circuit.json
|
|
96
|
+
* Output: circuit.ccs (in same directory as input)
|
|
97
|
+
*/
|
|
98
|
+
async sunspotCompile(circuitJsonPath) {
|
|
99
|
+
return this.execute(this.config.sunspotBinaryPath, ["compile", circuitJsonPath]);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Run sunspot setup to generate proving and verification keys
|
|
103
|
+
* Input: circuit.ccs
|
|
104
|
+
* Output: circuit.pk, circuit.vk (in same directory as input)
|
|
105
|
+
*/
|
|
106
|
+
async sunspotSetup(ccsPath) {
|
|
107
|
+
return this.execute(this.config.sunspotBinaryPath, ["setup", ccsPath]);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Run sunspot prove to generate proof
|
|
111
|
+
* Inputs: circuit.json, witness.gz, circuit.ccs, circuit.pk
|
|
112
|
+
* Outputs: circuit.proof, circuit.pw (in same directory as ccs)
|
|
113
|
+
*/
|
|
114
|
+
async sunspotProve(circuitJsonPath, witnessPath, ccsPath, pkPath) {
|
|
115
|
+
return this.execute(this.config.sunspotBinaryPath, [
|
|
116
|
+
"prove",
|
|
117
|
+
circuitJsonPath,
|
|
118
|
+
witnessPath,
|
|
119
|
+
ccsPath,
|
|
120
|
+
pkPath
|
|
121
|
+
]);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Run sunspot verify to verify a proof
|
|
125
|
+
* Inputs: circuit.vk, circuit.proof, circuit.pw
|
|
126
|
+
* Returns: true if verification succeeds
|
|
127
|
+
*/
|
|
128
|
+
async sunspotVerify(vkPath, proofPath, publicWitnessPath) {
|
|
129
|
+
return this.execute(this.config.sunspotBinaryPath, [
|
|
130
|
+
"verify",
|
|
131
|
+
vkPath,
|
|
132
|
+
proofPath,
|
|
133
|
+
publicWitnessPath
|
|
134
|
+
]);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// src/infra/provingSystems/Sunspot.ts
|
|
139
|
+
var Sunspot = class {
|
|
140
|
+
config;
|
|
141
|
+
executor;
|
|
142
|
+
precompiledPaths;
|
|
143
|
+
precompiledCircuit;
|
|
144
|
+
/**
|
|
145
|
+
* Create a new Sunspot proving system
|
|
146
|
+
* @param config - Configuration options or pre-compiled circuit paths
|
|
147
|
+
*/
|
|
148
|
+
constructor(config = {}) {
|
|
149
|
+
if ("pkPath" in config && "vkPath" in config && "circuitPath" in config) {
|
|
150
|
+
this.config = { ...DEFAULT_SUNSPOT_CONFIG };
|
|
151
|
+
this.precompiledPaths = config;
|
|
152
|
+
} else {
|
|
153
|
+
const initConfig = config;
|
|
154
|
+
this.config = { ...DEFAULT_SUNSPOT_CONFIG, ...initConfig };
|
|
155
|
+
this.precompiledPaths = initConfig.precompiledPaths;
|
|
156
|
+
}
|
|
157
|
+
this.executor = new SunspotCliExecutor(this.config);
|
|
158
|
+
if (this.precompiledPaths) {
|
|
159
|
+
this.precompiledCircuit = this.createPrecompiledCircuit(this.precompiledPaths);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Create a SunspotCompiledCircuit from pre-compiled paths
|
|
164
|
+
*/
|
|
165
|
+
createPrecompiledCircuit(paths) {
|
|
166
|
+
const baseDir = dirname(paths.circuitPath);
|
|
167
|
+
return {
|
|
168
|
+
bytecode: "",
|
|
169
|
+
// Not needed for prove/verify with pre-compiled
|
|
170
|
+
abi: { parameters: [], return_type: null, error_types: {} },
|
|
171
|
+
debug_symbols: "",
|
|
172
|
+
file_map: {},
|
|
173
|
+
__sunspot: true,
|
|
174
|
+
paths: {
|
|
175
|
+
workDir: baseDir,
|
|
176
|
+
noirProjectDir: baseDir,
|
|
177
|
+
circuitJsonPath: paths.circuitPath,
|
|
178
|
+
witnessPath: join(baseDir, "circuit.gz"),
|
|
179
|
+
ccsPath: join(baseDir, "circuit.ccs"),
|
|
180
|
+
pkPath: paths.pkPath,
|
|
181
|
+
vkPath: paths.vkPath,
|
|
182
|
+
proofPath: join(baseDir, "circuit.proof"),
|
|
183
|
+
publicWitnessPath: join(baseDir, "circuit.pw"),
|
|
184
|
+
proverTomlPath: join(baseDir, "Prover.toml")
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Create a temporary Noir project for compilation
|
|
190
|
+
*/
|
|
191
|
+
async createNoirProject(noirCode, packageName) {
|
|
192
|
+
const rootDir = await mkdtemp(join(tmpdir(), "sunspot-circuit-"));
|
|
193
|
+
const srcDir = join(rootDir, "src");
|
|
194
|
+
await mkdir(srcDir, { recursive: true });
|
|
195
|
+
const nargoToml = `[package]
|
|
196
|
+
name = "${packageName}"
|
|
197
|
+
type = "bin"
|
|
198
|
+
authors = [""]
|
|
199
|
+
|
|
200
|
+
[dependencies]
|
|
201
|
+
`;
|
|
202
|
+
await writeFile(join(rootDir, "Nargo.toml"), nargoToml);
|
|
203
|
+
await writeFile(join(srcDir, "main.nr"), noirCode);
|
|
204
|
+
return { rootDir };
|
|
205
|
+
}
|
|
206
|
+
async compile(noirCode) {
|
|
207
|
+
if (this.precompiledPaths) {
|
|
208
|
+
throw new Error(
|
|
209
|
+
"Sunspot was initialized with pre-compiled circuit paths. compile() is not available. Use generateProof() and verifyProof() directly."
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
const project = await this.createNoirProject(noirCode, "circuit");
|
|
213
|
+
const targetDir = join(project.rootDir, "target");
|
|
214
|
+
await this.executor.nargoCompile(project.rootDir);
|
|
215
|
+
const circuitJsonPath = join(targetDir, "circuit.json");
|
|
216
|
+
await this.executor.sunspotCompile(circuitJsonPath);
|
|
217
|
+
const ccsPath = join(dirname(circuitJsonPath), "circuit.ccs");
|
|
218
|
+
await this.executor.sunspotSetup(ccsPath);
|
|
219
|
+
const pkPath = join(dirname(ccsPath), "circuit.pk");
|
|
220
|
+
const vkPath = join(dirname(ccsPath), "circuit.vk");
|
|
221
|
+
const circuitJson = JSON.parse(await readFile(circuitJsonPath, "utf-8"));
|
|
222
|
+
const paths = {
|
|
223
|
+
workDir: project.rootDir,
|
|
224
|
+
noirProjectDir: project.rootDir,
|
|
225
|
+
circuitJsonPath,
|
|
226
|
+
witnessPath: join(targetDir, "circuit.gz"),
|
|
227
|
+
ccsPath,
|
|
228
|
+
pkPath,
|
|
229
|
+
vkPath,
|
|
230
|
+
proofPath: join(dirname(ccsPath), "circuit.proof"),
|
|
231
|
+
publicWitnessPath: join(dirname(ccsPath), "circuit.pw"),
|
|
232
|
+
proverTomlPath: join(project.rootDir, "Prover.toml")
|
|
233
|
+
};
|
|
234
|
+
const sunspotCircuit = {
|
|
235
|
+
bytecode: circuitJson.bytecode || "",
|
|
236
|
+
abi: circuitJson.abi || {
|
|
237
|
+
parameters: [],
|
|
238
|
+
return_type: null,
|
|
239
|
+
error_types: {}
|
|
240
|
+
},
|
|
241
|
+
debug_symbols: circuitJson.debug_symbols || "",
|
|
242
|
+
file_map: circuitJson.file_map || {},
|
|
243
|
+
__sunspot: true,
|
|
244
|
+
paths
|
|
245
|
+
};
|
|
246
|
+
return sunspotCircuit;
|
|
247
|
+
}
|
|
248
|
+
async generateProof(circuit, inputs) {
|
|
249
|
+
const circuitToUse = this.resolveCircuit(circuit);
|
|
250
|
+
if (!isSunspotCircuit(circuitToUse)) {
|
|
251
|
+
throw new Error(
|
|
252
|
+
"Sunspot.generateProof requires a SunspotCompiledCircuit. Use Sunspot.compile() first."
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
const paths = circuitToUse.paths;
|
|
256
|
+
try {
|
|
257
|
+
const proverToml = this.generateProverToml(inputs);
|
|
258
|
+
await writeFile(paths.proverTomlPath, proverToml);
|
|
259
|
+
await this.executor.nargoExecute(paths.noirProjectDir);
|
|
260
|
+
await this.executor.sunspotProve(
|
|
261
|
+
paths.circuitJsonPath,
|
|
262
|
+
paths.witnessPath,
|
|
263
|
+
paths.ccsPath,
|
|
264
|
+
paths.pkPath
|
|
265
|
+
);
|
|
266
|
+
const proofBytes = new Uint8Array(await readFile(paths.proofPath));
|
|
267
|
+
const publicWitnessBytes = new Uint8Array(await readFile(paths.publicWitnessPath));
|
|
268
|
+
const publicInputs = this.parsePublicWitness(publicWitnessBytes);
|
|
269
|
+
return {
|
|
270
|
+
proof: proofBytes,
|
|
271
|
+
publicInputs
|
|
272
|
+
};
|
|
273
|
+
} catch (error) {
|
|
274
|
+
if (!this.config.keepArtifacts) {
|
|
275
|
+
await rm(paths.workDir, { recursive: true, force: true }).catch(() => {
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
async verifyProof(circuit, proof, publicInputs) {
|
|
282
|
+
const circuitToUse = this.resolveCircuit(circuit);
|
|
283
|
+
if (!isSunspotCircuit(circuitToUse)) {
|
|
284
|
+
throw new Error(
|
|
285
|
+
"Sunspot.verifyProof requires a SunspotCompiledCircuit. Use Sunspot.compile() first."
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
const paths = circuitToUse.paths;
|
|
289
|
+
try {
|
|
290
|
+
const existingProof = await readFile(paths.proofPath).catch(() => null);
|
|
291
|
+
if (!existingProof || !this.bytesEqual(existingProof, proof)) {
|
|
292
|
+
await writeFile(paths.proofPath, proof);
|
|
293
|
+
}
|
|
294
|
+
await this.executor.sunspotVerify(
|
|
295
|
+
paths.vkPath,
|
|
296
|
+
paths.proofPath,
|
|
297
|
+
paths.publicWitnessPath
|
|
298
|
+
);
|
|
299
|
+
return true;
|
|
300
|
+
} catch (error) {
|
|
301
|
+
if (error instanceof SunspotCliError) {
|
|
302
|
+
if (error.stderr.toLowerCase().includes("verification failed") || error.stderr.toLowerCase().includes("invalid proof")) {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
throw error;
|
|
307
|
+
} finally {
|
|
308
|
+
if (!this.config.keepArtifacts) {
|
|
309
|
+
await rm(paths.workDir, { recursive: true, force: true }).catch(() => {
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Resolve which circuit to use - precompiled or provided
|
|
316
|
+
*/
|
|
317
|
+
resolveCircuit(circuit) {
|
|
318
|
+
if (isSunspotCircuit(circuit)) {
|
|
319
|
+
return circuit;
|
|
320
|
+
}
|
|
321
|
+
if (this.precompiledCircuit) {
|
|
322
|
+
return this.precompiledCircuit;
|
|
323
|
+
}
|
|
324
|
+
return circuit;
|
|
325
|
+
}
|
|
326
|
+
generateProverToml(inputs) {
|
|
327
|
+
const lines = [];
|
|
328
|
+
for (const [key, value] of Object.entries(inputs)) {
|
|
329
|
+
lines.push(`${key} = ${this.formatTomlValue(value)}`);
|
|
330
|
+
}
|
|
331
|
+
return lines.join("\n") + "\n";
|
|
332
|
+
}
|
|
333
|
+
formatTomlValue(value) {
|
|
334
|
+
if (typeof value === "string") {
|
|
335
|
+
if (value.startsWith("0x")) return `"${value}"`;
|
|
336
|
+
if (/^\d+$/.test(value)) return value;
|
|
337
|
+
return `"${value}"`;
|
|
338
|
+
}
|
|
339
|
+
if (typeof value === "number" || typeof value === "bigint") {
|
|
340
|
+
return value.toString();
|
|
341
|
+
}
|
|
342
|
+
if (Array.isArray(value)) {
|
|
343
|
+
return `[${value.map((v) => this.formatTomlValue(v)).join(", ")}]`;
|
|
344
|
+
}
|
|
345
|
+
return String(value);
|
|
346
|
+
}
|
|
347
|
+
parsePublicWitness(bytes) {
|
|
348
|
+
const publicInputs = [];
|
|
349
|
+
const FIELD_SIZE = 32;
|
|
350
|
+
for (let i = 0; i < bytes.length; i += FIELD_SIZE) {
|
|
351
|
+
const fieldBytes = bytes.slice(i, Math.min(i + FIELD_SIZE, bytes.length));
|
|
352
|
+
if (fieldBytes.length === FIELD_SIZE) {
|
|
353
|
+
const hex = "0x" + Array.from(fieldBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
354
|
+
publicInputs.push(hex);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return publicInputs;
|
|
358
|
+
}
|
|
359
|
+
bytesEqual(a, b) {
|
|
360
|
+
if (a.length !== b.length) return false;
|
|
361
|
+
for (let i = 0; i < a.length; i++) {
|
|
362
|
+
if (a[i] !== b[i]) return false;
|
|
363
|
+
}
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
// src/domain/types/provider.ts
|
|
369
|
+
var Provider = /* @__PURE__ */ ((Provider2) => {
|
|
370
|
+
Provider2["Barretenberg"] = "barretenberg";
|
|
371
|
+
Provider2["Arkworks"] = "arkworks";
|
|
372
|
+
Provider2["Sunspot"] = "sunspot";
|
|
373
|
+
return Provider2;
|
|
374
|
+
})(Provider || {});
|
|
375
|
+
|
|
376
|
+
// src/providers/sunspot.ts
|
|
377
|
+
var IziNoirSunspot = class _IziNoirSunspot {
|
|
378
|
+
provingSystem;
|
|
379
|
+
compiledCircuit = null;
|
|
380
|
+
constructor(provingSystem) {
|
|
381
|
+
this.provingSystem = provingSystem;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Initialize IziNoirSunspot with pre-compiled circuit paths.
|
|
385
|
+
* Note: Sunspot requires pre-compiled circuits for prove/verify operations.
|
|
386
|
+
*
|
|
387
|
+
* @param circuitPaths - Paths to the pre-compiled circuit files
|
|
388
|
+
*/
|
|
389
|
+
static async init(circuitPaths) {
|
|
390
|
+
const sunspot = new Sunspot(circuitPaths);
|
|
391
|
+
return new _IziNoirSunspot(sunspot);
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Initialize IziNoirSunspot for full compilation mode.
|
|
395
|
+
* Requires nargo and sunspot CLI tools to be installed.
|
|
396
|
+
*/
|
|
397
|
+
static async initForCompilation() {
|
|
398
|
+
const sunspot = new Sunspot();
|
|
399
|
+
return new _IziNoirSunspot(sunspot);
|
|
400
|
+
}
|
|
401
|
+
getProvingSystem() {
|
|
402
|
+
return this.provingSystem;
|
|
403
|
+
}
|
|
404
|
+
getCompiledCircuit() {
|
|
405
|
+
return this.compiledCircuit;
|
|
406
|
+
}
|
|
407
|
+
async compile(noirCode) {
|
|
408
|
+
this.compiledCircuit = await this.provingSystem.compile(noirCode);
|
|
409
|
+
return this.compiledCircuit;
|
|
410
|
+
}
|
|
411
|
+
async prove(inputs, circuit) {
|
|
412
|
+
const circuitToUse = circuit || this.compiledCircuit;
|
|
413
|
+
if (!circuitToUse) {
|
|
414
|
+
throw new Error("No circuit available. Call compile() first or provide a circuit.");
|
|
415
|
+
}
|
|
416
|
+
return this.provingSystem.generateProof(circuitToUse, inputs);
|
|
417
|
+
}
|
|
418
|
+
async verify(proof, publicInputs, circuit) {
|
|
419
|
+
const circuitToUse = circuit || this.compiledCircuit;
|
|
420
|
+
if (!circuitToUse) {
|
|
421
|
+
throw new Error("No circuit available. Call compile() first or provide a circuit.");
|
|
422
|
+
}
|
|
423
|
+
return this.provingSystem.verifyProof(circuitToUse, proof, publicInputs);
|
|
424
|
+
}
|
|
425
|
+
async createProof(noirCode, inputs) {
|
|
426
|
+
const circuit = await this.compile(noirCode);
|
|
427
|
+
const proof = await this.prove(inputs, circuit);
|
|
428
|
+
const verified = await this.verify(proof.proof, proof.publicInputs, circuit);
|
|
429
|
+
return { proof, verified };
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
async function initSunspotIziNoir(circuitPaths) {
|
|
433
|
+
return IziNoirSunspot.init(circuitPaths);
|
|
434
|
+
}
|
|
435
|
+
export {
|
|
436
|
+
IziNoirSunspot,
|
|
437
|
+
Provider,
|
|
438
|
+
Sunspot,
|
|
439
|
+
SunspotCliError,
|
|
440
|
+
initSunspotIziNoir,
|
|
441
|
+
isSunspotCircuit
|
|
442
|
+
};
|
|
443
|
+
//# sourceMappingURL=sunspot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/infra/provingSystems/Sunspot.ts","../../src/infra/sunspot/types.ts","../../src/infra/sunspot/SunspotCliExecutor.ts","../../src/domain/types/provider.ts","../../src/providers/sunspot.ts"],"sourcesContent":["import { readFile, writeFile, rm, mkdtemp, mkdir } from 'node:fs/promises';\nimport { join, dirname } from 'node:path';\nimport { tmpdir } from 'node:os';\nimport type { IProvingSystem } from '../../domain/interfaces/proving/IProvingSystem.js';\nimport type { CompiledCircuit, InputMap, ProofData } from '../../domain/types.js';\nimport type { SunspotConfig, SunspotCircuitPaths, SunspotCompiledCircuit } from '../sunspot/types.js';\nimport { DEFAULT_SUNSPOT_CONFIG, isSunspotCircuit, SunspotCliError } from '../sunspot/types.js';\nimport { SunspotCliExecutor } from '../sunspot/SunspotCliExecutor.js';\nimport type { CircuitPaths } from '../../domain/types/provider.js';\n\n/**\n * Configuration for Sunspot constructor\n */\nexport interface SunspotInitConfig extends Partial<SunspotConfig> {\n /** Pre-compiled circuit paths (if provided, compile() is disabled) */\n precompiledPaths?: CircuitPaths;\n}\n\n/**\n * Sunspot proving system using CLI tools.\n * Node.js only (requires nargo and sunspot binaries).\n * Produces Groth16 proofs (~324 bytes) for Solana on-chain verification.\n *\n * Can be used in two modes:\n * 1. Full compilation: Call compile() with Noir code (requires nargo + sunspot CLI)\n * 2. Pre-compiled: Provide circuitPaths in constructor, then only prove/verify\n *\n * @example Full compilation\n * ```typescript\n * const sunspot = new Sunspot();\n * const circuit = await sunspot.compile(noirCode);\n * const proof = await sunspot.generateProof(circuit, inputs);\n * ```\n *\n * @example Pre-compiled (via IziNoir)\n * ```typescript\n * const izi = await IziNoir.init({\n * provider: Provider.Sunspot,\n * circuitPaths: { pkPath: '...', vkPath: '...', circuitPath: '...' }\n * });\n * ```\n */\nexport class Sunspot implements IProvingSystem {\n private readonly config: SunspotConfig;\n private readonly executor: SunspotCliExecutor;\n private readonly precompiledPaths?: CircuitPaths;\n private precompiledCircuit?: SunspotCompiledCircuit;\n\n /**\n * Create a new Sunspot proving system\n * @param config - Configuration options or pre-compiled circuit paths\n */\n constructor(config: SunspotInitConfig | CircuitPaths = {}) {\n // Check if config is CircuitPaths (has pkPath, vkPath, circuitPath)\n if ('pkPath' in config && 'vkPath' in config && 'circuitPath' in config) {\n this.config = { ...DEFAULT_SUNSPOT_CONFIG };\n this.precompiledPaths = config as CircuitPaths;\n } else {\n const initConfig = config as SunspotInitConfig;\n this.config = { ...DEFAULT_SUNSPOT_CONFIG, ...initConfig };\n this.precompiledPaths = initConfig.precompiledPaths;\n }\n\n this.executor = new SunspotCliExecutor(this.config);\n\n // If pre-compiled paths provided, create a dummy circuit object\n if (this.precompiledPaths) {\n this.precompiledCircuit = this.createPrecompiledCircuit(this.precompiledPaths);\n }\n }\n\n /**\n * Create a SunspotCompiledCircuit from pre-compiled paths\n */\n private createPrecompiledCircuit(paths: CircuitPaths): SunspotCompiledCircuit {\n const baseDir = dirname(paths.circuitPath);\n return {\n bytecode: '', // Not needed for prove/verify with pre-compiled\n abi: { parameters: [], return_type: null, error_types: {} },\n debug_symbols: '',\n file_map: {},\n __sunspot: true,\n paths: {\n workDir: baseDir,\n noirProjectDir: baseDir,\n circuitJsonPath: paths.circuitPath,\n witnessPath: join(baseDir, 'circuit.gz'),\n ccsPath: join(baseDir, 'circuit.ccs'),\n pkPath: paths.pkPath,\n vkPath: paths.vkPath,\n proofPath: join(baseDir, 'circuit.proof'),\n publicWitnessPath: join(baseDir, 'circuit.pw'),\n proverTomlPath: join(baseDir, 'Prover.toml'),\n },\n };\n }\n\n /**\n * Create a temporary Noir project for compilation\n */\n private async createNoirProject(noirCode: string, packageName: string): Promise<{ rootDir: string }> {\n const rootDir = await mkdtemp(join(tmpdir(), 'sunspot-circuit-'));\n const srcDir = join(rootDir, 'src');\n await mkdir(srcDir, { recursive: true });\n\n const nargoToml = `[package]\nname = \"${packageName}\"\ntype = \"bin\"\nauthors = [\"\"]\n\n[dependencies]\n`;\n\n await writeFile(join(rootDir, 'Nargo.toml'), nargoToml);\n await writeFile(join(srcDir, 'main.nr'), noirCode);\n\n return { rootDir };\n }\n\n async compile(noirCode: string): Promise<CompiledCircuit> {\n if (this.precompiledPaths) {\n throw new Error(\n 'Sunspot was initialized with pre-compiled circuit paths. ' +\n 'compile() is not available. Use generateProof() and verifyProof() directly.'\n );\n }\n\n // 1. Create temp Noir project\n const project = await this.createNoirProject(noirCode, 'circuit');\n const targetDir = join(project.rootDir, 'target');\n\n // 2. Run nargo compile → circuit.json\n await this.executor.nargoCompile(project.rootDir);\n const circuitJsonPath = join(targetDir, 'circuit.json');\n\n // 3. Run sunspot compile → circuit.ccs\n await this.executor.sunspotCompile(circuitJsonPath);\n const ccsPath = join(dirname(circuitJsonPath), 'circuit.ccs');\n\n // 4. Run sunspot setup → circuit.pk + circuit.vk\n await this.executor.sunspotSetup(ccsPath);\n const pkPath = join(dirname(ccsPath), 'circuit.pk');\n const vkPath = join(dirname(ccsPath), 'circuit.vk');\n\n // 5. Read circuit.json to extract ABI\n const circuitJson = JSON.parse(await readFile(circuitJsonPath, 'utf-8'));\n\n // 6. Build paths object\n const paths: SunspotCircuitPaths = {\n workDir: project.rootDir,\n noirProjectDir: project.rootDir,\n circuitJsonPath,\n witnessPath: join(targetDir, 'circuit.gz'),\n ccsPath,\n pkPath,\n vkPath,\n proofPath: join(dirname(ccsPath), 'circuit.proof'),\n publicWitnessPath: join(dirname(ccsPath), 'circuit.pw'),\n proverTomlPath: join(project.rootDir, 'Prover.toml'),\n };\n\n // 7. Return SunspotCompiledCircuit (don't cleanup - prover needs the files)\n const sunspotCircuit: SunspotCompiledCircuit = {\n bytecode: circuitJson.bytecode || '',\n abi: circuitJson.abi || {\n parameters: [],\n return_type: null,\n error_types: {},\n },\n debug_symbols: circuitJson.debug_symbols || '',\n file_map: circuitJson.file_map || {},\n __sunspot: true,\n paths,\n };\n\n return sunspotCircuit;\n }\n\n async generateProof(circuit: CompiledCircuit, inputs: InputMap): Promise<ProofData> {\n // Use precompiled circuit if available and circuit is empty/default\n const circuitToUse = this.resolveCircuit(circuit);\n\n if (!isSunspotCircuit(circuitToUse)) {\n throw new Error(\n 'Sunspot.generateProof requires a SunspotCompiledCircuit. Use Sunspot.compile() first.'\n );\n }\n\n const paths = circuitToUse.paths;\n\n try {\n // 1. Write Prover.toml with inputs\n const proverToml = this.generateProverToml(inputs);\n await writeFile(paths.proverTomlPath, proverToml);\n\n // 2. Run nargo execute to generate witness\n await this.executor.nargoExecute(paths.noirProjectDir);\n\n // 3. Run sunspot prove to generate proof\n await this.executor.sunspotProve(\n paths.circuitJsonPath,\n paths.witnessPath,\n paths.ccsPath,\n paths.pkPath\n );\n\n // 4. Read proof and public witness files\n const proofBytes = new Uint8Array(await readFile(paths.proofPath));\n const publicWitnessBytes = new Uint8Array(await readFile(paths.publicWitnessPath));\n\n // 5. Parse public inputs from public witness\n const publicInputs = this.parsePublicWitness(publicWitnessBytes);\n\n return {\n proof: proofBytes,\n publicInputs,\n };\n } catch (error) {\n if (!this.config.keepArtifacts) {\n await rm(paths.workDir, { recursive: true, force: true }).catch(() => {});\n }\n throw error;\n }\n }\n\n async verifyProof(\n circuit: CompiledCircuit,\n proof: Uint8Array,\n publicInputs: string[]\n ): Promise<boolean> {\n // Use precompiled circuit if available and circuit is empty/default\n const circuitToUse = this.resolveCircuit(circuit);\n\n if (!isSunspotCircuit(circuitToUse)) {\n throw new Error(\n 'Sunspot.verifyProof requires a SunspotCompiledCircuit. Use Sunspot.compile() first.'\n );\n }\n\n const paths = circuitToUse.paths;\n\n try {\n // Use existing .proof and .pw files from generateProof\n const existingProof = await readFile(paths.proofPath).catch(() => null);\n if (!existingProof || !this.bytesEqual(existingProof, proof)) {\n await writeFile(paths.proofPath, proof);\n }\n\n await this.executor.sunspotVerify(\n paths.vkPath,\n paths.proofPath,\n paths.publicWitnessPath\n );\n\n return true;\n } catch (error) {\n if (error instanceof SunspotCliError) {\n if (error.stderr.toLowerCase().includes('verification failed') ||\n error.stderr.toLowerCase().includes('invalid proof')) {\n return false;\n }\n }\n throw error;\n } finally {\n if (!this.config.keepArtifacts) {\n await rm(paths.workDir, { recursive: true, force: true }).catch(() => {});\n }\n }\n }\n\n /**\n * Resolve which circuit to use - precompiled or provided\n */\n private resolveCircuit(circuit: CompiledCircuit): CompiledCircuit {\n // If circuit is a proper SunspotCompiledCircuit, use it\n if (isSunspotCircuit(circuit)) {\n return circuit;\n }\n\n // If we have precompiled paths, use those\n if (this.precompiledCircuit) {\n return this.precompiledCircuit;\n }\n\n // Otherwise, return the provided circuit (will fail validation)\n return circuit;\n }\n\n private generateProverToml(inputs: InputMap): string {\n const lines: string[] = [];\n for (const [key, value] of Object.entries(inputs)) {\n lines.push(`${key} = ${this.formatTomlValue(value)}`);\n }\n return lines.join('\\n') + '\\n';\n }\n\n private formatTomlValue(value: unknown): string {\n if (typeof value === 'string') {\n if (value.startsWith('0x')) return `\"${value}\"`;\n if (/^\\d+$/.test(value)) return value;\n return `\"${value}\"`;\n }\n if (typeof value === 'number' || typeof value === 'bigint') {\n return value.toString();\n }\n if (Array.isArray(value)) {\n return `[${value.map(v => this.formatTomlValue(v)).join(', ')}]`;\n }\n return String(value);\n }\n\n private parsePublicWitness(bytes: Uint8Array): string[] {\n const publicInputs: string[] = [];\n const FIELD_SIZE = 32;\n\n for (let i = 0; i < bytes.length; i += FIELD_SIZE) {\n const fieldBytes = bytes.slice(i, Math.min(i + FIELD_SIZE, bytes.length));\n if (fieldBytes.length === FIELD_SIZE) {\n const hex = '0x' + Array.from(fieldBytes)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('');\n publicInputs.push(hex);\n }\n }\n\n return publicInputs;\n }\n\n private bytesEqual(a: Buffer | Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n }\n}\n","import type { CompiledCircuit } from '@noir-lang/types';\n\n/**\n * Configuration for Sunspot CLI execution\n */\nexport interface SunspotConfig {\n /** Path to nargo binary (default: 'nargo') */\n nargoBinaryPath: string;\n /** Path to sunspot binary (default: 'sunspot') */\n sunspotBinaryPath: string;\n /** Keep temp artifacts for debugging (default: false) */\n keepArtifacts: boolean;\n /** Timeout for CLI commands in ms (default: 120000) */\n timeoutMs: number;\n}\n\nexport const DEFAULT_SUNSPOT_CONFIG: SunspotConfig = {\n nargoBinaryPath: process.env.NARGO_PATH || 'nargo',\n sunspotBinaryPath: process.env.SUNSPOT_PATH || 'sunspot',\n keepArtifacts: process.env.SUNSPOT_KEEP_ARTIFACTS === 'true',\n timeoutMs: 120000,\n};\n\n/**\n * Paths to all Sunspot artifacts in the temp directory\n */\nexport interface SunspotCircuitPaths {\n /** Base temp directory */\n workDir: string;\n /** Noir project directory with Nargo.toml */\n noirProjectDir: string;\n /** Path to compiled circuit.json (ACIR) */\n circuitJsonPath: string;\n /** Path to witness.gz */\n witnessPath: string;\n /** Path to circuit.ccs */\n ccsPath: string;\n /** Path to proving key */\n pkPath: string;\n /** Path to verification key */\n vkPath: string;\n /** Path to proof file */\n proofPath: string;\n /** Path to public witness file */\n publicWitnessPath: string;\n /** Path to Prover.toml */\n proverTomlPath: string;\n}\n\n/**\n * Extended CompiledCircuit for Sunspot backend\n */\nexport interface SunspotCompiledCircuit extends CompiledCircuit {\n /** Marker to identify Sunspot circuits */\n __sunspot: true;\n /** Paths to all artifacts */\n paths: SunspotCircuitPaths;\n}\n\n/**\n * Type guard to check if a circuit is a Sunspot circuit\n */\nexport function isSunspotCircuit(circuit: CompiledCircuit): circuit is SunspotCompiledCircuit {\n return '__sunspot' in circuit && (circuit as SunspotCompiledCircuit).__sunspot === true;\n}\n\n/**\n * Result of CLI command execution\n */\nexport interface CliResult {\n stdout: string;\n stderr: string;\n exitCode: number;\n}\n\n/**\n * Error thrown when CLI command fails\n */\nexport class SunspotCliError extends Error {\n constructor(\n message: string,\n public readonly command: string,\n public readonly exitCode: number,\n public readonly stderr: string\n ) {\n super(message);\n this.name = 'SunspotCliError';\n }\n}\n","import { spawn } from 'node:child_process';\nimport type { SunspotConfig, CliResult } from './types.js';\nimport { SunspotCliError } from './types.js';\n\n/**\n * Executes Sunspot and Nargo CLI commands\n */\nexport class SunspotCliExecutor {\n constructor(private readonly config: SunspotConfig) {}\n\n /**\n * Execute a CLI command and return the result\n */\n private async execute(command: string, args: string[], cwd?: string): Promise<CliResult> {\n return new Promise((resolve, reject) => {\n const proc = spawn(command, args, {\n cwd,\n timeout: this.config.timeoutMs,\n env: { ...process.env },\n });\n\n let stdout = '';\n let stderr = '';\n\n proc.stdout.on('data', (data) => {\n stdout += data.toString();\n });\n\n proc.stderr.on('data', (data) => {\n stderr += data.toString();\n });\n\n proc.on('close', (exitCode) => {\n const result: CliResult = {\n stdout,\n stderr,\n exitCode: exitCode ?? 1,\n };\n\n if (exitCode !== 0) {\n reject(new SunspotCliError(\n `Command failed: ${command} ${args.join(' ')}\\n${stderr || stdout}`,\n `${command} ${args.join(' ')}`,\n exitCode ?? 1,\n stderr || stdout\n ));\n } else {\n resolve(result);\n }\n });\n\n proc.on('error', (error) => {\n const message = error.message.includes('ENOENT')\n ? `Binary not found: ${command}. Ensure it is installed and in PATH.`\n : `Failed to execute ${command}: ${error.message}`;\n\n reject(new SunspotCliError(\n message,\n `${command} ${args.join(' ')}`,\n 1,\n error.message\n ));\n });\n });\n }\n\n /**\n * Run nargo compile in the project directory\n * Output: target/circuit.json\n */\n async nargoCompile(projectDir: string): Promise<CliResult> {\n return this.execute(this.config.nargoBinaryPath, ['compile'], projectDir);\n }\n\n /**\n * Run nargo execute to generate witness\n * Output: target/circuit.gz\n */\n async nargoExecute(projectDir: string): Promise<CliResult> {\n return this.execute(this.config.nargoBinaryPath, ['execute'], projectDir);\n }\n\n /**\n * Run sunspot compile to generate CCS\n * Input: circuit.json\n * Output: circuit.ccs (in same directory as input)\n */\n async sunspotCompile(circuitJsonPath: string): Promise<CliResult> {\n return this.execute(this.config.sunspotBinaryPath, ['compile', circuitJsonPath]);\n }\n\n /**\n * Run sunspot setup to generate proving and verification keys\n * Input: circuit.ccs\n * Output: circuit.pk, circuit.vk (in same directory as input)\n */\n async sunspotSetup(ccsPath: string): Promise<CliResult> {\n return this.execute(this.config.sunspotBinaryPath, ['setup', ccsPath]);\n }\n\n /**\n * Run sunspot prove to generate proof\n * Inputs: circuit.json, witness.gz, circuit.ccs, circuit.pk\n * Outputs: circuit.proof, circuit.pw (in same directory as ccs)\n */\n async sunspotProve(\n circuitJsonPath: string,\n witnessPath: string,\n ccsPath: string,\n pkPath: string\n ): Promise<CliResult> {\n return this.execute(this.config.sunspotBinaryPath, [\n 'prove',\n circuitJsonPath,\n witnessPath,\n ccsPath,\n pkPath,\n ]);\n }\n\n /**\n * Run sunspot verify to verify a proof\n * Inputs: circuit.vk, circuit.proof, circuit.pw\n * Returns: true if verification succeeds\n */\n async sunspotVerify(\n vkPath: string,\n proofPath: string,\n publicWitnessPath: string\n ): Promise<CliResult> {\n return this.execute(this.config.sunspotBinaryPath, [\n 'verify',\n vkPath,\n proofPath,\n publicWitnessPath,\n ]);\n }\n}\n","import { Chain } from './chain.js';\n\n/**\n * Available proving system providers\n */\nexport enum Provider {\n /** Barretenberg backend - browser compatible, UltraHonk proofs (~16KB) */\n Barretenberg = 'barretenberg',\n /** Arkworks WASM backend - browser compatible, Groth16 proofs (~256 bytes) */\n Arkworks = 'arkworks',\n /** Sunspot CLI backend - Node.js only, Groth16 proofs (~256 bytes) */\n Sunspot = 'sunspot',\n}\n\n/**\n * Configuration for circuit paths (required for Sunspot)\n */\nexport interface CircuitPaths {\n /** Path to the proving key file */\n pkPath: string;\n /** Path to the verification key file */\n vkPath: string;\n /** Path to the compiled circuit JSON file */\n circuitPath: string;\n}\n\n/**\n * Configuration for IziNoir initialization\n */\nexport interface IziNoirConfig {\n /** The proving system provider to use */\n provider: Provider;\n /**\n * Target blockchain for proof formatting.\n * If omitted, operates in offchain mode (raw proofs, no chain formatting).\n */\n chain?: Chain;\n /** Circuit paths - required for Sunspot provider */\n circuitPaths?: CircuitPaths;\n}\n\n// Re-export Chain for convenience\nexport { Chain };\n","/**\n * Sunspot entry point for Node.js.\n *\n * This module provides Sunspot support which is NOT available in the main\n * `@izi-noir/sdk` entry point due to Node.js-only dependencies.\n *\n * Note: Sunspot requires nargo and sunspot CLI tools to be installed.\n *\n * @example Using Sunspot directly\n * ```typescript\n * import { Sunspot } from '@izi-noir/sdk/sunspot';\n *\n * // Full compilation mode\n * const sunspot = new Sunspot();\n * const circuit = await sunspot.compile(noirCode);\n * const proof = await sunspot.generateProof(circuit, inputs);\n * const verified = await sunspot.verifyProof(circuit, proof.proof, proof.publicInputs);\n *\n * // Pre-compiled mode\n * const sunspot = new Sunspot({\n * pkPath: './circuit/circuit.pk',\n * vkPath: './circuit/circuit.vk',\n * circuitPath: './circuit/circuit.json',\n * });\n * ```\n *\n * @example Using initSunspotIziNoir helper\n * ```typescript\n * import { initSunspotIziNoir } from '@izi-noir/sdk/sunspot';\n *\n * const izi = await initSunspotIziNoir({\n * pkPath: './circuit/circuit.pk',\n * vkPath: './circuit/circuit.vk',\n * circuitPath: './circuit/circuit.json',\n * });\n *\n * // Use like regular IziNoir (but only prove/verify, not compile)\n * const proof = await izi.prove(inputs);\n * const verified = await izi.verify(proof.proof, proof.publicInputs);\n * ```\n *\n * @module @izi-noir/sdk/sunspot\n */\n\nimport type { IProvingSystem } from '../domain/interfaces/proving/IProvingSystem.js';\nimport type { CompiledCircuit, InputMap, ProofData } from '../domain/types.js';\nimport type { CircuitPaths } from '../domain/types/provider.js';\nimport { Sunspot } from '../infra/provingSystems/Sunspot.js';\n\nexport { Sunspot } from '../infra/provingSystems/Sunspot.js';\nexport type { SunspotInitConfig } from '../infra/provingSystems/Sunspot.js';\nexport type {\n SunspotConfig,\n SunspotCircuitPaths,\n SunspotCompiledCircuit,\n} from '../infra/sunspot/types.js';\nexport { isSunspotCircuit, SunspotCliError } from '../infra/sunspot/types.js';\n\n// Re-export common types\nexport { Provider, type IziNoirConfig, type CircuitPaths } from '../domain/types/provider.js';\nexport type { CompiledCircuit, InputMap, ProofData } from '../domain/types.js';\nexport type { IProvingSystem } from '../domain/interfaces/proving/IProvingSystem.js';\n\n/**\n * IziNoir-like wrapper for Sunspot.\n * Provides a similar API to IziNoir but backed by the Sunspot proving system.\n */\nexport class IziNoirSunspot {\n private provingSystem: IProvingSystem;\n private compiledCircuit: CompiledCircuit | null = null;\n\n private constructor(provingSystem: IProvingSystem) {\n this.provingSystem = provingSystem;\n }\n\n /**\n * Initialize IziNoirSunspot with pre-compiled circuit paths.\n * Note: Sunspot requires pre-compiled circuits for prove/verify operations.\n *\n * @param circuitPaths - Paths to the pre-compiled circuit files\n */\n static async init(circuitPaths: CircuitPaths): Promise<IziNoirSunspot> {\n const sunspot = new Sunspot(circuitPaths);\n return new IziNoirSunspot(sunspot);\n }\n\n /**\n * Initialize IziNoirSunspot for full compilation mode.\n * Requires nargo and sunspot CLI tools to be installed.\n */\n static async initForCompilation(): Promise<IziNoirSunspot> {\n const sunspot = new Sunspot();\n return new IziNoirSunspot(sunspot);\n }\n\n getProvingSystem(): IProvingSystem {\n return this.provingSystem;\n }\n\n getCompiledCircuit(): CompiledCircuit | null {\n return this.compiledCircuit;\n }\n\n async compile(noirCode: string): Promise<CompiledCircuit> {\n this.compiledCircuit = await this.provingSystem.compile(noirCode);\n return this.compiledCircuit;\n }\n\n async prove(inputs: InputMap, circuit?: CompiledCircuit): Promise<ProofData> {\n const circuitToUse = circuit || this.compiledCircuit;\n if (!circuitToUse) {\n throw new Error('No circuit available. Call compile() first or provide a circuit.');\n }\n return this.provingSystem.generateProof(circuitToUse, inputs);\n }\n\n async verify(\n proof: Uint8Array,\n publicInputs: string[],\n circuit?: CompiledCircuit\n ): Promise<boolean> {\n const circuitToUse = circuit || this.compiledCircuit;\n if (!circuitToUse) {\n throw new Error('No circuit available. Call compile() first or provide a circuit.');\n }\n return this.provingSystem.verifyProof(circuitToUse, proof, publicInputs);\n }\n\n async createProof(\n noirCode: string,\n inputs: InputMap\n ): Promise<{ proof: ProofData; verified: boolean }> {\n const circuit = await this.compile(noirCode);\n const proof = await this.prove(inputs, circuit);\n const verified = await this.verify(proof.proof, proof.publicInputs, circuit);\n return { proof, verified };\n }\n}\n\n/**\n * Helper function to create an IziNoirSunspot instance with pre-compiled circuit paths.\n * @deprecated Use `IziNoirSunspot.init(circuitPaths)` instead.\n */\nexport async function initSunspotIziNoir(circuitPaths: CircuitPaths): Promise<IziNoirSunspot> {\n return IziNoirSunspot.init(circuitPaths);\n}\n"],"mappings":";AAAA,SAAS,UAAU,WAAW,IAAI,SAAS,aAAa;AACxD,SAAS,MAAM,eAAe;AAC9B,SAAS,cAAc;;;ACchB,IAAM,yBAAwC;AAAA,EACnD,iBAAiB,QAAQ,IAAI,cAAc;AAAA,EAC3C,mBAAmB,QAAQ,IAAI,gBAAgB;AAAA,EAC/C,eAAe,QAAQ,IAAI,2BAA2B;AAAA,EACtD,WAAW;AACb;AAyCO,SAAS,iBAAiB,SAA6D;AAC5F,SAAO,eAAe,WAAY,QAAmC,cAAc;AACrF;AAcO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YACE,SACgB,SACA,UACA,QAChB;AACA,UAAM,OAAO;AAJG;AACA;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;ACxFA,SAAS,aAAa;AAOf,IAAM,qBAAN,MAAyB;AAAA,EAC9B,YAA6B,QAAuB;AAAvB;AAAA,EAAwB;AAAA;AAAA;AAAA;AAAA,EAKrD,MAAc,QAAQ,SAAiB,MAAgB,KAAkC;AACvF,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,YAAM,OAAO,MAAM,SAAS,MAAM;AAAA,QAChC;AAAA,QACA,SAAS,KAAK,OAAO;AAAA,QACrB,KAAK,EAAE,GAAG,QAAQ,IAAI;AAAA,MACxB,CAAC;AAED,UAAI,SAAS;AACb,UAAI,SAAS;AAEb,WAAK,OAAO,GAAG,QAAQ,CAAC,SAAS;AAC/B,kBAAU,KAA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IAAI,MAAM,kEAAkE;AAAA,IACpF;AACA,WAAO,KAAK,cAAc,cAAc,cAAc,MAAM;AAAA,EAC9D;AAAA,EAEA,MAAM,OACJ,OACA,cACA,SACkB;AAClB,UAAM,eAAe,WAAW,KAAK;AACrC,QAAI,CAAC,cAAc;AACjB,YAAM,IAAI,MAAM,kEAAkE;AAAA,IACpF;AACA,WAAO,KAAK,cAAc,YAAY,cAAc,OAAO,YAAY;AAAA,EACzE;AAAA,EAEA,MAAM,YACJ,UACA,QACkD;AAClD,UAAM,UAAU,MAAM,KAAK,QAAQ,QAAQ;AAC3C,UAAM,QAAQ,MAAM,KAAK,MAAM,QAAQ,OAAO;AAC9C,UAAM,WAAW,MAAM,KAAK,OAAO,MAAM,OAAO,MAAM,cAAc,OAAO;AAC3E,WAAO,EAAE,OAAO,SAAS;AAAA,EAC3B;AACF;AAMA,eAAsB,mBAAmB,cAAqD;AAC5F,SAAO,eAAe,KAAK,YAAY;AACzC;","names":["Provider"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
type InputValue = number | string | bigint;
|
|
2
|
+
interface ProofTimings {
|
|
3
|
+
parseMs: number;
|
|
4
|
+
generateMs: number;
|
|
5
|
+
compileMs: number;
|
|
6
|
+
witnessMs: number;
|
|
7
|
+
proofMs: number;
|
|
8
|
+
verifyMs: number;
|
|
9
|
+
totalMs: number;
|
|
10
|
+
}
|
|
11
|
+
interface ProofResult {
|
|
12
|
+
proof: Uint8Array;
|
|
13
|
+
publicInputs: string[];
|
|
14
|
+
verified: boolean;
|
|
15
|
+
noirCode: string;
|
|
16
|
+
timings: ProofTimings;
|
|
17
|
+
}
|
|
18
|
+
type CircuitFunction = (publicArgs: InputValue[], privateArgs: InputValue[]) => void;
|
|
19
|
+
interface ProofData {
|
|
20
|
+
proof: Uint8Array;
|
|
21
|
+
publicInputs: string[];
|
|
22
|
+
}
|
|
23
|
+
interface ProverOptions {
|
|
24
|
+
threads?: number;
|
|
25
|
+
verbose?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface VerifierOptions {
|
|
28
|
+
verbose?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Verifying key data for on-chain verification.
|
|
32
|
+
* Stored on the IziNoir instance after prove() is called.
|
|
33
|
+
*/
|
|
34
|
+
interface VerifyingKeyData {
|
|
35
|
+
/** Base64-encoded VK in gnark format */
|
|
36
|
+
base64: string;
|
|
37
|
+
/** Raw VK bytes */
|
|
38
|
+
bytes: Uint8Array;
|
|
39
|
+
/** Number of public inputs for this circuit */
|
|
40
|
+
nrPublicInputs: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Data ready for Solana on-chain verification.
|
|
44
|
+
*
|
|
45
|
+
* Contains everything needed to:
|
|
46
|
+
* 1. Initialize a VK account (`verifyingKey`)
|
|
47
|
+
* 2. Verify a proof on-chain (`proof` + `publicInputs`)
|
|
48
|
+
*
|
|
49
|
+
* All data is pre-formatted for direct use with the IZI-NOIR Solana program,
|
|
50
|
+
* eliminating the need for manual copy-paste from the frontend.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const izi = await IziNoir.init({ provider: Provider.Arkworks, chain: Chain.Solana });
|
|
55
|
+
* await izi.compile(noirCode);
|
|
56
|
+
* const solanaProof = await izi.prove(inputs);
|
|
57
|
+
*
|
|
58
|
+
* // Use directly in tests or transactions:
|
|
59
|
+
* await program.methods.initVkFromBytes(
|
|
60
|
+
* solanaProof.verifyingKey.nrPublicInputs,
|
|
61
|
+
* Buffer.from(solanaProof.verifyingKey.bytes)
|
|
62
|
+
* ).rpc();
|
|
63
|
+
*
|
|
64
|
+
* await program.methods.verifyProof(
|
|
65
|
+
* Buffer.from(solanaProof.proof.bytes),
|
|
66
|
+
* solanaProof.publicInputs.bytes.map(b => Array.from(b))
|
|
67
|
+
* ).rpc();
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
interface SolanaProofData {
|
|
71
|
+
/** Verifying key for init_vk instruction */
|
|
72
|
+
verifyingKey: VerifyingKeyData;
|
|
73
|
+
/** Groth16 proof for verify_proof instruction */
|
|
74
|
+
proof: {
|
|
75
|
+
/** Base64-encoded proof (256 bytes) */
|
|
76
|
+
base64: string;
|
|
77
|
+
/** Raw proof bytes */
|
|
78
|
+
bytes: Uint8Array;
|
|
79
|
+
};
|
|
80
|
+
/** Public inputs for the proof */
|
|
81
|
+
publicInputs: {
|
|
82
|
+
/** Hex-encoded inputs (0x prefixed) */
|
|
83
|
+
hex: string[];
|
|
84
|
+
/** 32-byte arrays for each input */
|
|
85
|
+
bytes: Uint8Array[];
|
|
86
|
+
};
|
|
87
|
+
/** Estimated VK account size in bytes */
|
|
88
|
+
accountSize: number;
|
|
89
|
+
/** Estimated rent in lamports for the VK account */
|
|
90
|
+
estimatedRent: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export type { CircuitFunction as C, InputValue as I, ProofData as P, SolanaProofData as S, VerifyingKeyData as V, ProofResult as a, ProofTimings as b, ProverOptions as c, VerifierOptions as d };
|