diff --git a/lib/types/Internal.types.ts b/lib/types/Internal.types.ts index 0c7115eb..09d50a35 100644 --- a/lib/types/Internal.types.ts +++ b/lib/types/Internal.types.ts @@ -92,6 +92,8 @@ export class InternalPresentationDefinitionV2 implements PresentationDefinitionV export interface DiscoveredVersion { version?: PEVersion; error?: string; + v1Errors?: any + v2Errors?: any } export type IPresentationDefinition = PresentationDefinitionV1 | PresentationDefinitionV2; diff --git a/lib/types/SSITypesBuilder.ts b/lib/types/SSITypesBuilder.ts index c6ee4847..86bfa01b 100644 --- a/lib/types/SSITypesBuilder.ts +++ b/lib/types/SSITypesBuilder.ts @@ -63,7 +63,11 @@ export class SSITypesBuilder { static toInternalPresentationDefinition(presentationDefinition: IPresentationDefinition): IInternalPresentationDefinition { const presentationDefinitionCopy: IPresentationDefinition = JSON.parse(JSON.stringify(presentationDefinition)); const versionResult: DiscoveredVersion = definitionVersionDiscovery(presentationDefinitionCopy); - if (versionResult.error) throw versionResult.error; + if (versionResult.error) { + throw new Error( + `${versionResult.error} \nv1 errors:\n${JSON.stringify(versionResult.v1Errors, null, 2)} \n\nv2 errors:\n${JSON.stringify(versionResult.v2Errors, null, 2)}`, + ); + } if (versionResult.version == PEVersion.v1) { return SSITypesBuilder.modelEntityToInternalPresentationDefinitionV1(presentationDefinitionCopy as PresentationDefinitionV1); } diff --git a/lib/utils/VCUtils.ts b/lib/utils/VCUtils.ts index 0e29cf15..82d4115b 100644 --- a/lib/utils/VCUtils.ts +++ b/lib/utils/VCUtils.ts @@ -35,14 +35,26 @@ export function definitionVersionDiscovery(presentationDefinition: IPresentation JsonPathUtils.changePropertyNameRecursively(presentationDefinitionCopy, '_enum', 'enum'); const data = { presentation_definition: presentationDefinitionCopy }; let result = validatePDv2(data); + if (result) { return { version: PEVersion.v2 }; } + // Errors are added to the validation method, but not typed correctly + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const v2Errors = validatePDv2.errors; + result = validatePDv1(data); if (result) { return { version: PEVersion.v1 }; } - return { error: 'This is not a valid PresentationDefinition' }; + + // Errors are added to the validation method, but not typed correctly + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const v1Errors = validatePDv1.errors; + + return { error: 'This is not a valid PresentationDefinition', v1Errors, v2Errors }; } export function uniformDIDMethods(dids?: string[], opts?: { removePrefix: 'did:' }) {