AffixIO commited on
Commit
44f0c63
·
verified ·
1 Parent(s): 7a012c1

Upload folder using huggingface_hub

Browse files
.gitignore ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Noir build artifacts
2
+ target/
3
+ **/*.json
4
+ !package.json
5
+ !tsconfig.json
6
+
7
+ # Compiled files
8
+ *.bin
9
+ *.pkey
10
+ *.vkey
11
+
12
+ # IDE files
13
+ .idea/
14
+ .vscode/
15
+ *.swp
16
+ *.swo
17
+ *~
18
+
19
+ # OS files
20
+ .DS_Store
21
+ Thumbs.db
22
+
23
+ # Logs
24
+ *.log
25
+ npm-debug.log*
26
+
27
+ # Environment files
28
+ .env
29
+ .env.local
30
+ .env.*.local
31
+
32
+ # Dependencies (if any)
33
+ node_modules/
34
+
35
+ # API Keys and secrets
36
+ *.key
37
+ *.pem
38
+ secrets/
39
+ config.local.*
40
+
CITATION.cff ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ cff-version: 1.2.0
2
+ message: "If you use this circuit, please cite it as below."
3
+ authors:
4
+ - given-names: "AffixIO"
5
+ family-names: "Team"
6
+ title: "Audit Proof Circuit - Zero-Knowledge Proof Circuit for Audit Logs"
7
+ version: "0.1.0"
8
+ date-released: "2024-01-01"
9
+ license: MIT
10
+ repository-code: "https://huggingface.co/affixio/audit-proof-circuit"
11
+ url: "https://huggingface.co/affixio/audit-proof-circuit"
12
+ keywords:
13
+ - "zero-knowledge-proof"
14
+ - "zkp"
15
+ - "audit"
16
+ - "compliance"
17
+ - "privacy"
18
+ - "noir"
19
+ abstract: "A zero-knowledge proof circuit for generating tamper-proof audit logs without exposing sensitive data. Requires AffixIO SDK with API key for production use."
20
+
LICENSE ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2024 AffixIO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
Nargo.toml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ [package]
2
+ name = "audit_proof"
3
+ version = "0.1.0"
4
+ type = "bin"
5
+
6
+ [dependencies]
7
+
Prover.toml.example ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Example Prover.toml file
2
+ # This file shows the expected input format for the circuit
3
+ # Users should create their own Prover.toml with actual values when using nargo prove
4
+ # When using the AffixIO SDK, inputs are provided programmatically via the API
5
+
6
+ decision_value = ""
7
+ pseudonymised_id = ""
8
+ rules_hash = ""
9
+ timestamp = ""
10
+
README.md CHANGED
@@ -1,3 +1,356 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Audit Proof Circuit
2
+
3
+ A zero-knowledge proof circuit for generating tamper-proof audit logs without exposing sensitive data. This circuit implements patent claims 6 and 9, providing cryptographic integrity verification for audit trails while maintaining complete privacy.
4
+
5
+ ## ⚠️ Important: SDK Required with API Key
6
+
7
+ **This circuit requires the AffixIO SDK from NPM to function. The SDK is NOT included in this repository.**
8
+
9
+ **For production use, you MUST have an API key from AffixIO. Get your API key at: https://dashboard.affix-io.com**
10
+
11
+ ## Model Details
12
+
13
+ - **Circuit Type**: Zero-Knowledge Proof (Noir)
14
+ - **Proof System**: Noir (Barretenberg backend)
15
+ - **Version**: 0.1.0
16
+ - **Use Case**: Audit logging, compliance verification, tamper-proof records
17
+ - **License**: MIT
18
+ - **Developed by**: AffixIO
19
+
20
+ ## Model Description
21
+
22
+ The Audit Proof circuit generates zero-knowledge proofs for audit logs, allowing verification of audit integrity without revealing:
23
+ - Decision values
24
+ - Timestamps
25
+ - Pseudonymised identifiers
26
+ - Rule hashes
27
+
28
+ This enables privacy-preserving compliance logging and audit trail verification across industries including finance, healthcare, government, and enterprise sectors.
29
+
30
+ ## Inputs
31
+
32
+ The circuit accepts four private inputs (all `Field` type):
33
+
34
+ | Input | Type | Description |
35
+ |-------|------|-------------|
36
+ | `decision_value` | Field | The decision value being audited |
37
+ | `timestamp` | Field | Timestamp of the audit event |
38
+ | `pseudonymised_id` | Field | Pseudonymised identifier for privacy |
39
+ | `rules_hash` | Field | Cryptographic hash of the rules applied |
40
+
41
+ ## Outputs
42
+
43
+ The circuit returns a single public output:
44
+
45
+ | Output | Type | Description |
46
+ |--------|------|-------------|
47
+ | `integrity_verified` | Field | Integrity verification result (1 = verified, 0 = failed) |
48
+
49
+ ## Installation
50
+
51
+ ### Step 1: Install the AffixIO SDK
52
+
53
+ **This is required to use this circuit. The SDK is not included in this repository.**
54
+
55
+ ```bash
56
+ npm install @affixio/sdk
57
+ ```
58
+
59
+ ### Step 2: Get Your API Key
60
+
61
+ 1. Sign up at https://dashboard.affix-io.com
62
+ 2. Navigate to API Keys section
63
+ 3. Create a new API key
64
+ 4. Copy your API key (starts with `affix_`)
65
+
66
+ ### Step 3: Install Noir (Optional - for circuit development only)
67
+
68
+ If you want to compile or modify the circuit locally:
69
+
70
+ ```bash
71
+ # Using noirup (Recommended)
72
+ curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
73
+ noirup
74
+
75
+ # Or using npm
76
+ npm install -g @noir-lang/noir_wasm
77
+
78
+ # Or using cargo
79
+ cargo install nargo
80
+ ```
81
+
82
+ ## Usage
83
+
84
+ ### Production Usage with API Key (Required)
85
+
86
+ **You must use an API key for production deployments. Sandbox mode is only for testing.**
87
+
88
+ ```typescript
89
+ import { AffixIO } from '@affixio/sdk';
90
+
91
+ // Initialize SDK with your API key
92
+ const sdk = new AffixIO({
93
+ apiKey: process.env.AFFIXIO_API_KEY || 'affix_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
94
+ baseURL: 'https://api.affix-io.com'
95
+ });
96
+
97
+ // Generate audit proof
98
+ const result = await sdk.circuits.auditProof({
99
+ decisionValue: 1, // 1 = approved, 0 = denied
100
+ pseudonymisedId: '0x1234567890abcdef1234567890abcdef',
101
+ rulesHash: '0xabcdef1234567890abcdef1234567890',
102
+ timestamp: new Date().toISOString()
103
+ });
104
+
105
+ console.log('Decision:', result.decision ? 'Approved' : 'Denied');
106
+ console.log('Verified:', result.verified);
107
+ console.log('Proof ID:', result.proofId);
108
+ console.log('Proof:', result.proof);
109
+ ```
110
+
111
+ ### Environment Variables
112
+
113
+ For security, store your API key in environment variables:
114
+
115
+ ```bash
116
+ # .env file
117
+ AFFIXIO_API_KEY=affix_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
118
+ ```
119
+
120
+ ```typescript
121
+ import { AffixIO } from '@affixio/sdk';
122
+
123
+ const sdk = new AffixIO({
124
+ apiKey: process.env.AFFIXIO_API_KEY, // Load from environment
125
+ baseURL: 'https://api.affix-io.com'
126
+ });
127
+ ```
128
+
129
+ ### Sandbox Mode (Testing Only)
130
+
131
+ **Note: Sandbox mode is for testing only. Production requires an API key.**
132
+
133
+ ```typescript
134
+ import { AffixIO } from '@affixio/sdk';
135
+
136
+ // Initialize SDK in sandbox mode (no API key needed for testing)
137
+ const sdk = new AffixIO({
138
+ sandbox: true
139
+ });
140
+
141
+ // Generate audit proof
142
+ const result = await sdk.circuits.auditProof({
143
+ decisionValue: 1,
144
+ pseudonymisedId: '0x1234567890abcdef',
145
+ rulesHash: '0xabcdef1234567890',
146
+ timestamp: new Date().toISOString()
147
+ }, true); // Use sandbox mode
148
+
149
+ console.log('Decision:', result.decision);
150
+ console.log('Verified:', result.verified);
151
+ console.log('Proof:', result.proof);
152
+ ```
153
+
154
+ ### Direct Circuit Compilation (Advanced)
155
+
156
+ If you want to compile and use the circuit directly with Noir (not recommended for production):
157
+
158
+ ```bash
159
+ # Compile the circuit
160
+ nargo compile
161
+
162
+ # This generates circuit artifacts in target/
163
+ ```
164
+
165
+ Then use with Noir SDK:
166
+
167
+ ```typescript
168
+ import { Noir } from '@noir-lang/noir_js';
169
+ import { BarretenbergBackend } from '@noir-lang/backend_barretenberg';
170
+ import circuit from './target/audit_proof.json';
171
+
172
+ // Initialize backend and circuit
173
+ const backend = new BarretenbergBackend(circuit);
174
+ const noir = new Noir(circuit);
175
+
176
+ // Prepare inputs
177
+ const inputs = {
178
+ decision_value: "1",
179
+ timestamp: "1704067200",
180
+ pseudonymised_id: "0x1234567890abcdef",
181
+ rules_hash: "0xabcdef1234567890"
182
+ };
183
+
184
+ // Generate proof
185
+ const proof = await noir.generateProof(inputs);
186
+
187
+ // Verify proof
188
+ const verification = await noir.verifyProof(proof);
189
+ console.log('Verification result:', verification);
190
+ ```
191
+
192
+ ## Examples
193
+
194
+ See the `examples/` directory for complete usage examples:
195
+ - `basic-usage.ts` - Basic SDK usage with sandbox mode
196
+ - `authenticated-usage.ts` - Production API usage with API key
197
+ - `batch-audit.ts` - Batch audit proof generation
198
+
199
+ ## Use Cases
200
+
201
+ ### Compliance & Regulatory
202
+ - **GDPR/CCPA Compliance**: Generate audit proofs without storing personal data
203
+ - **Financial Audits**: Tamper-proof transaction logs
204
+ - **Healthcare**: HIPAA-compliant audit trails
205
+ - **Government**: Secure compliance verification
206
+
207
+ ### Enterprise Applications
208
+ - **Access Control**: Audit access decisions without exposing user data
209
+ - **Decision Logging**: Privacy-preserving decision audit trails
210
+ - **Compliance Reporting**: Generate verifiable compliance reports
211
+ - **Risk Management**: Audit risk assessment decisions
212
+
213
+ ## Circuit Structure
214
+
215
+ ```
216
+ .
217
+ ├── src/
218
+ │ └── main.nr # Main circuit implementation
219
+ ├── Nargo.toml # Noir project configuration
220
+ ├── Prover.toml.example # Example prover configuration
221
+ ├── README.md # This file
222
+ ├── examples/ # Usage examples
223
+ │ ├── basic-usage.ts
224
+ │ ├── authenticated-usage.ts
225
+ │ └── batch-audit.ts
226
+ ├── metadata.yaml # Circuit metadata
227
+ ├── LICENSE # MIT License
228
+ └── CITATION.cff # Citation information
229
+ ```
230
+
231
+ ## Input Format
232
+
233
+ All inputs are Noir `Field` types, which are integers modulo the field modulus. When using the SDK, you can pass:
234
+
235
+ - **Numbers**: String representations (e.g., `"1"`, `"1704067200"`)
236
+ - **Hex Strings**: Hexadecimal strings prefixed with `0x` (e.g., `"0x1234"`)
237
+ - **BigInt**: BigInt values for large numbers
238
+ - **ISO Timestamps**: For timestamp fields, the SDK accepts ISO 8601 strings which are converted to Unix timestamps
239
+
240
+ ## Output Format
241
+
242
+ The circuit returns a `Field` value:
243
+ - `1` if integrity verification passes
244
+ - `0` if integrity verification fails
245
+
246
+ ## Security Notes
247
+
248
+ ⚠️ **Important Security Considerations**:
249
+
250
+ - **API Key Security**: Never commit API keys to version control. Always use environment variables
251
+ - This circuit uses a simplified integrity check. In production, consider implementing proper cryptographic hash verification
252
+ - Always verify proofs on-chain or in a trusted verification environment
253
+ - Keep private inputs secure and never expose them in logs or error messages
254
+ - Use the AffixIO SDK for production deployments as it includes additional security features
255
+ - Store proofs securely and maintain proof verification records
256
+
257
+ ## Performance
258
+
259
+ - **Proof Generation**: < 500ms average (online), < 200ms (offline with SDK)
260
+ - **Verification**: < 100ms average
261
+ - **Circuit Size**: Optimized for production use
262
+
263
+ ## Limitations
264
+
265
+ - Simplified integrity check (for production, use full cryptographic hashing)
266
+ - **Requires AffixIO SDK with API key for production use**
267
+ - Field size limitations apply (Noir field modulus)
268
+ - SDK must be installed separately (not included in repository)
269
+
270
+ ## API Key Management
271
+
272
+ ### Getting an API Key
273
+
274
+ 1. Visit https://dashboard.affix-io.com
275
+ 2. Sign up or log in
276
+ 3. Navigate to "API Keys" section
277
+ 4. Create a new API key
278
+ 5. Copy and store securely
279
+
280
+ ### Using API Keys Securely
281
+
282
+ ```typescript
283
+ // ✅ Good: Use environment variables
284
+ const sdk = new AffixIO({
285
+ apiKey: process.env.AFFIXIO_API_KEY
286
+ });
287
+
288
+ // ❌ Bad: Hardcode API keys
289
+ const sdk = new AffixIO({
290
+ apiKey: 'affix_my_secret_key_here' // Never do this!
291
+ });
292
+ ```
293
+
294
+ ### API Key Format
295
+
296
+ API keys start with `affix_` followed by a long alphanumeric string:
297
+ ```
298
+ affix_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
299
+ ```
300
+
301
+ ## Citation
302
+
303
+ If you use this circuit in your research or production system, please cite:
304
+
305
+ ```bibtex
306
+ @software{affixio_audit_proof,
307
+ title = {Audit Proof Circuit - Zero-Knowledge Proof for Tamper-Proof Audit Logs},
308
+ author = {AffixIO},
309
+ year = {2024},
310
+ url = {https://huggingface.co/affixio/audit-proof-circuit}
311
+ }
312
+ ```
313
+
314
+ ## License
315
+
316
+ MIT License - See LICENSE file for details
317
+
318
+ ## Contributing
319
+
320
+ Contributions to improve the circuit or documentation are welcome. Please ensure:
321
+ - All changes maintain backward compatibility
322
+ - Security best practices are followed
323
+ - Tests are included for new features
324
+
325
+ ## Support
326
+
327
+ For issues related to:
328
+
329
+ - **This Circuit**: Open an issue on the Hugging Face model page
330
+ - **AffixIO SDK**: Visit https://www.affix-io.com/docs or email support@affix-io.com
331
+ - **API Keys**: Visit https://dashboard.affix-io.com
332
+ - **Noir SDK**: Visit [Noir documentation](https://noir-lang.org/docs) or [Noir GitHub](https://github.com/noir-lang/noir)
333
+
334
+ ## References
335
+
336
+ - [AffixIO Documentation](https://www.affix-io.com/docs)
337
+ - [AffixIO SDK](https://www.npmjs.com/package/@affixio/sdk)
338
+ - [AffixIO Dashboard](https://dashboard.affix-io.com)
339
+ - [Noir Documentation](https://noir-lang.org/docs)
340
+ - [Noir GitHub Repository](https://github.com/noir-lang/noir)
341
+ - [Zero-Knowledge Proofs Explained](https://en.wikipedia.org/wiki/Zero-knowledge_proof)
342
+
343
+ ## Related Models
344
+
345
+ Check out other AffixIO circuits on Hugging Face:
346
+ - [Yes/No Decision Circuit](https://huggingface.co/affixio/yesno-circuit)
347
+ - [KYC Circuit](https://huggingface.co/affixio/kyc-circuit)
348
+ - [Eligibility Circuit](https://huggingface.co/affixio/eligibility-circuit)
349
+ - [Consent Verification Circuit](https://huggingface.co/affixio/consent-verification-circuit)
350
+
351
+ ---
352
+
353
+ **Built with ❤️ by [AffixIO](https://www.affix-io.com)**
354
+
355
+ **⚠️ Remember: This circuit requires the AffixIO SDK with an API key for production use. Get your API key at https://dashboard.affix-io.com**
356
+
examples/README.md ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Usage Examples
2
+
3
+ This directory contains example code demonstrating how to use the Audit Proof Circuit with the AffixIO SDK.
4
+
5
+ ## Prerequisites
6
+
7
+ Before running any examples, install the required dependencies:
8
+
9
+ ```bash
10
+ npm install @affixio/sdk typescript @types/node ts-node
11
+ ```
12
+
13
+ ## Examples
14
+
15
+ ### 1. Basic Usage (`basic-usage.ts`)
16
+
17
+ Demonstrates basic usage with sandbox mode (no API key required for testing).
18
+
19
+ ```bash
20
+ npx ts-node examples/basic-usage.ts
21
+ ```
22
+
23
+ **Note**: Sandbox mode is for testing only. Production requires an API key.
24
+
25
+ ### 2. Authenticated Usage (`authenticated-usage.ts`)
26
+
27
+ Demonstrates production usage with API key authentication.
28
+
29
+ **⚠️ Requires API Key**: Get your API key at https://dashboard.affix-io.com
30
+
31
+ ```bash
32
+ # Set your API key as environment variable
33
+ export AFFIXIO_API_KEY=affix_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
34
+
35
+ # Run the example
36
+ npx ts-node examples/authenticated-usage.ts
37
+ ```
38
+
39
+ Or set it inline:
40
+ ```bash
41
+ AFFIXIO_API_KEY=affix_xxxxx npx ts-node examples/authenticated-usage.ts
42
+ ```
43
+
44
+ ### 3. Batch Audit (`batch-audit.ts`)
45
+
46
+ Demonstrates generating multiple audit proofs in batch for compliance reporting.
47
+
48
+ ```bash
49
+ npx ts-node examples/batch-audit.ts
50
+ ```
51
+
52
+ ## Getting an API Key
53
+
54
+ 1. Visit https://dashboard.affix-io.com
55
+ 2. Sign up or log in
56
+ 3. Navigate to "API Keys" section
57
+ 4. Create a new API key
58
+ 5. Copy and store securely
59
+
60
+ ## Security Best Practices
61
+
62
+ - ✅ Always use environment variables for API keys
63
+ - ✅ Never commit API keys to version control
64
+ - ✅ Use sandbox mode only for testing
65
+ - ✅ Use authenticated mode for production
66
+
67
+ ## More Information
68
+
69
+ - [AffixIO SDK Documentation](https://www.affix-io.com/docs)
70
+ - [NPM Package](https://www.npmjs.com/package/@affixio/sdk)
71
+ - [Dashboard](https://dashboard.affix-io.com)
72
+
examples/authenticated-usage.ts ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Authenticated Usage Example - Audit Proof Circuit
3
+ *
4
+ * This example demonstrates how to use the Audit Proof circuit
5
+ * with the AffixIO SDK in production mode with API authentication.
6
+ *
7
+ * ⚠️ IMPORTANT: This example requires an API key from AffixIO.
8
+ * Get your API key at: https://dashboard.affix-io.com
9
+ *
10
+ * Prerequisites:
11
+ * - npm install @affixio/sdk
12
+ * - npm install typescript @types/node ts-node
13
+ * - Get an API key from https://dashboard.affix-io.com
14
+ * - Set AFFIXIO_API_KEY environment variable or replace the placeholder
15
+ *
16
+ * Run with:
17
+ * AFFIXIO_API_KEY=affix_xxxxx npx ts-node examples/authenticated-usage.ts
18
+ */
19
+
20
+ import { AffixIO } from '@affixio/sdk';
21
+
22
+ async function main() {
23
+ // Get API key from environment variable or use placeholder
24
+ const apiKey = process.env.AFFIXIO_API_KEY || 'affix_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
25
+
26
+ if (apiKey === 'affix_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') {
27
+ console.error('❌ Error: API key not provided!');
28
+ console.error(' Please set AFFIXIO_API_KEY environment variable or update the code.');
29
+ console.error(' Get your API key at: https://dashboard.affix-io.com');
30
+ process.exit(1);
31
+ }
32
+
33
+ // Initialize SDK with API key for production use
34
+ const sdk = new AffixIO({
35
+ apiKey: apiKey,
36
+ baseURL: 'https://api.affix-io.com'
37
+ });
38
+
39
+ console.log('🔐 Generating audit proof with authentication...\n');
40
+
41
+ // Example: Audit a payment authorization decision
42
+ const paymentDecision = {
43
+ decisionValue: 1, // 1 = approved, 0 = denied
44
+ pseudonymisedId: '0x' + Buffer.from('user123').toString('hex').padStart(64, '0'),
45
+ rulesHash: '0x' + Buffer.from('balance >= amount && kyc_verified').toString('hex').padStart(64, '0'),
46
+ timestamp: new Date().toISOString()
47
+ };
48
+
49
+ try {
50
+ const result = await sdk.circuits.auditProof(paymentDecision);
51
+
52
+ console.log('✅ Audit Proof Generated:');
53
+ console.log(' Decision:', result.decision ? 'Approved' : 'Denied');
54
+ console.log(' Verified:', result.verified);
55
+ console.log(' Proof ID:', result.proofId);
56
+ console.log(' Timestamp:', result.timestamp);
57
+ console.log(' Sector:', result.sector || 'N/A');
58
+ console.log('\n✨ Audit proof stored and verified!');
59
+
60
+ // Verify the proof
61
+ console.log('\n🔍 Verifying proof...');
62
+ const verification = await sdk.client.verifyProof({
63
+ proofId: result.proofId,
64
+ proof: result.proof,
65
+ publicInputs: result.publicInputs
66
+ });
67
+
68
+ console.log(' Verification Result:', verification.verified ? '✅ Valid' : '❌ Invalid');
69
+ console.log(' Decision:', verification.decision);
70
+
71
+ } catch (error: any) {
72
+ console.error('❌ Error generating audit proof:', error.message);
73
+ if (error.statusCode) {
74
+ console.error(' Status Code:', error.statusCode);
75
+ }
76
+ if (error.statusCode === 401) {
77
+ console.error(' ⚠️ Authentication failed. Please check your API key.');
78
+ console.error(' Get your API key at: https://dashboard.affix-io.com');
79
+ }
80
+ }
81
+ }
82
+
83
+ // Run the example
84
+ main().catch(console.error);
85
+
examples/basic-usage.ts ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Basic Usage Example - Audit Proof Circuit
3
+ *
4
+ * This example demonstrates how to use the Audit Proof circuit
5
+ * with the AffixIO SDK in sandbox mode (no API key required for testing).
6
+ *
7
+ * ⚠️ Note: Sandbox mode is for testing only. Production requires an API key.
8
+ *
9
+ * Prerequisites:
10
+ * - npm install @affixio/sdk
11
+ * - npm install typescript @types/node ts-node
12
+ *
13
+ * Run with: npx ts-node examples/basic-usage.ts
14
+ */
15
+
16
+ import { AffixIO } from '@affixio/sdk';
17
+
18
+ async function main() {
19
+ // Initialize SDK in sandbox mode (no API key needed for testing)
20
+ const sdk = new AffixIO({
21
+ sandbox: true
22
+ });
23
+
24
+ console.log('🔐 Generating audit proof in sandbox mode...\n');
25
+ console.log('⚠️ Note: Sandbox mode is for testing only. Production requires an API key.\n');
26
+
27
+ // Generate audit proof
28
+ const result = await sdk.circuits.auditProof({
29
+ decisionValue: 1, // Decision: approved
30
+ pseudonymisedId: '0x1234567890abcdef1234567890abcdef',
31
+ rulesHash: '0xabcdef1234567890abcdef1234567890',
32
+ timestamp: new Date().toISOString()
33
+ }, true); // Use sandbox mode
34
+
35
+ console.log('✅ Audit Proof Generated:');
36
+ console.log(' Decision:', result.decision ? 'Verified' : 'Failed');
37
+ console.log(' Verified:', result.verified);
38
+ console.log(' Proof ID:', result.proofId);
39
+ console.log(' Proof:', result.proof.substring(0, 50) + '...');
40
+ console.log(' Public Inputs:', result.publicInputs);
41
+ console.log('\n✨ Audit proof generated successfully!');
42
+ console.log('\n📝 For production use, get your API key at: https://dashboard.affix-io.com');
43
+ }
44
+
45
+ // Run the example
46
+ main().catch(console.error);
47
+
examples/batch-audit.ts ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Batch Audit Example - Audit Proof Circuit
3
+ *
4
+ * This example demonstrates how to generate multiple audit proofs
5
+ * in batch for compliance reporting or bulk operations.
6
+ *
7
+ * ⚠️ Note: This example uses sandbox mode. For production, use API key authentication.
8
+ *
9
+ * Prerequisites:
10
+ * - npm install @affixio/sdk
11
+ * - npm install typescript @types/node ts-node
12
+ *
13
+ * Run with: npx ts-node examples/batch-audit.ts
14
+ */
15
+
16
+ import { AffixIO } from '@affixio/sdk';
17
+
18
+ interface AuditEvent {
19
+ decisionValue: number;
20
+ pseudonymisedId: string;
21
+ rulesHash: string;
22
+ timestamp: string;
23
+ description: string;
24
+ }
25
+
26
+ async function generateBatchAuditProofs(sdk: AffixIO, events: AuditEvent[]) {
27
+ console.log(`📋 Generating audit proofs for ${events.length} events...\n`);
28
+
29
+ const results = [];
30
+ const errors = [];
31
+
32
+ for (let i = 0; i < events.length; i++) {
33
+ const event = events[i];
34
+ console.log(`[${i + 1}/${events.length}] Processing: ${event.description}`);
35
+
36
+ try {
37
+ const result = await sdk.circuits.auditProof({
38
+ decisionValue: event.decisionValue,
39
+ pseudonymisedId: event.pseudonymisedId,
40
+ rulesHash: event.rulesHash,
41
+ timestamp: event.timestamp
42
+ }, true); // Use sandbox mode
43
+
44
+ results.push({
45
+ event: event.description,
46
+ proofId: result.proofId,
47
+ verified: result.verified,
48
+ decision: result.decision
49
+ });
50
+
51
+ console.log(` ✅ Proof generated: ${result.proofId.substring(0, 20)}...`);
52
+ } catch (error: any) {
53
+ errors.push({
54
+ event: event.description,
55
+ error: error.message
56
+ });
57
+ console.log(` ❌ Error: ${error.message}`);
58
+ }
59
+ }
60
+
61
+ console.log('\n📊 Batch Audit Summary:');
62
+ console.log(` Total Events: ${events.length}`);
63
+ console.log(` Successful: ${results.length}`);
64
+ console.log(` Failed: ${errors.length}`);
65
+ console.log(` Success Rate: ${((results.length / events.length) * 100).toFixed(1)}%`);
66
+
67
+ return { results, errors };
68
+ }
69
+
70
+ async function main() {
71
+ // Initialize SDK
72
+ // For production, use: new AffixIO({ apiKey: process.env.AFFIXIO_API_KEY })
73
+ const sdk = new AffixIO({
74
+ sandbox: true
75
+ });
76
+
77
+ // Example: Generate audit proofs for multiple compliance events
78
+ const auditEvents: AuditEvent[] = [
79
+ {
80
+ decisionValue: 1,
81
+ pseudonymisedId: '0x' + Buffer.from('user001').toString('hex').padStart(64, '0'),
82
+ rulesHash: '0x' + Buffer.from('kyc_verified && age >= 18').toString('hex').padStart(64, '0'),
83
+ timestamp: new Date().toISOString(),
84
+ description: 'User registration - KYC verified'
85
+ },
86
+ {
87
+ decisionValue: 1,
88
+ pseudonymisedId: '0x' + Buffer.from('user002').toString('hex').padStart(64, '0'),
89
+ rulesHash: '0x' + Buffer.from('balance >= amount').toString('hex').padStart(64, '0'),
90
+ timestamp: new Date().toISOString(),
91
+ description: 'Payment authorization - Sufficient balance'
92
+ },
93
+ {
94
+ decisionValue: 0,
95
+ pseudonymisedId: '0x' + Buffer.from('user003').toString('hex').padStart(64, '0'),
96
+ rulesHash: '0x' + Buffer.from('fraud_score < threshold').toString('hex').padStart(64, '0'),
97
+ timestamp: new Date().toISOString(),
98
+ description: 'Transaction denied - High fraud score'
99
+ },
100
+ {
101
+ decisionValue: 1,
102
+ pseudonymisedId: '0x' + Buffer.from('user004').toString('hex').padStart(64, '0'),
103
+ rulesHash: '0x' + Buffer.from('consent_given && gdpr_compliant').toString('hex').padStart(64, '0'),
104
+ timestamp: new Date().toISOString(),
105
+ description: 'Data processing - GDPR consent verified'
106
+ }
107
+ ];
108
+
109
+ const { results, errors } = await generateBatchAuditProofs(sdk, auditEvents);
110
+
111
+ // Generate compliance report
112
+ console.log('\n📄 Compliance Report:');
113
+ results.forEach((result, index) => {
114
+ console.log(`\n Event ${index + 1}: ${result.event}`);
115
+ console.log(` Proof ID: ${result.proofId}`);
116
+ console.log(` Status: ${result.verified ? '✅ Verified' : '❌ Failed'}`);
117
+ console.log(` Decision: ${result.decision ? 'Approved' : 'Denied'}`);
118
+ });
119
+
120
+ if (errors.length > 0) {
121
+ console.log('\n⚠️ Errors:');
122
+ errors.forEach((error, index) => {
123
+ console.log(` ${index + 1}. ${error.event}: ${error.error}`);
124
+ });
125
+ }
126
+
127
+ console.log('\n📝 For production use, get your API key at: https://dashboard.affix-io.com');
128
+ }
129
+
130
+ // Run the example
131
+ main().catch(console.error);
132
+
metadata.yaml ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ circuit:
2
+ name: "audit_proof"
3
+ version: "0.1.0"
4
+ description: "Zero-knowledge proof circuit for generating tamper-proof audit logs without exposing sensitive data. Requires AffixIO SDK with API key for production use."
5
+ proof_system: "Noir"
6
+ backend: "Barretenberg"
7
+
8
+ inputs:
9
+ - name: "decision_value"
10
+ type: "Field"
11
+ description: "The decision value being audited"
12
+ required: true
13
+ - name: "timestamp"
14
+ type: "Field"
15
+ description: "Timestamp of the audit event"
16
+ required: true
17
+ - name: "pseudonymised_id"
18
+ type: "Field"
19
+ description: "Pseudonymised identifier for privacy"
20
+ required: true
21
+ - name: "rules_hash"
22
+ type: "Field"
23
+ description: "Cryptographic hash of the rules applied"
24
+ required: true
25
+
26
+ outputs:
27
+ - name: "integrity_verified"
28
+ type: "Field"
29
+ description: "Integrity verification result (1 = verified, 0 = failed)"
30
+
31
+ use_cases:
32
+ - "Compliance & Regulatory"
33
+ - "GDPR/CCPA Compliance"
34
+ - "Financial Audits"
35
+ - "Healthcare Audit Trails"
36
+ - "Government Compliance"
37
+ - "Enterprise Access Control"
38
+ - "Decision Logging"
39
+ - "Risk Management"
40
+
41
+ tags:
42
+ - "zero-knowledge-proof"
43
+ - "zkp"
44
+ - "audit"
45
+ - "compliance"
46
+ - "privacy"
47
+ - "noir"
48
+ - "barretenberg"
49
+ - "affixio"
50
+
51
+ requirements:
52
+ sdk: "@affixio/sdk"
53
+ sdk_npm: "https://www.npmjs.com/package/@affixio/sdk"
54
+ api_key_required: true
55
+ api_key_url: "https://dashboard.affix-io.com"
56
+ noir_version: ">=0.20.0"
57
+ node_version: ">=18.0.0"
58
+
59
+ links:
60
+ documentation: "https://www.affix-io.com/docs"
61
+ sdk: "https://www.npmjs.com/package/@affixio/sdk"
62
+ api: "https://api.affix-io.com"
63
+ dashboard: "https://dashboard.affix-io.com"
64
+ github: "https://github.com/affixio"
65
+
66
+ license: "MIT"
67
+ author: "AffixIO"
68
+
69
+ performance:
70
+ proof_generation_online: "< 500ms"
71
+ proof_generation_offline: "< 200ms"
72
+ verification: "< 100ms"
73
+
74
+ security:
75
+ note: "Uses simplified integrity check. For production, implement proper cryptographic hash verification. API key required for production use."
76
+ best_practices:
77
+ - "Always verify proofs in trusted environment"
78
+ - "Keep private inputs secure"
79
+ - "Use AffixIO SDK for production deployments"
80
+ - "Store proofs securely"
81
+ - "Never commit API keys to version control"
82
+ - "Use environment variables for API keys"
83
+
src/main.nr ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // ZKP Audit Proof Circuit
2
+ // Generates zero-knowledge proofs for audit logs without exposing data
3
+ // Patent Claim 6, 9
4
+
5
+ fn main(
6
+ decision_value: Field,
7
+ timestamp: Field,
8
+ pseudonymised_id: Field,
9
+ rules_hash: Field
10
+ ) -> pub Field {
11
+ // Generate audit proof hash
12
+ let audit_proof = decision_value + timestamp + pseudonymised_id + rules_hash;
13
+
14
+ // Verify integrity (simplified - in production use proper hash verification)
15
+ let integrity_verified = if audit_proof != 0 { 1 } else { 0 };
16
+
17
+ // Return integrity verification result
18
+ integrity_verified
19
+ }
20
+