@zkpassport/sdk 0.16.2 → 0.17.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,400 +1,3 @@
1
- import { Query, IDCredential, IDCredentialValue, NumericalIDCredential, DisclosableIDCredential, BoundData, SupportedChain, SanctionsCountries, SanctionsLists, FacematchMode, ProofResult, NullifierType, QueryResult, ProofMode } from '@zkpassport/utils';
1
+ export { D as DashboardConfig, d as OfflineQueryBuilderResult, O as OnSuccessVerdict, P as Policy, Q as QueryBuilder, a as QueryBuilderResult, e as QueryResultError, f as QueryResultErrors, R as RequestSuccess, h as RequestedNullifierType, S as SolidityProofVerificationData, i as SolidityServiceConfig, j as SolidityVerifierParameters, V as VerificationResult, k as VerifierMode, Z as ZKPassport, c as createOfflineQuery } from './index-PPMt5JWF.js';
2
2
  export { ASEAN_COUNTRIES, BoundData, CountryName, DisclosableIDCredential, EEA_COUNTRIES, EU_COUNTRIES, FacematchMode, IDCredential, IDCredentialValue, JsonRpcRequest, MERCOSUR_COUNTRIES, NullifierType, NumericalIDCredential, ProofMode, ProofResult, ProofType, ProofTypeLength, Query, QueryResult, SANCTIONED_COUNTRIES, SCHENGEN_COUNTRIES, SanctionsCountries, SanctionsLists, Service, SupportedChain } from '@zkpassport/utils';
