@zkpassport/sdk 0.8.8 → 0.9.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.
@@ -0,0 +1,2058 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/public-input-checker.ts
21
+ var public_input_checker_exports = {};
22
+ __export(public_input_checker_exports, {
23
+ PublicInputChecker: () => PublicInputChecker
24
+ });
25
+ module.exports = __toCommonJS(public_input_checker_exports);
26
+ var import_utils = require("@zkpassport/utils");
27
+ var import_registry = require("@zkpassport/registry");
28
+
29
+ // src/constants.ts
30
+ var DEFAULT_VALIDITY = 7 * 24 * 60 * 60;
31
+ var DEFAULT_DATE_VALUE = /* @__PURE__ */ new Date(0);
32
+ var ZKPASSPORT_APP_ID_HASH = "0x1fa73686cf510f8f85757b0602de0dd72a13e68ae2092462be8b72662e7f179b";
33
+ var APPLE_APP_ATTEST_ROOT_KEY_HASH = "0x2532418a107c5306fa8308c22255792cf77e4a290cbce8a840a642a3e591340b";
34
+
35
+ // src/public-input-checker.ts
36
+ var PublicInputChecker = class {
37
+ static checkDiscloseBytesPublicInputs(proof, queryResult) {
38
+ const queryResultErrors = {};
39
+ let isCorrect = true;
40
+ const disclosedDataPassport = import_utils.DisclosedData.fromDisclosedBytes(
41
+ (proof.committedInputs?.disclose_bytes).disclosedBytes,
42
+ "passport"
43
+ );
44
+ const disclosedDataIDCard = import_utils.DisclosedData.fromDisclosedBytes(
45
+ (proof.committedInputs?.disclose_bytes).disclosedBytes,
46
+ "id_card"
47
+ );
48
+ if (queryResult.document_type) {
49
+ if (queryResult.document_type.eq && queryResult.document_type.eq.result && queryResult.document_type.eq.expected !== disclosedDataPassport.documentType) {
50
+ console.warn("Document type does not match the expected document type");
51
+ isCorrect = false;
52
+ queryResultErrors.document_type = {
53
+ ...queryResultErrors.document_type,
54
+ eq: {
55
+ expected: `${queryResult.document_type.eq.expected}`,
56
+ received: `${disclosedDataPassport.documentType ?? disclosedDataIDCard.documentType}`,
57
+ message: "Document type does not match the expected document type"
58
+ }
59
+ };
60
+ }
61
+ if (queryResult.document_type.disclose?.result !== disclosedDataIDCard.documentType) {
62
+ console.warn("Document type does not match the disclosed document type in query result");
63
+ isCorrect = false;
64
+ queryResultErrors.document_type = {
65
+ ...queryResultErrors.document_type,
66
+ disclose: {
67
+ expected: `${queryResult.document_type.disclose?.result}`,
68
+ received: `${disclosedDataIDCard.documentType ?? disclosedDataPassport.documentType}`,
69
+ message: "Document type does not match the disclosed document type in query result"
70
+ }
71
+ };
72
+ }
73
+ }
74
+ if (queryResult.birthdate) {
75
+ const birthdatePassport = disclosedDataPassport.dateOfBirth;
76
+ const birthdateIDCard = disclosedDataIDCard.dateOfBirth;
77
+ if (queryResult.birthdate.eq && queryResult.birthdate.eq.result && !(0, import_utils.areDatesEqual)(queryResult.birthdate.eq.expected, birthdatePassport) && !(0, import_utils.areDatesEqual)(queryResult.birthdate.eq.expected, birthdateIDCard)) {
78
+ console.warn("Birthdate does not match the expected birthdate");
79
+ isCorrect = false;
80
+ queryResultErrors.birthdate = {
81
+ ...queryResultErrors.birthdate,
82
+ eq: {
83
+ expected: `${queryResult.birthdate.eq.expected.toISOString()}`,
84
+ received: `${birthdatePassport?.toISOString() ?? birthdateIDCard?.toISOString()}`,
85
+ message: "Birthdate does not match the expected birthdate"
86
+ }
87
+ };
88
+ }
89
+ if (queryResult.birthdate.disclose && !(0, import_utils.areDatesEqual)(queryResult.birthdate.disclose.result, birthdatePassport) && !(0, import_utils.areDatesEqual)(queryResult.birthdate.disclose.result, birthdateIDCard)) {
90
+ console.warn("Birthdate does not match the disclosed birthdate in query result");
91
+ isCorrect = false;
92
+ queryResultErrors.birthdate = {
93
+ ...queryResultErrors.birthdate,
94
+ disclose: {
95
+ expected: `${queryResult.birthdate.disclose.result.toISOString()}`,
96
+ received: `${birthdatePassport?.toISOString() ?? birthdateIDCard?.toISOString()}`,
97
+ message: "Birthdate does not match the disclosed birthdate in query result"
98
+ }
99
+ };
100
+ }
101
+ }
102
+ if (queryResult.expiry_date) {
103
+ const expiryDatePassport = disclosedDataPassport.dateOfExpiry;
104
+ const expiryDateIDCard = disclosedDataIDCard.dateOfExpiry;
105
+ if (queryResult.expiry_date.eq && queryResult.expiry_date.eq.result && !(0, import_utils.areDatesEqual)(queryResult.expiry_date.eq.expected, expiryDatePassport) && !(0, import_utils.areDatesEqual)(queryResult.expiry_date.eq.expected, expiryDateIDCard)) {
106
+ console.warn("Expiry date does not match the expected expiry date");
107
+ isCorrect = false;
108
+ queryResultErrors.expiry_date = {
109
+ ...queryResultErrors.expiry_date,
110
+ eq: {
111
+ expected: `${queryResult.expiry_date.eq.expected.toISOString()}`,
112
+ received: `${expiryDatePassport?.toISOString() ?? expiryDateIDCard?.toISOString()}`,
113
+ message: "Expiry date does not match the expected expiry date"
114
+ }
115
+ };
116
+ }
117
+ if (queryResult.expiry_date.disclose && !(0, import_utils.areDatesEqual)(queryResult.expiry_date.disclose.result, expiryDatePassport) && !(0, import_utils.areDatesEqual)(queryResult.expiry_date.disclose.result, expiryDateIDCard)) {
118
+ console.warn("Expiry date does not match the disclosed expiry date in query result");
119
+ isCorrect = false;
120
+ queryResultErrors.expiry_date = {
121
+ ...queryResultErrors.expiry_date,
122
+ disclose: {
123
+ expected: `${queryResult.expiry_date.disclose.result.toISOString()}`,
124
+ received: `${expiryDatePassport?.toISOString() ?? expiryDateIDCard?.toISOString()}`,
125
+ message: "Expiry date does not match the disclosed expiry date in query result"
126
+ }
127
+ };
128
+ }
129
+ }
130
+ if (queryResult.nationality) {
131
+ const nationalityPassport = disclosedDataPassport.nationality;
132
+ const nationalityIDCard = disclosedDataIDCard.nationality;
133
+ if (queryResult.nationality.eq && queryResult.nationality.eq.result && queryResult.nationality.eq.expected !== nationalityPassport && queryResult.nationality.eq.expected !== nationalityIDCard) {
134
+ console.warn("Nationality does not match the expected nationality");
135
+ isCorrect = false;
136
+ queryResultErrors.nationality = {
137
+ ...queryResultErrors.nationality,
138
+ eq: {
139
+ expected: `${queryResult.nationality.eq.expected}`,
140
+ received: `${nationalityPassport ?? nationalityIDCard}`,
141
+ message: "Nationality does not match the expected nationality"
142
+ }
143
+ };
144
+ }
145
+ if (queryResult.nationality.disclose && queryResult.nationality.disclose.result !== nationalityPassport && queryResult.nationality.disclose.result !== nationalityIDCard) {
146
+ console.warn("Nationality does not match the disclosed nationality in query result");
147
+ isCorrect = false;
148
+ queryResultErrors.nationality = {
149
+ ...queryResultErrors.nationality,
150
+ disclose: {
151
+ expected: `${queryResult.nationality.disclose.result}`,
152
+ received: `${nationalityPassport ?? nationalityIDCard}`,
153
+ message: "Nationality does not match the disclosed nationality in query result"
154
+ }
155
+ };
156
+ }
157
+ }
158
+ if (queryResult.document_number) {
159
+ const documentNumberPassport = disclosedDataPassport.documentNumber;
160
+ const documentNumberIDCard = disclosedDataIDCard.documentNumber;
161
+ if (queryResult.document_number.eq && queryResult.document_number.eq.result && queryResult.document_number.eq.expected !== documentNumberPassport && queryResult.document_number.eq.expected !== documentNumberIDCard) {
162
+ console.warn("Document number does not match the expected document number");
163
+ isCorrect = false;
164
+ queryResultErrors.document_number = {
165
+ ...queryResultErrors.document_number,
166
+ eq: {
167
+ expected: `${queryResult.document_number.eq.expected}`,
168
+ received: `${documentNumberPassport ?? documentNumberIDCard}`,
169
+ message: "Document number does not match the expected document number"
170
+ }
171
+ };
172
+ }
173
+ if (queryResult.document_number.disclose && queryResult.document_number.disclose.result !== documentNumberPassport && queryResult.document_number.disclose.result !== documentNumberIDCard) {
174
+ console.warn("Document number does not match the disclosed document number in query result");
175
+ isCorrect = false;
176
+ queryResultErrors.document_number = {
177
+ ...queryResultErrors.document_number,
178
+ disclose: {
179
+ expected: `${queryResult.document_number.disclose.result}`,
180
+ received: `${documentNumberPassport ?? documentNumberIDCard}`,
181
+ message: "Document number does not match the disclosed document number in query result"
182
+ }
183
+ };
184
+ }
185
+ }
186
+ if (queryResult.gender) {
187
+ const genderPassport = disclosedDataPassport.gender;
188
+ const genderIDCard = disclosedDataIDCard.gender;
189
+ if (queryResult.gender.eq && queryResult.gender.eq.result && queryResult.gender.eq.expected !== genderPassport && queryResult.gender.eq.expected !== genderIDCard) {
190
+ console.warn("Gender does not match the expected gender");
191
+ isCorrect = false;
192
+ queryResultErrors.gender = {
193
+ ...queryResultErrors.gender,
194
+ eq: {
195
+ expected: `${queryResult.gender.eq.expected}`,
196
+ received: `${genderPassport ?? genderIDCard}`,
197
+ message: "Gender does not match the expected gender"
198
+ }
199
+ };
200
+ }
201
+ if (queryResult.gender.disclose && queryResult.gender.disclose.result !== genderPassport && queryResult.gender.disclose.result !== genderIDCard) {
202
+ console.warn("Gender does not match the disclosed gender in query result");
203
+ isCorrect = false;
204
+ queryResultErrors.gender = {
205
+ ...queryResultErrors.gender,
206
+ disclose: {
207
+ expected: `${queryResult.gender.disclose.result}`,
208
+ received: `${genderPassport ?? genderIDCard}`,
209
+ message: "Gender does not match the disclosed gender in query result"
210
+ }
211
+ };
212
+ }
213
+ }
214
+ if (queryResult.issuing_country) {
215
+ const issuingCountryPassport = disclosedDataPassport.issuingCountry;
216
+ const issuingCountryIDCard = disclosedDataIDCard.issuingCountry;
217
+ if (queryResult.issuing_country.eq && queryResult.issuing_country.eq.result && queryResult.issuing_country.eq.expected !== issuingCountryPassport && queryResult.issuing_country.eq.expected !== issuingCountryIDCard) {
218
+ console.warn("Issuing country does not match the expected issuing country");
219
+ isCorrect = false;
220
+ queryResultErrors.issuing_country = {
221
+ ...queryResultErrors.issuing_country,
222
+ eq: {
223
+ expected: `${queryResult.issuing_country.eq.expected}`,
224
+ received: `${issuingCountryPassport ?? issuingCountryIDCard}`,
225
+ message: "Issuing country does not match the expected issuing country"
226
+ }
227
+ };
228
+ }
229
+ if (queryResult.issuing_country.disclose && queryResult.issuing_country.disclose.result !== issuingCountryPassport && queryResult.issuing_country.disclose.result !== issuingCountryIDCard) {
230
+ console.warn("Issuing country does not match the disclosed issuing country in query result");
231
+ isCorrect = false;
232
+ queryResultErrors.issuing_country = {
233
+ ...queryResultErrors.issuing_country,
234
+ disclose: {
235
+ expected: `${queryResult.issuing_country.disclose.result}`,
236
+ received: `${issuingCountryPassport ?? issuingCountryIDCard}`,
237
+ message: "Issuing country does not match the disclosed issuing country in query result"
238
+ }
239
+ };
240
+ }
241
+ }
242
+ if (queryResult.fullname) {
243
+ const fullnamePassport = disclosedDataPassport.name;
244
+ const fullnameIDCard = disclosedDataIDCard.name;
245
+ if (queryResult.fullname.eq && queryResult.fullname.eq.result && (0, import_utils.formatName)(queryResult.fullname.eq.expected).toLowerCase() !== fullnamePassport.toLowerCase() && (0, import_utils.formatName)(queryResult.fullname.eq.expected).toLowerCase() !== fullnameIDCard.toLowerCase()) {
246
+ console.warn("Fullname does not match the expected fullname");
247
+ isCorrect = false;
248
+ queryResultErrors.fullname = {
249
+ ...queryResultErrors.fullname,
250
+ eq: {
251
+ expected: `${queryResult.fullname.eq.expected}`,
252
+ received: `${fullnamePassport ?? fullnameIDCard}`,
253
+ message: "Fullname does not match the expected fullname"
254
+ }
255
+ };
256
+ }
257
+ if (queryResult.fullname.disclose && (0, import_utils.formatName)(queryResult.fullname.disclose.result).toLowerCase() !== fullnamePassport.toLowerCase() && (0, import_utils.formatName)(queryResult.fullname.disclose.result).toLowerCase() !== fullnameIDCard.toLowerCase()) {
258
+ console.warn("Fullname does not match the disclosed fullname in query result");
259
+ isCorrect = false;
260
+ queryResultErrors.fullname = {
261
+ ...queryResultErrors.fullname,
262
+ disclose: {
263
+ expected: `${queryResult.fullname.disclose.result}`,
264
+ received: `${fullnamePassport ?? fullnameIDCard}`,
265
+ message: "Fullname does not match the disclosed fullname in query result"
266
+ }
267
+ };
268
+ }
269
+ }
270
+ if (queryResult.firstname) {
271
+ const firstnamePassport = disclosedDataPassport.firstName && disclosedDataPassport.firstName.length > 0 ? disclosedDataPassport.firstName : disclosedDataPassport.name;
272
+ const firstnameIDCard = disclosedDataIDCard.firstName && disclosedDataIDCard.firstName.length > 0 ? disclosedDataIDCard.firstName : disclosedDataIDCard.name;
273
+ if (queryResult.firstname.eq && queryResult.firstname.eq.result && (0, import_utils.formatName)(queryResult.firstname.eq.expected).toLowerCase() !== firstnamePassport.toLowerCase() && (0, import_utils.formatName)(queryResult.firstname.eq.expected).toLowerCase() !== firstnameIDCard.toLowerCase()) {
274
+ console.warn("Firstname does not match the expected firstname");
275
+ isCorrect = false;
276
+ queryResultErrors.firstname = {
277
+ ...queryResultErrors.firstname,
278
+ eq: {
279
+ expected: `${queryResult.firstname.eq.expected}`,
280
+ received: `${firstnamePassport ?? firstnameIDCard}`,
281
+ message: "Firstname does not match the expected firstname"
282
+ }
283
+ };
284
+ }
285
+ if (queryResult.firstname.disclose && (0, import_utils.formatName)(queryResult.firstname.disclose.result).toLowerCase() !== firstnamePassport.toLowerCase() && (0, import_utils.formatName)(queryResult.firstname.disclose.result).toLowerCase() !== firstnameIDCard.toLowerCase()) {
286
+ console.warn("Firstname does not match the disclosed firstname in query result");
287
+ isCorrect = false;
288
+ queryResultErrors.firstname = {
289
+ ...queryResultErrors.firstname,
290
+ disclose: {
291
+ expected: `${queryResult.firstname.disclose.result}`,
292
+ received: `${firstnamePassport ?? firstnameIDCard}`,
293
+ message: "Firstname does not match the disclosed firstname in query result"
294
+ }
295
+ };
296
+ }
297
+ }
298
+ if (queryResult.lastname) {
299
+ const lastnamePassport = disclosedDataPassport.lastName && disclosedDataPassport.lastName.length > 0 ? disclosedDataPassport.lastName : disclosedDataPassport.name;
300
+ const lastnameIDCard = disclosedDataIDCard.lastName && disclosedDataIDCard.lastName.length > 0 ? disclosedDataIDCard.lastName : disclosedDataIDCard.name;
301
+ if (queryResult.lastname.eq && queryResult.lastname.eq.result && (0, import_utils.formatName)(queryResult.lastname.eq.expected).toLowerCase() !== lastnamePassport.toLowerCase() && (0, import_utils.formatName)(queryResult.lastname.eq.expected).toLowerCase() !== lastnameIDCard.toLowerCase()) {
302
+ console.warn("Lastname does not match the expected lastname");
303
+ isCorrect = false;
304
+ queryResultErrors.lastname = {
305
+ ...queryResultErrors.lastname,
306
+ eq: {
307
+ expected: `${queryResult.lastname.eq.expected}`,
308
+ received: `${lastnamePassport ?? lastnameIDCard}`,
309
+ message: "Lastname does not match the expected lastname"
310
+ }
311
+ };
312
+ }
313
+ if (queryResult.lastname.disclose && (0, import_utils.formatName)(queryResult.lastname.disclose.result).toLowerCase() !== lastnamePassport.toLowerCase() && (0, import_utils.formatName)(queryResult.lastname.disclose.result).toLowerCase() !== lastnameIDCard.toLowerCase()) {
314
+ console.warn("Lastname does not match the disclosed lastname in query result");
315
+ isCorrect = false;
316
+ queryResultErrors.lastname = {
317
+ ...queryResultErrors.lastname,
318
+ disclose: {
319
+ expected: `${queryResult.lastname.disclose.result}`,
320
+ received: `${lastnamePassport ?? lastnameIDCard}`,
321
+ message: "Lastname does not match the disclosed lastname in query result"
322
+ }
323
+ };
324
+ }
325
+ }
326
+ return { isCorrect, queryResultErrors };
327
+ }
328
+ static checkAgePublicInputs(proof, queryResult) {
329
+ const queryResultErrors = {};
330
+ let isCorrect = true;
331
+ const currentTime = /* @__PURE__ */ new Date();
332
+ const today = new Date(
333
+ currentTime.getFullYear(),
334
+ currentTime.getMonth(),
335
+ currentTime.getDate(),
336
+ 0,
337
+ 0,
338
+ 0,
339
+ 0
340
+ );
341
+ const minAge = (0, import_utils.getMinAgeFromCommittedInputs)(
342
+ proof.committedInputs?.compare_age
343
+ );
344
+ const maxAge = (0, import_utils.getMaxAgeFromCommittedInputs)(
345
+ proof.committedInputs?.compare_age
346
+ );
347
+ if (queryResult.age) {
348
+ if (queryResult.age.gte && queryResult.age.gte.result && minAge !== queryResult.age.gte.expected) {
349
+ console.warn("Age is not greater than or equal to the expected age");
350
+ isCorrect = false;
351
+ queryResultErrors.age = {
352
+ ...queryResultErrors.age,
353
+ gte: {
354
+ expected: queryResult.age.gte.expected,
355
+ received: minAge,
356
+ message: "Age is not greater than or equal to the expected age"
357
+ }
358
+ };
359
+ }
360
+ if (queryResult.age.lt && queryResult.age.lt.result && maxAge !== queryResult.age.lt.expected) {
361
+ console.warn("Age is not less than the expected age");
362
+ isCorrect = false;
363
+ queryResultErrors.age = {
364
+ ...queryResultErrors.age,
365
+ lt: {
366
+ expected: queryResult.age.lt.expected,
367
+ received: maxAge,
368
+ message: "Age is not less than the expected age"
369
+ }
370
+ };
371
+ }
372
+ if (queryResult.age.range) {
373
+ if (queryResult.age.range.result && (minAge !== queryResult.age.range.expected[0] || maxAge !== queryResult.age.range.expected[1])) {
374
+ console.warn("Age is not in the expected range");
375
+ isCorrect = false;
376
+ queryResultErrors.age = {
377
+ ...queryResultErrors.age,
378
+ range: {
379
+ expected: queryResult.age.range.expected,
380
+ received: [minAge, maxAge],
381
+ message: "Age is not in the expected range"
382
+ }
383
+ };
384
+ }
385
+ }
386
+ if (!queryResult.age.lt && !queryResult.age.lte && !queryResult.age.eq && !queryResult.age.range && maxAge != 0) {
387
+ console.warn("Maximum age should be equal to 0");
388
+ isCorrect = false;
389
+ queryResultErrors.age = {
390
+ ...queryResultErrors.age,
391
+ disclose: {
392
+ expected: 0,
393
+ received: maxAge,
394
+ message: "Maximum age should be equal to 0"
395
+ }
396
+ };
397
+ }
398
+ if (!queryResult.age.gte && !queryResult.age.gt && !queryResult.age.eq && !queryResult.age.range && minAge != 0) {
399
+ console.warn("Minimum age should be equal to 0");
400
+ isCorrect = false;
401
+ queryResultErrors.age = {
402
+ ...queryResultErrors.age,
403
+ disclose: {
404
+ expected: 0,
405
+ received: minAge,
406
+ message: "Minimum age should be equal to 0"
407
+ }
408
+ };
409
+ }
410
+ if (queryResult.age.disclose && (queryResult.age.disclose.result !== minAge || queryResult.age.disclose.result !== maxAge)) {
411
+ console.warn("Age does not match the disclosed age in query result");
412
+ isCorrect = false;
413
+ queryResultErrors.age = {
414
+ ...queryResultErrors.age,
415
+ disclose: {
416
+ expected: `${minAge}`,
417
+ received: `${queryResult.age.disclose.result}`,
418
+ message: "Age does not match the disclosed age in query result"
419
+ }
420
+ };
421
+ }
422
+ } else {
423
+ console.warn("Age is not set in the query result");
424
+ isCorrect = false;
425
+ queryResultErrors.age = {
426
+ ...queryResultErrors.age,
427
+ disclose: {
428
+ message: "Age is not set in the query result"
429
+ }
430
+ };
431
+ }
432
+ const currentDate = (0, import_utils.getCurrentDateFromCommittedInputs)(
433
+ proof.committedInputs?.compare_age
434
+ );
435
+ if (!(0, import_utils.areDatesEqual)(currentDate, today) && !(0, import_utils.areDatesEqual)(currentDate, today.getTime() - 864e5)) {
436
+ console.warn("Current date in the proof is too old");
437
+ isCorrect = false;
438
+ queryResultErrors.age = {
439
+ ...queryResultErrors.age,
440
+ disclose: {
441
+ expected: `${today.toISOString()}`,
442
+ received: `${currentDate.toISOString()}`,
443
+ message: "Current date in the proof is too old"
444
+ }
445
+ };
446
+ }
447
+ return { isCorrect, queryResultErrors };
448
+ }
449
+ static checkBirthdatePublicInputs(proof, queryResult) {
450
+ const queryResultErrors = {};
451
+ let isCorrect = true;
452
+ const currentTime = /* @__PURE__ */ new Date();
453
+ const today = new Date(
454
+ currentTime.getFullYear(),
455
+ currentTime.getMonth(),
456
+ currentTime.getDate(),
457
+ 0,
458
+ 0,
459
+ 0
460
+ );
461
+ const minDate = (0, import_utils.getBirthdateMinDateTimestamp)(
462
+ proof.committedInputs?.compare_birthdate,
463
+ -1 * import_utils.SECONDS_BETWEEN_1900_AND_1970
464
+ );
465
+ const maxDate = (0, import_utils.getBirthdateMaxDateTimestamp)(
466
+ proof.committedInputs?.compare_birthdate,
467
+ -1 * import_utils.SECONDS_BETWEEN_1900_AND_1970
468
+ );
469
+ const currentDate = (0, import_utils.getCurrentDateFromCommittedInputs)(
470
+ proof.committedInputs?.compare_birthdate
471
+ );
472
+ if (queryResult.birthdate) {
473
+ if (queryResult.birthdate.gte && queryResult.birthdate.gte.result && !(0, import_utils.areDatesEqual)(minDate, queryResult.birthdate.gte.expected)) {
474
+ console.warn("Birthdate is not greater than or equal to the expected birthdate");
475
+ isCorrect = false;
476
+ queryResultErrors.birthdate = {
477
+ ...queryResultErrors.birthdate,
478
+ gte: {
479
+ expected: queryResult.birthdate.gte.expected,
480
+ received: minDate,
481
+ message: "Birthdate is not greater than or equal to the expected birthdate"
482
+ }
483
+ };
484
+ }
485
+ if (queryResult.birthdate.lte && queryResult.birthdate.lte.result && !(0, import_utils.areDatesEqual)(maxDate, queryResult.birthdate.lte.expected)) {
486
+ console.warn("Birthdate is not less than the expected birthdate");
487
+ isCorrect = false;
488
+ queryResultErrors.birthdate = {
489
+ ...queryResultErrors.birthdate,
490
+ lte: {
491
+ expected: queryResult.birthdate.lte.expected,
492
+ received: maxDate,
493
+ message: "Birthdate is not less than the expected birthdate"
494
+ }
495
+ };
496
+ }
497
+ if (queryResult.birthdate.range) {
498
+ if (queryResult.birthdate.range.result && (!(0, import_utils.areDatesEqual)(minDate, queryResult.birthdate.range.expected[0]) || !(0, import_utils.areDatesEqual)(maxDate, queryResult.birthdate.range.expected[1]))) {
499
+ console.warn("Birthdate is not in the expected range");
500
+ isCorrect = false;
501
+ queryResultErrors.birthdate = {
502
+ ...queryResultErrors.birthdate,
503
+ range: {
504
+ expected: queryResult.birthdate.range.expected,
505
+ received: [minDate, maxDate],
506
+ message: "Birthdate is not in the expected range"
507
+ }
508
+ };
509
+ }
510
+ }
511
+ if (!queryResult.birthdate.lte && !queryResult.birthdate.lt && !queryResult.birthdate.eq && !queryResult.birthdate.range && !(0, import_utils.areDatesEqual)(maxDate, DEFAULT_DATE_VALUE)) {
512
+ console.warn("Maximum birthdate should be equal to default date value");
513
+ isCorrect = false;
514
+ queryResultErrors.birthdate = {
515
+ ...queryResultErrors.birthdate,
516
+ disclose: {
517
+ expected: `${DEFAULT_DATE_VALUE.toISOString()}`,
518
+ received: `${maxDate.toISOString()}`,
519
+ message: "Maximum birthdate should be equal to default date value"
520
+ }
521
+ };
522
+ }
523
+ if (!queryResult.birthdate.gte && !queryResult.birthdate.gt && !queryResult.birthdate.eq && !queryResult.birthdate.range && !(0, import_utils.areDatesEqual)(minDate, DEFAULT_DATE_VALUE)) {
524
+ console.warn("Minimum birthdate should be equal to default date value");
525
+ isCorrect = false;
526
+ queryResultErrors.birthdate = {
527
+ ...queryResultErrors.birthdate,
528
+ disclose: {
529
+ expected: `${DEFAULT_DATE_VALUE.toISOString()}`,
530
+ received: `${minDate.toISOString()}`,
531
+ message: "Minimum birthdate should be equal to default date value"
532
+ }
533
+ };
534
+ }
535
+ } else {
536
+ console.warn("Birthdate is not set in the query result");
537
+ isCorrect = false;
538
+ queryResultErrors.birthdate = {
539
+ ...queryResultErrors.birthdate,
540
+ disclose: {
541
+ message: "Birthdate is not set in the query result"
542
+ }
543
+ };
544
+ }
545
+ if (!(0, import_utils.areDatesEqual)(currentDate, today) && !(0, import_utils.areDatesEqual)(currentDate, today.getTime() - 864e5)) {
546
+ console.warn("Current date in the proof is too old");
547
+ isCorrect = false;
548
+ queryResultErrors.birthdate = {
549
+ ...queryResultErrors.birthdate,
550
+ disclose: {
551
+ expected: `${today.toISOString()}`,
552
+ received: `${currentDate.toISOString()}`,
553
+ message: "Current date in the proof is too old"
554
+ }
555
+ };
556
+ }
557
+ return { isCorrect, queryResultErrors };
558
+ }
559
+ static checkExpiryDatePublicInputs(proof, queryResult) {
560
+ const queryResultErrors = {};
561
+ let isCorrect = true;
562
+ const currentTime = /* @__PURE__ */ new Date();
563
+ const today = new Date(
564
+ currentTime.getFullYear(),
565
+ currentTime.getMonth(),
566
+ currentTime.getDate(),
567
+ 0,
568
+ 0,
569
+ 0
570
+ );
571
+ const minDate = (0, import_utils.getMinDateFromCommittedInputs)(
572
+ proof.committedInputs?.compare_expiry
573
+ );
574
+ const maxDate = (0, import_utils.getMaxDateFromCommittedInputs)(
575
+ proof.committedInputs?.compare_expiry
576
+ );
577
+ const currentDate = (0, import_utils.getCurrentDateFromCommittedInputs)(
578
+ proof.committedInputs?.compare_expiry
579
+ );
580
+ if (queryResult.expiry_date) {
581
+ if (queryResult.expiry_date.gte && queryResult.expiry_date.gte.result && !(0, import_utils.areDatesEqual)(minDate, queryResult.expiry_date.gte.expected)) {
582
+ console.warn("Expiry date is not greater than or equal to the expected expiry date");
583
+ isCorrect = false;
584
+ queryResultErrors.expiry_date = {
585
+ ...queryResultErrors.expiry_date,
586
+ gte: {
587
+ expected: queryResult.expiry_date.gte.expected,
588
+ received: minDate,
589
+ message: "Expiry date is not greater than or equal to the expected expiry date"
590
+ }
591
+ };
592
+ }
593
+ if (queryResult.expiry_date.lte && queryResult.expiry_date.lte.result && !(0, import_utils.areDatesEqual)(maxDate, queryResult.expiry_date.lte.expected)) {
594
+ console.warn("Expiry date is not less than the expected expiry date");
595
+ isCorrect = false;
596
+ queryResultErrors.expiry_date = {
597
+ ...queryResultErrors.expiry_date,
598
+ lte: {
599
+ expected: queryResult.expiry_date.lte.expected,
600
+ received: maxDate,
601
+ message: "Expiry date is not less than the expected expiry date"
602
+ }
603
+ };
604
+ }
605
+ if (queryResult.expiry_date.range) {
606
+ if (queryResult.expiry_date.range.result && (!(0, import_utils.areDatesEqual)(minDate, queryResult.expiry_date.range.expected[0]) || !(0, import_utils.areDatesEqual)(maxDate, queryResult.expiry_date.range.expected[1]))) {
607
+ console.warn("Expiry date is not in the expected range");
608
+ isCorrect = false;
609
+ queryResultErrors.expiry_date = {
610
+ ...queryResultErrors.expiry_date,
611
+ range: {
612
+ expected: queryResult.expiry_date.range.expected,
613
+ received: [minDate, maxDate],
614
+ message: "Expiry date is not in the expected range"
615
+ }
616
+ };
617
+ }
618
+ }
619
+ if (!queryResult.expiry_date.lte && !queryResult.expiry_date.lt && !queryResult.expiry_date.eq && !queryResult.expiry_date.range && !(0, import_utils.areDatesEqual)(maxDate, DEFAULT_DATE_VALUE)) {
620
+ console.warn("Maximum expiry date should be equal to default date value");
621
+ isCorrect = false;
622
+ queryResultErrors.expiry_date = {
623
+ ...queryResultErrors.expiry_date,
624
+ disclose: {
625
+ expected: `${DEFAULT_DATE_VALUE.toISOString()}`,
626
+ received: `${maxDate.toISOString()}`,
627
+ message: "Maximum expiry date should be equal to default date value"
628
+ }
629
+ };
630
+ }
631
+ if (!queryResult.expiry_date.gte && !queryResult.expiry_date.gt && !queryResult.expiry_date.eq && !queryResult.expiry_date.range && !(0, import_utils.areDatesEqual)(minDate, DEFAULT_DATE_VALUE)) {
632
+ console.warn("Minimum expiry date should be equal to default date value");
633
+ isCorrect = false;
634
+ queryResultErrors.expiry_date = {
635
+ ...queryResultErrors.expiry_date,
636
+ disclose: {
637
+ expected: `${DEFAULT_DATE_VALUE.toISOString()}`,
638
+ received: `${minDate.toISOString()}`,
639
+ message: "Minimum expiry date should be equal to default date value"
640
+ }
641
+ };
642
+ }
643
+ } else {
644
+ console.warn("Expiry date is not set in the query result");
645
+ isCorrect = false;
646
+ queryResultErrors.expiry_date = {
647
+ ...queryResultErrors.expiry_date,
648
+ disclose: {
649
+ message: "Expiry date is not set in the query result"
650
+ }
651
+ };
652
+ }
653
+ if (!(0, import_utils.areDatesEqual)(currentDate, today) && !(0, import_utils.areDatesEqual)(currentDate, today.getTime() - 864e5)) {
654
+ console.warn("Current date in the proof is too old");
655
+ isCorrect = false;
656
+ queryResultErrors.expiry_date = {
657
+ ...queryResultErrors.expiry_date,
658
+ disclose: {
659
+ expected: `${today.toISOString()}`,
660
+ received: `${currentDate.toISOString()}`,
661
+ message: "Current date in the proof is too old"
662
+ }
663
+ };
664
+ }
665
+ return { isCorrect, queryResultErrors };
666
+ }
667
+ static checkNationalityExclusionPublicInputs(queryResult, countryList) {
668
+ const queryResultErrors = {};
669
+ let isCorrect = true;
670
+ if (queryResult.nationality && queryResult.nationality.out && queryResult.nationality.out.result) {
671
+ if (!queryResult.nationality.out.expected?.every((country) => countryList.includes(country))) {
672
+ console.warn("Nationality exclusion list does not match the one from the query results");
673
+ isCorrect = false;
674
+ queryResultErrors.nationality = {
675
+ ...queryResultErrors.nationality,
676
+ out: {
677
+ expected: queryResult.nationality.out.expected,
678
+ received: countryList,
679
+ message: "Nationality exclusion list does not match the one from the query results"
680
+ }
681
+ };
682
+ }
683
+ } else if (!queryResult.nationality || !queryResult.nationality.out) {
684
+ console.warn("Nationality exclusion is not set in the query result");
685
+ isCorrect = false;
686
+ queryResultErrors.nationality = {
687
+ ...queryResultErrors.nationality,
688
+ out: {
689
+ message: "Nationality exclusion is not set in the query result"
690
+ }
691
+ };
692
+ }
693
+ for (let i = 1; i < countryList.length; i++) {
694
+ if (countryList[i] < countryList[i - 1]) {
695
+ console.warn(
696
+ "The nationality exclusion list has not been sorted, and thus the proof cannot be trusted"
697
+ );
698
+ isCorrect = false;
699
+ queryResultErrors.nationality = {
700
+ ...queryResultErrors.nationality,
701
+ out: {
702
+ message: "The nationality exclusion list has not been sorted, and thus the proof cannot be trusted"
703
+ }
704
+ };
705
+ }
706
+ }
707
+ return { isCorrect, queryResultErrors };
708
+ }
709
+ static checkIssuingCountryExclusionPublicInputs(queryResult, countryList) {
710
+ const queryResultErrors = {};
711
+ let isCorrect = true;
712
+ if (queryResult.issuing_country && queryResult.issuing_country.out && queryResult.issuing_country.out.result) {
713
+ if (!queryResult.issuing_country.out.expected?.every((country) => countryList.includes(country))) {
714
+ console.warn("Issuing country exclusion list does not match the one from the query results");
715
+ isCorrect = false;
716
+ queryResultErrors.issuing_country = {
717
+ ...queryResultErrors.issuing_country,
718
+ out: {
719
+ expected: queryResult.issuing_country.out.expected,
720
+ received: countryList,
721
+ message: "Issuing country exclusion list does not match the one from the query results"
722
+ }
723
+ };
724
+ }
725
+ } else if (!queryResult.issuing_country || !queryResult.issuing_country.out) {
726
+ console.warn("Issuing country exclusion is not set in the query result");
727
+ isCorrect = false;
728
+ queryResultErrors.issuing_country = {
729
+ ...queryResultErrors.issuing_country,
730
+ out: {
731
+ message: "Issuing country exclusion is not set in the query result"
732
+ }
733
+ };
734
+ }
735
+ for (let i = 1; i < countryList.length; i++) {
736
+ if (countryList[i] < countryList[i - 1]) {
737
+ console.warn(
738
+ "The issuing country exclusion list has not been sorted, and thus the proof cannot be trusted"
739
+ );
740
+ isCorrect = false;
741
+ queryResultErrors.issuing_country = {
742
+ ...queryResultErrors.issuing_country,
743
+ out: {
744
+ message: "The issuing country exclusion list has not been sorted, and thus the proof cannot be trusted"
745
+ }
746
+ };
747
+ }
748
+ }
749
+ return { isCorrect, queryResultErrors };
750
+ }
751
+ static checkNationalityInclusionPublicInputs(queryResult, countryList) {
752
+ const queryResultErrors = {};
753
+ let isCorrect = true;
754
+ if (queryResult.nationality && queryResult.nationality.in && queryResult.nationality.in.result) {
755
+ if (!queryResult.nationality.in.expected?.every((country) => countryList.includes(country))) {
756
+ console.warn("Nationality inclusion list does not match the one from the query results");
757
+ isCorrect = false;
758
+ queryResultErrors.nationality = {
759
+ ...queryResultErrors.nationality,
760
+ in: {
761
+ expected: queryResult.nationality.in.expected,
762
+ received: countryList,
763
+ message: "Nationality inclusion list does not match the one from the query results"
764
+ }
765
+ };
766
+ }
767
+ } else if (!queryResult.nationality || !queryResult.nationality.in) {
768
+ console.warn("Nationality inclusion is not set in the query result");
769
+ isCorrect = false;
770
+ queryResultErrors.nationality = {
771
+ ...queryResultErrors.nationality,
772
+ in: {
773
+ message: "Nationality inclusion is not set in the query result"
774
+ }
775
+ };
776
+ }
777
+ return { isCorrect, queryResultErrors };
778
+ }
779
+ static checkIssuingCountryInclusionPublicInputs(queryResult, countryList) {
780
+ const queryResultErrors = {};
781
+ let isCorrect = true;
782
+ if (queryResult.issuing_country && queryResult.issuing_country.in && queryResult.issuing_country.in.result) {
783
+ if (!queryResult.issuing_country.in.expected?.every((country) => countryList.includes(country))) {
784
+ console.warn("Issuing country inclusion list does not match the one from the query results");
785
+ isCorrect = false;
786
+ queryResultErrors.issuing_country = {
787
+ ...queryResultErrors.issuing_country,
788
+ in: {
789
+ expected: queryResult.issuing_country.in.expected,
790
+ received: countryList,
791
+ message: "Issuing country inclusion list does not match the one from the query results"
792
+ }
793
+ };
794
+ }
795
+ } else if (!queryResult.issuing_country || !queryResult.issuing_country.in) {
796
+ console.warn("Issuing country inclusion is not set in the query result");
797
+ isCorrect = false;
798
+ queryResultErrors.issuing_country = {
799
+ ...queryResultErrors.issuing_country,
800
+ in: {
801
+ message: "Issuing country inclusion is not set in the query result"
802
+ }
803
+ };
804
+ }
805
+ return { isCorrect, queryResultErrors };
806
+ }
807
+ static checkScopeFromDisclosureProof(domain, proofData, queryResultErrors, key, scope) {
808
+ let isCorrect = true;
809
+ if (domain && (0, import_utils.getServiceScopeHash)(domain) !== BigInt(proofData.publicInputs[1])) {
810
+ console.warn("The proof comes from a different domain than the one expected");
811
+ isCorrect = false;
812
+ if (!queryResultErrors[key]) {
813
+ queryResultErrors[key] = {};
814
+ }
815
+ queryResultErrors[key].scope = {
816
+ expected: `Scope: ${(0, import_utils.getServiceScopeHash)(domain).toString()}`,
817
+ received: `Scope: ${BigInt(proofData.publicInputs[1]).toString()}`,
818
+ message: "The proof comes from a different domain than the one expected"
819
+ };
820
+ }
821
+ if (scope && (0, import_utils.getScopeHash)(scope) !== BigInt(proofData.publicInputs[2])) {
822
+ console.warn("The proof uses a different scope than the one expected");
823
+ isCorrect = false;
824
+ if (!queryResultErrors[key]) {
825
+ queryResultErrors[key] = {};
826
+ }
827
+ queryResultErrors[key].scope = {
828
+ expected: `Scope: ${(0, import_utils.getScopeHash)(scope).toString()}`,
829
+ received: `Scope: ${BigInt(proofData.publicInputs[2]).toString()}`,
830
+ message: "The proof uses a different scope than the one expected"
831
+ };
832
+ }
833
+ return { isCorrect, queryResultErrors };
834
+ }
835
+ static async checkCertificateRegistryRoot(root, queryResultErrors, outer) {
836
+ let isCorrect = true;
837
+ try {
838
+ const registryClient = new import_registry.RegistryClient({ chainId: 11155111 });
839
+ const isValid = await registryClient.isCertificateRootValid(root);
840
+ if (!isValid) {
841
+ console.warn("The ID was signed by an unrecognized root certificate");
842
+ isCorrect = false;
843
+ if (!queryResultErrors[outer ? "outer" : "sig_check_dsc"]) {
844
+ queryResultErrors[outer ? "outer" : "sig_check_dsc"] = {};
845
+ }
846
+ queryResultErrors[outer ? "outer" : "sig_check_dsc"].certificate = {
847
+ expected: `A valid root from ZKPassport Registry`,
848
+ received: `Got invalid certificate registry root: ${root}`,
849
+ message: "The ID was signed by an unrecognized root certificate"
850
+ };
851
+ }
852
+ } catch (error) {
853
+ console.warn(error);
854
+ console.warn("The ID was signed by an unrecognized root certificate");
855
+ isCorrect = false;
856
+ if (!queryResultErrors[outer ? "outer" : "sig_check_dsc"]) {
857
+ queryResultErrors[outer ? "outer" : "sig_check_dsc"] = {};
858
+ }
859
+ queryResultErrors[outer ? "outer" : "sig_check_dsc"].certificate = {
860
+ expected: `A valid root from ZKPassport Registry`,
861
+ received: `Got invalid certificate registry root: ${root}`,
862
+ message: "The ID was signed by an unrecognized root certificate"
863
+ };
864
+ }
865
+ return { isCorrect, queryResultErrors };
866
+ }
867
+ static async checkCircuitRegistryRoot(root, queryResultErrors) {
868
+ let isCorrect = true;
869
+ try {
870
+ const registryClient = new import_registry.RegistryClient({ chainId: 11155111 });
871
+ const isValid = await registryClient.isCircuitRootValid(root);
872
+ if (!isValid) {
873
+ console.warn("The proof uses unrecognized circuits");
874
+ isCorrect = false;
875
+ queryResultErrors.outer.circuit = {
876
+ expected: `A valid circuit from ZKPassport Registry`,
877
+ received: `Got invalid circuit registry root: ${root}`,
878
+ message: "The proof uses an unrecognized circuit"
879
+ };
880
+ }
881
+ } catch (error) {
882
+ console.warn(error);
883
+ console.warn("The proof uses unrecognized circuits");
884
+ isCorrect = false;
885
+ queryResultErrors.outer.circuit = {
886
+ expected: `A valid circuit from ZKPassport Registry`,
887
+ received: `Got invalid circuit registry root: ${root}`,
888
+ message: "The proof uses an unrecognized circuit"
889
+ };
890
+ }
891
+ return { isCorrect, queryResultErrors };
892
+ }
893
+ static checkBindPublicInputs(queryResult, boundData) {
894
+ const queryResultErrors = {};
895
+ let isCorrect = true;
896
+ if (queryResult.bind) {
897
+ if (queryResult.bind.user_address?.toLowerCase().replace("0x", "") !== boundData.user_address?.toLowerCase().replace("0x", "")) {
898
+ console.warn("Bound user address does not match the one from the query results");
899
+ isCorrect = false;
900
+ queryResultErrors.bind = {
901
+ ...queryResultErrors.bind,
902
+ eq: {
903
+ expected: queryResult.bind.user_address,
904
+ received: boundData.user_address,
905
+ message: "Bound user address does not match the one from the query results"
906
+ }
907
+ };
908
+ }
909
+ if (queryResult.bind.chain !== boundData.chain) {
910
+ console.warn("Bound chain id does not match the one from the query results");
911
+ isCorrect = false;
912
+ queryResultErrors.bind = {
913
+ ...queryResultErrors.bind,
914
+ eq: {
915
+ expected: queryResult.bind.chain,
916
+ received: boundData.chain,
917
+ message: "Bound chain id does not match the one from the query results"
918
+ }
919
+ };
920
+ }
921
+ if (queryResult.bind.custom_data?.trim().toLowerCase() !== boundData.custom_data?.trim().toLowerCase()) {
922
+ console.warn("Bound custom data does not match the one from the query results");
923
+ isCorrect = false;
924
+ queryResultErrors.bind = {
925
+ ...queryResultErrors.bind,
926
+ eq: {
927
+ expected: queryResult.bind.custom_data,
928
+ received: boundData.custom_data,
929
+ message: "Bound custom data does not match the one from the query results"
930
+ }
931
+ };
932
+ }
933
+ }
934
+ return { isCorrect, queryResultErrors };
935
+ }
936
+ static async checkSanctionsExclusionPublicInputs(queryResult, root, sanctionsBuilder) {
937
+ const queryResultErrors = {};
938
+ let isCorrect = true;
939
+ if (queryResult.sanctions && queryResult.sanctions.passed) {
940
+ const EXPECTED_ROOT = await sanctionsBuilder.getRoot();
941
+ if (root !== EXPECTED_ROOT) {
942
+ console.warn("Invalid sanctions registry root");
943
+ isCorrect = false;
944
+ queryResultErrors.sanctions = {
945
+ ...queryResultErrors.sanctions,
946
+ eq: {
947
+ expected: EXPECTED_ROOT,
948
+ received: root,
949
+ message: "Invalid sanctions registry root"
950
+ }
951
+ };
952
+ }
953
+ }
954
+ return { isCorrect, queryResultErrors };
955
+ }
956
+ static async checkFacematchPublicInputs(queryResult, facematchCommittedInputs) {
957
+ let isCorrect = true;
958
+ let queryResultErrors = {};
959
+ if (queryResult.facematch && queryResult.facematch.passed) {
960
+ if (facematchCommittedInputs.rootKeyLeaf !== APPLE_APP_ATTEST_ROOT_KEY_HASH) {
961
+ console.warn("Invalid facematch root key hash");
962
+ isCorrect = false;
963
+ queryResultErrors.facematch = {
964
+ ...queryResultErrors.facematch,
965
+ eq: {
966
+ expected: APPLE_APP_ATTEST_ROOT_KEY_HASH,
967
+ received: facematchCommittedInputs.rootKeyLeaf,
968
+ message: "Invalid facematch root key hash"
969
+ }
970
+ };
971
+ }
972
+ const EXPECTED_ENVIRONMENT = "production";
973
+ if (facematchCommittedInputs.environment !== EXPECTED_ENVIRONMENT) {
974
+ console.warn("Invalid facematch environment, it should be production");
975
+ isCorrect = false;
976
+ queryResultErrors.facematch = {
977
+ ...queryResultErrors.facematch,
978
+ eq: {
979
+ expected: EXPECTED_ENVIRONMENT,
980
+ received: facematchCommittedInputs.environment,
981
+ message: "Invalid facematch environment, it should be production"
982
+ }
983
+ };
984
+ }
985
+ if (facematchCommittedInputs.appId !== ZKPASSPORT_APP_ID_HASH) {
986
+ console.warn(
987
+ "Invalid facematch app id hash, the attestation should be coming from the ZKPassport app"
988
+ );
989
+ isCorrect = false;
990
+ queryResultErrors.facematch = {
991
+ ...queryResultErrors.facematch,
992
+ eq: {
993
+ expected: ZKPASSPORT_APP_ID_HASH,
994
+ received: facematchCommittedInputs.appId,
995
+ message: "Invalid facematch app id hash, the attestation should be coming from the ZKPassport app"
996
+ }
997
+ };
998
+ }
999
+ }
1000
+ return { isCorrect, queryResultErrors };
1001
+ }
1002
+ static async checkPublicInputs(domain, proofs, queryResult, validity, scope) {
1003
+ let commitmentIn;
1004
+ let commitmentOut;
1005
+ let isCorrect = true;
1006
+ let uniqueIdentifier;
1007
+ let uniqueIdentifierType;
1008
+ const currentTime = /* @__PURE__ */ new Date();
1009
+ const today = new Date(
1010
+ currentTime.getFullYear(),
1011
+ currentTime.getMonth(),
1012
+ currentTime.getDate(),
1013
+ 0,
1014
+ 0,
1015
+ 0,
1016
+ 0
1017
+ );
1018
+ let queryResultErrors = {};
1019
+ const sortedProofs = proofs.sort((a, b) => {
1020
+ const proofOrder = [
1021
+ "sig_check_dsc",
1022
+ "sig_check_id_data",
1023
+ "data_check_integrity",
1024
+ "disclose_bytes",
1025
+ "compare_age",
1026
+ "compare_birthdate",
1027
+ "compare_expiry",
1028
+ "exclusion_check_nationality",
1029
+ "inclusion_check_nationality",
1030
+ "exclusion_check_issuing_country",
1031
+ "inclusion_check_issuing_country",
1032
+ "bind",
1033
+ "exclusion_check_sanctions",
1034
+ "facematch"
1035
+ ];
1036
+ const getIndex = (proof) => {
1037
+ const name = proof.name || "";
1038
+ return proofOrder.findIndex((p) => name.startsWith(p));
1039
+ };
1040
+ return getIndex(a) - getIndex(b);
1041
+ });
1042
+ for (const proof of sortedProofs) {
1043
+ const proofData = (0, import_utils.getProofData)(proof.proof, (0, import_utils.getNumberOfPublicInputs)(proof.name));
1044
+ if (proof.name?.startsWith("outer")) {
1045
+ const isForEVM = proof.name?.startsWith("outer_evm");
1046
+ const certificateRegistryRoot = (0, import_utils.getCertificateRegistryRootFromOuterProof)(proofData);
1047
+ const {
1048
+ isCorrect: isCorrectCertificateRegistryRoot,
1049
+ queryResultErrors: queryResultErrorsCertificateRegistryRoot
1050
+ } = await this.checkCertificateRegistryRoot(
1051
+ certificateRegistryRoot.toString(16),
1052
+ queryResultErrors,
1053
+ true
1054
+ );
1055
+ isCorrect = isCorrect && isCorrectCertificateRegistryRoot;
1056
+ queryResultErrors = {
1057
+ ...queryResultErrors,
1058
+ ...queryResultErrorsCertificateRegistryRoot
1059
+ };
1060
+ const circuitRegistryRoot = (0, import_utils.getCircuitRegistryRootFromOuterProof)(proofData);
1061
+ const {
1062
+ isCorrect: isCorrectCircuitRegistryRoot,
1063
+ queryResultErrors: queryResultErrorsCircuitRegistryRoot
1064
+ } = await this.checkCircuitRegistryRoot(circuitRegistryRoot.toString(16), queryResultErrors);
1065
+ isCorrect = isCorrect && isCorrectCircuitRegistryRoot;
1066
+ queryResultErrors = {
1067
+ ...queryResultErrors,
1068
+ ...queryResultErrorsCircuitRegistryRoot
1069
+ };
1070
+ const currentDate = (0, import_utils.getCurrentDateFromOuterProof)(proofData);
1071
+ const todayToCurrentDate = today.getTime() - currentDate.getTime();
1072
+ const expectedDifference = validity ? validity * 1e3 : DEFAULT_VALIDITY * 1e3;
1073
+ const actualDifference = today.getTime() - (today.getTime() - expectedDifference);
1074
+ if (todayToCurrentDate >= actualDifference) {
1075
+ console.warn(
1076
+ `The date used to check the validity of the ID is older than the validity period`
1077
+ );
1078
+ isCorrect = false;
1079
+ queryResultErrors.outer = {
1080
+ ...queryResultErrors.outer,
1081
+ date: {
1082
+ expected: `Difference: ${validity} seconds`,
1083
+ received: `Difference: ${Math.round(todayToCurrentDate / 1e3)} seconds`,
1084
+ message: "The date used to check the validity of the ID is older than the validity period"
1085
+ }
1086
+ };
1087
+ }
1088
+ const paramCommitments = (0, import_utils.getParamCommitmentsFromOuterProof)(proofData);
1089
+ const committedInputs = proof.committedInputs;
1090
+ const keysInCommittedInputs = Object.keys(committedInputs || {});
1091
+ if (keysInCommittedInputs.length !== paramCommitments.length) {
1092
+ console.warn("The proof does not verify all the requested conditions and information");
1093
+ isCorrect = false;
1094
+ queryResultErrors.outer = {
1095
+ ...queryResultErrors.outer,
1096
+ commitment: {
1097
+ expected: `Number of parameter commitments: ${paramCommitments.length}`,
1098
+ received: `Number of disclosure proofs provided: ${keysInCommittedInputs.length}`,
1099
+ message: "The proof does not verify all the requested conditions and information"
1100
+ }
1101
+ };
1102
+ }
1103
+ if (domain && (0, import_utils.getServiceScopeHash)(domain) !== (0, import_utils.getScopeFromOuterProof)(proofData)) {
1104
+ console.warn("The proof comes from a different domain than the one expected");
1105
+ isCorrect = false;
1106
+ queryResultErrors.outer = {
1107
+ ...queryResultErrors.outer,
1108
+ scope: {
1109
+ expected: `Scope: ${(0, import_utils.getServiceScopeHash)(domain).toString()}`,
1110
+ received: `Scope: ${(0, import_utils.getScopeFromOuterProof)(proofData).toString()}`,
1111
+ message: "The proof comes from a different domain than the one expected"
1112
+ }
1113
+ };
1114
+ }
1115
+ if (scope && (0, import_utils.getScopeHash)(scope) !== (0, import_utils.getSubscopeFromOuterProof)(proofData)) {
1116
+ console.warn("The proof uses a different scope than the one expected");
1117
+ isCorrect = false;
1118
+ queryResultErrors.outer = {
1119
+ ...queryResultErrors.outer,
1120
+ scope: {
1121
+ expected: `Scope: ${(0, import_utils.getScopeHash)(scope).toString()}`,
1122
+ received: `Scope: ${(0, import_utils.getSubscopeFromOuterProof)(proofData).toString()}`,
1123
+ message: "The proof uses a different scope than the one expected"
1124
+ }
1125
+ };
1126
+ }
1127
+ if (!!committedInputs?.compare_age) {
1128
+ const ageCommittedInputs = committedInputs?.compare_age;
1129
+ const ageParameterCommitment = isForEVM ? await (0, import_utils.getAgeEVMParameterCommitment)(
1130
+ ageCommittedInputs.currentDateTimestamp,
1131
+ ageCommittedInputs.minAge,
1132
+ ageCommittedInputs.maxAge
1133
+ ) : await (0, import_utils.getAgeParameterCommitment)(
1134
+ ageCommittedInputs.currentDateTimestamp,
1135
+ ageCommittedInputs.minAge,
1136
+ ageCommittedInputs.maxAge
1137
+ );
1138
+ if (!paramCommitments.includes(ageParameterCommitment)) {
1139
+ console.warn("This proof does not verify the age");
1140
+ isCorrect = false;
1141
+ queryResultErrors.age = {
1142
+ ...queryResultErrors.age,
1143
+ commitment: {
1144
+ expected: `Age parameter commitment: ${ageParameterCommitment.toString()}`,
1145
+ received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1146
+ message: "This proof does not verify the age"
1147
+ }
1148
+ };
1149
+ }
1150
+ const { isCorrect: isCorrectAge, queryResultErrors: queryResultErrorsAge } = this.checkAgePublicInputs(proof, queryResult);
1151
+ isCorrect = isCorrect && isCorrectAge;
1152
+ queryResultErrors = {
1153
+ ...queryResultErrors,
1154
+ ...queryResultErrorsAge
1155
+ };
1156
+ } else if (!!committedInputs?.compare_birthdate) {
1157
+ const birthdateCommittedInputs = committedInputs?.compare_birthdate;
1158
+ const birthdateParameterCommitment = isForEVM ? await (0, import_utils.getDateEVMParameterCommitment)(
1159
+ import_utils.ProofType.BIRTHDATE,
1160
+ birthdateCommittedInputs.currentDateTimestamp,
1161
+ birthdateCommittedInputs.minDateTimestamp,
1162
+ birthdateCommittedInputs.maxDateTimestamp,
1163
+ 0
1164
+ ) : await (0, import_utils.getDateParameterCommitment)(
1165
+ import_utils.ProofType.BIRTHDATE,
1166
+ birthdateCommittedInputs.currentDateTimestamp,
1167
+ birthdateCommittedInputs.minDateTimestamp,
1168
+ birthdateCommittedInputs.maxDateTimestamp,
1169
+ 0
1170
+ );
1171
+ if (!paramCommitments.includes(birthdateParameterCommitment)) {
1172
+ console.warn("This proof does not verify the birthdate");
1173
+ isCorrect = false;
1174
+ queryResultErrors.birthdate = {
1175
+ ...queryResultErrors.birthdate,
1176
+ commitment: {
1177
+ expected: `Birthdate parameter commitment: ${birthdateParameterCommitment.toString()}`,
1178
+ received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1179
+ message: "This proof does not verify the birthdate"
1180
+ }
1181
+ };
1182
+ }
1183
+ const { isCorrect: isCorrectBirthdate, queryResultErrors: queryResultErrorsBirthdate } = this.checkBirthdatePublicInputs(proof, queryResult);
1184
+ isCorrect = isCorrect && isCorrectBirthdate;
1185
+ queryResultErrors = {
1186
+ ...queryResultErrors,
1187
+ ...queryResultErrorsBirthdate
1188
+ };
1189
+ } else if (!!committedInputs?.compare_expiry) {
1190
+ const expiryCommittedInputs = committedInputs?.compare_expiry;
1191
+ const expiryParameterCommitment = isForEVM ? await (0, import_utils.getDateEVMParameterCommitment)(
1192
+ import_utils.ProofType.EXPIRY_DATE,
1193
+ expiryCommittedInputs.currentDateTimestamp,
1194
+ expiryCommittedInputs.minDateTimestamp,
1195
+ expiryCommittedInputs.maxDateTimestamp
1196
+ ) : await (0, import_utils.getDateParameterCommitment)(
1197
+ import_utils.ProofType.EXPIRY_DATE,
1198
+ expiryCommittedInputs.currentDateTimestamp,
1199
+ expiryCommittedInputs.minDateTimestamp,
1200
+ expiryCommittedInputs.maxDateTimestamp
1201
+ );
1202
+ if (!paramCommitments.includes(expiryParameterCommitment)) {
1203
+ console.warn("This proof does not verify the expiry date");
1204
+ isCorrect = false;
1205
+ queryResultErrors.expiry_date = {
1206
+ ...queryResultErrors.expiry_date,
1207
+ commitment: {
1208
+ expected: `Expiry date parameter commitment: ${expiryParameterCommitment.toString()}`,
1209
+ received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1210
+ message: "This proof does not verify the expiry date"
1211
+ }
1212
+ };
1213
+ }
1214
+ const { isCorrect: isCorrectExpiryDate, queryResultErrors: queryResultErrorsExpiryDate } = this.checkExpiryDatePublicInputs(proof, queryResult);
1215
+ isCorrect = isCorrect && isCorrectExpiryDate;
1216
+ queryResultErrors = {
1217
+ ...queryResultErrors,
1218
+ ...queryResultErrorsExpiryDate
1219
+ };
1220
+ } else if (!!committedInputs?.disclose_bytes) {
1221
+ const discloseCommittedInputs = committedInputs?.disclose_bytes;
1222
+ const discloseParameterCommitment = isForEVM ? await (0, import_utils.getDiscloseEVMParameterCommitment)(
1223
+ discloseCommittedInputs.discloseMask,
1224
+ discloseCommittedInputs.disclosedBytes
1225
+ ) : await (0, import_utils.getDiscloseParameterCommitment)(
1226
+ discloseCommittedInputs.discloseMask,
1227
+ discloseCommittedInputs.disclosedBytes
1228
+ );
1229
+ if (!paramCommitments.includes(discloseParameterCommitment)) {
1230
+ console.warn("This proof does not verify any of the data disclosed");
1231
+ isCorrect = false;
1232
+ queryResultErrors.disclose = {
1233
+ ...queryResultErrors.disclose,
1234
+ commitment: {
1235
+ expected: `Disclosure parameter commitment: ${discloseParameterCommitment.toString()}`,
1236
+ received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1237
+ message: "This proof does not verify any of the data disclosed"
1238
+ }
1239
+ };
1240
+ }
1241
+ const { isCorrect: isCorrectDisclose, queryResultErrors: queryResultErrorsDisclose } = this.checkDiscloseBytesPublicInputs(proof, queryResult);
1242
+ isCorrect = isCorrect && isCorrectDisclose;
1243
+ queryResultErrors = {
1244
+ ...queryResultErrors,
1245
+ ...queryResultErrorsDisclose
1246
+ };
1247
+ } else if (!!committedInputs?.inclusion_check_nationality) {
1248
+ const inclusionCheckNationalityCommittedInputs = committedInputs?.inclusion_check_nationality;
1249
+ const inclusionCheckNationalityParameterCommitment = isForEVM ? await (0, import_utils.getCountryEVMParameterCommitment)(
1250
+ import_utils.ProofType.NATIONALITY_INCLUSION,
1251
+ inclusionCheckNationalityCommittedInputs.countries
1252
+ ) : await (0, import_utils.getCountryParameterCommitment)(
1253
+ import_utils.ProofType.NATIONALITY_INCLUSION,
1254
+ inclusionCheckNationalityCommittedInputs.countries
1255
+ );
1256
+ if (!paramCommitments.includes(inclusionCheckNationalityParameterCommitment)) {
1257
+ console.warn("This proof does not verify the inclusion of the nationality");
1258
+ isCorrect = false;
1259
+ queryResultErrors.nationality = {
1260
+ ...queryResultErrors.nationality,
1261
+ commitment: {
1262
+ expected: `Nationality parameter commitment: ${inclusionCheckNationalityParameterCommitment.toString()}`,
1263
+ received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1264
+ message: "This proof does not verify the inclusion of the nationality"
1265
+ }
1266
+ };
1267
+ }
1268
+ const countryList = inclusionCheckNationalityCommittedInputs.countries;
1269
+ const {
1270
+ isCorrect: isCorrectNationalityInclusion,
1271
+ queryResultErrors: queryResultErrorsNationalityInclusion
1272
+ } = this.checkNationalityInclusionPublicInputs(queryResult, countryList);
1273
+ isCorrect = isCorrect && isCorrectNationalityInclusion;
1274
+ queryResultErrors = {
1275
+ ...queryResultErrors,
1276
+ ...queryResultErrorsNationalityInclusion
1277
+ };
1278
+ } else if (!!committedInputs?.inclusion_check_issuing_country) {
1279
+ const inclusionCheckIssuingCountryCommittedInputs = committedInputs?.inclusion_check_issuing_country;
1280
+ const inclusionCheckIssuingCountryParameterCommitment = isForEVM ? await (0, import_utils.getCountryEVMParameterCommitment)(
1281
+ import_utils.ProofType.ISSUING_COUNTRY_INCLUSION,
1282
+ inclusionCheckIssuingCountryCommittedInputs.countries
1283
+ ) : await (0, import_utils.getCountryParameterCommitment)(
1284
+ import_utils.ProofType.ISSUING_COUNTRY_INCLUSION,
1285
+ inclusionCheckIssuingCountryCommittedInputs.countries
1286
+ );
1287
+ if (!paramCommitments.includes(inclusionCheckIssuingCountryParameterCommitment)) {
1288
+ console.warn("This proof does not verify the inclusion of the issuing country");
1289
+ isCorrect = false;
1290
+ queryResultErrors.issuing_country = {
1291
+ ...queryResultErrors.issuing_country,
1292
+ commitment: {
1293
+ expected: `Issuing country parameter commitment: ${inclusionCheckIssuingCountryParameterCommitment.toString()}`,
1294
+ received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1295
+ message: "This proof does not verify the inclusion of the issuing country"
1296
+ }
1297
+ };
1298
+ }
1299
+ const countryList = inclusionCheckIssuingCountryCommittedInputs.countries;
1300
+ const {
1301
+ isCorrect: isCorrectIssuingCountryInclusion,
1302
+ queryResultErrors: queryResultErrorsIssuingCountryInclusion
1303
+ } = this.checkIssuingCountryInclusionPublicInputs(queryResult, countryList);
1304
+ isCorrect = isCorrect && isCorrectIssuingCountryInclusion;
1305
+ queryResultErrors = {
1306
+ ...queryResultErrors,
1307
+ ...queryResultErrorsIssuingCountryInclusion
1308
+ };
1309
+ } else if (!!committedInputs?.exclusion_check_nationality) {
1310
+ const exclusionCheckNationalityCommittedInputs = committedInputs?.exclusion_check_nationality;
1311
+ const exclusionCheckNationalityParameterCommitment = isForEVM ? await (0, import_utils.getCountryEVMParameterCommitment)(
1312
+ import_utils.ProofType.NATIONALITY_EXCLUSION,
1313
+ exclusionCheckNationalityCommittedInputs.countries
1314
+ ) : await (0, import_utils.getCountryParameterCommitment)(
1315
+ import_utils.ProofType.NATIONALITY_EXCLUSION,
1316
+ exclusionCheckNationalityCommittedInputs.countries
1317
+ );
1318
+ if (!paramCommitments.includes(exclusionCheckNationalityParameterCommitment)) {
1319
+ console.warn("This proof does not verify the exclusion of the nationality");
1320
+ isCorrect = false;
1321
+ queryResultErrors.nationality = {
1322
+ ...queryResultErrors.nationality,
1323
+ commitment: {
1324
+ expected: `Nationality parameter commitment: ${exclusionCheckNationalityParameterCommitment.toString()}`,
1325
+ received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1326
+ message: "This proof does not verify the exclusion of the nationality"
1327
+ }
1328
+ };
1329
+ }
1330
+ const countryList = exclusionCheckNationalityCommittedInputs.countries;
1331
+ const {
1332
+ isCorrect: isCorrectNationalityExclusion,
1333
+ queryResultErrors: queryResultErrorsNationalityExclusion
1334
+ } = this.checkNationalityExclusionPublicInputs(queryResult, countryList);
1335
+ isCorrect = isCorrect && isCorrectNationalityExclusion;
1336
+ queryResultErrors = {
1337
+ ...queryResultErrors,
1338
+ ...queryResultErrorsNationalityExclusion
1339
+ };
1340
+ } else if (!!committedInputs?.exclusion_check_issuing_country) {
1341
+ const exclusionCheckIssuingCountryCommittedInputs = committedInputs?.exclusion_check_issuing_country;
1342
+ const exclusionCheckIssuingCountryParameterCommitment = isForEVM ? await (0, import_utils.getCountryEVMParameterCommitment)(
1343
+ import_utils.ProofType.ISSUING_COUNTRY_EXCLUSION,
1344
+ exclusionCheckIssuingCountryCommittedInputs.countries
1345
+ ) : await (0, import_utils.getCountryParameterCommitment)(
1346
+ import_utils.ProofType.ISSUING_COUNTRY_EXCLUSION,
1347
+ exclusionCheckIssuingCountryCommittedInputs.countries
1348
+ );
1349
+ if (!paramCommitments.includes(exclusionCheckIssuingCountryParameterCommitment)) {
1350
+ console.warn("This proof does not verify the exclusion of the issuing country");
1351
+ isCorrect = false;
1352
+ queryResultErrors.issuing_country = {
1353
+ ...queryResultErrors.issuing_country,
1354
+ commitment: {
1355
+ expected: `Issuing country parameter commitment: ${exclusionCheckIssuingCountryParameterCommitment.toString()}`,
1356
+ received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1357
+ message: "This proof does not verify the exclusion of the issuing country"
1358
+ }
1359
+ };
1360
+ }
1361
+ const countryList = exclusionCheckIssuingCountryCommittedInputs.countries;
1362
+ const {
1363
+ isCorrect: isCorrectIssuingCountryExclusion,
1364
+ queryResultErrors: queryResultErrorsIssuingCountryExclusion
1365
+ } = this.checkIssuingCountryExclusionPublicInputs(queryResult, countryList);
1366
+ isCorrect = isCorrect && isCorrectIssuingCountryExclusion;
1367
+ queryResultErrors = {
1368
+ ...queryResultErrors,
1369
+ ...queryResultErrorsIssuingCountryExclusion
1370
+ };
1371
+ } else if (!!committedInputs?.bind) {
1372
+ const bindCommittedInputs = committedInputs?.bind;
1373
+ const bindParameterCommitment = isForEVM ? await (0, import_utils.getBindEVMParameterCommitment)((0, import_utils.formatBoundData)(bindCommittedInputs.data)) : await (0, import_utils.getBindParameterCommitment)((0, import_utils.formatBoundData)(bindCommittedInputs.data));
1374
+ if (!paramCommitments.includes(bindParameterCommitment)) {
1375
+ console.warn("This proof does not verify the bound data");
1376
+ isCorrect = false;
1377
+ queryResultErrors.bind = {
1378
+ ...queryResultErrors.bind,
1379
+ commitment: {
1380
+ expected: `Bind parameter commitment: ${bindParameterCommitment.toString()}`,
1381
+ received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1382
+ message: "This proof does not verify the bound data"
1383
+ }
1384
+ };
1385
+ }
1386
+ const { isCorrect: isCorrectBind, queryResultErrors: queryResultErrorsBind } = this.checkBindPublicInputs(queryResult, bindCommittedInputs.data);
1387
+ isCorrect = isCorrect && isCorrectBind;
1388
+ queryResultErrors = {
1389
+ ...queryResultErrors,
1390
+ ...queryResultErrorsBind
1391
+ };
1392
+ } else if (!!committedInputs?.exclusion_check_sanctions) {
1393
+ const sanctionsBuilder = await import_utils.SanctionsBuilder.create();
1394
+ const exclusionCheckSanctionsCommittedInputs = committedInputs?.exclusion_check_sanctions;
1395
+ const exclusionCheckSanctionsParameterCommitment = isForEVM ? await sanctionsBuilder.getSanctionsEvmParameterCommitment() : await sanctionsBuilder.getSanctionsParameterCommitment();
1396
+ if (!paramCommitments.includes(exclusionCheckSanctionsParameterCommitment)) {
1397
+ console.warn("This proof does not verify the exclusion from the sanction lists");
1398
+ isCorrect = false;
1399
+ queryResultErrors.sanctions = {
1400
+ ...queryResultErrors.sanctions,
1401
+ commitment: {
1402
+ expected: `Sanctions parameter commitment: ${exclusionCheckSanctionsParameterCommitment.toString()}`,
1403
+ received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1404
+ message: "This proof does not verify the exclusion from the sanction lists"
1405
+ }
1406
+ };
1407
+ }
1408
+ const {
1409
+ isCorrect: isCorrectSanctionsExclusion,
1410
+ queryResultErrors: queryResultErrorsSanctionsExclusion
1411
+ } = await this.checkSanctionsExclusionPublicInputs(
1412
+ queryResult,
1413
+ exclusionCheckSanctionsCommittedInputs.rootHash,
1414
+ sanctionsBuilder
1415
+ );
1416
+ isCorrect = isCorrect && isCorrectSanctionsExclusion;
1417
+ queryResultErrors = {
1418
+ ...queryResultErrors,
1419
+ ...queryResultErrorsSanctionsExclusion
1420
+ };
1421
+ } else if (!!committedInputs?.facematch) {
1422
+ const facematchCommittedInputs = committedInputs?.facematch;
1423
+ const facematchParameterCommitment = isForEVM ? await (0, import_utils.getFacematchEvmParameterCommitment)(
1424
+ BigInt(facematchCommittedInputs.rootKeyLeaf),
1425
+ facematchCommittedInputs.environment === "development" ? 0n : 1n,
1426
+ BigInt(facematchCommittedInputs.appId),
1427
+ // TODO: Uncomment this when the facematch mode is properly supported
1428
+ // facematchCommittedInputs.mode === "regular" ? 1n : 2n,
1429
+ 1n
1430
+ ) : await (0, import_utils.getFacematchParameterCommitment)(
1431
+ BigInt(facematchCommittedInputs.rootKeyLeaf),
1432
+ facematchCommittedInputs.environment === "development" ? 0n : 1n,
1433
+ BigInt(facematchCommittedInputs.appId),
1434
+ // TODO: Uncomment this when the facematch mode is properly supported
1435
+ // facematchCommittedInputs.mode === "regular" ? 1n : 2n,
1436
+ 1n
1437
+ );
1438
+ if (!paramCommitments.includes(facematchParameterCommitment)) {
1439
+ console.warn("This proof does not verify FaceMatch");
1440
+ isCorrect = false;
1441
+ queryResultErrors.facematch = {
1442
+ ...queryResultErrors.facematch,
1443
+ commitment: {
1444
+ expected: `Facematch parameter commitment: ${facematchParameterCommitment.toString()}`,
1445
+ received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1446
+ message: "This proof does not verify FaceMatch"
1447
+ }
1448
+ };
1449
+ }
1450
+ const { isCorrect: isCorrectFacematch, queryResultErrors: queryResultErrorsFacematch } = await this.checkFacematchPublicInputs(queryResult, facematchCommittedInputs);
1451
+ isCorrect = isCorrect && isCorrectFacematch;
1452
+ queryResultErrors = {
1453
+ ...queryResultErrors,
1454
+ ...queryResultErrorsFacematch
1455
+ };
1456
+ }
1457
+ uniqueIdentifier = (0, import_utils.getNullifierFromOuterProof)(proofData).toString(10);
1458
+ uniqueIdentifierType = (0, import_utils.getNullifierTypeFromOuterProof)(proofData);
1459
+ } else if (proof.name?.startsWith("sig_check_dsc")) {
1460
+ commitmentOut = (0, import_utils.getCommitmentFromDSCProof)(proofData);
1461
+ const merkleRoot = (0, import_utils.getMerkleRootFromDSCProof)(proofData);
1462
+ const {
1463
+ isCorrect: isCorrectCertificateRegistryRoot,
1464
+ queryResultErrors: queryResultErrorsCertificateRegistryRoot
1465
+ } = await this.checkCertificateRegistryRoot(
1466
+ merkleRoot.toString(16),
1467
+ queryResultErrors,
1468
+ false
1469
+ );
1470
+ isCorrect = isCorrect && isCorrectCertificateRegistryRoot;
1471
+ queryResultErrors = {
1472
+ ...queryResultErrors,
1473
+ ...queryResultErrorsCertificateRegistryRoot
1474
+ };
1475
+ } else if (proof.name?.startsWith("sig_check_id_data")) {
1476
+ commitmentIn = (0, import_utils.getCommitmentInFromIDDataProof)(proofData);
1477
+ if (commitmentIn !== commitmentOut) {
1478
+ console.warn(
1479
+ "Failed to check the link between the certificate signature and ID signature"
1480
+ );
1481
+ isCorrect = false;
1482
+ queryResultErrors.sig_check_id_data = {
1483
+ ...queryResultErrors.sig_check_id_data,
1484
+ commitment: {
1485
+ expected: `Commitment: ${commitmentOut?.toString() || "undefined"}`,
1486
+ received: `Commitment: ${commitmentIn?.toString() || "undefined"}`,
1487
+ message: "Failed to check the link between the certificate signature and ID signature"
1488
+ }
1489
+ };
1490
+ }
1491
+ commitmentOut = (0, import_utils.getCommitmentOutFromIDDataProof)(proofData);
1492
+ } else if (proof.name?.startsWith("data_check_integrity")) {
1493
+ commitmentIn = (0, import_utils.getCommitmentInFromIntegrityProof)(proofData);
1494
+ if (commitmentIn !== commitmentOut) {
1495
+ console.warn("Failed to check the link between the ID signature and the data signed");
1496
+ isCorrect = false;
1497
+ queryResultErrors.data_check_integrity = {
1498
+ ...queryResultErrors.data_check_integrity,
1499
+ commitment: {
1500
+ expected: `Commitment: ${commitmentOut?.toString() || "undefined"}`,
1501
+ received: `Commitment: ${commitmentIn?.toString() || "undefined"}`,
1502
+ message: "Failed to check the link between the ID signature and the data signed"
1503
+ }
1504
+ };
1505
+ }
1506
+ commitmentOut = (0, import_utils.getCommitmentOutFromIntegrityProof)(proofData);
1507
+ const currentDate = (0, import_utils.getCurrentDateFromIntegrityProof)(proofData);
1508
+ const todayToCurrentDate = today.getTime() - currentDate.getTime();
1509
+ const expectedDifference = validity ? validity * 1e3 : DEFAULT_VALIDITY * 1e3;
1510
+ const actualDifference = today.getTime() - (today.getTime() - expectedDifference);
1511
+ if (todayToCurrentDate >= actualDifference) {
1512
+ console.warn(
1513
+ `The date used to check the validity of the ID is older than the validity period`
1514
+ );
1515
+ isCorrect = false;
1516
+ queryResultErrors.data_check_integrity = {
1517
+ ...queryResultErrors.data_check_integrity,
1518
+ date: {
1519
+ expected: `Difference: ${validity} seconds`,
1520
+ received: `Difference: ${Math.round(todayToCurrentDate / 1e3)} seconds`,
1521
+ message: "The date used to check the validity of the ID is older than the validity period"
1522
+ }
1523
+ };
1524
+ }
1525
+ } else if (proof.name === "disclose_bytes") {
1526
+ commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1527
+ if (commitmentIn !== commitmentOut) {
1528
+ console.warn(
1529
+ "Failed to check the link between the validity of the ID and the data to disclose"
1530
+ );
1531
+ isCorrect = false;
1532
+ queryResultErrors.disclose = {
1533
+ ...queryResultErrors.disclose,
1534
+ commitment: {
1535
+ expected: `Commitment: ${commitmentOut?.toString() || "undefined"}`,
1536
+ received: `Commitment: ${commitmentIn?.toString() || "undefined"}`,
1537
+ message: "Failed to check the link between the validity of the ID and the data to disclose"
1538
+ }
1539
+ };
1540
+ }
1541
+ const paramCommitment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1542
+ const calculatedParamCommitment = await (0, import_utils.getDiscloseParameterCommitment)(
1543
+ (proof.committedInputs?.disclose_bytes).discloseMask,
1544
+ (proof.committedInputs?.disclose_bytes).disclosedBytes
1545
+ );
1546
+ if (paramCommitment !== calculatedParamCommitment) {
1547
+ console.warn("The disclosed data does not match the data committed by the proof");
1548
+ isCorrect = false;
1549
+ queryResultErrors.disclose = {
1550
+ ...queryResultErrors.disclose,
1551
+ commitment: {
1552
+ expected: `Commitment: ${calculatedParamCommitment}`,
1553
+ received: `Commitment: ${paramCommitment}`,
1554
+ message: "The disclosed data does not match the data committed by the proof"
1555
+ }
1556
+ };
1557
+ }
1558
+ const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(
1559
+ domain,
1560
+ proofData,
1561
+ queryResultErrors,
1562
+ "disclose",
1563
+ scope
1564
+ );
1565
+ isCorrect = isCorrect && isCorrectScope;
1566
+ queryResultErrors = {
1567
+ ...queryResultErrors,
1568
+ ...queryResultErrorsScope
1569
+ };
1570
+ const { isCorrect: isCorrectDisclose, queryResultErrors: queryResultErrorsDisclose } = this.checkDiscloseBytesPublicInputs(proof, queryResult);
1571
+ isCorrect = isCorrect && isCorrectDisclose && isCorrectScope;
1572
+ queryResultErrors = {
1573
+ ...queryResultErrors,
1574
+ ...queryResultErrorsDisclose,
1575
+ ...queryResultErrorsScope
1576
+ };
1577
+ uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1578
+ uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1579
+ } else if (proof.name === "compare_age") {
1580
+ commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1581
+ if (commitmentIn !== commitmentOut) {
1582
+ console.warn(
1583
+ "Failed to check the link between the validity of the ID and the age derived from it"
1584
+ );
1585
+ isCorrect = false;
1586
+ queryResultErrors.age = {
1587
+ ...queryResultErrors.age,
1588
+ commitment: {
1589
+ expected: `Commitment: ${commitmentOut}`,
1590
+ received: `Commitment: ${commitmentIn}`,
1591
+ message: "Failed to check the link between the validity of the ID and the age derived from it"
1592
+ }
1593
+ };
1594
+ }
1595
+ const paramCommitment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1596
+ const committedInputs = proof.committedInputs?.compare_age;
1597
+ const calculatedParamCommitment = await (0, import_utils.getAgeParameterCommitment)(
1598
+ committedInputs.currentDateTimestamp,
1599
+ committedInputs.minAge,
1600
+ committedInputs.maxAge
1601
+ );
1602
+ if (paramCommitment !== calculatedParamCommitment) {
1603
+ console.warn(
1604
+ "The conditions for the age check do not match the conditions checked by the proof"
1605
+ );
1606
+ isCorrect = false;
1607
+ queryResultErrors.age = {
1608
+ ...queryResultErrors.age,
1609
+ commitment: {
1610
+ expected: `Commitment: ${calculatedParamCommitment}`,
1611
+ received: `Commitment: ${paramCommitment}`,
1612
+ message: "The conditions for the age check do not match the conditions checked by the proof"
1613
+ }
1614
+ };
1615
+ }
1616
+ const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(domain, proofData, queryResultErrors, "age", scope);
1617
+ const { isCorrect: isCorrectAge, queryResultErrors: queryResultErrorsAge } = this.checkAgePublicInputs(proof, queryResult);
1618
+ isCorrect = isCorrect && isCorrectAge && isCorrectScope;
1619
+ queryResultErrors = {
1620
+ ...queryResultErrors,
1621
+ ...queryResultErrorsAge,
1622
+ ...queryResultErrorsScope
1623
+ };
1624
+ uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1625
+ uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1626
+ } else if (proof.name === "compare_birthdate") {
1627
+ commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1628
+ if (commitmentIn !== commitmentOut) {
1629
+ console.warn(
1630
+ "Failed to check the link between the validity of the ID and the birthdate derived from it"
1631
+ );
1632
+ isCorrect = false;
1633
+ queryResultErrors.birthdate = {
1634
+ ...queryResultErrors.birthdate,
1635
+ commitment: {
1636
+ expected: `Commitment: ${commitmentOut}`,
1637
+ received: `Commitment: ${commitmentIn}`,
1638
+ message: "Failed to check the link between the validity of the ID and the birthdate derived from it"
1639
+ }
1640
+ };
1641
+ }
1642
+ const paramCommitment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1643
+ const committedInputs = proof.committedInputs?.compare_birthdate;
1644
+ const calculatedParamCommitment = await (0, import_utils.getDateParameterCommitment)(
1645
+ import_utils.ProofType.BIRTHDATE,
1646
+ committedInputs.currentDateTimestamp,
1647
+ committedInputs.minDateTimestamp,
1648
+ committedInputs.maxDateTimestamp,
1649
+ 0
1650
+ );
1651
+ if (paramCommitment !== calculatedParamCommitment) {
1652
+ console.warn(
1653
+ "The conditions for the birthdate check do not match the conditions checked by the proof"
1654
+ );
1655
+ isCorrect = false;
1656
+ queryResultErrors.birthdate = {
1657
+ ...queryResultErrors.birthdate,
1658
+ commitment: {
1659
+ expected: `Commitment: ${calculatedParamCommitment}`,
1660
+ received: `Commitment: ${paramCommitment}`,
1661
+ message: "The conditions for the birthdate check do not match the conditions checked by the proof"
1662
+ }
1663
+ };
1664
+ }
1665
+ const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(
1666
+ domain,
1667
+ proofData,
1668
+ queryResultErrors,
1669
+ "birthdate",
1670
+ scope
1671
+ );
1672
+ const { isCorrect: isCorrectBirthdate, queryResultErrors: queryResultErrorsBirthdate } = this.checkBirthdatePublicInputs(proof, queryResult);
1673
+ isCorrect = isCorrect && isCorrectBirthdate && isCorrectScope;
1674
+ queryResultErrors = {
1675
+ ...queryResultErrors,
1676
+ ...queryResultErrorsBirthdate,
1677
+ ...queryResultErrorsScope
1678
+ };
1679
+ uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1680
+ uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1681
+ } else if (proof.name === "compare_expiry") {
1682
+ commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1683
+ if (commitmentIn !== commitmentOut) {
1684
+ console.warn(
1685
+ "Failed to check the link between the validity of the ID and its expiry date"
1686
+ );
1687
+ isCorrect = false;
1688
+ queryResultErrors.expiry_date = {
1689
+ ...queryResultErrors.expiry_date,
1690
+ commitment: {
1691
+ expected: `Commitment: ${commitmentOut}`,
1692
+ received: `Commitment: ${commitmentIn}`,
1693
+ message: "Failed to check the link between the validity of the ID and its expiry date"
1694
+ }
1695
+ };
1696
+ }
1697
+ const paramCommitment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1698
+ const committedInputs = proof.committedInputs?.compare_expiry;
1699
+ const calculatedParamCommitment = await (0, import_utils.getDateParameterCommitment)(
1700
+ import_utils.ProofType.EXPIRY_DATE,
1701
+ committedInputs.currentDateTimestamp,
1702
+ committedInputs.minDateTimestamp,
1703
+ committedInputs.maxDateTimestamp
1704
+ );
1705
+ if (paramCommitment !== calculatedParamCommitment) {
1706
+ console.warn(
1707
+ "The conditions for the expiry date check do not match the conditions checked by the proof"
1708
+ );
1709
+ isCorrect = false;
1710
+ queryResultErrors.expiry_date = {
1711
+ ...queryResultErrors.expiry_date,
1712
+ commitment: {
1713
+ expected: `Commitment: ${calculatedParamCommitment}`,
1714
+ received: `Commitment: ${paramCommitment}`,
1715
+ message: "The conditions for the expiry date check do not match the conditions checked by the proof"
1716
+ }
1717
+ };
1718
+ }
1719
+ const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(
1720
+ domain,
1721
+ proofData,
1722
+ queryResultErrors,
1723
+ "expiry_date",
1724
+ scope
1725
+ );
1726
+ const { isCorrect: isCorrectExpiryDate, queryResultErrors: queryResultErrorsExpiryDate } = this.checkExpiryDatePublicInputs(proof, queryResult);
1727
+ isCorrect = isCorrect && isCorrectExpiryDate && isCorrectScope;
1728
+ queryResultErrors = {
1729
+ ...queryResultErrors,
1730
+ ...queryResultErrorsExpiryDate,
1731
+ ...queryResultErrorsScope
1732
+ };
1733
+ uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1734
+ uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1735
+ } else if (proof.name === "exclusion_check_nationality") {
1736
+ commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1737
+ if (commitmentIn !== commitmentOut) {
1738
+ console.warn(
1739
+ "Failed to check the link between the validity of the ID and the nationality exclusion check"
1740
+ );
1741
+ isCorrect = false;
1742
+ queryResultErrors.nationality = {
1743
+ ...queryResultErrors.nationality,
1744
+ commitment: {
1745
+ expected: `Commitment: ${commitmentOut}`,
1746
+ received: `Commitment: ${commitmentIn}`,
1747
+ message: "Failed to check the link between the validity of the ID and the nationality exclusion check"
1748
+ }
1749
+ };
1750
+ }
1751
+ const countryList = (proof.committedInputs?.exclusion_check_nationality).countries;
1752
+ const paramCommittment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1753
+ const calculatedParamCommitment = await (0, import_utils.getCountryParameterCommitment)(
1754
+ import_utils.ProofType.NATIONALITY_EXCLUSION,
1755
+ countryList,
1756
+ true
1757
+ );
1758
+ if (paramCommittment !== calculatedParamCommitment) {
1759
+ console.warn(
1760
+ "The committed country list for the exclusion check does not match the one from the proof"
1761
+ );
1762
+ isCorrect = false;
1763
+ queryResultErrors.nationality = {
1764
+ ...queryResultErrors.nationality,
1765
+ commitment: {
1766
+ expected: `Commitment: ${calculatedParamCommitment}`,
1767
+ received: `Commitment: ${paramCommittment}`,
1768
+ message: "The committed country list for the exclusion check does not match the one from the proof"
1769
+ }
1770
+ };
1771
+ }
1772
+ const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(
1773
+ domain,
1774
+ proofData,
1775
+ queryResultErrors,
1776
+ "nationality",
1777
+ scope
1778
+ );
1779
+ const {
1780
+ isCorrect: isCorrectNationalityExclusion,
1781
+ queryResultErrors: queryResultErrorsNationalityExclusion
1782
+ } = this.checkNationalityExclusionPublicInputs(queryResult, countryList);
1783
+ isCorrect = isCorrect && isCorrectNationalityExclusion && isCorrectScope;
1784
+ queryResultErrors = {
1785
+ ...queryResultErrors,
1786
+ ...queryResultErrorsNationalityExclusion,
1787
+ ...queryResultErrorsScope
1788
+ };
1789
+ uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1790
+ uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1791
+ } else if (proof.name === "exclusion_check_issuing_country") {
1792
+ commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1793
+ if (commitmentIn !== commitmentOut) {
1794
+ console.warn(
1795
+ "Failed to check the link between the validity of the ID and the issuing country exclusion check"
1796
+ );
1797
+ isCorrect = false;
1798
+ queryResultErrors.nationality = {
1799
+ ...queryResultErrors.nationality,
1800
+ commitment: {
1801
+ expected: `Commitment: ${commitmentOut}`,
1802
+ received: `Commitment: ${commitmentIn}`,
1803
+ message: "Failed to check the link between the validity of the ID and the issuing country exclusion check"
1804
+ }
1805
+ };
1806
+ }
1807
+ const countryList = (proof.committedInputs?.exclusion_check_issuing_country).countries;
1808
+ const paramCommittment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1809
+ const calculatedParamCommitment = await (0, import_utils.getCountryParameterCommitment)(
1810
+ import_utils.ProofType.ISSUING_COUNTRY_EXCLUSION,
1811
+ countryList,
1812
+ true
1813
+ );
1814
+ if (paramCommittment !== calculatedParamCommitment) {
1815
+ console.warn(
1816
+ "The committed country list for the issuing country exclusion check does not match the one from the proof"
1817
+ );
1818
+ isCorrect = false;
1819
+ queryResultErrors.issuing_country = {
1820
+ ...queryResultErrors.issuing_country,
1821
+ commitment: {
1822
+ expected: `Commitment: ${calculatedParamCommitment}`,
1823
+ received: `Commitment: ${paramCommittment}`,
1824
+ message: "The committed country list for the issuing country exclusion check does not match the one from the proof"
1825
+ }
1826
+ };
1827
+ }
1828
+ const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(
1829
+ domain,
1830
+ proofData,
1831
+ queryResultErrors,
1832
+ "nationality",
1833
+ scope
1834
+ );
1835
+ const {
1836
+ isCorrect: isCorrectIssuingCountryExclusion,
1837
+ queryResultErrors: queryResultErrorsIssuingCountryExclusion
1838
+ } = this.checkIssuingCountryExclusionPublicInputs(queryResult, countryList);
1839
+ isCorrect = isCorrect && isCorrectIssuingCountryExclusion && isCorrectScope;
1840
+ queryResultErrors = {
1841
+ ...queryResultErrors,
1842
+ ...queryResultErrorsIssuingCountryExclusion,
1843
+ ...queryResultErrorsScope
1844
+ };
1845
+ uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1846
+ uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1847
+ } else if (proof.name === "inclusion_check_nationality") {
1848
+ commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1849
+ if (commitmentIn !== commitmentOut) {
1850
+ console.warn(
1851
+ "Failed to check the link between the validity of the ID and the nationality inclusion check"
1852
+ );
1853
+ isCorrect = false;
1854
+ queryResultErrors.nationality = {
1855
+ ...queryResultErrors.nationality,
1856
+ commitment: {
1857
+ expected: `Commitment: ${commitmentOut}`,
1858
+ received: `Commitment: ${commitmentIn}`,
1859
+ message: "Failed to check the link between the validity of the ID and the nationality inclusion check"
1860
+ }
1861
+ };
1862
+ }
1863
+ const countryList = (proof.committedInputs?.inclusion_check_nationality).countries;
1864
+ const paramCommittment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1865
+ const calculatedParamCommitment = await (0, import_utils.getCountryParameterCommitment)(
1866
+ import_utils.ProofType.NATIONALITY_INCLUSION,
1867
+ countryList,
1868
+ false
1869
+ );
1870
+ if (paramCommittment !== calculatedParamCommitment) {
1871
+ console.warn(
1872
+ "The committed country list for the nationality inclusion check does not match the one from the proof"
1873
+ );
1874
+ isCorrect = false;
1875
+ queryResultErrors.nationality = {
1876
+ ...queryResultErrors.nationality,
1877
+ commitment: {
1878
+ expected: `Commitment: ${calculatedParamCommitment}`,
1879
+ received: `Commitment: ${paramCommittment}`,
1880
+ message: "The committed country list for the nationality inclusion check does not match the one from the proof"
1881
+ }
1882
+ };
1883
+ }
1884
+ const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(
1885
+ domain,
1886
+ proofData,
1887
+ queryResultErrors,
1888
+ "nationality",
1889
+ scope
1890
+ );
1891
+ const {
1892
+ isCorrect: isCorrectNationalityInclusion,
1893
+ queryResultErrors: queryResultErrorsNationalityInclusion
1894
+ } = this.checkNationalityInclusionPublicInputs(queryResult, countryList);
1895
+ isCorrect = isCorrect && isCorrectNationalityInclusion && isCorrectScope;
1896
+ queryResultErrors = {
1897
+ ...queryResultErrors,
1898
+ ...queryResultErrorsNationalityInclusion,
1899
+ ...queryResultErrorsScope
1900
+ };
1901
+ uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1902
+ uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1903
+ } else if (proof.name === "inclusion_check_issuing_country") {
1904
+ commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1905
+ if (commitmentIn !== commitmentOut) {
1906
+ console.warn(
1907
+ "Failed to check the link between the validity of the ID and the issuing country inclusion check"
1908
+ );
1909
+ isCorrect = false;
1910
+ queryResultErrors.nationality = {
1911
+ ...queryResultErrors.nationality,
1912
+ commitment: {
1913
+ expected: `Commitment: ${commitmentOut}`,
1914
+ received: `Commitment: ${commitmentIn}`,
1915
+ message: "Failed to check the link between the validity of the ID and the issuing country inclusion check"
1916
+ }
1917
+ };
1918
+ }
1919
+ const countryList = (proof.committedInputs?.inclusion_check_issuing_country).countries;
1920
+ const paramCommittment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1921
+ const calculatedParamCommitment = await (0, import_utils.getCountryParameterCommitment)(
1922
+ import_utils.ProofType.ISSUING_COUNTRY_INCLUSION,
1923
+ countryList,
1924
+ false
1925
+ );
1926
+ if (paramCommittment !== calculatedParamCommitment) {
1927
+ console.warn(
1928
+ "The committed country list for the issuing country inclusion check does not match the one from the proof"
1929
+ );
1930
+ isCorrect = false;
1931
+ queryResultErrors.issuing_country = {
1932
+ ...queryResultErrors.issuing_country,
1933
+ commitment: {
1934
+ expected: `Commitment: ${calculatedParamCommitment}`,
1935
+ received: `Commitment: ${paramCommittment}`,
1936
+ message: "The committed country list for the issuing country inclusion check does not match the one from the proof"
1937
+ }
1938
+ };
1939
+ }
1940
+ const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(
1941
+ domain,
1942
+ proofData,
1943
+ queryResultErrors,
1944
+ "nationality",
1945
+ scope
1946
+ );
1947
+ const {
1948
+ isCorrect: isCorrectIssuingCountryInclusion,
1949
+ queryResultErrors: queryResultErrorsIssuingCountryInclusion
1950
+ } = this.checkIssuingCountryInclusionPublicInputs(queryResult, countryList);
1951
+ isCorrect = isCorrect && isCorrectIssuingCountryInclusion && isCorrectScope;
1952
+ queryResultErrors = {
1953
+ ...queryResultErrors,
1954
+ ...queryResultErrorsIssuingCountryInclusion,
1955
+ ...queryResultErrorsScope
1956
+ };
1957
+ uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1958
+ uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1959
+ } else if (proof.name === "bind") {
1960
+ const bindCommittedInputs = proof.committedInputs?.bind;
1961
+ const paramCommittment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1962
+ const calculatedParamCommitment = await (0, import_utils.getBindParameterCommitment)(
1963
+ (0, import_utils.formatBoundData)(bindCommittedInputs.data)
1964
+ );
1965
+ if (paramCommittment !== calculatedParamCommitment) {
1966
+ console.warn("The bound data does not match the one from the proof");
1967
+ isCorrect = false;
1968
+ queryResultErrors.bind = {
1969
+ ...queryResultErrors.bind,
1970
+ commitment: {
1971
+ expected: `Commitment: ${calculatedParamCommitment}`,
1972
+ received: `Commitment: ${paramCommittment}`,
1973
+ message: "The bound data does not match the one from the proof"
1974
+ }
1975
+ };
1976
+ }
1977
+ const { isCorrect: isCorrectBind, queryResultErrors: queryResultErrorsBind } = this.checkBindPublicInputs(queryResult, bindCommittedInputs.data);
1978
+ isCorrect = isCorrect && isCorrectBind;
1979
+ queryResultErrors = {
1980
+ ...queryResultErrors,
1981
+ ...queryResultErrorsBind
1982
+ };
1983
+ uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1984
+ uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1985
+ } else if (proof.name === "exclusion_check_sanctions") {
1986
+ const sanctionsBuilder = await import_utils.SanctionsBuilder.create();
1987
+ const exclusionCheckSanctionsCommittedInputs = proof.committedInputs?.exclusion_check_sanctions;
1988
+ const calculatedParamCommitment = await sanctionsBuilder.getSanctionsParameterCommitment();
1989
+ const paramCommittment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1990
+ if (paramCommittment !== calculatedParamCommitment) {
1991
+ console.warn(
1992
+ "The sanction lists check against do not match the sanction lists from the proof"
1993
+ );
1994
+ isCorrect = false;
1995
+ queryResultErrors.sanctions = {
1996
+ ...queryResultErrors.sanctions,
1997
+ commitment: {
1998
+ expected: `Commitment: ${calculatedParamCommitment.toString()}`,
1999
+ received: `Commitment: ${paramCommittment.toString()}`,
2000
+ message: "The sanction lists check against do not match the sanction lists from the proof"
2001
+ }
2002
+ };
2003
+ }
2004
+ const {
2005
+ isCorrect: isCorrectSanctionsExclusion,
2006
+ queryResultErrors: queryResultErrorsSanctionsExclusion
2007
+ } = await this.checkSanctionsExclusionPublicInputs(
2008
+ queryResult,
2009
+ exclusionCheckSanctionsCommittedInputs.rootHash,
2010
+ sanctionsBuilder
2011
+ );
2012
+ isCorrect = isCorrect && isCorrectSanctionsExclusion;
2013
+ queryResultErrors = {
2014
+ ...queryResultErrors,
2015
+ ...queryResultErrorsSanctionsExclusion
2016
+ };
2017
+ uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
2018
+ uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
2019
+ } else if (proof.name === "facematch") {
2020
+ const facematchCommittedInputs = proof.committedInputs?.facematch;
2021
+ const paramCommittment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
2022
+ const calculatedParamCommitment = await (0, import_utils.getFacematchParameterCommitment)(
2023
+ BigInt(facematchCommittedInputs.rootKeyLeaf),
2024
+ facematchCommittedInputs.environment === "development" ? 0n : 1n,
2025
+ BigInt(facematchCommittedInputs.appId),
2026
+ // TODO: Uncomment this when the facematch mode is properly supported
2027
+ // facematchCommittedInputs.mode === "regular" ? 1n : 2n,
2028
+ 1n
2029
+ );
2030
+ if (paramCommittment !== calculatedParamCommitment) {
2031
+ console.warn("The FaceMatch verification does not match the ones from the proof");
2032
+ isCorrect = false;
2033
+ queryResultErrors.facematch = {
2034
+ ...queryResultErrors.facematch,
2035
+ commitment: {
2036
+ expected: `Commitment: ${calculatedParamCommitment.toString()}`,
2037
+ received: `Commitment: ${paramCommittment.toString()}`,
2038
+ message: "The FaceMatch verification does not match the ones from the proof"
2039
+ }
2040
+ };
2041
+ }
2042
+ const { isCorrect: isCorrectFacematch, queryResultErrors: queryResultErrorsFacematch } = await this.checkFacematchPublicInputs(queryResult, facematchCommittedInputs);
2043
+ isCorrect = isCorrect && isCorrectFacematch;
2044
+ queryResultErrors = {
2045
+ ...queryResultErrors,
2046
+ ...queryResultErrorsFacematch
2047
+ };
2048
+ uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
2049
+ uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
2050
+ }
2051
+ }
2052
+ return { isCorrect, uniqueIdentifier, uniqueIdentifierType, queryResultErrors };
2053
+ }
2054
+ };
2055
+ // Annotate the CommonJS export names for ESM import in node:
2056
+ 0 && (module.exports = {
2057
+ PublicInputChecker
2058
+ });