Skip to content

Commit

Permalink
feat: implement proof presentation for holder (#860)
Browse files Browse the repository at this point in the history
* feat: accept proof request by holder API

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

* feat: holder get proof presentation and get proof presentation by id

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

* refactor: changes in accept proof request and get proof request

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

---------

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>
  • Loading branch information
KulkarniShashank authored and KulkarniShashank committed Sep 11, 2024
1 parent def73bf commit 1df5fb7
Show file tree
Hide file tree
Showing 12 changed files with 470 additions and 82 deletions.
112 changes: 109 additions & 3 deletions apps/api-gateway/src/cloud-wallet/cloud-wallet.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IResponse } from '@credebl/common/interfaces/response.interface';
import { ResponseMessages } from '@credebl/common/response-messages';
import { Controller, Post, Logger, Body, HttpStatus, Res, UseFilters, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiForbiddenResponse, ApiOperation, ApiResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger';
import { Controller, Post, Logger, Body, HttpStatus, Res, UseFilters, UseGuards, Get, Param, Query } from '@nestjs/common';
import { ApiBearerAuth, ApiForbiddenResponse, ApiOperation, ApiQuery, ApiResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger';
import { ForbiddenErrorDto } from '../dtos/forbidden-error.dto';
import { UnauthorizedErrorDto } from '../dtos/unauthorized-error.dto';
import { CloudWalletService } from './cloud-wallet.service';
Expand All @@ -14,6 +14,9 @@ import { AuthGuard } from '@nestjs/passport';
import { User } from '../authz/decorators/user.decorator';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { user } from '@prisma/client';
import { UserRoleGuard } from '../authz/guards/user-role.guard';
import { AcceptProofRequestDto } from './dtos/accept-proof-request.dto';
import { IGetProofPresentation, IGetProofPresentationById } from '@credebl/common/interfaces/cloud-wallet.interface';


@UseFilters(CustomExceptionFilter)
Expand Down Expand Up @@ -45,7 +48,12 @@ export class CloudWalletController {
@User() user: user
): Promise<Response> {

const configureBaseWalletData = await this.cloudWalletService.configureBaseWallet(cloudBaseWalletConfigure, user);
const { id, email } = user;

cloudBaseWalletConfigure.userId = id;
cloudBaseWalletConfigure.email = email;

const configureBaseWalletData = await this.cloudWalletService.configureBaseWallet(cloudBaseWalletConfigure);
const finalResponse: IResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.cloudWallet.success.configureBaseWallet,
Expand All @@ -54,6 +62,104 @@ export class CloudWalletController {
return res.status(HttpStatus.CREATED).json(finalResponse);
}

/**
* Accept proof request
* @param acceptProofRequest
* @param user
* @param res
* @returns sucess message
*/
@Post('/proofs/accept-request')
@ApiOperation({ summary: 'Accept proof request', description: 'Accept proof request' })
@ApiResponse({ status: HttpStatus.CREATED, description: 'Created', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
async acceptProofRequest(
@Res() res: Response,
@Body() acceptProofRequest: AcceptProofRequestDto,
@User() user: user
): Promise<Response> {
const { id, email } = user;
acceptProofRequest.userId = id;
acceptProofRequest.email = email;

const acceptProofRequestDetails = await this.cloudWalletService.acceptProofRequest(acceptProofRequest);
const finalResponse: IResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.cloudWallet.success.acceptProofRequest,
data: acceptProofRequestDetails
};
return res.status(HttpStatus.CREATED).json(finalResponse);
}

/**
* Get proof presentation by proof id
* @param proofRecordId
* @param res
* @returns sucess message
*/
@Get('/proofs/:proofRecordId')
@ApiOperation({ summary: 'Get proof presentation by Id', description: 'Get proof presentation by Id' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
async getProofById(
@Param('proofRecordId') proofRecordId: string,
@Res() res: Response,
@User() user: user
): Promise<Response> {
const { id, email } = user;

const proofPresentationByIdPayload: IGetProofPresentationById = {
userId: id,
email,
proofRecordId
};

const getProofDetails = await this.cloudWalletService.getProofById(proofPresentationByIdPayload);
const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
message: ResponseMessages.cloudWallet.success.getProofById,
data: getProofDetails
};
return res.status(HttpStatus.OK).json(finalResponse);
}

/**
* Get proof presentations
* @param threadId
* @param res
* @returns sucess message
*/
@Get('/proofs')
@ApiOperation({ summary: 'Get proof presentation', description: 'Get proof presentation' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
@ApiQuery({
name: 'threadId',
required: false
})
async getProofPresentation(
@Res() res: Response,
@User() user: user,
@Query('threadId') threadId?: string
): Promise<Response> {

const { id, email } = user;

const proofPresentationPayload: IGetProofPresentation = {
userId: id,
email,
threadId
};

const getProofDetails = await this.cloudWalletService.getProofPresentation(proofPresentationPayload);
const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
message: ResponseMessages.cloudWallet.success.getProofPresentation,
data: getProofDetails
};
return res.status(HttpStatus.OK).json(finalResponse);
}

/**
* Create cloud wallet
* @param cloudWalletDetails
Expand Down
28 changes: 21 additions & 7 deletions apps/api-gateway/src/cloud-wallet/cloud-wallet.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

import { ICreateCloudWallet, IGetStoredWalletInfo, IStoredWalletDetails } from '@credebl/common/interfaces/cloud-wallet.interface';
import { IAcceptProofRequest, IProofRequestRes, ICloudBaseWalletConfigure, ICreateCloudWallet, IGetProofPresentation, IGetProofPresentationById, IGetStoredWalletInfo, IStoredWalletDetails } from '@credebl/common/interfaces/cloud-wallet.interface';
import { Inject, Injectable} from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
import { BaseService } from 'libs/service/base.service';
import { CloudBaseWalletConfigureDto } from './dtos/configure-base-wallet.dto';
import { user } from '@prisma/client';

@Injectable()
export class CloudWalletService extends BaseService {
Expand All @@ -13,11 +11,27 @@ export class CloudWalletService extends BaseService {
}

configureBaseWallet(
cloudBaseWalletConfigure: CloudBaseWalletConfigureDto,
user: user
cloudBaseWalletConfigure: ICloudBaseWalletConfigure
): Promise<IGetStoredWalletInfo> {
const payload = {cloudBaseWalletConfigure, user};
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'configure-cloud-base-wallet', payload);
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'configure-cloud-base-wallet', cloudBaseWalletConfigure);
}

acceptProofRequest(
acceptProofRequest: IAcceptProofRequest
): Promise<IProofRequestRes> {
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'accept-proof-request-by-holder', acceptProofRequest);
}

getProofById(
proofPresentationByIdPayload: IGetProofPresentationById
): Promise<IProofRequestRes> {
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'get-proof-by-proof-id-holder', proofPresentationByIdPayload);
}

getProofPresentation(
proofPresentationPayload: IGetProofPresentation
): Promise<IProofRequestRes[]> {
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'get-proof-presentation-holder', proofPresentationPayload);
}

createCloudWallet(
Expand Down
29 changes: 29 additions & 0 deletions apps/api-gateway/src/cloud-wallet/dtos/accept-proof-request.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsBoolean, IsNotEmpty, IsOptional, IsString, IsUUID } from 'class-validator';

export class AcceptProofRequestDto {
@ApiProperty({ example: '4e687079-273b-447b-b9dd-9589c84dc6dd' })
@IsString({ message: 'proofRecordId must be a string' })
@IsNotEmpty({ message: 'please provide valid proofRecordId' })
@IsUUID()
proofRecordId: string;

@ApiPropertyOptional({ example: false })
@IsOptional()
@IsBoolean({ message: 'filterByPresentationPreview must be a boolean' })
filterByPresentationPreview?: boolean;

@ApiPropertyOptional({ example: false })
@IsOptional()
@IsBoolean({ message: 'filterByNonRevocationRequirements must be a boolean' })
filterByNonRevocationRequirements?: boolean;

@ApiPropertyOptional({ example: '' })
@IsOptional()
@IsString({ message: 'comment must be a string' })
comment?: string;

userId: string;

email: string;
}
1 change: 0 additions & 1 deletion apps/api-gateway/src/cloud-wallet/dtos/cloudWallet.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ export class CreateCloudWalletDto {
@IsNotEmpty({ message: 'please provide valid image URL' })
@IsNotSQLInjection({ message: 'Image URL is required.' })
connectionImageUrl?: string;

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
import { IsNotEmpty, IsString } from 'class-validator';

import { ApiProperty } from '@nestjs/swagger';
import { IsHostPortOrDomain, trim } from '@credebl/common/cast.helper';
import { Transform } from 'class-transformer';
import { IsHostPortOrDomain } from '@credebl/common/cast.helper';

export class CloudBaseWalletConfigureDto {
@ApiProperty({ example: 'awqx@getnada.com' })
@IsEmail({}, { message: 'Please provide a valid email' })
@IsNotEmpty({ message: 'Email is required' })
@IsString({ message: 'Email should be a string' })
@Transform(({ value }) => trim(value))
email: string;

@ApiProperty({ example: 'xxx-xxxx-xxxx' })
@IsString({ message: 'walletKey must be a string' })
@IsNotEmpty({ message: 'please provide valid walletKey' })
Expand All @@ -27,4 +19,8 @@ export class CloudBaseWalletConfigureDto {
@IsNotEmpty({ message: 'please provide valid agentEndpoint' })
@IsHostPortOrDomain({ message: 'agentEndpoint must be a valid host:port or domain' })
agentEndpoint: string;

userId: string;

email: string;
}
31 changes: 0 additions & 31 deletions apps/cloud-wallet/interfaces/cloud-wallet.interface.ts

This file was deleted.

22 changes: 18 additions & 4 deletions apps/cloud-wallet/src/cloud-wallet.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@
import { Controller } from '@nestjs/common'; // Import the common service in the library
import { CloudWalletService } from './cloud-wallet.service'; // Import the common service in connection module
import { MessagePattern } from '@nestjs/microservices'; // Import the nestjs microservices package
import { ICreateCloudWallet, IStoredWalletDetails } from '@credebl/common/interfaces/cloud-wallet.interface';
import { IConfigureCloudBaseWalletPayload, IGetStoredWalletInfo } from '../interfaces/cloud-wallet.interface';
import { IAcceptProofRequest, IProofRequestRes, ICloudBaseWalletConfigure, ICreateCloudWallet, IGetProofPresentation, IGetProofPresentationById, IGetStoredWalletInfo, IStoredWalletDetails } from '@credebl/common/interfaces/cloud-wallet.interface';

@Controller()
export class CloudWalletController {
constructor(private readonly cloudWalletService: CloudWalletService) {}

@MessagePattern({ cmd: 'configure-cloud-base-wallet' })
async configureBaseWallet(payload: IConfigureCloudBaseWalletPayload): Promise<IGetStoredWalletInfo> {
return this.cloudWalletService.configureBaseWallet(payload.cloudBaseWalletConfigure, payload.user);
async configureBaseWallet(configureBaseWalletPayload: ICloudBaseWalletConfigure): Promise<IGetStoredWalletInfo> {
return this.cloudWalletService.configureBaseWallet(configureBaseWalletPayload);
}

@MessagePattern({ cmd: 'accept-proof-request-by-holder' })
async acceptProofRequest(acceptProofRequestPayload: IAcceptProofRequest): Promise<IProofRequestRes> {
return this.cloudWalletService.acceptProofRequest(acceptProofRequestPayload);
}

@MessagePattern({ cmd: 'get-proof-by-proof-id-holder' })
async getProofById(proofPrsentationByIdPayload: IGetProofPresentationById): Promise<IProofRequestRes> {
return this.cloudWalletService.getProofById(proofPrsentationByIdPayload);
}

@MessagePattern({ cmd: 'get-proof-presentation-holder' })
async getProofPresentation(proofPresentationPayload: IGetProofPresentation): Promise<IProofRequestRes[]> {
return this.cloudWalletService.getProofPresentation(proofPresentationPayload);
}

@MessagePattern({ cmd: 'create-cloud-wallet' })
Expand Down
Loading

0 comments on commit 1df5fb7

Please sign in to comment.