Skip to content

Commit

Permalink
fix proof-request for multiple proof request (#61)
Browse files Browse the repository at this point in the history
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
KulkarniShashank authored and KulkarniShashank committed Sep 11, 2024
1 parent 33a393d commit 88f6cd5
Showing 1 changed file with 69 additions and 1 deletion.
70 changes: 69 additions & 1 deletion apps/verification/src/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export class VerificationService {
*/
async sendProofRequest(requestProof: IRequestProof): Promise<string> {
try {
let requestedAttributes = {};
const requestedPredicates = {};
const comment = requestProof.comment ? requestProof.comment : '';

let proofRequestPayload: ISendProofRequestPayload = {
Expand All @@ -174,7 +176,73 @@ export class VerificationService {
autoAcceptProof: ''
};

const { requestedAttributes, requestedPredicates } = await this._proofRequestPayload(requestProof);
const attributeWithSchemaIdExists = requestProof.attributes.some(attribute => attribute.schemaId);
if (attributeWithSchemaIdExists) {
requestedAttributes = Object.fromEntries(requestProof.attributes.map((attribute, index) => {

const attributeElement = attribute.attributeName;
const attributeReferent = `additionalProp${index + 1}`;

if (!attribute.condition && !attribute.value) {
const keys = Object.keys(requestedAttributes);

if (0 < keys.length) {
let attributeFound = false;

for (const attr of keys) {
if (
requestedAttributes[attr].restrictions.some(res => res.schema_id) ===
requestProof.attributes[index].schemaId
) {
requestedAttributes[attr].name.push(attributeElement);
attributeFound = true;
}

if (attr === keys[keys.length - 1] && !attributeFound) {
requestedAttributes[attributeReferent] = {
name: attributeElement,
restrictions: [
{
cred_def_id: requestProof.attributes[index].credDefId ? requestProof.attributes[index].credDefId : undefined,
schema_id: requestProof.attributes[index].schemaId
}
]
};
}
}
} else {
return [
attributeReferent,
{
name: attributeElement,
restrictions: [
{
cred_def_id: requestProof.attributes[index].credDefId ? requestProof.attributes[index].credDefId : undefined,
schema_id: requestProof.attributes[index].schemaId
}
]
}
];
}
} else {
requestedPredicates[attributeReferent] = {
p_type: attribute.condition,
restrictions: [
{
cred_def_id: requestProof.attributes[index].credDefId ? requestProof.attributes[index].credDefId : undefined,
schema_id: requestProof.attributes[index].schemaId
}
],
name: attributeElement,
p_value: parseInt(attribute.value)
};
}

return [attributeReferent, null];
}));
} else {
throw new BadRequestException(ResponseMessages.verification.error.schemaIdNotFound);
}

proofRequestPayload = {
protocolVersion: requestProof.protocolVersion ? requestProof.protocolVersion : 'v1',
Expand Down

0 comments on commit 88f6cd5

Please sign in to comment.