From 2765845e4255e0ff5c087563d52cf6ac0d4bd3e9 Mon Sep 17 00:00:00 2001 From: Shailesh Patil <53746241+mineme0110@users.noreply.github.com> Date: Thu, 23 Feb 2023 12:42:56 +0000 Subject: [PATCH] =?UTF-8?q?feat(pollux):=20Moving=20the=20check=20when=20a?= =?UTF-8?q?ccepting=20the=20credential=20to=20crea=E2=80=A6=20(#391)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(pollux): Moving the check when accepting the creadential to creat VP * feat(pollux): pr comments addressed --- .../core/service/PresentationService.scala | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/PresentationService.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/PresentationService.scala index b1423e1eb2..2d58486ec7 100644 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/PresentationService.scala +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/PresentationService.scala @@ -159,14 +159,8 @@ private class PresentationServiceImpl( .getValidIssuedCredentials(credentialsToUse.map(UUID.fromString)) .mapError(RepositoryError.apply) - _ <- ZIO.cond( - issuedValidCredentials.forall(_.subjectId == prover.did.value), - (), - PresentationError.HolderBindingError( - s"Presenting credential with different subject than the prover DID is not supported" - ) - ) - issuedRawCredentials = issuedValidCredentials.map(_.issuedCredentialRaw.map(IssuedCredentialRaw(_))).flatten + issuedRawCredentials = issuedValidCredentials.flatMap(_.issuedCredentialRaw.map(IssuedCredentialRaw(_))) + issuedCredentials <- ZIO.fromEither( Either.cond( issuedRawCredentials.nonEmpty, @@ -363,6 +357,14 @@ private class PresentationServiceImpl( issuedValidCredentials <- credentialRepository .getValidIssuedCredentials(credentialsToUse.map(UUID.fromString)) .mapError(RepositoryError.apply) + _ <- ZIO.cond( + (issuedValidCredentials.map(_.subjectId).toSet.size == 1), + (), + PresentationError.HolderBindingError( + s"Creating a Verifiable Presentation for credential with different subject DID is not supported, found : ${issuedValidCredentials + .map(_.subjectId)}" + ) + ) issuedRawCredentials = issuedValidCredentials.flatMap(_.issuedCredentialRaw.map(IssuedCredentialRaw(_))) issuedCredentials <- ZIO.fromEither( Either.cond(