Skip to content

Commit

Permalink
♻️ api: use safe parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jgalat committed Dec 11, 2023
1 parent 4962924 commit 9399f30
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pomelo/api/transactions/authorizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { VercelRequest, VercelResponse } from "@vercel/node";

import buffer from "../../utils/buffer.js";
import processTransaction from "../../utils/transaction.js";
import type { AuthorizationRequest } from "../../utils/types.js";
import { authorizationRequest } from "../../utils/types.js";
import { signResponse, verifySignature } from "../../utils/verify.js";

export const runtime = "nodejs";
Expand All @@ -25,6 +25,12 @@ export default async function authorizations(request: VercelRequest, response: V
return response.status(403).end("forbidden");
}

const tx = await processTransaction(JSON.parse(raw) as AuthorizationRequest);
return signResponse(request, response.status(200), JSON.stringify(tx));
const parsed = authorizationRequest.safeParse(raw);

if (parsed.success) {
const tx = await processTransaction(parsed.data);
return signResponse(request, response.status(200), JSON.stringify(tx));
} else {
return response.status(400).end("bad request");
}
}

0 comments on commit 9399f30

Please sign in to comment.