@zk-email/sdk 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +39 -0
- package/dist/index.d.mts +388 -0
- package/dist/index.d.ts +388 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +50 -0
package/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# zk-email-sdk-js
|
2
|
+
|
3
|
+
With the ZK Email SDK you can easily compile zk regex circuits and directly create proofs with them.
|
4
|
+
|
5
|
+
## Test a decomposed regex locally
|
6
|
+
|
7
|
+
Currently only works with bun. Install Bun:
|
8
|
+
|
9
|
+
`brew install oven-sh/bun/bun`.
|
10
|
+
|
11
|
+
Install dependencies:
|
12
|
+
|
13
|
+
`bun i`
|
14
|
+
|
15
|
+
Run example:
|
16
|
+
|
17
|
+
`bun example.ts`
|
18
|
+
|
19
|
+
## Note
|
20
|
+
|
21
|
+
This first version of this SDK does not support compiling the circuits and running the proofs without our infra,
|
22
|
+
but it is our priority to make this work with your own ifra easily, too.
|
23
|
+
|
24
|
+
## Setup
|
25
|
+
|
26
|
+
This project uses bun. So to install packages use `bun i`.
|
27
|
+
|
28
|
+
## Run integration tests
|
29
|
+
|
30
|
+
Before you can run the tests, you must have the conductor running.
|
31
|
+
|
32
|
+
Then you can run `bun test`.
|
33
|
+
|
34
|
+
### Directly start downloads
|
35
|
+
|
36
|
+
To run the `start download` test, you first have to compile the TypeScript files to js with `bun run build`.
|
37
|
+
|
38
|
+
If you have python installed run `python -m http.server 8000`. Then you can go to
|
39
|
+
`http://localhost:8000/integration_tests/start_downlaod_in_browser.html` and click the download button.
|
package/dist/index.d.mts
ADDED
@@ -0,0 +1,388 @@
|
|
1
|
+
import { Proof as Proof$1 } from 'viem/_types/types/proof';
|
2
|
+
|
3
|
+
type BlueprintProps = {
|
4
|
+
id?: string;
|
5
|
+
title: string;
|
6
|
+
description?: string;
|
7
|
+
slug?: string;
|
8
|
+
tags?: string[];
|
9
|
+
emailQuery?: string;
|
10
|
+
circuitName: string;
|
11
|
+
ignoreBodyHashCheck?: boolean;
|
12
|
+
shaPrecomputeSelector?: string;
|
13
|
+
emailBodyMaxLength?: number;
|
14
|
+
emailHeaderMaxLength?: number;
|
15
|
+
removeSoftLinebreaks?: boolean;
|
16
|
+
githubUsername?: string;
|
17
|
+
senderDomain?: string;
|
18
|
+
enableHeaderMasking?: boolean;
|
19
|
+
enableBodyMasking?: boolean;
|
20
|
+
zkFramework?: ZkFramework;
|
21
|
+
isPublic?: boolean;
|
22
|
+
createdAt?: Date;
|
23
|
+
updatedAt?: Date;
|
24
|
+
externalInputs?: ExternalInput[];
|
25
|
+
decomposedRegexes: DecomposedRegex[];
|
26
|
+
status?: Status;
|
27
|
+
verifierContract?: VerifierContract;
|
28
|
+
version?: number;
|
29
|
+
};
|
30
|
+
type DecomposedRegex = {
|
31
|
+
parts: DecomposedRegexPart[];
|
32
|
+
name: string;
|
33
|
+
maxLength: number;
|
34
|
+
location: "body" | "header";
|
35
|
+
};
|
36
|
+
type DecomposedRegexPart = {
|
37
|
+
isPublic: boolean;
|
38
|
+
regexDef: string;
|
39
|
+
};
|
40
|
+
type DecomposedRegexJson = {
|
41
|
+
parts: DecomposedRegexPartJson[];
|
42
|
+
name: string;
|
43
|
+
max_length: number;
|
44
|
+
location: "body" | "header";
|
45
|
+
};
|
46
|
+
type DecomposedRegexPartJson = {
|
47
|
+
is_public: boolean;
|
48
|
+
regex_def: string;
|
49
|
+
};
|
50
|
+
type ExternalInput = {
|
51
|
+
name: string;
|
52
|
+
maxLength: number;
|
53
|
+
};
|
54
|
+
declare enum ZkFramework {
|
55
|
+
Circom = "circom"
|
56
|
+
}
|
57
|
+
declare enum Status {
|
58
|
+
None = 0,
|
59
|
+
Draft = 1,
|
60
|
+
InProgress = 2,
|
61
|
+
Done = 3,
|
62
|
+
Failed = 4
|
63
|
+
}
|
64
|
+
type VerifierContract = {
|
65
|
+
address?: string;
|
66
|
+
chain: number;
|
67
|
+
};
|
68
|
+
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
|
+
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
|
+
};
|
122
|
+
type ServerDate = {
|
123
|
+
seconds: number;
|
124
|
+
nanos: number;
|
125
|
+
};
|
126
|
+
type ExternalInputResponse = {
|
127
|
+
name: string;
|
128
|
+
max_length: number;
|
129
|
+
};
|
130
|
+
type DecomposedRegexResponse = {
|
131
|
+
parts: DecomposedRegexPartResponse[];
|
132
|
+
name: string;
|
133
|
+
max_length: number;
|
134
|
+
location: "body" | "header";
|
135
|
+
};
|
136
|
+
type DecomposedRegexPartResponse = {
|
137
|
+
is_public: boolean;
|
138
|
+
regex_def: string;
|
139
|
+
};
|
140
|
+
type ListBlueprintsOptions = {
|
141
|
+
skip?: number;
|
142
|
+
limit?: number;
|
143
|
+
sort?: -1 | 1;
|
144
|
+
status?: Status;
|
145
|
+
isPublic?: boolean;
|
146
|
+
search?: string;
|
147
|
+
};
|
148
|
+
type ListBlueprintsOptionsRequest = {
|
149
|
+
skip?: number;
|
150
|
+
limit?: number;
|
151
|
+
sort?: -1 | 1;
|
152
|
+
status?: Status;
|
153
|
+
is_public?: boolean;
|
154
|
+
search?: string;
|
155
|
+
};
|
156
|
+
|
157
|
+
declare enum ProofStatus {
|
158
|
+
None = 0,
|
159
|
+
InProgress = 1,
|
160
|
+
Done = 2,
|
161
|
+
Failed = 3
|
162
|
+
}
|
163
|
+
type ProofProps = {
|
164
|
+
id: string;
|
165
|
+
status?: ProofStatus;
|
166
|
+
circuitInput?: string;
|
167
|
+
startedAt?: Date;
|
168
|
+
provenAt?: Date;
|
169
|
+
};
|
170
|
+
type ProofResponse = {
|
171
|
+
id: string;
|
172
|
+
blueprint_id: string;
|
173
|
+
circuit_input: string;
|
174
|
+
started_at: ServerDate;
|
175
|
+
proven_at?: ServerDate;
|
176
|
+
status: string;
|
177
|
+
};
|
178
|
+
type ProofRequest = {
|
179
|
+
blueprint_id: string;
|
180
|
+
circuit_input: string;
|
181
|
+
};
|
182
|
+
|
183
|
+
/**
|
184
|
+
* A generated proof. You get get proof data and verify proofs on chain.
|
185
|
+
*/
|
186
|
+
declare class Proof {
|
187
|
+
blueprint: Blueprint;
|
188
|
+
props: ProofProps;
|
189
|
+
private lastCheckedStatus;
|
190
|
+
constructor(blueprint: Blueprint, props: ProofProps);
|
191
|
+
getId(): string;
|
192
|
+
/**
|
193
|
+
* Returns a download link for the files of the proof.
|
194
|
+
* @returns The the url to download a zip of the proof files.
|
195
|
+
*/
|
196
|
+
getProofDataDownloadLink(): Promise<string>;
|
197
|
+
startFilesDownload(): Promise<void>;
|
198
|
+
/**
|
199
|
+
* Checks the status of proof.
|
200
|
+
* checkStatus can be used in a while(await checkStatus()) loop, since it will wait a fixed
|
201
|
+
* amount of time before the second time you call it.
|
202
|
+
* @returns A promise with the Status.
|
203
|
+
*/
|
204
|
+
checkStatus(): Promise<ProofStatus>;
|
205
|
+
verifyOnChain(): Promise<void>;
|
206
|
+
/**
|
207
|
+
* Fetches an existing Proof from the database.
|
208
|
+
* @param id - Id of the Proof.
|
209
|
+
* @returns A promise that resolves to a new instance of Proof.
|
210
|
+
*/
|
211
|
+
static getPoofById(id: string): Promise<Proof>;
|
212
|
+
static responseToProofProps(response: ProofResponse): ProofProps;
|
213
|
+
}
|
214
|
+
|
215
|
+
type ProverOptions = {
|
216
|
+
isLocal: boolean;
|
217
|
+
};
|
218
|
+
|
219
|
+
/**
|
220
|
+
* Represents a Prover generated from a blueprint that can generate Proofs
|
221
|
+
*/
|
222
|
+
declare class Prover {
|
223
|
+
options: ProverOptions;
|
224
|
+
blueprint: Blueprint;
|
225
|
+
constructor(blueprint: Blueprint, options?: ProverOptions);
|
226
|
+
/**
|
227
|
+
* Generates a proof for a given email.
|
228
|
+
* @param eml - Email to prove agains the blueprint of this Prover.
|
229
|
+
* @returns A promise that resolves to a new instance of Proof. The Proof will have the status
|
230
|
+
* Done or Failed.
|
231
|
+
*/
|
232
|
+
generateProof(eml: string): Promise<Proof>;
|
233
|
+
/**
|
234
|
+
* Starts proving for a given email.
|
235
|
+
* @param eml - Email to prove agains the blueprint of this Prover.
|
236
|
+
* @returns A promise that resolves to a new instance of Proof. The Proof will have the status
|
237
|
+
* InProgress.
|
238
|
+
*/
|
239
|
+
generateProofRequest(eml: string): Promise<Proof>;
|
240
|
+
}
|
241
|
+
|
242
|
+
/**
|
243
|
+
* Interface for authentication for creating and updating blueprints
|
244
|
+
*/
|
245
|
+
interface Auth {
|
246
|
+
/**
|
247
|
+
* Retrieves the authentication token
|
248
|
+
* e.g. from a req for next.js or the localstorage for frontend
|
249
|
+
* @returns Promise that resolves to the token string or null if no token exists
|
250
|
+
*/
|
251
|
+
getToken: () => Promise<string | null>;
|
252
|
+
/**
|
253
|
+
* Callback triggered when the authentication token expires
|
254
|
+
* @returns Promise that resolves when expired token is handled
|
255
|
+
*/
|
256
|
+
onTokenExpired: () => Promise<void>;
|
257
|
+
}
|
258
|
+
|
259
|
+
/**
|
260
|
+
* Represents a Regex Blueprint including the decomposed regex access to the circuit.
|
261
|
+
*/
|
262
|
+
declare class Blueprint {
|
263
|
+
props: BlueprintProps;
|
264
|
+
auth?: Auth;
|
265
|
+
private lastCheckedStatus;
|
266
|
+
constructor(props: BlueprintProps, auth?: Auth);
|
267
|
+
addAuth(auth: Auth): void;
|
268
|
+
/**
|
269
|
+
* Fetches an existing RegexBlueprint from the database.
|
270
|
+
* @param {string} id - Id of the RegexBlueprint.
|
271
|
+
* @returns A promise that resolves to a new instance of RegexBlueprint.
|
272
|
+
*/
|
273
|
+
static getBlueprintById(id: string, auth?: Auth): Promise<Blueprint>;
|
274
|
+
private static responseToBlueprintProps;
|
275
|
+
private static blueprintPropsToRequest;
|
276
|
+
/**
|
277
|
+
* Submits a new RegexBlueprint to the registry as draft.
|
278
|
+
* This does not compile the circuits yet and you will still be able to make changes.
|
279
|
+
* @returns A promise. Once it resolves, `getId` can be called.
|
280
|
+
*/
|
281
|
+
submitDraft(): Promise<void>;
|
282
|
+
/**
|
283
|
+
* Submits a new version of the RegexBlueprint to the registry as draft.
|
284
|
+
* This does not compile the circuits yet and you will still be able to make changes.
|
285
|
+
* @param newProps - The updated blueprint props.
|
286
|
+
* @returns A promise. Once it resolves, the current Blueprint will be replaced with the new one.
|
287
|
+
*/
|
288
|
+
submitNewVersionDraft(newProps: BlueprintProps): Promise<void>;
|
289
|
+
/**
|
290
|
+
* Submits a new version of the blueprint. This will save the new blueprint version
|
291
|
+
* and start the compilation.
|
292
|
+
* This will also overwrite the current Blueprint with its new version, even if the last
|
293
|
+
* version was not compiled yet.
|
294
|
+
* @param newProps - The updated blueprint props.
|
295
|
+
*/
|
296
|
+
submitNewVersion(newProps: BlueprintProps): Promise<void>;
|
297
|
+
/**
|
298
|
+
* Lists blueblueprints, only including the latest version per unique slug.
|
299
|
+
* @param options - Options to filter the blueprints by.
|
300
|
+
* @returns A promise. Once it resolves, `getId` can be called.
|
301
|
+
*/
|
302
|
+
static listBlueprints(options?: ListBlueprintsOptions, auth?: Auth): Promise<Blueprint[]>;
|
303
|
+
/**
|
304
|
+
* Submits a blueprint. This will save the blueprint if it didn't exist before
|
305
|
+
* and start the compilation.
|
306
|
+
*/
|
307
|
+
submit(): Promise<void>;
|
308
|
+
private _checkStatus;
|
309
|
+
/**
|
310
|
+
* Checks the status of blueprint.
|
311
|
+
* checkStatus can be used in a while(await checkStatus()) loop, since it will wait a fixed
|
312
|
+
* amount of time the second time you call it.
|
313
|
+
* @returns A promise with the Status.
|
314
|
+
*/
|
315
|
+
checkStatus(): Promise<Status>;
|
316
|
+
/**
|
317
|
+
* Get the id of the blueprint.
|
318
|
+
* @returns The id of the blueprint. If it was not saved yet, return null.
|
319
|
+
*/
|
320
|
+
getId(): string | null;
|
321
|
+
/**
|
322
|
+
* Returns a download link for the ZKeys of the blueprint.
|
323
|
+
* @returns The the url to download the ZKeys.
|
324
|
+
*/
|
325
|
+
getZKeyDownloadLink(): Promise<string>;
|
326
|
+
/**
|
327
|
+
* Directly starts a download of the ZKeys in the browser.
|
328
|
+
* Must be called within a user action, like a button click.
|
329
|
+
*/
|
330
|
+
startZKeyDownload(): Promise<void>;
|
331
|
+
/**
|
332
|
+
* Creates an instance of Prover with which you can create proofs.
|
333
|
+
* @returns An instance of Prover.
|
334
|
+
*/
|
335
|
+
createProver(): Prover;
|
336
|
+
/**
|
337
|
+
* Verifies a proof on chain.
|
338
|
+
* @param proof - The generated proof you want to verify.
|
339
|
+
* @returns A true if the verification was successfull, false if it failed.
|
340
|
+
*/
|
341
|
+
verifyProofOnChain(proof: Proof$1): Promise<boolean>;
|
342
|
+
/**
|
343
|
+
* Returns a deep cloned version of the Blueprints props.
|
344
|
+
* This can be used to update properties and then to use them with createNewVersion.
|
345
|
+
* @param proof - The generated proof you want to verify.
|
346
|
+
* @returns A true if the verification was successfull, false if it failed.
|
347
|
+
*/
|
348
|
+
getClonedProps(): BlueprintProps;
|
349
|
+
/**
|
350
|
+
* Returns true if the blueprint can be updated. A blueprint can be updated if the circuits
|
351
|
+
* haven't beed compiled yet, i.e. the status is not Done. The blueprint also must be saved
|
352
|
+
* already before it can be updated.
|
353
|
+
* @returns true if it can be updated
|
354
|
+
*/
|
355
|
+
canUpdate(): boolean;
|
356
|
+
/**
|
357
|
+
* Updates an existing blueprint that is not compiled yet.
|
358
|
+
* @param newProps - The props the blueprint should be updated to.
|
359
|
+
* @returns a promise.
|
360
|
+
*/
|
361
|
+
update(newProps: BlueprintProps): Promise<void>;
|
362
|
+
listAllVersions(): Promise<Blueprint[]>;
|
363
|
+
}
|
364
|
+
|
365
|
+
type SdkOptions = {
|
366
|
+
auth?: Auth;
|
367
|
+
};
|
368
|
+
|
369
|
+
type ParsedEmail = {
|
370
|
+
canonicalized_header: string;
|
371
|
+
canonicalized_body: string;
|
372
|
+
signature: number[];
|
373
|
+
public_key: any[];
|
374
|
+
cleaned_body: string;
|
375
|
+
headers: Map<string, string[]>;
|
376
|
+
};
|
377
|
+
declare function parseEmail(eml: string): Promise<ParsedEmail>;
|
378
|
+
declare function testDecomposedRegex(eml: string, decomposedRegex: DecomposedRegex | DecomposedRegexJson, revealPrivate?: boolean): Promise<string[]>;
|
379
|
+
|
380
|
+
declare function getLoginWithGithubUrl(callbackUrl: string): string;
|
381
|
+
|
382
|
+
declare const _default: (sdkOptions?: SdkOptions) => {
|
383
|
+
createBlueprint(props: BlueprintProps): Blueprint;
|
384
|
+
getBlueprint(id: string): Promise<Blueprint>;
|
385
|
+
listBlueprints(options?: ListBlueprintsOptions): Promise<Blueprint[]>;
|
386
|
+
};
|
387
|
+
|
388
|
+
export { type Auth, Blueprint, type BlueprintProps, type BlueprintRequest, type BlueprintResponse, type DecomposedRegex, type DecomposedRegexJson, type DecomposedRegexPart, type DecomposedRegexPartJson, type DecomposedRegexPartResponse, type DecomposedRegexResponse, type ExternalInput, type ExternalInputResponse, type ListBlueprintsOptions, type ListBlueprintsOptionsRequest, Proof, type ProofProps, type ProofRequest, type ProofResponse, ProofStatus, type ServerDate, Status, type VerifierContract, ZkFramework, _default as default, getLoginWithGithubUrl, parseEmail, testDecomposedRegex };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,388 @@
|
|
1
|
+
import { Proof as Proof$1 } from 'viem/_types/types/proof';
|
2
|
+
|
3
|
+
type BlueprintProps = {
|
4
|
+
id?: string;
|
5
|
+
title: string;
|
6
|
+
description?: string;
|
7
|
+
slug?: string;
|
8
|
+
tags?: string[];
|
9
|
+
emailQuery?: string;
|
10
|
+
circuitName: string;
|
11
|
+
ignoreBodyHashCheck?: boolean;
|
12
|
+
shaPrecomputeSelector?: string;
|
13
|
+
emailBodyMaxLength?: number;
|
14
|
+
emailHeaderMaxLength?: number;
|
15
|
+
removeSoftLinebreaks?: boolean;
|
16
|
+
githubUsername?: string;
|
17
|
+
senderDomain?: string;
|
18
|
+
enableHeaderMasking?: boolean;
|
19
|
+
enableBodyMasking?: boolean;
|
20
|
+
zkFramework?: ZkFramework;
|
21
|
+
isPublic?: boolean;
|
22
|
+
createdAt?: Date;
|
23
|
+
updatedAt?: Date;
|
24
|
+
externalInputs?: ExternalInput[];
|
25
|
+
decomposedRegexes: DecomposedRegex[];
|
26
|
+
status?: Status;
|
27
|
+
verifierContract?: VerifierContract;
|
28
|
+
version?: number;
|
29
|
+
};
|
30
|
+
type DecomposedRegex = {
|
31
|
+
parts: DecomposedRegexPart[];
|
32
|
+
name: string;
|
33
|
+
maxLength: number;
|
34
|
+
location: "body" | "header";
|
35
|
+
};
|
36
|
+
type DecomposedRegexPart = {
|
37
|
+
isPublic: boolean;
|
38
|
+
regexDef: string;
|
39
|
+
};
|
40
|
+
type DecomposedRegexJson = {
|
41
|
+
parts: DecomposedRegexPartJson[];
|
42
|
+
name: string;
|
43
|
+
max_length: number;
|
44
|
+
location: "body" | "header";
|
45
|
+
};
|
46
|
+
type DecomposedRegexPartJson = {
|
47
|
+
is_public: boolean;
|
48
|
+
regex_def: string;
|
49
|
+
};
|
50
|
+
type ExternalInput = {
|
51
|
+
name: string;
|
52
|
+
maxLength: number;
|
53
|
+
};
|
54
|
+
declare enum ZkFramework {
|
55
|
+
Circom = "circom"
|
56
|
+
}
|
57
|
+
declare enum Status {
|
58
|
+
None = 0,
|
59
|
+
Draft = 1,
|
60
|
+
InProgress = 2,
|
61
|
+
Done = 3,
|
62
|
+
Failed = 4
|
63
|
+
}
|
64
|
+
type VerifierContract = {
|
65
|
+
address?: string;
|
66
|
+
chain: number;
|
67
|
+
};
|
68
|
+
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
|
+
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
|
+
};
|
122
|
+
type ServerDate = {
|
123
|
+
seconds: number;
|
124
|
+
nanos: number;
|
125
|
+
};
|
126
|
+
type ExternalInputResponse = {
|
127
|
+
name: string;
|
128
|
+
max_length: number;
|
129
|
+
};
|
130
|
+
type DecomposedRegexResponse = {
|
131
|
+
parts: DecomposedRegexPartResponse[];
|
132
|
+
name: string;
|
133
|
+
max_length: number;
|
134
|
+
location: "body" | "header";
|
135
|
+
};
|
136
|
+
type DecomposedRegexPartResponse = {
|
137
|
+
is_public: boolean;
|
138
|
+
regex_def: string;
|
139
|
+
};
|
140
|
+
type ListBlueprintsOptions = {
|
141
|
+
skip?: number;
|
142
|
+
limit?: number;
|
143
|
+
sort?: -1 | 1;
|
144
|
+
status?: Status;
|
145
|
+
isPublic?: boolean;
|
146
|
+
search?: string;
|
147
|
+
};
|
148
|
+
type ListBlueprintsOptionsRequest = {
|
149
|
+
skip?: number;
|
150
|
+
limit?: number;
|
151
|
+
sort?: -1 | 1;
|
152
|
+
status?: Status;
|
153
|
+
is_public?: boolean;
|
154
|
+
search?: string;
|
155
|
+
};
|
156
|
+
|
157
|
+
declare enum ProofStatus {
|
158
|
+
None = 0,
|
159
|
+
InProgress = 1,
|
160
|
+
Done = 2,
|
161
|
+
Failed = 3
|
162
|
+
}
|
163
|
+
type ProofProps = {
|
164
|
+
id: string;
|
165
|
+
status?: ProofStatus;
|
166
|
+
circuitInput?: string;
|
167
|
+
startedAt?: Date;
|
168
|
+
provenAt?: Date;
|
169
|
+
};
|
170
|
+
type ProofResponse = {
|
171
|
+
id: string;
|
172
|
+
blueprint_id: string;
|
173
|
+
circuit_input: string;
|
174
|
+
started_at: ServerDate;
|
175
|
+
proven_at?: ServerDate;
|
176
|
+
status: string;
|
177
|
+
};
|
178
|
+
type ProofRequest = {
|
179
|
+
blueprint_id: string;
|
180
|
+
circuit_input: string;
|
181
|
+
};
|
182
|
+
|
183
|
+
/**
|
184
|
+
* A generated proof. You get get proof data and verify proofs on chain.
|
185
|
+
*/
|
186
|
+
declare class Proof {
|
187
|
+
blueprint: Blueprint;
|
188
|
+
props: ProofProps;
|
189
|
+
private lastCheckedStatus;
|
190
|
+
constructor(blueprint: Blueprint, props: ProofProps);
|
191
|
+
getId(): string;
|
192
|
+
/**
|
193
|
+
* Returns a download link for the files of the proof.
|
194
|
+
* @returns The the url to download a zip of the proof files.
|
195
|
+
*/
|
196
|
+
getProofDataDownloadLink(): Promise<string>;
|
197
|
+
startFilesDownload(): Promise<void>;
|
198
|
+
/**
|
199
|
+
* Checks the status of proof.
|
200
|
+
* checkStatus can be used in a while(await checkStatus()) loop, since it will wait a fixed
|
201
|
+
* amount of time before the second time you call it.
|
202
|
+
* @returns A promise with the Status.
|
203
|
+
*/
|
204
|
+
checkStatus(): Promise<ProofStatus>;
|
205
|
+
verifyOnChain(): Promise<void>;
|
206
|
+
/**
|
207
|
+
* Fetches an existing Proof from the database.
|
208
|
+
* @param id - Id of the Proof.
|
209
|
+
* @returns A promise that resolves to a new instance of Proof.
|
210
|
+
*/
|
211
|
+
static getPoofById(id: string): Promise<Proof>;
|
212
|
+
static responseToProofProps(response: ProofResponse): ProofProps;
|
213
|
+
}
|
214
|
+
|
215
|
+
type ProverOptions = {
|
216
|
+
isLocal: boolean;
|
217
|
+
};
|
218
|
+
|
219
|
+
/**
|
220
|
+
* Represents a Prover generated from a blueprint that can generate Proofs
|
221
|
+
*/
|
222
|
+
declare class Prover {
|
223
|
+
options: ProverOptions;
|
224
|
+
blueprint: Blueprint;
|
225
|
+
constructor(blueprint: Blueprint, options?: ProverOptions);
|
226
|
+
/**
|
227
|
+
* Generates a proof for a given email.
|
228
|
+
* @param eml - Email to prove agains the blueprint of this Prover.
|
229
|
+
* @returns A promise that resolves to a new instance of Proof. The Proof will have the status
|
230
|
+
* Done or Failed.
|
231
|
+
*/
|
232
|
+
generateProof(eml: string): Promise<Proof>;
|
233
|
+
/**
|
234
|
+
* Starts proving for a given email.
|
235
|
+
* @param eml - Email to prove agains the blueprint of this Prover.
|
236
|
+
* @returns A promise that resolves to a new instance of Proof. The Proof will have the status
|
237
|
+
* InProgress.
|
238
|
+
*/
|
239
|
+
generateProofRequest(eml: string): Promise<Proof>;
|
240
|
+
}
|
241
|
+
|
242
|
+
/**
|
243
|
+
* Interface for authentication for creating and updating blueprints
|
244
|
+
*/
|
245
|
+
interface Auth {
|
246
|
+
/**
|
247
|
+
* Retrieves the authentication token
|
248
|
+
* e.g. from a req for next.js or the localstorage for frontend
|
249
|
+
* @returns Promise that resolves to the token string or null if no token exists
|
250
|
+
*/
|
251
|
+
getToken: () => Promise<string | null>;
|
252
|
+
/**
|
253
|
+
* Callback triggered when the authentication token expires
|
254
|
+
* @returns Promise that resolves when expired token is handled
|
255
|
+
*/
|
256
|
+
onTokenExpired: () => Promise<void>;
|
257
|
+
}
|
258
|
+
|
259
|
+
/**
|
260
|
+
* Represents a Regex Blueprint including the decomposed regex access to the circuit.
|
261
|
+
*/
|
262
|
+
declare class Blueprint {
|
263
|
+
props: BlueprintProps;
|
264
|
+
auth?: Auth;
|
265
|
+
private lastCheckedStatus;
|
266
|
+
constructor(props: BlueprintProps, auth?: Auth);
|
267
|
+
addAuth(auth: Auth): void;
|
268
|
+
/**
|
269
|
+
* Fetches an existing RegexBlueprint from the database.
|
270
|
+
* @param {string} id - Id of the RegexBlueprint.
|
271
|
+
* @returns A promise that resolves to a new instance of RegexBlueprint.
|
272
|
+
*/
|
273
|
+
static getBlueprintById(id: string, auth?: Auth): Promise<Blueprint>;
|
274
|
+
private static responseToBlueprintProps;
|
275
|
+
private static blueprintPropsToRequest;
|
276
|
+
/**
|
277
|
+
* Submits a new RegexBlueprint to the registry as draft.
|
278
|
+
* This does not compile the circuits yet and you will still be able to make changes.
|
279
|
+
* @returns A promise. Once it resolves, `getId` can be called.
|
280
|
+
*/
|
281
|
+
submitDraft(): Promise<void>;
|
282
|
+
/**
|
283
|
+
* Submits a new version of the RegexBlueprint to the registry as draft.
|
284
|
+
* This does not compile the circuits yet and you will still be able to make changes.
|
285
|
+
* @param newProps - The updated blueprint props.
|
286
|
+
* @returns A promise. Once it resolves, the current Blueprint will be replaced with the new one.
|
287
|
+
*/
|
288
|
+
submitNewVersionDraft(newProps: BlueprintProps): Promise<void>;
|
289
|
+
/**
|
290
|
+
* Submits a new version of the blueprint. This will save the new blueprint version
|
291
|
+
* and start the compilation.
|
292
|
+
* This will also overwrite the current Blueprint with its new version, even if the last
|
293
|
+
* version was not compiled yet.
|
294
|
+
* @param newProps - The updated blueprint props.
|
295
|
+
*/
|
296
|
+
submitNewVersion(newProps: BlueprintProps): Promise<void>;
|
297
|
+
/**
|
298
|
+
* Lists blueblueprints, only including the latest version per unique slug.
|
299
|
+
* @param options - Options to filter the blueprints by.
|
300
|
+
* @returns A promise. Once it resolves, `getId` can be called.
|
301
|
+
*/
|
302
|
+
static listBlueprints(options?: ListBlueprintsOptions, auth?: Auth): Promise<Blueprint[]>;
|
303
|
+
/**
|
304
|
+
* Submits a blueprint. This will save the blueprint if it didn't exist before
|
305
|
+
* and start the compilation.
|
306
|
+
*/
|
307
|
+
submit(): Promise<void>;
|
308
|
+
private _checkStatus;
|
309
|
+
/**
|
310
|
+
* Checks the status of blueprint.
|
311
|
+
* checkStatus can be used in a while(await checkStatus()) loop, since it will wait a fixed
|
312
|
+
* amount of time the second time you call it.
|
313
|
+
* @returns A promise with the Status.
|
314
|
+
*/
|
315
|
+
checkStatus(): Promise<Status>;
|
316
|
+
/**
|
317
|
+
* Get the id of the blueprint.
|
318
|
+
* @returns The id of the blueprint. If it was not saved yet, return null.
|
319
|
+
*/
|
320
|
+
getId(): string | null;
|
321
|
+
/**
|
322
|
+
* Returns a download link for the ZKeys of the blueprint.
|
323
|
+
* @returns The the url to download the ZKeys.
|
324
|
+
*/
|
325
|
+
getZKeyDownloadLink(): Promise<string>;
|
326
|
+
/**
|
327
|
+
* Directly starts a download of the ZKeys in the browser.
|
328
|
+
* Must be called within a user action, like a button click.
|
329
|
+
*/
|
330
|
+
startZKeyDownload(): Promise<void>;
|
331
|
+
/**
|
332
|
+
* Creates an instance of Prover with which you can create proofs.
|
333
|
+
* @returns An instance of Prover.
|
334
|
+
*/
|
335
|
+
createProver(): Prover;
|
336
|
+
/**
|
337
|
+
* Verifies a proof on chain.
|
338
|
+
* @param proof - The generated proof you want to verify.
|
339
|
+
* @returns A true if the verification was successfull, false if it failed.
|
340
|
+
*/
|
341
|
+
verifyProofOnChain(proof: Proof$1): Promise<boolean>;
|
342
|
+
/**
|
343
|
+
* Returns a deep cloned version of the Blueprints props.
|
344
|
+
* This can be used to update properties and then to use them with createNewVersion.
|
345
|
+
* @param proof - The generated proof you want to verify.
|
346
|
+
* @returns A true if the verification was successfull, false if it failed.
|
347
|
+
*/
|
348
|
+
getClonedProps(): BlueprintProps;
|
349
|
+
/**
|
350
|
+
* Returns true if the blueprint can be updated. A blueprint can be updated if the circuits
|
351
|
+
* haven't beed compiled yet, i.e. the status is not Done. The blueprint also must be saved
|
352
|
+
* already before it can be updated.
|
353
|
+
* @returns true if it can be updated
|
354
|
+
*/
|
355
|
+
canUpdate(): boolean;
|
356
|
+
/**
|
357
|
+
* Updates an existing blueprint that is not compiled yet.
|
358
|
+
* @param newProps - The props the blueprint should be updated to.
|
359
|
+
* @returns a promise.
|
360
|
+
*/
|
361
|
+
update(newProps: BlueprintProps): Promise<void>;
|
362
|
+
listAllVersions(): Promise<Blueprint[]>;
|
363
|
+
}
|
364
|
+
|
365
|
+
type SdkOptions = {
|
366
|
+
auth?: Auth;
|
367
|
+
};
|
368
|
+
|
369
|
+
type ParsedEmail = {
|
370
|
+
canonicalized_header: string;
|
371
|
+
canonicalized_body: string;
|
372
|
+
signature: number[];
|
373
|
+
public_key: any[];
|
374
|
+
cleaned_body: string;
|
375
|
+
headers: Map<string, string[]>;
|
376
|
+
};
|
377
|
+
declare function parseEmail(eml: string): Promise<ParsedEmail>;
|
378
|
+
declare function testDecomposedRegex(eml: string, decomposedRegex: DecomposedRegex | DecomposedRegexJson, revealPrivate?: boolean): Promise<string[]>;
|
379
|
+
|
380
|
+
declare function getLoginWithGithubUrl(callbackUrl: string): string;
|
381
|
+
|
382
|
+
declare const _default: (sdkOptions?: SdkOptions) => {
|
383
|
+
createBlueprint(props: BlueprintProps): Blueprint;
|
384
|
+
getBlueprint(id: string): Promise<Blueprint>;
|
385
|
+
listBlueprints(options?: ListBlueprintsOptions): Promise<Blueprint[]>;
|
386
|
+
};
|
387
|
+
|
388
|
+
export { type Auth, Blueprint, type BlueprintProps, type BlueprintRequest, type BlueprintResponse, type DecomposedRegex, type DecomposedRegexJson, type DecomposedRegexPart, type DecomposedRegexPartJson, type DecomposedRegexPartResponse, type DecomposedRegexResponse, type ExternalInput, type ExternalInputResponse, type ListBlueprintsOptions, type ListBlueprintsOptionsRequest, Proof, type ProofProps, type ProofRequest, type ProofResponse, ProofStatus, type ServerDate, Status, type VerifierContract, ZkFramework, _default as default, getLoginWithGithubUrl, parseEmail, testDecomposedRegex };
|
package/dist/index.js
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var viem=require('viem'),chains=require('viem/chains');var f=(i=>(i[i.None=0]="None",i[i.InProgress=1]="InProgress",i[i.Done=2]="Done",i[i.Failed=3]="Failed",i))(f||{});var D="Ov23liUVyAeZK1bxoAkh";function R(o){let e=encodeURIComponent(o);return `https://github.com/login/oauth/authorize?client_id=${D}&scope=user:email&state=${e}`}async function h(o){try{let e=await o.getToken();if(e||(await o.onTokenExpired(),e=await o.getToken()),!e)throw new Error("Failed to get new token");return `Bearer ${e}`}catch(e){throw console.error("Failed to get token from auth"),e}}var b="pk_live_51NXwT8cHf0vYAjQK9LzB3pM6R8gWx2F",y,_=new Promise(o=>{y=o;});if(typeof window>"u"||typeof Deno<"u")console.warn("Relayer utils won't work when used server side");else try{import('@dimidumo/relayer-utils/web').then(async o=>{await o.default(),y(o);}).catch(o=>{console.log("Failed to init WASM: ",o);});}catch{}async function p(o,e,t){try{let r={method:"POST",headers:{"Content-Type":"application/json","x-api-key":b,...t?{Authorization:await h(t)}:{}}};e&&(r.body=JSON.stringify(e));let i=await fetch(o,r),s=await i.json();if(!i.ok)throw new Error(`HTTP error! status: ${i.status}, message: ${s}`);return s}catch(r){throw console.error("POST Error:",r),r}}async function P(o,e,t){try{let r={method:"PATCH",headers:{"Content-Type":"application/json","x-api-key":b,...t?{Authorization:await h(t)}:{}}};e&&(r.body=JSON.stringify(e));let i=await fetch(o,r),s=await i.json();if(!i.ok)throw new Error(`HTTP error! status: ${i.status}, message: ${s}`);return s}catch(r){throw console.error("PATCH Error:",r),r}}async function a(o,e,t){try{let r=o;if(e){let s=new URLSearchParams;Object.entries(e).forEach(([u,g])=>{g&&s.append(u,String(g));}),s.size>0&&(r+=`?${s.toString()}`);}let i=await fetch(r,{method:"GET",headers:{"Content-Type":"application/json","x-api-key":b,...t?{Authorization:await h(t)}:{}}});if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);return await i.json()}catch(r){throw console.error("GET Error:",r),r}}async function x(o){try{return console.log("parsing"),await(await _).parseEmail(o)}catch(e){throw console.error("Failed to parse email: ",e),e}}async function T(o,e,t=!1){let r=await x(o),i={parts:e.parts.map(c=>({is_public:"isPublic"in c?c.isPublic:c.is_public,regex_def:"regexDef"in c?c.regexDef:c.regex_def}))},s;if(e.location==="body")s=r.canonicalized_body;else if(e.location==="header")s=r.canonicalized_header;else throw Error(`Unsupported location ${e.location}`);let u="maxLength"in e?e.maxLength:e.max_length;if(s.length>u)throw new Error(`Max length of ${u} was exceeded`);return (await _).extractSubstr(s,i,t)}var w="http://localhost:8080",d=class o{blueprint;props;lastCheckedStatus=null;constructor(e,t){if(!(e instanceof n))throw new Error("Invalid blueprint: must be an instance of Blueprint class");if(this.blueprint=e,!t?.id)throw new Error("A proof must have an id");this.props={status:1,...t};}getId(){return this.props.id}async getProofDataDownloadLink(){if(this.props.status!==2)throw new Error("The proving is not done yet.");let e;try{e=await a(`${w}/proof/files/${this.props.id}`);}catch(t){throw console.error("Failed calling GET on /proof/files/:id in getProofDataDownloadLink: ",t),t}return e.url}async startFilesDownload(){if(!window&&!document)throw Error("startFilesDownload can only be used in a browser");let e;try{e=await this.getProofDataDownloadLink();}catch(r){throw console.error("Failed to start download of ZKeys: ",r),r}let t=document.createElement("a");t.href=e,t.download="proof_files.zip",document.body.appendChild(t),t.click(),document.body.removeChild(t);}async checkStatus(){if(this.props.status===2)return this.props.status;if(!this.lastCheckedStatus)this.lastCheckedStatus=new Date;else {let r=new Date().getTime()-this.lastCheckedStatus.getTime();r<500&&await new Promise(i=>setTimeout(i,500-r));}let e;try{e=await a(`${w}/proof/status/${this.props.id}`);}catch(t){throw console.error("Failed calling GET /blueprint/status in getStatus(): ",t),t}return this.props.status=e.status,e.status}async verifyOnChain(){}static async getPoofById(e){let t;try{t=await a(`${w}/proof/${e}`);}catch(s){throw console.error("Failed calling /proof/:id in getProofById: ",s),s}let r=this.responseToProofProps(t),i=await n.getBlueprintById(t.blueprint_id);return new o(i,r)}static responseToProofProps(e){return {id:e.id,status:1,circuitInput:e.circuit_input,startedAt:new Date(e.started_at.seconds*1e3),provenAt:e.proven_at?new Date(e.proven_at.seconds*1e3):void 0}}};var v="http://localhost:8080",m=class{options;blueprint;constructor(e,t){if(t?.isLocal===!0)throw new Error("Local proving is not supported yet");if(!(e instanceof n))throw new Error("Invalid blueprint: must be an instance of Blueprint class");this.blueprint=e,this.options={isLocal:!1,...t||{}};}async generateProof(e){let t=await this.generateProofRequest(e);for(;![2,3].includes(await t.checkStatus()););return t}async generateProofRequest(e){let t=this.blueprint.getId();if(!t)throw new Error("Blueprint of Proover must be initialized in order to create a Proof");let r;try{let s={blueprint_id:t,circuit_input:e};r=await p(`${v}/proof`,s);}catch(s){throw console.error("Failed calling POST on /proof/ in generateProofRequest: ",s),s}let i=d.responseToProofProps(r);return new d(this.blueprint,i)}};var E=(e=>(e.Circom="circom",e))(E||{}),B=(s=>(s[s.None=0]="None",s[s.Draft=1]="Draft",s[s.InProgress=2]="InProgress",s[s.Done=3]="Done",s[s.Failed=4]="Failed",s))(B||{});var C="0x4200000000000000000000000000000000000006",I=[{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],type:"function"}],F=viem.createPublicClient({chain:chains.baseSepolia,transport:viem.http()});async function k(){try{return await F.readContract({address:C,abi:I,functionName:"totalSupply"})}catch(o){throw console.error("Error fetching WETH total supply:",o),o}}var l="http://localhost:8080",n=class o{props;auth;lastCheckedStatus=null;constructor(e,t){this.props={ignoreBodyHashCheck:!1,enableHeaderMasking:!1,enableBodyMasking:!1,isPublic:!0,status:1,...e},this.auth=t;}addAuth(e){this.auth=e;}static async getBlueprintById(e,t){let r;try{r=await a(`${l}/blueprint/${e}`);}catch(u){throw console.error("Failed calling /blueprint/:id in getBlueprintById: ",u),u}let i=this.responseToBlueprintProps(r);return new o(i,t)}static responseToBlueprintProps(e){return {id:e.id,title:e.title,description:e.description,slug:e.slug,tags:e.tags,emailQuery:e.email_query,circuitName:e.circuit_name,ignoreBodyHashCheck:e.ignore_body_hash_check,shaPrecomputeSelector:e.sha_precompute_selector,emailBodyMaxLength:e.email_body_max_length,emailHeaderMaxLength:e.email_header_max_length,removeSoftLinebreaks:e.remove_soft_linebreaks,githubUsername:e.github_username,senderDomain:e.sender_domain,enableHeaderMasking:e.enable_header_masking,enableBodyMasking:e.enable_body_masking,zkFramework:e.zk_framework,isPublic:e.is_public,createdAt:new Date(e.created_at.seconds*1e3),updatedAt:new Date(e.updated_at.seconds*1e3),externalInputs:e.external_inputs?.map(r=>({name:r.name,maxLength:r.max_length})),decomposedRegexes:e.decomposed_regexes?.map(r=>({parts:r.parts.map(i=>({isPublic:i.is_public,regexDef:i.regex_def})),name:r.name,maxLength:r.max_length,location:r.location})),status:e.status,verifierContract:{address:e.verifier_contract_address,chain:e.verifier_contract_chain},version:e.version}}static blueprintPropsToRequest(e){return {id:e.id,title:e.title,description:e.description,slug:e.slug,tags:e.tags,email_query:e.emailQuery,circuit_name:e.circuitName,ignore_body_hash_check:e.ignoreBodyHashCheck,sha_precompute_selector:e.shaPrecomputeSelector,email_body_max_length:e.emailBodyMaxLength,email_header_max_length:e.emailHeaderMaxLength,remove_soft_linebreaks:e.removeSoftLinebreaks,github_username:e.githubUsername,sender_domain:e.senderDomain,enable_header_masking:e.enableHeaderMasking,enable_body_masking:e.enableBodyMasking,zk_framework:e.zkFramework,is_public:e.isPublic,external_inputs:e.externalInputs?.map(r=>({name:r.name,max_length:r.maxLength})),decomposed_regexes:e.decomposedRegexes?.map(r=>({parts:r.parts.map(i=>({is_public:i.isPublic,regex_def:i.regexDef})),name:r.name,max_length:r.maxLength,location:r.location})),verifier_contract_address:e.verifierContract?.address,verifier_contract_chain:e.verifierContract?.chain}}async submitDraft(){if(!this.auth)throw new Error("auth is required, add it with Blueprint.addAuth(auth)");if(this.props.id)throw new Error("Blueprint was already saved");let e=o.blueprintPropsToRequest(this.props),t;try{t=await p(`${l}/blueprint`,e,this.auth);}catch(r){throw console.error("Failed calling POST on /blueprint/ in submitDraft: ",r),r}this.props=o.responseToBlueprintProps(t);}async submitNewVersionDraft(e){if(!this.auth)throw new Error("auth is required, add it with Blueprint.addAuth(auth)");let t=o.blueprintPropsToRequest(e),r;try{r=await p(`${l}/blueprint`,t,this.auth);}catch(i){throw console.error("Failed calling POST on /blueprint/ in submitDraft: ",i),i}this.props=o.responseToBlueprintProps(r);}async submitNewVersion(e){if(!this.auth)throw new Error("auth is required, add it with Blueprint.addAuth(auth)");await this.submitNewVersionDraft(e);try{await p(`${l}/blueprint/compile/${this.props.id}`,null,this.auth);}catch(t){throw console.error("Failed calling POST on /blueprint/compile in submit: ",t),t}}static async listBlueprints(e,t){let r={skip:e?.skip,limit:e?.limit,sort:e?.sort,status:e?.status,is_public:e?.isPublic,search:e?.search},i;try{i=await a(`${l}/blueprint`,r);}catch(s){throw console.error("Failed calling POST on /blueprint/ in submitDraft: ",s),s}return i.blueprints?i.blueprints.map(s=>{let u=o.responseToBlueprintProps(s);return new o(u,t)}):[]}async submit(){if(!this.auth)throw new Error("auth is required, add it with Blueprint.addAuth(auth)");if(!this.props.id)try{await this.submitDraft();}catch(t){throw console.error("Failed to create blueprint: ",t),t}let e=await this._checkStatus();if(3===e)throw new Error("The circuits are already compiled.");if(2===e)throw new Error("The circuits already being compiled, please wait.");try{await p(`${l}/blueprint/compile/${this.props.id}`,null,this.auth);}catch(t){throw console.error("Failed calling POST on /blueprint/compile in submit: ",t),t}}async _checkStatus(){let e;try{e=await a(`${l}/blueprint/status/${this.props.id}`);}catch(t){throw console.error("Failed calling GET /blueprint/status in getStatus(): ",t),t}return this.props.status=e.status,e.status}async checkStatus(){if(!this.props.id)return this.props.status;if([4,3].includes(this.props.status))return this.props.status;if(!this.lastCheckedStatus)this.lastCheckedStatus=new Date;else {let r=new Date().getTime()-this.lastCheckedStatus.getTime();r<500&&await new Promise(i=>setTimeout(i,500-r));}return await this._checkStatus()}getId(){return this.props.id||null}async getZKeyDownloadLink(){if(this.props.status!==3)throw new Error("The circuits are not compiled yet, nothing to download.");let e;try{e=await a(`${l}/blueprint/zkey/${this.props.id}`);}catch(t){throw console.error("Failed calling GET on /blueprint/zkey/:id in getZKeyDownloadLink: ",t),t}return e.url}async startZKeyDownload(){if(!window&&!document)throw Error("startZKeyDownload can only be used in a browser");let e;try{e=await this.getZKeyDownloadLink();}catch(r){throw console.error("Failed to start download of ZKeys: ",r),r}let t=document.createElement("a");t.href=e,t.download="ZKeys.txt",document.body.appendChild(t),t.click(),document.body.removeChild(t);}createProver(){return new m(this)}async verifyProofOnChain(e){try{let t=await k();}catch(t){return console.error("Failed to verify proof on chain: ",t),!1}return !0}getClonedProps(){let e=JSON.parse(JSON.stringify(this.props));return e.createdAt&&(e.createdAt=new Date(e.createdAt)),e.updatedAt&&(e.updatedAt=new Date(e.updatedAt)),e}canUpdate(){return !!(this.props.id&&![3,2].includes(this.props.status))}async update(e){if(!this.auth)throw new Error("auth is required, add it with Blueprint.addAuth(auth)");if(!this.canUpdate())throw new Error("Blueprint already compied, cannot update");let t=o.blueprintPropsToRequest(e),r;try{r=await P(`${l}/blueprint/${this.props.id}`,t,this.auth);}catch(i){throw console.error("Failed calling POST on /blueprint/ in submitDraft: ",i),i}this.props=o.responseToBlueprintProps(r);}async listAllVersions(){if(!this.props.id)throw new Error("Blueprint was not saved yet");let e;try{e=await a(`${l}/blueprint/versions/${encodeURIComponent(this.props.slug)}`);}catch(t){throw console.error("Failed calling GET on /blueprint/versions/:slug in listAllVersions: ",t),t}return e.blueprints.map(t=>{let r=o.responseToBlueprintProps(t);return new o(r)})}};var Pe=o=>({createBlueprint(e){if(!o&&!o.auth)throw new Error("You need to specify options.auth to use createBlueprint");return new n(e,o.auth)},async getBlueprint(e){return n.getBlueprintById(e,o?.auth)},async listBlueprints(e){return n.listBlueprints(e,o?.auth)}});
|
2
|
+
exports.Blueprint=n;exports.Proof=d;exports.ProofStatus=f;exports.Status=B;exports.ZkFramework=E;exports.default=Pe;exports.getLoginWithGithubUrl=R;exports.parseEmail=x;exports.testDecomposedRegex=T;//# sourceMappingURL=index.js.map
|
3
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/types/proof.ts","../src/auth.ts","../src/utils.ts","../src/proof.ts","../src/prover.ts","../src/types/blueprint.ts","../src/chain/index.ts","../src/blueprint.ts","../src/index.ts"],"names":["ProofStatus","GITHUB_CLIENT_ID","getLoginWithGithubUrl","callbackUrl","state","getTokenFromAuth","auth","token","err","PUBLIC_SDK_KEY","relayerUtilsResolver","relayerUtils","resolve","rl","post","url","data","request","response","body","error","patch","get","queryParams","fullUrl","searchParams","key","value","parseEmail","eml","testDecomposedRegex","decomposedRegex","revealPrivate","parsedEmail","inputDecomposedRegex","p","inputStr","maxLength","BASE_URL","Proof","_Proof","blueprint","props","Blueprint","link","sinceLastChecked","r","id","proofResponse","proofProps","Prover","options","proof","blueprintId","requestData","ZkFramework","Status","WETHContractAddress","WETHContractABI","client","createPublicClient","baseSepolia","http","verifyProofOnChain","_Blueprint","blueprintResponse","blueprintProps","input","regex","part","newProps","requestOptions","status","result","cloned","src_default","sdkOptions"],"mappings":"6HAGO,IAAKA,CACVA,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,CAAA,IACAA,CAAAA,CAAAA,CAAAA,CAAAA,MAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA,UACAA,CAAAA,CAAAA,CAAAA,CAAAA,YAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA,IACAA,CAAAA,CAAAA,CAAAA,CAAAA,MAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA,MAJUA,CAAAA,CAAAA,CAAAA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AC,CACH,CACF,EC7fOS,IAAAA,EAAAA,CAASC,CACP,GAAA,CACL,eAAgBlC,CAAAA,CAAAA,CAAuB,CACrC,GAAI,CAACkC,CAAAA,EAAc,CAACA,CAAAA,CAAY,IAC9B,CAAA,MAAM,IAAI,KAAM,CAAA,yDAAyD,CAG3E,CAAA,OADkB,IAAIjC,CAAAA,CAAUD,CAAOkC,CAAAA,CAAAA,CAAY,IAAI,CAEzD,CACA,CAAA,MAAM,YAAa7B,CAAAA,CAAAA,CAAgC,CACjD,OAAOJ,EAAU,gBAAiBI,CAAAA,CAAAA,CAAI6B,CAAY,EAAA,IAAI,CACxD,CAAA,CACA,MAAM,cAAA,CAAezB,CAAuD,CAAA,CAC1E,OAAOR,CAAAA,CAAU,cAAeQ,CAAAA,CAAAA,CAASyB,CAAY,EAAA,IAAI,CAC3D,CACF,CAAA","file":"index.js","sourcesContent":["import { ServerDate } from \"./blueprint\";\n\n// According to protobufs\nexport enum ProofStatus {\n None,\n InProgress,\n Done,\n Failed,\n}\n\nexport type ProofProps = {\n id: string;\n status?: ProofStatus;\n circuitInput?: string;\n startedAt?: Date;\n provenAt?: Date;\n};\n\nexport type ProofResponse = {\n id: string;\n blueprint_id: string;\n circuit_input: string;\n started_at: ServerDate;\n proven_at?: ServerDate;\n status: string;\n};\n\nexport type ProofRequest = {\n blueprint_id: string;\n circuit_input: string;\n};\n","import { Auth } from \"./types/auth\";\n\nconst GITHUB_CLIENT_ID = \"Ov23liUVyAeZK1bxoAkh\";\n\nexport function getLoginWithGithubUrl(callbackUrl: string): string {\n const state = encodeURIComponent(callbackUrl);\n return `https://github.com/login/oauth/authorize?client_id=${GITHUB_CLIENT_ID}&scope=user:email&state=${state}`;\n}\n\nexport async function getTokenFromAuth(auth: Auth): Promise<string> {\n try {\n let token = await auth.getToken();\n\n if (!token) {\n await auth.onTokenExpired();\n token = await auth.getToken();\n }\n\n if (!token) {\n throw new Error(\"Failed to get new token\");\n }\n\n return `Bearer ${token}`;\n } catch (err) {\n console.error(\"Failed to get token from auth\");\n throw err;\n }\n}\n","const PUBLIC_SDK_KEY = \"pk_live_51NXwT8cHf0vYAjQK9LzB3pM6R8gWx2F\";\n\nimport {\n DecomposedRegex,\n DecomposedRegexJson,\n DecomposedRegexPart,\n DecomposedRegexPartJson,\n} from \"./blueprint\";\nimport { Auth } from \"./types/auth\";\nimport { getTokenFromAuth } from \"./auth\";\nimport type * as NodeUtils from \"@dimidumo/relayer-utils/node\";\nimport type * as WebUtils from \"@dimidumo/relayer-utils/web\";\n\ntype RelayerUtilsType = typeof NodeUtils | typeof WebUtils;\n\nlet relayerUtilsResolver: (value: any) => void;\nconst relayerUtils: Promise<RelayerUtilsType> = new Promise((resolve) => {\n relayerUtilsResolver = resolve;\n});\n\n// @ts-ignore\nif (typeof window === \"undefined\" || typeof Deno !== \"undefined\") {\n console.warn(\"Relayer utils won't work when used server side\");\n // console.log(\"Initializing for node\");\n // import(\"@dimidumo/relayer-utils/node\")\n // .then((rl) => {\n // relayerUtilsResolver(rl);\n // })\n // .catch((err) => console.log(\"failed to init WASM on node: \", err));\n} else {\n try {\n import(\"@dimidumo/relayer-utils/web\")\n .then(async (rl) => {\n // @ts-ignore\n await rl.default();\n relayerUtilsResolver(rl);\n })\n .catch((err) => {\n console.log(\"Failed to init WASM: \", err);\n });\n } catch (err) {}\n}\n\nexport async function post<T>(url: string, data?: object | null, auth?: Auth): Promise<T> {\n try {\n const request: RequestInit = {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": PUBLIC_SDK_KEY,\n ...(!auth ? {} : { Authorization: await getTokenFromAuth(auth) }),\n },\n };\n\n if (data) {\n request.body = JSON.stringify(data);\n }\n\n const response = await fetch(url, request);\n\n const body = await response.json();\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}, message: ${body}`);\n }\n\n return body;\n } catch (error) {\n // TODO: Handle token expired\n console.error(\"POST Error:\", error);\n throw error;\n }\n}\n\nexport async function patch<T>(url: string, data?: object | null, auth?: Auth): Promise<T> {\n try {\n const request: RequestInit = {\n method: \"PATCH\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": PUBLIC_SDK_KEY,\n ...(!auth ? {} : { Authorization: await getTokenFromAuth(auth) }),\n },\n };\n\n if (data) {\n request.body = JSON.stringify(data);\n }\n\n const response = await fetch(url, request);\n\n const body = await response.json();\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}, message: ${body}`);\n }\n\n return body;\n } catch (error) {\n console.error(\"PATCH Error:\", error);\n throw error;\n }\n}\n\nexport async function get<T>(url: string, queryParams?: object | null, auth?: Auth): Promise<T> {\n try {\n let fullUrl = url;\n if (queryParams) {\n const searchParams = new URLSearchParams();\n Object.entries(queryParams).forEach(([key, value]) => {\n if (value) {\n searchParams.append(key, String(value));\n }\n });\n if (searchParams.size > 0) {\n fullUrl += `?${searchParams.toString()}`;\n }\n }\n\n const response = await fetch(fullUrl, {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": PUBLIC_SDK_KEY,\n ...(!auth ? {} : { Authorization: await getTokenFromAuth(auth) }),\n },\n });\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n return await response.json();\n } catch (error) {\n console.error(\"GET Error:\", error);\n throw error;\n }\n}\n\n// Provisional type, delete once libary types\ntype ParsedEmail = {\n canonicalized_header: string;\n canonicalized_body: string;\n signature: number[];\n public_key: any[];\n cleaned_body: string;\n headers: Map<string, string[]>;\n};\n\nexport async function parseEmail(eml: string): Promise<ParsedEmail> {\n try {\n console.log(\"parsing\");\n const utils = await relayerUtils;\n const parsedEmail = await utils.parseEmail(eml);\n return parsedEmail as ParsedEmail;\n } catch (err) {\n console.error(\"Failed to parse email: \", err);\n throw err;\n }\n}\n\nexport async function testDecomposedRegex(\n eml: string,\n decomposedRegex: DecomposedRegex | DecomposedRegexJson,\n revealPrivate = false\n): Promise<string[]> {\n const parsedEmail = await parseEmail(eml);\n\n const inputDecomposedRegex = {\n parts: decomposedRegex.parts.map((p: DecomposedRegexPart | DecomposedRegexPartJson) => ({\n is_public: \"isPublic\" in p ? p.isPublic : p.is_public,\n regex_def: \"regexDef\" in p ? p.regexDef : p.regex_def,\n })),\n };\n\n let inputStr: string;\n if (decomposedRegex.location === \"body\") {\n inputStr = parsedEmail.canonicalized_body;\n } else if (decomposedRegex.location === \"header\") {\n inputStr = parsedEmail.canonicalized_header;\n } else {\n throw Error(`Unsupported location ${decomposedRegex.location}`);\n }\n\n const maxLength =\n \"maxLength\" in decomposedRegex ? decomposedRegex.maxLength : decomposedRegex.max_length;\n if (inputStr.length > maxLength) {\n throw new Error(`Max length of ${maxLength} was exceeded`);\n }\n\n const utils = await relayerUtils;\n const result = utils.extractSubstr(inputStr, inputDecomposedRegex, revealPrivate);\n return result;\n}\n","import { Blueprint, Status } from \"./blueprint\";\nimport { ProofProps, ProofResponse, ProofStatus } from \"./types/proof\";\nimport { get } from \"./utils\";\n\n// TODO: replace with prod version\nconst BASE_URL = \"http://localhost:8080\";\n\n/**\n * A generated proof. You get get proof data and verify proofs on chain.\n */\nexport class Proof {\n blueprint: Blueprint;\n props: ProofProps;\n private lastCheckedStatus: Date | null = null;\n\n constructor(blueprint: Blueprint, props: ProofProps) {\n if (!(blueprint instanceof Blueprint)) {\n throw new Error(\"Invalid blueprint: must be an instance of Blueprint class\");\n }\n this.blueprint = blueprint;\n\n if (!props?.id) {\n throw new Error(\"A proof must have an id\");\n }\n\n this.props = {\n status: ProofStatus.InProgress,\n ...props,\n };\n }\n\n getId(): string {\n return this.props.id;\n }\n\n /**\n * Returns a download link for the files of the proof.\n * @returns The the url to download a zip of the proof files.\n */\n async getProofDataDownloadLink(): Promise<string> {\n if (this.props.status !== ProofStatus.Done) {\n throw new Error(\"The proving is not done yet.\");\n }\n\n let response: { url: string };\n try {\n response = await get<{ url: string }>(`${BASE_URL}/proof/files/${this.props.id}`);\n } catch (err) {\n console.error(\"Failed calling GET on /proof/files/:id in getProofDataDownloadLink: \", err);\n throw err;\n }\n\n return response.url;\n }\n\n async startFilesDownload() {\n if (!window && !document) {\n throw Error(\"startFilesDownload can only be used in a browser\");\n }\n\n let url: string;\n try {\n url = await this.getProofDataDownloadLink();\n } catch (err) {\n console.error(\"Failed to start download of ZKeys: \", err);\n throw err;\n }\n\n const link = document.createElement(\"a\");\n link.href = url;\n link.download = \"proof_files.zip\"; // Set the desired filename\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n }\n\n /**\n * Checks the status of proof.\n * checkStatus can be used in a while(await checkStatus()) loop, since it will wait a fixed\n * amount of time before the second time you call it.\n * @returns A promise with the Status.\n */\n async checkStatus(): Promise<ProofStatus> {\n if (this.props.status === ProofStatus.Done) {\n return this.props.status;\n }\n\n // Waits for a fixed period of time before you can call checkStatus again\n // This enables you to put checkStatus in a while(await checkStatu()) loop\n if (!this.lastCheckedStatus) {\n this.lastCheckedStatus = new Date();\n } else {\n const waitTime = 500;\n const sinceLastChecked = new Date().getTime() - this.lastCheckedStatus.getTime();\n if (sinceLastChecked < waitTime) {\n await new Promise((r) => setTimeout(r, waitTime - sinceLastChecked));\n }\n }\n\n // Submit compile request\n let response: { status: ProofStatus };\n try {\n response = await get<{ status: ProofStatus }>(`${BASE_URL}/proof/status/${this.props.id}`);\n } catch (err) {\n console.error(\"Failed calling GET /blueprint/status in getStatus(): \", err);\n throw err;\n }\n\n this.props.status = response.status;\n return response.status;\n }\n\n async verifyOnChain() {}\n\n /**\n * Fetches an existing Proof from the database.\n * @param id - Id of the Proof.\n * @returns A promise that resolves to a new instance of Proof.\n */\n public static async getPoofById(id: string): Promise<Proof> {\n let proofResponse: ProofResponse;\n try {\n proofResponse = await get<ProofResponse>(`${BASE_URL}/proof/${id}`);\n } catch (err) {\n console.error(\"Failed calling /proof/:id in getProofById: \", err);\n throw err;\n }\n\n const proofProps = this.responseToProofProps(proofResponse);\n const blueprint = await Blueprint.getBlueprintById(proofResponse.blueprint_id);\n\n return new Proof(blueprint, proofProps);\n }\n\n public static responseToProofProps(response: ProofResponse): ProofProps {\n const props: ProofProps = {\n id: response.id,\n status: ProofStatus.InProgress,\n circuitInput: response.circuit_input,\n startedAt: new Date(response.started_at.seconds * 1000),\n provenAt: response.proven_at ? new Date(response.proven_at.seconds * 1000) : undefined,\n };\n return props;\n }\n}\n","import { Blueprint } from \"./blueprint\";\nimport { Proof } from \"./proof\";\nimport { ProofProps, ProofRequest, ProofResponse, ProofStatus } from \"./types/proof\";\nimport { ProverOptions } from \"./types/prover\";\nimport { post } from \"./utils\";\n\n// TODO: replace with prod version\nconst BASE_URL = \"http://localhost:8080\";\n\n/**\n * Represents a Prover generated from a blueprint that can generate Proofs\n */\nexport class Prover {\n options: ProverOptions;\n blueprint: Blueprint;\n\n constructor(blueprint: Blueprint, options?: ProverOptions) {\n if (options?.isLocal === true) {\n throw new Error(\"Local proving is not supported yet\");\n }\n\n if (!(blueprint instanceof Blueprint)) {\n throw new Error(\"Invalid blueprint: must be an instance of Blueprint class\");\n }\n\n this.blueprint = blueprint;\n\n // Use defaults for unset fields\n this.options = {\n isLocal: false,\n ...(!!options ? options : {}),\n };\n }\n\n // TODO: Add parsed email input\n /**\n * Generates a proof for a given email.\n * @param eml - Email to prove agains the blueprint of this Prover.\n * @returns A promise that resolves to a new instance of Proof. The Proof will have the status\n * Done or Failed.\n */\n async generateProof(eml: string): Promise<Proof> {\n const proof = await this.generateProofRequest(eml);\n\n // Wait for proof to finish\n while (![ProofStatus.Done, ProofStatus.Failed].includes(await proof.checkStatus())) {}\n return proof;\n }\n\n // TODO: Add parsed email input\n /**\n * Starts proving for a given email.\n * @param eml - Email to prove agains the blueprint of this Prover.\n * @returns A promise that resolves to a new instance of Proof. The Proof will have the status\n * InProgress.\n */\n async generateProofRequest(eml: string): Promise<Proof> {\n const blueprintId = this.blueprint.getId();\n if (!blueprintId) {\n throw new Error(\"Blueprint of Proover must be initialized in order to create a Proof\");\n }\n\n let response: ProofResponse;\n try {\n const requestData: ProofRequest = {\n blueprint_id: blueprintId,\n circuit_input: eml,\n };\n\n response = await post<ProofResponse>(`${BASE_URL}/proof`, requestData);\n } catch (err) {\n console.error(\"Failed calling POST on /proof/ in generateProofRequest: \", err);\n throw err;\n }\n\n const proofProps = Proof.responseToProofProps(response);\n return new Proof(this.blueprint, proofProps);\n }\n}\n","export type BlueprintProps = {\n id?: string;\n title: string;\n description?: string;\n slug?: string;\n tags?: string[];\n emailQuery?: string;\n circuitName: string;\n ignoreBodyHashCheck?: boolean;\n shaPrecomputeSelector?: string;\n emailBodyMaxLength?: number;\n emailHeaderMaxLength?: number;\n removeSoftLinebreaks?: boolean;\n githubUsername?: string;\n senderDomain?: string;\n enableHeaderMasking?: boolean;\n enableBodyMasking?: boolean;\n zkFramework?: ZkFramework;\n isPublic?: boolean;\n createdAt?: Date;\n updatedAt?: Date;\n externalInputs?: ExternalInput[];\n decomposedRegexes: DecomposedRegex[];\n status?: Status;\n verifierContract?: VerifierContract;\n version?: number;\n};\n\nexport type DecomposedRegex = {\n parts: DecomposedRegexPart[];\n name: string;\n maxLength: number;\n location: \"body\" | \"header\";\n};\n\nexport type DecomposedRegexPart = {\n isPublic: boolean;\n regexDef: string;\n};\n\nexport type DecomposedRegexJson = {\n parts: DecomposedRegexPartJson[];\n name: string;\n max_length: number;\n location: \"body\" | \"header\";\n};\n\nexport type DecomposedRegexPartJson = {\n is_public: boolean;\n regex_def: string;\n};\n\nexport type ExternalInput = {\n name: string;\n maxLength: number;\n};\n\nexport enum ZkFramework {\n Circom = \"circom\",\n}\n\n// According to protobufs\nexport enum Status {\n None,\n Draft,\n InProgress,\n Done,\n Failed,\n}\n\nexport type VerifierContract = {\n address?: string;\n chain: number;\n};\n\nexport type BlueprintRequest = {\n id?: string;\n title: string;\n description?: string;\n slug?: string;\n tags?: string[];\n email_query?: string;\n circuit_name?: string;\n ignore_body_hash_check?: boolean;\n sha_precompute_selector?: string;\n email_body_max_length?: number;\n email_header_max_length?: number;\n remove_soft_linebreaks?: boolean;\n // TODO: Make non ? after login with github\n github_username?: string;\n sender_domain?: string;\n enable_header_masking?: boolean;\n enable_body_masking?: boolean;\n zk_framework?: string;\n is_public?: boolean;\n external_inputs?: ExternalInputResponse[];\n decomposed_regexes: DecomposedRegexResponse[];\n status?: string;\n verifier_contract_address?: string;\n verifier_contract_chain?: number;\n version?: number;\n};\n\nexport type BlueprintResponse = {\n id: string;\n title: string;\n description: string;\n slug: string;\n tags: string[];\n email_query: string;\n circuit_name: string;\n ignore_body_hash_check: boolean;\n sha_precompute_selector: string;\n email_body_max_length: number;\n email_header_max_length?: number;\n remove_soft_linebreaks?: boolean;\n github_username?: string;\n sender_domain: string;\n enable_header_masking?: boolean;\n enable_body_masking?: boolean;\n zk_framework: string;\n is_public: boolean;\n created_at: ServerDate;\n updated_at: ServerDate;\n external_inputs: ExternalInputResponse[];\n decomposed_regexes: DecomposedRegexResponse[];\n status: number;\n verifier_contract_address: string;\n verifier_contract_chain: number;\n version: number;\n};\n\nexport type ServerDate = {\n seconds: number;\n nanos: number;\n};\n\nexport type ExternalInputResponse = {\n name: string;\n max_length: number;\n};\n\nexport type DecomposedRegexResponse = {\n parts: DecomposedRegexPartResponse[];\n name: string;\n max_length: number;\n location: \"body\" | \"header\";\n};\n\nexport type DecomposedRegexPartResponse = {\n is_public: boolean;\n regex_def: string;\n};\n\nexport type ListBlueprintsOptions = {\n skip?: number;\n limit?: number;\n sort?: -1 | 1;\n status?: Status;\n isPublic?: boolean;\n search?: string;\n};\n\nexport type ListBlueprintsOptionsRequest = {\n skip?: number;\n limit?: number;\n sort?: -1 | 1;\n status?: Status;\n is_public?: boolean;\n search?: string;\n};\n","import { createPublicClient, http } from \"viem\";\nimport { baseSepolia } from \"viem/chains\";\n\nconst WETHContractAddress = \"0x4200000000000000000000000000000000000006\";\n\nconst WETHContractABI = [\n {\n constant: true,\n inputs: [],\n name: \"totalSupply\",\n outputs: [{ name: \"\", type: \"uint256\" }],\n type: \"function\",\n },\n] as const;\n\nconst client = createPublicClient({\n chain: baseSepolia,\n transport: http(),\n});\n\nexport async function verifyProofOnChain() {\n try {\n const totalSupply = await client.readContract({\n address: WETHContractAddress,\n abi: WETHContractABI,\n functionName: \"totalSupply\",\n });\n\n return totalSupply;\n } catch (error) {\n console.error(\"Error fetching WETH total supply:\", error);\n throw error;\n }\n}\n","import { Proof } from \"viem/_types/types/proof\";\nimport { Prover } from \"./prover\";\nimport {\n BlueprintProps,\n BlueprintRequest,\n BlueprintResponse,\n ListBlueprintsOptions,\n ListBlueprintsOptionsRequest,\n Status,\n ZkFramework,\n} from \"./types/blueprint\";\nimport { get, patch, post } from \"./utils\";\nimport { verifyProofOnChain } from \"./chain\";\nimport { Auth } from \"./types/auth\";\n\n// TODO: replace with prod version\nconst BASE_URL = \"http://localhost:8080\";\n\n/**\n * Represents a Regex Blueprint including the decomposed regex access to the circuit.\n */\nexport class Blueprint {\n // TODO: Implement getter and setter pattern\n props: BlueprintProps;\n auth?: Auth;\n\n private lastCheckedStatus: Date | null = null;\n\n constructor(props: BlueprintProps, auth?: Auth) {\n // Use defaults for unset fields\n this.props = {\n ignoreBodyHashCheck: false,\n enableHeaderMasking: false,\n enableBodyMasking: false,\n isPublic: true,\n status: Status.Draft,\n ...props,\n };\n\n this.auth = auth;\n }\n\n addAuth(auth: Auth) {\n this.auth = auth;\n }\n\n /**\n * Fetches an existing RegexBlueprint from the database.\n * @param {string} id - Id of the RegexBlueprint.\n * @returns A promise that resolves to a new instance of RegexBlueprint.\n */\n public static async getBlueprintById(id: string, auth?: Auth): Promise<Blueprint> {\n let blueprintResponse: BlueprintResponse;\n try {\n blueprintResponse = await get<BlueprintResponse>(`${BASE_URL}/blueprint/${id}`);\n } catch (err) {\n console.error(\"Failed calling /blueprint/:id in getBlueprintById: \", err);\n throw err;\n }\n\n const blueprintProps = this.responseToBlueprintProps(blueprintResponse);\n\n const blueprint = new Blueprint(blueprintProps, auth);\n\n return blueprint;\n }\n\n // Maps the blueprint API response to the BlueprintProps\n private static responseToBlueprintProps(response: BlueprintResponse): BlueprintProps {\n const props: BlueprintProps = {\n id: response.id,\n title: response.title,\n description: response.description,\n slug: response.slug,\n tags: response.tags,\n emailQuery: response.email_query,\n circuitName: response.circuit_name,\n ignoreBodyHashCheck: response.ignore_body_hash_check,\n shaPrecomputeSelector: response.sha_precompute_selector,\n emailBodyMaxLength: response.email_body_max_length,\n emailHeaderMaxLength: response.email_header_max_length,\n removeSoftLinebreaks: response.remove_soft_linebreaks,\n githubUsername: response.github_username,\n senderDomain: response.sender_domain,\n enableHeaderMasking: response.enable_header_masking,\n enableBodyMasking: response.enable_body_masking,\n zkFramework: response.zk_framework as ZkFramework,\n isPublic: response.is_public,\n createdAt: new Date(response.created_at.seconds * 1000),\n updatedAt: new Date(response.updated_at.seconds * 1000),\n externalInputs: response.external_inputs?.map((input) => ({\n name: input.name,\n maxLength: input.max_length,\n })),\n decomposedRegexes: response.decomposed_regexes?.map((regex) => ({\n parts: regex.parts.map((part) => ({\n isPublic: part.is_public,\n regexDef: part.regex_def,\n })),\n name: regex.name,\n maxLength: regex.max_length,\n location: regex.location,\n })),\n status: response.status as Status,\n verifierContract: {\n address: response.verifier_contract_address,\n chain: response.verifier_contract_chain,\n },\n version: response.version,\n };\n\n return props;\n }\n\n // Maps the BlueprintProps to the BlueprintResponse\n private static blueprintPropsToRequest(props: BlueprintProps): BlueprintRequest {\n const response: BlueprintRequest = {\n id: props.id,\n title: props.title,\n description: props.description,\n slug: props.slug,\n tags: props.tags,\n email_query: props.emailQuery,\n circuit_name: props.circuitName,\n ignore_body_hash_check: props.ignoreBodyHashCheck,\n sha_precompute_selector: props.shaPrecomputeSelector,\n email_body_max_length: props.emailBodyMaxLength,\n email_header_max_length: props.emailHeaderMaxLength,\n remove_soft_linebreaks: props.removeSoftLinebreaks,\n github_username: props.githubUsername,\n sender_domain: props.senderDomain,\n enable_header_masking: props.enableHeaderMasking,\n enable_body_masking: props.enableBodyMasking,\n zk_framework: props.zkFramework,\n is_public: props.isPublic,\n external_inputs: props.externalInputs?.map((input) => ({\n name: input.name,\n max_length: input.maxLength,\n })),\n decomposed_regexes: props.decomposedRegexes?.map((regex) => ({\n parts: regex.parts.map((part) => ({\n is_public: part.isPublic,\n regex_def: part.regexDef,\n })),\n name: regex.name,\n max_length: regex.maxLength,\n location: regex.location,\n })),\n verifier_contract_address: props.verifierContract?.address,\n verifier_contract_chain: props.verifierContract?.chain,\n };\n\n return response;\n }\n\n /**\n * Submits a new RegexBlueprint to the registry as draft.\n * This does not compile the circuits yet and you will still be able to make changes.\n * @returns A promise. Once it resolves, `getId` can be called.\n */\n public async submitDraft() {\n if (!this.auth) {\n throw new Error(\"auth is required, add it with Blueprint.addAuth(auth)\");\n }\n\n if (this.props.id) {\n throw new Error(\"Blueprint was already saved\");\n }\n\n const requestData = Blueprint.blueprintPropsToRequest(this.props);\n\n let response: BlueprintResponse;\n try {\n response = await post<BlueprintResponse>(`${BASE_URL}/blueprint`, requestData, this.auth);\n } catch (err) {\n console.error(\"Failed calling POST on /blueprint/ in submitDraft: \", err);\n throw err;\n }\n\n this.props = Blueprint.responseToBlueprintProps(response);\n }\n\n /**\n * Submits a new version of the RegexBlueprint to the registry as draft.\n * This does not compile the circuits yet and you will still be able to make changes.\n * @param newProps - The updated blueprint props.\n * @returns A promise. Once it resolves, the current Blueprint will be replaced with the new one.\n */\n public async submitNewVersionDraft(newProps: BlueprintProps) {\n if (!this.auth) {\n throw new Error(\"auth is required, add it with Blueprint.addAuth(auth)\");\n }\n\n const requestData = Blueprint.blueprintPropsToRequest(newProps);\n\n let response: BlueprintResponse;\n try {\n response = await post<BlueprintResponse>(`${BASE_URL}/blueprint`, requestData, this.auth);\n } catch (err) {\n console.error(\"Failed calling POST on /blueprint/ in submitDraft: \", err);\n throw err;\n }\n\n this.props = Blueprint.responseToBlueprintProps(response);\n }\n\n /**\n * Submits a new version of the blueprint. This will save the new blueprint version\n * and start the compilation.\n * This will also overwrite the current Blueprint with its new version, even if the last\n * version was not compiled yet.\n * @param newProps - The updated blueprint props.\n */\n async submitNewVersion(newProps: BlueprintProps) {\n if (!this.auth) {\n throw new Error(\"auth is required, add it with Blueprint.addAuth(auth)\");\n }\n\n await this.submitNewVersionDraft(newProps);\n\n // We don't check the status here, since we are compiling directly after submiting the draft.\n\n // Submit compile request\n try {\n await post<{ status: Status }>(\n `${BASE_URL}/blueprint/compile/${this.props.id}`,\n null,\n this.auth\n );\n } catch (err) {\n // We don't set the status here, since the api call can't fail due to the actual job failing\n // It can only due to connectivity issues or the job runner not being available\n console.error(\"Failed calling POST on /blueprint/compile in submit: \", err);\n throw err;\n }\n }\n\n /**\n * Lists blueblueprints, only including the latest version per unique slug.\n * @param options - Options to filter the blueprints by.\n * @returns A promise. Once it resolves, `getId` can be called.\n */\n public static async listBlueprints(\n options?: ListBlueprintsOptions,\n auth?: Auth\n ): Promise<Blueprint[]> {\n const requestOptions: ListBlueprintsOptionsRequest = {\n skip: options?.skip,\n limit: options?.limit,\n sort: options?.sort,\n status: options?.status,\n is_public: options?.isPublic,\n search: options?.search,\n };\n\n let response: { blueprints?: BlueprintResponse[] };\n try {\n response = await get<{ blueprints?: BlueprintResponse[] }>(\n `${BASE_URL}/blueprint`,\n requestOptions\n );\n } catch (err) {\n console.error(\"Failed calling POST on /blueprint/ in submitDraft: \", err);\n throw err;\n }\n\n if (!response.blueprints) {\n return [];\n }\n\n return response.blueprints.map((blueprintResponse) => {\n const blueprintProps = Blueprint.responseToBlueprintProps(blueprintResponse);\n return new Blueprint(blueprintProps, auth);\n });\n }\n\n /**\n * Submits a blueprint. This will save the blueprint if it didn't exist before\n * and start the compilation.\n */\n async submit() {\n if (!this.auth) {\n throw new Error(\"auth is required, add it with Blueprint.addAuth(auth)\");\n }\n\n // If the blueprint wasn't save yet, we save it first to db\n if (!this.props.id) {\n try {\n await this.submitDraft();\n } catch (err) {\n console.error(\"Failed to create blueprint: \", err);\n throw err;\n }\n }\n\n const status = await this._checkStatus();\n\n // TODO: Should we allow retry on failed?\n if (Status.Done === status) {\n throw new Error(\"The circuits are already compiled.\");\n }\n if (Status.InProgress === status) {\n throw new Error(\"The circuits already being compiled, please wait.\");\n }\n\n // Submit compile request\n try {\n await post<{ status: Status }>(\n `${BASE_URL}/blueprint/compile/${this.props.id}`,\n null,\n this.auth\n );\n } catch (err) {\n // We don't set the status here, since the api call can't fail due to the actual job failing\n // It can only due to connectivity issues or the job runner not being available\n console.error(\"Failed calling POST on /blueprint/compile in submit: \", err);\n throw err;\n }\n }\n\n // Request status from server and updates props.status\n private async _checkStatus(): Promise<Status> {\n let response: { status: Status };\n try {\n response = await get<{ status: Status }>(`${BASE_URL}/blueprint/status/${this.props.id}`);\n } catch (err) {\n console.error(\"Failed calling GET /blueprint/status in getStatus(): \", err);\n throw err;\n }\n\n this.props.status = response.status;\n return response.status;\n }\n\n /**\n * Checks the status of blueprint.\n * checkStatus can be used in a while(await checkStatus()) loop, since it will wait a fixed\n * amount of time the second time you call it.\n * @returns A promise with the Status.\n */\n async checkStatus(): Promise<Status> {\n // Blueprint wasn't saved yet, return default status\n if (!this.props.id) {\n return this.props.status!;\n }\n\n if ([Status.Failed, Status.Done].includes(this.props.status!)) {\n return this.props.status!;\n }\n\n // Waits for a fixed period of time before you can call checkStatus again\n // This enables you to put checkStatus in a while(await checkStatus()) loop\n if (!this.lastCheckedStatus) {\n this.lastCheckedStatus = new Date();\n } else {\n // TODO: change for prod to one minute\n const waitTime = 0.5 * 1_000; // TODO: should be one minute;\n const sinceLastChecked = new Date().getTime() - this.lastCheckedStatus.getTime();\n if (sinceLastChecked < waitTime) {\n await new Promise((r) => setTimeout(r, waitTime - sinceLastChecked));\n }\n }\n\n const status = await this._checkStatus();\n\n return status;\n }\n\n /**\n * Get the id of the blueprint.\n * @returns The id of the blueprint. If it was not saved yet, return null.\n */\n getId(): string | null {\n return this.props.id || null;\n }\n\n /**\n * Returns a download link for the ZKeys of the blueprint.\n * @returns The the url to download the ZKeys.\n */\n async getZKeyDownloadLink(): Promise<string> {\n if (this.props.status !== Status.Done) {\n throw new Error(\"The circuits are not compiled yet, nothing to download.\");\n }\n\n let response: { url: string };\n try {\n response = await get<{ url: string }>(`${BASE_URL}/blueprint/zkey/${this.props.id}`);\n } catch (err) {\n console.error(\"Failed calling GET on /blueprint/zkey/:id in getZKeyDownloadLink: \", err);\n throw err;\n }\n\n return response.url;\n }\n\n /**\n * Directly starts a download of the ZKeys in the browser.\n * Must be called within a user action, like a button click.\n */\n async startZKeyDownload() {\n if (!window && !document) {\n throw Error(\"startZKeyDownload can only be used in a browser\");\n }\n\n let url: string;\n try {\n url = await this.getZKeyDownloadLink();\n } catch (err) {\n console.error(\"Failed to start download of ZKeys: \", err);\n throw err;\n }\n\n const link = document.createElement(\"a\");\n link.href = url;\n link.download = \"ZKeys.txt\"; // Set the desired filename\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n }\n\n /**\n * Creates an instance of Prover with which you can create proofs.\n * @returns An instance of Prover.\n */\n createProver() {\n return new Prover(this);\n }\n\n /**\n * Verifies a proof on chain.\n * @param proof - The generated proof you want to verify.\n * @returns A true if the verification was successfull, false if it failed.\n */\n async verifyProofOnChain(proof: Proof): Promise<boolean> {\n try {\n const result = await verifyProofOnChain();\n } catch (err) {\n console.error(\"Failed to verify proof on chain: \", err);\n return false;\n }\n return true;\n }\n\n /**\n * Returns a deep cloned version of the Blueprints props.\n * This can be used to update properties and then to use them with createNewVersion.\n * @param proof - The generated proof you want to verify.\n * @returns A true if the verification was successfull, false if it failed.\n */\n getClonedProps(): BlueprintProps {\n const cloned = JSON.parse(JSON.stringify(this.props));\n\n // Conver date strings\n if (cloned.createdAt) {\n cloned.createdAt = new Date(cloned.createdAt);\n }\n if (cloned.updatedAt) {\n cloned.updatedAt = new Date(cloned.updatedAt);\n }\n\n return cloned;\n }\n\n /**\n * Returns true if the blueprint can be updated. A blueprint can be updated if the circuits\n * haven't beed compiled yet, i.e. the status is not Done. The blueprint also must be saved\n * already before it can be updated.\n * @returns true if it can be updated\n */\n canUpdate(): boolean {\n return !!(this.props.id && ![Status.Done, Status.InProgress].includes(this.props.status!));\n }\n\n /**\n * Updates an existing blueprint that is not compiled yet.\n * @param newProps - The props the blueprint should be updated to.\n * @returns a promise.\n */\n async update(newProps: BlueprintProps) {\n if (!this.auth) {\n throw new Error(\"auth is required, add it with Blueprint.addAuth(auth)\");\n }\n\n if (!this.canUpdate()) {\n throw new Error(\"Blueprint already compied, cannot update\");\n }\n\n const requestData = Blueprint.blueprintPropsToRequest(newProps);\n\n let response: BlueprintResponse;\n try {\n response = await patch<BlueprintResponse>(\n `${BASE_URL}/blueprint/${this.props.id}`,\n requestData,\n this.auth\n );\n } catch (err) {\n console.error(\"Failed calling POST on /blueprint/ in submitDraft: \", err);\n throw err;\n }\n\n this.props = Blueprint.responseToBlueprintProps(response);\n }\n\n async listAllVersions(): Promise<Blueprint[]> {\n if (!this.props.id) {\n throw new Error(\"Blueprint was not saved yet\");\n }\n let response: { blueprints: BlueprintResponse[] };\n try {\n response = await get<{ blueprints: BlueprintResponse[] }>(\n `${BASE_URL}/blueprint/versions/${encodeURIComponent(this.props.slug!)}`\n );\n } catch (err) {\n console.error(\"Failed calling GET on /blueprint/versions/:slug in listAllVersions: \", err);\n throw err;\n }\n\n return response.blueprints.map((blueprintResponse) => {\n const blueprintProps = Blueprint.responseToBlueprintProps(blueprintResponse);\n return new Blueprint(blueprintProps);\n });\n }\n}\n\n// export {\n// BlueprintProps,\n// DecomposedRegex,\n// DecomposedRegexPart,\n// ExternalInput,\n// ZkFramework,\n// Status,\n// VerifierContract,\n// RevealHeaderFields,\n// } from \"./types/blueprint\";\n\nexport * from \"./types/blueprint\";\n","import { Blueprint, BlueprintProps, ListBlueprintsOptions } from \"./blueprint\";\nimport { SdkOptions } from \"./types/sdk\";\n\n// Export Types\nexport * from \"./types/blueprint\";\nexport { Blueprint } from \"./blueprint\";\nexport * from \"./types/proof\";\nexport { Proof } from \"./proof\";\nexport { Auth } from \"./types/auth\";\n\n// Exports that don't need initialization or options\nexport { testDecomposedRegex, parseEmail } from \"./utils\";\nexport { getLoginWithGithubUrl } from \"./auth\";\n\n// Exported sdk, functions that need initialization\nexport default (sdkOptions?: SdkOptions) => {\n return {\n createBlueprint(props: BlueprintProps) {\n if (!sdkOptions && !sdkOptions!.auth) {\n throw new Error(\"You need to specify options.auth to use createBlueprint\");\n }\n const blueprint = new Blueprint(props, sdkOptions!.auth);\n return blueprint;\n },\n async getBlueprint(id: string): Promise<Blueprint> {\n return Blueprint.getBlueprintById(id, sdkOptions?.auth);\n },\n async listBlueprints(options?: ListBlueprintsOptions): Promise<Blueprint[]> {\n return Blueprint.listBlueprints(options, sdkOptions?.auth);\n },\n };\n};\n"]}
|
package/dist/index.mjs
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
import {createPublicClient,http}from'viem';import {baseSepolia}from'viem/chains';var f=(i=>(i[i.None=0]="None",i[i.InProgress=1]="InProgress",i[i.Done=2]="Done",i[i.Failed=3]="Failed",i))(f||{});var D="Ov23liUVyAeZK1bxoAkh";function R(o){let e=encodeURIComponent(o);return `https://github.com/login/oauth/authorize?client_id=${D}&scope=user:email&state=${e}`}async function h(o){try{let e=await o.getToken();if(e||(await o.onTokenExpired(),e=await o.getToken()),!e)throw new Error("Failed to get new token");return `Bearer ${e}`}catch(e){throw console.error("Failed to get token from auth"),e}}var b="pk_live_51NXwT8cHf0vYAjQK9LzB3pM6R8gWx2F",y,_=new Promise(o=>{y=o;});if(typeof window>"u"||typeof Deno<"u")console.warn("Relayer utils won't work when used server side");else try{import('@dimidumo/relayer-utils/web').then(async o=>{await o.default(),y(o);}).catch(o=>{console.log("Failed to init WASM: ",o);});}catch{}async function p(o,e,t){try{let r={method:"POST",headers:{"Content-Type":"application/json","x-api-key":b,...t?{Authorization:await h(t)}:{}}};e&&(r.body=JSON.stringify(e));let i=await fetch(o,r),s=await i.json();if(!i.ok)throw new Error(`HTTP error! status: ${i.status}, message: ${s}`);return s}catch(r){throw console.error("POST Error:",r),r}}async function P(o,e,t){try{let r={method:"PATCH",headers:{"Content-Type":"application/json","x-api-key":b,...t?{Authorization:await h(t)}:{}}};e&&(r.body=JSON.stringify(e));let i=await fetch(o,r),s=await i.json();if(!i.ok)throw new Error(`HTTP error! status: ${i.status}, message: ${s}`);return s}catch(r){throw console.error("PATCH Error:",r),r}}async function a(o,e,t){try{let r=o;if(e){let s=new URLSearchParams;Object.entries(e).forEach(([u,g])=>{g&&s.append(u,String(g));}),s.size>0&&(r+=`?${s.toString()}`);}let i=await fetch(r,{method:"GET",headers:{"Content-Type":"application/json","x-api-key":b,...t?{Authorization:await h(t)}:{}}});if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);return await i.json()}catch(r){throw console.error("GET Error:",r),r}}async function x(o){try{return console.log("parsing"),await(await _).parseEmail(o)}catch(e){throw console.error("Failed to parse email: ",e),e}}async function T(o,e,t=!1){let r=await x(o),i={parts:e.parts.map(c=>({is_public:"isPublic"in c?c.isPublic:c.is_public,regex_def:"regexDef"in c?c.regexDef:c.regex_def}))},s;if(e.location==="body")s=r.canonicalized_body;else if(e.location==="header")s=r.canonicalized_header;else throw Error(`Unsupported location ${e.location}`);let u="maxLength"in e?e.maxLength:e.max_length;if(s.length>u)throw new Error(`Max length of ${u} was exceeded`);return (await _).extractSubstr(s,i,t)}var w="http://localhost:8080",d=class o{blueprint;props;lastCheckedStatus=null;constructor(e,t){if(!(e instanceof n))throw new Error("Invalid blueprint: must be an instance of Blueprint class");if(this.blueprint=e,!t?.id)throw new Error("A proof must have an id");this.props={status:1,...t};}getId(){return this.props.id}async getProofDataDownloadLink(){if(this.props.status!==2)throw new Error("The proving is not done yet.");let e;try{e=await a(`${w}/proof/files/${this.props.id}`);}catch(t){throw console.error("Failed calling GET on /proof/files/:id in getProofDataDownloadLink: ",t),t}return e.url}async startFilesDownload(){if(!window&&!document)throw Error("startFilesDownload can only be used in a browser");let e;try{e=await this.getProofDataDownloadLink();}catch(r){throw console.error("Failed to start download of ZKeys: ",r),r}let t=document.createElement("a");t.href=e,t.download="proof_files.zip",document.body.appendChild(t),t.click(),document.body.removeChild(t);}async checkStatus(){if(this.props.status===2)return this.props.status;if(!this.lastCheckedStatus)this.lastCheckedStatus=new Date;else {let r=new Date().getTime()-this.lastCheckedStatus.getTime();r<500&&await new Promise(i=>setTimeout(i,500-r));}let e;try{e=await a(`${w}/proof/status/${this.props.id}`);}catch(t){throw console.error("Failed calling GET /blueprint/status in getStatus(): ",t),t}return this.props.status=e.status,e.status}async verifyOnChain(){}static async getPoofById(e){let t;try{t=await a(`${w}/proof/${e}`);}catch(s){throw console.error("Failed calling /proof/:id in getProofById: ",s),s}let r=this.responseToProofProps(t),i=await n.getBlueprintById(t.blueprint_id);return new o(i,r)}static responseToProofProps(e){return {id:e.id,status:1,circuitInput:e.circuit_input,startedAt:new Date(e.started_at.seconds*1e3),provenAt:e.proven_at?new Date(e.proven_at.seconds*1e3):void 0}}};var v="http://localhost:8080",m=class{options;blueprint;constructor(e,t){if(t?.isLocal===!0)throw new Error("Local proving is not supported yet");if(!(e instanceof n))throw new Error("Invalid blueprint: must be an instance of Blueprint class");this.blueprint=e,this.options={isLocal:!1,...t||{}};}async generateProof(e){let t=await this.generateProofRequest(e);for(;![2,3].includes(await t.checkStatus()););return t}async generateProofRequest(e){let t=this.blueprint.getId();if(!t)throw new Error("Blueprint of Proover must be initialized in order to create a Proof");let r;try{let s={blueprint_id:t,circuit_input:e};r=await p(`${v}/proof`,s);}catch(s){throw console.error("Failed calling POST on /proof/ in generateProofRequest: ",s),s}let i=d.responseToProofProps(r);return new d(this.blueprint,i)}};var E=(e=>(e.Circom="circom",e))(E||{}),B=(s=>(s[s.None=0]="None",s[s.Draft=1]="Draft",s[s.InProgress=2]="InProgress",s[s.Done=3]="Done",s[s.Failed=4]="Failed",s))(B||{});var C="0x4200000000000000000000000000000000000006",I=[{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],type:"function"}],F=createPublicClient({chain:baseSepolia,transport:http()});async function k(){try{return await F.readContract({address:C,abi:I,functionName:"totalSupply"})}catch(o){throw console.error("Error fetching WETH total supply:",o),o}}var l="http://localhost:8080",n=class o{props;auth;lastCheckedStatus=null;constructor(e,t){this.props={ignoreBodyHashCheck:!1,enableHeaderMasking:!1,enableBodyMasking:!1,isPublic:!0,status:1,...e},this.auth=t;}addAuth(e){this.auth=e;}static async getBlueprintById(e,t){let r;try{r=await a(`${l}/blueprint/${e}`);}catch(u){throw console.error("Failed calling /blueprint/:id in getBlueprintById: ",u),u}let i=this.responseToBlueprintProps(r);return new o(i,t)}static responseToBlueprintProps(e){return {id:e.id,title:e.title,description:e.description,slug:e.slug,tags:e.tags,emailQuery:e.email_query,circuitName:e.circuit_name,ignoreBodyHashCheck:e.ignore_body_hash_check,shaPrecomputeSelector:e.sha_precompute_selector,emailBodyMaxLength:e.email_body_max_length,emailHeaderMaxLength:e.email_header_max_length,removeSoftLinebreaks:e.remove_soft_linebreaks,githubUsername:e.github_username,senderDomain:e.sender_domain,enableHeaderMasking:e.enable_header_masking,enableBodyMasking:e.enable_body_masking,zkFramework:e.zk_framework,isPublic:e.is_public,createdAt:new Date(e.created_at.seconds*1e3),updatedAt:new Date(e.updated_at.seconds*1e3),externalInputs:e.external_inputs?.map(r=>({name:r.name,maxLength:r.max_length})),decomposedRegexes:e.decomposed_regexes?.map(r=>({parts:r.parts.map(i=>({isPublic:i.is_public,regexDef:i.regex_def})),name:r.name,maxLength:r.max_length,location:r.location})),status:e.status,verifierContract:{address:e.verifier_contract_address,chain:e.verifier_contract_chain},version:e.version}}static blueprintPropsToRequest(e){return {id:e.id,title:e.title,description:e.description,slug:e.slug,tags:e.tags,email_query:e.emailQuery,circuit_name:e.circuitName,ignore_body_hash_check:e.ignoreBodyHashCheck,sha_precompute_selector:e.shaPrecomputeSelector,email_body_max_length:e.emailBodyMaxLength,email_header_max_length:e.emailHeaderMaxLength,remove_soft_linebreaks:e.removeSoftLinebreaks,github_username:e.githubUsername,sender_domain:e.senderDomain,enable_header_masking:e.enableHeaderMasking,enable_body_masking:e.enableBodyMasking,zk_framework:e.zkFramework,is_public:e.isPublic,external_inputs:e.externalInputs?.map(r=>({name:r.name,max_length:r.maxLength})),decomposed_regexes:e.decomposedRegexes?.map(r=>({parts:r.parts.map(i=>({is_public:i.isPublic,regex_def:i.regexDef})),name:r.name,max_length:r.maxLength,location:r.location})),verifier_contract_address:e.verifierContract?.address,verifier_contract_chain:e.verifierContract?.chain}}async submitDraft(){if(!this.auth)throw new Error("auth is required, add it with Blueprint.addAuth(auth)");if(this.props.id)throw new Error("Blueprint was already saved");let e=o.blueprintPropsToRequest(this.props),t;try{t=await p(`${l}/blueprint`,e,this.auth);}catch(r){throw console.error("Failed calling POST on /blueprint/ in submitDraft: ",r),r}this.props=o.responseToBlueprintProps(t);}async submitNewVersionDraft(e){if(!this.auth)throw new Error("auth is required, add it with Blueprint.addAuth(auth)");let t=o.blueprintPropsToRequest(e),r;try{r=await p(`${l}/blueprint`,t,this.auth);}catch(i){throw console.error("Failed calling POST on /blueprint/ in submitDraft: ",i),i}this.props=o.responseToBlueprintProps(r);}async submitNewVersion(e){if(!this.auth)throw new Error("auth is required, add it with Blueprint.addAuth(auth)");await this.submitNewVersionDraft(e);try{await p(`${l}/blueprint/compile/${this.props.id}`,null,this.auth);}catch(t){throw console.error("Failed calling POST on /blueprint/compile in submit: ",t),t}}static async listBlueprints(e,t){let r={skip:e?.skip,limit:e?.limit,sort:e?.sort,status:e?.status,is_public:e?.isPublic,search:e?.search},i;try{i=await a(`${l}/blueprint`,r);}catch(s){throw console.error("Failed calling POST on /blueprint/ in submitDraft: ",s),s}return i.blueprints?i.blueprints.map(s=>{let u=o.responseToBlueprintProps(s);return new o(u,t)}):[]}async submit(){if(!this.auth)throw new Error("auth is required, add it with Blueprint.addAuth(auth)");if(!this.props.id)try{await this.submitDraft();}catch(t){throw console.error("Failed to create blueprint: ",t),t}let e=await this._checkStatus();if(3===e)throw new Error("The circuits are already compiled.");if(2===e)throw new Error("The circuits already being compiled, please wait.");try{await p(`${l}/blueprint/compile/${this.props.id}`,null,this.auth);}catch(t){throw console.error("Failed calling POST on /blueprint/compile in submit: ",t),t}}async _checkStatus(){let e;try{e=await a(`${l}/blueprint/status/${this.props.id}`);}catch(t){throw console.error("Failed calling GET /blueprint/status in getStatus(): ",t),t}return this.props.status=e.status,e.status}async checkStatus(){if(!this.props.id)return this.props.status;if([4,3].includes(this.props.status))return this.props.status;if(!this.lastCheckedStatus)this.lastCheckedStatus=new Date;else {let r=new Date().getTime()-this.lastCheckedStatus.getTime();r<500&&await new Promise(i=>setTimeout(i,500-r));}return await this._checkStatus()}getId(){return this.props.id||null}async getZKeyDownloadLink(){if(this.props.status!==3)throw new Error("The circuits are not compiled yet, nothing to download.");let e;try{e=await a(`${l}/blueprint/zkey/${this.props.id}`);}catch(t){throw console.error("Failed calling GET on /blueprint/zkey/:id in getZKeyDownloadLink: ",t),t}return e.url}async startZKeyDownload(){if(!window&&!document)throw Error("startZKeyDownload can only be used in a browser");let e;try{e=await this.getZKeyDownloadLink();}catch(r){throw console.error("Failed to start download of ZKeys: ",r),r}let t=document.createElement("a");t.href=e,t.download="ZKeys.txt",document.body.appendChild(t),t.click(),document.body.removeChild(t);}createProver(){return new m(this)}async verifyProofOnChain(e){try{let t=await k();}catch(t){return console.error("Failed to verify proof on chain: ",t),!1}return !0}getClonedProps(){let e=JSON.parse(JSON.stringify(this.props));return e.createdAt&&(e.createdAt=new Date(e.createdAt)),e.updatedAt&&(e.updatedAt=new Date(e.updatedAt)),e}canUpdate(){return !!(this.props.id&&![3,2].includes(this.props.status))}async update(e){if(!this.auth)throw new Error("auth is required, add it with Blueprint.addAuth(auth)");if(!this.canUpdate())throw new Error("Blueprint already compied, cannot update");let t=o.blueprintPropsToRequest(e),r;try{r=await P(`${l}/blueprint/${this.props.id}`,t,this.auth);}catch(i){throw console.error("Failed calling POST on /blueprint/ in submitDraft: ",i),i}this.props=o.responseToBlueprintProps(r);}async listAllVersions(){if(!this.props.id)throw new Error("Blueprint was not saved yet");let e;try{e=await a(`${l}/blueprint/versions/${encodeURIComponent(this.props.slug)}`);}catch(t){throw console.error("Failed calling GET on /blueprint/versions/:slug in listAllVersions: ",t),t}return e.blueprints.map(t=>{let r=o.responseToBlueprintProps(t);return new o(r)})}};var Pe=o=>({createBlueprint(e){if(!o&&!o.auth)throw new Error("You need to specify options.auth to use createBlueprint");return new n(e,o.auth)},async getBlueprint(e){return n.getBlueprintById(e,o?.auth)},async listBlueprints(e){return n.listBlueprints(e,o?.auth)}});
|
2
|
+
export{n as Blueprint,d as Proof,f as ProofStatus,B as Status,E as ZkFramework,Pe as default,R as getLoginWithGithubUrl,x as parseEmail,T as testDecomposedRegex};//# sourceMappingURL=index.mjs.map
|
3
|
+
//# sourceMappingURL=index.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/types/proof.ts","../src/auth.ts","../src/utils.ts","../src/proof.ts","../src/prover.ts","../src/types/blueprint.ts","../src/chain/index.ts","../src/blueprint.ts","../src/index.ts"],"names":["ProofStatus","GITHUB_CLIENT_ID","getLoginWithGithubUrl","callbackUrl","state","getTokenFromAuth","auth","token","err","PUBLIC_SDK_KEY","relayerUtilsResolver","relayerUtils","resolve","rl","post","url","data","request","response","body","error","patch","get","queryParams","fullUrl","searchParams","key","value","parseEmail","eml","testDecomposedRegex","decomposedRegex","revealPrivate","parsedEmail","inputDecomposedRegex","p","inputStr","maxLength","BASE_URL","Proof","_Proof","blueprint","props","Blueprint","link","sinceLastChecked","r","id","proofResponse","proofProps","Prover","options","proof","blueprintId","requestData","ZkFramework","Status","WETHContractAddress","WETHContractABI","client","createPublicClient","baseSepolia","http","verifyProofOnChain","_Blueprint","blueprintResponse","blueprintProps","input","regex","part","newProps","requestOptions","status","result","cloned","src_default","sdkOptions"],"mappings":"iFAGO,IAAKA,CACVA,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,CAAA,I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CACZ,MAAQ,OAAA,CAAA,KAAA,CAAM,sEAAwEA,CAAAA,CAAG,CACnFA,CAAAA,CACR,CAEA,OAAOU,EAAS,UAAW,CAAA,GAAA,CAAK+C,CAAsB,EAAA,CACpD,IAAMC,CAAAA,CAAiBF,CAAU,CAAA,wBAAA,CAAyBC,CAAiB,CAAA,CAC3E,OAAO,IAAID,CAAUE,CAAAA,CAAc,CACrC,CAAC,CACH,CACF,EC7fOS,IAAAA,EAAAA,CAASC,CACP,GAAA,CACL,eAAgBlC,CAAAA,CAAAA,CAAuB,CACrC,GAAI,CAACkC,CAAAA,EAAc,CAACA,CAAAA,CAAY,IAC9B,CAAA,MAAM,IAAI,KAAM,CAAA,yDAAyD,CAG3E,CAAA,OADkB,IAAIjC,CAAAA,CAAUD,CAAOkC,CAAAA,CAAAA,CAAY,IAAI,CAEzD,CACA,CAAA,MAAM,YAAa7B,CAAAA,CAAAA,CAAgC,CACjD,OAAOJ,EAAU,gBAAiBI,CAAAA,CAAAA,CAAI6B,CAAY,EAAA,IAAI,CACxD,CAAA,CACA,MAAM,cAAA,CAAezB,CAAuD,CAAA,CAC1E,OAAOR,CAAAA,CAAU,cAAeQ,CAAAA,CAAAA,CAASyB,CAAY,EAAA,IAAI,CAC3D,CACF,CAAA","file":"index.mjs","sourcesContent":["import { ServerDate } from \"./blueprint\";\n\n// According to protobufs\nexport enum ProofStatus {\n None,\n InProgress,\n Done,\n Failed,\n}\n\nexport type ProofProps = {\n id: string;\n status?: ProofStatus;\n circuitInput?: string;\n startedAt?: Date;\n provenAt?: Date;\n};\n\nexport type ProofResponse = {\n id: string;\n blueprint_id: string;\n circuit_input: string;\n started_at: ServerDate;\n proven_at?: ServerDate;\n status: string;\n};\n\nexport type ProofRequest = {\n blueprint_id: string;\n circuit_input: string;\n};\n","import { Auth } from \"./types/auth\";\n\nconst GITHUB_CLIENT_ID = \"Ov23liUVyAeZK1bxoAkh\";\n\nexport function getLoginWithGithubUrl(callbackUrl: string): string {\n const state = encodeURIComponent(callbackUrl);\n return `https://github.com/login/oauth/authorize?client_id=${GITHUB_CLIENT_ID}&scope=user:email&state=${state}`;\n}\n\nexport async function getTokenFromAuth(auth: Auth): Promise<string> {\n try {\n let token = await auth.getToken();\n\n if (!token) {\n await auth.onTokenExpired();\n token = await auth.getToken();\n }\n\n if (!token) {\n throw new Error(\"Failed to get new token\");\n }\n\n return `Bearer ${token}`;\n } catch (err) {\n console.error(\"Failed to get token from auth\");\n throw err;\n }\n}\n","const PUBLIC_SDK_KEY = \"pk_live_51NXwT8cHf0vYAjQK9LzB3pM6R8gWx2F\";\n\nimport {\n DecomposedRegex,\n DecomposedRegexJson,\n DecomposedRegexPart,\n DecomposedRegexPartJson,\n} from \"./blueprint\";\nimport { Auth } from \"./types/auth\";\nimport { getTokenFromAuth } from \"./auth\";\nimport type * as NodeUtils from \"@dimidumo/relayer-utils/node\";\nimport type * as WebUtils from \"@dimidumo/relayer-utils/web\";\n\ntype RelayerUtilsType = typeof NodeUtils | typeof WebUtils;\n\nlet relayerUtilsResolver: (value: any) => void;\nconst relayerUtils: Promise<RelayerUtilsType> = new Promise((resolve) => {\n relayerUtilsResolver = resolve;\n});\n\n// @ts-ignore\nif (typeof window === \"undefined\" || typeof Deno !== \"undefined\") {\n console.warn(\"Relayer utils won't work when used server side\");\n // console.log(\"Initializing for node\");\n // import(\"@dimidumo/relayer-utils/node\")\n // .then((rl) => {\n // relayerUtilsResolver(rl);\n // })\n // .catch((err) => console.log(\"failed to init WASM on node: \", err));\n} else {\n try {\n import(\"@dimidumo/relayer-utils/web\")\n .then(async (rl) => {\n // @ts-ignore\n await rl.default();\n relayerUtilsResolver(rl);\n })\n .catch((err) => {\n console.log(\"Failed to init WASM: \", err);\n });\n } catch (err) {}\n}\n\nexport async function post<T>(url: string, data?: object | null, auth?: Auth): Promise<T> {\n try {\n const request: RequestInit = {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": PUBLIC_SDK_KEY,\n ...(!auth ? {} : { Authorization: await getTokenFromAuth(auth) }),\n },\n };\n\n if (data) {\n request.body = JSON.stringify(data);\n }\n\n const response = await fetch(url, request);\n\n const body = await response.json();\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}, message: ${body}`);\n }\n\n return body;\n } catch (error) {\n // TODO: Handle token expired\n console.error(\"POST Error:\", error);\n throw error;\n }\n}\n\nexport async function patch<T>(url: string, data?: object | null, auth?: Auth): Promise<T> {\n try {\n const request: RequestInit = {\n method: \"PATCH\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": PUBLIC_SDK_KEY,\n ...(!auth ? {} : { Authorization: await getTokenFromAuth(auth) }),\n },\n };\n\n if (data) {\n request.body = JSON.stringify(data);\n }\n\n const response = await fetch(url, request);\n\n const body = await response.json();\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}, message: ${body}`);\n }\n\n return body;\n } catch (error) {\n console.error(\"PATCH Error:\", error);\n throw error;\n }\n}\n\nexport async function get<T>(url: string, queryParams?: object | null, auth?: Auth): Promise<T> {\n try {\n let fullUrl = url;\n if (queryParams) {\n const searchParams = new URLSearchParams();\n Object.entries(queryParams).forEach(([key, value]) => {\n if (value) {\n searchParams.append(key, String(value));\n }\n });\n if (searchParams.size > 0) {\n fullUrl += `?${searchParams.toString()}`;\n }\n }\n\n const response = await fetch(fullUrl, {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": PUBLIC_SDK_KEY,\n ...(!auth ? {} : { Authorization: await getTokenFromAuth(auth) }),\n },\n });\n\n if (!response.ok) {\n throw new Error(`HTTP error! status: ${response.status}`);\n }\n\n return await response.json();\n } catch (error) {\n console.error(\"GET Error:\", error);\n throw error;\n }\n}\n\n// Provisional type, delete once libary types\ntype ParsedEmail = {\n canonicalized_header: string;\n canonicalized_body: string;\n signature: number[];\n public_key: any[];\n cleaned_body: string;\n headers: Map<string, string[]>;\n};\n\nexport async function parseEmail(eml: string): Promise<ParsedEmail> {\n try {\n console.log(\"parsing\");\n const utils = await relayerUtils;\n const parsedEmail = await utils.parseEmail(eml);\n return parsedEmail as ParsedEmail;\n } catch (err) {\n console.error(\"Failed to parse email: \", err);\n throw err;\n }\n}\n\nexport async function testDecomposedRegex(\n eml: string,\n decomposedRegex: DecomposedRegex | DecomposedRegexJson,\n revealPrivate = false\n): Promise<string[]> {\n const parsedEmail = await parseEmail(eml);\n\n const inputDecomposedRegex = {\n parts: decomposedRegex.parts.map((p: DecomposedRegexPart | DecomposedRegexPartJson) => ({\n is_public: \"isPublic\" in p ? p.isPublic : p.is_public,\n regex_def: \"regexDef\" in p ? p.regexDef : p.regex_def,\n })),\n };\n\n let inputStr: string;\n if (decomposedRegex.location === \"body\") {\n inputStr = parsedEmail.canonicalized_body;\n } else if (decomposedRegex.location === \"header\") {\n inputStr = parsedEmail.canonicalized_header;\n } else {\n throw Error(`Unsupported location ${decomposedRegex.location}`);\n }\n\n const maxLength =\n \"maxLength\" in decomposedRegex ? decomposedRegex.maxLength : decomposedRegex.max_length;\n if (inputStr.length > maxLength) {\n throw new Error(`Max length of ${maxLength} was exceeded`);\n }\n\n const utils = await relayerUtils;\n const result = utils.extractSubstr(inputStr, inputDecomposedRegex, revealPrivate);\n return result;\n}\n","import { Blueprint, Status } from \"./blueprint\";\nimport { ProofProps, ProofResponse, ProofStatus } from \"./types/proof\";\nimport { get } from \"./utils\";\n\n// TODO: replace with prod version\nconst BASE_URL = \"http://localhost:8080\";\n\n/**\n * A generated proof. You get get proof data and verify proofs on chain.\n */\nexport class Proof {\n blueprint: Blueprint;\n props: ProofProps;\n private lastCheckedStatus: Date | null = null;\n\n constructor(blueprint: Blueprint, props: ProofProps) {\n if (!(blueprint instanceof Blueprint)) {\n throw new Error(\"Invalid blueprint: must be an instance of Blueprint class\");\n }\n this.blueprint = blueprint;\n\n if (!props?.id) {\n throw new Error(\"A proof must have an id\");\n }\n\n this.props = {\n status: ProofStatus.InProgress,\n ...props,\n };\n }\n\n getId(): string {\n return this.props.id;\n }\n\n /**\n * Returns a download link for the files of the proof.\n * @returns The the url to download a zip of the proof files.\n */\n async getProofDataDownloadLink(): Promise<string> {\n if (this.props.status !== ProofStatus.Done) {\n throw new Error(\"The proving is not done yet.\");\n }\n\n let response: { url: string };\n try {\n response = await get<{ url: string }>(`${BASE_URL}/proof/files/${this.props.id}`);\n } catch (err) {\n console.error(\"Failed calling GET on /proof/files/:id in getProofDataDownloadLink: \", err);\n throw err;\n }\n\n return response.url;\n }\n\n async startFilesDownload() {\n if (!window && !document) {\n throw Error(\"startFilesDownload can only be used in a browser\");\n }\n\n let url: string;\n try {\n url = await this.getProofDataDownloadLink();\n } catch (err) {\n console.error(\"Failed to start download of ZKeys: \", err);\n throw err;\n }\n\n const link = document.createElement(\"a\");\n link.href = url;\n link.download = \"proof_files.zip\"; // Set the desired filename\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n }\n\n /**\n * Checks the status of proof.\n * checkStatus can be used in a while(await checkStatus()) loop, since it will wait a fixed\n * amount of time before the second time you call it.\n * @returns A promise with the Status.\n */\n async checkStatus(): Promise<ProofStatus> {\n if (this.props.status === ProofStatus.Done) {\n return this.props.status;\n }\n\n // Waits for a fixed period of time before you can call checkStatus again\n // This enables you to put checkStatus in a while(await checkStatu()) loop\n if (!this.lastCheckedStatus) {\n this.lastCheckedStatus = new Date();\n } else {\n const waitTime = 500;\n const sinceLastChecked = new Date().getTime() - this.lastCheckedStatus.getTime();\n if (sinceLastChecked < waitTime) {\n await new Promise((r) => setTimeout(r, waitTime - sinceLastChecked));\n }\n }\n\n // Submit compile request\n let response: { status: ProofStatus };\n try {\n response = await get<{ status: ProofStatus }>(`${BASE_URL}/proof/status/${this.props.id}`);\n } catch (err) {\n console.error(\"Failed calling GET /blueprint/status in getStatus(): \", err);\n throw err;\n }\n\n this.props.status = response.status;\n return response.status;\n }\n\n async verifyOnChain() {}\n\n /**\n * Fetches an existing Proof from the database.\n * @param id - Id of the Proof.\n * @returns A promise that resolves to a new instance of Proof.\n */\n public static async getPoofById(id: string): Promise<Proof> {\n let proofResponse: ProofResponse;\n try {\n proofResponse = await get<ProofResponse>(`${BASE_URL}/proof/${id}`);\n } catch (err) {\n console.error(\"Failed calling /proof/:id in getProofById: \", err);\n throw err;\n }\n\n const proofProps = this.responseToProofProps(proofResponse);\n const blueprint = await Blueprint.getBlueprintById(proofResponse.blueprint_id);\n\n return new Proof(blueprint, proofProps);\n }\n\n public static responseToProofProps(response: ProofResponse): ProofProps {\n const props: ProofProps = {\n id: response.id,\n status: ProofStatus.InProgress,\n circuitInput: response.circuit_input,\n startedAt: new Date(response.started_at.seconds * 1000),\n provenAt: response.proven_at ? new Date(response.proven_at.seconds * 1000) : undefined,\n };\n return props;\n }\n}\n","import { Blueprint } from \"./blueprint\";\nimport { Proof } from \"./proof\";\nimport { ProofProps, ProofRequest, ProofResponse, ProofStatus } from \"./types/proof\";\nimport { ProverOptions } from \"./types/prover\";\nimport { post } from \"./utils\";\n\n// TODO: replace with prod version\nconst BASE_URL = \"http://localhost:8080\";\n\n/**\n * Represents a Prover generated from a blueprint that can generate Proofs\n */\nexport class Prover {\n options: ProverOptions;\n blueprint: Blueprint;\n\n constructor(blueprint: Blueprint, options?: ProverOptions) {\n if (options?.isLocal === true) {\n throw new Error(\"Local proving is not supported yet\");\n }\n\n if (!(blueprint instanceof Blueprint)) {\n throw new Error(\"Invalid blueprint: must be an instance of Blueprint class\");\n }\n\n this.blueprint = blueprint;\n\n // Use defaults for unset fields\n this.options = {\n isLocal: false,\n ...(!!options ? options : {}),\n };\n }\n\n // TODO: Add parsed email input\n /**\n * Generates a proof for a given email.\n * @param eml - Email to prove agains the blueprint of this Prover.\n * @returns A promise that resolves to a new instance of Proof. The Proof will have the status\n * Done or Failed.\n */\n async generateProof(eml: string): Promise<Proof> {\n const proof = await this.generateProofRequest(eml);\n\n // Wait for proof to finish\n while (![ProofStatus.Done, ProofStatus.Failed].includes(await proof.checkStatus())) {}\n return proof;\n }\n\n // TODO: Add parsed email input\n /**\n * Starts proving for a given email.\n * @param eml - Email to prove agains the blueprint of this Prover.\n * @returns A promise that resolves to a new instance of Proof. The Proof will have the status\n * InProgress.\n */\n async generateProofRequest(eml: string): Promise<Proof> {\n const blueprintId = this.blueprint.getId();\n if (!blueprintId) {\n throw new Error(\"Blueprint of Proover must be initialized in order to create a Proof\");\n }\n\n let response: ProofResponse;\n try {\n const requestData: ProofRequest = {\n blueprint_id: blueprintId,\n circuit_input: eml,\n };\n\n response = await post<ProofResponse>(`${BASE_URL}/proof`, requestData);\n } catch (err) {\n console.error(\"Failed calling POST on /proof/ in generateProofRequest: \", err);\n throw err;\n }\n\n const proofProps = Proof.responseToProofProps(response);\n return new Proof(this.blueprint, proofProps);\n }\n}\n","export type BlueprintProps = {\n id?: string;\n title: string;\n description?: string;\n slug?: string;\n tags?: string[];\n emailQuery?: string;\n circuitName: string;\n ignoreBodyHashCheck?: boolean;\n shaPrecomputeSelector?: string;\n emailBodyMaxLength?: number;\n emailHeaderMaxLength?: number;\n removeSoftLinebreaks?: boolean;\n githubUsername?: string;\n senderDomain?: string;\n enableHeaderMasking?: boolean;\n enableBodyMasking?: boolean;\n zkFramework?: ZkFramework;\n isPublic?: boolean;\n createdAt?: Date;\n updatedAt?: Date;\n externalInputs?: ExternalInput[];\n decomposedRegexes: DecomposedRegex[];\n status?: Status;\n verifierContract?: VerifierContract;\n version?: number;\n};\n\nexport type DecomposedRegex = {\n parts: DecomposedRegexPart[];\n name: string;\n maxLength: number;\n location: \"body\" | \"header\";\n};\n\nexport type DecomposedRegexPart = {\n isPublic: boolean;\n regexDef: string;\n};\n\nexport type DecomposedRegexJson = {\n parts: DecomposedRegexPartJson[];\n name: string;\n max_length: number;\n location: \"body\" | \"header\";\n};\n\nexport type DecomposedRegexPartJson = {\n is_public: boolean;\n regex_def: string;\n};\n\nexport type ExternalInput = {\n name: string;\n maxLength: number;\n};\n\nexport enum ZkFramework {\n Circom = \"circom\",\n}\n\n// According to protobufs\nexport enum Status {\n None,\n Draft,\n InProgress,\n Done,\n Failed,\n}\n\nexport type VerifierContract = {\n address?: string;\n chain: number;\n};\n\nexport type BlueprintRequest = {\n id?: string;\n title: string;\n description?: string;\n slug?: string;\n tags?: string[];\n email_query?: string;\n circuit_name?: string;\n ignore_body_hash_check?: boolean;\n sha_precompute_selector?: string;\n email_body_max_length?: number;\n email_header_max_length?: number;\n remove_soft_linebreaks?: boolean;\n // TODO: Make non ? after login with github\n github_username?: string;\n sender_domain?: string;\n enable_header_masking?: boolean;\n enable_body_masking?: boolean;\n zk_framework?: string;\n is_public?: boolean;\n external_inputs?: ExternalInputResponse[];\n decomposed_regexes: DecomposedRegexResponse[];\n status?: string;\n verifier_contract_address?: string;\n verifier_contract_chain?: number;\n version?: number;\n};\n\nexport type BlueprintResponse = {\n id: string;\n title: string;\n description: string;\n slug: string;\n tags: string[];\n email_query: string;\n circuit_name: string;\n ignore_body_hash_check: boolean;\n sha_precompute_selector: string;\n email_body_max_length: number;\n email_header_max_length?: number;\n remove_soft_linebreaks?: boolean;\n github_username?: string;\n sender_domain: string;\n enable_header_masking?: boolean;\n enable_body_masking?: boolean;\n zk_framework: string;\n is_public: boolean;\n created_at: ServerDate;\n updated_at: ServerDate;\n external_inputs: ExternalInputResponse[];\n decomposed_regexes: DecomposedRegexResponse[];\n status: number;\n verifier_contract_address: string;\n verifier_contract_chain: number;\n version: number;\n};\n\nexport type ServerDate = {\n seconds: number;\n nanos: number;\n};\n\nexport type ExternalInputResponse = {\n name: string;\n max_length: number;\n};\n\nexport type DecomposedRegexResponse = {\n parts: DecomposedRegexPartResponse[];\n name: string;\n max_length: number;\n location: \"body\" | \"header\";\n};\n\nexport type DecomposedRegexPartResponse = {\n is_public: boolean;\n regex_def: string;\n};\n\nexport type ListBlueprintsOptions = {\n skip?: number;\n limit?: number;\n sort?: -1 | 1;\n status?: Status;\n isPublic?: boolean;\n search?: string;\n};\n\nexport type ListBlueprintsOptionsRequest = {\n skip?: number;\n limit?: number;\n sort?: -1 | 1;\n status?: Status;\n is_public?: boolean;\n search?: string;\n};\n","import { createPublicClient, http } from \"viem\";\nimport { baseSepolia } from \"viem/chains\";\n\nconst WETHContractAddress = \"0x4200000000000000000000000000000000000006\";\n\nconst WETHContractABI = [\n {\n constant: true,\n inputs: [],\n name: \"totalSupply\",\n outputs: [{ name: \"\", type: \"uint256\" }],\n type: \"function\",\n },\n] as const;\n\nconst client = createPublicClient({\n chain: baseSepolia,\n transport: http(),\n});\n\nexport async function verifyProofOnChain() {\n try {\n const totalSupply = await client.readContract({\n address: WETHContractAddress,\n abi: WETHContractABI,\n functionName: \"totalSupply\",\n });\n\n return totalSupply;\n } catch (error) {\n console.error(\"Error fetching WETH total supply:\", error);\n throw error;\n }\n}\n","import { Proof } from \"viem/_types/types/proof\";\nimport { Prover } from \"./prover\";\nimport {\n BlueprintProps,\n BlueprintRequest,\n BlueprintResponse,\n ListBlueprintsOptions,\n ListBlueprintsOptionsRequest,\n Status,\n ZkFramework,\n} from \"./types/blueprint\";\nimport { get, patch, post } from \"./utils\";\nimport { verifyProofOnChain } from \"./chain\";\nimport { Auth } from \"./types/auth\";\n\n// TODO: replace with prod version\nconst BASE_URL = \"http://localhost:8080\";\n\n/**\n * Represents a Regex Blueprint including the decomposed regex access to the circuit.\n */\nexport class Blueprint {\n // TODO: Implement getter and setter pattern\n props: BlueprintProps;\n auth?: Auth;\n\n private lastCheckedStatus: Date | null = null;\n\n constructor(props: BlueprintProps, auth?: Auth) {\n // Use defaults for unset fields\n this.props = {\n ignoreBodyHashCheck: false,\n enableHeaderMasking: false,\n enableBodyMasking: false,\n isPublic: true,\n status: Status.Draft,\n ...props,\n };\n\n this.auth = auth;\n }\n\n addAuth(auth: Auth) {\n this.auth = auth;\n }\n\n /**\n * Fetches an existing RegexBlueprint from the database.\n * @param {string} id - Id of the RegexBlueprint.\n * @returns A promise that resolves to a new instance of RegexBlueprint.\n */\n public static async getBlueprintById(id: string, auth?: Auth): Promise<Blueprint> {\n let blueprintResponse: BlueprintResponse;\n try {\n blueprintResponse = await get<BlueprintResponse>(`${BASE_URL}/blueprint/${id}`);\n } catch (err) {\n console.error(\"Failed calling /blueprint/:id in getBlueprintById: \", err);\n throw err;\n }\n\n const blueprintProps = this.responseToBlueprintProps(blueprintResponse);\n\n const blueprint = new Blueprint(blueprintProps, auth);\n\n return blueprint;\n }\n\n // Maps the blueprint API response to the BlueprintProps\n private static responseToBlueprintProps(response: BlueprintResponse): BlueprintProps {\n const props: BlueprintProps = {\n id: response.id,\n title: response.title,\n description: response.description,\n slug: response.slug,\n tags: response.tags,\n emailQuery: response.email_query,\n circuitName: response.circuit_name,\n ignoreBodyHashCheck: response.ignore_body_hash_check,\n shaPrecomputeSelector: response.sha_precompute_selector,\n emailBodyMaxLength: response.email_body_max_length,\n emailHeaderMaxLength: response.email_header_max_length,\n removeSoftLinebreaks: response.remove_soft_linebreaks,\n githubUsername: response.github_username,\n senderDomain: response.sender_domain,\n enableHeaderMasking: response.enable_header_masking,\n enableBodyMasking: response.enable_body_masking,\n zkFramework: response.zk_framework as ZkFramework,\n isPublic: response.is_public,\n createdAt: new Date(response.created_at.seconds * 1000),\n updatedAt: new Date(response.updated_at.seconds * 1000),\n externalInputs: response.external_inputs?.map((input) => ({\n name: input.name,\n maxLength: input.max_length,\n })),\n decomposedRegexes: response.decomposed_regexes?.map((regex) => ({\n parts: regex.parts.map((part) => ({\n isPublic: part.is_public,\n regexDef: part.regex_def,\n })),\n name: regex.name,\n maxLength: regex.max_length,\n location: regex.location,\n })),\n status: response.status as Status,\n verifierContract: {\n address: response.verifier_contract_address,\n chain: response.verifier_contract_chain,\n },\n version: response.version,\n };\n\n return props;\n }\n\n // Maps the BlueprintProps to the BlueprintResponse\n private static blueprintPropsToRequest(props: BlueprintProps): BlueprintRequest {\n const response: BlueprintRequest = {\n id: props.id,\n title: props.title,\n description: props.description,\n slug: props.slug,\n tags: props.tags,\n email_query: props.emailQuery,\n circuit_name: props.circuitName,\n ignore_body_hash_check: props.ignoreBodyHashCheck,\n sha_precompute_selector: props.shaPrecomputeSelector,\n email_body_max_length: props.emailBodyMaxLength,\n email_header_max_length: props.emailHeaderMaxLength,\n remove_soft_linebreaks: props.removeSoftLinebreaks,\n github_username: props.githubUsername,\n sender_domain: props.senderDomain,\n enable_header_masking: props.enableHeaderMasking,\n enable_body_masking: props.enableBodyMasking,\n zk_framework: props.zkFramework,\n is_public: props.isPublic,\n external_inputs: props.externalInputs?.map((input) => ({\n name: input.name,\n max_length: input.maxLength,\n })),\n decomposed_regexes: props.decomposedRegexes?.map((regex) => ({\n parts: regex.parts.map((part) => ({\n is_public: part.isPublic,\n regex_def: part.regexDef,\n })),\n name: regex.name,\n max_length: regex.maxLength,\n location: regex.location,\n })),\n verifier_contract_address: props.verifierContract?.address,\n verifier_contract_chain: props.verifierContract?.chain,\n };\n\n return response;\n }\n\n /**\n * Submits a new RegexBlueprint to the registry as draft.\n * This does not compile the circuits yet and you will still be able to make changes.\n * @returns A promise. Once it resolves, `getId` can be called.\n */\n public async submitDraft() {\n if (!this.auth) {\n throw new Error(\"auth is required, add it with Blueprint.addAuth(auth)\");\n }\n\n if (this.props.id) {\n throw new Error(\"Blueprint was already saved\");\n }\n\n const requestData = Blueprint.blueprintPropsToRequest(this.props);\n\n let response: BlueprintResponse;\n try {\n response = await post<BlueprintResponse>(`${BASE_URL}/blueprint`, requestData, this.auth);\n } catch (err) {\n console.error(\"Failed calling POST on /blueprint/ in submitDraft: \", err);\n throw err;\n }\n\n this.props = Blueprint.responseToBlueprintProps(response);\n }\n\n /**\n * Submits a new version of the RegexBlueprint to the registry as draft.\n * This does not compile the circuits yet and you will still be able to make changes.\n * @param newProps - The updated blueprint props.\n * @returns A promise. Once it resolves, the current Blueprint will be replaced with the new one.\n */\n public async submitNewVersionDraft(newProps: BlueprintProps) {\n if (!this.auth) {\n throw new Error(\"auth is required, add it with Blueprint.addAuth(auth)\");\n }\n\n const requestData = Blueprint.blueprintPropsToRequest(newProps);\n\n let response: BlueprintResponse;\n try {\n response = await post<BlueprintResponse>(`${BASE_URL}/blueprint`, requestData, this.auth);\n } catch (err) {\n console.error(\"Failed calling POST on /blueprint/ in submitDraft: \", err);\n throw err;\n }\n\n this.props = Blueprint.responseToBlueprintProps(response);\n }\n\n /**\n * Submits a new version of the blueprint. This will save the new blueprint version\n * and start the compilation.\n * This will also overwrite the current Blueprint with its new version, even if the last\n * version was not compiled yet.\n * @param newProps - The updated blueprint props.\n */\n async submitNewVersion(newProps: BlueprintProps) {\n if (!this.auth) {\n throw new Error(\"auth is required, add it with Blueprint.addAuth(auth)\");\n }\n\n await this.submitNewVersionDraft(newProps);\n\n // We don't check the status here, since we are compiling directly after submiting the draft.\n\n // Submit compile request\n try {\n await post<{ status: Status }>(\n `${BASE_URL}/blueprint/compile/${this.props.id}`,\n null,\n this.auth\n );\n } catch (err) {\n // We don't set the status here, since the api call can't fail due to the actual job failing\n // It can only due to connectivity issues or the job runner not being available\n console.error(\"Failed calling POST on /blueprint/compile in submit: \", err);\n throw err;\n }\n }\n\n /**\n * Lists blueblueprints, only including the latest version per unique slug.\n * @param options - Options to filter the blueprints by.\n * @returns A promise. Once it resolves, `getId` can be called.\n */\n public static async listBlueprints(\n options?: ListBlueprintsOptions,\n auth?: Auth\n ): Promise<Blueprint[]> {\n const requestOptions: ListBlueprintsOptionsRequest = {\n skip: options?.skip,\n limit: options?.limit,\n sort: options?.sort,\n status: options?.status,\n is_public: options?.isPublic,\n search: options?.search,\n };\n\n let response: { blueprints?: BlueprintResponse[] };\n try {\n response = await get<{ blueprints?: BlueprintResponse[] }>(\n `${BASE_URL}/blueprint`,\n requestOptions\n );\n } catch (err) {\n console.error(\"Failed calling POST on /blueprint/ in submitDraft: \", err);\n throw err;\n }\n\n if (!response.blueprints) {\n return [];\n }\n\n return response.blueprints.map((blueprintResponse) => {\n const blueprintProps = Blueprint.responseToBlueprintProps(blueprintResponse);\n return new Blueprint(blueprintProps, auth);\n });\n }\n\n /**\n * Submits a blueprint. This will save the blueprint if it didn't exist before\n * and start the compilation.\n */\n async submit() {\n if (!this.auth) {\n throw new Error(\"auth is required, add it with Blueprint.addAuth(auth)\");\n }\n\n // If the blueprint wasn't save yet, we save it first to db\n if (!this.props.id) {\n try {\n await this.submitDraft();\n } catch (err) {\n console.error(\"Failed to create blueprint: \", err);\n throw err;\n }\n }\n\n const status = await this._checkStatus();\n\n // TODO: Should we allow retry on failed?\n if (Status.Done === status) {\n throw new Error(\"The circuits are already compiled.\");\n }\n if (Status.InProgress === status) {\n throw new Error(\"The circuits already being compiled, please wait.\");\n }\n\n // Submit compile request\n try {\n await post<{ status: Status }>(\n `${BASE_URL}/blueprint/compile/${this.props.id}`,\n null,\n this.auth\n );\n } catch (err) {\n // We don't set the status here, since the api call can't fail due to the actual job failing\n // It can only due to connectivity issues or the job runner not being available\n console.error(\"Failed calling POST on /blueprint/compile in submit: \", err);\n throw err;\n }\n }\n\n // Request status from server and updates props.status\n private async _checkStatus(): Promise<Status> {\n let response: { status: Status };\n try {\n response = await get<{ status: Status }>(`${BASE_URL}/blueprint/status/${this.props.id}`);\n } catch (err) {\n console.error(\"Failed calling GET /blueprint/status in getStatus(): \", err);\n throw err;\n }\n\n this.props.status = response.status;\n return response.status;\n }\n\n /**\n * Checks the status of blueprint.\n * checkStatus can be used in a while(await checkStatus()) loop, since it will wait a fixed\n * amount of time the second time you call it.\n * @returns A promise with the Status.\n */\n async checkStatus(): Promise<Status> {\n // Blueprint wasn't saved yet, return default status\n if (!this.props.id) {\n return this.props.status!;\n }\n\n if ([Status.Failed, Status.Done].includes(this.props.status!)) {\n return this.props.status!;\n }\n\n // Waits for a fixed period of time before you can call checkStatus again\n // This enables you to put checkStatus in a while(await checkStatus()) loop\n if (!this.lastCheckedStatus) {\n this.lastCheckedStatus = new Date();\n } else {\n // TODO: change for prod to one minute\n const waitTime = 0.5 * 1_000; // TODO: should be one minute;\n const sinceLastChecked = new Date().getTime() - this.lastCheckedStatus.getTime();\n if (sinceLastChecked < waitTime) {\n await new Promise((r) => setTimeout(r, waitTime - sinceLastChecked));\n }\n }\n\n const status = await this._checkStatus();\n\n return status;\n }\n\n /**\n * Get the id of the blueprint.\n * @returns The id of the blueprint. If it was not saved yet, return null.\n */\n getId(): string | null {\n return this.props.id || null;\n }\n\n /**\n * Returns a download link for the ZKeys of the blueprint.\n * @returns The the url to download the ZKeys.\n */\n async getZKeyDownloadLink(): Promise<string> {\n if (this.props.status !== Status.Done) {\n throw new Error(\"The circuits are not compiled yet, nothing to download.\");\n }\n\n let response: { url: string };\n try {\n response = await get<{ url: string }>(`${BASE_URL}/blueprint/zkey/${this.props.id}`);\n } catch (err) {\n console.error(\"Failed calling GET on /blueprint/zkey/:id in getZKeyDownloadLink: \", err);\n throw err;\n }\n\n return response.url;\n }\n\n /**\n * Directly starts a download of the ZKeys in the browser.\n * Must be called within a user action, like a button click.\n */\n async startZKeyDownload() {\n if (!window && !document) {\n throw Error(\"startZKeyDownload can only be used in a browser\");\n }\n\n let url: string;\n try {\n url = await this.getZKeyDownloadLink();\n } catch (err) {\n console.error(\"Failed to start download of ZKeys: \", err);\n throw err;\n }\n\n const link = document.createElement(\"a\");\n link.href = url;\n link.download = \"ZKeys.txt\"; // Set the desired filename\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n }\n\n /**\n * Creates an instance of Prover with which you can create proofs.\n * @returns An instance of Prover.\n */\n createProver() {\n return new Prover(this);\n }\n\n /**\n * Verifies a proof on chain.\n * @param proof - The generated proof you want to verify.\n * @returns A true if the verification was successfull, false if it failed.\n */\n async verifyProofOnChain(proof: Proof): Promise<boolean> {\n try {\n const result = await verifyProofOnChain();\n } catch (err) {\n console.error(\"Failed to verify proof on chain: \", err);\n return false;\n }\n return true;\n }\n\n /**\n * Returns a deep cloned version of the Blueprints props.\n * This can be used to update properties and then to use them with createNewVersion.\n * @param proof - The generated proof you want to verify.\n * @returns A true if the verification was successfull, false if it failed.\n */\n getClonedProps(): BlueprintProps {\n const cloned = JSON.parse(JSON.stringify(this.props));\n\n // Conver date strings\n if (cloned.createdAt) {\n cloned.createdAt = new Date(cloned.createdAt);\n }\n if (cloned.updatedAt) {\n cloned.updatedAt = new Date(cloned.updatedAt);\n }\n\n return cloned;\n }\n\n /**\n * Returns true if the blueprint can be updated. A blueprint can be updated if the circuits\n * haven't beed compiled yet, i.e. the status is not Done. The blueprint also must be saved\n * already before it can be updated.\n * @returns true if it can be updated\n */\n canUpdate(): boolean {\n return !!(this.props.id && ![Status.Done, Status.InProgress].includes(this.props.status!));\n }\n\n /**\n * Updates an existing blueprint that is not compiled yet.\n * @param newProps - The props the blueprint should be updated to.\n * @returns a promise.\n */\n async update(newProps: BlueprintProps) {\n if (!this.auth) {\n throw new Error(\"auth is required, add it with Blueprint.addAuth(auth)\");\n }\n\n if (!this.canUpdate()) {\n throw new Error(\"Blueprint already compied, cannot update\");\n }\n\n const requestData = Blueprint.blueprintPropsToRequest(newProps);\n\n let response: BlueprintResponse;\n try {\n response = await patch<BlueprintResponse>(\n `${BASE_URL}/blueprint/${this.props.id}`,\n requestData,\n this.auth\n );\n } catch (err) {\n console.error(\"Failed calling POST on /blueprint/ in submitDraft: \", err);\n throw err;\n }\n\n this.props = Blueprint.responseToBlueprintProps(response);\n }\n\n async listAllVersions(): Promise<Blueprint[]> {\n if (!this.props.id) {\n throw new Error(\"Blueprint was not saved yet\");\n }\n let response: { blueprints: BlueprintResponse[] };\n try {\n response = await get<{ blueprints: BlueprintResponse[] }>(\n `${BASE_URL}/blueprint/versions/${encodeURIComponent(this.props.slug!)}`\n );\n } catch (err) {\n console.error(\"Failed calling GET on /blueprint/versions/:slug in listAllVersions: \", err);\n throw err;\n }\n\n return response.blueprints.map((blueprintResponse) => {\n const blueprintProps = Blueprint.responseToBlueprintProps(blueprintResponse);\n return new Blueprint(blueprintProps);\n });\n }\n}\n\n// export {\n// BlueprintProps,\n// DecomposedRegex,\n// DecomposedRegexPart,\n// ExternalInput,\n// ZkFramework,\n// Status,\n// VerifierContract,\n// RevealHeaderFields,\n// } from \"./types/blueprint\";\n\nexport * from \"./types/blueprint\";\n","import { Blueprint, BlueprintProps, ListBlueprintsOptions } from \"./blueprint\";\nimport { SdkOptions } from \"./types/sdk\";\n\n// Export Types\nexport * from \"./types/blueprint\";\nexport { Blueprint } from \"./blueprint\";\nexport * from \"./types/proof\";\nexport { Proof } from \"./proof\";\nexport { Auth } from \"./types/auth\";\n\n// Exports that don't need initialization or options\nexport { testDecomposedRegex, parseEmail } from \"./utils\";\nexport { getLoginWithGithubUrl } from \"./auth\";\n\n// Exported sdk, functions that need initialization\nexport default (sdkOptions?: SdkOptions) => {\n return {\n createBlueprint(props: BlueprintProps) {\n if (!sdkOptions && !sdkOptions!.auth) {\n throw new Error(\"You need to specify options.auth to use createBlueprint\");\n }\n const blueprint = new Blueprint(props, sdkOptions!.auth);\n return blueprint;\n },\n async getBlueprint(id: string): Promise<Blueprint> {\n return Blueprint.getBlueprintById(id, sdkOptions?.auth);\n },\n async listBlueprints(options?: ListBlueprintsOptions): Promise<Blueprint[]> {\n return Blueprint.listBlueprints(options, sdkOptions?.auth);\n },\n };\n};\n"]}
|
package/package.json
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
{
|
2
|
+
"name": "@zk-email/sdk",
|
3
|
+
"version": "0.0.1",
|
4
|
+
"description": "ZK Email SDK for TypeScript",
|
5
|
+
"main": "./dist/index.js",
|
6
|
+
"module": "./dist/index.mjs",
|
7
|
+
"types": "./dist/index.d.ts",
|
8
|
+
"exports": {
|
9
|
+
".": {
|
10
|
+
"require": "./dist/index.js",
|
11
|
+
"import": "./dist/index.mjs",
|
12
|
+
"types": "./dist/index.d.ts"
|
13
|
+
}
|
14
|
+
},
|
15
|
+
"files": [
|
16
|
+
"dist",
|
17
|
+
"README.md"
|
18
|
+
],
|
19
|
+
"scripts": {
|
20
|
+
"build": "bunx tsup",
|
21
|
+
"typecheck": "tsc --noEmit",
|
22
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
23
|
+
"prepublishOnly": "bun run build",
|
24
|
+
"clean": "rm -rf dist",
|
25
|
+
"publish": "npm publish --access public"
|
26
|
+
},
|
27
|
+
"keywords": [
|
28
|
+
"zk",
|
29
|
+
"email",
|
30
|
+
"sdk",
|
31
|
+
"typescript"
|
32
|
+
],
|
33
|
+
"author": "",
|
34
|
+
"license": "MIT",
|
35
|
+
"devDependencies": {
|
36
|
+
"@types/bun": "^1.1.12",
|
37
|
+
"@types/pg": "^8.11.10",
|
38
|
+
"open": "^10.1.0",
|
39
|
+
"pg": "^8.13.0",
|
40
|
+
"prettier": "^3.3.3",
|
41
|
+
"tsup": "^8.3.5"
|
42
|
+
},
|
43
|
+
"peerDependencies": {
|
44
|
+
"typescript": "^5.0.0"
|
45
|
+
},
|
46
|
+
"dependencies": {
|
47
|
+
"@dimidumo/relayer-utils": "^0.4.12",
|
48
|
+
"viem": "^2.21.29"
|
49
|
+
}
|
50
|
+
}
|