@zkpassport/sdk 0.11.0 → 0.12.0

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