Skip to content

Commit

Permalink
feat: Added basic message on cloud wallet (#868)
Browse files Browse the repository at this point in the history
* feat: creat cloud wallet

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

* fix: added error handling logic in common file

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

* fix: changed nkey veriable

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

* feat: creat DID for wallet

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

* resolve conflicts

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

* feat: credential APIs for cloud-wallet

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

* fix: changed create DID route

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

* fix: changed create DID route

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

* feat: added baisc message implementation in cloud wallet

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

---------

Signed-off-by: tipusinghaw <[email protected]>
  • Loading branch information
tipusinghaw authored and KulkarniShashank committed Sep 6, 2024
1 parent 0260440 commit c5872db
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 75 deletions.
206 changes: 149 additions & 57 deletions apps/api-gateway/src/cloud-wallet/cloud-wallet.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ApiBearerAuth, ApiForbiddenResponse, ApiOperation, ApiQuery, ApiRespons
import { ForbiddenErrorDto } from '../dtos/forbidden-error.dto';
import { UnauthorizedErrorDto } from '../dtos/unauthorized-error.dto';
import { CloudWalletService } from './cloud-wallet.service';
import { AcceptOfferDto, CreateCloudWalletDidDto, CreateCloudWalletDto, CredentialListDto, ReceiveInvitationUrlDTO } from './dtos/cloudWallet.dto';
import { AcceptOfferDto, BasicMessageDTO, CreateCloudWalletDidDto, CreateCloudWalletDto, CredentialListDto, GetAllCloudWalletConnectionsDto, ReceiveInvitationUrlDTO } from './dtos/cloudWallet.dto';
import { Response } from 'express';
import { CustomExceptionFilter } from 'apps/api-gateway/common/exception-handler';
import { ApiResponseDto } from '../dtos/apiResponse.dto';
Expand All @@ -18,7 +18,7 @@ import { validateDid } from '@credebl/common/did.validator';
import { CommonConstants } from '@credebl/common/common.constant';
import { UserRoleGuard } from '../authz/guards/user-role.guard';
import { AcceptProofRequestDto } from './dtos/accept-proof-request.dto';
import { IConnectionDetailsById, ICredentialDetails, IGetProofPresentation, IGetProofPresentationById, IWalletDetailsForDidList } from '@credebl/common/interfaces/cloud-wallet.interface';
import { IBasicMessage, IConnectionDetailsById, ICredentialDetails, IGetProofPresentation, IGetProofPresentationById, IWalletDetailsForDidList } from '@credebl/common/interfaces/cloud-wallet.interface';
import { CreateConnectionDto } from './dtos/create-connection.dto';


Expand Down Expand Up @@ -65,33 +65,39 @@ export class CloudWalletController {
return res.status(HttpStatus.CREATED).json(finalResponse);
}

@Post('/connections/invitation')
@ApiOperation({ summary: 'Create connection invitation', description: 'Create connection invitation' })
@ApiResponse({ status: HttpStatus.CREATED, description: 'Created', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
async createConnection(
@Res() res: Response,
@Body() createConnection: CreateConnectionDto,
@User() user: user
): Promise<Response> {
const { id, email } = user;
createConnection.userId = id;
createConnection.email = email;
/**
* Create cloud wallet
* @param cloudWalletDetails
* @param res
* @returns Sucess message and wallet details
*/
@Post('/create-wallet')
@ApiOperation({ summary: 'Create cloud wallet', description: 'Create cloud wallet' })
@ApiResponse({ status: HttpStatus.CREATED, description: 'Created', type: ApiResponseDto })
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
async createCloudWallet(
@Res() res: Response,
@Body() cloudWalletDetails: CreateCloudWalletDto,
@User() user: user
): Promise<Response> {
const {email, id} = user;
cloudWalletDetails.email = email;
cloudWalletDetails.userId = id;
const cloudWalletData = await this.cloudWalletService.createCloudWallet(cloudWalletDetails);
const finalResponse: IResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.cloudWallet.success.create,
data: cloudWalletData
};
return res.status(HttpStatus.CREATED).json(finalResponse);

}

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

/**
* Accept proof request
* @param acceptProofRequest
* @param user
* @param res
* @returns sucess message
*/
@Post('/proofs/accept-request')
Expand Down Expand Up @@ -185,35 +191,6 @@ export class CloudWalletController {
return res.status(HttpStatus.OK).json(finalResponse);
}

/**
* Create cloud wallet
* @param cloudWalletDetails
* @param res
* @returns Sucess message and wallet details
*/
@Post('/create-wallet')
@ApiOperation({ summary: 'Create cloud wallet', description: 'Create cloud wallet' })
@ApiResponse({ status: HttpStatus.CREATED, description: 'Created', type: ApiResponseDto })
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
async createCloudWallet(
@Res() res: Response,
@Body() cloudWalletDetails: CreateCloudWalletDto,
@User() user: user
): Promise<Response> {
const {email, id} = user;
cloudWalletDetails.email = email;
cloudWalletDetails.userId = id;
const cloudWalletData = await this.cloudWalletService.createCloudWallet(cloudWalletDetails);
const finalResponse: IResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.cloudWallet.success.create,
data: cloudWalletData
};
return res.status(HttpStatus.CREATED).json(finalResponse);

}

/**
* Receive invitation by URL
* @param receiveInvitation
Expand Down Expand Up @@ -272,7 +249,6 @@ export class CloudWalletController {

}

// This function will be used after multiple did method implementation in create wallet
/**
* Create did
* @param orgId
Expand Down Expand Up @@ -320,7 +296,7 @@ export class CloudWalletController {
* @returns DID list
*/
@Get('/did')
@ApiOperation({ summary: 'Get DID list by tenant Id', description: 'Get DID list by tenant Id' })
@ApiOperation({ summary: 'Get DID list from wallet', description: 'Get DID list from wallet' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
async getDidList(
Expand All @@ -343,6 +319,33 @@ export class CloudWalletController {
return res.status(HttpStatus.OK).json(finalResponse);
}

/**
* Accept proof request
* @param CreateConnectionDto
* @returns sucess message
*/
@Post('/connections/invitation')
@ApiOperation({ summary: 'Create connection invitation for cloud wallet', description: 'Create connection invitation' })
@ApiResponse({ status: HttpStatus.CREATED, description: 'Created', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
async createConnection(
@Res() res: Response,
@Body() createConnection: CreateConnectionDto,
@User() user: user
): Promise<Response> {
const { id, email } = user;
createConnection.userId = id;
createConnection.email = email;

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

/**
* Get connection list by tenant id and connection id
* @param tenantId
Expand Down Expand Up @@ -376,14 +379,42 @@ export class CloudWalletController {
return res.status(HttpStatus.OK).json(finalResponse);
}

/**
* Get connection list by tenant id
* @param res
* @returns DID list
*/
@Get('/connections')
@ApiOperation({ summary: 'Get all wallet connections', description: 'Get all wallet connections' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
async getAllconnectionById(
@Query() connectionListQueryOptions: GetAllCloudWalletConnectionsDto,
@Res() res: Response,
@User() user: user
): Promise<Response> {
const { id, email } = user;

connectionListQueryOptions.userId = id;
connectionListQueryOptions.email = email;

const connectionDetailResponse = await this.cloudWalletService.getAllconnectionById(connectionListQueryOptions);
const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
message: ResponseMessages.cloudWallet.success.connectionList,
data: connectionDetailResponse
};
return res.status(HttpStatus.OK).json(finalResponse);
}

/**
* Get credential list by tenant id
* @param credentialListQueryOptions
* @param res
* @returns Credential list
*/
@Get('/credential')
@ApiOperation({ summary: 'Get credential list by tenant Id', description: 'Get credential list by tenant Id' })
@ApiOperation({ summary: 'Get credential list from cloud wallet', description: 'Get credential list from cloud wallet' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
async getCredentialList(
Expand Down Expand Up @@ -431,10 +462,71 @@ export class CloudWalletController {
const connectionDetailResponse = await this.cloudWalletService.getCredentialByCredentialRecordId(credentialDetails);
const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
message: ResponseMessages.cloudWallet.success.creddentialByRecordId,
message: ResponseMessages.cloudWallet.success.credentialByRecordId,
data: connectionDetailResponse
};
return res.status(HttpStatus.OK).json(finalResponse);
}

/**
* Get basic-message by connection id
* @param connectionId
* @param res
* @returns Credential list
*/
@Get('/basic-message/:connectionId')
@ApiOperation({ summary: 'Get basic message by connection id', description: 'Get basic message by connection id' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
async getBasicMessageByConnectionId(
@Param('connectionId') connectionId: string,
@Res() res: Response,
@User() user: user
): Promise<Response> {
const { id, email } = user;

const connectionDetails: IBasicMessage = {
userId: id,
email,
connectionId
};

const basicMessageDetailResponse = await this.cloudWalletService.getBasicMessageByConnectionId(connectionDetails);
const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
message: ResponseMessages.cloudWallet.success.basicMessageByConnectionId,
data: basicMessageDetailResponse
};
return res.status(HttpStatus.OK).json(finalResponse);
}

/**
* Get basic-message by connection id
* @param credentialListQueryOptions
* @param res
* @returns Credential list
*/
@Post('/basic-message/:connectionId')
@ApiOperation({ summary: 'Send basic message', description: 'Send basic message' })
@ApiResponse({ status: HttpStatus.CREATED, description: 'Created', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
async sendBasicMessage(
@Param('connectionId') connectionId: string,
@Res() res: Response,
@Body() messageDetails: BasicMessageDTO,
@User() user: user
): Promise<Response> {
const { id, email } = user;
messageDetails.userId = id;
messageDetails.email = email;
messageDetails.connectionId = connectionId;
const basicMessageDetails = await this.cloudWalletService.sendBasicMessage(messageDetails);
const finalResponse: IResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.cloudWallet.success.basicMessage,
data: basicMessageDetails
};
return res.status(HttpStatus.CREATED).json(finalResponse);
}

}
19 changes: 18 additions & 1 deletion apps/api-gateway/src/cloud-wallet/cloud-wallet.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { IAcceptOffer, ICreateCloudWallet, ICreateCloudWalletDid, IReceiveInvitation, IAcceptProofRequest, IProofRequestRes, ICloudBaseWalletConfigure, IGetProofPresentation, IGetProofPresentationById, IGetStoredWalletInfo, IStoredWalletDetails, IWalletDetailsForDidList, IConnectionDetailsById, ITenantDetail, ICredentialDetails, ICreateConnection, IConnectionInvitationResponse } from '@credebl/common/interfaces/cloud-wallet.interface';
import { IAcceptOffer, ICreateCloudWallet, ICreateCloudWalletDid, IReceiveInvitation, IAcceptProofRequest, IProofRequestRes, ICloudBaseWalletConfigure, IGetProofPresentation, IGetProofPresentationById, IGetStoredWalletInfo, IStoredWalletDetails, IWalletDetailsForDidList, IConnectionDetailsById, ITenantDetail, ICredentialDetails, ICreateConnection, IConnectionInvitationResponse, GetAllCloudWalletConnections, IBasicMessage, IBasicMessageDetails } 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';
Expand Down Expand Up @@ -73,6 +73,11 @@ getconnectionById(
): Promise<Response> {
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'get-cloud-wallet-connection-by-id', connectionDetails);
}
getAllconnectionById(
connectionDetails: GetAllCloudWalletConnections
): Promise<Response> {
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'get-all-cloud-wallet-connections-list-by-id', connectionDetails);
}

getCredentialList(
tenantDetails: ITenantDetail
Expand All @@ -85,4 +90,16 @@ getCredentialByCredentialRecordId(
): Promise<Response> {
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'wallet-credential-by-record-id', credentialDetails);
}

getBasicMessageByConnectionId(
connectionDetails: IBasicMessage
): Promise<Response> {
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'basic-message-list-by-connection-id', connectionDetails);
}

sendBasicMessage(
messageDetails: IBasicMessageDetails
): Promise<Response> {
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'send-basic-message', messageDetails);
}
}
56 changes: 52 additions & 4 deletions apps/api-gateway/src/cloud-wallet/dtos/cloudWallet.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsBoolean, IsInt, IsNotEmpty, IsObject, IsOptional, IsString, Matches, MaxLength } from 'class-validator';
import { IsBoolean, IsInt, IsNotEmpty, IsOptional, IsString, Matches, MaxLength } from 'class-validator';

import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsNotSQLInjection, trim } from '@credebl/common/cast.helper';
Expand Down Expand Up @@ -112,9 +112,7 @@ export class ReceiveInvitationUrlDTO {
@IsString({ message: 'credentialRecordId must be a string' })
credentialRecordId: string;

@ApiPropertyOptional({ type: Object, description: 'Credential formats' })
@Transform(({ value }) => trim(value))
@IsObject({ message: 'credentialFormats must be an object' })
@ApiProperty({ type: Object, description: 'Credential formats' })
credentialFormats: object;

email?: string;
Expand Down Expand Up @@ -215,4 +213,54 @@ export class CredentialListDto {
email?: string;

userId?: string;
}

export class GetAllCloudWalletConnectionsDto {
@ApiProperty({ required: false, example: 'e315f30d-9beb-4068-aea4-abb5fe5eecb1' })
@IsNotEmpty()
@IsString()
@IsOptional()
outOfBandId: string;

@ApiProperty({ required: false, example: 'Test' })
@IsNotEmpty()
@IsString()
@IsOptional()
alias: string;

@ApiProperty({ required: false, example: 'did:example:e315f30d-9beb-4068-aea4-abb5fe5eecb1' })
@IsNotEmpty()
@IsString()
@IsOptional()
myDid: string;

@ApiProperty({ required: false, example: 'did:example:e315f30d-9beb-4068-aea4-abb5fe5eecb1' })
@IsNotEmpty()
@IsString()
@IsOptional()
theirDid: string;

@ApiProperty({ required: false, example: 'Bob' })
@IsNotEmpty()
@IsString()
@IsOptional()
theirLabel: string;

email?: string;

userId?: string;
}

export class BasicMessageDTO {
@ApiProperty({ example: 'Message'})
@IsNotEmpty({ message: 'content is required' })
@Transform(({ value }) => trim(value))
@IsString({ message: 'content should be in string format.' })
content: string;

email?: string;

userId?: string;

connectionId: string;
}
Loading

0 comments on commit c5872db

Please sign in to comment.