Skip to content

Commit

Permalink
Feat/oob credential issuance verification (#512)
Browse files Browse the repository at this point in the history
* fix: removed the unnecessary logger from the agent-service module (#419)

Signed-off-by: KulkarniShashank <[email protected]>

* WIP:OOB Proof Request

Signed-off-by: ankita_patidar <[email protected]>

* WIP:OOB Proof Request

Signed-off-by: ankita_patidar <[email protected]>

* fix:OOB Credential Offer restore changes

Signed-off-by: ankita_patidar <[email protected]>

* fix:add email as optional

Signed-off-by: ankita_patidar <[email protected]>

* fix:take response from presentation request payload

Signed-off-by: ankita_patidar <[email protected]>

* fix: resolved sonar lint checks

Signed-off-by: bhavanakarwade <[email protected]>

* fix: dco error

Signed-off-by: bhavanakarwade <[email protected]>

* fix: dco error

Signed-off-by: bhavanakarwade <[email protected]>

* expose agent format of proof request to API endpoint, disabled send offer by email

Signed-off-by: ankita_patidar <[email protected]>

---------

Signed-off-by: KulkarniShashank <[email protected]>
Signed-off-by: ankita_patidar <[email protected]>
Signed-off-by: bhavanakarwade <[email protected]>
Signed-off-by: Ankita Patidar <[email protected]>
Co-authored-by: Nishad Shirsat <[email protected]>
Co-authored-by: Nishad <[email protected]>
Co-authored-by: Shashank Kulkarni <[email protected]>
Co-authored-by: bhavanakarwade <[email protected]>
Co-authored-by: bhavanakarwade <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
6 people committed Sep 11, 2024
1 parent 0d98267 commit e967b23
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 52 deletions.
44 changes: 44 additions & 0 deletions apps/api-gateway/src/verification/dto/request-proof.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
11 changes: 3 additions & 8 deletions apps/api-gateway/src/verification/verification.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<Response> {

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,
Expand Down
4 changes: 2 additions & 2 deletions apps/api-gateway/src/verification/verification.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<object> {
sendOutOfBandPresentationRequest(outOfBandRequestProof: ISendProofRequestPayload, user: IUserRequest): Promise<object> {
const payload = { outOfBandRequestProof, user };
return this.sendNatsMessage(this.verificationServiceProxy, 'send-out-of-band-proof-request', payload);
}
Expand Down
6 changes: 3 additions & 3 deletions apps/verification/src/interfaces/verification.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 } 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';
Expand Down Expand Up @@ -63,8 +63,8 @@ export class VerificationController {
}

@MessagePattern({ cmd: 'send-out-of-band-proof-request' })
async sendOutOfBandPresentationRequest(payload: { outOfBandRequestProof: IRequestProof, user: IUserRequest }): Promise<boolean|object> {
return this.verificationService.sendOutOfBandPresentationRequest(payload.outOfBandRequestProof);
async sendOutOfBandPresentationRequest(payload: { outOfBandRequestProof: ISendProofRequestPayload, user: IUserRequest }): Promise<boolean|object> {
return this.verificationService.sendOutOfBandPresentationRequest(payload.outOfBandRequestProof, payload.user);
}

@MessagePattern({ cmd: 'get-verified-proof-details' })
Expand Down
62 changes: 26 additions & 36 deletions apps/verification/src/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,20 +331,18 @@ export class VerificationService {
* @param outOfBandRequestProof
* @returns Get requested proof presentation details
*/
async sendOutOfBandPresentationRequest(outOfBandRequestProof: IRequestProof): Promise<boolean|object> {
async sendOutOfBandPresentationRequest(outOfBandRequestProof: ISendProofRequestPayload, user: IUserRequest): Promise<boolean|object> {
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);
Expand All @@ -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);
Expand Down

0 comments on commit e967b23

Please sign in to comment.