Skip to content

Commit

Permalink
feat: implement credential APIs for cloud wallet (#865)
Browse files Browse the repository at this point in the history
* feat: creat cloud wallet

Signed-off-by: tipusinghaw <tipu.singh@ayanworks.com>

* fix: added error handling logic in common file

Signed-off-by: tipusinghaw <tipu.singh@ayanworks.com>

* fix: changed nkey veriable

Signed-off-by: tipusinghaw <tipu.singh@ayanworks.com>

* feat: creat DID for wallet

Signed-off-by: tipusinghaw <tipu.singh@ayanworks.com>

* resolve conflicts

Signed-off-by: tipusinghaw <tipu.singh@ayanworks.com>

* feat: credential APIs for cloud-wallet

Signed-off-by: tipusinghaw <tipu.singh@ayanworks.com>

* fix: changed create DID route

Signed-off-by: tipusinghaw <tipu.singh@ayanworks.com>

* fix: changed create DID route

Signed-off-by: tipusinghaw <tipu.singh@ayanworks.com>

---------

Signed-off-by: tipusinghaw <tipu.singh@ayanworks.com>
  • Loading branch information
tipusinghaw authored Jul 22, 2024
1 parent 0122f6f commit 92bd967
Show file tree
Hide file tree
Showing 10 changed files with 396 additions and 21 deletions.
131 changes: 128 additions & 3 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, ReceiveInvitationUrlDTO } from './dtos/cloudWallet.dto';
import { AcceptOfferDto, CreateCloudWalletDidDto, CreateCloudWalletDto, CredentialListDto, 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 { IGetProofPresentation, IGetProofPresentationById } from '@credebl/common/interfaces/cloud-wallet.interface';
import { IConnectionDetailsById, ICredentialDetails, IGetProofPresentation, IGetProofPresentationById, IWalletDetailsForDidList } from '@credebl/common/interfaces/cloud-wallet.interface';
import { CreateConnectionDto } from './dtos/create-connection.dto';


Expand Down Expand Up @@ -278,7 +278,7 @@ export class CloudWalletController {
* @param orgId
* @returns did
*/
@Post('/create-did')
@Post('/did')
@ApiOperation({
summary: 'Create new did',
description: 'Create new did for cloud wallet'
Expand Down Expand Up @@ -312,4 +312,129 @@ export class CloudWalletController {

return res.status(HttpStatus.CREATED).json(finalResponse);
}

/**
* Get DID list by tenant id
* @param tenantId
* @param res
* @returns DID list
*/
@Get('/did')
@ApiOperation({ summary: 'Get DID list by tenant Id', description: 'Get DID list by tenant Id' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
async getDidList(
@Res() res: Response,
@User() user: user
): Promise<Response> {
const { id, email } = user;

const walletDetails: IWalletDetailsForDidList = {
userId: id,
email
};

const didListDetails = await this.cloudWalletService.getDidList(walletDetails);
const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
message: ResponseMessages.cloudWallet.success.didList,
data: didListDetails
};
return res.status(HttpStatus.OK).json(finalResponse);
}

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

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

const connectionDetailResponse = await this.cloudWalletService.getconnectionById(connectionDetails);
const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
message: ResponseMessages.cloudWallet.success.connectionById,
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' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
async getCredentialList(
@Query() credentialListQueryOptions: CredentialListDto,
@Res() res: Response,
@User() user: user
): Promise<Response> {
const { id, email } = user;

credentialListQueryOptions.userId = id;
credentialListQueryOptions.email = email;

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

/**
* Get credential list by tenant id
* @param credentialListQueryOptions
* @param res
* @returns Credential list
*/
@Get('/credential/:credentialRecordId')
@ApiOperation({ summary: 'Get credential by credential record Id', description: 'Get credential by credential record Id' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), UserRoleGuard)
async getCredentialByCredentialRecordId(
@Param('credentialRecordId') credentialRecordId: string,
@Res() res: Response,
@User() user: user
): Promise<Response> {
const { id, email } = user;

const credentialDetails: ICredentialDetails = {
userId: id,
email,
credentialRecordId
};

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

}
25 changes: 24 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, 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 } 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 @@ -62,4 +62,27 @@ export class CloudWalletService extends BaseService {
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'create-cloud-wallet-did', createDidDetails);
}

getDidList(
walletDetails: IWalletDetailsForDidList
): Promise<IProofRequestRes[]> {
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'cloud-wallet-did-list', walletDetails);
}

getconnectionById(
connectionDetails: IConnectionDetailsById
): Promise<Response> {
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'get-cloud-wallet-connection-by-id', connectionDetails);
}

getCredentialList(
tenantDetails: ITenantDetail
): Promise<Response> {
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'wallet-credential-by-id', tenantDetails);
}

getCredentialByCredentialRecordId(
credentialDetails: ICredentialDetails
): Promise<Response> {
return this.sendNatsMessage(this.cloudWalletServiceProxy, 'wallet-credential-by-record-id', credentialDetails);
}
}
43 changes: 31 additions & 12 deletions apps/api-gateway/src/cloud-wallet/dtos/cloudWallet.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class ReceiveInvitationUrlDTO {

export class CreateCloudWalletDidDto {

@ApiProperty({ example: '000000000000000000000000000Seed2' })
@ApiProperty({ example: '000000000000000000000000000Seed1' })
@MaxLength(32, { message: 'seed must be at most 32 characters.' })
@Transform(({ value }) => trim(value))
@IsOptional()
Expand All @@ -141,19 +141,19 @@ export class ReceiveInvitationUrlDTO {
@IsString({ message: 'key type be in string format.' })
keyType: string;

@ApiProperty({ example: 'polygon'})
@ApiProperty({ example: 'indy'})
@IsNotEmpty({ message: 'method is required' })
@Transform(({ value }) => trim(value))
@IsString({ message: 'method must be in string format.' })
method: string;

@ApiPropertyOptional({example: 'indicio:testnet'})
@ApiPropertyOptional({example: 'bcovrin:testnet'})
@IsOptional()
@Transform(({ value }) => trim(value))
@IsString({ message: 'network must be in string format.' })
network?: string;

@ApiPropertyOptional({example: 'www.google.com'})
@ApiPropertyOptional({example: 'www.github.com'})
@IsOptional()
@Transform(({ value }) => trim(value))
@IsString({ message: 'domain must be in string format.' })
Expand All @@ -171,7 +171,7 @@ export class ReceiveInvitationUrlDTO {
@Transform(({ value }) => trim(value))
privatekey?: string;

@ApiPropertyOptional({example: 'http://localhost:4006/docs'})
@ApiPropertyOptional({example: 'http://localhost:6006/docs'})
@IsOptional()
@IsString({ message: 'endpoint must be in string format.' })
endpoint?: string;
Expand All @@ -182,18 +182,37 @@ export class ReceiveInvitationUrlDTO {
@IsString({ message: 'did must be in string format.' })
did?: string;

@ApiPropertyOptional({example: 'did:indy:indicio:testnet:UEeW111G1tYo1nEkPwMef'})
@ApiPropertyOptional({example: 'did:indy:bcovrin:testnet:UEeW111G1tYo1nEkPwMcF'})
@IsOptional()
@Transform(({ value }) => trim(value))
@IsString({ message: 'endorser did must be in string format.' })
endorserDid?: string;

@ApiProperty({example: false})
@ApiPropertyOptional()
@IsBoolean({ message: 'isPrimaryDid did must be true or false.' })
isPrimaryDid: boolean = false;
endorserDid?: string;

email?: string;

userId?: string;
}

export class CredentialListDto {
@ApiProperty({ required: false})
@IsNotEmpty()
@IsOptional()
@IsString()
threadId: string;

@ApiProperty({ required: false})
@IsNotEmpty()
@IsOptional()
@IsString()
connectionId: string;

@ApiProperty({ required: false})
@IsNotEmpty()
@IsOptional()
@IsString()
state: string;

email?: string;

userId?: string;
}
23 changes: 22 additions & 1 deletion apps/cloud-wallet/src/cloud-wallet.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } 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 } from '@credebl/common/interfaces/cloud-wallet.interface';

@Controller()
export class CloudWalletController {
Expand Down Expand Up @@ -52,4 +52,25 @@ export class CloudWalletController {
async createDid(createDidDetails: ICreateCloudWalletDid): Promise<Response> {
return this.cloudWalletService.createDid(createDidDetails);
}

@MessagePattern({ cmd: 'cloud-wallet-did-list' })
async getDidList(walletDetails: IWalletDetailsForDidList): Promise<Response> {
return this.cloudWalletService.getDidList(walletDetails);
}

@MessagePattern({ cmd: 'get-cloud-wallet-connection-by-id' })
async getconnectionById(connectionDetails: IConnectionDetailsById): Promise<Response> {
return this.cloudWalletService.getconnectionById(connectionDetails);
}

@MessagePattern({ cmd: 'wallet-credential-by-id' })
async getCredentialList(tenantDetails: ITenantDetail): Promise<Response> {
return this.cloudWalletService.getCredentialListById(tenantDetails);
}

@MessagePattern({ cmd: 'wallet-credential-by-record-id' })
async getCredentialByCredentialRecordId(credentialDetails: ICredentialDetails): Promise<Response> {
return this.cloudWalletService.getCredentialByRecord(credentialDetails);
}

}
Loading

0 comments on commit 92bd967

Please sign in to comment.