diff --git a/agent-swagger.json b/agent-swagger.json index 5abd221ff7a6baa8cbb6dfd58c6c99489bf9a132..14412bef8a90088901894f7400cbba2ab4a066ab 100644 --- a/agent-swagger.json +++ b/agent-swagger.json @@ -250,6 +250,33 @@ } } }, + "/api/v1/connections/ping/{id}": { + "post": { + "operationId": "RestController_pingConnection", + "parameters": [ + { + "name": "id", + "required": true, + "in": "path", + "schema": { + "type": "string" + } + } + ], + "responses": { + "201": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/BaseRecordDto" + } + } + } + } + } + } + }, "/api/v1/schemas": { "post": { "operationId": "RestController_createSchema", @@ -1138,6 +1165,22 @@ "state" ] }, + "BaseRecordDto": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "createdAt": { + "format": "date-time", + "type": "string" + }, + "updatedAt": { + "format": "date-time", + "type": "string" + } + } + }, "CreateSchemaRequestDto": { "type": "object", "properties": { @@ -1169,6 +1212,17 @@ "SchemaRecordDto": { "type": "object", "properties": { + "id": { + "type": "string" + }, + "createdAt": { + "format": "date-time", + "type": "string" + }, + "updatedAt": { + "format": "date-time", + "type": "string" + }, "name": { "type": "string" }, @@ -1186,17 +1240,6 @@ }, "methodName": { "type": "string" - }, - "id": { - "type": "string" - }, - "createdAt": { - "format": "date-time", - "type": "string" - }, - "updatedAt": { - "format": "date-time", - "type": "string" } }, "required": [ @@ -1219,24 +1262,24 @@ "CreddefRecordDto": { "type": "object", "properties": { - "schemaId": { + "id": { "type": "string" }, - "issuerId": { + "createdAt": { + "format": "date-time", "type": "string" }, - "tag": { + "updatedAt": { + "format": "date-time", "type": "string" }, - "id": { + "schemaId": { "type": "string" }, - "createdAt": { - "format": "date-time", + "issuerId": { "type": "string" }, - "updatedAt": { - "format": "date-time", + "tag": { "type": "string" } }, @@ -1301,6 +1344,17 @@ "CredentialRecordDto": { "type": "object", "properties": { + "id": { + "type": "string" + }, + "createdAt": { + "format": "date-time", + "type": "string" + }, + "updatedAt": { + "format": "date-time", + "type": "string" + }, "state": { "enum": [ "proposal-sent", @@ -1331,17 +1385,6 @@ }, "tags": { "type": "object" - }, - "id": { - "type": "string" - }, - "createdAt": { - "format": "date-time", - "type": "string" - }, - "updatedAt": { - "format": "date-time", - "type": "string" } }, "required": [ @@ -1435,6 +1478,17 @@ "MessageRecordDto": { "type": "object", "properties": { + "id": { + "type": "string" + }, + "createdAt": { + "format": "date-time", + "type": "string" + }, + "updatedAt": { + "format": "date-time", + "type": "string" + }, "connectionId": { "type": "string", "example": "6464b521-005a-4379-91e0-a3692b31cafd" @@ -1460,17 +1514,6 @@ "content": { "type": "string", "example": "hello world" - }, - "id": { - "type": "string" - }, - "createdAt": { - "format": "date-time", - "type": "string" - }, - "updatedAt": { - "format": "date-time", - "type": "string" } }, "required": [ @@ -1483,6 +1526,17 @@ "ProofRecordDto": { "type": "object", "properties": { + "id": { + "type": "string" + }, + "createdAt": { + "format": "date-time", + "type": "string" + }, + "updatedAt": { + "format": "date-time", + "type": "string" + }, "connectionId": { "type": "string" }, @@ -1502,17 +1556,6 @@ }, "tags": { "type": "object" - }, - "id": { - "type": "string" - }, - "createdAt": { - "format": "date-time", - "type": "string" - }, - "updatedAt": { - "format": "date-time", - "type": "string" } }, "required": [ @@ -1610,6 +1653,17 @@ "DidRecordDto": { "type": "object", "properties": { + "id": { + "type": "string" + }, + "createdAt": { + "format": "date-time", + "type": "string" + }, + "updatedAt": { + "format": "date-time", + "type": "string" + }, "did": { "type": "string" }, @@ -1625,17 +1679,6 @@ }, "tags": { "type": "object" - }, - "id": { - "type": "string" - }, - "createdAt": { - "format": "date-time", - "type": "string" - }, - "updatedAt": { - "format": "date-time", - "type": "string" } }, "required": [ diff --git a/libs/askar/src/agent.utils.ts b/libs/askar/src/agent.utils.ts index 4ec261786715ef036ed67468f161f323ebaf111b..c7cf78055dbb16913487b18e30e0500e111c71e3 100644 --- a/libs/askar/src/agent.utils.ts +++ b/libs/askar/src/agent.utils.ts @@ -31,6 +31,7 @@ import { DidDocument, WebDidResolver, JwkDidResolver, + TrustPingResponseReceivedEvent, } from "@aries-framework/core"; import { AnonCredsCredentialFormatService, @@ -598,3 +599,18 @@ export const attachDidWebHandler = ( } }); }; + +export const webHookHandler = async ( + addr: string, + ev: TrustPingResponseReceivedEvent, +) => { + try { + await axios.post(addr, { + thid: ev.payload.message.threadId, + connectionId: ev.payload.connectionRecord.id, + }); + } catch (e) { + console.log("Error sending webhook"); + console.log(JSON.stringify(e, null, 2)); + } +}; diff --git a/libs/askar/src/askar-rest/rest.controller.ts b/libs/askar/src/askar-rest/rest.controller.ts index a39330a4fcce7376d00857e8c1afddbd6e2590ac..adbc7697379bbf79965709327459c5b525b690a2 100644 --- a/libs/askar/src/askar-rest/rest.controller.ts +++ b/libs/askar/src/askar-rest/rest.controller.ts @@ -91,6 +91,11 @@ export class RestController { return this.agentService.getConnectionByOobId(id); } + @Post("/connections/ping/:id") + async pingConnection(@Param("id") id: string) { + return this.agentService.trustPingToConnection(id); + } + @Post("/schemas") async createSchema(@Body() schemaDto: CreateSchemaRequestDto) { return this.agentService.createSchema(schemaDto); diff --git a/libs/askar/src/askar/agent-event-listener.service.ts b/libs/askar/src/askar/agent-event-listener.service.ts index 33ca9af17b7597721b3bed9004c3d2c777ef9213..2e06a1a13266162539742f56d6059b3eccad11dc 100644 --- a/libs/askar/src/askar/agent-event-listener.service.ts +++ b/libs/askar/src/askar/agent-event-listener.service.ts @@ -3,12 +3,14 @@ import { GatewayClient } from "@ocm-engine/clients"; import { AskarService } from "./askar.service"; import { BasicMessageEventTypes, + TrustPingEventTypes, BasicMessageRole, BasicMessageStateChangedEvent, ConnectionEventTypes, ConnectionStateChangedEvent, ProofEventTypes, ProofStateChangedEvent, + TrustPingResponseReceivedEvent, } from "@aries-framework/core"; import { MessageRecordDto, makeEvent, MESSAGE_MAKE } from "@ocm-engine/dtos"; import { IConfAgent } from "@ocm-engine/config"; @@ -16,6 +18,7 @@ import { ConfigService } from "@nestjs/config"; import { svdxConnectionStateChangeHandler, svdxProofStateChangeHandler, + webHookHandler, } from "../agent.utils"; @Injectable() @@ -60,6 +63,17 @@ export class AgentEventListenerService implements OnModuleInit { ); }, ); + + this.askar.agent.events.on( + TrustPingEventTypes.TrustPingResponseReceivedEvent, + async (ev: TrustPingResponseReceivedEvent) => { + if (!this.agentConfig?.agentWebHook) { + throw new Error("Agent config is missing agentWebHook"); + } + + return webHookHandler(this.agentConfig?.agentWebHook, ev); + }, + ); } this.askar.agent.events.on( diff --git a/libs/askar/src/askar/agent.service.ts b/libs/askar/src/askar/agent.service.ts index 54b666908f1642b299a20013190a59e765eb2f54..9439fbba76dce855bf87829ce35bb8c1156a3acf 100644 --- a/libs/askar/src/askar/agent.service.ts +++ b/libs/askar/src/askar/agent.service.ts @@ -28,6 +28,7 @@ import { CreateInvitationRequestDto, InvitationFilterDto, DidRecordDto, + BaseRecordDto, } from "@ocm-engine/dtos"; import { AutoAcceptCredential, @@ -1041,4 +1042,16 @@ export class AgentService { return dto; }); }; + + trustPingToConnection = async (connectionId: string) => { + const msg = await this.askar.agent.connections.sendPing(connectionId, { + responseRequested: true, + withReturnRouting: false, + }); + + const response = new BaseRecordDto(); + response.id = msg.toJSON()["@id"]; + + return response; + }; } diff --git a/libs/config/src/config/agent.config.ts b/libs/config/src/config/agent.config.ts index f0ab211b07809151eaea10ba85d325b52d54f361..d982a1304b7a87861162e6b153d6c6647218fc44 100644 --- a/libs/config/src/config/agent.config.ts +++ b/libs/config/src/config/agent.config.ts @@ -36,5 +36,6 @@ export const agentConfig = registerAs( agentAuthJwtEnabled: !!process.env["AUTH_JWT_PUBLIC_KEY"], agentAuthJwtPublicKey: process.env["AUTH_JWT_PUBLIC_KEY"]!, logLevel: parseInt(process.env["LOG_LEVEL"]!) || LogLevel.error, + agentWebHook: process.env["AGENT_WEBHOOK_URL"]!, }), ); diff --git a/libs/config/src/interfaces/agent.config.interface.ts b/libs/config/src/interfaces/agent.config.interface.ts index 3afa27b841f9832b0998b9300f69807c5769b38b..d5fed1a5da7bd7f5c2b82b8d237d827d2340e40a 100644 --- a/libs/config/src/interfaces/agent.config.interface.ts +++ b/libs/config/src/interfaces/agent.config.interface.ts @@ -26,4 +26,5 @@ export interface IConfAgent { agentAuthJwtPublicKey: string; logLevel: number; + agentWebHook: string; } diff --git a/libs/dtos/src/index.ts b/libs/dtos/src/index.ts index f5ff5ecf5c5b62b31923e102469da191a3c06f3f..b9c5a35e1e3438b9057f02cfd751ba970342e02b 100644 --- a/libs/dtos/src/index.ts +++ b/libs/dtos/src/index.ts @@ -1,5 +1,6 @@ export * from "./dtos.module"; +export * from "./dtos/generics/base.record.dto"; export * from "./dtos/generics/connection.record.dto"; export * from "./dtos/generics/creddef.record.dto"; export * from "./dtos/generics/credential.record.dto";