diff --git a/apps/agent-service/src/interface/agent-service.interface.ts b/apps/agent-service/src/interface/agent-service.interface.ts index 685122c49..663a32e27 100644 --- a/apps/agent-service/src/interface/agent-service.interface.ts +++ b/apps/agent-service/src/interface/agent-service.interface.ts @@ -277,6 +277,9 @@ interface IRequestedPredicatesName { interface IRequestedRestriction { cred_def_id?: string; schema_id?: string; + schema_issuer_did?: string; + schema_name?: string; + issuer_did?: string; } export interface IAgentSpinUpSatus { diff --git a/apps/api-gateway/src/verification/dto/request-proof.dto.ts b/apps/api-gateway/src/verification/dto/request-proof.dto.ts index 01789e009..dc765e008 100644 --- a/apps/api-gateway/src/verification/dto/request-proof.dto.ts +++ b/apps/api-gateway/src/verification/dto/request-proof.dto.ts @@ -1,8 +1,9 @@ -import { IsArray, IsBoolean, IsEmail, IsEnum, IsNotEmpty, IsNumberString, IsObject, IsOptional, IsString } from 'class-validator'; +import { IsArray, IsBoolean, IsEmail, IsEnum, IsNotEmpty, IsNumberString, IsObject, IsOptional, IsString, IsUUID } from 'class-validator'; import { toLowerCase, trim } from '@credebl/common/cast.helper'; import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { Transform } from 'class-transformer'; import { AutoAccept } from '@credebl/enum/enum'; +import { IProofFormats } from '../interfaces/verification.interface'; export class ProofRequestAttribute { @IsString() @@ -135,46 +136,62 @@ export class OutOfBandRequestProof extends ProofPayload { autoAcceptProof: string; } +export class SendProofRequestPayload { -interface IProofFormats { - indy: IndyProof -} + @ApiPropertyOptional() + @IsString({ message: 'protocolVersion must be in string' }) + @IsNotEmpty({ message: 'please provide valid protocol version' }) + @IsOptional() + protocolVersion: string; -interface IndyProof { - name: string; - version: string; - requested_attributes: IRequestedAttributes; - requested_predicates: IRequestedPredicates; -} + @ApiPropertyOptional() + @IsOptional() + @IsString({ message: 'comment must be in string' }) + comment: string; -interface IRequestedAttributes { - [key: string]: IRequestedAttributesName; -} + @ApiProperty() + @IsString() + @Transform(({ value }) => trim(value)) + @Transform(({ value }) => toLowerCase(value)) + @IsNotEmpty({ message: 'connectionId is required.' }) + connectionId: string; -interface IRequestedAttributesName { - name: string; - restrictions: IRequestedRestriction[] -} + @ApiProperty({ + 'example': [ + { + indy: { + name: 'Verify national identity', + version: '1.0', + // eslint-disable-next-line camelcase + requested_attributes: {}, + // eslint-disable-next-line camelcase + requested_predicates: {} + } + } + ] + }) + @IsObject({ each: true }) + @IsNotEmpty({ message: 'please provide valid proofFormat' }) + proofFormats: IProofFormats; -interface IRequestedPredicates { - [key: string]: IRequestedPredicatesName; -} + @ApiPropertyOptional() + @IsString({ message: 'auto accept proof must be in string' }) + @IsNotEmpty({ message: 'please provide from valid auto accept proof options' }) + @IsOptional() + @IsEnum(AutoAccept, { + message: `Invalid auto accept proof. It should be one of: ${Object.values(AutoAccept).join(', ')}` + }) + autoAcceptProof: AutoAccept; -interface IRequestedPredicatesName { - name: string; - restrictions: IRequestedRestriction[] -} + @ApiPropertyOptional() + @IsOptional() + @IsString({ message: 'label must be in string' }) + label: string; -interface IRequestedRestriction { - cred_def_id?: string; - schema_id?: string; + @ApiPropertyOptional() + @IsOptional() + @IsUUID() + @IsNotEmpty({ message: 'please provide valid parentThreadId' }) + parentThreadId: string; } -export interface ISendProofRequestPayload { - protocolVersion?: string; - comment?: string; - connectionId?: string; - proofFormats: IProofFormats; - autoAcceptProof?: string; - label?: string; -} diff --git a/apps/api-gateway/src/verification/interfaces/verification.interface.ts b/apps/api-gateway/src/verification/interfaces/verification.interface.ts index 7937c6aee..a722da72a 100644 --- a/apps/api-gateway/src/verification/interfaces/verification.interface.ts +++ b/apps/api-gateway/src/verification/interfaces/verification.interface.ts @@ -51,3 +51,42 @@ interface ITags { state: string; threadId: string; } + +export interface IProofFormats { + indy: IndyProof +} + +interface IndyProof { + name: string; + version: string; + requested_attributes: IRequestedAttributes; + requested_predicates: IRequestedPredicates; +} + +interface IRequestedAttributes { + [key: string]: IRequestedAttributesName; +} + +interface IRequestedAttributesName { + name?: string; + names?: string; + restrictions: IRequestedRestriction[] +} + +interface IRequestedPredicates { + [key: string]: IRequestedPredicatesName; +} + +interface IRequestedPredicatesName { + name: string; + restrictions: IRequestedRestriction[] +} + +interface IRequestedRestriction { + cred_def_id?: string; + schema_id?: string; + schema_issuer_did?: string; + schema_name?: string; + issuer_did?: string; + schema_version?: string; +} \ No newline at end of file diff --git a/apps/api-gateway/src/verification/verification.controller.ts b/apps/api-gateway/src/verification/verification.controller.ts index e35baaba0..7f9bb9b45 100644 --- a/apps/api-gateway/src/verification/verification.controller.ts +++ b/apps/api-gateway/src/verification/verification.controller.ts @@ -16,7 +16,7 @@ import { Controller, Logger, Post, Body, Get, Query, HttpStatus, Res, UseGuards, import { ApiResponseDto } from '../dtos/apiResponse.dto'; import { UnauthorizedErrorDto } from '../dtos/unauthorized-error.dto'; import { ForbiddenErrorDto } from '../dtos/forbidden-error.dto'; -import { ISendProofRequestPayload, OutOfBandRequestProof, RequestProofDto } from './dto/request-proof.dto'; +import { SendProofRequestPayload, RequestProofDto } from './dto/request-proof.dto'; import { VerificationService } from './verification.service'; import IResponseType, { IResponse } from '@credebl/common/interfaces/response.interface'; import { Response } from 'express'; @@ -247,14 +247,14 @@ export class VerificationController { @ApiResponse({ status: HttpStatus.CREATED, description: 'Success', type: ApiResponseDto }) @ApiUnauthorizedResponse({ status: HttpStatus.UNAUTHORIZED, description: 'Unauthorized', type: UnauthorizedErrorDto }) @ApiForbiddenResponse({ status: HttpStatus.FORBIDDEN, description: 'Forbidden', type: ForbiddenErrorDto }) - @ApiBody({ type: OutOfBandRequestProof }) + @ApiBody({ type: SendProofRequestPayload }) @Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.VERIFIER) @ApiBearerAuth() @UseGuards(AuthGuard('jwt'), OrgRolesGuard) async sendOutOfBandPresentationRequest( @Res() res: Response, @User() user: IUserRequest, - @Body() outOfBandRequestProof: ISendProofRequestPayload, + @Body() outOfBandRequestProof: SendProofRequestPayload, @Param('orgId') orgId: string ): Promise { user.orgId = orgId; diff --git a/apps/api-gateway/src/verification/verification.service.ts b/apps/api-gateway/src/verification/verification.service.ts index 44dffc4b4..8a51651b4 100644 --- a/apps/api-gateway/src/verification/verification.service.ts +++ b/apps/api-gateway/src/verification/verification.service.ts @@ -1,7 +1,7 @@ import { Injectable, Inject} from '@nestjs/common'; import { ClientProxy} from '@nestjs/microservices'; import { BaseService } from 'libs/service/base.service'; -import { ISendProofRequestPayload, RequestProofDto } from './dto/request-proof.dto'; +import { SendProofRequestPayload, RequestProofDto } from './dto/request-proof.dto'; import { IUserRequest } from '@credebl/user-request/user-request.interface'; import { WebhookPresentationProofDto } from './dto/webhook-proof.dto'; import { IProofPresentationDetails, IProofPresentationList } from '@credebl/common/interfaces/verification.interface'; @@ -70,7 +70,7 @@ export class VerificationService extends BaseService { * @param outOfBandRequestProof * @returns Get out-of-band requested proof presentation details */ - sendOutOfBandPresentationRequest(outOfBandRequestProof: ISendProofRequestPayload, user: IUserRequest): Promise { + sendOutOfBandPresentationRequest(outOfBandRequestProof: SendProofRequestPayload, user: IUserRequest): Promise { const payload = { outOfBandRequestProof, user }; return this.sendNatsMessage(this.verificationServiceProxy, 'send-out-of-band-proof-request', payload); } diff --git a/apps/verification/src/interfaces/verification.interface.ts b/apps/verification/src/interfaces/verification.interface.ts index 8e2da7579..082fe897f 100644 --- a/apps/verification/src/interfaces/verification.interface.ts +++ b/apps/verification/src/interfaces/verification.interface.ts @@ -65,7 +65,8 @@ interface IRequestedAttributes { } interface IRequestedAttributesName { - name: string; + name?: string; + names?: string; restrictions: IRequestedRestriction[] } @@ -81,6 +82,10 @@ interface IRequestedPredicatesName { interface IRequestedRestriction { cred_def_id?: string; schema_id?: string; + schema_issuer_did?: string; + schema_name?: string; + issuer_did?: string; + schema_version?: string; } export interface ISendProofRequestPayload {