Skip to content

Commit

Permalink
fix: Added validation for schema and cred-def and updated payload for…
Browse files Browse the repository at this point in the history
… create request cred-def (#149)

* fix: Added validation for the schema and cred-def request creation

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

* Remove commented code

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

---------

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>
  • Loading branch information
KulkarniShashank authored and KulkarniShashank committed Sep 10, 2024
1 parent 87a909e commit 31317c6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
54 changes: 52 additions & 2 deletions apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,14 @@ export class EcosystemService {
if (endorsementTransactionPayload.type === endorsementTransactionType.SCHEMA) {
return this.handleSchemaSubmission(endorsementTransactionPayload, ecosystemMemberDetails, submitTransactionRequest);
} else if (endorsementTransactionPayload.type === endorsementTransactionType.CREDENTIAL_DEFINITION) {
payload.credentialDefinition = {
tag: parsedRequestPayload.operation.tag,
issuerId: ecosystemMemberDetails.orgDid,
schemaId: endorsementTransactionPayload.requestBody['schemaId'],
type: endorsementTransactionPayload.requestBody['type'],
value: endorsementTransactionPayload.requestBody['value']
};
}

if ('undefined' === submitTransactionRequest['message'].credentialDefinitionId.split(':')[3]) {

Expand All @@ -828,6 +836,43 @@ export class EcosystemService {

throw new InternalServerErrorException(ResponseMessages.ecosystem.error.sumbitTransaction);
}
const saveSchemaPayload: SaveSchema = {
name: endorsementTransactionPayload.requestBody['name'],
version: endorsementTransactionPayload.requestBody['version'],
attributes: JSON.stringify(endorsementTransactionPayload.requestBody['attributes']),
schemaLedgerId: submitTransactionRequest['message'].schemaId,
issuerId: ecosystemMemberDetails.orgDid,
createdBy: endorsementTransactionPayload.ecosystemOrgs.orgId,
lastChangedBy: endorsementTransactionPayload.ecosystemOrgs.orgId,
publisherDid: extractedDidValue,
orgId: endorsementTransactionPayload.ecosystemOrgs.orgId,
ledgerId: ecosystemMemberDetails.ledgerId
};
const saveSchemaDetails = await this.ecosystemRepository.saveSchema(saveSchemaPayload);
if (!saveSchemaDetails) {
throw new InternalServerErrorException(ResponseMessages.ecosystem.error.saveSchema);
}
return saveSchemaDetails;
} else if (endorsementTransactionPayload.type === endorsementTransactionType.CREDENTIAL_DEFINITION) {

const schemaDetails = await this.ecosystemRepository.getSchemaDetailsById(endorsementTransactionPayload.requestBody['schemaId']);
const saveCredentialDefinition: saveCredDef = {
schemaLedgerId: endorsementTransactionPayload.requestBody['schemaId'],
tag: endorsementTransactionPayload.requestBody['tag'],
credentialDefinitionId: submitTransactionRequest['message'].credentialDefinitionId,
revocable: false,
createdBy: endorsementTransactionPayload.ecosystemOrgs.orgId,
orgId: ecosystemMemberDetails.orgId,
schemaId: schemaDetails.id
};

const saveCredDefDetails = await this.ecosystemRepository.saveCredDef(saveCredentialDefinition);
if (!saveCredDefDetails) {
throw new InternalServerErrorException(ResponseMessages.ecosystem.error.saveCredDef);
}
return saveCredDefDetails;
}


return this.handleCredDefSubmission(endorsementTransactionPayload, ecosystemMemberDetails, submitTransactionRequest);
}
Expand Down Expand Up @@ -985,8 +1030,13 @@ export class EcosystemService {
* @returns EndorsementTransaction Status message
*/

async autoSignAndSubmitTransaction(): Promise<object> {
try {
/**
*
* @param ecosystemId
* @param endorsementId
* @param orgId
* @returns EndorsementTransactionRequest Status message
*/

return await this.ecosystemRepository.updateAutoSignAndSubmitTransaction();
} catch (error) {
Expand Down
2 changes: 0 additions & 2 deletions libs/common/src/response-messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ export const ResponseMessages = {
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',
credDefAlreadyExist: 'Credential definition already exist',
saveSchema: 'Error while storing the schema details',
Expand Down

0 comments on commit 31317c6

Please sign in to comment.