Skip to content

Commit

Permalink
ATL-7775: Fix 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 Sep 24, 2024
1 parent cad232a commit 00d9698
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 112 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.hyperledger.identus.issue.controller

import cats.Applicative
import org.hyperledger.identus.agent.server.config.AppConfig
import org.hyperledger.identus.agent.server.ControllerHelper
import org.hyperledger.identus.agent.walletapi.model.PublicationState
Expand Down Expand Up @@ -65,7 +64,10 @@ class IssueControllerImpl(
pairwiseHolderDID = offerContext.pairwiseHolderDID,
kidIssuer = request.issuingKid,
thid = DidCommID(),
maybeSchemaIds = Applicative[Option].map2(request.schemaIds, request.schemaId.map(List(_)))(_ ++ _),
maybeSchemaIds = request.schemaId.map {
case schemaId: String => List(schemaId)
case schemaIds: List[String] => schemaIds
},
claims = jsonClaims,
validityPeriod = request.validityPeriod,
automaticIssuance = request.automaticIssuance.orElse(Some(true)),
Expand All @@ -90,7 +92,10 @@ class IssueControllerImpl(
pairwiseHolderDID = offerContext.pairwiseHolderDID,
kidIssuer = request.issuingKid,
thid = DidCommID(),
maybeSchemaIds = request.schemaId.map(List(_)),
maybeSchemaIds = request.schemaId.map {
case schemaId: String => List(schemaId)
case schemaIds: List[String] => schemaIds
},
claims = jsonClaims,
validityPeriod = request.validityPeriod,
automaticIssuance = request.automaticIssuance.orElse(Some(true)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import sttp.tapir.Schema.annotations.{description, encodedExample}
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, JsonDecoder, JsonEncoder}

import java.util.UUID
import scala.language.implicitConversions

/** A class to represent an incoming request to create a new credential offer.
*
Expand All @@ -33,10 +34,7 @@ final case class CreateIssueCredentialRecordRequest(
validityPeriod: Option[Double] = None,
@description(annotations.schemaId.description)
@encodedExample(annotations.schemaId.example)
schemaId: Option[String] = None,
@description(annotations.schemaId.description)
@encodedExample(annotations.schemaId.example)
schemaIds: Option[List[String]] = None,
schemaId: Option[String | List[String]] = None,
@description(annotations.credentialDefinitionId.description)
@encodedExample(annotations.credentialDefinitionId.example)
credentialDefinitionId: Option[UUID],
Expand Down Expand Up @@ -88,21 +86,6 @@ object CreateIssueCredentialRecordRequest {
)
)

object schemaIds
extends Annotation[Option[List[String]]](
description = """
|The URL pointing to the JSON schema that will be used for this offer (should be 'http' or 'https').
|When dereferenced, the returned content should be a JSON schema compliant with the '[Draft 2020-12](https://json-schema.org/draft/2020-12/release-notes)' version of the specification.
|Note that this parameter only applies when the offer is of type 'JWT'.
|""".stripMargin,
example = Some(
List(
"https://agent-host.com/cloud-agent/schema-registry/schemas/d9569cec-c81e-4779-aa86-0d5994d82676/schema",
"https://agent-host.com/cloud-agent/schema-registry/schemas/d9569cec-c81e-4779-aa86-0d5994d82676/schema2"
)
)
)

object credentialDefinitionId
extends Annotation[Option[UUID]](
description = """
Expand Down Expand Up @@ -196,13 +179,37 @@ object CreateIssueCredentialRecordRequest {
)
}

given schemaIdEncoder: JsonEncoder[String | List[String]] =
JsonEncoder[String]
.orElseEither(JsonEncoder[List[String]])
.contramap[String | List[String]] {
case schemaId: String => Left(schemaId)
case schemaIds: List[String] => Right(schemaIds)
}

given schemaIdDecoder: JsonDecoder[String | List[String]] =
JsonDecoder[List[String]]
.map(schemaId => schemaId: String | List[String])
.orElse(JsonDecoder[String].map(schemaId => schemaId: String | List[String]))

given encoder: JsonEncoder[CreateIssueCredentialRecordRequest] =
DeriveJsonEncoder.gen[CreateIssueCredentialRecordRequest]

given decoder: JsonDecoder[CreateIssueCredentialRecordRequest] =
DeriveJsonDecoder.gen[CreateIssueCredentialRecordRequest]

given schemaJson: Schema[KeyId] = Schema.schemaForString.map[KeyId](v => Some(KeyId(v)))(KeyId.value)

given schemaId: Schema[String | List[String]] = Schema
.schemaForEither(Schema.schemaForString, Schema.schemaForArray[String])
.map[String | List[String]] {
case Left(value) => Some(value)
case Right(values) => Some(values.toList)
} {
case value: String => Left(value)
case values: List[String] => Right(values.toArray)
}

given schema: Schema[CreateIssueCredentialRecordRequest] = Schema.derived

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ object VcVerificationControllerImplSpec extends ZIOSpecDefault with VcVerificati
maybeValidFrom = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeValidUntil = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeCredentialSchema = Some(
Left(
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
),
credentialSubject = Json.obj(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ class CredentialServiceImpl(
issuanceDate = issuanceDate,
maybeExpirationDate = record.validityPeriod.map(sec => issuanceDate.plusSeconds(sec.toLong)),
maybeCredentialSchema = record.schemaUris.map(ids =>
Right(ids.map(id => org.hyperledger.identus.pollux.vc.jwt.CredentialSchema(id, VC_JSON_SCHEMA_TYPE)))
ids.map(id => org.hyperledger.identus.pollux.vc.jwt.CredentialSchema(id, VC_JSON_SCHEMA_TYPE))
),
maybeCredentialStatus = Some(credentialStatus),
credentialSubject = claims.add("id", jwtPresentation.iss.asJson).asJson,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ package org.hyperledger.identus.pollux.core.service.verification

import org.hyperledger.identus.pollux.core.model.schema.CredentialSchema
import org.hyperledger.identus.pollux.core.service.URIDereferencer
import org.hyperledger.identus.pollux.vc.jwt.{CredentialPayload, DidResolver, JWT, JWTVerification, JwtCredential}
import org.hyperledger.identus.pollux.vc.jwt.{
CredentialPayload,
CredentialSchema as JwtCredentialSchema,
DidResolver,
JWT,
JWTVerification,
JwtCredential
}
import org.hyperledger.identus.pollux.vc.jwt.CredentialPayload.Implicits
import zio.*

Expand Down Expand Up @@ -54,7 +61,10 @@ class VcVerificationServiceImpl(didResolver: DidResolver, uriDereferencer: URIDe
ZIO
.fromOption(decodedJwt.maybeCredentialSchema)
.mapError(error => VcVerificationServiceError.UnexpectedError(s"Missing Credential Schema: $error"))
credentialSchemas = credentialSchema.fold(List(_), identity)
credentialSchemas = credentialSchema match {
case schema: JwtCredentialSchema => List(schema)
case schemaList: List[JwtCredentialSchema] => schemaList
}
result <-
ZIO.collectAll(
credentialSchemas.map(credentialSchema =>
Expand Down Expand Up @@ -98,7 +108,10 @@ class VcVerificationServiceImpl(didResolver: DidResolver, uriDereferencer: URIDe
ZIO
.fromOption(decodedJwt.maybeCredentialSchema)
.mapError(error => VcVerificationServiceError.UnexpectedError(s"Missing Credential Schema: $error"))
credentialSchemas = credentialSchema.fold(List(_), identity)
credentialSchemas = credentialSchema match {
case schema: JwtCredentialSchema => List(schema)
case schemaList: List[JwtCredentialSchema] => schemaList
}
result <-
ZIO.collectAll(
credentialSchemas.map(credentialSchema =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ object VcVerificationServiceImplSpec extends ZIOSpecDefault with VcVerificationS
maybeValidFrom = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeValidUntil = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeCredentialSchema = Some(
Left(
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
),
credentialSubject = Json.obj(
Expand Down Expand Up @@ -100,11 +98,9 @@ object VcVerificationServiceImplSpec extends ZIOSpecDefault with VcVerificationS
maybeValidFrom = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeValidUntil = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeCredentialSchema = Some(
Left(
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
),
credentialSubject = Json.obj(
Expand Down Expand Up @@ -167,11 +163,9 @@ object VcVerificationServiceImplSpec extends ZIOSpecDefault with VcVerificationS
maybeValidFrom = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeValidUntil = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeCredentialSchema = Some(
Left(
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
),
credentialSubject = Json.obj(
Expand Down Expand Up @@ -234,11 +228,9 @@ object VcVerificationServiceImplSpec extends ZIOSpecDefault with VcVerificationS
maybeValidFrom = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeValidUntil = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeCredentialSchema = Some(
Left(
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
),
credentialSubject = Json.obj(
Expand Down Expand Up @@ -308,11 +300,9 @@ object VcVerificationServiceImplSpec extends ZIOSpecDefault with VcVerificationS
maybeValidFrom = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeValidUntil = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeCredentialSchema = Some(
Left(
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
),
credentialSubject = Json.obj(
Expand Down Expand Up @@ -379,11 +369,9 @@ object VcVerificationServiceImplSpec extends ZIOSpecDefault with VcVerificationS
maybeValidFrom = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeValidUntil = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeCredentialSchema = Some(
Left(
CredentialSchema(
id = "resource:///vc-schema-personal.json",
`type` = "JsonSchemaValidator2018"
)
CredentialSchema(
id = "resource:///vc-schema-personal.json",
`type` = "JsonSchemaValidator2018"
)
),
credentialSubject = Json.obj(
Expand Down Expand Up @@ -450,16 +438,14 @@ object VcVerificationServiceImplSpec extends ZIOSpecDefault with VcVerificationS
maybeValidFrom = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeValidUntil = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeCredentialSchema = Some(
Right(
List(
CredentialSchema(
id = "resource:///vc-schema-personal.json",
`type` = "JsonSchemaValidator2018"
),
CredentialSchema(
id = "resource:///vc-schema-driver-license.json",
`type` = "JsonSchemaValidator2018"
)
List(
CredentialSchema(
id = "resource:///vc-schema-personal.json",
`type` = "JsonSchemaValidator2018"
),
CredentialSchema(
id = "resource:///vc-schema-driver-license.json",
`type` = "JsonSchemaValidator2018"
)
)
),
Expand Down Expand Up @@ -530,16 +516,14 @@ object VcVerificationServiceImplSpec extends ZIOSpecDefault with VcVerificationS
maybeValidFrom = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeValidUntil = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeCredentialSchema = Some(
Right(
List(
CredentialSchema(
id = "resource:///vc-schema-personal.json",
`type` = "JsonSchemaValidator2018"
),
CredentialSchema(
id = "resource:///vc-schema-driver-license.json",
`type` = "JsonSchemaValidator2018"
)
List(
CredentialSchema(
id = "resource:///vc-schema-personal.json",
`type` = "JsonSchemaValidator2018"
),
CredentialSchema(
id = "resource:///vc-schema-driver-license.json",
`type` = "JsonSchemaValidator2018"
)
)
),
Expand Down Expand Up @@ -611,11 +595,9 @@ object VcVerificationServiceImplSpec extends ZIOSpecDefault with VcVerificationS
maybeValidFrom = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeValidUntil = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeCredentialSchema = Some(
Left(
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
),
credentialSubject = Json.obj(
Expand Down Expand Up @@ -679,11 +661,9 @@ object VcVerificationServiceImplSpec extends ZIOSpecDefault with VcVerificationS
maybeValidFrom = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeValidUntil = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeCredentialSchema = Some(
Left(
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
),
credentialSubject = Json.obj(
Expand Down Expand Up @@ -747,11 +727,9 @@ object VcVerificationServiceImplSpec extends ZIOSpecDefault with VcVerificationS
maybeValidFrom = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeValidUntil = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeCredentialSchema = Some(
Left(
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
),
credentialSubject = Json.obj(
Expand Down Expand Up @@ -815,11 +793,9 @@ object VcVerificationServiceImplSpec extends ZIOSpecDefault with VcVerificationS
maybeValidFrom = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeValidUntil = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeCredentialSchema = Some(
Left(
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
)
),
credentialSubject = Json.obj(
Expand Down
Loading

0 comments on commit 00d9698

Please sign in to comment.