diff --git a/backend-peer/package.json b/backend-peer/package.json index 492bc52..30c906c 100644 --- a/backend-peer/package.json +++ b/backend-peer/package.json @@ -1,6 +1,6 @@ { "name": "@digicatapult/nice-agent-portal-backend-peer", - "version": "0.2.5", + "version": "0.3.0", "description": "OpenAPI service to manage profiles for the NICE agent and communication with veritable-cloudagent", "main": "src/index.ts", "type": "module", diff --git a/backend-peer/src/controllers/connection/index.ts b/backend-peer/src/controllers/connection/index.ts deleted file mode 100644 index 977a30c..0000000 --- a/backend-peer/src/controllers/connection/index.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Controller, Post, Route, SuccessResponse, Tags, Body } from 'tsoa' -import { injectable } from 'tsyringe' - -import { CloudagentManager } from '../../lib/services/cloudagent.js' - -import { logger } from '../../lib/logger.js' -const log = logger.child({ context: 'ConnectionController' }) - -@Route('api/connection') -@Tags('connection') -@injectable() -export class ConnectionController extends Controller { - constructor(private cloudagent: CloudagentManager) { - super() - } - - /** - * @summary Create a new connection. - * @description If any existing connections for the did exists, delete and replace them with a single new one. - */ - @SuccessResponse(204) - @Post('/') - public async post(@Body() body: { did: string }) { - log.debug({ - msg: 'new request received', - controller: '/connection', - payload: body, - }) - - const { did } = body - - const connections = await this.cloudagent.getConnections() - - for (const { id, invitationDid } of connections) { - if (invitationDid === did) { - await this.cloudagent.deleteConnection(id) - } - } - - return this.cloudagent.receiveImplicitInvitation(did) - } -} diff --git a/backend-peer/src/controllers/messages/index.ts b/backend-peer/src/controllers/messages/index.ts index f1a3967..e4aebe3 100644 --- a/backend-peer/src/controllers/messages/index.ts +++ b/backend-peer/src/controllers/messages/index.ts @@ -43,10 +43,7 @@ export class MessagesController extends Controller { if (connectionId === undefined) { //create a connection if one does not exist - const connectionRecord = await this.cloudagent.receiveImplicitInvitation( - did, - true - ) + const connectionRecord = await this.cloudagent.createConnection(did, true) if (!connectionRecord) { throw new Error('Failed to create connection record.') // Handle the case where connectionRecord is undefined } diff --git a/backend-peer/src/lib/services/cloudagent.ts b/backend-peer/src/lib/services/cloudagent.ts index fb2b46c..cac069a 100644 --- a/backend-peer/src/lib/services/cloudagent.ts +++ b/backend-peer/src/lib/services/cloudagent.ts @@ -112,24 +112,15 @@ export class CloudagentManager { return agentInfo as AgentInfo } - receiveImplicitInvitation = async ( + createConnection = async ( did: string, waitUntilCompleted: boolean = false ) => { - const requestBody = { - did, - handshakeProtocols: ['https://didcomm.org/connections/1.x'], - autoAcceptConnection: true, - } - - const res = await wrappedFetch( - `${this.url_prefix}/oob/receive-implicit-invitation`, - { - headers: { 'Content-Type': 'application/json' }, - body: requestBody, - method: 'POST', - } - ) + const res = await wrappedFetch(`${this.url_prefix}/connections`, { + headers: { 'Content-Type': 'application/json' }, + body: { did }, + method: 'POST', + }) const responseBody = await res.json() diff --git a/package-lock.json b/package-lock.json index 2f1d382..e2b434e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@digicatapult/nice-agent-portal", - "version": "0.2.8", + "version": "0.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@digicatapult/nice-agent-portal", - "version": "0.2.8", + "version": "0.3.0", "license": "Apache-2.0", "workspaces": [ "frontend", @@ -93,7 +93,7 @@ }, "backend-peer": { "name": "@digicatapult/nice-agent-portal-backend-peer", - "version": "0.2.5", + "version": "0.3.0", "license": "Apache-2.0", "dependencies": { "@aries-framework/core": "^0.4.2", diff --git a/package.json b/package.json index 1bdd376..dc69bd9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@digicatapult/nice-agent-portal", - "version": "0.2.8", + "version": "0.3.0", "description": "NICE agent portal", "homepage": "https://github.com/digicatapult/nice-agent-portal", "type": "module", diff --git a/test/e2e/connection.test.ts b/test/e2e/connection.test.ts deleted file mode 100644 index 4a38e62..0000000 --- a/test/e2e/connection.test.ts +++ /dev/null @@ -1,114 +0,0 @@ -import { expect } from 'chai' -import request from 'supertest' -import { describe } from 'mocha' -import { ConnectionRecord } from '@aries-framework/core' - -import { getConfig } from './fixtures/config.js' -import { pollGetConnections } from './utils/shared.js' -import { importDids } from './utils/setup.js' - -describe('Connection', async function () { - const config = getConfig() - const aliceClient = request(config.alice.portalUrl) - const aliceVeritableClient = request(config.alice.veritableUrl) - const bobVeritableCLient = request(config.bob.veritableUrl) - - before(async function () { - // import dids on Alice and Bob - await importDids() - }) - - afterEach(async function () { - // clear all connections - const { body: aliceConns } = await aliceVeritableClient.get(`/connections`) - for (const { id } of aliceConns) { - await aliceVeritableClient.delete(`/connections/${id}`) - } - const { body: bobConns } = await bobVeritableCLient.get(`/connections`) - for (const { id } of bobConns) { - await bobVeritableCLient.delete(`/connections/${id}`) - } - }) - - describe('happy path', async function () { - it('Alice creates a connection with Bob', async function () { - await aliceClient - .post('/connection') - .send({ did: config.bob.did }) - .expect(204) - - // poll until a completed connection appears - await pollGetConnections( - config.alice.veritableUrl, - (connections) => - connections.length === 1 && connections[0].state === 'completed' - ) - - const { body: aliceConnections } = await request( - config.alice.veritableUrl - ).get('/connections') - - const aliceConnectionRecord = aliceConnections[0] as ConnectionRecord - expect(aliceConnectionRecord.invitationDid).to.equal(config.bob.did) - - // poll until a completed connection appears - await pollGetConnections( - config.bob.veritableUrl, - (connections) => - connections.length === 1 && connections[0].state === 'completed' - ) - - const { body: bobConnections } = await request( - config.bob.veritableUrl - ).get(`/connections`) - - const bobConnectionRecord = bobConnections[0] as ConnectionRecord - expect(bobConnectionRecord.state).to.equal('completed') - expect(bobConnectionRecord.did).to.equal(aliceConnectionRecord.theirDid) - }) - - it('Alice replaces old connection with Bob', async function () { - // create a connection to be replaced - await aliceClient - .post('/connection') - .send({ did: config.bob.did }) - .expect(204) - - await pollGetConnections( - config.alice.veritableUrl, - (connections) => - connections.length === 1 && connections[0].state === 'completed' - ) - - const { body: aliceConnectionsFirst } = await request( - config.alice.veritableUrl - ).get('/connections') - expect(aliceConnectionsFirst[0].invitationDid).to.equal(config.bob.did) - - // replace the connection - await aliceClient - .post('/connection') - .send({ did: config.bob.did }) - .expect(204) - - await pollGetConnections( - config.alice.veritableUrl, - (connections) => - connections.length === 1 && - connections[0].id !== aliceConnectionsFirst[0].id && - connections[0].state === 'completed' - ) - - const { body: aliceConnectionsSecond } = await request( - config.alice.veritableUrl - ).get('/connections') - expect(aliceConnectionsSecond[0].invitationDid).to.equal(config.bob.did) - }) - }) - - describe('sad path', async function () { - it('500s if invalid DID', async function () { - await aliceClient.post('/connection').send({ did: 'bla' }).expect(500) - }) - }) -})