@affix-io/sdk 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env.example ADDED
@@ -0,0 +1,5 @@
1
+ # Copy to .env. The key below is the public SDK tier (6 req/sec per IP).
2
+ # Commercial keys: contact AffixIO.
3
+
4
+ AFFIX_API_KEY=aio_1b51ae929fb4ac1e78e6d5f61ab50262a4302dedbfd9b583
5
+ AFFIX_API_BASE=https://api.affix-io.com
package/AUTHORS ADDED
@@ -0,0 +1,5 @@
1
+ # Authors
2
+
3
+ AffixIO <dev@affix-io.com>
4
+
5
+ Maintained by [AffixIO](https://github.com/AffixIO).
@@ -0,0 +1,32 @@
1
+ # Contributing
2
+
3
+ This repository ships compiled JavaScript in `dist/`. TypeScript source is maintained privately by AffixIO.
4
+
5
+ ## What we accept
6
+
7
+ - Documentation fixes (README, SECURITY, examples)
8
+ - Issue reports with reproduction steps
9
+ - Feature requests with concrete use cases
10
+
11
+ ## What we do not accept
12
+
13
+ - Pull requests that modify `dist/` directly
14
+ - Changes that expose witness construction or circuit internals
15
+
16
+ ## Development setup
17
+
18
+ ```bash
19
+ git clone https://github.com/AffixIO/SDK.git
20
+ cd SDK
21
+ npm install
22
+ cp .env.example .env
23
+ npx affix-sdk health
24
+ ```
25
+
26
+ ## Code of conduct
27
+
28
+ Be direct, stay on topic, no harassment.
29
+
30
+ ## Commercial access
31
+
32
+ For source access, custom circuits, or higher API limits: [affix-io.com](https://affix-io.com).
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 AffixIO
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,7 @@
1
+ AffixIO SDK
2
+ Copyright 2026 AffixIO
3
+
4
+ This product includes software developed for zero-knowledge proof generation
5
+ and verification using Noir circuits and the Barretenberg proving system.
6
+
7
+ Post-quantum attestation uses ML-DSA-65 as specified in NIST FIPS 204.
package/README.md ADDED
@@ -0,0 +1,211 @@
1
+ # AffixIO SDK
2
+
3
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
4
+ [![Node](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](package.json)
5
+ [![FIPS 204](https://img.shields.io/badge/FIPS%20204-ML--DSA-blue)](https://csrc.nist.gov/pubs/fips/204/final)
6
+ [![ZK](https://img.shields.io/badge/zero--knowledge-Noir%20%2B%20Barretenberg-8b5cf6)](https://noir-lang.org/)
7
+
8
+ Node.js SDK for **privacy-preserving zero-knowledge proofs** with **post-quantum attestation**. Prove eligibility, KYC outcomes, age checks, residency, and other predicates without exposing raw credentials. Verify proofs locally or via the AffixIO API.
9
+
10
+ Built for developers working with [Noir](https://noir-lang.org/) circuits, [Barretenberg](https://github.com/AztecProtocol/barretenberg) (UltraHonk), verifiable credentials, and [NIST post-quantum standards](https://csrc.nist.gov/projects/post-quantum-cryptography) ([FIPS 204 ML-DSA](https://csrc.nist.gov/pubs/fips/204/final)).
11
+
12
+ ## Why AffixIO
13
+
14
+ Classical signatures (ECDSA, EdDSA, RSA) are vulnerable to future quantum attacks via Shor's algorithm. NIST finalised ML-KEM, ML-DSA, and SLH-DSA in 2024. AffixIO combines:
15
+
16
+ - **Zero-knowledge SNARK proving** over Noir attestation circuits (115+ templates)
17
+ - **ML-DSA-65 (FIPS 204)** signatures on proof payloads and credentials
18
+ - **Merkle audit anchoring** for tamper-evident proof history
19
+ - **Offline-first queue** for unreliable networks
20
+
21
+ You get prove, verify, storage, and a CLI without running a proving cluster locally.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ npm install @affix-io/sdk
27
+ ```
28
+
29
+ Or clone this repository (compiled `dist/` only):
30
+
31
+ ```bash
32
+ git clone https://github.com/AffixIO/SDK.git
33
+ cd SDK
34
+ npm install
35
+ cp .env.example .env
36
+ ```
37
+
38
+ Requires Node.js 18+.
39
+
40
+ ## Quick start
41
+
42
+ ```typescript
43
+ import { AffixSDK, defaultContext } from "@affix-io/sdk";
44
+
45
+ const sdk = new AffixSDK();
46
+
47
+ const result = await sdk.prove({
48
+ circuitId: "attested_boolean",
49
+ credential: {
50
+ schema_id: "eligibility_v1",
51
+ issuer_id: "issuer_abc",
52
+ issuer_pubkey_hash: "0x...",
53
+ credential_id: "0x...",
54
+ claim_value: "approved",
55
+ valid_from: 1700000000,
56
+ valid_until: 1800000000,
57
+ },
58
+ context: defaultContext({ required_claim_hash: "approved" }),
59
+ });
60
+
61
+ console.log(result.valid, result.decision);
62
+ ```
63
+
64
+ ```bash
65
+ npx affix-sdk health
66
+ npx affix-sdk prove --circuit attested_boolean --claim approved
67
+ npx affix-sdk verify <proof-id>
68
+ ```
69
+
70
+ ## API key
71
+
72
+ A public-tier key ships in `.env.example` (6 requests/second per IP). Copy to `.env`:
73
+
74
+ ```bash
75
+ cp .env.example .env
76
+ ```
77
+
78
+ | Variable | Required | Default |
79
+ |---|---|---|
80
+ | `AFFIX_API_KEY` | Yes | Public tier key in `.env.example` |
81
+ | `AFFIX_API_BASE` | No | `https://api.affix-io.com` |
82
+
83
+ Commercial keys with higher throughput: [affix-io.com](https://affix-io.com).
84
+
85
+ ## Prove input modes
86
+
87
+ `prove()` accepts one of three shapes.
88
+
89
+ ### 1. Credential + context (recommended)
90
+
91
+ Credentials are normalised to BN254 field elements, witness-prepared server-side, then proved.
92
+
93
+ ```typescript
94
+ await sdk.prove({ circuitId, credential, context });
95
+ ```
96
+
97
+ ### 2. Pre-built witness
98
+
99
+ Call `buildWitness()` (`POST /v1/witness/prepare`) then prove:
100
+
101
+ ```typescript
102
+ const witness = await sdk.buildWitness(circuitId, credential, context);
103
+ await sdk.prove({ circuitId, witness });
104
+ ```
105
+
106
+ ### 3. Raw circuit fields
107
+
108
+ For Merkle batch proofs and custom Noir inputs:
109
+
110
+ ```typescript
111
+ await sdk.prove({
112
+ circuitId: "merkle_batch",
113
+ fields: { leaf: "0x...", sibling0: "0x...", index: "0", expected_root: "0x..." },
114
+ });
115
+ ```
116
+
117
+ ## SDK methods
118
+
119
+ | Method | Description |
120
+ |---|---|
121
+ | `prove(input)` | Generate a zero-knowledge proof |
122
+ | `verify(circuitId, proof)` | Verify a proof string |
123
+ | `proveAndVerify(input)` | Prove then verify in one call |
124
+ | `buildWitness(...)` | Server-side witness preparation |
125
+ | `isOnline()` | API health check |
126
+ | `flushOfflineQueue()` | Replay queued prove jobs |
127
+ | `listQueuedJobs()` | Inspect offline queue |
128
+ | `listStoredProofs()` | Local proof store (last 500) |
129
+
130
+ ## CLI
131
+
132
+ ```bash
133
+ npx affix-sdk config
134
+ npx affix-sdk health
135
+ npx affix-sdk circuits
136
+ npx affix-sdk prove [--circuit <id>] [--claim <value>]
137
+ npx affix-sdk verify <proof-id-or-path> [--circuit <id>]
138
+ npx affix-sdk list
139
+ npx affix-sdk flush
140
+ ```
141
+
142
+ ## Post-quantum attestation
143
+
144
+ Proof responses can include **ML-DSA-65** attestations (FIPS 204, CRYSTALS-Dilithium family). Credentials carry `mldsa_signature_b64` for issuer binding. This aligns with the migration path described in [NIST IR 8547](https://csrc.nist.gov/pubs/ir/8547/final) toward quantum-resistant cryptography.
145
+
146
+ The proving backend uses Noir compiled to ACIR with Barretenberg UltraHonk, the same stack documented in the [Noir web app guide](https://noir-lang.org/docs/dev/guides/building_a_web_app).
147
+
148
+ ## Circuit library
149
+
150
+ 115+ attested Noir circuits including:
151
+
152
+ | Domain | Examples |
153
+ |---|---|
154
+ | Identity / KYC | `kyc`, `attested_boolean`, `attested_membership` |
155
+ | Age / health | `health_age`, `health_vaccination_status` |
156
+ | Residency / travel | `ticket_local_resident`, `travel_visa_eligibility` |
157
+ | Education | `edu_attendance_threshold`, `edu_enrollment_verification` |
158
+ | Merkle / audit | `merkle_batch`, `audit_proof`, `quantum_safe_token` |
159
+ | Governance | `govt_voting_eligibility`, `zk_voting` |
160
+
161
+ Run `npx affix-sdk circuits` for the full list from the live API.
162
+
163
+ ## Offline queue
164
+
165
+ When `prove()` fails and `queueOnFailure` is not `false`:
166
+
167
+ 1. **Witness or fields** bodies queue as-is for `flushOfflineQueue()`.
168
+ 2. **Credential-based** queueing requires the private `@affix-io/sdk-witness` add-on (commercial).
169
+ 3. Online witness prep always uses `POST /v1/witness/prepare`.
170
+
171
+ Local paths: `.affix/offline-queue.json`, `.affix/proofs.json`.
172
+
173
+ ## API endpoints
174
+
175
+ | Endpoint | Purpose |
176
+ |---|---|
177
+ | `GET /api/health` | Service health |
178
+ | `GET /v1/circuits` | Circuit catalogue |
179
+ | `POST /v1/witness/prepare` | Witness preparation |
180
+ | `POST /v1/circuits/:id/prove` | SNARK proof generation |
181
+ | `POST /v1/circuits/:id/verify` | Proof verification |
182
+ | `GET /v1/merkle/root` | Audit Merkle root |
183
+ | `POST /v1/merkle/audit` | Anchor proof to audit log |
184
+
185
+ ## Use cases
186
+
187
+ - **Privacy-preserving KYC**: prove eligibility without revealing PII
188
+ - **Age verification**: `health_age`, `ent_age_restriction`, `hosp_checkin_age`
189
+ - **Local residency / ticketing**: `ticket_local_resident`, `ticket_student_discount`
190
+ - **Verifiable credentials**: ML-DSA-signed claims with ZK predicates
191
+ - **Compliance audit trails**: Merkle-anchored proof history
192
+ - **Quantum-safe token validation**: `quantum_safe_token` circuit
193
+
194
+ ## Related projects
195
+
196
+ - [noir-lang/noir](https://github.com/noir-lang/noir) — ZK domain-specific language
197
+ - [@aztec/bb.js](https://www.npmjs.com/package/@aztec/bb.js) — Barretenberg proving backend
198
+ - [@noble/post-quantum](https://www.npmjs.com/package/@noble/post-quantum) — ML-DSA / SLH-DSA primitives
199
+ - [NIST PQC standards](https://csrc.nist.gov/projects/post-quantum-cryptography) — FIPS 203, 204, 205
200
+
201
+ ## License
202
+
203
+ Apache License 2.0. See [LICENSE](LICENSE).
204
+
205
+ ## Security
206
+
207
+ Report vulnerabilities via [SECURITY.md](SECURITY.md).
208
+
209
+ ---
210
+
211
+ Maintained by [AffixIO](https://github.com/AffixIO). See [AUTHORS](AUTHORS).
package/SECURITY.md ADDED
@@ -0,0 +1,39 @@
1
+ # Security policy
2
+
3
+ ## Supported versions
4
+
5
+ | Version | Supported |
6
+ |---|---|
7
+ | 2.x | Yes |
8
+
9
+ ## Reporting a vulnerability
10
+
11
+ Email security@affix-io.com with:
12
+
13
+ - Description of the issue
14
+ - Steps to reproduce
15
+ - Impact assessment (confidentiality, integrity, availability)
16
+ - Proof-of-concept if available
17
+
18
+ Do not open public GitHub issues for security reports.
19
+
20
+ We aim to acknowledge reports within 72 hours.
21
+
22
+ ## Scope
23
+
24
+ In scope:
25
+
26
+ - This SDK package (`dist/`, CLI, local storage)
27
+ - Credential handling and offline queue behaviour
28
+ - TLS certificate pinning in `certs/`
29
+
30
+ Out of scope:
31
+
32
+ - The AffixIO API infrastructure (report separately)
33
+ - Third-party proving backends (Noir, Barretenberg, noble-post-quantum)
34
+
35
+ ## Safe defaults
36
+
37
+ - Never commit `.env` with production API keys
38
+ - Use commercial keys for production workloads
39
+ - The public-tier key is rate-limited (6 req/sec per IP)
@@ -0,0 +1,36 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIGTDCCBDSgAwIBAgIQOXpmzCdWNi4NqofKbqvjsTANBgkqhkiG9w0BAQwFADBf
3
+ MQswCQYDVQQGEwJHQjEYMBYGA1UEChMPU2VjdGlnbyBMaW1pdGVkMTYwNAYDVQQD
4
+ Ey1TZWN0aWdvIFB1YmxpYyBTZXJ2ZXIgQXV0aGVudGljYXRpb24gUm9vdCBSNDYw
5
+ HhcNMjEwMzIyMDAwMDAwWhcNMzYwMzIxMjM1OTU5WjBgMQswCQYDVQQGEwJHQjEY
6
+ MBYGA1UEChMPU2VjdGlnbyBMaW1pdGVkMTcwNQYDVQQDEy5TZWN0aWdvIFB1Ymxp
7
+ YyBTZXJ2ZXIgQXV0aGVudGljYXRpb24gQ0EgRFYgUjM2MIIBojANBgkqhkiG9w0B
8
+ AQEFAAOCAY8AMIIBigKCAYEAljZf2HIz7+SPUPQCQObZYcrxLTHYdf1ZtMRe7Yeq
9
+ RPSwygz16qJ9cAWtWNTcuICc++p8Dct7zNGxCpqmEtqifO7NvuB5dEVexXn9RFFH
10
+ 12Hm+NtPRQgXIFjx6MSJcNWuVO3XGE57L1mHlcQYj+g4hny90aFh2SCZCDEVkAja
11
+ EMMfYPKuCjHuuF+bzHFb/9gV8P9+ekcHENF2nR1efGWSKwnfG5RawlkaQDpRtZTm
12
+ M64TIsv/r7cyFO4nSjs1jLdXYdz5q3a4L0NoabZfbdxVb+CUEHfB0bpulZQtH1Rv
13
+ 38e/lIdP7OTTIlZh6OYL6NhxP8So0/sht/4J9mqIGxRFc0/pC8suja+wcIUna0HB
14
+ pXKfXTKpzgis+zmXDL06ASJf5E4A2/m+Hp6b84sfPAwQ766rI65mh50S0Di9E3Pn
15
+ 2WcaJc+PILsBmYpgtmgWTR9eV9otfKRUBfzHUHcVgarub/XluEpRlTtZudU5xbFN
16
+ xx/DgMrXLUAPaI60fZ6wA+PTAgMBAAGjggGBMIIBfTAfBgNVHSMEGDAWgBRWc1hk
17
+ lfmSGrASKgRieaFAFYghSTAdBgNVHQ4EFgQUaMASFhgOr872h6YyV6NGUV3LBycw
18
+ DgYDVR0PAQH/BAQDAgGGMBIGA1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0lBBYwFAYI
19
+ KwYBBQUHAwEGCCsGAQUFBwMCMBsGA1UdIAQUMBIwBgYEVR0gADAIBgZngQwBAgEw
20
+ VAYDVR0fBE0wSzBJoEegRYZDaHR0cDovL2NybC5zZWN0aWdvLmNvbS9TZWN0aWdv
21
+ UHVibGljU2VydmVyQXV0aGVudGljYXRpb25Sb290UjQ2LmNybDCBhAYIKwYBBQUH
22
+ AQEEeDB2ME8GCCsGAQUFBzAChkNodHRwOi8vY3J0LnNlY3RpZ28uY29tL1NlY3Rp
23
+ Z29QdWJsaWNTZXJ2ZXJBdXRoZW50aWNhdGlvblJvb3RSNDYucDdjMCMGCCsGAQUF
24
+ BzABhhdodHRwOi8vb2NzcC5zZWN0aWdvLmNvbTANBgkqhkiG9w0BAQwFAAOCAgEA
25
+ YtOC9Fy+TqECFw40IospI92kLGgoSZGPOSQXMBqmsGWZUQ7rux7cj1du6d9rD6C8
26
+ ze1B2eQjkrGkIL/OF1s7vSmgYVafsRoZd/IHUrkoQvX8FZwUsmPu7amgBfaY3g+d
27
+ q1x0jNGKb6I6Bzdl6LgMD9qxp+3i7GQOnd9J8LFSietY6Z4jUBzVoOoz8iAU84OF
28
+ h2HhAuiPw1ai0VnY38RTI+8kepGWVfGxfBWzwH9uIjeooIeaosVFvE8cmYUB4TSH
29
+ 5dUyD0jHct2+8ceKEtIoFU/FfHq/mDaVnvcDCZXtIgitdMFQdMZaVehmObyhRdDD
30
+ 4NQCs0gaI9AAgFj4L9QtkARzhQLNyRf87Kln+YU0lgCGr9HLg3rGO8q+Y4ppLsOd
31
+ unQZ6ZxPNGIfOApbPVf5hCe58EZwiWdHIMn9lPP6+F404y8NNugbQixBber+x536
32
+ WrZhFZLjEkhp7fFXf9r32rNPfb74X/U90Bdy4lzp3+X1ukh1BuMxA/EEhDoTOS3l
33
+ 7ABvc7BYSQubQ2490OcdkIzUh3ZwDrakMVrbaTxUM2p24N6dB+ns2zptWCva6jzW
34
+ r8IWKIMxzxLPv5Kt3ePKcUdvkBU/smqujSczTzzSjIoR5QqQA6lN1ZRSnuHIWCvh
35
+ JEltkYnTAH41QJ6SAWO66GrrUESwN/cgZzL4JLEqz1Y=
36
+ -----END CERTIFICATE-----
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync, existsSync } from "node:fs";
3
+ import { AffixSDK, defaultContext, envStatus, loadEnv, randomFieldHex } from "./index.js";
4
+ loadEnv();
5
+ function arg(name) {
6
+ const idx = process.argv.indexOf(name);
7
+ if (idx === -1)
8
+ return undefined;
9
+ return process.argv[idx + 1];
10
+ }
11
+ function resolveVerifyTarget(sdk, target, circuitFlag) {
12
+ const stored = sdk.listStoredProofs().find((p) => p.proof_id === target);
13
+ if (stored) {
14
+ return { circuitId: stored.circuit_id, proof: stored.proof };
15
+ }
16
+ if (existsSync(target)) {
17
+ const raw = readFileSync(target, "utf8").trim();
18
+ try {
19
+ const parsed = JSON.parse(raw);
20
+ if (parsed.proof && parsed.circuit_id) {
21
+ return { circuitId: parsed.circuit_id, proof: parsed.proof };
22
+ }
23
+ if (parsed.proof && circuitFlag) {
24
+ return { circuitId: circuitFlag, proof: parsed.proof };
25
+ }
26
+ }
27
+ catch {
28
+ if (circuitFlag) {
29
+ return { circuitId: circuitFlag, proof: raw };
30
+ }
31
+ }
32
+ throw new Error("verify_path_needs_circuit_or_json_with_circuit_id");
33
+ }
34
+ if (circuitFlag) {
35
+ return { circuitId: circuitFlag, proof: target };
36
+ }
37
+ throw new Error("verify_needs_stored_proof_id_path_or_circuit");
38
+ }
39
+ async function main() {
40
+ const command = process.argv[2] ?? "health";
41
+ if (command === "config") {
42
+ console.log(JSON.stringify(envStatus(), null, 2));
43
+ return;
44
+ }
45
+ const apiKey = process.env.AFFIX_API_KEY ?? arg("--api-key");
46
+ if (!apiKey) {
47
+ const status = envStatus();
48
+ console.error(`Set AFFIX_API_KEY in ${status.env_file} or pass --api-key`);
49
+ process.exit(1);
50
+ }
51
+ const sdk = new AffixSDK({
52
+ apiKey,
53
+ apiBase: process.env.AFFIX_API_BASE ?? arg("--api-base") ?? "https://api.affix-io.com",
54
+ });
55
+ if (command === "health") {
56
+ console.log(JSON.stringify(await sdk.client.health(), null, 2));
57
+ return;
58
+ }
59
+ if (command === "flush") {
60
+ const flushed = await sdk.flushOfflineQueue();
61
+ console.log(JSON.stringify({ flushed: flushed.length, proofs: flushed }, null, 2));
62
+ return;
63
+ }
64
+ if (command === "circuits") {
65
+ console.log(JSON.stringify(await sdk.client.listCircuits(), null, 2));
66
+ return;
67
+ }
68
+ if (command === "list") {
69
+ console.log(JSON.stringify({
70
+ queued: sdk.listQueuedJobs(),
71
+ stored: sdk.listStoredProofs(),
72
+ }, null, 2));
73
+ return;
74
+ }
75
+ if (command === "verify") {
76
+ const target = process.argv[3];
77
+ if (!target) {
78
+ console.error("Usage: affix-sdk verify <proof-id-or-path> [--circuit <id>]");
79
+ process.exit(1);
80
+ }
81
+ const circuitFlag = arg("--circuit");
82
+ const { circuitId, proof } = resolveVerifyTarget(sdk, target, circuitFlag);
83
+ const result = await sdk.verify(circuitId, proof);
84
+ console.log(JSON.stringify(result, null, 2));
85
+ return;
86
+ }
87
+ if (command === "prove") {
88
+ const circuitId = arg("--circuit") ?? "ticket_local_resident";
89
+ const now = Math.floor(Date.now() / 1000);
90
+ const claim = arg("--claim") ?? "local_resident";
91
+ const region = arg("--region") ?? claim;
92
+ const schemaLabel = arg("--schema") ?? "residency_v1";
93
+ const credential = {
94
+ schema_id: schemaLabel,
95
+ issuer_id: "demo_issuer",
96
+ issuer_pubkey_hash: randomFieldHex(),
97
+ credential_id: randomFieldHex(),
98
+ claim_value: claim,
99
+ valid_from: now - 86_400,
100
+ valid_until: now + 31_536_000,
101
+ fields: { region },
102
+ };
103
+ const context = defaultContext({
104
+ region_hash: region,
105
+ as_of_timestamp: now,
106
+ });
107
+ const result = await sdk.prove({ circuitId, credential, context });
108
+ console.log(JSON.stringify(result, null, 2));
109
+ return;
110
+ }
111
+ console.log("Usage: affix-sdk config | health | prove | verify | circuits | list | flush");
112
+ }
113
+ main().catch((err) => {
114
+ console.error(err instanceof Error ? err.message : String(err));
115
+ process.exit(1);
116
+ });