@zkpassport/aztec 0.1.0-beta.1 → 0.1.0-beta.3

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
@@ -6,20 +6,29 @@ library.
6
6
  ## Install
7
7
 
8
8
  ```sh
9
- npm install @zkpassport/aztec @aztec-labs/aztec.js@6.0 @aztec-labs/stdlib@6.0
9
+ npm install @zkpassport/aztec @aztec-labs/aztec.js@6.1 @aztec-labs/stdlib@6.1
10
10
  ```
11
11
 
12
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
13
+ 6.1.x and uses the app's own copies of them. Until the first stable release, install
14
14
  `@zkpassport/aztec@beta`.
15
15
 
16
16
  ## Features
17
17
 
18
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.
19
+ - **`toAztecCapsules(params, contract, sender)`**: a contract that verifies a proof reads it, and the data its query asks for, from capsules. The ZKPassport SDK's `getAztecVerifierParameters({ proof })` returns them as plain data for an `outer_count_N` proof, and this turns them into the aztec.js `Capsule`s to send with the call:
20
+
21
+ ```ts
22
+ // `network` is needed for a proof bound to no Aztec network
23
+ const params = await zkPassport.getAztecVerifierParameters({ proof, network: "aztec" })
24
+ const capsules = toAztecCapsules(params, gate.address, sender)
25
+ await gate.methods.claim(user).send({ from: sender, capsules })
26
+ ```
27
+
28
+ - **`assembleProofCapsule` / `assembleDiscloseCapsule` / `assembleSanctionsCapsule` / `assembleFacematchCapsule`**: the same capsules' fields from the parts of a proof, for a client that builds them itself. The proof capsule ends with the circuits release that made the proof; only 0.23.x proofs verify. The face match capsule holds a face match's committed inputs; an Android one verifies only under a revocation root the registry accepts.
20
29
  - **`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
30
  - **`fetchOuterVk(vkeyHash)`**: the outer vk from the live `circuits2.zkpassport.id` host.
22
- - **`constants.ts`** — TS mirror of `core/src/constants.nr`.
31
+ - **`constants.ts`**: the field counts and capsule slots, from `@zkpassport/utils`' mirror of `core/src/constants.nr`.
23
32
 
24
33
  ## Development
25
34
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { ContractArtifact } from '@aztec-labs/aztec.js/abi';
2
- import { Fr } from '@aztec-labs/aztec.js/fields';
3
2
  import { AztecAddress } from '@aztec-labs/aztec.js/addresses';
3
+ import { Fr } from '@aztec-labs/aztec.js/fields';
4
+ import { Capsule } from '@aztec-labs/aztec.js/tx';
5
+ import { FacematchCommittedInputs, AztecVerifierParameters, getAztecOuterPublicInputCount } from '@zkpassport/utils';
4
6
  import { ContractInstanceWithAddress } from '@aztec-labs/stdlib/contract';
5
7
 
6
8
  /**
@@ -9,24 +11,35 @@ import { ContractInstanceWithAddress } from '@aztec-labs/stdlib/contract';
9
11
 
10
12
  declare const ZKPassportRegistryArtifact: ContractArtifact;
11
13
 
12
- /** The three field groups of an outer proof, as hex strings from the SDK/utils. */
14
+ /**
15
+ * The three field groups of an outer proof, as hex strings from the SDK/utils, and the circuits
16
+ * release that made it (the SDK's `ProofResult.version`, e.g. "0.23.0").
17
+ */
13
18
  interface OuterProofParts {
14
19
  vk: string[];
15
20
  proof: string[];
16
21
  publicInputs: string[];
22
+ version: string;
17
23
  }
18
24
  /**
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.
25
+ * The capsules of the SDK's `getAztecVerifierParameters` for `contract`, scoped to `sender`, the
26
+ * account whose PXE sends the transaction: pass them as the `capsules` of the call that verifies
27
+ * the proof.
28
+ */
29
+ declare function toAztecCapsules(params: AztecVerifierParameters, contract: AztecAddress, sender: AztecAddress): Capsule[];
30
+ /**
31
+ * Assemble the proof-capsule blob the library's `verify_zkpassport_proof` consumes:
32
+ * `vk(115) ‖ proof(458) ‖ public_inputs(K + 6) ‖ circuit_version`, which can then be delivered on
33
+ * `PROOF_CAPSULE_SLOT` of the verifier contract. The version is packed as the registry keys vks
34
+ * by it, and the registry only accepts the proof's vk under the release that built it.
22
35
  *
23
36
  * Shape-checks first: the on-chain load of a wrong-shaped blob just returns
24
37
  * None ("missing zkpassport proof capsule"). `k` is the outer circuit's subproof count
25
- * (`outer_count_5` → 5, the shape current SDK queries produce).
38
+ * (`outer_count_5` → 5, the shape current SDK queries produce). A release other than 0.23.x is
39
+ * rejected, since the library would reject its proof.
26
40
  *
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.
41
+ * The SDK/utils emit field elements as bare hex (no `0x`), which are read as hex, never as
42
+ * decimal.
30
43
  */
31
44
  declare function assembleProofCapsule(parts: OuterProofParts, k?: number): Fr[];
32
45
  /**
@@ -40,25 +53,44 @@ declare function assembleDiscloseCapsule(discloseMask: number[], disclosedBytes:
40
53
  * against, the SDK's `SanctionsCommittedInputs.rootHash`.
41
54
  */
42
55
  declare function assembleSanctionsCapsule(rootHash: string): Fr[];
56
+ /**
57
+ * Assemble the capsule for `FACE_MATCH_CAPSULE_SLOT` from a face match's committed inputs, the
58
+ * SDK's `FacematchCommittedInputs`: the root key leaf, the environment, the app id hash, the
59
+ * integrity public key hash, the mode and the revocation root, in the order the proof commits
60
+ * them.
61
+ */
62
+ declare function assembleFacematchCapsule(facematch: FacematchCommittedInputs): Fr[];
43
63
 
44
64
  /**
45
- * Note: this is a TS mirror of `noir/core/src/constants.nr`. That is the source of truth.
65
+ * Note: these come from `@zkpassport/utils`, a TS mirror of `noir/core/src/constants.nr`. That is
66
+ * the source of truth.
46
67
  */
68
+
47
69
  /** Fields in the outer circuit's UltraHonk verification key. */
48
70
  declare const VK_FIELDS = 115;
49
71
  /** Fields in the outer ZK UltraHonk proof. */
50
72
  declare const PROOF_FIELDS = 458;
51
73
  /** Capsule slot the library loads the proof blob from (per-verifier address space). */
52
- declare const PROOF_CAPSULE_SLOT = 1n;
74
+ declare const PROOF_CAPSULE_SLOT: bigint;
53
75
  /** Capsule slot for the disclose preimage (mask ‖ disclosed bytes). */
54
- declare const DISCLOSE_CAPSULE_SLOT = 2n;
76
+ declare const DISCLOSE_CAPSULE_SLOT: bigint;
55
77
  /** Capsule slot for the sanctions exclusion payload. */
56
- declare const SANCTIONS_CAPSULE_SLOT = 3n;
78
+ declare const SANCTIONS_CAPSULE_SLOT: bigint;
79
+ /** Capsule slot for a face match's parameters. */
80
+ declare const FACE_MATCH_CAPSULE_SLOT: bigint;
57
81
  /** The canonical 90-byte disclose payload length (TD1 exactly; TD3 zero-padded). */
58
82
  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`. */
