Skip to content

Commit

Permalink
Feat/oob credential issuance verification (#467)
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]>

---------

Signed-off-by: KulkarniShashank <[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]>
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
5 people committed Sep 11, 2024
1 parent 81d5066 commit ee3ec04
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
29 changes: 29 additions & 0 deletions apps/api-gateway/src/issuance/issuance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response> {
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
Expand Down
2 changes: 1 addition & 1 deletion apps/api-gateway/src/verification/dto/request-proof.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions apps/api-gateway/src/verification/verification.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/verification/src/verification.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class VerificationController {
}

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

Expand Down
33 changes: 29 additions & 4 deletions apps/verification/src/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,10 @@ export class VerificationService {
* @param outOfBandRequestProof
* @returns Get requested proof presentation details
*/
async sendOutOfBandPresentationRequest(outOfBandRequestProof: IRequestProof): Promise<boolean> {
async sendOutOfBandPresentationRequest(outOfBandRequestProof: IRequestProof): 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';
Expand Down Expand Up @@ -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<object> {
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<void> {
const accumulatedErrors = [];

Expand Down

0 comments on commit ee3ec04

Please sign in to comment.