Skip to content

Commit

Permalink
chore: minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas-londhe committed Oct 13, 2024
1 parent 019169b commit b7c3f00
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 83 deletions.
25 changes: 11 additions & 14 deletions frontend/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,18 @@ export default function Home() {
const generateProof = async (jwt: string, pubkey: any) => {
try {
setStepStatuses((prev) => ["success", "processing", "idle"]);

const response1 = await axios.post("/api/generateCircuitInputs", {
jwt,
pubkey,
maxMessageLength: 1024,
});

console.log("Sending to proxyJwtProver:", {
input: response1.data,
});
const response2 = await axios.post("/api/proxyJwtProver", {
input: response1.data,
const circuitInputs = await axios.post(
"/api/generateCircuitInputs",
{
jwt,
pubkey,
maxMessageLength: 1024,
}
);
const proverResponse = await axios.post("/api/proxyJwtProver", {
input: circuitInputs.data,
});
console.log("Proof:", response2.data.proof);
setProof(response2.data.proof);
setProof(proverResponse.data.proof);
setStepStatuses((prev) => ["success", "success", "success"]);
} catch (error) {
console.error("Error generating proof:", error);
Expand Down
50 changes: 25 additions & 25 deletions frontend/pages/api/generateCircuitInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method === "POST") {
try {
console.log("req.body", req.body);
const { jwt, pubkey, maxMessageLength } = req.body;
if (!jwt || !pubkey || !maxMessageLength) {
res.status(400).json({ error: "Missing required fields" });
return;
}
const accountCode = await genAccountCode();
console.log("accountCode", accountCode);
const circuitInputs = await generateJWTVerifierInputs(
jwt,
pubkey,
accountCode,
{
maxMessageLength: maxMessageLength,
}
);
console.log("circuitInputs", circuitInputs);
res.status(200).json(circuitInputs);
} catch (error) {
res.status(500).json({ error: "Failed to generate inputs" });
}
} else {
if (req.method !== "POST") {
res.setHeader("Allow", ["POST"]);
res.status(405).end(`Method ${req.method} Not Allowed`);
return res.status(405).end(`Method ${req.method} Not Allowed`);
}

try {
const { jwt, pubkey, maxMessageLength } = req.body;

if (!jwt || !pubkey || !maxMessageLength) {
return res.status(400).json({ error: "Missing required fields" });
}

const accountCode = await genAccountCode();
const circuitInputs = await generateJWTVerifierInputs(
jwt,
pubkey,
accountCode,
{
maxMessageLength,
}
);

res.status(200).json(circuitInputs);
} catch (error) {
console.error("Error generating circuit inputs:", error);
res.status(500).json({ error: "Failed to generate inputs" });
}
}
81 changes: 37 additions & 44 deletions frontend/pages/api/proxyJwtProver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,50 @@ export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method === "POST") {
try {
console.log("Received request body:", req.body);
if (req.method !== "POST") {
res.setHeader("Allow", ["POST"]);
return res.status(405).end(`Method ${req.method} Not Allowed`);
}

const response = await axios.post(
"https://zkemail--jwt-prover-v0-1-0-flask-app.modal.run/prove/jwt",
req.body,
{
headers: {
"Content-Type": "application/json",
},
}
);
try {
const response = await axios.post(
"https://zkemail--jwt-prover-v0-1-0-flask-app.modal.run/prove/jwt",
req.body,
{
headers: {
"Content-Type": "application/json",
},
}
);

console.log("Prover response:", response.data);
res.status(200).json(response.data);
} catch (error) {
console.error("Error proxying request to JWT prover:", error);
res.status(200).json(response.data);
} catch (error) {
console.error("Error proxying request to JWT prover:", error);

if (axios.isAxiosError(error)) {
if (error.response) {
console.error(
"Prover error response:",
error.response.data
);
res.status(error.response.status).json({
error: "Error from JWT prover service",
message: error.response.data,
status: error.response.status,
});
} else if (error.request) {
res.status(503).json({
error: "No response from JWT prover service",
message: "The service might be down or unreachable",
});
} else {
res.status(500).json({
error: "Error setting up request to JWT prover",
message: error.message,
});
}
if (axios.isAxiosError(error)) {
if (error.response) {
res.status(error.response.status).json({
error: "Error from JWT prover service",
message: error.response.data,
status: error.response.status,
});
} else if (error.request) {
res.status(503).json({
error: "No response from JWT prover service",
message: "The service might be down or unreachable",
});
} else {
res.status(500).json({
error: "Unknown error occurred",
message:
"An unexpected error occurred while processing the request",
error: "Error setting up request to JWT prover",
message: error.message,
});
}
} else {
res.status(500).json({
error: "Unknown error occurred",
message:
"An unexpected error occurred while processing the request",
});
}
} else {
res.setHeader("Allow", ["POST"]);
res.status(405).end(`Method ${req.method} Not Allowed`);
}
}

0 comments on commit b7c3f00

Please sign in to comment.