@zkpassport/sdk 0.2.10 → 0.2.11

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.
@@ -200,13 +200,17 @@ export declare class ZKPassport {
200
200
  private checkPublicInputs;
201
201
  /**
202
202
  * @notice Verify the proofs received from the mobile app.
203
- * @param requestId The request ID.
204
203
  * @param proofs The proofs to verify.
205
204
  * @param queryResult The query result to verify against
205
+ * @param validity How many days ago should have the ID been last scanned by the user?
206
206
  * @returns An object containing the unique identifier associated to the user
207
207
  * and a boolean indicating whether the proofs were successfully verified.
208
208
  */
209
- verify(requestId: string, proofs?: Array<ProofResult>, queryResult?: QueryResult): Promise<{
209
+ verify({ proofs, queryResult, validity, }: {
210
+ proofs: Array<ProofResult>;
211
+ queryResult: QueryResult;
212
+ validity?: number;
213
+ }): Promise<{
210
214
  uniqueIdentifier: string | undefined;
211
215
  verified: boolean;
212
216
  queryResultErrors?: QueryResultErrors;
package/dist/cjs/index.js CHANGED
@@ -11,8 +11,6 @@ const json_rpc_1 = require("./json-rpc");
11
11
  const encryption_1 = require("./encryption");
12
12
  const logger_1 = require("./logger");
13
13
  const pako_1 = require("pako");
14
- //import initNoirC from '@noir-lang/noirc_abi'
15
- //import initACVM from '@noir-lang/acvm_js'
16
14
  const en_json_1 = tslib_1.__importDefault(require("i18n-iso-countries/langs/en.json"));
17
15
  const buffer_1 = require("buffer/");
18
16
  // If Buffer is not defined, then we use the Buffer from the buffer package
@@ -94,18 +92,17 @@ class ZKPassport {
94
92
  }
95
93
  this.domain = _domain || window.location.hostname;
96
94
  }
97
- /*private async initWasmVerifier() {
98
- const acvm = await import('@noir-lang/acvm_js/web/acvm_js_bg.wasm')
99
- const noirc = await import('@noir-lang/noirc_abi/web/noirc_abi_wasm_bg.wasm')
100
- await Promise.all([initACVM(acvm), initNoirC(noirc)])
101
- this.wasmVerifierInit = true
102
- }*/
103
95
  async handleResult(topic) {
104
96
  const result = this.topicToResults[topic];
105
97
  // Clear the results straight away to avoid concurrency issues
106
98
  delete this.topicToResults[topic];
107
99
  // Verify the proofs and extract the unique identifier (aka nullifier) and the verification result
108
- const { uniqueIdentifier, verified, queryResultErrors } = await this.verify(topic, this.topicToProofs[topic], result);
100
+ const { uniqueIdentifier, verified, queryResultErrors } = await this.verify({
101
+ proofs: this.topicToProofs[topic],
102
+ queryResult: result,
103
+ validity: this.topicToLocalConfig[topic]?.validity,
104
+ });
105
+ delete this.topicToProofs[topic];
109
106
  const hasFailedProofs = this.topicToFailedProofCount[topic] > 0;
110
107
  await Promise.all(this.onResultCallbacks[topic].map((callback) => callback({
111
108
  // If there are failed proofs, we don't return the unique identifier
@@ -401,7 +398,7 @@ class ZKPassport {
401
398
  };
402
399
  return this.getZkPassportRequest(topic);
403
400
  }
404
- async checkPublicInputs(proofs, queryResult, topic) {
401
+ async checkPublicInputs(proofs, queryResult, validity) {
405
402
  let commitmentIn;
406
403
  let commitmentOut;
407
404
  let isCorrect = true;
@@ -491,14 +488,15 @@ class ZKPassport {
491
488
  commitmentOut = (0, utils_1.getCommitmentOutFromIntegrityProof)(proofData);
492
489
  const currentDate = (0, utils_1.getCurrentDateFromIntegrityProof)(proofData);
493
490
  const todayToCurrentDate = today.getTime() - currentDate.getTime();
494
- const expectedDifference = this.topicToLocalConfig[topic]?.validity * 86400000;
491
+ const differenceInDays = validity ?? 180;
492
+ const expectedDifference = differenceInDays * 86400000;
495
493
  const actualDifference = today.getTime() - (today.getTime() - expectedDifference);
496
494
  // The ID should not expire within the next 6 months (or whatever the custom value is)
497
495
  if (todayToCurrentDate >= actualDifference) {
498
- console.warn(`The date used to check the validity of the ID is older than ${this.topicToLocalConfig[topic]?.validity} days. You can ask the user to rescan their ID or ask them to disclose their expiry date`);
496
+ console.warn(`The date used to check the validity of the ID is older than ${differenceInDays} days. You can ask the user to rescan their ID or ask them to disclose their expiry date`);
499
497
  isCorrect = false;
500
498
  queryResultErrors.data_check_integrity.date = {
501
- expected: `Difference: ${this.topicToLocalConfig[topic]?.validity} days`,
499
+ expected: `Difference: ${differenceInDays} days`,
502
500
  received: `Difference: ${Math.round(todayToCurrentDate / 86400000)} days`,
503
501
  message: "The date used to check the validity of the ID is older than the validity period",
504
502
  };
@@ -906,7 +904,7 @@ class ZKPassport {
906
904
  message: "Current date in the proof is too old",
907
905
  };
908
906
  }
909
- uniqueIdentifier = (0, utils_1.getCommitmentInFromDisclosureProof)(proofData).toString(10);
907
+ uniqueIdentifier = (0, utils_1.getNullifierFromDisclosureProof)(proofData).toString(10);
910
908
  }
911
909
  else if (proof.name === "compare_birthdate") {
912
910
  commitmentIn = (0, utils_1.getCommitmentInFromDisclosureProof)(proofData);
@@ -987,7 +985,7 @@ class ZKPassport {
987
985
  message: "Birthdate is not set in the query result",
988
986
  };
989
987
  }
990
- uniqueIdentifier = (0, utils_1.getCommitmentInFromDisclosureProof)(proofData).toString(10);
988
+ uniqueIdentifier = (0, utils_1.getNullifierFromDisclosureProof)(proofData).toString(10);
991
989
  }
992
990
  else if (proof.name === "compare_expiry") {
993
991
  commitmentIn = (0, utils_1.getCommitmentInFromDisclosureProof)(proofData);
@@ -1235,35 +1233,25 @@ class ZKPassport {
1235
1233
  }
1236
1234
  /**
1237
1235
  * @notice Verify the proofs received from the mobile app.
1238
- * @param requestId The request ID.
1239
1236
  * @param proofs The proofs to verify.
1240
1237
  * @param queryResult The query result to verify against
1238
+ * @param validity How many days ago should have the ID been last scanned by the user?
1241
1239
  * @returns An object containing the unique identifier associated to the user
1242
1240
  * and a boolean indicating whether the proofs were successfully verified.
1243
1241
  */
1244
- async verify(requestId, proofs, queryResult) {
1245
- let proofsToVerify = proofs;
1246
- // There is a minimum of 4 subproofs to make a complete proof
1247
- if (!proofs || proofs.length < 4) {
1248
- proofsToVerify = this.topicToProofs[requestId];
1249
- }
1242
+ async verify({ proofs, queryResult, validity, }) {
1250
1243
  const { BarretenbergVerifier } = await Promise.resolve().then(() => tslib_1.__importStar(require("@aztec/bb.js")));
1251
1244
  const verifier = new BarretenbergVerifier();
1252
- /*if (!this.wasmVerifierInit) {
1253
- await this.initWasmVerifier()
1254
- }*/
1255
1245
  let verified = true;
1256
1246
  let uniqueIdentifier;
1257
1247
  let queryResultErrors;
1258
- if (queryResult) {
1259
- const { isCorrect, uniqueIdentifier: uniqueIdentifierFromPublicInputs, queryResultErrors: queryResultErrorsFromPublicInputs, } = await this.checkPublicInputs(proofsToVerify, queryResult, requestId);
1260
- uniqueIdentifier = uniqueIdentifierFromPublicInputs;
1261
- verified = isCorrect;
1262
- queryResultErrors = isCorrect ? undefined : queryResultErrorsFromPublicInputs;
1263
- }
1248
+ const { isCorrect, uniqueIdentifier: uniqueIdentifierFromPublicInputs, queryResultErrors: queryResultErrorsFromPublicInputs, } = await this.checkPublicInputs(proofs, queryResult, validity);
1249
+ uniqueIdentifier = uniqueIdentifierFromPublicInputs;
1250
+ verified = isCorrect;
1251
+ queryResultErrors = isCorrect ? undefined : queryResultErrorsFromPublicInputs;
1264
1252
  // Only proceed with the proof verification if the public inputs are correct
1265
- if (verified && queryResult) {
1266
- for (const proof of proofsToVerify) {
1253
+ if (verified) {
1254
+ for (const proof of proofs) {
1267
1255
  const proofData = (0, utils_1.getProofData)(proof.proof, true);
1268
1256
  const hostedPackagedCircuit = await (0, utils_1.getHostedPackagedCircuitByName)(proof.version, proof.name);
1269
1257
  const vkeyBytes = buffer_1.Buffer.from(hostedPackagedCircuit.vkey, "base64");
@@ -1281,7 +1269,8 @@ class ZKPassport {
1281
1269
  }
1282
1270
  }
1283
1271
  }
1284
- this.topicToProofs[requestId] = [];
1272
+ // If the proofs are not verified, we don't return the unique identifier
1273
+ uniqueIdentifier = verified ? uniqueIdentifier : undefined;
1285
1274
  return { uniqueIdentifier, verified, queryResultErrors };
1286
1275
  }
1287
1276
  /**
@@ -200,13 +200,17 @@ export declare class ZKPassport {
200
200
  private checkPublicInputs;
201
201
  /**
202
202
  * @notice Verify the proofs received from the mobile app.
203
- * @param requestId The request ID.
204
203
  * @param proofs The proofs to verify.
205
204
  * @param queryResult The query result to verify against
205
+ * @param validity How many days ago should have the ID been last scanned by the user?
206
206
  * @returns An object containing the unique identifier associated to the user
207
207
  * and a boolean indicating whether the proofs were successfully verified.
208
208
  */
209
- verify(requestId: string, proofs?: Array<ProofResult>, queryResult?: QueryResult): Promise<{
209
+ verify({ proofs, queryResult, validity, }: {
210
+ proofs: Array<ProofResult>;
211
+ queryResult: QueryResult;
212
+ validity?: number;
213
+ }): Promise<{
210
214
  uniqueIdentifier: string | undefined;
211
215
  verified: boolean;
212
216
  queryResultErrors?: QueryResultErrors;
package/dist/esm/index.js CHANGED
@@ -7,8 +7,6 @@ import { createEncryptedJsonRpcRequest } from "./json-rpc";
7
7
  import { decrypt, generateECDHKeyPair, getSharedSecret } from "./encryption";
8
8
  import { noLogger as logger } from "./logger";
9
9
  import { inflate } from "pako";
10
- //import initNoirC from '@noir-lang/noirc_abi'
11
- //import initACVM from '@noir-lang/acvm_js'
12
10
  import i18en from "i18n-iso-countries/langs/en.json";
13
11
  import { Buffer } from "buffer/";
14
12
  // If Buffer is not defined, then we use the Buffer from the buffer package
@@ -84,18 +82,17 @@ export class ZKPassport {
84
82
  }
85
83
  this.domain = _domain || window.location.hostname;
86
84
  }
87
- /*private async initWasmVerifier() {
88
- const acvm = await import('@noir-lang/acvm_js/web/acvm_js_bg.wasm')
89
- const noirc = await import('@noir-lang/noirc_abi/web/noirc_abi_wasm_bg.wasm')
90
- await Promise.all([initACVM(acvm), initNoirC(noirc)])
91
- this.wasmVerifierInit = true
92
- }*/
93
85
  async handleResult(topic) {
94
86
  const result = this.topicToResults[topic];
95
87
  // Clear the results straight away to avoid concurrency issues
96
88
  delete this.topicToResults[topic];
97
89
  // Verify the proofs and extract the unique identifier (aka nullifier) and the verification result
98
- const { uniqueIdentifier, verified, queryResultErrors } = await this.verify(topic, this.topicToProofs[topic], result);
90
+ const { uniqueIdentifier, verified, queryResultErrors } = await this.verify({
91
+ proofs: this.topicToProofs[topic],
92
+ queryResult: result,
93
+ validity: this.topicToLocalConfig[topic]?.validity,
94
+ });
95
+ delete this.topicToProofs[topic];
99
96
  const hasFailedProofs = this.topicToFailedProofCount[topic] > 0;
100
97
  await Promise.all(this.onResultCallbacks[topic].map((callback) => callback({
101
98
  // If there are failed proofs, we don't return the unique identifier
@@ -391,7 +388,7 @@ export class ZKPassport {
391
388
  };
392
389
  return this.getZkPassportRequest(topic);
393
390
  }
394
- async checkPublicInputs(proofs, queryResult, topic) {
391
+ async checkPublicInputs(proofs, queryResult, validity) {
395
392
  let commitmentIn;
396
393
  let commitmentOut;
397
394
  let isCorrect = true;
@@ -481,14 +478,15 @@ export class ZKPassport {
481
478
  commitmentOut = getCommitmentOutFromIntegrityProof(proofData);
482
479
  const currentDate = getCurrentDateFromIntegrityProof(proofData);
483
480
  const todayToCurrentDate = today.getTime() - currentDate.getTime();
484
- const expectedDifference = this.topicToLocalConfig[topic]?.validity * 86400000;
481
+ const differenceInDays = validity ?? 180;
482
+ const expectedDifference = differenceInDays * 86400000;
485
483
  const actualDifference = today.getTime() - (today.getTime() - expectedDifference);
486
484
  // The ID should not expire within the next 6 months (or whatever the custom value is)
487
485
  if (todayToCurrentDate >= actualDifference) {
488
- console.warn(`The date used to check the validity of the ID is older than ${this.topicToLocalConfig[topic]?.validity} days. You can ask the user to rescan their ID or ask them to disclose their expiry date`);
486
+ console.warn(`The date used to check the validity of the ID is older than ${differenceInDays} days. You can ask the user to rescan their ID or ask them to disclose their expiry date`);
489
487
  isCorrect = false;
490
488
  queryResultErrors.data_check_integrity.date = {
491
- expected: `Difference: ${this.topicToLocalConfig[topic]?.validity} days`,
489
+ expected: `Difference: ${differenceInDays} days`,
492
490
  received: `Difference: ${Math.round(todayToCurrentDate / 86400000)} days`,
493
491
  message: "The date used to check the validity of the ID is older than the validity period",
494
492
  };
@@ -896,7 +894,7 @@ export class ZKPassport {
896
894
  message: "Current date in the proof is too old",
897
895
  };
898
896
  }
899
- uniqueIdentifier = getCommitmentInFromDisclosureProof(proofData).toString(10);
897
+ uniqueIdentifier = getNullifierFromDisclosureProof(proofData).toString(10);
900
898
  }
901
899
  else if (proof.name === "compare_birthdate") {
902
900
  commitmentIn = getCommitmentInFromDisclosureProof(proofData);
@@ -977,7 +975,7 @@ export class ZKPassport {
977
975
  message: "Birthdate is not set in the query result",
978
976
  };
979
977
  }
980
- uniqueIdentifier = getCommitmentInFromDisclosureProof(proofData).toString(10);
978
+ uniqueIdentifier = getNullifierFromDisclosureProof(proofData).toString(10);
981
979
  }
982
980
  else if (proof.name === "compare_expiry") {
983
981
  commitmentIn = getCommitmentInFromDisclosureProof(proofData);
@@ -1225,35 +1223,25 @@ export class ZKPassport {
1225
1223
  }
1226
1224
  /**
1227
1225
  * @notice Verify the proofs received from the mobile app.
1228
- * @param requestId The request ID.
1229
1226
  * @param proofs The proofs to verify.
1230
1227
  * @param queryResult The query result to verify against
1228
+ * @param validity How many days ago should have the ID been last scanned by the user?
1231
1229
  * @returns An object containing the unique identifier associated to the user
1232
1230
  * and a boolean indicating whether the proofs were successfully verified.
1233
1231
  */
1234
- async verify(requestId, proofs, queryResult) {
1235
- let proofsToVerify = proofs;
1236
- // There is a minimum of 4 subproofs to make a complete proof
1237
- if (!proofs || proofs.length < 4) {
1238
- proofsToVerify = this.topicToProofs[requestId];
1239
- }
1232
+ async verify({ proofs, queryResult, validity, }) {
1240
1233
  const { BarretenbergVerifier } = await import("@aztec/bb.js");
1241
1234
  const verifier = new BarretenbergVerifier();
1242
- /*if (!this.wasmVerifierInit) {
1243
- await this.initWasmVerifier()
1244
- }*/
1245
1235
  let verified = true;
1246
1236
  let uniqueIdentifier;
1247
1237
  let queryResultErrors;
1248
- if (queryResult) {
1249
- const { isCorrect, uniqueIdentifier: uniqueIdentifierFromPublicInputs, queryResultErrors: queryResultErrorsFromPublicInputs, } = await this.checkPublicInputs(proofsToVerify, queryResult, requestId);
1250
- uniqueIdentifier = uniqueIdentifierFromPublicInputs;
1251
- verified = isCorrect;
1252
- queryResultErrors = isCorrect ? undefined : queryResultErrorsFromPublicInputs;
1253
- }
1238
+ const { isCorrect, uniqueIdentifier: uniqueIdentifierFromPublicInputs, queryResultErrors: queryResultErrorsFromPublicInputs, } = await this.checkPublicInputs(proofs, queryResult, validity);
1239
+ uniqueIdentifier = uniqueIdentifierFromPublicInputs;
1240
+ verified = isCorrect;
1241
+ queryResultErrors = isCorrect ? undefined : queryResultErrorsFromPublicInputs;
1254
1242
  // Only proceed with the proof verification if the public inputs are correct
1255
- if (verified && queryResult) {
1256
- for (const proof of proofsToVerify) {
1243
+ if (verified) {
1244
+ for (const proof of proofs) {
1257
1245
  const proofData = getProofData(proof.proof, true);
1258
1246
  const hostedPackagedCircuit = await getHostedPackagedCircuitByName(proof.version, proof.name);
1259
1247
  const vkeyBytes = Buffer.from(hostedPackagedCircuit.vkey, "base64");
@@ -1271,7 +1259,8 @@ export class ZKPassport {
1271
1259
  }
1272
1260
  }
1273
1261
  }
1274
- this.topicToProofs[requestId] = [];
1262
+ // If the proofs are not verified, we don't return the unique identifier
1263
+ uniqueIdentifier = verified ? uniqueIdentifier : undefined;
1275
1264
  return { uniqueIdentifier, verified, queryResultErrors };
1276
1265
  }
1277
1266
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zkpassport/sdk",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "description": "Privacy-preserving identity verification using passports and ID cards",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
package/src/index.ts CHANGED
@@ -38,8 +38,6 @@ import { createEncryptedJsonRpcRequest } from "./json-rpc"
38
38
  import { decrypt, generateECDHKeyPair, getSharedSecret } from "./encryption"
39
39
  import { noLogger as logger } from "./logger"
40
40
  import { inflate } from "pako"
41
- //import initNoirC from '@noir-lang/noirc_abi'
42
- //import initACVM from '@noir-lang/acvm_js'
43
41
  import i18en from "i18n-iso-countries/langs/en.json"
44
42
  import { Buffer } from "buffer/"
45
43
 
@@ -339,23 +337,17 @@ export class ZKPassport {
339
337
  this.domain = _domain || window.location.hostname
340
338
  }
341
339
 
342
- /*private async initWasmVerifier() {
343
- const acvm = await import('@noir-lang/acvm_js/web/acvm_js_bg.wasm')
344
- const noirc = await import('@noir-lang/noirc_abi/web/noirc_abi_wasm_bg.wasm')
345
- await Promise.all([initACVM(acvm), initNoirC(noirc)])
346
- this.wasmVerifierInit = true
347
- }*/
348
-
349
340
  private async handleResult(topic: string) {
350
341
  const result = this.topicToResults[topic]
351
342
  // Clear the results straight away to avoid concurrency issues
352
343
  delete this.topicToResults[topic]
353
344
  // Verify the proofs and extract the unique identifier (aka nullifier) and the verification result
354
- const { uniqueIdentifier, verified, queryResultErrors } = await this.verify(
355
- topic,
356
- this.topicToProofs[topic],
357
- result,
358
- )
345
+ const { uniqueIdentifier, verified, queryResultErrors } = await this.verify({
346
+ proofs: this.topicToProofs[topic],
347
+ queryResult: result,
348
+ validity: this.topicToLocalConfig[topic]?.validity,
349
+ })
350
+ delete this.topicToProofs[topic]
359
351
  const hasFailedProofs = this.topicToFailedProofCount[topic] > 0
360
352
  await Promise.all(
361
353
  this.onResultCallbacks[topic].map((callback) =>
@@ -728,7 +720,7 @@ export class ZKPassport {
728
720
  private async checkPublicInputs(
729
721
  proofs: Array<ProofResult>,
730
722
  queryResult: QueryResult,
731
- topic: string,
723
+ validity?: number,
732
724
  ) {
733
725
  let commitmentIn: bigint | undefined
734
726
  let commitmentOut: bigint | undefined
@@ -831,16 +823,17 @@ export class ZKPassport {
831
823
  commitmentOut = getCommitmentOutFromIntegrityProof(proofData)
832
824
  const currentDate = getCurrentDateFromIntegrityProof(proofData)
833
825
  const todayToCurrentDate = today.getTime() - currentDate.getTime()
834
- const expectedDifference = this.topicToLocalConfig[topic]?.validity * 86400000
826
+ const differenceInDays = validity ?? 180
827
+ const expectedDifference = differenceInDays * 86400000
835
828
  const actualDifference = today.getTime() - (today.getTime() - expectedDifference)
836
829
  // The ID should not expire within the next 6 months (or whatever the custom value is)
837
830
  if (todayToCurrentDate >= actualDifference) {
838
831
  console.warn(
839
- `The date used to check the validity of the ID is older than ${this.topicToLocalConfig[topic]?.validity} days. You can ask the user to rescan their ID or ask them to disclose their expiry date`,
832
+ `The date used to check the validity of the ID is older than ${differenceInDays} days. You can ask the user to rescan their ID or ask them to disclose their expiry date`,
840
833
  )
841
834
  isCorrect = false
842
835
  queryResultErrors.data_check_integrity.date = {
843
- expected: `Difference: ${this.topicToLocalConfig[topic]?.validity} days`,
836
+ expected: `Difference: ${differenceInDays} days`,
844
837
  received: `Difference: ${Math.round(todayToCurrentDate / 86400000)} days`,
845
838
  message:
846
839
  "The date used to check the validity of the ID is older than the validity period",
@@ -1310,7 +1303,7 @@ export class ZKPassport {
1310
1303
  message: "Current date in the proof is too old",
1311
1304
  }
1312
1305
  }
1313
- uniqueIdentifier = getCommitmentInFromDisclosureProof(proofData).toString(10)
1306
+ uniqueIdentifier = getNullifierFromDisclosureProof(proofData).toString(10)
1314
1307
  } else if (proof.name === "compare_birthdate") {
1315
1308
  commitmentIn = getCommitmentInFromDisclosureProof(proofData)
1316
1309
  if (commitmentIn !== commitmentOut) {
@@ -1402,7 +1395,7 @@ export class ZKPassport {
1402
1395
  message: "Birthdate is not set in the query result",
1403
1396
  }
1404
1397
  }
1405
- uniqueIdentifier = getCommitmentInFromDisclosureProof(proofData).toString(10)
1398
+ uniqueIdentifier = getNullifierFromDisclosureProof(proofData).toString(10)
1406
1399
  } else if (proof.name === "compare_expiry") {
1407
1400
  commitmentIn = getCommitmentInFromDisclosureProof(proofData)
1408
1401
  if (commitmentIn !== commitmentOut) {
@@ -1697,47 +1690,41 @@ export class ZKPassport {
1697
1690
 
1698
1691
  /**
1699
1692
  * @notice Verify the proofs received from the mobile app.
1700
- * @param requestId The request ID.
1701
1693
  * @param proofs The proofs to verify.
1702
1694
  * @param queryResult The query result to verify against
1695
+ * @param validity How many days ago should have the ID been last scanned by the user?
1703
1696
  * @returns An object containing the unique identifier associated to the user
1704
1697
  * and a boolean indicating whether the proofs were successfully verified.
1705
1698
  */
1706
- public async verify(
1707
- requestId: string,
1708
- proofs?: Array<ProofResult>,
1709
- queryResult?: QueryResult,
1710
- ): Promise<{
1699
+ public async verify({
1700
+ proofs,
1701
+ queryResult,
1702
+ validity,
1703
+ }: {
1704
+ proofs: Array<ProofResult>
1705
+ queryResult: QueryResult
1706
+ validity?: number
1707
+ }): Promise<{
1711
1708
  uniqueIdentifier: string | undefined
1712
1709
  verified: boolean
1713
1710
  queryResultErrors?: QueryResultErrors
1714
1711
  }> {
1715
- let proofsToVerify = proofs
1716
- // There is a minimum of 4 subproofs to make a complete proof
1717
- if (!proofs || proofs.length < 4) {
1718
- proofsToVerify = this.topicToProofs[requestId]
1719
- }
1720
1712
  const { BarretenbergVerifier } = await import("@aztec/bb.js")
1721
1713
  const verifier = new BarretenbergVerifier()
1722
- /*if (!this.wasmVerifierInit) {
1723
- await this.initWasmVerifier()
1724
- }*/
1725
1714
  let verified = true
1726
1715
  let uniqueIdentifier: string | undefined
1727
1716
  let queryResultErrors: QueryResultErrors | undefined
1728
- if (queryResult) {
1729
- const {
1730
- isCorrect,
1731
- uniqueIdentifier: uniqueIdentifierFromPublicInputs,
1732
- queryResultErrors: queryResultErrorsFromPublicInputs,
1733
- } = await this.checkPublicInputs(proofsToVerify!, queryResult!, requestId)
1734
- uniqueIdentifier = uniqueIdentifierFromPublicInputs
1735
- verified = isCorrect
1736
- queryResultErrors = isCorrect ? undefined : queryResultErrorsFromPublicInputs
1737
- }
1717
+ const {
1718
+ isCorrect,
1719
+ uniqueIdentifier: uniqueIdentifierFromPublicInputs,
1720
+ queryResultErrors: queryResultErrorsFromPublicInputs,
1721
+ } = await this.checkPublicInputs(proofs, queryResult, validity)
1722
+ uniqueIdentifier = uniqueIdentifierFromPublicInputs
1723
+ verified = isCorrect
1724
+ queryResultErrors = isCorrect ? undefined : queryResultErrorsFromPublicInputs
1738
1725
  // Only proceed with the proof verification if the public inputs are correct
1739
- if (verified && queryResult) {
1740
- for (const proof of proofsToVerify!) {
1726
+ if (verified) {
1727
+ for (const proof of proofs) {
1741
1728
  const proofData = getProofData(proof.proof as string, true)
1742
1729
  const hostedPackagedCircuit = await getHostedPackagedCircuitByName(
1743
1730
  proof.version as any,
@@ -1757,7 +1744,8 @@ export class ZKPassport {
1757
1744
  }
1758
1745
  }
1759
1746
  }
1760
- this.topicToProofs[requestId] = []
1747
+ // If the proofs are not verified, we don't return the unique identifier
1748
+ uniqueIdentifier = verified ? uniqueIdentifier : undefined
1761
1749
  return { uniqueIdentifier, verified, queryResultErrors }
1762
1750
  }
1763
1751