@zkpassport/sdk 0.14.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -3
- package/dist/esm/index.d.ts +1 -3
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.d.cts
CHANGED
|
@@ -33,7 +33,6 @@ type SolidityServiceConfig = {
|
|
|
33
33
|
domain: string;
|
|
34
34
|
scope: string;
|
|
35
35
|
devMode: boolean;
|
|
36
|
-
oprfPubKeyHash: string;
|
|
37
36
|
};
|
|
38
37
|
type SolidityVerifierParameters = {
|
|
39
38
|
version: string;
|
|
@@ -327,13 +326,12 @@ declare class ZKPassport {
|
|
|
327
326
|
}[];
|
|
328
327
|
}[];
|
|
329
328
|
};
|
|
330
|
-
getSolidityVerifierParameters({ proof, validityPeriodInSeconds, domain, scope, devMode,
|
|
329
|
+
getSolidityVerifierParameters({ proof, validityPeriodInSeconds, domain, scope, devMode, }: {
|
|
331
330
|
proof: ProofResult;
|
|
332
331
|
validityPeriodInSeconds?: number;
|
|
333
332
|
domain?: string;
|
|
334
333
|
scope?: string;
|
|
335
334
|
devMode?: boolean;
|
|
336
|
-
oprfPubKeyHash?: string;
|
|
337
335
|
}): SolidityVerifierParameters;
|
|
338
336
|
private _getUrl;
|
|
339
337
|
/**
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -33,7 +33,6 @@ type SolidityServiceConfig = {
|
|
|
33
33
|
domain: string;
|
|
34
34
|
scope: string;
|
|
35
35
|
devMode: boolean;
|
|
36
|
-
oprfPubKeyHash: string;
|
|
37
36
|
};
|
|
38
37
|
type SolidityVerifierParameters = {
|
|
39
38
|
version: string;
|
|
@@ -327,13 +326,12 @@ declare class ZKPassport {
|
|
|
327
326
|
}[];
|
|
328
327
|
}[];
|
|
329
328
|
};
|
|
330
|
-
getSolidityVerifierParameters({ proof, validityPeriodInSeconds, domain, scope, devMode,
|
|
329
|
+
getSolidityVerifierParameters({ proof, validityPeriodInSeconds, domain, scope, devMode, }: {
|
|
331
330
|
proof: ProofResult;
|
|
332
331
|
validityPeriodInSeconds?: number;
|
|
333
332
|
domain?: string;
|
|
334
333
|
scope?: string;
|
|
335
334
|
devMode?: boolean;
|
|
336
|
-
oprfPubKeyHash?: string;
|
|
337
335
|
}): SolidityVerifierParameters;
|
|
338
336
|
private _getUrl;
|
|
339
337
|
/**
|
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {registerLocale,getAlpha3Code}from'i18n-iso-countries';import {formatQueryResultDates,NullifierType,getProofData,getNumberOfPublicInputs,DisclosedData,areDatesEqual,formatName,getMinAgeFromCommittedInputs,getMaxAgeFromCommittedInputs,getBirthdateMinDateTimestamp,SECONDS_BETWEEN_1900_AND_1970,getBirthdateMaxDateTimestamp,getMinDateFromCommittedInputs,getMaxDateFromCommittedInputs,getServiceScopeHash,getServiceScopeFromDisclosureProof,getScopeHash,getServiceSubScopeFromDisclosureProof,getCurrentDateFromDisclosureProof,getCertificateRegistryRootFromOuterProof,getCircuitRegistryRootFromOuterProof,getCurrentDateFromOuterProof,getParamCommitmentsFromOuterProof,getScopeFromOuterProof,getSubscopeFromOuterProof,getAgeEVMParameterCommitment,getAgeParameterCommitment,getDateEVMParameterCommitment,ProofType,getDateParameterCommitment,getDiscloseEVMParameterCommitment,getDiscloseParameterCommitment,getCountryEVMParameterCommitment,getCountryParameterCommitment,getBindEVMParameterCommitment,formatBoundData,getBindParameterCommitment,SanctionsBuilder,getFacematchEvmParameterCommitment,getFacematchParameterCommitment,getNullifierFromOuterProof,getNullifierTypeFromOuterProof,getCommitmentFromDSCProof,getMerkleRootFromDSCProof,getCommitmentInFromIDDataProof,getCommitmentOutFromIDDataProof,getCommitmentInFromIntegrityProof,getCommitmentOutFromIntegrityProof,getCommitmentInFromDisclosureProof,getParameterCommitmentFromDisclosureProof,getNullifierFromDisclosureProof,getNullifierTypeFromDisclosureProof,getOprfPublicKey,OPRF_DEFAULT_KEY_ID,hashOprfPublicKey,getOprfPkHashFromDisclosureProof,getCommittedInputCount,ProofTypeLength,rightPadArrayWithZeros,numberToBytesBE}from'@zkpassport/utils';export{ASEAN_COUNTRIES,EEA_COUNTRIES,EU_COUNTRIES,MERCOSUR_COUNTRIES,NullifierType,ProofType,ProofTypeLength,SANCTIONED_COUNTRIES,SCHENGEN_COUNTRIES}from'@zkpassport/utils';import _t from'i18n-iso-countries/langs/en.json';import {Buffer}from'buffer/';import {RegistryClient}from'@zkpassport/registry';import {Bridge}from'@obsidion/bridge';import {sha256}from'@noble/hashes/sha2.js';import {hexToBytes,bytesToHex}from'@noble/hashes/utils.js';var be="0.12.0";var Y=new Date(0),ye="0x0000000000000000000000000000000000000000000000000000000000000000",re="0x1fa73686cf510f8f85757b0602de0dd72a13e68ae2092462be8b72662e7f179b",de="0x24d9929b248be7eeecaa98e105c034a50539610f3fdd4cb9c8983ef4100d615d",ce="0x2532418a107c5306fa8308c22255792cf77e4a290cbce8a840a642a3e591340b",fe="0x16700a2d9168a194fc85f237af5829b5a2be05b8ae8ac4879ada34cf54a9c211",me="0x0e1889bec6c1d686abcf08360ff404f803ab345881ea8cba6aad33b7f7f7ffe0";var ne=class{static checkDiscloseBytesPublicInputs(i,a,e){let t={},s=true,c=i.committedInputs?.disclose_bytes?.disclosedBytes??i.committedInputs?.disclose_bytes_evm?.disclosedBytes,h=DisclosedData.fromDisclosedBytes(c,"passport"),p=DisclosedData.fromDisclosedBytes(c,"id_card");if(e.document_type&&(e.document_type.eq&&e.document_type.eq.result&&e.document_type.eq.expected!==h.documentType&&(console.warn("Document type does not match the expected document type"),s=false,t.document_type={...t.document_type,eq:{expected:`${e.document_type.eq.expected}`,received:`${h.documentType??p.documentType}`,message:"Document type does not match the expected document type"}}),e.document_type.disclose&&e.document_type.disclose.result!==p.documentType&&(console.warn("Document type does not match the disclosed document type in query result"),s=false,t.document_type={...t.document_type,disclose:{expected:`${e.document_type.disclose?.result}`,received:`${p.documentType??h.documentType}`,message:"Document type does not match the disclosed document type in query result"}}),e.document_type.eq&&(a.document_type?.eq===void 0||e.document_type.eq.expected!==a.document_type.eq)&&(console.warn("Document type eq does not match the original query"),s=false,t.document_type={...t.document_type,eq:{expected:`${a.document_type?.eq}`,received:`${e.document_type.eq.expected}`,message:"Document type eq does not match the original query"}}),e.document_type.disclose&&!a.document_type?.disclose&&(console.warn("Document type disclose is not in the original query"),s=false,t.document_type={...t.document_type,disclose:{expected:"Not requested in original query",received:`${e.document_type.disclose.result}`,message:"Document type disclose is not in the original query"}})),e.birthdate){let r=h.dateOfBirth,f=p.dateOfBirth;e.birthdate.eq&&e.birthdate.eq.result&&!areDatesEqual(e.birthdate.eq.expected,r)&&!areDatesEqual(e.birthdate.eq.expected,f)&&(console.warn("Birthdate does not match the expected birthdate"),s=false,t.birthdate={...t.birthdate,eq:{expected:`${e.birthdate.eq.expected.toISOString()}`,received:`${r?.toISOString()??f?.toISOString()}`,message:"Birthdate does not match the expected birthdate"}}),e.birthdate.disclose&&!areDatesEqual(e.birthdate.disclose.result,r)&&!areDatesEqual(e.birthdate.disclose.result,f)&&(console.warn("Birthdate does not match the disclosed birthdate in query result"),s=false,t.birthdate={...t.birthdate,disclose:{expected:`${e.birthdate.disclose.result.toISOString()}`,received:`${r?.toISOString()??f?.toISOString()}`,message:"Birthdate does not match the disclosed birthdate in query result"}}),e.birthdate.eq&&(a.birthdate?.eq===void 0||!areDatesEqual(e.birthdate.eq.expected,a.birthdate.eq))&&(console.warn("Birthdate eq does not match the original query"),s=false,t.birthdate={...t.birthdate,eq:{expected:`${a.birthdate?.eq?.toISOString?.()??"undefined"}`,received:`${e.birthdate.eq.expected.toISOString()}`,message:"Birthdate eq does not match the original query"}}),e.birthdate.disclose&&!a.birthdate?.disclose&&(console.warn("Birthdate disclose is not in the original query"),s=false,t.birthdate={...t.birthdate,disclose:{expected:"Not requested in original query",received:`${e.birthdate.disclose.result}`,message:"Birthdate disclose is not in the original query"}});}if(e.expiry_date){let r=h.dateOfExpiry,f=p.dateOfExpiry;e.expiry_date.eq&&e.expiry_date.eq.result&&!areDatesEqual(e.expiry_date.eq.expected,r)&&!areDatesEqual(e.expiry_date.eq.expected,f)&&(console.warn("Expiry date does not match the expected expiry date"),s=false,t.expiry_date={...t.expiry_date,eq:{expected:`${e.expiry_date.eq.expected.toISOString()}`,received:`${r?.toISOString()??f?.toISOString()}`,message:"Expiry date does not match the expected expiry date"}}),e.expiry_date.disclose&&!areDatesEqual(e.expiry_date.disclose.result,r)&&!areDatesEqual(e.expiry_date.disclose.result,f)&&(console.warn("Expiry date does not match the disclosed expiry date in query result"),s=false,t.expiry_date={...t.expiry_date,disclose:{expected:`${e.expiry_date.disclose.result.toISOString()}`,received:`${r?.toISOString()??f?.toISOString()}`,message:"Expiry date does not match the disclosed expiry date in query result"}}),e.expiry_date.eq&&(a.expiry_date?.eq===void 0||!areDatesEqual(e.expiry_date.eq.expected,a.expiry_date.eq))&&(console.warn("Expiry date eq does not match the original query"),s=false,t.expiry_date={...t.expiry_date,eq:{expected:`${a.expiry_date?.eq?.toISOString?.()??"undefined"}`,received:`${e.expiry_date.eq.expected.toISOString()}`,message:"Expiry date eq does not match the original query"}}),e.expiry_date.disclose&&!a.expiry_date?.disclose&&(console.warn("Expiry date disclose is not in the original query"),s=false,t.expiry_date={...t.expiry_date,disclose:{expected:"Not requested in original query",received:`${e.expiry_date.disclose.result}`,message:"Expiry date disclose is not in the original query"}});}if(e.nationality){let r=h.nationality,f=p.nationality;e.nationality.eq&&e.nationality.eq.result&&e.nationality.eq.expected!==r&&e.nationality.eq.expected!==f&&(console.warn("Nationality does not match the expected nationality"),s=false,t.nationality={...t.nationality,eq:{expected:`${e.nationality.eq.expected}`,received:`${r??f}`,message:"Nationality does not match the expected nationality"}}),e.nationality.disclose&&e.nationality.disclose.result!==r&&e.nationality.disclose.result!==f&&(console.warn("Nationality does not match the disclosed nationality in query result"),s=false,t.nationality={...t.nationality,disclose:{expected:`${e.nationality.disclose.result}`,received:`${r??f}`,message:"Nationality does not match the disclosed nationality in query result"}}),e.nationality.eq&&(a.nationality?.eq===void 0||e.nationality.eq.expected!==a.nationality.eq)&&(console.warn("Nationality eq does not match the original query"),s=false,t.nationality={...t.nationality,eq:{expected:`${a.nationality?.eq}`,received:`${e.nationality.eq.expected}`,message:"Nationality eq does not match the original query"}}),e.nationality.disclose&&!a.nationality?.disclose&&(console.warn("Nationality disclose is not in the original query"),s=false,t.nationality={...t.nationality,disclose:{expected:"Not requested in original query",received:`${e.nationality.disclose.result}`,message:"Nationality disclose is not in the original query"}});}if(e.document_number){let r=h.documentNumber,f=p.documentNumber;e.document_number.eq&&e.document_number.eq.result&&e.document_number.eq.expected!==r&&e.document_number.eq.expected!==f&&(console.warn("Document number does not match the expected document number"),s=false,t.document_number={...t.document_number,eq:{expected:`${e.document_number.eq.expected}`,received:`${r??f}`,message:"Document number does not match the expected document number"}}),e.document_number.disclose&&e.document_number.disclose.result!==r&&e.document_number.disclose.result!==f&&(console.warn("Document number does not match the disclosed document number in query result"),s=false,t.document_number={...t.document_number,disclose:{expected:`${e.document_number.disclose.result}`,received:`${r??f}`,message:"Document number does not match the disclosed document number in query result"}}),e.document_number.eq&&(a.document_number?.eq===void 0||e.document_number.eq.expected!==a.document_number.eq)&&(console.warn("Document number eq does not match the original query"),s=false,t.document_number={...t.document_number,eq:{expected:`${a.document_number?.eq}`,received:`${e.document_number.eq.expected}`,message:"Document number eq does not match the original query"}}),e.document_number.disclose&&!a.document_number?.disclose&&(console.warn("Document number disclose is not in the original query"),s=false,t.document_number={...t.document_number,disclose:{expected:"Not requested in original query",received:`${e.document_number.disclose.result}`,message:"Document number disclose is not in the original query"}});}if(e.gender){let r=h.gender,f=p.gender;e.gender.eq&&e.gender.eq.result&&e.gender.eq.expected!==r&&e.gender.eq.expected!==f&&(console.warn("Gender does not match the expected gender"),s=false,t.gender={...t.gender,eq:{expected:`${e.gender.eq.expected}`,received:`${r??f}`,message:"Gender does not match the expected gender"}}),e.gender.disclose&&e.gender.disclose.result!==r&&e.gender.disclose.result!==f&&(console.warn("Gender does not match the disclosed gender in query result"),s=false,t.gender={...t.gender,disclose:{expected:`${e.gender.disclose.result}`,received:`${r??f}`,message:"Gender does not match the disclosed gender in query result"}}),e.gender.eq&&(a.gender?.eq===void 0||e.gender.eq.expected!==a.gender.eq)&&(console.warn("Gender eq does not match the original query"),s=false,t.gender={...t.gender,eq:{expected:`${a.gender?.eq}`,received:`${e.gender.eq.expected}`,message:"Gender eq does not match the original query"}}),e.gender.disclose&&!a.gender?.disclose&&(console.warn("Gender disclose is not in the original query"),s=false,t.gender={...t.gender,disclose:{expected:"Not requested in original query",received:`${e.gender.disclose.result}`,message:"Gender disclose is not in the original query"}});}if(e.issuing_country){let r=h.issuingCountry,f=p.issuingCountry;e.issuing_country.eq&&e.issuing_country.eq.result&&e.issuing_country.eq.expected!==r&&e.issuing_country.eq.expected!==f&&(console.warn("Issuing country does not match the expected issuing country"),s=false,t.issuing_country={...t.issuing_country,eq:{expected:`${e.issuing_country.eq.expected}`,received:`${r??f}`,message:"Issuing country does not match the expected issuing country"}}),e.issuing_country.disclose&&e.issuing_country.disclose.result!==r&&e.issuing_country.disclose.result!==f&&(console.warn("Issuing country does not match the disclosed issuing country in query result"),s=false,t.issuing_country={...t.issuing_country,disclose:{expected:`${e.issuing_country.disclose.result}`,received:`${r??f}`,message:"Issuing country does not match the disclosed issuing country in query result"}}),e.issuing_country.eq&&(a.issuing_country?.eq===void 0||e.issuing_country.eq.expected!==a.issuing_country.eq)&&(console.warn("Issuing country eq does not match the original query"),s=false,t.issuing_country={...t.issuing_country,eq:{expected:`${a.issuing_country?.eq}`,received:`${e.issuing_country.eq.expected}`,message:"Issuing country eq does not match the original query"}}),e.issuing_country.disclose&&!a.issuing_country?.disclose&&(console.warn("Issuing country disclose is not in the original query"),s=false,t.issuing_country={...t.issuing_country,disclose:{expected:"Not requested in original query",received:`${e.issuing_country.disclose.result}`,message:"Issuing country disclose is not in the original query"}});}if(e.fullname){let r=h.name,f=p.name;e.fullname.eq&&e.fullname.eq.result&&formatName(e.fullname.eq.expected).toLowerCase()!==r.toLowerCase()&&formatName(e.fullname.eq.expected).toLowerCase()!==f.toLowerCase()&&(console.warn("Fullname does not match the expected fullname"),s=false,t.fullname={...t.fullname,eq:{expected:`${e.fullname.eq.expected}`,received:`${r??f}`,message:"Fullname does not match the expected fullname"}}),e.fullname.disclose&&formatName(e.fullname.disclose.result).toLowerCase()!==r.toLowerCase()&&formatName(e.fullname.disclose.result).toLowerCase()!==f.toLowerCase()&&(console.warn("Fullname does not match the disclosed fullname in query result"),s=false,t.fullname={...t.fullname,disclose:{expected:`${e.fullname.disclose.result}`,received:`${r??f}`,message:"Fullname does not match the disclosed fullname in query result"}}),e.fullname.eq&&(a.fullname?.eq===void 0||formatName(e.fullname.eq.expected).toLowerCase()!==formatName(a.fullname.eq).toLowerCase())&&(console.warn("Fullname eq does not match the original query"),s=false,t.fullname={...t.fullname,eq:{expected:`${a.fullname?.eq}`,received:`${e.fullname.eq.expected}`,message:"Fullname eq does not match the original query"}}),e.fullname.disclose&&!a.fullname?.disclose&&(console.warn("Fullname disclose is not in the original query"),s=false,t.fullname={...t.fullname,disclose:{expected:"Not requested in original query",received:`${e.fullname.disclose.result}`,message:"Fullname disclose is not in the original query"}});}if(e.firstname){let r=h.firstName&&h.firstName.length>0?h.firstName:h.name,f=p.firstName&&p.firstName.length>0?p.firstName:p.name;e.firstname.eq&&e.firstname.eq.result&&formatName(e.firstname.eq.expected).toLowerCase()!==r.toLowerCase()&&formatName(e.firstname.eq.expected).toLowerCase()!==f.toLowerCase()&&(console.warn("Firstname does not match the expected firstname"),s=false,t.firstname={...t.firstname,eq:{expected:`${e.firstname.eq.expected}`,received:`${r??f}`,message:"Firstname does not match the expected firstname"}}),e.firstname.disclose&&formatName(e.firstname.disclose.result).toLowerCase()!==r.toLowerCase()&&formatName(e.firstname.disclose.result).toLowerCase()!==f.toLowerCase()&&(console.warn("Firstname does not match the disclosed firstname in query result"),s=false,t.firstname={...t.firstname,disclose:{expected:`${e.firstname.disclose.result}`,received:`${r??f}`,message:"Firstname does not match the disclosed firstname in query result"}}),e.firstname.eq&&(a.firstname?.eq===void 0||formatName(e.firstname.eq.expected).toLowerCase()!==formatName(a.firstname.eq).toLowerCase())&&(console.warn("Firstname eq does not match the original query"),s=false,t.firstname={...t.firstname,eq:{expected:`${a.firstname?.eq}`,received:`${e.firstname.eq.expected}`,message:"Firstname eq does not match the original query"}}),e.firstname.disclose&&!a.firstname?.disclose&&(console.warn("Firstname disclose is not in the original query"),s=false,t.firstname={...t.firstname,disclose:{expected:"Not requested in original query",received:`${e.firstname.disclose.result}`,message:"Firstname disclose is not in the original query"}});}if(e.lastname){let r=h.lastName&&h.lastName.length>0?h.lastName:h.name,f=p.lastName&&p.lastName.length>0?p.lastName:p.name;e.lastname.eq&&e.lastname.eq.result&&formatName(e.lastname.eq.expected).toLowerCase()!==r.toLowerCase()&&formatName(e.lastname.eq.expected).toLowerCase()!==f.toLowerCase()&&(console.warn("Lastname does not match the expected lastname"),s=false,t.lastname={...t.lastname,eq:{expected:`${e.lastname.eq.expected}`,received:`${r??f}`,message:"Lastname does not match the expected lastname"}}),e.lastname.disclose&&formatName(e.lastname.disclose.result).toLowerCase()!==r.toLowerCase()&&formatName(e.lastname.disclose.result).toLowerCase()!==f.toLowerCase()&&(console.warn("Lastname does not match the disclosed lastname in query result"),s=false,t.lastname={...t.lastname,disclose:{expected:`${e.lastname.disclose.result}`,received:`${r??f}`,message:"Lastname does not match the disclosed lastname in query result"}}),e.lastname.eq&&(a.lastname?.eq===void 0||formatName(e.lastname.eq.expected).toLowerCase()!==formatName(a.lastname.eq).toLowerCase())&&(console.warn("Lastname eq does not match the original query"),s=false,t.lastname={...t.lastname,eq:{expected:`${a.lastname?.eq}`,received:`${e.lastname.eq.expected}`,message:"Lastname eq does not match the original query"}}),e.lastname.disclose&&!a.lastname?.disclose&&(console.warn("Lastname disclose is not in the original query"),s=false,t.lastname={...t.lastname,disclose:{expected:"Not requested in original query",received:`${e.lastname.disclose.result}`,message:"Lastname disclose is not in the original query"}});}return {isCorrect:s,queryResultErrors:t}}static checkAgePublicInputs(i,a,e){let t={},s=true,c=new Date;new Date(c.getFullYear(),c.getMonth(),c.getDate(),0,0,0,0);let p=getMinAgeFromCommittedInputs(i.committedInputs?.compare_age??i.committedInputs?.compare_age_evm),r=getMaxAgeFromCommittedInputs(i.committedInputs?.compare_age??i.committedInputs?.compare_age_evm);return e.age?(e.age.gte&&e.age.gte.result&&p!==e.age.gte.expected&&(console.warn("Age is not greater than or equal to the expected age"),s=false,t.age={...t.age,gte:{expected:e.age.gte.expected,received:p,message:"Age is not greater than or equal to the expected age"}}),e.age.gt&&e.age.gt.result&&p!==e.age.gt.expected+1&&(console.warn("Age is not greater than the expected age"),s=false,t.age={...t.age,gt:{expected:e.age.gt.expected,received:p,message:"Age is not greater than the expected age"}}),e.age.lt&&e.age.lt.result&&r!==e.age.lt.expected-1&&(console.warn("Age is not less than the expected age"),s=false,t.age={...t.age,lt:{expected:e.age.lt.expected,received:r,message:"Age is not less than the expected age"}}),e.age.lte&&e.age.lte.result&&r!==e.age.lte.expected&&(console.warn("Age is not less than or equal to the expected age"),s=false,t.age={...t.age,lte:{expected:e.age.lte.expected,received:r,message:"Age is not less than or equal to the expected age"}}),e.age.eq&&e.age.eq.result&&(p!==e.age.eq.expected||r!==e.age.eq.expected)&&(console.warn("Age does not match the expected age"),s=false,t.age={...t.age,eq:{expected:e.age.eq.expected,received:p!==e.age.eq.expected?p:r,message:"Age does not match the expected age"}}),e.age.range&&e.age.range.result&&(p!==e.age.range.expected[0]||r!==e.age.range.expected[1])&&(console.warn("Age is not in the expected range"),s=false,t.age={...t.age,range:{expected:e.age.range.expected,received:[p,r],message:"Age is not in the expected range"}}),!e.age.lt&&!e.age.lte&&!e.age.eq&&!e.age.range&&r!=0&&(console.warn("Maximum age should be equal to 0"),s=false,t.age={...t.age,disclose:{expected:0,received:r,message:"Maximum age should be equal to 0"}}),!e.age.gte&&!e.age.gt&&!e.age.eq&&!e.age.range&&p!=0&&(console.warn("Minimum age should be equal to 0"),s=false,t.age={...t.age,disclose:{expected:0,received:p,message:"Minimum age should be equal to 0"}}),e.age.disclose&&(e.age.disclose.result!==p||e.age.disclose.result!==r)&&(console.warn("Age does not match the disclosed age in query result"),s=false,t.age={...t.age,disclose:{expected:`${p}`,received:`${e.age.disclose.result}`,message:"Age does not match the disclosed age in query result"}})):(console.warn("Age is not set in the query result"),s=false,t.age={...t.age,disclose:{message:"Age is not set in the query result"}}),e.age?.gte&&(a.age?.gte===void 0||e.age.gte.expected!==a.age.gte)&&(console.warn("Age gte does not match the original query"),s=false,t.age={...t.age,gte:{expected:a.age?.gte,received:e.age.gte.expected,message:"Age gte does not match the original query"}}),e.age?.gt&&(a.age?.gt===void 0||e.age.gt.expected!==a.age.gt)&&(console.warn("Age gt does not match the original query"),s=false,t.age={...t.age,gt:{expected:a.age?.gt,received:e.age.gt.expected,message:"Age gt does not match the original query"}}),e.age?.lt&&(a.age?.lt===void 0||e.age.lt.expected!==a.age.lt)&&(console.warn("Age lt does not match the original query"),s=false,t.age={...t.age,lt:{expected:a.age?.lt,received:e.age.lt.expected,message:"Age lt does not match the original query"}}),e.age?.lte&&(a.age?.lte===void 0||e.age.lte.expected!==a.age.lte)&&(console.warn("Age lte does not match the original query"),s=false,t.age={...t.age,lte:{expected:a.age?.lte,received:e.age.lte.expected,message:"Age lte does not match the original query"}}),e.age?.eq&&(a.age?.eq===void 0||e.age.eq.expected!==a.age.eq)&&(console.warn("Age eq does not match the original query"),s=false,t.age={...t.age,eq:{expected:a.age?.eq,received:e.age.eq.expected,message:"Age eq does not match the original query"}}),e.age?.range&&(a.age?.range===void 0||e.age.range.expected[0]!==a.age.range[0]||e.age.range.expected[1]!==a.age.range[1])&&(console.warn("Age range does not match the original query"),s=false,t.age={...t.age,range:{expected:a.age?.range,received:e.age.range.expected,message:"Age range does not match the original query"}}),e.age?.disclose&&!a.age?.disclose&&(console.warn("Age disclose is not in the original query"),s=false,t.age={...t.age,disclose:{expected:"Not requested in original query",received:`${e.age.disclose.result}`,message:"Age disclose is not in the original query"}}),{isCorrect:s,queryResultErrors:t}}static checkBirthdatePublicInputs(i,a,e){let t={},s=true,c=new Date;new Date(c.getFullYear(),c.getMonth(),c.getDate(),0,0,0);let p=getBirthdateMinDateTimestamp(i.committedInputs?.compare_birthdate??i.committedInputs?.compare_birthdate_evm,-1*SECONDS_BETWEEN_1900_AND_1970),r=getBirthdateMaxDateTimestamp(i.committedInputs?.compare_birthdate??i.committedInputs?.compare_birthdate_evm,-1*SECONDS_BETWEEN_1900_AND_1970);if(e.birthdate){if(e.birthdate.gte&&e.birthdate.gte.result&&!areDatesEqual(p,e.birthdate.gte.expected)&&(console.warn("Birthdate is not greater than or equal to the expected birthdate"),s=false,t.birthdate={...t.birthdate,gte:{expected:e.birthdate.gte.expected,received:p,message:"Birthdate is not greater than or equal to the expected birthdate"}}),e.birthdate.gt&&e.birthdate.gt.result){let f=new Date(e.birthdate.gt.expected);f.setDate(f.getDate()+1),areDatesEqual(p,f)||(console.warn("Birthdate is not greater than the expected birthdate"),s=false,t.birthdate={...t.birthdate,gt:{expected:e.birthdate.gt.expected,received:p,message:"Birthdate is not greater than the expected birthdate"}});}if(e.birthdate.lte&&e.birthdate.lte.result&&!areDatesEqual(r,e.birthdate.lte.expected)&&(console.warn("Birthdate is not less than the expected birthdate"),s=false,t.birthdate={...t.birthdate,lte:{expected:e.birthdate.lte.expected,received:r,message:"Birthdate is not less than the expected birthdate"}}),e.birthdate.lt&&e.birthdate.lt.result){let f=new Date(e.birthdate.lt.expected);f.setDate(f.getDate()-1),areDatesEqual(r,f)||(console.warn("Birthdate is not less than the expected birthdate"),s=false,t.birthdate={...t.birthdate,lt:{expected:e.birthdate.lt.expected,received:r,message:"Birthdate is not less than the expected birthdate"}});}e.birthdate.range&&e.birthdate.range.result&&(!areDatesEqual(p,e.birthdate.range.expected[0])||!areDatesEqual(r,e.birthdate.range.expected[1]))&&(console.warn("Birthdate is not in the expected range"),s=false,t.birthdate={...t.birthdate,range:{expected:e.birthdate.range.expected,received:[p,r],message:"Birthdate is not in the expected range"}}),!e.birthdate.lte&&!e.birthdate.lt&&!e.birthdate.eq&&!e.birthdate.range&&!areDatesEqual(r,Y)&&(console.warn("Maximum birthdate should be equal to default date value"),s=false,t.birthdate={...t.birthdate,disclose:{expected:`${Y.toISOString()}`,received:`${r.toISOString()}`,message:"Maximum birthdate should be equal to default date value"}}),!e.birthdate.gte&&!e.birthdate.gt&&!e.birthdate.eq&&!e.birthdate.range&&!areDatesEqual(p,Y)&&(console.warn("Minimum birthdate should be equal to default date value"),s=false,t.birthdate={...t.birthdate,disclose:{expected:`${Y.toISOString()}`,received:`${p.toISOString()}`,message:"Minimum birthdate should be equal to default date value"}});}else console.warn("Birthdate is not set in the query result"),s=false,t.birthdate={...t.birthdate,disclose:{message:"Birthdate is not set in the query result"}};return e.birthdate?.gte&&(a.birthdate?.gte===void 0||!areDatesEqual(e.birthdate.gte.expected,a.birthdate.gte))&&(console.warn("Birthdate gte does not match the original query"),s=false,t.birthdate={...t.birthdate,gte:{expected:a.birthdate?.gte,received:e.birthdate.gte.expected,message:"Birthdate gte does not match the original query"}}),e.birthdate?.gt&&(a.birthdate?.gt===void 0||!areDatesEqual(e.birthdate.gt.expected,a.birthdate.gt))&&(console.warn("Birthdate gt does not match the original query"),s=false,t.birthdate={...t.birthdate,gt:{expected:a.birthdate?.gt,received:e.birthdate.gt.expected,message:"Birthdate gt does not match the original query"}}),e.birthdate?.lte&&(a.birthdate?.lte===void 0||!areDatesEqual(e.birthdate.lte.expected,a.birthdate.lte))&&(console.warn("Birthdate lte does not match the original query"),s=false,t.birthdate={...t.birthdate,lte:{expected:a.birthdate?.lte,received:e.birthdate.lte.expected,message:"Birthdate lte does not match the original query"}}),e.birthdate?.lt&&(a.birthdate?.lt===void 0||!areDatesEqual(e.birthdate.lt.expected,a.birthdate.lt))&&(console.warn("Birthdate lt does not match the original query"),s=false,t.birthdate={...t.birthdate,lt:{expected:a.birthdate?.lt,received:e.birthdate.lt.expected,message:"Birthdate lt does not match the original query"}}),e.birthdate?.range&&(a.birthdate?.range===void 0||!areDatesEqual(e.birthdate.range.expected[0],a.birthdate.range[0])||!areDatesEqual(e.birthdate.range.expected[1],a.birthdate.range[1]))&&(console.warn("Birthdate range does not match the original query"),s=false,t.birthdate={...t.birthdate,range:{expected:a.birthdate?.range,received:e.birthdate.range.expected,message:"Birthdate range does not match the original query"}}),{isCorrect:s,queryResultErrors:t}}static checkExpiryDatePublicInputs(i,a,e){let t={},s=true,c=new Date;new Date(c.getFullYear(),c.getMonth(),c.getDate(),0,0,0);let p=getMinDateFromCommittedInputs(i.committedInputs?.compare_expiry??i.committedInputs?.compare_expiry_evm),r=getMaxDateFromCommittedInputs(i.committedInputs?.compare_expiry??i.committedInputs?.compare_expiry_evm);return e.expiry_date?(e.expiry_date.gte&&e.expiry_date.gte.result&&!areDatesEqual(p,e.expiry_date.gte.expected)&&(console.warn("Expiry date is not greater than or equal to the expected expiry date"),s=false,t.expiry_date={...t.expiry_date,gte:{expected:e.expiry_date.gte.expected,received:p,message:"Expiry date is not greater than or equal to the expected expiry date"}}),e.expiry_date.lte&&e.expiry_date.lte.result&&!areDatesEqual(r,e.expiry_date.lte.expected)&&(console.warn("Expiry date is not less than the expected expiry date"),s=false,t.expiry_date={...t.expiry_date,lte:{expected:e.expiry_date.lte.expected,received:r,message:"Expiry date is not less than the expected expiry date"}}),e.expiry_date.range&&e.expiry_date.range.result&&(!areDatesEqual(p,e.expiry_date.range.expected[0])||!areDatesEqual(r,e.expiry_date.range.expected[1]))&&(console.warn("Expiry date is not in the expected range"),s=false,t.expiry_date={...t.expiry_date,range:{expected:e.expiry_date.range.expected,received:[p,r],message:"Expiry date is not in the expected range"}}),!e.expiry_date.lte&&!e.expiry_date.lt&&!e.expiry_date.eq&&!e.expiry_date.range&&!areDatesEqual(r,Y)&&(console.warn("Maximum expiry date should be equal to default date value"),s=false,t.expiry_date={...t.expiry_date,disclose:{expected:`${Y.toISOString()}`,received:`${r.toISOString()}`,message:"Maximum expiry date should be equal to default date value"}}),!e.expiry_date.gte&&!e.expiry_date.gt&&!e.expiry_date.eq&&!e.expiry_date.range&&!areDatesEqual(p,Y)&&(console.warn("Minimum expiry date should be equal to default date value"),s=false,t.expiry_date={...t.expiry_date,disclose:{expected:`${Y.toISOString()}`,received:`${p.toISOString()}`,message:"Minimum expiry date should be equal to default date value"}})):(console.warn("Expiry date is not set in the query result"),s=false,t.expiry_date={...t.expiry_date,disclose:{message:"Expiry date is not set in the query result"}}),e.expiry_date?.gte&&(a.expiry_date?.gte===void 0||!areDatesEqual(e.expiry_date.gte.expected,a.expiry_date.gte))&&(console.warn("Expiry date gte does not match the original query"),s=false,t.expiry_date={...t.expiry_date,gte:{expected:a.expiry_date?.gte,received:e.expiry_date.gte.expected,message:"Expiry date gte does not match the original query"}}),e.expiry_date?.gt&&(a.expiry_date?.gt===void 0||!areDatesEqual(e.expiry_date.gt.expected,a.expiry_date.gt))&&(console.warn("Expiry date gt does not match the original query"),s=false,t.expiry_date={...t.expiry_date,gt:{expected:a.expiry_date?.gt,received:e.expiry_date.gt.expected,message:"Expiry date gt does not match the original query"}}),e.expiry_date?.lte&&(a.expiry_date?.lte===void 0||!areDatesEqual(e.expiry_date.lte.expected,a.expiry_date.lte))&&(console.warn("Expiry date lte does not match the original query"),s=false,t.expiry_date={...t.expiry_date,lte:{expected:a.expiry_date?.lte,received:e.expiry_date.lte.expected,message:"Expiry date lte does not match the original query"}}),e.expiry_date?.lt&&(a.expiry_date?.lt===void 0||!areDatesEqual(e.expiry_date.lt.expected,a.expiry_date.lt))&&(console.warn("Expiry date lt does not match the original query"),s=false,t.expiry_date={...t.expiry_date,lt:{expected:a.expiry_date?.lt,received:e.expiry_date.lt.expected,message:"Expiry date lt does not match the original query"}}),e.expiry_date?.range&&(a.expiry_date?.range===void 0||!areDatesEqual(e.expiry_date.range.expected[0],a.expiry_date.range[0])||!areDatesEqual(e.expiry_date.range.expected[1],a.expiry_date.range[1]))&&(console.warn("Expiry date range does not match the original query"),s=false,t.expiry_date={...t.expiry_date,range:{expected:a.expiry_date?.range,received:e.expiry_date.range.expected,message:"Expiry date range does not match the original query"}}),{isCorrect:s,queryResultErrors:t}}static checkNationalityExclusionPublicInputs(i,a,e){let t={},s=true;a.nationality&&a.nationality.out&&a.nationality.out.result?a.nationality.out.expected?.every(c=>e.includes(c))||(console.warn("Nationality exclusion list does not match the one from the query results"),s=false,t.nationality={...t.nationality,out:{expected:a.nationality.out.expected,received:e,message:"Nationality exclusion list does not match the one from the query results"}}):(!a.nationality||!a.nationality.out)&&(console.warn("Nationality exclusion is not set in the query result"),s=false,t.nationality={...t.nationality,out:{message:"Nationality exclusion is not set in the query result"}});for(let c=1;c<e.length;c++)e[c]<e[c-1]&&(console.warn("The nationality exclusion list has not been sorted, and thus the proof cannot be trusted"),s=false,t.nationality={...t.nationality,out:{message:"The nationality exclusion list has not been sorted, and thus the proof cannot be trusted"}});return a.nationality?.out&&(i.nationality?.out===void 0||a.nationality.out.expected?.length!==i.nationality.out.length||!a.nationality.out.expected?.every(c=>i.nationality.out.includes(c)))&&(console.warn("Nationality exclusion list does not match the original query"),s=false,t.nationality={...t.nationality,out:{expected:i.nationality?.out,received:a.nationality.out.expected,message:"Nationality exclusion list does not match the original query"}}),{isCorrect:s,queryResultErrors:t}}static checkIssuingCountryExclusionPublicInputs(i,a,e){let t={},s=true;a.issuing_country&&a.issuing_country.out&&a.issuing_country.out.result?a.issuing_country.out.expected?.every(c=>e.includes(c))||(console.warn("Issuing country exclusion list does not match the one from the query results"),s=false,t.issuing_country={...t.issuing_country,out:{expected:a.issuing_country.out.expected,received:e,message:"Issuing country exclusion list does not match the one from the query results"}}):(!a.issuing_country||!a.issuing_country.out)&&(console.warn("Issuing country exclusion is not set in the query result"),s=false,t.issuing_country={...t.issuing_country,out:{message:"Issuing country exclusion is not set in the query result"}});for(let c=1;c<e.length;c++)e[c]<e[c-1]&&(console.warn("The issuing country exclusion list has not been sorted, and thus the proof cannot be trusted"),s=false,t.issuing_country={...t.issuing_country,out:{message:"The issuing country exclusion list has not been sorted, and thus the proof cannot be trusted"}});return a.issuing_country?.out&&(i.issuing_country?.out===void 0||a.issuing_country.out.expected?.length!==i.issuing_country.out.length||!a.issuing_country.out.expected?.every(c=>i.issuing_country.out.includes(c)))&&(console.warn("Issuing country exclusion list does not match the original query"),s=false,t.issuing_country={...t.issuing_country,out:{expected:i.issuing_country?.out,received:a.issuing_country.out.expected,message:"Issuing country exclusion list does not match the original query"}}),{isCorrect:s,queryResultErrors:t}}static checkNationalityInclusionPublicInputs(i,a,e){let t={},s=true;return a.nationality&&a.nationality.in&&a.nationality.in.result?a.nationality.in.expected?.every(c=>e.includes(c))||(console.warn("Nationality inclusion list does not match the one from the query results"),s=false,t.nationality={...t.nationality,in:{expected:a.nationality.in.expected,received:e,message:"Nationality inclusion list does not match the one from the query results"}}):(!a.nationality||!a.nationality.in)&&(console.warn("Nationality inclusion is not set in the query result"),s=false,t.nationality={...t.nationality,in:{message:"Nationality inclusion is not set in the query result"}}),a.nationality?.in&&(i.nationality?.in===void 0||a.nationality.in.expected?.length!==i.nationality.in.length||!a.nationality.in.expected?.every(c=>i.nationality.in.includes(c)))&&(console.warn("Nationality inclusion list does not match the original query"),s=false,t.nationality={...t.nationality,in:{expected:i.nationality?.in,received:a.nationality.in.expected,message:"Nationality inclusion list does not match the original query"}}),{isCorrect:s,queryResultErrors:t}}static checkIssuingCountryInclusionPublicInputs(i,a,e){let t={},s=true;return a.issuing_country&&a.issuing_country.in&&a.issuing_country.in.result?a.issuing_country.in.expected?.every(c=>e.includes(c))||(console.warn("Issuing country inclusion list does not match the one from the query results"),s=false,t.issuing_country={...t.issuing_country,in:{expected:a.issuing_country.in.expected,received:e,message:"Issuing country inclusion list does not match the one from the query results"}}):(!a.issuing_country||!a.issuing_country.in)&&(console.warn("Issuing country inclusion is not set in the query result"),s=false,t.issuing_country={...t.issuing_country,in:{message:"Issuing country inclusion is not set in the query result"}}),a.issuing_country?.in&&(i.issuing_country?.in===void 0||a.issuing_country.in.expected?.length!==i.issuing_country.in.length||!a.issuing_country.in.expected?.every(c=>i.issuing_country.in.includes(c)))&&(console.warn("Issuing country inclusion list does not match the original query"),s=false,t.issuing_country={...t.issuing_country,in:{expected:i.issuing_country?.in,received:a.issuing_country.in.expected,message:"Issuing country inclusion list does not match the original query"}}),{isCorrect:s,queryResultErrors:t}}static checkScopeFromDisclosureProof(i,a,e,t,s){let c=true;return i&&getServiceScopeHash(i)!==getServiceScopeFromDisclosureProof(a)&&(console.warn("The proof comes from a different domain than the one expected"),c=false,e[t]||(e[t]={}),e[t].scope={expected:`Scope: ${getServiceScopeHash(i).toString()}`,received:`Scope: ${BigInt(a.publicInputs[1]).toString()}`,message:"The proof comes from a different domain than the one expected"}),s&&getScopeHash(s)!==getServiceSubScopeFromDisclosureProof(a)&&(console.warn("The proof uses a different scope than the one expected"),c=false,e[t]||(e[t]={}),e[t].scope={expected:`Scope: ${getScopeHash(s).toString()}`,received:`Scope: ${BigInt(a.publicInputs[2]).toString()}`,message:"The proof uses a different scope than the one expected"}),{isCorrect:c,queryResultErrors:e}}static async checkCertificateRegistryRoot(i,a,e,t){let s=true;try{await new RegistryClient({chainId:t?11155111:1}).isCertificateRootValid(i)||(console.warn("The ID was signed by an unrecognized root certificate"),s=!1,a[e?"outer":"sig_check_dsc"]||(a[e?"outer":"sig_check_dsc"]={}),a[e?"outer":"sig_check_dsc"].certificate={expected:"A valid root from ZKPassport Registry",received:`Got invalid certificate registry root: ${i}`,message:"The ID was signed by an unrecognized root certificate"});}catch(c){console.warn(c),console.warn("The ID was signed by an unrecognized root certificate"),s=false,a[e?"outer":"sig_check_dsc"]||(a[e?"outer":"sig_check_dsc"]={}),a[e?"outer":"sig_check_dsc"].certificate={expected:"A valid root from ZKPassport Registry",received:`Got invalid certificate registry root: ${i}`,message:"The ID was signed by an unrecognized root certificate"};}return {isCorrect:s,queryResultErrors:a}}static async checkCircuitRegistryRoot(i,a,e){let t=true;try{await new RegistryClient({chainId:e?11155111:1}).isCircuitRootValid(i)||(console.warn("The proof uses unrecognized circuits"),t=!1,a.outer||(a.outer={}),a.outer.circuit={expected:"A valid circuit from ZKPassport Registry",received:`Got invalid circuit registry root: ${i}`,message:"The proof uses an unrecognized circuit"});}catch(s){console.warn(s),console.warn("The proof uses unrecognized circuits"),t=false,a.outer||(a.outer={}),a.outer.circuit={expected:"A valid circuit from ZKPassport Registry",received:`Got invalid circuit registry root: ${i}`,message:"The proof uses an unrecognized circuit"};}return {isCorrect:t,queryResultErrors:a}}static checkBindPublicInputs(i,a,e){let t={},s=true;if(a.bind){let c=[];a.bind.user_address?.toLowerCase().replace("0x","")!==e.user_address?.toLowerCase().replace("0x","")&&(console.warn("Bound user address does not match the one from the query results"),s=false,c.push(`user_address: expected ${a.bind.user_address}, received ${e.user_address}`)),a.bind.chain!==e.chain&&(console.warn("Bound chain id does not match the one from the query results"),s=false,c.push(`chain: expected ${a.bind.chain}, received ${e.chain}`)),a.bind.custom_data?.trim().toLowerCase()!==e.custom_data?.trim().toLowerCase()&&(console.warn("Bound custom data does not match the one from the query results"),s=false,c.push(`custom_data: expected ${a.bind.custom_data}, received ${e.custom_data}`)),c.length>0&&(t.bind={...t.bind,eq:{expected:`${a.bind.user_address}, ${a.bind.chain}, ${a.bind.custom_data}`,received:`${e.user_address}, ${e.chain}, ${e.custom_data}`,message:`Bound data does not match: ${c.join("; ")}`}});}return a.bind&&(i.bind===void 0||a.bind.user_address?.toLowerCase().replace("0x","")!==i.bind.user_address?.toLowerCase().replace("0x","")||a.bind.chain!==i.bind.chain||a.bind.custom_data?.trim().toLowerCase()!==i.bind.custom_data?.trim().toLowerCase())&&(console.warn("Bound data does not match the original query"),s=false,t.bind={...t.bind,eq:{expected:`${i.bind?.user_address}, ${i.bind?.chain}, ${i.bind?.custom_data}`,received:`${a.bind.user_address}, ${a.bind.chain}, ${a.bind.custom_data}`,message:"Bound data does not match the original query"}}),{isCorrect:s,queryResultErrors:t}}static async checkSanctionsExclusionPublicInputs(i,a,e,t){let s={},c=true;if(a.sanctions&&a.sanctions.passed){let h=await t.getRoot();e.rootHash!==h&&(console.warn("Invalid sanctions registry root"),c=false,s.sanctions={...s.sanctions,eq:{expected:h,received:e.rootHash,message:"Invalid sanctions registry root"}}),a.sanctions.isStrict!==e.isStrict&&(console.warn("Invalid sanctions strict mode"),c=false,s.sanctions={...s.sanctions,eq:{expected:a.sanctions.isStrict.toString(),received:e.isStrict.toString(),message:"Invalid sanctions strict mode"}});}return a.sanctions&&(i.sanctions===void 0||a.sanctions.isStrict!==(i.sanctions.strict??false))&&(console.warn("Sanctions config does not match the original query"),c=false,s.sanctions={...s.sanctions,eq:{expected:`strict: ${i.sanctions?.strict??false}`,received:`strict: ${a.sanctions.isStrict}`,message:"Sanctions config does not match the original query"}}),{isCorrect:c,queryResultErrors:s}}static async checkFacematchPublicInputs(i,a,e){let t=true,s={};if(a.facematch&&a.facematch.passed){e.rootKeyLeaf!==ce&&e.rootKeyLeaf!==fe&&e.rootKeyLeaf!==me&&(console.warn("Invalid facematch root key hash"),t=false,s.facematch={...s.facematch,eq:{expected:`${ce} (iOS) or ${fe} (Android) or ${me} (Android)`,received:e.rootKeyLeaf,message:"Invalid facematch root key hash"}});let c="production";e.environment!==c&&(console.warn("Invalid facematch environment, it should be production"),t=false,s.facematch={...s.facematch,eq:{expected:c,received:e.environment,message:"Invalid facematch environment, it should be production"}}),e.appIdHash!==re&&e.appIdHash!==de&&(console.warn("Invalid facematch app id hash, the attestation should be coming from the ZKPassport app"),t=false,s.facematch={...s.facematch,eq:{expected:`${re} (iOS) or ${de} (Android)`,received:e.appIdHash,message:"Invalid facematch app id hash, the attestation should be coming from the ZKPassport app"}}),(e.mode!==a.facematch?.mode||e.mode!==i.facematch?.mode)&&(console.warn("Invalid facematch mode"),t=false,s.facematch={...s.facematch,eq:{expected:i.facematch?.mode,received:e.mode,message:"Invalid facematch mode"}});}return {isCorrect:t,queryResultErrors:s}}static async checkCurrentDate(i,a,e,t){let s=new Date,c=new Date(s.getFullYear(),s.getMonth(),s.getDate(),0,0,0,0),h=getCurrentDateFromDisclosureProof(a),p=c.getTime()-h.getTime(),r=e?e*1e3:604800*1e3,f=true;return p>=r&&(console.warn("The date used to check the validity of the ID falls out of the validity period"),f=false,t[i]||(t[i]={}),t[i].date={expected:`Difference: ${e} seconds`,received:`Difference: ${Math.round(p/1e3)} seconds`,message:"The date used to check the validity of the ID falls out of the validity period"}),{isCorrect:f,queryResultErrors:t}}static async checkPublicInputs(i,a,e,t,s,c,h,p){let r,f,o=true,$,P,N=new Date,B=new Date(N.getFullYear(),N.getMonth(),N.getDate(),0,0,0,0),n={},A=a.sort((b,d)=>{let m=["sig_check_dsc","sig_check_id_data","data_check_integrity","disclose_bytes","compare_age","compare_birthdate","compare_expiry","exclusion_check_nationality","inclusion_check_nationality","exclusion_check_issuing_country","inclusion_check_issuing_country","bind","exclusion_check_sanctions","facematch"],l=u=>{let v=u.name||"";return m.findIndex(x=>v.startsWith(x))};return l(b)-l(d)});for(let b of A){let d=getProofData(b.proof,getNumberOfPublicInputs(b.name));if(b.name?.startsWith("outer")){let m=b.name?.startsWith("outer_evm"),l=getCertificateRegistryRootFromOuterProof(d),{isCorrect:u,queryResultErrors:v}=await this.checkCertificateRegistryRoot(l.toString(16),n,true,p);o=o&&u,n={...n,...v};let x=getCircuitRegistryRootFromOuterProof(d),{isCorrect:_,queryResultErrors:I}=await this.checkCircuitRegistryRoot(x.toString(16),n,p);o=o&&_,n={...n,...I};let S=getCurrentDateFromOuterProof(d),D=B.getTime()-S.getTime(),j=s?s*1e3:604800*1e3;D>=j&&(console.warn("The date used to check the validity of the ID is older than the validity period"),o=false,n.outer={...n.outer,date:{expected:`Difference: ${s} seconds`,received:`Difference: ${Math.round(D/1e3)} seconds`,message:"The date used to check the validity of the ID is older than the validity period"}});let w=getParamCommitmentsFromOuterProof(d),g=b.committedInputs,Q=Object.keys(g||{});if(Q.length!==w.length&&(console.warn("The proof does not verify all the requested conditions and information"),o=false,n.outer={...n.outer,commitment:{expected:`Number of parameter commitments: ${w.length}`,received:`Number of disclosure proofs provided: ${Q.length}`,message:"The proof does not verify all the requested conditions and information"}}),i&&getServiceScopeHash(i)!==getScopeFromOuterProof(d)&&(console.warn("The proof comes from a different domain than the one expected"),o=false,n.outer={...n.outer,scope:{expected:`Scope: ${getServiceScopeHash(i).toString()}`,received:`Scope: ${getScopeFromOuterProof(d).toString()}`,message:"The proof comes from a different domain than the one expected"}}),c&&getScopeHash(c)!==getSubscopeFromOuterProof(d)&&(console.warn("The proof uses a different scope than the one expected"),o=false,n.outer={...n.outer,scope:{expected:`Scope: ${getScopeHash(c).toString()}`,received:`Scope: ${getSubscopeFromOuterProof(d).toString()}`,message:"The proof uses a different scope than the one expected"}}),g?.compare_age||g?.compare_age_evm){let y=g?.compare_age??g?.compare_age_evm,T=m?await getAgeEVMParameterCommitment(y.minAge,y.maxAge):await getAgeParameterCommitment(y.minAge,y.maxAge);w.includes(T)||(console.warn("This proof does not verify the age"),o=false,n.age={...n.age,commitment:{expected:`Age parameter commitment: ${T.toString()}`,received:`Parameter commitments included: ${w.join(", ")}`,message:"This proof does not verify the age"}});let{isCorrect:k,queryResultErrors:E}=this.checkAgePublicInputs(b,e,t);o=o&&k,n={...n,...E};}if(g?.compare_birthdate||g?.compare_birthdate_evm){let y=g?.compare_birthdate??g?.compare_birthdate_evm,T=m?await getDateEVMParameterCommitment(ProofType.BIRTHDATE,y.minDateTimestamp,y.maxDateTimestamp,0):await getDateParameterCommitment(ProofType.BIRTHDATE,y.minDateTimestamp,y.maxDateTimestamp,0);w.includes(T)||(console.warn("This proof does not verify the birthdate"),o=false,n.birthdate={...n.birthdate,commitment:{expected:`Birthdate parameter commitment: ${T.toString()}`,received:`Parameter commitments included: ${w.join(", ")}`,message:"This proof does not verify the birthdate"}});let{isCorrect:k,queryResultErrors:E}=this.checkBirthdatePublicInputs(b,e,t);o=o&&k,n={...n,...E};}if(g?.compare_expiry||g?.compare_expiry_evm){let y=g?.compare_expiry??g?.compare_expiry_evm,T=m?await getDateEVMParameterCommitment(ProofType.EXPIRY_DATE,y.minDateTimestamp,y.maxDateTimestamp):await getDateParameterCommitment(ProofType.EXPIRY_DATE,y.minDateTimestamp,y.maxDateTimestamp);w.includes(T)||(console.warn("This proof does not verify the expiry date"),o=false,n.expiry_date={...n.expiry_date,commitment:{expected:`Expiry date parameter commitment: ${T.toString()}`,received:`Parameter commitments included: ${w.join(", ")}`,message:"This proof does not verify the expiry date"}});let{isCorrect:k,queryResultErrors:E}=this.checkExpiryDatePublicInputs(b,e,t);o=o&&k,n={...n,...E};}if(g?.disclose_bytes||g?.disclose_bytes_evm){let y=g?.disclose_bytes??g?.disclose_bytes_evm,T=m?await getDiscloseEVMParameterCommitment(y.discloseMask,y.disclosedBytes):await getDiscloseParameterCommitment(y.discloseMask,y.disclosedBytes);w.includes(T)||(console.warn("This proof does not verify any of the data disclosed"),o=false,n.disclose={...n.disclose,commitment:{expected:`Disclosure parameter commitment: ${T.toString()}`,received:`Parameter commitments included: ${w.join(", ")}`,message:"This proof does not verify any of the data disclosed"}});let{isCorrect:k,queryResultErrors:E}=this.checkDiscloseBytesPublicInputs(b,e,t);o=o&&k,n={...n,...E};}if(g?.inclusion_check_nationality||g?.inclusion_check_nationality_evm){let y=g?.inclusion_check_nationality??g?.inclusion_check_nationality_evm,T=m?await getCountryEVMParameterCommitment(ProofType.NATIONALITY_INCLUSION,y.countries):await getCountryParameterCommitment(ProofType.NATIONALITY_INCLUSION,y.countries);w.includes(T)||(console.warn("This proof does not verify the inclusion of the nationality"),o=false,n.nationality={...n.nationality,commitment:{expected:`Nationality parameter commitment: ${T.toString()}`,received:`Parameter commitments included: ${w.join(", ")}`,message:"This proof does not verify the inclusion of the nationality"}});let k=y.countries,{isCorrect:E,queryResultErrors:q}=this.checkNationalityInclusionPublicInputs(e,t,k);o=o&&E,n={...n,...q};}if(g?.inclusion_check_issuing_country||g?.inclusion_check_issuing_country_evm){let y=g?.inclusion_check_issuing_country??g?.inclusion_check_issuing_country_evm,T=m?await getCountryEVMParameterCommitment(ProofType.ISSUING_COUNTRY_INCLUSION,y.countries):await getCountryParameterCommitment(ProofType.ISSUING_COUNTRY_INCLUSION,y.countries);w.includes(T)||(console.warn("This proof does not verify the inclusion of the issuing country"),o=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Issuing country parameter commitment: ${T.toString()}`,received:`Parameter commitments included: ${w.join(", ")}`,message:"This proof does not verify the inclusion of the issuing country"}});let k=y.countries,{isCorrect:E,queryResultErrors:q}=this.checkIssuingCountryInclusionPublicInputs(e,t,k);o=o&&E,n={...n,...q};}if(g?.exclusion_check_nationality||g?.exclusion_check_nationality_evm){let y=g?.exclusion_check_nationality??g?.exclusion_check_nationality_evm,T=m?await getCountryEVMParameterCommitment(ProofType.NATIONALITY_EXCLUSION,y.countries):await getCountryParameterCommitment(ProofType.NATIONALITY_EXCLUSION,y.countries);w.includes(T)||(console.warn("This proof does not verify the exclusion of the nationality"),o=false,n.nationality={...n.nationality,commitment:{expected:`Nationality parameter commitment: ${T.toString()}`,received:`Parameter commitments included: ${w.join(", ")}`,message:"This proof does not verify the exclusion of the nationality"}});let k=y.countries,{isCorrect:E,queryResultErrors:q}=this.checkNationalityExclusionPublicInputs(e,t,k);o=o&&E,n={...n,...q};}if(g?.exclusion_check_issuing_country||g?.exclusion_check_issuing_country_evm){let y=g?.exclusion_check_issuing_country??g?.exclusion_check_issuing_country_evm,T=m?await getCountryEVMParameterCommitment(ProofType.ISSUING_COUNTRY_EXCLUSION,y.countries):await getCountryParameterCommitment(ProofType.ISSUING_COUNTRY_EXCLUSION,y.countries);w.includes(T)||(console.warn("This proof does not verify the exclusion of the issuing country"),o=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Issuing country parameter commitment: ${T.toString()}`,received:`Parameter commitments included: ${w.join(", ")}`,message:"This proof does not verify the exclusion of the issuing country"}});let k=y.countries,{isCorrect:E,queryResultErrors:q}=this.checkIssuingCountryExclusionPublicInputs(e,t,k);o=o&&E,n={...n,...q};}if(g?.bind||g?.bind_evm){let y=g?.bind??g?.bind_evm,T=m?await getBindEVMParameterCommitment(formatBoundData(y.data)):await getBindParameterCommitment(formatBoundData(y.data));w.includes(T)||(console.warn("This proof does not verify the bound data"),o=false,n.bind={...n.bind,commitment:{expected:`Bind parameter commitment: ${T.toString()}`,received:`Parameter commitments included: ${w.join(", ")}`,message:"This proof does not verify the bound data"}});let{isCorrect:k,queryResultErrors:E}=this.checkBindPublicInputs(e,t,y.data);o=o&&k,n={...n,...E};}if(g?.exclusion_check_sanctions||g?.exclusion_check_sanctions_evm){let y=await SanctionsBuilder.create(),T=g?.exclusion_check_sanctions??g?.exclusion_check_sanctions_evm,k=m?await y.getSanctionsEvmParameterCommitment(T.isStrict):await y.getSanctionsParameterCommitment(T.isStrict);w.includes(k)||(console.warn("This proof does not verify the exclusion from the sanction lists"),o=false,n.sanctions={...n.sanctions,commitment:{expected:`Sanctions parameter commitment: ${k.toString()}`,received:`Parameter commitments included: ${w.join(", ")}`,message:"This proof does not verify the exclusion from the sanction lists"}});let{isCorrect:E,queryResultErrors:q}=await this.checkSanctionsExclusionPublicInputs(e,t,T,y);o=o&&E,n={...n,...q};}if(g?.facematch||g?.facematch_evm){let y=g?.facematch??g?.facematch_evm,T=m?await getFacematchEvmParameterCommitment(BigInt(y.rootKeyLeaf),y.environment==="development"?0n:1n,BigInt(y.appIdHash),y.mode==="regular"?1n:2n):await getFacematchParameterCommitment(BigInt(y.rootKeyLeaf),y.environment==="development"?0n:1n,BigInt(y.appIdHash),y.mode==="regular"?1n:2n);w.includes(T)||(console.warn("This proof does not verify FaceMatch"),o=false,n.facematch={...n.facematch,commitment:{expected:`Facematch parameter commitment: ${T.toString()}`,received:`Parameter commitments included: ${w.join(", ")}`,message:"This proof does not verify FaceMatch"}});let{isCorrect:k,queryResultErrors:E}=await this.checkFacematchPublicInputs(e,t,y);o=o&&k,n={...n,...E};}$=getNullifierFromOuterProof(d).toString(10),P=getNullifierTypeFromOuterProof(d);}else if(b.name?.startsWith("sig_check_dsc")){f=getCommitmentFromDSCProof(d);let m=getMerkleRootFromDSCProof(d),{isCorrect:l,queryResultErrors:u}=await this.checkCertificateRegistryRoot(m.toString(16),n,false,p);o=o&&l,n={...n,...u};}else if(b.name?.startsWith("sig_check_id_data"))r=getCommitmentInFromIDDataProof(d),r!==f&&(console.warn("Failed to check the link between the certificate signature and ID signature"),o=false,n.sig_check_id_data={...n.sig_check_id_data,commitment:{expected:`Commitment: ${f?.toString()||"undefined"}`,received:`Commitment: ${r?.toString()||"undefined"}`,message:"Failed to check the link between the certificate signature and ID signature"}}),f=getCommitmentOutFromIDDataProof(d);else if(b.name?.startsWith("data_check_integrity"))r=getCommitmentInFromIntegrityProof(d),r!==f&&(console.warn("Failed to check the link between the ID signature and the data signed"),o=false,n.data_check_integrity={...n.data_check_integrity,commitment:{expected:`Commitment: ${f?.toString()||"undefined"}`,received:`Commitment: ${r?.toString()||"undefined"}`,message:"Failed to check the link between the ID signature and the data signed"}}),f=getCommitmentOutFromIntegrityProof(d);else if(b.name==="disclose_bytes"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the data to disclose"),o=false,n.disclose={...n.disclose,commitment:{expected:`Commitment: ${f?.toString()||"undefined"}`,received:`Commitment: ${r?.toString()||"undefined"}`,message:"Failed to check the link between the validity of the ID and the data to disclose"}});let m=getParameterCommitmentFromDisclosureProof(d),l=await getDiscloseParameterCommitment((b.committedInputs?.disclose_bytes).discloseMask,(b.committedInputs?.disclose_bytes).disclosedBytes);m!==l&&(console.warn("The disclosed data does not match the data committed by the proof"),o=false,n.disclose={...n.disclose,commitment:{expected:`Commitment: ${l}`,received:`Commitment: ${m}`,message:"The disclosed data does not match the data committed by the proof"}});let{isCorrect:u,queryResultErrors:v}=this.checkScopeFromDisclosureProof(i,d,n,"disclose",c);o=o&&u,n={...n,...v};let{isCorrect:x,queryResultErrors:_}=this.checkDiscloseBytesPublicInputs(b,e,t);o=o&&x&&u,n={...n,..._,...v};let{isCorrect:I,queryResultErrors:S}=await this.checkCurrentDate("disclose",d,s??604800,n);o=o&&I,n={...n,...S},$=getNullifierFromDisclosureProof(d).toString(10),P=getNullifierTypeFromDisclosureProof(d);}else if(b.name==="compare_age"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the age derived from it"),o=false,n.age={...n.age,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the age derived from it"}});let m=getParameterCommitmentFromDisclosureProof(d),l=b.committedInputs?.compare_age,u=await getAgeParameterCommitment(l.minAge,l.maxAge);m!==u&&(console.warn("The conditions for the age check do not match the conditions checked by the proof"),o=false,n.age={...n.age,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${m}`,message:"The conditions for the age check do not match the conditions checked by the proof"}});let{isCorrect:v,queryResultErrors:x}=this.checkScopeFromDisclosureProof(i,d,n,"age",c),{isCorrect:_,queryResultErrors:I}=this.checkAgePublicInputs(b,e,t);o=o&&_&&v,n={...n,...I,...x};let{isCorrect:S,queryResultErrors:D}=await this.checkCurrentDate("age",d,s??604800,n);o=o&&S,n={...n,...D},$=getNullifierFromDisclosureProof(d).toString(10),P=getNullifierTypeFromDisclosureProof(d);}else if(b.name==="compare_birthdate"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the birthdate derived from it"),o=false,n.birthdate={...n.birthdate,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the birthdate derived from it"}});let m=getParameterCommitmentFromDisclosureProof(d),l=b.committedInputs?.compare_birthdate,u=await getDateParameterCommitment(ProofType.BIRTHDATE,l.minDateTimestamp,l.maxDateTimestamp,0);m!==u&&(console.warn("The conditions for the birthdate check do not match the conditions checked by the proof"),o=false,n.birthdate={...n.birthdate,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${m}`,message:"The conditions for the birthdate check do not match the conditions checked by the proof"}});let{isCorrect:v,queryResultErrors:x}=this.checkScopeFromDisclosureProof(i,d,n,"birthdate",c),{isCorrect:_,queryResultErrors:I}=this.checkBirthdatePublicInputs(b,e,t);o=o&&_&&v,n={...n,...I,...x};let{isCorrect:S,queryResultErrors:D}=await this.checkCurrentDate("birthdate",d,s??604800,n);o=o&&S,n={...n,...D},$=getNullifierFromDisclosureProof(d).toString(10),P=getNullifierTypeFromDisclosureProof(d);}else if(b.name==="compare_expiry"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and its expiry date"),o=false,n.expiry_date={...n.expiry_date,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and its expiry date"}});let m=getParameterCommitmentFromDisclosureProof(d),l=b.committedInputs?.compare_expiry,u=await getDateParameterCommitment(ProofType.EXPIRY_DATE,l.minDateTimestamp,l.maxDateTimestamp);m!==u&&(console.warn("The conditions for the expiry date check do not match the conditions checked by the proof"),o=false,n.expiry_date={...n.expiry_date,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${m}`,message:"The conditions for the expiry date check do not match the conditions checked by the proof"}});let{isCorrect:v,queryResultErrors:x}=this.checkScopeFromDisclosureProof(i,d,n,"expiry_date",c),{isCorrect:_,queryResultErrors:I}=this.checkExpiryDatePublicInputs(b,e,t);o=o&&_&&v,n={...n,...I,...x};let{isCorrect:S,queryResultErrors:D}=await this.checkCurrentDate("expiry_date",d,s??604800,n);o=o&&S,n={...n,...D},$=getNullifierFromDisclosureProof(d).toString(10),P=getNullifierTypeFromDisclosureProof(d);}else if(b.name==="exclusion_check_nationality"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the nationality exclusion check"),o=false,n.nationality={...n.nationality,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the nationality exclusion check"}});let m=(b.committedInputs?.exclusion_check_nationality).countries,l=getParameterCommitmentFromDisclosureProof(d),u=await getCountryParameterCommitment(ProofType.NATIONALITY_EXCLUSION,m,true);l!==u&&(console.warn("The committed country list for the exclusion check does not match the one from the proof"),o=false,n.nationality={...n.nationality,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${l}`,message:"The committed country list for the exclusion check does not match the one from the proof"}});let{isCorrect:v,queryResultErrors:x}=this.checkScopeFromDisclosureProof(i,d,n,"nationality",c),{isCorrect:_,queryResultErrors:I}=this.checkNationalityExclusionPublicInputs(e,t,m);o=o&&_&&v,n={...n,...I,...x};let{isCorrect:S,queryResultErrors:D}=await this.checkCurrentDate("nationality",d,s??604800,n);o=o&&S,n={...n,...D},$=getNullifierFromDisclosureProof(d).toString(10),P=getNullifierTypeFromDisclosureProof(d);}else if(b.name==="exclusion_check_issuing_country"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the issuing country exclusion check"),o=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the issuing country exclusion check"}});let m=(b.committedInputs?.exclusion_check_issuing_country).countries,l=getParameterCommitmentFromDisclosureProof(d),u=await getCountryParameterCommitment(ProofType.ISSUING_COUNTRY_EXCLUSION,m,true);l!==u&&(console.warn("The committed country list for the issuing country exclusion check does not match the one from the proof"),o=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${l}`,message:"The committed country list for the issuing country exclusion check does not match the one from the proof"}});let{isCorrect:v,queryResultErrors:x}=this.checkScopeFromDisclosureProof(i,d,n,"issuing_country",c),{isCorrect:_,queryResultErrors:I}=this.checkIssuingCountryExclusionPublicInputs(e,t,m);o=o&&_&&v,n={...n,...I,...x};let{isCorrect:S,queryResultErrors:D}=await this.checkCurrentDate("issuing_country",d,s??604800,n);o=o&&S,n={...n,...D},$=getNullifierFromDisclosureProof(d).toString(10),P=getNullifierTypeFromDisclosureProof(d);}else if(b.name==="inclusion_check_nationality"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the nationality inclusion check"),o=false,n.nationality={...n.nationality,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the nationality inclusion check"}});let m=(b.committedInputs?.inclusion_check_nationality).countries,l=getParameterCommitmentFromDisclosureProof(d),u=await getCountryParameterCommitment(ProofType.NATIONALITY_INCLUSION,m,false);l!==u&&(console.warn("The committed country list for the nationality inclusion check does not match the one from the proof"),o=false,n.nationality={...n.nationality,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${l}`,message:"The committed country list for the nationality inclusion check does not match the one from the proof"}});let{isCorrect:v,queryResultErrors:x}=this.checkScopeFromDisclosureProof(i,d,n,"nationality",c),{isCorrect:_,queryResultErrors:I}=this.checkNationalityInclusionPublicInputs(e,t,m);o=o&&_&&v,n={...n,...I,...x};let{isCorrect:S,queryResultErrors:D}=await this.checkCurrentDate("nationality",d,s??604800,n);o=o&&S,n={...n,...D},$=getNullifierFromDisclosureProof(d).toString(10),P=getNullifierTypeFromDisclosureProof(d);}else if(b.name==="inclusion_check_issuing_country"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the issuing country inclusion check"),o=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the issuing country inclusion check"}});let m=(b.committedInputs?.inclusion_check_issuing_country).countries,l=getParameterCommitmentFromDisclosureProof(d),u=await getCountryParameterCommitment(ProofType.ISSUING_COUNTRY_INCLUSION,m,false);l!==u&&(console.warn("The committed country list for the issuing country inclusion check does not match the one from the proof"),o=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${l}`,message:"The committed country list for the issuing country inclusion check does not match the one from the proof"}});let{isCorrect:v,queryResultErrors:x}=this.checkScopeFromDisclosureProof(i,d,n,"issuing_country",c),{isCorrect:_,queryResultErrors:I}=this.checkIssuingCountryInclusionPublicInputs(e,t,m);o=o&&_&&v,n={...n,...I,...x};let{isCorrect:S,queryResultErrors:D}=await this.checkCurrentDate("issuing_country",d,s??604800,n);o=o&&S,n={...n,...D},$=getNullifierFromDisclosureProof(d).toString(10),P=getNullifierTypeFromDisclosureProof(d);}else if(b.name==="bind"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the bound data"),o=false,n.bind={...n.bind,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the bound data"}});let m=b.committedInputs?.bind,l=getParameterCommitmentFromDisclosureProof(d),u=await getBindParameterCommitment(formatBoundData(m.data));l!==u&&(console.warn("The bound data does not match the one from the proof"),o=false,n.bind={...n.bind,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${l}`,message:"The bound data does not match the one from the proof"}});let{isCorrect:v,queryResultErrors:x}=this.checkScopeFromDisclosureProof(i,d,n,"bind",c),{isCorrect:_,queryResultErrors:I}=this.checkBindPublicInputs(e,t,m.data);o=o&&_&&v,n={...n,...I,...x};let{isCorrect:S,queryResultErrors:D}=await this.checkCurrentDate("bind",d,s??604800,n);o=o&&S,n={...n,...D},$=getNullifierFromDisclosureProof(d).toString(10),P=getNullifierTypeFromDisclosureProof(d);}else if(b.name==="exclusion_check_sanctions"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the sanctions exclusion check"),o=false,n.sanctions={...n.sanctions,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the sanctions exclusion check"}});let m=await SanctionsBuilder.create(),l=b.committedInputs?.exclusion_check_sanctions,u=await m.getSanctionsParameterCommitment(l.isStrict),v=getParameterCommitmentFromDisclosureProof(d);v!==u&&(console.warn("The sanction lists check against do not match the sanction lists from the proof"),o=false,n.sanctions={...n.sanctions,commitment:{expected:`Commitment: ${u.toString()}`,received:`Commitment: ${v.toString()}`,message:"The sanction lists check against do not match the sanction lists from the proof"}});let{isCorrect:x,queryResultErrors:_}=this.checkScopeFromDisclosureProof(i,d,n,"sanctions",c),{isCorrect:I,queryResultErrors:S}=await this.checkSanctionsExclusionPublicInputs(e,t,l,m);o=o&&I&&x,n={...n,...S,..._};let{isCorrect:D,queryResultErrors:j}=await this.checkCurrentDate("sanctions",d,s??604800,n);o=o&&D,n={...n,...j},$=getNullifierFromDisclosureProof(d).toString(10),P=getNullifierTypeFromDisclosureProof(d);}else if(b.name?.startsWith("facematch")&&!b.name?.endsWith("_evm")){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the facematch check"),o=false,n.facematch={...n.facematch,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the facematch check"}});let m=b.committedInputs?.facematch,l=getParameterCommitmentFromDisclosureProof(d),u=await getFacematchParameterCommitment(BigInt(m.rootKeyLeaf),m.environment==="development"?0n:1n,BigInt(m.appIdHash),m.mode==="regular"?1n:2n);l!==u&&(console.warn("The FaceMatch verification does not match the ones from the proof"),o=false,n.facematch={...n.facematch,commitment:{expected:`Commitment: ${u.toString()}`,received:`Commitment: ${l.toString()}`,message:"The FaceMatch verification does not match the ones from the proof"}});let{isCorrect:v,queryResultErrors:x}=this.checkScopeFromDisclosureProof(i,d,n,"facematch",c),{isCorrect:_,queryResultErrors:I}=await this.checkFacematchPublicInputs(e,t,m);o=o&&_&&v,n={...n,...I,...x};let{isCorrect:S,queryResultErrors:D}=await this.checkCurrentDate("facematch",d,s??604800,n);o=o&&S,n={...n,...D};}}if(o&&P&&(P===NullifierType.SALTED||P===NullifierType.SALTED_MOCK))try{let b=await getOprfPublicKey(h??OPRF_DEFAULT_KEY_ID),d=await hashOprfPublicKey(b),m=A.find(l=>l.name&&!l.name.startsWith("sig_check_")&&!l.name.startsWith("data_check_")&&!l.name.startsWith("outer")&&!l.name.startsWith("facematch"));if(m){let l=getProofData(m.proof,getNumberOfPublicInputs(m.name));getOprfPkHashFromDisclosureProof(l)!==d&&(console.warn("OPRF public key hash mismatch: proof uses an unknown OPRF key"),o=!1);}}catch(b){console.warn("Failed to verify OPRF public key:",b),o=false;}return {isCorrect:o,uniqueIdentifier:$,uniqueIdentifierType:P,queryResultErrors:n}}};var Ae={abi:[{type:"constructor",inputs:[{name:"_admin",type:"address",internalType:"address"},{name:"_guardian",type:"address",internalType:"address"},{name:"_rootRegistry",type:"address",internalType:"contract RootRegistry"},{name:"_defaultOPRFPubKeyHash",type:"bytes32",internalType:"bytes32"}],stateMutability:"nonpayable"},{type:"function",name:"addHelper",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"},{name:"newHelper",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addSubVerifier",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"},{name:"subVerifier",type:"address",internalType:"contract SubVerifier"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"admin",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"config",inputs:[{name:"key",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"value",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"defaultOPRFPubKeyHash",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"getHelper",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"getSubVerifier",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"guardian",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"helperCount",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"helpers",inputs:[{name:"",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"address",internalType:"contract VerifierHelper"}],stateMutability:"view"},{type:"function",name:"pause",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"paused",inputs:[],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"removeHelper",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"removeSubVerifier",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"rootRegistry",inputs:[],outputs:[{name:"",type:"address",internalType:"contract RootRegistry"}],stateMutability:"view"},{type:"function",name:"setDefaultOPRFPubKeyHash",inputs:[{name:"newHash",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setGuardian",inputs:[{name:"newGuardian",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"subverifierCount",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"subverifiers",inputs:[{name:"",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"address",internalType:"contract SubVerifier"}],stateMutability:"view"},{type:"function",name:"transferAdmin",inputs:[{name:"newAdmin",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"unpause",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"updateConfig",inputs:[{name:"key",type:"bytes32",internalType:"bytes32"},{name:"value",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"updateHelper",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"},{name:"newHelper",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"updateSubVerifier",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"},{name:"newSubVerifier",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"verify",inputs:[{name:"params",type:"tuple",internalType:"struct ProofVerificationParams",components:[{name:"version",type:"bytes32",internalType:"bytes32"},{name:"proofVerificationData",type:"tuple",internalType:"struct ProofVerificationData",components:[{name:"vkeyHash",type:"bytes32",internalType:"bytes32"},{name:"proof",type:"bytes",internalType:"bytes"},{name:"publicInputs",type:"bytes32[]",internalType:"bytes32[]"}]},{name:"committedInputs",type:"bytes",internalType:"bytes"},{name:"serviceConfig",type:"tuple",internalType:"struct ServiceConfig",components:[{name:"validityPeriodInSeconds",type:"uint256",internalType:"uint256"},{name:"domain",type:"string",internalType:"string"},{name:"scope",type:"string",internalType:"string"},{name:"devMode",type:"bool",internalType:"bool"},{name:"oprfPubKeyHash",type:"bytes32",internalType:"bytes32"}]}]}],outputs:[{name:"valid",type:"bool",internalType:"bool"},{name:"uniqueIdentifier",type:"bytes32",internalType:"bytes32"},{name:"helper",type:"address",internalType:"contract VerifierHelper"}],stateMutability:"view"},{type:"event",name:"AdminUpdated",inputs:[{name:"oldAdmin",type:"address",indexed:true,internalType:"address"},{name:"newAdmin",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"ConfigUpdated",inputs:[{name:"key",type:"bytes32",indexed:true,internalType:"bytes32"},{name:"oldValue",type:"bytes32",indexed:false,internalType:"bytes32"},{name:"newValue",type:"bytes32",indexed:false,internalType:"bytes32"}],anonymous:false},{type:"event",name:"DefaultOPRFPubKeyHashUpdated",inputs:[{name:"oldHash",type:"bytes32",indexed:false,internalType:"bytes32"},{name:"newHash",type:"bytes32",indexed:false,internalType:"bytes32"}],anonymous:false},{type:"event",name:"GuardianUpdated",inputs:[{name:"oldGuardian",type:"address",indexed:true,internalType:"address"},{name:"newGuardian",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"HelperAdded",inputs:[{name:"version",type:"bytes32",indexed:true,internalType:"bytes32"},{name:"helper",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"HelperRemoved",inputs:[{name:"version",type:"bytes32",indexed:true,internalType:"bytes32"},{name:"helper",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"HelperUpdated",inputs:[{name:"version",type:"bytes32",indexed:true,internalType:"bytes32"},{name:"oldHelper",type:"address",indexed:true,internalType:"address"},{name:"newHelper",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"PausedStatusChanged",inputs:[{name:"paused",type:"bool",indexed:false,internalType:"bool"}],anonymous:false},{type:"event",name:"RootRegistryUpdated",inputs:[{name:"oldRootRegistry",type:"address",indexed:true,internalType:"address"},{name:"newRootRegistry",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"RootVerifierDeployed",inputs:[{name:"admin",type:"address",indexed:false,internalType:"address"},{name:"guardian",type:"address",indexed:false,internalType:"address"},{name:"rootRegistry",type:"address",indexed:false,internalType:"address"}],anonymous:false},{type:"event",name:"SubVerifierAdded",inputs:[{name:"version",type:"bytes32",indexed:true,internalType:"bytes32"},{name:"subVerifier",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"SubVerifierRemoved",inputs:[{name:"version",type:"bytes32",indexed:true,internalType:"bytes32"},{name:"subVerifier",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"SubVerifierUpdated",inputs:[{name:"version",type:"bytes32",indexed:true,internalType:"bytes32"},{name:"oldSubVerifier",type:"address",indexed:true,internalType:"address"},{name:"newSubVerifier",type:"address",indexed:true,internalType:"address"}],anonymous:false}]};var J=class{static getDetails(){return {...{functionName:"verify",abi:Ae.abi},address:"0x1D000001000EFD9a6371f4d90bB8920D5431c0D8"}}static getParameters({proof:i,validityPeriodInSeconds:a=604800,domain:e,scope:t,devMode:s=false,oprfPubKeyHash:c}){if(!i.name?.startsWith("outer_evm"))throw new Error("This proof cannot be verified on an EVM chain. Please make sure to use the `compressed-evm` mode.");let h=getProofData(i.proof,getNumberOfPublicInputs(i.name)),p=[],r=[];for(let A in i.committedInputs){let b=getCommittedInputCount(A),d=A;p.push({circuitName:d,count:b});let m="";if(d==="inclusion_check_issuing_country_evm"||d==="inclusion_check_nationality_evm"||d==="exclusion_check_issuing_country_evm"||d==="exclusion_check_nationality_evm"){let u=i.committedInputs[d].countries;(d==="exclusion_check_issuing_country_evm"||d==="exclusion_check_nationality_evm")&&u.sort((x,_)=>x.localeCompare(_));let v=(()=>{switch(d){case "exclusion_check_issuing_country_evm":return ProofType.ISSUING_COUNTRY_EXCLUSION;case "exclusion_check_nationality_evm":return ProofType.NATIONALITY_EXCLUSION;case "inclusion_check_issuing_country_evm":return ProofType.ISSUING_COUNTRY_INCLUSION;case "inclusion_check_nationality_evm":return ProofType.NATIONALITY_INCLUSION}})();m=v.toString(16).padStart(2,"0")+ProofTypeLength[v].evm.toString(16).padStart(4,"0")+rightPadArrayWithZeros(u.map(x=>Array.from(new TextEncoder().encode(x))).flat(),600).map(x=>x.toString(16).padStart(2,"0")).join("");}else if(d==="compare_age_evm"){let l=i.committedInputs[d];m=ProofType.AGE.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.AGE].evm.toString(16).padStart(4,"0")+l.minAge.toString(16).padStart(2,"0")+l.maxAge.toString(16).padStart(2,"0");}else if(d==="compare_birthdate_evm"){let l=i.committedInputs[d],u=Array.from(numberToBytesBE(l.minDateTimestamp,8)),v=Array.from(numberToBytesBE(l.maxDateTimestamp,8));m=ProofType.BIRTHDATE.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.BIRTHDATE].evm.toString(16).padStart(4,"0")+u.map(x=>x.toString(16).padStart(2,"0")).join("")+v.map(x=>x.toString(16).padStart(2,"0")).join("");}else if(d==="compare_expiry_evm"){let l=i.committedInputs[d],u=Array.from(numberToBytesBE(l.minDateTimestamp,8)),v=Array.from(numberToBytesBE(l.maxDateTimestamp,8));m=ProofType.EXPIRY_DATE.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.EXPIRY_DATE].evm.toString(16).padStart(4,"0")+u.map(x=>x.toString(16).padStart(2,"0")).join("")+v.map(x=>x.toString(16).padStart(2,"0")).join("");}else if(d==="disclose_bytes_evm"){let l=i.committedInputs[d];m=ProofType.DISCLOSE.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.DISCLOSE].evm.toString(16).padStart(4,"0")+l.discloseMask.map(u=>u.toString(16).padStart(2,"0")).join("")+l.disclosedBytes.map(u=>u.toString(16).padStart(2,"0")).join("");}else if(d==="bind_evm"){let l=i.committedInputs[d];m=ProofType.BIND.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.BIND].evm.toString(16).padStart(4,"0")+rightPadArrayWithZeros(formatBoundData(l.data),509).map(u=>u.toString(16).padStart(2,"0")).join("");}else if(d==="exclusion_check_sanctions_evm"){let l=i.committedInputs[d];m+=ProofType.SANCTIONS_EXCLUSION.toString(16).padStart(2,"0"),m+=ProofTypeLength[ProofType.SANCTIONS_EXCLUSION].evm.toString(16).padStart(4,"0"),m+=Array.from(numberToBytesBE(BigInt(l.rootHash),32)).map(u=>u.toString(16).padStart(2,"0")).join(""),m+=l.isStrict?"01":"00";}else if(d.startsWith("facematch")&&d.endsWith("_evm")){let l=i.committedInputs[d];m+=ProofType.FACEMATCH.toString(16).padStart(2,"0"),m+=ProofTypeLength[ProofType.FACEMATCH].evm.toString(16).padStart(4,"0"),m+=Array.from(numberToBytesBE(BigInt(l.rootKeyLeaf),32)).map(u=>u.toString(16).padStart(2,"0")).join(""),m+=l.environment==="development"?"00":"01",m+=Array.from(numberToBytesBE(BigInt(l.appIdHash),32)).map(u=>u.toString(16).padStart(2,"0")).join(""),m+=Array.from(numberToBytesBE(BigInt(l.integrityPubkeyHash),32)).map(u=>u.toString(16).padStart(2,"0")).join(""),m+=l.mode==="regular"?"01":"02";}else throw new Error(`Unsupported circuit for EVM verification: ${d}`);r.push({circuitName:d,inputs:m});}let f=getParamCommitmentsFromOuterProof(h).map(A=>A.toString(16).padStart(64,"0")),o="";for(let A of f){let b=r.find(d=>{let m=sha256(hexToBytes(d.inputs)),l=new Uint8Array(m.length);for(let u=0;u<m.length-1;u++)l[u+1]=m[u];return l[0]=0,bytesToHex(l)===A.replace("0x","")});if(b){let d=p.find(m=>m.circuitName===b.circuitName)?.count;if(d)o+=b.inputs;else throw new Error(`Unknown circuit name: ${b.circuitName}`)}else throw new Error(`Invalid commitment: ${A}`)}let P=i.version?.split(".").map(A=>Number(A));if(!P||P.length!==3)throw new Error("Invalid version format");let N=new Uint8Array([...numberToBytesBE(P[0],2),...numberToBytesBE(P[1],2),...numberToBytesBE(P[2],2)]);return {version:`0x${bytesToHex(N).padEnd(64,"0")}`,proofVerificationData:{vkeyHash:`0x${i.vkeyHash.replace("0x","").padStart(64,"0")}`,proof:`0x${h.proof.join("")}`,publicInputs:h.publicInputs},committedInputs:`0x${o}`,serviceConfig:{validityPeriodInSeconds:a,domain:e,scope:t??"",devMode:s,oprfPubKeyHash:c??ye}}}};typeof globalThis.Buffer>"u"&&(globalThis.Buffer=Buffer,typeof window<"u"&&(window.Buffer=Buffer));registerLocale(_t);function pe(H){if(H==="Zero Knowledge Republic")return "ZKR";let i;return i=getAlpha3Code(H,"en")||H||"ZKR",i}function oe(H,i,a,e,t){t[e][i]={...t[e][i],[H]:a};}function St(H,i,a,e){e[a][H]={...e[a][H],range:i};}function ue(H,i,a,e,t){t[e][i]={...t[e][i],[H]:a};}var Ve=class{constructor(i){this.topicToConfig={};this.topicToLocalConfig={};this.topicToPublicKey={};this.topicToBridge={};this.topicToRequestReceived={};this.topicToService={};this.topicToProofs={};this.topicToFailedProofCount={};this.topicToResults={};this.onRequestReceivedCallbacks={};this.onGeneratingProofCallbacks={};this.onBridgeConnectCallbacks={};this.onProofGeneratedCallbacks={};this.onResultCallbacks={};this.onRejectCallbacks={};this.onErrorCallbacks={};if(!i&&typeof window>"u")throw new Error("Domain argument is required in Node.js environment");this.domain=this.normalizeDomain(i||window.location.hostname);}normalizeDomain(i){return i.trim().replace(/^https?:\/\//,"").replace(/\/[^/]*$/,"").replace(/:[0-9]+/,"").replace(/\?.*$/,"").replace(/#.*$/,"").toLowerCase()}async handleResult(i){let a=this.topicToResults[i];delete this.topicToResults[i];let{uniqueIdentifier:e,uniqueIdentifierType:t,verified:s,queryResultErrors:c}=await this.verify({proofs:this.topicToProofs[i],originalQuery:this.topicToConfig[i],queryResult:a,validity:this.topicToLocalConfig[i]?.validity,scope:this.topicToService[i]?.scope,devMode:this.topicToLocalConfig[i]?.devMode,oprfKeyId:this.topicToLocalConfig[i]?.oprfKeyId??void 0});delete this.topicToProofs[i];let h=this.topicToFailedProofCount[i]>0;await Promise.all(this.onResultCallbacks[i].map(p=>p({uniqueIdentifier:h?void 0:e,uniqueIdentifierType:h?void 0:t,verified:h?false:s,result:a,queryResultErrors:c}))),delete this.topicToFailedProofCount[i];}async handleEncryptedMessage(i,a){if(a.method==="accept")await Promise.all(this.onGeneratingProofCallbacks[i].map(e=>e(i)));else if(a.method==="reject")await Promise.all(this.onRejectCallbacks[i].map(e=>e()));else if(a.method==="proof")this.topicToProofs[i].push(a.params),await Promise.all(this.onProofGeneratedCallbacks[i].map(e=>e(a.params))),this.topicToResults[i]&&a.params.total===this.topicToProofs[i].length+this.topicToFailedProofCount[i]&&await this.handleResult(i);else if(a.method==="done")this.topicToResults[i]=formatQueryResultDates(a.params),this.topicToProofs[i].length>0&&this.topicToProofs[i].length+this.topicToFailedProofCount[i]===this.topicToProofs[i][0].total&&await this.handleResult(i);else if(a.method==="error"){let e=a.params.error;e&&e==="This ID is not supported yet"?this.topicToResults[i]&&await this.handleResult(i):e&&e.startsWith("Cannot generate proof")&&(this.topicToFailedProofCount[i]+=1,this.topicToResults[i]&&this.topicToProofs[i].length>0&&this.topicToProofs[i].length+this.topicToFailedProofCount[i]===this.topicToProofs[i][0].total&&await this.handleResult(i)),await Promise.all(this.onErrorCallbacks[i].map(t=>t(e)));}}getZkPassportRequest(i){return {eq:(a,e)=>((a==="issuing_country"||a==="nationality")&&(e=pe(e)),ue("eq",a,e,i,this.topicToConfig),this.getZkPassportRequest(i)),gte:(a,e)=>{if(oe("gte",a,e,i,this.topicToConfig),a==="age"&&(e<1||e>=100))throw new Error("Age must be between 1 and 99 (inclusive)");return this.getZkPassportRequest(i)},gt:(a,e)=>(oe("gt",a,e,i,this.topicToConfig),this.getZkPassportRequest(i)),lte:(a,e)=>(oe("lte",a,e,i,this.topicToConfig),this.getZkPassportRequest(i)),lt:(a,e)=>(oe("lt",a,e,i,this.topicToConfig),this.getZkPassportRequest(i)),range:(a,e,t)=>(St(a,[e,t],i,this.topicToConfig),this.getZkPassportRequest(i)),in:(a,e)=>(e=e.map(t=>pe(t)),ue("in",a,e,i,this.topicToConfig),this.getZkPassportRequest(i)),out:(a,e)=>(e=e.map(t=>pe(t)),ue("out",a,e,i,this.topicToConfig),this.getZkPassportRequest(i)),disclose:a=>(this.topicToConfig[i][a]={...this.topicToConfig[i][a],disclose:true},this.getZkPassportRequest(i)),bind:(a,e)=>(this.topicToConfig[i].bind={...this.topicToConfig[i].bind,[a]:e},this.getZkPassportRequest(i)),sanctions:(a="all",e="all",t={strict:false})=>(this.topicToConfig[i].sanctions={...this.topicToConfig[i].sanctions,countries:a,lists:e,strict:t.strict??false},this.getZkPassportRequest(i)),facematch:(a="regular")=>(this.topicToConfig[i].facematch={mode:a},this.getZkPassportRequest(i)),done:(()=>{if(this.topicToFailedProofCount[i]=0,i==="offline-query"){let s=this.topicToConfig[i];return delete this.topicToConfig[i],{query:s}}let a=this.topicToLocalConfig[i],e=this.topicToConfig[i],t=!!e.facematch&&e.facematch?.mode==="strict";if(a.uniqueIdentifierType===NullifierType.SALTED&&!t)throw new Error("Salted nullifier requires strict facematch. Add .facematch('strict') to your query or remove the salted nullifier option.");return {url:this._getUrl(i),query:this.topicToConfig[i],requestId:i,onRequestReceived:s=>this.onRequestReceivedCallbacks[i].push(s),onGeneratingProof:s=>this.onGeneratingProofCallbacks[i].push(s),onBridgeConnect:s=>this.onBridgeConnectCallbacks[i].push(s),onProofGenerated:s=>this.onProofGeneratedCallbacks[i].push(s),onResult:s=>this.onResultCallbacks[i].push(s),onReject:s=>this.onRejectCallbacks[i].push(s),onError:s=>this.onErrorCallbacks[i].push(s),isBridgeConnected:()=>this.topicToBridge[i].isBridgeConnected(),requestReceived:()=>this.topicToRequestReceived[i]===true}})}}async request({name:i,logo:a,purpose:e,scope:t,projectID:s,mode:c,validity:h,devMode:p,uniqueIdentifierType:r,oprfKeyId:f,topicOverride:o,keyPairOverride:$,cloudProverUrl:P,bridgeUrl:N}){if(o==="offline-query")throw new Error("You cannot override the topic with 'offline-query'");let B=await Bridge.create({keyPair:$,bridgeId:o,bridgeUrl:N}),n=B.connection.getBridgeId();return this.topicToConfig[n]={},this.topicToService[n]={name:i,logo:a,purpose:e,scope:t,projectID:s,cloudProverUrl:P,bridgeUrl:N},this.topicToProofs[n]=[],this.topicToLocalConfig[n]={validity:h||604800,mode:c||"fast",devMode:p||false,uniqueIdentifierType:f?NullifierType.SALTED:r,oprfKeyId:f??null},this.onRequestReceivedCallbacks[n]=[],this.onGeneratingProofCallbacks[n]=[],this.onBridgeConnectCallbacks[n]=[],this.onProofGeneratedCallbacks[n]=[],this.onResultCallbacks[n]=[],this.onRejectCallbacks[n]=[],this.onErrorCallbacks[n]=[],this.topicToPublicKey[n]=B.getPublicKey(),this.topicToBridge[n]=B,B.onConnect(async A=>{await Promise.all(this.onBridgeConnectCallbacks[n].map(b=>b()));}),B.onSecureChannelEstablished(async()=>{await Promise.all(this.onRequestReceivedCallbacks[n].map(A=>A()));}),B.onSecureMessage(async A=>{this.handleEncryptedMessage(n,A);}),this.getZkPassportRequest(n)}createQuery(){return this.topicToConfig["offline-query"]={},this.getZkPassportRequest("offline-query")}async verify({proofs:i,originalQuery:a,queryResult:e,validity:t,scope:s,devMode:c=false,writingDirectory:h,oprfKeyId:p}){if(!i||i.length===0)return {uniqueIdentifier:void 0,uniqueIdentifierType:void 0,verified:false};let r=formatQueryResultDates(e),{UltraHonkVerifierBackend:f,Barretenberg:o}=await import('@aztec/bb.js');typeof window>"u"&&!h&&(h="/tmp");let $=await o.new({crsPath:h?h+"/.bb-crs":void 0}),P=new f($),N=true,B,n,A,{isCorrect:b,uniqueIdentifier:d,uniqueIdentifierType:m,queryResultErrors:l}=await ne.checkPublicInputs(this.domain,i,a,r,t,s,p,c);if(B=d,n=m,N=b,A=b?void 0:l,B&&n&&(n===NullifierType.SALTED_MOCK||n===NullifierType.NON_SALTED_MOCK)&&!c&&(N=false,console.warn("You are trying to verify a mock proof. This is only allowed in dev mode. To enable dev mode, set the `devMode` parameter to `true` in the request function parameters.")),N){let u=new RegistryClient({chainId:c?11155111:1}),v=await u.getCircuitManifest(void 0,{version:i[0].version});for(let x of i){let _=x.name?.startsWith("outer_evm_"),I=x.name,S=getProofData(x.proof,getNumberOfPublicInputs(I)),D=await u.getPackagedCircuit(I,v,{validate:!_});if(_)try{let{createPublicClient:j,http:w}=await import('viem'),{sepolia:g}=await import('viem/chains'),{address:Q,abi:y,functionName:T}=this.getSolidityVerifierDetails(),k=j({chain:g,transport:w("https://ethereum-sepolia-rpc.publicnode.com")}),E=this.getSolidityVerifierParameters({proof:x,domain:this.domain,scope:s,devMode:c}),q=await k.readContract({address:Q,abi:y,functionName:T,args:[E]});N=Array.isArray(q)?!!q[0]:!1;}catch(j){console.warn("Error verifying proof",j),N=false;}else {let j=Buffer.from(D.vkey,"base64");try{N=await P.verifyProof({proof:Buffer.from(S.proof.join(""),"hex"),publicInputs:S.publicInputs,verificationKey:new Uint8Array(j)});}catch(w){console.warn(`Error verifying proof ${I}`,w),N=false;}}if(!N)break}}return B=N?B:void 0,n=N?n:void 0,{uniqueIdentifier:B,uniqueIdentifierType:n,verified:N,queryResultErrors:A}}getSolidityVerifierDetails(){return J.getDetails()}getSolidityVerifierParameters({proof:i,validityPeriodInSeconds:a=604800,domain:e,scope:t,devMode:s=false,oprfPubKeyHash:c}){return J.getParameters({proof:i,validityPeriodInSeconds:a,domain:e??this.domain,scope:t,devMode:s,oprfPubKeyHash:c})}_getUrl(i){let a=Buffer.from(JSON.stringify(this.topicToConfig[i])).toString("base64"),e=Buffer.from(JSON.stringify(this.topicToService[i])).toString("base64"),t=this.topicToPublicKey[i],s=Math.floor(Date.now()/1e3)-this.topicToLocalConfig[i].validity,c=this.topicToLocalConfig[i].uniqueIdentifierType,h=this.topicToLocalConfig[i].oprfKeyId,p=`https://zkpassport.id/r?d=${this.domain}&t=${i}&c=${a}&s=${e}&p=${t}&m=${this.topicToLocalConfig[i].mode}&v=${be}&dt=${s}&dev=${this.topicToLocalConfig[i].devMode?"1":"0"}`;return c&&(p+=`&nt=${c}`),h&&(p+=`&oprf_k=${h}`),p}getUrl(i){return this._getUrl(i)}cancelRequest(i){this.topicToBridge[i]&&(this.topicToBridge[i].close(),delete this.topicToBridge[i]),delete this.topicToPublicKey[i],delete this.topicToConfig[i],delete this.topicToLocalConfig[i],delete this.topicToProofs[i],delete this.topicToFailedProofCount[i],delete this.topicToResults[i],this.onRequestReceivedCallbacks[i]=[],this.onGeneratingProofCallbacks[i]=[],this.onBridgeConnectCallbacks[i]=[],this.onProofGeneratedCallbacks[i]=[],this.onRejectCallbacks[i]=[],this.onErrorCallbacks[i]=[];}clearAllRequests(){for(let i in this.topicToBridge)this.cancelRequest(i);}};
|
|
1
|
+
import {registerLocale,getAlpha3Code}from'i18n-iso-countries';import {formatQueryResultDates,NullifierType,getProofData,getNumberOfPublicInputs,DisclosedData,areDatesEqual,formatName,getMinAgeFromCommittedInputs,getMaxAgeFromCommittedInputs,getBirthdateMinDateTimestamp,SECONDS_BETWEEN_1900_AND_1970,getBirthdateMaxDateTimestamp,getMinDateFromCommittedInputs,getMaxDateFromCommittedInputs,getServiceScopeHash,getServiceScopeFromDisclosureProof,getScopeHash,getServiceSubScopeFromDisclosureProof,getCurrentDateFromDisclosureProof,getCertificateRegistryRootFromOuterProof,getCircuitRegistryRootFromOuterProof,getCurrentDateFromOuterProof,getParamCommitmentsFromOuterProof,getScopeFromOuterProof,getSubscopeFromOuterProof,getAgeEVMParameterCommitment,getAgeParameterCommitment,getDateEVMParameterCommitment,ProofType,getDateParameterCommitment,getDiscloseEVMParameterCommitment,getDiscloseParameterCommitment,getCountryEVMParameterCommitment,getCountryParameterCommitment,getBindEVMParameterCommitment,formatBoundData,getBindParameterCommitment,SanctionsBuilder,getFacematchEvmParameterCommitment,getFacematchParameterCommitment,getNullifierFromOuterProof,getNullifierTypeFromOuterProof,getCommitmentFromDSCProof,getMerkleRootFromDSCProof,getCommitmentInFromIDDataProof,getCommitmentOutFromIDDataProof,getCommitmentInFromIntegrityProof,getCommitmentOutFromIntegrityProof,getCommitmentInFromDisclosureProof,getParameterCommitmentFromDisclosureProof,getNullifierFromDisclosureProof,getNullifierTypeFromDisclosureProof,getOprfPublicKey,OPRF_DEFAULT_KEY_ID,hashOprfPublicKey,getOprfPkHashFromDisclosureProof,getCommittedInputCount,ProofTypeLength,rightPadArrayWithZeros,numberToBytesBE}from'@zkpassport/utils';export{ASEAN_COUNTRIES,EEA_COUNTRIES,EU_COUNTRIES,MERCOSUR_COUNTRIES,NullifierType,ProofType,ProofTypeLength,SANCTIONED_COUNTRIES,SCHENGEN_COUNTRIES}from'@zkpassport/utils';import wt from'i18n-iso-countries/langs/en.json';import {Buffer}from'buffer/';import {RegistryClient}from'@zkpassport/registry';import {Bridge}from'@obsidion/bridge';import {sha256}from'@noble/hashes/sha2.js';import {hexToBytes,bytesToHex}from'@noble/hashes/utils.js';var ye="0.12.0";var Y=new Date(0);var re="0x1fa73686cf510f8f85757b0602de0dd72a13e68ae2092462be8b72662e7f179b",de="0x24d9929b248be7eeecaa98e105c034a50539610f3fdd4cb9c8983ef4100d615d",ce="0x2532418a107c5306fa8308c22255792cf77e4a290cbce8a840a642a3e591340b",fe="0x16700a2d9168a194fc85f237af5829b5a2be05b8ae8ac4879ada34cf54a9c211",me="0x0e1889bec6c1d686abcf08360ff404f803ab345881ea8cba6aad33b7f7f7ffe0";var ne=class{static checkDiscloseBytesPublicInputs(i,a,e){let t={},s=true,c=i.committedInputs?.disclose_bytes?.disclosedBytes??i.committedInputs?.disclose_bytes_evm?.disclosedBytes,g=DisclosedData.fromDisclosedBytes(c,"passport"),u=DisclosedData.fromDisclosedBytes(c,"id_card");if(e.document_type&&(e.document_type.eq&&e.document_type.eq.result&&e.document_type.eq.expected!==g.documentType&&(console.warn("Document type does not match the expected document type"),s=false,t.document_type={...t.document_type,eq:{expected:`${e.document_type.eq.expected}`,received:`${g.documentType??u.documentType}`,message:"Document type does not match the expected document type"}}),e.document_type.disclose&&e.document_type.disclose.result!==u.documentType&&(console.warn("Document type does not match the disclosed document type in query result"),s=false,t.document_type={...t.document_type,disclose:{expected:`${e.document_type.disclose?.result}`,received:`${u.documentType??g.documentType}`,message:"Document type does not match the disclosed document type in query result"}}),e.document_type.eq&&(a.document_type?.eq===void 0||e.document_type.eq.expected!==a.document_type.eq)&&(console.warn("Document type eq does not match the original query"),s=false,t.document_type={...t.document_type,eq:{expected:`${a.document_type?.eq}`,received:`${e.document_type.eq.expected}`,message:"Document type eq does not match the original query"}}),e.document_type.disclose&&!a.document_type?.disclose&&(console.warn("Document type disclose is not in the original query"),s=false,t.document_type={...t.document_type,disclose:{expected:"Not requested in original query",received:`${e.document_type.disclose.result}`,message:"Document type disclose is not in the original query"}})),e.birthdate){let r=g.dateOfBirth,f=u.dateOfBirth;e.birthdate.eq&&e.birthdate.eq.result&&!areDatesEqual(e.birthdate.eq.expected,r)&&!areDatesEqual(e.birthdate.eq.expected,f)&&(console.warn("Birthdate does not match the expected birthdate"),s=false,t.birthdate={...t.birthdate,eq:{expected:`${e.birthdate.eq.expected.toISOString()}`,received:`${r?.toISOString()??f?.toISOString()}`,message:"Birthdate does not match the expected birthdate"}}),e.birthdate.disclose&&!areDatesEqual(e.birthdate.disclose.result,r)&&!areDatesEqual(e.birthdate.disclose.result,f)&&(console.warn("Birthdate does not match the disclosed birthdate in query result"),s=false,t.birthdate={...t.birthdate,disclose:{expected:`${e.birthdate.disclose.result.toISOString()}`,received:`${r?.toISOString()??f?.toISOString()}`,message:"Birthdate does not match the disclosed birthdate in query result"}}),e.birthdate.eq&&(a.birthdate?.eq===void 0||!areDatesEqual(e.birthdate.eq.expected,a.birthdate.eq))&&(console.warn("Birthdate eq does not match the original query"),s=false,t.birthdate={...t.birthdate,eq:{expected:`${a.birthdate?.eq?.toISOString?.()??"undefined"}`,received:`${e.birthdate.eq.expected.toISOString()}`,message:"Birthdate eq does not match the original query"}}),e.birthdate.disclose&&!a.birthdate?.disclose&&(console.warn("Birthdate disclose is not in the original query"),s=false,t.birthdate={...t.birthdate,disclose:{expected:"Not requested in original query",received:`${e.birthdate.disclose.result}`,message:"Birthdate disclose is not in the original query"}});}if(e.expiry_date){let r=g.dateOfExpiry,f=u.dateOfExpiry;e.expiry_date.eq&&e.expiry_date.eq.result&&!areDatesEqual(e.expiry_date.eq.expected,r)&&!areDatesEqual(e.expiry_date.eq.expected,f)&&(console.warn("Expiry date does not match the expected expiry date"),s=false,t.expiry_date={...t.expiry_date,eq:{expected:`${e.expiry_date.eq.expected.toISOString()}`,received:`${r?.toISOString()??f?.toISOString()}`,message:"Expiry date does not match the expected expiry date"}}),e.expiry_date.disclose&&!areDatesEqual(e.expiry_date.disclose.result,r)&&!areDatesEqual(e.expiry_date.disclose.result,f)&&(console.warn("Expiry date does not match the disclosed expiry date in query result"),s=false,t.expiry_date={...t.expiry_date,disclose:{expected:`${e.expiry_date.disclose.result.toISOString()}`,received:`${r?.toISOString()??f?.toISOString()}`,message:"Expiry date does not match the disclosed expiry date in query result"}}),e.expiry_date.eq&&(a.expiry_date?.eq===void 0||!areDatesEqual(e.expiry_date.eq.expected,a.expiry_date.eq))&&(console.warn("Expiry date eq does not match the original query"),s=false,t.expiry_date={...t.expiry_date,eq:{expected:`${a.expiry_date?.eq?.toISOString?.()??"undefined"}`,received:`${e.expiry_date.eq.expected.toISOString()}`,message:"Expiry date eq does not match the original query"}}),e.expiry_date.disclose&&!a.expiry_date?.disclose&&(console.warn("Expiry date disclose is not in the original query"),s=false,t.expiry_date={...t.expiry_date,disclose:{expected:"Not requested in original query",received:`${e.expiry_date.disclose.result}`,message:"Expiry date disclose is not in the original query"}});}if(e.nationality){let r=g.nationality,f=u.nationality;e.nationality.eq&&e.nationality.eq.result&&e.nationality.eq.expected!==r&&e.nationality.eq.expected!==f&&(console.warn("Nationality does not match the expected nationality"),s=false,t.nationality={...t.nationality,eq:{expected:`${e.nationality.eq.expected}`,received:`${r??f}`,message:"Nationality does not match the expected nationality"}}),e.nationality.disclose&&e.nationality.disclose.result!==r&&e.nationality.disclose.result!==f&&(console.warn("Nationality does not match the disclosed nationality in query result"),s=false,t.nationality={...t.nationality,disclose:{expected:`${e.nationality.disclose.result}`,received:`${r??f}`,message:"Nationality does not match the disclosed nationality in query result"}}),e.nationality.eq&&(a.nationality?.eq===void 0||e.nationality.eq.expected!==a.nationality.eq)&&(console.warn("Nationality eq does not match the original query"),s=false,t.nationality={...t.nationality,eq:{expected:`${a.nationality?.eq}`,received:`${e.nationality.eq.expected}`,message:"Nationality eq does not match the original query"}}),e.nationality.disclose&&!a.nationality?.disclose&&(console.warn("Nationality disclose is not in the original query"),s=false,t.nationality={...t.nationality,disclose:{expected:"Not requested in original query",received:`${e.nationality.disclose.result}`,message:"Nationality disclose is not in the original query"}});}if(e.document_number){let r=g.documentNumber,f=u.documentNumber;e.document_number.eq&&e.document_number.eq.result&&e.document_number.eq.expected!==r&&e.document_number.eq.expected!==f&&(console.warn("Document number does not match the expected document number"),s=false,t.document_number={...t.document_number,eq:{expected:`${e.document_number.eq.expected}`,received:`${r??f}`,message:"Document number does not match the expected document number"}}),e.document_number.disclose&&e.document_number.disclose.result!==r&&e.document_number.disclose.result!==f&&(console.warn("Document number does not match the disclosed document number in query result"),s=false,t.document_number={...t.document_number,disclose:{expected:`${e.document_number.disclose.result}`,received:`${r??f}`,message:"Document number does not match the disclosed document number in query result"}}),e.document_number.eq&&(a.document_number?.eq===void 0||e.document_number.eq.expected!==a.document_number.eq)&&(console.warn("Document number eq does not match the original query"),s=false,t.document_number={...t.document_number,eq:{expected:`${a.document_number?.eq}`,received:`${e.document_number.eq.expected}`,message:"Document number eq does not match the original query"}}),e.document_number.disclose&&!a.document_number?.disclose&&(console.warn("Document number disclose is not in the original query"),s=false,t.document_number={...t.document_number,disclose:{expected:"Not requested in original query",received:`${e.document_number.disclose.result}`,message:"Document number disclose is not in the original query"}});}if(e.gender){let r=g.gender,f=u.gender;e.gender.eq&&e.gender.eq.result&&e.gender.eq.expected!==r&&e.gender.eq.expected!==f&&(console.warn("Gender does not match the expected gender"),s=false,t.gender={...t.gender,eq:{expected:`${e.gender.eq.expected}`,received:`${r??f}`,message:"Gender does not match the expected gender"}}),e.gender.disclose&&e.gender.disclose.result!==r&&e.gender.disclose.result!==f&&(console.warn("Gender does not match the disclosed gender in query result"),s=false,t.gender={...t.gender,disclose:{expected:`${e.gender.disclose.result}`,received:`${r??f}`,message:"Gender does not match the disclosed gender in query result"}}),e.gender.eq&&(a.gender?.eq===void 0||e.gender.eq.expected!==a.gender.eq)&&(console.warn("Gender eq does not match the original query"),s=false,t.gender={...t.gender,eq:{expected:`${a.gender?.eq}`,received:`${e.gender.eq.expected}`,message:"Gender eq does not match the original query"}}),e.gender.disclose&&!a.gender?.disclose&&(console.warn("Gender disclose is not in the original query"),s=false,t.gender={...t.gender,disclose:{expected:"Not requested in original query",received:`${e.gender.disclose.result}`,message:"Gender disclose is not in the original query"}});}if(e.issuing_country){let r=g.issuingCountry,f=u.issuingCountry;e.issuing_country.eq&&e.issuing_country.eq.result&&e.issuing_country.eq.expected!==r&&e.issuing_country.eq.expected!==f&&(console.warn("Issuing country does not match the expected issuing country"),s=false,t.issuing_country={...t.issuing_country,eq:{expected:`${e.issuing_country.eq.expected}`,received:`${r??f}`,message:"Issuing country does not match the expected issuing country"}}),e.issuing_country.disclose&&e.issuing_country.disclose.result!==r&&e.issuing_country.disclose.result!==f&&(console.warn("Issuing country does not match the disclosed issuing country in query result"),s=false,t.issuing_country={...t.issuing_country,disclose:{expected:`${e.issuing_country.disclose.result}`,received:`${r??f}`,message:"Issuing country does not match the disclosed issuing country in query result"}}),e.issuing_country.eq&&(a.issuing_country?.eq===void 0||e.issuing_country.eq.expected!==a.issuing_country.eq)&&(console.warn("Issuing country eq does not match the original query"),s=false,t.issuing_country={...t.issuing_country,eq:{expected:`${a.issuing_country?.eq}`,received:`${e.issuing_country.eq.expected}`,message:"Issuing country eq does not match the original query"}}),e.issuing_country.disclose&&!a.issuing_country?.disclose&&(console.warn("Issuing country disclose is not in the original query"),s=false,t.issuing_country={...t.issuing_country,disclose:{expected:"Not requested in original query",received:`${e.issuing_country.disclose.result}`,message:"Issuing country disclose is not in the original query"}});}if(e.fullname){let r=g.name,f=u.name;e.fullname.eq&&e.fullname.eq.result&&formatName(e.fullname.eq.expected).toLowerCase()!==r.toLowerCase()&&formatName(e.fullname.eq.expected).toLowerCase()!==f.toLowerCase()&&(console.warn("Fullname does not match the expected fullname"),s=false,t.fullname={...t.fullname,eq:{expected:`${e.fullname.eq.expected}`,received:`${r??f}`,message:"Fullname does not match the expected fullname"}}),e.fullname.disclose&&formatName(e.fullname.disclose.result).toLowerCase()!==r.toLowerCase()&&formatName(e.fullname.disclose.result).toLowerCase()!==f.toLowerCase()&&(console.warn("Fullname does not match the disclosed fullname in query result"),s=false,t.fullname={...t.fullname,disclose:{expected:`${e.fullname.disclose.result}`,received:`${r??f}`,message:"Fullname does not match the disclosed fullname in query result"}}),e.fullname.eq&&(a.fullname?.eq===void 0||formatName(e.fullname.eq.expected).toLowerCase()!==formatName(a.fullname.eq).toLowerCase())&&(console.warn("Fullname eq does not match the original query"),s=false,t.fullname={...t.fullname,eq:{expected:`${a.fullname?.eq}`,received:`${e.fullname.eq.expected}`,message:"Fullname eq does not match the original query"}}),e.fullname.disclose&&!a.fullname?.disclose&&(console.warn("Fullname disclose is not in the original query"),s=false,t.fullname={...t.fullname,disclose:{expected:"Not requested in original query",received:`${e.fullname.disclose.result}`,message:"Fullname disclose is not in the original query"}});}if(e.firstname){let r=g.firstName&&g.firstName.length>0?g.firstName:g.name,f=u.firstName&&u.firstName.length>0?u.firstName:u.name;e.firstname.eq&&e.firstname.eq.result&&formatName(e.firstname.eq.expected).toLowerCase()!==r.toLowerCase()&&formatName(e.firstname.eq.expected).toLowerCase()!==f.toLowerCase()&&(console.warn("Firstname does not match the expected firstname"),s=false,t.firstname={...t.firstname,eq:{expected:`${e.firstname.eq.expected}`,received:`${r??f}`,message:"Firstname does not match the expected firstname"}}),e.firstname.disclose&&formatName(e.firstname.disclose.result).toLowerCase()!==r.toLowerCase()&&formatName(e.firstname.disclose.result).toLowerCase()!==f.toLowerCase()&&(console.warn("Firstname does not match the disclosed firstname in query result"),s=false,t.firstname={...t.firstname,disclose:{expected:`${e.firstname.disclose.result}`,received:`${r??f}`,message:"Firstname does not match the disclosed firstname in query result"}}),e.firstname.eq&&(a.firstname?.eq===void 0||formatName(e.firstname.eq.expected).toLowerCase()!==formatName(a.firstname.eq).toLowerCase())&&(console.warn("Firstname eq does not match the original query"),s=false,t.firstname={...t.firstname,eq:{expected:`${a.firstname?.eq}`,received:`${e.firstname.eq.expected}`,message:"Firstname eq does not match the original query"}}),e.firstname.disclose&&!a.firstname?.disclose&&(console.warn("Firstname disclose is not in the original query"),s=false,t.firstname={...t.firstname,disclose:{expected:"Not requested in original query",received:`${e.firstname.disclose.result}`,message:"Firstname disclose is not in the original query"}});}if(e.lastname){let r=g.lastName&&g.lastName.length>0?g.lastName:g.name,f=u.lastName&&u.lastName.length>0?u.lastName:u.name;e.lastname.eq&&e.lastname.eq.result&&formatName(e.lastname.eq.expected).toLowerCase()!==r.toLowerCase()&&formatName(e.lastname.eq.expected).toLowerCase()!==f.toLowerCase()&&(console.warn("Lastname does not match the expected lastname"),s=false,t.lastname={...t.lastname,eq:{expected:`${e.lastname.eq.expected}`,received:`${r??f}`,message:"Lastname does not match the expected lastname"}}),e.lastname.disclose&&formatName(e.lastname.disclose.result).toLowerCase()!==r.toLowerCase()&&formatName(e.lastname.disclose.result).toLowerCase()!==f.toLowerCase()&&(console.warn("Lastname does not match the disclosed lastname in query result"),s=false,t.lastname={...t.lastname,disclose:{expected:`${e.lastname.disclose.result}`,received:`${r??f}`,message:"Lastname does not match the disclosed lastname in query result"}}),e.lastname.eq&&(a.lastname?.eq===void 0||formatName(e.lastname.eq.expected).toLowerCase()!==formatName(a.lastname.eq).toLowerCase())&&(console.warn("Lastname eq does not match the original query"),s=false,t.lastname={...t.lastname,eq:{expected:`${a.lastname?.eq}`,received:`${e.lastname.eq.expected}`,message:"Lastname eq does not match the original query"}}),e.lastname.disclose&&!a.lastname?.disclose&&(console.warn("Lastname disclose is not in the original query"),s=false,t.lastname={...t.lastname,disclose:{expected:"Not requested in original query",received:`${e.lastname.disclose.result}`,message:"Lastname disclose is not in the original query"}});}return {isCorrect:s,queryResultErrors:t}}static checkAgePublicInputs(i,a,e){let t={},s=true,c=new Date;new Date(c.getFullYear(),c.getMonth(),c.getDate(),0,0,0,0);let u=getMinAgeFromCommittedInputs(i.committedInputs?.compare_age??i.committedInputs?.compare_age_evm),r=getMaxAgeFromCommittedInputs(i.committedInputs?.compare_age??i.committedInputs?.compare_age_evm);return e.age?(e.age.gte&&e.age.gte.result&&u!==e.age.gte.expected&&(console.warn("Age is not greater than or equal to the expected age"),s=false,t.age={...t.age,gte:{expected:e.age.gte.expected,received:u,message:"Age is not greater than or equal to the expected age"}}),e.age.gt&&e.age.gt.result&&u!==e.age.gt.expected+1&&(console.warn("Age is not greater than the expected age"),s=false,t.age={...t.age,gt:{expected:e.age.gt.expected,received:u,message:"Age is not greater than the expected age"}}),e.age.lt&&e.age.lt.result&&r!==e.age.lt.expected-1&&(console.warn("Age is not less than the expected age"),s=false,t.age={...t.age,lt:{expected:e.age.lt.expected,received:r,message:"Age is not less than the expected age"}}),e.age.lte&&e.age.lte.result&&r!==e.age.lte.expected&&(console.warn("Age is not less than or equal to the expected age"),s=false,t.age={...t.age,lte:{expected:e.age.lte.expected,received:r,message:"Age is not less than or equal to the expected age"}}),e.age.eq&&e.age.eq.result&&(u!==e.age.eq.expected||r!==e.age.eq.expected)&&(console.warn("Age does not match the expected age"),s=false,t.age={...t.age,eq:{expected:e.age.eq.expected,received:u!==e.age.eq.expected?u:r,message:"Age does not match the expected age"}}),e.age.range&&e.age.range.result&&(u!==e.age.range.expected[0]||r!==e.age.range.expected[1])&&(console.warn("Age is not in the expected range"),s=false,t.age={...t.age,range:{expected:e.age.range.expected,received:[u,r],message:"Age is not in the expected range"}}),!e.age.lt&&!e.age.lte&&!e.age.eq&&!e.age.range&&r!=0&&(console.warn("Maximum age should be equal to 0"),s=false,t.age={...t.age,disclose:{expected:0,received:r,message:"Maximum age should be equal to 0"}}),!e.age.gte&&!e.age.gt&&!e.age.eq&&!e.age.range&&u!=0&&(console.warn("Minimum age should be equal to 0"),s=false,t.age={...t.age,disclose:{expected:0,received:u,message:"Minimum age should be equal to 0"}}),e.age.disclose&&(e.age.disclose.result!==u||e.age.disclose.result!==r)&&(console.warn("Age does not match the disclosed age in query result"),s=false,t.age={...t.age,disclose:{expected:`${u}`,received:`${e.age.disclose.result}`,message:"Age does not match the disclosed age in query result"}})):(console.warn("Age is not set in the query result"),s=false,t.age={...t.age,disclose:{message:"Age is not set in the query result"}}),e.age?.gte&&(a.age?.gte===void 0||e.age.gte.expected!==a.age.gte)&&(console.warn("Age gte does not match the original query"),s=false,t.age={...t.age,gte:{expected:a.age?.gte,received:e.age.gte.expected,message:"Age gte does not match the original query"}}),e.age?.gt&&(a.age?.gt===void 0||e.age.gt.expected!==a.age.gt)&&(console.warn("Age gt does not match the original query"),s=false,t.age={...t.age,gt:{expected:a.age?.gt,received:e.age.gt.expected,message:"Age gt does not match the original query"}}),e.age?.lt&&(a.age?.lt===void 0||e.age.lt.expected!==a.age.lt)&&(console.warn("Age lt does not match the original query"),s=false,t.age={...t.age,lt:{expected:a.age?.lt,received:e.age.lt.expected,message:"Age lt does not match the original query"}}),e.age?.lte&&(a.age?.lte===void 0||e.age.lte.expected!==a.age.lte)&&(console.warn("Age lte does not match the original query"),s=false,t.age={...t.age,lte:{expected:a.age?.lte,received:e.age.lte.expected,message:"Age lte does not match the original query"}}),e.age?.eq&&(a.age?.eq===void 0||e.age.eq.expected!==a.age.eq)&&(console.warn("Age eq does not match the original query"),s=false,t.age={...t.age,eq:{expected:a.age?.eq,received:e.age.eq.expected,message:"Age eq does not match the original query"}}),e.age?.range&&(a.age?.range===void 0||e.age.range.expected[0]!==a.age.range[0]||e.age.range.expected[1]!==a.age.range[1])&&(console.warn("Age range does not match the original query"),s=false,t.age={...t.age,range:{expected:a.age?.range,received:e.age.range.expected,message:"Age range does not match the original query"}}),e.age?.disclose&&!a.age?.disclose&&(console.warn("Age disclose is not in the original query"),s=false,t.age={...t.age,disclose:{expected:"Not requested in original query",received:`${e.age.disclose.result}`,message:"Age disclose is not in the original query"}}),{isCorrect:s,queryResultErrors:t}}static checkBirthdatePublicInputs(i,a,e){let t={},s=true,c=new Date;new Date(c.getFullYear(),c.getMonth(),c.getDate(),0,0,0);let u=getBirthdateMinDateTimestamp(i.committedInputs?.compare_birthdate??i.committedInputs?.compare_birthdate_evm,-1*SECONDS_BETWEEN_1900_AND_1970),r=getBirthdateMaxDateTimestamp(i.committedInputs?.compare_birthdate??i.committedInputs?.compare_birthdate_evm,-1*SECONDS_BETWEEN_1900_AND_1970);if(e.birthdate){if(e.birthdate.gte&&e.birthdate.gte.result&&!areDatesEqual(u,e.birthdate.gte.expected)&&(console.warn("Birthdate is not greater than or equal to the expected birthdate"),s=false,t.birthdate={...t.birthdate,gte:{expected:e.birthdate.gte.expected,received:u,message:"Birthdate is not greater than or equal to the expected birthdate"}}),e.birthdate.gt&&e.birthdate.gt.result){let f=new Date(e.birthdate.gt.expected);f.setDate(f.getDate()+1),areDatesEqual(u,f)||(console.warn("Birthdate is not greater than the expected birthdate"),s=false,t.birthdate={...t.birthdate,gt:{expected:e.birthdate.gt.expected,received:u,message:"Birthdate is not greater than the expected birthdate"}});}if(e.birthdate.lte&&e.birthdate.lte.result&&!areDatesEqual(r,e.birthdate.lte.expected)&&(console.warn("Birthdate is not less than the expected birthdate"),s=false,t.birthdate={...t.birthdate,lte:{expected:e.birthdate.lte.expected,received:r,message:"Birthdate is not less than the expected birthdate"}}),e.birthdate.lt&&e.birthdate.lt.result){let f=new Date(e.birthdate.lt.expected);f.setDate(f.getDate()-1),areDatesEqual(r,f)||(console.warn("Birthdate is not less than the expected birthdate"),s=false,t.birthdate={...t.birthdate,lt:{expected:e.birthdate.lt.expected,received:r,message:"Birthdate is not less than the expected birthdate"}});}e.birthdate.range&&e.birthdate.range.result&&(!areDatesEqual(u,e.birthdate.range.expected[0])||!areDatesEqual(r,e.birthdate.range.expected[1]))&&(console.warn("Birthdate is not in the expected range"),s=false,t.birthdate={...t.birthdate,range:{expected:e.birthdate.range.expected,received:[u,r],message:"Birthdate is not in the expected range"}}),!e.birthdate.lte&&!e.birthdate.lt&&!e.birthdate.eq&&!e.birthdate.range&&!areDatesEqual(r,Y)&&(console.warn("Maximum birthdate should be equal to default date value"),s=false,t.birthdate={...t.birthdate,disclose:{expected:`${Y.toISOString()}`,received:`${r.toISOString()}`,message:"Maximum birthdate should be equal to default date value"}}),!e.birthdate.gte&&!e.birthdate.gt&&!e.birthdate.eq&&!e.birthdate.range&&!areDatesEqual(u,Y)&&(console.warn("Minimum birthdate should be equal to default date value"),s=false,t.birthdate={...t.birthdate,disclose:{expected:`${Y.toISOString()}`,received:`${u.toISOString()}`,message:"Minimum birthdate should be equal to default date value"}});}else console.warn("Birthdate is not set in the query result"),s=false,t.birthdate={...t.birthdate,disclose:{message:"Birthdate is not set in the query result"}};return e.birthdate?.gte&&(a.birthdate?.gte===void 0||!areDatesEqual(e.birthdate.gte.expected,a.birthdate.gte))&&(console.warn("Birthdate gte does not match the original query"),s=false,t.birthdate={...t.birthdate,gte:{expected:a.birthdate?.gte,received:e.birthdate.gte.expected,message:"Birthdate gte does not match the original query"}}),e.birthdate?.gt&&(a.birthdate?.gt===void 0||!areDatesEqual(e.birthdate.gt.expected,a.birthdate.gt))&&(console.warn("Birthdate gt does not match the original query"),s=false,t.birthdate={...t.birthdate,gt:{expected:a.birthdate?.gt,received:e.birthdate.gt.expected,message:"Birthdate gt does not match the original query"}}),e.birthdate?.lte&&(a.birthdate?.lte===void 0||!areDatesEqual(e.birthdate.lte.expected,a.birthdate.lte))&&(console.warn("Birthdate lte does not match the original query"),s=false,t.birthdate={...t.birthdate,lte:{expected:a.birthdate?.lte,received:e.birthdate.lte.expected,message:"Birthdate lte does not match the original query"}}),e.birthdate?.lt&&(a.birthdate?.lt===void 0||!areDatesEqual(e.birthdate.lt.expected,a.birthdate.lt))&&(console.warn("Birthdate lt does not match the original query"),s=false,t.birthdate={...t.birthdate,lt:{expected:a.birthdate?.lt,received:e.birthdate.lt.expected,message:"Birthdate lt does not match the original query"}}),e.birthdate?.range&&(a.birthdate?.range===void 0||!areDatesEqual(e.birthdate.range.expected[0],a.birthdate.range[0])||!areDatesEqual(e.birthdate.range.expected[1],a.birthdate.range[1]))&&(console.warn("Birthdate range does not match the original query"),s=false,t.birthdate={...t.birthdate,range:{expected:a.birthdate?.range,received:e.birthdate.range.expected,message:"Birthdate range does not match the original query"}}),{isCorrect:s,queryResultErrors:t}}static checkExpiryDatePublicInputs(i,a,e){let t={},s=true,c=new Date;new Date(c.getFullYear(),c.getMonth(),c.getDate(),0,0,0);let u=getMinDateFromCommittedInputs(i.committedInputs?.compare_expiry??i.committedInputs?.compare_expiry_evm),r=getMaxDateFromCommittedInputs(i.committedInputs?.compare_expiry??i.committedInputs?.compare_expiry_evm);return e.expiry_date?(e.expiry_date.gte&&e.expiry_date.gte.result&&!areDatesEqual(u,e.expiry_date.gte.expected)&&(console.warn("Expiry date is not greater than or equal to the expected expiry date"),s=false,t.expiry_date={...t.expiry_date,gte:{expected:e.expiry_date.gte.expected,received:u,message:"Expiry date is not greater than or equal to the expected expiry date"}}),e.expiry_date.lte&&e.expiry_date.lte.result&&!areDatesEqual(r,e.expiry_date.lte.expected)&&(console.warn("Expiry date is not less than the expected expiry date"),s=false,t.expiry_date={...t.expiry_date,lte:{expected:e.expiry_date.lte.expected,received:r,message:"Expiry date is not less than the expected expiry date"}}),e.expiry_date.range&&e.expiry_date.range.result&&(!areDatesEqual(u,e.expiry_date.range.expected[0])||!areDatesEqual(r,e.expiry_date.range.expected[1]))&&(console.warn("Expiry date is not in the expected range"),s=false,t.expiry_date={...t.expiry_date,range:{expected:e.expiry_date.range.expected,received:[u,r],message:"Expiry date is not in the expected range"}}),!e.expiry_date.lte&&!e.expiry_date.lt&&!e.expiry_date.eq&&!e.expiry_date.range&&!areDatesEqual(r,Y)&&(console.warn("Maximum expiry date should be equal to default date value"),s=false,t.expiry_date={...t.expiry_date,disclose:{expected:`${Y.toISOString()}`,received:`${r.toISOString()}`,message:"Maximum expiry date should be equal to default date value"}}),!e.expiry_date.gte&&!e.expiry_date.gt&&!e.expiry_date.eq&&!e.expiry_date.range&&!areDatesEqual(u,Y)&&(console.warn("Minimum expiry date should be equal to default date value"),s=false,t.expiry_date={...t.expiry_date,disclose:{expected:`${Y.toISOString()}`,received:`${u.toISOString()}`,message:"Minimum expiry date should be equal to default date value"}})):(console.warn("Expiry date is not set in the query result"),s=false,t.expiry_date={...t.expiry_date,disclose:{message:"Expiry date is not set in the query result"}}),e.expiry_date?.gte&&(a.expiry_date?.gte===void 0||!areDatesEqual(e.expiry_date.gte.expected,a.expiry_date.gte))&&(console.warn("Expiry date gte does not match the original query"),s=false,t.expiry_date={...t.expiry_date,gte:{expected:a.expiry_date?.gte,received:e.expiry_date.gte.expected,message:"Expiry date gte does not match the original query"}}),e.expiry_date?.gt&&(a.expiry_date?.gt===void 0||!areDatesEqual(e.expiry_date.gt.expected,a.expiry_date.gt))&&(console.warn("Expiry date gt does not match the original query"),s=false,t.expiry_date={...t.expiry_date,gt:{expected:a.expiry_date?.gt,received:e.expiry_date.gt.expected,message:"Expiry date gt does not match the original query"}}),e.expiry_date?.lte&&(a.expiry_date?.lte===void 0||!areDatesEqual(e.expiry_date.lte.expected,a.expiry_date.lte))&&(console.warn("Expiry date lte does not match the original query"),s=false,t.expiry_date={...t.expiry_date,lte:{expected:a.expiry_date?.lte,received:e.expiry_date.lte.expected,message:"Expiry date lte does not match the original query"}}),e.expiry_date?.lt&&(a.expiry_date?.lt===void 0||!areDatesEqual(e.expiry_date.lt.expected,a.expiry_date.lt))&&(console.warn("Expiry date lt does not match the original query"),s=false,t.expiry_date={...t.expiry_date,lt:{expected:a.expiry_date?.lt,received:e.expiry_date.lt.expected,message:"Expiry date lt does not match the original query"}}),e.expiry_date?.range&&(a.expiry_date?.range===void 0||!areDatesEqual(e.expiry_date.range.expected[0],a.expiry_date.range[0])||!areDatesEqual(e.expiry_date.range.expected[1],a.expiry_date.range[1]))&&(console.warn("Expiry date range does not match the original query"),s=false,t.expiry_date={...t.expiry_date,range:{expected:a.expiry_date?.range,received:e.expiry_date.range.expected,message:"Expiry date range does not match the original query"}}),{isCorrect:s,queryResultErrors:t}}static checkNationalityExclusionPublicInputs(i,a,e){let t={},s=true;a.nationality&&a.nationality.out&&a.nationality.out.result?a.nationality.out.expected?.every(c=>e.includes(c))||(console.warn("Nationality exclusion list does not match the one from the query results"),s=false,t.nationality={...t.nationality,out:{expected:a.nationality.out.expected,received:e,message:"Nationality exclusion list does not match the one from the query results"}}):(!a.nationality||!a.nationality.out)&&(console.warn("Nationality exclusion is not set in the query result"),s=false,t.nationality={...t.nationality,out:{message:"Nationality exclusion is not set in the query result"}});for(let c=1;c<e.length;c++)e[c]<e[c-1]&&(console.warn("The nationality exclusion list has not been sorted, and thus the proof cannot be trusted"),s=false,t.nationality={...t.nationality,out:{message:"The nationality exclusion list has not been sorted, and thus the proof cannot be trusted"}});return a.nationality?.out&&(i.nationality?.out===void 0||a.nationality.out.expected?.length!==i.nationality.out.length||!a.nationality.out.expected?.every(c=>i.nationality.out.includes(c)))&&(console.warn("Nationality exclusion list does not match the original query"),s=false,t.nationality={...t.nationality,out:{expected:i.nationality?.out,received:a.nationality.out.expected,message:"Nationality exclusion list does not match the original query"}}),{isCorrect:s,queryResultErrors:t}}static checkIssuingCountryExclusionPublicInputs(i,a,e){let t={},s=true;a.issuing_country&&a.issuing_country.out&&a.issuing_country.out.result?a.issuing_country.out.expected?.every(c=>e.includes(c))||(console.warn("Issuing country exclusion list does not match the one from the query results"),s=false,t.issuing_country={...t.issuing_country,out:{expected:a.issuing_country.out.expected,received:e,message:"Issuing country exclusion list does not match the one from the query results"}}):(!a.issuing_country||!a.issuing_country.out)&&(console.warn("Issuing country exclusion is not set in the query result"),s=false,t.issuing_country={...t.issuing_country,out:{message:"Issuing country exclusion is not set in the query result"}});for(let c=1;c<e.length;c++)e[c]<e[c-1]&&(console.warn("The issuing country exclusion list has not been sorted, and thus the proof cannot be trusted"),s=false,t.issuing_country={...t.issuing_country,out:{message:"The issuing country exclusion list has not been sorted, and thus the proof cannot be trusted"}});return a.issuing_country?.out&&(i.issuing_country?.out===void 0||a.issuing_country.out.expected?.length!==i.issuing_country.out.length||!a.issuing_country.out.expected?.every(c=>i.issuing_country.out.includes(c)))&&(console.warn("Issuing country exclusion list does not match the original query"),s=false,t.issuing_country={...t.issuing_country,out:{expected:i.issuing_country?.out,received:a.issuing_country.out.expected,message:"Issuing country exclusion list does not match the original query"}}),{isCorrect:s,queryResultErrors:t}}static checkNationalityInclusionPublicInputs(i,a,e){let t={},s=true;return a.nationality&&a.nationality.in&&a.nationality.in.result?a.nationality.in.expected?.every(c=>e.includes(c))||(console.warn("Nationality inclusion list does not match the one from the query results"),s=false,t.nationality={...t.nationality,in:{expected:a.nationality.in.expected,received:e,message:"Nationality inclusion list does not match the one from the query results"}}):(!a.nationality||!a.nationality.in)&&(console.warn("Nationality inclusion is not set in the query result"),s=false,t.nationality={...t.nationality,in:{message:"Nationality inclusion is not set in the query result"}}),a.nationality?.in&&(i.nationality?.in===void 0||a.nationality.in.expected?.length!==i.nationality.in.length||!a.nationality.in.expected?.every(c=>i.nationality.in.includes(c)))&&(console.warn("Nationality inclusion list does not match the original query"),s=false,t.nationality={...t.nationality,in:{expected:i.nationality?.in,received:a.nationality.in.expected,message:"Nationality inclusion list does not match the original query"}}),{isCorrect:s,queryResultErrors:t}}static checkIssuingCountryInclusionPublicInputs(i,a,e){let t={},s=true;return a.issuing_country&&a.issuing_country.in&&a.issuing_country.in.result?a.issuing_country.in.expected?.every(c=>e.includes(c))||(console.warn("Issuing country inclusion list does not match the one from the query results"),s=false,t.issuing_country={...t.issuing_country,in:{expected:a.issuing_country.in.expected,received:e,message:"Issuing country inclusion list does not match the one from the query results"}}):(!a.issuing_country||!a.issuing_country.in)&&(console.warn("Issuing country inclusion is not set in the query result"),s=false,t.issuing_country={...t.issuing_country,in:{message:"Issuing country inclusion is not set in the query result"}}),a.issuing_country?.in&&(i.issuing_country?.in===void 0||a.issuing_country.in.expected?.length!==i.issuing_country.in.length||!a.issuing_country.in.expected?.every(c=>i.issuing_country.in.includes(c)))&&(console.warn("Issuing country inclusion list does not match the original query"),s=false,t.issuing_country={...t.issuing_country,in:{expected:i.issuing_country?.in,received:a.issuing_country.in.expected,message:"Issuing country inclusion list does not match the original query"}}),{isCorrect:s,queryResultErrors:t}}static checkScopeFromDisclosureProof(i,a,e,t,s){let c=true;return i&&getServiceScopeHash(i)!==getServiceScopeFromDisclosureProof(a)&&(console.warn("The proof comes from a different domain than the one expected"),c=false,e[t]||(e[t]={}),e[t].scope={expected:`Scope: ${getServiceScopeHash(i).toString()}`,received:`Scope: ${BigInt(a.publicInputs[1]).toString()}`,message:"The proof comes from a different domain than the one expected"}),s&&getScopeHash(s)!==getServiceSubScopeFromDisclosureProof(a)&&(console.warn("The proof uses a different scope than the one expected"),c=false,e[t]||(e[t]={}),e[t].scope={expected:`Scope: ${getScopeHash(s).toString()}`,received:`Scope: ${BigInt(a.publicInputs[2]).toString()}`,message:"The proof uses a different scope than the one expected"}),{isCorrect:c,queryResultErrors:e}}static async checkCertificateRegistryRoot(i,a,e,t){let s=true;try{await new RegistryClient({chainId:t?11155111:1}).isCertificateRootValid(i)||(console.warn("The ID was signed by an unrecognized root certificate"),s=!1,a[e?"outer":"sig_check_dsc"]||(a[e?"outer":"sig_check_dsc"]={}),a[e?"outer":"sig_check_dsc"].certificate={expected:"A valid root from ZKPassport Registry",received:`Got invalid certificate registry root: ${i}`,message:"The ID was signed by an unrecognized root certificate"});}catch(c){console.warn(c),console.warn("The ID was signed by an unrecognized root certificate"),s=false,a[e?"outer":"sig_check_dsc"]||(a[e?"outer":"sig_check_dsc"]={}),a[e?"outer":"sig_check_dsc"].certificate={expected:"A valid root from ZKPassport Registry",received:`Got invalid certificate registry root: ${i}`,message:"The ID was signed by an unrecognized root certificate"};}return {isCorrect:s,queryResultErrors:a}}static async checkCircuitRegistryRoot(i,a,e){let t=true;try{await new RegistryClient({chainId:e?11155111:1}).isCircuitRootValid(i)||(console.warn("The proof uses unrecognized circuits"),t=!1,a.outer||(a.outer={}),a.outer.circuit={expected:"A valid circuit from ZKPassport Registry",received:`Got invalid circuit registry root: ${i}`,message:"The proof uses an unrecognized circuit"});}catch(s){console.warn(s),console.warn("The proof uses unrecognized circuits"),t=false,a.outer||(a.outer={}),a.outer.circuit={expected:"A valid circuit from ZKPassport Registry",received:`Got invalid circuit registry root: ${i}`,message:"The proof uses an unrecognized circuit"};}return {isCorrect:t,queryResultErrors:a}}static checkBindPublicInputs(i,a,e){let t={},s=true;if(a.bind){let c=[];a.bind.user_address?.toLowerCase().replace("0x","")!==e.user_address?.toLowerCase().replace("0x","")&&(console.warn("Bound user address does not match the one from the query results"),s=false,c.push(`user_address: expected ${a.bind.user_address}, received ${e.user_address}`)),a.bind.chain!==e.chain&&(console.warn("Bound chain id does not match the one from the query results"),s=false,c.push(`chain: expected ${a.bind.chain}, received ${e.chain}`)),a.bind.custom_data?.trim().toLowerCase()!==e.custom_data?.trim().toLowerCase()&&(console.warn("Bound custom data does not match the one from the query results"),s=false,c.push(`custom_data: expected ${a.bind.custom_data}, received ${e.custom_data}`)),c.length>0&&(t.bind={...t.bind,eq:{expected:`${a.bind.user_address}, ${a.bind.chain}, ${a.bind.custom_data}`,received:`${e.user_address}, ${e.chain}, ${e.custom_data}`,message:`Bound data does not match: ${c.join("; ")}`}});}return a.bind&&(i.bind===void 0||a.bind.user_address?.toLowerCase().replace("0x","")!==i.bind.user_address?.toLowerCase().replace("0x","")||a.bind.chain!==i.bind.chain||a.bind.custom_data?.trim().toLowerCase()!==i.bind.custom_data?.trim().toLowerCase())&&(console.warn("Bound data does not match the original query"),s=false,t.bind={...t.bind,eq:{expected:`${i.bind?.user_address}, ${i.bind?.chain}, ${i.bind?.custom_data}`,received:`${a.bind.user_address}, ${a.bind.chain}, ${a.bind.custom_data}`,message:"Bound data does not match the original query"}}),{isCorrect:s,queryResultErrors:t}}static async checkSanctionsExclusionPublicInputs(i,a,e,t){let s={},c=true;if(a.sanctions&&a.sanctions.passed){let g=await t.getRoot();e.rootHash!==g&&(console.warn("Invalid sanctions registry root"),c=false,s.sanctions={...s.sanctions,eq:{expected:g,received:e.rootHash,message:"Invalid sanctions registry root"}}),a.sanctions.isStrict!==e.isStrict&&(console.warn("Invalid sanctions strict mode"),c=false,s.sanctions={...s.sanctions,eq:{expected:a.sanctions.isStrict.toString(),received:e.isStrict.toString(),message:"Invalid sanctions strict mode"}});}return a.sanctions&&(i.sanctions===void 0||a.sanctions.isStrict!==(i.sanctions.strict??false))&&(console.warn("Sanctions config does not match the original query"),c=false,s.sanctions={...s.sanctions,eq:{expected:`strict: ${i.sanctions?.strict??false}`,received:`strict: ${a.sanctions.isStrict}`,message:"Sanctions config does not match the original query"}}),{isCorrect:c,queryResultErrors:s}}static async checkFacematchPublicInputs(i,a,e){let t=true,s={};if(a.facematch&&a.facematch.passed){e.rootKeyLeaf!==ce&&e.rootKeyLeaf!==fe&&e.rootKeyLeaf!==me&&(console.warn("Invalid facematch root key hash"),t=false,s.facematch={...s.facematch,eq:{expected:`${ce} (iOS) or ${fe} (Android) or ${me} (Android)`,received:e.rootKeyLeaf,message:"Invalid facematch root key hash"}});let c="production";e.environment!==c&&(console.warn("Invalid facematch environment, it should be production"),t=false,s.facematch={...s.facematch,eq:{expected:c,received:e.environment,message:"Invalid facematch environment, it should be production"}}),e.appIdHash!==re&&e.appIdHash!==de&&(console.warn("Invalid facematch app id hash, the attestation should be coming from the ZKPassport app"),t=false,s.facematch={...s.facematch,eq:{expected:`${re} (iOS) or ${de} (Android)`,received:e.appIdHash,message:"Invalid facematch app id hash, the attestation should be coming from the ZKPassport app"}}),(e.mode!==a.facematch?.mode||e.mode!==i.facematch?.mode)&&(console.warn("Invalid facematch mode"),t=false,s.facematch={...s.facematch,eq:{expected:i.facematch?.mode,received:e.mode,message:"Invalid facematch mode"}});}return {isCorrect:t,queryResultErrors:s}}static async checkCurrentDate(i,a,e,t){let s=new Date,c=new Date(s.getFullYear(),s.getMonth(),s.getDate(),0,0,0,0),g=getCurrentDateFromDisclosureProof(a),u=c.getTime()-g.getTime(),r=e?e*1e3:604800*1e3,f=true;return u>=r&&(console.warn("The date used to check the validity of the ID falls out of the validity period"),f=false,t[i]||(t[i]={}),t[i].date={expected:`Difference: ${e} seconds`,received:`Difference: ${Math.round(u/1e3)} seconds`,message:"The date used to check the validity of the ID falls out of the validity period"}),{isCorrect:f,queryResultErrors:t}}static async checkPublicInputs(i,a,e,t,s,c,g,u){let r,f,o=true,k,A,N=new Date,B=new Date(N.getFullYear(),N.getMonth(),N.getDate(),0,0,0,0),n={},$=a.sort((l,d)=>{let m=["sig_check_dsc","sig_check_id_data","data_check_integrity","disclose_bytes","compare_age","compare_birthdate","compare_expiry","exclusion_check_nationality","inclusion_check_nationality","exclusion_check_issuing_country","inclusion_check_issuing_country","bind","exclusion_check_sanctions","facematch"],p=y=>{let x=y.name||"";return m.findIndex(T=>x.startsWith(T))};return p(l)-p(d)});for(let l of $){let d=getProofData(l.proof,getNumberOfPublicInputs(l.name));if(l.name?.startsWith("outer")){let m=l.name?.startsWith("outer_evm"),p=getCertificateRegistryRootFromOuterProof(d),{isCorrect:y,queryResultErrors:x}=await this.checkCertificateRegistryRoot(p.toString(16),n,true,u);o=o&&y,n={...n,...x};let T=getCircuitRegistryRootFromOuterProof(d),{isCorrect:I,queryResultErrors:w}=await this.checkCircuitRegistryRoot(T.toString(16),n,u);o=o&&I,n={...n,...w};let S=getCurrentDateFromOuterProof(d),P=B.getTime()-S.getTime(),j=s?s*1e3:604800*1e3;P>=j&&(console.warn("The date used to check the validity of the ID is older than the validity period"),o=false,n.outer={...n.outer,date:{expected:`Difference: ${s} seconds`,received:`Difference: ${Math.round(P/1e3)} seconds`,message:"The date used to check the validity of the ID is older than the validity period"}});let _=getParamCommitmentsFromOuterProof(d),h=l.committedInputs,Q=Object.keys(h||{});if(Q.length!==_.length&&(console.warn("The proof does not verify all the requested conditions and information"),o=false,n.outer={...n.outer,commitment:{expected:`Number of parameter commitments: ${_.length}`,received:`Number of disclosure proofs provided: ${Q.length}`,message:"The proof does not verify all the requested conditions and information"}}),i&&getServiceScopeHash(i)!==getScopeFromOuterProof(d)&&(console.warn("The proof comes from a different domain than the one expected"),o=false,n.outer={...n.outer,scope:{expected:`Scope: ${getServiceScopeHash(i).toString()}`,received:`Scope: ${getScopeFromOuterProof(d).toString()}`,message:"The proof comes from a different domain than the one expected"}}),c&&getScopeHash(c)!==getSubscopeFromOuterProof(d)&&(console.warn("The proof uses a different scope than the one expected"),o=false,n.outer={...n.outer,scope:{expected:`Scope: ${getScopeHash(c).toString()}`,received:`Scope: ${getSubscopeFromOuterProof(d).toString()}`,message:"The proof uses a different scope than the one expected"}}),h?.compare_age||h?.compare_age_evm){let b=h?.compare_age??h?.compare_age_evm,C=m?await getAgeEVMParameterCommitment(b.minAge,b.maxAge):await getAgeParameterCommitment(b.minAge,b.maxAge);_.includes(C)||(console.warn("This proof does not verify the age"),o=false,n.age={...n.age,commitment:{expected:`Age parameter commitment: ${C.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the age"}});let{isCorrect:D,queryResultErrors:E}=this.checkAgePublicInputs(l,e,t);o=o&&D,n={...n,...E};}if(h?.compare_birthdate||h?.compare_birthdate_evm){let b=h?.compare_birthdate??h?.compare_birthdate_evm,C=m?await getDateEVMParameterCommitment(ProofType.BIRTHDATE,b.minDateTimestamp,b.maxDateTimestamp,0):await getDateParameterCommitment(ProofType.BIRTHDATE,b.minDateTimestamp,b.maxDateTimestamp,0);_.includes(C)||(console.warn("This proof does not verify the birthdate"),o=false,n.birthdate={...n.birthdate,commitment:{expected:`Birthdate parameter commitment: ${C.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the birthdate"}});let{isCorrect:D,queryResultErrors:E}=this.checkBirthdatePublicInputs(l,e,t);o=o&&D,n={...n,...E};}if(h?.compare_expiry||h?.compare_expiry_evm){let b=h?.compare_expiry??h?.compare_expiry_evm,C=m?await getDateEVMParameterCommitment(ProofType.EXPIRY_DATE,b.minDateTimestamp,b.maxDateTimestamp):await getDateParameterCommitment(ProofType.EXPIRY_DATE,b.minDateTimestamp,b.maxDateTimestamp);_.includes(C)||(console.warn("This proof does not verify the expiry date"),o=false,n.expiry_date={...n.expiry_date,commitment:{expected:`Expiry date parameter commitment: ${C.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the expiry date"}});let{isCorrect:D,queryResultErrors:E}=this.checkExpiryDatePublicInputs(l,e,t);o=o&&D,n={...n,...E};}if(h?.disclose_bytes||h?.disclose_bytes_evm){let b=h?.disclose_bytes??h?.disclose_bytes_evm,C=m?await getDiscloseEVMParameterCommitment(b.discloseMask,b.disclosedBytes):await getDiscloseParameterCommitment(b.discloseMask,b.disclosedBytes);_.includes(C)||(console.warn("This proof does not verify any of the data disclosed"),o=false,n.disclose={...n.disclose,commitment:{expected:`Disclosure parameter commitment: ${C.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify any of the data disclosed"}});let{isCorrect:D,queryResultErrors:E}=this.checkDiscloseBytesPublicInputs(l,e,t);o=o&&D,n={...n,...E};}if(h?.inclusion_check_nationality||h?.inclusion_check_nationality_evm){let b=h?.inclusion_check_nationality??h?.inclusion_check_nationality_evm,C=m?await getCountryEVMParameterCommitment(ProofType.NATIONALITY_INCLUSION,b.countries):await getCountryParameterCommitment(ProofType.NATIONALITY_INCLUSION,b.countries);_.includes(C)||(console.warn("This proof does not verify the inclusion of the nationality"),o=false,n.nationality={...n.nationality,commitment:{expected:`Nationality parameter commitment: ${C.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the inclusion of the nationality"}});let D=b.countries,{isCorrect:E,queryResultErrors:q}=this.checkNationalityInclusionPublicInputs(e,t,D);o=o&&E,n={...n,...q};}if(h?.inclusion_check_issuing_country||h?.inclusion_check_issuing_country_evm){let b=h?.inclusion_check_issuing_country??h?.inclusion_check_issuing_country_evm,C=m?await getCountryEVMParameterCommitment(ProofType.ISSUING_COUNTRY_INCLUSION,b.countries):await getCountryParameterCommitment(ProofType.ISSUING_COUNTRY_INCLUSION,b.countries);_.includes(C)||(console.warn("This proof does not verify the inclusion of the issuing country"),o=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Issuing country parameter commitment: ${C.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the inclusion of the issuing country"}});let D=b.countries,{isCorrect:E,queryResultErrors:q}=this.checkIssuingCountryInclusionPublicInputs(e,t,D);o=o&&E,n={...n,...q};}if(h?.exclusion_check_nationality||h?.exclusion_check_nationality_evm){let b=h?.exclusion_check_nationality??h?.exclusion_check_nationality_evm,C=m?await getCountryEVMParameterCommitment(ProofType.NATIONALITY_EXCLUSION,b.countries):await getCountryParameterCommitment(ProofType.NATIONALITY_EXCLUSION,b.countries);_.includes(C)||(console.warn("This proof does not verify the exclusion of the nationality"),o=false,n.nationality={...n.nationality,commitment:{expected:`Nationality parameter commitment: ${C.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the exclusion of the nationality"}});let D=b.countries,{isCorrect:E,queryResultErrors:q}=this.checkNationalityExclusionPublicInputs(e,t,D);o=o&&E,n={...n,...q};}if(h?.exclusion_check_issuing_country||h?.exclusion_check_issuing_country_evm){let b=h?.exclusion_check_issuing_country??h?.exclusion_check_issuing_country_evm,C=m?await getCountryEVMParameterCommitment(ProofType.ISSUING_COUNTRY_EXCLUSION,b.countries):await getCountryParameterCommitment(ProofType.ISSUING_COUNTRY_EXCLUSION,b.countries);_.includes(C)||(console.warn("This proof does not verify the exclusion of the issuing country"),o=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Issuing country parameter commitment: ${C.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the exclusion of the issuing country"}});let D=b.countries,{isCorrect:E,queryResultErrors:q}=this.checkIssuingCountryExclusionPublicInputs(e,t,D);o=o&&E,n={...n,...q};}if(h?.bind||h?.bind_evm){let b=h?.bind??h?.bind_evm,C=m?await getBindEVMParameterCommitment(formatBoundData(b.data)):await getBindParameterCommitment(formatBoundData(b.data));_.includes(C)||(console.warn("This proof does not verify the bound data"),o=false,n.bind={...n.bind,commitment:{expected:`Bind parameter commitment: ${C.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the bound data"}});let{isCorrect:D,queryResultErrors:E}=this.checkBindPublicInputs(e,t,b.data);o=o&&D,n={...n,...E};}if(h?.exclusion_check_sanctions||h?.exclusion_check_sanctions_evm){let b=await SanctionsBuilder.create(),C=h?.exclusion_check_sanctions??h?.exclusion_check_sanctions_evm,D=m?await b.getSanctionsEvmParameterCommitment(C.isStrict):await b.getSanctionsParameterCommitment(C.isStrict);_.includes(D)||(console.warn("This proof does not verify the exclusion from the sanction lists"),o=false,n.sanctions={...n.sanctions,commitment:{expected:`Sanctions parameter commitment: ${D.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the exclusion from the sanction lists"}});let{isCorrect:E,queryResultErrors:q}=await this.checkSanctionsExclusionPublicInputs(e,t,C,b);o=o&&E,n={...n,...q};}if(h?.facematch||h?.facematch_evm){let b=h?.facematch??h?.facematch_evm,C=m?await getFacematchEvmParameterCommitment(BigInt(b.rootKeyLeaf),b.environment==="development"?0n:1n,BigInt(b.appIdHash),b.mode==="regular"?1n:2n):await getFacematchParameterCommitment(BigInt(b.rootKeyLeaf),b.environment==="development"?0n:1n,BigInt(b.appIdHash),b.mode==="regular"?1n:2n);_.includes(C)||(console.warn("This proof does not verify FaceMatch"),o=false,n.facematch={...n.facematch,commitment:{expected:`Facematch parameter commitment: ${C.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify FaceMatch"}});let{isCorrect:D,queryResultErrors:E}=await this.checkFacematchPublicInputs(e,t,b);o=o&&D,n={...n,...E};}k=getNullifierFromOuterProof(d).toString(10),A=getNullifierTypeFromOuterProof(d);}else if(l.name?.startsWith("sig_check_dsc")){f=getCommitmentFromDSCProof(d);let m=getMerkleRootFromDSCProof(d),{isCorrect:p,queryResultErrors:y}=await this.checkCertificateRegistryRoot(m.toString(16),n,false,u);o=o&&p,n={...n,...y};}else if(l.name?.startsWith("sig_check_id_data"))r=getCommitmentInFromIDDataProof(d),r!==f&&(console.warn("Failed to check the link between the certificate signature and ID signature"),o=false,n.sig_check_id_data={...n.sig_check_id_data,commitment:{expected:`Commitment: ${f?.toString()||"undefined"}`,received:`Commitment: ${r?.toString()||"undefined"}`,message:"Failed to check the link between the certificate signature and ID signature"}}),f=getCommitmentOutFromIDDataProof(d);else if(l.name?.startsWith("data_check_integrity"))r=getCommitmentInFromIntegrityProof(d),r!==f&&(console.warn("Failed to check the link between the ID signature and the data signed"),o=false,n.data_check_integrity={...n.data_check_integrity,commitment:{expected:`Commitment: ${f?.toString()||"undefined"}`,received:`Commitment: ${r?.toString()||"undefined"}`,message:"Failed to check the link between the ID signature and the data signed"}}),f=getCommitmentOutFromIntegrityProof(d);else if(l.name==="disclose_bytes"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the data to disclose"),o=false,n.disclose={...n.disclose,commitment:{expected:`Commitment: ${f?.toString()||"undefined"}`,received:`Commitment: ${r?.toString()||"undefined"}`,message:"Failed to check the link between the validity of the ID and the data to disclose"}});let m=getParameterCommitmentFromDisclosureProof(d),p=await getDiscloseParameterCommitment((l.committedInputs?.disclose_bytes).discloseMask,(l.committedInputs?.disclose_bytes).disclosedBytes);m!==p&&(console.warn("The disclosed data does not match the data committed by the proof"),o=false,n.disclose={...n.disclose,commitment:{expected:`Commitment: ${p}`,received:`Commitment: ${m}`,message:"The disclosed data does not match the data committed by the proof"}});let{isCorrect:y,queryResultErrors:x}=this.checkScopeFromDisclosureProof(i,d,n,"disclose",c);o=o&&y,n={...n,...x};let{isCorrect:T,queryResultErrors:I}=this.checkDiscloseBytesPublicInputs(l,e,t);o=o&&T&&y,n={...n,...I,...x};let{isCorrect:w,queryResultErrors:S}=await this.checkCurrentDate("disclose",d,s??604800,n);o=o&&w,n={...n,...S},k=getNullifierFromDisclosureProof(d).toString(10),A=getNullifierTypeFromDisclosureProof(d);}else if(l.name==="compare_age"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the age derived from it"),o=false,n.age={...n.age,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the age derived from it"}});let m=getParameterCommitmentFromDisclosureProof(d),p=l.committedInputs?.compare_age,y=await getAgeParameterCommitment(p.minAge,p.maxAge);m!==y&&(console.warn("The conditions for the age check do not match the conditions checked by the proof"),o=false,n.age={...n.age,commitment:{expected:`Commitment: ${y}`,received:`Commitment: ${m}`,message:"The conditions for the age check do not match the conditions checked by the proof"}});let{isCorrect:x,queryResultErrors:T}=this.checkScopeFromDisclosureProof(i,d,n,"age",c),{isCorrect:I,queryResultErrors:w}=this.checkAgePublicInputs(l,e,t);o=o&&I&&x,n={...n,...w,...T};let{isCorrect:S,queryResultErrors:P}=await this.checkCurrentDate("age",d,s??604800,n);o=o&&S,n={...n,...P},k=getNullifierFromDisclosureProof(d).toString(10),A=getNullifierTypeFromDisclosureProof(d);}else if(l.name==="compare_birthdate"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the birthdate derived from it"),o=false,n.birthdate={...n.birthdate,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the birthdate derived from it"}});let m=getParameterCommitmentFromDisclosureProof(d),p=l.committedInputs?.compare_birthdate,y=await getDateParameterCommitment(ProofType.BIRTHDATE,p.minDateTimestamp,p.maxDateTimestamp,0);m!==y&&(console.warn("The conditions for the birthdate check do not match the conditions checked by the proof"),o=false,n.birthdate={...n.birthdate,commitment:{expected:`Commitment: ${y}`,received:`Commitment: ${m}`,message:"The conditions for the birthdate check do not match the conditions checked by the proof"}});let{isCorrect:x,queryResultErrors:T}=this.checkScopeFromDisclosureProof(i,d,n,"birthdate",c),{isCorrect:I,queryResultErrors:w}=this.checkBirthdatePublicInputs(l,e,t);o=o&&I&&x,n={...n,...w,...T};let{isCorrect:S,queryResultErrors:P}=await this.checkCurrentDate("birthdate",d,s??604800,n);o=o&&S,n={...n,...P},k=getNullifierFromDisclosureProof(d).toString(10),A=getNullifierTypeFromDisclosureProof(d);}else if(l.name==="compare_expiry"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and its expiry date"),o=false,n.expiry_date={...n.expiry_date,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and its expiry date"}});let m=getParameterCommitmentFromDisclosureProof(d),p=l.committedInputs?.compare_expiry,y=await getDateParameterCommitment(ProofType.EXPIRY_DATE,p.minDateTimestamp,p.maxDateTimestamp);m!==y&&(console.warn("The conditions for the expiry date check do not match the conditions checked by the proof"),o=false,n.expiry_date={...n.expiry_date,commitment:{expected:`Commitment: ${y}`,received:`Commitment: ${m}`,message:"The conditions for the expiry date check do not match the conditions checked by the proof"}});let{isCorrect:x,queryResultErrors:T}=this.checkScopeFromDisclosureProof(i,d,n,"expiry_date",c),{isCorrect:I,queryResultErrors:w}=this.checkExpiryDatePublicInputs(l,e,t);o=o&&I&&x,n={...n,...w,...T};let{isCorrect:S,queryResultErrors:P}=await this.checkCurrentDate("expiry_date",d,s??604800,n);o=o&&S,n={...n,...P},k=getNullifierFromDisclosureProof(d).toString(10),A=getNullifierTypeFromDisclosureProof(d);}else if(l.name==="exclusion_check_nationality"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the nationality exclusion check"),o=false,n.nationality={...n.nationality,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the nationality exclusion check"}});let m=(l.committedInputs?.exclusion_check_nationality).countries,p=getParameterCommitmentFromDisclosureProof(d),y=await getCountryParameterCommitment(ProofType.NATIONALITY_EXCLUSION,m,true);p!==y&&(console.warn("The committed country list for the exclusion check does not match the one from the proof"),o=false,n.nationality={...n.nationality,commitment:{expected:`Commitment: ${y}`,received:`Commitment: ${p}`,message:"The committed country list for the exclusion check does not match the one from the proof"}});let{isCorrect:x,queryResultErrors:T}=this.checkScopeFromDisclosureProof(i,d,n,"nationality",c),{isCorrect:I,queryResultErrors:w}=this.checkNationalityExclusionPublicInputs(e,t,m);o=o&&I&&x,n={...n,...w,...T};let{isCorrect:S,queryResultErrors:P}=await this.checkCurrentDate("nationality",d,s??604800,n);o=o&&S,n={...n,...P},k=getNullifierFromDisclosureProof(d).toString(10),A=getNullifierTypeFromDisclosureProof(d);}else if(l.name==="exclusion_check_issuing_country"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the issuing country exclusion check"),o=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the issuing country exclusion check"}});let m=(l.committedInputs?.exclusion_check_issuing_country).countries,p=getParameterCommitmentFromDisclosureProof(d),y=await getCountryParameterCommitment(ProofType.ISSUING_COUNTRY_EXCLUSION,m,true);p!==y&&(console.warn("The committed country list for the issuing country exclusion check does not match the one from the proof"),o=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Commitment: ${y}`,received:`Commitment: ${p}`,message:"The committed country list for the issuing country exclusion check does not match the one from the proof"}});let{isCorrect:x,queryResultErrors:T}=this.checkScopeFromDisclosureProof(i,d,n,"issuing_country",c),{isCorrect:I,queryResultErrors:w}=this.checkIssuingCountryExclusionPublicInputs(e,t,m);o=o&&I&&x,n={...n,...w,...T};let{isCorrect:S,queryResultErrors:P}=await this.checkCurrentDate("issuing_country",d,s??604800,n);o=o&&S,n={...n,...P},k=getNullifierFromDisclosureProof(d).toString(10),A=getNullifierTypeFromDisclosureProof(d);}else if(l.name==="inclusion_check_nationality"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the nationality inclusion check"),o=false,n.nationality={...n.nationality,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the nationality inclusion check"}});let m=(l.committedInputs?.inclusion_check_nationality).countries,p=getParameterCommitmentFromDisclosureProof(d),y=await getCountryParameterCommitment(ProofType.NATIONALITY_INCLUSION,m,false);p!==y&&(console.warn("The committed country list for the nationality inclusion check does not match the one from the proof"),o=false,n.nationality={...n.nationality,commitment:{expected:`Commitment: ${y}`,received:`Commitment: ${p}`,message:"The committed country list for the nationality inclusion check does not match the one from the proof"}});let{isCorrect:x,queryResultErrors:T}=this.checkScopeFromDisclosureProof(i,d,n,"nationality",c),{isCorrect:I,queryResultErrors:w}=this.checkNationalityInclusionPublicInputs(e,t,m);o=o&&I&&x,n={...n,...w,...T};let{isCorrect:S,queryResultErrors:P}=await this.checkCurrentDate("nationality",d,s??604800,n);o=o&&S,n={...n,...P},k=getNullifierFromDisclosureProof(d).toString(10),A=getNullifierTypeFromDisclosureProof(d);}else if(l.name==="inclusion_check_issuing_country"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the issuing country inclusion check"),o=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the issuing country inclusion check"}});let m=(l.committedInputs?.inclusion_check_issuing_country).countries,p=getParameterCommitmentFromDisclosureProof(d),y=await getCountryParameterCommitment(ProofType.ISSUING_COUNTRY_INCLUSION,m,false);p!==y&&(console.warn("The committed country list for the issuing country inclusion check does not match the one from the proof"),o=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Commitment: ${y}`,received:`Commitment: ${p}`,message:"The committed country list for the issuing country inclusion check does not match the one from the proof"}});let{isCorrect:x,queryResultErrors:T}=this.checkScopeFromDisclosureProof(i,d,n,"issuing_country",c),{isCorrect:I,queryResultErrors:w}=this.checkIssuingCountryInclusionPublicInputs(e,t,m);o=o&&I&&x,n={...n,...w,...T};let{isCorrect:S,queryResultErrors:P}=await this.checkCurrentDate("issuing_country",d,s??604800,n);o=o&&S,n={...n,...P},k=getNullifierFromDisclosureProof(d).toString(10),A=getNullifierTypeFromDisclosureProof(d);}else if(l.name==="bind"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the bound data"),o=false,n.bind={...n.bind,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the bound data"}});let m=l.committedInputs?.bind,p=getParameterCommitmentFromDisclosureProof(d),y=await getBindParameterCommitment(formatBoundData(m.data));p!==y&&(console.warn("The bound data does not match the one from the proof"),o=false,n.bind={...n.bind,commitment:{expected:`Commitment: ${y}`,received:`Commitment: ${p}`,message:"The bound data does not match the one from the proof"}});let{isCorrect:x,queryResultErrors:T}=this.checkScopeFromDisclosureProof(i,d,n,"bind",c),{isCorrect:I,queryResultErrors:w}=this.checkBindPublicInputs(e,t,m.data);o=o&&I&&x,n={...n,...w,...T};let{isCorrect:S,queryResultErrors:P}=await this.checkCurrentDate("bind",d,s??604800,n);o=o&&S,n={...n,...P},k=getNullifierFromDisclosureProof(d).toString(10),A=getNullifierTypeFromDisclosureProof(d);}else if(l.name==="exclusion_check_sanctions"){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the sanctions exclusion check"),o=false,n.sanctions={...n.sanctions,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the sanctions exclusion check"}});let m=await SanctionsBuilder.create(),p=l.committedInputs?.exclusion_check_sanctions,y=await m.getSanctionsParameterCommitment(p.isStrict),x=getParameterCommitmentFromDisclosureProof(d);x!==y&&(console.warn("The sanction lists check against do not match the sanction lists from the proof"),o=false,n.sanctions={...n.sanctions,commitment:{expected:`Commitment: ${y.toString()}`,received:`Commitment: ${x.toString()}`,message:"The sanction lists check against do not match the sanction lists from the proof"}});let{isCorrect:T,queryResultErrors:I}=this.checkScopeFromDisclosureProof(i,d,n,"sanctions",c),{isCorrect:w,queryResultErrors:S}=await this.checkSanctionsExclusionPublicInputs(e,t,p,m);o=o&&w&&T,n={...n,...S,...I};let{isCorrect:P,queryResultErrors:j}=await this.checkCurrentDate("sanctions",d,s??604800,n);o=o&&P,n={...n,...j},k=getNullifierFromDisclosureProof(d).toString(10),A=getNullifierTypeFromDisclosureProof(d);}else if(l.name?.startsWith("facematch")&&!l.name?.endsWith("_evm")){r=getCommitmentInFromDisclosureProof(d),r!==f&&(console.warn("Failed to check the link between the validity of the ID and the facematch check"),o=false,n.facematch={...n.facematch,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${r}`,message:"Failed to check the link between the validity of the ID and the facematch check"}});let m=l.committedInputs?.facematch,p=getParameterCommitmentFromDisclosureProof(d),y=await getFacematchParameterCommitment(BigInt(m.rootKeyLeaf),m.environment==="development"?0n:1n,BigInt(m.appIdHash),m.mode==="regular"?1n:2n);p!==y&&(console.warn("The FaceMatch verification does not match the ones from the proof"),o=false,n.facematch={...n.facematch,commitment:{expected:`Commitment: ${y.toString()}`,received:`Commitment: ${p.toString()}`,message:"The FaceMatch verification does not match the ones from the proof"}});let{isCorrect:x,queryResultErrors:T}=this.checkScopeFromDisclosureProof(i,d,n,"facematch",c),{isCorrect:I,queryResultErrors:w}=await this.checkFacematchPublicInputs(e,t,m);o=o&&I&&x,n={...n,...w,...T};let{isCorrect:S,queryResultErrors:P}=await this.checkCurrentDate("facematch",d,s??604800,n);o=o&&S,n={...n,...P};}}if(o&&A&&(A===NullifierType.SALTED||A===NullifierType.SALTED_MOCK))try{let l=await getOprfPublicKey(g??OPRF_DEFAULT_KEY_ID),d=await hashOprfPublicKey(l),m=$.find(p=>p.name&&!p.name.startsWith("sig_check_")&&!p.name.startsWith("data_check_")&&!p.name.startsWith("outer")&&!p.name.startsWith("facematch"));if(m){let p=getProofData(m.proof,getNumberOfPublicInputs(m.name));getOprfPkHashFromDisclosureProof(p)!==d&&(console.warn("OPRF public key hash mismatch: proof uses an unknown OPRF key"),o=!1);}}catch(l){console.warn("Failed to verify OPRF public key:",l),o=false;}return {isCorrect:o,uniqueIdentifier:k,uniqueIdentifierType:A,queryResultErrors:n}}};var Ae={abi:[{type:"constructor",inputs:[{name:"_admin",type:"address",internalType:"address"},{name:"_guardian",type:"address",internalType:"address"},{name:"_rootRegistry",type:"address",internalType:"contract RootRegistry"},{name:"_defaultOPRFPubKeyHash",type:"bytes32",internalType:"bytes32"}],stateMutability:"nonpayable"},{type:"function",name:"addHelper",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"},{name:"newHelper",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"addSubVerifier",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"},{name:"subVerifier",type:"address",internalType:"contract SubVerifier"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"admin",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"config",inputs:[{name:"key",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"value",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"defaultOPRFPubKeyHash",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"getHelper",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"getSubVerifier",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"guardian",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"helperCount",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"helpers",inputs:[{name:"",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"address",internalType:"contract VerifierHelper"}],stateMutability:"view"},{type:"function",name:"pause",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"paused",inputs:[],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"removeHelper",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"removeSubVerifier",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"rootRegistry",inputs:[],outputs:[{name:"",type:"address",internalType:"contract RootRegistry"}],stateMutability:"view"},{type:"function",name:"setDefaultOPRFPubKeyHash",inputs:[{name:"newHash",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setGuardian",inputs:[{name:"newGuardian",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"subverifierCount",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"subverifiers",inputs:[{name:"",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"address",internalType:"contract SubVerifier"}],stateMutability:"view"},{type:"function",name:"transferAdmin",inputs:[{name:"newAdmin",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"unpause",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"updateConfig",inputs:[{name:"key",type:"bytes32",internalType:"bytes32"},{name:"value",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"updateHelper",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"},{name:"newHelper",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"updateSubVerifier",inputs:[{name:"version",type:"bytes32",internalType:"bytes32"},{name:"newSubVerifier",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"verify",inputs:[{name:"params",type:"tuple",internalType:"struct ProofVerificationParams",components:[{name:"version",type:"bytes32",internalType:"bytes32"},{name:"proofVerificationData",type:"tuple",internalType:"struct ProofVerificationData",components:[{name:"vkeyHash",type:"bytes32",internalType:"bytes32"},{name:"proof",type:"bytes",internalType:"bytes"},{name:"publicInputs",type:"bytes32[]",internalType:"bytes32[]"}]},{name:"committedInputs",type:"bytes",internalType:"bytes"},{name:"serviceConfig",type:"tuple",internalType:"struct ServiceConfig",components:[{name:"validityPeriodInSeconds",type:"uint256",internalType:"uint256"},{name:"domain",type:"string",internalType:"string"},{name:"scope",type:"string",internalType:"string"},{name:"devMode",type:"bool",internalType:"bool"}]}]}],outputs:[{name:"valid",type:"bool",internalType:"bool"},{name:"uniqueIdentifier",type:"bytes32",internalType:"bytes32"},{name:"helper",type:"address",internalType:"contract VerifierHelper"}],stateMutability:"view"},{type:"event",name:"AdminUpdated",inputs:[{name:"oldAdmin",type:"address",indexed:true,internalType:"address"},{name:"newAdmin",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"ConfigUpdated",inputs:[{name:"key",type:"bytes32",indexed:true,internalType:"bytes32"},{name:"oldValue",type:"bytes32",indexed:false,internalType:"bytes32"},{name:"newValue",type:"bytes32",indexed:false,internalType:"bytes32"}],anonymous:false},{type:"event",name:"DefaultOPRFPubKeyHashUpdated",inputs:[{name:"oldHash",type:"bytes32",indexed:false,internalType:"bytes32"},{name:"newHash",type:"bytes32",indexed:false,internalType:"bytes32"}],anonymous:false},{type:"event",name:"GuardianUpdated",inputs:[{name:"oldGuardian",type:"address",indexed:true,internalType:"address"},{name:"newGuardian",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"HelperAdded",inputs:[{name:"version",type:"bytes32",indexed:true,internalType:"bytes32"},{name:"helper",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"HelperRemoved",inputs:[{name:"version",type:"bytes32",indexed:true,internalType:"bytes32"},{name:"helper",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"HelperUpdated",inputs:[{name:"version",type:"bytes32",indexed:true,internalType:"bytes32"},{name:"oldHelper",type:"address",indexed:true,internalType:"address"},{name:"newHelper",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"PausedStatusChanged",inputs:[{name:"paused",type:"bool",indexed:false,internalType:"bool"}],anonymous:false},{type:"event",name:"RootRegistryUpdated",inputs:[{name:"oldRootRegistry",type:"address",indexed:true,internalType:"address"},{name:"newRootRegistry",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"RootVerifierDeployed",inputs:[{name:"admin",type:"address",indexed:false,internalType:"address"},{name:"guardian",type:"address",indexed:false,internalType:"address"},{name:"rootRegistry",type:"address",indexed:false,internalType:"address"}],anonymous:false},{type:"event",name:"SubVerifierAdded",inputs:[{name:"version",type:"bytes32",indexed:true,internalType:"bytes32"},{name:"subVerifier",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"SubVerifierRemoved",inputs:[{name:"version",type:"bytes32",indexed:true,internalType:"bytes32"},{name:"subVerifier",type:"address",indexed:true,internalType:"address"}],anonymous:false},{type:"event",name:"SubVerifierUpdated",inputs:[{name:"version",type:"bytes32",indexed:true,internalType:"bytes32"},{name:"oldSubVerifier",type:"address",indexed:true,internalType:"address"},{name:"newSubVerifier",type:"address",indexed:true,internalType:"address"}],anonymous:false}]};var J=class{static getDetails(){return {...{functionName:"verify",abi:Ae.abi},address:"0x1D000001000EFD9a6371f4d90bB8920D5431c0D8"}}static getParameters({proof:i,validityPeriodInSeconds:a=604800,domain:e,scope:t,devMode:s=false}){if(!i.name?.startsWith("outer_evm"))throw new Error("This proof cannot be verified on an EVM chain. Please make sure to use the `compressed-evm` mode.");let c=getProofData(i.proof,getNumberOfPublicInputs(i.name)),g=[],u=[];for(let n in i.committedInputs){let $=getCommittedInputCount(n),l=n;g.push({circuitName:l,count:$});let d="";if(l==="inclusion_check_issuing_country_evm"||l==="inclusion_check_nationality_evm"||l==="exclusion_check_issuing_country_evm"||l==="exclusion_check_nationality_evm"){let p=i.committedInputs[l].countries;(l==="exclusion_check_issuing_country_evm"||l==="exclusion_check_nationality_evm")&&p.sort((x,T)=>x.localeCompare(T));let y=(()=>{switch(l){case "exclusion_check_issuing_country_evm":return ProofType.ISSUING_COUNTRY_EXCLUSION;case "exclusion_check_nationality_evm":return ProofType.NATIONALITY_EXCLUSION;case "inclusion_check_issuing_country_evm":return ProofType.ISSUING_COUNTRY_INCLUSION;case "inclusion_check_nationality_evm":return ProofType.NATIONALITY_INCLUSION}})();d=y.toString(16).padStart(2,"0")+ProofTypeLength[y].evm.toString(16).padStart(4,"0")+rightPadArrayWithZeros(p.map(x=>Array.from(new TextEncoder().encode(x))).flat(),600).map(x=>x.toString(16).padStart(2,"0")).join("");}else if(l==="compare_age_evm"){let m=i.committedInputs[l];d=ProofType.AGE.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.AGE].evm.toString(16).padStart(4,"0")+m.minAge.toString(16).padStart(2,"0")+m.maxAge.toString(16).padStart(2,"0");}else if(l==="compare_birthdate_evm"){let m=i.committedInputs[l],p=Array.from(numberToBytesBE(m.minDateTimestamp,8)),y=Array.from(numberToBytesBE(m.maxDateTimestamp,8));d=ProofType.BIRTHDATE.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.BIRTHDATE].evm.toString(16).padStart(4,"0")+p.map(x=>x.toString(16).padStart(2,"0")).join("")+y.map(x=>x.toString(16).padStart(2,"0")).join("");}else if(l==="compare_expiry_evm"){let m=i.committedInputs[l],p=Array.from(numberToBytesBE(m.minDateTimestamp,8)),y=Array.from(numberToBytesBE(m.maxDateTimestamp,8));d=ProofType.EXPIRY_DATE.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.EXPIRY_DATE].evm.toString(16).padStart(4,"0")+p.map(x=>x.toString(16).padStart(2,"0")).join("")+y.map(x=>x.toString(16).padStart(2,"0")).join("");}else if(l==="disclose_bytes_evm"){let m=i.committedInputs[l];d=ProofType.DISCLOSE.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.DISCLOSE].evm.toString(16).padStart(4,"0")+m.discloseMask.map(p=>p.toString(16).padStart(2,"0")).join("")+m.disclosedBytes.map(p=>p.toString(16).padStart(2,"0")).join("");}else if(l==="bind_evm"){let m=i.committedInputs[l];d=ProofType.BIND.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.BIND].evm.toString(16).padStart(4,"0")+rightPadArrayWithZeros(formatBoundData(m.data),509).map(p=>p.toString(16).padStart(2,"0")).join("");}else if(l==="exclusion_check_sanctions_evm"){let m=i.committedInputs[l];d+=ProofType.SANCTIONS_EXCLUSION.toString(16).padStart(2,"0"),d+=ProofTypeLength[ProofType.SANCTIONS_EXCLUSION].evm.toString(16).padStart(4,"0"),d+=Array.from(numberToBytesBE(BigInt(m.rootHash),32)).map(p=>p.toString(16).padStart(2,"0")).join(""),d+=m.isStrict?"01":"00";}else if(l.startsWith("facematch")&&l.endsWith("_evm")){let m=i.committedInputs[l];d+=ProofType.FACEMATCH.toString(16).padStart(2,"0"),d+=ProofTypeLength[ProofType.FACEMATCH].evm.toString(16).padStart(4,"0"),d+=Array.from(numberToBytesBE(BigInt(m.rootKeyLeaf),32)).map(p=>p.toString(16).padStart(2,"0")).join(""),d+=m.environment==="development"?"00":"01",d+=Array.from(numberToBytesBE(BigInt(m.appIdHash),32)).map(p=>p.toString(16).padStart(2,"0")).join(""),d+=Array.from(numberToBytesBE(BigInt(m.integrityPubkeyHash),32)).map(p=>p.toString(16).padStart(2,"0")).join(""),d+=m.mode==="regular"?"01":"02";}else throw new Error(`Unsupported circuit for EVM verification: ${l}`);u.push({circuitName:l,inputs:d});}let r=getParamCommitmentsFromOuterProof(c).map(n=>n.toString(16).padStart(64,"0")),f="";for(let n of r){let $=u.find(l=>{let d=sha256(hexToBytes(l.inputs)),m=new Uint8Array(d.length);for(let p=0;p<d.length-1;p++)m[p+1]=d[p];return m[0]=0,bytesToHex(m)===n.replace("0x","")});if($){let l=g.find(d=>d.circuitName===$.circuitName)?.count;if(l)f+=$.inputs;else throw new Error(`Unknown circuit name: ${$.circuitName}`)}else throw new Error(`Invalid commitment: ${n}`)}let k=i.version?.split(".").map(n=>Number(n));if(!k||k.length!==3)throw new Error("Invalid version format");let A=new Uint8Array([...numberToBytesBE(k[0],2),...numberToBytesBE(k[1],2),...numberToBytesBE(k[2],2)]);return {version:`0x${bytesToHex(A).padEnd(64,"0")}`,proofVerificationData:{vkeyHash:`0x${i.vkeyHash.replace("0x","").padStart(64,"0")}`,proof:`0x${c.proof.join("")}`,publicInputs:c.publicInputs},committedInputs:`0x${f}`,serviceConfig:{validityPeriodInSeconds:a,domain:e,scope:t??"",devMode:s}}}};typeof globalThis.Buffer>"u"&&(globalThis.Buffer=Buffer,typeof window<"u"&&(window.Buffer=Buffer));registerLocale(wt);function pe(H){if(H==="Zero Knowledge Republic")return "ZKR";let i;return i=getAlpha3Code(H,"en")||H||"ZKR",i}function oe(H,i,a,e,t){t[e][i]={...t[e][i],[H]:a};}function Pt(H,i,a,e){e[a][H]={...e[a][H],range:i};}function ue(H,i,a,e,t){t[e][i]={...t[e][i],[H]:a};}var Ve=class{constructor(i){this.topicToConfig={};this.topicToLocalConfig={};this.topicToPublicKey={};this.topicToBridge={};this.topicToRequestReceived={};this.topicToService={};this.topicToProofs={};this.topicToFailedProofCount={};this.topicToResults={};this.onRequestReceivedCallbacks={};this.onGeneratingProofCallbacks={};this.onBridgeConnectCallbacks={};this.onProofGeneratedCallbacks={};this.onResultCallbacks={};this.onRejectCallbacks={};this.onErrorCallbacks={};if(!i&&typeof window>"u")throw new Error("Domain argument is required in Node.js environment");this.domain=this.normalizeDomain(i||window.location.hostname);}normalizeDomain(i){return i.trim().replace(/^https?:\/\//,"").replace(/\/[^/]*$/,"").replace(/:[0-9]+/,"").replace(/\?.*$/,"").replace(/#.*$/,"").toLowerCase()}async handleResult(i){let a=this.topicToResults[i];delete this.topicToResults[i];let{uniqueIdentifier:e,uniqueIdentifierType:t,verified:s,queryResultErrors:c}=await this.verify({proofs:this.topicToProofs[i],originalQuery:this.topicToConfig[i],queryResult:a,validity:this.topicToLocalConfig[i]?.validity,scope:this.topicToService[i]?.scope,devMode:this.topicToLocalConfig[i]?.devMode,oprfKeyId:this.topicToLocalConfig[i]?.oprfKeyId??void 0});delete this.topicToProofs[i];let g=this.topicToFailedProofCount[i]>0;await Promise.all(this.onResultCallbacks[i].map(u=>u({uniqueIdentifier:g?void 0:e,uniqueIdentifierType:g?void 0:t,verified:g?false:s,result:a,queryResultErrors:c}))),delete this.topicToFailedProofCount[i];}async handleEncryptedMessage(i,a){if(a.method==="accept")await Promise.all(this.onGeneratingProofCallbacks[i].map(e=>e(i)));else if(a.method==="reject")await Promise.all(this.onRejectCallbacks[i].map(e=>e()));else if(a.method==="proof")this.topicToProofs[i].push(a.params),await Promise.all(this.onProofGeneratedCallbacks[i].map(e=>e(a.params))),this.topicToResults[i]&&a.params.total===this.topicToProofs[i].length+this.topicToFailedProofCount[i]&&await this.handleResult(i);else if(a.method==="done")this.topicToResults[i]=formatQueryResultDates(a.params),this.topicToProofs[i].length>0&&this.topicToProofs[i].length+this.topicToFailedProofCount[i]===this.topicToProofs[i][0].total&&await this.handleResult(i);else if(a.method==="error"){let e=a.params.error;e&&e==="This ID is not supported yet"?this.topicToResults[i]&&await this.handleResult(i):e&&e.startsWith("Cannot generate proof")&&(this.topicToFailedProofCount[i]+=1,this.topicToResults[i]&&this.topicToProofs[i].length>0&&this.topicToProofs[i].length+this.topicToFailedProofCount[i]===this.topicToProofs[i][0].total&&await this.handleResult(i)),await Promise.all(this.onErrorCallbacks[i].map(t=>t(e)));}}getZkPassportRequest(i){return {eq:(a,e)=>((a==="issuing_country"||a==="nationality")&&(e=pe(e)),ue("eq",a,e,i,this.topicToConfig),this.getZkPassportRequest(i)),gte:(a,e)=>{if(oe("gte",a,e,i,this.topicToConfig),a==="age"&&(e<1||e>=100))throw new Error("Age must be between 1 and 99 (inclusive)");return this.getZkPassportRequest(i)},gt:(a,e)=>(oe("gt",a,e,i,this.topicToConfig),this.getZkPassportRequest(i)),lte:(a,e)=>(oe("lte",a,e,i,this.topicToConfig),this.getZkPassportRequest(i)),lt:(a,e)=>(oe("lt",a,e,i,this.topicToConfig),this.getZkPassportRequest(i)),range:(a,e,t)=>(Pt(a,[e,t],i,this.topicToConfig),this.getZkPassportRequest(i)),in:(a,e)=>(e=e.map(t=>pe(t)),ue("in",a,e,i,this.topicToConfig),this.getZkPassportRequest(i)),out:(a,e)=>(e=e.map(t=>pe(t)),ue("out",a,e,i,this.topicToConfig),this.getZkPassportRequest(i)),disclose:a=>(this.topicToConfig[i][a]={...this.topicToConfig[i][a],disclose:true},this.getZkPassportRequest(i)),bind:(a,e)=>(this.topicToConfig[i].bind={...this.topicToConfig[i].bind,[a]:e},this.getZkPassportRequest(i)),sanctions:(a="all",e="all",t={strict:false})=>(this.topicToConfig[i].sanctions={...this.topicToConfig[i].sanctions,countries:a,lists:e,strict:t.strict??false},this.getZkPassportRequest(i)),facematch:(a="regular")=>(this.topicToConfig[i].facematch={mode:a},this.getZkPassportRequest(i)),done:(()=>{if(this.topicToFailedProofCount[i]=0,i==="offline-query"){let s=this.topicToConfig[i];return delete this.topicToConfig[i],{query:s}}let a=this.topicToLocalConfig[i],e=this.topicToConfig[i],t=!!e.facematch&&e.facematch?.mode==="strict";if(a.uniqueIdentifierType===NullifierType.SALTED&&!t)throw new Error("Salted nullifier requires strict facematch. Add .facematch('strict') to your query or remove the salted nullifier option.");return {url:this._getUrl(i),query:this.topicToConfig[i],requestId:i,onRequestReceived:s=>this.onRequestReceivedCallbacks[i].push(s),onGeneratingProof:s=>this.onGeneratingProofCallbacks[i].push(s),onBridgeConnect:s=>this.onBridgeConnectCallbacks[i].push(s),onProofGenerated:s=>this.onProofGeneratedCallbacks[i].push(s),onResult:s=>this.onResultCallbacks[i].push(s),onReject:s=>this.onRejectCallbacks[i].push(s),onError:s=>this.onErrorCallbacks[i].push(s),isBridgeConnected:()=>this.topicToBridge[i].isBridgeConnected(),requestReceived:()=>this.topicToRequestReceived[i]===true}})}}async request({name:i,logo:a,purpose:e,scope:t,projectID:s,mode:c,validity:g,devMode:u,uniqueIdentifierType:r,oprfKeyId:f,topicOverride:o,keyPairOverride:k,cloudProverUrl:A,bridgeUrl:N}){if(o==="offline-query")throw new Error("You cannot override the topic with 'offline-query'");let B=await Bridge.create({keyPair:k,bridgeId:o,bridgeUrl:N}),n=B.connection.getBridgeId();return this.topicToConfig[n]={},this.topicToService[n]={name:i,logo:a,purpose:e,scope:t,projectID:s,cloudProverUrl:A,bridgeUrl:N},this.topicToProofs[n]=[],this.topicToLocalConfig[n]={validity:g||604800,mode:c||"fast",devMode:u||false,uniqueIdentifierType:f?NullifierType.SALTED:r,oprfKeyId:f??null},this.onRequestReceivedCallbacks[n]=[],this.onGeneratingProofCallbacks[n]=[],this.onBridgeConnectCallbacks[n]=[],this.onProofGeneratedCallbacks[n]=[],this.onResultCallbacks[n]=[],this.onRejectCallbacks[n]=[],this.onErrorCallbacks[n]=[],this.topicToPublicKey[n]=B.getPublicKey(),this.topicToBridge[n]=B,B.onConnect(async $=>{await Promise.all(this.onBridgeConnectCallbacks[n].map(l=>l()));}),B.onSecureChannelEstablished(async()=>{await Promise.all(this.onRequestReceivedCallbacks[n].map($=>$()));}),B.onSecureMessage(async $=>{this.handleEncryptedMessage(n,$);}),this.getZkPassportRequest(n)}createQuery(){return this.topicToConfig["offline-query"]={},this.getZkPassportRequest("offline-query")}async verify({proofs:i,originalQuery:a,queryResult:e,validity:t,scope:s,devMode:c=false,writingDirectory:g,oprfKeyId:u}){if(!i||i.length===0)return {uniqueIdentifier:void 0,uniqueIdentifierType:void 0,verified:false};let r=formatQueryResultDates(e),{UltraHonkVerifierBackend:f,Barretenberg:o}=await import('@aztec/bb.js');typeof window>"u"&&!g&&(g="/tmp");let k=await o.new({crsPath:g?g+"/.bb-crs":void 0}),A=new f(k),N=true,B,n,$,{isCorrect:l,uniqueIdentifier:d,uniqueIdentifierType:m,queryResultErrors:p}=await ne.checkPublicInputs(this.domain,i,a,r,t,s,u,c);if(B=d,n=m,N=l,$=l?void 0:p,B&&n&&(n===NullifierType.SALTED_MOCK||n===NullifierType.NON_SALTED_MOCK)&&!c&&(N=false,console.warn("You are trying to verify a mock proof. This is only allowed in dev mode. To enable dev mode, set the `devMode` parameter to `true` in the request function parameters.")),N){let y=new RegistryClient({chainId:c?11155111:1}),x=await y.getCircuitManifest(void 0,{version:i[0].version});for(let T of i){let I=T.name?.startsWith("outer_evm_"),w=T.name,S=getProofData(T.proof,getNumberOfPublicInputs(w)),P=await y.getPackagedCircuit(w,x,{validate:!I});if(I)try{let{createPublicClient:j,http:_}=await import('viem'),{sepolia:h}=await import('viem/chains'),{mainnet:Q}=await import('viem/chains'),{address:b,abi:C,functionName:D}=this.getSolidityVerifierDetails(),q=j({chain:c?h:Q,transport:_(c?"https://eth-sepolia.g.alchemy.com/v2/in6UjcATST36yyKuk83yb1yukKs65u8G":"https://eth-mainnet.g.alchemy.com/v2/in6UjcATST36yyKuk83yb1yukKs65u8G")}),Oe=this.getSolidityVerifierParameters({proof:T,domain:this.domain,scope:s,devMode:c}),be=await q.readContract({address:b,abi:C,functionName:D,args:[Oe]});N=Array.isArray(be)?!!be[0]:!1;}catch(j){console.warn("Error verifying proof",j),N=false;}else {let j=Buffer.from(P.vkey,"base64");try{N=await A.verifyProof({proof:Buffer.from(S.proof.join(""),"hex"),publicInputs:S.publicInputs,verificationKey:new Uint8Array(j)});}catch(_){console.warn(`Error verifying proof ${w}`,_),N=false;}}if(!N)break}}return B=N?B:void 0,n=N?n:void 0,{uniqueIdentifier:B,uniqueIdentifierType:n,verified:N,queryResultErrors:$}}getSolidityVerifierDetails(){return J.getDetails()}getSolidityVerifierParameters({proof:i,validityPeriodInSeconds:a=604800,domain:e,scope:t,devMode:s=false}){return J.getParameters({proof:i,validityPeriodInSeconds:a,domain:e??this.domain,scope:t,devMode:s})}_getUrl(i){let a=Buffer.from(JSON.stringify(this.topicToConfig[i])).toString("base64"),e=Buffer.from(JSON.stringify(this.topicToService[i])).toString("base64"),t=this.topicToPublicKey[i],s=Math.floor(Date.now()/1e3)-this.topicToLocalConfig[i].validity,c=this.topicToLocalConfig[i].uniqueIdentifierType,g=this.topicToLocalConfig[i].oprfKeyId,u=`https://zkpassport.id/r?d=${this.domain}&t=${i}&c=${a}&s=${e}&p=${t}&m=${this.topicToLocalConfig[i].mode}&v=${ye}&dt=${s}&dev=${this.topicToLocalConfig[i].devMode?"1":"0"}`;return c&&(u+=`&nt=${c}`),g&&(u+=`&oprf_k=${g}`),u}getUrl(i){return this._getUrl(i)}cancelRequest(i){this.topicToBridge[i]&&(this.topicToBridge[i].close(),delete this.topicToBridge[i]),delete this.topicToPublicKey[i],delete this.topicToConfig[i],delete this.topicToLocalConfig[i],delete this.topicToProofs[i],delete this.topicToFailedProofCount[i],delete this.topicToResults[i],this.onRequestReceivedCallbacks[i]=[],this.onGeneratingProofCallbacks[i]=[],this.onBridgeConnectCallbacks[i]=[],this.onProofGeneratedCallbacks[i]=[],this.onRejectCallbacks[i]=[],this.onErrorCallbacks[i]=[];}clearAllRequests(){for(let i in this.topicToBridge)this.cancelRequest(i);}};
|
|
2
2
|
export{Ve as ZKPassport};//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|