3
-
4
- type QueryResultError<T> = {
5
- expected?: T;
6
- received?: T;
7
- message: string;
8
- };
9
- type QueryResultErrors = {
10
- [key in IDCredential | "sig_check_dsc" | "sig_check_id_data" | "data_check_integrity" | "outer" | "disclose" | "bind" | "facematch" | "sanctions"]: {
11
- disclose?: QueryResultError<string | number | Date>;
12
- gte?: QueryResultError<number | Date>;
13
- gt?: QueryResultError<number | Date>;
14
- lte?: QueryResultError<number | Date>;
15
- lt?: QueryResultError<number | Date>;
16
- range?: QueryResultError<[number | Date, number | Date]>;
17
- in?: QueryResultError<string[]>;
18
- out?: QueryResultError<string[]>;
19
- eq?: QueryResultError<string | number | Date>;
20
- commitment?: QueryResultError<string>;
21
- date?: QueryResultError<string>;
22
- certificate?: QueryResultError<string>;
23
- scope?: QueryResultError<string>;
24
- };
25
- };
26
- type SolidityProofVerificationData = {
27
- vkeyHash: string;
28
- proof: string;
29
- publicInputs: string[];
30
- };
31
- type SolidityServiceConfig = {
32
- validityPeriodInSeconds: number;
33
- domain: string;
34
- scope: string;
35
- devMode: boolean;
36
- };
37
- type SolidityVerifierParameters = {
38
- version: string;
39
- proofVerificationData: SolidityProofVerificationData;
40
- committedInputs: string;
41
- serviceConfig: SolidityServiceConfig;
42
- };
43
- type Policy = {
44
- id: string;
45
- version: number;
46
- name: string;
47
- purpose: string;
48
- projectId: string | null;
49
- query: Query;
50
- };
51
- type DashboardConfig = {
52
- project: {
53
- name: string;
54
- domain: string;
55
- logoUrl: string | null;
56
- allowedOrigins: string[];
57
- };
58
- policies: Policy[];
59
- };
60
- type QueryBuilderResult = {
61
- /**
62
- * The URL of the request.
63
- *
64
- * You can either encode the URL in a QR code or let the user click the link
65
- * to this URL on your website if they're visiting your website on their phone.
66
- */
67
- url: string;
68
- /**
69
- * The query object.
70
- */
71
- query: Query;
72
- /**
73
- * The id of the request.
74
- */
75
- requestId: string;
76
- /**
77
- * The id of the policy used to build the request, if one was provided.
78
- */
79
- policy?: string;
80
- /**
81
- * Called when the user has scanned the QR code or clicked the link to the request.
82
- *
83
- * This means the user is currently viewing the request popup with your website information
84
- * and the information requested from them.
85
- */
86
- onRequestReceived: (callback: () => void) => void;
87
- /**
88
- * Called when the user has accepted the request and
89
- * started to generate the proof on their phone.
90
- */
91
- onGeneratingProof: (callback: () => void) => void;
92
- /**
93
- * Called when the SDK successfully connects to the bridge with the mobile app.
94
- */
95
- onBridgeConnect: (callback: () => void) => void;
96
- /**
97
- * Called when the user has generated a proof.
98
- *
99
- * There is a minimum of 4 proofs, but there can be more depending
100
- * on the type of information requested from the user.
101
- */
102
- onProofGenerated: (callback: (proof: ProofResult) => void) => void;
103
- /**
104
- * Called when the user has sent the query result.
105
- *
106
- * The response contains the unique identifier associated to the user,
107
- * your domain name and chosen scope, along with the query result and whether
108
- * the proofs were successfully verified.
109
- */
110
- onResult: (callback: (response: {
111
- uniqueIdentifier: string | undefined;
112
- uniqueIdentifierType: NullifierType | undefined;
113
- verified: boolean;
114
- result: QueryResult;
115
- queryResultErrors?: Partial<QueryResultErrors>;
116
- proofs: ProofResult[];
117
- sdkInstance: ZKPassport;
118
- }) => void) => void;
119
- /**
120
- * Called when the user has rejected the request.
121
- */
122
- onReject: (callback: () => void) => void;
123
- /**
124
- * Called when an error occurs, such as one of the requirements not being met
125
- * or a proof failing to be generated.
126
- */
127
- onError: (callback: (error: string) => void) => void;
128
- /**
129
- * @returns true if the bridge with the mobile app is connected
130
- */
131
- isBridgeConnected: () => boolean;
132
- /**
133
- * Get if the user has scanned the QR code or the link to this request
134
- * @returns true if the request has been received by the user on their phone
135
- */
136
- requestReceived: () => boolean;
137
- };
138
- type OfflineQueryBuilderResult = {
139
- query: Query;
140
- };
141
- type QueryBuilder<T extends "online" | "offline" = "online"> = {
142
- /**
143
- * Requires this attribute to be equal to the provided value.
144
- * @param key The attribute to compare.
145
- * @param value The value of the attribute you require.
146
- */
147
- eq: <T extends IDCredential>(key: T, value: IDCredentialValue<T>) => QueryBuilder;
148
- /**
149
- * Requires this attribute to be greater than or equal to the provided value.
150
- * @param key The attribute to compare.
151
- * @param value The value of the attribute you require.
152
- */
153
- gte: <T extends NumericalIDCredential>(key: T, value: IDCredentialValue<T>) => QueryBuilder;
154
- /**
155
- * Requires this attribute to be greater than the provided value.
156
- * @param key The attribute to compare.
157
- * @param value The value of the attribute you require.
158
- */
159
- gt: <T extends NumericalIDCredential>(key: T, value: IDCredentialValue<T>) => QueryBuilder;
160
- /**
161
- * Requires this attribute to be less than or equal to the provided value.
162
- * @param key The attribute to compare.
163
- * @param value The value of the attribute you require.
164
- */
165
- lte: <T extends NumericalIDCredential>(key: T, value: IDCredentialValue<T>) => QueryBuilder;
166
- /**
167
- * Requires this attribute to be less than the provided value.
168
- * @param key The attribute to compare.
169
- * @param value The value of the attribute you require.
170
- */
171
- lt: <T extends NumericalIDCredential>(key: T, value: IDCredentialValue<T>) => QueryBuilder;
172
- /**
173
- * Requires this attribute to be included in the provided range.
174
- * @param key The attribute to compare.
175
- * @param start The start of the range.
176
- * @param end The end of the range.
177
- */
178
- range: <T extends NumericalIDCredential>(key: T, start: IDCredentialValue<T>, end: IDCredentialValue<T>) => QueryBuilder;
179
- /**
180
- * Requires this attribute to be included in the provided list.
181
- * @param key The attribute to compare.
182
- * @param value The list of values to check inclusion against.
183
- */
184
- in: <T extends "nationality" | "issuing_country">(key: T, value: IDCredentialValue<T>[]) => QueryBuilder;
185
- /**
186
- * Requires this attribute to be excluded from the provided list.
187
- * @param key The attribute to compare.
188
- * @param value The list of values to check exclusion against.
189
- */
190
- out: <T extends "nationality" | "issuing_country">(key: T, value: IDCredentialValue<T>[]) => QueryBuilder;
191
- /**
192
- * Requires this attribute to be disclosed.
193
- * @param key The attribute to disclose.
194
- */
195
- disclose: (key: DisclosableIDCredential) => QueryBuilder;
196
- /**
197
- * Binds a value to the request.
198
- * @param key The key of the value to bind.
199
- * @param value The value to bind the request to.
200
- */
201
- bind: <T extends keyof BoundData>(key: T, value: T extends "chain" ? SupportedChain : T extends "user_address" ? `0x${string}` : string | undefined) => QueryBuilder;
202
- /**
203
- * Requires that the ID holder is not part of any of the specified sanction lists.
204
- * @param countries The country or list of countries whose sanction lists to check against. Defaults to "all".
205
- * e.g. "US", ["US", "GB", "CH", "EU"], "all"
206
- * @param lists The specific lists from a given country to check against. Defaults to "all".
207
- * e.g. ["OFAC_SDN"], "all"
208
- * @param options The options to use for the sanction check.
209
- * @param options.strict Whether to use a strict sanction check. Defaults to false.
210
- *
211
- * If set to true, this means the checks will be done against just the lastname and firstname,
212
- * while when set to false, matches will need to include either the date of birth and name or
213
- * the passport number and nationality.
214
- * Strict mode has therefore a higher false positive rate but is harder to evade.
215
- */
216
- sanctions: (countries?: SanctionsCountries, lists?: SanctionsLists, options?: {
217
- strict?: boolean;
218
- }) => QueryBuilder;
219
- /**
220
- * Requires that the ID holder's face matches the photo on the ID.
221
- * @param mode The mode to use for the face match. Defaults to "regular".
222
- * @param mode "strict" - The user will have to go through an extensive liveness check to prevent spoofing making it more secure.
223
- * Best for high security requirements such as KYC.
224
- * @param mode "regular" - The user will only have to go through a basic liveness check to prevent spoofing, making it faster for the user.
225
- * Best for lower security requirements that requires fast verification such as age verification.
226
- */
227
- facematch: (mode?: FacematchMode) => QueryBuilder;
228
- /**
229
- * Applies an immutable policy fetched from the dashboard. The policy's query,
230
- * purpose and scope are locked; combining with builder methods (except
231
- * `.bind()`, which may follow it) or calling twice throws.
232
- * @param id The policy id (e.g. `'pol_xyz'`).
233
- */
234
- policy: (id: string) => QueryBuilder<T>;
235
- /**
236
- * Builds the request.
237
- *
238
- * This will return the URL of the request, which you can either encode in a QR code
239
- * or provide as a link to the user if they're visiting your website on their phone.
240
- * It also returns all the callbacks you can use to handle the user's response.
241
- */
242
- done: () => T extends "online" ? QueryBuilderResult : OfflineQueryBuilderResult;
243
- };
244
-
245
- declare class ZKPassport {
246
- private domain;
247
- private domainProvided;
248
- private disableProofStorage;
249
- private topicToConfig;
250
- private topicToLocalConfig;
251
- private topicToPublicKey;
252
- private topicToBridge;
253
- private topicToRequestReceived;
254
- private topicToService;
255
- private topicToCallerPurpose;
256
- private topicToProofs;
257
- private topicToFailedProofCount;
258
- private topicToResults;
259
- private topicToPolicy;
260
- private dashboardConfig;
261
- private dashboardConfigPromise;
262
- private dashboardConfigError;
263
- private onRequestReceivedCallbacks;
264
- private onGeneratingProofCallbacks;
265
- private onBridgeConnectCallbacks;
266
- private onProofGeneratedCallbacks;
267
- private onResultCallbacks;
268
- private onRejectCallbacks;
269
- private onErrorCallbacks;
270
- private normalizeDomain;
271
- constructor(_domain?: string, options?: {
272
- disableProofStorage?: boolean;
273
- });
274
- private handleResult;
275
- /**
276
- * @notice Handle an encrypted message.
277
- * @param request The request.
278
- * @param outerRequest The outer request.
279
- */
280
- private handleEncryptedMessage;
281
- private assertNotPolicyLocked;
282
- private getZkPassportRequest;
283
- private getDashboardConfig;
284
- private fetchDashboardConfig;
285
- private findPolicy;
286
- private assertCanApplyPolicy;
287
- /**
288
- * @notice Create a new request. To apply a policy, chain `.policy('<id>')` on
289
- * the returned builder; a policy locks the query and scope.
290
- * @param name Your service name. Defaults to the dashboard branding, then the domain.
291
- * @param logo Your service logo. Defaults to the dashboard branding.
292
- * @param purpose Explanation shown to the user. Defaults to the policy's purpose (if any), then a generic message.
293
- * @param scope Use-case scope (drives the nullifier). Defaults to the domain. Locked by `.policy()` (to `<id>:<version>`).
294
- * @param projectID The project ID of your service
295
- * @param validity How many seconds ago the proof checking the expiry date of the ID should have been generated
296
- * @param mode The proof mode (e.g. "fast" / "compressed").
297
- * @param devMode Whether to enable dev mode. This will allow you to verify mock proofs (i.e. from ZKR)
298
- * @returns The query builder object.
299
- */
300
- request({ name, logo, purpose, scope, projectID, mode, validity, devMode, uniqueIdentifierType, oprfKeyId, topicOverride, keyPairOverride, cloudProverUrl, bridgeUrl, returnDeepLink, }: {
301
- name?: string;
302
- logo?: string;
303
- purpose?: string;
304
- scope?: string;
305
- mode?: ProofMode;
306
- projectID?: string;
307
- validity?: number;
308
- devMode?: boolean;
309
- uniqueIdentifierType?: NullifierType.NON_SALTED | NullifierType.SALTED;
310
- oprfKeyId?: string;
311
- topicOverride?: string;
312
- keyPairOverride?: {
313
- privateKey: Uint8Array;
314
- publicKey: Uint8Array;
315
- };
316
- cloudProverUrl?: string;
317
- bridgeUrl?: string;
318
- returnDeepLink?: string;
319
- }): Promise<QueryBuilder>;
320
- /**
321
- * @notice Create a new offline query
322
- * Unlike request(), this function does not connect to the bridge.
323
- * It returns only the query object and no callbacks and no URL.
324
- * This can be useful to recreate the same query server-side when calling `verify()`
325
- * to ensure the original query wasn't tampered with.
326
- * @returns The query builder object.
327
- */
328
- createQuery(): QueryBuilder<"offline">;
329
- /**
330
- * @notice Verify the proofs received from the mobile app.
331
- * @param proofs The proofs to verify.
332
- * @param originalQuery The original query that was sent to the mobile app.
333
- * @param queryResult The query result to verify against
334
- * @param validity How many seconds ago the proof checking the expiry date of the ID should have been generated
335
- * @param scope Scope this request to a specific use case
336
- * @param devMode Whether to enable dev mode. This will allow you to verify mock proofs (i.e. from ZKR)
337
- * @param writingDirectory The directory (e.g. `./tmp`) where the necessary temporary artifacts for verification are written to.
338
- * It should only be needed when running the `verify` function on a server with restricted write access (e.g. Vercel)
339
- * @returns An object containing the unique identifier associated to the user
340
- * and a boolean indicating whether the proofs were successfully verified.
341
- */
342
- verify({ proofs, originalQuery, queryResult, validity, scope, devMode, writingDirectory, oprfKeyId, }: {
343
- proofs: Array<ProofResult>;
344
- originalQuery: Query;
345
- queryResult: QueryResult;
346
- validity?: number;
347
- scope?: string;
348
- devMode?: boolean;
349
- writingDirectory?: string;
350
- oprfKeyId?: string;
351
- }): Promise<{
352
- uniqueIdentifier: string | undefined;
353
- uniqueIdentifierType: NullifierType | undefined;
354
- verified: boolean;
355
- queryResultErrors?: Partial<QueryResultErrors>;
356
- }>;
357
- getSolidityVerifierDetails(): {
358
- address: `0x${string}`;
359
- functionName: string;
360
- abi: {
361
- type: "function" | "event" | "constructor";
362
- name: string;
363
- inputs: {
364
- name: string;
365
- type: string;
366
- internalType: string;
367
- }[];
368
- outputs: {
369
- name: string;
370
- type: string;
371
- internalType: string;
372
- }[];
373
- }[];
374
- };
375
- getSolidityVerifierParameters({ proof, validityPeriodInSeconds, domain, scope, devMode, }: {
376
- proof: ProofResult;
377
- validityPeriodInSeconds?: number;
378
- domain?: string;
379
- scope?: string;
380
- devMode?: boolean;
381
- }): SolidityVerifierParameters;
382
- private _getUrl;
383
- /**
384
- * @notice Returns the URL of the request.
385
- * @param requestId The request ID.
386
- * @returns The URL of the request.
387
- */
388
- getUrl(requestId: string): string;
389
- /**
390
- * @notice Cancels a request by closing the WebSocket connection and deleting the associated data.
391
- * @param requestId The request ID.
392
- */
393
- cancelRequest(requestId: string): void;
394
- /**
395
- * @notice Clears all requests.
396
- */
397
- clearAllRequests(): void;
398
- }
399
-
400
- export { type DashboardConfig, type OfflineQueryBuilderResult, type Policy, type QueryBuilder, type QueryBuilderResult, type QueryResultError, type QueryResultErrors, type SolidityProofVerificationData, type SolidityServiceConfig, type SolidityVerifierParameters, ZKPassport };
3
+ import 'i18n-iso-countries';