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

fix: proof-request for multiple proof request #61

Merged
merged 1 commit into from
Aug 25, 2023
Merged
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
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