Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support to select multiple connections while sending proof request #1086

Open
wants to merge 6 commits into
base: develop-dco-fixed
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions apps/api-gateway/src/verification/dto/request-proof.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArrayNotEmpty, IsArray, IsBoolean, IsEmail, IsEnum, IsNotEmpty, IsNumberString, IsObject, IsOptional, IsString, ValidateIf, ValidateNested, IsUUID, ArrayUnique, ArrayMaxSize } from 'class-validator';
import { ArrayNotEmpty, IsArray, IsBoolean, IsEmail, IsEnum, IsNotEmpty, IsNumberString, IsObject, IsOptional, IsString, ValidateIf, ValidateNested, IsUUID, ArrayUnique, ArrayMaxSize, ArrayMinSize } from 'class-validator';
import { trim } from '@credebl/common/cast.helper';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
Expand All @@ -7,7 +7,6 @@ import { IProofFormats } from '../interfaces/verification.interface';
import { ProofRequestType } from '../enum/verification.enum';

export class ProofRequestAttribute {

@ValidateIf((obj) => obj.attributeNames === undefined)
@IsNotEmpty()
@IsString()
Expand All @@ -23,15 +22,18 @@ export class ProofRequestAttribute {
@ApiPropertyOptional()
@IsString()
@IsOptional()
@IsNotEmpty({ message: 'schemaId is required.' })
schemaId?: string;

@ApiPropertyOptional()
@ValidateIf((obj) => obj.value !== undefined)
@IsString()
@IsOptional()
@IsNotEmpty({ message: 'condition is required.' })
condition?: string;

@ApiPropertyOptional()
@ValidateIf((obj) => obj.condition !== undefined)
@IsOptional()
@IsNotEmpty({ message: 'value is required.' })
@IsNumberString({}, { message: 'Value must be a number' })
Expand All @@ -40,6 +42,7 @@ export class ProofRequestAttribute {
@ApiPropertyOptional()
@IsString()
@IsOptional()
@IsNotEmpty({ message: 'credDefId is required.' })
credDefId?: string;
}

Expand All @@ -54,7 +57,7 @@ class ProofPayload {
@IsString({ message: 'parentThreadId must be in string' })
@IsNotEmpty({ message: 'please provide valid parentThreadId' })
@IsOptional()
parentThreadId: string;
parentThreadId?: string;

@ApiPropertyOptional()
@IsBoolean({ message: 'willConfirm must be in boolean' })
Expand Down Expand Up @@ -138,12 +141,12 @@ export class ProofRequestPresentationDefinition {
@IsOptional()
name: string;

@ApiProperty({type: () => [InputDescriptors]})
pranalidhanavade marked this conversation as resolved.
Show resolved Hide resolved
@IsNotEmpty({ message: 'inputDescriptors is required.' })
@ApiProperty()
@IsArray({ message: 'inputDescriptors must be an array' })
@IsObject({ each: true })
@IsNotEmpty({ message: 'inputDescriptors is required.' })
@ArrayMinSize(1)
@ValidateNested({each:true})
@Type(() => InputDescriptors)
@ValidateNested()
// eslint-disable-next-line camelcase
input_descriptors:InputDescriptors[];
}
Expand All @@ -162,7 +165,7 @@ export class ProofRequestAttributeDto {
type: () => [ProofRequestAttribute]
})
@IsArray({ message: 'attributes must be in array' })
@ValidateNested()
@ValidateNested({ each: true })
@IsObject({ each: true })
@IsNotEmpty({ message: 'please provide valid attributes' })
@Type(() => ProofRequestAttribute)
Expand Down Expand Up @@ -192,12 +195,17 @@ export class IndyDto {
}

export class RequestProofDto extends ProofPayload {
@ApiProperty()
@IsString()
@Transform(({ value }) => trim(value))
@IsUUID()
@IsNotEmpty({ message: 'connectionId is required.' })
connectionId: string;
@ApiProperty({
example: ['32f54163-7166-48f1-93d8-ff217bdb0653']
})

@IsNotEmpty({ each: true, message: 'connectionId array elements must not be empty.' })
@ValidateIf((obj) => Array.isArray(obj.connectionId))
@IsArray({ message: 'connectionId must be an array.' })
@ArrayMinSize(1, { message: 'connectionId must contain at least 1 element.' })
@ArrayMaxSize(10, { message: 'connectionId can contain at most 10 elements.' })
@IsUUID('all', { each: true, message: 'Each connectionId must be a valid UUID.' })
connectionId: string | string[];
pranalidhanavade marked this conversation as resolved.
Show resolved Hide resolved
pranalidhanavade marked this conversation as resolved.
Show resolved Hide resolved

@ApiProperty({
'example':
Expand Down Expand Up @@ -227,7 +235,8 @@ export class RequestProofDto extends ProofPayload {
'example':
{
id: '32f54163-7166-48f1-93d8-ff217bdb0653',
inputDescriptors: [
// eslint-disable-next-line camelcase
input_descriptors: [
{
'id': 'healthcare_input_1',
'name': 'Medical History',
Expand Down Expand Up @@ -272,7 +281,7 @@ export class RequestProofDto extends ProofPayload {
@IsEnum(AutoAccept, {
message: `Invalid auto accept proof. It should be one of: ${Object.values(AutoAccept).join(', ')}`
})
autoAcceptProof: AutoAccept;
pranalidhanavade marked this conversation as resolved.
Show resolved Hide resolved
autoAcceptProof: string;
}

export class OutOfBandRequestProof extends ProofPayload {
Expand Down
21 changes: 1 addition & 20 deletions apps/api-gateway/src/verification/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { IProofPresentationDetails, IProofPresentationList, IVerificationRecords
import { IPresentation, IProofRequest, IProofRequestSearchCriteria } from './interfaces/verification.interface';
import { IProofPresentation } from './interfaces/verification.interface';
// To do make a similar interface in API-gateway
import { IRequestProof } from 'apps/verification/src/interfaces/verification.interface';
import { user } from '@prisma/client';
import { NATSClient } from '@credebl/common/NATSClient';

Expand Down Expand Up @@ -49,25 +48,7 @@ export class VerificationService extends BaseService {
* @returns Requested proof presentation details
*/
sendProofRequest(requestProofDto: RequestProofDto, user: IUserRequest): Promise<IProofRequest> {
const requestProof: IRequestProof = {
orgId: requestProofDto.orgId,
type: requestProofDto.type,
comment: requestProofDto.comment,
autoAcceptProof: requestProofDto.autoAcceptProof,
connectionId: requestProofDto.connectionId,
goalCode: requestProofDto.goalCode,
parentThreadId: requestProofDto.parentThreadId,
protocolVersion: requestProofDto.protocolVersion,
willConfirm: requestProofDto.willConfirm
};
if (requestProofDto.proofFormats) {
requestProof.attributes = requestProofDto.proofFormats.indy.attributes;
}
if (requestProofDto.presentationDefinition) {
requestProof.presentationDefinition = requestProofDto.presentationDefinition;
}

const payload = { requestProof, user };
const payload = { requestProofDto, user };
return this.natsClient.sendNatsMessage(this.verificationServiceProxy, 'send-proof-request', payload);
}

Expand Down
39 changes: 39 additions & 0 deletions apps/verification/src/interfaces/verification.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,45 @@ export interface IRequestProof {
willConfirm?: boolean;
}

export interface IProofRequestData {
goalCode?: string;
parentThreadId?: string;
willConfirm?: boolean;
protocolVersion?: string;
proofFormats?:IProofFormat;
orgId: string;
connectionId?: string | string[];
attributes?: IProofRequestAttribute[];
type: ProofRequestType;
presentationDefinition?:IProofRequestPresentationDefinition;
comment: string;
autoAcceptProof: AutoAccept;
}
export interface IProofFormat {
indy: Indy;
}

export interface Indy {
attributes: IProofAttributesData[];
}

export interface IProofAttributesData {
attributeName: string;
attributeNames?: string[];
condition: string;
value: string;
credDefId: string;
schemaId: string;
}

export interface ProofRequestAttributeDto {
pranalidhanavade marked this conversation as resolved.
Show resolved Hide resolved
attributeName: string;
condition: string;
value: string;
credDefId: string;
schemaId: string;
}

export interface IGetAllProofPresentations {
url: string;
apiKey: string;
Expand Down
6 changes: 3 additions & 3 deletions apps/verification/src/verification.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller } from '@nestjs/common';
import { VerificationService } from './verification.service';
import { MessagePattern } from '@nestjs/microservices';
import { IProofPresentation, IProofPresentationData, IProofRequests, IRequestProof, ISendProofRequestPayload } from './interfaces/verification.interface';
import { IProofPresentation, IProofPresentationData, IProofRequestData, IProofRequests, ISendProofRequestPayload } from './interfaces/verification.interface';
import { IUserRequest } from '@credebl/user-request/user-request.interface';
import { presentations, user } from '@prisma/client';
import { IProofPresentationDetails, IProofPresentationList, IVerificationRecords } from '@credebl/common/interfaces/verification.interface';
Expand Down Expand Up @@ -44,8 +44,8 @@ export class VerificationController {
* @returns Requested proof presentation details
*/
@MessagePattern({ cmd: 'send-proof-request' })
async sendProofRequest(payload: { requestProof: IRequestProof, user: IUserRequest }): Promise<string> {
return this.verificationService.sendProofRequest(payload.requestProof);
async sendProofRequest(payload: { requestProofDto: IProofRequestData, user: IUserRequest }): Promise<string[]> {
return this.verificationService.sendProofRequest(payload.requestProofDto);
}

/**
Expand Down
Loading