Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: endorsement flow for key and web method #831

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 9 additions & 6 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,14 @@ export class AgentServiceService {
let agentProcess;
let ledgerIdData = [];
try {
if (payload.method !== DidMethod.KEY && payload.method !== DidMethod.WEB) {
let ledger;
const { network } = payload;
const ledger = await ledgerName(network);
if (network) {
ledger = await ledgerName(network);
} else {
ledger = Ledgers.Not_Applicable;
}

const ledgerList = (await this._getALlLedgerDetails()) as unknown as LedgerListResponse;
const isLedgerExist = ledgerList.response.find((existingLedgers) => existingLedgers.name === ledger);
if (!isLedgerExist) {
Expand All @@ -813,10 +818,8 @@ export class AgentServiceService {
description: ResponseMessages.errorMessages.notFound
});
}

ledgerIdData = await this.agentServiceRepository.getLedgerDetails(ledger);
}


const agentSpinUpStatus = AgentSpinUpStatus.PROCESSED;

// Create and stored agent details
Expand Down Expand Up @@ -859,7 +862,7 @@ export class AgentServiceService {
orgAgentTypeId,
tenantId: tenantDetails.walletResponseDetails['id'],
walletName: payload.label,
ledgerId: ledgerIdData ? ledgerIdData.map((item) => item.id) : null,
ledgerId: ledgerIdData.map((item) => item.id),
id: agentProcess?.id
};

Expand Down
5 changes: 3 additions & 2 deletions apps/api-gateway/src/ecosystem/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,11 @@ export class EcosystemController {
@Res() res: Response
): Promise<Response> {
const transactionResponse = await this.ecosystemService.submitTransaction(endorsementId, ecosystemId, orgId, user);

const finalResponse: IResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.ecosystem.success.submit,
data: transactionResponse
message: transactionResponse?.['responseMessage'],
data: transactionResponse?.['txnPayload']
};
return res.status(HttpStatus.CREATED).json(finalResponse);
}
Expand Down
18 changes: 12 additions & 6 deletions apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { EcosystemInviteTemplate } from '../templates/EcosystemInviteTemplate';
import { EmailDto } from '@credebl/common/dtos/email.dto';
import { sendEmail } from '@credebl/common/send-grid-helper-file';
import { AcceptRejectEcosystemInvitationDto } from '../dtos/accept-reject-ecosysteminvitation.dto';
import { EcosystemConfigSettings, Invitation, JSONSchemaType, OrgAgentType, SchemaType, SchemaTypeEnum } from '@credebl/enum/enum';
import { EcosystemConfigSettings, Invitation, LedgerLessConstant, OrgAgentType, SchemaType, SchemaTypeEnum } from '@credebl/enum/enum';
import {
DeploymentModeType,
EcosystemOrgStatus,
Expand Down Expand Up @@ -136,7 +136,7 @@ export class EcosystemService {
throw new NotFoundException(ResponseMessages.ecosystem.error.orgDidNotExist);
}

const ecosystemLedgers = orgDetails.org_agents.map((agent) => agent.ledgers.id);
const ecosystemLedgers = orgDetails.org_agents.map((agent) => agent.ledgers?.id);

const createEcosystem = await this.ecosystemRepository.createNewEcosystem(createEcosystemDto, ecosystemLedgers);
if (!createEcosystem) {
Expand Down Expand Up @@ -1604,7 +1604,7 @@ export class EcosystemService {
return this.ecosystemRepository.updateTransactionStatus(endorsementId, endorsementTransactionStatus.SUBMITED);
}

async submitTransaction(transactionPayload: ITransactionData): Promise<object> {
async submitTransaction(transactionPayload: ITransactionData): Promise<{txnPayload: object, responseMessage: string}> {
try {
let txnPayload;

Expand All @@ -1624,13 +1624,19 @@ export class EcosystemService {
throw new ConflictException(ResponseMessages.ecosystem.error.transactionSubmitted);
}

const parsedRequestPayload = JSON.parse(endorsementPayload?.requestPayload);

const responseMessage = LedgerLessConstant.NO_LEDGER === parsedRequestPayload?.schemaType
? ResponseMessages.ecosystem.success.submitNoLedgerSchema
: ResponseMessages.ecosystem.success.submit;

if (endorsementPayload?.type === endorsementTransactionType.W3C_SCHEMA) {
txnPayload = await this.submitW3CTransaction(transactionPayload);
} else {
txnPayload = await this.submitIndyTransaction(transactionPayload);
}

return txnPayload;
return { txnPayload, responseMessage };
} catch (error) {
this.logger.error(`In submit transaction: ${JSON.stringify(error)}`);
if (error?.error) {
Expand Down Expand Up @@ -1773,11 +1779,11 @@ export class EcosystemService {
schemaPayload: {
schemaName: w3cEndorsementTransactionPayload?.requestBody?.['schemaName'],
attributes: w3cEndorsementTransactionPayload?.requestBody?.['attributes'],
schemaType: JSONSchemaType.POLYGON_W3C,
schemaType: w3cEndorsementTransactionPayload?.requestBody?.['schemaType'],
description: w3cEndorsementTransactionPayload?.requestBody?.['description']
}
},
orgId: transactionPayload?.orgId,
orgId: w3cEndorsementTransactionPayload?.['ecosystemOrgs']?.orgId,
user: transactionPayload?.user
};

Expand Down
5 changes: 2 additions & 3 deletions apps/issuance/src/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { ICredentialOfferResponse, IDeletedIssuanceRecords, IIssuedCredential, I
import { OOBIssueCredentialDto } from 'apps/api-gateway/src/issuance/dtos/issuance.dto';
import { RecordType, agent_invitations, organisation, user } from '@prisma/client';
import { createOobJsonldIssuancePayload, validateEmail } from '@credebl/common/cast.helper';
// import { sendEmail } from '@credebl/common/send-grid-helper-file';
import { sendEmail } from '@credebl/common/send-grid-helper-file';
import * as pLimit from 'p-limit';
import { UserActivityRepository } from 'libs/user-activity/repositories';
import { validateW3CSchemaAttributes } from '../libs/helpers/attributes.validator';
Expand Down Expand Up @@ -804,8 +804,7 @@ async sendEmailForCredentialOffer(sendEmailCredentialOffer: SendEmailCredentialO
}
];

const isEmailSent = true; // change this after testing on local
// const isEmailSent = await sendEmail(this.emailData);
const isEmailSent = await sendEmail(this.emailData);

this.logger.log(`isEmailSent ::: ${JSON.stringify(isEmailSent)}-${this.counter}`);
this.counter++;
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger/src/schema/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class SchemaService extends BaseService {
async createW3CSchema(orgId:string, schemaPayload: ICreateW3CSchema, user: string): Promise<ISchemaData> {
try {
let createSchema;

const { description, attributes, schemaName} = schemaPayload;
const agentDetails = await this.schemaRepository.getAgentDetailsByOrgId(orgId);
if (!agentDetails) {
Expand Down
3 changes: 2 additions & 1 deletion libs/common/src/response-messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ export const ResponseMessages = {
schemaRequest: 'Schema transaction request created successfully',
credDefRequest: 'Credential definition transaction request created successfully',
sign: 'Endorsement request approved',
submit: 'Endorsement request submitted to ledger',
submit: 'Endorsement request is submitted to ledger',
submitNoLedgerSchema: 'Endorsement request is submitted',
invitationReject: 'Ecosystem invitation rejected',
invitationAccept: 'Ecosystem invitation accepted successfully',
deleteEcosystemMember: 'You are deleted as a ecosystem member',
Expand Down