-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/migrate-from-circe-to-zio-json
Signed-off-by: Benjamin Voiturier <[email protected]>
- Loading branch information
Showing
40 changed files
with
580 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...cala/org/hyperledger/identus/issue/controller/CredentialSchemaReferenceParsingLogic.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.hyperledger.identus.issue.controller | ||
|
||
import org.hyperledger.identus.api.http.ErrorResponse | ||
import org.hyperledger.identus.issue.controller.http.CredentialSchemaRef as HTTPCredentialSchemaRef | ||
import org.hyperledger.identus.pollux.core.model.primitives.UriString | ||
import org.hyperledger.identus.pollux.core.model.schema.{ | ||
CredentialSchemaRef as DomainCredentialSchemaRef, | ||
CredentialSchemaRefType | ||
} | ||
import zio.{IO, ZIO} | ||
|
||
trait CredentialSchemaReferenceParsingLogic { | ||
|
||
// According to VCDM 1.1, the property "credentialSchema" is required to issue JWT, JSON, and JSON-LD credentials. | ||
// The "id" property in the "credentialSchema" object is a URI that points to the schema of the credential. | ||
// The "type" property in the "credentialSchema" object must be "JsonSchemaValidator2018". | ||
// Multiple schemas are not allowed in VCDM 1.1. | ||
def parseCredentialSchemaRef_VCDM1_1( | ||
deprecatedSchemaIdProperty: Option[String | List[String]], | ||
credentialSchemaRefOption: Option[HTTPCredentialSchemaRef] | ||
): IO[ErrorResponse, DomainCredentialSchemaRef] = { | ||
credentialSchemaRefOption match { | ||
case Some(csr) if csr.`type` == "JsonSchemaValidator2018" => | ||
makeDomainCredentialSchemaRef(csr.id) | ||
case Some(csr) => | ||
ZIO.fail(ErrorResponse.badRequest(detail = Some(s"Invalid credentialSchema type: ${csr.`type`}."))) | ||
case None => | ||
handleDeprecatedSchemaId(deprecatedSchemaIdProperty) | ||
.flatMap(makeDomainCredentialSchemaRef) | ||
} | ||
} | ||
|
||
def parseSchemaIdForAnonCredsModelV1( | ||
deprecatedSchemaIdProperty: Option[String | List[String]], | ||
schemaIdProperty: Option[String] | ||
): IO[ErrorResponse, UriString] = { | ||
schemaIdProperty | ||
.map(makeUriStringOrErrorResponse) | ||
.getOrElse(handleDeprecatedSchemaId(deprecatedSchemaIdProperty).flatMap(makeUriStringOrErrorResponse)) | ||
} | ||
|
||
private def handleDeprecatedSchemaId( | ||
deprecatedSchemaIdProperty: Option[String | List[String]] | ||
): IO[ErrorResponse, String] = { | ||
deprecatedSchemaIdProperty match { | ||
case Some(schemaId: String) => | ||
ZIO.succeed(schemaId) | ||
case Some(_: List[String]) => | ||
ZIO.fail(ErrorResponse.badRequest(detail = Some("Multiple credential schemas are not allowed."))) | ||
case None => | ||
ZIO.fail(ErrorResponse.badRequest(detail = Some("Credential schema property missed."))) | ||
} | ||
} | ||
|
||
private def makeDomainCredentialSchemaRef(input: String): IO[ErrorResponse, DomainCredentialSchemaRef] = | ||
makeUriStringOrErrorResponse(input).map( | ||
DomainCredentialSchemaRef(CredentialSchemaRefType.JsonSchemaValidator2018, _) | ||
) | ||
|
||
private def makeUriStringOrErrorResponse(input: String): IO[ErrorResponse, UriString] = | ||
UriString.make(input).toZIO.mapError(uriParseError => ErrorResponse.badRequest(detail = Some(uriParseError))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.