Skip to content

Commit 687705d

Browse files
authored
Merge pull request #12 from commandlayer/codex/fix-syntax-error-in-server.mjs
simplify /verify handler to remove dangling IIFE closure risk
2 parents fc0d4b6 + 8c34200 commit 687705d

1 file changed

Lines changed: 37 additions & 38 deletions

File tree

server.mjs

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,20 +1545,18 @@ for (const v of Object.keys(handlers)) {
15451545

15461546
app.post("/verify", async (req, res) => {
15471547
const timer = new Promise((_, rej) => setTimeout(() => rej(new Error("verify_timeout")), VERIFY_MAX_MS));
1548+
const runVerify = async () => {
1549+
const receipt = req.body;
15481550

1549-
try {
1550-
await Promise.race([
1551-
(async () => {
1552-
const receipt = req.body;
1551+
const wantEns = String(req.query.ens || "0") === "1";
1552+
const strictKid = String(req.query.strict_kid || "0") === "1";
1553+
const refresh = String(req.query.refresh || "0") === "1";
1554+
const wantSchema = String(req.query.schema || "0") === "1";
15531555

1554-
const wantEns = String(req.query.ens || "0") === "1";
1555-
const strictKid = String(req.query.strict_kid || "0") === "1";
1556-
const refresh = String(req.query.refresh || "0") === "1";
1557-
const wantSchema = String(req.query.schema || "0") === "1";
1556+
const proof = receipt?.metadata?.proof;
1557+
const proofCanonical = String(proof?.canonical_id || proof?.canonical || "");
1558+
const runtimeCoreReceipt = normalizeReceiptForRuntimeCoreVerify(receipt);
15581559

1559-
const proof = receipt?.metadata?.proof;
1560-
const proofCanonical = String(proof?.canonical_id || proof?.canonical || "");
1561-
const runtimeCoreReceipt = normalizeReceiptForRuntimeCoreVerify(receipt);
15621560

15631561
if (!proof?.signature_b64 || !proof?.hash_sha256) {
15641562
return res.status(400).json({
@@ -1736,33 +1734,34 @@ app.post("/verify", async (req, res) => {
17361734

17371735
const okFinal = hashMatches === true && signatureValid === true && (wantSchema ? schemaOk === true : true);
17381736

1739-
return res.json({
1740-
ok: okFinal,
1741-
...(okFinal ? {} : { reason: sigErr || (wantSchema && !schemaOk ? "schema_invalid" : "verify_failed") }),
1742-
signer_id: proof?.signer_id ?? null,
1743-
kid: proof?.kid ?? null,
1744-
hash_sha256: proof?.hash_sha256 ?? null,
1745-
verified_with: wantEns ? "ens" : "env",
1746-
checks: {
1747-
schema_valid: schemaOk,
1748-
hash_matches: hashMatches,
1749-
signature_valid: signatureValid,
1750-
ens_match: wantEns ? true : null,
1751-
},
1752-
values: {
1753-
verb: receipt?.x402?.verb ?? null,
1754-
signer_id: proof?.signer_id ?? null,
1755-
kid: proof?.kid ?? null,
1756-
canonical_id: proofCanonical || null,
1757-
pubkey_source: pubSrc,
1758-
ens: ensExpect,
1759-
},
1760-
errors: { schema_errors: schemaErrors, signature_error: sigErr },
1761-
...instancePayload(),
1762-
});
1763-
})(),
1764-
timer,
1765-
]);
1737+
return res.json({
1738+
ok: okFinal,
1739+
...(okFinal ? {} : { reason: sigErr || (wantSchema && !schemaOk ? "schema_invalid" : "verify_failed") }),
1740+
signer_id: proof?.signer_id ?? null,
1741+
kid: proof?.kid ?? null,
1742+
hash_sha256: proof?.hash_sha256 ?? null,
1743+
verified_with: wantEns ? "ens" : "env",
1744+
checks: {
1745+
schema_valid: schemaOk,
1746+
hash_matches: hashMatches,
1747+
signature_valid: signatureValid,
1748+
ens_match: wantEns ? true : null,
1749+
},
1750+
values: {
1751+
verb: receipt?.x402?.verb ?? null,
1752+
signer_id: proof?.signer_id ?? null,
1753+
kid: proof?.kid ?? null,
1754+
canonical_id: proofCanonical || null,
1755+
pubkey_source: pubSrc,
1756+
ens: ensExpect,
1757+
},
1758+
errors: { schema_errors: schemaErrors, signature_error: sigErr },
1759+
...instancePayload(),
1760+
});
1761+
};
1762+
1763+
try {
1764+
await Promise.race([runVerify(), timer]);
17661765
} catch (e) {
17671766
return res.status(500).json({
17681767
ok: false,

0 commit comments

Comments
 (0)