UNPKG

ava-zk

Version:

Cross-chain ZK proof system using Circom, snarkjs, and Solidity smart contracts with Teleporter bridge integration for Avalanche subnets

138 lines (118 loc) • 3.13 kB
#!/usr/bin/env node import { execSync } from 'child_process'; import { existsSync } from 'fs'; import path from 'path'; /** * ZK Proof Cross-Chain Workflow * Programmatic interface for Circom circuits and cross-chain proof operations */ const projectRoot = process.cwd(); /** * Execute a shell script with error handling */ function executeScript(scriptPath, args = []) { const fullPath = path.join(projectRoot, scriptPath); if (!existsSync(fullPath)) { throw new Error(`Script not found: ${fullPath}`); } try { const command = `bash ${fullPath} ${args.join(' ')}`; console.log(`šŸ”„ Executing: ${command}`); const result = execSync(command, { stdio: 'inherit', cwd: projectRoot, encoding: 'utf8' }); console.log(`āœ… Script completed successfully`); return result; } catch (error) { console.error(`āŒ Script failed: ${error.message}`); throw error; } } /** * ZK Proof Workflow Operations */ export const zkProof = { /** * Run the complete Circom workflow */ workflow: (circuitFile = 'multiplier2.circom') => { return executeScript('circom_workflow.sh', [circuitFile]); }, /** * Deploy contracts to both chains */ deploy: () => { return executeScript('deploy.sh'); }, /** * Send proof cross-chain */ send: () => { return executeScript('send_proof.sh'); }, /** * Receive and verify proof */ receive: () => { return executeScript('receive_proof.sh'); }, /** * Parse proof data from contract */ parse: () => { return executeScript('parse_proof_data.py'); }, /** * Verify proof directly on receiver chain */ verifyDirect: () => { return executeScript('verify_proof_directly.sh'); } }; /** * CLI interface when run directly */ if (import.meta.url === `file://${process.argv[1]}`) { const command = process.argv[2]; const args = process.argv.slice(3); switch (command) { case 'workflow': zkProof.workflow(args[0]); break; case 'deploy': zkProof.deploy(); break; case 'send': zkProof.send(); break; case 'receive': zkProof.receive(); break; case 'parse': zkProof.parse(); break; case 'verify': zkProof.verifyDirect(); break; default: console.log(` šŸ”¬ ZK Proof Cross-Chain CLI Usage: node index.js <command> Commands: workflow [circuit] Run complete Circom workflow deploy Deploy contracts to both chains send Send proof cross-chain receive Receive and verify proof parse Parse proof data from contract verify Verify proof directly Examples: node index.js workflow multiplier2.circom node index.js deploy node index.js send node index.js receive `); } } export default zkProof;