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