@zkpassport/aztec 0.0.0-stage → 0.1.0-beta.1

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/README.md CHANGED
@@ -1,3 +1,41 @@
1
- # Temporary Holding Version
1
+ # @zkpassport/aztec
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TS companion for the [`zkpassport_aztec_verifier`](../noir/verifier) Aztec verification
4
+ library.
5
+
6
+ ## Install
7
+
8
+ ```sh
9
+ npm install @zkpassport/aztec @aztec-labs/aztec.js@6.0 @aztec-labs/stdlib@6.0
10
+ ```
11
+
12
+ `@aztec-labs/aztec.js` and `@aztec-labs/stdlib` are peer dependencies: the package works with Aztec
13
+ 6.0.x and uses the app's own copies of them. Until the first stable release, install
14
+ `@zkpassport/aztec@beta`.
15
+
16
+ ## Features
17
+
18
+ - **`ZKPassportRegistryArtifact` + `registerZKPassportRegistry(wallet, node, address)`**: utility to register the shared registry's artifact with the user's PXE (the verifier transitively `.view()`s it during local simulation/proving).
19
+ - **`assembleProofCapsule` / `assembleDiscloseCapsule` / `assembleSanctionsCapsule`**: the proof, the disclose preimage and the sanctions root must be passed via capsules to contracts that need to verify. These functions are conveniences to do so.
20
+ - **`nationalityBytes` / `packNationality` / `isIdCard`** — TS twins of the Noir `disclosed_data` module's nationality reader. `@zkpassport/utils`' `DisclosedData.fromDisclosedBytes(bytes, isIdCard(bytes) ? "id_card" : "passport")` reads every field.
21
+ - **`fetchOuterVk(vkeyHash)`**: the outer vk from the live `circuits2.zkpassport.id` host.
22
+ - **`constants.ts`** — TS mirror of `core/src/constants.nr`.
23
+
24
+ ## Development
25
+
26
+ The package ships a copy of the compiled ZKPassportRegistry artifact without its Noir sources and
27
+ debug symbols, `registry/ZKPassportRegistry.json`. After a change to the registry, compile the Noir workspace with
28
+ the Aztec toolchain in `../.aztecrc` (see [the Noir README](../noir/README.md#running-the-tests))
29
+ and refresh the copy. CI fails while the copy's contract class differs from the compiled registry's.
30
+
31
+ ```sh
32
+ cd ../noir && aztec compile && cd ../ts
33
+ bun scripts/registry-artifact.ts copy
34
+ ```
35
+
36
+ Checks:
37
+
38
+ ```sh
39
+ bun run typecheck
40
+ bun run test
41
+ ```
@@ -0,0 +1,121 @@
1
+ import { ContractArtifact } from '@aztec-labs/aztec.js/abi';
2
+ import { Fr } from '@aztec-labs/aztec.js/fields';
3
+ import { AztecAddress } from '@aztec-labs/aztec.js/addresses';
4
+ import { ContractInstanceWithAddress } from '@aztec-labs/stdlib/contract';
5
+
6
+ /**
7
+ * The compiled ZKPassportRegistry artifact.
8
+ */
9
+
10
+ declare const ZKPassportRegistryArtifact: ContractArtifact;
11
+
12
+ /** The three field groups of an outer proof, as hex strings from the SDK/utils. */
13
+ interface OuterProofParts {
14
+ vk: string[];
15
+ proof: string[];
16
+ publicInputs: string[];
17
+ }
18
+ /**
19
+ * Assemble the proof-capsule blob the library's `load_proof_capsule` consumes:
20
+ * `vk(115) ‖ proof(458) ‖ public_inputs(K + 5)`, which can then be delivered on
21
+ * `PROOF_CAPSULE_SLOT` of the verifier contract.
22
+ *
23
+ * Shape-checks first: the on-chain load of a wrong-shaped blob just returns
24
+ * None ("missing zkpassport proof capsule"). `k` is the outer circuit's subproof count
25
+ * (`outer_count_5` → 5, the shape current SDK queries produce).
26
+ *
27
+ * Parsing note: the SDK/utils emit field elements as BARE hex (no `0x`).
28
+ * `Fr.fromString` would reject those — and silently misread an all-digit hex
29
+ * string as decimal — so every element is parsed explicitly as hex.
30
+ */
31
+ declare function assembleProofCapsule(parts: OuterProofParts, k?: number): Fr[];
32
+ /**
33
+ * Assemble the disclose preimage for `DISCLOSE_CAPSULE_SLOT`:
34
+ * `mask(90) ‖ disclosedBytes(90)`, one field per element — what the library's
35
+ * `verify_zkpassport_proof` loads when the contract's query discloses a field.
36
+ */
37
+ declare function assembleDiscloseCapsule(discloseMask: number[], disclosedBytes: number[]): Fr[];
38
+ /**
39
+ * Assemble the capsule for `SANCTIONS_CAPSULE_SLOT` from the sanctions root the proof was made
40
+ * against, the SDK's `SanctionsCommittedInputs.rootHash`.
41
+ */
42
+ declare function assembleSanctionsCapsule(rootHash: string): Fr[];
43
+
44
+ /**
45
+ * Note: this is a TS mirror of `noir/core/src/constants.nr`. That is the source of truth.
46
+ */
47
+ /** Fields in the outer circuit's UltraHonk verification key. */
48
+ declare const VK_FIELDS = 115;
49
+ /** Fields in the outer ZK UltraHonk proof. */
50
+ declare const PROOF_FIELDS = 458;
51
+ /** Capsule slot the library loads the proof blob from (per-verifier address space). */
52
+ declare const PROOF_CAPSULE_SLOT = 1n;
53
+ /** Capsule slot for the disclose preimage (mask ‖ disclosed bytes). */
54
+ declare const DISCLOSE_CAPSULE_SLOT = 2n;
55
+ /** Capsule slot for the sanctions exclusion payload. */
56
+ declare const SANCTIONS_CAPSULE_SLOT = 3n;
57
+ /** The canonical 90-byte disclose payload length (TD1 exactly; TD3 zero-padded). */
58
+ declare const MRZ_LENGTH = 90;
59
+ /** Public-input count for `outer_count_K` is K + 5; param commitments are K - 3. */
60
+ declare const outerPublicInputCount: (k: number) => number;
61
+ /** Total field count of the proof-capsule blob for `outer_count_K`. */
62
+ declare const outerCapsuleLength: (k: number) => number;
63
+
64
+ /**
65
+ * TS twin of `noir/core/src/disclosed_data.nr`.
66
+ *
67
+ * The app-side helpers here are convenience: they predict what the in-circuit
68
+ * `disclosed_nationality` will accept so the claim value can be built (and bad
69
+ * queries fail client-side with a readable error).
70
+ */
71
+ /** ICAO 9303 nationality offset in a TD3 passport MRZ (2 x 44, zero-padded to 90). */
72
+ declare const TD3_NATIONALITY_INDEX = 54;
73
+ /** ICAO 9303 nationality offset in a TD1 ID-card MRZ (3 x 30 = 90). */
74
+ declare const TD1_NATIONALITY_INDEX = 45;
75
+ /** ICAO document codes: passports start with 'P'; TD1 ID cards with 'I'/'A'/'C'. */
76
+ declare function isIdCard(disclosedBytes: number[]): boolean;
77
+ /**
78
+ * The disclosed alpha-3 nationality bytes, layout-aware. RAW, deliberately not
79
+ * normalized: German documents disclose "D<<", and normalizing to "DEU" (as
80
+ * `DisclosedData` does) would desync any packed claim value from the in-circuit
81
+ * pack.
82
+ */
83
+ declare function nationalityBytes(disclosedBytes: number[]): number[];
84
+ /**
85
+ * Big-endian pack of the 3 raw nationality bytes — equals `DisclosedNationality.packed`
86
+ * in the Noir twin and `@zkpassport/utils`' getCountryWeightedSum encoding.
87
+ */
88
+ declare function packNationality(disclosedBytes: number[]): bigint;
89
+
90
+ interface RegistryNode {
91
+ getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined>;
92
+ }
93
+ interface RegistryWallet {
94
+ registerContract(instance: ContractInstanceWithAddress, artifact: ContractArtifact): Promise<unknown>;
95
+ hasContract?(address: AztecAddress): Promise<boolean>;
96
+ }
97
+ /**
98
+ * Register the shared ZKPassportRegistry's artifact with the wallet's PXE.
99
+ *
100
+ * Any app whose verifier calls `verify_zkpassport_proof*` needs this once per
101
+ * wallet: the verifier privately `.view()`s the registry, and the PXE executes
102
+ * that call locally during simulation/proving.
103
+ */
104
+ declare function registerZKPassportRegistry(wallet: RegistryWallet, node: RegistryNode, registryAddress: AztecAddress | string, artifact?: ContractArtifact): Promise<ContractInstanceWithAddress>;
105
+
106
+ /**
107
+ * Fetch the 115-field outer vk for a proof from zkPassport's live circuit host:
108
+ * `circuits2.zkpassport.id/<net>/by-hash/<0xhash>.json` (open CORS; the same
109
+ * source `@zkpassport/registry`'s RegistryClient reads). Needed by the
110
+ * recursive `mode: "compressed"` flow — the capsule carries the full vk so the
111
+ * proof can be verified in-circuit.
112
+ *
113
+ * Why not the SDK's `getHostedPackagedCircuitByVkeyHash`: `@zkpassport/utils`
114
+ * still points it at the deprecated `circuits.zkpassport.id/hashes/…` host,
115
+ * which 404s (and the util JSON.parses the HTML body into a cryptic
116
+ * `SyntaxError: Unexpected token '<'`). Collapse back to the one-line util call
117
+ * once it targets circuits2.
118
+ */
119
+ declare function fetchOuterVk(vkeyHash: string): Promise<string[]>;
120
+
121
+ export { DISCLOSE_CAPSULE_SLOT, MRZ_LENGTH, type OuterProofParts, PROOF_CAPSULE_SLOT, PROOF_FIELDS, type RegistryNode, type RegistryWallet, SANCTIONS_CAPSULE_SLOT, TD1_NATIONALITY_INDEX, TD3_NATIONALITY_INDEX, VK_FIELDS, ZKPassportRegistryArtifact, assembleDiscloseCapsule, assembleProofCapsule, assembleSanctionsCapsule, fetchOuterVk, isIdCard, nationalityBytes, outerCapsuleLength, outerPublicInputCount, packNationality, registerZKPassportRegistry };