Skip to content

Commit de36cd4

Browse files
committed
return details for jsonld errors
1 parent eef8189 commit de36cd4

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

src/Verify.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ export async function verifyCredential({ credential, knownDIDRegistries}: { cred
9292
checkStatus: statusChecker,
9393
verifyMatchingIssuers: false
9494
});
95-
9695
const adjustedResponse = await transformResponse(verificationResponse, credential, knownDIDRegistries)
9796
return adjustedResponse;
9897
} catch (error) {
@@ -133,9 +132,7 @@ async function transformResponse(verificationResponse: any, credential: Credenti
133132
return verificationResponse as VerificationResponse;
134133
}
135134

136-
function buildFatalErrorObject(fatalErrorMessage: string, name: string, credential: Credential, stackTrace: string | null): VerificationResponse {
137-
return { credential, errors: [{ name, message: fatalErrorMessage, ...(stackTrace ? { stackTrace } : null) }] };
138-
}
135+
139136

140137
function handleAnyFatalCredentialErrors(credential: Credential): VerificationResponse | null {
141138
const validVCContexts = [
@@ -195,17 +192,17 @@ function handleAnySignatureError({ verificationResponse, credential }: { verific
195192
if (verificationResponse.error) {
196193

197194
if (verificationResponse?.error?.name === VERIFICATION_ERROR) {
198-
// Can't validate the signature.
199-
// Either a bad signature or maybe a did:web that can't
200-
// be resolved. Because we can't validate the signature, we
195+
// Can't verify the signature. Maybe a bad signature or a did:web that can't
196+
// be resolved or a json-ld error. Because we can't validate the signature, we
201197
// can't therefore say anything conclusive about the various
202-
// steps in verification.
203-
// So, return a fatal error and no log (because we can't say
204-
// anything meaningful about the steps in the log)
198+
// steps in verification, so return a fatal error and no log
205199
let fatalErrorMessage = ""
206200
let errorName = ""
207201
// check to see if the error is http related
208202
const httpError = verificationResponse.error.errors.find((error: any) => error.name === 'HTTPError')
203+
// or a json-ld parsing error
204+
const jsonLdError = verificationResponse.error.errors.find((error: any) => error.name === 'jsonld.ValidationError')
205+
209206
if (httpError) {
210207
fatalErrorMessage = 'An http error prevented the signature check.'
211208
errorName = HTTP_ERROR_WITH_SIGNATURE_CHECK
@@ -219,8 +216,16 @@ function handleAnySignatureError({ verificationResponse, credential }: { verific
219216
errorName = DID_WEB_UNRESOLVED
220217
}
221218
}
219+
} else if (jsonLdError) {
220+
const errors = verificationResponse.error.errors.map((error:any)=>{
221+
// need to rename the stack property to stackTrace to fit with old error structure
222+
error.stackTrace = error.stack;
223+
delete error.stack;
224+
return error
225+
})
226+
return {credential, errors}
222227
} else {
223-
// not an http error, so likely bad signature
228+
// not an http or json-ld error, so likely bad signature
224229
fatalErrorMessage = 'The signature is not valid.'
225230
errorName = INVALID_SIGNATURE
226231
}
@@ -244,4 +249,6 @@ function handleAnySignatureError({ verificationResponse, credential }: { verific
244249

245250

246251

247-
252+
function buildFatalErrorObject(fatalErrorMessage: string, name: string, credential: Credential, stackTrace: string | null): VerificationResponse {
253+
return { credential, errors: [{ name, message: fatalErrorMessage, ...(stackTrace ? { stackTrace } : null) }] };
254+
}

src/types/result.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
export interface VerificationError {
33
"message": string,
44
"name"?: string,
5+
"details"?: object,
56
"stackTrace"?: any
67
}
78

@@ -28,7 +29,7 @@ export interface VerificationError {
2829
"additionalInformation"?: AdditionalInformationEntry[];
2930
"credential"?: object,
3031
"errors"?: VerificationError[],
31-
"log"?: VerificationStep[]
32+
"log"?: VerificationStep[],
3233
}
3334

3435

0 commit comments

Comments
 (0)