From 755dc4fb72d654b1ee425244f7bc34043240c2d5 Mon Sep 17 00:00:00 2001 From: James Chartrand Date: Mon, 21 Oct 2024 17:49:27 -0400 Subject: [PATCH] fix check on vc posted to issue endpoint --- src/app.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app.js b/src/app.js index e2643fa..f56afd2 100644 --- a/src/app.js +++ b/src/app.js @@ -22,6 +22,10 @@ async function callService (endpoint, body) { return data } +function isNotValidVC(unSignedVC) { + return !unSignedVC || !Object.keys(unSignedVC).length || !unSignedVC.credentialSubject +} + export async function build (opts = {}) { const { enableStatusService, @@ -88,10 +92,10 @@ export async function build (opts = {}) { const authHeader = req.headers.authorization const body = req.body const unSignedVC = body.credential ? body.credential : body - + 422 await verifyAuthHeader(authHeader, tenantName) // NOTE: we throw the error here which will then be caught by middleware errorhandler - if (!unSignedVC || !Object.keys(unSignedVC).length) throw new IssuingException(400, 'A verifiable credential must be provided in the body') + if (isNotValidVC(unSignedVC)) throw new IssuingException(422, 'A verifiable credential must be provided in the body') const vcWithStatus = enableStatusService ? await callService(`http://${statusService}/credentials/status/allocate`, unSignedVC) : unSignedVC