Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/new-anoncred-endpoints' int…
Browse files Browse the repository at this point in the history
…o feat/new-anoncred-endpoints
  • Loading branch information
bvoiturier committed Sep 11, 2023
2 parents 41713df + 359d255 commit 1b2f1f9
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.iohk.atala.pollux.core.model

enum CredentialFormat:
case JWT extends CredentialFormat
case AnonCreds extends CredentialFormat
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ object IssueCredentialRecord {
case Issuer extends Role
case Holder extends Role

enum CredentialFormat:
case JWT extends CredentialFormat
case AnonCreds extends CredentialFormat

enum ProtocolState:
// Issuer has created an offer in a database, but it has not been sent yet (in Issuer DB)
case OfferPending extends ProtocolState
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.iohk.atala.mercury.protocol.presentproof.RequestPresentation
import io.iohk.atala.mercury.protocol.presentproof.Presentation
import io.iohk.atala.mercury.model.DidId
import java.time.Instant

final case class PresentationRecord(
id: DidCommID,
createdAt: Instant,
Expand All @@ -15,6 +16,7 @@ final case class PresentationRecord(
role: PresentationRecord.Role,
subjectId: DidId,
protocolState: PresentationRecord.ProtocolState,
credentialFormat: CredentialFormat,
requestPresentationData: Option[RequestPresentation],
proposePresentationData: Option[ProposePresentation],
presentationData: Option[Presentation],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.iohk.atala.castor.core.model.did.CanonicalPrismDID
import io.iohk.atala.mercury.model.DidId
import io.iohk.atala.mercury.protocol.issuecredential.{Attribute, IssueCredential, OfferCredential, RequestCredential}
import io.iohk.atala.pollux.core.model.*
import io.iohk.atala.pollux.core.model.IssueCredentialRecord.CredentialFormat
import io.iohk.atala.pollux.core.model.error.CredentialServiceError
import io.iohk.atala.pollux.core.model.error.CredentialServiceError.*
import io.iohk.atala.pollux.vc.jwt.{Issuer, JWT, PresentationPayload, W3cCredentialPayload}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.iohk.atala.iris.proto.service.IrisOperationId
import io.iohk.atala.iris.proto.service.IrisServiceGrpc.IrisServiceStub
import io.iohk.atala.iris.proto.vc_operations.IssueCredentialsBatch
import io.iohk.atala.mercury.model.{AttachmentDescriptor, Base64, DidId, JsonData}
import io.iohk.atala.mercury.protocol.issuecredential.{CredentialFormat as MercuryCredentialFormat, *}
import io.iohk.atala.mercury.protocol.issuecredential.*
import io.iohk.atala.pollux.*
import io.iohk.atala.pollux.anoncreds.{AnoncredLib, CreateCredentialDefinition}
import io.iohk.atala.pollux.core.model.*
Expand Down Expand Up @@ -550,16 +550,13 @@ private class CredentialServiceImpl(
) = {
for {
credentialPreview <- ZIO.succeed(CredentialPreview(schema_id = schemaId, attributes = claims))
attachmentId = java.util.UUID.randomUUID.toString
body = OfferCredential.Body(
goal_code = Some("Offer Credential"),
credential_preview = credentialPreview,
formats = Seq(MercuryCredentialFormat(attachmentId, MercuryCredentialFormat.JWT))
)
attachments <- ZIO.succeed(
Seq(
AttachmentDescriptor.buildJsonAttachment(
id = attachmentId,
mediaType = Some("application/json"),
format = Some(IssueCredentialOfferFormat.JWT.name),
payload = PresentationAttachment(
Expand Down Expand Up @@ -588,16 +585,13 @@ private class CredentialServiceImpl(
) = {
for {
credentialPreview <- ZIO.succeed(CredentialPreview(schema_id = Some(schemaId), attributes = claims))
attachmentId = java.util.UUID.randomUUID.toString
body = OfferCredential.Body(
goal_code = Some("Offer Credential"),
credential_preview = credentialPreview,
formats = Seq(MercuryCredentialFormat(attachmentId, MercuryCredentialFormat.AnonCreds))
)
attachments <- createAnonCredsOffer(credentialDefinitionId).map { offer =>
Seq(
AttachmentDescriptor.buildBase64Attachment(
id = attachmentId,
mediaType = Some("application/json"),
format = Some(IssueCredentialOfferFormat.Anoncred.name),
payload = offer.data.getBytes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import io.iohk.atala.castor.core.model.did.CanonicalPrismDID
import io.iohk.atala.event.notification.*
import io.iohk.atala.mercury.model.DidId
import io.iohk.atala.mercury.protocol.issuecredential.{IssueCredential, OfferCredential, RequestCredential}
import io.iohk.atala.pollux.core.model.IssueCredentialRecord.CredentialFormat
import io.iohk.atala.pollux.core.model.{CredentialFormat, DidCommID, IssueCredentialRecord, PublishedBatchData}
import io.iohk.atala.pollux.core.model.error.CredentialServiceError
import io.iohk.atala.pollux.core.model.{DidCommID, IssueCredentialRecord, PublishedBatchData}
import io.iohk.atala.pollux.vc.jwt.{Issuer, JWT, PresentationPayload, W3cCredentialPayload}
import io.iohk.atala.prism.crypto.MerkleInclusionProof
import io.iohk.atala.shared.models.WalletAccessContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import io.circe.Json
import io.iohk.atala.castor.core.model.did.CanonicalPrismDID
import io.iohk.atala.mercury.model.DidId
import io.iohk.atala.mercury.protocol.issuecredential.{IssueCredential, OfferCredential, RequestCredential}
import io.iohk.atala.pollux.core.model.IssueCredentialRecord.CredentialFormat
import io.iohk.atala.pollux.core.model.error.CredentialServiceError
import io.iohk.atala.pollux.core.model.{DidCommID, IssueCredentialRecord, PublishedBatchData}
import io.iohk.atala.pollux.core.model.{CredentialFormat, DidCommID, IssueCredentialRecord, PublishedBatchData}
import io.iohk.atala.pollux.vc.jwt.{Issuer, JWT, PresentationPayload, W3cCredentialPayload}
import io.iohk.atala.prism.crypto.MerkleInclusionProof
import zio.mock.{Mock, Proxy}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,23 @@ private class PresentationServiceImpl(
issuedValidCredentials <- credentialRepository
.getValidIssuedCredentials(credentialsToUse.map(DidCommID(_)))
.mapError(RepositoryError.apply)

issuedRawCredentials = issuedValidCredentials.flatMap(
_.issuedCredentialRaw.map(data => IssuedCredentialRaw(signedCredential = data, format = ???)) // FIXME
)

signedCredentials = issuedValidCredentials.flatMap(_.issuedCredentialRaw)
issuedCredentials <- ZIO.fromEither(
Either.cond(
issuedRawCredentials.nonEmpty,
issuedRawCredentials,
signedCredentials.nonEmpty,
signedCredentials,
PresentationError.IssuedCredentialNotFoundError(
new Throwable("No matching issued credentials found in prover db")
)
)
)

presentationPayload <- createPresentationPayloadFromCredential(issuedCredentials, requestPresentation, prover)
presentationPayload <- createPresentationPayloadFromCredential(
issuedCredentials,
record.credentialFormat,
requestPresentation,
prover
)
} yield presentationPayload
}

Expand Down Expand Up @@ -162,6 +163,7 @@ private class PresentationServiceImpl(
role = PresentationRecord.Role.Verifier,
subjectId = pairwiseProverDID,
protocolState = PresentationRecord.ProtocolState.RequestPending,
credentialFormat = ???, // FIXME
requestPresentationData = Some(request),
proposePresentationData = None,
presentationData = None,
Expand Down Expand Up @@ -209,6 +211,7 @@ private class PresentationServiceImpl(
role = Role.Prover,
subjectId = request.to,
protocolState = PresentationRecord.ProtocolState.RequestReceived,
credentialFormat = ???, // FIXME
requestPresentationData = Some(request),
proposePresentationData = None,
presentationData = None,
Expand All @@ -229,7 +232,8 @@ private class PresentationServiceImpl(
}

private def createPresentationPayloadFromCredential(
issuedCredentials: Seq[IssuedCredentialRaw],
issuedCredentials: Seq[String],
format: CredentialFormat,
requestPresentation: RequestPresentation,
prover: Issuer
): IO[PresentationError, PresentationPayload] = {
Expand All @@ -238,22 +242,22 @@ private class PresentationServiceImpl(
PresentationError.PresentationDecodingError,
Seq[JwtVerifiableCredentialPayload | AnoncredVerifiableCredentialPayload]
] =
issuedCredentials.map { issuedCredential =>
issuedCredential.format match {
case CredentialFormat.PrismJWT =>
decode[io.iohk.atala.mercury.model.Base64](issuedCredential.signedCredential)
issuedCredentials.map { signedCredential =>
format match {
case CredentialFormat.JWT =>
decode[io.iohk.atala.mercury.model.Base64](signedCredential)
.flatMap(x => Right(new String(java.util.Base64.getDecoder().decode(x.base64))))
.flatMap(x => Right(JwtVerifiableCredentialPayload(JWT(x))))
.left
.map(err => PresentationDecodingError(new Throwable(s"JsonData decoding error: $err")))
case CredentialFormat.PrismAnoncred =>
decode[io.iohk.atala.mercury.model.Base64](issuedCredential.signedCredential)
case CredentialFormat.AnonCreds =>
decode[io.iohk.atala.mercury.model.Base64](signedCredential)
.flatMap(x => Right(new String(java.util.Base64.getDecoder().decode(x.base64))))
.flatMap(x => Right(AnoncredVerifiableCredentialPayload(x)))
.left
.map(err => PresentationDecodingError(new Throwable(s"JsonData decoding error: $err")))
case CredentialFormat.UnsupportedCredentialFormat(otherFormat) =>
Left(PresentationDecodingError(new Throwable(s"This is a UnsupportedCredentialFormat: $otherFormat")))
// case CredentialFormat.Unsupported(otherFormat) =>
// Left(PresentationDecodingError(new Throwable(s"This is a UnsupportedCredentialFormat: $otherFormat")))
}
}.sequence

Expand Down Expand Up @@ -327,13 +331,15 @@ private class PresentationServiceImpl(
.map(_.subjectId)}"
)
)
issuedRawCredentials = issuedValidCredentials.flatMap(
_.issuedCredentialRaw.map(data => IssuedCredentialRaw(signedCredential = data, format = ???)) // FIXME
)
signedCredentials = issuedValidCredentials.flatMap(_.issuedCredentialRaw)
// record.credentialFormat match {
// case PresentationRecord.CredentialFormat.JWT => issuedRawCredentials
// case CredentialFormat.AnonCreds => issuedRawCredentials
// }
issuedCredentials <- ZIO.fromEither(
Either.cond(
issuedRawCredentials.nonEmpty,
issuedRawCredentials,
signedCredentials.nonEmpty,
signedCredentials,
PresentationError.IssuedCredentialNotFoundError(
new Throwable(s"No matching issued credentials found in prover db from the given: $credentialsToUse")
)
Expand Down

0 comments on commit 1b2f1f9

Please sign in to comment.