Skip to content

Commit

Permalink
fix(oob): legacy invitation with multiple endpoint (#825)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra committed Jun 1, 2022
1 parent dda1bd3 commit 8dd7f80
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
21 changes: 0 additions & 21 deletions packages/core/src/modules/oob/__tests__/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,4 @@ describe('convertToOldInvitation', () => {
did: 'did:sov:a-did',
})
})

it('throws an error when more than service is present in the out of band invitation', () => {
const oobInvitation = new OutOfBandInvitation({
id: 'd88ff8fd-6c43-4683-969e-11a87a572cf2',
imageUrl: 'https://my-image.com',
label: 'a-label',
services: [
new DidCommV1Service({
id: '#inline',
recipientKeys: ['did:key:z6MkmjY8GnV5i9YTDtPETC2uUAW6ejw3nk5mXF5yci5ab7th'],
routingKeys: ['did:key:z6Mkk7yqnGF3YwTrLpqrW6PGsKci7dNqh1CjnvMbzrMerSeL'],
serviceEndpoint: 'https://my-agent.com',
}),
'did:sov:a-did',
],
})

expect(() => convertToOldInvitation(oobInvitation)).toThrowError(
`Attribute 'services' MUST have exactly one entry. It contains 2 entries.`
)
})
})
7 changes: 1 addition & 6 deletions packages/core/src/modules/oob/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ export function convertToNewInvitation(oldInvitation: ConnectionInvitationMessag
}

export function convertToOldInvitation(newInvitation: OutOfBandInvitation) {
if (newInvitation.services.length > 1) {
throw new AriesFrameworkError(
`Attribute 'services' MUST have exactly one entry. It contains ${newInvitation.services.length} entries.`
)
}

// Taking first service, as we can only include one service in a legacy invitation.
const [service] = newInvitation.services

let options
Expand Down
14 changes: 14 additions & 0 deletions packages/core/tests/oob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SubjectInboundTransport } from '../../../tests/transport/SubjectInbound
import { SubjectOutboundTransport } from '../../../tests/transport/SubjectOutboundTransport'
import { Agent } from '../src/agent/Agent'
import { DidExchangeState, HandshakeProtocol } from '../src/modules/connections'
import { Key } from '../src/modules/dids'
import { OutOfBandDidCommService } from '../src/modules/oob/domain/OutOfBandDidCommService'
import { OutOfBandEventTypes } from '../src/modules/oob/domain/OutOfBandEvents'
import { OutOfBandRole } from '../src/modules/oob/domain/OutOfBandRole'
Expand Down Expand Up @@ -329,6 +330,19 @@ describe('out of band', () => {
expect(aliceFaberConnection).toBeConnectedWith(faberAliceConnection)
})

test('make a connection based on old connection invitation with multiple endpoints uses first endpoint for invitation', async () => {
const { invitation } = await faberAgent.oob.createLegacyInvitation({
...makeConnectionConfig,
routing: {
endpoints: ['https://endpoint-1.com', 'https://endpoint-2.com'],
routingKeys: [Key.fromFingerprint('z6MkiP5ghmdLFh1GyGRQQQLVJhJtjQjTpxUY3AnY3h5gu3BE')],
recipientKey: Key.fromFingerprint('z6MkuXrzmDjBoy7r9LA1Czjv9eQXMGr9gt6JBH8zPUMKkCQH'),
},
})

expect(invitation.serviceEndpoint).toBe('https://endpoint-1.com')
})

test('process credential offer requests based on OOB message', async () => {
const { message } = await faberAgent.credentials.createOffer(credentialTemplate)
const { outOfBandInvitation } = await faberAgent.oob.createInvitation({
Expand Down

0 comments on commit 8dd7f80

Please sign in to comment.