create-izi-noir 0.1.3 → 0.1.5

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.
Files changed (2) hide show
  1. package/dist/index.js +46 -24
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -170,10 +170,9 @@ function generatePackageJson(options) {
170
170
  },
171
171
  files: ["dist", "circuits", "generated"],
172
172
  scripts: {
173
- build: "izi-noir build && tsc",
174
- "build:circuits": "izi-noir build",
175
- dev: "izi-noir build --watch",
173
+ build: "tsc",
176
174
  test: "tsx scripts/test-proof.ts",
175
+ "test:watch": "tsx watch scripts/test-proof.ts",
177
176
  prepublishOnly: "npm run build"
178
177
  },
179
178
  dependencies: {
@@ -310,6 +309,20 @@ export { ageProof } from './age-proof.js';
310
309
  `;
311
310
  }
312
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
+ }
313
326
 
314
327
  // src/generators/scripts.ts
315
328
  function generateTestScript(options) {
@@ -320,9 +333,16 @@ function generateTestScript(options) {
320
333
  *
321
334
  * Run with: npm test
322
335
  */
323
- import { IziNoir, Provider } from '@izi-noir/sdk';
336
+ import { IziNoir, Provider, AcornParser, generateNoir } from '@izi-noir/sdk';
324
337
  ${imports}
325
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
+
326
346
  async function main() {
327
347
  console.log('Initializing IZI-NOIR...');
328
348
  const izi = await IziNoir.init({
@@ -355,40 +375,41 @@ function getTests(template) {
355
375
  case "minimal":
356
376
  return ` // Test: myCircuit
357
377
  console.log('\\nTesting myCircuit...');
358
- const result1 = await izi.createProof(
359
- myCircuit,
360
- [42], // public: expected value
361
- [42] // private: actual value
362
- );
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
+ });
363
383
  console.log(' Proof verified:', result1.verified);`;
364
384
  case "balance-proof":
365
385
  return ` // Test: Balance Proof
366
386
  console.log('\\nTesting balanceProof...');
367
- const result1 = await izi.createProof(
368
- balanceProof,
369
- [100], // public: threshold
370
- [1500] // private: actual balance
371
- );
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
+ });
372
392
  console.log(' Proof verified:', result1.verified);
373
393
  console.log(' The prover has >= 100 balance (actual: hidden)');`;
374
394
  default:
375
395
  return ` // Test 1: Balance Proof
376
396
  console.log('\\nTesting balanceProof...');
377
- const result1 = await izi.createProof(
378
- balanceProof,
379
- [100], // public: threshold
380
- [1500] // private: actual balance
381
- );
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
+ });
382
402
  console.log(' Proof verified:', result1.verified);
383
403
  console.log(' The prover has >= 100 balance (actual: hidden)');
384
404
 
385
405
  // Test 2: Age Proof
386
406
  console.log('\\nTesting ageProof...');
387
- const result2 = await izi.createProof(
388
- ageProof,
389
- [2024, 18], // public: current year, minimum age
390
- [1990] // private: birth year
391
- );
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
+ });
392
413
  console.log(' Proof verified:', result2.verified);
393
414
  console.log(' The prover is >= 18 years old (birth year: hidden)');`;
394
415
  }
@@ -605,6 +626,7 @@ async function createProjectStructure(projectDir, options) {
605
626
  break;
606
627
  }
607
628
  files.push(["circuits/index.ts", generateCircuitsIndex(options.template)]);
629
+ files.push(["circuits/types.d.ts", generateCircuitTypes()]);
608
630
  files.push([
609
631
  "generated/.gitkeep",
610
632
  "# This directory contains compiled circuit artifacts\n# Generated by: npm run build\n"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-izi-noir",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "CLI to scaffold IZI-NOIR ZK projects",
5
5
  "type": "module",
6
6
  "bin": {