From fa98ef14171d420e57c7a189f40c481d456a0131 Mon Sep 17 00:00:00 2001 From: tipusinghaw <126460794+tipusinghaw@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:50:32 +0530 Subject: [PATCH] feat: Added basic message on cloud wallet (#868) * feat: creat cloud wallet Signed-off-by: tipusinghaw * fix: added error handling logic in common file Signed-off-by: tipusinghaw * fix: changed nkey veriable Signed-off-by: tipusinghaw * feat: creat DID for wallet Signed-off-by: tipusinghaw * resolve conflicts Signed-off-by: tipusinghaw * feat: credential APIs for cloud-wallet Signed-off-by: tipusinghaw * fix: changed create DID route Signed-off-by: tipusinghaw * fix: changed create DID route Signed-off-by: tipusinghaw * feat: added baisc message implementation in cloud wallet Signed-off-by: tipusinghaw --------- Signed-off-by: tipusinghaw Signed-off-by: KulkarniShashank --- .../cloud-wallet/cloud-wallet.controller.ts | 206 +++++++++++++----- .../src/cloud-wallet/cloud-wallet.service.ts | 19 +- .../src/cloud-wallet/dtos/cloudWallet.dto.ts | 56 ++++- .../dtos/configure-base-wallet.dto.ts | 4 +- .../src/cloud-wallet.controller.ts | 18 +- apps/cloud-wallet/src/cloud-wallet.service.ts | 97 ++++++++- libs/common/src/cast.helper.ts | 5 +- libs/common/src/common.constant.ts | 1 + .../src/interfaces/cloud-wallet.interface.ts | 23 ++ libs/common/src/response-messages/index.ts | 5 +- 10 files changed, 358 insertions(+), 76 deletions(-) diff --git a/apps/api-gateway/src/cloud-wallet/cloud-wallet.controller.ts b/apps/api-gateway/src/cloud-wallet/cloud-wallet.controller.ts index 1e1e07b06..449e746fa 100644 --- a/apps/api-gateway/src/cloud-wallet/cloud-wallet.controller.ts +++ b/apps/api-gateway/src/cloud-wallet/cloud-wallet.controller.ts @@ -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'; @@ -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'; @@ -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 { - 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 { + 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') @@ -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 { - 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 @@ -272,7 +249,6 @@ export class CloudWalletController { } - // This function will be used after multiple did method implementation in create wallet /** * Create did * @param orgId @@ -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( @@ -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 { + 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 @@ -376,6 +379,34 @@ 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 { + 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 @@ -383,7 +414,7 @@ export class CloudWalletController { * @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( @@ -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 { + 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 { + 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); + } + } diff --git a/apps/api-gateway/src/cloud-wallet/cloud-wallet.service.ts b/apps/api-gateway/src/cloud-wallet/cloud-wallet.service.ts index 7fbd20038..b7ada713f 100644 --- a/apps/api-gateway/src/cloud-wallet/cloud-wallet.service.ts +++ b/apps/api-gateway/src/cloud-wallet/cloud-wallet.service.ts @@ -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'; @@ -73,6 +73,11 @@ getconnectionById( ): Promise { return this.sendNatsMessage(this.cloudWalletServiceProxy, 'get-cloud-wallet-connection-by-id', connectionDetails); } +getAllconnectionById( + connectionDetails: GetAllCloudWalletConnections +): Promise { + return this.sendNatsMessage(this.cloudWalletServiceProxy, 'get-all-cloud-wallet-connections-list-by-id', connectionDetails); +} getCredentialList( tenantDetails: ITenantDetail @@ -85,4 +90,16 @@ getCredentialByCredentialRecordId( ): Promise { return this.sendNatsMessage(this.cloudWalletServiceProxy, 'wallet-credential-by-record-id', credentialDetails); } + +getBasicMessageByConnectionId( + connectionDetails: IBasicMessage +): Promise { + return this.sendNatsMessage(this.cloudWalletServiceProxy, 'basic-message-list-by-connection-id', connectionDetails); +} + +sendBasicMessage( + messageDetails: IBasicMessageDetails +): Promise { + return this.sendNatsMessage(this.cloudWalletServiceProxy, 'send-basic-message', messageDetails); +} } diff --git a/apps/api-gateway/src/cloud-wallet/dtos/cloudWallet.dto.ts b/apps/api-gateway/src/cloud-wallet/dtos/cloudWallet.dto.ts index 9dbd8345c..050eb587d 100644 --- a/apps/api-gateway/src/cloud-wallet/dtos/cloudWallet.dto.ts +++ b/apps/api-gateway/src/cloud-wallet/dtos/cloudWallet.dto.ts @@ -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'; @@ -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; @@ -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; } \ No newline at end of file diff --git a/apps/api-gateway/src/cloud-wallet/dtos/configure-base-wallet.dto.ts b/apps/api-gateway/src/cloud-wallet/dtos/configure-base-wallet.dto.ts index 47d89271b..7c14c928a 100644 --- a/apps/api-gateway/src/cloud-wallet/dtos/configure-base-wallet.dto.ts +++ b/apps/api-gateway/src/cloud-wallet/dtos/configure-base-wallet.dto.ts @@ -14,10 +14,10 @@ export class CloudBaseWalletConfigureDto { @IsNotEmpty({ message: 'please provide valid apiKey' }) apiKey: string; - @ApiProperty({ example: '0.0.0.0' }) + @ApiProperty({ example: 'http://0.0.0.0:4001' }) @IsString({ message: 'agentEndpoint must be a string' }) @IsNotEmpty({ message: 'please provide valid agentEndpoint' }) - @IsHostPortOrDomain({ message: 'agentEndpoint must be a valid host:port or domain' }) + @IsHostPortOrDomain({ message: 'Agent Endpoint must be a valid protocol://host:port or domain'}) agentEndpoint: string; userId: string; diff --git a/apps/cloud-wallet/src/cloud-wallet.controller.ts b/apps/cloud-wallet/src/cloud-wallet.controller.ts index b5a03d73c..842f422d4 100644 --- a/apps/cloud-wallet/src/cloud-wallet.controller.ts +++ b/apps/cloud-wallet/src/cloud-wallet.controller.ts @@ -2,7 +2,7 @@ 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 { IAcceptOffer, ICreateCloudWalletDid, IReceiveInvitation, IAcceptProofRequest, IProofRequestRes, ICloudBaseWalletConfigure, ICreateCloudWallet, IGetProofPresentation, IGetProofPresentationById, IGetStoredWalletInfo, IStoredWalletDetails, ICreateConnection, IConnectionInvitationResponse, IWalletDetailsForDidList, IConnectionDetailsById, ITenantDetail, ICredentialDetails } from '@credebl/common/interfaces/cloud-wallet.interface'; +import { IAcceptOffer, ICreateCloudWalletDid, IReceiveInvitation, IAcceptProofRequest, IProofRequestRes, ICloudBaseWalletConfigure, ICreateCloudWallet, IGetProofPresentation, IGetProofPresentationById, IGetStoredWalletInfo, IStoredWalletDetails, ICreateConnection, IConnectionInvitationResponse, IWalletDetailsForDidList, IConnectionDetailsById, ITenantDetail, ICredentialDetails, GetAllCloudWalletConnections, IBasicMessage, IBasicMessageDetails } from '@credebl/common/interfaces/cloud-wallet.interface'; @Controller() export class CloudWalletController { @@ -63,6 +63,12 @@ export class CloudWalletController { return this.cloudWalletService.getconnectionById(connectionDetails); } + + @MessagePattern({ cmd: 'get-all-cloud-wallet-connections-list-by-id' }) + async getAllconnectionById(connectionDetails: GetAllCloudWalletConnections): Promise { + return this.cloudWalletService.getAllconnectionById(connectionDetails); + } + @MessagePattern({ cmd: 'wallet-credential-by-id' }) async getCredentialList(tenantDetails: ITenantDetail): Promise { return this.cloudWalletService.getCredentialListById(tenantDetails); @@ -72,5 +78,15 @@ export class CloudWalletController { async getCredentialByCredentialRecordId(credentialDetails: ICredentialDetails): Promise { return this.cloudWalletService.getCredentialByRecord(credentialDetails); } + + @MessagePattern({ cmd: 'basic-message-list-by-connection-id' }) + async getBasicMessageByConnectionId(connectionDetails: IBasicMessage): Promise { + return this.cloudWalletService.getBasicMessageByConnectionId(connectionDetails); + } + + @MessagePattern({ cmd: 'send-basic-message' }) + async sendBasicMessage(messageDetails: IBasicMessageDetails): Promise { + return this.cloudWalletService.sendBasicMessage(messageDetails); + } } \ No newline at end of file diff --git a/apps/cloud-wallet/src/cloud-wallet.service.ts b/apps/cloud-wallet/src/cloud-wallet.service.ts index 2590d92fc..5dcd378c1 100644 --- a/apps/cloud-wallet/src/cloud-wallet.service.ts +++ b/apps/cloud-wallet/src/cloud-wallet.service.ts @@ -32,7 +32,10 @@ import { ITenantDetail, ICredentialDetails, ICreateConnection, - IConnectionInvitationResponse + IConnectionInvitationResponse, + GetAllCloudWalletConnections, + IBasicMessage, + IBasicMessageDetails } from '@credebl/common/interfaces/cloud-wallet.interface'; import { CloudWalletRepository } from './cloud-wallet.repository'; import { ResponseMessages } from '@credebl/common/response-messages'; @@ -105,6 +108,8 @@ export class CloudWalletService { const { userId, ...connectionPayload } = createConnection; const [baseWalletDetails, getTenant, decryptedApiKey] = await this._commonCloudWalletInfo(userId); + delete connectionPayload.email; + const { tenantId } = getTenant; const { agentEndpoint } = baseWalletDetails; @@ -218,8 +223,8 @@ export class CloudWalletService { } const getTenant = await this.cloudWalletRepository.getCloudSubWallet(userId); - - if (!getTenant) { + + if (!getTenant || !getTenant?.tenantId) { throw new NotFoundException(ResponseMessages.cloudWallet.error.walletRecordNotFound); } @@ -248,11 +253,12 @@ export class CloudWalletService { if (checkUserExist) { throw new ConflictException(ResponseMessages.cloudWallet.error.userExist); } - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const [baseWalletDetails, getTenant, decryptedApiKey] = await this._commonCloudWalletInfo(userId); + + const baseWalletDetails = await this.cloudWalletRepository.getCloudWalletDetails(CloudWalletType.BASE_WALLET); const { agentEndpoint, agentApiKey } = baseWalletDetails; const url = `${agentEndpoint}${CommonConstants.URL_SHAGENT_CREATE_TENANT}`; + const decryptedApiKey = await this.commonService.decryptPassword(agentApiKey); const checkCloudWalletAgentHealth = await this.commonService.checkAgentHealth(agentEndpoint, decryptedApiKey); @@ -448,7 +454,7 @@ export class CloudWalletService { const { tenantId } = getTenant; const { agentEndpoint } = baseWalletDetails; - const url = `${agentEndpoint}${CommonConstants.CLOUD_WALLET_DID_LIST}/${tenantId}}`; + const url = `${agentEndpoint}${CommonConstants.CLOUD_WALLET_DID_LIST}${tenantId}`; const didList = await this.commonService.httpGet(url, { headers: { authorization: decryptedApiKey } }); return didList; @@ -471,7 +477,7 @@ export class CloudWalletService { const { tenantId } = getTenant; const { agentEndpoint } = baseWalletDetails; - const url = `${agentEndpoint}${CommonConstants.CLOUD_WALLET_CONNECTION_BY_ID}/${tenantId}}/${connectionId}`; + const url = `${agentEndpoint}${CommonConstants.CLOUD_WALLET_CONNECTION_BY_ID}${connectionId}/${tenantId}`; const connectionDetailResponse = await this.commonService.httpGet(url, { headers: { authorization: decryptedApiKey } }); return connectionDetailResponse; @@ -481,6 +487,36 @@ export class CloudWalletService { } } + /** + * Get connection list by tenant id + * @param connectionDetails + * @returns Connection Details + */ + async getAllconnectionById(connectionDetails: GetAllCloudWalletConnections): Promise { + try { + const { userId, alias, myDid, outOfBandId, theirDid, theirLabel } = connectionDetails; + const [baseWalletDetails, getTenant, decryptedApiKey] = await this._commonCloudWalletInfo(userId); + const urlOptions = { + alias, + myDid, + outOfBandId, + theirDid, + theirLabel + }; + const optionalParameter = await this.commonService.createDynamicUrl(urlOptions); + const { tenantId } = getTenant; + const { agentEndpoint } = baseWalletDetails; + + const url = `${agentEndpoint}${CommonConstants.CLOUD_WALLET_CONNECTION_BY_ID}${tenantId}${optionalParameter}`; + + const connectionDetailList = await this.commonService.httpGet(url, { headers: { authorization: decryptedApiKey } }); + return connectionDetailList; + } catch (error) { + await this.commonService.handleError(error); + throw error; + } + } + /** * Get credential list by tenant id * @param tenantDetails @@ -532,4 +568,51 @@ export class CloudWalletService { throw error; } } + + /** + * Get basic-message by connection id + * @param connectionDetails + * @returns Basic message Details + */ + async getBasicMessageByConnectionId(connectionDetails: IBasicMessage): Promise { + try { + const { userId, connectionId } = connectionDetails; + const [baseWalletDetails, getTenant, decryptedApiKey] = await this._commonCloudWalletInfo(userId); + + const {tenantId} = getTenant; + const { agentEndpoint } = baseWalletDetails; + + const url = `${agentEndpoint}${CommonConstants.CLOUD_WALLET_BASIC_MESSAGE}${connectionId}/${tenantId}`; + + const basicMessageResponse = await this.commonService.httpGet(url, { headers: { authorization: decryptedApiKey } }); + return basicMessageResponse; + } catch (error) { + await this.commonService.handleError(error); + throw error; + } + } + + /** + * Send basic-message by connection id + * @param messageDetails + * @returns Basic message Details + */ + async sendBasicMessage(messageDetails: IBasicMessageDetails): Promise { + try { + const { userId, connectionId, content } = messageDetails; + const [baseWalletDetails, getTenant, decryptedApiKey] = await this._commonCloudWalletInfo(userId); + + const {tenantId} = getTenant; + const { agentEndpoint } = baseWalletDetails; + + const url = `${agentEndpoint}${CommonConstants.CLOUD_WALLET_BASIC_MESSAGE}${connectionId}/${tenantId}`; + const basicMessageResponse = await this.commonService.httpPost(url, {content}, { + headers: { authorization: decryptedApiKey } + }); + return basicMessageResponse; + } catch (error) { + await this.commonService.handleError(error); + throw error; + } + } } diff --git a/libs/common/src/cast.helper.ts b/libs/common/src/cast.helper.ts index 1d30bd422..4bd45e760 100644 --- a/libs/common/src/cast.helper.ts +++ b/libs/common/src/cast.helper.ts @@ -332,9 +332,8 @@ export const createOobJsonldIssuancePayload = (JsonldCredentialDetails: IJsonldC export class IsHostPortOrDomainConstraint implements ValidatorConstraintInterface { validate(value: string): boolean { // Regular expression for validating URL with host:port or domain - const hostPortRegex = - /^(http:\/\/|https:\/\/)?(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)):(?:\d{1,5})$/; - const domainRegex = /^(http:\/\/|https:\/\/)?(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/; + const hostPortRegex = /^(http:\/\/|https:\/\/)?(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)):(?:\d{1,5})(\/[^\s]*)?$/; + const domainRegex = /^(http:\/\/|https:\/\/)?(?:localhost|(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,})(:\d{1,5})?(\/[^\s]*)?$/; return hostPortRegex.test(value) || domainRegex.test(value); } diff --git a/libs/common/src/common.constant.ts b/libs/common/src/common.constant.ts index 330f4952f..a18b5b7ae 100644 --- a/libs/common/src/common.constant.ts +++ b/libs/common/src/common.constant.ts @@ -336,6 +336,7 @@ CLOUD_WALLET_ACCEPT_PROOF_REQUEST = '/accept-request/', CLOUD_WALLET_DID_LIST = '/multi-tenancy/dids/', CLOUD_WALLET_CONNECTION_BY_ID = '/multi-tenancy/connections/', CLOUD_WALLET_CREDENTIAL = '/multi-tenancy/credentials', +CLOUD_WALLET_BASIC_MESSAGE = '/multi-tenancy/basic-messages/', // Bulk-issuance BATCH_SIZE = 100, diff --git a/libs/common/src/interfaces/cloud-wallet.interface.ts b/libs/common/src/interfaces/cloud-wallet.interface.ts index 7ab89fad6..bd3a496ff 100644 --- a/libs/common/src/interfaces/cloud-wallet.interface.ts +++ b/libs/common/src/interfaces/cloud-wallet.interface.ts @@ -307,3 +307,26 @@ export interface IConnectionInvitationResponse { outOfBandRecord: OutOfBandRecord; invitationDid: string; } + +export interface GetAllCloudWalletConnections { + outOfBandId?: string; + alias?: string; + myDid?: string; + theirDid?: string; + theirLabel?: string; + email?: string; + userId?: string; +} + +export interface IBasicMessage { + userId: string; + email: string; + connectionId: string; +} + +export interface IBasicMessageDetails { + userId?: string; + email?: string; + content: string; + connectionId: string +} diff --git a/libs/common/src/response-messages/index.ts b/libs/common/src/response-messages/index.ts index c27f28556..38beeb111 100644 --- a/libs/common/src/response-messages/index.ts +++ b/libs/common/src/response-messages/index.ts @@ -558,12 +558,15 @@ export const ResponseMessages = { configureBaseWallet: 'Successfully configure the base wallet.', acceptProofRequest: 'Proof request has been successfully accepted.', createConnection: 'Connection created successfully.', + basicMessage: 'Basic message send successfully', getProofById: 'Proof presentation has been successfully received.', getProofPresentation: 'Proof presentations has been successfully received.', didList: 'DID list fetched sucessfully', connectionById: 'Connection record fetched successfully', credentials: 'Credentials fetched successfully', - creddentialByRecordId: 'Credential fetched successfully' + credentialByRecordId: 'Credential fetched successfully', + connectionList: 'Connection list fetched successfully', + basicMessageByConnectionId: 'Basic message fetched successfully' }, error: { baseWalletNotFound: 'Base wallet configuration not found',