From d8e21201f2b07cd03afbba8fb668329105048ba2 Mon Sep 17 00:00:00 2001 From: Fabio Pinheiro Date: Fri, 14 Jun 2024 12:15:32 +0100 Subject: [PATCH] feat: Integrate ZIO failures and defects ADR in DID Registrar Controller and Mercury (#1180) Related with the tickets ATL-6831 and parcial for ATL-7257 Signed-off-by: FabioPinheiro --- .../castor/core/service/DIDService.scala | 4 +- .../core/util/DIDOperationValidator.scala | 19 +++--- .../controller/DIDRegistrarController.scala | 30 ++++----- .../DIDRegistrarServerEndpoints.scala | 12 ++-- .../controller/DIDCommController.scala | 2 +- .../controller/DIDCommControllerImpl.scala | 22 ++++--- .../controller/DIDCommServerEndpoints.scala | 2 +- ...dDIDServiceWithEventNotificationImpl.scala | 1 - .../issuecredential/IssueCredential.scala | 65 ++++++++++--------- .../issuecredential/OfferCredential.scala | 35 ++++++---- .../issuecredential/RequestCredential.scala | 49 +++++++------- .../UtilsCredentialSpec.scala | 54 ++++++++------- .../RevocationNotification.scala | 34 ++++++---- .../CredentialRepositorySpecSuite.scala | 15 +++-- .../service/CredentialServiceImplSpec.scala | 20 ++++-- .../service/PresentationServiceSpec.scala | 20 ++++-- 16 files changed, 218 insertions(+), 166 deletions(-) diff --git a/castor/src/main/scala/org/hyperledger/identus/castor/core/service/DIDService.scala b/castor/src/main/scala/org/hyperledger/identus/castor/core/service/DIDService.scala index 5e8358e7e6..e0fc3cb2c6 100644 --- a/castor/src/main/scala/org/hyperledger/identus/castor/core/service/DIDService.scala +++ b/castor/src/main/scala/org/hyperledger/identus/castor/core/service/DIDService.scala @@ -44,9 +44,7 @@ private class DIDServiceImpl(didOpValidator: DIDOperationValidator, nodeClient: override def scheduleOperation( signedOperation: SignedPrismDIDOperation ): IO[DIDOperationError, ScheduleDIDOperationOutcome] = { - val operationRequest = node_api.ScheduleOperationsRequest( - signedOperations = Seq(signedOperation.toProto) - ) + val operationRequest = node_api.ScheduleOperationsRequest(signedOperations = Seq(signedOperation.toProto)) for { _ <- ZIO .fromEither(didOpValidator.validate(signedOperation.operation)) diff --git a/castor/src/main/scala/org/hyperledger/identus/castor/core/util/DIDOperationValidator.scala b/castor/src/main/scala/org/hyperledger/identus/castor/core/util/DIDOperationValidator.scala index fbeab5d5c6..8de4e44269 100644 --- a/castor/src/main/scala/org/hyperledger/identus/castor/core/util/DIDOperationValidator.scala +++ b/castor/src/main/scala/org/hyperledger/identus/castor/core/util/DIDOperationValidator.scala @@ -83,15 +83,15 @@ private object CreateOperationValidator extends BaseOperationValidator { case InternalPublicKey(id, purpose, data) => (id, purpose, data) } - private def extractServiceIds(operation: PrismDIDOperation.Create): Seq[String] = operation.services.map(_.id) + private def extractServiceIds(operation: PrismDIDOperation.Create): Seq[String] = + operation.services.map(_.id) - private def extractServiceEndpoint(operation: PrismDIDOperation.Create): Seq[(String, ServiceEndpoint)] = { + private def extractServiceEndpoint(operation: PrismDIDOperation.Create): Seq[(String, ServiceEndpoint)] = operation.services.map { s => (s.id, s.serviceEndpoint) } - } - private def extractServiceType(operation: PrismDIDOperation.Create): Seq[(String, ServiceType)] = { + private def extractServiceType(operation: PrismDIDOperation.Create): Seq[(String, ServiceType)] = operation.services.map { s => (s.id, s.`type`) } - } + } private object UpdateOperationValidator extends BaseOperationValidator { @@ -346,16 +346,13 @@ private trait BaseOperationValidator { protected def validatePreviousOperationHash[T <: PrismDIDOperation]( operation: T, previousOperationHashExtractor: T => ArraySeq[Byte] - ): Either[OperationValidationError, Unit] = { - val previousOperationHash = previousOperationHashExtractor(operation) - if (previousOperationHash.length == 32) Right(()) + ): Either[OperationValidationError, Unit] = + if (previousOperationHashExtractor(operation).length == 32) Right(()) else Left(OperationValidationError.InvalidArgument(s"previousOperationHash must have a size of 32 bytes")) - } /** @return true if a given uri is normalized */ - protected def isUriNormalized(uri: String): Boolean = { + protected def isUriNormalized(uri: String): Boolean = UriUtils.normalizeUri(uri).contains(uri) - } protected def validateMasterKeyIsSecp256k1[T <: PrismDIDOperation]( operation: T, diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/controller/DIDRegistrarController.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/controller/DIDRegistrarController.scala index e32d88012f..6db15a9d35 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/controller/DIDRegistrarController.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/controller/DIDRegistrarController.scala @@ -27,25 +27,25 @@ import zio.* import scala.language.implicitConversions trait DIDRegistrarController { - def listManagedDid(paginationInput: PaginationInput)(implicit + def listManagedDid(paginationInput: PaginationInput)(using rc: RequestContext ): ZIO[WalletAccessContext, ErrorResponse, ManagedDIDPage] - def createManagedDid(request: CreateManagedDidRequest)(implicit + def createManagedDid(request: CreateManagedDidRequest)(using rc: RequestContext ): ZIO[WalletAccessContext, ErrorResponse, CreateManagedDIDResponse] - def getManagedDid(did: String)(implicit rc: RequestContext): ZIO[WalletAccessContext, ErrorResponse, ManagedDID] + def getManagedDid(did: String)(using rc: RequestContext): ZIO[WalletAccessContext, ErrorResponse, ManagedDID] - def publishManagedDid(did: String)(implicit + def publishManagedDid(did: String)(using rc: RequestContext ): ZIO[WalletAccessContext, ErrorResponse, DIDOperationResponse] - def updateManagedDid(did: String, updateRequest: UpdateManagedDIDRequest)(implicit + def updateManagedDid(did: String, updateRequest: UpdateManagedDIDRequest)(using rc: RequestContext ): ZIO[WalletAccessContext, ErrorResponse, DIDOperationResponse] - def deactivateManagedDid(did: String)(implicit + def deactivateManagedDid(did: String)(using rc: RequestContext ): ZIO[WalletAccessContext, ErrorResponse, DIDOperationResponse] } @@ -55,14 +55,14 @@ object DIDRegistrarController { case GetManagedDIDError.OperationError(e) => ErrorResponse.internalServerError(detail = Some(e.toString)) case GetManagedDIDError.WalletStorageError(e) => - ErrorResponse.internalServerError(detail = Some(e.toString)) + ErrorResponse.internalServerError(detail = Some(e.getMessage)) } given Conversion[CreateManagedDIDError, ErrorResponse] = { case CreateManagedDIDError.InvalidArgument(msg) => ErrorResponse.unprocessableEntity(detail = Some(msg)) case CreateManagedDIDError.WalletStorageError(e) => - ErrorResponse.internalServerError(detail = Some(e.toString)) + ErrorResponse.internalServerError(detail = Some(e.getMessage)) case CreateManagedDIDError.InvalidOperation(e) => ErrorResponse.unprocessableEntity(detail = Some(e.toString)) } @@ -71,7 +71,7 @@ object DIDRegistrarController { case PublishManagedDIDError.DIDNotFound(did) => ErrorResponse.notFound(detail = Some(s"DID not found: $did")) case PublishManagedDIDError.WalletStorageError(e) => - ErrorResponse.internalServerError(detail = Some(e.toString)) + ErrorResponse.internalServerError(detail = Some(e.getMessage)) case PublishManagedDIDError.OperationError(e) => ErrorResponse.internalServerError(detail = Some(e.toString)) case PublishManagedDIDError.CryptographyError(e) => @@ -99,7 +99,7 @@ class DIDRegistrarControllerImpl(service: ManagedDIDService) extends DIDRegistra override def listManagedDid( paginationInput: PaginationInput - )(implicit rc: RequestContext): ZIO[WalletAccessContext, ErrorResponse, ManagedDIDPage] = { + )(using rc: RequestContext): ZIO[WalletAccessContext, ErrorResponse, ManagedDIDPage] = { val uri = rc.request.uri val pagination = paginationInput.toPagination for { @@ -117,7 +117,7 @@ class DIDRegistrarControllerImpl(service: ManagedDIDService) extends DIDRegistra ) } - override def createManagedDid(createManagedDidRequest: CreateManagedDidRequest)(implicit + override def createManagedDid(createManagedDidRequest: CreateManagedDidRequest)(using rc: RequestContext ): ZIO[WalletAccessContext, ErrorResponse, CreateManagedDIDResponse] = { for { @@ -132,7 +132,7 @@ class DIDRegistrarControllerImpl(service: ManagedDIDService) extends DIDRegistra override def getManagedDid( did: String - )(implicit rc: RequestContext): ZIO[WalletAccessContext, ErrorResponse, ManagedDID] = { + )(using rc: RequestContext): ZIO[WalletAccessContext, ErrorResponse, ManagedDID] = { for { prismDID <- extractPrismDID(did) didDetail <- service @@ -145,7 +145,7 @@ class DIDRegistrarControllerImpl(service: ManagedDIDService) extends DIDRegistra override def publishManagedDid( did: String - )(implicit rc: RequestContext): ZIO[WalletAccessContext, ErrorResponse, DIDOperationResponse] = { + )(using rc: RequestContext): ZIO[WalletAccessContext, ErrorResponse, DIDOperationResponse] = { for { prismDID <- extractPrismDID(did) outcome <- service @@ -154,7 +154,7 @@ class DIDRegistrarControllerImpl(service: ManagedDIDService) extends DIDRegistra } yield outcome } - override def updateManagedDid(did: String, updateRequest: UpdateManagedDIDRequest)(implicit + override def updateManagedDid(did: String, updateRequest: UpdateManagedDIDRequest)(using rc: RequestContext ): ZIO[WalletAccessContext, ErrorResponse, DIDOperationResponse] = { for { @@ -170,7 +170,7 @@ class DIDRegistrarControllerImpl(service: ManagedDIDService) extends DIDRegistra override def deactivateManagedDid( did: String - )(implicit rc: RequestContext): ZIO[WalletAccessContext, ErrorResponse, DIDOperationResponse] = { + )(using rc: RequestContext): ZIO[WalletAccessContext, ErrorResponse, DIDOperationResponse] = { for { prismDID <- extractPrismDID(did) outcome <- service diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/controller/DIDRegistrarServerEndpoints.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/controller/DIDRegistrarServerEndpoints.scala index fe76416d9f..460365426a 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/controller/DIDRegistrarServerEndpoints.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/controller/DIDRegistrarServerEndpoints.scala @@ -19,7 +19,7 @@ class DIDRegistrarServerEndpoints( .serverLogic { wac => { case (rc, paginationInput) => didRegistrarController - .listManagedDid(paginationInput)(rc) + .listManagedDid(paginationInput)(using rc) .provideSomeLayer(ZLayer.succeed(wac)) .logTrace(rc) } @@ -31,7 +31,7 @@ class DIDRegistrarServerEndpoints( .serverLogic { wac => { case (rc, createManagedDidRequest) => didRegistrarController - .createManagedDid(createManagedDidRequest)(rc) + .createManagedDid(createManagedDidRequest)(using rc) .provideSomeLayer(ZLayer.succeed(wac)) .logTrace(rc) } @@ -43,7 +43,7 @@ class DIDRegistrarServerEndpoints( .serverLogic { wac => { case (rc, did) => didRegistrarController - .getManagedDid(did)(rc) + .getManagedDid(did)(using rc) .provideSomeLayer(ZLayer.succeed(wac)) .logTrace(rc) } @@ -55,7 +55,7 @@ class DIDRegistrarServerEndpoints( .serverLogic { wac => { case (rc, did) => didRegistrarController - .publishManagedDid(did)(rc) + .publishManagedDid(did)(using rc) .provideSomeLayer(ZLayer.succeed(wac)) .logTrace(rc) } @@ -67,7 +67,7 @@ class DIDRegistrarServerEndpoints( .serverLogic { wac => { case (rc, did, updateRequest) => didRegistrarController - .updateManagedDid(did, updateRequest)(rc) + .updateManagedDid(did, updateRequest)(using rc) .provideSomeLayer(ZLayer.succeed(wac)) .logTrace(rc) } @@ -79,7 +79,7 @@ class DIDRegistrarServerEndpoints( .serverLogic { wac => { case (rc, did) => didRegistrarController - .deactivateManagedDid(did)(rc) + .deactivateManagedDid(did)(using rc) .provideSomeLayer(ZLayer.succeed(wac)) .logTrace(rc) } diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommController.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommController.scala index 03d715dd41..2a57dd80a6 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommController.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommController.scala @@ -5,5 +5,5 @@ import org.hyperledger.identus.didcomm.controller.http.DIDCommMessage import zio.IO trait DIDCommController { - def handleDIDCommMessage(msg: DIDCommMessage)(implicit rc: RequestContext): IO[ErrorResponse, Unit] + def handleDIDCommMessage(msg: DIDCommMessage)(using rc: RequestContext): IO[ErrorResponse, Unit] } diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommControllerImpl.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommControllerImpl.scala index b1e4b7ac4d..feef2638ce 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommControllerImpl.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommControllerImpl.scala @@ -35,7 +35,7 @@ class DIDCommControllerImpl( appConfig: AppConfig ) extends DIDCommController { - override def handleDIDCommMessage(msg: DIDCommMessage)(implicit rc: RequestContext): IO[ErrorResponse, Unit] = { + override def handleDIDCommMessage(msg: DIDCommMessage)(using rc: RequestContext): IO[ErrorResponse, Unit] = { for { _ <- validateContentType(rc.request.contentType) _ <- handleMessage(msg) @@ -53,10 +53,8 @@ class DIDCommControllerImpl( msgAndContext <- unpackMessage(msg) _ <- processMessage(msgAndContext._1) .catchAll { - case t: Throwable => ZIO.die(t) // Convert any 'Throwable' failure to a defect case f: Failure => ZIO.fail(f) case _: DIDCommMessageParsingError => ZIO.fail(UnexpectedError(StatusCode.BadRequest)) - case _: CredentialServiceError => ZIO.fail(UnexpectedError(StatusCode.UnprocessableContent)) case _: PresentationError => ZIO.fail(UnexpectedError(StatusCode.UnprocessableContent)) } .provideSomeLayer(ZLayer.succeed(msgAndContext._2)) @@ -126,19 +124,25 @@ class DIDCommControllerImpl( : PartialFunction[Message, ZIO[WalletAccessContext, CredentialServiceError, Unit]] = { case msg if msg.piuri == OfferCredential.`type` => for { - offerFromIssuer <- ZIO.succeed(OfferCredential.readFromMessage(msg)) + offerFromIssuer <- ZIO + .fromEither(OfferCredential.readFromMessage(msg)) + .mapError(CredentialServiceError.InvalidCredentialOffer(_)) _ <- ZIO.logInfo("As an Holder in issue-credential got OfferCredential: " + offerFromIssuer) _ <- credentialService.receiveCredentialOffer(offerFromIssuer) } yield () case msg if msg.piuri == RequestCredential.`type` => for { - requestCredential <- ZIO.succeed(RequestCredential.readFromMessage(msg)) + requestCredential <- ZIO + .fromEither(RequestCredential.readFromMessage(msg)) + .mapError(CredentialServiceError.InvalidCredentialRequest(_)) _ <- ZIO.logInfo("As an Issuer in issue-credential got RequestCredential: " + requestCredential) _ <- credentialService.receiveCredentialRequest(requestCredential) } yield () case msg if msg.piuri == IssueCredential.`type` => for { - issueCredential <- ZIO.succeed(IssueCredential.readFromMessage(msg)) + issueCredential <- ZIO + .fromEither(IssueCredential.readFromMessage(msg)) + .mapError(CredentialServiceError.InvalidCredentialIssue(_)) _ <- ZIO.logInfo("As an Holder in issue-credential got IssueCredential: " + issueCredential) _ <- credentialService.receiveCredentialIssue(issueCredential) } yield () @@ -168,10 +172,12 @@ class DIDCommControllerImpl( } yield () } - private val revocationNotification: PartialFunction[Message, ZIO[Any, Throwable, Unit]] = { + private val revocationNotification: PartialFunction[Message, ZIO[Any, DIDCommMessageParsingError, Unit]] = { case msg if msg.piuri == RevocationNotification.`type` => for { - revocationNotification <- ZIO.attempt(RevocationNotification.readFromMessage(msg)) + revocationNotification <- ZIO + .fromEither(RevocationNotification.readFromMessage(msg)) + .mapError(DIDCommMessageParsingError(_)) _ <- ZIO.logInfo("Got RevocationNotification: " + revocationNotification) } yield () } diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommServerEndpoints.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommServerEndpoints.scala index 0b6472c23b..dd72de568d 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommServerEndpoints.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/didcomm/controller/DIDCommServerEndpoints.scala @@ -10,7 +10,7 @@ class DIDCommServerEndpoints( ) { private val handleDIDCommMessageServerEndpoint: ZServerEndpoint[Any, Any] = DIDCommEndpoints.handleDIDCommMessage .zServerLogic { case (ctx: RequestContext, msg: DIDCommMessage) => - didCommController.handleDIDCommMessage(msg)(ctx) + didCommController.handleDIDCommMessage(msg)(using ctx) } val all: List[ZServerEndpoint[Any, Any]] = List(handleDIDCommMessageServerEndpoint) diff --git a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceWithEventNotificationImpl.scala b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceWithEventNotificationImpl.scala index a0cb4e55e6..782ee6d9ec 100644 --- a/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceWithEventNotificationImpl.scala +++ b/cloud-agent/service/wallet-api/src/main/scala/org/hyperledger/identus/agent/walletapi/service/ManagedDIDServiceWithEventNotificationImpl.scala @@ -4,7 +4,6 @@ import org.hyperledger.identus.agent.walletapi.model.error.CommonWalletStorageEr import org.hyperledger.identus.agent.walletapi.model.ManagedDIDDetail import org.hyperledger.identus.agent.walletapi.storage.{DIDNonSecretStorage, DIDSecretStorage, WalletSecretStorage} import org.hyperledger.identus.castor.core.model.did.CanonicalPrismDID -import org.hyperledger.identus.castor.core.model.error import org.hyperledger.identus.castor.core.model.error.DIDOperationError import org.hyperledger.identus.castor.core.service.DIDService import org.hyperledger.identus.castor.core.util.DIDOperationValidator diff --git a/mercury/protocol-issue-credential/src/main/scala/org/hyperledger/identus/mercury/protocol/issuecredential/IssueCredential.scala b/mercury/protocol-issue-credential/src/main/scala/org/hyperledger/identus/mercury/protocol/issuecredential/IssueCredential.scala index a3c439a2c5..25b97a9772 100644 --- a/mercury/protocol-issue-credential/src/main/scala/org/hyperledger/identus/mercury/protocol/issuecredential/IssueCredential.scala +++ b/mercury/protocol-issue-credential/src/main/scala/org/hyperledger/identus/mercury/protocol/issuecredential/IssueCredential.scala @@ -73,36 +73,43 @@ object IssueCredential { given Decoder[Body] = deriveDecoder[Body] } - def makeIssueCredentialFromRequestCredential(msg: Message): IssueCredential = { - val rc: RequestCredential = RequestCredential.readFromMessage(msg) + def makeIssueCredentialFromRequestCredential(msg: Message): Either[String, IssueCredential] = + RequestCredential.readFromMessage(msg).map { rc => + IssueCredential( + body = IssueCredential.Body( + goal_code = rc.body.goal_code, + comment = rc.body.comment, + replacement_id = None, + more_available = None, + ), + attachments = rc.attachments, + thid = msg.thid.orElse(Some(rc.id)), + from = rc.to, + to = rc.from, + ) + } - IssueCredential( - body = IssueCredential.Body( - goal_code = rc.body.goal_code, - comment = rc.body.comment, - replacement_id = None, - more_available = None, - ), - attachments = rc.attachments, - thid = msg.thid.orElse(Some(rc.id)), - from = rc.to, - to = rc.from, - ) + def readFromMessage(message: Message): Either[String, IssueCredential] = { + message.body.asJson.as[IssueCredential.Body] match + case Left(fail) => Left("Fail to parse IssueCredential's body: " + fail.getMessage) + case Right(body) => + message.from match + case None => Left("IssueCredential MUST have the sender explicit") + case Some(from) => + message.to match + case firstTo +: Seq() => + Right( + IssueCredential( + id = message.id, + `type` = message.piuri, + body = body, + attachments = message.attachments.getOrElse(Seq.empty), + thid = message.thid, + from = from, + to = firstTo + ) + ) + case tos => Left(s"IssueCredential MUST have only 1 recipient instead has '${tos}'") } - def readFromMessage(message: Message): IssueCredential = { - val body = message.body.asJson.as[IssueCredential.Body].toOption.get // TODO get - IssueCredential( - id = message.id, - `type` = message.piuri, - body = body, - attachments = message.attachments.getOrElse(Seq.empty), - thid = message.thid, - from = message.from.get, // TODO get - to = { - assert(message.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") // TODO return error - message.to.head - }, - ) - } } diff --git a/mercury/protocol-issue-credential/src/main/scala/org/hyperledger/identus/mercury/protocol/issuecredential/OfferCredential.scala b/mercury/protocol-issue-credential/src/main/scala/org/hyperledger/identus/mercury/protocol/issuecredential/OfferCredential.scala index 5848e5fe12..c60054d9bc 100644 --- a/mercury/protocol-issue-credential/src/main/scala/org/hyperledger/identus/mercury/protocol/issuecredential/OfferCredential.scala +++ b/mercury/protocol-issue-credential/src/main/scala/org/hyperledger/identus/mercury/protocol/issuecredential/OfferCredential.scala @@ -99,19 +99,26 @@ object OfferCredential { ) } - def readFromMessage(message: Message): OfferCredential = { - val body = message.body.asJson.as[OfferCredential.Body].toOption.get // TODO get - OfferCredential( - id = message.id, - `type` = message.piuri, - body = body, - attachments = message.attachments.getOrElse(Seq.empty), - thid = message.thid, - from = message.from.get, // TODO get - to = { - assert(message.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") // TODO return error - message.to.head - }, - ) + def readFromMessage(message: Message): Either[String, OfferCredential] = { + message.body.asJson.as[OfferCredential.Body] match + case Left(fail) => Left("Fail to parse OfferCredential's body: " + fail.getMessage) + case Right(body) => + message.from match + case None => Left("OfferCredential MUST have the sender explicit") + case Some(from) => + message.to match + case firstTo +: Seq() => + Right( + OfferCredential( + id = message.id, + `type` = message.piuri, + body = body, + attachments = message.attachments.getOrElse(Seq.empty), + thid = message.thid, + from = from, + to = firstTo, + ) + ) + case tos => Left(s"OfferCredential MUST have only 1 recipient instead has '${tos}'") } } diff --git a/mercury/protocol-issue-credential/src/main/scala/org/hyperledger/identus/mercury/protocol/issuecredential/RequestCredential.scala b/mercury/protocol-issue-credential/src/main/scala/org/hyperledger/identus/mercury/protocol/issuecredential/RequestCredential.scala index d4843d8a51..c800e89bcd 100644 --- a/mercury/protocol-issue-credential/src/main/scala/org/hyperledger/identus/mercury/protocol/issuecredential/RequestCredential.scala +++ b/mercury/protocol-issue-credential/src/main/scala/org/hyperledger/identus/mercury/protocol/issuecredential/RequestCredential.scala @@ -62,35 +62,36 @@ object RequestCredential { given Decoder[Body] = deriveDecoder[Body] } - def makeRequestCredentialFromOffer(msg: Message): RequestCredential = { // TODO change msg: Message to RequestCredential - val oc: OfferCredential = OfferCredential.readFromMessage(msg) - + def makeRequestCredentialFromOffer(oc: OfferCredential): RequestCredential = RequestCredential( - body = RequestCredential.Body( - goal_code = oc.body.goal_code, - comment = oc.body.comment, - ), + body = RequestCredential.Body(goal_code = oc.body.goal_code, comment = oc.body.comment), attachments = oc.attachments, - thid = msg.thid.orElse(Some(oc.id)), + thid = oc.thid.orElse(Some(oc.id)), from = oc.to, to = oc.from, ) - } - - def readFromMessage(message: Message): RequestCredential = - val body = message.body.asJson.as[RequestCredential.Body].toOption.get // TODO get - RequestCredential( - id = message.id, - `type` = message.piuri, - body = body, - attachments = message.attachments.getOrElse(Seq.empty), - thid = message.thid, - from = message.from.get, // TODO get - to = { - assert(message.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") // TODO return error - message.to.head - }, - ) + def readFromMessage(message: Message): Either[String, RequestCredential] = { + message.body.asJson.as[RequestCredential.Body] match + case Left(fail) => Left("Fail to parse RequestCredential's body: " + fail.getMessage) + case Right(body) => + message.from match + case None => Left("RequestCredential MUST have the sender explicit") + case Some(from) => + message.to match + case firstTo +: Seq() => + Right( + RequestCredential( + id = message.id, + `type` = message.piuri, + body = body, + attachments = message.attachments.getOrElse(Seq.empty), + thid = message.thid, + from = from, + to = firstTo, + ) + ) + case tos => Left(s"RequestCredential MUST have only 1 recipient instead has '${tos}'") + } } diff --git a/mercury/protocol-issue-credential/src/test/scala/org/hyperledger/identus/mercury/protocol/anotherclasspath/UtilsCredentialSpec.scala b/mercury/protocol-issue-credential/src/test/scala/org/hyperledger/identus/mercury/protocol/anotherclasspath/UtilsCredentialSpec.scala index 670320daf2..d8fbb4da22 100644 --- a/mercury/protocol-issue-credential/src/test/scala/org/hyperledger/identus/mercury/protocol/anotherclasspath/UtilsCredentialSpec.scala +++ b/mercury/protocol-issue-credential/src/test/scala/org/hyperledger/identus/mercury/protocol/anotherclasspath/UtilsCredentialSpec.scala @@ -54,14 +54,16 @@ class UtilsCredentialSpec extends ZSuite { ) .makeMessage - val obj = IssueCredential.readFromMessage(msg) - - assertEquals(obj.getCredentialFormatAndCredential.size, 1) - assertEquals( - obj.getCredentialFormatAndCredential.map(_._2), - Seq(IssueCredentialIssuedFormat.Unsupported(nameCredentialType).name) - ) - assertEquals(obj.getCredential[TestCredentialType](nameCredentialType).headOption, Some(credential)) + IssueCredential.readFromMessage(msg) match + case Left(value) => fail("Must Have not error reading message") + case Right(obj) => { + assertEquals(obj.getCredentialFormatAndCredential.size, 1) + assertEquals( + obj.getCredentialFormatAndCredential.map(_._2), + Seq(IssueCredentialIssuedFormat.Unsupported(nameCredentialType).name) + ) + assertEquals(obj.getCredential[TestCredentialType](nameCredentialType).headOption, Some(credential)) + } } test("OfferCredential encode and decode any type of Credential into the attachments") { @@ -76,14 +78,16 @@ class UtilsCredentialSpec extends ZSuite { ) .makeMessage - val obj = OfferCredential.readFromMessage(msg) - - assertEquals(obj.getCredentialFormatAndCredential.size, 1) - assertEquals( - obj.getCredentialFormatAndCredential.map(_._2), - Seq(IssueCredentialOfferFormat.Unsupported(nameCredentialType).name) - ) - assertEquals(obj.getCredential[TestCredentialType](nameCredentialType).headOption, Some(credential)) + OfferCredential.readFromMessage(msg) match + case Left(value) => fail("Must Have not error reading message") + case Right(obj) => { + assertEquals(obj.getCredentialFormatAndCredential.size, 1) + assertEquals( + obj.getCredentialFormatAndCredential.map(_._2), + Seq(IssueCredentialOfferFormat.Unsupported(nameCredentialType).name) + ) + assertEquals(obj.getCredential[TestCredentialType](nameCredentialType).headOption, Some(credential)) + } } test("ProposeCredential encode and decode any type of Credential into the attachments") { @@ -119,13 +123,15 @@ class UtilsCredentialSpec extends ZSuite { ) .makeMessage - val obj = RequestCredential.readFromMessage(msg) - - assertEquals(obj.getCredentialFormatAndCredential.size, 1) - assertEquals( - obj.getCredentialFormatAndCredential.map(_._2), - Seq(IssueCredentialRequestFormat.Unsupported(nameCredentialType).name) - ) - assertEquals(obj.getCredential[TestCredentialType](nameCredentialType).headOption, Some(credential)) + RequestCredential.readFromMessage(msg) match + case Left(value) => fail("Must Have not error reading message") + case Right(obj) => { + assertEquals(obj.getCredentialFormatAndCredential.size, 1) + assertEquals( + obj.getCredentialFormatAndCredential.map(_._2), + Seq(IssueCredentialRequestFormat.Unsupported(nameCredentialType).name) + ) + assertEquals(obj.getCredential[TestCredentialType](nameCredentialType).headOption, Some(credential)) + } } } diff --git a/mercury/protocol-revocation-notification/src/main/scala/org/hyperledger/identus/mercury/protocol/revocationnotificaiton/RevocationNotification.scala b/mercury/protocol-revocation-notification/src/main/scala/org/hyperledger/identus/mercury/protocol/revocationnotificaiton/RevocationNotification.scala index cecdcc7360..be73af85c4 100644 --- a/mercury/protocol-revocation-notification/src/main/scala/org/hyperledger/identus/mercury/protocol/revocationnotificaiton/RevocationNotification.scala +++ b/mercury/protocol-revocation-notification/src/main/scala/org/hyperledger/identus/mercury/protocol/revocationnotificaiton/RevocationNotification.scala @@ -58,19 +58,25 @@ object RevocationNotification { given Decoder[Body] = deriveDecoder[Body] } - def readFromMessage(message: Message): RevocationNotification = - val body = message.body.asJson.as[RevocationNotification.Body].toOption.get - - RevocationNotification( - id = message.id, - `type` = message.piuri, - body = body, - thid = message.thid, - from = message.from.get, // TODO get - to = { - assert(message.to.length == 1, "The recipient is ambiguous. Need to have only 1 recipient") - message.to.head - }, - ) + def readFromMessage(message: Message): Either[String, RevocationNotification] = + message.body.asJson.as[RevocationNotification.Body] match + case Left(fail) => Left("Fail to parse RevocationNotification's body: " + fail.getMessage) + case Right(body) => + message.from match + case None => Left("OfferCredential MUST have the sender explicit") + case Some(from) => + message.to match + case firstTo +: Seq() => + Right( + RevocationNotification( + id = message.id, + `type` = message.piuri, + body = body, + thid = message.thid, + from = from, + to = firstTo, + ) + ) + case tos => Left(s"OfferCredential MUST have only 1 recipient instead has '${tos}'") } diff --git a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/repository/CredentialRepositorySpecSuite.scala b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/repository/CredentialRepositorySpecSuite.scala index c54e93e90d..6ca9741f80 100644 --- a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/repository/CredentialRepositorySpecSuite.scala +++ b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/repository/CredentialRepositorySpecSuite.scala @@ -255,9 +255,12 @@ object CredentialRepositorySpecSuite { _ <- repo.create(bRecord) _ <- repo.create(cRecord) _ <- repo.create(dRecord) + issueCredential <- ZIO.fromEither( + IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage) + ) _ <- repo.updateWithIssuedRawCredential( aRecord.id, - IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage), + issueCredential, "RAW_CREDENTIAL_DATA", None, None, @@ -265,7 +268,7 @@ object CredentialRepositorySpecSuite { ) _ <- repo.updateWithIssuedRawCredential( dRecord.id, - IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage), + issueCredential, "RAW_CREDENTIAL_DATA", None, None, @@ -343,7 +346,9 @@ object CredentialRepositorySpecSuite { aRecord = issueCredentialRecord(CredentialFormat.JWT) _ <- repo.create(aRecord) record <- repo.findById(aRecord.id) - issueCredential = IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage) + issueCredential <- ZIO.fromEither( + IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage) + ) _ <- repo.updateWithIssueCredential(aRecord.id, issueCredential, ProtocolState.CredentialPending) updatedRecord <- repo.findById(aRecord.id) } yield { @@ -357,7 +362,9 @@ object CredentialRepositorySpecSuite { aRecord = issueCredentialRecord(CredentialFormat.JWT) _ <- repo.create(aRecord) record <- repo.findById(aRecord.id) - issueCredential = IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage) + issueCredential <- ZIO.fromEither( + IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage) + ) _ <- repo.updateWithIssuedRawCredential( aRecord.id, issueCredential, diff --git a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImplSpec.scala b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImplSpec.scala index 8545ab52e4..9e114213d8 100644 --- a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImplSpec.scala +++ b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/CredentialServiceImplSpec.scala @@ -502,7 +502,8 @@ object CredentialServiceImplSpec extends MockSpecDefault with CredentialServiceS _ <- issuerSvc.markOfferSent(issuerRecordId) msg <- ZIO.fromEither(offerCreatedRecord.offerCredentialData.get.makeMessage.asJson.as[Message]) // Holder receives offer - offerReceivedRecord <- holderSvc.receiveCredentialOffer(OfferCredential.readFromMessage(msg)) + offerCredential <- ZIO.fromEither(OfferCredential.readFromMessage(msg)) + offerReceivedRecord <- holderSvc.receiveCredentialOffer(offerCredential) holderRecordId = offerReceivedRecord.id subjectId = "did:prism:60821d6833158c93fde5bb6a40d69996a683bf1fa5cdf32c458395b2887597c3" // Holder accepts offer @@ -513,7 +514,8 @@ object CredentialServiceImplSpec extends MockSpecDefault with CredentialServiceS _ <- holderSvc.markRequestSent(holderRecordId) msg <- ZIO.fromEither(requestGeneratedRecord.requestCredentialData.get.makeMessage.asJson.as[Message]) // Issuer receives request - requestReceivedRecord <- issuerSvc.receiveCredentialRequest(RequestCredential.readFromMessage(msg)) + requestCredential <- ZIO.fromEither(RequestCredential.readFromMessage(msg)) + requestReceivedRecord <- issuerSvc.receiveCredentialRequest(requestCredential) // Issuer accepts request requestAcceptedRecord <- issuerSvc.acceptCredentialRequest(issuerRecordId) // Issuer generates credential @@ -525,7 +527,8 @@ object CredentialServiceImplSpec extends MockSpecDefault with CredentialServiceS _ <- issuerSvc.markCredentialSent(issuerRecordId) msg <- ZIO.fromEither(credentialGenerateRecord.issueCredentialData.get.makeMessage.asJson.as[Message]) // Holder receives credential - _ <- holderSvc.receiveCredentialIssue(IssueCredential.readFromMessage(msg)) + issueCredential <- ZIO.fromEither(IssueCredential.readFromMessage(msg)) + _ <- holderSvc.receiveCredentialIssue(issueCredential) } yield assertTrue(true) }.provideSomeLayer( (holderDidServiceExpectations ++ issuerDidServiceExpectations).toLayer @@ -577,7 +580,8 @@ object CredentialServiceImplSpec extends MockSpecDefault with CredentialServiceS ResourceURIDereferencerImpl.layerWithExtraResources >>> credentialServiceLayer ) - offerReceivedRecord <- holderSvc.receiveCredentialOffer(OfferCredential.readFromMessage(msg)) + offerCredential <- ZIO.fromEither(OfferCredential.readFromMessage(msg)) + offerReceivedRecord <- holderSvc.receiveCredentialOffer(offerCredential) holderRecordId = offerReceivedRecord.id // Holder accepts offer _ <- holderSvc.acceptCredentialOffer(holderRecordId, None) @@ -587,7 +591,8 @@ object CredentialServiceImplSpec extends MockSpecDefault with CredentialServiceS _ <- holderSvc.markRequestSent(holderRecordId) msg <- ZIO.fromEither(requestGeneratedRecord.requestCredentialData.get.makeMessage.asJson.as[Message]) // Issuer receives request - _ <- issuerSvc.receiveCredentialRequest(RequestCredential.readFromMessage(msg)) + requestCredential <- ZIO.fromEither(RequestCredential.readFromMessage(msg)) + _ <- issuerSvc.receiveCredentialRequest(requestCredential) // Issuer accepts request _ <- issuerSvc.acceptCredentialRequest(issuerRecordId) // Issuer generates credential @@ -595,8 +600,9 @@ object CredentialServiceImplSpec extends MockSpecDefault with CredentialServiceS // Issuer sends credential _ <- issuerSvc.markCredentialSent(issuerRecordId) msg <- ZIO.fromEither(credentialGenerateRecord.issueCredentialData.get.makeMessage.asJson.as[Message]) - // Holder receives credential - record <- holderSvc.receiveCredentialIssue(IssueCredential.readFromMessage(msg)) + // Holder receives credential\ + issueCredential <- ZIO.fromEither(IssueCredential.readFromMessage(msg)) + record <- holderSvc.receiveCredentialIssue(issueCredential) } yield { assertTrue(record.issueCredentialData.isDefined) && assertTrue(record.issueCredentialData.get.attachments.nonEmpty) && diff --git a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceSpec.scala b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceSpec.scala index b1ff6d356b..6acf26211e 100644 --- a/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceSpec.scala +++ b/pollux/core/src/test/scala/org/hyperledger/identus/pollux/core/service/PresentationServiceSpec.scala @@ -228,9 +228,12 @@ object PresentationServiceSpec extends ZIOSpecDefault with PresentationServiceSp _ <- repo.create(aIssueCredentialRecord) rawCredentialData = """{"base64":"ZXlKaGJHY2lPaUpGVXpJMU5rc2lMQ0owZVhBaU9pSktWMVFpZlEuZXlKcFlYUWlPakUyTnprek1qYzROaklzSW1GMVpDSTZJbVJ2YldGcGJpSXNJbTV2Ym1ObElqb2lZMlk1T1RJMk56Z3RPREV3TmkwME1EZzVMV0UxWXprdE5tTmhObU0wWkRBMU1HVTBJaXdpZG5BaU9uc2lRR052Ym5SbGVIUWlPbHNpYUhSMGNITTZMeTkzZDNjdWR6TXViM0puTHpJd01UZ3ZjSEpsYzJWdWRHRjBhVzl1Y3k5Mk1TSmRMQ0owZVhCbElqcGJJbFpsY21sbWFXRmliR1ZRY21WelpXNTBZWFJwYjI0aVhYMHNJbWx6Y3lJNkltUnBaRHB3Y21semJUcGhaR0psT1RJNE9XUXdZelZtWWpVMlptWmhOVEF6T0Rka01UZ3dOR0ZpTkdFeE5UYzJOVEkzWXprME5tRTFNalV5T0RFM1ptRTRaVGhoTW1OalpXUXdPa056YzBKRGMyZENSVzFKUzBSWE1XaGpNMUpzWTJsb2NHSnRVbXhsUTJ0UlFWVktVRU5uYkZSYVYwNTNUV3BWTW1GNlJWTkpSUzFNYVVkTU0xRklaRlZ1VG10d1dXSkthSE5VYTIxWVVGaEpVM0ZXZWpjMll6RlZPWGhvVURseWNFZHBSSEZXTlRselJYcEtWbEpEYWxJMGEwMHdaMGg0YkhWUU5tVk5Ta2wwZHpJMk4yWllWbEpoTUhoRE5XaEthVU5uTVhSWldFNHdXbGhKYjJGWE5XdGFXR2R3UlVGU1ExUjNiMHBWTWxacVkwUkpNVTV0YzNoRmFVSlFhVFJvYVRrd1FqTldTbnBhUzFkSGVWbGlSVFZLYkhveGVVVnhiR010TFc1T1ZsQmpXVlJmWVRaU2IyYzJiR1ZtWWtKTmVWWlZVVzh3WlVwRVRrbENPRnBpYWkxdWFrTlRUR05PZFhVek1URlZWM1JOVVhWWkluMC5CcmFpbEVXa2VlSXhWbjY3dnpkVHZGTXpBMV9oNzFoaDZsODBHRFBpbkRaVVB4ajAxSC0tUC1QZDIxTk9wRDd3am51SDkxdUNBOFZMUW9fS2FnVjlnQQo="}""" + issueCredential <- ZIO.fromEither( + IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage) + ) _ <- repo.updateWithIssuedRawCredential( aIssueCredentialRecord.id, - IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage), + issueCredential, rawCredentialData, None, None, @@ -469,9 +472,12 @@ object PresentationServiceSpec extends ZIOSpecDefault with PresentationServiceSp _ <- repo.create(aIssueCredentialRecord) rawCredentialData = """{"base64":"ZXlKaGJHY2lPaUpGVXpJMU5rc2lMQ0owZVhBaU9pSktWMVFpZlEuZXlKcFlYUWlPakUyTnprek1qYzROaklzSW1GMVpDSTZJbVJ2YldGcGJpSXNJbTV2Ym1ObElqb2lZMlk1T1RJMk56Z3RPREV3TmkwME1EZzVMV0UxWXprdE5tTmhObU0wWkRBMU1HVTBJaXdpZG5BaU9uc2lRR052Ym5SbGVIUWlPbHNpYUhSMGNITTZMeTkzZDNjdWR6TXViM0puTHpJd01UZ3ZjSEpsYzJWdWRHRjBhVzl1Y3k5Mk1TSmRMQ0owZVhCbElqcGJJbFpsY21sbWFXRmliR1ZRY21WelpXNTBZWFJwYjI0aVhYMHNJbWx6Y3lJNkltUnBaRHB3Y21semJUcGhaR0psT1RJNE9XUXdZelZtWWpVMlptWmhOVEF6T0Rka01UZ3dOR0ZpTkdFeE5UYzJOVEkzWXprME5tRTFNalV5T0RFM1ptRTRaVGhoTW1OalpXUXdPa056YzBKRGMyZENSVzFKUzBSWE1XaGpNMUpzWTJsb2NHSnRVbXhsUTJ0UlFWVktVRU5uYkZSYVYwNTNUV3BWTW1GNlJWTkpSUzFNYVVkTU0xRklaRlZ1VG10d1dXSkthSE5VYTIxWVVGaEpVM0ZXZWpjMll6RlZPWGhvVURseWNFZHBSSEZXTlRselJYcEtWbEpEYWxJMGEwMHdaMGg0YkhWUU5tVk5Ta2wwZHpJMk4yWllWbEpoTUhoRE5XaEthVU5uTVhSWldFNHdXbGhKYjJGWE5XdGFXR2R3UlVGU1ExUjNiMHBWTWxacVkwUkpNVTV0YzNoRmFVSlFhVFJvYVRrd1FqTldTbnBhUzFkSGVWbGlSVFZLYkhveGVVVnhiR010TFc1T1ZsQmpXVlJmWVRaU2IyYzJiR1ZtWWtKTmVWWlZVVzh3WlVwRVRrbENPRnBpYWkxdWFrTlRUR05PZFhVek1URlZWM1JOVVhWWkluMC5CcmFpbEVXa2VlSXhWbjY3dnpkVHZGTXpBMV9oNzFoaDZsODBHRFBpbkRaVVB4ajAxSC0tUC1QZDIxTk9wRDd3am51SDkxdUNBOFZMUW9fS2FnVjlnQQo="}""" + issueCredential <- ZIO.fromEither( + IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage) + ) _ <- repo.updateWithIssuedRawCredential( aIssueCredentialRecord.id, - IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage), + issueCredential, rawCredentialData, None, None, @@ -500,9 +506,12 @@ object PresentationServiceSpec extends ZIOSpecDefault with PresentationServiceSp _ <- repo.create(aIssueCredentialRecord) rawCredentialData = """{"base64":"ZXlKaGJHY2lPaUpGVXpJMU5rc2lMQ0owZVhBaU9pSktWMVFpZlEuZXlKcFlYUWlPakUyTnprek1qYzROaklzSW1GMVpDSTZJbVJ2YldGcGJpSXNJbTV2Ym1ObElqb2lZMlk1T1RJMk56Z3RPREV3TmkwME1EZzVMV0UxWXprdE5tTmhObU0wWkRBMU1HVTBJaXdpZG5BaU9uc2lRR052Ym5SbGVIUWlPbHNpYUhSMGNITTZMeTkzZDNjdWR6TXViM0puTHpJd01UZ3ZjSEpsYzJWdWRHRjBhVzl1Y3k5Mk1TSmRMQ0owZVhCbElqcGJJbFpsY21sbWFXRmliR1ZRY21WelpXNTBZWFJwYjI0aVhYMHNJbWx6Y3lJNkltUnBaRHB3Y21semJUcGhaR0psT1RJNE9XUXdZelZtWWpVMlptWmhOVEF6T0Rka01UZ3dOR0ZpTkdFeE5UYzJOVEkzWXprME5tRTFNalV5T0RFM1ptRTRaVGhoTW1OalpXUXdPa056YzBKRGMyZENSVzFKUzBSWE1XaGpNMUpzWTJsb2NHSnRVbXhsUTJ0UlFWVktVRU5uYkZSYVYwNTNUV3BWTW1GNlJWTkpSUzFNYVVkTU0xRklaRlZ1VG10d1dXSkthSE5VYTIxWVVGaEpVM0ZXZWpjMll6RlZPWGhvVURseWNFZHBSSEZXTlRselJYcEtWbEpEYWxJMGEwMHdaMGg0YkhWUU5tVk5Ta2wwZHpJMk4yWllWbEpoTUhoRE5XaEthVU5uTVhSWldFNHdXbGhKYjJGWE5XdGFXR2R3UlVGU1ExUjNiMHBWTWxacVkwUkpNVTV0YzNoRmFVSlFhVFJvYVRrd1FqTldTbnBhUzFkSGVWbGlSVFZLYkhveGVVVnhiR010TFc1T1ZsQmpXVlJmWVRaU2IyYzJiR1ZtWWtKTmVWWlZVVzh3WlVwRVRrbENPRnBpYWkxdWFrTlRUR05PZFhVek1URlZWM1JOVVhWWkluMC5CcmFpbEVXa2VlSXhWbjY3dnpkVHZGTXpBMV9oNzFoaDZsODBHRFBpbkRaVVB4ajAxSC0tUC1QZDIxTk9wRDd3am51SDkxdUNBOFZMUW9fS2FnVjlnQQo="}""" + issueCredential <- ZIO.fromEither( + IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage) + ) _ <- repo.updateWithIssuedRawCredential( aIssueCredentialRecord.id, - IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage), + issueCredential, rawCredentialData, Some("SchemaId"), Some("CredDefId"), @@ -559,9 +568,12 @@ object PresentationServiceSpec extends ZIOSpecDefault with PresentationServiceSp _ <- repo.create(aIssueCredentialRecord) rawCredentialData = """{"base64":"ZXlKaGJHY2lPaUpGVXpJMU5rc2lMQ0owZVhBaU9pSktWMVFpZlEuZXlKcFlYUWlPakUyTnprek1qYzROaklzSW1GMVpDSTZJbVJ2YldGcGJpSXNJbTV2Ym1ObElqb2lZMlk1T1RJMk56Z3RPREV3TmkwME1EZzVMV0UxWXprdE5tTmhObU0wWkRBMU1HVTBJaXdpZG5BaU9uc2lRR052Ym5SbGVIUWlPbHNpYUhSMGNITTZMeTkzZDNjdWR6TXViM0puTHpJd01UZ3ZjSEpsYzJWdWRHRjBhVzl1Y3k5Mk1TSmRMQ0owZVhCbElqcGJJbFpsY21sbWFXRmliR1ZRY21WelpXNTBZWFJwYjI0aVhYMHNJbWx6Y3lJNkltUnBaRHB3Y21semJUcGhaR0psT1RJNE9XUXdZelZtWWpVMlptWmhOVEF6T0Rka01UZ3dOR0ZpTkdFeE5UYzJOVEkzWXprME5tRTFNalV5T0RFM1ptRTRaVGhoTW1OalpXUXdPa056YzBKRGMyZENSVzFKUzBSWE1XaGpNMUpzWTJsb2NHSnRVbXhsUTJ0UlFWVktVRU5uYkZSYVYwNTNUV3BWTW1GNlJWTkpSUzFNYVVkTU0xRklaRlZ1VG10d1dXSkthSE5VYTIxWVVGaEpVM0ZXZWpjMll6RlZPWGhvVURseWNFZHBSSEZXTlRselJYcEtWbEpEYWxJMGEwMHdaMGg0YkhWUU5tVk5Ta2wwZHpJMk4yWllWbEpoTUhoRE5XaEthVU5uTVhSWldFNHdXbGhKYjJGWE5XdGFXR2R3UlVGU1ExUjNiMHBWTWxacVkwUkpNVTV0YzNoRmFVSlFhVFJvYVRrd1FqTldTbnBhUzFkSGVWbGlSVFZLYkhveGVVVnhiR010TFc1T1ZsQmpXVlJmWVRaU2IyYzJiR1ZtWWtKTmVWWlZVVzh3WlVwRVRrbENPRnBpYWkxdWFrTlRUR05PZFhVek1URlZWM1JOVVhWWkluMC5CcmFpbEVXa2VlSXhWbjY3dnpkVHZGTXpBMV9oNzFoaDZsODBHRFBpbkRaVVB4ajAxSC0tUC1QZDIxTk9wRDd3am51SDkxdUNBOFZMUW9fS2FnVjlnQQo="}""" + issueCredential <- ZIO.fromEither( + IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage) + ) _ <- repo.updateWithIssuedRawCredential( aIssueCredentialRecord.id, - IssueCredential.makeIssueCredentialFromRequestCredential(requestCredential.makeMessage), + issueCredential, rawCredentialData, None, None,