From 359d255404bb4720f93b26469cca943ac4f81831 Mon Sep 17 00:00:00 2001 From: FabioPinheiro Date: Mon, 11 Sep 2023 15:49:13 +0100 Subject: [PATCH] Make pollux compile --- .../pollux/core/model/CredentialFormat.scala | 5 ++ .../core/model/IssueCredentialRecord.scala | 4 -- .../core/model/IssuedCredentialRaw.scala | 7 --- .../core/model/PresentationRecord.scala | 2 + .../core/service/CredentialService.scala | 1 - .../core/service/CredentialServiceImpl.scala | 11 ++-- .../service/CredentialServiceNotifier.scala | 3 +- .../core/service/MockCredentialService.scala | 3 +- .../service/PresentationServiceImpl.scala | 50 +++++++++++-------- 9 files changed, 40 insertions(+), 46 deletions(-) create mode 100644 pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/CredentialFormat.scala delete mode 100644 pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/IssuedCredentialRaw.scala diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/CredentialFormat.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/CredentialFormat.scala new file mode 100644 index 0000000000..bc384c299a --- /dev/null +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/CredentialFormat.scala @@ -0,0 +1,5 @@ +package io.iohk.atala.pollux.core.model + +enum CredentialFormat: + case JWT extends CredentialFormat + case AnonCreds extends CredentialFormat diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/IssueCredentialRecord.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/IssueCredentialRecord.scala index de39ffd8ec..ff25367903 100644 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/IssueCredentialRecord.scala +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/IssueCredentialRecord.scala @@ -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 diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/IssuedCredentialRaw.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/IssuedCredentialRaw.scala deleted file mode 100644 index 5068760821..0000000000 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/IssuedCredentialRaw.scala +++ /dev/null @@ -1,7 +0,0 @@ -//FIXME REMOVE -// package io.iohk.atala.pollux.core.model - -// final case class IssuedCredentialRaw( -// signedCredential: String, -// format: CredentialOfferFormat -// ) 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 b16c068ec6..eb2a93d15f 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 @@ -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, @@ -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], diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialService.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialService.scala index deaf33d046..eddfcfe1d9 100644 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialService.scala +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialService.scala @@ -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} diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialServiceImpl.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialServiceImpl.scala index 4c075ec76d..be07f55e68 100644 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialServiceImpl.scala +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialServiceImpl.scala @@ -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.* @@ -536,16 +536,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( @@ -574,18 +571,16 @@ 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() + format = Some(IssueCredentialOfferFormat.Anoncred.name), + payload = offer.data.getBytes() ) ) } diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialServiceNotifier.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialServiceNotifier.scala index 1b3ddf6912..230d5141a9 100644 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialServiceNotifier.scala +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialServiceNotifier.scala @@ -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 diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/MockCredentialService.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/MockCredentialService.scala index c3155aeae5..35c4fd5804 100644 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/MockCredentialService.scala +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/MockCredentialService.scala @@ -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} diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/PresentationServiceImpl.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/PresentationServiceImpl.scala index 98671f3626..14e7031209 100644 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/PresentationServiceImpl.scala +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/PresentationServiceImpl.scala @@ -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 } @@ -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, @@ -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, @@ -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] = { @@ -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 @@ -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") )