From 5f25c4b43a4e9385fca20d2c671171a23f130b93 Mon Sep 17 00:00:00 2001 From: Ankita Patidar <35130088+ankita-p17@users.noreply.github.com> Date: Thu, 15 Feb 2024 00:44:56 +0530 Subject: [PATCH] Feat/oob credential issuance verification (#512) * 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 * fix:add email as optional Signed-off-by: ankita_patidar * fix:take response from presentation request payload Signed-off-by: ankita_patidar * fix: resolved sonar lint checks Signed-off-by: bhavanakarwade * fix: dco error Signed-off-by: bhavanakarwade * fix: dco error Signed-off-by: bhavanakarwade * expose agent format of proof request to API endpoint, disabled send offer by email Signed-off-by: ankita_patidar --------- Signed-off-by: KulkarniShashank Signed-off-by: ankita_patidar Signed-off-by: bhavanakarwade Signed-off-by: Ankita Patidar <35130088+ankita-p17@users.noreply.github.com> 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> Co-authored-by: bhavanakarwade --- .../src/verification/dto/request-proof.dto.ts | 44 +++++++++++++ .../verification/verification.controller.ts | 11 +--- .../src/verification/verification.service.ts | 4 +- .../src/interfaces/verification.interface.ts | 6 +- .../src/verification.controller.ts | 6 +- apps/verification/src/verification.service.ts | 62 ++++++++----------- 6 files changed, 81 insertions(+), 52 deletions(-) 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 9ca102123..01789e009 100644 --- a/apps/api-gateway/src/verification/dto/request-proof.dto.ts +++ b/apps/api-gateway/src/verification/dto/request-proof.dto.ts @@ -134,3 +134,47 @@ export class OutOfBandRequestProof extends ProofPayload { }) autoAcceptProof: string; } + + +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; + restrictions: IRequestedRestriction[] +} + +interface IRequestedPredicates { + [key: string]: IRequestedPredicatesName; +} + +interface IRequestedPredicatesName { + name: string; + restrictions: IRequestedRestriction[] +} + +interface IRequestedRestriction { + cred_def_id?: string; + schema_id?: string; +} + +export interface ISendProofRequestPayload { + protocolVersion?: string; + comment?: string; + connectionId?: string; + proofFormats: IProofFormats; + autoAcceptProof?: string; + label?: string; +} diff --git a/apps/api-gateway/src/verification/verification.controller.ts b/apps/api-gateway/src/verification/verification.controller.ts index 6719b45c8..9cfed6275 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 { OutOfBandRequestProof, RequestProofDto } from './dto/request-proof.dto'; +import { ISendProofRequestPayload, OutOfBandRequestProof, RequestProofDto } from './dto/request-proof.dto'; import { VerificationService } from './verification.service'; import IResponseType, { IResponse } from '@credebl/common/interfaces/response.interface'; import { Response } from 'express'; @@ -256,15 +256,10 @@ export class VerificationController { async sendOutOfBandPresentationRequest( @Res() res: Response, @User() user: IUserRequest, - @Body() outOfBandRequestProof: OutOfBandRequestProof, + @Body() outOfBandRequestProof: ISendProofRequestPayload, @Param('orgId') orgId: string ): Promise { - - for (const attrData of outOfBandRequestProof.attributes) { - await this.validateAttribute(attrData); - } - - outOfBandRequestProof.orgId = orgId; + user.orgId = orgId; const result = await this.verificationService.sendOutOfBandPresentationRequest(outOfBandRequestProof, user); const finalResponse: IResponseType = { statusCode: HttpStatus.CREATED, diff --git a/apps/api-gateway/src/verification/verification.service.ts b/apps/api-gateway/src/verification/verification.service.ts index 9faea8c2b..44dffc4b4 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 { OutOfBandRequestProof, RequestProofDto } from './dto/request-proof.dto'; +import { ISendProofRequestPayload, 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: OutOfBandRequestProof, user: IUserRequest): Promise { + sendOutOfBandPresentationRequest(outOfBandRequestProof: ISendProofRequestPayload, 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 d35a2daaf..8e2da7579 100644 --- a/apps/verification/src/interfaces/verification.interface.ts +++ b/apps/verification/src/interfaces/verification.interface.ts @@ -84,11 +84,11 @@ interface IRequestedRestriction { } export interface ISendProofRequestPayload { - protocolVersion: string; - comment: string; + protocolVersion?: string; + comment?: string; connectionId?: string; proofFormats: IProofFormats; - autoAcceptProof: string; + autoAcceptProof?: string; label?: string; goalCode?: string; parentThreadId?: string; diff --git a/apps/verification/src/verification.controller.ts b/apps/verification/src/verification.controller.ts index 2ca29829d..34e8bd9db 100644 --- a/apps/verification/src/verification.controller.ts +++ b/apps/verification/src/verification.controller.ts @@ -1,7 +1,7 @@ import { Controller } from '@nestjs/common'; import { VerificationService } from './verification.service'; import { MessagePattern } from '@nestjs/microservices'; -import { IProofPresentation, IProofPresentationData, IProofRequests, IRequestProof } from './interfaces/verification.interface'; +import { IProofPresentation, IProofPresentationData, IProofRequests, IRequestProof, ISendProofRequestPayload } from './interfaces/verification.interface'; import { IUserRequest } from '@credebl/user-request/user-request.interface'; import { presentations } from '@prisma/client'; import { IProofPresentationDetails, IProofPresentationList } from '@credebl/common/interfaces/verification.interface'; @@ -63,8 +63,8 @@ export class VerificationController { } @MessagePattern({ cmd: 'send-out-of-band-proof-request' }) - async sendOutOfBandPresentationRequest(payload: { outOfBandRequestProof: IRequestProof, user: IUserRequest }): Promise { - return this.verificationService.sendOutOfBandPresentationRequest(payload.outOfBandRequestProof); + async sendOutOfBandPresentationRequest(payload: { outOfBandRequestProof: ISendProofRequestPayload, user: IUserRequest }): Promise { + return this.verificationService.sendOutOfBandPresentationRequest(payload.outOfBandRequestProof, payload.user); } @MessagePattern({ cmd: 'get-verified-proof-details' }) diff --git a/apps/verification/src/verification.service.ts b/apps/verification/src/verification.service.ts index 265e9b297..ed5ce6f28 100644 --- a/apps/verification/src/verification.service.ts +++ b/apps/verification/src/verification.service.ts @@ -331,20 +331,18 @@ export class VerificationService { * @param outOfBandRequestProof * @returns Get requested proof presentation details */ - async sendOutOfBandPresentationRequest(outOfBandRequestProof: IRequestProof): Promise { + async sendOutOfBandPresentationRequest(outOfBandRequestProof: ISendProofRequestPayload, user: IUserRequest): Promise { try { this.logger.log(`-------outOfBandRequestProof------${JSON.stringify(outOfBandRequestProof)}`); - const comment = outOfBandRequestProof.comment || ''; - const protocolVersion = outOfBandRequestProof.protocolVersion || 'v1'; - const autoAcceptProof = outOfBandRequestProof.autoAcceptProof || 'never'; + outOfBandRequestProof.protocolVersion = outOfBandRequestProof.protocolVersion || 'v1'; + outOfBandRequestProof.autoAcceptProof = outOfBandRequestProof.autoAcceptProof || 'always'; - const { requestedAttributes, requestedPredicates } = await this._proofRequestPayload(outOfBandRequestProof); + // const { requestedAttributes, requestedPredicates } = await this._proofRequestPayload(outOfBandRequestProof); - - const [getAgentDetails, organizationDetails] = await Promise.all([ - this.verificationRepository.getAgentEndPoint(outOfBandRequestProof.orgId), - this.verificationRepository.getOrganization(outOfBandRequestProof.orgId) + const [getAgentDetails] = await Promise.all([ + this.verificationRepository.getAgentEndPoint(user.orgId), + this.verificationRepository.getOrganization(user.orgId) ]); const orgAgentType = await this.verificationRepository.getOrgAgentType(getAgentDetails?.orgAgentTypeId); @@ -353,39 +351,31 @@ export class VerificationService { const url = await this.getAgentUrl(verificationMethodLabel, orgAgentType, getAgentDetails?.agentEndPoint, getAgentDetails?.tenantId); this.logger.log(`cachedApiKey----${apiKey}`); if (!apiKey || null === apiKey || undefined === apiKey) { - apiKey = await this._getOrgAgentApiKey(outOfBandRequestProof.orgId); + apiKey = await this._getOrgAgentApiKey(user.orgId); } const payload: IProofRequestPayload = { apiKey, url, - proofRequestPayload: { - protocolVersion, - comment, - label: organizationDetails?.name, - proofFormats: { - indy: { - name: 'Proof Request', - version: '1.0', - requested_attributes: requestedAttributes, - requested_predicates: requestedPredicates - } - }, - autoAcceptProof, - goalCode: outOfBandRequestProof.goalCode || undefined, - parentThreadId: outOfBandRequestProof.parentThreadId || undefined, - willConfirm: outOfBandRequestProof.willConfirm || undefined - } + proofRequestPayload: outOfBandRequestProof }; - - 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); - } + + const getProofPresentation = await this._sendOutOfBandProofRequest(payload); + this.logger.log(`-----getProofPresentation---${JSON.stringify(getProofPresentation)}`); + if (!getProofPresentation) { + throw new Error(ResponseMessages.verification.error.proofPresentationNotFound); + } + return getProofPresentation.response; + + // Unused code : to be segregated + // 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);