Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,15 @@ app.post("/verify", async (req, res) => {
const proof = receipt?.metadata?.proof;
const proofCanonical = String(proof?.canonical_id || proof?.canonical || "");
const runtimeCoreReceipt = normalizeReceiptForRuntimeCoreVerify(receipt);
const verb = String(receipt?.x402?.verb || "").trim();

console.error("[verify] entered", {
wantSchema,
wantEns,
verb,
VERIFY_SCHEMA_CACHED_ONLY,
hasValidatorCached: hasValidatorCached(verb),
});

const verifyLogic = async () => {
if (!proof?.signature_b64 || !proof?.hash_sha256) {
Expand All @@ -1754,6 +1763,7 @@ app.post("/verify", async (req, res) => {
let ensExpect = null;

if (wantEns) {
console.error("[verify] entering ENS resolution", { verb });
const signerForEns = String(proof?.signer_id || runtimeConfig.signerId || "").trim();
const ensOut = await fetchEnsSignerBundle({ signerName: signerForEns, refresh });

Expand Down Expand Up @@ -1826,6 +1836,7 @@ app.post("/verify", async (req, res) => {
// 2) verify signature/hash via runtime-core
let v;
try {
console.error("[verify] entering crypto verify", { verb });
v = verifyReceiptEd25519Sha256(runtimeCoreReceipt, {
publicKeyPemOrDer: pubPem,
allowedCanonicals: [runtimeConfig.canonicalId],
Expand Down Expand Up @@ -1862,11 +1873,12 @@ app.post("/verify", async (req, res) => {

if (wantSchema) {
schemaOk = false;
const verb = String(receipt?.x402?.verb || "").trim();
const validatorCached = hasValidatorCached(verb);

if (!verb) {
schemaErrors = [{ message: "missing receipt.x402.verb" }];
} else if (VERIFY_SCHEMA_CACHED_ONLY && !hasValidatorCached(verb)) {
} else if (VERIFY_SCHEMA_CACHED_ONLY && !validatorCached) {
console.error("[verify] returning 202 validator_not_warmed_yet", { verb });
warmQueue.add(verb);
startWarmWorker();

Expand All @@ -1891,6 +1903,11 @@ app.post("/verify", async (req, res) => {
});
} else {
try {
console.error("[verify] entering schema validation path", {
verb,
cachedOnly: VERIFY_SCHEMA_CACHED_ONLY,
validatorCached,
});
const validate = VERIFY_SCHEMA_CACHED_ONLY ? validatorCache.get(verb)?.validate : await getValidatorForVerb(verb);
if (!validate) {
schemaOk = false;
Expand Down
Loading