Skip to content

Commit

Permalink
feat: VCVerification API support ARRAY or OBJECT as Credential Sc… (#…
Browse files Browse the repository at this point in the history
…1355)

Signed-off-by: Bassam Riman <[email protected]>
  • Loading branch information
CryptoKnightIOG authored Sep 16, 2024
1 parent 6a0a3ea commit 91cb4e7
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ 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.{DidResolver, JWT, JWTVerification, JwtCredential}
import org.hyperledger.identus.pollux.vc.jwt.{CredentialPayload, DidResolver, JWT, JWTVerification, JwtCredential}
import org.hyperledger.identus.pollux.vc.jwt.CredentialPayload.Implicits
import zio.*

import java.time.OffsetDateTime
Expand Down Expand Up @@ -104,7 +105,7 @@ class VcVerificationServiceImpl(didResolver: DidResolver, uriDereferencer: URIDe
CredentialSchema
.validateJWTCredentialSubject(
credentialSchema.id,
decodedJwt.credentialSubject.noSpaces,
CredentialPayload.Implicits.jwtVcEncoder(decodedJwt.vc).noSpaces,
uriDereferencer
)
.mapError(error =>
Expand Down
6 changes: 3 additions & 3 deletions pollux/core/src/test/resources/vc-schema-driver-license.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
"format": "date-time"
},
"drivingLicenseID": {
"type": "string"
"type": "integer"
},
"drivingClass": {
"type": "integer"
}
},
"required": ["dateOfIssuance", "drivingLicenseID", "drivingClass"],
"additionalProperties": false
"additionalProperties": true
}
},
"required": ["credentialSubject"],
"additionalProperties": false
"additionalProperties": true
}
4 changes: 2 additions & 2 deletions pollux/core/src/test/resources/vc-schema-personal.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
}
},
"required": ["email", "userName", "age"],
"additionalProperties": false
"additionalProperties": true
}
},
"required": ["credentialSubject"],
"additionalProperties": false
"additionalProperties": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,86 @@ object VcVerificationServiceImplSpec extends ZIOSpecDefault with VcVerificationS
someVcVerificationServiceLayer ++
ZLayer.succeed(WalletAccessContext(WalletId.random))
),
test("verify subject given multiple schema") {
for {
svc <- ZIO.service[VcVerificationService]
verifier = "did:prism:verifier"
jwtCredentialPayload = W3cCredentialPayload(
`@context` =
Set("https://www.w3.org/2018/credentials/v1", "https://www.w3.org/2018/credentials/examples/v1"),
maybeId = Some("http://example.edu/credentials/3732"),
`type` = Set("VerifiableCredential", "UniversityDegreeCredential"),
issuer = Left(issuer.did.toString),
issuanceDate = Instant.parse("2010-01-01T00:00:00Z"),
maybeExpirationDate = Some(Instant.parse("2010-01-12T00:00:00Z")),
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"
)
)
)
),
credentialSubject = Json.obj(
"userName" -> Json.fromString("Alice"),
"age" -> Json.fromInt(42),
"email" -> Json.fromString("[email protected]"),
"dateOfIssuance" -> Json.fromString("2000-01-01T10:00:00Z"),
"drivingLicenseID" -> Json.fromInt(12345),
"drivingClass" -> Json.fromInt(5)
),
maybeCredentialStatus = Some(
CredentialStatus(
id = "did:work:MDP8AsFhHzhwUvGNuYkX7T;id=06e126d1-fa44-4882-a243-1e326fbe21db;version=1.0",
`type` = "StatusList2021Entry",
statusPurpose = StatusPurpose.Revocation,
statusListIndex = 0,
statusListCredential = "https://example.com/credentials/status/3"
)
),
maybeRefreshService = Some(
RefreshService(
id = "https://example.edu/refresh/3732",
`type` = "ManualRefreshService2018"
)
),
maybeEvidence = Option.empty,
maybeTermsOfUse = Option.empty,
aud = Set(verifier)
).toJwtCredentialPayload
signedJwtCredential = issuer.signer.encode(jwtCredentialPayload.asJson)
result <-
svc.verify(
List(
VcVerificationRequest(signedJwtCredential.value, VcVerification.SubjectVerification)
)
)
} yield {
assertTrue(
result.contains(
VcVerificationResult(
signedJwtCredential.value,
VcVerification.SubjectVerification,
true
)
)
)
}
}.provideSomeLayer(
MockDIDService.empty ++
MockManagedDIDService.empty ++
ResourceURIDereferencerImpl.layer >+>
someVcVerificationServiceLayer ++
ZLayer.succeed(WalletAccessContext(WalletId.random))
),
test("verify nbf given valid") {
for {
svc <- ZIO.service[VcVerificationService]
Expand Down

0 comments on commit 91cb4e7

Please sign in to comment.