From 1cc8f4661c666fb49625cf935877ff5e5d88b524 Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Wed, 15 Jun 2022 12:59:31 +0200 Subject: [PATCH] fix(credentials): parse and validate preview @type (#861) Signed-off-by: Timo Glastra --- .../protocol/v2/messages/V2CredentialPreview.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/core/src/modules/credentials/protocol/v2/messages/V2CredentialPreview.ts b/packages/core/src/modules/credentials/protocol/v2/messages/V2CredentialPreview.ts index 7b70be910e..d566faa1a0 100644 --- a/packages/core/src/modules/credentials/protocol/v2/messages/V2CredentialPreview.ts +++ b/packages/core/src/modules/credentials/protocol/v2/messages/V2CredentialPreview.ts @@ -1,9 +1,10 @@ import type { CredentialPreviewOptions } from '../../../models/CredentialPreviewAttribute' -import { Expose, Type } from 'class-transformer' -import { Equals, IsInstance, ValidateNested } from 'class-validator' +import { Expose, Transform, Type } from 'class-transformer' +import { IsInstance, ValidateNested } from 'class-validator' import { JsonTransformer } from '../../../../../utils/JsonTransformer' +import { IsValidMessageType, parseMessageType, replaceLegacyDidSovPrefix } from '../../../../../utils/messageType' import { CredentialPreviewAttribute } from '../../../models/CredentialPreviewAttribute' /** @@ -21,9 +22,12 @@ export class V2CredentialPreview { } @Expose({ name: '@type' }) - @Equals(V2CredentialPreview.type) - public type = V2CredentialPreview.type - public static type = 'https://didcomm.org/issue-credential/2.0/credential-preview' + @IsValidMessageType(V2CredentialPreview.type) + @Transform(({ value }) => replaceLegacyDidSovPrefix(value), { + toClassOnly: true, + }) + public readonly type = V2CredentialPreview.type.messageTypeUri + public static readonly type = parseMessageType('https://didcomm.org/issue-credential/2.0/credential-preview') @Type(() => CredentialPreviewAttribute) @ValidateNested({ each: true })