From ee85dcaa543a39e7b66e35a41bb303a9ff796f57 Mon Sep 17 00:00:00 2001 From: Sebastian Schmittner Date: Thu, 14 Nov 2024 17:31:02 +0100 Subject: [PATCH] fixing a few NPEs --- api/src/routes/verify/index.ts | 2 +- api/src/services/documentLoader/index.ts | 2 +- api/src/services/fetch/index.ts | 2 +- api/src/services/verifier/gs1.ts | 4 ++-- api/src/services/verifier/index.ts | 4 ++-- frontend/package-lock.json | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api/src/routes/verify/index.ts b/api/src/routes/verify/index.ts index 615f6e8..b426c25 100644 --- a/api/src/routes/verify/index.ts +++ b/api/src/routes/verify/index.ts @@ -123,7 +123,7 @@ export class VerifyRoutes { return res .status(StatusCodes.OK) - .json(await GS1Verifier.verify(req.body, challenge, domain)); + .json(await GS1Verifier.verify(req?.body, challenge, domain)); } catch (error) { console.error(error); return res diff --git a/api/src/services/documentLoader/index.ts b/api/src/services/documentLoader/index.ts index 28f2cb9..481defc 100644 --- a/api/src/services/documentLoader/index.ts +++ b/api/src/services/documentLoader/index.ts @@ -63,7 +63,7 @@ const documentLoader: (url: string) => Promise = } if ( - !document.type || + !document?.type || !Array.isArray(document.type) || !uncachedStatusListCredentialTypes.some((t: string) => document.type.includes(t) diff --git a/api/src/services/fetch/index.ts b/api/src/services/fetch/index.ts index 14d1dd2..f831c38 100644 --- a/api/src/services/fetch/index.ts +++ b/api/src/services/fetch/index.ts @@ -25,7 +25,7 @@ export async function fetch_jsonld(url: string): Promise { // search for json-ld link if no json-ld is returned const link = parseLink(response.headers.get('Link')); - if (link && link.alternate && link.alternate.rel == 'alternate' && link.alternate.type == 'application/ld+json') { + if (link?.alternate?.rel == 'alternate' && link?.alternate?.type == 'application/ld+json') { const linkResponse = await fetch(url + link.alternate.url, { method: 'GET', headers: HEADERS }); diff --git a/api/src/services/verifier/gs1.ts b/api/src/services/verifier/gs1.ts index d1fb16f..0dd9369 100644 --- a/api/src/services/verifier/gs1.ts +++ b/api/src/services/verifier/gs1.ts @@ -58,14 +58,14 @@ export class GS1Verifier { domain?: string ): Promise { let result; - if (verifiable.type.includes("VerifiableCredential")) { + if (verifiable?.type.includes?.("VerifiableCredential")) { result = await checkGS1Credential( verifiable, getVerifierFunction(challenge, domain) ); } - if (verifiable.type.includes("VerifiablePresentation")) { + if (verifiable?.type.includes?.("VerifiablePresentation")) { const presentation = verifiable as VerifiablePresentation; result = await verifyGS1Credentials( diff --git a/api/src/services/verifier/index.ts b/api/src/services/verifier/index.ts index cf36609..d4c7191 100644 --- a/api/src/services/verifier/index.ts +++ b/api/src/services/verifier/index.ts @@ -23,7 +23,7 @@ const { } = jsigs; function getSuite(proof: Proof): unknown[] { - switch (proof.type) { + switch (proof?.type) { case "Ed25519Signature2018": return new Ed25519Signature2018(); @@ -36,7 +36,7 @@ function getSuite(proof: Proof): unknown[] { }); default: - throw new Error(`${proof.type} not implemented`); + throw new Error(`${proof?.type} not implemented`); } } diff --git a/frontend/package-lock.json b/frontend/package-lock.json index bdec954..1554da6 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "verifier_frontend", - "version": "1.5.2", + "version": "2.0.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "verifier_frontend", - "version": "1.5.2", + "version": "2.0.3", "license": "AGPL-3.0", "dependencies": { "axios": "^1.1.3",