waltid-verifiable-credentials v1.0.6-SNAPSHOT
What it provides
- create and sign W3Cv1.1
and W3Cv2.0 verifiable credentials (jwt, sd-jwt)
using the JWS signature scheme
- static properties
- dynamically configurable properties (using data-functions)
- perform policy validation for verifiable credentials and presentations
- policy management
Verifiable Credentials library relies on the following walt.id libraries:
- waltid-sd-jwt library for sd-jwt related processing
- waltid-did library for DID related operations
- waltid-crypto library for key related operations
Installation
Add the verifiable credentials library as a dependency to your Kotlin or Java project, which includes the crypto and did lib.
walt.id Repository
Add the Maven repository which hosts the walt.id libraries to your build.gradle file.
repositories {
maven { url = uri("https://maven.walt.id/repository/waltid/") }
}
Library Dependency
Adding the verifiable credentials library as dependency. Specify the version that coincides with the latest or required snapshot for your project. Latest releases.
dependencies {
implementation("id.walt.credentials:waltid-verifiable-credentials:<version>")
}
Replace version
with the version of the walt.id verifiable credential library you want to use.
Note: As the verifiable credentials lib is part of the mono-repo walt.id identity, you need to use the version of
walt.id identity.
How to use it
Build credential
Build a W3Cv2.0 verifiable credential:
val credentialBuilder = CredentialBuilderType.W3CV2CredentialBuilder
val credentialSubject = mapOf(
"entityIdentification" to entityIdentificationNumber,
"issuingAuthority" to issuingAuthorityId,
"issuingCircumstances" to mapOf(
"proofType" to proofType,
"locationType" to "physicalLocation",
"location" to proofLocation
)
).toJsonObject()
val w3cCredential = CredentialBuilder(credentialBuilder).apply {
useCredentialSubject(credentialSubject)
}.buildW3C()
Issue credential
Static configuration
Issue a jwt-formatted verifiable credential:
val dataOverWrites = mapOf("entityIdentification" to entityIdentificationNumber.toJsonElement())
val dataUpdates = mapOf("issuingAuthority" to issuingAuthorityId.toJsonElement())
val jwt = w3cCredential.baseIssue(
issuerKey = issuerKey,
issuerDid = issuerDid,
subjectDid = holderDid,
dataOverwrites = dataOverwrites,
dataUpdates = dataUpdates,
additionalJwtHeader = emptyMap(),
additionalJwtOptions = emptyMap(),
)
Dynamic configuration
Issue a jwt-formatted verifiable credential:
val jwt = w3cCredential.mergingJwtIssue(
issuerKey = issuerKey,
issuerDid = issuerDid,
subjectDid = holderDid,
mappings = mapping,
additionalJwtHeader = emptyMap(),
additionalJwtOptions = emptyMap(),
)
Issue an sdjwt-formatted verifiable credential:
val sdjwt = w3cCredential.mergingSdJwtIssue(
issuerKey = issuerKey,
issuerDid = issuerDid,
subjectDid = holderDid,
mappings = mapping,
additionalJwtHeader = emptyMap(),
additionalJwtOptions = emptyMap(),
disclosureMap = selectiveDisclosureMap
)
Validate policy
val vpToken = "jwt"
// configure the validation policies
val vcPolicies = Json.parseToJsonElement(
"""
[
"signature",
"expired",
"not-before"
]
"""
).jsonArray.parsePolicyRequests()
val vpPolicies = Json.parseToJsonElement(
"""
[
"signature",
"expired",
"not-before"
]
"""
).jsonArray.parsePolicyRequests()
val specificPolicies = Json.parseToJsonElement(
"""
{
"OpenBadgeCredential": [
{
"policy": "schema",
"args": {
"type": "object",
"required": ["issuer"],
"properties": {
"issuer": {
"type": "object"
}
}
}
}
]
}
"""
).jsonObject.mapValues { it.value.jsonArray.parsePolicyRequests() }
// validate verifiable presentation against the configured policies
val validationResult = PolicyRunner.verifyPresentation(
vpTokenJwt = vpToken,
vpPolicies = vpPolicies,
globalVcPolicies = vcPolicies,
specificCredentialPolicies = specificPolicies,
mapOf(
"presentationSubmission" to JsonObject(emptyMap()),
"challenge" to "abc"
)
)
2 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago