{"_id":"@api-mertering-zk/proof-system","_rev":"2-2770bdfe072b34ac6cb2850476e148b7","name":"@api-mertering-zk/proof-system","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"@api-mertering-zk/proof-system","version":"1.0.0","keywords":["zero-knowledge","proof-system","noir","bb.js","api-metering","zk-snark","ethereum","api-payments"],"author":{"name":"Your Name"},"license":"MIT","_id":"@api-mertering-zk/proof-system@1.0.0","maintainers":[{"name":"manansinghal","email":"web3.manan@gmail.com"}],"homepage":"https://github.com/MananSinghal123/eth-api-payments#readme","bugs":{"url":"https://github.com/MananSinghal123/eth-api-payments/issues"},"dist":{"shasum":"4a75b5b799b47ab03e876becdb1da9a4c414b47b","tarball":"https://registry.npmjs.org/@api-mertering-zk/proof-system/-/proof-system-1.0.0.tgz","fileCount":5,"integrity":"sha512-lrBEQbEmOxFg2l7t8gWSbTtx5HF3buKFv9/Nh0983J5WyeYIlEZ6nbwEV8tdp4Rupg3oriwZuNP+NCBBPn/nfQ==","signatures":[{"sig":"MEUCIEMCMOob+RevMdfrbSiqvmd7SXW5ZKRhRQ4g7YVSoyAYAiEAkJCrYgy5nZbvHkYzyAsoDly23VwyI6qf5BkY/Shoa2s=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":8912},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"3f9088730be3938543949e2b199ee32fce6ffc00","scripts":{"dev":"tsc --watch","build":"tsc","clean":"rm -rf dist","prepublishOnly":"npm run clean && npm run build"},"_npmUser":{"name":"manansinghal","email":"web3.manan@gmail.com"},"repository":{"url":"git+https://github.com/MananSinghal123/eth-api-payments.git","type":"git","directory":"proof-system-package"},"_npmVersion":"10.9.3","description":"Zero-knowledge proof system for API metering using Noir and bb.js","directories":{},"_nodeVersion":"22.18.0","dependencies":{"@aztec/bb.js":"^1.2.1","@noir-lang/noir_js":"^1.0.0-beta.11"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.2","@types/node":"^24.5.2"},"_npmOperationalInternal":{"tmp":"tmp/proof-system_1.0.0_1759014812726_0.47966389004073484","host":"s3://npm-registry-packages-npm-production"}},"1.2.0":{"name":"@api-mertering-zk/proof-system","version":"1.2.0","description":"Zero-knowledge proof system for API metering using Noir and bb.js","main":"dist/index.js","types":"dist/index.d.ts","type":"module","publishConfig":{"access":"public"},"exports":{".":{"import":"./dist/index.js","types":"./dist/index.d.ts"}},"scripts":{"build":"tsc","clean":"rm -rf dist","prepublishOnly":"npm run clean && npm run build","dev":"tsc --watch"},"keywords":["zero-knowledge","proof-system","noir","bb.js","api-metering","zk-snark","ethereum","api-payments"],"author":{"name":"Your Name"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/MananSinghal123/eth-api-payments.git","directory":"proof-system-package"},"dependencies":{"@aztec/bb.js":"^1.2.1","@noir-lang/noir_js":"^1.0.0-beta.11"},"devDependencies":{"@types/node":"^24.5.2","typescript":"^5.9.2"},"engines":{"node":">=18.0.0"},"_id":"@api-mertering-zk/proof-system@1.2.0","gitHead":"63541ee5d4346728e9ac268fd64dd8369224f133","bugs":{"url":"https://github.com/MananSinghal123/eth-api-payments/issues"},"homepage":"https://github.com/MananSinghal123/eth-api-payments#readme","_nodeVersion":"22.18.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-0PcDOwcAuezXvwinUmQQOa44Luoy1g47XFzJ8Btke6t3sKF4zLi9IdLc1wsvGCy+N0/Dyf7EPDxJMeN91XaWfQ==","shasum":"df6cea4bbea69bb125a14b22d3d5c0f42a03d50e","tarball":"https://registry.npmjs.org/@api-mertering-zk/proof-system/-/proof-system-1.2.0.tgz","fileCount":5,"unpackedSize":14215,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCuWVIdchu1dERkwXwEjR8PYAzFVrhPiwl7GQ0TQiQCAQIgXAJ5gBgqAEUYOQzqPNuUTVgF6IuRTI8orTopI3NK738="}]},"_npmUser":{"name":"manansinghal","email":"web3.manan@gmail.com"},"directories":{},"maintainers":[{"name":"manansinghal","email":"web3.manan@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/proof-system_1.2.0_1759016792667_0.5374021340708566"},"_hasShrinkwrap":false}},"time":{"created":"2025-09-27T23:13:32.668Z","modified":"2025-09-27T23:46:33.172Z","1.0.0":"2025-09-27T23:13:32.916Z","1.2.0":"2025-09-27T23:46:32.873Z"},"bugs":{"url":"https://github.com/MananSinghal123/eth-api-payments/issues"},"author":{"name":"Your Name"},"license":"MIT","homepage":"https://github.com/MananSinghal123/eth-api-payments#readme","keywords":["zero-knowledge","proof-system","noir","bb.js","api-metering","zk-snark","ethereum","api-payments"],"repository":{"type":"git","url":"git+https://github.com/MananSinghal123/eth-api-payments.git","directory":"proof-system-package"},"description":"Zero-knowledge proof system for API metering using Noir and bb.js","maintainers":[{"name":"manansinghal","email":"web3.manan@gmail.com"}],"readme":"# @api-mertering-zk/proof-system\n\nA zero-knowledge proof system package for API metering using Noir and bb.js. This package provides a simple interface for initializing and working with zero-knowledge proofs for API usage verification.\n\n## 🚀 Features\n\n- **Zero-knowledge proof generation and verification** using Noir circuits\n- **Built on industry-standard libraries**: Noir and bb.js (UltraHonk backend)\n- **API metering support** with pre-compiled circuits\n- **Full TypeScript support** with type definitions\n- **Dual API design**: Both class-based and functional interfaces\n- **ES modules support** with proper module resolution\n- **Error handling** with descriptive error messages\n\n## 📦 Installation\n\n```bash\nnpm install @api-mertering-zk/proof-system\n```\n\n## 🔧 Usage\n\n### Class-based API (Recommended)\n\nThe class-based API provides better encapsulation and allows for multiple instances:\n\n```typescript\nimport { ProofSystem } from '@api-mertering-zk/proof-system';\n\n// Create a new proof system instance\nconst proofSystem = new ProofSystem();\n\n// Initialize with default circuit path\nawait proofSystem.initialize();\n\n// Get the initialized instances\nconst noir = proofSystem.getNoir();\nconst backend = proofSystem.getBackend();\nconst circuit = proofSystem.getCircuit();\n\nconsole.log('Proof system ready!', proofSystem.getIsInitialized());\n```\n\n### Function-based API (Legacy Support)\n\nFor backward compatibility, a global function-based API is available:\n\n```typescript\nimport { \n  initializeProofSystem, \n  getNoir, \n  getBackend, \n  getIsInitialized \n} from '@api-mertering-zk/proof-system';\n\n// Initialize the global proof system\nawait initializeProofSystem();\n\n// Access global instances\nconst noir = getNoir();\nconst backend = getBackend();\nconst isReady = getIsInitialized();\n\nconsole.log('Global proof system ready!', isReady);\n```\n\n### Custom Circuit Path\n\nYou can specify a custom path to your compiled circuit:\n\n```typescript\nimport { ProofSystem } from '@api-mertering-zk/proof-system';\n\nconst proofSystem = new ProofSystem({\n  circuitPath: '/path/to/your/custom/circuit.json'\n});\n\nawait proofSystem.initialize();\n```\n\n### Error Handling\n\nThe package provides proper error handling:\n\n```typescript\nimport { ProofSystem } from '@api-mertering-zk/proof-system';\n\ntry {\n  const proofSystem = new ProofSystem();\n  await proofSystem.initialize();\n  \n  // Use the proof system\n  const noir = proofSystem.getNoir();\n  // ... your proof generation logic\n  \n} catch (error) {\n  console.error('Failed to initialize proof system:', error.message);\n}\n```\n\n### Integration Example\n\nHere's a complete example of how to integrate the proof system:\n\n```typescript\nimport { ProofSystem } from '@api-mertering-zk/proof-system';\n\nclass ApiMeteringService {\n  private proofSystem: ProofSystem;\n\n  constructor() {\n    this.proofSystem = new ProofSystem();\n  }\n\n  async initialize() {\n    await this.proofSystem.initialize();\n    console.log('API metering service ready!');\n  }\n\n  async generateUsageProof(apiCalls: number, timestamp: number) {\n    const noir = this.proofSystem.getNoir();\n    const backend = this.proofSystem.getBackend();\n\n    // Generate proof for API usage\n    const input = { api_calls: apiCalls, timestamp };\n    const { witness } = await noir.execute(input);\n    const proof = await backend.generateProof(witness);\n\n    return proof;\n  }\n\n  async verifyUsageProof(proof: Uint8Array, publicInputs: Uint8Array) {\n    const backend = this.proofSystem.getBackend();\n    return await backend.verifyProof(proof, publicInputs);\n  }\n}\n\n// Usage\nconst meteringService = new ApiMeteringService();\nawait meteringService.initialize();\n\nconst proof = await meteringService.generateUsageProof(100, Date.now());\nconst isValid = await meteringService.verifyUsageProof(proof, publicInputs);\n```\n\n## 📋 Requirements\n\n- **Node.js** >= 18.0.0\n- **TypeScript** >= 5.0.0 (for TypeScript projects)\n- The package includes a pre-compiled circuit (`api_metering.json`)\n\n## 📖 API Reference\n\n### ProofSystem Class\n\nThe main class for managing zero-knowledge proof operations.\n\n#### `constructor(config?: ProofSystemConfig)`\nCreates a new ProofSystem instance.\n\n**Parameters:**\n- `config` (optional): Configuration object with circuit path\n\n**Example:**\n```typescript\nconst proofSystem = new ProofSystem({\n  circuitPath: './custom/circuit.json'\n});\n```\n\n#### `initialize(): Promise<void>`\nInitializes the proof system by loading and parsing the circuit file.\n\n**Throws:**\n- `Error` if circuit file is not found or invalid\n\n#### `getNoir(): Noir`\nReturns the Noir instance for proof generation.\n\n**Throws:**\n- `Error` if called before initialization\n\n#### `getBackend(): UltraHonkBackend`\nReturns the UltraHonk backend for proof verification.\n\n**Throws:**\n- `Error` if called before initialization\n\n#### `getCircuit(): any`\nReturns the loaded circuit object.\n\n**Throws:**\n- `Error` if called before initialization\n\n#### `getIsInitialized(): boolean`\nReturns whether the system has been initialized.\n\n### Function-based API\n\nLegacy functions for backward compatibility:\n\n#### `initializeProofSystem(config?: ProofSystemConfig): Promise<void>`\nInitializes the global proof system instance.\n\n#### `getNoir(): Noir`\nReturns the global Noir instance.\n\n#### `getBackend(): UltraHonkBackend`  \nReturns the global UltraHonk backend.\n\n#### `getIsInitialized(): boolean`\nReturns whether the global system is initialized.\n\n### Types\n\n#### `ProofSystemConfig`\nConfiguration interface for the proof system.\n\n```typescript\ninterface ProofSystemConfig {\n  circuitPath?: string; // Path to compiled circuit JSON file\n}\n```\n\n#### Re-exported Types\n- `Noir`: From `@noir-lang/noir_js`\n- `UltraHonkBackend`: From `@aztec/bb.js`\n\n## 🏗️ Circuit Structure\n\nThe package expects a compiled Noir circuit in JSON format with the following structure:\n\n```json\n{\n  \"bytecode\": \"...\",      // Compiled circuit bytecode\n  \"abi\": { ... },         // Circuit ABI definition  \n  \"debug_symbols\": \"...\"  // Debug information\n}\n```\n\n## 🚦 Error Handling\n\nThe package provides descriptive error messages:\n\n- **Circuit not found**: `Compiled circuit not found at: [path]`\n- **Not initialized**: `Proof system not initialized. Call initialize() first.`\n- **JSON parse errors**: Standard JSON parsing error messages\n\n## 🔍 Troubleshooting\n\n### Common Issues\n\n1. **Circuit file not found**\n   - Ensure the circuit file exists at the specified path\n   - Check file permissions\n\n2. **Module resolution errors**\n   - Ensure you're using Node.js >= 18.0.0\n   - Check that your project supports ES modules\n\n3. **TypeScript errors**\n   - Make sure TypeScript is configured for ES modules\n   - Update your `tsconfig.json` if needed\n\n### Debug Mode\n\nEnable debug logging by setting the environment variable:\n\n```bash\nDEBUG=proof-system npm start\n```\n\n## 📄 Package Information\n\n- **Package Name**: `@api-mertering-zk/proof-system`\n- **Version**: 1.0.0\n- **License**: MIT\n- **Repository**: [eth-api-payments](https://github.com/MananSinghal123/eth-api-payments)\n\n## 🤝 Contributing\n\nContributions are welcome! Please see the main repository for contribution guidelines.\n\n## 📝 License\n\nMIT License - see the LICENSE file for details.","readmeFilename":"README.md"}