@zkpassport/sdk 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +2 -4785
- package/dist/cjs/index.d.cts +207 -9
- package/dist/esm/index.d.ts +207 -9
- package/dist/esm/index.js +2 -629
- package/package.json +17 -8
- package/dist/cjs/constants.cjs +0 -48
- package/dist/cjs/constants.d.cts +0 -9
- package/dist/cjs/logger.cjs +0 -47
- package/dist/cjs/logger.d.cts +0 -14
- package/dist/cjs/public-input-checker.cjs +0 -2151
- package/dist/cjs/public-input-checker.d.cts +0 -70
- package/dist/cjs/solidity-verifier.cjs +0 -2033
- package/dist/cjs/solidity-verifier.d.cts +0 -32
- package/dist/cjs/types.cjs +0 -18
- package/dist/cjs/types.d.cts +0 -208
- package/dist/esm/chunk-6F4PWJZI.js +0 -0
- package/dist/esm/chunk-AFLQN3AC.js +0 -22
- package/dist/esm/chunk-B57NBZWJ.js +0 -18
- package/dist/esm/chunk-KUTKOI3P.js +0 -2018
- package/dist/esm/chunk-N322IQZC.js +0 -2177
- package/dist/esm/constants.d.ts +0 -9
- package/dist/esm/constants.js +0 -18
- package/dist/esm/logger.d.ts +0 -14
- package/dist/esm/logger.js +0 -8
- package/dist/esm/public-input-checker.d.ts +0 -70
- package/dist/esm/public-input-checker.js +0 -7
- package/dist/esm/solidity-verifier.d.ts +0 -32
- package/dist/esm/solidity-verifier.js +0 -7
- package/dist/esm/types.d.ts +0 -208
- package/dist/esm/types.js +0 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,629 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-AFLQN3AC.js";
|
|
4
|
-
import {
|
|
5
|
-
PublicInputChecker
|
|
6
|
-
} from "./chunk-N322IQZC.js";
|
|
7
|
-
import {
|
|
8
|
-
SolidityVerifier
|
|
9
|
-
} from "./chunk-KUTKOI3P.js";
|
|
10
|
-
import {
|
|
11
|
-
DEFAULT_VALIDITY,
|
|
12
|
-
VERSION
|
|
13
|
-
} from "./chunk-B57NBZWJ.js";
|
|
14
|
-
import "./chunk-6F4PWJZI.js";
|
|
15
|
-
|
|
16
|
-
// src/index.ts
|
|
17
|
-
import { getAlpha3Code, registerLocale } from "i18n-iso-countries";
|
|
18
|
-
import {
|
|
19
|
-
getProofData,
|
|
20
|
-
getNumberOfPublicInputs,
|
|
21
|
-
formatQueryResultDates,
|
|
22
|
-
NullifierType
|
|
23
|
-
} from "@zkpassport/utils";
|
|
24
|
-
import i18en from "i18n-iso-countries/langs/en.json";
|
|
25
|
-
import { Buffer } from "buffer/";
|
|
26
|
-
import { RegistryClient } from "@zkpassport/registry";
|
|
27
|
-
import { Bridge } from "@obsidion/bridge";
|
|
28
|
-
import {
|
|
29
|
-
SANCTIONED_COUNTRIES,
|
|
30
|
-
EU_COUNTRIES,
|
|
31
|
-
EEA_COUNTRIES,
|
|
32
|
-
SCHENGEN_COUNTRIES,
|
|
33
|
-
ASEAN_COUNTRIES,
|
|
34
|
-
MERCOSUR_COUNTRIES
|
|
35
|
-
} from "@zkpassport/utils";
|
|
36
|
-
if (typeof globalThis.Buffer === "undefined") {
|
|
37
|
-
globalThis.Buffer = Buffer;
|
|
38
|
-
if (typeof window !== "undefined") {
|
|
39
|
-
window.Buffer = Buffer;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
registerLocale(i18en);
|
|
43
|
-
function hasRequestedAccessToField(credentialsRequest, field) {
|
|
44
|
-
const fieldValue = credentialsRequest[field];
|
|
45
|
-
const isDefined = fieldValue !== void 0 && fieldValue !== null;
|
|
46
|
-
if (!isDefined) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
for (const key in fieldValue) {
|
|
50
|
-
if (fieldValue[key] !== void 0 && fieldValue[key] !== null) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
function normalizeCountry(country) {
|
|
57
|
-
if (country === "Zero Knowledge Republic") {
|
|
58
|
-
return "ZKR";
|
|
59
|
-
}
|
|
60
|
-
let normalizedCountry;
|
|
61
|
-
const alpha3 = getAlpha3Code(country, "en");
|
|
62
|
-
normalizedCountry = alpha3 || country || "ZKR";
|
|
63
|
-
return normalizedCountry;
|
|
64
|
-
}
|
|
65
|
-
function numericalCompare(fnName, key, value, requestId, requestIdToConfig) {
|
|
66
|
-
requestIdToConfig[requestId][key] = {
|
|
67
|
-
...requestIdToConfig[requestId][key],
|
|
68
|
-
[fnName]: value
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function rangeCompare(key, value, requestId, requestIdToConfig) {
|
|
72
|
-
requestIdToConfig[requestId][key] = {
|
|
73
|
-
...requestIdToConfig[requestId][key],
|
|
74
|
-
range: value
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function generalCompare(fnName, key, value, requestId, requestIdToConfig) {
|
|
78
|
-
requestIdToConfig[requestId][key] = {
|
|
79
|
-
...requestIdToConfig[requestId][key],
|
|
80
|
-
[fnName]: value
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
var ZKPassport = class {
|
|
84
|
-
constructor(_domain) {
|
|
85
|
-
this.topicToConfig = {};
|
|
86
|
-
this.topicToLocalConfig = {};
|
|
87
|
-
this.topicToPublicKey = {};
|
|
88
|
-
this.topicToBridge = {};
|
|
89
|
-
this.topicToRequestReceived = {};
|
|
90
|
-
this.topicToService = {};
|
|
91
|
-
this.topicToProofs = {};
|
|
92
|
-
this.topicToExpectedProofCount = {};
|
|
93
|
-
this.topicToFailedProofCount = {};
|
|
94
|
-
this.topicToResults = {};
|
|
95
|
-
this.onRequestReceivedCallbacks = {};
|
|
96
|
-
this.onGeneratingProofCallbacks = {};
|
|
97
|
-
this.onBridgeConnectCallbacks = {};
|
|
98
|
-
this.onProofGeneratedCallbacks = {};
|
|
99
|
-
this.onResultCallbacks = {};
|
|
100
|
-
this.onRejectCallbacks = {};
|
|
101
|
-
this.onErrorCallbacks = {};
|
|
102
|
-
if (!_domain && typeof window === "undefined") {
|
|
103
|
-
throw new Error("Domain argument is required in Node.js environment");
|
|
104
|
-
}
|
|
105
|
-
this.domain = this.normalizeDomain(_domain || window.location.hostname);
|
|
106
|
-
}
|
|
107
|
-
//private wasmVerifierInit: boolean = false
|
|
108
|
-
normalizeDomain(domain) {
|
|
109
|
-
return domain.trim().replace(/^https?:\/\//, "").replace(/\/[^/]*$/, "").replace(/:[0-9]+/, "").replace(/\?.*$/, "").replace(/#.*$/, "").toLowerCase();
|
|
110
|
-
}
|
|
111
|
-
async handleResult(topic) {
|
|
112
|
-
const result = this.topicToResults[topic];
|
|
113
|
-
delete this.topicToResults[topic];
|
|
114
|
-
const { uniqueIdentifier, verified, queryResultErrors } = await this.verify({
|
|
115
|
-
proofs: this.topicToProofs[topic],
|
|
116
|
-
queryResult: result,
|
|
117
|
-
validity: this.topicToLocalConfig[topic]?.validity,
|
|
118
|
-
scope: this.topicToService[topic]?.scope,
|
|
119
|
-
devMode: this.topicToLocalConfig[topic]?.devMode
|
|
120
|
-
});
|
|
121
|
-
delete this.topicToProofs[topic];
|
|
122
|
-
const hasFailedProofs = this.topicToFailedProofCount[topic] > 0;
|
|
123
|
-
await Promise.all(
|
|
124
|
-
this.onResultCallbacks[topic].map(
|
|
125
|
-
(callback) => callback({
|
|
126
|
-
// If there are failed proofs, we don't return the unique identifier
|
|
127
|
-
// and we set the verified result to false
|
|
128
|
-
uniqueIdentifier: hasFailedProofs ? void 0 : uniqueIdentifier,
|
|
129
|
-
verified: hasFailedProofs ? false : verified,
|
|
130
|
-
result,
|
|
131
|
-
queryResultErrors
|
|
132
|
-
})
|
|
133
|
-
)
|
|
134
|
-
);
|
|
135
|
-
delete this.topicToExpectedProofCount[topic];
|
|
136
|
-
delete this.topicToFailedProofCount[topic];
|
|
137
|
-
}
|
|
138
|
-
setExpectedProofCount(topic) {
|
|
139
|
-
if (this.topicToLocalConfig[topic].mode !== "fast") {
|
|
140
|
-
this.topicToExpectedProofCount[topic] = 1;
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
const fields = Object.keys(this.topicToConfig[topic]).filter(
|
|
144
|
-
(key) => hasRequestedAccessToField(this.topicToConfig[topic], key)
|
|
145
|
-
);
|
|
146
|
-
const neededCircuits = [];
|
|
147
|
-
for (const field of fields) {
|
|
148
|
-
for (const key in this.topicToConfig[topic][field]) {
|
|
149
|
-
switch (key) {
|
|
150
|
-
case "disclose":
|
|
151
|
-
if (field !== "age" && !neededCircuits.includes("disclose_bytes")) {
|
|
152
|
-
neededCircuits.push("disclose_bytes");
|
|
153
|
-
} else if (field === "age" && !neededCircuits.includes("compare_age")) {
|
|
154
|
-
neededCircuits.push("compare_age");
|
|
155
|
-
}
|
|
156
|
-
break;
|
|
157
|
-
case "eq":
|
|
158
|
-
if (field !== "age" && field !== "birthdate" && field !== "expiry_date" && !neededCircuits.includes("disclose_bytes")) {
|
|
159
|
-
neededCircuits.push("disclose_bytes");
|
|
160
|
-
} else if (field === "age" && !neededCircuits.includes("compare_age")) {
|
|
161
|
-
neededCircuits.push("compare_age");
|
|
162
|
-
} else if (field === "birthdate" && !neededCircuits.includes("compare_birthdate")) {
|
|
163
|
-
neededCircuits.push("compare_birthdate");
|
|
164
|
-
} else if (field === "expiry_date" && !neededCircuits.includes("compare_expiry")) {
|
|
165
|
-
neededCircuits.push("compare_expiry");
|
|
166
|
-
}
|
|
167
|
-
break;
|
|
168
|
-
case "gte":
|
|
169
|
-
case "gt":
|
|
170
|
-
case "lte":
|
|
171
|
-
case "lt":
|
|
172
|
-
case "range":
|
|
173
|
-
if (field === "age" && !neededCircuits.includes("compare_age")) {
|
|
174
|
-
neededCircuits.push("compare_age");
|
|
175
|
-
} else if (field === "expiry_date" && !neededCircuits.includes("compare_expiry")) {
|
|
176
|
-
neededCircuits.push("compare_expiry");
|
|
177
|
-
} else if (field === "birthdate" && !neededCircuits.includes("compare_birthdate")) {
|
|
178
|
-
neededCircuits.push("compare_birthdate");
|
|
179
|
-
}
|
|
180
|
-
break;
|
|
181
|
-
case "in":
|
|
182
|
-
if (field === "nationality" && !neededCircuits.includes("inclusion_check_nationality")) {
|
|
183
|
-
neededCircuits.push("inclusion_check_nationality");
|
|
184
|
-
} else if (field === "issuing_country" && !neededCircuits.includes("inclusion_check_issuing_country")) {
|
|
185
|
-
neededCircuits.push("inclusion_check_issuing_country");
|
|
186
|
-
}
|
|
187
|
-
break;
|
|
188
|
-
case "out":
|
|
189
|
-
if (field === "nationality" && !neededCircuits.includes("exclusion_check_nationality")) {
|
|
190
|
-
neededCircuits.push("exclusion_check_nationality");
|
|
191
|
-
} else if (field === "issuing_country" && !neededCircuits.includes("exclusion_check_issuing_country")) {
|
|
192
|
-
neededCircuits.push("exclusion_check_issuing_country");
|
|
193
|
-
}
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
if (this.topicToConfig[topic].bind) {
|
|
199
|
-
neededCircuits.push("bind");
|
|
200
|
-
}
|
|
201
|
-
if (this.topicToConfig[topic].sanctions) {
|
|
202
|
-
neededCircuits.push("exclusion_check_sanctions");
|
|
203
|
-
}
|
|
204
|
-
if (this.topicToConfig[topic].facematch) {
|
|
205
|
-
neededCircuits.push("facematch");
|
|
206
|
-
}
|
|
207
|
-
this.topicToExpectedProofCount[topic] = neededCircuits.length === 0 ? 4 : 3 + neededCircuits.length;
|
|
208
|
-
this.topicToFailedProofCount[topic] = 0;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* @notice Handle an encrypted message.
|
|
212
|
-
* @param request The request.
|
|
213
|
-
* @param outerRequest The outer request.
|
|
214
|
-
*/
|
|
215
|
-
async handleEncryptedMessage(topic, request) {
|
|
216
|
-
noLogger.debug("Received encrypted message:", request);
|
|
217
|
-
if (request.method === "accept") {
|
|
218
|
-
noLogger.debug(`User accepted the request and is generating a proof`);
|
|
219
|
-
await Promise.all(this.onGeneratingProofCallbacks[topic].map((callback) => callback(topic)));
|
|
220
|
-
} else if (request.method === "reject") {
|
|
221
|
-
noLogger.debug(`User rejected the request`);
|
|
222
|
-
await Promise.all(this.onRejectCallbacks[topic].map((callback) => callback()));
|
|
223
|
-
} else if (request.method === "proof") {
|
|
224
|
-
noLogger.debug(`User generated proof`);
|
|
225
|
-
this.topicToProofs[topic].push(request.params);
|
|
226
|
-
await Promise.all(
|
|
227
|
-
this.onProofGeneratedCallbacks[topic].map((callback) => callback(request.params))
|
|
228
|
-
);
|
|
229
|
-
if (this.topicToResults[topic] && this.topicToExpectedProofCount[topic] === this.topicToProofs[topic].length) {
|
|
230
|
-
await this.handleResult(topic);
|
|
231
|
-
}
|
|
232
|
-
} else if (request.method === "done") {
|
|
233
|
-
noLogger.debug(`User sent the query result`);
|
|
234
|
-
this.topicToResults[topic] = formatQueryResultDates(request.params);
|
|
235
|
-
if (this.topicToExpectedProofCount[topic] === this.topicToProofs[topic].length) {
|
|
236
|
-
await this.handleResult(topic);
|
|
237
|
-
}
|
|
238
|
-
} else if (request.method === "error") {
|
|
239
|
-
const error = request.params.error;
|
|
240
|
-
if (error && error === "This ID is not supported yet") {
|
|
241
|
-
this.topicToExpectedProofCount[topic] = 0;
|
|
242
|
-
this.topicToFailedProofCount[topic] += this.topicToExpectedProofCount[topic];
|
|
243
|
-
if (this.topicToResults[topic]) {
|
|
244
|
-
await this.handleResult(topic);
|
|
245
|
-
}
|
|
246
|
-
} else if (error && error.startsWith("Cannot generate proof")) {
|
|
247
|
-
this.topicToExpectedProofCount[topic] -= 1;
|
|
248
|
-
this.topicToFailedProofCount[topic] += 1;
|
|
249
|
-
if (this.topicToResults[topic] && this.topicToExpectedProofCount[topic] === this.topicToProofs[topic].length) {
|
|
250
|
-
await this.handleResult(topic);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
await Promise.all(this.onErrorCallbacks[topic].map((callback) => callback(error)));
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
getZkPassportRequest(topic) {
|
|
257
|
-
return {
|
|
258
|
-
eq: (key, value) => {
|
|
259
|
-
if (key === "issuing_country" || key === "nationality") {
|
|
260
|
-
value = normalizeCountry(value);
|
|
261
|
-
}
|
|
262
|
-
generalCompare("eq", key, value, topic, this.topicToConfig);
|
|
263
|
-
return this.getZkPassportRequest(topic);
|
|
264
|
-
},
|
|
265
|
-
gte: (key, value) => {
|
|
266
|
-
numericalCompare("gte", key, value, topic, this.topicToConfig);
|
|
267
|
-
if (key === "age" && (value < 1 || value >= 100)) {
|
|
268
|
-
throw new Error("Age must be between 1 and 99 (inclusive)");
|
|
269
|
-
}
|
|
270
|
-
return this.getZkPassportRequest(topic);
|
|
271
|
-
},
|
|
272
|
-
gt: (key, value) => {
|
|
273
|
-
numericalCompare("gt", key, value, topic, this.topicToConfig);
|
|
274
|
-
return this.getZkPassportRequest(topic);
|
|
275
|
-
},
|
|
276
|
-
lte: (key, value) => {
|
|
277
|
-
numericalCompare("lte", key, value, topic, this.topicToConfig);
|
|
278
|
-
return this.getZkPassportRequest(topic);
|
|
279
|
-
},
|
|
280
|
-
lt: (key, value) => {
|
|
281
|
-
numericalCompare("lt", key, value, topic, this.topicToConfig);
|
|
282
|
-
return this.getZkPassportRequest(topic);
|
|
283
|
-
},
|
|
284
|
-
range: (key, start, end) => {
|
|
285
|
-
rangeCompare(key, [start, end], topic, this.topicToConfig);
|
|
286
|
-
return this.getZkPassportRequest(topic);
|
|
287
|
-
},
|
|
288
|
-
in: (key, value) => {
|
|
289
|
-
value = value.map((v) => normalizeCountry(v));
|
|
290
|
-
generalCompare("in", key, value, topic, this.topicToConfig);
|
|
291
|
-
return this.getZkPassportRequest(topic);
|
|
292
|
-
},
|
|
293
|
-
out: (key, value) => {
|
|
294
|
-
value = value.map((v) => normalizeCountry(v));
|
|
295
|
-
generalCompare("out", key, value, topic, this.topicToConfig);
|
|
296
|
-
return this.getZkPassportRequest(topic);
|
|
297
|
-
},
|
|
298
|
-
disclose: (key) => {
|
|
299
|
-
this.topicToConfig[topic][key] = {
|
|
300
|
-
...this.topicToConfig[topic][key],
|
|
301
|
-
disclose: true
|
|
302
|
-
};
|
|
303
|
-
return this.getZkPassportRequest(topic);
|
|
304
|
-
},
|
|
305
|
-
bind: (key, value) => {
|
|
306
|
-
this.topicToConfig[topic].bind = {
|
|
307
|
-
...this.topicToConfig[topic].bind,
|
|
308
|
-
[key]: value
|
|
309
|
-
};
|
|
310
|
-
return this.getZkPassportRequest(topic);
|
|
311
|
-
},
|
|
312
|
-
sanctions: (countries = "all", lists = "all", options = { strict: false }) => {
|
|
313
|
-
this.topicToConfig[topic].sanctions = {
|
|
314
|
-
...this.topicToConfig[topic].sanctions,
|
|
315
|
-
countries: countries === "all" ? "all" : Array.isArray(countries) ? [
|
|
316
|
-
...this.topicToConfig[topic].sanctions?.countries ?? [],
|
|
317
|
-
...countries
|
|
318
|
-
] : [
|
|
319
|
-
...this.topicToConfig[topic].sanctions?.countries ?? [],
|
|
320
|
-
countries
|
|
321
|
-
],
|
|
322
|
-
lists: lists === "all" ? "all" : Array.isArray(lists) ? [...this.topicToConfig[topic].sanctions?.lists ?? [], ...lists] : [...this.topicToConfig[topic].sanctions?.lists ?? [], lists],
|
|
323
|
-
strict: options.strict ?? false
|
|
324
|
-
};
|
|
325
|
-
return this.getZkPassportRequest(topic);
|
|
326
|
-
},
|
|
327
|
-
facematch: (mode = "regular") => {
|
|
328
|
-
this.topicToConfig[topic].facematch = {
|
|
329
|
-
mode
|
|
330
|
-
};
|
|
331
|
-
return this.getZkPassportRequest(topic);
|
|
332
|
-
},
|
|
333
|
-
done: () => {
|
|
334
|
-
this.setExpectedProofCount(topic);
|
|
335
|
-
return {
|
|
336
|
-
url: this._getUrl(topic),
|
|
337
|
-
requestId: topic,
|
|
338
|
-
onRequestReceived: (callback) => this.onRequestReceivedCallbacks[topic].push(callback),
|
|
339
|
-
onGeneratingProof: (callback) => this.onGeneratingProofCallbacks[topic].push(callback),
|
|
340
|
-
onBridgeConnect: (callback) => this.onBridgeConnectCallbacks[topic].push(callback),
|
|
341
|
-
onProofGenerated: (callback) => this.onProofGeneratedCallbacks[topic].push(callback),
|
|
342
|
-
onResult: (callback) => this.onResultCallbacks[topic].push(callback),
|
|
343
|
-
onReject: (callback) => this.onRejectCallbacks[topic].push(callback),
|
|
344
|
-
onError: (callback) => this.onErrorCallbacks[topic].push(callback),
|
|
345
|
-
isBridgeConnected: () => this.topicToBridge[topic].isBridgeConnected(),
|
|
346
|
-
requestReceived: () => this.topicToRequestReceived[topic] === true
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* @notice Create a new request
|
|
353
|
-
* @param name Your service name
|
|
354
|
-
* @param logo The logo of your service
|
|
355
|
-
* @param purpose To explain what you want to do with the user's data
|
|
356
|
-
* @param scope Scope this request to a specific use case
|
|
357
|
-
* @param projectID The project ID of your service
|
|
358
|
-
* @param validity How many seconds ago the proof checking the expiry date of the ID should have been generated
|
|
359
|
-
* @param devMode Whether to enable dev mode. This will allow you to verify mock proofs (i.e. from ZKR)
|
|
360
|
-
* @returns The query builder object.
|
|
361
|
-
*/
|
|
362
|
-
async request({
|
|
363
|
-
name,
|
|
364
|
-
logo,
|
|
365
|
-
purpose,
|
|
366
|
-
scope,
|
|
367
|
-
projectID,
|
|
368
|
-
mode,
|
|
369
|
-
validity,
|
|
370
|
-
devMode,
|
|
371
|
-
topicOverride,
|
|
372
|
-
keyPairOverride,
|
|
373
|
-
cloudProverUrl,
|
|
374
|
-
bridgeUrl
|
|
375
|
-
}) {
|
|
376
|
-
const bridge = await Bridge.create({
|
|
377
|
-
keyPair: keyPairOverride,
|
|
378
|
-
bridgeId: topicOverride,
|
|
379
|
-
bridgeUrl
|
|
380
|
-
});
|
|
381
|
-
const topic = bridge.connection.getBridgeId();
|
|
382
|
-
this.topicToConfig[topic] = {};
|
|
383
|
-
this.topicToService[topic] = {
|
|
384
|
-
name,
|
|
385
|
-
logo,
|
|
386
|
-
purpose,
|
|
387
|
-
scope,
|
|
388
|
-
projectID,
|
|
389
|
-
cloudProverUrl,
|
|
390
|
-
bridgeUrl
|
|
391
|
-
};
|
|
392
|
-
this.topicToProofs[topic] = [];
|
|
393
|
-
this.topicToExpectedProofCount[topic] = 0;
|
|
394
|
-
this.topicToLocalConfig[topic] = {
|
|
395
|
-
// Default to 7 days
|
|
396
|
-
validity: validity || DEFAULT_VALIDITY,
|
|
397
|
-
mode: mode || "fast",
|
|
398
|
-
devMode: devMode || false
|
|
399
|
-
};
|
|
400
|
-
this.onRequestReceivedCallbacks[topic] = [];
|
|
401
|
-
this.onGeneratingProofCallbacks[topic] = [];
|
|
402
|
-
this.onBridgeConnectCallbacks[topic] = [];
|
|
403
|
-
this.onProofGeneratedCallbacks[topic] = [];
|
|
404
|
-
this.onResultCallbacks[topic] = [];
|
|
405
|
-
this.onRejectCallbacks[topic] = [];
|
|
406
|
-
this.onErrorCallbacks[topic] = [];
|
|
407
|
-
this.topicToPublicKey[topic] = bridge.getPublicKey();
|
|
408
|
-
this.topicToBridge[topic] = bridge;
|
|
409
|
-
bridge.onConnect(async (reconnection) => {
|
|
410
|
-
noLogger.debug("Bridge connected");
|
|
411
|
-
noLogger.debug("Is reconnection:", reconnection);
|
|
412
|
-
await Promise.all(this.onBridgeConnectCallbacks[topic].map((callback) => callback()));
|
|
413
|
-
});
|
|
414
|
-
bridge.onSecureChannelEstablished(async () => {
|
|
415
|
-
noLogger.debug("Secure channel established");
|
|
416
|
-
await Promise.all(this.onRequestReceivedCallbacks[topic].map((callback) => callback()));
|
|
417
|
-
});
|
|
418
|
-
bridge.onSecureMessage(async (message) => {
|
|
419
|
-
noLogger.debug("Received message:", message);
|
|
420
|
-
this.handleEncryptedMessage(topic, message);
|
|
421
|
-
});
|
|
422
|
-
return this.getZkPassportRequest(topic);
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* @notice Verify the proofs received from the mobile app.
|
|
426
|
-
* @param proofs The proofs to verify.
|
|
427
|
-
* @param queryResult The query result to verify against
|
|
428
|
-
* @param validity How many seconds ago the proof checking the expiry date of the ID should have been generated
|
|
429
|
-
* @param scope Scope this request to a specific use case
|
|
430
|
-
* @param devMode Whether to enable dev mode. This will allow you to verify mock proofs (i.e. from ZKR)
|
|
431
|
-
* @param writingDirectory The directory (e.g. `./tmp`) where the necessary temporary artifacts for verification are written to.
|
|
432
|
-
* It should only be needed when running the `verify` function on a server with restricted write access (e.g. Vercel)
|
|
433
|
-
* @returns An object containing the unique identifier associated to the user
|
|
434
|
-
* and a boolean indicating whether the proofs were successfully verified.
|
|
435
|
-
*/
|
|
436
|
-
async verify({
|
|
437
|
-
proofs,
|
|
438
|
-
queryResult,
|
|
439
|
-
validity,
|
|
440
|
-
scope,
|
|
441
|
-
devMode = false,
|
|
442
|
-
writingDirectory
|
|
443
|
-
}) {
|
|
444
|
-
if (!proofs || proofs.length === 0) {
|
|
445
|
-
return {
|
|
446
|
-
uniqueIdentifier: void 0,
|
|
447
|
-
uniqueIdentifierType: void 0,
|
|
448
|
-
verified: false
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
const formattedResult = formatQueryResultDates(queryResult);
|
|
452
|
-
const { UltraHonkVerifierBackend } = await import("@aztec/bb.js");
|
|
453
|
-
if (typeof window === "undefined" && !writingDirectory) {
|
|
454
|
-
writingDirectory = "/tmp";
|
|
455
|
-
}
|
|
456
|
-
const verifier = new UltraHonkVerifierBackend({
|
|
457
|
-
crsPath: writingDirectory ? writingDirectory + "/.bb-crs" : void 0
|
|
458
|
-
});
|
|
459
|
-
let verified = true;
|
|
460
|
-
let uniqueIdentifier;
|
|
461
|
-
let uniqueIdentifierType;
|
|
462
|
-
let queryResultErrors;
|
|
463
|
-
const {
|
|
464
|
-
isCorrect,
|
|
465
|
-
uniqueIdentifier: uniqueIdentifierFromPublicInputs,
|
|
466
|
-
uniqueIdentifierType: uniqueIdentifierTypeFromPublicInputs,
|
|
467
|
-
queryResultErrors: queryResultErrorsFromPublicInputs
|
|
468
|
-
} = await PublicInputChecker.checkPublicInputs(
|
|
469
|
-
this.domain,
|
|
470
|
-
proofs,
|
|
471
|
-
formattedResult,
|
|
472
|
-
validity,
|
|
473
|
-
scope
|
|
474
|
-
);
|
|
475
|
-
uniqueIdentifier = uniqueIdentifierFromPublicInputs;
|
|
476
|
-
uniqueIdentifierType = uniqueIdentifierTypeFromPublicInputs;
|
|
477
|
-
verified = isCorrect;
|
|
478
|
-
queryResultErrors = isCorrect ? void 0 : queryResultErrorsFromPublicInputs;
|
|
479
|
-
if (uniqueIdentifier && uniqueIdentifierType && (uniqueIdentifierType === NullifierType.SALTED_MOCK || uniqueIdentifierType === NullifierType.NON_SALTED_MOCK) && !devMode) {
|
|
480
|
-
verified = false;
|
|
481
|
-
console.warn(
|
|
482
|
-
"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."
|
|
483
|
-
);
|
|
484
|
-
}
|
|
485
|
-
if (verified) {
|
|
486
|
-
const registryClient = new RegistryClient({ chainId: 11155111 });
|
|
487
|
-
const circuitManifest = await registryClient.getCircuitManifest(void 0, {
|
|
488
|
-
// We assume all proofs have the same version
|
|
489
|
-
version: proofs[0].version
|
|
490
|
-
});
|
|
491
|
-
for (const proof of proofs) {
|
|
492
|
-
const isOuterEVM = proof.name?.startsWith("outer_evm_");
|
|
493
|
-
const proofName = proof.name;
|
|
494
|
-
const proofData = getProofData(proof.proof, getNumberOfPublicInputs(proofName));
|
|
495
|
-
const hostedPackagedCircuit = await registryClient.getPackagedCircuit(
|
|
496
|
-
proofName,
|
|
497
|
-
circuitManifest,
|
|
498
|
-
// TODO: set to always validate when the issue is vkey hash calculation is fixed
|
|
499
|
-
// Not as important anyway, as the solidity verifier is the ultimate anchor for
|
|
500
|
-
// EVM outer proofs verification
|
|
501
|
-
{ validate: !isOuterEVM }
|
|
502
|
-
);
|
|
503
|
-
if (isOuterEVM) {
|
|
504
|
-
try {
|
|
505
|
-
const { createPublicClient, http } = await import("viem");
|
|
506
|
-
const { sepolia } = await import("viem/chains");
|
|
507
|
-
const { address, abi, functionName } = this.getSolidityVerifierDetails("ethereum_sepolia");
|
|
508
|
-
const client = createPublicClient({
|
|
509
|
-
chain: sepolia,
|
|
510
|
-
transport: http("https://ethereum-sepolia-rpc.publicnode.com")
|
|
511
|
-
});
|
|
512
|
-
const params = this.getSolidityVerifierParameters({
|
|
513
|
-
proof,
|
|
514
|
-
domain: this.domain,
|
|
515
|
-
scope,
|
|
516
|
-
devMode
|
|
517
|
-
});
|
|
518
|
-
const result = await client.readContract({
|
|
519
|
-
address,
|
|
520
|
-
abi,
|
|
521
|
-
functionName,
|
|
522
|
-
args: [params]
|
|
523
|
-
});
|
|
524
|
-
const isVerified = Array.isArray(result) ? Boolean(result[0]) : false;
|
|
525
|
-
verified = isVerified;
|
|
526
|
-
} catch (error) {
|
|
527
|
-
console.warn("Error verifying proof", error);
|
|
528
|
-
verified = false;
|
|
529
|
-
}
|
|
530
|
-
} else {
|
|
531
|
-
const vkeyBytes = Buffer.from(hostedPackagedCircuit.vkey, "base64");
|
|
532
|
-
try {
|
|
533
|
-
verified = await verifier.verifyProof({
|
|
534
|
-
proof: Buffer.from(proofData.proof.join(""), "hex"),
|
|
535
|
-
publicInputs: proofData.publicInputs,
|
|
536
|
-
verificationKey: new Uint8Array(vkeyBytes)
|
|
537
|
-
});
|
|
538
|
-
} catch (e) {
|
|
539
|
-
console.warn("Error verifying proof", e);
|
|
540
|
-
verified = false;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
if (!verified) {
|
|
544
|
-
break;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
uniqueIdentifier = verified ? uniqueIdentifier : void 0;
|
|
549
|
-
uniqueIdentifierType = verified ? uniqueIdentifierType : void 0;
|
|
550
|
-
return { uniqueIdentifier, uniqueIdentifierType, verified, queryResultErrors };
|
|
551
|
-
}
|
|
552
|
-
getSolidityVerifierDetails(network) {
|
|
553
|
-
return SolidityVerifier.getDetails(network);
|
|
554
|
-
}
|
|
555
|
-
getSolidityVerifierParameters({
|
|
556
|
-
proof,
|
|
557
|
-
validityPeriodInSeconds = DEFAULT_VALIDITY,
|
|
558
|
-
domain,
|
|
559
|
-
scope,
|
|
560
|
-
devMode = false
|
|
561
|
-
}) {
|
|
562
|
-
return SolidityVerifier.getParameters({
|
|
563
|
-
proof,
|
|
564
|
-
validityPeriodInSeconds,
|
|
565
|
-
domain: domain ?? this.domain,
|
|
566
|
-
scope,
|
|
567
|
-
devMode
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
_getUrl(requestId) {
|
|
571
|
-
const base64Config = Buffer.from(JSON.stringify(this.topicToConfig[requestId])).toString(
|
|
572
|
-
"base64"
|
|
573
|
-
);
|
|
574
|
-
const base64Service = Buffer.from(JSON.stringify(this.topicToService[requestId])).toString(
|
|
575
|
-
"base64"
|
|
576
|
-
);
|
|
577
|
-
const pubkey = this.topicToPublicKey[requestId];
|
|
578
|
-
const timestamp = Math.floor(Date.now() / 1e3) - this.topicToLocalConfig[requestId].validity;
|
|
579
|
-
return `https://zkpassport.id/r?d=${this.domain}&t=${requestId}&c=${base64Config}&s=${base64Service}&p=${pubkey}&m=${this.topicToLocalConfig[requestId].mode}&v=${VERSION}&dt=${timestamp}&dev=${this.topicToLocalConfig[requestId].devMode ? "1" : "0"}`;
|
|
580
|
-
}
|
|
581
|
-
/**
|
|
582
|
-
* @notice Returns the URL of the request.
|
|
583
|
-
* @param requestId The request ID.
|
|
584
|
-
* @returns The URL of the request.
|
|
585
|
-
*/
|
|
586
|
-
getUrl(requestId) {
|
|
587
|
-
return this._getUrl(requestId);
|
|
588
|
-
}
|
|
589
|
-
/**
|
|
590
|
-
* @notice Cancels a request by closing the WebSocket connection and deleting the associated data.
|
|
591
|
-
* @param requestId The request ID.
|
|
592
|
-
*/
|
|
593
|
-
cancelRequest(requestId) {
|
|
594
|
-
if (this.topicToBridge[requestId]) {
|
|
595
|
-
this.topicToBridge[requestId].close();
|
|
596
|
-
delete this.topicToBridge[requestId];
|
|
597
|
-
}
|
|
598
|
-
delete this.topicToPublicKey[requestId];
|
|
599
|
-
delete this.topicToConfig[requestId];
|
|
600
|
-
delete this.topicToLocalConfig[requestId];
|
|
601
|
-
delete this.topicToProofs[requestId];
|
|
602
|
-
delete this.topicToExpectedProofCount[requestId];
|
|
603
|
-
delete this.topicToFailedProofCount[requestId];
|
|
604
|
-
delete this.topicToResults[requestId];
|
|
605
|
-
this.onRequestReceivedCallbacks[requestId] = [];
|
|
606
|
-
this.onGeneratingProofCallbacks[requestId] = [];
|
|
607
|
-
this.onBridgeConnectCallbacks[requestId] = [];
|
|
608
|
-
this.onProofGeneratedCallbacks[requestId] = [];
|
|
609
|
-
this.onRejectCallbacks[requestId] = [];
|
|
610
|
-
this.onErrorCallbacks[requestId] = [];
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* @notice Clears all requests.
|
|
614
|
-
*/
|
|
615
|
-
clearAllRequests() {
|
|
616
|
-
for (const requestId in this.topicToBridge) {
|
|
617
|
-
this.cancelRequest(requestId);
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
};
|
|
621
|
-
export {
|
|
622
|
-
ASEAN_COUNTRIES,
|
|
623
|
-
EEA_COUNTRIES,
|
|
624
|
-
EU_COUNTRIES,
|
|
625
|
-
MERCOSUR_COUNTRIES,
|
|
626
|
-
SANCTIONED_COUNTRIES,
|
|
627
|
-
SCHENGEN_COUNTRIES,
|
|
628
|
-
ZKPassport
|
|
629
|
-
};
|
|
1
|
+
import {registerLocale,getAlpha3Code}from'i18n-iso-countries';import {formatQueryResultDates,NullifierType,getProofData,getNumberOfPublicInputs,DisclosedData,areDatesEqual,formatName,getMinAgeFromCommittedInputs,getMaxAgeFromCommittedInputs,getBirthdateMinDateTimestamp,SECONDS_BETWEEN_1900_AND_1970,getBirthdateMaxDateTimestamp,getMinDateFromCommittedInputs,getMaxDateFromCommittedInputs,getServiceScopeHash,getServiceScopeFromDisclosureProof,getScopeHash,getServiceSubScopeFromDisclosureProof,getCurrentDateFromDisclosureProof,getCertificateRegistryRootFromOuterProof,getCircuitRegistryRootFromOuterProof,getCurrentDateFromOuterProof,getParamCommitmentsFromOuterProof,getScopeFromOuterProof,getSubscopeFromOuterProof,getAgeEVMParameterCommitment,getAgeParameterCommitment,getDateEVMParameterCommitment,ProofType,getDateParameterCommitment,getDiscloseEVMParameterCommitment,getDiscloseParameterCommitment,getCountryEVMParameterCommitment,getCountryParameterCommitment,getBindEVMParameterCommitment,formatBoundData,getBindParameterCommitment,SanctionsBuilder,getFacematchEvmParameterCommitment,getFacematchParameterCommitment,getNullifierFromOuterProof,getNullifierTypeFromOuterProof,getCommitmentFromDSCProof,getMerkleRootFromDSCProof,getCommitmentInFromIDDataProof,getCommitmentOutFromIDDataProof,getCommitmentInFromIntegrityProof,getCommitmentOutFromIntegrityProof,getCommitmentInFromDisclosureProof,getParameterCommitmentFromDisclosureProof,getNullifierFromDisclosureProof,getNullifierTypeFromDisclosureProof,getCommittedInputCount,ProofTypeLength,rightPadArrayWithZeros,numberToBytesBE}from'@zkpassport/utils';export{ASEAN_COUNTRIES,EEA_COUNTRIES,EU_COUNTRIES,MERCOSUR_COUNTRIES,ProofType,ProofTypeLength,SANCTIONED_COUNTRIES,SCHENGEN_COUNTRIES}from'@zkpassport/utils';import pt from'i18n-iso-countries/langs/en.json';import {Buffer}from'buffer/';import {RegistryClient}from'@zkpassport/registry';import {Bridge}from'@obsidion/bridge';import {sha256}from'@noble/hashes/sha2';import {hexToBytes,bytesToHex}from'@noble/hashes/utils';var me="0.12.0";var Q=new Date(0),ne="0x1fa73686cf510f8f85757b0602de0dd72a13e68ae2092462be8b72662e7f179b",se="0x24d9929b248be7eeecaa98e105c034a50539610f3fdd4cb9c8983ef4100d615d",re="0x2532418a107c5306fa8308c22255792cf77e4a290cbce8a840a642a3e591340b",oe="0x16700a2d9168a194fc85f237af5829b5a2be05b8ae8ac4879ada34cf54a9c211";var te=class{static checkDiscloseBytesPublicInputs(t,e){let i={},s=true,c=(t.committedInputs?.disclose_bytes).disclosedBytes??(t.committedInputs?.disclose_bytes_evm).disclosedBytes,o=DisclosedData.fromDisclosedBytes(c,"passport"),d=DisclosedData.fromDisclosedBytes(c,"id_card");if(e.document_type&&(e.document_type.eq&&e.document_type.eq.result&&e.document_type.eq.expected!==o.documentType&&(console.warn("Document type does not match the expected document type"),s=false,i.document_type={...i.document_type,eq:{expected:`${e.document_type.eq.expected}`,received:`${o.documentType??d.documentType}`,message:"Document type does not match the expected document type"}}),e.document_type.disclose?.result!==d.documentType&&(console.warn("Document type does not match the disclosed document type in query result"),s=false,i.document_type={...i.document_type,disclose:{expected:`${e.document_type.disclose?.result}`,received:`${d.documentType??o.documentType}`,message:"Document type does not match the disclosed document type in query result"}})),e.birthdate){let a=o.dateOfBirth,m=d.dateOfBirth;e.birthdate.eq&&e.birthdate.eq.result&&!areDatesEqual(e.birthdate.eq.expected,a)&&!areDatesEqual(e.birthdate.eq.expected,m)&&(console.warn("Birthdate does not match the expected birthdate"),s=false,i.birthdate={...i.birthdate,eq:{expected:`${e.birthdate.eq.expected.toISOString()}`,received:`${a?.toISOString()??m?.toISOString()}`,message:"Birthdate does not match the expected birthdate"}}),e.birthdate.disclose&&!areDatesEqual(e.birthdate.disclose.result,a)&&!areDatesEqual(e.birthdate.disclose.result,m)&&(console.warn("Birthdate does not match the disclosed birthdate in query result"),s=false,i.birthdate={...i.birthdate,disclose:{expected:`${e.birthdate.disclose.result.toISOString()}`,received:`${a?.toISOString()??m?.toISOString()}`,message:"Birthdate does not match the disclosed birthdate in query result"}});}if(e.expiry_date){let a=o.dateOfExpiry,m=d.dateOfExpiry;e.expiry_date.eq&&e.expiry_date.eq.result&&!areDatesEqual(e.expiry_date.eq.expected,a)&&!areDatesEqual(e.expiry_date.eq.expected,m)&&(console.warn("Expiry date does not match the expected expiry date"),s=false,i.expiry_date={...i.expiry_date,eq:{expected:`${e.expiry_date.eq.expected.toISOString()}`,received:`${a?.toISOString()??m?.toISOString()}`,message:"Expiry date does not match the expected expiry date"}}),e.expiry_date.disclose&&!areDatesEqual(e.expiry_date.disclose.result,a)&&!areDatesEqual(e.expiry_date.disclose.result,m)&&(console.warn("Expiry date does not match the disclosed expiry date in query result"),s=false,i.expiry_date={...i.expiry_date,disclose:{expected:`${e.expiry_date.disclose.result.toISOString()}`,received:`${a?.toISOString()??m?.toISOString()}`,message:"Expiry date does not match the disclosed expiry date in query result"}});}if(e.nationality){let a=o.nationality,m=d.nationality;e.nationality.eq&&e.nationality.eq.result&&e.nationality.eq.expected!==a&&e.nationality.eq.expected!==m&&(console.warn("Nationality does not match the expected nationality"),s=false,i.nationality={...i.nationality,eq:{expected:`${e.nationality.eq.expected}`,received:`${a??m}`,message:"Nationality does not match the expected nationality"}}),e.nationality.disclose&&e.nationality.disclose.result!==a&&e.nationality.disclose.result!==m&&(console.warn("Nationality does not match the disclosed nationality in query result"),s=false,i.nationality={...i.nationality,disclose:{expected:`${e.nationality.disclose.result}`,received:`${a??m}`,message:"Nationality does not match the disclosed nationality in query result"}});}if(e.document_number){let a=o.documentNumber,m=d.documentNumber;e.document_number.eq&&e.document_number.eq.result&&e.document_number.eq.expected!==a&&e.document_number.eq.expected!==m&&(console.warn("Document number does not match the expected document number"),s=false,i.document_number={...i.document_number,eq:{expected:`${e.document_number.eq.expected}`,received:`${a??m}`,message:"Document number does not match the expected document number"}}),e.document_number.disclose&&e.document_number.disclose.result!==a&&e.document_number.disclose.result!==m&&(console.warn("Document number does not match the disclosed document number in query result"),s=false,i.document_number={...i.document_number,disclose:{expected:`${e.document_number.disclose.result}`,received:`${a??m}`,message:"Document number does not match the disclosed document number in query result"}});}if(e.gender){let a=o.gender,m=d.gender;e.gender.eq&&e.gender.eq.result&&e.gender.eq.expected!==a&&e.gender.eq.expected!==m&&(console.warn("Gender does not match the expected gender"),s=false,i.gender={...i.gender,eq:{expected:`${e.gender.eq.expected}`,received:`${a??m}`,message:"Gender does not match the expected gender"}}),e.gender.disclose&&e.gender.disclose.result!==a&&e.gender.disclose.result!==m&&(console.warn("Gender does not match the disclosed gender in query result"),s=false,i.gender={...i.gender,disclose:{expected:`${e.gender.disclose.result}`,received:`${a??m}`,message:"Gender does not match the disclosed gender in query result"}});}if(e.issuing_country){let a=o.issuingCountry,m=d.issuingCountry;e.issuing_country.eq&&e.issuing_country.eq.result&&e.issuing_country.eq.expected!==a&&e.issuing_country.eq.expected!==m&&(console.warn("Issuing country does not match the expected issuing country"),s=false,i.issuing_country={...i.issuing_country,eq:{expected:`${e.issuing_country.eq.expected}`,received:`${a??m}`,message:"Issuing country does not match the expected issuing country"}}),e.issuing_country.disclose&&e.issuing_country.disclose.result!==a&&e.issuing_country.disclose.result!==m&&(console.warn("Issuing country does not match the disclosed issuing country in query result"),s=false,i.issuing_country={...i.issuing_country,disclose:{expected:`${e.issuing_country.disclose.result}`,received:`${a??m}`,message:"Issuing country does not match the disclosed issuing country in query result"}});}if(e.fullname){let a=o.name,m=d.name;e.fullname.eq&&e.fullname.eq.result&&formatName(e.fullname.eq.expected).toLowerCase()!==a.toLowerCase()&&formatName(e.fullname.eq.expected).toLowerCase()!==m.toLowerCase()&&(console.warn("Fullname does not match the expected fullname"),s=false,i.fullname={...i.fullname,eq:{expected:`${e.fullname.eq.expected}`,received:`${a??m}`,message:"Fullname does not match the expected fullname"}}),e.fullname.disclose&&formatName(e.fullname.disclose.result).toLowerCase()!==a.toLowerCase()&&formatName(e.fullname.disclose.result).toLowerCase()!==m.toLowerCase()&&(console.warn("Fullname does not match the disclosed fullname in query result"),s=false,i.fullname={...i.fullname,disclose:{expected:`${e.fullname.disclose.result}`,received:`${a??m}`,message:"Fullname does not match the disclosed fullname in query result"}});}if(e.firstname){let a=o.firstName&&o.firstName.length>0?o.firstName:o.name,m=d.firstName&&d.firstName.length>0?d.firstName:d.name;e.firstname.eq&&e.firstname.eq.result&&formatName(e.firstname.eq.expected).toLowerCase()!==a.toLowerCase()&&formatName(e.firstname.eq.expected).toLowerCase()!==m.toLowerCase()&&(console.warn("Firstname does not match the expected firstname"),s=false,i.firstname={...i.firstname,eq:{expected:`${e.firstname.eq.expected}`,received:`${a??m}`,message:"Firstname does not match the expected firstname"}}),e.firstname.disclose&&formatName(e.firstname.disclose.result).toLowerCase()!==a.toLowerCase()&&formatName(e.firstname.disclose.result).toLowerCase()!==m.toLowerCase()&&(console.warn("Firstname does not match the disclosed firstname in query result"),s=false,i.firstname={...i.firstname,disclose:{expected:`${e.firstname.disclose.result}`,received:`${a??m}`,message:"Firstname does not match the disclosed firstname in query result"}});}if(e.lastname){let a=o.lastName&&o.lastName.length>0?o.lastName:o.name,m=d.lastName&&d.lastName.length>0?d.lastName:d.name;e.lastname.eq&&e.lastname.eq.result&&formatName(e.lastname.eq.expected).toLowerCase()!==a.toLowerCase()&&formatName(e.lastname.eq.expected).toLowerCase()!==m.toLowerCase()&&(console.warn("Lastname does not match the expected lastname"),s=false,i.lastname={...i.lastname,eq:{expected:`${e.lastname.eq.expected}`,received:`${a??m}`,message:"Lastname does not match the expected lastname"}}),e.lastname.disclose&&formatName(e.lastname.disclose.result).toLowerCase()!==a.toLowerCase()&&formatName(e.lastname.disclose.result).toLowerCase()!==m.toLowerCase()&&(console.warn("Lastname does not match the disclosed lastname in query result"),s=false,i.lastname={...i.lastname,disclose:{expected:`${e.lastname.disclose.result}`,received:`${a??m}`,message:"Lastname does not match the disclosed lastname in query result"}});}return {isCorrect:s,queryResultErrors:i}}static checkAgePublicInputs(t,e){let i={},s=true,c=new Date;new Date(c.getFullYear(),c.getMonth(),c.getDate(),0,0,0,0);let d=getMinAgeFromCommittedInputs(t.committedInputs?.compare_age??t.committedInputs?.compare_age_evm),a=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"),s=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.lt&&e.age.lt.result&&a!==e.age.lt.expected&&(console.warn("Age is not less than the expected age"),s=false,i.age={...i.age,lt:{expected:e.age.lt.expected,received:a,message:"Age is not less than the expected age"}}),e.age.range&&e.age.range.result&&(d!==e.age.range.expected[0]||a!==e.age.range.expected[1])&&(console.warn("Age is not in the expected range"),s=false,i.age={...i.age,range:{expected:e.age.range.expected,received:[d,a],message:"Age is not in the expected range"}}),!e.age.lt&&!e.age.lte&&!e.age.eq&&!e.age.range&&a!=0&&(console.warn("Maximum age should be equal to 0"),s=false,i.age={...i.age,disclose:{expected:0,received:a,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"),s=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!==a)&&(console.warn("Age does not match the disclosed age in query result"),s=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"),s=false,i.age={...i.age,disclose:{message:"Age is not set in the query result"}}),{isCorrect:s,queryResultErrors:i}}static checkBirthdatePublicInputs(t,e){let i={},s=true,c=new Date;new Date(c.getFullYear(),c.getMonth(),c.getDate(),0,0,0);let d=getBirthdateMinDateTimestamp(t.committedInputs?.compare_birthdate??t.committedInputs?.compare_birthdate_evm,-1*SECONDS_BETWEEN_1900_AND_1970),a=getBirthdateMaxDateTimestamp(t.committedInputs?.compare_birthdate??t.committedInputs?.compare_birthdate_evm,-1*SECONDS_BETWEEN_1900_AND_1970);return e.birthdate?(e.birthdate.gte&&e.birthdate.gte.result&&!areDatesEqual(d,e.birthdate.gte.expected)&&(console.warn("Birthdate is not greater than or equal to the expected birthdate"),s=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.lte&&e.birthdate.lte.result&&!areDatesEqual(a,e.birthdate.lte.expected)&&(console.warn("Birthdate is not less than the expected birthdate"),s=false,i.birthdate={...i.birthdate,lte:{expected:e.birthdate.lte.expected,received:a,message:"Birthdate is not less than the expected birthdate"}}),e.birthdate.range&&e.birthdate.range.result&&(!areDatesEqual(d,e.birthdate.range.expected[0])||!areDatesEqual(a,e.birthdate.range.expected[1]))&&(console.warn("Birthdate is not in the expected range"),s=false,i.birthdate={...i.birthdate,range:{expected:e.birthdate.range.expected,received:[d,a],message:"Birthdate is not in the expected range"}}),!e.birthdate.lte&&!e.birthdate.lt&&!e.birthdate.eq&&!e.birthdate.range&&!areDatesEqual(a,Q)&&(console.warn("Maximum birthdate should be equal to default date value"),s=false,i.birthdate={...i.birthdate,disclose:{expected:`${Q.toISOString()}`,received:`${a.toISOString()}`,message:"Maximum birthdate should be equal to default date value"}}),!e.birthdate.gte&&!e.birthdate.gt&&!e.birthdate.eq&&!e.birthdate.range&&!areDatesEqual(d,Q)&&(console.warn("Minimum birthdate should be equal to default date value"),s=false,i.birthdate={...i.birthdate,disclose:{expected:`${Q.toISOString()}`,received:`${d.toISOString()}`,message:"Minimum birthdate should be equal to default date value"}})):(console.warn("Birthdate is not set in the query result"),s=false,i.birthdate={...i.birthdate,disclose:{message:"Birthdate is not set in the query result"}}),{isCorrect:s,queryResultErrors:i}}static checkExpiryDatePublicInputs(t,e){let i={},s=true,c=new Date;new Date(c.getFullYear(),c.getMonth(),c.getDate(),0,0,0);let d=getMinDateFromCommittedInputs(t.committedInputs?.compare_expiry??t.committedInputs?.compare_expiry_evm),a=getMaxDateFromCommittedInputs(t.committedInputs?.compare_expiry??t.committedInputs?.compare_expiry_evm);return e.expiry_date?(e.expiry_date.gte&&e.expiry_date.gte.result&&!areDatesEqual(d,e.expiry_date.gte.expected)&&(console.warn("Expiry date is not greater than or equal to the expected expiry date"),s=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&&!areDatesEqual(a,e.expiry_date.lte.expected)&&(console.warn("Expiry date is not less than the expected expiry date"),s=false,i.expiry_date={...i.expiry_date,lte:{expected:e.expiry_date.lte.expected,received:a,message:"Expiry date is not less than the expected expiry date"}}),e.expiry_date.range&&e.expiry_date.range.result&&(!areDatesEqual(d,e.expiry_date.range.expected[0])||!areDatesEqual(a,e.expiry_date.range.expected[1]))&&(console.warn("Expiry date is not in the expected range"),s=false,i.expiry_date={...i.expiry_date,range:{expected:e.expiry_date.range.expected,received:[d,a],message:"Expiry date is not in the expected range"}}),!e.expiry_date.lte&&!e.expiry_date.lt&&!e.expiry_date.eq&&!e.expiry_date.range&&!areDatesEqual(a,Q)&&(console.warn("Maximum expiry date should be equal to default date value"),s=false,i.expiry_date={...i.expiry_date,disclose:{expected:`${Q.toISOString()}`,received:`${a.toISOString()}`,message:"Maximum expiry date should be equal to default date value"}}),!e.expiry_date.gte&&!e.expiry_date.gt&&!e.expiry_date.eq&&!e.expiry_date.range&&!areDatesEqual(d,Q)&&(console.warn("Minimum expiry date should be equal to default date value"),s=false,i.expiry_date={...i.expiry_date,disclose:{expected:`${Q.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"),s=false,i.expiry_date={...i.expiry_date,disclose:{message:"Expiry date is not set in the query result"}}),{isCorrect:s,queryResultErrors:i}}static checkNationalityExclusionPublicInputs(t,e){let i={},s=true;t.nationality&&t.nationality.out&&t.nationality.out.result?t.nationality.out.expected?.every(c=>e.includes(c))||(console.warn("Nationality exclusion list does not match the one from the query results"),s=false,i.nationality={...i.nationality,out:{expected:t.nationality.out.expected,received:e,message:"Nationality exclusion list does not match the one from the query results"}}):(!t.nationality||!t.nationality.out)&&(console.warn("Nationality exclusion is not set in the query result"),s=false,i.nationality={...i.nationality,out:{message:"Nationality exclusion is not set in the query result"}});for(let c=1;c<e.length;c++)e[c]<e[c-1]&&(console.warn("The nationality exclusion list has not been sorted, and thus the proof cannot be trusted"),s=false,i.nationality={...i.nationality,out:{message:"The nationality exclusion list has not been sorted, and thus the proof cannot be trusted"}});return {isCorrect:s,queryResultErrors:i}}static checkIssuingCountryExclusionPublicInputs(t,e){let i={},s=true;t.issuing_country&&t.issuing_country.out&&t.issuing_country.out.result?t.issuing_country.out.expected?.every(c=>e.includes(c))||(console.warn("Issuing country exclusion list does not match the one from the query results"),s=false,i.issuing_country={...i.issuing_country,out:{expected:t.issuing_country.out.expected,received:e,message:"Issuing country exclusion list does not match the one from the query results"}}):(!t.issuing_country||!t.issuing_country.out)&&(console.warn("Issuing country exclusion is not set in the query result"),s=false,i.issuing_country={...i.issuing_country,out:{message:"Issuing country exclusion is not set in the query result"}});for(let c=1;c<e.length;c++)e[c]<e[c-1]&&(console.warn("The issuing country exclusion list has not been sorted, and thus the proof cannot be trusted"),s=false,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 {isCorrect:s,queryResultErrors:i}}static checkNationalityInclusionPublicInputs(t,e){let i={},s=true;return t.nationality&&t.nationality.in&&t.nationality.in.result?t.nationality.in.expected?.every(c=>e.includes(c))||(console.warn("Nationality inclusion list does not match the one from the query results"),s=false,i.nationality={...i.nationality,in:{expected:t.nationality.in.expected,received:e,message:"Nationality inclusion list does not match the one from the query results"}}):(!t.nationality||!t.nationality.in)&&(console.warn("Nationality inclusion is not set in the query result"),s=false,i.nationality={...i.nationality,in:{message:"Nationality inclusion is not set in the query result"}}),{isCorrect:s,queryResultErrors:i}}static checkIssuingCountryInclusionPublicInputs(t,e){let i={},s=true;return t.issuing_country&&t.issuing_country.in&&t.issuing_country.in.result?t.issuing_country.in.expected?.every(c=>e.includes(c))||(console.warn("Issuing country inclusion list does not match the one from the query results"),s=false,i.issuing_country={...i.issuing_country,in:{expected:t.issuing_country.in.expected,received:e,message:"Issuing country inclusion list does not match the one from the query results"}}):(!t.issuing_country||!t.issuing_country.in)&&(console.warn("Issuing country inclusion is not set in the query result"),s=false,i.issuing_country={...i.issuing_country,in:{message:"Issuing country inclusion is not set in the query result"}}),{isCorrect:s,queryResultErrors:i}}static checkScopeFromDisclosureProof(t,e,i,s,c){let o=true;return t&&getServiceScopeHash(t)!==getServiceScopeFromDisclosureProof(e)&&(console.warn("The proof comes from a different domain than the one expected"),o=false,i[s]||(i[s]={}),i[s].scope={expected:`Scope: ${getServiceScopeHash(t).toString()}`,received:`Scope: ${BigInt(e.publicInputs[1]).toString()}`,message:"The proof comes from a different domain than the one expected"}),c&&getScopeHash(c)!==getServiceSubScopeFromDisclosureProof(e)&&(console.warn("The proof uses a different scope than the one expected"),o=false,i[s]||(i[s]={}),i[s].scope={expected:`Scope: ${getScopeHash(c).toString()}`,received:`Scope: ${BigInt(e.publicInputs[2]).toString()}`,message:"The proof uses a different scope than the one expected"}),{isCorrect:o,queryResultErrors:i}}static async checkCertificateRegistryRoot(t,e,i){let s=true;try{await new RegistryClient({chainId:11155111}).isCertificateRootValid(t)||(console.warn("The ID was signed by an unrecognized root certificate"),s=!1,e[i?"outer":"sig_check_dsc"]||(e[i?"outer":"sig_check_dsc"]={}),e[i?"outer":"sig_check_dsc"].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"});}catch(c){console.warn(c),console.warn("The ID was signed by an unrecognized root certificate"),s=false,e[i?"outer":"sig_check_dsc"]||(e[i?"outer":"sig_check_dsc"]={}),e[i?"outer":"sig_check_dsc"].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"};}return {isCorrect:s,queryResultErrors:e}}static async checkCircuitRegistryRoot(t,e){let i=true;try{await new RegistryClient({chainId:11155111}).isCircuitRootValid(t)||(console.warn("The proof uses unrecognized circuits"),i=!1,e.outer.circuit={expected:"A valid circuit from ZKPassport Registry",received:`Got invalid circuit registry root: ${t}`,message:"The proof uses an unrecognized circuit"});}catch(s){console.warn(s),console.warn("The proof uses unrecognized circuits"),i=false,e.outer.circuit={expected:"A valid circuit from ZKPassport Registry",received:`Got invalid circuit registry root: ${t}`,message:"The proof uses an unrecognized circuit"};}return {isCorrect:i,queryResultErrors:e}}static checkBindPublicInputs(t,e){let i={},s=true;return t.bind&&(t.bind.user_address?.toLowerCase().replace("0x","")!==e.user_address?.toLowerCase().replace("0x","")&&(console.warn("Bound user address does not match the one from the query results"),s=false,i.bind={...i.bind,eq:{expected:t.bind.user_address,received:e.user_address,message:"Bound user address does not match the one from the query results"}}),t.bind.chain!==e.chain&&(console.warn("Bound chain id does not match the one from the query results"),s=false,i.bind={...i.bind,eq:{expected:t.bind.chain,received:e.chain,message:"Bound chain id does not match the one from the query results"}}),t.bind.custom_data?.trim().toLowerCase()!==e.custom_data?.trim().toLowerCase()&&(console.warn("Bound custom data does not match the one from the query results"),s=false,i.bind={...i.bind,eq:{expected:t.bind.custom_data,received:e.custom_data,message:"Bound custom data does not match the one from the query results"}})),{isCorrect:s,queryResultErrors:i}}static async checkSanctionsExclusionPublicInputs(t,e,i){let s={},c=true;if(t.sanctions&&t.sanctions.passed){let o=await i.getRoot();e.rootHash!==o&&(console.warn("Invalid sanctions registry root"),c=false,s.sanctions={...s.sanctions,eq:{expected:o,received:e.rootHash,message:"Invalid sanctions registry root"}}),t.sanctions.isStrict!==e.isStrict&&(console.warn("Invalid sanctions strict mode"),c=false,s.sanctions={...s.sanctions,eq:{expected:t.sanctions.isStrict.toString(),received:e.isStrict.toString(),message:"Invalid sanctions strict mode"}});}return {isCorrect:c,queryResultErrors:s}}static async checkFacematchPublicInputs(t,e){let i=true,s={};if(t.facematch&&t.facematch.passed){e.rootKeyLeaf!==re&&e.rootKeyLeaf!==oe&&(console.warn("Invalid facematch root key hash"),i=false,s.facematch={...s.facematch,eq:{expected:`${re} (iOS) or ${oe} (Android)`,received:e.rootKeyLeaf,message:"Invalid facematch root key hash"}});let c="production";e.environment!==c&&(console.warn("Invalid facematch environment, it should be production"),i=false,s.facematch={...s.facematch,eq:{expected:c,received:e.environment,message:"Invalid facematch environment, it should be production"}}),e.appIdHash!==ne&&e.appIdHash!==se&&(console.warn("Invalid facematch app id hash, the attestation should be coming from the ZKPassport app"),i=false,s.facematch={...s.facematch,eq:{expected:`${ne} (iOS) or ${se} (Android)`,received:e.appIdHash,message:"Invalid facematch app id hash, the attestation should be coming from the ZKPassport app"}});}return {isCorrect:i,queryResultErrors:s}}static async checkCurrentDate(t,e,i,s){let c=new Date,o=new Date(c.getFullYear(),c.getMonth(),c.getDate(),0,0,0,0),d=getCurrentDateFromDisclosureProof(e),a=o.getTime()-d.getTime(),m=i?i*1e3:604800*1e3,x=o.getTime()-(o.getTime()-m),$=true;return a>=x&&(console.warn("The date used to check the validity of the ID falls out of the validity period"),$=false,s[t]||(s[t]={}),s[t].date={expected:`Difference: ${i} seconds`,received:`Difference: ${Math.round(a/1e3)} seconds`,message:"The date used to check the validity of the ID falls out of the validity period"}),{isCorrect:$,queryResultErrors:s}}static async checkPublicInputs(t,e,i,s,c){let o,d,a=true,m,x,$=new Date,D=new Date($.getFullYear(),$.getMonth(),$.getDate(),0,0,0,0),n={},w=e.sort((h,r)=>{let l=["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"],f=u=>{let p=u.name||"";return l.findIndex(y=>p.startsWith(y))};return f(h)-f(r)});for(let h of w){let r=getProofData(h.proof,getNumberOfPublicInputs(h.name));if(h.name?.startsWith("outer")){let l=h.name?.startsWith("outer_evm"),f=getCertificateRegistryRootFromOuterProof(r),{isCorrect:u,queryResultErrors:p}=await this.checkCertificateRegistryRoot(f.toString(16),n,true);a=a&&u,n={...n,...p};let y=getCircuitRegistryRootFromOuterProof(r),{isCorrect:T,queryResultErrors:C}=await this.checkCircuitRegistryRoot(y.toString(16),n);a=a&&T,n={...n,...C};let S=getCurrentDateFromOuterProof(r),k=D.getTime()-S.getTime(),Y=s?s*1e3:604800*1e3,ae=D.getTime()-(D.getTime()-Y);k>=ae&&(console.warn("The date used to check the validity of the ID is older than the validity period"),a=false,n.outer={...n.outer,date:{expected:`Difference: ${s} seconds`,received:`Difference: ${Math.round(k/1e3)} seconds`,message:"The date used to check the validity of the ID is older than the validity period"}});let _=getParamCommitmentsFromOuterProof(r),g=h.committedInputs,j=Object.keys(g||{});if(j.length!==_.length&&(console.warn("The proof does not verify all the requested conditions and information"),a=false,n.outer={...n.outer,commitment:{expected:`Number of parameter commitments: ${_.length}`,received:`Number of disclosure proofs provided: ${j.length}`,message:"The proof does not verify all the requested conditions and information"}}),t&&getServiceScopeHash(t)!==getScopeFromOuterProof(r)&&(console.warn("The proof comes from a different domain than the one expected"),a=false,n.outer={...n.outer,scope:{expected:`Scope: ${getServiceScopeHash(t).toString()}`,received:`Scope: ${getScopeFromOuterProof(r).toString()}`,message:"The proof comes from a different domain than the one expected"}}),c&&getScopeHash(c)!==getSubscopeFromOuterProof(r)&&(console.warn("The proof uses a different scope than the one expected"),a=false,n.outer={...n.outer,scope:{expected:`Scope: ${getScopeHash(c).toString()}`,received:`Scope: ${getSubscopeFromOuterProof(r).toString()}`,message:"The proof uses a different scope than the one expected"}}),g?.compare_age||g?.compare_age_evm){let b=g?.compare_age??g?.compare_age_evm,v=l?await getAgeEVMParameterCommitment(b.minAge,b.maxAge):await getAgeParameterCommitment(b.minAge,b.maxAge);_.includes(v)||(console.warn("This proof does not verify the age"),a=false,n.age={...n.age,commitment:{expected:`Age parameter commitment: ${v.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the age"}});let{isCorrect:I,queryResultErrors:P}=this.checkAgePublicInputs(h,i);a=a&&I,n={...n,...P};}if(g?.compare_birthdate||g?.compare_birthdate_evm){let b=g?.compare_birthdate??g?.compare_birthdate_evm,v=l?await getDateEVMParameterCommitment(ProofType.BIRTHDATE,b.minDateTimestamp,b.maxDateTimestamp):await getDateParameterCommitment(ProofType.BIRTHDATE,b.minDateTimestamp,b.maxDateTimestamp);_.includes(v)||(console.warn("This proof does not verify the birthdate"),a=false,n.birthdate={...n.birthdate,commitment:{expected:`Birthdate parameter commitment: ${v.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the birthdate"}});let{isCorrect:I,queryResultErrors:P}=this.checkBirthdatePublicInputs(h,i);a=a&&I,n={...n,...P};}if(g?.compare_expiry||g?.compare_expiry_evm){let b=g?.compare_expiry??g?.compare_expiry_evm,v=l?await getDateEVMParameterCommitment(ProofType.EXPIRY_DATE,b.minDateTimestamp,b.maxDateTimestamp):await getDateParameterCommitment(ProofType.EXPIRY_DATE,b.minDateTimestamp,b.maxDateTimestamp);_.includes(v)||(console.warn("This proof does not verify the expiry date"),a=false,n.expiry_date={...n.expiry_date,commitment:{expected:`Expiry date parameter commitment: ${v.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the expiry date"}});let{isCorrect:I,queryResultErrors:P}=this.checkExpiryDatePublicInputs(h,i);a=a&&I,n={...n,...P};}if(g?.disclose_bytes||g?.disclose_bytes_evm){let b=g?.disclose_bytes??g?.disclose_bytes_evm,v=l?await getDiscloseEVMParameterCommitment(b.discloseMask,b.disclosedBytes):await getDiscloseParameterCommitment(b.discloseMask,b.disclosedBytes);_.includes(v)||(console.warn("This proof does not verify any of the data disclosed"),a=false,n.disclose={...n.disclose,commitment:{expected:`Disclosure parameter commitment: ${v.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify any of the data disclosed"}});let{isCorrect:I,queryResultErrors:P}=this.checkDiscloseBytesPublicInputs(h,i);a=a&&I,n={...n,...P};}if(g?.inclusion_check_nationality||g?.inclusion_check_nationality_evm){let b=g?.inclusion_check_nationality??g?.inclusion_check_nationality_evm,v=l?await getCountryEVMParameterCommitment(ProofType.NATIONALITY_INCLUSION,b.countries):await getCountryParameterCommitment(ProofType.NATIONALITY_INCLUSION,b.countries);_.includes(v)||(console.warn("This proof does not verify the inclusion of the nationality"),a=false,n.nationality={...n.nationality,commitment:{expected:`Nationality parameter commitment: ${v.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the inclusion of the nationality"}});let I=b.countries,{isCorrect:P,queryResultErrors:L}=this.checkNationalityInclusionPublicInputs(i,I);a=a&&P,n={...n,...L};}if(g?.inclusion_check_issuing_country||g?.inclusion_check_issuing_country_evm){let b=g?.inclusion_check_issuing_country??g?.inclusion_check_issuing_country_evm,v=l?await getCountryEVMParameterCommitment(ProofType.ISSUING_COUNTRY_INCLUSION,b.countries):await getCountryParameterCommitment(ProofType.ISSUING_COUNTRY_INCLUSION,b.countries);_.includes(v)||(console.warn("This proof does not verify the inclusion of the issuing country"),a=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Issuing country parameter commitment: ${v.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the inclusion of the issuing country"}});let I=b.countries,{isCorrect:P,queryResultErrors:L}=this.checkIssuingCountryInclusionPublicInputs(i,I);a=a&&P,n={...n,...L};}if(g?.exclusion_check_nationality||g?.exclusion_check_nationality_evm){let b=g?.exclusion_check_nationality??g?.exclusion_check_nationality_evm,v=l?await getCountryEVMParameterCommitment(ProofType.NATIONALITY_EXCLUSION,b.countries):await getCountryParameterCommitment(ProofType.NATIONALITY_EXCLUSION,b.countries);_.includes(v)||(console.warn("This proof does not verify the exclusion of the nationality"),a=false,n.nationality={...n.nationality,commitment:{expected:`Nationality parameter commitment: ${v.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the exclusion of the nationality"}});let I=b.countries,{isCorrect:P,queryResultErrors:L}=this.checkNationalityExclusionPublicInputs(i,I);a=a&&P,n={...n,...L};}if(g?.exclusion_check_issuing_country||g?.exclusion_check_issuing_country_evm){let b=g?.exclusion_check_issuing_country??g?.exclusion_check_issuing_country_evm,v=l?await getCountryEVMParameterCommitment(ProofType.ISSUING_COUNTRY_EXCLUSION,b.countries):await getCountryParameterCommitment(ProofType.ISSUING_COUNTRY_EXCLUSION,b.countries);_.includes(v)||(console.warn("This proof does not verify the exclusion of the issuing country"),a=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Issuing country parameter commitment: ${v.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the exclusion of the issuing country"}});let I=b.countries,{isCorrect:P,queryResultErrors:L}=this.checkIssuingCountryExclusionPublicInputs(i,I);a=a&&P,n={...n,...L};}if(g?.bind||g?.bind_evm){let b=g?.bind??g?.bind_evm,v=l?await getBindEVMParameterCommitment(formatBoundData(b.data)):await getBindParameterCommitment(formatBoundData(b.data));_.includes(v)||(console.warn("This proof does not verify the bound data"),a=false,n.bind={...n.bind,commitment:{expected:`Bind parameter commitment: ${v.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the bound data"}});let{isCorrect:I,queryResultErrors:P}=this.checkBindPublicInputs(i,b.data);a=a&&I,n={...n,...P};}if(g?.exclusion_check_sanctions||g?.exclusion_check_sanctions_evm){let b=await SanctionsBuilder.create(),v=g?.exclusion_check_sanctions??g?.exclusion_check_sanctions_evm,I=l?await b.getSanctionsEvmParameterCommitment(v.isStrict):await b.getSanctionsParameterCommitment(v.isStrict);_.includes(I)||(console.warn("This proof does not verify the exclusion from the sanction lists"),a=false,n.sanctions={...n.sanctions,commitment:{expected:`Sanctions parameter commitment: ${I.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify the exclusion from the sanction lists"}});let{isCorrect:P,queryResultErrors:L}=await this.checkSanctionsExclusionPublicInputs(i,v,b);a=a&&P,n={...n,...L};}if(g?.facematch||g?.facematch_evm){let b=g?.facematch??g?.facematch_evm,v=l?await getFacematchEvmParameterCommitment(BigInt(b.rootKeyLeaf),b.environment==="development"?0n:1n,BigInt(b.appIdHash),b.mode==="regular"?1n:2n):await getFacematchParameterCommitment(BigInt(b.rootKeyLeaf),b.environment==="development"?0n:1n,BigInt(b.appIdHash),b.mode==="regular"?1n:2n);_.includes(v)||(console.warn("This proof does not verify FaceMatch"),a=false,n.facematch={...n.facematch,commitment:{expected:`Facematch parameter commitment: ${v.toString()}`,received:`Parameter commitments included: ${_.join(", ")}`,message:"This proof does not verify FaceMatch"}});let{isCorrect:I,queryResultErrors:P}=await this.checkFacematchPublicInputs(i,b);a=a&&I,n={...n,...P};}m=getNullifierFromOuterProof(r).toString(10),x=getNullifierTypeFromOuterProof(r);}else if(h.name?.startsWith("sig_check_dsc")){d=getCommitmentFromDSCProof(r);let l=getMerkleRootFromDSCProof(r),{isCorrect:f,queryResultErrors:u}=await this.checkCertificateRegistryRoot(l.toString(16),n,false);a=a&&f,n={...n,...u};}else if(h.name?.startsWith("sig_check_id_data"))o=getCommitmentInFromIDDataProof(r),o!==d&&(console.warn("Failed to check the link between the certificate signature and ID signature"),a=false,n.sig_check_id_data={...n.sig_check_id_data,commitment:{expected:`Commitment: ${d?.toString()||"undefined"}`,received:`Commitment: ${o?.toString()||"undefined"}`,message:"Failed to check the link between the certificate signature and ID signature"}}),d=getCommitmentOutFromIDDataProof(r);else if(h.name?.startsWith("data_check_integrity"))o=getCommitmentInFromIntegrityProof(r),o!==d&&(console.warn("Failed to check the link between the ID signature and the data signed"),a=false,n.data_check_integrity={...n.data_check_integrity,commitment:{expected:`Commitment: ${d?.toString()||"undefined"}`,received:`Commitment: ${o?.toString()||"undefined"}`,message:"Failed to check the link between the ID signature and the data signed"}}),d=getCommitmentOutFromIntegrityProof(r);else if(h.name==="disclose_bytes"){o=getCommitmentInFromDisclosureProof(r),o!==d&&(console.warn("Failed to check the link between the validity of the ID and the data to disclose"),a=false,n.disclose={...n.disclose,commitment:{expected:`Commitment: ${d?.toString()||"undefined"}`,received:`Commitment: ${o?.toString()||"undefined"}`,message:"Failed to check the link between the validity of the ID and the data to disclose"}});let l=getParameterCommitmentFromDisclosureProof(r),f=await getDiscloseParameterCommitment((h.committedInputs?.disclose_bytes).discloseMask,(h.committedInputs?.disclose_bytes).disclosedBytes);l!==f&&(console.warn("The disclosed data does not match the data committed by the proof"),a=false,n.disclose={...n.disclose,commitment:{expected:`Commitment: ${f}`,received:`Commitment: ${l}`,message:"The disclosed data does not match the data committed by the proof"}});let{isCorrect:u,queryResultErrors:p}=this.checkScopeFromDisclosureProof(t,r,n,"disclose",c);a=a&&u,n={...n,...p};let{isCorrect:y,queryResultErrors:T}=this.checkDiscloseBytesPublicInputs(h,i);a=a&&y&&u,n={...n,...T,...p};let{isCorrect:C,queryResultErrors:S}=await this.checkCurrentDate("disclose",r,s??604800,n);a=a&&C,n={...n,...S},m=getNullifierFromDisclosureProof(r).toString(10),x=getNullifierTypeFromDisclosureProof(r);}else if(h.name==="compare_age"){o=getCommitmentInFromDisclosureProof(r),o!==d&&(console.warn("Failed to check the link between the validity of the ID and the age derived from it"),a=false,n.age={...n.age,commitment:{expected:`Commitment: ${d}`,received:`Commitment: ${o}`,message:"Failed to check the link between the validity of the ID and the age derived from it"}});let l=getParameterCommitmentFromDisclosureProof(r),f=h.committedInputs?.compare_age,u=await getAgeParameterCommitment(f.minAge,f.maxAge);l!==u&&(console.warn("The conditions for the age check do not match the conditions checked by the proof"),a=false,n.age={...n.age,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${l}`,message:"The conditions for the age check do not match the conditions checked by the proof"}});let{isCorrect:p,queryResultErrors:y}=this.checkScopeFromDisclosureProof(t,r,n,"age",c),{isCorrect:T,queryResultErrors:C}=this.checkAgePublicInputs(h,i);a=a&&T&&p,n={...n,...C,...y};let{isCorrect:S,queryResultErrors:k}=await this.checkCurrentDate("age",r,s??604800,n);a=a&&S,n={...n,...k},m=getNullifierFromDisclosureProof(r).toString(10),x=getNullifierTypeFromDisclosureProof(r);}else if(h.name==="compare_birthdate"){o=getCommitmentInFromDisclosureProof(r),o!==d&&(console.warn("Failed to check the link between the validity of the ID and the birthdate derived from it"),a=false,n.birthdate={...n.birthdate,commitment:{expected:`Commitment: ${d}`,received:`Commitment: ${o}`,message:"Failed to check the link between the validity of the ID and the birthdate derived from it"}});let l=getParameterCommitmentFromDisclosureProof(r),f=h.committedInputs?.compare_birthdate,u=await getDateParameterCommitment(ProofType.BIRTHDATE,f.minDateTimestamp,f.maxDateTimestamp,0);l!==u&&(console.warn("The conditions for the birthdate check do not match the conditions checked by the proof"),a=false,n.birthdate={...n.birthdate,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${l}`,message:"The conditions for the birthdate check do not match the conditions checked by the proof"}});let{isCorrect:p,queryResultErrors:y}=this.checkScopeFromDisclosureProof(t,r,n,"birthdate",c),{isCorrect:T,queryResultErrors:C}=this.checkBirthdatePublicInputs(h,i);a=a&&T&&p,n={...n,...C,...y};let{isCorrect:S,queryResultErrors:k}=await this.checkCurrentDate("birthdate",r,s??604800,n);a=a&&S,n={...n,...k},m=getNullifierFromDisclosureProof(r).toString(10),x=getNullifierTypeFromDisclosureProof(r);}else if(h.name==="compare_expiry"){o=getCommitmentInFromDisclosureProof(r),o!==d&&(console.warn("Failed to check the link between the validity of the ID and its expiry date"),a=false,n.expiry_date={...n.expiry_date,commitment:{expected:`Commitment: ${d}`,received:`Commitment: ${o}`,message:"Failed to check the link between the validity of the ID and its expiry date"}});let l=getParameterCommitmentFromDisclosureProof(r),f=h.committedInputs?.compare_expiry,u=await getDateParameterCommitment(ProofType.EXPIRY_DATE,f.minDateTimestamp,f.maxDateTimestamp);l!==u&&(console.warn("The conditions for the expiry date check do not match the conditions checked by the proof"),a=false,n.expiry_date={...n.expiry_date,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${l}`,message:"The conditions for the expiry date check do not match the conditions checked by the proof"}});let{isCorrect:p,queryResultErrors:y}=this.checkScopeFromDisclosureProof(t,r,n,"expiry_date",c),{isCorrect:T,queryResultErrors:C}=this.checkExpiryDatePublicInputs(h,i);a=a&&T&&p,n={...n,...C,...y};let{isCorrect:S,queryResultErrors:k}=await this.checkCurrentDate("expiry_date",r,s??604800,n);a=a&&S,n={...n,...k},m=getNullifierFromDisclosureProof(r).toString(10),x=getNullifierTypeFromDisclosureProof(r);}else if(h.name==="exclusion_check_nationality"){o=getCommitmentInFromDisclosureProof(r),o!==d&&(console.warn("Failed to check the link between the validity of the ID and the nationality exclusion check"),a=false,n.nationality={...n.nationality,commitment:{expected:`Commitment: ${d}`,received:`Commitment: ${o}`,message:"Failed to check the link between the validity of the ID and the nationality exclusion check"}});let l=(h.committedInputs?.exclusion_check_nationality).countries,f=getParameterCommitmentFromDisclosureProof(r),u=await getCountryParameterCommitment(ProofType.NATIONALITY_EXCLUSION,l,true);f!==u&&(console.warn("The committed country list for the exclusion check does not match the one from the proof"),a=false,n.nationality={...n.nationality,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${f}`,message:"The committed country list for the exclusion check does not match the one from the proof"}});let{isCorrect:p,queryResultErrors:y}=this.checkScopeFromDisclosureProof(t,r,n,"nationality",c),{isCorrect:T,queryResultErrors:C}=this.checkNationalityExclusionPublicInputs(i,l);a=a&&T&&p,n={...n,...C,...y};let{isCorrect:S,queryResultErrors:k}=await this.checkCurrentDate("nationality",r,s??604800,n);a=a&&S,n={...n,...k},m=getNullifierFromDisclosureProof(r).toString(10),x=getNullifierTypeFromDisclosureProof(r);}else if(h.name==="exclusion_check_issuing_country"){o=getCommitmentInFromDisclosureProof(r),o!==d&&(console.warn("Failed to check the link between the validity of the ID and the issuing country exclusion check"),a=false,n.nationality={...n.nationality,commitment:{expected:`Commitment: ${d}`,received:`Commitment: ${o}`,message:"Failed to check the link between the validity of the ID and the issuing country exclusion check"}});let l=(h.committedInputs?.exclusion_check_issuing_country).countries,f=getParameterCommitmentFromDisclosureProof(r),u=await getCountryParameterCommitment(ProofType.ISSUING_COUNTRY_EXCLUSION,l,true);f!==u&&(console.warn("The committed country list for the issuing country exclusion check does not match the one from the proof"),a=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${f}`,message:"The committed country list for the issuing country exclusion check does not match the one from the proof"}});let{isCorrect:p,queryResultErrors:y}=this.checkScopeFromDisclosureProof(t,r,n,"nationality",c),{isCorrect:T,queryResultErrors:C}=this.checkIssuingCountryExclusionPublicInputs(i,l);a=a&&T&&p,n={...n,...C,...y};let{isCorrect:S,queryResultErrors:k}=await this.checkCurrentDate("issuing_country",r,s??604800,n);a=a&&S,n={...n,...k},m=getNullifierFromDisclosureProof(r).toString(10),x=getNullifierTypeFromDisclosureProof(r);}else if(h.name==="inclusion_check_nationality"){o=getCommitmentInFromDisclosureProof(r),o!==d&&(console.warn("Failed to check the link between the validity of the ID and the nationality inclusion check"),a=false,n.nationality={...n.nationality,commitment:{expected:`Commitment: ${d}`,received:`Commitment: ${o}`,message:"Failed to check the link between the validity of the ID and the nationality inclusion check"}});let l=(h.committedInputs?.inclusion_check_nationality).countries,f=getParameterCommitmentFromDisclosureProof(r),u=await getCountryParameterCommitment(ProofType.NATIONALITY_INCLUSION,l,false);f!==u&&(console.warn("The committed country list for the nationality inclusion check does not match the one from the proof"),a=false,n.nationality={...n.nationality,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${f}`,message:"The committed country list for the nationality inclusion check does not match the one from the proof"}});let{isCorrect:p,queryResultErrors:y}=this.checkScopeFromDisclosureProof(t,r,n,"nationality",c),{isCorrect:T,queryResultErrors:C}=this.checkNationalityInclusionPublicInputs(i,l);a=a&&T&&p,n={...n,...C,...y};let{isCorrect:S,queryResultErrors:k}=await this.checkCurrentDate("nationality",r,s??604800,n);a=a&&S,n={...n,...k},m=getNullifierFromDisclosureProof(r).toString(10),x=getNullifierTypeFromDisclosureProof(r);}else if(h.name==="inclusion_check_issuing_country"){o=getCommitmentInFromDisclosureProof(r),o!==d&&(console.warn("Failed to check the link between the validity of the ID and the issuing country inclusion check"),a=false,n.nationality={...n.nationality,commitment:{expected:`Commitment: ${d}`,received:`Commitment: ${o}`,message:"Failed to check the link between the validity of the ID and the issuing country inclusion check"}});let l=(h.committedInputs?.inclusion_check_issuing_country).countries,f=getParameterCommitmentFromDisclosureProof(r),u=await getCountryParameterCommitment(ProofType.ISSUING_COUNTRY_INCLUSION,l,false);f!==u&&(console.warn("The committed country list for the issuing country inclusion check does not match the one from the proof"),a=false,n.issuing_country={...n.issuing_country,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${f}`,message:"The committed country list for the issuing country inclusion check does not match the one from the proof"}});let{isCorrect:p,queryResultErrors:y}=this.checkScopeFromDisclosureProof(t,r,n,"nationality",c),{isCorrect:T,queryResultErrors:C}=this.checkIssuingCountryInclusionPublicInputs(i,l);a=a&&T&&p,n={...n,...C,...y};let{isCorrect:S,queryResultErrors:k}=await this.checkCurrentDate("issuing_country",r,s??604800,n);a=a&&S,n={...n,...k},m=getNullifierFromDisclosureProof(r).toString(10),x=getNullifierTypeFromDisclosureProof(r);}else if(h.name==="bind"){let l=h.committedInputs?.bind,f=getParameterCommitmentFromDisclosureProof(r),u=await getBindParameterCommitment(formatBoundData(l.data));f!==u&&(console.warn("The bound data does not match the one from the proof"),a=false,n.bind={...n.bind,commitment:{expected:`Commitment: ${u}`,received:`Commitment: ${f}`,message:"The bound data does not match the one from the proof"}});let{isCorrect:p,queryResultErrors:y}=this.checkBindPublicInputs(i,l.data);a=a&&p,n={...n,...y};let{isCorrect:T,queryResultErrors:C}=await this.checkCurrentDate("bind",r,s??604800,n);a=a&&T,n={...n,...C},m=getNullifierFromDisclosureProof(r).toString(10),x=getNullifierTypeFromDisclosureProof(r);}else if(h.name==="exclusion_check_sanctions"){let l=await SanctionsBuilder.create(),f=h.committedInputs?.exclusion_check_sanctions,u=await l.getSanctionsParameterCommitment(f.isStrict),p=getParameterCommitmentFromDisclosureProof(r);p!==u&&(console.warn("The sanction lists check against do not match the sanction lists from the proof"),a=false,n.sanctions={...n.sanctions,commitment:{expected:`Commitment: ${u.toString()}`,received:`Commitment: ${p.toString()}`,message:"The sanction lists check against do not match the sanction lists from the proof"}});let{isCorrect:y,queryResultErrors:T}=await this.checkSanctionsExclusionPublicInputs(i,f,l);a=a&&y,n={...n,...T};let{isCorrect:C,queryResultErrors:S}=await this.checkCurrentDate("sanctions",r,s??604800,n);a=a&&C,n={...n,...S},m=getNullifierFromDisclosureProof(r).toString(10),x=getNullifierTypeFromDisclosureProof(r);}else if(h.name?.startsWith("facematch")&&!h.name?.endsWith("_evm")){let l=h.committedInputs?.facematch,f=getParameterCommitmentFromDisclosureProof(r),u=await getFacematchParameterCommitment(BigInt(l.rootKeyLeaf),l.environment==="development"?0n:1n,BigInt(l.appIdHash),l.mode==="regular"?1n:2n);f!==u&&(console.warn("The FaceMatch verification does not match the ones from the proof"),a=false,n.facematch={...n.facematch,commitment:{expected:`Commitment: ${u.toString()}`,received:`Commitment: ${f.toString()}`,message:"The FaceMatch verification does not match the ones from the proof"}});let{isCorrect:p,queryResultErrors:y}=await this.checkFacematchPublicInputs(i,l);a=a&&p,n={...n,...y};let{isCorrect:T,queryResultErrors:C}=await this.checkCurrentDate("facematch",r,s??604800,n);a=a&&T,n={...n,...C},m=getNullifierFromDisclosureProof(r).toString(10),x=getNullifierTypeFromDisclosureProof(r);}}return {isCorrect:a,uniqueIdentifier:m,uniqueIdentifierType:x,queryResultErrors:n}}};var _e={abi:[{type:"constructor",inputs:[{name:"_admin",type:"address",internalType:"address"},{name:"_guardian",type:"address",internalType:"address"},{name:"_rootRegistry",type:"address",internalType:"contract IRootRegistry"}],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 ZKPassportSubVerifier"}],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:"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 ZKPassportHelper"}],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 IRootRegistry"}],stateMutability:"view"},{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 ZKPassportSubVerifier"}],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 ZKPassportHelper"}],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:"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 q=class{static getDetails(){return {...{functionName:"verify",abi:_e.abi},address:"0x1D000001000EFD9a6371f4d90bB8920D5431c0D8"}}static getParameters({proof:t,validityPeriodInSeconds:e=604800,domain:i,scope:s,devMode:c=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=getProofData(t.proof,getNumberOfPublicInputs(t.name)),d=[],a=[];for(let r in t.committedInputs){let l=getCommittedInputCount(r),f=r;d.push({circuitName:f,count:l});let u="";if(f==="inclusion_check_issuing_country_evm"||f==="inclusion_check_nationality_evm"||f==="exclusion_check_issuing_country_evm"||f==="exclusion_check_nationality_evm"){let y=t.committedInputs[f].countries;(f==="exclusion_check_issuing_country_evm"||f==="exclusion_check_nationality_evm")&&y.sort((C,S)=>C.localeCompare(S));let T=(()=>{switch(f){case "exclusion_check_issuing_country_evm":return ProofType.ISSUING_COUNTRY_EXCLUSION;case "exclusion_check_nationality_evm":return ProofType.NATIONALITY_EXCLUSION;case "inclusion_check_issuing_country_evm":return ProofType.ISSUING_COUNTRY_INCLUSION;case "inclusion_check_nationality_evm":return ProofType.NATIONALITY_INCLUSION}})();u=T.toString(16).padStart(2,"0")+ProofTypeLength[T].evm.toString(16).padStart(4,"0")+rightPadArrayWithZeros(y.map(C=>Array.from(new TextEncoder().encode(C))).flat(),600).map(C=>C.toString(16).padStart(2,"0")).join("");}else if(f==="compare_age_evm"){let p=t.committedInputs[f];u=ProofType.AGE.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.AGE].evm.toString(16).padStart(4,"0")+p.minAge.toString(16).padStart(2,"0")+p.maxAge.toString(16).padStart(2,"0");}else if(f==="compare_birthdate_evm"){let p=t.committedInputs[f],y=Array.from(numberToBytesBE(p.minDateTimestamp,8)),T=Array.from(numberToBytesBE(p.maxDateTimestamp,8));u=ProofType.BIRTHDATE.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.BIRTHDATE].evm.toString(16).padStart(4,"0")+y.map(C=>C.toString(16).padStart(2,"0")).join("")+T.map(C=>C.toString(16).padStart(2,"0")).join("");}else if(f==="compare_expiry_evm"){let p=t.committedInputs[f],y=Array.from(numberToBytesBE(p.minDateTimestamp,8)),T=Array.from(numberToBytesBE(p.maxDateTimestamp,8));u=ProofType.EXPIRY_DATE.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.EXPIRY_DATE].evm.toString(16).padStart(4,"0")+y.map(C=>C.toString(16).padStart(2,"0")).join("")+T.map(C=>C.toString(16).padStart(2,"0")).join("");}else if(f==="disclose_bytes_evm"){let p=t.committedInputs[f];u=ProofType.DISCLOSE.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.DISCLOSE].evm.toString(16).padStart(4,"0")+p.discloseMask.map(y=>y.toString(16).padStart(2,"0")).join("")+p.disclosedBytes.map(y=>y.toString(16).padStart(2,"0")).join("");}else if(f==="bind_evm"){let p=t.committedInputs[f];u=ProofType.BIND.toString(16).padStart(2,"0")+ProofTypeLength[ProofType.BIND].evm.toString(16).padStart(4,"0")+rightPadArrayWithZeros(formatBoundData(p.data),509).map(y=>y.toString(16).padStart(2,"0")).join("");}else if(f==="exclusion_check_sanctions_evm"){let p=t.committedInputs[f];u+=ProofType.SANCTIONS_EXCLUSION.toString(16).padStart(2,"0"),u+=ProofTypeLength[ProofType.SANCTIONS_EXCLUSION].evm.toString(16).padStart(4,"0"),u+=Array.from(numberToBytesBE(BigInt(p.rootHash),32)).map(y=>y.toString(16).padStart(2,"0")).join(""),u+=p.isStrict?"01":"00";}else if(f.startsWith("facematch")&&f.endsWith("_evm")){let p=t.committedInputs[f];u+=ProofType.FACEMATCH.toString(16).padStart(2,"0"),u+=ProofTypeLength[ProofType.FACEMATCH].evm.toString(16).padStart(4,"0"),u+=Array.from(numberToBytesBE(BigInt(p.rootKeyLeaf),32)).map(y=>y.toString(16).padStart(2,"0")).join(""),u+=p.environment==="development"?"00":"01",u+=Array.from(numberToBytesBE(BigInt(p.appIdHash),32)).map(y=>y.toString(16).padStart(2,"0")).join(""),u+=Array.from(numberToBytesBE(BigInt(p.integrityPubkeyHash),32)).map(y=>y.toString(16).padStart(2,"0")).join(""),u+=p.mode==="regular"?"01":"02";}else throw new Error(`Unsupported circuit for EVM verification: ${f}`);a.push({circuitName:f,inputs:u});}let m=getParamCommitmentsFromOuterProof(o).map(r=>r.toString(16).padStart(64,"0")),x="";for(let r of m){let l=a.find(f=>{let u=sha256(hexToBytes(f.inputs)),p=new Uint8Array(u.length);for(let y=0;y<u.length-1;y++)p[y+1]=u[y];return p[0]=0,bytesToHex(p)===r.replace("0x","")});if(l){let f=d.find(u=>u.circuitName===l.circuitName)?.count;if(f)x+=l.inputs;else throw new Error(`Unknown circuit name: ${l.circuitName}`)}else throw new Error(`Invalid commitment: ${r}`)}let D=t.version?.split(".").map(r=>Number(r));if(!D||D.length!==3)throw new Error("Invalid version format");let n=new Uint8Array([...numberToBytesBE(D[0],2),...numberToBytesBE(D[1],2),...numberToBytesBE(D[2],2)]);return {version:`0x${bytesToHex(n).padEnd(64,"0")}`,proofVerificationData:{vkeyHash:`0x${t.vkeyHash.replace("0x","").padStart(64,"0")}`,proof:`0x${o.proof.join("")}`,publicInputs:o.publicInputs},committedInputs:`0x${x}`,serviceConfig:{validityPeriodInSeconds:e,domain:i,scope:s??"",devMode:c}}}};typeof globalThis.Buffer>"u"&&(globalThis.Buffer=Buffer,typeof window<"u"&&(window.Buffer=Buffer));registerLocale(pt);function de(V){if(V==="Zero Knowledge Republic")return "ZKR";let t;return t=getAlpha3Code(V,"en")||V||"ZKR",t}function ie(V,t,e,i,s){s[i][t]={...s[i][t],[V]:e};}function ht(V,t,e,i){i[e][V]={...i[e][V],range:t};}function fe(V,t,e,i,s){s[i][t]={...s[i][t],[V]:e};}var Pe=class{constructor(t){this.topicToConfig={};this.topicToLocalConfig={};this.topicToPublicKey={};this.topicToBridge={};this.topicToRequestReceived={};this.topicToService={};this.topicToProofs={};this.topicToFailedProofCount={};this.topicToResults={};this.onRequestReceivedCallbacks={};this.onGeneratingProofCallbacks={};this.onBridgeConnectCallbacks={};this.onProofGeneratedCallbacks={};this.onResultCallbacks={};this.onRejectCallbacks={};this.onErrorCallbacks={};if(!t&&typeof window>"u")throw new Error("Domain argument is required in Node.js environment");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 e=this.topicToResults[t];delete this.topicToResults[t];let{uniqueIdentifier:i,verified:s,queryResultErrors:c}=await this.verify({proofs:this.topicToProofs[t],queryResult:e,validity:this.topicToLocalConfig[t]?.validity,scope:this.topicToService[t]?.scope,devMode:this.topicToLocalConfig[t]?.devMode});delete this.topicToProofs[t];let o=this.topicToFailedProofCount[t]>0;await Promise.all(this.onResultCallbacks[t].map(d=>d({uniqueIdentifier:o?void 0:i,verified:o?false:s,result:e,queryResultErrors:c}))),delete this.topicToFailedProofCount[t];}async handleEncryptedMessage(t,e){if(e.method==="accept")await Promise.all(this.onGeneratingProofCallbacks[t].map(i=>i(t)));else if(e.method==="reject")await Promise.all(this.onRejectCallbacks[t].map(i=>i()));else if(e.method==="proof")this.topicToProofs[t].push(e.params),await Promise.all(this.onProofGeneratedCallbacks[t].map(i=>i(e.params))),this.topicToResults[t]&&e.params.total===this.topicToProofs[t].length+this.topicToFailedProofCount[t]&&await this.handleResult(t);else if(e.method==="done")this.topicToResults[t]=formatQueryResultDates(e.params),this.topicToProofs[t].length>0&&this.topicToProofs[t].length+this.topicToFailedProofCount[t]===this.topicToProofs[t][0].total&&await this.handleResult(t);else if(e.method==="error"){let i=e.params.error;i&&i==="This ID is not supported yet"?this.topicToResults[t]&&await this.handleResult(t):i&&i.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(s=>s(i)));}}getZkPassportRequest(t){return {eq:(e,i)=>((e==="issuing_country"||e==="nationality")&&(i=de(i)),fe("eq",e,i,t,this.topicToConfig),this.getZkPassportRequest(t)),gte:(e,i)=>{if(ie("gte",e,i,t,this.topicToConfig),e==="age"&&(i<1||i>=100))throw new Error("Age must be between 1 and 99 (inclusive)");return this.getZkPassportRequest(t)},gt:(e,i)=>(ie("gt",e,i,t,this.topicToConfig),this.getZkPassportRequest(t)),lte:(e,i)=>(ie("lte",e,i,t,this.topicToConfig),this.getZkPassportRequest(t)),lt:(e,i)=>(ie("lt",e,i,t,this.topicToConfig),this.getZkPassportRequest(t)),range:(e,i,s)=>(ht(e,[i,s],t,this.topicToConfig),this.getZkPassportRequest(t)),in:(e,i)=>(i=i.map(s=>de(s)),fe("in",e,i,t,this.topicToConfig),this.getZkPassportRequest(t)),out:(e,i)=>(i=i.map(s=>de(s)),fe("out",e,i,t,this.topicToConfig),this.getZkPassportRequest(t)),disclose:e=>(this.topicToConfig[t][e]={...this.topicToConfig[t][e],disclose:true},this.getZkPassportRequest(t)),bind:(e,i)=>(this.topicToConfig[t].bind={...this.topicToConfig[t].bind,[e]:i},this.getZkPassportRequest(t)),sanctions:(e="all",i="all",s={strict:false})=>(this.topicToConfig[t].sanctions={...this.topicToConfig[t].sanctions,countries:e==="all"?"all":Array.isArray(e)?[...this.topicToConfig[t].sanctions?.countries??[],...e]:[...this.topicToConfig[t].sanctions?.countries??[],e],lists:i==="all"?"all":Array.isArray(i)?[...this.topicToConfig[t].sanctions?.lists??[],...i]:[...this.topicToConfig[t].sanctions?.lists??[],i],strict:s.strict??false},this.getZkPassportRequest(t)),facematch:(e="regular")=>(this.topicToConfig[t].facematch={mode:e},this.getZkPassportRequest(t)),done:()=>(this.topicToFailedProofCount[t]=0,{url:this._getUrl(t),requestId:t,onRequestReceived:e=>this.onRequestReceivedCallbacks[t].push(e),onGeneratingProof:e=>this.onGeneratingProofCallbacks[t].push(e),onBridgeConnect:e=>this.onBridgeConnectCallbacks[t].push(e),onProofGenerated:e=>this.onProofGeneratedCallbacks[t].push(e),onResult:e=>this.onResultCallbacks[t].push(e),onReject:e=>this.onRejectCallbacks[t].push(e),onError:e=>this.onErrorCallbacks[t].push(e),isBridgeConnected:()=>this.topicToBridge[t].isBridgeConnected(),requestReceived:()=>this.topicToRequestReceived[t]===true})}}async request({name:t,logo:e,purpose:i,scope:s,projectID:c,mode:o,validity:d,devMode:a,topicOverride:m,keyPairOverride:x,cloudProverUrl:$,bridgeUrl:D}){let n=await Bridge.create({keyPair:x,bridgeId:m,bridgeUrl:D}),w=n.connection.getBridgeId();return this.topicToConfig[w]={},this.topicToService[w]={name:t,logo:e,purpose:i,scope:s,projectID:c,cloudProverUrl:$,bridgeUrl:D},this.topicToProofs[w]=[],this.topicToLocalConfig[w]={validity:d||604800,mode:o||"fast",devMode:a||false},this.onRequestReceivedCallbacks[w]=[],this.onGeneratingProofCallbacks[w]=[],this.onBridgeConnectCallbacks[w]=[],this.onProofGeneratedCallbacks[w]=[],this.onResultCallbacks[w]=[],this.onRejectCallbacks[w]=[],this.onErrorCallbacks[w]=[],this.topicToPublicKey[w]=n.getPublicKey(),this.topicToBridge[w]=n,n.onConnect(async h=>{await Promise.all(this.onBridgeConnectCallbacks[w].map(r=>r()));}),n.onSecureChannelEstablished(async()=>{await Promise.all(this.onRequestReceivedCallbacks[w].map(h=>h()));}),n.onSecureMessage(async h=>{this.handleEncryptedMessage(w,h);}),this.getZkPassportRequest(w)}async verify({proofs:t,queryResult:e,validity:i,scope:s,devMode:c=false,writingDirectory:o}){if(!t||t.length===0)return {uniqueIdentifier:void 0,uniqueIdentifierType:void 0,verified:false};let d=formatQueryResultDates(e),{UltraHonkVerifierBackend:a}=await import('@aztec/bb.js');typeof window>"u"&&!o&&(o="/tmp");let m=new a({crsPath:o?o+"/.bb-crs":void 0}),x=true,$,D,n,{isCorrect:w,uniqueIdentifier:h,uniqueIdentifierType:r,queryResultErrors:l}=await te.checkPublicInputs(this.domain,t,d,i,s);if($=h,D=r,x=w,n=w?void 0:l,$&&D&&(D===NullifierType.SALTED_MOCK||D===NullifierType.NON_SALTED_MOCK)&&!c&&(x=false,console.warn("You are trying to verify a mock proof. This is only allowed in dev mode. To enable dev mode, set the `devMode` parameter to `true` in the request function parameters.")),x){let f=new RegistryClient({chainId:11155111}),u=await f.getCircuitManifest(void 0,{version:t[0].version});for(let p of t){let y=p.name?.startsWith("outer_evm_"),T=p.name,C=getProofData(p.proof,getNumberOfPublicInputs(T)),S=await f.getPackagedCircuit(T,u,{validate:!y});if(y)try{let{createPublicClient:k,http:Y}=await import('viem'),{sepolia:ae}=await import('viem/chains'),{address:_,abi:g,functionName:j}=this.getSolidityVerifierDetails(),b=k({chain:ae,transport:Y("https://ethereum-sepolia-rpc.publicnode.com")}),v=this.getSolidityVerifierParameters({proof:p,domain:this.domain,scope:s,devMode:c}),I=await b.readContract({address:_,abi:g,functionName:j,args:[v]});x=Array.isArray(I)?!!I[0]:!1;}catch(k){console.warn("Error verifying proof",k),x=false;}else {let k=Buffer.from(S.vkey,"base64");try{x=await m.verifyProof({proof:Buffer.from(C.proof.join(""),"hex"),publicInputs:C.publicInputs,verificationKey:new Uint8Array(k)});}catch(Y){console.warn("Error verifying proof",Y),x=false;}}if(!x)break}}return $=x?$:void 0,D=x?D:void 0,{uniqueIdentifier:$,uniqueIdentifierType:D,verified:x,queryResultErrors:n}}getSolidityVerifierDetails(){return q.getDetails()}getSolidityVerifierParameters({proof:t,validityPeriodInSeconds:e=604800,domain:i,scope:s,devMode:c=false}){return q.getParameters({proof:t,validityPeriodInSeconds:e,domain:i??this.domain,scope:s,devMode:c})}_getUrl(t){let e=Buffer.from(JSON.stringify(this.topicToConfig[t])).toString("base64"),i=Buffer.from(JSON.stringify(this.topicToService[t])).toString("base64"),s=this.topicToPublicKey[t],c=Math.floor(Date.now()/1e3)-this.topicToLocalConfig[t].validity;return `https://zkpassport.id/r?d=${this.domain}&t=${t}&c=${e}&s=${i}&p=${s}&m=${this.topicToLocalConfig[t].mode}&v=${me}&dt=${c}&dev=${this.topicToLocalConfig[t].devMode?"1":"0"}`}getUrl(t){return this._getUrl(t)}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],this.onRequestReceivedCallbacks[t]=[],this.onGeneratingProofCallbacks[t]=[],this.onBridgeConnectCallbacks[t]=[],this.onProofGeneratedCallbacks[t]=[],this.onRejectCallbacks[t]=[],this.onErrorCallbacks[t]=[];}clearAllRequests(){for(let t in this.topicToBridge)this.cancelRequest(t);}};
|
|
2
|
+
export{Pe as ZKPassport};
|