@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
@@ -0,0 +1,52 @@
1
+ import { Blueprint } from "./blueprint";
2
+ import { ExternalInputProof, ProofProps, ProofResponse, ProofStatus, PublicProofData } from "./types/proof";
3
+ /**
4
+ * A generated proof. You get get proof data and verify proofs on chain.
5
+ */
6
+ export declare class Proof {
7
+ blueprint: Blueprint;
8
+ props: ProofProps;
9
+ private lastCheckedStatus;
10
+ constructor(blueprint: Blueprint, props: ProofProps);
11
+ getId(): string;
12
+ /**
13
+ * Returns a download link for the files of the proof.
14
+ * @returns The the url to download a zip of the proof files.
15
+ */
16
+ getProofDataDownloadLink(): Promise<string>;
17
+ startFilesDownload(): Promise<void>;
18
+ /**
19
+ * Checks the status of proof.
20
+ * checkStatus can be used in a while(await checkStatus()) loop, since it will wait a fixed
21
+ * amount of time before the second time you call it.
22
+ * @returns A promise with the Status.
23
+ */
24
+ checkStatus(): Promise<ProofStatus>;
25
+ waitForCompletion(): Promise<ProofStatus>;
26
+ /**
27
+ * Verifies the proof on chain using the verifier contract defined in the blueprint.
28
+ * Will throw an error if it cannot verify the proof. If the function call succeeds,
29
+ * the proof was validated.
30
+ */
31
+ verifyOnChain(): Promise<void>;
32
+ /**
33
+ * Generates call data for the proof that can be used to verify the proof on chain.
34
+ */
35
+ createCallData(): Promise<(bigint[] | bigint[][])[]>;
36
+ /**
37
+ * Fetches an existing Proof from the database.
38
+ * @param id - Id of the Proof.
39
+ * @returns A promise that resolves to a new instance of Proof.
40
+ */
41
+ static getProofById(id: string, baseUrl: string): Promise<Proof>;
42
+ static responseToProofProps(response: ProofResponse): ProofProps;
43
+ /**
44
+ * @returns The public data and proof data.
45
+ */
46
+ getProofData(): {
47
+ proofData: string;
48
+ publicData: PublicProofData;
49
+ publicOutputs: string[];
50
+ externalInputs: ExternalInputProof;
51
+ };
52
+ }
@@ -0,0 +1,39 @@
1
+ import { Blueprint } from "./blueprint";
2
+ import { Proof } from "./proof";
3
+ import { ExternalInputInput, ProverOptions } from "./types/prover";
4
+ /**
5
+ * Represents a Prover generated from a blueprint that can generate Proofs
6
+ */
7
+ export declare class Prover {
8
+ options: ProverOptions;
9
+ blueprint: Blueprint;
10
+ constructor(blueprint: Blueprint, options?: ProverOptions);
11
+ /**
12
+ * Generates a proof for a given email.
13
+ * @param eml - Email to prove agains the blueprint of this Prover.
14
+ * @returns A promise that resolves to a new instance of Proof. The Proof will have the status
15
+ * Done or Failed.
16
+ */
17
+ generateProof(eml: string, externalInputs?: ExternalInputInput[]): Promise<Proof>;
18
+ /**
19
+ * Generates inputs needed to generate a proof
20
+ * @param eml - Email to prove agains the blueprint of this Prover.
21
+ * @returns A promise that resolves to the inputs.
22
+ */
23
+ generateProofInputs(eml: string, externalInputs?: ExternalInputInput[]): Promise<string>;
24
+ /**
25
+ * Starts proving for a given email.
26
+ * @param eml - Email to prove agains the blueprint of this Prover.
27
+ * @returns A promise that resolves to a new instance of Proof. The Proof will have the status
28
+ * InProgress.
29
+ */
30
+ generateProofRequest(eml: string, externalInputs?: ExternalInputInput[]): Promise<Proof>;
31
+ /**
32
+ * Starts proving locally for a given email.
33
+ * @param eml - Email to prove agains the blueprint of this Prover.
34
+ * @returns A promise that resolves to a new instance of Proof. The Proof will have the status
35
+ * Done or Failed.
36
+ */
37
+ generateLocalProof(eml: string, externalInputs?: ExternalInputInput[]): Promise<Proof>;
38
+ private _incNumLocalProofs;
39
+ }
@@ -0,0 +1,14 @@
1
+ import { DecomposedRegex, DecomposedRegexJson } from "./blueprint";
2
+ import { BlueprintProps, GenerateProofInputsParams, ParsedEmail, ExternalInputInput, PublicProofData } from "./types";
3
+ export declare function parseEmail(eml: string): Promise<ParsedEmail>;
4
+ export declare function testBlueprint(eml: string, blueprint: BlueprintProps, revealPrivate?: boolean): Promise<string[][]>;
5
+ export declare function testDecomposedRegex(body: string, header: string, decomposedRegex: DecomposedRegex | DecomposedRegexJson, revealPrivate?: boolean): Promise<string[]>;
6
+ export declare function generateProofInputs(eml: string, decomposedRegexes: DecomposedRegex[], externalInputs: ExternalInputInput[], params: GenerateProofInputsParams): Promise<string>;
7
+ export declare function getMaxEmailBodyLength(emlContent: string, shaPrecomputeSelector: string): Promise<number>;
8
+ export declare function extractEMLDetails(emlContent: string): Promise<{
9
+ senderDomain: string | null;
10
+ headerLength: number;
11
+ emailQuery: string;
12
+ emailBodyMaxLength: number;
13
+ }>;
14
+ export declare function parsePublicSignals(publicSignals: string[], decomposedRegexes: DecomposedRegex[]): PublicProofData;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Interface for authentication for creating and updating blueprints
3
+ */
4
+ export type Auth = {
5
+ /**
6
+ * Retrieves the authentication token
7
+ * e.g. from a req for next.js or the localstorage for frontend
8
+ * @returns Promise that resolves to the token string or null if no token exists
9
+ */
10
+ getToken: () => Promise<string | null>;
11
+ /**
12
+ * Callback triggered when the authentication token expires
13
+ * @returns Promise that resolves when expired token is handled
14
+ */
15
+ onTokenExpired: () => Promise<void>;
16
+ };
@@ -0,0 +1,155 @@
1
+ export type BlueprintProps = {
2
+ id?: string;
3
+ title: string;
4
+ description?: string;
5
+ slug?: string;
6
+ tags?: string[];
7
+ emailQuery?: string;
8
+ circuitName: string;
9
+ ignoreBodyHashCheck?: boolean;
10
+ shaPrecomputeSelector?: string;
11
+ emailBodyMaxLength?: number;
12
+ emailHeaderMaxLength?: number;
13
+ removeSoftLinebreaks?: boolean;
14
+ githubUsername?: string;
15
+ senderDomain?: string;
16
+ enableHeaderMasking?: boolean;
17
+ enableBodyMasking?: boolean;
18
+ zkFramework?: ZkFramework;
19
+ isPublic?: boolean;
20
+ createdAt?: Date;
21
+ updatedAt?: Date;
22
+ externalInputs?: ExternalInput[];
23
+ decomposedRegexes: DecomposedRegex[];
24
+ status?: Status;
25
+ verifierContract?: VerifierContract;
26
+ version?: number;
27
+ stars?: number;
28
+ numLocalProofs?: number;
29
+ };
30
+ export type DecomposedRegex = {
31
+ parts: DecomposedRegexPart[];
32
+ name: string;
33
+ maxLength: number;
34
+ location: "body" | "header";
35
+ };
36
+ export type DecomposedRegexPart = {
37
+ isPublic: boolean;
38
+ regexDef: string;
39
+ };
40
+ export type DecomposedRegexJson = {
41
+ parts: DecomposedRegexPartJson[];
42
+ name: string;
43
+ max_length: number;
44
+ location: "body" | "header";
45
+ };
46
+ export type DecomposedRegexPartJson = {
47
+ is_public: boolean;
48
+ regex_def: string;
49
+ };
50
+ export type ExternalInput = {
51
+ name: string;
52
+ maxLength: number;
53
+ };
54
+ export declare enum ZkFramework {
55
+ Circom = "circom"
56
+ }
57
+ export declare enum Status {
58
+ None = 0,
59
+ Draft = 1,
60
+ InProgress = 2,
61
+ Done = 3,
62
+ Failed = 4
63
+ }
64
+ export type VerifierContract = {
65
+ address?: string;
66
+ chain: number;
67
+ };
68
+ export type BlueprintRequest = {
69
+ id?: string;
70
+ title: string;
71
+ description?: string;
72
+ slug?: string;
73
+ tags?: string[];
74
+ email_query?: string;
75
+ circuit_name?: string;
76
+ ignore_body_hash_check?: boolean;
77
+ sha_precompute_selector?: string;
78
+ email_body_max_length?: number;
79
+ email_header_max_length?: number;
80
+ remove_soft_linebreaks?: boolean;
81
+ github_username?: string;
82
+ sender_domain?: string;
83
+ enable_header_masking?: boolean;
84
+ enable_body_masking?: boolean;
85
+ zk_framework?: string;
86
+ is_public?: boolean;
87
+ external_inputs?: ExternalInputResponse[];
88
+ decomposed_regexes: DecomposedRegexResponse[];
89
+ status?: string;
90
+ verifier_contract_address?: string;
91
+ verifier_contract_chain?: number;
92
+ version?: number;
93
+ };
94
+ export type BlueprintResponse = {
95
+ id: string;
96
+ title: string;
97
+ description: string;
98
+ slug: string;
99
+ tags: string[];
100
+ email_query: string;
101
+ circuit_name: string;
102
+ ignore_body_hash_check: boolean;
103
+ sha_precompute_selector: string;
104
+ email_body_max_length: number;
105
+ email_header_max_length?: number;
106
+ remove_soft_linebreaks?: boolean;
107
+ github_username?: string;
108
+ sender_domain: string;
109
+ enable_header_masking?: boolean;
110
+ enable_body_masking?: boolean;
111
+ zk_framework: string;
112
+ is_public: boolean;
113
+ created_at: ServerDate;
114
+ updated_at: ServerDate;
115
+ external_inputs: ExternalInputResponse[];
116
+ decomposed_regexes: DecomposedRegexResponse[];
117
+ status: number;
118
+ verifier_contract_address: string;
119
+ verifier_contract_chain: number;
120
+ version: number;
121
+ stars: number;
122
+ num_local_proofs: number;
123
+ };
124
+ export type ServerDate = {
125
+ seconds: number;
126
+ nanos: number;
127
+ };
128
+ export type ExternalInputResponse = {
129
+ name: string;
130
+ max_length: number;
131
+ };
132
+ export type DecomposedRegexResponse = {
133
+ parts: DecomposedRegexPartResponse[];
134
+ name: string;
135
+ max_length: number;
136
+ location: "body" | "header";
137
+ };
138
+ export type DecomposedRegexPartResponse = {
139
+ is_public: boolean;
140
+ regex_def: string;
141
+ };
142
+ export type ListBlueprintsOptions = {
143
+ skip?: number;
144
+ limit?: number;
145
+ sort?: -1 | 1;
146
+ sortBy?: "updatedAt" | "stars";
147
+ status?: Status[];
148
+ isPublic?: boolean;
149
+ search?: string;
150
+ };
151
+ export type DownloadUrls = Record<string, string>;
152
+ export type ChunkedZkeyUrl = {
153
+ url: string;
154
+ suffix: "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k";
155
+ };
@@ -0,0 +1,6 @@
1
+ export * from "./auth";
2
+ export * from "./blueprint";
3
+ export * from "./proof";
4
+ export * from "./prover";
5
+ export * from "./sdk";
6
+ export * from "./utils";
@@ -0,0 +1,63 @@
1
+ import { ServerDate } from "./blueprint";
2
+ export declare enum ProofStatus {
3
+ None = 0,
4
+ InProgress = 1,
5
+ Done = 2,
6
+ Failed = 3
7
+ }
8
+ export type PublicProofData = {
9
+ [key: string]: string[];
10
+ };
11
+ export type ExternalInputProof = {
12
+ [key: string]: string;
13
+ };
14
+ export type ProofProps = {
15
+ id: string;
16
+ blueprintId: string;
17
+ input: string;
18
+ proofData?: string;
19
+ publicData?: PublicProofData;
20
+ publicOutputs?: string[];
21
+ externalInputs?: ExternalInputProof;
22
+ status?: ProofStatus;
23
+ startedAt?: Date;
24
+ provedAt?: Date;
25
+ isLocal: boolean;
26
+ };
27
+ export type ProofResponse = {
28
+ id: string;
29
+ blueprint_id: string;
30
+ input: string;
31
+ proof?: string;
32
+ public?: PublicProofData;
33
+ external_inputs?: ExternalInputProof;
34
+ public_outputs?: string[];
35
+ started_at: ServerDate;
36
+ proved_at?: ServerDate;
37
+ status: number;
38
+ };
39
+ export type ProofRequest = {
40
+ blueprint_id: string;
41
+ input: any;
42
+ external_inputs: any;
43
+ };
44
+ export type GenerateProofInputsParams = {
45
+ emailHeaderMaxLength: number;
46
+ emailBodyMaxLength: number;
47
+ ignoreBodyHashCheck: boolean;
48
+ removeSoftLinebreaks: boolean;
49
+ shaPrecomputeSelector?: string;
50
+ };
51
+ export type GenerateProofInputsParamsInternal = {
52
+ maxHeaderLength: number;
53
+ maxBodyLength: number;
54
+ ignoreBodyHashCheck: boolean;
55
+ removeSoftLinesBreaks: boolean;
56
+ shaPrecomputeSelector?: string;
57
+ };
58
+ export type ProofData = {
59
+ pi_a: [string, string, string];
60
+ pi_b: [[string, string], [string, string], [string, string]];
61
+ pi_c: [string, string, string];
62
+ protocol: string;
63
+ };
@@ -0,0 +1,8 @@
1
+ export type ProverOptions = {
2
+ isLocal: boolean;
3
+ };
4
+ export type ExternalInputInput = {
5
+ name: string;
6
+ value: string;
7
+ maxLength: number;
8
+ };
@@ -0,0 +1,5 @@
1
+ import { Auth } from "./auth";
2
+ export type SdkOptions = {
3
+ auth?: Auth;
4
+ baseUrl?: string;
5
+ };
@@ -0,0 +1,8 @@
1
+ export type ParsedEmail = {
2
+ canonicalizedHeader: string;
3
+ canonicalizedBody: string;
4
+ signature: number[];
5
+ publicKey: any[];
6
+ cleanedBody: string;
7
+ headers: Map<string, string[]>;
8
+ };
@@ -0,0 +1,5 @@
1
+ import { Auth } from "./types";
2
+ /**
3
+ * @returns An array of slugs that the user starred
4
+ */
5
+ export declare function getStarredBlueprints(baseUrl: string, auth: Auth): Promise<string[]>;
@@ -0,0 +1,7 @@
1
+ import { Auth } from "./types/auth";
2
+ export declare function post<T>(url: string, data?: object | null, auth?: Auth): Promise<T>;
3
+ export declare function patch<T>(url: string, data?: object | null, auth?: Auth): Promise<T>;
4
+ export declare function get<T>(url: string, queryParams?: object | null, auth?: Auth): Promise<T>;
5
+ export declare function del<T>(url: string, data?: object | null, auth?: Auth): Promise<T>;
6
+ export declare function startJsonFileDownload(json: string, name?: string): void;
7
+ export declare function getDKIMSelector(emlContent: string): string | null;
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-76VwpgoI.js");exports.Blueprint=e.Blueprint;exports.Proof=e.Proof;Object.defineProperty(exports,"ProofStatus",{enumerable:!0,get:()=>e.ProofStatus});Object.defineProperty(exports,"Status",{enumerable:!0,get:()=>e.Status});Object.defineProperty(exports,"ZkFramework",{enumerable:!0,get:()=>e.ZkFramework});exports.ZodError=e.ZodError;exports.default=e.index;exports.generateProofInputs=e.generateProofInputs;exports.getDKIMSelector=e.getDKIMSelector;exports.getLoginWithGithubUrl=e.getLoginWithGithubUrl;exports.parseEmail=e.parseEmail;exports.startJsonFileDownload=e.startJsonFileDownload;exports.testBlueprint=e.testBlueprint;exports.testDecomposedRegex=e.testDecomposedRegex;
2
+ //# sourceMappingURL=zk-email-sdk.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zk-email-sdk.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ import { h as t, P as e, q as o, S as r, o as l, Z as n, f as i, l as p, k as u, n as f, p as g, j as m, m as d, t as P } from "./index-BBAkhu6Z.mjs";
2
+ export {
3
+ t as Blueprint,
4
+ e as Proof,
5
+ o as ProofStatus,
6
+ r as Status,
7
+ l as ZkFramework,
8
+ n as ZodError,
9
+ i as default,
10
+ p as generateProofInputs,
11
+ u as getDKIMSelector,
12
+ f as getLoginWithGithubUrl,
13
+ g as parseEmail,
14
+ m as startJsonFileDownload,
15
+ d as testBlueprint,
16
+ P as testDecomposedRegex
17
+ };
18
+ //# sourceMappingURL=zk-email-sdk.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zk-email-sdk.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@zk-email/sdk",
3
- "version": "0.0.86",
3
+ "version": "0.0.88",
4
4
  "description": "ZK Email SDK for TypeScript",
