@zkpassport/sdk 0.20.1 → 0.21.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- 'use strict';var utils=require('@zkpassport/utils'),_=require('buffer/'),registry=require('@zkpassport/registry'),bridge=require('@obsidion/bridge'),i18nIsoCountries=require('i18n-iso-countries'),ut=require('i18n-iso-countries/langs/en.json'),sha2_js=require('@noble/hashes/sha2.js'),utils_js=require('@noble/hashes/utils.js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var ut__default=/*#__PURE__*/_interopDefault(ut);var M={debug:(...p)=>{},info:(...p)=>{},warn:(...p)=>{},error:(...p)=>{}};i18nIsoCountries.registerLocale(ut__default.default);function te(p){if(p==="Zero Knowledge Republic")return "ZKR";let t;return t=i18nIsoCountries.getAlpha3Code(p,"en")||p||"ZKR",t}function J(p,t,n,e,i){i[e][t]={...i[e][t],[p]:n};}function ve(p,t,n,e){e[n][p]={...e[n][p],range:t};}function oe(p,t,n,e,i){i[e][t]={...i[e][t],[p]:n};}function Te(){let p={query:{}},t="query",n=false,e=a=>{if(p[t].policy)throw new Error(`Cannot call .${a}() on a policy-driven query. The query for policy '${p[t].policy}' is immutable.`);n=true;},i={eq:(a,o)=>(e("eq"),(a==="issuing_country"||a==="nationality")&&(o=te(o)),oe("eq",a,o,t,p),i),gte:(a,o)=>{if(e("gte"),J("gte",a,o,t,p),a==="age"&&(o<1||o>=100))throw new Error("Age must be between 1 and 99 (inclusive)");return i},gt:(a,o)=>(e("gt"),J("gt",a,o,t,p),i),lte:(a,o)=>(e("lte"),J("lte",a,o,t,p),i),lt:(a,o)=>(e("lt"),J("lt",a,o,t,p),i),range:(a,o,m)=>(e("range"),ve(a,[o,m],t,p),i),in:(a,o)=>(e("in"),o=o.map(m=>te(m)),oe("in",a,o,t,p),i),out:(a,o)=>(e("out"),o=o.map(m=>te(m)),oe("out",a,o,t,p),i),disclose:a=>(e("disclose"),p[t][a]={...p[t][a],disclose:true},i),bind:(a,o)=>(p[t].bind={...p[t].bind,[a]:o},i),sanctions:(a="all",o="all",m={strict:false})=>(e("sanctions"),p[t].sanctions={...p[t].sanctions,countries:a,lists:o,strict:m.strict??false},i),facematch:(a="strict")=>(e("facematch"),p[t].facematch={mode:a},i),raw:a=>(e("raw"),p[t]=a,i),policy:a=>{if(typeof a!="string"||a.length===0)throw new Error(".policy() requires a non-empty string id.");if(p[t].policy)throw new Error(`Cannot call .policy() more than once on a request (already set to '${p[t].policy}').`);if(n)throw new Error("Cannot combine .policy() with builder methods like .gte()/.disclose()/etc.");return p[t].policy=a,i},done:(()=>({query:p[t]}))};return i}var Ve="0.20.1";var ce=Ve,F=10080*60,ee=new Date(0),le="https://dashboard-api.zkpassport.id",qe="https://verifier.zkpassport.id";var _e="0x1fa73686cf510f8f85757b0602de0dd72a13e68ae2092462be8b72662e7f179b",we="0x24d9929b248be7eeecaa98e105c034a50539610f3fdd4cb9c8983ef4100d615d",Ie="0x2532418a107c5306fa8308c22255792cf77e4a290cbce8a840a642a3e591340b",Pe="0x16700a2d9168a194fc85f237af5829b5a2be05b8ae8ac4879ada34cf54a9c211",Se="0x0e1889bec6c1d686abcf08360ff404f803ab345881ea8cba6aad33b7f7f7ffe0";var Ze=1440*60*1e3;function he(p){return !["firstname","lastname","fullname","birthdate","expiry_date","nationality","gender","document_number"].some(n=>p[n]?.disclose||p[n]?.eq!==void 0)||p.document_type?.disclose||p.document_type?.eq!==void 0?p:{...p,document_type:{...p.document_type,disclose:true}}}var ye=class{static checkDiscloseBytesPublicInputs(t,n,e){let i={},a=true;n=he(n);let o=t.committedInputs?.disclose_bytes?.disclosedBytes??t.committedInputs?.disclose_bytes_evm?.disclosedBytes,m=o?.[0]?String.fromCharCode(o[0])==="P"?"passport":"id_card":void 0,c=utils.DisclosedData.fromDisclosedBytes(o,m??"passport"),u=utils.DisclosedData.fromDisclosedBytes(o,m??"id_card");if(e.document_type&&(e.document_type.eq&&e.document_type.eq.result&&e.document_type.eq.expected!==c.documentType&&(console.warn("Document type does not match the expected document type"),a=false,i.document_type={...i.document_type,eq:{expected:`${e.document_type.eq.expected}`,received:`${c.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"),a=false,i.document_type={...i.document_type,disclose:{expected:`${e.document_type.disclose?.result}`,received:`${u.documentType??c.documentType}`,message:"Document type does not match the disclosed document type in query result"}}),e.document_type.eq&&(n.document_type?.eq===void 0||e.document_type.eq.expected!==n.document_type.eq)&&(console.warn("Document type eq does not match the original query"),a=false,i.document_type={...i.document_type,eq:{expected:`${n.document_type?.eq}`,received:`${e.document_type.eq.expected}`,message:"Document type eq does not match the original query"}}),e.document_type.disclose&&!n.document_type?.disclose&&(console.warn("Document type disclose is not in the original query"),a=false,i.document_type={...i.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 d=c.dateOfBirth,f=u.dateOfBirth;e.birthdate.eq&&e.birthdate.eq.result&&!utils.areDatesEqual(e.birthdate.eq.expected,d)&&!utils.areDatesEqual(e.birthdate.eq.expected,f)&&(console.warn("Birthdate does not match the expected birthdate"),a=false,i.birthdate={...i.birthdate,eq:{expected:`${e.birthdate.eq.expected.toISOString()}`,received:`${d?.toISOString()??f?.toISOString()}`,message:"Birthdate does not match the expected birthdate"}}),e.birthdate.disclose&&!utils.areDatesEqual(e.birthdate.disclose.result,d)&&!utils.areDatesEqual(e.birthdate.disclose.result,f)&&(console.warn("Birthdate does not match the disclosed birthdate in query result"),a=false,i.birthdate={...i.birthdate,disclose:{expected:`${e.birthdate.disclose.result.toISOString()}`,received:`${d?.toISOString()??f?.toISOString()}`,message:"Birthdate does not match the disclosed birthdate in query result"}}),e.birthdate.eq&&(n.birthdate?.eq===void 0||!utils.areDatesEqual(e.birthdate.eq.expected,n.birthdate.eq))&&(console.warn("Birthdate eq does not match the original query"),a=false,i.birthdate={...i.birthdate,eq:{expected:`${n.birthdate?.eq?.toISOString?.()??"undefined"}`,received:`${e.birthdate.eq.expected.toISOString()}`,message:"Birthdate eq does not match the original query"}}),e.birthdate.disclose&&!n.birthdate?.disclose&&(console.warn("Birthdate disclose is not in the original query"),a=false,i.birthdate={...i.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 d=c.dateOfExpiry,f=u.dateOfExpiry;e.expiry_date.eq&&e.expiry_date.eq.result&&!utils.areDatesEqual(e.expiry_date.eq.expected,d)&&!utils.areDatesEqual(e.expiry_date.eq.expected,f)&&(console.warn("Expiry date does not match the expected expiry date"),a=false,i.expiry_date={...i.expiry_date,eq:{expected:`${e.expiry_date.eq.expected.toISOString()}`,received:`${d?.toISOString()??f?.toISOString()}`,message:"Expiry date does not match the expected expiry date"}}),e.expiry_date.disclose&&!utils.areDatesEqual(e.expiry_date.disclose.result,d)&&!utils.areDatesEqual(e.expiry_date.disclose.result,f)&&(console.warn("Expiry date does not match the disclosed expiry date in query result"),a=false,i.expiry_date={...i.expiry_date,disclose:{expected:`${e.expiry_date.disclose.result.toISOString()}`,received:`${d?.toISOString()??f?.toISOString()}`,message:"Expiry date does not match the disclosed expiry date in query result"}}),e.expiry_date.eq&&(n.expiry_date?.eq===void 0||!utils.areDatesEqual(e.expiry_date.eq.expected,n.expiry_date.eq))&&(console.warn("Expiry date eq does not match the original query"),a=false,i.expiry_date={...i.expiry_date,eq:{expected:`${n.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&&!n.expiry_date?.disclose&&(console.warn("Expiry date disclose is not in the original query"),a=false,i.expiry_date={...i.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 d=c.nationality,f=u.nationality;e.nationality.eq&&e.nationality.eq.result&&e.nationality.eq.expected!==d&&e.nationality.eq.expected!==f&&(console.warn("Nationality does not match the expected nationality"),a=false,i.nationality={...i.nationality,eq:{expected:`${e.nationality.eq.expected}`,received:`${d??f}`,message:"Nationality does not match the expected nationality"}}),e.nationality.disclose&&e.nationality.disclose.result!==d&&e.nationality.disclose.result!==f&&(console.warn("Nationality does not match the disclosed nationality in query result"),a=false,i.nationality={...i.nationality,disclose:{expected:`${e.nationality.disclose.result}`,received:`${d??f}`,message:"Nationality does not match the disclosed nationality in query result"}}),e.nationality.eq&&(n.nationality?.eq===void 0||e.nationality.eq.expected!==n.nationality.eq)&&(console.warn("Nationality eq does not match the original query"),a=false,i.nationality={...i.nationality,eq:{expected:`${n.nationality?.eq}`,received:`${e.nationality.eq.expected}`,message:"Nationality eq does not match the original query"}}),e.nationality.disclose&&!n.nationality?.disclose&&(console.warn("Nationality disclose is not in the original query"),a=false,i.nationality={...i.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 d=c.documentNumber,f=u.documentNumber;e.document_number.eq&&e.document_number.eq.result&&e.document_number.eq.expected!==d&&e.document_number.eq.expected!==f&&(console.warn("Document number does not match the expected document number"),a=false,i.document_number={...i.document_number,eq:{expected:`${e.document_number.eq.expected}`,received:`${d??f}`,message:"Document number does not match the expected document number"}}),e.document_number.disclose&&e.document_number.disclose.result!==d&&e.document_number.disclose.result!==f&&(console.warn("Document number does not match the disclosed document number in query result"),a=false,i.document_number={...i.document_number,disclose:{expected:`${e.document_number.disclose.result}`,received:`${d??f}`,message:"Document number does not match the disclosed document number in query result"}}),e.document_number.eq&&(n.document_number?.eq===void 0||e.document_number.eq.expected!==n.document_number.eq)&&(console.warn("Document number eq does not match the original query"),a=false,i.document_number={...i.document_number,eq:{expected:`${n.document_number?.eq}`,received:`${e.document_number.eq.expected}`,message:"Document number eq does not match the original query"}}),e.document_number.disclose&&!n.document_number?.disclose&&(console.warn("Document number disclose is not in the original query"),a=false,i.document_number={...i.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 d=c.gender,f=u.gender;e.gender.eq&&e.gender.eq.result&&e.gender.eq.expected!==d&&e.gender.eq.expected!==f&&(console.warn("Gender does not match the expected gender"),a=false,i.gender={...i.gender,eq:{expected:`${e.gender.eq.expected}`,received:`${d??f}`,message:"Gender does not match the expected gender"}}),e.gender.disclose&&e.gender.disclose.result!==d&&e.gender.disclose.result!==f&&(console.warn("Gender does not match the disclosed gender in query result"),a=false,i.gender={...i.gender,disclose:{expected:`${e.gender.disclose.result}`,received:`${d??f}`,message:"Gender does not match the disclosed gender in query result"}}),e.gender.eq&&(n.gender?.eq===void 0||e.gender.eq.expected!==n.gender.eq)&&(console.warn("Gender eq does not match the original query"),a=false,i.gender={...i.gender,eq:{expected:`${n.gender?.eq}`,received:`${e.gender.eq.expected}`,message:"Gender eq does not match the original query"}}),e.gender.disclose&&!n.gender?.disclose&&(console.warn("Gender disclose is not in the original query"),a=false,i.gender={...i.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 d=c.issuingCountry,f=u.issuingCountry;e.issuing_country.eq&&e.issuing_country.eq.result&&e.issuing_country.eq.expected!==d&&e.issuing_country.eq.expected!==f&&(console.warn("Issuing country does not match the expected issuing country"),a=false,i.issuing_country={...i.issuing_country,eq:{expected:`${e.issuing_country.eq.expected}`,received:`${d??f}`,message:"Issuing country does not match the expected issuing country"}}),e.issuing_country.disclose&&e.issuing_country.disclose.result!==d&&e.issuing_country.disclose.result!==f&&(console.warn("Issuing country does not match the disclosed issuing country in query result"),a=false,i.issuing_country={...i.issuing_country,disclose:{expected:`${e.issuing_country.disclose.result}`,received:`${d??f}`,message:"Issuing country does not match the disclosed issuing country in query result"}}),e.issuing_country.eq&&(n.issuing_country?.eq===void 0||e.issuing_country.eq.expected!==n.issuing_country.eq)&&(console.warn("Issuing country eq does not match the original query"),a=false,i.issuing_country={...i.issuing_country,eq:{expected:`${n.issuing_country?.eq}`,received:`${e.issuing_country.eq.expected}`,message:"Issuing country eq does not match the original query"}}),e.issuing_country.disclose&&!n.issuing_country?.disclose&&(console.warn("Issuing country disclose is not in the original query"),a=false,i.issuing_country={...i.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 d=c.name,f=u.name;e.fullname.eq&&e.fullname.eq.result&&utils.formatName(e.fullname.eq.expected).toLowerCase()!==d.toLowerCase()&&utils.formatName(e.fullname.eq.expected).toLowerCase()!==f.toLowerCase()&&(console.warn("Fullname does not match the expected fullname"),a=false,i.fullname={...i.fullname,eq:{expected:`${e.fullname.eq.expected}`,received:`${d??f}`,message:"Fullname does not match the expected fullname"}}),e.fullname.disclose&&utils.formatName(e.fullname.disclose.result).toLowerCase()!==d.toLowerCase()&&utils.formatName(e.fullname.disclose.result).toLowerCase()!==f.toLowerCase()&&(console.warn("Fullname does not match the disclosed fullname in query result"),a=false,i.fullname={...i.fullname,disclose:{expected:`${e.fullname.disclose.result}`,received:`${d??f}`,message:"Fullname does not match the disclosed fullname in query result"}}),e.fullname.eq&&(n.fullname?.eq===void 0||utils.formatName(e.fullname.eq.expected).toLowerCase()!==utils.formatName(n.fullname.eq).toLowerCase())&&(console.warn("Fullname eq does not match the original query"),a=false,i.fullname={...i.fullname,eq:{expected:`${n.fullname?.eq}`,received:`${e.fullname.eq.expected}`,message:"Fullname eq does not match the original query"}}),e.fullname.disclose&&!n.fullname?.disclose&&(console.warn("Fullname disclose is not in the original query"),a=false,i.fullname={...i.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 d=c.firstName&&c.firstName.length>0?c.firstName:c.name,f=u.firstName&&u.firstName.length>0?u.firstName:u.name;e.firstname.eq&&e.firstname.eq.result&&utils.formatName(e.firstname.eq.expected).toLowerCase()!==d.toLowerCase()&&utils.formatName(e.firstname.eq.expected).toLowerCase()!==f.toLowerCase()&&(console.warn("Firstname does not match the expected firstname"),a=false,i.firstname={...i.firstname,eq:{expected:`${e.firstname.eq.expected}`,received:`${d??f}`,message:"Firstname does not match the expected firstname"}}),e.firstname.disclose&&utils.formatName(e.firstname.disclose.result).toLowerCase()!==d.toLowerCase()&&utils.formatName(e.firstname.disclose.result).toLowerCase()!==f.toLowerCase()&&(console.warn("Firstname does not match the disclosed firstname in query result"),a=false,i.firstname={...i.firstname,disclose:{expected:`${e.firstname.disclose.result}`,received:`${d??f}`,message:"Firstname does not match the disclosed firstname in query result"}}),e.firstname.eq&&(n.firstname?.eq===void 0||utils.formatName(e.firstname.eq.expected).toLowerCase()!==utils.formatName(n.firstname.eq).toLowerCase())&&(console.warn("Firstname eq does not match the original query"),a=false,i.firstname={...i.firstname,eq:{expected:`${n.firstname?.eq}`,received:`${e.firstname.eq.expected}`,message:"Firstname eq does not match the original query"}}),e.firstname.disclose&&!n.firstname?.disclose&&(console.warn("Firstname disclose is not in the original query"),a=false,i.firstname={...i.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 d=c.lastName&&c.lastName.length>0?c.lastName:c.name,f=u.lastName&&u.lastName.length>0?u.lastName:u.name;e.lastname.eq&&e.lastname.eq.result&&utils.formatName(e.lastname.eq.expected).toLowerCase()!==d.toLowerCase()&&utils.formatName(e.lastname.eq.expected).toLowerCase()!==f.toLowerCase()&&(console.warn("Lastname does not match the expected lastname"),a=false,i.lastname={...i.lastname,eq:{expected:`${e.lastname.eq.expected}`,received:`${d??f}`,message:"Lastname does not match the expected lastname"}}),e.lastname.disclose&&utils.formatName(e.lastname.disclose.result).toLowerCase()!==d.toLowerCase()&&utils.formatName(e.lastname.disclose.result).toLowerCase()!==f.toLowerCase()&&(console.warn("Lastname does not match the disclosed lastname in query result"),a=false,i.lastname={...i.lastname,disclose:{expected:`${e.lastname.disclose.result}`,received:`${d??f}`,message:"Lastname does not match the disclosed lastname in query result"}}),e.lastname.eq&&(n.lastname?.eq===void 0||utils.formatName(e.lastname.eq.expected).toLowerCase()!==utils.formatName(n.lastname.eq).toLowerCase())&&(console.warn("Lastname eq does not match the original query"),a=false,i.lastname={...i.lastname,eq:{expected:`${n.lastname?.eq}`,received:`${e.lastname.eq.expected}`,message:"Lastname eq does not match the original query"}}),e.lastname.disclose&&!n.lastname?.disclose&&(console.warn("Lastname disclose is not in the original query"),a=false,i.lastname={...i.lastname,disclose:{expected:"Not requested in original query",received:`${e.lastname.disclose.result}`,message:"Lastname disclose is not in the original query"}});}return {isCorrect:a,queryResultErrors:i}}static checkAgePublicInputs(t,n,e){let i={},a=true,o=new Date;new Date(o.getFullYear(),o.getMonth(),o.getDate(),0,0,0,0);let c=utils.getMinAgeFromCommittedInputs(t.committedInputs?.compare_age??t.committedInputs?.compare_age_evm),u=utils.getMaxAgeFromCommittedInputs(t.committedInputs?.compare_age??t.committedInputs?.compare_age_evm);return e.age?(e.age.gte&&e.age.gte.result&&c!==e.age.gte.expected&&(console.warn("Age is not greater than or equal to the expected age"),a=false,i.age={...i.age,gte:{expected:e.age.gte.expected,received:c,message:"Age is not greater than or equal to the expected age"}}),e.age.gt&&e.age.gt.result&&c!==e.age.gt.expected+1&&(console.warn("Age is not greater than the expected age"),a=false,i.age={...i.age,gt:{expected:e.age.gt.expected,received:c,message:"Age is not greater than the expected age"}}),e.age.lt&&e.age.lt.result&&u!==e.age.lt.expected-1&&(console.warn("Age is not less than the expected age"),a=false,i.age={...i.age,lt:{expected:e.age.lt.expected,received:u,message:"Age is not less than the expected age"}}),e.age.lte&&e.age.lte.result&&u!==e.age.lte.expected&&(console.warn("Age is not less than or equal to the expected age"),a=false,i.age={...i.age,lte:{expected:e.age.lte.expected,received:u,message:"Age is not less than or equal to the expected age"}}),e.age.eq&&e.age.eq.result&&(c!==e.age.eq.expected||u!==e.age.eq.expected)&&(console.warn("Age does not match the expected age"),a=false,i.age={...i.age,eq:{expected:e.age.eq.expected,received:c!==e.age.eq.expected?c:u,message:"Age does not match the expected age"}}),e.age.range&&e.age.range.result&&(c!==e.age.range.expected[0]||u!==e.age.range.expected[1])&&(console.warn("Age is not in the expected range"),a=false,i.age={...i.age,range:{expected:e.age.range.expected,received:[c,u],message:"Age is not in the expected range"}}),!e.age.lt&&!e.age.lte&&!e.age.eq&&!e.age.range&&u!=0&&(console.warn("Maximum age should be equal to 0"),a=false,i.age={...i.age,disclose:{expected:0,received:u,message:"Maximum age should be equal to 0"}}),!e.age.gte&&!e.age.gt&&!e.age.eq&&!e.age.range&&c!=0&&(console.warn("Minimum age should be equal to 0"),a=false,i.age={...i.age,disclose:{expected:0,received:c,message:"Minimum age should be equal to 0"}}),e.age.disclose&&(e.age.disclose.result!==c||e.age.disclose.result!==u)&&(console.warn("Age does not match the disclosed age in query result"),a=false,i.age={...i.age,disclose:{expected:`${c}`,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"),a=false,i.age={...i.age,disclose:{message:"Age is not set in the query result"}}),e.age?.gte&&(n.age?.gte===void 0||e.age.gte.expected!==n.age.gte)&&(console.warn("Age gte does not match the original query"),a=false,i.age={...i.age,gte:{expected:n.age?.gte,received:e.age.gte.expected,message:"Age gte does not match the original query"}}),e.age?.gt&&(n.age?.gt===void 0||e.age.gt.expected!==n.age.gt)&&(console.warn("Age gt does not match the original query"),a=false,i.age={...i.age,gt:{expected:n.age?.gt,received:e.age.gt.expected,message:"Age gt does not match the original query"}}),e.age?.lt&&(n.age?.lt===void 0||e.age.lt.expected!==n.age.lt)&&(console.warn("Age lt does not match the original query"),a=false,i.age={...i.age,lt:{expected:n.age?.lt,received:e.age.lt.expected,message:"Age lt does not match the original query"}}),e.age?.lte&&(n.age?.lte===void 0||e.age.lte.expected!==n.age.lte)&&(console.warn("Age lte does not match the original query"),a=false,i.age={...i.age,lte:{expected:n.age?.lte,received:e.age.lte.expected,message:"Age lte does not match the original query"}}),e.age?.eq&&(n.age?.eq===void 0||e.age.eq.expected!==n.age.eq)&&(console.warn("Age eq does not match the original query"),a=false,i.age={...i.age,eq:{expected:n.age?.eq,received:e.age.eq.expected,message:"Age eq does not match the original query"}}),e.age?.range&&(n.age?.range===void 0||e.age.range.expected[0]!==n.age.range[0]||e.age.range.expected[1]!==n.age.range[1])&&(console.warn("Age range does not match the original query"),a=false,i.age={...i.age,range:{expected:n.age?.range,received:e.age.range.expected,message:"Age range does not match the original query"}}),e.age?.disclose&&!n.age?.disclose&&(console.warn("Age disclose is not in the original query"),a=false,i.age={...i.age,disclose:{expected:"Not requested in original query",received:`${e.age.disclose.result}`,message:"Age disclose is not in the original query"}}),{isCorrect:a,queryResultErrors:i}}static checkBirthdatePublicInputs(t,n,e){let i={},a=true,o=new Date;new Date(o.getFullYear(),o.getMonth(),o.getDate(),0,0,0);let c=utils.getBirthdateMinDateTimestamp(t.committedInputs?.compare_birthdate??t.committedInputs?.compare_birthdate_evm,-1*utils.SECONDS_BETWEEN_1900_AND_1970),u=utils.getBirthdateMaxDateTimestamp(t.committedInputs?.compare_birthdate??t.committedInputs?.compare_birthdate_evm,-1*utils.SECONDS_BETWEEN_1900_AND_1970);if(e.birthdate){if(e.birthdate.gte&&e.birthdate.gte.result&&!utils.areDatesEqual(c,e.birthdate.gte.expected)&&(console.warn("Birthdate is not greater than or equal to the expected birthdate"),a=false,i.birthdate={...i.birthdate,gte:{expected:e.birthdate.gte.expected,received:c,message:"Birthdate is not greater than or equal to the expected birthdate"}}),e.birthdate.gt&&e.birthdate.gt.result){let d=new Date(e.birthdate.gt.expected);d.setDate(d.getDate()+1),utils.areDatesEqual(c,d)||(console.warn("Birthdate is not greater than the expected birthdate"),a=false,i.birthdate={...i.birthdate,gt:{expected:e.birthdate.gt.expected,received:c,message:"Birthdate is not greater than the expected birthdate"}});}if(e.birthdate.lte&&e.birthdate.lte.result&&!utils.areDatesEqual(u,e.birthdate.lte.expected)&&(console.warn("Birthdate is not less than the expected birthdate"),a=false,i.birthdate={...i.birthdate,lte:{expected:e.birthdate.lte.expected,received:u,message:"Birthdate is not less than the expected birthdate"}}),e.birthdate.lt&&e.birthdate.lt.result){let d=new Date(e.birthdate.lt.expected);d.setDate(d.getDate()-1),utils.areDatesEqual(u,d)||(console.warn("Birthdate is not less than the expected birthdate"),a=false,i.birthdate={...i.birthdate,lt:{expected:e.birthdate.lt.expected,received:u,message:"Birthdate is not less than the expected birthdate"}});}e.birthdate.range&&e.birthdate.range.result&&(!utils.areDatesEqual(c,e.birthdate.range.expected[0])||!utils.areDatesEqual(u,e.birthdate.range.expected[1]))&&(console.warn("Birthdate is not in the expected range"),a=false,i.birthdate={...i.birthdate,range:{expected:e.birthdate.range.expected,received:[c,u],message:"Birthdate is not in the expected range"}}),!e.birthdate.lte&&!e.birthdate.lt&&!e.birthdate.eq&&!e.birthdate.range&&!utils.areDatesEqual(u,ee)&&(console.warn("Maximum birthdate should be equal to default date value"),a=false,i.birthdate={...i.birthdate,disclose:{expected:`${ee.toISOString()}`,received:`${u.toISOString()}`,message:"Maximum birthdate should be equal to default date value"}}),!e.birthdate.gte&&!e.birthdate.gt&&!e.birthdate.eq&&!e.birthdate.range&&!utils.areDatesEqual(c,ee)&&(console.warn("Minimum birthdate should be equal to default date value"),a=false,i.birthdate={...i.birthdate,disclose:{expected:`${ee.toISOString()}`,received:`${c.toISOString()}`,message:"Minimum birthdate should be equal to default date value"}});}else console.warn("Birthdate is not set in the query result"),a=false,i.birthdate={...i.birthdate,disclose:{message:"Birthdate is not set in the query result"}};return e.birthdate?.gte&&(n.birthdate?.gte===void 0||!utils.areDatesEqual(e.birthdate.gte.expected,n.birthdate.gte))&&(console.warn("Birthdate gte does not match the original query"),a=false,i.birthdate={...i.birthdate,gte:{expected:n.birthdate?.gte,received:e.birthdate.gte.expected,message:"Birthdate gte does not match the original query"}}),e.birthdate?.gt&&(n.birthdate?.gt===void 0||!utils.areDatesEqual(e.birthdate.gt.expected,n.birthdate.gt))&&(console.warn("Birthdate gt does not match the original query"),a=false,i.birthdate={...i.birthdate,gt:{expected:n.birthdate?.gt,received:e.birthdate.gt.expected,message:"Birthdate gt does not match the original query"}}),e.birthdate?.lte&&(n.birthdate?.lte===void 0||!utils.areDatesEqual(e.birthdate.lte.expected,n.birthdate.lte))&&(console.warn("Birthdate lte does not match the original query"),a=false,i.birthdate={...i.birthdate,lte:{expected:n.birthdate?.lte,received:e.birthdate.lte.expected,message:"Birthdate lte does not match the original query"}}),e.birthdate?.lt&&(n.birthdate?.lt===void 0||!utils.areDatesEqual(e.birthdate.lt.expected,n.birthdate.lt))&&(console.warn("Birthdate lt does not match the original query"),a=false,i.birthdate={...i.birthdate,lt:{expected:n.birthdate?.lt,received:e.birthdate.lt.expected,message:"Birthdate lt does not match the original query"}}),e.birthdate?.range&&(n.birthdate?.range===void 0||!utils.areDatesEqual(e.birthdate.range.expected[0],n.birthdate.range[0])||!utils.areDatesEqual(e.birthdate.range.expected[1],n.birthdate.range[1]))&&(console.warn("Birthdate range does not match the original query"),a=false,i.birthdate={...i.birthdate,range:{expected:n.birthdate?.range,received:e.birthdate.range.expected,message:"Birthdate range does not match the original query"}}),{isCorrect:a,queryResultErrors:i}}static checkExpiryDatePublicInputs(t,n,e){let i={},a=true,o=new Date;new Date(o.getFullYear(),o.getMonth(),o.getDate(),0,0,0);let c=utils.getMinDateFromCommittedInputs(t.committedInputs?.compare_expiry??t.committedInputs?.compare_expiry_evm),u=utils.getMaxDateFromCommittedInputs(t.committedInputs?.compare_expiry??t.committedInputs?.compare_expiry_evm);return e.expiry_date?(e.expiry_date.gte&&e.expiry_date.gte.result&&!utils.areDatesEqual(c,e.expiry_date.gte.expected)&&(console.warn("Expiry date is not greater than or equal to the expected expiry date"),a=false,i.expiry_date={...i.expiry_date,gte:{expected:e.expiry_date.gte.expected,received:c,message:"Expiry date is not greater than or equal to the expected expiry date"}}),e.expiry_date.lte&&e.expiry_date.lte.result&&!utils.areDatesEqual(u,e.expiry_date.lte.expected)&&(console.warn("Expiry date is not less than the expected expiry date"),a=false,i.expiry_date={...i.expiry_date,lte:{expected:e.expiry_date.lte.expected,received:u,message:"Expiry date is not less than the expected expiry date"}}),e.expiry_date.range&&e.expiry_date.range.result&&(!utils.areDatesEqual(c,e.expiry_date.range.expected[0])||!utils.areDatesEqual(u,e.expiry_date.range.expected[1]))&&(console.warn("Expiry date is not in the expected range"),a=false,i.expiry_date={...i.expiry_date,range:{expected:e.expiry_date.range.expected,received:[c,u],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&&!utils.areDatesEqual(u,ee)&&(console.warn("Maximum expiry date should be equal to default date value"),a=false,i.expiry_date={...i.expiry_date,disclose:{expected:`${ee.toISOString()}`,received:`${u.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&&!utils.areDatesEqual(c,ee)&&(console.warn("Minimum expiry date should be equal to default date value"),a=false,i.expiry_date={...i.expiry_date,disclose:{expected:`${ee.toISOString()}`,received:`${c.toISOString()}`,message:"Minimum expiry date should be equal to default date value"}})):(console.warn("Expiry date is not set in the query result"),a=false,i.expiry_date={...i.expiry_date,disclose:{message:"Expiry date is not set in the query result"}}),e.expiry_date?.gte&&(n.expiry_date?.gte===void 0||!utils.areDatesEqual(e.expiry_date.gte.expected,n.expiry_date.gte))&&(console.warn("Expiry date gte does not match the original query"),a=false,i.expiry_date={...i.expiry_date,gte:{expected:n.expiry_date?.gte,received:e.expiry_date.gte.expected,message:"Expiry date gte does not match the original query"}}),e.expiry_date?.gt&&(n.expiry_date?.gt===void 0||!utils.areDatesEqual(e.expiry_date.gt.expected,n.expiry_date.gt))&&(console.warn("Expiry date gt does not match the original query"),a=false,i.expiry_date={...i.expiry_date,gt:{expected:n.expiry_date?.gt,received:e.expiry_date.gt.expected,message:"Expiry date gt does not match the original query"}}),e.expiry_date?.lte&&(n.expiry_date?.lte===void 0||!utils.areDatesEqual(e.expiry_date.lte.expected,n.expiry_date.lte))&&(console.warn("Expiry date lte does not match the original query"),a=false,i.expiry_date={...i.expiry_date,lte:{expected:n.expiry_date?.lte,received:e.expiry_date.lte.expected,message:"Expiry date lte does not match the original query"}}),e.expiry_date?.lt&&(n.expiry_date?.lt===void 0||!utils.areDatesEqual(e.expiry_date.lt.expected,n.expiry_date.lt))&&(console.warn("Expiry date lt does not match the original query"),a=false,i.expiry_date={...i.expiry_date,lt:{expected:n.expiry_date?.lt,received:e.expiry_date.lt.expected,message:"Expiry date lt does not match the original query"}}),e.expiry_date?.range&&(n.expiry_date?.range===void 0||!utils.areDatesEqual(e.expiry_date.range.expected[0],n.expiry_date.range[0])||!utils.areDatesEqual(e.expiry_date.range.expected[1],n.expiry_date.range[1]))&&(console.warn("Expiry date range does not match the original query"),a=false,i.expiry_date={...i.expiry_date,range:{expected:n.expiry_date?.range,received:e.expiry_date.range.expected,message:"Expiry date range does not match the original query"}}),{isCorrect:a,queryResultErrors:i}}static checkNationalityExclusionPublicInputs(t,n,e){let i={},a=true;n.nationality&&n.nationality.out&&n.nationality.out.result?n.nationality.out.expected?.every(o=>e.includes(o))||(console.warn("Nationality exclusion list does not match the one from the query results"),a=false,i.nationality={...i.nationality,out:{expected:n.nationality.out.expected,received:e,message:"Nationality exclusion list does not match the one from the query results"}}):(!n.nationality||!n.nationality.out)&&(console.warn("Nationality exclusion is not set in the query result"),a=false,i.nationality={...i.nationality,out:{message:"Nationality exclusion is not set in the query result"}});for(let o=1;o<e.length;o++)e[o]<e[o-1]&&(console.warn("The nationality exclusion list has not been sorted, and thus the proof cannot be trusted"),a=false,i.nationality={...i.nationality,out:{message:"The nationality exclusion list has not been sorted, and thus the proof cannot be trusted"}});return n.nationality?.out&&(t.nationality?.out===void 0||n.nationality.out.expected?.length!==t.nationality.out.length||!n.nationality.out.expected?.every(o=>t.nationality.out.includes(o)))&&(console.warn("Nationality exclusion list does not match the original query"),a=false,i.nationality={...i.nationality,out:{expected:t.nationality?.out,received:n.nationality.out.expected,message:"Nationality exclusion list does not match the original query"}}),{isCorrect:a,queryResultErrors:i}}static checkIssuingCountryExclusionPublicInputs(t,n,e){let i={},a=true;n.issuing_country&&n.issuing_country.out&&n.issuing_country.out.result?n.issuing_country.out.expected?.every(o=>e.includes(o))||(console.warn("Issuing country exclusion list does not match the one from the query results"),a=false,i.issuing_country={...i.issuing_country,out:{expected:n.issuing_country.out.expected,received:e,message:"Issuing country exclusion list does not match the one from the query results"}}):(!n.issuing_country||!n.issuing_country.out)&&(console.warn("Issuing country exclusion is not set in the query result"),a=false,i.issuing_country={...i.issuing_country,out:{message:"Issuing country exclusion is not set in the query result"}});for(let o=1;o<e.length;o++)e[o]<e[o-1]&&(console.warn("The issuing country exclusion list has not been sorted, and thus the proof cannot be trusted"),a=false,i.issuing_country={...i.issuing_country,out:{message:"The issuing country exclusion list has not been sorted, and thus the proof cannot be trusted"}});return n.issuing_country?.out&&(t.issuing_country?.out===void 0||n.issuing_country.out.expected?.length!==t.issuing_country.out.length||!n.issuing_country.out.expected?.every(o=>t.issuing_country.out.includes(o)))&&(console.warn("Issuing country exclusion list does not match the original query"),a=false,i.issuing_country={...i.issuing_country,out:{expected:t.issuing_country?.out,received:n.issuing_country.out.expected,message:"Issuing country exclusion list does not match the original query"}}),{isCorrect:a,queryResultErrors:i}}static checkNationalityInclusionPublicInputs(t,n,e){let i={},a=true;return n.nationality&&n.nationality.in&&n.nationality.in.result?n.nationality.in.expected?.every(o=>e.includes(o))||(console.warn("Nationality inclusion list does not match the one from the query results"),a=false,i.nationality={...i.nationality,in:{expected:n.nationality.in.expected,received:e,message:"Nationality inclusion list does not match the one from the query results"}}):(!n.nationality||!n.nationality.in)&&(console.warn("Nationality inclusion is not set in the query result"),a=false,i.nationality={...i.nationality,in:{message:"Nationality inclusion is not set in the query result"}}),n.nationality?.in&&(t.nationality?.in===void 0||n.nationality.in.expected?.length!==t.nationality.in.length||!n.nationality.in.expected?.every(o=>t.nationality.in.includes(o)))&&(console.warn("Nationality inclusion list does not match the original query"),a=false,i.nationality={...i.nationality,in:{expected:t.nationality?.in,received:n.nationality.in.expected,message:"Nationality inclusion list does not match the original query"}}),{isCorrect:a,queryResultErrors:i}}static checkIssuingCountryInclusionPublicInputs(t,n,e){let i={},a=true;return n.issuing_country&&n.issuing_country.in&&n.issuing_country.in.result?n.issuing_country.in.expected?.every(o=>e.includes(o))||(console.warn("Issuing country inclusion list does not match the one from the query results"),a=false,i.issuing_country={...i.issuing_country,in:{expected:n.issuing_country.in.expected,received:e,message:"Issuing country inclusion list does not match the one from the query results"}}):(!n.issuing_country||!n.issuing_country.in)&&(console.warn("Issuing country inclusion is not set in the query result"),a=false,i.issuing_country={...i.issuing_country,in:{message:"Issuing country inclusion is not set in the query result"}}),n.issuing_country?.in&&(t.issuing_country?.in===void 0||n.issuing_country.in.expected?.length!==t.issuing_country.in.length||!n.issuing_country.in.expected?.every(o=>t.issuing_country.in.includes(o)))&&(console.warn("Issuing country inclusion list does not match the original query"),a=false,i.issuing_country={...i.issuing_country,in:{expected:t.issuing_country?.in,received:n.issuing_country.in.expected,message:"Issuing country inclusion list does not match the original query"}}),{isCorrect:a,queryResultErrors:i}}static checkScopeFromDisclosureProof(t,n,e,i,a){if(t==="*")return {isCorrect:true,queryResultErrors:e};let o=true;if(utils.getServiceScopeHash(t)!==utils.getServiceScopeFromDisclosureProof(n)&&(console.warn("The proof comes from a different domain than the one expected"),o=false,e[i]||(e[i]={}),e[i].scope={expected:`Scope: ${utils.getServiceScopeHash(t).toString()}`,received:`Scope: ${utils.getServiceScopeFromDisclosureProof(n).toString()}`,message:"The proof comes from a different domain than the one expected"}),utils.getScopeHash(a)!==utils.getServiceSubScopeFromDisclosureProof(n)){let m=a?"The proof uses a different scope than the one expected":"The proof uses a scope but none was passed to verify()";console.warn(m),o=false,e[i]||(e[i]={}),e[i].scope={expected:`Scope: ${utils.getScopeHash(a).toString()}`,received:`Scope: ${utils.getServiceSubScopeFromDisclosureProof(n).toString()}`,message:m};}return {isCorrect:o,queryResultErrors:e}}static async checkRegistryRoot(t,n,e,i,a,o){let m;try{m=await t(o??registry.createRegistryClient(utils.getChainFromQuery(e,!!n)));}catch(c){console.warn(c),m=false;}if(!m){console.warn(a.message);let{section:c,field:u,...d}=a;i[c]={...i[c],[u]:d};}return {isCorrect:m,queryResultErrors:i}}static async checkCertificateRegistryRoot(t,n,e,i,a,o={},m){return this.checkRegistryRoot(c=>c.isCertificateRootValid(t,a),i,o,n,{section:e?"outer":"sig_check_dsc",field:"certificate",expected:"A valid root from ZKPassport Registry",received:`Got invalid certificate registry root: ${t}`,message:"The ID was signed by an unrecognized root certificate"},m)}static async checkCircuitRegistryRoot(t,n,e,i,a={},o){return this.checkRegistryRoot(m=>m.isCircuitRootValid(t,i),e,a,n,{section:"outer",field:"circuit",expected:"A valid circuit from ZKPassport Registry",received:`Got invalid circuit registry root: ${t}`,message:"The proof uses an unrecognized circuit"},o)}static async checkSanctionsRegistryRoot(t,n,e,i,a={},o){return this.checkRegistryRoot(m=>m.isSanctionsRootValid(t,i),e,a,n,{section:"sanctions",field:"eq",expected:"A valid root from ZKPassport Registry",received:`Got invalid sanctions registry root: ${t}`,message:"Invalid sanctions registry root"},o)}static checkBindPublicInputs(t,n,e){let i={},a=true;if(n.bind){let o=[];n.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"),a=false,o.push(`user_address: expected ${n.bind.user_address}, received ${e.user_address}`)),n.bind.chain!==e.chain&&(console.warn("Bound chain id does not match the one from the query results"),a=false,o.push(`chain: expected ${n.bind.chain}, received ${e.chain}`)),n.bind.custom_data?.trim().toLowerCase()!==e.custom_data?.trim().toLowerCase()&&(console.warn("Bound custom data does not match the one from the query results"),a=false,o.push(`custom_data: expected ${n.bind.custom_data}, received ${e.custom_data}`)),o.length>0&&(i.bind={...i.bind,eq:{expected:`${n.bind.user_address}, ${n.bind.chain}, ${n.bind.custom_data}`,received:`${e.user_address}, ${e.chain}, ${e.custom_data}`,message:`Bound data does not match: ${o.join("; ")}`}});}return (t.bind===void 0||e.user_address?.toLowerCase().replace("0x","")!==t.bind.user_address?.toLowerCase().replace("0x","")||e.chain!==t.bind.chain||e.custom_data?.trim().toLowerCase()!==t.bind.custom_data?.trim().toLowerCase())&&(console.warn("Bound data does not match the original query"),a=false,i.bind={...i.bind,eq:{expected:`${t.bind?.user_address}, ${t.bind?.chain}, ${t.bind?.custom_data}`,received:`${e.user_address}, ${e.chain}, ${e.custom_data}`,message:"Bound data does not match the original query"}}),{isCorrect:a,queryResultErrors:i}}static async checkSanctionsExclusionPublicInputs(t,n,e,i,a,o){let m={},c=true;e.isStrict!==(t.sanctions?.strict??false)&&(console.warn("Sanctions strict mode does not match the original query"),c=false,m.sanctions={...m.sanctions,eq:{expected:`strict: ${t.sanctions?.strict??false}`,received:`strict: ${e.isStrict}`,message:"Sanctions strict mode does not match the original query"}});let{isCorrect:u}=await this.checkSanctionsRegistryRoot(e.rootHash,m,i,a,t,o);return c=c&&u,n.sanctions&&n.sanctions.passed&&n.sanctions.isStrict!==e.isStrict&&(console.warn("Invalid sanctions strict mode"),c=false,m.sanctions={...m.sanctions,eq:{expected:n.sanctions.isStrict.toString(),received:e.isStrict.toString(),message:"Invalid sanctions strict mode"}}),n.sanctions&&(t.sanctions===void 0||n.sanctions.isStrict!==(t.sanctions.strict??false))&&(console.warn("Sanctions config does not match the original query"),c=false,m.sanctions={...m.sanctions,eq:{expected:`strict: ${t.sanctions?.strict??false}`,received:`strict: ${n.sanctions.isStrict}`,message:"Sanctions config does not match the original query"}}),{isCorrect:c,queryResultErrors:m}}static async checkFacematchPublicInputs(t,n,e){let i=true,a={};e.rootKeyLeaf!==Ie&&e.rootKeyLeaf!==Pe&&e.rootKeyLeaf!==Se&&(console.warn("Invalid facematch root key hash"),i=false,a.facematch={...a.facematch,eq:{expected:`${Ie} (iOS) or ${Pe} (Android) or ${Se} (Android)`,received:e.rootKeyLeaf,message:"Invalid facematch root key hash"}});let o="production";return e.environment!==o&&(console.warn("Invalid facematch environment, it should be production"),i=false,a.facematch={...a.facematch,eq:{expected:o,received:e.environment,message:"Invalid facematch environment, it should be production"}}),e.appIdHash!==_e&&e.appIdHash!==we&&(console.warn("Invalid facematch app id hash, the attestation should be coming from the ZKPassport app"),i=false,a.facematch={...a.facematch,eq:{expected:`${_e} (iOS) or ${we} (Android)`,received:e.appIdHash,message:"Invalid facematch app id hash, the attestation should be coming from the ZKPassport app"}}),(n.facematch&&e.mode!==n.facematch.mode||e.mode!==t.facematch?.mode)&&(console.warn("Invalid facematch mode"),i=false,a.facematch={...a.facematch,eq:{expected:t.facematch?.mode,received:e.mode,message:"Invalid facematch mode"}}),{isCorrect:i,queryResultErrors:a}}static async checkCurrentDate(t,n,e,i){let a=new Date,o=new Date(a.getFullYear(),a.getMonth(),a.getDate(),0,0,0,0),m=utils.getCurrentDateFromDisclosureProof(n),c=o.getTime()-m.getTime(),u=e?e*1e3:F*1e3,d=true;return c>=u&&(console.warn("The date used to check the validity of the ID falls out of the validity period"),d=false,i[t]||(i[t]={}),i[t].date={expected:`Difference: ${e} seconds`,received:`Difference: ${Math.round(c/1e3)} seconds`,message:"The date used to check the validity of the ID falls out of the validity period"}),m.getTime()-o.getTime()>Ze&&(console.warn("The date used to check the validity of the ID is in the future"),d=false,i[t]||(i[t]={}),i[t].date={expected:`Difference: ${e} seconds`,received:`Difference: ${Math.round(c/1e3)} seconds`,message:"The date used to check the validity of the ID is in the future"}),{isCorrect:d,queryResultErrors:i}}static checkQueryCompleteness(t,n){let e=true,i={},a=(...y)=>y.some(x=>n.has(x)),o=(y,x)=>{e=false,i[y]={...i[y],commitment:{expected:"A proof covering the requested condition",received:"No matching proof was provided",message:x}};},m=a("disclose_bytes","disclose_bytes_evm"),c=y=>!!y&&(y.gte!==void 0||y.gt!==void 0||y.lte!==void 0||y.lt!==void 0||y.range!==void 0),u=y=>!!y&&(y.eq!==void 0||y.disclose===true),d=t.age;(c(d)||d?.eq!==void 0)&&!a("compare_age","compare_age_evm")&&o("age","The proof does not verify the requested age condition"),c(t.birthdate)&&!a("compare_birthdate","compare_birthdate_evm")&&o("birthdate","The proof does not verify the requested birthdate condition"),u(t.birthdate)&&!m&&o("birthdate","The proof does not disclose the requested birthdate"),c(t.expiry_date)&&!a("compare_expiry","compare_expiry_evm")&&o("expiry_date","The proof does not verify the requested expiry date condition"),u(t.expiry_date)&&!m&&o("expiry_date","The proof does not disclose the requested expiry date");let f=t.nationality;f?.in!==void 0&&!a("inclusion_check_nationality","inclusion_check_nationality_evm")&&o("nationality","The proof does not verify the requested nationality inclusion"),f?.out!==void 0&&!a("exclusion_check_nationality","exclusion_check_nationality_evm")&&o("nationality","The proof does not verify the requested nationality exclusion"),u(f)&&!m&&o("nationality","The proof does not disclose the requested nationality");let r=t.issuing_country;r?.in!==void 0&&!a("inclusion_check_issuing_country","inclusion_check_issuing_country_evm")&&o("issuing_country","The proof does not verify the requested issuing country inclusion"),r?.out!==void 0&&!a("exclusion_check_issuing_country","exclusion_check_issuing_country_evm")&&o("issuing_country","The proof does not verify the requested issuing country exclusion"),u(r)&&!m&&o("issuing_country","The proof does not disclose the requested issuing country");let _=["firstname","lastname","fullname","document_number","document_type","gender"];for(let y of _)u(t[y])&&!m&&o(y,`The proof does not disclose the requested ${y}`);return t.bind&&!a("bind","bind_evm")&&o("bind","The proof does not verify the requested bound data"),t.sanctions&&!a("exclusion_check_sanctions","exclusion_check_sanctions_evm")&&o("sanctions","The proof does not verify the requested sanctions exclusion"),t.facematch&&!a("facematch","facematch_evm")&&o("facematch","The proof does not verify the requested FaceMatch"),e||console.warn("The proof does not verify all the requested conditions and information"),{isCorrect:e,queryResultErrors:i}}static async checkPublicInputs(t,n,e,i,a,o,m,c,u){let d,f,r=true,_,y,x,I=new Date,w=new Date(I.getFullYear(),I.getMonth(),I.getDate(),0,0,0,0),s={};if(n.length>1&&n.some(b=>b.name?.startsWith("outer")))return console.warn("An outer proof must be the only proof provided"),s.outer={commitment:{expected:"Number of proofs: 1",received:`Number of proofs: ${n.length}`,message:"An outer proof must be the only proof provided"}},{isCorrect:false,uniqueIdentifier:void 0,uniqueIdentifierType:void 0,queryResultErrors:s};let z=["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"],A=n.sort((b,l)=>{let h=v=>{let T=v.name||"";return z.findIndex(D=>T.startsWith(D))};return h(b)-h(l)}),j=z.slice(3),k=A.find(b=>j.some(l=>b.name?.startsWith(l))),K=k?utils.getCurrentDateFromDisclosureProof(utils.getProofData(k.proof,utils.getNumberOfPublicInputs(k.name))):void 0,Q=K?Math.floor(K.getTime()/1e3):void 0;for(let b of A){let l=utils.getProofData(b.proof,utils.getNumberOfPublicInputs(b.name));if(b.name?.startsWith("outer")){let h=b.name?.startsWith("outer_evm"),v=utils.getCurrentDateFromOuterProof(l),T=Math.floor(v.getTime()/1e3),D=utils.getCertificateRegistryRootFromOuterProof(l),{isCorrect:E,queryResultErrors:$}=await this.checkCertificateRegistryRoot(D.toString(16),s,true,c,T,e,u);r=r&&E,s={...s,...$};let V=utils.getCircuitRegistryRootFromOuterProof(l),{isCorrect:q,queryResultErrors:R}=await this.checkCircuitRegistryRoot(V.toString(16),s,c,T,e,u);r=r&&q,s={...s,...R};let Ce=w.getTime()-v.getTime(),ct=a?a*1e3:F*1e3;Ce>=ct&&(console.warn("The date used to check the validity of the ID is older than the validity period"),r=false,s.outer={...s.outer,date:{expected:`Difference: ${a} seconds`,received:`Difference: ${Math.round(Ce/1e3)} seconds`,message:"The date used to check the validity of the ID is older than the validity period"}}),v.getTime()-w.getTime()>Ze&&(console.warn("The date used to check the validity of the ID is in the future"),r=false,s.outer={...s.outer,date:{expected:`Difference: ${a} seconds`,received:`Difference: ${Math.round(Ce/1e3)} seconds`,message:"The date used to check the validity of the ID is in the future"}});let N=utils.getParamCommitmentsFromOuterProof(l),C=b.committedInputs,$e=Object.keys(C||{});if($e.length!==N.length&&(console.warn("The proof does not verify all the requested conditions and information"),r=false,s.outer={...s.outer,commitment:{expected:`Number of parameter commitments: ${N.length}`,received:`Number of disclosure proofs provided: ${$e.length}`,message:"The proof does not verify all the requested conditions and information"}}),utils.getServiceScopeHash(t)!==utils.getScopeFromOuterProof(l)&&(console.warn("The proof comes from a different domain than the one expected"),r=false,s.outer={...s.outer,scope:{expected:`Scope: ${utils.getServiceScopeHash(t).toString()}`,received:`Scope: ${utils.getScopeFromOuterProof(l).toString()}`,message:"The proof comes from a different domain than the one expected"}}),utils.getScopeHash(o)!==utils.getSubscopeFromOuterProof(l)){let g=o?"The proof uses a different scope than the one expected":"The proof uses a scope but none was passed to verify()";console.warn(g),r=false,s.outer={...s.outer,scope:{expected:`Scope: ${utils.getScopeHash(o).toString()}`,received:`Scope: ${utils.getSubscopeFromOuterProof(l).toString()}`,message:g}};}if(C?.compare_age||C?.compare_age_evm){let g=C?.compare_age??C?.compare_age_evm,S=h?await utils.getAgeEVMParameterCommitment(g.minAge,g.maxAge):await utils.getAgeParameterCommitment(g.minAge,g.maxAge);N.includes(S)||(console.warn("This proof does not verify the age"),r=false,s.age={...s.age,commitment:{expected:`Age parameter commitment: ${S.toString()}`,received:`Parameter commitments included: ${N.join(", ")}`,message:"This proof does not verify the age"}});let{isCorrect:B,queryResultErrors:O}=this.checkAgePublicInputs(b,e,i);r=r&&B,s={...s,...O};}if(C?.compare_birthdate||C?.compare_birthdate_evm){let g=C?.compare_birthdate??C?.compare_birthdate_evm,S=h?await utils.getDateEVMParameterCommitment(utils.ProofType.BIRTHDATE,g.minDateTimestamp,g.maxDateTimestamp,0):await utils.getDateParameterCommitment(utils.ProofType.BIRTHDATE,g.minDateTimestamp,g.maxDateTimestamp,0);N.includes(S)||(console.warn("This proof does not verify the birthdate"),r=false,s.birthdate={...s.birthdate,commitment:{expected:`Birthdate parameter commitment: ${S.toString()}`,received:`Parameter commitments included: ${N.join(", ")}`,message:"This proof does not verify the birthdate"}});let{isCorrect:B,queryResultErrors:O}=this.checkBirthdatePublicInputs(b,e,i);r=r&&B,s={...s,...O};}if(C?.compare_expiry||C?.compare_expiry_evm){let g=C?.compare_expiry??C?.compare_expiry_evm,S=h?await utils.getDateEVMParameterCommitment(utils.ProofType.EXPIRY_DATE,g.minDateTimestamp,g.maxDateTimestamp):await utils.getDateParameterCommitment(utils.ProofType.EXPIRY_DATE,g.minDateTimestamp,g.maxDateTimestamp);N.includes(S)||(console.warn("This proof does not verify the expiry date"),r=false,s.expiry_date={...s.expiry_date,commitment:{expected:`Expiry date parameter commitment: ${S.toString()}`,received:`Parameter commitments included: ${N.join(", ")}`,message:"This proof does not verify the expiry date"}});let{isCorrect:B,queryResultErrors:O}=this.checkExpiryDatePublicInputs(b,e,i);r=r&&B,s={...s,...O};}if(C?.disclose_bytes||C?.disclose_bytes_evm){let g=C?.disclose_bytes??C?.disclose_bytes_evm,S=h?await utils.getDiscloseEVMParameterCommitment(g.discloseMask,g.disclosedBytes):await utils.getDiscloseParameterCommitment(g.discloseMask,g.disclosedBytes);N.includes(S)||(console.warn("This proof does not verify any of the data disclosed"),r=false,s.disclose={...s.disclose,commitment:{expected:`Disclosure parameter commitment: ${S.toString()}`,received:`Parameter commitments included: ${N.join(", ")}`,message:"This proof does not verify any of the data disclosed"}});let{isCorrect:B,queryResultErrors:O}=this.checkDiscloseBytesPublicInputs(b,e,i);r=r&&B,s={...s,...O};}if(C?.inclusion_check_nationality||C?.inclusion_check_nationality_evm){let g=C?.inclusion_check_nationality??C?.inclusion_check_nationality_evm,S=h?await utils.getCountryEVMParameterCommitment(utils.ProofType.NATIONALITY_INCLUSION,g.countries):await utils.getCountryParameterCommitment(utils.ProofType.NATIONALITY_INCLUSION,g.countries);N.includes(S)||(console.warn("This proof does not verify the inclusion of the nationality"),r=false,s.nationality={...s.nationality,commitment:{expected:`Nationality parameter commitment: ${S.toString()}`,received:`Parameter commitments included: ${N.join(", ")}`,message:"This proof does not verify the inclusion of the nationality"}});let B=g.countries,{isCorrect:O,queryResultErrors:se}=this.checkNationalityInclusionPublicInputs(e,i,B);r=r&&O,s={...s,...se};}if(C?.inclusion_check_issuing_country||C?.inclusion_check_issuing_country_evm){let g=C?.inclusion_check_issuing_country??C?.inclusion_check_issuing_country_evm,S=h?await utils.getCountryEVMParameterCommitment(utils.ProofType.ISSUING_COUNTRY_INCLUSION,g.countries):await utils.getCountryParameterCommitment(utils.ProofType.ISSUING_COUNTRY_INCLUSION,g.countries);N.includes(S)||(console.warn("This proof does not verify the inclusion of the issuing country"),r=false,s.issuing_country={...s.issuing_country,commitment:{expected:`Issuing country parameter commitment: ${S.toString()}`,received:`Parameter commitments included: ${N.join(", ")}`,message:"This proof does not verify the inclusion of the issuing country"}});let B=g.countries,{isCorrect:O,queryResultErrors:se}=this.checkIssuingCountryInclusionPublicInputs(e,i,B);r=r&&O,s={...s,...se};}if(C?.exclusion_check_nationality||C?.exclusion_check_nationality_evm){let g=C?.exclusion_check_nationality??C?.exclusion_check_nationality_evm,S=h?await utils.getCountryEVMParameterCommitment(utils.ProofType.NATIONALITY_EXCLUSION,g.countries):await utils.getCountryParameterCommitment(utils.ProofType.NATIONALITY_EXCLUSION,g.countries);N.includes(S)||(console.warn("This proof does not verify the exclusion of the nationality"),r=false,s.nationality={...s.nationality,commitment:{expected:`Nationality parameter commitment: ${S.toString()}`,received:`Parameter commitments included: ${N.join(", ")}`,message:"This proof does not verify the exclusion of the nationality"}});let B=g.countries,{isCorrect:O,queryResultErrors:se}=this.checkNationalityExclusionPublicInputs(e,i,B);r=r&&O,s={...s,...se};}if(C?.exclusion_check_issuing_country||C?.exclusion_check_issuing_country_evm){let g=C?.exclusion_check_issuing_country??C?.exclusion_check_issuing_country_evm,S=h?await utils.getCountryEVMParameterCommitment(utils.ProofType.ISSUING_COUNTRY_EXCLUSION,g.countries):await utils.getCountryParameterCommitment(utils.ProofType.ISSUING_COUNTRY_EXCLUSION,g.countries);N.includes(S)||(console.warn("This proof does not verify the exclusion of the issuing country"),r=false,s.issuing_country={...s.issuing_country,commitment:{expected:`Issuing country parameter commitment: ${S.toString()}`,received:`Parameter commitments included: ${N.join(", ")}`,message:"This proof does not verify the exclusion of the issuing country"}});let B=g.countries,{isCorrect:O,queryResultErrors:se}=this.checkIssuingCountryExclusionPublicInputs(e,i,B);r=r&&O,s={...s,...se};}if(C?.bind||C?.bind_evm){let g=C?.bind??C?.bind_evm,S=h?await utils.getBindEVMParameterCommitment(utils.formatBoundData(g.data)):await utils.getBindParameterCommitment(utils.formatBoundData(g.data));N.includes(S)||(console.warn("This proof does not verify the bound data"),r=false,s.bind={...s.bind,commitment:{expected:`Bind parameter commitment: ${S.toString()}`,received:`Parameter commitments included: ${N.join(", ")}`,message:"This proof does not verify the bound data"}});let{isCorrect:B,queryResultErrors:O}=this.checkBindPublicInputs(e,i,g.data);r=r&&B,s={...s,...O};}if(C?.exclusion_check_sanctions||C?.exclusion_check_sanctions_evm){let g=C?.exclusion_check_sanctions??C?.exclusion_check_sanctions_evm,S=h?await utils.getSanctionsEvmParameterCommitment(g.rootHash,g.isStrict):await utils.getSanctionsParameterCommitment(g.rootHash,g.isStrict);N.includes(S)||(console.warn("This proof does not verify the exclusion from the sanction lists"),r=false,s.sanctions={...s.sanctions,commitment:{expected:`Sanctions parameter commitment: ${S.toString()}`,received:`Parameter commitments included: ${N.join(", ")}`,message:"This proof does not verify the exclusion from the sanction lists"}});let{isCorrect:B,queryResultErrors:O}=await this.checkSanctionsExclusionPublicInputs(e,i,g,c,T,u);r=r&&B,s={...s,...O};}if(C?.facematch||C?.facematch_evm){let g=C?.facematch??C?.facematch_evm,S=h?await utils.getFacematchEvmParameterCommitment(BigInt(g.rootKeyLeaf),g.environment==="development"?0n:1n,BigInt(g.appIdHash),g.mode==="regular"?1n:2n):await utils.getFacematchParameterCommitment(BigInt(g.rootKeyLeaf),g.environment==="development"?0n:1n,BigInt(g.appIdHash),g.mode==="regular"?1n:2n);N.includes(S)||(console.warn("This proof does not verify FaceMatch"),r=false,s.facematch={...s.facematch,commitment:{expected:`Facematch parameter commitment: ${S.toString()}`,received:`Parameter commitments included: ${N.join(", ")}`,message:"This proof does not verify FaceMatch"}});let{isCorrect:B,queryResultErrors:O}=await this.checkFacematchPublicInputs(e,i,g);r=r&&B,s={...s,...O};}_=utils.getNullifierFromOuterProof(l).toString(10),y=utils.getNullifierTypeFromOuterProof(l),x=utils.getOprfPkHashFromOuterProof(l);}else if(b.name?.startsWith("sig_check_dsc")){f=utils.getCommitmentFromDSCProof(l);let h=utils.getMerkleRootFromDSCProof(l),{isCorrect:v,queryResultErrors:T}=await this.checkCertificateRegistryRoot(h.toString(16),s,false,c,Q,e,u);r=r&&v,s={...s,...T};}else if(b.name?.startsWith("sig_check_id_data"))d=utils.getCommitmentInFromIDDataProof(l),d!==f&&(console.warn("Failed to check the link between the certificate signature and ID signature"),r=false,s.sig_check_id_data={...s.sig_check_id_data,commitment:{expected:`Commitment: ${f?.toString()||"undefined"}`,received:`Commitment: ${d?.toString()||"undefined"}`,message:"Failed to check the link between the certificate signature and ID signature"}}),f=utils.getCommitmentOutFromIDDataProof(l);else if(b.name?.startsWith("data_check_integrity"))d=utils.getCommitmentInFromIntegrityProof(l),d!==f&&(console.warn("Failed to check the link between the ID signature and the data signed"),r=false,s.data_check_integrity={...s.data_check_integrity,commitment:{expected:`Commitment: ${f?.toString()||"undefined"}`,received:`Commitment: ${d?.toString()||"undefined"}`,message:"Failed to check the link between the ID signature and the data signed"}}),f=utils.getCommitmentOutFromIntegrityProof(l);else if(b.name==="disclose_bytes"){d=utils.getCommitmentInFromDisclosureProof(l),d!==f&&(console.warn("Failed to check the link between the validity of the ID and the data to disclose"),r=false,s.disclose={...s.disclose,commitment:{expected:`Commitment: ${f?.toString()||"undefined"}`,received:`Commitment: ${d?.toString()||"undefined"}`,message:"Failed to check the link between the validity of the ID and the data to disclose"}});let h=utils.getParameterCommitmentFromDisclosureProof(l),v=await utils.getDiscloseParameterCommitment((b.committedInputs?.disclose_bytes).discloseMask,(b.committedInputs?.disclose_bytes).disclosedBytes);h!==v&&(console.warn("The disclosed data does not match the data committed by the proof"),r=false,s.disclose={...s.disclose,commitment:{expected:`Commitment: ${v}`,received:`Commitment: ${h}`,message:"The disclosed data does not match the data committed by the proof"}});let{isCorrect:T,queryResultErrors:D}=this.checkScopeFromDisclosureProof(t,l,s,"disclose",o);r=r&&T,s={...s,...D};let{isCorrect:E,queryResultErrors:$}=this.checkDiscloseBytesPublicInputs(b,e,i);r=r&&E&&T,s={...s,...$,...D};let{isCorrect:V,queryResultErrors:q}=await this.checkCurrentDate("disclose",l,a??F,s);r=r&&V,s={...s,...q},_=utils.getNullifierFromDisclosureProof(l).toString(10),y=utils.getNullifierTypeFromDisclosureProof(l);}else if(b.name==="compare_age"){d=utils.getCommitmentInFromDisclosureProof(l),d!==f&&(console.warn("Failed to check the link between the validity of the ID and the age derived from it"),r=false,s.age={...s.age,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${d}`,message:"Failed to check the link between the validity of the ID and the age derived from it"}});let h=utils.getParameterCommitmentFromDisclosureProof(l),v=b.committedInputs?.compare_age,T=await utils.getAgeParameterCommitment(v.minAge,v.maxAge);h!==T&&(console.warn("The conditions for the age check do not match the conditions checked by the proof"),r=false,s.age={...s.age,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${h}`,message:"The conditions for the age check do not match the conditions checked by the proof"}});let{isCorrect:D,queryResultErrors:E}=this.checkScopeFromDisclosureProof(t,l,s,"age",o),{isCorrect:$,queryResultErrors:V}=this.checkAgePublicInputs(b,e,i);r=r&&$&&D,s={...s,...V,...E};let{isCorrect:q,queryResultErrors:R}=await this.checkCurrentDate("age",l,a??F,s);r=r&&q,s={...s,...R},_=utils.getNullifierFromDisclosureProof(l).toString(10),y=utils.getNullifierTypeFromDisclosureProof(l);}else if(b.name==="compare_birthdate"){d=utils.getCommitmentInFromDisclosureProof(l),d!==f&&(console.warn("Failed to check the link between the validity of the ID and the birthdate derived from it"),r=false,s.birthdate={...s.birthdate,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${d}`,message:"Failed to check the link between the validity of the ID and the birthdate derived from it"}});let h=utils.getParameterCommitmentFromDisclosureProof(l),v=b.committedInputs?.compare_birthdate,T=await utils.getDateParameterCommitment(utils.ProofType.BIRTHDATE,v.minDateTimestamp,v.maxDateTimestamp,0);h!==T&&(console.warn("The conditions for the birthdate check do not match the conditions checked by the proof"),r=false,s.birthdate={...s.birthdate,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${h}`,message:"The conditions for the birthdate check do not match the conditions checked by the proof"}});let{isCorrect:D,queryResultErrors:E}=this.checkScopeFromDisclosureProof(t,l,s,"birthdate",o),{isCorrect:$,queryResultErrors:V}=this.checkBirthdatePublicInputs(b,e,i);r=r&&$&&D,s={...s,...V,...E};let{isCorrect:q,queryResultErrors:R}=await this.checkCurrentDate("birthdate",l,a??F,s);r=r&&q,s={...s,...R},_=utils.getNullifierFromDisclosureProof(l).toString(10),y=utils.getNullifierTypeFromDisclosureProof(l);}else if(b.name==="compare_expiry"){d=utils.getCommitmentInFromDisclosureProof(l),d!==f&&(console.warn("Failed to check the link between the validity of the ID and its expiry date"),r=false,s.expiry_date={...s.expiry_date,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${d}`,message:"Failed to check the link between the validity of the ID and its expiry date"}});let h=utils.getParameterCommitmentFromDisclosureProof(l),v=b.committedInputs?.compare_expiry,T=await utils.getDateParameterCommitment(utils.ProofType.EXPIRY_DATE,v.minDateTimestamp,v.maxDateTimestamp);h!==T&&(console.warn("The conditions for the expiry date check do not match the conditions checked by the proof"),r=false,s.expiry_date={...s.expiry_date,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${h}`,message:"The conditions for the expiry date check do not match the conditions checked by the proof"}});let{isCorrect:D,queryResultErrors:E}=this.checkScopeFromDisclosureProof(t,l,s,"expiry_date",o),{isCorrect:$,queryResultErrors:V}=this.checkExpiryDatePublicInputs(b,e,i);r=r&&$&&D,s={...s,...V,...E};let{isCorrect:q,queryResultErrors:R}=await this.checkCurrentDate("expiry_date",l,a??F,s);r=r&&q,s={...s,...R},_=utils.getNullifierFromDisclosureProof(l).toString(10),y=utils.getNullifierTypeFromDisclosureProof(l);}else if(b.name==="exclusion_check_nationality"){d=utils.getCommitmentInFromDisclosureProof(l),d!==f&&(console.warn("Failed to check the link between the validity of the ID and the nationality exclusion check"),r=false,s.nationality={...s.nationality,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${d}`,message:"Failed to check the link between the validity of the ID and the nationality exclusion check"}});let h=(b.committedInputs?.exclusion_check_nationality).countries,v=utils.getParameterCommitmentFromDisclosureProof(l),T=await utils.getCountryParameterCommitment(utils.ProofType.NATIONALITY_EXCLUSION,h,true);v!==T&&(console.warn("The committed country list for the exclusion check does not match the one from the proof"),r=false,s.nationality={...s.nationality,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${v}`,message:"The committed country list for the exclusion check does not match the one from the proof"}});let{isCorrect:D,queryResultErrors:E}=this.checkScopeFromDisclosureProof(t,l,s,"nationality",o),{isCorrect:$,queryResultErrors:V}=this.checkNationalityExclusionPublicInputs(e,i,h);r=r&&$&&D,s={...s,...V,...E};let{isCorrect:q,queryResultErrors:R}=await this.checkCurrentDate("nationality",l,a??F,s);r=r&&q,s={...s,...R},_=utils.getNullifierFromDisclosureProof(l).toString(10),y=utils.getNullifierTypeFromDisclosureProof(l);}else if(b.name==="exclusion_check_issuing_country"){d=utils.getCommitmentInFromDisclosureProof(l),d!==f&&(console.warn("Failed to check the link between the validity of the ID and the issuing country exclusion check"),r=false,s.issuing_country={...s.issuing_country,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${d}`,message:"Failed to check the link between the validity of the ID and the issuing country exclusion check"}});let h=(b.committedInputs?.exclusion_check_issuing_country).countries,v=utils.getParameterCommitmentFromDisclosureProof(l),T=await utils.getCountryParameterCommitment(utils.ProofType.ISSUING_COUNTRY_EXCLUSION,h,true);v!==T&&(console.warn("The committed country list for the issuing country exclusion check does not match the one from the proof"),r=false,s.issuing_country={...s.issuing_country,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${v}`,message:"The committed country list for the issuing country exclusion check does not match the one from the proof"}});let{isCorrect:D,queryResultErrors:E}=this.checkScopeFromDisclosureProof(t,l,s,"issuing_country",o),{isCorrect:$,queryResultErrors:V}=this.checkIssuingCountryExclusionPublicInputs(e,i,h);r=r&&$&&D,s={...s,...V,...E};let{isCorrect:q,queryResultErrors:R}=await this.checkCurrentDate("issuing_country",l,a??F,s);r=r&&q,s={...s,...R},_=utils.getNullifierFromDisclosureProof(l).toString(10),y=utils.getNullifierTypeFromDisclosureProof(l);}else if(b.name==="inclusion_check_nationality"){d=utils.getCommitmentInFromDisclosureProof(l),d!==f&&(console.warn("Failed to check the link between the validity of the ID and the nationality inclusion check"),r=false,s.nationality={...s.nationality,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${d}`,message:"Failed to check the link between the validity of the ID and the nationality inclusion check"}});let h=(b.committedInputs?.inclusion_check_nationality).countries,v=utils.getParameterCommitmentFromDisclosureProof(l),T=await utils.getCountryParameterCommitment(utils.ProofType.NATIONALITY_INCLUSION,h,false);v!==T&&(console.warn("The committed country list for the nationality inclusion check does not match the one from the proof"),r=false,s.nationality={...s.nationality,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${v}`,message:"The committed country list for the nationality inclusion check does not match the one from the proof"}});let{isCorrect:D,queryResultErrors:E}=this.checkScopeFromDisclosureProof(t,l,s,"nationality",o),{isCorrect:$,queryResultErrors:V}=this.checkNationalityInclusionPublicInputs(e,i,h);r=r&&$&&D,s={...s,...V,...E};let{isCorrect:q,queryResultErrors:R}=await this.checkCurrentDate("nationality",l,a??F,s);r=r&&q,s={...s,...R},_=utils.getNullifierFromDisclosureProof(l).toString(10),y=utils.getNullifierTypeFromDisclosureProof(l);}else if(b.name==="inclusion_check_issuing_country"){d=utils.getCommitmentInFromDisclosureProof(l),d!==f&&(console.warn("Failed to check the link between the validity of the ID and the issuing country inclusion check"),r=false,s.issuing_country={...s.issuing_country,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${d}`,message:"Failed to check the link between the validity of the ID and the issuing country inclusion check"}});let h=(b.committedInputs?.inclusion_check_issuing_country).countries,v=utils.getParameterCommitmentFromDisclosureProof(l),T=await utils.getCountryParameterCommitment(utils.ProofType.ISSUING_COUNTRY_INCLUSION,h,false);v!==T&&(console.warn("The committed country list for the issuing country inclusion check does not match the one from the proof"),r=false,s.issuing_country={...s.issuing_country,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${v}`,message:"The committed country list for the issuing country inclusion check does not match the one from the proof"}});let{isCorrect:D,queryResultErrors:E}=this.checkScopeFromDisclosureProof(t,l,s,"issuing_country",o),{isCorrect:$,queryResultErrors:V}=this.checkIssuingCountryInclusionPublicInputs(e,i,h);r=r&&$&&D,s={...s,...V,...E};let{isCorrect:q,queryResultErrors:R}=await this.checkCurrentDate("issuing_country",l,a??F,s);r=r&&q,s={...s,...R},_=utils.getNullifierFromDisclosureProof(l).toString(10),y=utils.getNullifierTypeFromDisclosureProof(l);}else if(b.name==="bind"){d=utils.getCommitmentInFromDisclosureProof(l),d!==f&&(console.warn("Failed to check the link between the validity of the ID and the bound data"),r=false,s.bind={...s.bind,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${d}`,message:"Failed to check the link between the validity of the ID and the bound data"}});let h=b.committedInputs?.bind,v=utils.getParameterCommitmentFromDisclosureProof(l),T=await utils.getBindParameterCommitment(utils.formatBoundData(h.data));v!==T&&(console.warn("The bound data does not match the one from the proof"),r=false,s.bind={...s.bind,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${v}`,message:"The bound data does not match the one from the proof"}});let{isCorrect:D,queryResultErrors:E}=this.checkScopeFromDisclosureProof(t,l,s,"bind",o),{isCorrect:$,queryResultErrors:V}=this.checkBindPublicInputs(e,i,h.data);r=r&&$&&D,s={...s,...V,...E};let{isCorrect:q,queryResultErrors:R}=await this.checkCurrentDate("bind",l,a??F,s);r=r&&q,s={...s,...R},_=utils.getNullifierFromDisclosureProof(l).toString(10),y=utils.getNullifierTypeFromDisclosureProof(l);}else if(b.name==="exclusion_check_sanctions"){d=utils.getCommitmentInFromDisclosureProof(l),d!==f&&(console.warn("Failed to check the link between the validity of the ID and the sanctions exclusion check"),r=false,s.sanctions={...s.sanctions,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${d}`,message:"Failed to check the link between the validity of the ID and the sanctions exclusion check"}});let h=b.committedInputs?.exclusion_check_sanctions,v=await utils.getSanctionsParameterCommitment(h.rootHash,h.isStrict),T=utils.getParameterCommitmentFromDisclosureProof(l);T!==v&&(console.warn("The sanction lists check against do not match the sanction lists from the proof"),r=false,s.sanctions={...s.sanctions,commitment:{expected:`Commitment: ${v.toString()}`,received:`Commitment: ${T.toString()}`,message:"The sanction lists check against do not match the sanction lists from the proof"}});let{isCorrect:D,queryResultErrors:E}=this.checkScopeFromDisclosureProof(t,l,s,"sanctions",o),{isCorrect:$,queryResultErrors:V}=await this.checkSanctionsExclusionPublicInputs(e,i,h,c,Q,u);r=r&&$&&D,s={...s,...V,...E};let{isCorrect:q,queryResultErrors:R}=await this.checkCurrentDate("sanctions",l,a??F,s);r=r&&q,s={...s,...R},_=utils.getNullifierFromDisclosureProof(l).toString(10),y=utils.getNullifierTypeFromDisclosureProof(l);}else if(b.name?.startsWith("facematch")&&!b.name?.endsWith("_evm")){d=utils.getCommitmentInFromDisclosureProof(l),d!==f&&(console.warn("Failed to check the link between the validity of the ID and the facematch check"),r=false,s.facematch={...s.facematch,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${d}`,message:"Failed to check the link between the validity of the ID and the facematch check"}});let h=b.committedInputs?.facematch,v=utils.getParameterCommitmentFromDisclosureProof(l),T=await utils.getFacematchParameterCommitment(BigInt(h.rootKeyLeaf),h.environment==="development"?0n:1n,BigInt(h.appIdHash),h.mode==="regular"?1n:2n);v!==T&&(console.warn("The FaceMatch verification does not match the ones from the proof"),r=false,s.facematch={...s.facematch,commitment:{expected:`Commitment: ${T.toString()}`,received:`Commitment: ${v.toString()}`,message:"The FaceMatch verification does not match the ones from the proof"}});let{isCorrect:D,queryResultErrors:E}=this.checkScopeFromDisclosureProof(t,l,s,"facematch",o),{isCorrect:$,queryResultErrors:V}=await this.checkFacematchPublicInputs(e,i,h);r=r&&$&&D,s={...s,...V,...E};let{isCorrect:q,queryResultErrors:R}=await this.checkCurrentDate("facematch",l,a??F,s);r=r&&q,s={...s,...R};}else console.warn(`Unexpected proof: ${b.name}`),r=false;}let re=A.filter(b=>b.name!=="facematch"&&j.includes(b.name)).map(b=>utils.getProofData(b.proof,utils.getNumberOfPublicInputs(b.name)));if(re.length>0){let b=(T,D)=>[...new Set(T.filter(E=>E!==D))],l=b(re.map(utils.getNullifierFromDisclosureProof),0n),h=b(re.map(utils.getNullifierTypeFromDisclosureProof),utils.NullifierType.NONE),v=b(re.map(utils.getOprfPkHashFromDisclosureProof),0n);(l.length>1||h.length>1||v.length>1)&&(console.warn("The disclosure proofs do not share the same nullifier"),r=false),_=l[0]?.toString(10),y=h[0]??utils.NullifierType.NONE,x=v[0];}let Ne=new Set;for(let b of A)for(let l of Object.keys(b.committedInputs??{}))Ne.add(l);let{isCorrect:rt,queryResultErrors:dt}=this.checkQueryCompleteness(e,Ne);if(r=r&&rt,s={...s,...dt},r&&y&&(y===utils.NullifierType.SALTED||y===utils.NullifierType.SALTED_MOCK))try{let b=await utils.getOprfPublicKey(m??utils.OPRF_DEFAULT_KEY_ID),l=await utils.hashOprfPublicKey(b),h=x;(h===void 0||h!==l)&&(console.warn("OPRF public key hash mismatch: proof uses an unknown OPRF key"),r=!1);}catch(b){console.warn("Failed to verify OPRF public key:",b),r=false;}return y===utils.NullifierType.NONE?(_!==void 0&&BigInt(_)!==0n&&(console.warn("Proofs with the NONE nullifier type cannot carry a unique identifier"),r=false),_=void 0):_!==void 0&&BigInt(_)===0n&&(_=void 0),{isCorrect:r,uniqueIdentifier:_,uniqueIdentifierType:y,queryResultErrors:s}}};var We={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 de=class p{static getDetails(){return {...{functionName:"verify",abi:We.abi},address:"0x1D000001000EFD9a6371f4d90bB8920D5431c0D8"}}static getParameters({proof:t,validityPeriodInSeconds:n=F,domain:e,scope:i,devMode:a=false}){if(!t.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 o=utils.getProofData(t.proof,utils.getNumberOfPublicInputs(t.name)),m=[],c=[];for(let _ in t.committedInputs){let y=utils.getCommittedInputCount(_),x=_;m.push({circuitName:x,count:y});let I="";if(x==="inclusion_check_issuing_country_evm"||x==="inclusion_check_nationality_evm"||x==="exclusion_check_issuing_country_evm"||x==="exclusion_check_nationality_evm"){let s=t.committedInputs[x].countries;(x==="exclusion_check_issuing_country_evm"||x==="exclusion_check_nationality_evm")&&s.sort((A,j)=>A.localeCompare(j));let z=(()=>{switch(x){case "exclusion_check_issuing_country_evm":return utils.ProofType.ISSUING_COUNTRY_EXCLUSION;case "exclusion_check_nationality_evm":return utils.ProofType.NATIONALITY_EXCLUSION;case "inclusion_check_issuing_country_evm":return utils.ProofType.ISSUING_COUNTRY_INCLUSION;case "inclusion_check_nationality_evm":return utils.ProofType.NATIONALITY_INCLUSION}})();I=z.toString(16).padStart(2,"0")+utils.ProofTypeLength[z].evm.toString(16).padStart(4,"0")+utils.rightPadArrayWithZeros(s.map(A=>Array.from(new TextEncoder().encode(A))).flat(),600).map(A=>A.toString(16).padStart(2,"0")).join("");}else if(x==="compare_age_evm"){let w=t.committedInputs[x];I=utils.ProofType.AGE.toString(16).padStart(2,"0")+utils.ProofTypeLength[utils.ProofType.AGE].evm.toString(16).padStart(4,"0")+w.minAge.toString(16).padStart(2,"0")+w.maxAge.toString(16).padStart(2,"0");}else if(x==="compare_birthdate_evm"){let w=t.committedInputs[x],s=Array.from(utils.numberToBytesBE(w.minDateTimestamp,8)),z=Array.from(utils.numberToBytesBE(w.maxDateTimestamp,8));I=utils.ProofType.BIRTHDATE.toString(16).padStart(2,"0")+utils.ProofTypeLength[utils.ProofType.BIRTHDATE].evm.toString(16).padStart(4,"0")+s.map(A=>A.toString(16).padStart(2,"0")).join("")+z.map(A=>A.toString(16).padStart(2,"0")).join("");}else if(x==="compare_expiry_evm"){let w=t.committedInputs[x],s=Array.from(utils.numberToBytesBE(w.minDateTimestamp,8)),z=Array.from(utils.numberToBytesBE(w.maxDateTimestamp,8));I=utils.ProofType.EXPIRY_DATE.toString(16).padStart(2,"0")+utils.ProofTypeLength[utils.ProofType.EXPIRY_DATE].evm.toString(16).padStart(4,"0")+s.map(A=>A.toString(16).padStart(2,"0")).join("")+z.map(A=>A.toString(16).padStart(2,"0")).join("");}else if(x==="disclose_bytes_evm"){let w=t.committedInputs[x];I=utils.ProofType.DISCLOSE.toString(16).padStart(2,"0")+utils.ProofTypeLength[utils.ProofType.DISCLOSE].evm.toString(16).padStart(4,"0")+w.discloseMask.map(s=>s.toString(16).padStart(2,"0")).join("")+w.disclosedBytes.map(s=>s.toString(16).padStart(2,"0")).join("");}else if(x==="bind_evm"){let w=t.committedInputs[x];I=utils.ProofType.BIND.toString(16).padStart(2,"0")+utils.ProofTypeLength[utils.ProofType.BIND].evm.toString(16).padStart(4,"0")+utils.rightPadArrayWithZeros(utils.formatBoundData(w.data),509).map(s=>s.toString(16).padStart(2,"0")).join("");}else if(x==="exclusion_check_sanctions_evm"){let w=t.committedInputs[x];I+=utils.ProofType.SANCTIONS_EXCLUSION.toString(16).padStart(2,"0"),I+=utils.ProofTypeLength[utils.ProofType.SANCTIONS_EXCLUSION].evm.toString(16).padStart(4,"0"),I+=Array.from(utils.numberToBytesBE(BigInt(w.rootHash),32)).map(s=>s.toString(16).padStart(2,"0")).join(""),I+=w.isStrict?"01":"00";}else if(x.startsWith("facematch")&&x.endsWith("_evm")){let w=t.committedInputs[x];I+=utils.ProofType.FACEMATCH.toString(16).padStart(2,"0"),I+=utils.ProofTypeLength[utils.ProofType.FACEMATCH].evm.toString(16).padStart(4,"0"),I+=Array.from(utils.numberToBytesBE(BigInt(w.rootKeyLeaf),32)).map(s=>s.toString(16).padStart(2,"0")).join(""),I+=w.environment==="development"?"00":"01",I+=Array.from(utils.numberToBytesBE(BigInt(w.appIdHash),32)).map(s=>s.toString(16).padStart(2,"0")).join(""),I+=Array.from(utils.numberToBytesBE(BigInt(w.integrityPubkeyHash),32)).map(s=>s.toString(16).padStart(2,"0")).join(""),I+=w.mode==="regular"?"01":"02";}else throw new Error(`Unsupported circuit for EVM verification: ${x}`);c.push({circuitName:x,inputs:I});}let u=utils.getParamCommitmentsFromOuterProof(o).map(_=>_.toString(16).padStart(64,"0")),d="";for(let _ of u){let y=c.find(x=>{let I=sha2_js.sha256(utils_js.hexToBytes(x.inputs)),w=new Uint8Array(I.length);for(let s=0;s<I.length-1;s++)w[s+1]=I[s];return w[0]=0,utils_js.bytesToHex(w)===_.replace("0x","")});if(y){let x=m.find(I=>I.circuitName===y.circuitName)?.count;if(x)d+=y.inputs;else throw new Error(`Unknown circuit name: ${y.circuitName}`)}else throw new Error(`Invalid commitment: ${_}`)}return {version:utils.circuitVersionToBytes32(t.version),proofVerificationData:{vkeyHash:`0x${t.vkeyHash.replace("0x","").padStart(64,"0")}`,proof:`0x${o.proof.join("")}`,publicInputs:o.publicInputs},committedInputs:`0x${d}`,serviceConfig:{validityPeriodInSeconds:n,domain:e,scope:i??"",devMode:a}}}static async verify({proof:t,rpcUrl:n,validityPeriodInSeconds:e,domain:i,scope:a,devMode:o}){try{let{createPublicClient:m,http:c}=await import('viem'),{address:u,abi:d,functionName:f}=p.getDetails(),r=m({transport:c(n)}),_=p.getParameters({proof:t,validityPeriodInSeconds:e,domain:i,scope:a,devMode:o}),y=await r.readContract({address:u,abi:d,functionName:f,args:[_]});return Array.isArray(y)?!!y[0]:!1}catch(m){return console.warn("Error verifying proof",m),false}}};async function Qe({domain:p,proofs:t,query:n,queryResult:e,scope:i,policyId:a,requestId:o}){let m=t.map(c=>({proof:c.proof,vkeyHash:c.vkeyHash,version:c.version,name:c.name,index:c.index,total:c.total,committedInputs:c.committedInputs}));try{let c=await fetch(`${le}/public/proofs`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({domain:p,proofs:m,query:n,queryResult:e,scope:i,policyId:a,sdkVersion:ce,requestId:o}),signal:AbortSignal.timeout(3e4)});c.ok?M.debug("API response status:",c.status):M.warn("API request failed with status:",c.status);}catch(c){}}var ii=[0,22,0];function ni(p){if(!p)return "v6";let t=p.split(".").map(n=>Number(n));return t.length!==3||t.some(n=>Number.isNaN(n))||oi(t,ii)?"v6":"v5"}async function ai(p,{writingDirectory:t}={}){await si();let n=t?t+"/.bb-crs":void 0;if(p==="v5"){let{UltraHonkVerifierBackend:m,Barretenberg:c}=await import('@aztec/bb.js'),u=await c.new({crsPath:n});return {verifier:new m(u),destroy:()=>u.destroy()}}let{UltraHonkVerifierBackend:e,Barretenberg:i}=await import('@aztec-foundation/bb.js'),a=await i.new({crsPath:n});return {verifier:new e(a),destroy:()=>a.destroy()}}var ge=class{constructor({writingDirectory:t}={}){this.writingDirectory=t;}async verify(t,n){let e=utils.getProofData(t.proof,utils.getNumberOfPublicInputs(t.name));this.loadedVerifier??(this.loadedVerifier=await ai(ni(t.version),{writingDirectory:this.writingDirectory}));try{return await this.loadedVerifier.verifier.verifyProof({proof:_.Buffer.from(e.proof.join(""),"hex"),publicInputs:e.publicInputs,verificationKey:new Uint8Array(_.Buffer.from(n.vkey,"base64"))})}catch(i){return console.warn(`Error verifying proof ${t.name}`,i),false}}async destroy(){await this.loadedVerifier?.destroy();}},et="__zkpassport_bb_version",tt="keyval-store",it="v5";async function si(){if(!(typeof indexedDB>"u"))try{let p=typeof localStorage<"u"?localStorage:void 0;if((p?.getItem(et)??"v4")===it)return;let t=!0;if(typeof indexedDB.databases=="function")try{t=(await indexedDB.databases()).some(n=>n.name===tt);}catch{t=!0;}t&&await new Promise(n=>{let e=indexedDB.deleteDatabase(tt);e.onsuccess=e.onerror=e.onblocked=()=>n();}),p?.setItem(et,it);}catch{}}function oi(p,t){for(let[n,e]of t.entries())if(p[n]!==e)return p[n]>e;return true}async function Ae({proofs:p,originalQuery:t,queryResult:n,domain:e,validity:i,scope:a,devMode:o,oprfKeyId:m}){try{let c=await fetch(`${qe}/verify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({proofs:p,originalQuery:t,queryResult:n,serviceConfig:{domain:e,scope:a,validityPeriodInSeconds:i,devMode:o},oprfKeyId:m}),signal:AbortSignal.timeout(6e4)});if(c.status>=500)return console.warn(`Verifier API error (status ${c.status})`),null;let u=await c.json().catch(()=>null);return !u||typeof u.verified!="boolean"?(console.warn(`Unexpected verifier API response (status ${c.status})`),null):u.verified?{uniqueIdentifier:u.uniqueIdentifier,uniqueIdentifierType:u.uniqueIdentifierType,verified:!0}:(console.warn("Verifier API did not verify the proofs:",u.error),{uniqueIdentifier:void 0,uniqueIdentifierType:void 0,verified:!1,queryResultErrors:u.queryResultErrors})}catch(c){return console.warn("Verifier API call failed:",c),null}}typeof globalThis.Buffer>"u"&&(globalThis.Buffer=_.Buffer,typeof window<"u"&&(window.Buffer=_.Buffer));var at="Verify identity privately";function fi({uniqueIdentifier:p,uniqueIdentifierType:t}){return t===utils.NullifierType.SALTED_MOCK?utils.NullifierType.SALTED:t===utils.NullifierType.NON_SALTED_MOCK?p===void 0?utils.NullifierType.NONE:utils.NullifierType.NON_SALTED:t}function li(p,t){if(t==null||!p.verified||fi(p)===t)return p;let n=p.uniqueIdentifierType,e=n===void 0?"missing":utils.NullifierType[n];return console.warn(`Unique identifier type mismatch: requested ${utils.NullifierType[t]}, got ${e}`),{...p,uniqueIdentifier:void 0,uniqueIdentifierType:void 0,verified:false}}var st=false;function ui(){st||(st=true,console.warn("[zkpassport] onResult is deprecated. Use onSuccess and verify the proofs on your backend with verify()."));}var ot=class{constructor(t){this.topicToConfig={};this.topicToLocalConfig={};this.topicToPublicKey={};this.topicToBridge={};this.topicToRequestReceived={};this.topicToService={};this.topicToCallerPurpose={};this.topicToProofs={};this.topicToFailedProofCount={};this.topicToResults={};this.topicToPolicy={};this.dashboardConfig=null;this.dashboardConfigPromise=null;this.dashboardConfigError=null;this.onRequestReceivedCallbacks={};this.onGeneratingProofCallbacks={};this.onBridgeConnectCallbacks={};this.onBridgeConnectionLostCallbacks={};this.onProofGeneratedCallbacks={};this.onSuccessCallbacks={};this.onResultCallbacks={};this.onRejectCallbacks={};this.onErrorCallbacks={};if(!t&&typeof window>"u")throw new Error("Domain argument is required in Node.js environment");this.domainProvided=!!t,this.domain=this.normalizeDomain(t||window.location.hostname);}normalizeDomain(t){return t.trim().replace(/^https?:\/\//,"").replace(/\/[^/]*$/,"").replace(/:[0-9]+/,"").replace(/\?.*$/,"").replace(/#.*$/,"").toLowerCase()}async handleResult(t){let n=this.topicToResults[t];delete this.topicToResults[t];let e=this.topicToProofs[t],i=this.topicToFailedProofCount[t]>0,a=!i&&e.length>0;if(a)try{await Promise.all(this.onSuccessCallbacks[t].map(c=>c({proofs:e,result:n})));}catch(c){}let o=this.topicToLocalConfig[t]?.devMode===true,m=this.topicToPolicy[t]?.proofStorageEnabled===true;a&&m&&this.domainProvided&&!o&&Qe({domain:this.domain,proofs:e,query:this.topicToConfig[t],queryResult:n,scope:this.topicToService[t]?.scope,policyId:this.topicToPolicy[t]?.id,requestId:this.topicToPublicKey[t]}),this.onResultCallbacks[t].length>0&&await this.verifyAndReportResult(t,e,n,i),delete this.topicToProofs[t],delete this.topicToFailedProofCount[t];}async verifyAndReportResult(t,n,e,i){let a;try{a=await this.verify({proofs:n,originalQuery:this.topicToConfig[t],queryResult:e,validity:this.topicToLocalConfig[t]?.validity,scope:this.topicToService[t]?.scope,devMode:this.topicToLocalConfig[t]?.devMode,oprfKeyId:this.topicToLocalConfig[t]?.oprfKeyId??void 0,uniqueIdentifierType:this.topicToLocalConfig[t]?.uniqueIdentifierType,verifierMode:this.topicToLocalConfig[t]?.verifierMode,config:this.topicToLocalConfig[t]?.config});}catch(d){let f=d instanceof Error?d.message:String(d);await Promise.all(this.onErrorCallbacks[t].map(r=>r(f)));return}let{uniqueIdentifier:o,uniqueIdentifierType:m,verified:c,queryResultErrors:u}=a;await Promise.all(this.onResultCallbacks[t].map(d=>d({uniqueIdentifier:i?void 0:o,uniqueIdentifierType:i?void 0:m,verified:i?false:c,result:e,queryResultErrors:u,proofs:n,sdkInstance:this})));}async handleEncryptedMessage(t,n){if(n.method==="accept")await Promise.all(this.onGeneratingProofCallbacks[t].map(e=>e(t)));else if(n.method==="reject")await Promise.all(this.onRejectCallbacks[t].map(e=>e()));else if(n.method==="proof")this.topicToProofs[t].push(n.params),await Promise.all(this.onProofGeneratedCallbacks[t].map(e=>e(n.params))),this.topicToResults[t]&&n.params.total===this.topicToProofs[t].length+this.topicToFailedProofCount[t]&&await this.handleResult(t);else if(n.method==="done")this.topicToResults[t]=utils.formatQueryResultDates(n.params),this.topicToProofs[t].length>0&&this.topicToProofs[t].length+this.topicToFailedProofCount[t]===this.topicToProofs[t][0].total&&await this.handleResult(t);else if(n.method==="error"){let e=n.params.error;e&&e==="This ID is not supported yet"?this.topicToResults[t]&&await this.handleResult(t):e&&e.startsWith("Cannot generate proof")&&(this.topicToFailedProofCount[t]+=1,this.topicToResults[t]&&this.topicToProofs[t].length>0&&this.topicToProofs[t].length+this.topicToFailedProofCount[t]===this.topicToProofs[t][0].total&&await this.handleResult(t)),await Promise.all(this.onErrorCallbacks[t].map(i=>i(e)));}}assertNotPolicyLocked(t,n){if(this.topicToPolicy[t])throw new Error(`Cannot call .${n}() on a policy-driven request. The query for policy '${this.topicToPolicy[t].id}' is immutable.`)}getZkPassportRequest(t){return {eq:(n,e)=>(this.assertNotPolicyLocked(t,"eq"),(n==="issuing_country"||n==="nationality")&&(e=te(e)),oe("eq",n,e,t,this.topicToConfig),this.getZkPassportRequest(t)),gte:(n,e)=>{if(this.assertNotPolicyLocked(t,"gte"),J("gte",n,e,t,this.topicToConfig),n==="age"&&(e<1||e>=100))throw new Error("Age must be between 1 and 99 (inclusive)");return this.getZkPassportRequest(t)},gt:(n,e)=>(this.assertNotPolicyLocked(t,"gt"),J("gt",n,e,t,this.topicToConfig),this.getZkPassportRequest(t)),lte:(n,e)=>(this.assertNotPolicyLocked(t,"lte"),J("lte",n,e,t,this.topicToConfig),this.getZkPassportRequest(t)),lt:(n,e)=>(this.assertNotPolicyLocked(t,"lt"),J("lt",n,e,t,this.topicToConfig),this.getZkPassportRequest(t)),range:(n,e,i)=>(this.assertNotPolicyLocked(t,"range"),ve(n,[e,i],t,this.topicToConfig),this.getZkPassportRequest(t)),in:(n,e)=>(this.assertNotPolicyLocked(t,"in"),e=e.map(i=>te(i)),oe("in",n,e,t,this.topicToConfig),this.getZkPassportRequest(t)),out:(n,e)=>(this.assertNotPolicyLocked(t,"out"),e=e.map(i=>te(i)),oe("out",n,e,t,this.topicToConfig),this.getZkPassportRequest(t)),disclose:n=>(this.assertNotPolicyLocked(t,"disclose"),this.topicToConfig[t][n]={...this.topicToConfig[t][n],disclose:true},this.getZkPassportRequest(t)),bind:(n,e)=>(this.topicToConfig[t].bind={...this.topicToConfig[t].bind,[n]:e},this.getZkPassportRequest(t)),sanctions:(n="all",e="all",i={strict:false})=>(this.assertNotPolicyLocked(t,"sanctions"),this.topicToConfig[t].sanctions={...this.topicToConfig[t].sanctions,countries:n,lists:e,strict:i.strict??false},this.getZkPassportRequest(t)),facematch:(n="strict")=>(this.assertNotPolicyLocked(t,"facematch"),this.topicToConfig[t].facematch={mode:n},this.getZkPassportRequest(t)),raw:n=>{this.assertNotPolicyLocked(t,"raw");let{policy:e,bind:i,...a}=n;if(e){if(Object.keys(a).length>0)throw new Error("A query with `policy` cannot also carry conditions (bind is allowed).");this.getZkPassportRequest(t).policy(e),i&&(this.topicToConfig[t].bind=i);}else this.topicToConfig[t]=n;return this.getZkPassportRequest(t)},policy:n=>{if(this.assertCanApplyPolicy(t,n),!this.dashboardConfig)throw this.dashboardConfigError?this.dashboardConfigError:new Error(`${this.domain} is not set up for ZKPassport verification. If this is your site, register the domain at https://dashboard.zkpassport.id.`);let e=this.findPolicy(this.dashboardConfig,n),{bind:i,...a}=e.query;this.topicToConfig[t]=a;let o=this.topicToService[t];return o&&(this.topicToCallerPurpose[t]||(o.purpose=e.purpose||at),o.scope||(o.scope=e.id),o.policyId=e.id),this.topicToPolicy[t]={id:e.id,proofStorageEnabled:e.proofStorageEnabled===true},this.getZkPassportRequest(t)},done:(()=>{if(this.topicToFailedProofCount[t]=0,this.topicToConfig[t]=he(this.topicToConfig[t]),t==="offline-query"){let o=this.topicToConfig[t];return delete this.topicToConfig[t],delete this.topicToPolicy[t],{query:o}}let n=this.topicToLocalConfig[t],e=this.topicToConfig[t],i=!!e.facematch,a=!!e.facematch&&e.facematch?.mode==="strict";if(n.uniqueIdentifierType===utils.NullifierType.SALTED&&(n.devMode===false&&!a||!i))throw new Error("Salted nullifier requires strict facematch. Add .facematch('strict') to your query or remove the salted nullifier option.");return {url:this._getUrl(t),query:this.topicToConfig[t],requestId:t,policy:this.topicToPolicy[t]?.id,onRequestReceived:o=>this.onRequestReceivedCallbacks[t].push(o),onGeneratingProof:o=>this.onGeneratingProofCallbacks[t].push(o),onBridgeConnect:o=>this.onBridgeConnectCallbacks[t].push(o),onBridgeConnectionLost:o=>this.onBridgeConnectionLostCallbacks[t].push(o),onProofGenerated:o=>this.onProofGeneratedCallbacks[t].push(o),onSuccess:o=>this.onSuccessCallbacks[t].push(o),onResult:o=>{ui(),this.onResultCallbacks[t].push(o);},onReject:o=>this.onRejectCallbacks[t].push(o),onError:o=>this.onErrorCallbacks[t].push(o),isBridgeConnected:()=>this.topicToBridge[t].isBridgeConnected(),requestReceived:()=>this.topicToRequestReceived[t]===true}})}}async getDashboardConfig(){return this.dashboardConfig?this.dashboardConfig:(this.dashboardConfigPromise||(this.dashboardConfigPromise=this.fetchDashboardConfig().then(t=>(this.dashboardConfig=t,t)).catch(t=>{throw this.dashboardConfigPromise=null,t})),this.dashboardConfigPromise)}async fetchDashboardConfig(){let t=`${le}/public/project?domain=${encodeURIComponent(this.domain)}`,n;try{n=await fetch(t,{signal:AbortSignal.timeout(1e4)});}catch(i){throw new Error(`Failed to fetch dashboard config for domain '${this.domain}': ${i.message}`)}if(!n.ok)throw new Error(`Failed to fetch dashboard config for domain '${this.domain}': ${n.status} ${n.statusText}`);let e=await n.json();if(e&&e.project===null)return null;if(!e||!e.project||!Array.isArray(e.policies))throw new Error(`Invalid dashboard config response for domain '${this.domain}'`);return e}findPolicy(t,n){let e=t.policies.find(i=>i.id===n);if(!e)throw new Error(`Policy '${n}' not found for domain '${this.domain}'. The dashboard returned ${t.policies.length} policies for this domain.`);if(!e.query||typeof e.query!="object")throw new Error(`Invalid policy '${n}' for domain '${this.domain}': missing query object.`);return e}assertCanApplyPolicy(t,n){if(typeof n!="string"||n.length===0)throw new Error(".policy() requires a non-empty string id.");if(this.topicToPolicy[t])throw new Error(`Cannot call .policy() more than once on a request (already set to '${this.topicToPolicy[t].id}').`);if(Object.keys(this.topicToConfig[t]).length>0)throw new Error("Cannot combine .policy() with builder methods like .gte()/.disclose()/etc. Call .policy() first; only .bind() may follow it.")}async request({name:t,logo:n,purpose:e,scope:i,projectID:a,mode:o,validity:m,devMode:c,uniqueIdentifierType:u,oprfKeyId:d,topicOverride:f,keyPairOverride:r,replayMissedMessages:_,cloudProverUrl:y,bridgeUrl:x,returnDeepLink:I,verifierMode:w,config:s,overrides:z}){if(f==="offline-query")throw new Error("You cannot override the topic with 'offline-query'");if(d&&u===utils.NullifierType.NONE)throw new Error("An OPRF key cannot be used with the NONE unique identifier type. Remove the oprfKeyId option or use the SALTED type.");let A=null;try{A=await this.getDashboardConfig(),this.dashboardConfigError=null;}catch(K){this.dashboardConfigError=K;}let j=await bridge.Bridge.create({keyPair:r,bridgeId:f,bridgeUrl:x,replayFrom:_?1:void 0}),k=j.connection.getBridgeId();return this.topicToConfig[k]={},this.topicToCallerPurpose[k]=e,this.topicToService[k]={name:t||A?.project?.name||this.domain,logo:n||A?.project?.logoUrl||"",purpose:e||at,scope:i,projectID:a,cloudProverUrl:y,bridgeUrl:x},this.topicToProofs[k]=[],this.topicToLocalConfig[k]={validity:m||F,mode:o||"fast",devMode:c??false,uniqueIdentifierType:d?utils.NullifierType.SALTED:u,oprfKeyId:d??null,returnDeepLink:I,verifierMode:w,config:s,appClip:z?.appClip??false},this.onRequestReceivedCallbacks[k]=[],this.onGeneratingProofCallbacks[k]=[],this.onBridgeConnectCallbacks[k]=[],this.onBridgeConnectionLostCallbacks[k]=[],this.onProofGeneratedCallbacks[k]=[],this.onSuccessCallbacks[k]=[],this.onResultCallbacks[k]=[],this.onRejectCallbacks[k]=[],this.onErrorCallbacks[k]=[],this.topicToPublicKey[k]=j.getPublicKey(),this.topicToBridge[k]=j,j.onConnect(async K=>{await Promise.all(this.onBridgeConnectCallbacks[k].map(Q=>Q()));}),j.onDisconnect(async K=>{K.wasIntentionalClose||K.willReconnect||(await Promise.all(this.onBridgeConnectionLostCallbacks[k].map(Q=>Q())));}),j.onSecureChannelEstablished(async()=>{await Promise.all(this.onRequestReceivedCallbacks[k].map(K=>K()));}),j.onSecureMessage(async K=>{try{await this.handleEncryptedMessage(k,K);}catch(Q){}}),this.getZkPassportRequest(k)}createQuery(){return Te()}async verify({proofs:t,originalQuery:n,queryResult:e,validity:i,scope:a,devMode:o=false,writingDirectory:m,oprfKeyId:c,uniqueIdentifierType:u,verifierMode:d="auto",config:f}){if(!n||!e)throw new Error("verify() requires `originalQuery` and `queryResult`");n=he(n);let r={uniqueIdentifier:void 0,uniqueIdentifierType:void 0,verified:false};if(!t||t.length===0)return r;let _={proofs:t,originalQuery:n,queryResult:e,validity:i,scope:a,devMode:o,oprfKeyId:c},y={..._,writingDirectory:m,config:f},x={..._,domain:this.domain},I=c?utils.NullifierType.SALTED:u,w;if(d==="local")w=await this.verifyLocally(y);else if(d==="api")w=await Ae(x)??r;else {let s;try{s=await this.verifyLocally(y);}catch(z){console.warn("Local proof verification failed:",z);}w=s?.verified?s:await Ae(x)??s??r;}return li(w,I)}async verifyLocally({proofs:t,originalQuery:n,queryResult:e,validity:i,scope:a,devMode:o=false,writingDirectory:m,oprfKeyId:c,config:u}){let d=utils.formatQueryResultDates(e);typeof window>"u"&&!m&&(m="/tmp");let f=new ge({writingDirectory:m}),r=true,_,y,x;try{let I=registry.createRegistryClient(utils.getChainFromQuery(n,o),u),{isCorrect:w,uniqueIdentifier:s,uniqueIdentifierType:z,queryResultErrors:A}=await ye.checkPublicInputs(this.domain,t,n,d,i,a,c,o,I);if(_=s,y=z,r=w,x=w?void 0:A,(y===utils.NullifierType.SALTED_MOCK||y===utils.NullifierType.NON_SALTED_MOCK)&&!o&&(r=!1,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.")),r){let j=await I.getCircuitManifest(void 0,{version:t[0].version});for(let k of t){let K=k.name?.startsWith("outer_evm_"),Q=k.name,re=await I.getPackagedCircuit(Q,j,{validate:!K});if(K?r=await de.verify({proof:k,rpcUrl:I.getRpcUrl(),validityPeriodInSeconds:i,domain:this.domain,scope:a,devMode:o}):r=await f.verify(k,re),!r)break}}}finally{await f.destroy();}return _=r?_:void 0,y=r?y:void 0,{uniqueIdentifier:_,uniqueIdentifierType:y,verified:r,queryResultErrors:x}}getSolidityVerifierDetails(){return de.getDetails()}getSolidityVerifierParameters({proof:t,validityPeriodInSeconds:n=F,domain:e,scope:i,devMode:a=false}){return de.getParameters({proof:t,validityPeriodInSeconds:n,domain:e??this.domain,scope:i,devMode:a})}_getUrl(t){let n=_.Buffer.from(JSON.stringify(this.topicToConfig[t])).toString("base64"),e=_.Buffer.from(JSON.stringify(this.topicToService[t])).toString("base64"),i=this.topicToPublicKey[t],a=Math.floor(Date.now()/1e3)-this.topicToLocalConfig[t].validity,o=this.topicToLocalConfig[t].uniqueIdentifierType,m=this.topicToLocalConfig[t].oprfKeyId,c=this.topicToLocalConfig[t].returnDeepLink,d=`https://zkpassport.id/${this.topicToLocalConfig[t].appClip?"c":"r"}?d=${this.domain}&t=${t}&c=${encodeURIComponent(n)}&s=${encodeURIComponent(e)}&p=${i}&m=${this.topicToLocalConfig[t].mode}&v=${ce}&dt=${a}&dev=${this.topicToLocalConfig[t].devMode?"1":"0"}`;return o!=null&&(d+=`&nt=${o}`),m&&(d+=`&oprf_k=${m}`),c&&(d+=`&r=${encodeURIComponent(c)}`),d}getUrl(t){return this._getUrl(t)}getServiceDetails(t){return this.topicToService[t]}getRequestKeyPair(t){return this.topicToBridge[t]?.getKeyPair()}cancelRequest(t){this.topicToBridge[t]&&(this.topicToBridge[t].close(),delete this.topicToBridge[t]),delete this.topicToPublicKey[t],delete this.topicToConfig[t],delete this.topicToLocalConfig[t],delete this.topicToProofs[t],delete this.topicToFailedProofCount[t],delete this.topicToResults[t],delete this.topicToPolicy[t],this.onRequestReceivedCallbacks[t]=[],this.onGeneratingProofCallbacks[t]=[],this.onBridgeConnectCallbacks[t]=[],this.onBridgeConnectionLostCallbacks[t]=[],this.onProofGeneratedCallbacks[t]=[],this.onSuccessCallbacks[t]=[],this.onResultCallbacks[t]=[],this.onRejectCallbacks[t]=[],this.onErrorCallbacks[t]=[];}clearAllRequests(){for(let t in this.topicToBridge)this.cancelRequest(t);}};
2
- Object.defineProperty(exports,"ASEAN_COUNTRIES",{enumerable:true,get:function(){return utils.ASEAN_COUNTRIES}});Object.defineProperty(exports,"EEA_COUNTRIES",{enumerable:true,get:function(){return utils.EEA_COUNTRIES}});Object.defineProperty(exports,"EU_COUNTRIES",{enumerable:true,get:function(){return utils.EU_COUNTRIES}});Object.defineProperty(exports,"MERCOSUR_COUNTRIES",{enumerable:true,get:function(){return utils.MERCOSUR_COUNTRIES}});Object.defineProperty(exports,"NullifierType",{enumerable:true,get:function(){return utils.NullifierType}});Object.defineProperty(exports,"ProofType",{enumerable:true,get:function(){return utils.ProofType}});Object.defineProperty(exports,"ProofTypeLength",{enumerable:true,get:function(){return utils.ProofTypeLength}});Object.defineProperty(exports,"SANCTIONED_COUNTRIES",{enumerable:true,get:function(){return utils.SANCTIONED_COUNTRIES}});Object.defineProperty(exports,"SCHENGEN_COUNTRIES",{enumerable:true,get:function(){return utils.SCHENGEN_COUNTRIES}});Object.defineProperty(exports,"getChainFromId",{enumerable:true,get:function(){return utils.getChainFromId}});Object.defineProperty(exports,"getIdFromChain",{enumerable:true,get:function(){return utils.getIdFromChain}});exports.VERSION=ce;exports.ZKPassport=ot;exports.createOfflineQuery=Te;exports.normalizeCountry=te;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var utils=require('@zkpassport/utils'),_=require('buffer/'),registry=require('@zkpassport/registry'),bridge=require('@obsidion/bridge'),i18nIsoCountries=require('i18n-iso-countries'),kt=require('i18n-iso-countries/langs/en.json'),sha2_js=require('@noble/hashes/sha2.js'),utils_js=require('@noble/hashes/utils.js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var kt__default=/*#__PURE__*/_interopDefault(kt);var F={debug:(...p)=>{},info:(...p)=>{},warn:(...p)=>{},error:(...p)=>{}};i18nIsoCountries.registerLocale(kt__default.default);function se(p){if(p==="Zero Knowledge Republic")return "ZKR";let t;return t=i18nIsoCountries.getAlpha3Code(p,"en")||p||"ZKR",t}function te(p,t,n,e,i){i[e][t]={...i[e][t],[p]:n};}function Ve(p,t,n,e){e[n][p]={...e[n][p],range:t};}function fe(p,t,n,e,i){i[e][t]={...i[e][t],[p]:n};}function Ne(){let p={query:{}},t="query",n=false,e=a=>{if(p[t].policy)throw new Error(`Cannot call .${a}() on a policy-driven query. The query for policy '${p[t].policy}' is immutable.`);n=true;},i={eq:(a,o)=>(e("eq"),(a==="issuing_country"||a==="nationality")&&(o=se(o)),fe("eq",a,o,t,p),i),gte:(a,o)=>{if(e("gte"),te("gte",a,o,t,p),a==="age"&&(o<1||o>=100))throw new Error("Age must be between 1 and 99 (inclusive)");return i},gt:(a,o)=>(e("gt"),te("gt",a,o,t,p),i),lte:(a,o)=>(e("lte"),te("lte",a,o,t,p),i),lt:(a,o)=>(e("lt"),te("lt",a,o,t,p),i),range:(a,o,m)=>(e("range"),Ve(a,[o,m],t,p),i),in:(a,o)=>(e("in"),o=o.map(m=>se(m)),fe("in",a,o,t,p),i),out:(a,o)=>(e("out"),o=o.map(m=>se(m)),fe("out",a,o,t,p),i),disclose:a=>(e("disclose"),p[t][a]={...p[t][a],disclose:true},i),bind:(a,o)=>(p[t].bind={...p[t].bind,[a]:o},i),sanctions:(a="all",o="all",m={strict:false})=>(e("sanctions"),p[t].sanctions={...p[t].sanctions,countries:a,lists:o,strict:m.strict??false},i),facematch:(a="strict")=>(e("facematch"),p[t].facematch={mode:a},i),raw:a=>(e("raw"),p[t]=a,i),policy:a=>{if(typeof a!="string"||a.length===0)throw new Error(".policy() requires a non-empty string id.");if(p[t].policy)throw new Error(`Cannot call .policy() more than once on a request (already set to '${p[t].policy}').`);if(n)throw new Error("Cannot combine .policy() with builder methods like .gte()/.disclose()/etc.");return p[t].policy=a,i},done:(()=>({query:p[t]}))};return i}var Ke="0.21.0-beta.1";var me=Ke,H=10080*60,ie=new Date(0),he="https://dashboard-api.zkpassport.id",ze="https://verifier.zkpassport.id";var ge="0x1fa73686cf510f8f85757b0602de0dd72a13e68ae2092462be8b72662e7f179b",$e="0x1409355f7733451c37093c8aac68611b102c0f270c9961d74ef6cfa6f888d3f0",ve="0x24d9929b248be7eeecaa98e105c034a50539610f3fdd4cb9c8983ef4100d615d",pe="0x2532418a107c5306fa8308c22255792cf77e4a290cbce8a840a642a3e591340b",Ce="0x16700a2d9168a194fc85f237af5829b5a2be05b8ae8ac4879ada34cf54a9c211",xe="0x0e1889bec6c1d686abcf08360ff404f803ab345881ea8cba6aad33b7f7f7ffe0";var Be=1440*60*1e3,ft=720*60*60*1e3;function Se(p){return !["firstname","lastname","fullname","birthdate","expiry_date","nationality","gender","document_number"].some(n=>p[n]?.disclose||p[n]?.eq!==void 0)||p.document_type?.disclose||p.document_type?.eq!==void 0?p:{...p,document_type:{...p.document_type,disclose:true}}}var Pe=class{static checkDiscloseBytesPublicInputs(t,n,e){let i={},a=true;n=Se(n);let o=t.committedInputs?.disclose_bytes?.disclosedBytes??t.committedInputs?.disclose_bytes_evm?.disclosedBytes,m=o?.[0]?String.fromCharCode(o[0])==="P"?"passport":"id_card":void 0,d=utils.DisclosedData.fromDisclosedBytes(o,m??"passport"),f=utils.DisclosedData.fromDisclosedBytes(o,m??"id_card");if(e.document_type&&(e.document_type.eq&&e.document_type.eq.result&&e.document_type.eq.expected!==d.documentType&&(console.warn("Document type does not match the expected document type"),a=false,i.document_type={...i.document_type,eq:{expected:`${e.document_type.eq.expected}`,received:`${d.documentType??f.documentType}`,message:"Document type does not match the expected document type"}}),e.document_type.disclose&&e.document_type.disclose.result!==f.documentType&&(console.warn("Document type does not match the disclosed document type in query result"),a=false,i.document_type={...i.document_type,disclose:{expected:`${e.document_type.disclose?.result}`,received:`${f.documentType??d.documentType}`,message:"Document type does not match the disclosed document type in query result"}}),e.document_type.eq&&(n.document_type?.eq===void 0||e.document_type.eq.expected!==n.document_type.eq)&&(console.warn("Document type eq does not match the original query"),a=false,i.document_type={...i.document_type,eq:{expected:`${n.document_type?.eq}`,received:`${e.document_type.eq.expected}`,message:"Document type eq does not match the original query"}}),e.document_type.disclose&&!n.document_type?.disclose&&(console.warn("Document type disclose is not in the original query"),a=false,i.document_type={...i.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 l=d.dateOfBirth,c=f.dateOfBirth;e.birthdate.eq&&e.birthdate.eq.result&&!utils.areDatesEqual(e.birthdate.eq.expected,l)&&!utils.areDatesEqual(e.birthdate.eq.expected,c)&&(console.warn("Birthdate does not match the expected birthdate"),a=false,i.birthdate={...i.birthdate,eq:{expected:`${e.birthdate.eq.expected.toISOString()}`,received:`${l?.toISOString()??c?.toISOString()}`,message:"Birthdate does not match the expected birthdate"}}),e.birthdate.disclose&&!utils.areDatesEqual(e.birthdate.disclose.result,l)&&!utils.areDatesEqual(e.birthdate.disclose.result,c)&&(console.warn("Birthdate does not match the disclosed birthdate in query result"),a=false,i.birthdate={...i.birthdate,disclose:{expected:`${e.birthdate.disclose.result.toISOString()}`,received:`${l?.toISOString()??c?.toISOString()}`,message:"Birthdate does not match the disclosed birthdate in query result"}}),e.birthdate.eq&&(n.birthdate?.eq===void 0||!utils.areDatesEqual(e.birthdate.eq.expected,n.birthdate.eq))&&(console.warn("Birthdate eq does not match the original query"),a=false,i.birthdate={...i.birthdate,eq:{expected:`${n.birthdate?.eq?.toISOString?.()??"undefined"}`,received:`${e.birthdate.eq.expected.toISOString()}`,message:"Birthdate eq does not match the original query"}}),e.birthdate.disclose&&!n.birthdate?.disclose&&(console.warn("Birthdate disclose is not in the original query"),a=false,i.birthdate={...i.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 l=d.dateOfExpiry,c=f.dateOfExpiry;e.expiry_date.eq&&e.expiry_date.eq.result&&!utils.areDatesEqual(e.expiry_date.eq.expected,l)&&!utils.areDatesEqual(e.expiry_date.eq.expected,c)&&(console.warn("Expiry date does not match the expected expiry date"),a=false,i.expiry_date={...i.expiry_date,eq:{expected:`${e.expiry_date.eq.expected.toISOString()}`,received:`${l?.toISOString()??c?.toISOString()}`,message:"Expiry date does not match the expected expiry date"}}),e.expiry_date.disclose&&!utils.areDatesEqual(e.expiry_date.disclose.result,l)&&!utils.areDatesEqual(e.expiry_date.disclose.result,c)&&(console.warn("Expiry date does not match the disclosed expiry date in query result"),a=false,i.expiry_date={...i.expiry_date,disclose:{expected:`${e.expiry_date.disclose.result.toISOString()}`,received:`${l?.toISOString()??c?.toISOString()}`,message:"Expiry date does not match the disclosed expiry date in query result"}}),e.expiry_date.eq&&(n.expiry_date?.eq===void 0||!utils.areDatesEqual(e.expiry_date.eq.expected,n.expiry_date.eq))&&(console.warn("Expiry date eq does not match the original query"),a=false,i.expiry_date={...i.expiry_date,eq:{expected:`${n.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&&!n.expiry_date?.disclose&&(console.warn("Expiry date disclose is not in the original query"),a=false,i.expiry_date={...i.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 l=d.nationality,c=f.nationality;e.nationality.eq&&e.nationality.eq.result&&e.nationality.eq.expected!==l&&e.nationality.eq.expected!==c&&(console.warn("Nationality does not match the expected nationality"),a=false,i.nationality={...i.nationality,eq:{expected:`${e.nationality.eq.expected}`,received:`${l??c}`,message:"Nationality does not match the expected nationality"}}),e.nationality.disclose&&e.nationality.disclose.result!==l&&e.nationality.disclose.result!==c&&(console.warn("Nationality does not match the disclosed nationality in query result"),a=false,i.nationality={...i.nationality,disclose:{expected:`${e.nationality.disclose.result}`,received:`${l??c}`,message:"Nationality does not match the disclosed nationality in query result"}}),e.nationality.eq&&(n.nationality?.eq===void 0||e.nationality.eq.expected!==n.nationality.eq)&&(console.warn("Nationality eq does not match the original query"),a=false,i.nationality={...i.nationality,eq:{expected:`${n.nationality?.eq}`,received:`${e.nationality.eq.expected}`,message:"Nationality eq does not match the original query"}}),e.nationality.disclose&&!n.nationality?.disclose&&(console.warn("Nationality disclose is not in the original query"),a=false,i.nationality={...i.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 l=d.documentNumber,c=f.documentNumber;e.document_number.eq&&e.document_number.eq.result&&e.document_number.eq.expected!==l&&e.document_number.eq.expected!==c&&(console.warn("Document number does not match the expected document number"),a=false,i.document_number={...i.document_number,eq:{expected:`${e.document_number.eq.expected}`,received:`${l??c}`,message:"Document number does not match the expected document number"}}),e.document_number.disclose&&e.document_number.disclose.result!==l&&e.document_number.disclose.result!==c&&(console.warn("Document number does not match the disclosed document number in query result"),a=false,i.document_number={...i.document_number,disclose:{expected:`${e.document_number.disclose.result}`,received:`${l??c}`,message:"Document number does not match the disclosed document number in query result"}}),e.document_number.eq&&(n.document_number?.eq===void 0||e.document_number.eq.expected!==n.document_number.eq)&&(console.warn("Document number eq does not match the original query"),a=false,i.document_number={...i.document_number,eq:{expected:`${n.document_number?.eq}`,received:`${e.document_number.eq.expected}`,message:"Document number eq does not match the original query"}}),e.document_number.disclose&&!n.document_number?.disclose&&(console.warn("Document number disclose is not in the original query"),a=false,i.document_number={...i.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 l=d.gender,c=f.gender;e.gender.eq&&e.gender.eq.result&&e.gender.eq.expected!==l&&e.gender.eq.expected!==c&&(console.warn("Gender does not match the expected gender"),a=false,i.gender={...i.gender,eq:{expected:`${e.gender.eq.expected}`,received:`${l??c}`,message:"Gender does not match the expected gender"}}),e.gender.disclose&&e.gender.disclose.result!==l&&e.gender.disclose.result!==c&&(console.warn("Gender does not match the disclosed gender in query result"),a=false,i.gender={...i.gender,disclose:{expected:`${e.gender.disclose.result}`,received:`${l??c}`,message:"Gender does not match the disclosed gender in query result"}}),e.gender.eq&&(n.gender?.eq===void 0||e.gender.eq.expected!==n.gender.eq)&&(console.warn("Gender eq does not match the original query"),a=false,i.gender={...i.gender,eq:{expected:`${n.gender?.eq}`,received:`${e.gender.eq.expected}`,message:"Gender eq does not match the original query"}}),e.gender.disclose&&!n.gender?.disclose&&(console.warn("Gender disclose is not in the original query"),a=false,i.gender={...i.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 l=d.issuingCountry,c=f.issuingCountry;e.issuing_country.eq&&e.issuing_country.eq.result&&e.issuing_country.eq.expected!==l&&e.issuing_country.eq.expected!==c&&(console.warn("Issuing country does not match the expected issuing country"),a=false,i.issuing_country={...i.issuing_country,eq:{expected:`${e.issuing_country.eq.expected}`,received:`${l??c}`,message:"Issuing country does not match the expected issuing country"}}),e.issuing_country.disclose&&e.issuing_country.disclose.result!==l&&e.issuing_country.disclose.result!==c&&(console.warn("Issuing country does not match the disclosed issuing country in query result"),a=false,i.issuing_country={...i.issuing_country,disclose:{expected:`${e.issuing_country.disclose.result}`,received:`${l??c}`,message:"Issuing country does not match the disclosed issuing country in query result"}}),e.issuing_country.eq&&(n.issuing_country?.eq===void 0||e.issuing_country.eq.expected!==n.issuing_country.eq)&&(console.warn("Issuing country eq does not match the original query"),a=false,i.issuing_country={...i.issuing_country,eq:{expected:`${n.issuing_country?.eq}`,received:`${e.issuing_country.eq.expected}`,message:"Issuing country eq does not match the original query"}}),e.issuing_country.disclose&&!n.issuing_country?.disclose&&(console.warn("Issuing country disclose is not in the original query"),a=false,i.issuing_country={...i.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 l=d.name,c=f.name;e.fullname.eq&&e.fullname.eq.result&&utils.formatName(e.fullname.eq.expected).toLowerCase()!==l.toLowerCase()&&utils.formatName(e.fullname.eq.expected).toLowerCase()!==c.toLowerCase()&&(console.warn("Fullname does not match the expected fullname"),a=false,i.fullname={...i.fullname,eq:{expected:`${e.fullname.eq.expected}`,received:`${l??c}`,message:"Fullname does not match the expected fullname"}}),e.fullname.disclose&&utils.formatName(e.fullname.disclose.result).toLowerCase()!==l.toLowerCase()&&utils.formatName(e.fullname.disclose.result).toLowerCase()!==c.toLowerCase()&&(console.warn("Fullname does not match the disclosed fullname in query result"),a=false,i.fullname={...i.fullname,disclose:{expected:`${e.fullname.disclose.result}`,received:`${l??c}`,message:"Fullname does not match the disclosed fullname in query result"}}),e.fullname.eq&&(n.fullname?.eq===void 0||utils.formatName(e.fullname.eq.expected).toLowerCase()!==utils.formatName(n.fullname.eq).toLowerCase())&&(console.warn("Fullname eq does not match the original query"),a=false,i.fullname={...i.fullname,eq:{expected:`${n.fullname?.eq}`,received:`${e.fullname.eq.expected}`,message:"Fullname eq does not match the original query"}}),e.fullname.disclose&&!n.fullname?.disclose&&(console.warn("Fullname disclose is not in the original query"),a=false,i.fullname={...i.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 l=d.firstName&&d.firstName.length>0?d.firstName:d.name,c=f.firstName&&f.firstName.length>0?f.firstName:f.name;e.firstname.eq&&e.firstname.eq.result&&utils.formatName(e.firstname.eq.expected).toLowerCase()!==l.toLowerCase()&&utils.formatName(e.firstname.eq.expected).toLowerCase()!==c.toLowerCase()&&(console.warn("Firstname does not match the expected firstname"),a=false,i.firstname={...i.firstname,eq:{expected:`${e.firstname.eq.expected}`,received:`${l??c}`,message:"Firstname does not match the expected firstname"}}),e.firstname.disclose&&utils.formatName(e.firstname.disclose.result).toLowerCase()!==l.toLowerCase()&&utils.formatName(e.firstname.disclose.result).toLowerCase()!==c.toLowerCase()&&(console.warn("Firstname does not match the disclosed firstname in query result"),a=false,i.firstname={...i.firstname,disclose:{expected:`${e.firstname.disclose.result}`,received:`${l??c}`,message:"Firstname does not match the disclosed firstname in query result"}}),e.firstname.eq&&(n.firstname?.eq===void 0||utils.formatName(e.firstname.eq.expected).toLowerCase()!==utils.formatName(n.firstname.eq).toLowerCase())&&(console.warn("Firstname eq does not match the original query"),a=false,i.firstname={...i.firstname,eq:{expected:`${n.firstname?.eq}`,received:`${e.firstname.eq.expected}`,message:"Firstname eq does not match the original query"}}),e.firstname.disclose&&!n.firstname?.disclose&&(console.warn("Firstname disclose is not in the original query"),a=false,i.firstname={...i.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 l=d.lastName&&d.lastName.length>0?d.lastName:d.name,c=f.lastName&&f.lastName.length>0?f.lastName:f.name;e.lastname.eq&&e.lastname.eq.result&&utils.formatName(e.lastname.eq.expected).toLowerCase()!==l.toLowerCase()&&utils.formatName(e.lastname.eq.expected).toLowerCase()!==c.toLowerCase()&&(console.warn("Lastname does not match the expected lastname"),a=false,i.lastname={...i.lastname,eq:{expected:`${e.lastname.eq.expected}`,received:`${l??c}`,message:"Lastname does not match the expected lastname"}}),e.lastname.disclose&&utils.formatName(e.lastname.disclose.result).toLowerCase()!==l.toLowerCase()&&utils.formatName(e.lastname.disclose.result).toLowerCase()!==c.toLowerCase()&&(console.warn("Lastname does not match the disclosed lastname in query result"),a=false,i.lastname={...i.lastname,disclose:{expected:`${e.lastname.disclose.result}`,received:`${l??c}`,message:"Lastname does not match the disclosed lastname in query result"}}),e.lastname.eq&&(n.lastname?.eq===void 0||utils.formatName(e.lastname.eq.expected).toLowerCase()!==utils.formatName(n.lastname.eq).toLowerCase())&&(console.warn("Lastname eq does not match the original query"),a=false,i.lastname={...i.lastname,eq:{expected:`${n.lastname?.eq}`,received:`${e.lastname.eq.expected}`,message:"Lastname eq does not match the original query"}}),e.lastname.disclose&&!n.lastname?.disclose&&(console.warn("Lastname disclose is not in the original query"),a=false,i.lastname={...i.lastname,disclose:{expected:"Not requested in original query",received:`${e.lastname.disclose.result}`,message:"Lastname disclose is not in the original query"}});}return {isCorrect:a,queryResultErrors:i}}static checkAgePublicInputs(t,n,e){let i={},a=true,o=new Date;new Date(o.getFullYear(),o.getMonth(),o.getDate(),0,0,0,0);let d=utils.getMinAgeFromCommittedInputs(t.committedInputs?.compare_age??t.committedInputs?.compare_age_evm),f=utils.getMaxAgeFromCommittedInputs(t.committedInputs?.compare_age??t.committedInputs?.compare_age_evm);return e.age?(e.age.gte&&e.age.gte.result&&d!==e.age.gte.expected&&(console.warn("Age is not greater than or equal to the expected age"),a=false,i.age={...i.age,gte:{expected:e.age.gte.expected,received:d,message:"Age is not greater than or equal to the expected age"}}),e.age.gt&&e.age.gt.result&&d!==e.age.gt.expected+1&&(console.warn("Age is not greater than the expected age"),a=false,i.age={...i.age,gt:{expected:e.age.gt.expected,received:d,message:"Age is not greater than the expected age"}}),e.age.lt&&e.age.lt.result&&f!==e.age.lt.expected-1&&(console.warn("Age is not less than the expected age"),a=false,i.age={...i.age,lt:{expected:e.age.lt.expected,received:f,message:"Age is not less than the expected age"}}),e.age.lte&&e.age.lte.result&&f!==e.age.lte.expected&&(console.warn("Age is not less than or equal to the expected age"),a=false,i.age={...i.age,lte:{expected:e.age.lte.expected,received:f,message:"Age is not less than or equal to the expected age"}}),e.age.eq&&e.age.eq.result&&(d!==e.age.eq.expected||f!==e.age.eq.expected)&&(console.warn("Age does not match the expected age"),a=false,i.age={...i.age,eq:{expected:e.age.eq.expected,received:d!==e.age.eq.expected?d:f,message:"Age does not match the expected age"}}),e.age.range&&e.age.range.result&&(d!==e.age.range.expected[0]||f!==e.age.range.expected[1])&&(console.warn("Age is not in the expected range"),a=false,i.age={...i.age,range:{expected:e.age.range.expected,received:[d,f],message:"Age is not in the expected range"}}),!e.age.lt&&!e.age.lte&&!e.age.eq&&!e.age.range&&f!=0&&(console.warn("Maximum age should be equal to 0"),a=false,i.age={...i.age,disclose:{expected:0,received:f,message:"Maximum age should be equal to 0"}}),!e.age.gte&&!e.age.gt&&!e.age.eq&&!e.age.range&&d!=0&&(console.warn("Minimum age should be equal to 0"),a=false,i.age={...i.age,disclose:{expected:0,received:d,message:"Minimum age should be equal to 0"}}),e.age.disclose&&(e.age.disclose.result!==d||e.age.disclose.result!==f)&&(console.warn("Age does not match the disclosed age in query result"),a=false,i.age={...i.age,disclose:{expected:`${d}`,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"),a=false,i.age={...i.age,disclose:{message:"Age is not set in the query result"}}),e.age?.gte&&(n.age?.gte===void 0||e.age.gte.expected!==n.age.gte)&&(console.warn("Age gte does not match the original query"),a=false,i.age={...i.age,gte:{expected:n.age?.gte,received:e.age.gte.expected,message:"Age gte does not match the original query"}}),e.age?.gt&&(n.age?.gt===void 0||e.age.gt.expected!==n.age.gt)&&(console.warn("Age gt does not match the original query"),a=false,i.age={...i.age,gt:{expected:n.age?.gt,received:e.age.gt.expected,message:"Age gt does not match the original query"}}),e.age?.lt&&(n.age?.lt===void 0||e.age.lt.expected!==n.age.lt)&&(console.warn("Age lt does not match the original query"),a=false,i.age={...i.age,lt:{expected:n.age?.lt,received:e.age.lt.expected,message:"Age lt does not match the original query"}}),e.age?.lte&&(n.age?.lte===void 0||e.age.lte.expected!==n.age.lte)&&(console.warn("Age lte does not match the original query"),a=false,i.age={...i.age,lte:{expected:n.age?.lte,received:e.age.lte.expected,message:"Age lte does not match the original query"}}),e.age?.eq&&(n.age?.eq===void 0||e.age.eq.expected!==n.age.eq)&&(console.warn("Age eq does not match the original query"),a=false,i.age={...i.age,eq:{expected:n.age?.eq,received:e.age.eq.expected,message:"Age eq does not match the original query"}}),e.age?.range&&(n.age?.range===void 0||e.age.range.expected[0]!==n.age.range[0]||e.age.range.expected[1]!==n.age.range[1])&&(console.warn("Age range does not match the original query"),a=false,i.age={...i.age,range:{expected:n.age?.range,received:e.age.range.expected,message:"Age range does not match the original query"}}),e.age?.disclose&&!n.age?.disclose&&(console.warn("Age disclose is not in the original query"),a=false,i.age={...i.age,disclose:{expected:"Not requested in original query",received:`${e.age.disclose.result}`,message:"Age disclose is not in the original query"}}),{isCorrect:a,queryResultErrors:i}}static checkBirthdatePublicInputs(t,n,e){let i={},a=true,o=new Date;new Date(o.getFullYear(),o.getMonth(),o.getDate(),0,0,0);let d=utils.getBirthdateMinDateTimestamp(t.committedInputs?.compare_birthdate??t.committedInputs?.compare_birthdate_evm,-1*utils.SECONDS_BETWEEN_1900_AND_1970),f=utils.getBirthdateMaxDateTimestamp(t.committedInputs?.compare_birthdate??t.committedInputs?.compare_birthdate_evm,-1*utils.SECONDS_BETWEEN_1900_AND_1970);if(e.birthdate){if(e.birthdate.gte&&e.birthdate.gte.result&&!utils.areDatesEqual(d,e.birthdate.gte.expected)&&(console.warn("Birthdate is not greater than or equal to the expected birthdate"),a=false,i.birthdate={...i.birthdate,gte:{expected:e.birthdate.gte.expected,received:d,message:"Birthdate is not greater than or equal to the expected birthdate"}}),e.birthdate.gt&&e.birthdate.gt.result){let l=new Date(e.birthdate.gt.expected);l.setDate(l.getDate()+1),utils.areDatesEqual(d,l)||(console.warn("Birthdate is not greater than the expected birthdate"),a=false,i.birthdate={...i.birthdate,gt:{expected:e.birthdate.gt.expected,received:d,message:"Birthdate is not greater than the expected birthdate"}});}if(e.birthdate.lte&&e.birthdate.lte.result&&!utils.areDatesEqual(f,e.birthdate.lte.expected)&&(console.warn("Birthdate is not less than the expected birthdate"),a=false,i.birthdate={...i.birthdate,lte:{expected:e.birthdate.lte.expected,received:f,message:"Birthdate is not less than the expected birthdate"}}),e.birthdate.lt&&e.birthdate.lt.result){let l=new Date(e.birthdate.lt.expected);l.setDate(l.getDate()-1),utils.areDatesEqual(f,l)||(console.warn("Birthdate is not less than the expected birthdate"),a=false,i.birthdate={...i.birthdate,lt:{expected:e.birthdate.lt.expected,received:f,message:"Birthdate is not less than the expected birthdate"}});}e.birthdate.range&&e.birthdate.range.result&&(!utils.areDatesEqual(d,e.birthdate.range.expected[0])||!utils.areDatesEqual(f,e.birthdate.range.expected[1]))&&(console.warn("Birthdate is not in the expected range"),a=false,i.birthdate={...i.birthdate,range:{expected:e.birthdate.range.expected,received:[d,f],message:"Birthdate is not in the expected range"}}),!e.birthdate.lte&&!e.birthdate.lt&&!e.birthdate.eq&&!e.birthdate.range&&!utils.areDatesEqual(f,ie)&&(console.warn("Maximum birthdate should be equal to default date value"),a=false,i.birthdate={...i.birthdate,disclose:{expected:`${ie.toISOString()}`,received:`${f.toISOString()}`,message:"Maximum birthdate should be equal to default date value"}}),!e.birthdate.gte&&!e.birthdate.gt&&!e.birthdate.eq&&!e.birthdate.range&&!utils.areDatesEqual(d,ie)&&(console.warn("Minimum birthdate should be equal to default date value"),a=false,i.birthdate={...i.birthdate,disclose:{expected:`${ie.toISOString()}`,received:`${d.toISOString()}`,message:"Minimum birthdate should be equal to default date value"}});}else console.warn("Birthdate is not set in the query result"),a=false,i.birthdate={...i.birthdate,disclose:{message:"Birthdate is not set in the query result"}};return e.birthdate?.gte&&(n.birthdate?.gte===void 0||!utils.areDatesEqual(e.birthdate.gte.expected,n.birthdate.gte))&&(console.warn("Birthdate gte does not match the original query"),a=false,i.birthdate={...i.birthdate,gte:{expected:n.birthdate?.gte,received:e.birthdate.gte.expected,message:"Birthdate gte does not match the original query"}}),e.birthdate?.gt&&(n.birthdate?.gt===void 0||!utils.areDatesEqual(e.birthdate.gt.expected,n.birthdate.gt))&&(console.warn("Birthdate gt does not match the original query"),a=false,i.birthdate={...i.birthdate,gt:{expected:n.birthdate?.gt,received:e.birthdate.gt.expected,message:"Birthdate gt does not match the original query"}}),e.birthdate?.lte&&(n.birthdate?.lte===void 0||!utils.areDatesEqual(e.birthdate.lte.expected,n.birthdate.lte))&&(console.warn("Birthdate lte does not match the original query"),a=false,i.birthdate={...i.birthdate,lte:{expected:n.birthdate?.lte,received:e.birthdate.lte.expected,message:"Birthdate lte does not match the original query"}}),e.birthdate?.lt&&(n.birthdate?.lt===void 0||!utils.areDatesEqual(e.birthdate.lt.expected,n.birthdate.lt))&&(console.warn("Birthdate lt does not match the original query"),a=false,i.birthdate={...i.birthdate,lt:{expected:n.birthdate?.lt,received:e.birthdate.lt.expected,message:"Birthdate lt does not match the original query"}}),e.birthdate?.range&&(n.birthdate?.range===void 0||!utils.areDatesEqual(e.birthdate.range.expected[0],n.birthdate.range[0])||!utils.areDatesEqual(e.birthdate.range.expected[1],n.birthdate.range[1]))&&(console.warn("Birthdate range does not match the original query"),a=false,i.birthdate={...i.birthdate,range:{expected:n.birthdate?.range,received:e.birthdate.range.expected,message:"Birthdate range does not match the original query"}}),{isCorrect:a,queryResultErrors:i}}static checkExpiryDatePublicInputs(t,n,e){let i={},a=true,o=new Date;new Date(o.getFullYear(),o.getMonth(),o.getDate(),0,0,0);let d=utils.getMinDateFromCommittedInputs(t.committedInputs?.compare_expiry??t.committedInputs?.compare_expiry_evm),f=utils.getMaxDateFromCommittedInputs(t.committedInputs?.compare_expiry??t.committedInputs?.compare_expiry_evm);return e.expiry_date?(e.expiry_date.gte&&e.expiry_date.gte.result&&!utils.areDatesEqual(d,e.expiry_date.gte.expected)&&(console.warn("Expiry date is not greater than or equal to the expected expiry date"),a=false,i.expiry_date={...i.expiry_date,gte:{expected:e.expiry_date.gte.expected,received:d,message:"Expiry date is not greater than or equal to the expected expiry date"}}),e.expiry_date.lte&&e.expiry_date.lte.result&&!utils.areDatesEqual(f,e.expiry_date.lte.expected)&&(console.warn("Expiry date is not less than the expected expiry date"),a=false,i.expiry_date={...i.expiry_date,lte:{expected:e.expiry_date.lte.expected,received:f,message:"Expiry date is not less than the expected expiry date"}}),e.expiry_date.range&&e.expiry_date.range.result&&(!utils.areDatesEqual(d,e.expiry_date.range.expected[0])||!utils.areDatesEqual(f,e.expiry_date.range.expected[1]))&&(console.warn("Expiry date is not in the expected range"),a=false,i.expiry_date={...i.expiry_date,range:{expected:e.expiry_date.range.expected,received:[d,f],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&&!utils.areDatesEqual(f,ie)&&(console.warn("Maximum expiry date should be equal to default date value"),a=false,i.expiry_date={...i.expiry_date,disclose:{expected:`${ie.toISOString()}`,received:`${f.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&&!utils.areDatesEqual(d,ie)&&(console.warn("Minimum expiry date should be equal to default date value"),a=false,i.expiry_date={...i.expiry_date,disclose:{expected:`${ie.toISOString()}`,received:`${d.toISOString()}`,message:"Minimum expiry date should be equal to default date value"}})):(console.warn("Expiry date is not set in the query result"),a=false,i.expiry_date={...i.expiry_date,disclose:{message:"Expiry date is not set in the query result"}}),e.expiry_date?.gte&&(n.expiry_date?.gte===void 0||!utils.areDatesEqual(e.expiry_date.gte.expected,n.expiry_date.gte))&&(console.warn("Expiry date gte does not match the original query"),a=false,i.expiry_date={...i.expiry_date,gte:{expected:n.expiry_date?.gte,received:e.expiry_date.gte.expected,message:"Expiry date gte does not match the original query"}}),e.expiry_date?.gt&&(n.expiry_date?.gt===void 0||!utils.areDatesEqual(e.expiry_date.gt.expected,n.expiry_date.gt))&&(console.warn("Expiry date gt does not match the original query"),a=false,i.expiry_date={...i.expiry_date,gt:{expected:n.expiry_date?.gt,received:e.expiry_date.gt.expected,message:"Expiry date gt does not match the original query"}}),e.expiry_date?.lte&&(n.expiry_date?.lte===void 0||!utils.areDatesEqual(e.expiry_date.lte.expected,n.expiry_date.lte))&&(console.warn("Expiry date lte does not match the original query"),a=false,i.expiry_date={...i.expiry_date,lte:{expected:n.expiry_date?.lte,received:e.expiry_date.lte.expected,message:"Expiry date lte does not match the original query"}}),e.expiry_date?.lt&&(n.expiry_date?.lt===void 0||!utils.areDatesEqual(e.expiry_date.lt.expected,n.expiry_date.lt))&&(console.warn("Expiry date lt does not match the original query"),a=false,i.expiry_date={...i.expiry_date,lt:{expected:n.expiry_date?.lt,received:e.expiry_date.lt.expected,message:"Expiry date lt does not match the original query"}}),e.expiry_date?.range&&(n.expiry_date?.range===void 0||!utils.areDatesEqual(e.expiry_date.range.expected[0],n.expiry_date.range[0])||!utils.areDatesEqual(e.expiry_date.range.expected[1],n.expiry_date.range[1]))&&(console.warn("Expiry date range does not match the original query"),a=false,i.expiry_date={...i.expiry_date,range:{expected:n.expiry_date?.range,received:e.expiry_date.range.expected,message:"Expiry date range does not match the original query"}}),{isCorrect:a,queryResultErrors:i}}static checkNationalityExclusionPublicInputs(t,n,e){let i={},a=true;n.nationality&&n.nationality.out&&n.nationality.out.result?n.nationality.out.expected?.every(o=>e.includes(o))||(console.warn("Nationality exclusion list does not match the one from the query results"),a=false,i.nationality={...i.nationality,out:{expected:n.nationality.out.expected,received:e,message:"Nationality exclusion list does not match the one from the query results"}}):(!n.nationality||!n.nationality.out)&&(console.warn("Nationality exclusion is not set in the query result"),a=false,i.nationality={...i.nationality,out:{message:"Nationality exclusion is not set in the query result"}});for(let o=1;o<e.length;o++)e[o]<e[o-1]&&(console.warn("The nationality exclusion list has not been sorted, and thus the proof cannot be trusted"),a=false,i.nationality={...i.nationality,out:{message:"The nationality exclusion list has not been sorted, and thus the proof cannot be trusted"}});return n.nationality?.out&&(t.nationality?.out===void 0||n.nationality.out.expected?.length!==t.nationality.out.length||!n.nationality.out.expected?.every(o=>t.nationality.out.includes(o)))&&(console.warn("Nationality exclusion list does not match the original query"),a=false,i.nationality={...i.nationality,out:{expected:t.nationality?.out,received:n.nationality.out.expected,message:"Nationality exclusion list does not match the original query"}}),{isCorrect:a,queryResultErrors:i}}static checkIssuingCountryExclusionPublicInputs(t,n,e){let i={},a=true;n.issuing_country&&n.issuing_country.out&&n.issuing_country.out.result?n.issuing_country.out.expected?.every(o=>e.includes(o))||(console.warn("Issuing country exclusion list does not match the one from the query results"),a=false,i.issuing_country={...i.issuing_country,out:{expected:n.issuing_country.out.expected,received:e,message:"Issuing country exclusion list does not match the one from the query results"}}):(!n.issuing_country||!n.issuing_country.out)&&(console.warn("Issuing country exclusion is not set in the query result"),a=false,i.issuing_country={...i.issuing_country,out:{message:"Issuing country exclusion is not set in the query result"}});for(let o=1;o<e.length;o++)e[o]<e[o-1]&&(console.warn("The issuing country exclusion list has not been sorted, and thus the proof cannot be trusted"),a=false,i.issuing_country={...i.issuing_country,out:{message:"The issuing country exclusion list has not been sorted, and thus the proof cannot be trusted"}});return n.issuing_country?.out&&(t.issuing_country?.out===void 0||n.issuing_country.out.expected?.length!==t.issuing_country.out.length||!n.issuing_country.out.expected?.every(o=>t.issuing_country.out.includes(o)))&&(console.warn("Issuing country exclusion list does not match the original query"),a=false,i.issuing_country={...i.issuing_country,out:{expected:t.issuing_country?.out,received:n.issuing_country.out.expected,message:"Issuing country exclusion list does not match the original query"}}),{isCorrect:a,queryResultErrors:i}}static checkNationalityInclusionPublicInputs(t,n,e){let i={},a=true;return n.nationality&&n.nationality.in&&n.nationality.in.result?n.nationality.in.expected?.every(o=>e.includes(o))||(console.warn("Nationality inclusion list does not match the one from the query results"),a=false,i.nationality={...i.nationality,in:{expected:n.nationality.in.expected,received:e,message:"Nationality inclusion list does not match the one from the query results"}}):(!n.nationality||!n.nationality.in)&&(console.warn("Nationality inclusion is not set in the query result"),a=false,i.nationality={...i.nationality,in:{message:"Nationality inclusion is not set in the query result"}}),n.nationality?.in&&(t.nationality?.in===void 0||n.nationality.in.expected?.length!==t.nationality.in.length||!n.nationality.in.expected?.every(o=>t.nationality.in.includes(o)))&&(console.warn("Nationality inclusion list does not match the original query"),a=false,i.nationality={...i.nationality,in:{expected:t.nationality?.in,received:n.nationality.in.expected,message:"Nationality inclusion list does not match the original query"}}),{isCorrect:a,queryResultErrors:i}}static checkIssuingCountryInclusionPublicInputs(t,n,e){let i={},a=true;return n.issuing_country&&n.issuing_country.in&&n.issuing_country.in.result?n.issuing_country.in.expected?.every(o=>e.includes(o))||(console.warn("Issuing country inclusion list does not match the one from the query results"),a=false,i.issuing_country={...i.issuing_country,in:{expected:n.issuing_country.in.expected,received:e,message:"Issuing country inclusion list does not match the one from the query results"}}):(!n.issuing_country||!n.issuing_country.in)&&(console.warn("Issuing country inclusion is not set in the query result"),a=false,i.issuing_country={...i.issuing_country,in:{message:"Issuing country inclusion is not set in the query result"}}),n.issuing_country?.in&&(t.issuing_country?.in===void 0||n.issuing_country.in.expected?.length!==t.issuing_country.in.length||!n.issuing_country.in.expected?.every(o=>t.issuing_country.in.includes(o)))&&(console.warn("Issuing country inclusion list does not match the original query"),a=false,i.issuing_country={...i.issuing_country,in:{expected:t.issuing_country?.in,received:n.issuing_country.in.expected,message:"Issuing country inclusion list does not match the original query"}}),{isCorrect:a,queryResultErrors:i}}static checkScopeFromDisclosureProof(t,n,e,i,a){if(t==="*")return {isCorrect:true,queryResultErrors:e};let o=true;if(utils.getServiceScopeHash(t)!==utils.getServiceScopeFromDisclosureProof(n)&&(console.warn("The proof comes from a different domain than the one expected"),o=false,e[i]||(e[i]={}),e[i].scope={expected:`Scope: ${utils.getServiceScopeHash(t).toString()}`,received:`Scope: ${utils.getServiceScopeFromDisclosureProof(n).toString()}`,message:"The proof comes from a different domain than the one expected"}),utils.getScopeHash(a)!==utils.getServiceSubScopeFromDisclosureProof(n)){let m=a?"The proof uses a different scope than the one expected":"The proof uses a scope but none was passed to verify()";console.warn(m),o=false,e[i]||(e[i]={}),e[i].scope={expected:`Scope: ${utils.getScopeHash(a).toString()}`,received:`Scope: ${utils.getServiceSubScopeFromDisclosureProof(n).toString()}`,message:m};}return {isCorrect:o,queryResultErrors:e}}static async checkRegistryRoot(t,n,e,i,a,o){let m;try{m=await t(o??registry.createRegistryClient(utils.getChainFromQuery(e,!!n)));}catch(d){console.warn(d),m=false;}if(!m){console.warn(a.message);let{section:d,field:f,...l}=a;i[d]={...i[d],[f]:l};}return {isCorrect:m,queryResultErrors:i}}static async checkCertificateRegistryRoot(t,n,e,i,a,o={},m){return this.checkRegistryRoot(d=>d.isCertificateRootValid(t,a),i,o,n,{section:e?"outer":"sig_check_dsc",field:"certificate",expected:"A valid root from ZKPassport Registry",received:`Got invalid certificate registry root: ${t}`,message:"The ID was signed by an unrecognized root certificate"},m)}static async checkCircuitRegistryRoot(t,n,e,i,a={},o){return this.checkRegistryRoot(m=>m.isCircuitRootValid(t,i),e,a,n,{section:"outer",field:"circuit",expected:"A valid circuit from ZKPassport Registry",received:`Got invalid circuit registry root: ${t}`,message:"The proof uses an unrecognized circuit"},o)}static async checkSanctionsRegistryRoot(t,n,e,i,a={},o){return this.checkRegistryRoot(m=>m.isSanctionsRootValid(t,i),e,a,n,{section:"sanctions",field:"eq",expected:"A valid root from ZKPassport Registry",received:`Got invalid sanctions registry root: ${t}`,message:"Invalid sanctions registry root"},o)}static async checkAttestationRevocationRoot(t,n,e,i,a,o={},m){let d=BigInt(t)===BigInt(utils.EMPTY_ATTESTATION_REVOCATION_ROOT);return this.checkRegistryRoot(async f=>d?BigInt(await f.getLatestAttestationRevocationRoot())===0n:f.isAttestationRevocationRootValid(t,a),i,o,n,{section:e,field:"revocation",expected:"A valid root from ZKPassport Registry",received:`Got invalid attestation revocation root: ${t}`,message:"The device attestation was checked against an unrecognized revocation list"},m)}static checkBindPublicInputs(t,n,e){let i={},a=true;if(n.bind){let o=[];n.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"),a=false,o.push(`user_address: expected ${n.bind.user_address}, received ${e.user_address}`)),n.bind.chain!==e.chain&&(console.warn("Bound chain id does not match the one from the query results"),a=false,o.push(`chain: expected ${n.bind.chain}, received ${e.chain}`)),n.bind.custom_data?.trim().toLowerCase()!==e.custom_data?.trim().toLowerCase()&&(console.warn("Bound custom data does not match the one from the query results"),a=false,o.push(`custom_data: expected ${n.bind.custom_data}, received ${e.custom_data}`)),o.length>0&&(i.bind={...i.bind,eq:{expected:`${n.bind.user_address}, ${n.bind.chain}, ${n.bind.custom_data}`,received:`${e.user_address}, ${e.chain}, ${e.custom_data}`,message:`Bound data does not match: ${o.join("; ")}`}});}return (t.bind===void 0||e.user_address?.toLowerCase().replace("0x","")!==t.bind.user_address?.toLowerCase().replace("0x","")||e.chain!==t.bind.chain||e.custom_data?.trim().toLowerCase()!==t.bind.custom_data?.trim().toLowerCase())&&(console.warn("Bound data does not match the original query"),a=false,i.bind={...i.bind,eq:{expected:`${t.bind?.user_address}, ${t.bind?.chain}, ${t.bind?.custom_data}`,received:`${e.user_address}, ${e.chain}, ${e.custom_data}`,message:"Bound data does not match the original query"}}),{isCorrect:a,queryResultErrors:i}}static async checkSanctionsExclusionPublicInputs(t,n,e,i,a,o){let m={},d=true;e.isStrict!==(t.sanctions?.strict??false)&&(console.warn("Sanctions strict mode does not match the original query"),d=false,m.sanctions={...m.sanctions,eq:{expected:`strict: ${t.sanctions?.strict??false}`,received:`strict: ${e.isStrict}`,message:"Sanctions strict mode does not match the original query"}});let{isCorrect:f}=await this.checkSanctionsRegistryRoot(e.rootHash,m,i,a,t,o);return d=d&&f,n.sanctions&&n.sanctions.passed&&n.sanctions.isStrict!==e.isStrict&&(console.warn("Invalid sanctions strict mode"),d=false,m.sanctions={...m.sanctions,eq:{expected:n.sanctions.isStrict.toString(),received:e.isStrict.toString(),message:"Invalid sanctions strict mode"}}),n.sanctions&&(t.sanctions===void 0||n.sanctions.isStrict!==(t.sanctions.strict??false))&&(console.warn("Sanctions config does not match the original query"),d=false,m.sanctions={...m.sanctions,eq:{expected:`strict: ${t.sanctions?.strict??false}`,received:`strict: ${n.sanctions.isStrict}`,message:"Sanctions config does not match the original query"}}),{isCorrect:d,queryResultErrors:m}}static async checkFacematchPublicInputs(t,n,e,i,a,o){let m=true,d={};e.rootKeyLeaf!==pe&&e.rootKeyLeaf!==Ce&&e.rootKeyLeaf!==xe&&(console.warn("Invalid facematch root key hash"),m=false,d.facematch={...d.facematch,eq:{expected:`${pe} (iOS) or ${Ce} (Android) or ${xe} (Android)`,received:e.rootKeyLeaf,message:"Invalid facematch root key hash"}});let f="production";e.environment!==f&&(console.warn("Invalid facematch environment, it should be production"),m=false,d.facematch={...d.facematch,eq:{expected:f,received:e.environment,message:"Invalid facematch environment, it should be production"}}),e.appIdHash!==ge&&e.appIdHash!==$e&&e.appIdHash!==ve&&(console.warn("Invalid facematch app id hash, the attestation should be coming from the ZKPassport app"),m=false,d.facematch={...d.facematch,eq:{expected:`${ge} (iOS) or ${$e} (iOS App Clip) or ${ve} (Android)`,received:e.appIdHash,message:"Invalid facematch app id hash, the attestation should be coming from the ZKPassport app"}});let l=t.facematch?.mode;(n.facematch&&e.mode!==n.facematch.mode||l!==void 0&&e.mode!==l)&&(console.warn("Invalid facematch mode"),m=false,d.facematch={...d.facematch,eq:{expected:t.facematch?.mode,received:e.mode,message:"Invalid facematch mode"}});let c=e.revocationRoot??"0x0";if(e.rootKeyLeaf===pe)BigInt(c)!==0n&&(console.warn("An iOS face match has no revocation root"),m=false,d.facematch={...d.facematch,revocation:{expected:"0",received:c,message:"An iOS face match has no revocation root"}});else {let{isCorrect:x}=await this.checkAttestationRevocationRoot(c,d,"facematch",i,a,t,o);m=m&&x;}return {isCorrect:m,queryResultErrors:d}}static async checkCurrentDate(t,n,e,i){let a=new Date,o=new Date(a.getFullYear(),a.getMonth(),a.getDate(),0,0,0,0),m=utils.getCurrentDateFromDisclosureProof(n),d=o.getTime()-m.getTime(),f=e?e*1e3:H*1e3,l=true;return d>=f&&(console.warn("The date used to check the validity of the ID falls out of the validity period"),l=false,i[t]||(i[t]={}),i[t].date={expected:`Difference: ${e} seconds`,received:`Difference: ${Math.round(d/1e3)} seconds`,message:"The date used to check the validity of the ID falls out of the validity period"}),m.getTime()-o.getTime()>Be&&(console.warn("The date used to check the validity of the ID is in the future"),l=false,i[t]||(i[t]={}),i[t].date={expected:`Difference: ${e} seconds`,received:`Difference: ${Math.round(d/1e3)} seconds`,message:"The date used to check the validity of the ID is in the future"}),{isCorrect:l,queryResultErrors:i}}static checkQueryCompleteness(t,n){let e=true,i={},a=(...h)=>h.some(g=>n.has(g)),o=(h,g)=>{e=false,i[h]={...i[h],commitment:{expected:"A proof covering the requested condition",received:"No matching proof was provided",message:g}};},m=a("disclose_bytes","disclose_bytes_evm"),d=h=>!!h&&(h.gte!==void 0||h.gt!==void 0||h.lte!==void 0||h.lt!==void 0||h.range!==void 0),f=h=>!!h&&(h.eq!==void 0||h.disclose===true),l=t.age;(d(l)||l?.eq!==void 0)&&!a("compare_age","compare_age_evm")&&o("age","The proof does not verify the requested age condition"),d(t.birthdate)&&!a("compare_birthdate","compare_birthdate_evm")&&o("birthdate","The proof does not verify the requested birthdate condition"),f(t.birthdate)&&!m&&o("birthdate","The proof does not disclose the requested birthdate"),d(t.expiry_date)&&!a("compare_expiry","compare_expiry_evm")&&o("expiry_date","The proof does not verify the requested expiry date condition"),f(t.expiry_date)&&!m&&o("expiry_date","The proof does not disclose the requested expiry date");let c=t.nationality;c?.in!==void 0&&!a("inclusion_check_nationality","inclusion_check_nationality_evm")&&o("nationality","The proof does not verify the requested nationality inclusion"),c?.out!==void 0&&!a("exclusion_check_nationality","exclusion_check_nationality_evm")&&o("nationality","The proof does not verify the requested nationality exclusion"),f(c)&&!m&&o("nationality","The proof does not disclose the requested nationality");let x=t.issuing_country;x?.in!==void 0&&!a("inclusion_check_issuing_country","inclusion_check_issuing_country_evm")&&o("issuing_country","The proof does not verify the requested issuing country inclusion"),x?.out!==void 0&&!a("exclusion_check_issuing_country","exclusion_check_issuing_country_evm")&&o("issuing_country","The proof does not verify the requested issuing country exclusion"),f(x)&&!m&&o("issuing_country","The proof does not disclose the requested issuing country");let r=["firstname","lastname","fullname","document_number","document_type","gender"];for(let h of r)f(t[h])&&!m&&o(h,`The proof does not disclose the requested ${h}`);return t.bind&&!a("bind","bind_evm")&&o("bind","The proof does not verify the requested bound data"),t.sanctions&&!a("exclusion_check_sanctions","exclusion_check_sanctions_evm")&&o("sanctions","The proof does not verify the requested sanctions exclusion"),t.facematch&&!a("facematch","facematch_evm")&&o("facematch","The proof does not verify the requested FaceMatch"),e||console.warn("The proof does not verify all the requested conditions and information"),{isCorrect:e,queryResultErrors:i}}static async checkPublicInputs(t,n,e,i,a,o,m,d,f,l=utils.DEFAULT_ALLOWED_VERIFICATION_METHODS){let c,x,r=true,h,g,w,S=new Date,D=new Date(S.getFullYear(),S.getMonth(),S.getDate(),0,0,0,0),s={};if(n.length>1&&n.some(b=>b.name?.startsWith("outer")))return console.warn("An outer proof must be the only proof provided"),s.outer={commitment:{expected:"Number of proofs: 1",received:`Number of proofs: ${n.length}`,message:"An outer proof must be the only proof provided"}},{isCorrect:false,uniqueIdentifier:void 0,uniqueIdentifierType:void 0,queryResultErrors:s};let N=["attested_id",utils.AADHAAR_CIRCUIT_NAME,"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"],j=n.sort((b,u)=>{let y=C=>{let T=C.name||"";return N.findIndex(E=>T.startsWith(E))};return y(b)-y(u)}),Y=N.slice(5),I,L=j.find(b=>Y.some(u=>b.name?.startsWith(u))),ee=L?utils.getCurrentDateFromDisclosureProof(utils.getProofData(L.proof,utils.getNumberOfPublicInputs(L.name,L.version))):void 0,Z=ee?Math.floor(ee.getTime()/1e3):void 0;for(let b of j){let u=utils.getProofData(b.proof,utils.getNumberOfPublicInputs(b.name,b.version));if(b.name?.startsWith("outer")){let y=b.name?.startsWith("outer_evm"),C=utils.getCurrentDateFromOuterProof(u),T=Math.floor(C.getTime()/1e3),E=utils.getCertificateRegistryRootFromOuterProof(u),{isCorrect:A,queryResultErrors:R}=await this.checkCertificateRegistryRoot(E.toString(16),s,true,d,T,e,f);r=r&&A,s={...s,...R};let V=utils.getCircuitRegistryRootFromOuterProof(u),{isCorrect:$,queryResultErrors:M}=await this.checkCircuitRegistryRoot(V.toString(16),s,d,T,e,f);r=r&&$,s={...s,...M};let ue=D.getTime()-C.getTime(),It=a?a*1e3:H*1e3;ue>=It&&(console.warn("The date used to check the validity of the ID is older than the validity period"),r=false,s.outer={...s.outer,date:{expected:`Difference: ${a} seconds`,received:`Difference: ${Math.round(ue/1e3)} seconds`,message:"The date used to check the validity of the ID is older than the validity period"}}),C.getTime()-D.getTime()>Be&&(console.warn("The date used to check the validity of the ID is in the future"),r=false,s.outer={...s.outer,date:{expected:`Difference: ${a} seconds`,received:`Difference: ${Math.round(ue/1e3)} seconds`,message:"The date used to check the validity of the ID is in the future"}});let q=utils.getParamCommitmentsFromOuterProof(u,b.version),He=b.name.includes("_attested_"),Le=b.name.includes("_aadhaar_");I=He||Le||utils.hasVerificationMethod(b.version)?utils.getVerificationMethodFromOuterProof(u):utils.VerificationMethod.ICAO_CHIP,Le&&I!==utils.VerificationMethod.UIDAI_AADHAAR&&(console.warn("An Aadhaar outer proof states another verification method"),r=false,s.outer={...s.outer,certificate:{expected:`Verification method ${utils.VerificationMethod.UIDAI_AADHAAR}`,received:`Verification method ${I}`,message:"An Aadhaar outer proof states another verification method"}}),He&&utils.getTierForVerificationMethod(I)!==utils.VerificationTier.DEVICE_ATTESTED&&(console.warn("A Tier 2 outer proof states a scheme of another tier"),r=false,s.outer={...s.outer,certificate:{expected:"A device-attested verification method",received:`Verification method ${I}`,message:"A Tier 2 outer proof states a scheme of another tier"}});let _=b.committedInputs,Ue=Object.keys(_||{});if(Ue.length!==q.length&&(console.warn("The proof does not verify all the requested conditions and information"),r=false,s.outer={...s.outer,commitment:{expected:`Number of parameter commitments: ${q.length}`,received:`Number of disclosure proofs provided: ${Ue.length}`,message:"The proof does not verify all the requested conditions and information"}}),utils.getTierForVerificationMethod(I)===utils.VerificationTier.DEVICE_ATTESTED){let{isCorrect:v,queryResultErrors:k}=await this.checkOuterDeviceAttestation(I,_,q[0],y);r=r&&v,s={...s,...k};}if(utils.getServiceScopeHash(t)!==utils.getScopeFromOuterProof(u)&&(console.warn("The proof comes from a different domain than the one expected"),r=false,s.outer={...s.outer,scope:{expected:`Scope: ${utils.getServiceScopeHash(t).toString()}`,received:`Scope: ${utils.getScopeFromOuterProof(u).toString()}`,message:"The proof comes from a different domain than the one expected"}}),utils.getScopeHash(o)!==utils.getSubscopeFromOuterProof(u)){let v=o?"The proof uses a different scope than the one expected":"The proof uses a scope but none was passed to verify()";console.warn(v),r=false,s.outer={...s.outer,scope:{expected:`Scope: ${utils.getScopeHash(o).toString()}`,received:`Scope: ${utils.getSubscopeFromOuterProof(u).toString()}`,message:v}};}if(_?.compare_age||_?.compare_age_evm){let v=_?.compare_age??_?.compare_age_evm,k=y?await utils.getAgeEVMParameterCommitment(v.minAge,v.maxAge):await utils.getAgeParameterCommitment(v.minAge,v.maxAge);q.includes(k)||(console.warn("This proof does not verify the age"),r=false,s.age={...s.age,commitment:{expected:`Age parameter commitment: ${k.toString()}`,received:`Parameter commitments included: ${q.join(", ")}`,message:"This proof does not verify the age"}});let{isCorrect:O,queryResultErrors:B}=this.checkAgePublicInputs(b,e,i);r=r&&O,s={...s,...B};}if(_?.compare_birthdate||_?.compare_birthdate_evm){let v=_?.compare_birthdate??_?.compare_birthdate_evm,k=y?await utils.getDateEVMParameterCommitment(utils.ProofType.BIRTHDATE,v.minDateTimestamp,v.maxDateTimestamp,0):await utils.getDateParameterCommitment(utils.ProofType.BIRTHDATE,v.minDateTimestamp,v.maxDateTimestamp,0);q.includes(k)||(console.warn("This proof does not verify the birthdate"),r=false,s.birthdate={...s.birthdate,commitment:{expected:`Birthdate parameter commitment: ${k.toString()}`,received:`Parameter commitments included: ${q.join(", ")}`,message:"This proof does not verify the birthdate"}});let{isCorrect:O,queryResultErrors:B}=this.checkBirthdatePublicInputs(b,e,i);r=r&&O,s={...s,...B};}if(_?.compare_expiry||_?.compare_expiry_evm){let v=_?.compare_expiry??_?.compare_expiry_evm,k=y?await utils.getDateEVMParameterCommitment(utils.ProofType.EXPIRY_DATE,v.minDateTimestamp,v.maxDateTimestamp):await utils.getDateParameterCommitment(utils.ProofType.EXPIRY_DATE,v.minDateTimestamp,v.maxDateTimestamp);q.includes(k)||(console.warn("This proof does not verify the expiry date"),r=false,s.expiry_date={...s.expiry_date,commitment:{expected:`Expiry date parameter commitment: ${k.toString()}`,received:`Parameter commitments included: ${q.join(", ")}`,message:"This proof does not verify the expiry date"}});let{isCorrect:O,queryResultErrors:B}=this.checkExpiryDatePublicInputs(b,e,i);r=r&&O,s={...s,...B};}if(_?.disclose_bytes||_?.disclose_bytes_evm){let v=_?.disclose_bytes??_?.disclose_bytes_evm,k=y?await utils.getDiscloseEVMParameterCommitment(v.discloseMask,v.disclosedBytes):await utils.getDiscloseParameterCommitment(v.discloseMask,v.disclosedBytes);q.includes(k)||(console.warn("This proof does not verify any of the data disclosed"),r=false,s.disclose={...s.disclose,commitment:{expected:`Disclosure parameter commitment: ${k.toString()}`,received:`Parameter commitments included: ${q.join(", ")}`,message:"This proof does not verify any of the data disclosed"}});let{isCorrect:O,queryResultErrors:B}=this.checkDiscloseBytesPublicInputs(b,e,i);r=r&&O,s={...s,...B};}if(_?.inclusion_check_nationality||_?.inclusion_check_nationality_evm){let v=_?.inclusion_check_nationality??_?.inclusion_check_nationality_evm,k=y?await utils.getCountryEVMParameterCommitment(utils.ProofType.NATIONALITY_INCLUSION,v.countries):await utils.getCountryParameterCommitment(utils.ProofType.NATIONALITY_INCLUSION,v.countries);q.includes(k)||(console.warn("This proof does not verify the inclusion of the nationality"),r=false,s.nationality={...s.nationality,commitment:{expected:`Nationality parameter commitment: ${k.toString()}`,received:`Parameter commitments included: ${q.join(", ")}`,message:"This proof does not verify the inclusion of the nationality"}});let O=v.countries,{isCorrect:B,queryResultErrors:ce}=this.checkNationalityInclusionPublicInputs(e,i,O);r=r&&B,s={...s,...ce};}if(_?.inclusion_check_issuing_country||_?.inclusion_check_issuing_country_evm){let v=_?.inclusion_check_issuing_country??_?.inclusion_check_issuing_country_evm,k=y?await utils.getCountryEVMParameterCommitment(utils.ProofType.ISSUING_COUNTRY_INCLUSION,v.countries):await utils.getCountryParameterCommitment(utils.ProofType.ISSUING_COUNTRY_INCLUSION,v.countries);q.includes(k)||(console.warn("This proof does not verify the inclusion of the issuing country"),r=false,s.issuing_country={...s.issuing_country,commitment:{expected:`Issuing country parameter commitment: ${k.toString()}`,received:`Parameter commitments included: ${q.join(", ")}`,message:"This proof does not verify the inclusion of the issuing country"}});let O=v.countries,{isCorrect:B,queryResultErrors:ce}=this.checkIssuingCountryInclusionPublicInputs(e,i,O);r=r&&B,s={...s,...ce};}if(_?.exclusion_check_nationality||_?.exclusion_check_nationality_evm){let v=_?.exclusion_check_nationality??_?.exclusion_check_nationality_evm,k=y?await utils.getCountryEVMParameterCommitment(utils.ProofType.NATIONALITY_EXCLUSION,v.countries):await utils.getCountryParameterCommitment(utils.ProofType.NATIONALITY_EXCLUSION,v.countries);q.includes(k)||(console.warn("This proof does not verify the exclusion of the nationality"),r=false,s.nationality={...s.nationality,commitment:{expected:`Nationality parameter commitment: ${k.toString()}`,received:`Parameter commitments included: ${q.join(", ")}`,message:"This proof does not verify the exclusion of the nationality"}});let O=v.countries,{isCorrect:B,queryResultErrors:ce}=this.checkNationalityExclusionPublicInputs(e,i,O);r=r&&B,s={...s,...ce};}if(_?.exclusion_check_issuing_country||_?.exclusion_check_issuing_country_evm){let v=_?.exclusion_check_issuing_country??_?.exclusion_check_issuing_country_evm,k=y?await utils.getCountryEVMParameterCommitment(utils.ProofType.ISSUING_COUNTRY_EXCLUSION,v.countries):await utils.getCountryParameterCommitment(utils.ProofType.ISSUING_COUNTRY_EXCLUSION,v.countries);q.includes(k)||(console.warn("This proof does not verify the exclusion of the issuing country"),r=false,s.issuing_country={...s.issuing_country,commitment:{expected:`Issuing country parameter commitment: ${k.toString()}`,received:`Parameter commitments included: ${q.join(", ")}`,message:"This proof does not verify the exclusion of the issuing country"}});let O=v.countries,{isCorrect:B,queryResultErrors:ce}=this.checkIssuingCountryExclusionPublicInputs(e,i,O);r=r&&B,s={...s,...ce};}if(_?.bind||_?.bind_evm){let v=_?.bind??_?.bind_evm,k=y?await utils.getBindEVMParameterCommitment(utils.formatBoundData(v.data)):await utils.getBindParameterCommitment(utils.formatBoundData(v.data));q.includes(k)||(console.warn("This proof does not verify the bound data"),r=false,s.bind={...s.bind,commitment:{expected:`Bind parameter commitment: ${k.toString()}`,received:`Parameter commitments included: ${q.join(", ")}`,message:"This proof does not verify the bound data"}});let{isCorrect:O,queryResultErrors:B}=this.checkBindPublicInputs(e,i,v.data);r=r&&O,s={...s,...B};}if(_?.exclusion_check_sanctions||_?.exclusion_check_sanctions_evm){let v=_?.exclusion_check_sanctions??_?.exclusion_check_sanctions_evm,k=y?await utils.getSanctionsEvmParameterCommitment(v.rootHash,v.isStrict):await utils.getSanctionsParameterCommitment(v.rootHash,v.isStrict);q.includes(k)||(console.warn("This proof does not verify the exclusion from the sanction lists"),r=false,s.sanctions={...s.sanctions,commitment:{expected:`Sanctions parameter commitment: ${k.toString()}`,received:`Parameter commitments included: ${q.join(", ")}`,message:"This proof does not verify the exclusion from the sanction lists"}});let{isCorrect:O,queryResultErrors:B}=await this.checkSanctionsExclusionPublicInputs(e,i,v,d,T,f);r=r&&O,s={...s,...B};}if(_?.facematch||_?.facematch_evm){let v=_?.facematch??_?.facematch_evm,k=y?await utils.getFacematchEvmParameterCommitment(BigInt(v.rootKeyLeaf),v.environment==="development"?0n:1n,BigInt(v.appIdHash),v.mode==="regular"?1n:2n,void 0,BigInt(v.revocationRoot??0)):await utils.getFacematchParameterCommitment(BigInt(v.rootKeyLeaf),v.environment==="development"?0n:1n,BigInt(v.appIdHash),v.mode==="regular"?1n:2n,void 0,BigInt(v.revocationRoot??0));q.includes(k)||(console.warn("This proof does not verify FaceMatch"),r=false,s.facematch={...s.facematch,commitment:{expected:`Facematch parameter commitment: ${k.toString()}`,received:`Parameter commitments included: ${q.join(", ")}`,message:"This proof does not verify FaceMatch"}});let{isCorrect:O,queryResultErrors:B}=await this.checkFacematchPublicInputs(e,i,v,d,Z,f);r=r&&O,s={...s,...B};}h=utils.getNullifierFromOuterProof(u,b.version).toString(10),g=utils.getNullifierTypeFromOuterProof(u,b.version),w=utils.getOprfPkHashFromOuterProof(u,b.version);}else if(b.name?.startsWith("attested_id")){x=utils.getCommitmentOutFromAttestedIdProof(u),I=utils.getVerificationMethodFromAttestedIdProof(u);let y=utils.isAndroidAttestedIdCircuit(b.name)?"attested_id_android":"attested_id_ios",C=b.committedInputs?.[y],T=utils.getCurrentDateFromAttestedIdProof(u),{isCorrect:E,queryResultErrors:A}=this.checkAttestedIdDate(T);if(r=r&&E,s={...s,...A},!C)console.warn("The attested ID proof carries no committed attestation parameters"),r=false,s.attested_id={...s.attested_id,commitment:{expected:`Committed inputs for ${y}`,received:"none",message:"The attested ID proof carries no committed attestation parameters"}};else {let R=await utils.getAttestedIdParameterCommitment(BigInt(C.rootKeyLeaf),C.environment==="development"?0n:1n,BigInt(C.appIdHash),C.mode==="regular"?1n:2n,BigInt(C.integrityPubkeyHash),BigInt(C.revocationRoot??0)),V=utils.getParameterCommitmentFromAttestedIdProof(u);V!==R&&(console.warn("The attested ID proof does not match its committed parameters"),r=false,s.attested_id={...s.attested_id,commitment:{expected:`Parameter commitment: ${R.toString()}`,received:`Parameter commitment: ${V.toString()}`,message:"The attested ID proof does not match its committed parameters"}});let{isCorrect:$,queryResultErrors:M}=this.checkAttestedIdParameters(C,y==="attested_id_android");if(r=r&&$,s={...s,...M},y==="attested_id_android"){let{isCorrect:ue}=await this.checkAttestationRevocationRoot(C.revocationRoot??"0x0",s,"attested_id",d,T?Math.floor(T.getTime()/1e3):Z,e,f);r=r&&ue;}}}else if(b.name===utils.AADHAAR_CIRCUIT_NAME){x=utils.getCommitmentOutFromAadhaarProof(u),I=utils.getVerificationMethodFromAttestedIdProof(u);let{isCorrect:y,queryResultErrors:C}=await this.checkCertificateRegistryRoot(utils.getCertificateRegistryRootFromAadhaarProof(u).toString(16),s,false,d,Z,e,f);r=r&&y,s={...s,...C};}else if(b.name?.startsWith("sig_check_dsc")){x=utils.getCommitmentFromDSCProof(u);let y=utils.getMerkleRootFromDSCProof(u),{isCorrect:C,queryResultErrors:T}=await this.checkCertificateRegistryRoot(y.toString(16),s,false,d,Z,e,f);r=r&&C,s={...s,...T};}else if(b.name?.startsWith("sig_check_id_data"))c=utils.getCommitmentInFromIDDataProof(u),c!==x&&(console.warn("Failed to check the link between the certificate signature and ID signature"),r=false,s.sig_check_id_data={...s.sig_check_id_data,commitment:{expected:`Commitment: ${x?.toString()||"undefined"}`,received:`Commitment: ${c?.toString()||"undefined"}`,message:"Failed to check the link between the certificate signature and ID signature"}}),x=utils.getCommitmentOutFromIDDataProof(u);else if(b.name?.startsWith("data_check_integrity"))c=utils.getCommitmentInFromIntegrityProof(u),c!==x&&(console.warn("Failed to check the link between the ID signature and the data signed"),r=false,s.data_check_integrity={...s.data_check_integrity,commitment:{expected:`Commitment: ${x?.toString()||"undefined"}`,received:`Commitment: ${c?.toString()||"undefined"}`,message:"Failed to check the link between the ID signature and the data signed"}}),x=utils.getCommitmentOutFromIntegrityProof(u),I=utils.getVerificationMethodFromIntegrityProof(u)??utils.VerificationMethod.ICAO_CHIP;else if(b.name==="disclose_bytes"){c=utils.getCommitmentInFromDisclosureProof(u),c!==x&&(console.warn("Failed to check the link between the validity of the ID and the data to disclose"),r=false,s.disclose={...s.disclose,commitment:{expected:`Commitment: ${x?.toString()||"undefined"}`,received:`Commitment: ${c?.toString()||"undefined"}`,message:"Failed to check the link between the validity of the ID and the data to disclose"}});let y=utils.getParameterCommitmentFromDisclosureProof(u),C=await utils.getDiscloseParameterCommitment((b.committedInputs?.disclose_bytes).discloseMask,(b.committedInputs?.disclose_bytes).disclosedBytes);y!==C&&(console.warn("The disclosed data does not match the data committed by the proof"),r=false,s.disclose={...s.disclose,commitment:{expected:`Commitment: ${C}`,received:`Commitment: ${y}`,message:"The disclosed data does not match the data committed by the proof"}});let{isCorrect:T,queryResultErrors:E}=this.checkScopeFromDisclosureProof(t,u,s,"disclose",o);r=r&&T,s={...s,...E};let{isCorrect:A,queryResultErrors:R}=this.checkDiscloseBytesPublicInputs(b,e,i);r=r&&A&&T,s={...s,...R,...E};let{isCorrect:V,queryResultErrors:$}=await this.checkCurrentDate("disclose",u,a??H,s);r=r&&V,s={...s,...$},h=utils.getNullifierFromDisclosureProof(u).toString(10),g=utils.getNullifierTypeFromDisclosureProof(u);}else if(b.name==="compare_age"){c=utils.getCommitmentInFromDisclosureProof(u),c!==x&&(console.warn("Failed to check the link between the validity of the ID and the age derived from it"),r=false,s.age={...s.age,commitment:{expected:`Commitment: ${x}`,received:`Commitment: ${c}`,message:"Failed to check the link between the validity of the ID and the age derived from it"}});let y=utils.getParameterCommitmentFromDisclosureProof(u),C=b.committedInputs?.compare_age,T=await utils.getAgeParameterCommitment(C.minAge,C.maxAge);y!==T&&(console.warn("The conditions for the age check do not match the conditions checked by the proof"),r=false,s.age={...s.age,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${y}`,message:"The conditions for the age check do not match the conditions checked by the proof"}});let{isCorrect:E,queryResultErrors:A}=this.checkScopeFromDisclosureProof(t,u,s,"age",o),{isCorrect:R,queryResultErrors:V}=this.checkAgePublicInputs(b,e,i);r=r&&R&&E,s={...s,...V,...A};let{isCorrect:$,queryResultErrors:M}=await this.checkCurrentDate("age",u,a??H,s);r=r&&$,s={...s,...M},h=utils.getNullifierFromDisclosureProof(u).toString(10),g=utils.getNullifierTypeFromDisclosureProof(u);}else if(b.name==="compare_birthdate"){c=utils.getCommitmentInFromDisclosureProof(u),c!==x&&(console.warn("Failed to check the link between the validity of the ID and the birthdate derived from it"),r=false,s.birthdate={...s.birthdate,commitment:{expected:`Commitment: ${x}`,received:`Commitment: ${c}`,message:"Failed to check the link between the validity of the ID and the birthdate derived from it"}});let y=utils.getParameterCommitmentFromDisclosureProof(u),C=b.committedInputs?.compare_birthdate,T=await utils.getDateParameterCommitment(utils.ProofType.BIRTHDATE,C.minDateTimestamp,C.maxDateTimestamp,0);y!==T&&(console.warn("The conditions for the birthdate check do not match the conditions checked by the proof"),r=false,s.birthdate={...s.birthdate,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${y}`,message:"The conditions for the birthdate check do not match the conditions checked by the proof"}});let{isCorrect:E,queryResultErrors:A}=this.checkScopeFromDisclosureProof(t,u,s,"birthdate",o),{isCorrect:R,queryResultErrors:V}=this.checkBirthdatePublicInputs(b,e,i);r=r&&R&&E,s={...s,...V,...A};let{isCorrect:$,queryResultErrors:M}=await this.checkCurrentDate("birthdate",u,a??H,s);r=r&&$,s={...s,...M},h=utils.getNullifierFromDisclosureProof(u).toString(10),g=utils.getNullifierTypeFromDisclosureProof(u);}else if(b.name==="compare_expiry"){c=utils.getCommitmentInFromDisclosureProof(u),c!==x&&(console.warn("Failed to check the link between the validity of the ID and its expiry date"),r=false,s.expiry_date={...s.expiry_date,commitment:{expected:`Commitment: ${x}`,received:`Commitment: ${c}`,message:"Failed to check the link between the validity of the ID and its expiry date"}});let y=utils.getParameterCommitmentFromDisclosureProof(u),C=b.committedInputs?.compare_expiry,T=await utils.getDateParameterCommitment(utils.ProofType.EXPIRY_DATE,C.minDateTimestamp,C.maxDateTimestamp);y!==T&&(console.warn("The conditions for the expiry date check do not match the conditions checked by the proof"),r=false,s.expiry_date={...s.expiry_date,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${y}`,message:"The conditions for the expiry date check do not match the conditions checked by the proof"}});let{isCorrect:E,queryResultErrors:A}=this.checkScopeFromDisclosureProof(t,u,s,"expiry_date",o),{isCorrect:R,queryResultErrors:V}=this.checkExpiryDatePublicInputs(b,e,i);r=r&&R&&E,s={...s,...V,...A};let{isCorrect:$,queryResultErrors:M}=await this.checkCurrentDate("expiry_date",u,a??H,s);r=r&&$,s={...s,...M},h=utils.getNullifierFromDisclosureProof(u).toString(10),g=utils.getNullifierTypeFromDisclosureProof(u);}else if(b.name==="exclusion_check_nationality"){c=utils.getCommitmentInFromDisclosureProof(u),c!==x&&(console.warn("Failed to check the link between the validity of the ID and the nationality exclusion check"),r=false,s.nationality={...s.nationality,commitment:{expected:`Commitment: ${x}`,received:`Commitment: ${c}`,message:"Failed to check the link between the validity of the ID and the nationality exclusion check"}});let y=(b.committedInputs?.exclusion_check_nationality).countries,C=utils.getParameterCommitmentFromDisclosureProof(u),T=await utils.getCountryParameterCommitment(utils.ProofType.NATIONALITY_EXCLUSION,y,true);C!==T&&(console.warn("The committed country list for the exclusion check does not match the one from the proof"),r=false,s.nationality={...s.nationality,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${C}`,message:"The committed country list for the exclusion check does not match the one from the proof"}});let{isCorrect:E,queryResultErrors:A}=this.checkScopeFromDisclosureProof(t,u,s,"nationality",o),{isCorrect:R,queryResultErrors:V}=this.checkNationalityExclusionPublicInputs(e,i,y);r=r&&R&&E,s={...s,...V,...A};let{isCorrect:$,queryResultErrors:M}=await this.checkCurrentDate("nationality",u,a??H,s);r=r&&$,s={...s,...M},h=utils.getNullifierFromDisclosureProof(u).toString(10),g=utils.getNullifierTypeFromDisclosureProof(u);}else if(b.name==="exclusion_check_issuing_country"){c=utils.getCommitmentInFromDisclosureProof(u),c!==x&&(console.warn("Failed to check the link between the validity of the ID and the issuing country exclusion check"),r=false,s.issuing_country={...s.issuing_country,commitment:{expected:`Commitment: ${x}`,received:`Commitment: ${c}`,message:"Failed to check the link between the validity of the ID and the issuing country exclusion check"}});let y=(b.committedInputs?.exclusion_check_issuing_country).countries,C=utils.getParameterCommitmentFromDisclosureProof(u),T=await utils.getCountryParameterCommitment(utils.ProofType.ISSUING_COUNTRY_EXCLUSION,y,true);C!==T&&(console.warn("The committed country list for the issuing country exclusion check does not match the one from the proof"),r=false,s.issuing_country={...s.issuing_country,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${C}`,message:"The committed country list for the issuing country exclusion check does not match the one from the proof"}});let{isCorrect:E,queryResultErrors:A}=this.checkScopeFromDisclosureProof(t,u,s,"issuing_country",o),{isCorrect:R,queryResultErrors:V}=this.checkIssuingCountryExclusionPublicInputs(e,i,y);r=r&&R&&E,s={...s,...V,...A};let{isCorrect:$,queryResultErrors:M}=await this.checkCurrentDate("issuing_country",u,a??H,s);r=r&&$,s={...s,...M},h=utils.getNullifierFromDisclosureProof(u).toString(10),g=utils.getNullifierTypeFromDisclosureProof(u);}else if(b.name==="inclusion_check_nationality"){c=utils.getCommitmentInFromDisclosureProof(u),c!==x&&(console.warn("Failed to check the link between the validity of the ID and the nationality inclusion check"),r=false,s.nationality={...s.nationality,commitment:{expected:`Commitment: ${x}`,received:`Commitment: ${c}`,message:"Failed to check the link between the validity of the ID and the nationality inclusion check"}});let y=(b.committedInputs?.inclusion_check_nationality).countries,C=utils.getParameterCommitmentFromDisclosureProof(u),T=await utils.getCountryParameterCommitment(utils.ProofType.NATIONALITY_INCLUSION,y,false);C!==T&&(console.warn("The committed country list for the nationality inclusion check does not match the one from the proof"),r=false,s.nationality={...s.nationality,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${C}`,message:"The committed country list for the nationality inclusion check does not match the one from the proof"}});let{isCorrect:E,queryResultErrors:A}=this.checkScopeFromDisclosureProof(t,u,s,"nationality",o),{isCorrect:R,queryResultErrors:V}=this.checkNationalityInclusionPublicInputs(e,i,y);r=r&&R&&E,s={...s,...V,...A};let{isCorrect:$,queryResultErrors:M}=await this.checkCurrentDate("nationality",u,a??H,s);r=r&&$,s={...s,...M},h=utils.getNullifierFromDisclosureProof(u).toString(10),g=utils.getNullifierTypeFromDisclosureProof(u);}else if(b.name==="inclusion_check_issuing_country"){c=utils.getCommitmentInFromDisclosureProof(u),c!==x&&(console.warn("Failed to check the link between the validity of the ID and the issuing country inclusion check"),r=false,s.issuing_country={...s.issuing_country,commitment:{expected:`Commitment: ${x}`,received:`Commitment: ${c}`,message:"Failed to check the link between the validity of the ID and the issuing country inclusion check"}});let y=(b.committedInputs?.inclusion_check_issuing_country).countries,C=utils.getParameterCommitmentFromDisclosureProof(u),T=await utils.getCountryParameterCommitment(utils.ProofType.ISSUING_COUNTRY_INCLUSION,y,false);C!==T&&(console.warn("The committed country list for the issuing country inclusion check does not match the one from the proof"),r=false,s.issuing_country={...s.issuing_country,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${C}`,message:"The committed country list for the issuing country inclusion check does not match the one from the proof"}});let{isCorrect:E,queryResultErrors:A}=this.checkScopeFromDisclosureProof(t,u,s,"issuing_country",o),{isCorrect:R,queryResultErrors:V}=this.checkIssuingCountryInclusionPublicInputs(e,i,y);r=r&&R&&E,s={...s,...V,...A};let{isCorrect:$,queryResultErrors:M}=await this.checkCurrentDate("issuing_country",u,a??H,s);r=r&&$,s={...s,...M},h=utils.getNullifierFromDisclosureProof(u).toString(10),g=utils.getNullifierTypeFromDisclosureProof(u);}else if(b.name==="bind"){c=utils.getCommitmentInFromDisclosureProof(u),c!==x&&(console.warn("Failed to check the link between the validity of the ID and the bound data"),r=false,s.bind={...s.bind,commitment:{expected:`Commitment: ${x}`,received:`Commitment: ${c}`,message:"Failed to check the link between the validity of the ID and the bound data"}});let y=b.committedInputs?.bind,C=utils.getParameterCommitmentFromDisclosureProof(u),T=await utils.getBindParameterCommitment(utils.formatBoundData(y.data));C!==T&&(console.warn("The bound data does not match the one from the proof"),r=false,s.bind={...s.bind,commitment:{expected:`Commitment: ${T}`,received:`Commitment: ${C}`,message:"The bound data does not match the one from the proof"}});let{isCorrect:E,queryResultErrors:A}=this.checkScopeFromDisclosureProof(t,u,s,"bind",o),{isCorrect:R,queryResultErrors:V}=this.checkBindPublicInputs(e,i,y.data);r=r&&R&&E,s={...s,...V,...A};let{isCorrect:$,queryResultErrors:M}=await this.checkCurrentDate("bind",u,a??H,s);r=r&&$,s={...s,...M},h=utils.getNullifierFromDisclosureProof(u).toString(10),g=utils.getNullifierTypeFromDisclosureProof(u);}else if(b.name==="exclusion_check_sanctions"){c=utils.getCommitmentInFromDisclosureProof(u),c!==x&&(console.warn("Failed to check the link between the validity of the ID and the sanctions exclusion check"),r=false,s.sanctions={...s.sanctions,commitment:{expected:`Commitment: ${x}`,received:`Commitment: ${c}`,message:"Failed to check the link between the validity of the ID and the sanctions exclusion check"}});let y=b.committedInputs?.exclusion_check_sanctions,C=await utils.getSanctionsParameterCommitment(y.rootHash,y.isStrict),T=utils.getParameterCommitmentFromDisclosureProof(u);T!==C&&(console.warn("The sanction lists check against do not match the sanction lists from the proof"),r=false,s.sanctions={...s.sanctions,commitment:{expected:`Commitment: ${C.toString()}`,received:`Commitment: ${T.toString()}`,message:"The sanction lists check against do not match the sanction lists from the proof"}});let{isCorrect:E,queryResultErrors:A}=this.checkScopeFromDisclosureProof(t,u,s,"sanctions",o),{isCorrect:R,queryResultErrors:V}=await this.checkSanctionsExclusionPublicInputs(e,i,y,d,Z,f);r=r&&R&&E,s={...s,...V,...A};let{isCorrect:$,queryResultErrors:M}=await this.checkCurrentDate("sanctions",u,a??H,s);r=r&&$,s={...s,...M},h=utils.getNullifierFromDisclosureProof(u).toString(10),g=utils.getNullifierTypeFromDisclosureProof(u);}else if(b.name?.startsWith("facematch")&&!b.name?.endsWith("_evm")){c=utils.getCommitmentInFromDisclosureProof(u),c!==x&&(console.warn("Failed to check the link between the validity of the ID and the facematch check"),r=false,s.facematch={...s.facematch,commitment:{expected:`Commitment: ${x}`,received:`Commitment: ${c}`,message:"Failed to check the link between the validity of the ID and the facematch check"}});let y=b.committedInputs?.facematch,C=utils.getParameterCommitmentFromDisclosureProof(u),T=await utils.getFacematchParameterCommitment(BigInt(y.rootKeyLeaf),y.environment==="development"?0n:1n,BigInt(y.appIdHash),y.mode==="regular"?1n:2n,void 0,BigInt(y.revocationRoot??0));C!==T&&(console.warn("The FaceMatch verification does not match the ones from the proof"),r=false,s.facematch={...s.facematch,commitment:{expected:`Commitment: ${T.toString()}`,received:`Commitment: ${C.toString()}`,message:"The FaceMatch verification does not match the ones from the proof"}});let{isCorrect:E,queryResultErrors:A}=this.checkScopeFromDisclosureProof(t,u,s,"facematch",o),{isCorrect:R,queryResultErrors:V}=await this.checkFacematchPublicInputs(e,i,y,d,Z,f);r=r&&R&&E,s={...s,...V,...A};let{isCorrect:$,queryResultErrors:M}=await this.checkCurrentDate("facematch",u,a??H,s);r=r&&$,s={...s,...M};}else console.warn(`Unexpected proof: ${b.name}`),r=false;}let de=j.filter(b=>b.name!=="facematch"&&Y.includes(b.name)).map(b=>utils.getProofData(b.proof,utils.getNumberOfPublicInputs(b.name,b.version)));if(de.length>0){let b=(T,E)=>[...new Set(T.filter(A=>A!==E))],u=b(de.map(utils.getNullifierFromDisclosureProof),0n),y=b(de.map(utils.getNullifierTypeFromDisclosureProof),utils.NullifierType.NONE),C=b(de.map(utils.getOprfPkHashFromDisclosureProof),0n);(u.length>1||y.length>1||C.length>1)&&(console.warn("The disclosure proofs do not share the same nullifier"),r=false),h=u[0]?.toString(10),g=y[0]??utils.NullifierType.NONE,w=C[0];}let ye=new Set;for(let b of j)for(let u of Object.keys(b.committedInputs??{}))ye.add(u);let{isCorrect:Ae,queryResultErrors:wt}=this.checkQueryCompleteness(e,ye);if(r=r&&Ae,s={...s,...wt},r&&g&&(g===utils.NullifierType.SALTED||g===utils.NullifierType.SALTED_MOCK))try{let b=await utils.getOprfPublicKey(m??utils.OPRF_DEFAULT_KEY_ID),u=await utils.hashOprfPublicKey(b),y=w;(y===void 0||y!==u)&&(console.warn("OPRF public key hash mismatch: proof uses an unknown OPRF key"),r=!1);}catch(b){console.warn("Failed to verify OPRF public key:",b),r=false;}g===utils.NullifierType.NONE?(h!==void 0&&BigInt(h)!==0n&&(console.warn("Proofs with the NONE nullifier type cannot carry a unique identifier"),r=false),h=void 0):h!==void 0&&BigInt(h)===0n&&(h=void 0),I===utils.VerificationMethod.UIDAI_AADHAAR&&!j.some(b=>b.name?.startsWith("facematch")||b.name?.startsWith("outer")&&(!!b.committedInputs?.facematch||!!b.committedInputs?.facematch_evm))&&(console.warn("An Aadhaar proof must come with a face match against its photo"),r=false,s.facematch={...s.facematch,eq:{expected:"A FaceMatch proof",received:"none",message:"An Aadhaar proof must come with a face match against its photo"}}),I===utils.VerificationMethod.UIDAI_AADHAAR&&!utils.isAadhaarNationalityConditionAllowed(e.nationality)&&(console.warn("An Aadhaar does not prove a nationality, so it can only pass an exclusion check"),r=false,s.nationality={...s.nationality,eq:{expected:"An ID that proves a nationality",received:"Aadhaar",message:"An Aadhaar does not prove a nationality, so it can only pass an exclusion check"}});let Re=I??utils.VerificationMethod.ICAO_CHIP;return utils.isVerificationMethodAllowed(Re,l)||(console.warn("The service does not accept the verification method the ID was verified with"),r=false,s.verification_method={...s.verification_method,eq:{expected:`Allowed credentials: ${l.join(", ")}`,received:`Verification method: ${Re}`,message:"The service does not accept the verification method the ID was verified with"}}),{isCorrect:r,uniqueIdentifier:h,uniqueIdentifierType:g,queryResultErrors:s,verificationMethod:Re}}static checkAttestedIdDate(t){let n=true,e={},i=t?Date.now()-t.getTime():1/0;if(i>ft||-i>Be){let a="The attested ID proof's date is not recent";console.warn(a),n=false,e.attested_id={...e.attested_id,date:{expected:`Within ${ft/1e3} seconds of now`,received:t?.toISOString()??"no date",message:a}};}return {isCorrect:n,queryResultErrors:e}}static async checkOuterDeviceAttestation(t,n,e,i){let a=true,o={},m=(h,g,w)=>{console.warn(w),a=false,o.attested_id={...o.attested_id,commitment:{expected:h,received:g,message:w}};},d=t===utils.VerificationMethod.ATTESTED_CAPTURE_ANDROID;if(!d&&t!==utils.VerificationMethod.ATTESTED_CAPTURE_IOS)return m("A camera read scheme",String(t),"No circuit proves this verification method"),{isCorrect:a,queryResultErrors:o};let f=d?"attested_id_android":"attested_id_ios",l=n?.[f];if(!l)return m(`Committed inputs for ${f}`,"none","The proof carries no device attestation"),{isCorrect:a,queryResultErrors:o};let x=await(i?utils.getAttestedIdEvmParameterCommitment:utils.getAttestedIdParameterCommitment)(BigInt(l.rootKeyLeaf),l.environment==="development"?0n:1n,BigInt(l.appIdHash),l.mode==="regular"?1n:2n);e!==x&&m(`First parameter commitment: ${x.toString()}`,`First parameter commitment: ${e?.toString()}`,"The proof's device attestation does not match its committed parameters");let r=this.checkAttestedIdParameters(l,d);return {isCorrect:a&&r.isCorrect,queryResultErrors:{...o,...r.queryResultErrors}}}static checkAttestedIdParameters(t,n=false){let e=true,i={},a=(f,l,c)=>{console.warn(c),e=false,i.attested_id={...i.attested_id,eq:{expected:f,received:l,message:c}};},o=n?[Ce,xe]:[pe];o.includes(t.rootKeyLeaf)||a(o.join(" or "),t.rootKeyLeaf,"Invalid attested ID root key hash");let m=n?ve:ge;t.appIdHash!==m&&a(m,t.appIdHash,"Invalid attested ID app id hash");let d=n?[utils.GOOGLE_PLAY_INTEGRITY_PUBKEY_HASH]:[0n];return d.includes(BigInt(t.integrityPubkeyHash))||a(d.join(" or "),t.integrityPubkeyHash,"Invalid attested ID integrity key"),!n&&BigInt(t.revocationRoot??0)!==0n&&a("0",t.revocationRoot,"An iOS attested ID has no revocation root"),t.environment!=="production"&&a("production",t.environment,"Invalid attested ID environment"),t.mode!=="strict"&&a("strict",t.mode,"A Tier 2 ID requires a strict face match"),{isCorrect:e,queryResultErrors:i}}};var lt={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 le=class p{static getDetails(){return {...{functionName:"verify",abi:lt.abi},address:"0x1D000001000EFD9a6371f4d90bB8920D5431c0D8"}}static getParameters({proof:t,validityPeriodInSeconds:n=H,domain:e,scope:i,devMode:a=false}){if(!t.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 o=utils.getProofData(t.proof,utils.getNumberOfPublicInputs(t.name,t.version)),m=[],d=[];for(let r in t.committedInputs){if(r==="attested_id_ios"||r==="attested_id_android"){let S=mt(utils.ProofType.ATTESTED_ID,t.committedInputs[r]);m.push({circuitName:r,count:S.length/2}),d.push({circuitName:r,inputs:S});continue}let h=utils.getCommittedInputCount(r),g=r;m.push({circuitName:g,count:h});let w="";if(g==="inclusion_check_issuing_country_evm"||g==="inclusion_check_nationality_evm"||g==="exclusion_check_issuing_country_evm"||g==="exclusion_check_nationality_evm"){let D=t.committedInputs[g].countries;(g==="exclusion_check_issuing_country_evm"||g==="exclusion_check_nationality_evm")&&D.sort((N,j)=>N.localeCompare(j));let s=(()=>{switch(g){case "exclusion_check_issuing_country_evm":return utils.ProofType.ISSUING_COUNTRY_EXCLUSION;case "exclusion_check_nationality_evm":return utils.ProofType.NATIONALITY_EXCLUSION;case "inclusion_check_issuing_country_evm":return utils.ProofType.ISSUING_COUNTRY_INCLUSION;case "inclusion_check_nationality_evm":return utils.ProofType.NATIONALITY_INCLUSION}})();w=s.toString(16).padStart(2,"0")+utils.ProofTypeLength[s].evm.toString(16).padStart(4,"0")+utils.rightPadArrayWithZeros(D.map(N=>Array.from(new TextEncoder().encode(N))).flat(),600).map(N=>N.toString(16).padStart(2,"0")).join("");}else if(g==="compare_age_evm"){let S=t.committedInputs[g];w=utils.ProofType.AGE.toString(16).padStart(2,"0")+utils.ProofTypeLength[utils.ProofType.AGE].evm.toString(16).padStart(4,"0")+S.minAge.toString(16).padStart(2,"0")+S.maxAge.toString(16).padStart(2,"0");}else if(g==="compare_birthdate_evm"){let S=t.committedInputs[g],D=Array.from(utils.numberToBytesBE(S.minDateTimestamp,8)),s=Array.from(utils.numberToBytesBE(S.maxDateTimestamp,8));w=utils.ProofType.BIRTHDATE.toString(16).padStart(2,"0")+utils.ProofTypeLength[utils.ProofType.BIRTHDATE].evm.toString(16).padStart(4,"0")+D.map(N=>N.toString(16).padStart(2,"0")).join("")+s.map(N=>N.toString(16).padStart(2,"0")).join("");}else if(g==="compare_expiry_evm"){let S=t.committedInputs[g],D=Array.from(utils.numberToBytesBE(S.minDateTimestamp,8)),s=Array.from(utils.numberToBytesBE(S.maxDateTimestamp,8));w=utils.ProofType.EXPIRY_DATE.toString(16).padStart(2,"0")+utils.ProofTypeLength[utils.ProofType.EXPIRY_DATE].evm.toString(16).padStart(4,"0")+D.map(N=>N.toString(16).padStart(2,"0")).join("")+s.map(N=>N.toString(16).padStart(2,"0")).join("");}else if(g==="disclose_bytes_evm"){let S=t.committedInputs[g];w=utils.ProofType.DISCLOSE.toString(16).padStart(2,"0")+utils.ProofTypeLength[utils.ProofType.DISCLOSE].evm.toString(16).padStart(4,"0")+S.discloseMask.map(D=>D.toString(16).padStart(2,"0")).join("")+S.disclosedBytes.map(D=>D.toString(16).padStart(2,"0")).join("");}else if(g==="bind_evm"){let S=t.committedInputs[g];w=utils.ProofType.BIND.toString(16).padStart(2,"0")+utils.ProofTypeLength[utils.ProofType.BIND].evm.toString(16).padStart(4,"0")+utils.rightPadArrayWithZeros(utils.formatBoundData(S.data),509).map(D=>D.toString(16).padStart(2,"0")).join("");}else if(g==="exclusion_check_sanctions_evm"){let S=t.committedInputs[g];w+=utils.ProofType.SANCTIONS_EXCLUSION.toString(16).padStart(2,"0"),w+=utils.ProofTypeLength[utils.ProofType.SANCTIONS_EXCLUSION].evm.toString(16).padStart(4,"0"),w+=Array.from(utils.numberToBytesBE(BigInt(S.rootHash),32)).map(D=>D.toString(16).padStart(2,"0")).join(""),w+=S.isStrict?"01":"00";}else if(g.startsWith("facematch")&&g.endsWith("_evm"))w+=mt(utils.ProofType.FACEMATCH,t.committedInputs[g]);else throw new Error(`Unsupported circuit for EVM verification: ${g}`);d.push({circuitName:g,inputs:w});}let f=utils.getParamCommitmentsFromOuterProof(o,t.version).map(r=>r.toString(16).padStart(64,"0")),l="";for(let r of f){let h=d.find(g=>{let w=sha2_js.sha256(utils_js.hexToBytes(g.inputs)),S=new Uint8Array(w.length);for(let D=0;D<w.length-1;D++)S[D+1]=w[D];return S[0]=0,utils_js.bytesToHex(S)===r.replace("0x","")});if(h){let g=m.find(w=>w.circuitName===h.circuitName)?.count;if(g)l+=h.inputs;else throw new Error(`Unknown circuit name: ${h.circuitName}`)}else throw new Error(`Invalid commitment: ${r}`)}return {version:utils.circuitVersionToBytes32(t.version),proofVerificationData:{vkeyHash:`0x${t.vkeyHash.replace("0x","").padStart(64,"0")}`,proof:`0x${o.proof.join("")}`,publicInputs:o.publicInputs},committedInputs:`0x${l}`,serviceConfig:{validityPeriodInSeconds:n,domain:e,scope:i??"",devMode:a}}}static async verify({proof:t,rpcUrl:n,validityPeriodInSeconds:e,domain:i,scope:a,devMode:o}){try{let{createPublicClient:m,http:d}=await import('viem'),{address:f,abi:l,functionName:c}=p.getDetails(),x=m({transport:d(n)}),r=p.getParameters({proof:t,validityPeriodInSeconds:e,domain:i,scope:a,devMode:o}),h=await x.readContract({address:f,abi:l,functionName:c,args:[r]});return Array.isArray(h)?!!h[0]:!1}catch(m){return console.warn("Error verifying proof",m),false}}},ke=p=>Array.from(p).map(t=>t.toString(16).padStart(2,"0")).join("");function mt(p,t){return p.toString(16).padStart(2,"0")+utils.ProofTypeLength[p].evm.toString(16).padStart(4,"0")+ke(utils.numberToBytesBE(BigInt(t.rootKeyLeaf),32))+(t.environment==="development"?"00":"01")+ke(utils.numberToBytesBE(BigInt(t.appIdHash),32))+ke(utils.numberToBytesBE(BigInt(t.integrityPubkeyHash),32))+(t.mode==="regular"?"01":"02")+ke(utils.numberToBytesBE(BigInt(t.revocationRoot??0),32))}async function pt({domain:p,proofs:t,query:n,queryResult:e,scope:i,policyId:a,requestId:o}){let m=t.map(d=>({proof:d.proof,vkeyHash:d.vkeyHash,version:d.version,name:d.name,index:d.index,total:d.total,committedInputs:d.committedInputs}));try{let d=await fetch(`${he}/public/proofs`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({domain:p,proofs:m,query:n,queryResult:e,scope:i,policyId:a,sdkVersion:me,requestId:o}),signal:AbortSignal.timeout(3e4)});d.ok?F.debug("API response status:",d.status):F.warn("API request failed with status:",d.status);}catch(d){}}var Vi=[0,22,0];function Ni(p){if(!p)return "v6";let t=p.split(".").map(n=>Number(n));return t.length!==3||t.some(n=>Number.isNaN(n))||Mi(t,Vi)?"v6":"v5"}async function $i(p,{writingDirectory:t}={}){await qi();let n=t?t+"/.bb-crs":void 0;if(p==="v5"){let{UltraHonkVerifierBackend:m,Barretenberg:d}=await import('@aztec/bb.js'),f=await d.new({crsPath:n});return {verifier:new m(f),destroy:()=>f.destroy()}}let{UltraHonkVerifierBackend:e,Barretenberg:i}=await import('@aztec-foundation/bb.js'),a=await i.new({crsPath:n});return {verifier:new e(a),destroy:()=>a.destroy()}}var De=class{constructor({writingDirectory:t}={}){this.writingDirectory=t;}async verify(t,n){let e=utils.getProofData(t.proof,utils.getNumberOfPublicInputs(t.name,t.version));this.loadedVerifier??(this.loadedVerifier=await $i(Ni(t.version),{writingDirectory:this.writingDirectory}));try{return await this.loadedVerifier.verifier.verifyProof({proof:_.Buffer.from(e.proof.join(""),"hex"),publicInputs:e.publicInputs,verificationKey:new Uint8Array(_.Buffer.from(n.vkey,"base64"))})}catch(i){return console.warn(`Error verifying proof ${t.name}`,i),false}}async destroy(){await this.loadedVerifier?.destroy();}},yt="__zkpassport_bb_version",ht="keyval-store",gt="v5";async function qi(){if(!(typeof indexedDB>"u"))try{let p=typeof localStorage<"u"?localStorage:void 0;if((p?.getItem(yt)??"v4")===gt)return;let t=!0;if(typeof indexedDB.databases=="function")try{t=(await indexedDB.databases()).some(n=>n.name===ht);}catch{t=!0;}t&&await new Promise(n=>{let e=indexedDB.deleteDatabase(ht);e.onsuccess=e.onerror=e.onblocked=()=>n();}),p?.setItem(yt,gt);}catch{}}function Mi(p,t){for(let[n,e]of t.entries())if(p[n]!==e)return p[n]>e;return true}async function Fe({proofs:p,originalQuery:t,queryResult:n,domain:e,validity:i,scope:a,devMode:o,oprfKeyId:m,allowedVerificationMethods:d}){try{let f=await fetch(`${ze}/verify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({proofs:p,originalQuery:t,queryResult:n,serviceConfig:{domain:e,scope:a,validityPeriodInSeconds:i,devMode:o},oprfKeyId:m,allowedVerificationMethods:d}),signal:AbortSignal.timeout(6e4)});if(f.status>=500)return console.warn(`Verifier API error (status ${f.status})`),null;let l=await f.json().catch(()=>null);return !l||typeof l.verified!="boolean"?(console.warn(`Unexpected verifier API response (status ${f.status})`),null):l.verified?{uniqueIdentifier:l.uniqueIdentifier,uniqueIdentifierType:l.uniqueIdentifierType,verified:!0,verificationMethod:l.verificationMethod}:(console.warn("Verifier API did not verify the proofs:",l.error),{uniqueIdentifier:void 0,uniqueIdentifierType:void 0,verified:!1,queryResultErrors:l.queryResultErrors})}catch(f){return console.warn("Verifier API call failed:",f),null}}typeof globalThis.Buffer>"u"&&(globalThis.Buffer=_.Buffer,typeof window<"u"&&(window.Buffer=_.Buffer));var xt="Verify identity privately";function Ki(p){if(!p)return {};let{circuitsUrl:t,...n}=p;if(!t)return n;let e=t.replace(/\/+$/,"");return {...n,circuitManifestUrlGenerator:(i,{root:a,version:o})=>a?`${e}/by-root/${a}/manifest.json`:`${e}/by-version/${o}/manifest.json`,packagedCircuitUrlGenerator:(i,a)=>`${e}/by-hash/${a}.json`}}function zi({uniqueIdentifier:p,uniqueIdentifierType:t}){return t===utils.NullifierType.SALTED_MOCK?utils.NullifierType.SALTED:t===utils.NullifierType.NON_SALTED_MOCK?p===void 0?utils.NullifierType.NONE:utils.NullifierType.NON_SALTED:t}function ji(p,t){if(!p.verified)return p;let n=p.verificationMethod??utils.VerificationMethod.ICAO_CHIP;return utils.isVerificationMethodAllowed(n,t)?p:(console.warn(`The verification method ${n} is not one the service accepts`),{...p,verified:false,uniqueIdentifier:void 0,uniqueIdentifierType:void 0})}function Gi(p,t){if(t==null||!p.verified||zi(p)===t)return p;let n=p.uniqueIdentifierType,e=n===void 0?"missing":utils.NullifierType[n];return console.warn(`Unique identifier type mismatch: requested ${utils.NullifierType[t]}, got ${e}`),{...p,uniqueIdentifier:void 0,uniqueIdentifierType:void 0,verified:false}}var Tt=false;function Yi(){Tt||(Tt=true,console.warn("[zkpassport] onResult is deprecated. Use onSuccess and verify the proofs on your backend with verify()."));}var _t=class{constructor(t){this.topicToConfig={};this.topicToLocalConfig={};this.topicToPublicKey={};this.topicToBridge={};this.topicToRequestReceived={};this.topicToService={};this.topicToCallerPurpose={};this.topicToProofs={};this.topicToFailedProofCount={};this.topicToResults={};this.topicToPolicy={};this.dashboardConfig=null;this.dashboardConfigPromise=null;this.dashboardConfigError=null;this.onRequestReceivedCallbacks={};this.onGeneratingProofCallbacks={};this.onBridgeConnectCallbacks={};this.onBridgeConnectionLostCallbacks={};this.onProofGeneratedCallbacks={};this.onSuccessCallbacks={};this.onResultCallbacks={};this.onRejectCallbacks={};this.onErrorCallbacks={};if(!t&&typeof window>"u")throw new Error("Domain argument is required in Node.js environment");this.domainProvided=!!t,this.domain=this.normalizeDomain(t||window.location.hostname);}normalizeDomain(t){return t.trim().replace(/^https?:\/\//,"").replace(/\/[^/]*$/,"").replace(/:[0-9]+/,"").replace(/\?.*$/,"").replace(/#.*$/,"").toLowerCase()}async handleResult(t){let n=this.topicToResults[t];delete this.topicToResults[t];let e=this.topicToProofs[t],i=this.topicToFailedProofCount[t]>0,a=!i&&e.length>0;if(a)try{await Promise.all(this.onSuccessCallbacks[t].map(d=>d({proofs:e,result:n})));}catch(d){}let o=this.topicToLocalConfig[t]?.devMode===true,m=this.topicToPolicy[t]?.proofStorageEnabled===true;a&&m&&this.domainProvided&&!o&&pt({domain:this.domain,proofs:e,query:this.topicToConfig[t],queryResult:n,scope:this.topicToService[t]?.scope,policyId:this.topicToPolicy[t]?.id,requestId:this.topicToPublicKey[t]}),this.onResultCallbacks[t].length>0&&await this.verifyAndReportResult(t,e,n,i),delete this.topicToProofs[t],delete this.topicToFailedProofCount[t];}async verifyAndReportResult(t,n,e,i){let a;try{a=await this.verify({proofs:n,originalQuery:this.topicToConfig[t],queryResult:e,validity:this.topicToLocalConfig[t]?.validity,scope:this.topicToService[t]?.scope,devMode:this.topicToLocalConfig[t]?.devMode,oprfKeyId:this.topicToLocalConfig[t]?.oprfKeyId??void 0,uniqueIdentifierType:this.topicToLocalConfig[t]?.uniqueIdentifierType,verifierMode:this.topicToLocalConfig[t]?.verifierMode,config:this.topicToLocalConfig[t]?.config,allowedVerificationMethods:this.topicToLocalConfig[t]?.allowedVerificationMethods});}catch(c){let x=c instanceof Error?c.message:String(c);await Promise.all(this.onErrorCallbacks[t].map(r=>r(x)));return}let{uniqueIdentifier:o,uniqueIdentifierType:m,verified:d,queryResultErrors:f,verificationMethod:l}=a;await Promise.all(this.onResultCallbacks[t].map(c=>c({uniqueIdentifier:i?void 0:o,uniqueIdentifierType:i?void 0:m,verified:i?false:d,verificationMethod:l,result:e,queryResultErrors:f,proofs:n,sdkInstance:this})));}async handleEncryptedMessage(t,n){if(n.method==="accept")await Promise.all(this.onGeneratingProofCallbacks[t].map(e=>e(t)));else if(n.method==="reject")await Promise.all(this.onRejectCallbacks[t].map(e=>e()));else if(n.method==="proof")this.topicToProofs[t].push(n.params),await Promise.all(this.onProofGeneratedCallbacks[t].map(e=>e(n.params))),this.topicToResults[t]&&n.params.total===this.topicToProofs[t].length+this.topicToFailedProofCount[t]&&await this.handleResult(t);else if(n.method==="done")this.topicToResults[t]=utils.formatQueryResultDates(n.params),this.topicToProofs[t].length>0&&this.topicToProofs[t].length+this.topicToFailedProofCount[t]===this.topicToProofs[t][0].total&&await this.handleResult(t);else if(n.method==="error"){let e=n.params.error;e&&e==="This ID is not supported yet"?this.topicToResults[t]&&await this.handleResult(t):e&&e.startsWith("Cannot generate proof")&&(this.topicToFailedProofCount[t]+=1,this.topicToResults[t]&&this.topicToProofs[t].length>0&&this.topicToProofs[t].length+this.topicToFailedProofCount[t]===this.topicToProofs[t][0].total&&await this.handleResult(t)),await Promise.all(this.onErrorCallbacks[t].map(i=>i(e)));}}assertNotPolicyLocked(t,n){if(this.topicToPolicy[t])throw new Error(`Cannot call .${n}() on a policy-driven request. The query for policy '${this.topicToPolicy[t].id}' is immutable.`)}getZkPassportRequest(t){return {eq:(n,e)=>(this.assertNotPolicyLocked(t,"eq"),(n==="issuing_country"||n==="nationality")&&(e=se(e)),fe("eq",n,e,t,this.topicToConfig),this.getZkPassportRequest(t)),gte:(n,e)=>{if(this.assertNotPolicyLocked(t,"gte"),te("gte",n,e,t,this.topicToConfig),n==="age"&&(e<1||e>=100))throw new Error("Age must be between 1 and 99 (inclusive)");return this.getZkPassportRequest(t)},gt:(n,e)=>(this.assertNotPolicyLocked(t,"gt"),te("gt",n,e,t,this.topicToConfig),this.getZkPassportRequest(t)),lte:(n,e)=>(this.assertNotPolicyLocked(t,"lte"),te("lte",n,e,t,this.topicToConfig),this.getZkPassportRequest(t)),lt:(n,e)=>(this.assertNotPolicyLocked(t,"lt"),te("lt",n,e,t,this.topicToConfig),this.getZkPassportRequest(t)),range:(n,e,i)=>(this.assertNotPolicyLocked(t,"range"),Ve(n,[e,i],t,this.topicToConfig),this.getZkPassportRequest(t)),in:(n,e)=>(this.assertNotPolicyLocked(t,"in"),e=e.map(i=>se(i)),fe("in",n,e,t,this.topicToConfig),this.getZkPassportRequest(t)),out:(n,e)=>(this.assertNotPolicyLocked(t,"out"),e=e.map(i=>se(i)),fe("out",n,e,t,this.topicToConfig),this.getZkPassportRequest(t)),disclose:n=>(this.assertNotPolicyLocked(t,"disclose"),this.topicToConfig[t][n]={...this.topicToConfig[t][n],disclose:true},this.getZkPassportRequest(t)),bind:(n,e)=>(this.topicToConfig[t].bind={...this.topicToConfig[t].bind,[n]:e},this.getZkPassportRequest(t)),sanctions:(n="all",e="all",i={strict:false})=>(this.assertNotPolicyLocked(t,"sanctions"),this.topicToConfig[t].sanctions={...this.topicToConfig[t].sanctions,countries:n,lists:e,strict:i.strict??false},this.getZkPassportRequest(t)),facematch:(n="strict")=>(this.assertNotPolicyLocked(t,"facematch"),this.topicToConfig[t].facematch={mode:n},this.getZkPassportRequest(t)),raw:n=>{this.assertNotPolicyLocked(t,"raw");let{policy:e,bind:i,...a}=n;if(e){if(Object.keys(a).length>0)throw new Error("A query with `policy` cannot also carry conditions (bind is allowed).");this.getZkPassportRequest(t).policy(e),i&&(this.topicToConfig[t].bind=i);}else this.topicToConfig[t]=n;return this.getZkPassportRequest(t)},policy:n=>{if(this.assertCanApplyPolicy(t,n),!this.dashboardConfig)throw this.dashboardConfigError?this.dashboardConfigError:new Error(`${this.domain} is not set up for ZKPassport verification. If this is your site, register the domain at https://dashboard.zkpassport.id.`);let e=this.findPolicy(this.dashboardConfig,n),{bind:i,...a}=e.query;this.topicToConfig[t]=a;let o=this.topicToService[t];return o&&(this.topicToCallerPurpose[t]||(o.purpose=e.purpose||xt),o.scope||(o.scope=e.id),o.policyId=e.id),this.topicToPolicy[t]={id:e.id,proofStorageEnabled:e.proofStorageEnabled===true},this.getZkPassportRequest(t)},done:(()=>{if(this.topicToFailedProofCount[t]=0,this.topicToConfig[t]=Se(this.topicToConfig[t]),t==="offline-query"){let o=this.topicToConfig[t];return delete this.topicToConfig[t],delete this.topicToPolicy[t],{query:o}}let n=this.topicToLocalConfig[t],e=this.topicToConfig[t],i=!!e.facematch,a=!!e.facematch&&e.facematch?.mode==="strict";if(n.uniqueIdentifierType===utils.NullifierType.SALTED&&(n.devMode===false&&!a||!i))throw new Error("Salted nullifier requires strict facematch. Add .facematch('strict') to your query or remove the salted nullifier option.");return {url:this._getUrl(t),query:this.topicToConfig[t],requestId:t,policy:this.topicToPolicy[t]?.id,onRequestReceived:o=>this.onRequestReceivedCallbacks[t].push(o),onGeneratingProof:o=>this.onGeneratingProofCallbacks[t].push(o),onBridgeConnect:o=>this.onBridgeConnectCallbacks[t].push(o),onBridgeConnectionLost:o=>this.onBridgeConnectionLostCallbacks[t].push(o),onProofGenerated:o=>this.onProofGeneratedCallbacks[t].push(o),onSuccess:o=>this.onSuccessCallbacks[t].push(o),onResult:o=>{Yi(),this.onResultCallbacks[t].push(o);},onReject:o=>this.onRejectCallbacks[t].push(o),onError:o=>this.onErrorCallbacks[t].push(o),isBridgeConnected:()=>this.topicToBridge[t].isBridgeConnected(),requestReceived:()=>this.topicToRequestReceived[t]===true}})}}async getDashboardConfig(){return this.dashboardConfig?this.dashboardConfig:(this.dashboardConfigPromise||(this.dashboardConfigPromise=this.fetchDashboardConfig().then(t=>(this.dashboardConfig=t,t)).catch(t=>{throw this.dashboardConfigPromise=null,t})),this.dashboardConfigPromise)}async fetchDashboardConfig(){let t=`${he}/public/project?domain=${encodeURIComponent(this.domain)}`,n;try{n=await fetch(t,{signal:AbortSignal.timeout(1e4)});}catch(i){throw new Error(`Failed to fetch dashboard config for domain '${this.domain}': ${i.message}`)}if(!n.ok)throw new Error(`Failed to fetch dashboard config for domain '${this.domain}': ${n.status} ${n.statusText}`);let e=await n.json();if(e&&e.project===null)return null;if(!e||!e.project||!Array.isArray(e.policies))throw new Error(`Invalid dashboard config response for domain '${this.domain}'`);return e}findPolicy(t,n){let e=t.policies.find(i=>i.id===n);if(!e)throw new Error(`Policy '${n}' not found for domain '${this.domain}'. The dashboard returned ${t.policies.length} policies for this domain.`);if(!e.query||typeof e.query!="object")throw new Error(`Invalid policy '${n}' for domain '${this.domain}': missing query object.`);return e}assertCanApplyPolicy(t,n){if(typeof n!="string"||n.length===0)throw new Error(".policy() requires a non-empty string id.");if(this.topicToPolicy[t])throw new Error(`Cannot call .policy() more than once on a request (already set to '${this.topicToPolicy[t].id}').`);if(Object.keys(this.topicToConfig[t]).length>0)throw new Error("Cannot combine .policy() with builder methods like .gte()/.disclose()/etc. Call .policy() first; only .bind() may follow it.")}async request({name:t,logo:n,purpose:e,scope:i,projectID:a,mode:o,validity:m,devMode:d,uniqueIdentifierType:f,oprfKeyId:l,topicOverride:c,keyPairOverride:x,replayMissedMessages:r,cloudProverUrl:h,bridgeUrl:g,returnDeepLink:w,verifierMode:S,config:D,overrides:s,allowedVerificationMethods:N}){if(c==="offline-query")throw new Error("You cannot override the topic with 'offline-query'");if(N&&utils.serializeAllowedVerificationMethods(N),l&&f===utils.NullifierType.NONE)throw new Error("An OPRF key cannot be used with the NONE unique identifier type. Remove the oprfKeyId option or use the SALTED type.");let j=null;try{j=await this.getDashboardConfig(),this.dashboardConfigError=null;}catch(L){this.dashboardConfigError=L;}let Y=await bridge.Bridge.create({keyPair:x,bridgeId:c,bridgeUrl:g,replayFrom:r?1:void 0}),I=Y.connection.getBridgeId();return this.topicToConfig[I]={},this.topicToCallerPurpose[I]=e,this.topicToService[I]={name:t||j?.project?.name||this.domain,logo:n||j?.project?.logoUrl||"",purpose:e||xt,scope:i,projectID:a,cloudProverUrl:h,bridgeUrl:g},this.topicToProofs[I]=[],this.topicToLocalConfig[I]={validity:m||H,mode:o||"fast",devMode:d??false,uniqueIdentifierType:l?utils.NullifierType.SALTED:f,oprfKeyId:l??null,returnDeepLink:w,verifierMode:S,config:D,appClip:s?.appClip??false,allowedVerificationMethods:N},this.onRequestReceivedCallbacks[I]=[],this.onGeneratingProofCallbacks[I]=[],this.onBridgeConnectCallbacks[I]=[],this.onBridgeConnectionLostCallbacks[I]=[],this.onProofGeneratedCallbacks[I]=[],this.onSuccessCallbacks[I]=[],this.onResultCallbacks[I]=[],this.onRejectCallbacks[I]=[],this.onErrorCallbacks[I]=[],this.topicToPublicKey[I]=Y.getPublicKey(),this.topicToBridge[I]=Y,Y.onConnect(async L=>{await Promise.all(this.onBridgeConnectCallbacks[I].map(ee=>ee()));}),Y.onDisconnect(async L=>{L.wasIntentionalClose||L.willReconnect||(await Promise.all(this.onBridgeConnectionLostCallbacks[I].map(ee=>ee())));}),Y.onSecureChannelEstablished(async()=>{await Promise.all(this.onRequestReceivedCallbacks[I].map(L=>L()));}),Y.onSecureMessage(async L=>{try{await this.handleEncryptedMessage(I,L);}catch(ee){}}),this.getZkPassportRequest(I)}createQuery(){return Ne()}async verify({proofs:t,originalQuery:n,queryResult:e,validity:i,scope:a,devMode:o=false,writingDirectory:m,oprfKeyId:d,uniqueIdentifierType:f,verifierMode:l="auto",config:c,allowedVerificationMethods:x}){if(!n||!e)throw new Error("verify() requires `originalQuery` and `queryResult`");n=Se(n);let r={uniqueIdentifier:void 0,uniqueIdentifierType:void 0,verified:false};if(!t||t.length===0)return r;let h={proofs:t,originalQuery:n,queryResult:e,validity:i,scope:a,devMode:o,oprfKeyId:d,allowedVerificationMethods:x},g={...h,writingDirectory:m,config:c},w={...h,domain:this.domain},S=d?utils.NullifierType.SALTED:f,D;if(l==="local"||l==="auto"&&c?.circuitsUrl)D=await this.verifyLocally(g);else if(l==="api")D=await Fe(w)??r;else {let s;try{s=await this.verifyLocally(g);}catch(N){console.warn("Local proof verification failed:",N);}D=s?.verified?s:await Fe(w)??s??r;}return Gi(ji(D,x),S)}async verifyLocally({proofs:t,originalQuery:n,queryResult:e,validity:i,scope:a,devMode:o=false,writingDirectory:m,oprfKeyId:d,config:f,allowedVerificationMethods:l}){let c=utils.formatQueryResultDates(e),x=t[0]?.version;if(!utils.isCircuitVersion(x)||t.some(s=>s.version!==x))return console.warn("The proofs must all state the same circuit version"),{uniqueIdentifier:void 0,uniqueIdentifierType:void 0,verified:false};typeof window>"u"&&!m&&(m="/tmp");let r=new De({writingDirectory:m}),h=true,g,w,S,D;try{let s=registry.createRegistryClient(utils.getChainFromQuery(n,o),Ki(f)),{isCorrect:N,uniqueIdentifier:j,uniqueIdentifierType:Y,queryResultErrors:I,verificationMethod:L}=await Pe.checkPublicInputs(this.domain,t,n,c,i,a,d,o,s,l);if(D=L,g=j,w=Y,h=N,S=N?void 0:I,(w===utils.NullifierType.SALTED_MOCK||w===utils.NullifierType.NON_SALTED_MOCK)&&!o&&(h=!1,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.")),h){let ee=await s.getCircuitManifest(void 0,{version:t[0].version});for(let Z of t){let de=Z.name?.startsWith("outer_evm_"),ye=Z.name,Ae=await s.getPackagedCircuit(ye,ee,{validate:!de});if(de?h=await le.verify({proof:Z,rpcUrl:s.getRpcUrl(),validityPeriodInSeconds:i,domain:this.domain,scope:a,devMode:o}):h=await r.verify(Z,Ae),!h)break}}}finally{await r.destroy();}return g=h?g:void 0,w=h?w:void 0,{uniqueIdentifier:g,uniqueIdentifierType:w,verified:h,queryResultErrors:S,verificationMethod:D}}getSolidityVerifierDetails(){return le.getDetails()}getSolidityVerifierParameters({proof:t,validityPeriodInSeconds:n=H,domain:e,scope:i,devMode:a=false}){return le.getParameters({proof:t,validityPeriodInSeconds:n,domain:e??this.domain,scope:i,devMode:a})}_getUrl(t){let n=_.Buffer.from(JSON.stringify(this.topicToConfig[t])).toString("base64"),e=_.Buffer.from(JSON.stringify(this.topicToService[t])).toString("base64"),i=this.topicToPublicKey[t],a=Math.floor(Date.now()/1e3)-this.topicToLocalConfig[t].validity,o=this.topicToLocalConfig[t].uniqueIdentifierType,m=this.topicToLocalConfig[t].oprfKeyId,d=this.topicToLocalConfig[t].returnDeepLink,f=`https://zkpassport.id/r?d=${this.domain}&t=${t}&c=${encodeURIComponent(n)}&s=${encodeURIComponent(e)}&p=${i}&m=${this.topicToLocalConfig[t].mode}&v=${me}&dt=${a}&dev=${this.topicToLocalConfig[t].devMode?"1":"0"}`;o!=null&&(f+=`&nt=${o}`),m&&(f+=`&oprf_k=${m}`),d&&(f+=`&r=${encodeURIComponent(d)}`);let l=this.topicToLocalConfig[t].allowedVerificationMethods;return l&&(f+=`&ac=${utils.serializeAllowedVerificationMethods(l)}`),f}getUrl(t){return this._getUrl(t)}getServiceDetails(t){return this.topicToService[t]}getRequestKeyPair(t){return this.topicToBridge[t]?.getKeyPair()}cancelRequest(t){this.topicToBridge[t]&&(this.topicToBridge[t].close(),delete this.topicToBridge[t]),delete this.topicToPublicKey[t],delete this.topicToConfig[t],delete this.topicToLocalConfig[t],delete this.topicToProofs[t],delete this.topicToFailedProofCount[t],delete this.topicToResults[t],delete this.topicToPolicy[t],this.onRequestReceivedCallbacks[t]=[],this.onGeneratingProofCallbacks[t]=[],this.onBridgeConnectCallbacks[t]=[],this.onBridgeConnectionLostCallbacks[t]=[],this.onProofGeneratedCallbacks[t]=[],this.onSuccessCallbacks[t]=[],this.onResultCallbacks[t]=[],this.onRejectCallbacks[t]=[],this.onErrorCallbacks[t]=[];}clearAllRequests(){for(let t in this.topicToBridge)this.cancelRequest(t);}};
2
+ Object.defineProperty(exports,"ASEAN_COUNTRIES",{enumerable:true,get:function(){return utils.ASEAN_COUNTRIES}});Object.defineProperty(exports,"DEFAULT_ALLOWED_VERIFICATION_METHODS",{enumerable:true,get:function(){return utils.DEFAULT_ALLOWED_VERIFICATION_METHODS}});Object.defineProperty(exports,"EEA_COUNTRIES",{enumerable:true,get:function(){return utils.EEA_COUNTRIES}});Object.defineProperty(exports,"EU_COUNTRIES",{enumerable:true,get:function(){return utils.EU_COUNTRIES}});Object.defineProperty(exports,"MERCOSUR_COUNTRIES",{enumerable:true,get:function(){return utils.MERCOSUR_COUNTRIES}});Object.defineProperty(exports,"NullifierType",{enumerable:true,get:function(){return utils.NullifierType}});Object.defineProperty(exports,"ProofType",{enumerable:true,get:function(){return utils.ProofType}});Object.defineProperty(exports,"ProofTypeLength",{enumerable:true,get:function(){return utils.ProofTypeLength}});Object.defineProperty(exports,"SANCTIONED_COUNTRIES",{enumerable:true,get:function(){return utils.SANCTIONED_COUNTRIES}});Object.defineProperty(exports,"SCHENGEN_COUNTRIES",{enumerable:true,get:function(){return utils.SCHENGEN_COUNTRIES}});Object.defineProperty(exports,"VerificationMethod",{enumerable:true,get:function(){return utils.VerificationMethod}});Object.defineProperty(exports,"VerificationTier",{enumerable:true,get:function(){return utils.VerificationTier}});Object.defineProperty(exports,"expandAllowedVerificationMethods",{enumerable:true,get:function(){return utils.expandAllowedVerificationMethods}});Object.defineProperty(exports,"getChainFromId",{enumerable:true,get:function(){return utils.getChainFromId}});Object.defineProperty(exports,"getIdFromChain",{enumerable:true,get:function(){return utils.getIdFromChain}});Object.defineProperty(exports,"getTierForVerificationMethod",{enumerable:true,get:function(){return utils.getTierForVerificationMethod}});Object.defineProperty(exports,"isVerificationMethodAllowed",{enumerable:true,get:function(){return utils.isVerificationMethodAllowed}});exports.VERSION=me;exports.ZKPassport=_t;exports.createOfflineQuery=Ne;exports.getRegistryClientOptions=Ki;exports.normalizeCountry=se;//# sourceMappingURL=index.cjs.map
3
3
  //# sourceMappingURL=index.cjs.map