@zkpassport/sdk 0.11.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2151 +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, sanctionsCommittedInputs, sanctionsBuilder) {
889
- const queryResultErrors = {};
890
- let isCorrect = true;
891
- if (queryResult.sanctions && queryResult.sanctions.passed) {
892
- const EXPECTED_ROOT = await sanctionsBuilder.getRoot();
893
- if (sanctionsCommittedInputs.rootHash !== 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: sanctionsCommittedInputs.rootHash,
901
- message: "Invalid sanctions registry root"
902
- }
903
- };
904
- }
905
- if (queryResult.sanctions.isStrict !== sanctionsCommittedInputs.isStrict) {
906
- console.warn("Invalid sanctions strict mode");
907
- isCorrect = false;
908
- queryResultErrors.sanctions = {
909
- ...queryResultErrors.sanctions,
910
- eq: {
911
- expected: queryResult.sanctions.isStrict.toString(),
912
- received: sanctionsCommittedInputs.isStrict.toString(),
913
- message: "Invalid sanctions strict mode"
914
- }
915
- };
916
- }
917
- }
918
- return { isCorrect, queryResultErrors };
919
- }
920
- static async checkFacematchPublicInputs(queryResult, facematchCommittedInputs) {
921
- let isCorrect = true;
922
- let queryResultErrors = {};
923
- if (queryResult.facematch && queryResult.facematch.passed) {
924
- if (facematchCommittedInputs.rootKeyLeaf !== APPLE_APP_ATTEST_ROOT_KEY_HASH && facematchCommittedInputs.rootKeyLeaf !== GOOGLE_APP_ATTEST_RSA_ROOT_KEY_HASH) {
925
- console.warn("Invalid facematch root key hash");
926
- isCorrect = false;
927
- queryResultErrors.facematch = {
928
- ...queryResultErrors.facematch,
929
- eq: {
930
- expected: `${APPLE_APP_ATTEST_ROOT_KEY_HASH} (iOS) or ${GOOGLE_APP_ATTEST_RSA_ROOT_KEY_HASH} (Android)`,
931
- received: facematchCommittedInputs.rootKeyLeaf,
932
- message: "Invalid facematch root key hash"
933
- }
934
- };
935
- }
936
- const EXPECTED_ENVIRONMENT = "production";
937
- if (facematchCommittedInputs.environment !== EXPECTED_ENVIRONMENT) {
938
- console.warn("Invalid facematch environment, it should be production");
939
- isCorrect = false;
940
- queryResultErrors.facematch = {
941
- ...queryResultErrors.facematch,
942
- eq: {
943
- expected: EXPECTED_ENVIRONMENT,
944
- received: facematchCommittedInputs.environment,
945
- message: "Invalid facematch environment, it should be production"
946
- }
947
- };
948
- }
949
- if (facematchCommittedInputs.appIdHash !== ZKPASSPORT_IOS_APP_ID_HASH && facematchCommittedInputs.appIdHash !== ZKPASSPORT_ANDROID_APP_ID_HASH) {
950
- console.warn(
951
- "Invalid facematch app id hash, the attestation should be coming from the ZKPassport app"
952
- );
953
- isCorrect = false;
954
- queryResultErrors.facematch = {
955
- ...queryResultErrors.facematch,
956
- eq: {
957
- expected: `${ZKPASSPORT_IOS_APP_ID_HASH} (iOS) or ${ZKPASSPORT_ANDROID_APP_ID_HASH} (Android)`,
958
- received: facematchCommittedInputs.appIdHash,
959
- message: "Invalid facematch app id hash, the attestation should be coming from the ZKPassport app"
960
- }
961
- };
962
- }
963
- }
964
- return { isCorrect, queryResultErrors };
965
- }
966
- static async checkCurrentDate(circuitName, proofData, validity, queryResultErrors) {
967
- const currentTime = /* @__PURE__ */ new Date();
968
- const today = new Date(
969
- currentTime.getFullYear(),
970
- currentTime.getMonth(),
971
- currentTime.getDate(),
972
- 0,
973
- 0,
974
- 0,
975
- 0
976
- );
977
- const currentDate = (0, import_utils.getCurrentDateFromDisclosureProof)(proofData);
978
- const todayToCurrentDate = today.getTime() - currentDate.getTime();
979
- const expectedDifference = validity ? validity * 1e3 : DEFAULT_VALIDITY * 1e3;
980
- const actualDifference = today.getTime() - (today.getTime() - expectedDifference);
981
- let isCorrect = true;
982
- if (todayToCurrentDate >= actualDifference) {
983
- console.warn("The date used to check the validity of the ID falls out of the validity period");
984
- isCorrect = false;
985
- if (!queryResultErrors[circuitName]) {
986
- queryResultErrors[circuitName] = {};
987
- }
988
- queryResultErrors[circuitName].date = {
989
- expected: `Difference: ${validity} seconds`,
990
- received: `Difference: ${Math.round(todayToCurrentDate / 1e3)} seconds`,
991
- message: "The date used to check the validity of the ID falls out of the validity period"
992
- };
993
- }
994
- return { isCorrect, queryResultErrors };
995
- }
996
- static async checkPublicInputs(domain, proofs, queryResult, validity, scope) {
997
- let commitmentIn;
998
- let commitmentOut;
999
- let isCorrect = true;
1000
- let uniqueIdentifier;
1001
- let uniqueIdentifierType;
1002
- const currentTime = /* @__PURE__ */ new Date();
1003
- const today = new Date(
1004
- currentTime.getFullYear(),
1005
- currentTime.getMonth(),
1006
- currentTime.getDate(),
1007
- 0,
1008
- 0,
1009
- 0,
1010
- 0
1011
- );
1012
- let queryResultErrors = {};
1013
- const sortedProofs = proofs.sort((a, b) => {
1014
- const proofOrder = [
1015
- "sig_check_dsc",
1016
- "sig_check_id_data",
1017
- "data_check_integrity",
1018
- "disclose_bytes",
1019
- "compare_age",
1020
- "compare_birthdate",
1021
- "compare_expiry",
1022
- "exclusion_check_nationality",
1023
- "inclusion_check_nationality",
1024
- "exclusion_check_issuing_country",
1025
- "inclusion_check_issuing_country",
1026
- "bind",
1027
- "exclusion_check_sanctions",
1028
- "facematch"
1029
- ];
1030
- const getIndex = (proof) => {
1031
- const name = proof.name || "";
1032
- return proofOrder.findIndex((p) => name.startsWith(p));
1033
- };
1034
- return getIndex(a) - getIndex(b);
1035
- });
1036
- for (const proof of sortedProofs) {
1037
- const proofData = (0, import_utils.getProofData)(proof.proof, (0, import_utils.getNumberOfPublicInputs)(proof.name));
1038
- if (proof.name?.startsWith("outer")) {
1039
- const isForEVM = proof.name?.startsWith("outer_evm");
1040
- const certificateRegistryRoot = (0, import_utils.getCertificateRegistryRootFromOuterProof)(proofData);
1041
- const {
1042
- isCorrect: isCorrectCertificateRegistryRoot,
1043
- queryResultErrors: queryResultErrorsCertificateRegistryRoot
1044
- } = await this.checkCertificateRegistryRoot(
1045
- certificateRegistryRoot.toString(16),
1046
- queryResultErrors,
1047
- true
1048
- );
1049
- isCorrect = isCorrect && isCorrectCertificateRegistryRoot;
1050
- queryResultErrors = {
1051
- ...queryResultErrors,
1052
- ...queryResultErrorsCertificateRegistryRoot
1053
- };
1054
- const circuitRegistryRoot = (0, import_utils.getCircuitRegistryRootFromOuterProof)(proofData);
1055
- const {
1056
- isCorrect: isCorrectCircuitRegistryRoot,
1057
- queryResultErrors: queryResultErrorsCircuitRegistryRoot
1058
- } = await this.checkCircuitRegistryRoot(circuitRegistryRoot.toString(16), queryResultErrors);
1059
- isCorrect = isCorrect && isCorrectCircuitRegistryRoot;
1060
- queryResultErrors = {
1061
- ...queryResultErrors,
1062
- ...queryResultErrorsCircuitRegistryRoot
1063
- };
1064
- const currentDate = (0, import_utils.getCurrentDateFromOuterProof)(proofData);
1065
- const todayToCurrentDate = today.getTime() - currentDate.getTime();
1066
- const expectedDifference = validity ? validity * 1e3 : DEFAULT_VALIDITY * 1e3;
1067
- const actualDifference = today.getTime() - (today.getTime() - expectedDifference);
1068
- if (todayToCurrentDate >= actualDifference) {
1069
- console.warn(
1070
- `The date used to check the validity of the ID is older than the validity period`
1071
- );
1072
- isCorrect = false;
1073
- queryResultErrors.outer = {
1074
- ...queryResultErrors.outer,
1075
- date: {
1076
- expected: `Difference: ${validity} seconds`,
1077
- received: `Difference: ${Math.round(todayToCurrentDate / 1e3)} seconds`,
1078
- message: "The date used to check the validity of the ID is older than the validity period"
1079
- }
1080
- };
1081
- }
1082
- const paramCommitments = (0, import_utils.getParamCommitmentsFromOuterProof)(proofData);
1083
- const committedInputs = proof.committedInputs;
1084
- const keysInCommittedInputs = Object.keys(committedInputs || {});
1085
- if (keysInCommittedInputs.length !== paramCommitments.length) {
1086
- console.warn("The proof does not verify all the requested conditions and information");
1087
- isCorrect = false;
1088
- queryResultErrors.outer = {
1089
- ...queryResultErrors.outer,
1090
- commitment: {
1091
- expected: `Number of parameter commitments: ${paramCommitments.length}`,
1092
- received: `Number of disclosure proofs provided: ${keysInCommittedInputs.length}`,
1093
- message: "The proof does not verify all the requested conditions and information"
1094
- }
1095
- };
1096
- }
1097
- if (domain && (0, import_utils.getServiceScopeHash)(domain) !== (0, import_utils.getScopeFromOuterProof)(proofData)) {
1098
- console.warn("The proof comes from a different domain than the one expected");
1099
- isCorrect = false;
1100
- queryResultErrors.outer = {
1101
- ...queryResultErrors.outer,
1102
- scope: {
1103
- expected: `Scope: ${(0, import_utils.getServiceScopeHash)(domain).toString()}`,
1104
- received: `Scope: ${(0, import_utils.getScopeFromOuterProof)(proofData).toString()}`,
1105
- message: "The proof comes from a different domain than the one expected"
1106
- }
1107
- };
1108
- }
1109
- if (scope && (0, import_utils.getScopeHash)(scope) !== (0, import_utils.getSubscopeFromOuterProof)(proofData)) {
1110
- console.warn("The proof uses a different scope than the one expected");
1111
- isCorrect = false;
1112
- queryResultErrors.outer = {
1113
- ...queryResultErrors.outer,
1114
- scope: {
1115
- expected: `Scope: ${(0, import_utils.getScopeHash)(scope).toString()}`,
1116
- received: `Scope: ${(0, import_utils.getSubscopeFromOuterProof)(proofData).toString()}`,
1117
- message: "The proof uses a different scope than the one expected"
1118
- }
1119
- };
1120
- }
1121
- if (!!committedInputs?.compare_age || !!committedInputs?.compare_age_evm) {
1122
- const ageCommittedInputs = committedInputs?.compare_age ?? committedInputs?.compare_age_evm;
1123
- const ageParameterCommitment = isForEVM ? await (0, import_utils.getAgeEVMParameterCommitment)(
1124
- ageCommittedInputs.minAge,
1125
- ageCommittedInputs.maxAge
1126
- ) : await (0, import_utils.getAgeParameterCommitment)(ageCommittedInputs.minAge, ageCommittedInputs.maxAge);
1127
- if (!paramCommitments.includes(ageParameterCommitment)) {
1128
- console.warn("This proof does not verify the age");
1129
- isCorrect = false;
1130
- queryResultErrors.age = {
1131
- ...queryResultErrors.age,
1132
- commitment: {
1133
- expected: `Age parameter commitment: ${ageParameterCommitment.toString()}`,
1134
- received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1135
- message: "This proof does not verify the age"
1136
- }
1137
- };
1138
- }
1139
- const { isCorrect: isCorrectAge, queryResultErrors: queryResultErrorsAge } = this.checkAgePublicInputs(proof, queryResult);
1140
- isCorrect = isCorrect && isCorrectAge;
1141
- queryResultErrors = {
1142
- ...queryResultErrors,
1143
- ...queryResultErrorsAge
1144
- };
1145
- }
1146
- if (!!committedInputs?.compare_birthdate || !!committedInputs?.compare_birthdate_evm) {
1147
- const birthdateCommittedInputs = committedInputs?.compare_birthdate ?? committedInputs?.compare_birthdate_evm;
1148
- const birthdateParameterCommitment = isForEVM ? await (0, import_utils.getDateEVMParameterCommitment)(
1149
- import_utils.ProofType.BIRTHDATE,
1150
- birthdateCommittedInputs.minDateTimestamp,
1151
- birthdateCommittedInputs.maxDateTimestamp
1152
- ) : await (0, import_utils.getDateParameterCommitment)(
1153
- import_utils.ProofType.BIRTHDATE,
1154
- birthdateCommittedInputs.minDateTimestamp,
1155
- birthdateCommittedInputs.maxDateTimestamp
1156
- );
1157
- if (!paramCommitments.includes(birthdateParameterCommitment)) {
1158
- console.warn("This proof does not verify the birthdate");
1159
- isCorrect = false;
1160
- queryResultErrors.birthdate = {
1161
- ...queryResultErrors.birthdate,
1162
- commitment: {
1163
- expected: `Birthdate parameter commitment: ${birthdateParameterCommitment.toString()}`,
1164
- received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1165
- message: "This proof does not verify the birthdate"
1166
- }
1167
- };
1168
- }
1169
- const { isCorrect: isCorrectBirthdate, queryResultErrors: queryResultErrorsBirthdate } = this.checkBirthdatePublicInputs(proof, queryResult);
1170
- isCorrect = isCorrect && isCorrectBirthdate;
1171
- queryResultErrors = {
1172
- ...queryResultErrors,
1173
- ...queryResultErrorsBirthdate
1174
- };
1175
- }
1176
- if (!!committedInputs?.compare_expiry || !!committedInputs?.compare_expiry_evm) {
1177
- const expiryCommittedInputs = committedInputs?.compare_expiry ?? committedInputs?.compare_expiry_evm;
1178
- const expiryParameterCommitment = isForEVM ? await (0, import_utils.getDateEVMParameterCommitment)(
1179
- import_utils.ProofType.EXPIRY_DATE,
1180
- expiryCommittedInputs.minDateTimestamp,
1181
- expiryCommittedInputs.maxDateTimestamp
1182
- ) : await (0, import_utils.getDateParameterCommitment)(
1183
- import_utils.ProofType.EXPIRY_DATE,
1184
- expiryCommittedInputs.minDateTimestamp,
1185
- expiryCommittedInputs.maxDateTimestamp
1186
- );
1187
- if (!paramCommitments.includes(expiryParameterCommitment)) {
1188
- console.warn("This proof does not verify the expiry date");
1189
- isCorrect = false;
1190
- queryResultErrors.expiry_date = {
1191
- ...queryResultErrors.expiry_date,
1192
- commitment: {
1193
- expected: `Expiry date parameter commitment: ${expiryParameterCommitment.toString()}`,
1194
- received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1195
- message: "This proof does not verify the expiry date"
1196
- }
1197
- };
1198
- }
1199
- const { isCorrect: isCorrectExpiryDate, queryResultErrors: queryResultErrorsExpiryDate } = this.checkExpiryDatePublicInputs(proof, queryResult);
1200
- isCorrect = isCorrect && isCorrectExpiryDate;
1201
- queryResultErrors = {
1202
- ...queryResultErrors,
1203
- ...queryResultErrorsExpiryDate
1204
- };
1205
- }
1206
- if (!!committedInputs?.disclose_bytes || !!committedInputs?.disclose_bytes_evm) {
1207
- const discloseCommittedInputs = committedInputs?.disclose_bytes ?? committedInputs?.disclose_bytes_evm;
1208
- const discloseParameterCommitment = isForEVM ? await (0, import_utils.getDiscloseEVMParameterCommitment)(
1209
- discloseCommittedInputs.discloseMask,
1210
- discloseCommittedInputs.disclosedBytes
1211
- ) : await (0, import_utils.getDiscloseParameterCommitment)(
1212
- discloseCommittedInputs.discloseMask,
1213
- discloseCommittedInputs.disclosedBytes
1214
- );
1215
- if (!paramCommitments.includes(discloseParameterCommitment)) {
1216
- console.warn("This proof does not verify any of the data disclosed");
1217
- isCorrect = false;
1218
- queryResultErrors.disclose = {
1219
- ...queryResultErrors.disclose,
1220
- commitment: {
1221
- expected: `Disclosure parameter commitment: ${discloseParameterCommitment.toString()}`,
1222
- received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1223
- message: "This proof does not verify any of the data disclosed"
1224
- }
1225
- };
1226
- }
1227
- const { isCorrect: isCorrectDisclose, queryResultErrors: queryResultErrorsDisclose } = this.checkDiscloseBytesPublicInputs(proof, queryResult);
1228
- isCorrect = isCorrect && isCorrectDisclose;
1229
- queryResultErrors = {
1230
- ...queryResultErrors,
1231
- ...queryResultErrorsDisclose
1232
- };
1233
- }
1234
- if (!!committedInputs?.inclusion_check_nationality || !!committedInputs?.inclusion_check_nationality_evm) {
1235
- const inclusionCheckNationalityCommittedInputs = committedInputs?.inclusion_check_nationality ?? committedInputs?.inclusion_check_nationality_evm;
1236
- const inclusionCheckNationalityParameterCommitment = isForEVM ? await (0, import_utils.getCountryEVMParameterCommitment)(
1237
- import_utils.ProofType.NATIONALITY_INCLUSION,
1238
- inclusionCheckNationalityCommittedInputs.countries
1239
- ) : await (0, import_utils.getCountryParameterCommitment)(
1240
- import_utils.ProofType.NATIONALITY_INCLUSION,
1241
- inclusionCheckNationalityCommittedInputs.countries
1242
- );
1243
- if (!paramCommitments.includes(inclusionCheckNationalityParameterCommitment)) {
1244
- console.warn("This proof does not verify the inclusion of the nationality");
1245
- isCorrect = false;
1246
- queryResultErrors.nationality = {
1247
- ...queryResultErrors.nationality,
1248
- commitment: {
1249
- expected: `Nationality parameter commitment: ${inclusionCheckNationalityParameterCommitment.toString()}`,
1250
- received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1251
- message: "This proof does not verify the inclusion of the nationality"
1252
- }
1253
- };
1254
- }
1255
- const countryList = inclusionCheckNationalityCommittedInputs.countries;
1256
- const {
1257
- isCorrect: isCorrectNationalityInclusion,
1258
- queryResultErrors: queryResultErrorsNationalityInclusion
1259
- } = this.checkNationalityInclusionPublicInputs(queryResult, countryList);
1260
- isCorrect = isCorrect && isCorrectNationalityInclusion;
1261
- queryResultErrors = {
1262
- ...queryResultErrors,
1263
- ...queryResultErrorsNationalityInclusion
1264
- };
1265
- }
1266
- if (!!committedInputs?.inclusion_check_issuing_country || !!committedInputs?.inclusion_check_issuing_country_evm) {
1267
- const inclusionCheckIssuingCountryCommittedInputs = committedInputs?.inclusion_check_issuing_country ?? committedInputs?.inclusion_check_issuing_country_evm;
1268
- const inclusionCheckIssuingCountryParameterCommitment = isForEVM ? await (0, import_utils.getCountryEVMParameterCommitment)(
1269
- import_utils.ProofType.ISSUING_COUNTRY_INCLUSION,
1270
- inclusionCheckIssuingCountryCommittedInputs.countries
1271
- ) : await (0, import_utils.getCountryParameterCommitment)(
1272
- import_utils.ProofType.ISSUING_COUNTRY_INCLUSION,
1273
- inclusionCheckIssuingCountryCommittedInputs.countries
1274
- );
1275
- if (!paramCommitments.includes(inclusionCheckIssuingCountryParameterCommitment)) {
1276
- console.warn("This proof does not verify the inclusion of the issuing country");
1277
- isCorrect = false;
1278
- queryResultErrors.issuing_country = {
1279
- ...queryResultErrors.issuing_country,
1280
- commitment: {
1281
- expected: `Issuing country parameter commitment: ${inclusionCheckIssuingCountryParameterCommitment.toString()}`,
1282
- received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1283
- message: "This proof does not verify the inclusion of the issuing country"
1284
- }
1285
- };
1286
- }
1287
- const countryList = inclusionCheckIssuingCountryCommittedInputs.countries;
1288
- const {
1289
- isCorrect: isCorrectIssuingCountryInclusion,
1290
- queryResultErrors: queryResultErrorsIssuingCountryInclusion
1291
- } = this.checkIssuingCountryInclusionPublicInputs(queryResult, countryList);
1292
- isCorrect = isCorrect && isCorrectIssuingCountryInclusion;
1293
- queryResultErrors = {
1294
- ...queryResultErrors,
1295
- ...queryResultErrorsIssuingCountryInclusion
1296
- };
1297
- }
1298
- if (!!committedInputs?.exclusion_check_nationality || !!committedInputs?.exclusion_check_nationality_evm) {
1299
- const exclusionCheckNationalityCommittedInputs = committedInputs?.exclusion_check_nationality ?? committedInputs?.exclusion_check_nationality_evm;
1300
- const exclusionCheckNationalityParameterCommitment = isForEVM ? await (0, import_utils.getCountryEVMParameterCommitment)(
1301
- import_utils.ProofType.NATIONALITY_EXCLUSION,
1302
- exclusionCheckNationalityCommittedInputs.countries
1303
- ) : await (0, import_utils.getCountryParameterCommitment)(
1304
- import_utils.ProofType.NATIONALITY_EXCLUSION,
1305
- exclusionCheckNationalityCommittedInputs.countries
1306
- );
1307
- if (!paramCommitments.includes(exclusionCheckNationalityParameterCommitment)) {
1308
- console.warn("This proof does not verify the exclusion of the nationality");
1309
- isCorrect = false;
1310
- queryResultErrors.nationality = {
1311
- ...queryResultErrors.nationality,
1312
- commitment: {
1313
- expected: `Nationality parameter commitment: ${exclusionCheckNationalityParameterCommitment.toString()}`,
1314
- received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1315
- message: "This proof does not verify the exclusion of the nationality"
1316
- }
1317
- };
1318
- }
1319
- const countryList = exclusionCheckNationalityCommittedInputs.countries;
1320
- const {
1321
- isCorrect: isCorrectNationalityExclusion,
1322
- queryResultErrors: queryResultErrorsNationalityExclusion
1323
- } = this.checkNationalityExclusionPublicInputs(queryResult, countryList);
1324
- isCorrect = isCorrect && isCorrectNationalityExclusion;
1325
- queryResultErrors = {
1326
- ...queryResultErrors,
1327
- ...queryResultErrorsNationalityExclusion
1328
- };
1329
- }
1330
- if (!!committedInputs?.exclusion_check_issuing_country || !!committedInputs?.exclusion_check_issuing_country_evm) {
1331
- const exclusionCheckIssuingCountryCommittedInputs = committedInputs?.exclusion_check_issuing_country ?? committedInputs?.exclusion_check_issuing_country_evm;
1332
- const exclusionCheckIssuingCountryParameterCommitment = isForEVM ? await (0, import_utils.getCountryEVMParameterCommitment)(
1333
- import_utils.ProofType.ISSUING_COUNTRY_EXCLUSION,
1334
- exclusionCheckIssuingCountryCommittedInputs.countries
1335
- ) : await (0, import_utils.getCountryParameterCommitment)(
1336
- import_utils.ProofType.ISSUING_COUNTRY_EXCLUSION,
1337
- exclusionCheckIssuingCountryCommittedInputs.countries
1338
- );
1339
- if (!paramCommitments.includes(exclusionCheckIssuingCountryParameterCommitment)) {
1340
- console.warn("This proof does not verify the exclusion of the issuing country");
1341
- isCorrect = false;
1342
- queryResultErrors.issuing_country = {
1343
- ...queryResultErrors.issuing_country,
1344
- commitment: {
1345
- expected: `Issuing country parameter commitment: ${exclusionCheckIssuingCountryParameterCommitment.toString()}`,
1346
- received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1347
- message: "This proof does not verify the exclusion of the issuing country"
1348
- }
1349
- };
1350
- }
1351
- const countryList = exclusionCheckIssuingCountryCommittedInputs.countries;
1352
- const {
1353
- isCorrect: isCorrectIssuingCountryExclusion,
1354
- queryResultErrors: queryResultErrorsIssuingCountryExclusion
1355
- } = this.checkIssuingCountryExclusionPublicInputs(queryResult, countryList);
1356
- isCorrect = isCorrect && isCorrectIssuingCountryExclusion;
1357
- queryResultErrors = {
1358
- ...queryResultErrors,
1359
- ...queryResultErrorsIssuingCountryExclusion
1360
- };
1361
- }
1362
- if (!!committedInputs?.bind || !!committedInputs?.bind_evm) {
1363
- const bindCommittedInputs = committedInputs?.bind ?? committedInputs?.bind_evm;
1364
- 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));
1365
- if (!paramCommitments.includes(bindParameterCommitment)) {
1366
- console.warn("This proof does not verify the bound data");
1367
- isCorrect = false;
1368
- queryResultErrors.bind = {
1369
- ...queryResultErrors.bind,
1370
- commitment: {
1371
- expected: `Bind parameter commitment: ${bindParameterCommitment.toString()}`,
1372
- received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1373
- message: "This proof does not verify the bound data"
1374
- }
1375
- };
1376
- }
1377
- const { isCorrect: isCorrectBind, queryResultErrors: queryResultErrorsBind } = this.checkBindPublicInputs(queryResult, bindCommittedInputs.data);
1378
- isCorrect = isCorrect && isCorrectBind;
1379
- queryResultErrors = {
1380
- ...queryResultErrors,
1381
- ...queryResultErrorsBind
1382
- };
1383
- }
1384
- if (!!committedInputs?.exclusion_check_sanctions || !!committedInputs?.exclusion_check_sanctions_evm) {
1385
- const sanctionsBuilder = await import_utils.SanctionsBuilder.create();
1386
- const exclusionCheckSanctionsCommittedInputs = committedInputs?.exclusion_check_sanctions ?? committedInputs?.exclusion_check_sanctions_evm;
1387
- const exclusionCheckSanctionsParameterCommitment = isForEVM ? await sanctionsBuilder.getSanctionsEvmParameterCommitment(
1388
- exclusionCheckSanctionsCommittedInputs.isStrict
1389
- ) : await sanctionsBuilder.getSanctionsParameterCommitment(
1390
- exclusionCheckSanctionsCommittedInputs.isStrict
1391
- );
1392
- if (!paramCommitments.includes(exclusionCheckSanctionsParameterCommitment)) {
1393
- console.warn("This proof does not verify the exclusion from the sanction lists");
1394
- isCorrect = false;
1395
- queryResultErrors.sanctions = {
1396
- ...queryResultErrors.sanctions,
1397
- commitment: {
1398
- expected: `Sanctions parameter commitment: ${exclusionCheckSanctionsParameterCommitment.toString()}`,
1399
- received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1400
- message: "This proof does not verify the exclusion from the sanction lists"
1401
- }
1402
- };
1403
- }
1404
- const {
1405
- isCorrect: isCorrectSanctionsExclusion,
1406
- queryResultErrors: queryResultErrorsSanctionsExclusion
1407
- } = await this.checkSanctionsExclusionPublicInputs(
1408
- queryResult,
1409
- exclusionCheckSanctionsCommittedInputs,
1410
- sanctionsBuilder
1411
- );
1412
- isCorrect = isCorrect && isCorrectSanctionsExclusion;
1413
- queryResultErrors = {
1414
- ...queryResultErrors,
1415
- ...queryResultErrorsSanctionsExclusion
1416
- };
1417
- }
1418
- if (!!committedInputs?.facematch || !!committedInputs?.facematch_evm) {
1419
- const facematchCommittedInputs = committedInputs?.facematch ?? committedInputs?.facematch_evm;
1420
- const facematchParameterCommitment = isForEVM ? await (0, import_utils.getFacematchEvmParameterCommitment)(
1421
- BigInt(facematchCommittedInputs.rootKeyLeaf),
1422
- facematchCommittedInputs.environment === "development" ? 0n : 1n,
1423
- BigInt(facematchCommittedInputs.appIdHash),
1424
- facematchCommittedInputs.mode === "regular" ? 1n : 2n
1425
- ) : await (0, import_utils.getFacematchParameterCommitment)(
1426
- BigInt(facematchCommittedInputs.rootKeyLeaf),
1427
- facematchCommittedInputs.environment === "development" ? 0n : 1n,
1428
- BigInt(facematchCommittedInputs.appIdHash),
1429
- facematchCommittedInputs.mode === "regular" ? 1n : 2n
1430
- );
1431
- if (!paramCommitments.includes(facematchParameterCommitment)) {
1432
- console.warn("This proof does not verify FaceMatch");
1433
- isCorrect = false;
1434
- queryResultErrors.facematch = {
1435
- ...queryResultErrors.facematch,
1436
- commitment: {
1437
- expected: `Facematch parameter commitment: ${facematchParameterCommitment.toString()}`,
1438
- received: `Parameter commitments included: ${paramCommitments.join(", ")}`,
1439
- message: "This proof does not verify FaceMatch"
1440
- }
1441
- };
1442
- }
1443
- const { isCorrect: isCorrectFacematch, queryResultErrors: queryResultErrorsFacematch } = await this.checkFacematchPublicInputs(queryResult, facematchCommittedInputs);
1444
- isCorrect = isCorrect && isCorrectFacematch;
1445
- queryResultErrors = {
1446
- ...queryResultErrors,
1447
- ...queryResultErrorsFacematch
1448
- };
1449
- }
1450
- uniqueIdentifier = (0, import_utils.getNullifierFromOuterProof)(proofData).toString(10);
1451
- uniqueIdentifierType = (0, import_utils.getNullifierTypeFromOuterProof)(proofData);
1452
- } else if (proof.name?.startsWith("sig_check_dsc")) {
1453
- commitmentOut = (0, import_utils.getCommitmentFromDSCProof)(proofData);
1454
- const merkleRoot = (0, import_utils.getMerkleRootFromDSCProof)(proofData);
1455
- const {
1456
- isCorrect: isCorrectCertificateRegistryRoot,
1457
- queryResultErrors: queryResultErrorsCertificateRegistryRoot
1458
- } = await this.checkCertificateRegistryRoot(
1459
- merkleRoot.toString(16),
1460
- queryResultErrors,
1461
- false
1462
- );
1463
- isCorrect = isCorrect && isCorrectCertificateRegistryRoot;
1464
- queryResultErrors = {
1465
- ...queryResultErrors,
1466
- ...queryResultErrorsCertificateRegistryRoot
1467
- };
1468
- } else if (proof.name?.startsWith("sig_check_id_data")) {
1469
- commitmentIn = (0, import_utils.getCommitmentInFromIDDataProof)(proofData);
1470
- if (commitmentIn !== commitmentOut) {
1471
- console.warn(
1472
- "Failed to check the link between the certificate signature and ID signature"
1473
- );
1474
- isCorrect = false;
1475
- queryResultErrors.sig_check_id_data = {
1476
- ...queryResultErrors.sig_check_id_data,
1477
- commitment: {
1478
- expected: `Commitment: ${commitmentOut?.toString() || "undefined"}`,
1479
- received: `Commitment: ${commitmentIn?.toString() || "undefined"}`,
1480
- message: "Failed to check the link between the certificate signature and ID signature"
1481
- }
1482
- };
1483
- }
1484
- commitmentOut = (0, import_utils.getCommitmentOutFromIDDataProof)(proofData);
1485
- } else if (proof.name?.startsWith("data_check_integrity")) {
1486
- commitmentIn = (0, import_utils.getCommitmentInFromIntegrityProof)(proofData);
1487
- if (commitmentIn !== commitmentOut) {
1488
- console.warn("Failed to check the link between the ID signature and the data signed");
1489
- isCorrect = false;
1490
- queryResultErrors.data_check_integrity = {
1491
- ...queryResultErrors.data_check_integrity,
1492
- commitment: {
1493
- expected: `Commitment: ${commitmentOut?.toString() || "undefined"}`,
1494
- received: `Commitment: ${commitmentIn?.toString() || "undefined"}`,
1495
- message: "Failed to check the link between the ID signature and the data signed"
1496
- }
1497
- };
1498
- }
1499
- commitmentOut = (0, import_utils.getCommitmentOutFromIntegrityProof)(proofData);
1500
- } else if (proof.name === "disclose_bytes") {
1501
- commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1502
- if (commitmentIn !== commitmentOut) {
1503
- console.warn(
1504
- "Failed to check the link between the validity of the ID and the data to disclose"
1505
- );
1506
- isCorrect = false;
1507
- queryResultErrors.disclose = {
1508
- ...queryResultErrors.disclose,
1509
- commitment: {
1510
- expected: `Commitment: ${commitmentOut?.toString() || "undefined"}`,
1511
- received: `Commitment: ${commitmentIn?.toString() || "undefined"}`,
1512
- message: "Failed to check the link between the validity of the ID and the data to disclose"
1513
- }
1514
- };
1515
- }
1516
- const paramCommitment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1517
- const calculatedParamCommitment = await (0, import_utils.getDiscloseParameterCommitment)(
1518
- (proof.committedInputs?.disclose_bytes).discloseMask,
1519
- (proof.committedInputs?.disclose_bytes).disclosedBytes
1520
- );
1521
- if (paramCommitment !== calculatedParamCommitment) {
1522
- console.warn("The disclosed data does not match the data committed by the proof");
1523
- isCorrect = false;
1524
- queryResultErrors.disclose = {
1525
- ...queryResultErrors.disclose,
1526
- commitment: {
1527
- expected: `Commitment: ${calculatedParamCommitment}`,
1528
- received: `Commitment: ${paramCommitment}`,
1529
- message: "The disclosed data does not match the data committed by the proof"
1530
- }
1531
- };
1532
- }
1533
- const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(
1534
- domain,
1535
- proofData,
1536
- queryResultErrors,
1537
- "disclose",
1538
- scope
1539
- );
1540
- isCorrect = isCorrect && isCorrectScope;
1541
- queryResultErrors = {
1542
- ...queryResultErrors,
1543
- ...queryResultErrorsScope
1544
- };
1545
- const { isCorrect: isCorrectDisclose, queryResultErrors: queryResultErrorsDisclose } = this.checkDiscloseBytesPublicInputs(proof, queryResult);
1546
- isCorrect = isCorrect && isCorrectDisclose && isCorrectScope;
1547
- queryResultErrors = {
1548
- ...queryResultErrors,
1549
- ...queryResultErrorsDisclose,
1550
- ...queryResultErrorsScope
1551
- };
1552
- const { isCorrect: isCorrectCurrentDate, queryResultErrors: queryResultErrorsCurrentDate } = await this.checkCurrentDate(
1553
- "disclose",
1554
- proofData,
1555
- validity ?? DEFAULT_VALIDITY,
1556
- queryResultErrors
1557
- );
1558
- isCorrect = isCorrect && isCorrectCurrentDate;
1559
- queryResultErrors = {
1560
- ...queryResultErrors,
1561
- ...queryResultErrorsCurrentDate
1562
- };
1563
- uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1564
- uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1565
- } else if (proof.name === "compare_age") {
1566
- commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1567
- if (commitmentIn !== commitmentOut) {
1568
- console.warn(
1569
- "Failed to check the link between the validity of the ID and the age derived from it"
1570
- );
1571
- isCorrect = false;
1572
- queryResultErrors.age = {
1573
- ...queryResultErrors.age,
1574
- commitment: {
1575
- expected: `Commitment: ${commitmentOut}`,
1576
- received: `Commitment: ${commitmentIn}`,
1577
- message: "Failed to check the link between the validity of the ID and the age derived from it"
1578
- }
1579
- };
1580
- }
1581
- const paramCommitment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1582
- const committedInputs = proof.committedInputs?.compare_age;
1583
- const calculatedParamCommitment = await (0, import_utils.getAgeParameterCommitment)(
1584
- committedInputs.minAge,
1585
- committedInputs.maxAge
1586
- );
1587
- if (paramCommitment !== calculatedParamCommitment) {
1588
- console.warn(
1589
- "The conditions for the age check do not match the conditions checked by the proof"
1590
- );
1591
- isCorrect = false;
1592
- queryResultErrors.age = {
1593
- ...queryResultErrors.age,
1594
- commitment: {
1595
- expected: `Commitment: ${calculatedParamCommitment}`,
1596
- received: `Commitment: ${paramCommitment}`,
1597
- message: "The conditions for the age check do not match the conditions checked by the proof"
1598
- }
1599
- };
1600
- }
1601
- const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(domain, proofData, queryResultErrors, "age", scope);
1602
- const { isCorrect: isCorrectAge, queryResultErrors: queryResultErrorsAge } = this.checkAgePublicInputs(proof, queryResult);
1603
- isCorrect = isCorrect && isCorrectAge && isCorrectScope;
1604
- queryResultErrors = {
1605
- ...queryResultErrors,
1606
- ...queryResultErrorsAge,
1607
- ...queryResultErrorsScope
1608
- };
1609
- const { isCorrect: isCorrectCurrentDate, queryResultErrors: queryResultErrorsCurrentDate } = await this.checkCurrentDate(
1610
- "age",
1611
- proofData,
1612
- validity ?? DEFAULT_VALIDITY,
1613
- queryResultErrors
1614
- );
1615
- isCorrect = isCorrect && isCorrectCurrentDate;
1616
- queryResultErrors = {
1617
- ...queryResultErrors,
1618
- ...queryResultErrorsCurrentDate
1619
- };
1620
- uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1621
- uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1622
- } else if (proof.name === "compare_birthdate") {
1623
- commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1624
- if (commitmentIn !== commitmentOut) {
1625
- console.warn(
1626
- "Failed to check the link between the validity of the ID and the birthdate derived from it"
1627
- );
1628
- isCorrect = false;
1629
- queryResultErrors.birthdate = {
1630
- ...queryResultErrors.birthdate,
1631
- commitment: {
1632
- expected: `Commitment: ${commitmentOut}`,
1633
- received: `Commitment: ${commitmentIn}`,
1634
- message: "Failed to check the link between the validity of the ID and the birthdate derived from it"
1635
- }
1636
- };
1637
- }
1638
- const paramCommitment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1639
- const committedInputs = proof.committedInputs?.compare_birthdate;
1640
- const calculatedParamCommitment = await (0, import_utils.getDateParameterCommitment)(
1641
- import_utils.ProofType.BIRTHDATE,
1642
- committedInputs.minDateTimestamp,
1643
- committedInputs.maxDateTimestamp,
1644
- 0
1645
- );
1646
- if (paramCommitment !== calculatedParamCommitment) {
1647
- console.warn(
1648
- "The conditions for the birthdate check do not match the conditions checked by the proof"
1649
- );
1650
- isCorrect = false;
1651
- queryResultErrors.birthdate = {
1652
- ...queryResultErrors.birthdate,
1653
- commitment: {
1654
- expected: `Commitment: ${calculatedParamCommitment}`,
1655
- received: `Commitment: ${paramCommitment}`,
1656
- message: "The conditions for the birthdate check do not match the conditions checked by the proof"
1657
- }
1658
- };
1659
- }
1660
- const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(
1661
- domain,
1662
- proofData,
1663
- queryResultErrors,
1664
- "birthdate",
1665
- scope
1666
- );
1667
- const { isCorrect: isCorrectBirthdate, queryResultErrors: queryResultErrorsBirthdate } = this.checkBirthdatePublicInputs(proof, queryResult);
1668
- isCorrect = isCorrect && isCorrectBirthdate && isCorrectScope;
1669
- queryResultErrors = {
1670
- ...queryResultErrors,
1671
- ...queryResultErrorsBirthdate,
1672
- ...queryResultErrorsScope
1673
- };
1674
- const { isCorrect: isCorrectCurrentDate, queryResultErrors: queryResultErrorsCurrentDate } = await this.checkCurrentDate(
1675
- "birthdate",
1676
- proofData,
1677
- validity ?? DEFAULT_VALIDITY,
1678
- queryResultErrors
1679
- );
1680
- isCorrect = isCorrect && isCorrectCurrentDate;
1681
- queryResultErrors = {
1682
- ...queryResultErrors,
1683
- ...queryResultErrorsCurrentDate
1684
- };
1685
- uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1686
- uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1687
- } else if (proof.name === "compare_expiry") {
1688
- commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1689
- if (commitmentIn !== commitmentOut) {
1690
- console.warn(
1691
- "Failed to check the link between the validity of the ID and its expiry date"
1692
- );
1693
- isCorrect = false;
1694
- queryResultErrors.expiry_date = {
1695
- ...queryResultErrors.expiry_date,
1696
- commitment: {
1697
- expected: `Commitment: ${commitmentOut}`,
1698
- received: `Commitment: ${commitmentIn}`,
1699
- message: "Failed to check the link between the validity of the ID and its expiry date"
1700
- }
1701
- };
1702
- }
1703
- const paramCommitment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1704
- const committedInputs = proof.committedInputs?.compare_expiry;
1705
- const calculatedParamCommitment = await (0, import_utils.getDateParameterCommitment)(
1706
- import_utils.ProofType.EXPIRY_DATE,
1707
- committedInputs.minDateTimestamp,
1708
- committedInputs.maxDateTimestamp
1709
- );
1710
- if (paramCommitment !== calculatedParamCommitment) {
1711
- console.warn(
1712
- "The conditions for the expiry date check do not match the conditions checked by the proof"
1713
- );
1714
- isCorrect = false;
1715
- queryResultErrors.expiry_date = {
1716
- ...queryResultErrors.expiry_date,
1717
- commitment: {
1718
- expected: `Commitment: ${calculatedParamCommitment}`,
1719
- received: `Commitment: ${paramCommitment}`,
1720
- message: "The conditions for the expiry date check do not match the conditions checked by the proof"
1721
- }
1722
- };
1723
- }
1724
- const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(
1725
- domain,
1726
- proofData,
1727
- queryResultErrors,
1728
- "expiry_date",
1729
- scope
1730
- );
1731
- const { isCorrect: isCorrectExpiryDate, queryResultErrors: queryResultErrorsExpiryDate } = this.checkExpiryDatePublicInputs(proof, queryResult);
1732
- isCorrect = isCorrect && isCorrectExpiryDate && isCorrectScope;
1733
- queryResultErrors = {
1734
- ...queryResultErrors,
1735
- ...queryResultErrorsExpiryDate,
1736
- ...queryResultErrorsScope
1737
- };
1738
- const { isCorrect: isCorrectCurrentDate, queryResultErrors: queryResultErrorsCurrentDate } = await this.checkCurrentDate(
1739
- "expiry_date",
1740
- proofData,
1741
- validity ?? DEFAULT_VALIDITY,
1742
- queryResultErrors
1743
- );
1744
- isCorrect = isCorrect && isCorrectCurrentDate;
1745
- queryResultErrors = {
1746
- ...queryResultErrors,
1747
- ...queryResultErrorsCurrentDate
1748
- };
1749
- uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1750
- uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1751
- } else if (proof.name === "exclusion_check_nationality") {
1752
- commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1753
- if (commitmentIn !== commitmentOut) {
1754
- console.warn(
1755
- "Failed to check the link between the validity of the ID and the nationality exclusion check"
1756
- );
1757
- isCorrect = false;
1758
- queryResultErrors.nationality = {
1759
- ...queryResultErrors.nationality,
1760
- commitment: {
1761
- expected: `Commitment: ${commitmentOut}`,
1762
- received: `Commitment: ${commitmentIn}`,
1763
- message: "Failed to check the link between the validity of the ID and the nationality exclusion check"
1764
- }
1765
- };
1766
- }
1767
- const countryList = (proof.committedInputs?.exclusion_check_nationality).countries;
1768
- const paramCommittment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1769
- const calculatedParamCommitment = await (0, import_utils.getCountryParameterCommitment)(
1770
- import_utils.ProofType.NATIONALITY_EXCLUSION,
1771
- countryList,
1772
- true
1773
- );
1774
- if (paramCommittment !== calculatedParamCommitment) {
1775
- console.warn(
1776
- "The committed country list for the exclusion check does not match the one from the proof"
1777
- );
1778
- isCorrect = false;
1779
- queryResultErrors.nationality = {
1780
- ...queryResultErrors.nationality,
1781
- commitment: {
1782
- expected: `Commitment: ${calculatedParamCommitment}`,
1783
- received: `Commitment: ${paramCommittment}`,
1784
- message: "The committed country list for the exclusion check does not match the one from the proof"
1785
- }
1786
- };
1787
- }
1788
- const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(
1789
- domain,
1790
- proofData,
1791
- queryResultErrors,
1792
- "nationality",
1793
- scope
1794
- );
1795
- const {
1796
- isCorrect: isCorrectNationalityExclusion,
1797
- queryResultErrors: queryResultErrorsNationalityExclusion
1798
- } = this.checkNationalityExclusionPublicInputs(queryResult, countryList);
1799
- isCorrect = isCorrect && isCorrectNationalityExclusion && isCorrectScope;
1800
- queryResultErrors = {
1801
- ...queryResultErrors,
1802
- ...queryResultErrorsNationalityExclusion,
1803
- ...queryResultErrorsScope
1804
- };
1805
- const { isCorrect: isCorrectCurrentDate, queryResultErrors: queryResultErrorsCurrentDate } = await this.checkCurrentDate(
1806
- "nationality",
1807
- proofData,
1808
- validity ?? DEFAULT_VALIDITY,
1809
- queryResultErrors
1810
- );
1811
- isCorrect = isCorrect && isCorrectCurrentDate;
1812
- queryResultErrors = {
1813
- ...queryResultErrors,
1814
- ...queryResultErrorsCurrentDate
1815
- };
1816
- uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1817
- uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1818
- } else if (proof.name === "exclusion_check_issuing_country") {
1819
- commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1820
- if (commitmentIn !== commitmentOut) {
1821
- console.warn(
1822
- "Failed to check the link between the validity of the ID and the issuing country exclusion check"
1823
- );
1824
- isCorrect = false;
1825
- queryResultErrors.nationality = {
1826
- ...queryResultErrors.nationality,
1827
- commitment: {
1828
- expected: `Commitment: ${commitmentOut}`,
1829
- received: `Commitment: ${commitmentIn}`,
1830
- message: "Failed to check the link between the validity of the ID and the issuing country exclusion check"
1831
- }
1832
- };
1833
- }
1834
- const countryList = (proof.committedInputs?.exclusion_check_issuing_country).countries;
1835
- const paramCommittment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1836
- const calculatedParamCommitment = await (0, import_utils.getCountryParameterCommitment)(
1837
- import_utils.ProofType.ISSUING_COUNTRY_EXCLUSION,
1838
- countryList,
1839
- true
1840
- );
1841
- if (paramCommittment !== calculatedParamCommitment) {
1842
- console.warn(
1843
- "The committed country list for the issuing country exclusion check does not match the one from the proof"
1844
- );
1845
- isCorrect = false;
1846
- queryResultErrors.issuing_country = {
1847
- ...queryResultErrors.issuing_country,
1848
- commitment: {
1849
- expected: `Commitment: ${calculatedParamCommitment}`,
1850
- received: `Commitment: ${paramCommittment}`,
1851
- message: "The committed country list for the issuing country exclusion check does not match the one from the proof"
1852
- }
1853
- };
1854
- }
1855
- const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(
1856
- domain,
1857
- proofData,
1858
- queryResultErrors,
1859
- "nationality",
1860
- scope
1861
- );
1862
- const {
1863
- isCorrect: isCorrectIssuingCountryExclusion,
1864
- queryResultErrors: queryResultErrorsIssuingCountryExclusion
1865
- } = this.checkIssuingCountryExclusionPublicInputs(queryResult, countryList);
1866
- isCorrect = isCorrect && isCorrectIssuingCountryExclusion && isCorrectScope;
1867
- queryResultErrors = {
1868
- ...queryResultErrors,
1869
- ...queryResultErrorsIssuingCountryExclusion,
1870
- ...queryResultErrorsScope
1871
- };
1872
- const { isCorrect: isCorrectCurrentDate, queryResultErrors: queryResultErrorsCurrentDate } = await this.checkCurrentDate(
1873
- "issuing_country",
1874
- proofData,
1875
- validity ?? DEFAULT_VALIDITY,
1876
- queryResultErrors
1877
- );
1878
- isCorrect = isCorrect && isCorrectCurrentDate;
1879
- queryResultErrors = {
1880
- ...queryResultErrors,
1881
- ...queryResultErrorsCurrentDate
1882
- };
1883
- uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1884
- uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1885
- } else if (proof.name === "inclusion_check_nationality") {
1886
- commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1887
- if (commitmentIn !== commitmentOut) {
1888
- console.warn(
1889
- "Failed to check the link between the validity of the ID and the nationality inclusion check"
1890
- );
1891
- isCorrect = false;
1892
- queryResultErrors.nationality = {
1893
- ...queryResultErrors.nationality,
1894
- commitment: {
1895
- expected: `Commitment: ${commitmentOut}`,
1896
- received: `Commitment: ${commitmentIn}`,
1897
- message: "Failed to check the link between the validity of the ID and the nationality inclusion check"
1898
- }
1899
- };
1900
- }
1901
- const countryList = (proof.committedInputs?.inclusion_check_nationality).countries;
1902
- const paramCommittment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1903
- const calculatedParamCommitment = await (0, import_utils.getCountryParameterCommitment)(
1904
- import_utils.ProofType.NATIONALITY_INCLUSION,
1905
- countryList,
1906
- false
1907
- );
1908
- if (paramCommittment !== calculatedParamCommitment) {
1909
- console.warn(
1910
- "The committed country list for the nationality inclusion check does not match the one from the proof"
1911
- );
1912
- isCorrect = false;
1913
- queryResultErrors.nationality = {
1914
- ...queryResultErrors.nationality,
1915
- commitment: {
1916
- expected: `Commitment: ${calculatedParamCommitment}`,
1917
- received: `Commitment: ${paramCommittment}`,
1918
- message: "The committed country list for the nationality inclusion check does not match the one from the proof"
1919
- }
1920
- };
1921
- }
1922
- const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(
1923
- domain,
1924
- proofData,
1925
- queryResultErrors,
1926
- "nationality",
1927
- scope
1928
- );
1929
- const {
1930
- isCorrect: isCorrectNationalityInclusion,
1931
- queryResultErrors: queryResultErrorsNationalityInclusion
1932
- } = this.checkNationalityInclusionPublicInputs(queryResult, countryList);
1933
- isCorrect = isCorrect && isCorrectNationalityInclusion && isCorrectScope;
1934
- queryResultErrors = {
1935
- ...queryResultErrors,
1936
- ...queryResultErrorsNationalityInclusion,
1937
- ...queryResultErrorsScope
1938
- };
1939
- const { isCorrect: isCorrectCurrentDate, queryResultErrors: queryResultErrorsCurrentDate } = await this.checkCurrentDate(
1940
- "nationality",
1941
- proofData,
1942
- validity ?? DEFAULT_VALIDITY,
1943
- queryResultErrors
1944
- );
1945
- isCorrect = isCorrect && isCorrectCurrentDate;
1946
- queryResultErrors = {
1947
- ...queryResultErrors,
1948
- ...queryResultErrorsCurrentDate
1949
- };
1950
- uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
1951
- uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
1952
- } else if (proof.name === "inclusion_check_issuing_country") {
1953
- commitmentIn = (0, import_utils.getCommitmentInFromDisclosureProof)(proofData);
1954
- if (commitmentIn !== commitmentOut) {
1955
- console.warn(
1956
- "Failed to check the link between the validity of the ID and the issuing country inclusion check"
1957
- );
1958
- isCorrect = false;
1959
- queryResultErrors.nationality = {
1960
- ...queryResultErrors.nationality,
1961
- commitment: {
1962
- expected: `Commitment: ${commitmentOut}`,
1963
- received: `Commitment: ${commitmentIn}`,
1964
- message: "Failed to check the link between the validity of the ID and the issuing country inclusion check"
1965
- }
1966
- };
1967
- }
1968
- const countryList = (proof.committedInputs?.inclusion_check_issuing_country).countries;
1969
- const paramCommittment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
1970
- const calculatedParamCommitment = await (0, import_utils.getCountryParameterCommitment)(
1971
- import_utils.ProofType.ISSUING_COUNTRY_INCLUSION,
1972
- countryList,
1973
- false
1974
- );
1975
- if (paramCommittment !== calculatedParamCommitment) {
1976
- console.warn(
1977
- "The committed country list for the issuing country inclusion check does not match the one from the proof"
1978
- );
1979
- isCorrect = false;
1980
- queryResultErrors.issuing_country = {
1981
- ...queryResultErrors.issuing_country,
1982
- commitment: {
1983
- expected: `Commitment: ${calculatedParamCommitment}`,
1984
- received: `Commitment: ${paramCommittment}`,
1985
- message: "The committed country list for the issuing country inclusion check does not match the one from the proof"
1986
- }
1987
- };
1988
- }
1989
- const { isCorrect: isCorrectScope, queryResultErrors: queryResultErrorsScope } = this.checkScopeFromDisclosureProof(
1990
- domain,
1991
- proofData,
1992
- queryResultErrors,
1993
- "nationality",
1994
- scope
1995
- );
1996
- const {
1997
- isCorrect: isCorrectIssuingCountryInclusion,
1998
- queryResultErrors: queryResultErrorsIssuingCountryInclusion
1999
- } = this.checkIssuingCountryInclusionPublicInputs(queryResult, countryList);
2000
- isCorrect = isCorrect && isCorrectIssuingCountryInclusion && isCorrectScope;
2001
- queryResultErrors = {
2002
- ...queryResultErrors,
2003
- ...queryResultErrorsIssuingCountryInclusion,
2004
- ...queryResultErrorsScope
2005
- };
2006
- const { isCorrect: isCorrectCurrentDate, queryResultErrors: queryResultErrorsCurrentDate } = await this.checkCurrentDate(
2007
- "issuing_country",
2008
- proofData,
2009
- validity ?? DEFAULT_VALIDITY,
2010
- queryResultErrors
2011
- );
2012
- isCorrect = isCorrect && isCorrectCurrentDate;
2013
- queryResultErrors = {
2014
- ...queryResultErrors,
2015
- ...queryResultErrorsCurrentDate
2016
- };
2017
- uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
2018
- uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
2019
- } else if (proof.name === "bind") {
2020
- const bindCommittedInputs = proof.committedInputs?.bind;
2021
- const paramCommittment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
2022
- const calculatedParamCommitment = await (0, import_utils.getBindParameterCommitment)(
2023
- (0, import_utils.formatBoundData)(bindCommittedInputs.data)
2024
- );
2025
- if (paramCommittment !== calculatedParamCommitment) {
2026
- console.warn("The bound data does not match the one from the proof");
2027
- isCorrect = false;
2028
- queryResultErrors.bind = {
2029
- ...queryResultErrors.bind,
2030
- commitment: {
2031
- expected: `Commitment: ${calculatedParamCommitment}`,
2032
- received: `Commitment: ${paramCommittment}`,
2033
- message: "The bound data does not match the one from the proof"
2034
- }
2035
- };
2036
- }
2037
- const { isCorrect: isCorrectBind, queryResultErrors: queryResultErrorsBind } = this.checkBindPublicInputs(queryResult, bindCommittedInputs.data);
2038
- isCorrect = isCorrect && isCorrectBind;
2039
- queryResultErrors = {
2040
- ...queryResultErrors,
2041
- ...queryResultErrorsBind
2042
- };
2043
- const { isCorrect: isCorrectCurrentDate, queryResultErrors: queryResultErrorsCurrentDate } = await this.checkCurrentDate(
2044
- "bind",
2045
- proofData,
2046
- validity ?? DEFAULT_VALIDITY,
2047
- queryResultErrors
2048
- );
2049
- isCorrect = isCorrect && isCorrectCurrentDate;
2050
- queryResultErrors = {
2051
- ...queryResultErrors,
2052
- ...queryResultErrorsCurrentDate
2053
- };
2054
- uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
2055
- uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
2056
- } else if (proof.name === "exclusion_check_sanctions") {
2057
- const sanctionsBuilder = await import_utils.SanctionsBuilder.create();
2058
- const exclusionCheckSanctionsCommittedInputs = proof.committedInputs?.exclusion_check_sanctions;
2059
- const calculatedParamCommitment = await sanctionsBuilder.getSanctionsParameterCommitment(
2060
- exclusionCheckSanctionsCommittedInputs.isStrict
2061
- );
2062
- const paramCommittment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
2063
- if (paramCommittment !== calculatedParamCommitment) {
2064
- console.warn(
2065
- "The sanction lists check against do not match the sanction lists from the proof"
2066
- );
2067
- isCorrect = false;
2068
- queryResultErrors.sanctions = {
2069
- ...queryResultErrors.sanctions,
2070
- commitment: {
2071
- expected: `Commitment: ${calculatedParamCommitment.toString()}`,
2072
- received: `Commitment: ${paramCommittment.toString()}`,
2073
- message: "The sanction lists check against do not match the sanction lists from the proof"
2074
- }
2075
- };
2076
- }
2077
- const {
2078
- isCorrect: isCorrectSanctionsExclusion,
2079
- queryResultErrors: queryResultErrorsSanctionsExclusion
2080
- } = await this.checkSanctionsExclusionPublicInputs(
2081
- queryResult,
2082
- exclusionCheckSanctionsCommittedInputs,
2083
- sanctionsBuilder
2084
- );
2085
- isCorrect = isCorrect && isCorrectSanctionsExclusion;
2086
- queryResultErrors = {
2087
- ...queryResultErrors,
2088
- ...queryResultErrorsSanctionsExclusion
2089
- };
2090
- const { isCorrect: isCorrectCurrentDate, queryResultErrors: queryResultErrorsCurrentDate } = await this.checkCurrentDate(
2091
- "sanctions",
2092
- proofData,
2093
- validity ?? DEFAULT_VALIDITY,
2094
- queryResultErrors
2095
- );
2096
- isCorrect = isCorrect && isCorrectCurrentDate;
2097
- queryResultErrors = {
2098
- ...queryResultErrors,
2099
- ...queryResultErrorsCurrentDate
2100
- };
2101
- uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
2102
- uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
2103
- } else if (proof.name?.startsWith("facematch") && !proof.name?.endsWith("_evm")) {
2104
- const facematchCommittedInputs = proof.committedInputs?.facematch;
2105
- const paramCommittment = (0, import_utils.getParameterCommitmentFromDisclosureProof)(proofData);
2106
- const calculatedParamCommitment = await (0, import_utils.getFacematchParameterCommitment)(
2107
- BigInt(facematchCommittedInputs.rootKeyLeaf),
2108
- facematchCommittedInputs.environment === "development" ? 0n : 1n,
2109
- BigInt(facematchCommittedInputs.appIdHash),
2110
- facematchCommittedInputs.mode === "regular" ? 1n : 2n
2111
- );
2112
- if (paramCommittment !== calculatedParamCommitment) {
2113
- console.warn("The FaceMatch verification does not match the ones from the proof");
2114
- isCorrect = false;
2115
- queryResultErrors.facematch = {
2116
- ...queryResultErrors.facematch,
2117
- commitment: {
2118
- expected: `Commitment: ${calculatedParamCommitment.toString()}`,
2119
- received: `Commitment: ${paramCommittment.toString()}`,
2120
- message: "The FaceMatch verification does not match the ones from the proof"
2121
- }
2122
- };
2123
- }
2124
- const { isCorrect: isCorrectFacematch, queryResultErrors: queryResultErrorsFacematch } = await this.checkFacematchPublicInputs(queryResult, facematchCommittedInputs);
2125
- isCorrect = isCorrect && isCorrectFacematch;
2126
- queryResultErrors = {
2127
- ...queryResultErrors,
2128
- ...queryResultErrorsFacematch
2129
- };
2130
- const { isCorrect: isCorrectCurrentDate, queryResultErrors: queryResultErrorsCurrentDate } = await this.checkCurrentDate(
2131
- "facematch",
2132
- proofData,
2133
- validity ?? DEFAULT_VALIDITY,
2134
- queryResultErrors
2135
- );
2136
- isCorrect = isCorrect && isCorrectCurrentDate;
2137
- queryResultErrors = {
2138
- ...queryResultErrors,
2139
- ...queryResultErrorsCurrentDate
2140
- };
2141
- uniqueIdentifier = (0, import_utils.getNullifierFromDisclosureProof)(proofData).toString(10);
2142
- uniqueIdentifierType = (0, import_utils.getNullifierTypeFromDisclosureProof)(proofData);
2143
- }
2144
- }
2145
- return { isCorrect, uniqueIdentifier, uniqueIdentifierType, queryResultErrors };
2146
- }
2147
- };
2148
- // Annotate the CommonJS export names for ESM import in node:
2149
- 0 && (module.exports = {
2150
- PublicInputChecker
2151
- });