5
5
  "main": "./dist/index.js",
6
- "module": "./dist/index.mjs",
7
- "types": "./dist/index.d.ts",
6
+ "module": "./dist/zk-email-sdk.es.js",
7
+ "types": "./dist/types/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "require": "./dist/index.js",
11
- "import": "./dist/index.mjs",
12
- "types": "./dist/index.d.ts"
10
+ "require": "./dist/zk-email-sdk.cjs.js",
11
+ "import": "./dist/zk-email-sdk.es.js",
12
+ "types": "./dist/types/index.d.ts"
13
13
  }
14
14
  },
15
15
  "files": [
@@ -17,13 +17,15 @@
17
17
  "README.md"
18
18
  ],
19
19
  "scripts": {
20
- "build": "bunx tsup",
20
+ "build-old": "bunx tsup src/index.ts src/localProverWorker.ts --format esm,cjs --dts",
21
+ "build": "vite build",
22
+ "build-prove-worker": "bun x vite build --config vite.config.worker.ts && bun scripts/escape_str_chars.js",
23
+ "publish": "bun run build && npm publish --access public",
21
24
  "typecheck": "tsc --noEmit",
22
25
  "test": "echo \"Error: no test specified\" && exit 1",
23
26
  "prepublishOnly": "bun run build",
24
27
  "clean": "rm -rf dist",
25
- "publish": "npm publish --access public",
26
- "publish-nightly": "npm publish --access public --tag nightly"
28
+ "publish-nightly": "bun run build && npm publish --access public --tag nightly"
27
29
  },
