@zk-email/sdk 0.0.86 → 0.0.88

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.
Files changed (38) hide show
  1. package/README.md +30 -6
  2. package/dist/ccip-Blve6Z7V.js +2 -0
  3. package/dist/ccip-Blve6Z7V.js.map +1 -0
  4. package/dist/ccip-CqWwM5V5.mjs +147 -0
  5. package/dist/ccip-CqWwM5V5.mjs.map +1 -0
  6. package/dist/index-76VwpgoI.js +41 -0
  7. package/dist/index-76VwpgoI.js.map +1 -0
  8. package/dist/index-BBAkhu6Z.mjs +13594 -0
  9. package/dist/index-BBAkhu6Z.mjs.map +1 -0
  10. package/dist/types/auth.d.ts +3 -0
  11. package/dist/types/blueprint.d.ts +132 -0
  12. package/dist/types/blueprintValidation.d.ts +82 -0
  13. package/dist/types/chain/index.d.ts +2 -0
  14. package/dist/types/index.d.ts +24 -0
  15. package/dist/types/localProverWorkerString.d.ts +1 -0
  16. package/dist/types/proof.d.ts +52 -0
  17. package/dist/types/prover.d.ts +39 -0
  18. package/dist/types/relayerUtils.d.ts +14 -0
  19. package/dist/types/types/auth.d.ts +16 -0
  20. package/dist/types/types/blueprint.d.ts +155 -0
  21. package/dist/types/types/index.d.ts +6 -0
  22. package/dist/types/types/proof.d.ts +63 -0
  23. package/dist/types/types/prover.d.ts +8 -0
  24. package/dist/types/types/sdk.d.ts +5 -0
  25. package/dist/types/types/utils.d.ts +8 -0
  26. package/dist/types/user.d.ts +5 -0
  27. package/dist/types/utils.d.ts +7 -0
  28. package/dist/zk-email-sdk.cjs.js +2 -0
  29. package/dist/zk-email-sdk.cjs.js.map +1 -0
  30. package/dist/zk-email-sdk.es.js +18 -0
  31. package/dist/zk-email-sdk.es.js.map +1 -0
  32. package/package.json +25 -11
  33. package/dist/index.d.mts +0 -557
  34. package/dist/index.d.ts +0 -557
  35. package/dist/index.js +0 -7
  36. package/dist/index.js.map +0 -1
  37. package/dist/index.mjs +0 -7
  38. package/dist/index.mjs.map +0 -1
