-
Notifications
You must be signed in to change notification settings - Fork 0
/
input2.ts
45 lines (38 loc) · 1.63 KB
/
input2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { bytesToBigInt, fromHex } from "@zk-email/helpers";
import { generateCircuitInputs } from "@zk-email/helpers";
import { verifyDKIMSignature } from "@zk-email/helpers/dist/dkim";
import fs from "fs"
import path from "path"
export const STRING_PRESELECTOR = "email was meant for @";
export const MAX_HEADER_PADDED_BYTES = 1024;
export const MAX_BODY_PADDED_BYTES = 1536;
export async function generateBlackByrdVerifierCircuitInputs() {
const rawEmail = fs.readFileSync(
path.join(__dirname, "./emails/twitter.eml"),
"utf8"
);
const dkimResult = await verifyDKIMSignature(Buffer.from(rawEmail));
const emailVerifierInputs = generateCircuitInputs({
rsaSignature: dkimResult.signature,
rsaPublicKey: dkimResult.publicKey,
body: dkimResult.body,
bodyHash:dkimResult.bodyHash,
message: dkimResult.message,
shaPrecomputeSelector: STRING_PRESELECTOR,
maxMessageLength: MAX_HEADER_PADDED_BYTES,
maxBodyLength: MAX_BODY_PADDED_BYTES
});
const bodyRemaining = emailVerifierInputs.in_body_padded!.map(c => Number(c));
const selectorBuffer = Buffer.from(STRING_PRESELECTOR);
const usernameIndex = Buffer.from(bodyRemaining).indexOf(selectorBuffer) + selectorBuffer.length;
const address = bytesToBigInt(fromHex("0xd10339150eA31A668ca3Cb10E09c714229AF1FF9")).toString();
const inputJson = {
...emailVerifierInputs,
twitter_username_idx: usernameIndex.toString(),
address,
};
fs.writeFileSync("./input.json", JSON.stringify(inputJson))
}
(async () => {
await generateBlackByrdVerifierCircuitInputs();
}) ();