From b704abca020fc0d6f03f625aead2d206dba1818c Mon Sep 17 00:00:00 2001 From: Shailesh Patil <53746241+mineme0110@users.noreply.github.com> Date: Mon, 12 Dec 2022 11:09:21 +0000 Subject: [PATCH] feat(pollux): Added new state (#234) * Added new state for the Presentation flow --- .../core/model/PresentationRecord.scala | 6 ++- .../core/service/PresentationService.scala | 41 +++++-------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/PresentationRecord.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/PresentationRecord.scala index 4c542f9e60..121a555a66 100644 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/PresentationRecord.scala +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/PresentationRecord.scala @@ -57,13 +57,15 @@ object PresentationRecord { // Prover has "accepted" a Presentation request received from a Verifier (Prover DB) case PresentationPending extends ProtocolState // Prover has generated (signed) the VC and is now ready to send it to the Verifier (Prover DB) - case PresentationGenerated extends ProtocolState - // The Presentation has been sent to the Verifier (Prover DB) + + // Prover has sent the Presentation (Prover DB) case PresentationSent extends ProtocolState // Verifier has received the presentation (Verifier DB) case PresentationReceived extends ProtocolState // Verifier has verified the presentation (proof) (Verifier DB) case PresentationVerified extends ProtocolState + // Verifier has accepted the verified presentation (proof) (Verifier DB) + case PresentationAccepted extends ProtocolState // Verifier has rejected the presentation (proof) (Verifier DB) case PresentationRejected extends ProtocolState // TODO send problem report 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 643b84a496..c0ceb734fd 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 @@ -78,17 +78,14 @@ trait PresentationService { def markProposePresentationSent(recordId: UUID): IO[PresentationError, Option[PresentationRecord]] - def markPresentationGenerated( - recordId: UUID, - presentation: Presentation - ): IO[PresentationError, Option[PresentationRecord]] - def markPresentationSent(recordId: UUID): IO[PresentationError, Option[PresentationRecord]] def markPresentationVerified(recordId: UUID): IO[PresentationError, Option[PresentationRecord]] def markPresentationRejected(recordId: UUID): IO[PresentationError, Option[PresentationRecord]] + def markPresentationAccepted(recordId: UUID): IO[PresentationError, Option[PresentationRecord]] + } object PresentationServiceImpl { @@ -237,7 +234,7 @@ private class PresentationServiceImpl( ): IO[PresentationError, Option[PresentationRecord]] = { for { - // crecentialsToUse + maybeRecord <- presentationRepository .getPresentationRecord(recordId) .mapError(RepositoryError.apply) @@ -255,7 +252,6 @@ private class PresentationServiceImpl( .mapError(RepositoryError.apply) issuedRawCredentials = issuedValidCredentials.map(_.issuedCredentialRaw.map(IssuedCredentialRaw(_))).flatten - x = List(1) issuedCredentials <- ZIO.fromEither( Either.cond( issuedRawCredentials.nonEmpty, @@ -294,9 +290,8 @@ private class PresentationServiceImpl( presentationRequest <- ZIO .fromOption(record.presentationData) .mapError(_ => InvalidFlowStateError(s"No request found for this record: $recordId")) - _ <- ZIO.log(s"************presentationRequest*************$presentationRequest") - _ <- verifyPresentation(presentationRequest) // TODO - recordUpdated <- markPresentationVerified(record.id) + + recordUpdated <- markPresentationAccepted(record.id) } yield recordUpdated } @@ -381,26 +376,12 @@ private class PresentationServiceImpl( PresentationRecord.ProtocolState.PresentationVerified ) - override def markPresentationGenerated( - recordId: UUID, - presentation: Presentation - ): IO[PresentationError, Option[PresentationRecord]] = { - for { - count <- presentationRepository - .updateWithPresentation( - recordId, - presentation, - PresentationRecord.ProtocolState.PresentationGenerated - ) - .mapError(RepositoryError.apply) - _ <- count match - case 1 => ZIO.succeed(()) - case n => ZIO.fail(RecordIdNotFound(recordId)) - record <- presentationRepository - .getPresentationRecord(recordId) - .mapError(RepositoryError.apply) - } yield record - } + override def markPresentationAccepted(recordId: UUID): IO[PresentationError, Option[PresentationRecord]] = + updatePresentationRecordProtocolState( + recordId, + PresentationRecord.ProtocolState.PresentationVerified, + PresentationRecord.ProtocolState.PresentationAccepted + ) override def markPresentationSent(recordId: UUID): IO[PresentationError, Option[PresentationRecord]] = updatePresentationRecordProtocolState(