Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 21 additions & 54 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ import {
IDidCreate,
IWallet,
ITenantRecord,
LedgerListResponse,
ICreateConnectionInvitation,
IStoreAgent,
AgentHealthData,
IAgentStore,
IAgentConfigure,
OrgDid,
IBasicMessage,
WalletDetails
WalletDetails,
ILedger,
IStoreOrgAgent
} from './interface/agent-service.interface';
import { AgentSpinUpStatus, AgentType, DidMethod, Ledgers, OrgAgentType, PromiseResult } from '@credebl/enum/enum';
import { AgentServiceRepository } from './repositories/agent-service.repository';
Expand Down Expand Up @@ -497,8 +498,8 @@ export class AgentServiceService {
if (agentSpinupDto.method !== DidMethod.KEY && agentSpinupDto.method !== DidMethod.WEB) {
const { network } = agentSpinupDto;
const ledger = await ledgerName(network);
const ledgerList = (await this._getALlLedgerDetails()) as unknown as LedgerListResponse;
const isLedgerExist = ledgerList.response.find((existingLedgers) => existingLedgers.name === ledger);
const ledgerList = await this._getALlLedgerDetails();
const isLedgerExist = ledgerList.find((existingLedgers) => existingLedgers.name === ledger);
if (!isLedgerExist) {
throw new BadRequestException(ResponseMessages.agent.error.invalidLedger, {
cause: new Error(),
Expand All @@ -511,15 +512,14 @@ export class AgentServiceService {
/**
* Invoke wallet create and provision with agent
*/
const walletProvision = await this._walletProvision(walletProvisionPayload);
if (!walletProvision?.response) {
const agentDetails = await this._walletProvision(walletProvisionPayload);
if (!agentDetails) {
this.logger.error(`Agent not able to spin-up`);
throw new BadRequestException(ResponseMessages.agent.error.notAbleToSpinup, {
cause: new Error(),
description: ResponseMessages.errorMessages.badRequest
});
}
const agentDetails = walletProvision.response;
const agentEndPoint = `${process.env.API_GATEWAY_PROTOCOL}://${agentDetails.agentEndPoint}`;
/**
* Socket connection
Expand Down Expand Up @@ -693,48 +693,41 @@ export class AgentServiceService {
}
}

async _createConnectionInvitation(
orgId: string,
user: IUserRequestInterface,
label: string
): Promise<{
response;
}> {
async _createConnectionInvitation(orgId: string, user: IUserRequestInterface, label: string): Promise<object> {
try {
const pattern = {
cmd: 'create-connection-invitation'
};
const payload = { createOutOfBandConnectionInvitation: { orgId, user, label } };
return await this.natsCall(pattern, payload);
const result = await this.natsClient.send<object>(this.agentServiceProxy, pattern, payload);
return result;
} catch (error) {
this.logger.error(`error in create-connection in wallet provision : ${JSON.stringify(error)}`);
this.logger.error(`[natsCall] - error in create-connection in wallet provision : ${JSON.stringify(error)}`);
}
}
Comment thread
GHkrishna marked this conversation as resolved.

async _getALlLedgerDetails(): Promise<{
response;
}> {
async _getALlLedgerDetails(): Promise<ILedger[]> {
try {
const pattern = {
cmd: 'get-all-ledgers'
};
const payload = {};
return await this.natsCall(pattern, payload);
const result = await this.natsClient.send<ILedger[]>(this.agentServiceProxy, pattern, payload);
return result;
} catch (error) {
this.logger.error(`error in while fetching all the ledger details : ${JSON.stringify(error)}`);
this.logger.error(`[natsCall] - error in while fetching all the ledger details : ${JSON.stringify(error)}`);
}
}
Comment thread
GHkrishna marked this conversation as resolved.

async _walletProvision(payload: IWalletProvision): Promise<{
response;
}> {
async _walletProvision(payload: IWalletProvision): Promise<Partial<IStoreOrgAgent>> {
try {
const pattern = {
cmd: 'wallet-provisioning'
};
return await this.natsCall(pattern, payload);
const result = await this.natsClient.send<Partial<IStoreOrgAgent>>(this.agentServiceProxy, pattern, payload);
return result;
} catch (error) {
this.logger.error(`error in wallet provision : ${JSON.stringify(error)}`);
this.logger.error(`[natsCall] - error in wallet provision : ${JSON.stringify(error)}`);
throw error;
}
}
Expand Down Expand Up @@ -795,8 +788,8 @@ export class AgentServiceService {
ledger = Ledgers.Not_Applicable;
}

const ledgerList = (await this._getALlLedgerDetails()) as unknown as LedgerListResponse;
const isLedgerExist = ledgerList.response.find((existingLedgers) => existingLedgers.name === ledger);
const ledgerList = await this._getALlLedgerDetails();
const isLedgerExist = ledgerList.find((existingLedgers) => existingLedgers.name === ledger);
if (!isLedgerExist) {
Comment thread
GHkrishna marked this conversation as resolved.
throw new BadRequestException(ResponseMessages.agent.error.invalidLedger, {
cause: new Error(),
Expand Down Expand Up @@ -2191,32 +2184,6 @@ export class AgentServiceService {
}
}

async natsCall(
pattern: object,
payload: object
): Promise<{
response: string;
}> {
try {
return from(this.natsClient.send<string>(this.agentServiceProxy, pattern, payload))
.pipe(map((response) => ({ response })))
.toPromise()
.catch((error) => {
this.logger.error(`catch: ${JSON.stringify(error)}`);
throw new HttpException(
{
status: error.statusCode,
error: error.message
},
error.error
);
});
} catch (error) {
this.logger.error(`[natsCall] - error in nats call : ${JSON.stringify(error)}`);
throw error;
}
}

private async tokenEncryption(token: string): Promise<string> {
try {
const encryptedToken = CryptoJS.AES.encrypt(JSON.stringify(token), process.env.CRYPTO_PRIVATE_KEY).toString();
Expand Down
7 changes: 2 additions & 5 deletions apps/agent-service/src/interface/agent-service.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export interface IStoreOrgAgent {
id?: string;
clientSocketId?: string;
agentEndPoint?: string;
agentToken?: string;
apiKey?: string;
seed?: string;
did?: string;
Expand Down Expand Up @@ -556,7 +557,7 @@ export interface IQuestionPayload {
export interface IBasicMessage {
content: string;
}
interface Ledger {
export interface ILedger {
id: string;
createDateTime: string;
lastChangedDateTime: string;
Expand All @@ -570,10 +571,6 @@ interface Ledger {
networkUrl: string | null;
}

export interface LedgerListResponse {
response: Ledger[];
}

export interface ICreateConnectionInvitation {
label?: string;
alias?: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/api-gateway/src/connection/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ConnectionService extends BaseService {
try {
return this.natsClient.sendNatsMessage(this.connectionServiceProxy, 'send-question', questionDto);
} catch (error) {
throw new RpcException(error.response);
throw new RpcException(error?.response ?? error);
}
}

Expand Down
9 changes: 1 addition & 8 deletions apps/cloud-wallet/src/cloud-wallet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import { CommonService } from '@credebl/common';
import {
BadRequestException,
ConflictException,
Inject,
Injectable,
InternalServerErrorException,
Logger,
NotFoundException
} from '@nestjs/common';
import { Cache } from 'cache-manager';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import {
IAcceptOffer,
ICreateCloudWalletDid,
Expand Down Expand Up @@ -40,17 +37,13 @@ import { CloudWalletRepository } from './cloud-wallet.repository';
import { ResponseMessages } from '@credebl/common/response-messages';
import { CloudWalletType } from '@credebl/enum/enum';
import { CommonConstants } from '@credebl/common/common.constant';
import { ClientProxy } from '@nestjs/microservices';

@Injectable()
export class CloudWalletService {
constructor(
private readonly commonService: CommonService,
@Inject('NATS_CLIENT') private readonly cloudWalletServiceProxy: ClientProxy,
private readonly cloudWalletRepository: CloudWalletRepository,
private readonly logger: Logger,
// TODO: Remove duplicate, unused variable
@Inject(CACHE_MANAGER) private cacheService: Cache
private readonly logger: Logger
) {}

/**
Expand Down
18 changes: 9 additions & 9 deletions apps/connection/src/connection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ export class ConnectionController {
}

@MessagePattern({ cmd: 'get-all-agent-connection-list' })
async getConnectionListFromAgent(payload: GetAllConnections): Promise<string> {
const {orgId, connectionSearchCriteria } = payload;
async getConnectionListFromAgent(payload: GetAllConnections): Promise<IConnectionList> {
const { orgId, connectionSearchCriteria } = payload;
return this.connectionService.getAllConnectionListFromAgent(orgId, connectionSearchCriteria);
}

/**
*
*
* @param connectionId
* @param orgId
* @param orgId
* @returns connection details by connection Id
*/
@MessagePattern({ cmd: 'get-connection-details-by-connectionId' })
Expand All @@ -64,7 +64,7 @@ export class ConnectionController {
}

@MessagePattern({ cmd: 'get-connection-records' })
async getConnectionRecordsByOrgId(payload: { orgId: string, userId: string }): Promise<number> {
async getConnectionRecordsByOrgId(payload: { orgId: string; userId: string }): Promise<number> {
const { orgId } = payload;
return this.connectionService.getConnectionRecords(orgId);
}
Expand All @@ -80,7 +80,7 @@ export class ConnectionController {
const { user, receiveInvitation, orgId } = payload;
return this.connectionService.receiveInvitation(user, receiveInvitation, orgId);
}

@MessagePattern({ cmd: 'send-question' })
async sendQuestion(payload: IQuestionPayload): Promise<object> {
return this.connectionService.sendQuestion(payload);
Expand All @@ -97,13 +97,13 @@ export class ConnectionController {
}

@MessagePattern({ cmd: 'delete-connection-records' })
async deleteConnectionRecords(payload: {orgId: string, userDetails: user}): Promise<IDeletedConnectionsRecord> {
async deleteConnectionRecords(payload: { orgId: string; userDetails: user }): Promise<IDeletedConnectionsRecord> {
const { orgId, userDetails } = payload;
return this.connectionService.deleteConnectionRecords(orgId, userDetails);
}

@MessagePattern({ cmd: 'send-basic-message-on-connection' })
async sendBasicMessage(payload: {content: string, orgId: string, connectionId: string}): Promise<object> {
return this.connectionService.sendBasicMesage(payload);
async sendBasicMessage(payload: { content: string; orgId: string; connectionId: string }): Promise<object> {
return this.connectionService.sendBasicMessage(payload);
}
}
Loading