Skip to content

Commit

Permalink
ATL-6019: Answer PR Comments
Browse files Browse the repository at this point in the history
Signed-off-by: Bassam Riman <bassam.riman@iohk.io>
  • Loading branch information
CryptoKnightIOG committed Nov 22, 2023
1 parent 644d20f commit ebae28a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -259,27 +259,26 @@ 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))
UniffiCredentialRequests(credential, requestedAttributes.asJava, requestedPredicates.asJava)
}
}

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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <-
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down

0 comments on commit ebae28a

Please sign in to comment.