Skip to content

Commit

Permalink
improve proof error logging (#1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-t-wang authored Nov 18, 2024
1 parent fbfbe7c commit edb73d4
Showing 1 changed file with 41 additions and 30 deletions.
71 changes: 41 additions & 30 deletions web/api/v2/verify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,39 +138,50 @@ export async function POST(
});
}

// ANCHOR: Verify the proof with the World ID smart contract
const { error, success } = await verifyProof(
{
signal_hash: parsedParams.signal_hash,
proof: parsedParams.proof,
merkle_root: parsedParams.merkle_root,
nullifier_hash: parsedParams.nullifier_hash,
external_nullifier: action.external_nullifier,
},
{
is_staging: app.is_staging,
verification_level: parsedParams.verification_level,
max_age: parsedParams.max_age,
},
);

if (error || !success) {
await captureEvent({
event: "action_verify_failed",
distinctId: action.id,
properties: {
action_id: action.id,
app_id: app.id,
environment: app.is_staging ? "staging" : "production",
try {
// ANCHOR: Verify the proof with the World ID smart contract
const { error, success } = await verifyProof(
{
signal_hash: parsedParams.signal_hash,
proof: parsedParams.proof,
merkle_root: parsedParams.merkle_root,
nullifier_hash: parsedParams.nullifier_hash,
external_nullifier: action.external_nullifier,
},
{
is_staging: app.is_staging,
verification_level: parsedParams.verification_level,
error: error,
max_age: parsedParams.max_age,
},
});
);

if (error || !success) {
await captureEvent({
event: "action_verify_failed",
distinctId: action.id,
properties: {
action_id: action.id,
app_id: app.id,
environment: app.is_staging ? "staging" : "production",
verification_level: parsedParams.verification_level,
error: error,
},
});
return errorResponse({
statusCode: error?.statusCode || 400,
code: error?.code || AppErrorCodes.GenericError,
detail: error?.message || "There was an error verifying this proof.",
attribute: error?.attribute || null,
req,
});
}
} catch (e: any) {
console.warn("Error verifying proof", { error: e });
return errorResponse({
statusCode: error?.statusCode || 400,
code: error?.code || AppErrorCodes.GenericError,
detail: error?.message || "There was an error verifying this proof.",
attribute: error?.attribute || null,
statusCode: 400,
code: "verification_error",
detail: e.message,
attribute: null,
req,
});
}
Expand Down

0 comments on commit edb73d4

Please sign in to comment.