create-izi-noir 0.1.4 → 0.1.6
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.js +44 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -309,6 +309,20 @@ export { ageProof } from './age-proof.js';
|
|
|
309
309
|
`;
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
|
+
function generateCircuitTypes() {
|
|
313
|
+
return `/**
|
|
314
|
+
* Global type declarations for IZI-NOIR circuits
|
|
315
|
+
*/
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Assert a condition that must be true for the proof to be valid.
|
|
319
|
+
* This is the core primitive for defining ZK constraints.
|
|
320
|
+
*
|
|
321
|
+
* @param condition - The boolean condition to assert
|
|
322
|
+
*/
|
|
323
|
+
declare function assert(condition: boolean): void;
|
|
324
|
+
`;
|
|
325
|
+
}
|
|
312
326
|
|
|
313
327
|
// src/generators/scripts.ts
|
|
314
328
|
function generateTestScript(options) {
|
|
@@ -319,9 +333,16 @@ function generateTestScript(options) {
|
|
|
319
333
|
*
|
|
320
334
|
* Run with: npm test
|
|
321
335
|
*/
|
|
322
|
-
import { IziNoir, Provider } from '@izi-noir/sdk';
|
|
336
|
+
import { IziNoir, Provider, AcornParser, generateNoir } from '@izi-noir/sdk';
|
|
323
337
|
${imports}
|
|
324
338
|
|
|
339
|
+
// Helper to convert JS circuit function to Noir code
|
|
340
|
+
function toNoir(circuitFn: Function): string {
|
|
341
|
+
const parser = new AcornParser();
|
|
342
|
+
const parsed = parser.parse(circuitFn, [], []);
|
|
343
|
+
return generateNoir(parsed);
|
|
344
|
+
}
|
|
345
|
+
|
|
325
346
|
async function main() {
|
|
326
347
|
console.log('Initializing IZI-NOIR...');
|
|
327
348
|
const izi = await IziNoir.init({
|
|
@@ -354,40 +375,41 @@ function getTests(template) {
|
|
|
354
375
|
case "minimal":
|
|
355
376
|
return ` // Test: myCircuit
|
|
356
377
|
console.log('\\nTesting myCircuit...');
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
);
|
|
378
|
+
const noirCode1 = toNoir(myCircuit);
|
|
379
|
+
const result1 = await izi.createProof(noirCode1, {
|
|
380
|
+
publicInput: '42', // public: expected value
|
|
381
|
+
privateInput: '42', // private: actual value
|
|
382
|
+
});
|
|
362
383
|
console.log(' Proof verified:', result1.verified);`;
|
|
363
384
|
case "balance-proof":
|
|
364
385
|
return ` // Test: Balance Proof
|
|
365
386
|
console.log('\\nTesting balanceProof...');
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
);
|
|
387
|
+
const noirCode1 = toNoir(balanceProof);
|
|
388
|
+
const result1 = await izi.createProof(noirCode1, {
|
|
389
|
+
threshold: '100', // public: minimum required
|
|
390
|
+
balance: '1500', // private: actual balance
|
|
391
|
+
});
|
|
371
392
|
console.log(' Proof verified:', result1.verified);
|
|
372
393
|
console.log(' The prover has >= 100 balance (actual: hidden)');`;
|
|
373
394
|
default:
|
|
374
395
|
return ` // Test 1: Balance Proof
|
|
375
396
|
console.log('\\nTesting balanceProof...');
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
);
|
|
397
|
+
const noirCode1 = toNoir(balanceProof);
|
|
398
|
+
const result1 = await izi.createProof(noirCode1, {
|
|
399
|
+
threshold: '100', // public: minimum required
|
|
400
|
+
balance: '1500', // private: actual balance
|
|
401
|
+
});
|
|
381
402
|
console.log(' Proof verified:', result1.verified);
|
|
382
403
|
console.log(' The prover has >= 100 balance (actual: hidden)');
|
|
383
404
|
|
|
384
405
|
// Test 2: Age Proof
|
|
385
406
|
console.log('\\nTesting ageProof...');
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
407
|
+
const noirCode2 = toNoir(ageProof);
|
|
408
|
+
const result2 = await izi.createProof(noirCode2, {
|
|
409
|
+
currentYear: '2024', // public: current year
|
|
410
|
+
minAge: '18', // public: minimum age
|
|
411
|
+
birthYear: '1990', // private: birth year
|
|
412
|
+
});
|
|
391
413
|
console.log(' Proof verified:', result2.verified);
|
|
392
414
|
console.log(' The prover is >= 18 years old (birth year: hidden)');`;
|
|
393
415
|
}
|
|
@@ -604,6 +626,7 @@ async function createProjectStructure(projectDir, options) {
|
|
|
604
626
|
break;
|
|
605
627
|
}
|
|
606
628
|
files.push(["circuits/index.ts", generateCircuitsIndex(options.template)]);
|
|
629
|
+
files.push(["circuits/types.d.ts", generateCircuitTypes()]);
|
|
607
630
|
files.push([
|
|
608
631
|
"generated/.gitkeep",
|
|
609
632
|
"# This directory contains compiled circuit artifacts\n# Generated by: npm run build\n"
|