Skip to content

Commit

Permalink
fix(core): convert legacy prefix for inner msgs (#479)
Browse files Browse the repository at this point in the history
This commit adds legacy type prefix support for CredentialPreview,
PresentationPreview and SignatureDecorator.

It does this by converting replacing the
`did:sov:BzCbsNYhMrjHiqZDTUASHg;spec` legacy prefix with the newer
`https://didcomm.org` prefix.

Signed-off-by: Karim Stekelenburg <[email protected]>
  • Loading branch information
karimStekelenburg authored Oct 7, 2021
1 parent cf236df commit a2b655a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/core/src/decorators/signature/SignatureDecorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Expose } from 'class-transformer'
import { Expose, Transform } from 'class-transformer'
import { IsString, Matches } from 'class-validator'

import { MessageTypeRegExp } from '../../agent/BaseMessage'
import { replaceLegacyDidSovPrefix } from '../../utils/messageType'

/**
* Represents `[field]~sig` decorator
Expand All @@ -18,6 +19,9 @@ export class SignatureDecorator {
}

@Expose({ name: '@type' })
@Transform(({ value }) => replaceLegacyDidSovPrefix(value), {
toClassOnly: true,
})
@Matches(MessageTypeRegExp)
public signatureType!: string

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Expose, Type } from 'class-transformer'
import { Expose, Transform, Type } from 'class-transformer'
import { Equals, IsInstance, IsMimeType, IsOptional, IsString, ValidateNested } from 'class-validator'

import { JsonTransformer } from '../../../utils/JsonTransformer'
import { replaceLegacyDidSovPrefix } from '../../../utils/messageType'

interface CredentialPreviewAttributeOptions {
name: string
Expand Down Expand Up @@ -54,6 +55,9 @@ export class CredentialPreview {

@Expose({ name: '@type' })
@Equals(CredentialPreview.type)
@Transform(({ value }) => replaceLegacyDidSovPrefix(value), {
toClassOnly: true,
})
public readonly type = CredentialPreview.type
public static readonly type = 'https://didcomm.org/issue-credential/1.0/credential-preview'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Expose, Type } from 'class-transformer'
import { Expose, Transform, Type } from 'class-transformer'
import {
Equals,
IsEnum,
Expand All @@ -12,6 +12,7 @@ import {
} from 'class-validator'

import { JsonTransformer } from '../../../utils/JsonTransformer'
import { replaceLegacyDidSovPrefix } from '../../../utils/messageType'
import { PredicateType } from '../models/PredicateType'

export interface PresentationPreviewAttributeOptions {
Expand Down Expand Up @@ -115,6 +116,9 @@ export class PresentationPreview {

@Expose({ name: '@type' })
@Equals(PresentationPreview.type)
@Transform(({ value }) => replaceLegacyDidSovPrefix(value), {
toClassOnly: true,
})
public readonly type = PresentationPreview.type
public static readonly type = 'https://didcomm.org/present-proof/1.0/presentation-preview'

Expand Down

0 comments on commit a2b655a

Please sign in to comment.