@affixio/sdk
v1.0.2
Published
Official AffixIO SDK for Node.js - Zero-knowledge proof verification, QR code generation, and identity verification
Maintainers
Readme
AffixIO SDK
Official Node.js SDK for AffixIO - Zero-knowledge proof verification, QR code generation, and identity verification.
Installation
npm install @affixio/sdkQuick Start
Using Email/Password Login
const AffixIO = require('@affixio/sdk');
// Initialize SDK
const affixio = new AffixIO({
// apiBaseUrl now defaults to https://www.affix-io.com, override only if needed
email: '[email protected]',
password: 'your-password',
});
// Login
await affixio.login();
// Generate QR Code
const qrCode = await affixio.generateQRCode({
verdict: 'YES',
verification_mode: 'static',
time_limit_seconds: 86400, // 24 hours
metadata: {
name: 'Age Verification',
description: 'Customer age verification',
},
});
console.log('QR Code Image:', qrCode.qr_code_image);
console.log('Verification URL:', qrCode.verification_url);Using API Key
const AffixIO = require('@affixio/sdk');
// Initialize with API key
const affixio = new AffixIO({
// apiBaseUrl now defaults to https://www.affix-io.com, override only if needed
apiKey: 'your-api-key',
});
// Generate QR Code (no login needed)
const qrCode = await affixio.generateQRCode({
verdict: 'YES',
verification_mode: 'static',
time_limit_seconds: 86400,
});Features
- ✅ Authentication - Login with email/password or use API keys
- ✅ QR Code Generation - Create QR codes with zero-knowledge proofs
- ✅ Verification - Verify QR codes offline or online
- ✅ Analytics - Track QR code usage and statistics
- ✅ Error Handling - Comprehensive error handling with typed errors
- ✅ Tracking - Built-in usage tracking (optional)
- ✅ TypeScript Support - Full TypeScript definitions included
API Reference
Authentication
Login
await affixio.login({
email: '[email protected]',
password: 'your-password',
});Logout
await affixio.logout();Check Authentication
const isAuth = affixio.isAuthenticated();QR Code Generation
Generate QR Code
const qrCode = await affixio.generateQRCode({
verdict: 'YES' | 'NO', // Required for static mode
verification_mode: 'static' | 'hermes',
time_limit_seconds: 86400, // Optional, default: 86400 (24 hours)
max_scans: 10, // Optional, null = unlimited
qr_code_type: 'verification', // Optional
metadata: { // Optional
name: 'QR Code Name',
description: 'Description',
},
hermes_route_id: 'route-slug', // Required for hermes mode
store_image: true, // Optional, default: true
});List QR Codes
const qrCodes = await affixio.getQRCodes();Get QR Code by ID
const qrCode = await affixio.getQRCode(123);Revoke QR Code
await affixio.revokeQRCode(123);Verification
Verify QR Code
const result = await affixio.verifyQRCode('token-hash', zkProof);
// or
const result = await affixio.verification.verifyByURL('https://www.affix-io.com/verify/qr/token-hash');Analytics
Get Statistics
const stats = await affixio.getAnalytics();
console.log('Total QR Codes:', stats.total_qr_codes);
console.log('Total Scans:', stats.total_scans);Error Handling
The SDK provides typed error classes:
const { AffixIOError, AffixIOAuthError, AffixIOAPIError } = require('@affixio/sdk');
try {
await affixio.generateQRCode({ verdict: 'YES' });
} catch (error) {
if (error instanceof AffixIOAuthError) {
console.error('Authentication failed:', error.message);
} else if (error instanceof AffixIOAPIError) {
console.error('API error:', error.message, error.statusCode);
} else {
console.error('Unknown error:', error.message);
}
}Configuration
Options
const affixio = new AffixIO({
apiBaseUrl: 'https://www.affix-io.com', // Optional, default: https://www.affix-io.com
apiKey: 'your-api-key', // Optional, for API key auth
email: '[email protected]', // Optional, for login
password: 'your-password', // Optional, for login
enableTracking: true, // Optional, default: true
trackingId: 'custom-id', // Optional, auto-generated if not provided
});Examples
Complete Example
const AffixIO = require('@affixio/sdk');
async function main() {
// Initialize
const affixio = new AffixIO({
email: '[email protected]',
password: 'your-password',
});
// Login
await affixio.login();
console.log('Logged in successfully');
// Generate QR Code
const qrCode = await affixio.generateQRCode({
verdict: 'YES',
verification_mode: 'static',
time_limit_seconds: 3600, // 1 hour
metadata: {
name: 'Event Ticket',
description: 'VIP Access',
},
});
console.log('QR Code generated:', qrCode.qr_code.id);
console.log('Token Hash:', qrCode.token_hash);
console.log('Expires At:', qrCode.qr_code.expires_at);
// Verify QR Code
const verification = await affixio.verifyQRCode(qrCode.token_hash);
console.log('Verified:', verification.verified);
console.log('Verdict:', verification.verdict);
// Get Analytics
const stats = await affixio.getAnalytics();
console.log('Total QR Codes:', stats.total_qr_codes);
console.log('Total Scans:', stats.total_scans);
// Logout
await affixio.logout();
console.log('Logged out');
}
main().catch(console.error);License
MIT
Support
For support, visit https://www.affix-io.com or email [email protected]
