Skip to content

Commit

Permalink
refactor: endorsement flow for key and web method (#831)
Browse files Browse the repository at this point in the history
* refactor: endorsement flow for key and web method

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

* refactor: send email for issuance

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

---------

Signed-off-by: bhavanakarwade <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
bhavanakarwade authored and KulkarniShashank committed Sep 11, 2024
1 parent 632d184 commit 42ac366
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 62 deletions.
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 @@ -800,9 +800,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 @@ -811,10 +816,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 @@ -857,7 +860,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 @@ -448,10 +448,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 @@ -20,7 +20,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 @@ -134,7 +134,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 @@ -1603,7 +1603,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 @@ -1623,13 +1623,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 @@ -1776,11 +1782,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 @@ -802,8 +802,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
126 changes: 82 additions & 44 deletions libs/common/src/response-messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,50 +295,88 @@ export const ResponseMessages = {
bulkProcess: 'Process initiated for bulk issuance',
deleteIssuanceRecords: 'Issuance records deleted'
},
error: {
exists: 'Credentials is already exist',
credentialsNotFound: 'Credentials not found',
agentEndPointNotFound: 'Agent details not found',
organizationNotFound: 'organization Not Found',
agentUrlNotFound: 'agent url not found',
notFound: 'History not found',
credentialOfferNotFound: 'Credential offer not found',
invitationNotFound: 'Invitation not found',
unableToCreateOOBOffer: 'Unable to create out-of-band credential offer',
platformConfigNotFound: 'Platform config details not found',
emailSend: 'Unable to send email to the user',
previewFile: 'Error while fetching file details',
previewCachedData: 'Error while fetching cached data',
emptyFileData: 'File details does not exit or removed',
cacheTimeOut: 'Timeout for reviewing data, re-upload your file and generate new request',
fileNotFound: 'File details not found',
fileData: 'File data does not exist for the specific file',
retry: 'Credentials do not exist for retry',
walletError: 'Credential Issuance failed due to error in Wallet Agent',
emailIdNotPresent: 'EmailId is empty or not present',
attributesNotPresent: 'Attributes are not present or not empty',
unableToCreateOffer: 'Unable to create offer',
orgAgentTypeNotFound: 'Organization agent type not found',
credentialNotPresent: 'credential is required',
optionsNotPresent:'options are required',
attributesAreRequired: 'attributes are required',
invalidCredentialType:'invalid credential type',
missingRequestId: 'Param requestId is missing from the request.',
cachedData: 'Cached data does not exist',
cachedfileData: 'Cached file data does not exist',
storeBulkData: 'Error while storing the bulk deata',
issuanceRecordsNotFound: 'Issuance records does not exists',
removeIssuanceData: 'First you have to remove issuance data'
}
},
verification: {
success: {
fetch: 'Proof presentations details fetched successfully.',
create: 'Presentation of proof received successfully.',
verifiedProofDetails: 'Proof presentation details fetched successfully.',
send: 'Proof request send successfully.',
verified: 'Proof presentation verified successfully.',
deleteVerificationRecord: 'Verification records deleted'
ecosystem: {
success: {
create: 'Ecosystem created successfully',
update: 'Ecosystem details updated successfully',
add: 'Organization added successfully',
delete: 'Ecosystem invitations deleted successfully',
fetch: 'Ecosystem fetched successfully',
getEcosystemDashboard: 'Ecosystem dashboard details fetched successfully',
getInvitation: 'Ecosystem invitations fetched successfully',
createInvitation: 'Ecosystem invitations sent',
schemaRequest: 'Schema transaction request created successfully',
credDefRequest: 'Credential definition transaction request created successfully',
sign: 'Endorsement request approved',
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',
fetchEndorsors: 'Endorser transactions fetched successfully',
DeclineEndorsementTransaction: 'Endorsement request declined',
AutoEndorsementTransaction: 'The flag for transactions has been successfully set',
fetchMembers: 'Ecosystem members fetched successfully',
allschema: 'Schema details fetched successfully',
AutoSignAndSubmit: 'Endorsement request approved & submitted to ledger'
},
error: {
notCreated: 'Error while creating ecosystem',
agentNotSpunUp: 'Agent is not spun up for this organization',
userNotHaveAccess: 'You do not have access',
orgAlreadyExists: 'Organization is already exists in ecosystem',
unableToAdd: 'Unable to add organization',
partiallyAdded: 'Organization(s) are partially added',
orgNotExist: 'Organization does not exist',
orgDidNotExist: 'Organization did does not exist',
exists: 'An ecosystem name is already exist',
update: 'Error while updating ecosystem',
invalidInvitationStatus: 'Invalid invitation status',
invitationNotFound: 'Ecosystem Invitation not found',
invitationNotUpdate: 'Ecosystem Invitation not updated',
ledgerNotMatch: 'Organization ledger network not matched with Ecosystem',
orgsNotUpdate: 'Ecosystem Orgs not updated',
ecosystemNotEnabled: 'Ecosystem service is not enabled',
sumbitTransaction: 'Error while submitting transaction',
signTransactionNotApplicable: 'Signing transaction for w3c schema is not aapllicable',
requestSchemaTransaction: 'Error while request schema transaction',
requestCredDefTransaction: 'Error while submitting transaction',
notFound: 'Organization not found',
platformConfigNotFound: 'Platform configurations not found',
schemaNotFound: 'Schema not found',
ecosystemNotFound: 'Ecosystem not found',
ecosystemOrgNotFound: 'Ecosystem org not found',
ecosystemConfigNotFound: 'Ecosystem config not found',
credentialDefinitionNotFound: 'Credential definition found',
leadNotFound: 'Lead details not found',
signRequestError: 'Error while signing the transaction',
updateTransactionError: 'Error while update the transaction',
schemaAlreadyExist: 'Schema name and schema version already exist',
schemaNameAlreadyExist: 'Schema name already exist',
credDefAlreadyExist: 'Credential definition already exist',
saveSchema: 'Error while storing the schema details',
saveCredDef: 'Error while storing the credential-definition details',
invalidOrgId: 'Invalid organization Id',
invalidEcosystemId: 'Invalid ecosystem Id',
invalidTransaction: 'Transaction does not exist',
transactionSubmitted: 'Transaction already submitted',
transactionAlreadySigned: 'Transaction already signed',
transactionNotSigned: 'Transaction request is not signed',
transactionNotRequested: 'Transaction is not requested',
invalidAgentUrl: 'Invalid agent url',
EndorsementTransactionNotFoundException: 'Endorsement transaction with status requested not found',
OrgOrEcosystemNotFoundExceptionForEndorsementTransaction: 'The endorsement transaction status cant be updated',
ecosystemOrgAlready: 'Organization is already part of the ecosystem. Please ensure that the organization is not duplicated.',
updateSchemaId: 'Error while updating the schema id',
updateCredDefId: 'Error while updating the credential-definition',
invalidMessage: 'Invalid transaction details. Missing "message" property.',
invalidTransactionMessage: 'Invalid transaction details',
ecosystemRoleNotMatch: 'Ecosystem role not match',
orgEcoIdRequired: 'OrgId & EcosystemId is required',
ecosystemMembersNotExists: 'Ecosystem members does not exists',
notAbleToDeleteEcosystem: 'You cannot delete the ecosystem, because you are the ecosystem lead',
ecosystemNotExists: 'Ecosystem does not exists'
}
},
error: {
notFound: 'Organization agent not found',
Expand Down

0 comments on commit 42ac366

Please sign in to comment.