diff --git a/apps/verification/src/verification.service.ts b/apps/verification/src/verification.service.ts index 024d1e0df..36a0e38d3 100644 --- a/apps/verification/src/verification.service.ts +++ b/apps/verification/src/verification.service.ts @@ -157,6 +157,8 @@ export class VerificationService { */ async sendProofRequest(requestProof: IRequestProof): Promise { try { + let requestedAttributes = {}; + const requestedPredicates = {}; const comment = requestProof.comment ? requestProof.comment : ''; let proofRequestPayload: ISendProofRequestPayload = { @@ -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',