Skip to content
Snippets Groups Projects
Unverified Commit 444ee2d4 authored by Boyan Tsolov's avatar Boyan Tsolov Committed by Zdravko Iliev
Browse files

chore: abstract dtos to encompass a wider range of use cases

parent 932d1b1d
No related branches found
No related tags found
1 merge request!44Preparations for ui
Showing
with 288 additions and 96 deletions
......@@ -7,7 +7,7 @@ import {
ConnectionEvent,
CreateInvitationResponseDto,
GatewayAcceptedResponseDto,
GetConnectionRequestDto,
ConnectionRefDto,
makeEvent,
} from "@ocm-engine/dtos";
......@@ -21,7 +21,7 @@ export class AppController {
async create(
@Body()
payload: {
data: null | CreateInvitationResponseDto | GetConnectionRequestDto;
data: null | CreateInvitationResponseDto | ConnectionRefDto;
type: ConnectionEvent;
source: string;
},
......
......@@ -2,7 +2,7 @@ import { Body, Controller, Get, Param, Post, UseFilters } from "@nestjs/common";
import { AllExceptionsHandler } from "../exception.handler";
import { AttestationManagerClient } from "@ocm-engine/clients";
import {
AcceptCredentialOfferRequestDto,
CredentialRefDto,
CreateCredentialDefinitionRequsetDto,
CreateSchemaRequestDto,
CRED_DEF_CREATE,
......@@ -11,7 +11,7 @@ import {
CRED_OFFER_ACCEPT,
CRED_OFFER_LIST,
GatewayAcceptedResponseDto,
GetSchemaRequestDto,
SchemaRefDto,
IssueCredentialRequestDto,
MakeBasicMessageRequestDto,
MESSAGE_MAKE,
......@@ -165,8 +165,8 @@ export class AttestationController {
"Method will fetch specific schema or return null. The id of the response will be matched when you receive event from the websocket",
tags: ["Schema"],
})
async getSchemaById(@Body() schemaRequestDto: GetSchemaRequestDto) {
return this.amClient.sendPayload<GetSchemaRequestDto>({
async getSchemaById(@Body() schemaRequestDto: SchemaRefDto) {
return this.amClient.sendPayload<SchemaRefDto>({
pattern: "schemas",
payload: {
source: "/schemas-by-id",
......@@ -504,7 +504,7 @@ export class AttestationController {
tags: ["Credentials Offers"],
})
acceptCredential(@Param("credential_record_id") credentialRecordId: string) {
const data = new AcceptCredentialOfferRequestDto();
const data = new CredentialRefDto();
data.credentialRecordId = credentialRecordId;
return this.amClient.sendPayload({
pattern: "credentials",
......
......@@ -15,7 +15,7 @@ import {
CONNECTION_LIST,
CreateInvitationResponseDto,
GatewayAcceptedResponseDto,
GetConnectionRequestDto,
ConnectionRefDto,
} from "@ocm-engine/dtos";
import { AllExceptionsHandler } from "../exception.handler";
import {
......@@ -238,10 +238,10 @@ export class ConnectionController {
tags: ["Connections"],
})
async getById(@Param("id") id: string) {
const request = new GetConnectionRequestDto();
const request = new ConnectionRefDto();
request.connectionId = id;
return this.cmClient.sendPayload<GetConnectionRequestDto>({
return this.cmClient.sendPayload<ConnectionRefDto>({
pattern: "connections",
payload: {
source: "/connections/:id",
......
import { Body, Controller, Get, Param, Post, UseFilters } from "@nestjs/common";
import {
AcceptProofRequestDto,
DeclineProofRequestDto,
ProofRefDto,
GatewayAcceptedResponseDto,
GetProofRequestDto,
GetSchemaRequestDto,
SchemaRefDto,
IssueProofRequestDto,
PROOF_ACCEPT,
PROOF_DECLINE,
......@@ -62,7 +60,7 @@ export class ProofController {
tags: ["Credentials Proof"],
})
proofs() {
return this.pmClient.sendPayload<GetSchemaRequestDto>({
return this.pmClient.sendPayload<SchemaRefDto>({
pattern: "proofs",
payload: {
source: "/credential/proofs",
......@@ -108,10 +106,10 @@ export class ProofController {
tags: ["Credentials Proof"],
})
getProofById(@Param("proof_record_id") proofRecordId: string) {
const data = new GetProofRequestDto();
const data = new ProofRefDto();
data.proofRecordId = proofRecordId;
return this.pmClient.sendPayload<GetProofRequestDto>({
return this.pmClient.sendPayload<ProofRefDto>({
pattern: "proofs",
payload: {
source: "/credentials/proof/:proof_record_id",
......@@ -230,8 +228,8 @@ export class ProofController {
"Method accept credential proof. The id of the response will be matched when you receive event from the websocket",
tags: ["Credentials Proof"],
})
acceptProof(@Body() acceptProofRequestDto: AcceptProofRequestDto) {
return this.pmClient.sendPayload<AcceptProofRequestDto>({
acceptProof(@Body() acceptProofRequestDto: ProofRefDto) {
return this.pmClient.sendPayload<ProofRefDto>({
pattern: "proofs",
payload: {
source: "/credentials/proofs/accept",
......@@ -277,10 +275,10 @@ export class ProofController {
tags: ["Credentials Proof"],
})
declineProofRequest(@Param("proof_record_id") proofRecordId: string) {
const data = new DeclineProofRequestDto();
const data = new ProofRefDto();
data.proofRecordId = proofRecordId;
return this.pmClient.sendPayload<DeclineProofRequestDto>({
return this.pmClient.sendPayload<ProofRefDto>({
pattern: "proofs",
payload: {
source: "/credentials/proof/:proof_record_id/decline",
......
......@@ -3,7 +3,7 @@ import { Body, Controller, Logger } from "@nestjs/common";
import { ProducerService } from "@ocm-engine/nats";
import { MessagePattern, RpcException } from "@nestjs/microservices";
import {
AcceptProofRequestDto,
ProofRefDto,
CloudEventDto,
GatewayAcceptedResponseDto,
makeEvent,
......@@ -20,7 +20,7 @@ export class AppController {
async create(
@Body()
payload: {
data: null | AcceptProofRequestDto;
data: null | ProofRefDto;
type: ProofEvent;
source: string;
},
......
import { Injectable, Logger } from "@nestjs/common";
import { AgentService } from "../askar/agent.service";
import {
AcceptCredentialOfferRequestDto,
AcceptProofRequestDto,
CredentialRefDto,
ProofRefDto,
CloudEventDto,
CONNECTION_ACCEPT,
CONNECTION_CREATE,
......@@ -16,12 +16,11 @@ import {
CRED_LIST,
CRED_OFFER_ACCEPT,
CRED_OFFER_LIST,
GetConnectionRequestDto,
GetSchemaRequestDto,
ConnectionRefDto,
SchemaRefDto,
IssueCredentialRequestDto,
IssueProofRequestDto,
MakeBasicMessageRequestDto,
DeclineProofRequestDto,
MESSAGE_MAKE,
PROOF_ACCEPT,
PROOF_ISSUE,
......@@ -30,7 +29,6 @@ import {
SCHEMA_CREATE,
SCHEMA_GET,
SCHEMA_LIST,
GetProofRequestDto,
PROOF_DECLINE,
} from "@ocm-engine/dtos";
import asyncRetry from "async-retry";
......@@ -60,7 +58,7 @@ export class EventHandlerService {
break;
case CONNECTION_GET:
dto = event.data as GetConnectionRequestDto;
dto = event.data as ConnectionRefDto;
data = await this.agentService.getConnectionById(dto.connectionId);
break;
......@@ -73,7 +71,7 @@ export class EventHandlerService {
break;
case SCHEMA_GET:
dto = event.data as GetSchemaRequestDto;
dto = event.data as SchemaRefDto;
data = await this.agentService.getSchemaById(dto.schemaId);
break;
case CRED_DEF_CREATE:
......@@ -97,7 +95,7 @@ export class EventHandlerService {
break;
case CRED_OFFER_ACCEPT:
dto = event.data as AcceptCredentialOfferRequestDto;
dto = event.data as CredentialRefDto;
data = await this.agentService.acceptCredential(
dto.credentialRecordId,
);
......@@ -113,18 +111,18 @@ export class EventHandlerService {
break;
case PROOF_GET:
dto = event.data as GetProofRequestDto;
dto = event.data as ProofRefDto;
data = await this.agentService.getProofById(dto.proofRecordId);
break;
case PROOF_ACCEPT:
data = await this.agentService.acceptProof(
event.data as AcceptProofRequestDto,
event.data as ProofRefDto,
);
break;
case PROOF_DECLINE:
dto = event.data as DeclineProofRequestDto;
dto = event.data as ProofRefDto;
data = await this.agentService.declineProofRequest(
dto.proofRecordId,
);
......
......@@ -8,8 +8,7 @@ import {
IssueProofRequestDto,
CreateSchemaRequestDto,
MakeBasicMessageRequestDto,
AcceptProofRequestDto,
GetProofRequestDto,
ProofRefDto,
} from "@ocm-engine/dtos";
import { AllExceptionsHandler } from "./exception.handler";
......@@ -80,12 +79,12 @@ export class RestController {
}
@Get("credential/proof/:proof_record_id")
getProof(@Param("proof_record_id") data: GetProofRequestDto) {
getProof(@Param("proof_record_id") data: ProofRefDto) {
return this.agentService.getProofById(data.proofRecordId);
}
@Post(`/credential/proof/accept`)
acceptProof(@Body() acceptProofRequestDto: AcceptProofRequestDto) {
acceptProof(@Body() acceptProofRequestDto: ProofRefDto) {
return this.agentService.acceptProof(acceptProofRequestDto);
}
......
import { Injectable } from "@nestjs/common";
import { AskarService } from "./askar.service";
import {
AcceptInvitationResponseDto,
AcceptProofRequestDto,
ConnectionRecordDto,
ProofRefDto,
ConnectionNotFoundError,
CreateCredentialDefinitionRequsetDto,
CreateCredentialDefinitionResponseDto,
CreddefRecordDto,
CreateInvitationResponseDto,
CreateSchemaRequestDto,
CreateSchemaResponseDto,
SchemaRecordDto,
CredentialNotCreatedError,
IssueCredentialRequestDto,
IssueCredentialResponseDto,
CredentialRecordDto,
IssueProofRequestDto,
IssueProofResponseDto,
GetProofByIdResponseDto,
ProofRecordDto,
MakeBasicMessageRequestDto,
MakeBasicMessageResponseDto,
SchemaNotCreatedError,
DeclineProofResponseDto,
SchemaNotFoundError,
} from "@ocm-engine/dtos";
import {
AutoAcceptProof,
......@@ -54,7 +53,7 @@ export class AgentService {
throw new ConnectionNotFoundError();
}
const r = new AcceptInvitationResponseDto();
const r = new ConnectionRecordDto();
r.connectionName = connectionRecord.theirLabel;
r.connectionId = connectionRecord.id;
r.did = connectionRecord.did;
......@@ -65,20 +64,89 @@ export class AgentService {
return r;
};
fetchConnections() {
return this.askar.agent.connections.getAll();
async fetchConnections() {
let agentResponse = await this.askar.agent.connections.getAll();
let connectionArray = agentResponse.map((singleConnectionRes) => {
let connectionResponse = new ConnectionRecordDto();
connectionResponse.connectionId = singleConnectionRes.id;
connectionResponse.state = singleConnectionRes.state;
connectionResponse.connectionName = singleConnectionRes.theirLabel;
connectionResponse.alias = singleConnectionRes.alias;
connectionResponse.did = singleConnectionRes.did;
connectionResponse.invitationDid = singleConnectionRes.invitationDid;
connectionResponse.outOfBandId = singleConnectionRes.outOfBandId;
connectionResponse.createdAt = singleConnectionRes.createdAt;
return connectionResponse
})
if (connectionArray.length < 1) {
throw new ConnectionNotFoundError();
}
return connectionArray
}
getConnectionById = (id: string) => {
return this.askar.agent.connections.findById(id);
getConnectionById = async (id: string) => {
let agentResponse = await this.askar.agent.connections.findById(id);
if (!agentResponse) {
throw new ConnectionNotFoundError();
}
let connectionResponse = new ConnectionRecordDto();
connectionResponse.connectionId = agentResponse.id;
connectionResponse.state = agentResponse.state;
connectionResponse.connectionName = agentResponse.theirLabel;
connectionResponse.alias = agentResponse.alias;
connectionResponse.did = agentResponse.did;
connectionResponse.invitationDid = agentResponse.invitationDid;
connectionResponse.outOfBandId = agentResponse.outOfBandId;
connectionResponse.createdAt = agentResponse.createdAt;
return connectionResponse
};
fetchSchemas = () => {
return this.askar.agent.modules.anoncreds.getCreatedSchemas({});
fetchSchemas = async () => {
let agentResponse = await this.askar.agent.modules.anoncreds.getCreatedSchemas({});
let schemaResponse = agentResponse.map((singleSchemaRes) => {
let schemaResponse = new SchemaRecordDto();
schemaResponse.schemaId = singleSchemaRes.schemaId;
schemaResponse.name = singleSchemaRes.schema.name;
schemaResponse.attributes = singleSchemaRes.schema.attrNames;
schemaResponse.version = singleSchemaRes.schema.version;
schemaResponse.issuerId = singleSchemaRes.schema.issuerId;
schemaResponse.methodName = singleSchemaRes.methodName;
return schemaResponse
})
if (schemaResponse.length < 1) {
throw new SchemaNotFoundError()
}
return schemaResponse
};
getSchemaById = (schemaId: string) => {
return this.askar.agent.modules.anoncreds.getSchema(schemaId);
getSchemaById = async (schemaId: string) => {
let agentResponse = await this.askar.agent.modules.anoncreds.getSchema(schemaId);
if (!agentResponse || !agentResponse.schema) {
throw new SchemaNotFoundError();
}
let schemaResponse = new SchemaRecordDto();
schemaResponse.schemaId = agentResponse.schemaId;
schemaResponse.name = agentResponse.schema.name;
schemaResponse.attributes = agentResponse.schema.attrNames;
schemaResponse.version = agentResponse.schema.version;
schemaResponse.issuerId = agentResponse.schema.issuerId;
return schemaResponse
};
createSchema = async (schema: CreateSchemaRequestDto) => {
......@@ -99,7 +167,7 @@ export class AgentService {
throw new SchemaNotCreatedError();
}
const response = new CreateSchemaResponseDto();
const response = new SchemaRecordDto();
response.name = schemaResult.schemaState.schema.name;
response.schemaId = schemaResult.schemaState.schemaId;
......@@ -129,12 +197,12 @@ export class AgentService {
throw new CredentialNotCreatedError();
}
const response = new CreateCredentialDefinitionResponseDto();
const response = new CreddefRecordDto();
response.credentialDefinitionId =
credDef.credentialDefinitionState.credentialDefinitionId;
response.schemaId =
credDef.credentialDefinitionState.credentialDefinition.schemaId;
response.isserId =
response.issuerId =
credDef.credentialDefinitionState.credentialDefinition.issuerId;
response.tag = credDef.credentialDefinitionState.credentialDefinition.tag;
......@@ -160,7 +228,7 @@ export class AgentService {
});
console.log(JSON.stringify(credentialExchangeRecord, null, 2));
const response = new IssueCredentialResponseDto();
const response = new CredentialRecordDto();
response.credentialId = credentialExchangeRecord.id;
response.connectionId = credentialExchangeRecord.connectionId;
response.attributes = credentialExchangeRecord.credentialAttributes;
......@@ -188,7 +256,7 @@ export class AgentService {
credentialRecordId,
});
const response = new IssueCredentialResponseDto();
const response = new CredentialRecordDto();
response.credentialId = credentialExchangeRecord.id;
response.connectionId = credentialExchangeRecord.connectionId;
response.attributes = credentialExchangeRecord.credentialAttributes;
......@@ -202,9 +270,9 @@ export class AgentService {
state: CredentialState.Done,
});
const response: Array<IssueCredentialResponseDto> = [];
const response: Array<CredentialRecordDto> = [];
for (const offer of credentials) {
const t = new IssueCredentialResponseDto();
const t = new CredentialRecordDto();
t.credentialId = offer.id;
t.connectionId = offer.connectionId;
t.createdAt = offer.createdAt;
......@@ -220,9 +288,9 @@ export class AgentService {
state: CredentialState.OfferReceived,
});
const response: Array<IssueCredentialResponseDto> = [];
const response: Array<CredentialRecordDto> = [];
for (const offer of offers) {
const t = new IssueCredentialResponseDto();
const t = new CredentialRecordDto();
t.credentialId = offer.id;
t.connectionId = offer.connectionId;
t.createdAt = offer.createdAt;
......@@ -290,7 +358,7 @@ export class AgentService {
},
});
const response = new IssueProofResponseDto();
const response = new ProofRecordDto();
response.proofId = exchangeRecord.id;
response.connectionId = exchangeRecord.connectionId;
response.state = exchangeRecord.state;
......@@ -305,9 +373,9 @@ export class AgentService {
state: ProofState.RequestReceived,
});
const response: Array<IssueProofResponseDto> = [];
const response: Array<ProofRecordDto> = [];
for (const proof of proofs) {
const t = new IssueProofResponseDto();
const t = new ProofRecordDto();
t.proofId = proof.id;
t.connectionId = proof.connectionId;
t.state = proof.state;
......@@ -327,7 +395,7 @@ export class AgentService {
return proofRecord;
}
const proofResponse = new GetProofByIdResponseDto();
const proofResponse = new ProofRecordDto();
proofResponse.proofId = proofRecord.id;
proofResponse.connectionId = proofRecord.connectionId;
......@@ -338,11 +406,11 @@ export class AgentService {
return proofResponse;
};
acceptProof = async (acceptProofDto: AcceptProofRequestDto) => {
acceptProof = async (acceptProofDto: ProofRefDto) => {
if (acceptProofDto.proofUrl) {
return this.acceptOobProof(acceptProofDto.proofUrl);
}
return this.acceptConnectionProof(acceptProofDto.proofId);
return this.acceptConnectionProof(acceptProofDto.proofRecordId);
};
acceptOobProof = async (url: string) => {
......@@ -366,7 +434,7 @@ export class AgentService {
proofFormats: requestedCredentials.proofFormats,
});
const response = new IssueProofResponseDto();
const response = new ProofRecordDto();
response.proofId = acceptedRecord.id;
response.state = acceptedRecord.state;
......@@ -392,7 +460,7 @@ export class AgentService {
console.log(JSON.stringify(proof, null, 2));
const response = new IssueProofResponseDto();
const response = new ProofRecordDto();
response.proofId = proof.id;
response.connectionId = proof.connectionId;
response.state = proof.state;
......@@ -408,7 +476,7 @@ export class AgentService {
// sendProblemReport: false, // REVIEW: do we have a use case for this key?
});
const declineResponse = new DeclineProofResponseDto();
const declineResponse = new ProofRecordDto();
declineResponse.proofId = resultFromDecline.id;
declineResponse.connectionId = resultFromDecline.connectionId;
declineResponse.state = resultFromDecline.state;
......@@ -433,7 +501,7 @@ export class AgentService {
const connectionInfo = await this.getConnectionById(message.connectionId);
response.connectionId = m.connectionId;
response.to = connectionInfo?.theirLabel || "";
response.to = connectionInfo?.connectionName || "";
response.id = m.id;
response.message = m.content;
......
import { IsDateString, IsNotEmpty, IsString } from "class-validator";
export class IssueProofResponseDto {
@IsString()
@IsNotEmpty()
proofId: string;
// INFO: should cover:
// 1. get connection response
// 2. accept connection response
export class ConnectionRecordDto {
//@example 6464b521-005a-4379-91e0-a3692b31cafd
@IsNotEmpty()
@IsString()
connectionId?: string;
connectionId: string;
@IsString()
@IsNotEmpty()
@IsString()
state: string;
@IsDateString()
updatedAt?: Date;
@IsString()
connectionName?: string;
@IsString()
alias?: string;
@IsString()
did?: string;
@IsString()
invitationDid?: string;
@IsString()
outOfBandId?: string;
@IsNotEmpty()
@IsDateString()
@IsNotEmpty()
createdAt: Date;
}
}
\ No newline at end of file
import { IsNotEmpty, IsString } from "class-validator";
export class GetConnectionRequestDto {
// INFO: should cover:
// 1. get connection request
export class ConnectionRefDto {
//@example 6464b521-005a-4379-91e0-a3692b31cafd
@IsNotEmpty()
@IsString()
......
import { IsNotEmpty, IsString } from "class-validator";
export class CreateCredentialDefinitionResponseDto {
// INFO: should cover:
// 1. get credential definition response
// 2. create credential definition response
export class CreddefRecordDto {
@IsNotEmpty()
@IsString()
credentialDefinitionId: string;
......@@ -11,7 +18,7 @@ export class CreateCredentialDefinitionResponseDto {
@IsNotEmpty()
@IsString()
isserId: string;
issuerId: string;
@IsNotEmpty()
@IsString()
......
import { IsNotEmpty, IsString } from "class-validator";
export class GetProofRequestDto {
@IsString()
// INFO: should cover:
// 1. get credential definition request
export class CreddefRefDto {
@IsNotEmpty()
proofRecordId: string;
@IsString()
credentialDefinitionId: string;
}
......@@ -8,6 +8,14 @@ import {
import { Type } from "class-transformer";
import { IssueCredentialAttributes } from "../requests/issue.credential.request.dto";
// INFO: should cover:
// 1. create credential response
// 2. get credential response
export class Credential {
@IsNotEmpty()
@IsString()
......@@ -18,7 +26,7 @@ export class Credential {
credentialRecordId: string;
}
export class IssueCredentialResponseDto {
export class CredentialRecordDto {
@IsArray()
@ValidateNested({ each: true })
@Type(() => Credential)
......
import { IsNotEmpty, IsString } from "class-validator";
export class AcceptCredentialOfferRequestDto {
// INFO: should cover:
// 1. accept credential request
// 2. get credential request
export class CredentialRefDto {
//@example cf8395a5-9a53-4e06-8a5d-04e0fc00ca04
@IsNotEmpty()
@IsString()
credentialRecordId: string;
}
}
\ No newline at end of file
......@@ -4,7 +4,14 @@ import {
IsString
} from "class-validator";
export class GetProofByIdResponseDto {
// INFO: should cover:
// 1. decline proof response
// 2. get proof response
// 3. issue proof response
export class ProofRecordDto {
@IsString()
@IsNotEmpty()
proofId: string;
......
import { IsNotEmpty, IsString } from "class-validator";
// INFO: should cover:
// 1. get proof request
// 2. decline proof request
// 3. accept proof request
export class ProofRefDto {
@IsString()
@IsNotEmpty()
proofRecordId: string;
@IsString()
proofUrl?: string;
}
\ No newline at end of file
import { ArrayMinSize, IsArray, IsNotEmpty, IsString } from "class-validator";
import { IsDateString, IsNotEmpty, IsString } from "class-validator";
export class CreateSchemaResponseDto {
// INFO: should cover:
// 1. create schema response
// 2. get schema response
export class SchemaRecordDto {
@IsNotEmpty()
@IsString()
schemaId: string;
@IsNotEmpty()
@IsString()
issuerId: string;
@IsNotEmpty()
@IsString()
name: string;
@IsNotEmpty()
attributes: string[];
@IsNotEmpty()
@IsString()
version: string;
@IsArray()
@IsString({ each: true })
@ArrayMinSize(1)
attributes: string[];
}
@IsDateString()
updatedAt?: Date;
@IsString()
issuerId?: string;
@IsString()
methodName?: string;
}
\ No newline at end of file
import { IsNotEmpty, IsString } from "class-validator";
export class GetSchemaRequestDto {
// INFO: should cover:
// 1. get schema request
export class SchemaRefDto {
//@example "did:indy:LEDNGER:SXM76gQwRnjkgoz2oBnGjd/anoncreds/v0/SCHEMA/test schema/1.0.2"
@IsNotEmpty()
@IsString()
......
import { IsNotEmpty, IsString, ValidateIf } from "class-validator";
export class AcceptProofRequestDto {
@IsString()
@IsNotEmpty()
@ValidateIf((o) => o.proofUrl === undefined)
proofId: string;
@IsString()
@IsNotEmpty()
@ValidateIf((o) => o.proofId === undefined)
proofUrl: string;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment