-
Notifications
You must be signed in to change notification settings - Fork 13
/
generate-inputs.ts
39 lines (33 loc) · 1.27 KB
/
generate-inputs.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
import { bytesToBigInt, fromHex } from "@zk-email/helpers/dist/binaryFormat";
import { generateEmailVerifierInputs } from "@zk-email/helpers/dist/input-generators";
export const STRING_PRESELECTOR = "email was meant for @";
export type ITwitterCircuitInputs = {
twitterUsernameIndex: string;
address: string;
emailHeader: string[];
emailHeaderLength: string;
pubkey: string[];
signature: string[];
emailBody?: string[] | undefined;
emailBodyLength?: string | undefined;
precomputedSHA?: string[] | undefined;
bodyHashIndex?: string | undefined;
};
export async function generateTwitterVerifierCircuitInputs(
email: string | Buffer,
ethereumAddress: string
): Promise<ITwitterCircuitInputs> {
const emailVerifierInputs = await generateEmailVerifierInputs(email, {
shaPrecomputeSelector: STRING_PRESELECTOR,
});
const bodyRemaining = emailVerifierInputs.emailBody!.map((c) => Number(c)); // Char array to Uint8Array
const selectorBuffer = Buffer.from(STRING_PRESELECTOR);
const usernameIndex =
Buffer.from(bodyRemaining).indexOf(selectorBuffer) + selectorBuffer.length;
const address = bytesToBigInt(fromHex(ethereumAddress)).toString();
return {
...emailVerifierInputs,
twitterUsernameIndex: usernameIndex.toString(),
address,
};
}