mirror of
https://github.com/zkemail/zk-email-verify.git
synced 2026-01-08 21:18:09 -05:00
added message id hashing to wallet circom
This commit is contained in:
@@ -11,7 +11,7 @@ include "./regexes/from_regex.circom";
|
||||
include "./regexes/tofrom_domain_regex.circom";
|
||||
include "./regexes/body_hash_regex.circom";
|
||||
include "./regexes/twitter_reset_regex.circom";
|
||||
include "./regexes/subject_regex.circom";
|
||||
include "./regexes/subject_regex2.circom";
|
||||
include "./regexes/message_id_regex.circom";
|
||||
|
||||
|
||||
@@ -53,13 +53,17 @@ template EmailVerify(max_header_bytes, max_body_bytes, n, k, pack_size, calculat
|
||||
var max_subject_currency_packed_bytes = count_packed(max_subject_currency_len, pack_size);
|
||||
var max_subject_recipient_len = max_email_len;
|
||||
var max_subject_recipient_packed_bytes = count_packed(max_subject_recipient_len, pack_size);
|
||||
var max_message_id_len = max_email_len;
|
||||
var max_subject_command_len = 10;
|
||||
var max_subject_command_packed_bytes = count_packed(max_subject_command_len, pack_size);
|
||||
var max_message_id_len = 128;
|
||||
var max_email_from_len = max_email_len;
|
||||
var max_email_recipient_len = max_email_len;
|
||||
|
||||
signal input command_idx;
|
||||
signal input amount_idx;
|
||||
signal input currency_idx;
|
||||
signal input recipient_idx;
|
||||
signal output reveal_command_packed[max_subject_command_packed_bytes]; // packed into 7-bytes. TODO: make this rotate to take up even less space
|
||||
signal output reveal_amount_packed[max_subject_amount_packed_bytes]; // packed into 7-bytes. TODO: make this rotate to take up even less space
|
||||
signal output reveal_currency_packed[max_subject_currency_packed_bytes]; // packed into 7-bytes. TODO: make this rotate to take up even less space
|
||||
|
||||
@@ -123,11 +127,12 @@ template EmailVerify(max_header_bytes, max_body_bytes, n, k, pack_size, calculat
|
||||
|
||||
// SUBJECT HEADER REGEX: 736,553 constraints
|
||||
// This extracts the subject, and the precise regex format can be viewed in the README
|
||||
signal subject_regex_out, subject_regex_reveal_amount[max_header_bytes], subject_regex_reveal_currency[max_header_bytes], subject_regex_reveal_recipient[max_header_bytes];
|
||||
(subject_regex_out, subject_regex_reveal_amount, subject_regex_reveal_currency, subject_regex_reveal_recipient) <== WalletSubjectRegex(max_header_bytes)(in_padded);
|
||||
signal subject_regex_out, subject_regex_reveal_command[max_header_bytes], subject_regex_reveal_amount[max_header_bytes], subject_regex_reveal_currency[max_header_bytes], subject_regex_reveal_recipient[max_header_bytes];
|
||||
(subject_regex_out, subject_regex_reveal_command, subject_regex_reveal_amount, subject_regex_reveal_currency, subject_regex_reveal_recipient) <== WalletSubjectRegex(max_header_bytes)(in_padded);
|
||||
log(subject_regex_out);
|
||||
subject_regex_out === 1;
|
||||
|
||||
reveal_command_packed <== ShiftAndPack(max_header_bytes, max_subject_command_len, pack_size)(subject_regex_reveal_command, command_idx);
|
||||
reveal_amount_packed <== ShiftAndPack(max_header_bytes, max_subject_amount_len, pack_size)(subject_regex_reveal_amount, amount_idx);
|
||||
reveal_currency_packed <== ShiftAndPack(max_header_bytes, max_subject_currency_len, pack_size)(subject_regex_reveal_currency, currency_idx);
|
||||
|
||||
@@ -172,11 +177,13 @@ template EmailVerify(max_header_bytes, max_body_bytes, n, k, pack_size, calculat
|
||||
log(message_id_regex_out);
|
||||
message_id_regex_out === 1;
|
||||
shifted_message_id <== VarShiftLeft(max_header_bytes, max_message_id_len)(message_id_regex_reveal, message_id_idx);
|
||||
log(shifted_message_id[0]);
|
||||
|
||||
// FROM ANON ADDRESS
|
||||
if(calculate_from){
|
||||
signal input custom_message_id_from[max_message_id_len]; // previous message id, used to source past account
|
||||
signal output (salt_is_message_id_from, custom_anon_from_hashed_salt) <== MakeAnonEmailSalt(max_email_from_len, max_message_id_len)(email_from, custom_message_id_from, shifted_message_id);
|
||||
log(salt_is_message_id_from);
|
||||
}
|
||||
|
||||
// RECIPIENT ANON ADDRESS
|
||||
@@ -184,6 +191,7 @@ template EmailVerify(max_header_bytes, max_body_bytes, n, k, pack_size, calculat
|
||||
signal wallet_recipient[max_subject_recipient_len] <== VarShiftLeft(max_header_bytes, max_subject_recipient_len)(subject_regex_reveal_recipient, recipient_idx);
|
||||
signal input custom_message_id_recipient[max_message_id_len]; // previous message id, used to source past account
|
||||
signal output (salt_is_message_id_recipient, custom_anon_recipient_hashed_salt) <== MakeAnonEmailSalt(max_email_recipient_len, max_message_id_len)(wallet_recipient, custom_message_id_recipient, shifted_message_id);
|
||||
log(salt_is_message_id_recipient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
"react-use": "^17.3.2",
|
||||
"readline": "^1.3.0",
|
||||
"serve": "^14.0.1",
|
||||
"snarkjs": "https://github.com/sampritipanda/snarkjs.git#fef81fc51d17a734637555c6edbd585ecda02d9e",
|
||||
"snarkjs": "git+https://github.com/vb7401/snarkjs.git#24981febe8826b6ab76ae4d76cf7f9142919d2b8",
|
||||
"sshpk": "^1.17.0",
|
||||
"styled-components": "^5.3.5",
|
||||
"ts-node": "^10.9.1",
|
||||
|
||||
@@ -146,11 +146,11 @@ function regexToMinDFASpec(str) {
|
||||
// console.log(format_regex_printable(sig_regex));
|
||||
|
||||
// This raw subject line (with \\ replaced with \) can be put into regexr.com to test new match strings and sanity check that it works
|
||||
let email_address_regex = `([a-zA-Z0-9\\._%\\+-=]+@[a-zA-Z0-9\\.-]+)`;
|
||||
let email_address_regex = `([a-zA-Z0-9._%\\+-=]+@[a-zA-Z0-9.-]+)`;
|
||||
// TODO: Other valid chars in email addresses: #$%!^/&*, outlined at https://ladedu.com/valid-characters-for-email-addresses-the-complete-list/ and in the RFC
|
||||
// let send_specific_raw_subject_regex = `((\r\n)|^)subject:[Ss]end (\$)?[0-9]+(.[0-9]+)? [a-zA-Z]+ to (${email_address_regex}|0x[0-9a-fA_F]+)\r\n`;
|
||||
let raw_subject_regex = `((\r\n)|^)subject:[a-zA-Z] (\$)?[0-9]+(.[0-9]+)? [a-zA-Z]+ to (${email_address_regex}|0x[0-9a-fA_F]+)\r\n`;
|
||||
// let raw_subject_regex = `((\r\n)|^)subject:[Ss]end (\\$)?[0-9]+(.[0-9]+)? [a-zA-Z]+ to (([a-zA-Z0-9._%\\+-=]+@[a-zA-Z0-9.-]+)|0x[0-9]+)\r\n`;
|
||||
let raw_subject_regex = `((\r\n)|^)subject:[a-zA-Z]+ (\\$)?[0-9]+(.[0-9]+)? [a-zA-Z]+ to (${email_address_regex}|0x[0-9a-fA_F]+)\r\n`;
|
||||
// let raw_subject_regex = `((\r\n)|^)subject:[a-zA-Z]+ (\\$)?[0-9]+(.[0-9]+)? [a-zA-Z]+ to (([a-zA-Z0-9._%\\+-=]+@[a-zA-Z0-9.-]+)|0x[0-9]+)\r\n`;
|
||||
// Input: ((\\r\\n)|^)subject:[Ss]end (\$)?[0-9]+(.[0-9]+)? [a-zA-Z]+ to (([a-zA-Z0-9._%\+-=]+@[a-zA-Z0-9.-]+)|0x[0-9]+)\\r\\n
|
||||
let raw_from_regex = `(\r\n|^)from:([A-Za-z0-9 _.,"@-]+)<[a-zA-Z0-9_.-]+@[a-zA-Z0-9_.-]+>\r\n`;
|
||||
// let message_id_regex = `(\r\n|^)message-id:<[=@.\\+_-a-zA-Z0-9]+>\r\n`;
|
||||
|
||||
@@ -16,7 +16,7 @@ cd src/contracts
|
||||
forge install openzeppelin/openzeppelin-contracts
|
||||
```
|
||||
|
||||
To test,
|
||||
To test your own contracts, copy TestTwitter.t.sol into a new test file, and make sure you can compile your proof fine. You can run a specific test with `forge test --match test_name`. Then make sure the whole suite passes and isn't above the size limit:
|
||||
|
||||
```
|
||||
forge test
|
||||
|
||||
231
src/contracts/contract.abi
Normal file
231
src/contracts/contract.abi
Normal file
@@ -0,0 +1,231 @@
|
||||
[
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "contract Verifier",
|
||||
"name": "v",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "contract MailServer",
|
||||
"name": "m",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "constructor"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "addressIndexInSignals",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint16",
|
||||
"name": "",
|
||||
"type": "uint16"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"name": "balance",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "body_len",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint16",
|
||||
"name": "",
|
||||
"type": "uint16"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "commitment_len",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint16",
|
||||
"name": "",
|
||||
"type": "uint16"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "email",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"name": "getBalance",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "header_len",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint16",
|
||||
"name": "",
|
||||
"type": "uint16"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "msg_len",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint16",
|
||||
"name": "",
|
||||
"type": "uint16"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "nullifier",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "packSize",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint16",
|
||||
"name": "",
|
||||
"type": "uint16"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "rsa_modulus_chunks_len",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint16",
|
||||
"name": "",
|
||||
"type": "uint16"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "uint256[2]",
|
||||
"name": "a",
|
||||
"type": "uint256[2]"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256[2][2]",
|
||||
"name": "b",
|
||||
"type": "uint256[2][2]"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256[2]",
|
||||
"name": "c",
|
||||
"type": "uint256[2]"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256[34]",
|
||||
"name": "signals",
|
||||
"type": "uint256[34]"
|
||||
}
|
||||
],
|
||||
"name": "transfer",
|
||||
"outputs": [],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "verifiedMailserverKeys",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "verifier",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "contract Verifier",
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
}
|
||||
]
|
||||
@@ -4,10 +4,11 @@ export function bytesToString(bytes: Uint8Array): string {
|
||||
return new TextDecoder().decode(bytes);
|
||||
}
|
||||
|
||||
// stringToUint8Array
|
||||
export function stringToBytes(str: string) {
|
||||
const encodedText = new TextEncoder().encode(str);
|
||||
const toReturn = Uint8Array.from(str, (x) => x.charCodeAt(0));
|
||||
const buf = Buffer.from(str, "utf8");
|
||||
// const buf = Buffer.from(str, "utf8");
|
||||
return toReturn;
|
||||
// TODO: Check encoding mismatch if the proof doesnt work
|
||||
// Note that our custom encoding function maps (239, 191, 189) -> (253)
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
Uint8ArrayToCharArray,
|
||||
assert,
|
||||
mergeUInt8Arrays,
|
||||
int8toBytes,
|
||||
int64toBytes,
|
||||
} from "../helpers/binaryFormat";
|
||||
import { CIRCOM_FIELD_MODULUS, MAX_HEADER_PADDED_BYTES, MAX_BODY_PADDED_BYTES, STRING_PRESELECTOR } from "../../src/helpers/constants";
|
||||
@@ -32,7 +33,7 @@ async function getArgs() {
|
||||
const emailFileArg = args.find((arg) => arg.startsWith("--email_file="));
|
||||
const nonceArg = args.find((arg) => arg.startsWith("--nonce="));
|
||||
|
||||
const email_file = emailFileArg ? emailFileArg.split("=")[1] : "test_sendgrid.eml";
|
||||
const email_file = emailFileArg ? emailFileArg.split("=")[1] : "wallet_test.eml";
|
||||
const nonce = nonceArg ? nonceArg.split("=")[1] : null;
|
||||
|
||||
return { email_file, nonce };
|
||||
@@ -55,17 +56,23 @@ export interface ICircuitInputs {
|
||||
address_plus_one?: string;
|
||||
twitter_username_idx?: string;
|
||||
email_from_idx?: string;
|
||||
|
||||
// Wallet commands only
|
||||
command_idx?: string;
|
||||
message_id_idx?: string;
|
||||
amount_idx?: string;
|
||||
currency_idx?: string;
|
||||
recipient_idx?: string;
|
||||
custom_message_id_from?: string[];
|
||||
custom_message_id_recipient?: string[];
|
||||
}
|
||||
|
||||
enum CircuitType {
|
||||
RSA = "rsa",
|
||||
SHA = "sha",
|
||||
TEST = "test",
|
||||
EMAIL = "email",
|
||||
SUBJECTPARSER = "subjectparser",
|
||||
EMAIL_TWITTER = "email_twitter",
|
||||
EMAIL_WALLET = "email_wallet",
|
||||
}
|
||||
|
||||
async function findSelector(a: Uint8Array, selector: number[]): Promise<number> {
|
||||
@@ -85,6 +92,24 @@ async function findSelector(a: Uint8Array, selector: number[]): Promise<number>
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Returns the part of str that appears after substr
|
||||
function trimStrByStr(str: string, substr: string) {
|
||||
const index = str.indexOf(substr);
|
||||
if (index === -1) return str;
|
||||
return str.slice(index + substr.length, str.length);
|
||||
}
|
||||
|
||||
function strToCharArrayStr(str: string) {
|
||||
return str.split("").map((char) => char.charCodeAt(0).toString());
|
||||
}
|
||||
|
||||
// padWithZero(bodyRemaining, MAX_BODY_PADDED_BYTES)
|
||||
function padWithZero(arr: Uint8Array, length: number) {
|
||||
while (arr.length < length) {
|
||||
arr = mergeUInt8Arrays(arr, int8toBytes(0));
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
export async function getCircuitInputs(
|
||||
rsa_signature: BigInt,
|
||||
rsa_modulus: BigInt,
|
||||
@@ -138,9 +163,7 @@ export async function getCircuitInputs(
|
||||
const bodyRemainingLen = bodyPaddedLen - precomputeText.length;
|
||||
assert(bodyRemainingLen < MAX_BODY_PADDED_BYTES, "Invalid slice");
|
||||
assert(bodyRemaining.length % 64 === 0, "Not going to be padded correctly with int64s");
|
||||
while (bodyRemaining.length < MAX_BODY_PADDED_BYTES) {
|
||||
bodyRemaining = mergeUInt8Arrays(bodyRemaining, int64toBytes(0));
|
||||
}
|
||||
bodyRemaining = padWithZero(bodyRemaining, MAX_BODY_PADDED_BYTES);
|
||||
assert(bodyRemaining.length === MAX_BODY_PADDED_BYTES, "Invalid slice");
|
||||
const bodyShaPrecompute = await partialSha(precomputeText, shaCutoffIndex);
|
||||
|
||||
@@ -162,22 +185,10 @@ export async function getCircuitInputs(
|
||||
|
||||
const USERNAME_SELECTOR = Buffer.from(STRING_PRESELECTOR);
|
||||
|
||||
function trimStrByStr(str: string, substr: string) {
|
||||
const index = str.indexOf(substr);
|
||||
if (index === -1) {
|
||||
return str;
|
||||
}
|
||||
return str.slice(index + substr.length, str.length);
|
||||
}
|
||||
|
||||
let raw_header = Buffer.from(prehash_message_string).toString();
|
||||
const email_from_idx = raw_header.length - trimStrByStr(trimStrByStr(raw_header, "from:"), "<").length;
|
||||
let email_subject = trimStrByStr(raw_header, "subject:");
|
||||
const amount_idx = raw_header.length - trimStrByStr(email_subject, "end ").length;
|
||||
const currency_idx = raw_header.length - trimStrByStr(trimStrByStr(email_subject, "end "), " ").length;
|
||||
const recipient_idx = raw_header.length - trimStrByStr(email_subject, "to ").length;
|
||||
const twitter_username_idx = (Buffer.from(bodyRemaining).indexOf(USERNAME_SELECTOR) + USERNAME_SELECTOR.length).toString();
|
||||
console.log("Indexes into header string are: ", email_from_idx, amount_idx, currency_idx, recipient_idx, twitter_username_idx);
|
||||
let email_subject = trimStrByStr(raw_header, "\r\nsubject:");
|
||||
//in javascript, give me a function that extracts the first word in a string, everything before the first space
|
||||
|
||||
if (circuit === CircuitType.RSA) {
|
||||
circuitInputs = {
|
||||
@@ -185,7 +196,10 @@ export async function getCircuitInputs(
|
||||
signature,
|
||||
base_message,
|
||||
};
|
||||
} else if (circuit === CircuitType.EMAIL) {
|
||||
} else if (circuit === CircuitType.EMAIL_TWITTER) {
|
||||
const twitter_username_idx = (Buffer.from(bodyRemaining).indexOf(USERNAME_SELECTOR) + USERNAME_SELECTOR.length).toString();
|
||||
console.log("Indexes into header string are: ", email_from_idx, twitter_username_idx);
|
||||
|
||||
circuitInputs = {
|
||||
in_padded,
|
||||
modulus,
|
||||
@@ -200,19 +214,38 @@ export async function getCircuitInputs(
|
||||
body_hash_idx,
|
||||
// email_from_idx,
|
||||
};
|
||||
} else if (circuit === CircuitType.SUBJECTPARSER) {
|
||||
} else if (circuit === CircuitType.EMAIL_WALLET) {
|
||||
// First word after "subject:" (usually send/Send)
|
||||
const command = email_subject.split(" ")[0];
|
||||
const command_idx = raw_header.length - email_subject.length;
|
||||
// Index of first word after command
|
||||
const amount_idx = raw_header.length - trimStrByStr(email_subject, command).length;
|
||||
// Index of second word after command
|
||||
const currency_idx = raw_header.length - trimStrByStr(trimStrByStr(email_subject, command), " ").length;
|
||||
// Index of first word after subject and "to"
|
||||
const recipient_idx = raw_header.length - trimStrByStr(email_subject, " to ").length;
|
||||
// Used to get the private message-id
|
||||
const message_id_idx = raw_header.length - trimStrByStr(raw_header, "\r\nmessage-id:<").length;
|
||||
const message_id = raw_header.slice(message_id_idx).split(">\r\n")[0];
|
||||
const MAX_MESSAGE_ID_LEN = 128;
|
||||
const message_id_array = await Uint8ArrayToCharArray(padWithZero(stringToBytes(message_id), MAX_MESSAGE_ID_LEN));
|
||||
console.log("Indexes into header string are: ", email_from_idx, amount_idx, currency_idx, recipient_idx);
|
||||
|
||||
circuitInputs = {
|
||||
in_padded,
|
||||
modulus,
|
||||
signature,
|
||||
in_len_padded_bytes,
|
||||
address,
|
||||
address_plus_one,
|
||||
body_hash_idx,
|
||||
email_from_idx: email_from_idx.toString(),
|
||||
command_idx: command_idx.toString(),
|
||||
message_id_idx: message_id_idx.toString(),
|
||||
amount_idx: amount_idx.toString(),
|
||||
currency_idx: currency_idx.toString(),
|
||||
recipient_idx: recipient_idx.toString(),
|
||||
custom_message_id_from: message_id_array,
|
||||
custom_message_id_recipient: message_id_array,
|
||||
};
|
||||
} else {
|
||||
assert(circuit === CircuitType.SHA, "Invalid circuit type");
|
||||
@@ -253,7 +286,7 @@ export async function generate_inputs(raw_email: Buffer | string, eth_address: s
|
||||
const _ = result.results[0].publicKey.toString();
|
||||
console.log("DKIM verification successful");
|
||||
// try {
|
||||
// // TODO: Condiiton code on if there is an internet connection, run this code
|
||||
// // TODO: Condition code on if there is an internet connection, run this code
|
||||
// var frozen = Cryo.stringify(result);
|
||||
// fs.writeFileSync(`./email_cache_2.json`, frozen, { flag: "w" });
|
||||
// } catch (e) {
|
||||
@@ -265,7 +298,7 @@ export async function generate_inputs(raw_email: Buffer | string, eth_address: s
|
||||
let message = result.results[0].status.signature_header;
|
||||
let body = result.results[0].body;
|
||||
let body_hash = result.results[0].bodyHash;
|
||||
let circuitType = CircuitType.SUBJECTPARSER;
|
||||
let circuitType = CircuitType.EMAIL_WALLET;
|
||||
|
||||
let pubkey = result.results[0].publicKey;
|
||||
const pubKeyData = pki.publicKeyFromPem(pubkey.toString());
|
||||
@@ -274,22 +307,6 @@ export async function generate_inputs(raw_email: Buffer | string, eth_address: s
|
||||
return fin_result.circuitInputs;
|
||||
}
|
||||
|
||||
// Only called when the whole function is called from the command line, to read inputs
|
||||
async function do_generate(writeToFile: boolean = true) {
|
||||
const { email_file, nonce } = await getArgs();
|
||||
const email = fs.readFileSync(email_file.trim());
|
||||
console.log(email);
|
||||
const gen_inputs = await generate_inputs(email, "0x0000000000000000000000000000000000000000", nonce);
|
||||
console.log(JSON.stringify(gen_inputs));
|
||||
if (writeToFile) {
|
||||
const file_dir = email_file.substring(0, email_file.lastIndexOf("/") + 1);
|
||||
const filename = nonce ? `${file_dir}/input_${nonce}.json` : "./circuits/inputs/input.json";
|
||||
console.log(`Writing to default file ${filename}`);
|
||||
fs.writeFileSync(filename, JSON.stringify(gen_inputs), { flag: "w" });
|
||||
}
|
||||
return gen_inputs;
|
||||
}
|
||||
|
||||
// Sometimes, newline encodings re-encode \r\n as just \n, so re-insert the \r so that the email hashes correctly
|
||||
export async function insert13Before10(a: Uint8Array): Promise<Uint8Array> {
|
||||
let ret = new Uint8Array(a.length + 1000);
|
||||
@@ -306,7 +323,24 @@ export async function insert13Before10(a: Uint8Array): Promise<Uint8Array> {
|
||||
return ret.slice(0, j);
|
||||
}
|
||||
|
||||
// Only called when the whole function is called from the command line, to read inputs
|
||||
// Will generate a test proof with the empty Ethereum address, that cannot be proven by anybody else
|
||||
async function test_generate(writeToFile: boolean = true) {
|
||||
const { email_file, nonce } = await getArgs();
|
||||
const email = fs.readFileSync(email_file.trim());
|
||||
console.log(email);
|
||||
const gen_inputs = await generate_inputs(email, "0x0000000000000000000000000000000000000000", nonce);
|
||||
console.log(JSON.stringify(gen_inputs));
|
||||
if (writeToFile) {
|
||||
const file_dir = email_file.substring(0, email_file.lastIndexOf("/") + 1);
|
||||
const filename = nonce ? `${file_dir}/input_${nonce}.json` : "./circuits/inputs/input.json";
|
||||
console.log(`Writing to default file ${filename}`);
|
||||
fs.writeFileSync(filename, JSON.stringify(gen_inputs), { flag: "w" });
|
||||
}
|
||||
return gen_inputs;
|
||||
}
|
||||
|
||||
// If file called directly with `npx tsx generate_inputs.ts`
|
||||
if (typeof require !== "undefined" && require.main === module) {
|
||||
do_generate(true);
|
||||
test_generate(true);
|
||||
}
|
||||
|
||||
146
yarn.lock
146
yarn.lock
@@ -2280,13 +2280,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@iden3/binfileutils@npm:0.0.11":
|
||||
version: 0.0.11
|
||||
resolution: "@iden3/binfileutils@npm:0.0.11"
|
||||
"@iden3/binfileutils@npm:0.0.10":
|
||||
version: 0.0.10
|
||||
resolution: "@iden3/binfileutils@npm:0.0.10"
|
||||
dependencies:
|
||||
fastfile: 0.0.20
|
||||
fastfile: 0.0.19
|
||||
ffjavascript: ^0.2.48
|
||||
checksum: ca61db1325c7e038c6bd723c856eff5f2c82c76394db09d3350ef4f5b7525e3c9ab1f7429900ff5d3e9d26c5970bf5900e6126ccb5c5caa597c16a47336a6be8
|
||||
checksum: cdeb8ac01e12f485d9fb236654c00d5d5016fc89eae24f7822885dd42f09935cbef601dbdd8a0c96dfb00ded9f4f623e0eec0b568aa86d16522cf77ce6f9498b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -5706,6 +5706,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"big-integer@npm:^1.6.42, big-integer@npm:^1.6.48":
|
||||
version: 1.6.51
|
||||
resolution: "big-integer@npm:1.6.51"
|
||||
checksum: 3d444173d1b2e20747e2c175568bedeebd8315b0637ea95d75fd27830d3b8e8ba36c6af40374f36bdaea7b5de376dcada1b07587cb2a79a928fccdb6e6e3c518
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"big.js@npm:^5.2.2":
|
||||
version: 5.2.2
|
||||
resolution: "big.js@npm:5.2.2"
|
||||
@@ -6692,14 +6699,14 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"circom_runtime@npm:0.1.21":
|
||||
version: 0.1.21
|
||||
resolution: "circom_runtime@npm:0.1.21"
|
||||
"circom_runtime@npm:0.1.17":
|
||||
version: 0.1.17
|
||||
resolution: "circom_runtime@npm:0.1.17"
|
||||
dependencies:
|
||||
ffjavascript: 0.2.56
|
||||
ffjavascript: 0.2.48
|
||||
bin:
|
||||
calcwit: calcwit.js
|
||||
checksum: 3071f1e0fba9a5fb41c940454edb911ce09edfd5d0bd12156ec79045a0bf3ff2cc5b35f46e84e42902ef8bb0a4166f428b75d0ceb363c0d485f1a111b27daba1
|
||||
checksum: 595fc0cc3a62ba5daf8d849feae41c48805c0df43965f85dde4dc434efb607e455fa7801d41c1feacfe0c3c71952a45cd3985abf26fde40c54138392891afd8c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -8366,7 +8373,7 @@ __metadata:
|
||||
readline: ^1.3.0
|
||||
selenium-webdriver: ^4.8.1
|
||||
serve: ^14.0.1
|
||||
snarkjs: "https://github.com/sampritipanda/snarkjs.git#fef81fc51d17a734637555c6edbd585ecda02d9e"
|
||||
snarkjs: "git+https://github.com/vb7401/snarkjs.git#24981febe8826b6ab76ae4d76cf7f9142919d2b8"
|
||||
sshpk: ^1.17.0
|
||||
styled-components: ^5.3.5
|
||||
ts-node: ^10.9.1
|
||||
@@ -8447,13 +8454,13 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"ejs@npm:^3.1.6":
|
||||
version: 3.1.8
|
||||
resolution: "ejs@npm:3.1.8"
|
||||
version: 3.1.9
|
||||
resolution: "ejs@npm:3.1.9"
|
||||
dependencies:
|
||||
jake: ^10.8.5
|
||||
bin:
|
||||
ejs: bin/cli.js
|
||||
checksum: 1d40d198ad52e315ccf37e577bdec06e24eefdc4e3c27aafa47751a03a0c7f0ec4310254c9277a5f14763c3cd4bbacce27497332b2d87c74232b9b1defef8efc
|
||||
checksum: af6f10eb815885ff8a8cfacc42c6b6cf87daf97a4884f87a30e0c3271fedd85d76a3a297d9c33a70e735b97ee632887f85e32854b9cdd3a2d97edf931519a35f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -9780,10 +9787,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"fastfile@npm:0.0.20":
|
||||
version: 0.0.20
|
||||
resolution: "fastfile@npm:0.0.20"
|
||||
checksum: e5d6e5f57a9b58c9534202e477cbffbca2182c407171950695ddb5c3e6b89554bc8561fbb6e370c99e371a8f23486a23fbaca527827886cec4897d481cbd03b6
|
||||
"fastfile@npm:0.0.19, fastfile@npm:^0.0.19":
|
||||
version: 0.0.19
|
||||
resolution: "fastfile@npm:0.0.19"
|
||||
checksum: 6179bdd7c21be9882294dae66103795c099594098b51958bcf08a4545c91387321b43511730d0542a5a9ed8c5ec9069c065e065fd67255453ac900a23895dac1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -9861,18 +9868,19 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ffjavascript@npm:0.2.56":
|
||||
version: 0.2.56
|
||||
resolution: "ffjavascript@npm:0.2.56"
|
||||
"ffjavascript@npm:0.2.48":
|
||||
version: 0.2.48
|
||||
resolution: "ffjavascript@npm:0.2.48"
|
||||
dependencies:
|
||||
wasmbuilder: 0.0.16
|
||||
wasmcurves: 0.2.0
|
||||
big-integer: ^1.6.48
|
||||
wasmbuilder: ^0.0.12
|
||||
wasmcurves: 0.1.0
|
||||
web-worker: ^1.2.0
|
||||
checksum: d4e02263db4a94d111cdc7c1211ae96769370f5c8c3c338331e0ef99faed7b55e640bedf23fa8a83fc9a77f0e81140ea8f32e392812a00e15ca504221b879a4f
|
||||
checksum: 68beae9a4f642c06656685353b84fd7655020ca0e628ea046e94452ab779587953cc45cde106d74b68be7177b49c8f19b105d6552c4a1d715e784ae9e7c9ed34
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ffjavascript@npm:^0.2.45, ffjavascript@npm:^0.2.48":
|
||||
"ffjavascript@npm:^0.2.45":
|
||||
version: 0.2.57
|
||||
resolution: "ffjavascript@npm:0.2.57"
|
||||
dependencies:
|
||||
@@ -9883,6 +9891,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ffjavascript@npm:^0.2.48":
|
||||
version: 0.2.59
|
||||
resolution: "ffjavascript@npm:0.2.59"
|
||||
dependencies:
|
||||
wasmbuilder: 0.0.16
|
||||
wasmcurves: 0.2.1
|
||||
web-worker: ^1.2.0
|
||||
checksum: a2e77936b3b189b4728c625d04c2740ff7e2216970c7ba19ef0d480447ab770d08a01c036dbd906a3f587c297b697318e8cdaaaf2ec5d503003703e72dc82f30
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"figgy-pudding@npm:^3.5.1":
|
||||
version: 3.5.2
|
||||
resolution: "figgy-pudding@npm:3.5.2"
|
||||
@@ -9936,7 +9955,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"filelist@npm:^1.0.1":
|
||||
"filelist@npm:^1.0.4":
|
||||
version: 1.0.4
|
||||
resolution: "filelist@npm:1.0.4"
|
||||
dependencies:
|
||||
@@ -12121,16 +12140,16 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"jake@npm:^10.8.5":
|
||||
version: 10.8.5
|
||||
resolution: "jake@npm:10.8.5"
|
||||
version: 10.8.6
|
||||
resolution: "jake@npm:10.8.6"
|
||||
dependencies:
|
||||
async: ^3.2.3
|
||||
chalk: ^4.0.2
|
||||
filelist: ^1.0.1
|
||||
minimatch: ^3.0.4
|
||||
filelist: ^1.0.4
|
||||
minimatch: ^3.1.2
|
||||
bin:
|
||||
jake: ./bin/cli.js
|
||||
checksum: 56c913ecf5a8d74325d0af9bc17a233bad50977438d44864d925bb6c45c946e0fee8c4c1f5fe2225471ef40df5222e943047982717ebff0d624770564d3c46ba
|
||||
jake: bin/cli.js
|
||||
checksum: eebebd3ca62a01ced630afc116f429d727d34bebe58a9424c0d5a0618ad6c1db893163fb4fbcdff01f34d34d6d63c0dd2448de598270bcd27d9440630de4aeea
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -16638,15 +16657,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"r1csfile@npm:0.0.41":
|
||||
version: 0.0.41
|
||||
resolution: "r1csfile@npm:0.0.41"
|
||||
"r1csfile@npm:0.0.35":
|
||||
version: 0.0.35
|
||||
resolution: "r1csfile@npm:0.0.35"
|
||||
dependencies:
|
||||
"@iden3/bigarray": 0.0.2
|
||||
"@iden3/binfileutils": 0.0.11
|
||||
fastfile: 0.0.20
|
||||
ffjavascript: 0.2.56
|
||||
checksum: eec689416f66f09db2d6ca66fac1ef6841b088ab29abcde487145ebd2110916c92583e11ac86f0cdcc4e8a3a7c7df9ff5352ad959e8ae385d37c3b51cec5cf4d
|
||||
"@iden3/binfileutils": 0.0.10
|
||||
fastfile: 0.0.19
|
||||
ffjavascript: 0.2.48
|
||||
checksum: 84f7b4eab5bcdd6a3f6d699998c9479a5eff8d670383d4f0c5afc08431f45353abab9a8b07eeabaef89807e24b0ba50611d4d6280eb6c3a7483e1487a91f0ac6
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -18386,24 +18405,23 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"snarkjs@https://github.com/sampritipanda/snarkjs.git#fef81fc51d17a734637555c6edbd585ecda02d9e":
|
||||
version: 0.5.0
|
||||
resolution: "snarkjs@https://github.com/sampritipanda/snarkjs.git#commit=fef81fc51d17a734637555c6edbd585ecda02d9e"
|
||||
"snarkjs@git+https://github.com/vb7401/snarkjs.git#24981febe8826b6ab76ae4d76cf7f9142919d2b8":
|
||||
version: 0.4.12
|
||||
resolution: "snarkjs@https://github.com/vb7401/snarkjs.git#commit=24981febe8826b6ab76ae4d76cf7f9142919d2b8"
|
||||
dependencies:
|
||||
"@iden3/binfileutils": 0.0.11
|
||||
bfj: ^7.0.2
|
||||
"@iden3/binfileutils": 0.0.10
|
||||
blake2b-wasm: ^2.4.0
|
||||
circom_runtime: 0.1.21
|
||||
circom_runtime: 0.1.17
|
||||
ejs: ^3.1.6
|
||||
fastfile: 0.0.20
|
||||
ffjavascript: 0.2.56
|
||||
fastfile: ^0.0.19
|
||||
ffjavascript: 0.2.48
|
||||
js-sha3: ^0.8.0
|
||||
localforage: ^1.10.0
|
||||
logplease: ^1.2.15
|
||||
r1csfile: 0.0.41
|
||||
r1csfile: 0.0.35
|
||||
readline: ^1.3.0
|
||||
bin:
|
||||
snarkjs: build/cli.cjs
|
||||
checksum: f2050f0135d50d459ea0edddf3e394e833a2d28c6648e5889b2f896814865e5c60606e978a8a106bd5bfe7e27501c315f249db5b71895d5e7e6e9a87bfcd55ab
|
||||
checksum: 9011df4b58475a0b4ae988f8b459a9a4d2bb5d2b60221d0ec370a10f2492c88909768215f3b22e514b2cf24dca79818790447005a33ed6aee177b9fda6948a75
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -20556,6 +20574,25 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"wasmbuilder@npm:^0.0.12":
|
||||
version: 0.0.12
|
||||
resolution: "wasmbuilder@npm:0.0.12"
|
||||
dependencies:
|
||||
big-integer: ^1.6.48
|
||||
checksum: 327b3c50b0e1e5e3aac9e218e0f96fdc638b7952ab86acc2ad53960371996826dbb0a8095edce482cf1d9c245d96884449701909bc962920aa7ec8241db01214
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"wasmcurves@npm:0.1.0":
|
||||
version: 0.1.0
|
||||
resolution: "wasmcurves@npm:0.1.0"
|
||||
dependencies:
|
||||
big-integer: ^1.6.42
|
||||
blakejs: ^1.1.0
|
||||
checksum: 6bf6719e659a88904af0b98d152316e3b22435ca6a2cfc8bbf4530576806f17b2776b2c7d91d1a678fe0d51485a0d1748efcd080808c181c7977bee50b26efa9
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"wasmcurves@npm:0.2.0":
|
||||
version: 0.2.0
|
||||
resolution: "wasmcurves@npm:0.2.0"
|
||||
@@ -20565,6 +20602,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"wasmcurves@npm:0.2.1":
|
||||
version: 0.2.1
|
||||
resolution: "wasmcurves@npm:0.2.1"
|
||||
dependencies:
|
||||
wasmbuilder: 0.0.16
|
||||
checksum: 3bfd6c3bf339e5e3980590afecf83d5a06fbb0ec8d4e1612c5d7a8edd90173c05270b45832330964eac281c70b9d04229de430673952c6516c2feb9c42d2ab03
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"watchpack-chokidar2@npm:^2.0.1":
|
||||
version: 2.0.1
|
||||
resolution: "watchpack-chokidar2@npm:2.0.1"
|
||||
|
||||
Reference in New Issue
Block a user