import { PresentationValidator } from '../presentationValidatorFactory.js'; import { ValidationResult } from '../../shared/dto/validationResult.dto.js'; import { EbsiWrapper } from '../../shared/middleware/ebsiWrapper.js'; import { PresentationValidationOptions } from '../../shared/dto/validationOptions.dto.js'; import { DcqlPresentation } from './dcqlPresentation.js'; export class EbsiPresentationValidator implements PresentationValidator { constructor( private ebsiWrapper: EbsiWrapper, private options: PresentationValidationOptions, ) {} async validate( presentation: DcqlPresentation, audience: string, ): Promise { try { for (const { id } of this.options.dcqlQuery.credentials) { const vp = presentation[id] as string[]; for (const jwt of vp) { await this.ebsiWrapper.verifyPresentationJwt(jwt, audience, { ebsiAuthority: this.options.ebsiAuthority, }); } } return { valid: true }; } catch (e) { this.options.verifiablePresentationValidationReport?.updateFailedPresentation( [e.message], ); return { valid: false, messages: [e.message], }; } } }