diff --git a/packages/core/src/modules/oob/__tests__/OutOfBandInvitation.test.ts b/packages/core/src/modules/oob/__tests__/OutOfBandInvitation.test.ts index 29de6b5af6..2a607be68a 100644 --- a/packages/core/src/modules/oob/__tests__/OutOfBandInvitation.test.ts +++ b/packages/core/src/modules/oob/__tests__/OutOfBandInvitation.test.ts @@ -116,7 +116,47 @@ describe('OutOfBandInvitation', () => { } }) - test('throw validation error when incorrect service object present in services attribute', () => { + test('transforms legacy prefix message @type and handshake_protocols to https://didcomm.org prefix', () => { + const json = { + '@type': 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/out-of-band/1.1/invitation', + '@id': '69212a3a-d068-4f9d-a2dd-4741bca89af3', + label: 'Faber College', + goal_code: 'issue-vc', + goal: 'To issue a Faber College Graduate credential', + handshake_protocols: [ + 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/didexchange/1.0', + 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0', + ], + services: ['did:sov:123'], + } + + const invitation = OutOfBandInvitation.fromJson(json) + + expect(invitation.type).toBe('https://didcomm.org/out-of-band/1.1/invitation') + expect(invitation.handshakeProtocols).toEqual([ + 'https://didcomm.org/didexchange/1.0', + 'https://didcomm.org/connections/1.0', + ]) + }) + + // Check if options @Transform for legacy did:sov prefix doesn't fail if handshake_protocols is not present + test('should successfully transform if no handshake_protocols is present', () => { + const json = { + '@type': 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/out-of-band/1.1/invitation', + '@id': '69212a3a-d068-4f9d-a2dd-4741bca89af3', + label: 'Faber College', + goal_code: 'issue-vc', + goal: 'To issue a Faber College Graduate credential', + services: ['did:sov:123'], + } + + const invitation = OutOfBandInvitation.fromJson(json) + + expect(invitation.type).toBe('https://didcomm.org/out-of-band/1.1/invitation') + expect(invitation.handshakeProtocols).toBeUndefined() + }) + + test('throw validation error when incorrect service object present in services attribute', async () => { const json = { '@type': 'https://didcomm.org/out-of-band/1.1/invitation', '@id': '69212a3a-d068-4f9d-a2dd-4741bca89af3', diff --git a/packages/core/src/modules/oob/messages/OutOfBandInvitation.ts b/packages/core/src/modules/oob/messages/OutOfBandInvitation.ts index 8d631f4abe..db7967dc76 100644 --- a/packages/core/src/modules/oob/messages/OutOfBandInvitation.ts +++ b/packages/core/src/modules/oob/messages/OutOfBandInvitation.ts @@ -11,7 +11,7 @@ import { Attachment, AttachmentData } from '../../../decorators/attachment/Attac import { AriesFrameworkError } from '../../../error' import { JsonEncoder } from '../../../utils/JsonEncoder' import { JsonTransformer } from '../../../utils/JsonTransformer' -import { IsValidMessageType, parseMessageType } from '../../../utils/messageType' +import { IsValidMessageType, parseMessageType, replaceLegacyDidSovPrefix } from '../../../utils/messageType' import { IsStringOrInstance } from '../../../utils/validators' import { DidKey } from '../../dids' import { outOfBandServiceToNumAlgo2Did } from '../../dids/methods/peer/peerDidNumAlgo2' @@ -106,6 +106,9 @@ export class OutOfBandInvitation extends AgentMessage { .map((didKey) => DidKey.fromDid(didKey).key) } + @Transform(({ value }) => replaceLegacyDidSovPrefix(value), { + toClassOnly: true, + }) @IsValidMessageType(OutOfBandInvitation.type) public readonly type = OutOfBandInvitation.type.messageTypeUri public static readonly type = parseMessageType('https://didcomm.org/out-of-band/1.1/invitation') @@ -119,6 +122,7 @@ export class OutOfBandInvitation extends AgentMessage { public readonly accept?: string[] + @Transform(({ value }) => value?.map(replaceLegacyDidSovPrefix), { toClassOnly: true }) @Expose({ name: 'handshake_protocols' }) public handshakeProtocols?: HandshakeProtocol[]