From fdb34835abab2df004ccb66fe456145acae07f3d Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Wed, 1 Jun 2022 16:58:43 +0200 Subject: [PATCH] fix(oob): legacy invitation with multiple endpoint Signed-off-by: Timo Glastra --- .../src/modules/oob/__tests__/helpers.test.ts | 21 ------------------- packages/core/src/modules/oob/helpers.ts | 7 +------ packages/core/tests/oob.test.ts | 14 +++++++++++++ 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/packages/core/src/modules/oob/__tests__/helpers.test.ts b/packages/core/src/modules/oob/__tests__/helpers.test.ts index e81093276a..debbc71821 100644 --- a/packages/core/src/modules/oob/__tests__/helpers.test.ts +++ b/packages/core/src/modules/oob/__tests__/helpers.test.ts @@ -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.` - ) - }) }) diff --git a/packages/core/src/modules/oob/helpers.ts b/packages/core/src/modules/oob/helpers.ts index b0c1a913a7..17db647459 100644 --- a/packages/core/src/modules/oob/helpers.ts +++ b/packages/core/src/modules/oob/helpers.ts @@ -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 diff --git a/packages/core/tests/oob.test.ts b/packages/core/tests/oob.test.ts index b7c579ac47..2be73b900e 100644 --- a/packages/core/tests/oob.test.ts +++ b/packages/core/tests/oob.test.ts @@ -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' @@ -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({