Skip to content

Commit

Permalink
refactor: attributes payload changes while creating a proofrequest (#907
Browse files Browse the repository at this point in the history
)

* fix: verification bugs

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

* fix: take regex in common constants

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

* fix: added prooftype for polygon and no ledger

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

* fix: add proof type in common constants

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

---------

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>
  • Loading branch information
bhavanakarwade authored Aug 14, 2024
1 parent 1d41cc0 commit 8fee70b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
11 changes: 5 additions & 6 deletions apps/verification/src/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ClientProxy, RpcException } from '@nestjs/microservices';
import { map } from 'rxjs/operators';
import { IGetAllProofPresentations, IProofRequestSearchCriteria, IGetProofPresentationById, IProofPresentation, IProofRequestPayload, IRequestProof, ISendProofRequestPayload, IVerifyPresentation, IVerifiedProofData, IInvitation } from './interfaces/verification.interface';
import { VerificationRepository } from './repositories/verification.repository';
import { CommonConstants } from '@credebl/common/common.constant';
import { ATTRIBUTE_NAME_REGEX, CommonConstants } from '@credebl/common/common.constant';
import { RecordType, agent_invitations, org_agents, organisation, presentations, user } from '@prisma/client';
import { AutoAccept, OrgAgentType, VerificationProcessState } from '@credebl/enum/enum';
import { ResponseMessages } from '@credebl/common/response-messages';
Expand Down Expand Up @@ -275,7 +275,6 @@ export class VerificationService {
...proofRequestPayload
};
}

const getProofPresentationById = await this._sendProofRequest(payload);
return getProofPresentationById?.response;
} catch (error) {
Expand Down Expand Up @@ -781,7 +780,6 @@ export class VerificationService {
const verifiableCredential =
getProofPresentationById?.response?.presentation?.presentationExchange?.verifiableCredential[0]
?.credentialSubject;

if (getProofPresentationById?.response) {
certificate =
getProofPresentationById?.response?.presentation?.presentationExchange?.verifiableCredential[0].prettyVc
Expand All @@ -792,12 +790,13 @@ export class VerificationService {
Array.isArray(requestedAttributesForPresentationExchangeFormat)
) {
requestedAttributesForPresentationExchangeFormat.forEach((requestedAttributeKey) => {
const attributeName = requestedAttributeKey?.split('.').pop();
const attributeValue = verifiableCredential[attributeName];

const attributeName = requestedAttributeKey?.match(ATTRIBUTE_NAME_REGEX)?.[1];
const attributeValue = verifiableCredential?.[attributeName];

const schemaId =
getProofPresentationById?.response?.request?.presentationExchange?.presentation_definition
?.input_descriptors[0].schema[0].uri;

if (attributeName && attributeValue !== undefined) {
const extractedData: IProofPresentationDetails = {
[attributeName]: attributeValue,
Expand Down
6 changes: 4 additions & 2 deletions libs/common/src/cast.helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JSONSchemaType, ledgerLessDIDType, schemaRequestType, TemplateIdentifier } from '@credebl/enum/enum';
import { DidMethod, JSONSchemaType, ledgerLessDIDType, ProofType, schemaRequestType, TemplateIdentifier } from '@credebl/enum/enum';
import { ISchemaFields } from './interfaces/schema.interface';
import { BadRequestException, PipeTransform } from '@nestjs/common';
import { plainToClass } from 'class-transformer';
Expand Down Expand Up @@ -305,6 +305,8 @@ export const createOobJsonldIssuancePayload = (JsonldCredentialDetails: IJsonldC
const {credentialData, orgDid, orgId, schemaLedgerId, schemaName} = JsonldCredentialDetails;
const credentialSubject = { };

const proofType = (orgDid?.includes(DidMethod.POLYGON)) ? ProofType.POLYGON_PROOFTYPE : ProofType.NO_LEDGER_PROOFTYPE;

for (const key in credentialData) {
if (credentialData.hasOwnProperty(key) && TemplateIdentifier.EMAIL_COLUMN !== key) {
credentialSubject[key] = credentialData[key];
Expand All @@ -329,7 +331,7 @@ export const createOobJsonldIssuancePayload = (JsonldCredentialDetails: IJsonldC
prettyVc
},
'options': {
'proofType': 'Ed25519Signature2018',
proofType,
'proofPurpose': 'assertionMethod'
}
}
Expand Down
2 changes: 2 additions & 0 deletions libs/common/src/common.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ ACCEPT_OFFER = '/multi-tenancy/credentials/accept-offer/',
SEED_LENGTH = 32
}

export const ATTRIBUTE_NAME_REGEX = /\['(.*?)'\]/;

export const postgresqlErrorCodes = [];
postgresqlErrorCodes['23503'] = 'foreign_key_violation';
postgresqlErrorCodes['00000'] = 'successful_completion';
Expand Down
5 changes: 5 additions & 0 deletions libs/enum/src/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,9 @@ export enum CloudWalletType {
export enum UserRole {
DEFAULT_USER = 'DEFAULT_USER',
HOLDER = 'HOLDER'
}

export enum ProofType {
POLYGON_PROOFTYPE = 'EcdsaSecp256k1Signature2019',
NO_LEDGER_PROOFTYPE = 'Ed25519Signature2018'
}

0 comments on commit 8fee70b

Please sign in to comment.