Skip to content

Commit

Permalink
feat: Support Array Of Credential Schema (hyperledger#1351)
Browse files Browse the repository at this point in the history
Signed-off-by: Bassam Riman <[email protected]>
Signed-off-by: Hyperledger Bot <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Hyperledger Bot <[email protected]>
  • Loading branch information
3 people authored Sep 13, 2024
1 parent f80b3c3 commit 948e314
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ 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(
CredentialSchema(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "JsonSchemaValidator2018"
Left(
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 @@ -1137,8 +1137,9 @@ class CredentialServiceImpl(
issuer = Right(CredentialIssuer(jwtIssuer.did.toString, `type` = "Profile")),
issuanceDate = issuanceDate,
maybeExpirationDate = record.validityPeriod.map(sec => issuanceDate.plusSeconds(sec.toLong)),
maybeCredentialSchema =
record.schemaUri.map(id => org.hyperledger.identus.pollux.vc.jwt.CredentialSchema(id, VC_JSON_SCHEMA_TYPE)),
maybeCredentialSchema = record.schemaUri.map(id =>
Left(org.hyperledger.identus.pollux.vc.jwt.CredentialSchema(id, VC_JSON_SCHEMA_TYPE))
),
maybeCredentialStatus = Some(credentialStatus),
credentialSubject = claims.add("id", jwtPresentation.iss.asJson).asJson,
maybeRefreshService = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ class VcVerificationServiceImpl(didResolver: DidResolver, uriDereferencer: URIDe
ZIO
.fromOption(decodedJwt.maybeCredentialSchema)
.mapError(error => VcVerificationServiceError.UnexpectedError(s"Missing Credential Schema: $error"))
result <- CredentialSchema
.validSchemaValidator(
credentialSchema.id,
uriDereferencer
credentialSchemas = credentialSchema.fold(List(_), identity)
result <-
ZIO.collectAll(
credentialSchemas.map(credentialSchema =>
CredentialSchema
.validSchemaValidator(
credentialSchema.id,
uriDereferencer
)
.mapError(error => VcVerificationServiceError.UnexpectedError(s"Schema Validator Failed: $error"))
)
)
.mapError(error => VcVerificationServiceError.UnexpectedError(s"Schema Validator Failed: $error"))
} yield result

result
Expand Down Expand Up @@ -91,14 +97,20 @@ class VcVerificationServiceImpl(didResolver: DidResolver, uriDereferencer: URIDe
ZIO
.fromOption(decodedJwt.maybeCredentialSchema)
.mapError(error => VcVerificationServiceError.UnexpectedError(s"Missing Credential Schema: $error"))
result <- CredentialSchema
.validateJWTCredentialSubject(
credentialSchema.id,
decodedJwt.credentialSubject.noSpaces,
uriDereferencer
)
.mapError(error =>
VcVerificationServiceError.UnexpectedError(s"JWT Credential Subject Validation Failed: $error")
credentialSchemas = credentialSchema.fold(List(_), identity)
result <-
ZIO.collectAll(
credentialSchemas.map(credentialSchema =>
CredentialSchema
.validateJWTCredentialSubject(
credentialSchema.id,
decodedJwt.credentialSubject.noSpaces,
uriDereferencer
)
.mapError(error =>
VcVerificationServiceError.UnexpectedError(s"JWT Credential Subject Validation Failed: $error")
)
)
)
} yield result

Expand Down
26 changes: 26 additions & 0 deletions pollux/core/src/test/resources/vc-schema-driver-license.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "Driving License",
"type": "object",
"properties": {
"credentialSubject": {
"type": "object",
"properties": {
"dateOfIssuance": {
"type": "string",
"format": "date-time"
},
"drivingLicenseID": {
"type": "string"
},
"drivingClass": {
"type": "integer"
}
},
"required": ["dateOfIssuance", "drivingLicenseID", "drivingClass"],
"additionalProperties": false
}
},
"required": ["credentialSubject"],
"additionalProperties": false
}
6 changes: 2 additions & 4 deletions pollux/core/src/test/resources/vc-schema-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
"additionalProperties": false
}
},
"required": [
"credentialSubject"
],
"required": ["credentialSubject"],
"additionalProperties": false
}
}
26 changes: 26 additions & 0 deletions pollux/core/src/test/resources/vc-schema-personal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "Age",
"type": "object",
"properties": {
"credentialSubject": {
"type": "object",
"properties": {
"email": {
"type": "string",
"format": "email"
},
"userName": {
"type": "string"
},
"age": {
"type": "integer"
}
},
"required": ["email", "userName", "age"],
"additionalProperties": false
}
},
"required": ["credentialSubject"],
"additionalProperties": false
}
Loading

0 comments on commit 948e314

Please sign in to comment.