28
30
  "keywords": [
29
31
  "zk",
@@ -34,18 +36,30 @@
34
36
  "author": "",
35
37
  "license": "MIT",
36
38
  "devDependencies": {
39
+ "@esbuild-plugins/node-globals-polyfill": "^0.2.3",
40
+ "@rollup/plugin-typescript": "^12.1.2",
37
41
  "@types/bun": "^1.1.12",
38
42
  "@types/pg": "^8.11.10",
39
43
  "open": "^10.1.0",
40
44
  "pg": "^8.13.0",
41
45
  "prettier": "^3.3.3",
42
- "tsup": "^8.3.5"
46
+ "rollup-plugin-node-polyfills": "^0.2.1",
47
+ "vite": "^6.0.7",
48
+ "vite-plugin-commonjs": "^0.10.4",
49
+ "crypto-browserify": "^3.12.1",
50
+ "stream-browserify": "^3.0.0",
51
+ "buffer": "^6.0.3",
52
+ "vite-plugin-replace": "^0.1.1",
53
+ "localforage": "^1.10.0",
54
+ "localforage-memoryStorageDriver": "^0.9.2",
55
+ "pako": "^2.1.0",
56
+ "snarkjs": "https://github.com/sampritipanda/snarkjs.git#fef81fc51d17a734637555c6edbd585ecda02d9e"
43
57
  },
44
58
  "peerDependencies": {
45
59
  "typescript": "^5.0.0"
46
60
  },
47
61
  "dependencies": {
48
- "@zk-email/relayer-utils": "0.4.59",
62
+ "@zk-email/relayer-utils": "0.4.60",
49
63
  "ethers": "^6.13.4",
50
64
  "viem": "^2.21.53",
51
65
  "zod": "^3.23.8"