Skip to content

Commit

Permalink
feat(pollux): Added new state (#234)
Browse files Browse the repository at this point in the history
* Added new state for the Presentation flow
  • Loading branch information
mineme0110 authored Dec 12, 2022
1 parent 2dcf5e3 commit b704abc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -237,7 +234,7 @@ private class PresentationServiceImpl(
): IO[PresentationError, Option[PresentationRecord]] = {

for {
// crecentialsToUse

maybeRecord <- presentationRepository
.getPresentationRecord(recordId)
.mapError(RepositoryError.apply)
Expand All @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b704abc

Please sign in to comment.