diff --git a/pollux/lib/anoncreds/src/main/scala/io/iohk/atala/pollux/anoncreds/AnoncredLib.scala b/pollux/lib/anoncreds/src/main/scala/io/iohk/atala/pollux/anoncreds/AnoncredLib.scala index 6af77aa43f..9a932eec48 100644 --- a/pollux/lib/anoncreds/src/main/scala/io/iohk/atala/pollux/anoncreds/AnoncredLib.scala +++ b/pollux/lib/anoncreds/src/main/scala/io/iohk/atala/pollux/anoncreds/AnoncredLib.scala @@ -144,7 +144,7 @@ object AnoncredLib { def createPresentation( presentationRequest: PresentationRequest, - credentialRequests: Seq[CredentialAndRequestedAttributesPredicates], + credentialRequests: Seq[CredentialRequests], selfAttested: Map[String, String], linkSecret: LinkSecret, schemas: Map[SchemaId, SchemaDef], diff --git a/pollux/lib/anoncreds/src/main/scala/io/iohk/atala/pollux/anoncreds/Models.scala b/pollux/lib/anoncreds/src/main/scala/io/iohk/atala/pollux/anoncreds/Models.scala index 60fe22e64d..c3075f922a 100644 --- a/pollux/lib/anoncreds/src/main/scala/io/iohk/atala/pollux/anoncreds/Models.scala +++ b/pollux/lib/anoncreds/src/main/scala/io/iohk/atala/pollux/anoncreds/Models.scala @@ -3,17 +3,17 @@ package io.iohk.atala.pollux.anoncreds import uniffi.anoncreds.{ Nonce, Credential as UniffiCredential, - CredentialRequests as UniffiCredentialRequests, CredentialDefinition as UniffiCredentialDefinition, CredentialDefinitionPrivate as UniffiCredentialDefinitionPrivate, CredentialKeyCorrectnessProof as UniffiCredentialKeyCorrectnessProof, CredentialOffer as UniffiCredentialOffer, CredentialRequest as UniffiCredentialRequest, CredentialRequestMetadata as UniffiCredentialRequestMetadata, + CredentialRequests as UniffiCredentialRequests, LinkSecret as UniffiLinkSecret, - Schema as UniffiSchema, Presentation as UniffiPresentation, PresentationRequest as UniffiPresentationRequest, + Schema as UniffiSchema } import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, JsonDecoder, JsonEncoder} @@ -259,17 +259,16 @@ object Credential { } // **************************************************************************** -case class CredentialAndRequestedAttributesPredicates( +case class CredentialRequests( credential: Credential, requestedAttribute: Seq[String], requestedPredicate: Seq[String], ) -object CredentialAndRequestedAttributesPredicates { - given Conversion[CredentialAndRequestedAttributesPredicates, UniffiCredentialRequests] with { - import uniffi.anoncreds.RequestedAttribute - import uniffi.anoncreds.RequestedPredicate - def apply(credentialRequests: CredentialAndRequestedAttributesPredicates): UniffiCredentialRequests = { +object CredentialRequests { + given Conversion[CredentialRequests, UniffiCredentialRequests] with { + import uniffi.anoncreds.{RequestedAttribute, RequestedPredicate} + def apply(credentialRequests: CredentialRequests): UniffiCredentialRequests = { val credential = Credential.given_Conversion_Credential_UniffiCredential(credentialRequests.credential) val requestedAttributes = credentialRequests.requestedAttribute.map(a => RequestedAttribute(a, true)) val requestedPredicates = credentialRequests.requestedPredicate.map(p => RequestedPredicate(p)) @@ -277,9 +276,9 @@ object CredentialAndRequestedAttributesPredicates { } } - given Conversion[UniffiCredentialRequests, CredentialAndRequestedAttributesPredicates] with { - def apply(credentialRequests: UniffiCredentialRequests): CredentialAndRequestedAttributesPredicates = { - CredentialAndRequestedAttributesPredicates( + given Conversion[UniffiCredentialRequests, CredentialRequests] with { + def apply(credentialRequests: UniffiCredentialRequests): CredentialRequests = { + CredentialRequests( Credential.given_Conversion_UniffiCredential_Credential(credentialRequests.getCredential()), credentialRequests .getRequestedAttribute() diff --git a/pollux/lib/anoncredsTest/src/test/scala/io/iohk/atala/pollux/anoncreds/PoCNewLib.scala b/pollux/lib/anoncredsTest/src/test/scala/io/iohk/atala/pollux/anoncreds/PoCNewLib.scala index c400acd288..ade9cadb7a 100644 --- a/pollux/lib/anoncredsTest/src/test/scala/io/iohk/atala/pollux/anoncreds/PoCNewLib.scala +++ b/pollux/lib/anoncredsTest/src/test/scala/io/iohk/atala/pollux/anoncreds/PoCNewLib.scala @@ -102,7 +102,7 @@ class PoCNewLib extends AnyFlatSpec { val presentation = AnoncredLib.createPresentation( presentationRequest, // : PresentationRequest, Seq( - CredentialAndRequestedAttributesPredicates(credential, Seq("sex"), Seq("age")) + CredentialRequests(credential, Seq("sex"), Seq("age")) ), // credentials: Seq[Credential], Map(), // selfAttested: Map[String, String], linkSecret.secret, // linkSecret: LinkSecret, 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 a5a8fd384f..8f14afadde 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 @@ -452,21 +452,7 @@ private class PresentationServiceImpl( schemaMap <- ZIO .collectAll(schemaIds.map { schemaId => - for { - uri <- ZIO.attempt(new URI(schemaId)).mapError(e => UnexpectedError(e.getMessage)) - content <- uriDereferencer.dereference(uri).mapError(e => UnexpectedError(e.error)) - vcSchema <- parseCredentialSchema(content).mapError(e => UnexpectedError(e.message)) - anoncredSchema <- AnoncredSchemaSerDesV1.schemaSerDes - .deserialize(vcSchema.schema) - .mapError(e => UnexpectedError(e.error)) - anoncredLibSchema = - SchemaDef( - schemaId, - anoncredSchema.version, - anoncredSchema.attrNames, - anoncredSchema.issuerId - ) - } yield (schemaId, anoncredLibSchema) + resolveSchema(schemaId) }) .map(_.toMap) credentialDefinitionMap <- @@ -515,7 +501,7 @@ private class PresentationServiceImpl( AnoncredLib.createPresentation( PresentationRequest(presentationRequestData), verifiableCredentials.map(verifiableCredential => - CredentialAndRequestedAttributesPredicates( + CredentialRequests( Credential(verifiableCredential), deserializedPresentationRequestData.requested_attributes.keys.toSeq, // TO FIX deserializedPresentationRequestData.requested_predicates.keys.toSeq // TO FIX @@ -532,6 +518,24 @@ private class PresentationServiceImpl( } yield presentation } + private def resolveSchema(schemaId: String): IO[UnexpectedError, (String, SchemaDef)] = { + for { + uri <- ZIO.attempt(new URI(schemaId)).mapError(e => UnexpectedError(e.getMessage)) + content <- uriDereferencer.dereference(uri).mapError(e => UnexpectedError(e.error)) + vcSchema <- parseCredentialSchema(content).mapError(e => UnexpectedError(e.message)) + anoncredSchema <- AnoncredSchemaSerDesV1.schemaSerDes + .deserialize(vcSchema.schema) + .mapError(e => UnexpectedError(e.error)) + anoncredLibSchema = + SchemaDef( + schemaId, + anoncredSchema.version, + anoncredSchema.attrNames, + anoncredSchema.issuerId + ) + } yield (schemaId, anoncredLibSchema) + } + def acceptRequestPresentation( recordId: DidCommID, credentialsToUse: Seq[String]