package/dist/index.d.mts DELETED
@@ -1,557 +0,0 @@
1
- import { z } from 'zod';
2
- export { ZodError } from 'zod';
3
-
4
- type BlueprintProps = {
5
- id?: string;
6
- title: string;
7
- description?: string;
8
- slug?: string;
9
- tags?: string[];
10
- emailQuery?: string;
11
- circuitName: string;
12
- ignoreBodyHashCheck?: boolean;
13
- shaPrecomputeSelector?: string;
14
- emailBodyMaxLength?: number;
15
- emailHeaderMaxLength?: number;
16
- removeSoftLinebreaks?: boolean;
17
- githubUsername?: string;
18
- senderDomain?: string;
19
- enableHeaderMasking?: boolean;
20
- enableBodyMasking?: boolean;
21
- zkFramework?: ZkFramework;
22
- isPublic?: boolean;
23
- createdAt?: Date;
24
- updatedAt?: Date;
25
- externalInputs?: ExternalInput[];
26
- decomposedRegexes: DecomposedRegex[];
27
- status?: Status;
28
- verifierContract?: VerifierContract;
29
- version?: number;
30
- };
31
- type DecomposedRegex = {
32
- parts: DecomposedRegexPart[];
33
- name: string;
34
- maxLength: number;
35
- location: "body" | "header";
36
- };
37
- type DecomposedRegexPart = {
38
- isPublic: boolean;
39
- regexDef: string;
40
- };
41
- type DecomposedRegexJson = {
42
- parts: DecomposedRegexPartJson[];
43
- name: string;
44
- max_length: number;
45
- location: "body" | "header";
46
- };
47
- type DecomposedRegexPartJson = {
48
- is_public: boolean;
49
- regex_def: string;
50
- };
51
- type ExternalInput = {
52
- name: string;
53
- maxLength: number;
54
- };
55
- declare enum ZkFramework {
56
- Circom = "circom"
57
- }
58
- declare enum Status {
59
- None = 0,
60
- Draft = 1,
61
- InProgress = 2,
62
- Done = 3,
63
- Failed = 4
64
- }
65
- type VerifierContract = {
66
- address?: string;
67
- chain: number;
68
- };
69
- type BlueprintRequest = {
70
- id?: string;
71
- title: string;
72
- description?: string;
73
- slug?: string;
74
- tags?: string[];
75
- email_query?: string;
76
- circuit_name?: string;
77
- ignore_body_hash_check?: boolean;
78
- sha_precompute_selector?: string;
79
- email_body_max_length?: number;
80
- email_header_max_length?: number;
81
- remove_soft_linebreaks?: boolean;
82
- github_username?: string;
83
- sender_domain?: string;
84
- enable_header_masking?: boolean;
85
- enable_body_masking?: boolean;
86
- zk_framework?: string;
87
- is_public?: boolean;
88
- external_inputs?: ExternalInputResponse[];
89
- decomposed_regexes: DecomposedRegexResponse[];
90
- status?: string;
91
- verifier_contract_address?: string;
92
- verifier_contract_chain?: number;
93
- version?: number;
94
- };
95
- type BlueprintResponse = {
96
- id: string;
97
- title: string;
98
- description: string;
99
- slug: string;
100
- tags: string[];
101
- email_query: string;
102
- circuit_name: string;
103
- ignore_body_hash_check: boolean;
104
- sha_precompute_selector: string;
105
- email_body_max_length: number;
106
- email_header_max_length?: number;
107
- remove_soft_linebreaks?: boolean;
108
- github_username?: string;
109
- sender_domain: string;
110
- enable_header_masking?: boolean;
111
- enable_body_masking?: boolean;
112
- zk_framework: string;
113
- is_public: boolean;
114
- created_at: ServerDate;
115
- updated_at: ServerDate;
116
- external_inputs: ExternalInputResponse[];
117
- decomposed_regexes: DecomposedRegexResponse[];
118
- status: number;
119
- verifier_contract_address: string;
120
- verifier_contract_chain: number;
121
- version: number;
122
- };
123
- type ServerDate = {
124
- seconds: number;
125
- nanos: number;
126
- };
127
- type ExternalInputResponse = {
128
- name: string;
129
- max_length: number;
130
- };
131
- type DecomposedRegexResponse = {
132
- parts: DecomposedRegexPartResponse[];
133
- name: string;
134
- max_length: number;
135
- location: "body" | "header";
136
- };
137
- type DecomposedRegexPartResponse = {
138
- is_public: boolean;
139
- regex_def: string;
140
- };
141
- type ListBlueprintsOptions = {
142
- skip?: number;
143
- limit?: number;
144
- sort?: -1 | 1;
145
- status?: Status[];
146
- isPublic?: boolean;
147
- search?: string;
148
- };
149
- type ListBlueprintsOptionsRequest = {
150
- skip?: number;
151
- limit?: number;
152
- sort?: -1 | 1;
153
- status?: Status[];
154
- is_public?: boolean;
155
- search?: string;
156
- };
157
- type DownloadUrls = Record<string, string>;
158
-
159
- declare enum ProofStatus {
160
- None = 0,
161
- InProgress = 1,
162
- Done = 2,
163
- Failed = 3
164
- }
165
- type ProofProps = {
166
- id: string;
167
- blueprintId: string;
168
- input: string;
169
- proofData?: string;
170
- publicData?: string;
171
- publicOutputs?: string[];
172
- externalInputs?: string;
173
- status?: ProofStatus;
174
- startedAt?: Date;
175
- provedAt?: Date;
176
- };
177
- type ProofResponse = {
178
- id: string;
179
- blueprint_id: string;
180
- input: string;
181
- proof?: string;
182
- public?: string;
183
- external_inputs?: string;
184
- public_outputs?: string[];
185
- started_at: ServerDate;
186
- proved_at?: ServerDate;
187
- status: number;
188
- };
189
- type ProofRequest = {
190
- blueprint_id: string;
191
- input: any;
192
- external_inputs: any;
193
- };
194
- type GenerateProofInputsParams = {
195
- emailHeaderMaxLength: number;
196
- emailBodyMaxLength: number;
197
- ignoreBodyHashCheck: boolean;
198
- removeSoftLinebreaks: boolean;
199
- shaPrecomputeSelector?: string;
200
- };
201
- type GenerateProofInputsParamsInternal = {
202
- maxHeaderLength: number;
203
- maxBodyLength: number;
204
- ignoreBodyHashCheck: boolean;
205
- removeSoftLinesBreaks: boolean;
206
- shaPrecomputeSelector?: string;
207
- };
208
- type ProofData = {
209
- pi_a: [string, string, string];
210
- pi_b: [[string, string], [string, string], [string, string]];
211
- pi_c: [string, string, string];
212
- protocol: string;
213
- };
214
-
215
- /**
216
- * A generated proof. You get get proof data and verify proofs on chain.
217
- */
218
- declare class Proof {
219
- blueprint: Blueprint;
220
- props: ProofProps;
221
- private lastCheckedStatus;
222
- constructor(blueprint: Blueprint, props: ProofProps);
223
- getId(): string;
224
- /**
225
- * Returns a download link for the files of the proof.
226
- * @returns The the url to download a zip of the proof files.
227
- */
228
- getProofDataDownloadLink(): Promise<string>;
229
- startFilesDownload(): Promise<void>;
230
- /**
231
- * Checks the status of proof.
232
- * checkStatus can be used in a while(await checkStatus()) loop, since it will wait a fixed
233
- * amount of time before the second time you call it.
234
- * @returns A promise with the Status.
235
- */
236
- checkStatus(): Promise<ProofStatus>;
237
- waitForCompletion(): Promise<ProofStatus>;
238
- /**
239
- * Verifies the proof on chain using the verifier contract defined in the blueprint.
240
- * Will throw an error if it cannot verify the proof. If the function call succeeds,
241
- * the proof was validated.
242
- */
243
- verifyOnChain(): Promise<void>;
244
- /**
245
- * Generates call data for the proof that can be used to verify the proof on chain.
246
- */
247
- createCallData(): Promise<(bigint[] | bigint[][])[]>;
248
- /**
249
- * Fetches an existing Proof from the database.
250
- * @param id - Id of the Proof.
251
- * @returns A promise that resolves to a new instance of Proof.
252
- */
253
- static getProofById(id: string, baseUrl: string): Promise<Proof>;
254
- static responseToProofProps(response: ProofResponse): ProofProps;
255
- /**
256
- * @returns The public data and proof data.
257
- */
258
- getProofData(): {
259
- proofData: string;
260
- publicData: string;
261
- publicOutputs: string[];
262
- externalInputs: string;
263
- };
264
- }
265
-
266
- type ProverOptions = {
267
- isLocal: boolean;
268
- };
269
- type ExternalInputInput = {
270
- name: string;
271
- value: string;
272
- maxLength: number;
273
- };
274
-
275
- /**
276
- * Represents a Prover generated from a blueprint that can generate Proofs
277
- */
278
- declare class Prover {
279
- options: ProverOptions;
280
- blueprint: Blueprint;
281
- constructor(blueprint: Blueprint, options?: ProverOptions);
282
- /**
283
- * Generates a proof for a given email.
284
- * @param eml - Email to prove agains the blueprint of this Prover.
285
- * @returns A promise that resolves to a new instance of Proof. The Proof will have the status
286
- * Done or Failed.
287
- */
288
- generateProof(eml: string, externalInputs?: ExternalInputInput[]): Promise<Proof>;
289
- /**
290
- * Starts proving for a given email.
291
- * @param eml - Email to prove agains the blueprint of this Prover.
292
- * @returns A promise that resolves to a new instance of Proof. The Proof will have the status
293
- * InProgress.
294
- */
295
- generateProofRequest(eml: string, externalInputs?: ExternalInputInput[]): Promise<Proof>;
296
- }
297
-
298
- /**
299
- * Interface for authentication for creating and updating blueprints
300
- */
301
- type Auth = {
302
- /**
303
- * Retrieves the authentication token
304
- * e.g. from a req for next.js or the localstorage for frontend
305
- * @returns Promise that resolves to the token string or null if no token exists
306
- */
307
- getToken: () => Promise<string | null>;
308
- /**
309
- * Callback triggered when the authentication token expires
310
- * @returns Promise that resolves when expired token is handled
311
- */
312
- onTokenExpired: () => Promise<void>;
313
- };
314
-
315
- declare const blueprintFormSchema: z.ZodObject<{
316
- title: z.ZodString;
317
- circuitName: z.ZodString;
318
- description: z.ZodString;
319
- emailQuery: z.ZodString;
320
- ignoreBodyHashCheck: z.ZodBoolean;
321
- shaPrecomputeSelector: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
322
- senderDomain: z.ZodEffects<z.ZodString, string, string>;
323
- emailBodyMaxLength: z.ZodEffects<z.ZodNumber, number, number>;
324
- emailHeaderMaxLength: z.ZodDefault<z.ZodEffects<z.ZodNumber, number, number>>;
325
- decomposedRegexes: z.ZodArray<z.ZodObject<{
326
- name: z.ZodEffects<z.ZodString, string, string>;
327
- maxLength: z.ZodDefault<z.ZodNumber>;
328
- location: z.ZodString;
329
- parts: z.ZodUnion<[z.ZodOptional<z.ZodEffects<z.ZodString, any[], string>>, z.ZodArray<z.ZodAny, "many">]>;
330
- }, "strip", z.ZodTypeAny, {
331
- name: string;
332
- maxLength: number;
333
- location: string;
334
- parts?: any[] | undefined;
335
- }, {
336
- name: string;
337
- location: string;
338
- maxLength?: number | undefined;
339
- parts?: string | any[] | undefined;
340
- }>, "many">;
341
- externalInputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
342
- name: z.ZodString;
343
- maxLength: z.ZodDefault<z.ZodNumber>;
344
- }, "strip", z.ZodTypeAny, {
345
- name: string;
346
- maxLength: number;
347
- }, {
348
- name: string;
349
- maxLength?: number | undefined;
350
- }>, "many">>;
351
- }, "strip", z.ZodTypeAny, {
352
- description: string;
353
- title: string;
354
- circuitName: string;
355
- emailQuery: string;
356
- ignoreBodyHashCheck: boolean;
357
- senderDomain: string;
358
- emailBodyMaxLength: number;
359
- emailHeaderMaxLength: number;
360
- decomposedRegexes: {
361
- name: string;
362
- maxLength: number;
363
- location: string;
364
- parts?: any[] | undefined;
365
- }[];
366
- shaPrecomputeSelector?: string | undefined;
367
- externalInputs?: {
368
- name: string;
369
- maxLength: number;
370
- }[] | undefined;
371
- }, {
372
- description: string;
373
- title: string;
374
- circuitName: string;
375
- emailQuery: string;
376
- ignoreBodyHashCheck: boolean;
377
- senderDomain: string;
378
- emailBodyMaxLength: number;
379
- decomposedRegexes: {
380
- name: string;
381
- location: string;
382
- maxLength?: number | undefined;
383
- parts?: string | any[] | undefined;
384
- }[];
385
- shaPrecomputeSelector?: string | undefined;
386
- emailHeaderMaxLength?: number | undefined;
387
- externalInputs?: {
388
- name: string;
389
- maxLength?: number | undefined;
390
- }[] | undefined;
391
- }>;
392
- type ValidationErrors = {
393
- [K in keyof z.infer<typeof blueprintFormSchema>]?: string;
394
- };
395
-
396
- /**
397
- * Represents a Regex Blueprint including the decomposed regex access to the circuit.
398
- */
399
- declare class Blueprint {
400
- props: BlueprintProps;
401
- auth?: Auth;
402
- baseUrl: string;
403
- stars: number;
404
- static readonly formSchema: typeof blueprintFormSchema;
405
- private lastCheckedStatus;
406
- constructor(props: BlueprintProps, baseUrl: string, auth?: Auth);
407
- addAuth(auth: Auth): void;
408
- /**
409
- * Fetches an existing RegexBlueprint from the database.
410
- * @param {string} id - Id of the RegexBlueprint.
411
- * @returns A promise that resolves to a new instance of RegexBlueprint.
412
- */
413
- static getBlueprintById(id: string, baseUrl: string, auth?: Auth): Promise<Blueprint>;
414
- /**
415
- * Fetches an existing RegexBlueprint by slug from the database.
416
- * @param slug - Slug of the blueprint. Must include version, e.g. "slug:v1"
417
- * @param version - Version of the slug.
418
- * @returns A promise that resolves to a new instance of RegexBlueprint.
419
- */
420
- static getBlueprintBySlug(slug: string, baseUrl: string, auth?: Auth): Promise<Blueprint>;
421
- private static responseToBlueprintProps;
422
- private static blueprintPropsToRequest;
423
- /**
424
- * Submits a new RegexBlueprint to the registry as draft.
425
- * This does not compile the circuits yet and you will still be able to make changes.
426
- * @returns A promise. Once it resolves, `getId` can be called.
427
- */
428
- submitDraft(): Promise<void>;
429
- /**
430
- * Submits a new version of the RegexBlueprint to the registry as draft.
431
- * This does not compile the circuits yet and you will still be able to make changes.
432
- * @param newProps - The updated blueprint props.
433
- * @returns A promise. Once it resolves, the current Blueprint will be replaced with the new one.
434
- */
435
- submitNewVersionDraft(newProps: BlueprintProps): Promise<void>;
436
- /**
437
- * Submits a new version of the blueprint. This will save the new blueprint version
438
- * and start the compilation.
439
- * This will also overwrite the current Blueprint with its new version, even if the last
440
- * version was not compiled yet.
441
- * @param newProps - The updated blueprint props.
442
- */
443
- submitNewVersion(newProps: BlueprintProps): Promise<void>;
444
- /**
445
- * Lists blueblueprints, only including the latest version per unique slug.
446
- * @param options - Options to filter the blueprints by.
447
- * @returns A promise. Once it resolves, `getId` can be called.
448
- */
449
- static listBlueprints(baseUrl: string, options?: ListBlueprintsOptions, auth?: Auth, fetchStars?: boolean): Promise<Blueprint[]>;
450
- /**
451
- * Submits a blueprint. This will save the blueprint if it didn't exist before
452
- * and start the compilation.
453
- */
454
- submit(): Promise<void>;
455
- private _checkStatus;
456
- /**
457
- * Checks the status of blueprint.
458
- * checkStatus can be used in a while(await checkStatus()) loop, since it will wait a fixed
459
- * amount of time the second time you call it.
460
- * @returns A promise with the Status.
461
- */
462
- checkStatus(): Promise<Status>;
463
- /**
464
- * Get the id of the blueprint.
465
- * @returns The id of the blueprint. If it was not saved yet, return null.
466
- */
467
- getId(): string | null;
468
- /**
469
- * Returns a download link for the ZKeys of the blueprint.
470
- * @returns The the url to download the ZKeys.
471
- */
472
- getZKeyDownloadLink(): Promise<DownloadUrls>;
473
- /**
474
- * Directly starts a download of the ZKeys in the browser.
475
- * Must be called within a user action, like a button click.
476
- */
477
- startZKeyDownload(): Promise<void>;
478
- /**
479
- * Creates an instance of Prover with which you can create proofs.
480
- * @returns An instance of Prover.
481
- */
482
- createProver(): Prover;
483
- /**
484
- * Verifies a proof on chain.
485
- * @param proof - The generated proof you want to verify.
486
- * @returns A true if the verification was successfull, false if it failed.
487
- */
488
- verifyProofOnChain(proof: Proof): Promise<boolean>;
489
- /**
490
- * Returns a deep cloned version of the Blueprints props.
491
- * This can be used to update properties and then to use them with createNewVersion.
492
- * @param proof - The generated proof you want to verify.
493
- * @returns A true if the verification was successfull, false if it failed.
494
- */
495
- getClonedProps(): BlueprintProps;
496
- /**
497
- * Returns true if the blueprint can be updated. A blueprint can be updated if the circuits
498
- * haven't beed compiled yet, i.e. the status is not Done. The blueprint also must be saved
499
- * already before it can be updated.
500
- * @returns true if it can be updated
501
- */
502
- canUpdate(): boolean;
503
- /**
504
- * Updates an existing blueprint that is not compiled yet.
505
- * @param newProps - The props the blueprint should be updated to.
506
- * @returns a promise.
507
- */
508
- update(newProps: BlueprintProps): Promise<void>;
509
- listAllVersions(): Promise<Blueprint[]>;
510
- addStar(): Promise<number>;
511
- removeStar(): Promise<number>;
512
- getStars(): Promise<number>;
513
- cancelCompilation(): Promise<void>;
514
- delete(): Promise<void>;
515
- }
516
-
517
- type SdkOptions = {
518
- auth?: Auth;
519
- baseUrl?: string;
520
- };
521
-
522
- type ParsedEmail = {
523
- canonicalizedHeader: string;
524
- canonicalizedBody: string;
525
- signature: number[];
526
- publicKey: any[];
527
- cleanedBody: string;
528
- headers: Map<string, string[]>;
529
- };
530
-
531
- declare function startJsonFileDownload(json: string, name?: string): void;
532
- declare function getDKIMSelector(emlContent: string): string | null;
533
-
534
- declare function parseEmail(eml: string): Promise<ParsedEmail>;
535
- declare function testBlueprint(eml: string, blueprint: BlueprintProps, revealPrivate?: boolean): Promise<string[][]>;
536
- declare function testDecomposedRegex(body: string, header: string, decomposedRegex: DecomposedRegex | DecomposedRegexJson, revealPrivate?: boolean): Promise<string[]>;
537
- declare function generateProofInputs(eml: string, decomposedRegexes: DecomposedRegex[], externalInputs: ExternalInputInput[], params: GenerateProofInputsParams): Promise<string>;
538
- declare function getMaxEmailBodyLength(emlContent: string, shaPrecomputeSelector: string): Promise<number>;
539
- declare function extractEMLDetails(emlContent: string): Promise<{
540
- senderDomain: string | null;
541
- headerLength: number;
542
- emailQuery: string;
543
- emailBodyMaxLength: number;
544
- }>;
545
-
546
- declare function getLoginWithGithubUrl(callbackUrl: string, githubClientId?: string): string;
547
-
548
- declare const _default: (sdkOptions?: SdkOptions) => {
549
- createBlueprint(props: BlueprintProps): Blueprint;
550
- getBlueprint(slug: string): Promise<Blueprint>;
551
- getBlueprintById(id: string): Promise<Blueprint>;
552
- listBlueprints(options?: ListBlueprintsOptions): Promise<Blueprint[]>;
553
- getProof(id: string): Promise<Proof>;
554
- getStarredBlueprints(): Promise<string[]>;
555
- };
556
-
557
- export { type Auth, Blueprint, type BlueprintProps, type BlueprintRequest, type BlueprintResponse, type DecomposedRegex, type DecomposedRegexJson, type DecomposedRegexPart, type DecomposedRegexPartJson, type DecomposedRegexPartResponse, type DecomposedRegexResponse, type DownloadUrls, type ExternalInput, type ExternalInputInput, type ExternalInputResponse, type GenerateProofInputsParams, type GenerateProofInputsParamsInternal, type ListBlueprintsOptions, type ListBlueprintsOptionsRequest, type ParsedEmail, Proof, type ProofData, type ProofProps, type ProofRequest, type ProofResponse, ProofStatus, type ProverOptions, type ServerDate, Status, type ValidationErrors, type VerifierContract, ZkFramework, _default as default, extractEMLDetails, generateProofInputs, getDKIMSelector, getLoginWithGithubUrl, getMaxEmailBodyLength, parseEmail, startJsonFileDownload, testBlueprint, testDecomposedRegex };