From ee3ec04fd31d05205be21e1cab2c40d746032fa3 Mon Sep 17 00:00:00 2001 From: Ankita Patidar <35130088+ankita-p17@users.noreply.github.com> Date: Tue, 30 Jan 2024 22:04:19 +0530 Subject: [PATCH] Feat/oob credential issuance verification (#467) * fix: removed the unnecessary logger from the agent-service module (#419) Signed-off-by: KulkarniShashank * WIP:OOB Proof Request Signed-off-by: ankita_patidar * WIP:OOB Proof Request Signed-off-by: ankita_patidar * fix:OOB Credential Offer restore changes Signed-off-by: ankita_patidar --------- Signed-off-by: KulkarniShashank Signed-off-by: ankita_patidar Co-authored-by: Nishad Shirsat <103021375+nishad-ayanworks@users.noreply.github.com> Co-authored-by: Nishad Co-authored-by: Shashank Kulkarni <44693969+KulkarniShashank@users.noreply.github.com> Co-authored-by: bhavanakarwade <137506897+bhavanakarwade@users.noreply.github.com> Signed-off-by: KulkarniShashank --- .../src/issuance/issuance.controller.ts | 29 ++++++++++++++++ .../src/verification/dto/request-proof.dto.ts | 2 +- .../verification/verification.controller.ts | 5 +-- .../src/verification.controller.ts | 2 +- apps/verification/src/verification.service.ts | 33 ++++++++++++++++--- 5 files changed, 63 insertions(+), 8 deletions(-) diff --git a/apps/api-gateway/src/issuance/issuance.controller.ts b/apps/api-gateway/src/issuance/issuance.controller.ts index 688cb82e4..39c3952b7 100644 --- a/apps/api-gateway/src/issuance/issuance.controller.ts +++ b/apps/api-gateway/src/issuance/issuance.controller.ts @@ -532,6 +532,35 @@ export class IssuanceController { return res.status(HttpStatus.CREATED).json(finalResponse); } + /** + * Description: Issuer create out-of-band credential + * @param user + * @param issueCredentialDto + */ + @Post('/orgs/:orgId/credentials/oob/offer') + @ApiBearerAuth() + @ApiOperation({ + summary: `Create out-of-band credential offer`, + description: `Creates an out-of-band credential offer` + }) + @UseGuards(AuthGuard('jwt'), OrgRolesGuard) + @Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER) + @ApiResponse({ status: HttpStatus.CREATED, description: 'Success', type: ApiResponseDto }) + async createOOBCredentialOffer( + @Param('orgId') orgId: string, + @Body() issueCredentialDto: OOBIssueCredentialDto, + @Res() res: Response + ): Promise { + issueCredentialDto.orgId = orgId; + const getCredentialDetails = await this.issueCredentialService.sendCredentialOutOfBand(issueCredentialDto); + const finalResponse: IResponseType = { + statusCode: HttpStatus.CREATED, + message: ResponseMessages.issuance.success.create, + data: getCredentialDetails.response + }; + return res.status(HttpStatus.CREATED).json(finalResponse); + } + /** * Description: webhook Save issued credential details * @param user 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 a54bbdb59..4fc42b148 100644 --- a/apps/api-gateway/src/verification/dto/request-proof.dto.ts +++ b/apps/api-gateway/src/verification/dto/request-proof.dto.ts @@ -91,7 +91,7 @@ export class OutOfBandRequestProof { @IsNotEmpty({ message: 'Email is required' }) @Transform(({ value }) => trim(value)) @IsString({ each: true, message: 'Each emailId in the array should be a string' }) - emailId: string | string[]; + emailId?: string | string[]; @ApiProperty() @IsOptional() diff --git a/apps/api-gateway/src/verification/verification.controller.ts b/apps/api-gateway/src/verification/verification.controller.ts index 98794a0da..47593f9ac 100644 --- a/apps/api-gateway/src/verification/verification.controller.ts +++ b/apps/api-gateway/src/verification/verification.controller.ts @@ -254,10 +254,11 @@ export class VerificationController { } outOfBandRequestProof.orgId = orgId; - await this.verificationService.sendOutOfBandPresentationRequest(outOfBandRequestProof, user); + const result = await this.verificationService.sendOutOfBandPresentationRequest(outOfBandRequestProof, user); const finalResponse: IResponseType = { statusCode: HttpStatus.CREATED, - message: ResponseMessages.verification.success.send + message: ResponseMessages.verification.success.send, + data: result }; return res.status(HttpStatus.CREATED).json(finalResponse); } diff --git a/apps/verification/src/verification.controller.ts b/apps/verification/src/verification.controller.ts index 4cc9b737c..2ca29829d 100644 --- a/apps/verification/src/verification.controller.ts +++ b/apps/verification/src/verification.controller.ts @@ -63,7 +63,7 @@ export class VerificationController { } @MessagePattern({ cmd: 'send-out-of-band-proof-request' }) - async sendOutOfBandPresentationRequest(payload: { outOfBandRequestProof: IRequestProof, user: IUserRequest }): Promise { + async sendOutOfBandPresentationRequest(payload: { outOfBandRequestProof: IRequestProof, user: IUserRequest }): Promise { return this.verificationService.sendOutOfBandPresentationRequest(payload.outOfBandRequestProof); } diff --git a/apps/verification/src/verification.service.ts b/apps/verification/src/verification.service.ts index 244f10faa..1b7044712 100644 --- a/apps/verification/src/verification.service.ts +++ b/apps/verification/src/verification.service.ts @@ -324,8 +324,10 @@ export class VerificationService { * @param outOfBandRequestProof * @returns Get requested proof presentation details */ - async sendOutOfBandPresentationRequest(outOfBandRequestProof: IRequestProof): Promise { + async sendOutOfBandPresentationRequest(outOfBandRequestProof: IRequestProof): Promise { try { + + this.logger.log(`-------outOfBandRequestProof------${JSON.stringify(outOfBandRequestProof)}`); const comment = outOfBandRequestProof.comment || ''; const protocolVersion = outOfBandRequestProof.protocolVersion || 'v1'; const autoAcceptProof = outOfBandRequestProof.autoAcceptProof || 'never'; @@ -366,16 +368,39 @@ export class VerificationService { } }; - const batchSize = 100; // Define the batch size according to your needs - const { emailId } = outOfBandRequestProof; // Assuming it's an array - await this.sendEmailInBatches(payload, emailId, getAgentDetails, organizationDetails, batchSize); + if (outOfBandRequestProof.emailId) { + const batchSize = 100; // Define the batch size according to your needs + const { emailId } = outOfBandRequestProof; // Assuming it's an array + await this.sendEmailInBatches(payload, emailId, getAgentDetails, organizationDetails, batchSize); return true; + } else { + return this.generateOOBProofReq(payload, getAgentDetails); + } } catch (error) { this.logger.error(`[sendOutOfBandPresentationRequest] - error in out of band proof request : ${error.message}`); this.verificationErrorHandling(error); } } + + private async generateOOBProofReq(payload: IProofRequestPayload, getAgentDetails: org_agents): Promise { + let agentApiKey: string = await this.cacheService.get(CommonConstants.CACHE_APIKEY_KEY); + this.logger.log(`cachedApiKey----${agentApiKey}`); + if (!agentApiKey || null === agentApiKey || undefined === agentApiKey) { + agentApiKey = await this._getOrgAgentApiKey(getAgentDetails.orgId); + } + payload.apiKey = agentApiKey; + const getProofPresentation = await this._sendOutOfBandProofRequest(payload); + + this.logger.log(`-----getProofPresentation---${JSON.stringify(getProofPresentation)}`); + + if (!getProofPresentation) { + throw new Error(ResponseMessages.verification.error.proofPresentationNotFound); + } + return getProofPresentation; + } + + async sendEmailInBatches(payload: IProofRequestPayload, emailIds: string[] | string, getAgentDetails: org_agents, organizationDetails: organisation, batchSize: number): Promise { const accumulatedErrors = [];