/** * Authenticated Usage Example - Audit Proof Circuit * * This example demonstrates how to use the Audit Proof circuit * with the AffixIO SDK in production mode with API authentication. * * āš ļø IMPORTANT: This example requires an API key from AffixIO. * Get your API key at: https://dashboard.affix-io.com * * Prerequisites: * - npm install @affixio/sdk * - npm install typescript @types/node ts-node * - Get an API key from https://dashboard.affix-io.com * - Set AFFIXIO_API_KEY environment variable or replace the placeholder * * Run with: * AFFIXIO_API_KEY=affix_xxxxx npx ts-node examples/authenticated-usage.ts */ import { AffixIO } from '@affixio/sdk'; async function main() { // Get API key from environment variable or use placeholder const apiKey = process.env.AFFIXIO_API_KEY || 'affix_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; if (apiKey === 'affix_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') { console.error('āŒ Error: API key not provided!'); console.error(' Please set AFFIXIO_API_KEY environment variable or update the code.'); console.error(' Get your API key at: https://dashboard.affix-io.com'); process.exit(1); } // Initialize SDK with API key for production use const sdk = new AffixIO({ apiKey: apiKey, baseURL: 'https://api.affix-io.com' }); console.log('šŸ” Generating audit proof with authentication...\n'); // Example: Audit a payment authorization decision const paymentDecision = { decisionValue: 1, // 1 = approved, 0 = denied pseudonymisedId: '0x' + Buffer.from('user123').toString('hex').padStart(64, '0'), rulesHash: '0x' + Buffer.from('balance >= amount && kyc_verified').toString('hex').padStart(64, '0'), timestamp: new Date().toISOString() }; try { const result = await sdk.circuits.auditProof(paymentDecision); console.log('āœ… Audit Proof Generated:'); console.log(' Decision:', result.decision ? 'Approved' : 'Denied'); console.log(' Verified:', result.verified); console.log(' Proof ID:', result.proofId); console.log(' Timestamp:', result.timestamp); console.log(' Sector:', result.sector || 'N/A'); console.log('\n✨ Audit proof stored and verified!'); // Verify the proof console.log('\nšŸ” Verifying proof...'); const verification = await sdk.client.verifyProof({ proofId: result.proofId, proof: result.proof, publicInputs: result.publicInputs }); console.log(' Verification Result:', verification.verified ? 'āœ… Valid' : 'āŒ Invalid'); console.log(' Decision:', verification.decision); } catch (error: any) { console.error('āŒ Error generating audit proof:', error.message); if (error.statusCode) { console.error(' Status Code:', error.statusCode); } if (error.statusCode === 401) { console.error(' āš ļø Authentication failed. Please check your API key.'); console.error(' Get your API key at: https://dashboard.affix-io.com'); } } } // Run the example main().catch(console.error);