|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { AffixIO } from '@affixio/sdk'; |
|
|
|
|
|
async function main() { |
|
|
|
|
|
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); |
|
|
} |
|
|
|
|
|
|
|
|
const sdk = new AffixIO({ |
|
|
apiKey: apiKey, |
|
|
baseURL: 'https://api.affix-io.com' |
|
|
}); |
|
|
|
|
|
console.log('π Generating audit proof with authentication...\n'); |
|
|
|
|
|
|
|
|
const paymentDecision = { |
|
|
decisionValue: 1, |
|
|
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!'); |
|
|
|
|
|
|
|
|
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'); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
main().catch(console.error); |
|
|
|
|
|
|