Skip to content

Commit

Permalink
feat: presentation API refactor (#765)
Browse files Browse the repository at this point in the history
Signed-off-by: Bassam Riman <[email protected]>
  • Loading branch information
CryptoKnightIOG authored Oct 23, 2023
1 parent 5204838 commit 045d829
Showing 1 changed file with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import java.rmi.UnexpectedException
import java.time.Instant
import java.util as ju
import java.util.UUID
import io.iohk.atala.mercury.protocol.presentproof.PresentCredentialRequestFormat

private class PresentationServiceImpl(
presentationRepository: PresentationRepository,
Expand Down Expand Up @@ -148,7 +147,7 @@ private class PresentationServiceImpl(
thid: DidCommID,
connectionId: Option[String],
proofTypes: Seq[ProofType],
options: Option[io.iohk.atala.pollux.core.model.presentation.Options],
maybeOptions: Option[io.iohk.atala.pollux.core.model.presentation.Options],
format: CredentialFormat,
): ZIO[WalletAccessContext, PresentationError, PresentationRecord] = {
for {
Expand All @@ -158,8 +157,13 @@ private class PresentationServiceImpl(
thid,
pairwiseVerifierDID,
pairwiseProverDID,
options,
format,
format match {
case CredentialFormat.JWT => maybeOptions.map(options => Seq(toJWTAttachment(options))).getOrElse(Seq.empty)
case CredentialFormat.AnonCreds =>
maybeOptions
.map(options => Seq(toAnoncredAttachment(options)))
.getOrElse(Seq.empty) // TODO ATL-5945 Create Actual Anoncred Request
}
)
)
record <- ZIO.succeed(
Expand Down Expand Up @@ -610,31 +614,34 @@ private class PresentationServiceImpl(
} yield record
}

private[this] def toJWTAttachment(options: Options): AttachmentDescriptor = {
AttachmentDescriptor.buildJsonAttachment(
payload = PresentationAttachment.build(Some(options)),
format = Some(PresentCredentialRequestFormat.JWT.name)
)
}

// TODO ATL-5945 Create Actual Anoncred Request
private[this] def toAnoncredAttachment(options: Options): AttachmentDescriptor = {
AttachmentDescriptor.buildJsonAttachment(
payload = PresentationAttachment.build(Some(options)),
format = Some(PresentCredentialRequestFormat.Anoncred.name)
)
}

private[this] def createDidCommRequestPresentation(
proofTypes: Seq[ProofType],
thid: DidCommID,
pairwiseVerifierDID: DidId,
pairwiseProverDID: DidId,
maybeOptions: Option[io.iohk.atala.pollux.core.model.presentation.Options],
format: CredentialFormat,
attachments: Seq[AttachmentDescriptor]
): RequestPresentation = {
RequestPresentation(
body = RequestPresentation.Body(
goal_code = Some("Request Proof Presentation"),
proof_types = proofTypes
),
attachments = maybeOptions
.map(options =>
Seq(
AttachmentDescriptor.buildJsonAttachment(
payload = PresentationAttachment.build(Some(options)),
format = format match
case CredentialFormat.JWT => Some(PresentCredentialRequestFormat.JWT.name)
case CredentialFormat.AnonCreds => Some(PresentCredentialRequestFormat.Anoncred.name)
)
)
)
.getOrElse(Seq.empty),
attachments = attachments,
from = pairwiseVerifierDID,
to = pairwiseProverDID,
thid = Some(thid.toString)
Expand All @@ -656,8 +663,6 @@ private class PresentationServiceImpl(
)
}

import io.iohk.atala.pollux.vc.jwt.CredentialPayload.Implicits.*

private[this] def updatePresentationRecordProtocolState(
id: DidCommID,
from: PresentationRecord.ProtocolState,
Expand Down

0 comments on commit 045d829

Please sign in to comment.