83
+ /** The circuits releases the library parses: 0.23.x. */
84
+ declare const SUPPORTED_CIRCUIT_VERSION: RegExp;
85
+ /**
86
+ * Public-input count for a circuits 0.23.x `outer_count_K` proof is K + 6, ending in the
87
+ * verification method; param commitments are K - 3.
88
+ */
89
+ declare const outerPublicInputCount: typeof getAztecOuterPublicInputCount;
90
+ /**
91
+ * Total field count of the proof-capsule blob for `outer_count_K`:
92
+ * vk ‖ proof ‖ public inputs ‖ circuit version.
93
+ */
62
94
  declare const outerCapsuleLength: (k: number) => number;
63
95
 
64
96
  /**
@@ -90,9 +122,15 @@ declare function packNationality(disclosedBytes: number[]): bigint;
90
122
  interface RegistryNode {
91
123
  getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined>;
92
124
  }
125
+ /** The slice of an aztec.js `Wallet` that registration uses. */
93
126
  interface RegistryWallet {
94
127
  registerContract(instance: ContractInstanceWithAddress, artifact: ContractArtifact): Promise<unknown>;
95
- hasContract?(address: AztecAddress): Promise<boolean>;
128
+ getContractMetadata(address: AztecAddress): Promise<{
129
+ instance?: unknown;
130
+ }>;
131
+ getContractClassMetadata(id: Fr): Promise<{
132
+ isArtifactRegistered: boolean;
133
+ }>;
96
134
  }
97
135
  /**
98
136
  * Register the shared ZKPassportRegistry's artifact with the wallet's PXE.
@@ -100,6 +138,11 @@ interface RegistryWallet {
100
138
  * Any app whose verifier calls `verify_zkpassport_proof*` needs this once per
101
139
  * wallet: the verifier privately `.view()`s the registry, and the PXE executes
102
140
  * that call locally during simulation/proving.
141
+ *
142
+ * Registration is skipped only when the wallet reports both the registry's
143
+ * instance and the artifact of its current class. After the registry is
144
+ * upgraded, a wallet that still holds the old class's artifact is registered
145
+ * again with the current one.
103
146
  */
104
147
  declare function registerZKPassportRegistry(wallet: RegistryWallet, node: RegistryNode, registryAddress: AztecAddress | string, artifact?: ContractArtifact): Promise<ContractInstanceWithAddress>;
105
148
 
@@ -118,4 +161,4 @@ declare function registerZKPassportRegistry(wallet: RegistryWallet, node: Regist
118
161
  */
119
162
  declare function fetchOuterVk(vkeyHash: string): Promise<string[]>;
120
163
 
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 };
164
+ export { DISCLOSE_CAPSULE_SLOT, FACE_MATCH_CAPSULE_SLOT, MRZ_LENGTH, type OuterProofParts, PROOF_CAPSULE_SLOT, PROOF_FIELDS, type RegistryNode, type RegistryWallet, SANCTIONS_CAPSULE_SLOT, SUPPORTED_CIRCUIT_VERSION, TD1_NATIONALITY_INDEX, TD3_NATIONALITY_INDEX, VK_FIELDS, ZKPassportRegistryArtifact, assembleDiscloseCapsule, assembleFacematchCapsule, assembleProofCapsule, assembleSanctionsCapsule, fetchOuterVk, isIdCard, nationalityBytes, outerCapsuleLength, outerPublicInputCount, packNationality, registerZKPassportRegistry, toAztecCapsules };