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 all 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
5 changes: 4 additions & 1 deletion .env.demo
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,7 @@ ELK_LOG=true // ELK flag
LOG_LEVEL=debug // ELK log level
ELK_LOG_PATH = "http://localhost:9200/" // ELK log path
ELK_USERNAME=elastic // ELK user username
ELK_PASSWORD=xxxxxx // ELK user password
ELK_PASSWORD=xxxxxx // ELK user password
ORGANIZATION=credebl
CONTEXT=platform
APP=api
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,6 @@ LOG_LEVEL=debug // ELK log level
ELK_LOG_PATH = "http://localhost:9200/" // ELK log path
ELK_USERNAME=elastic // ELK user username
ELK_PASSWORD=xxxxxx // ELK user password
ORGANIZATION=credebl
CONTEXT=platform
APP=api
44 changes: 28 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, Matches } 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,11 @@ export class ProofRequestAttribute {
@ApiPropertyOptional()
@IsString()
@IsOptional()
@IsNotEmpty({ message: 'credDefId is required.' })
@Matches(
/^[a-zA-Z0-9]{21,22}:[a-zA-Z0-9]+:[a-zA-Z0-9]+:[0-9]+:[a-zA-Z0-9\s]+$/,
{ message: 'credDefId is it not a valid unqualified credDef' }
)
credDefId?: string;
}

Expand All @@ -54,7 +61,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 +145,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({type: () => [InputDescriptors]})
@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 +169,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 +199,16 @@ 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.' })
@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[];

@ApiProperty({
'example':
Expand Down Expand Up @@ -227,7 +238,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 @@ -265,7 +277,7 @@ export class RequestProofDto extends ProofPayload {

orgId: string;

@ApiPropertyOptional()
@ApiPropertyOptional({enum:AutoAccept})
@IsString({ message: 'auto accept proof must be in string' })
@IsNotEmpty({ message: 'please provide valid auto accept proof' })
@IsOptional()
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
31 changes: 31 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,37 @@ 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 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