Skip to content

Commit

Permalink
fix(oob): allow legacy did sov prefix (#889)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra authored Jun 20, 2022
1 parent 5b9efe3 commit c7766d0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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')
Expand All @@ -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[]

Expand Down

0 comments on commit c7766d0

Please sign in to comment.