The credentials module contains classes and utilities that make it easier to work with Verifiable Credentials.
This package provides function for working with verifiable credentials, status list credentials, and verifiable presentations.
Specifically, it includes:
- Creation, signing, verification, and general processing of Verifiable Credentials (VCs).
- Creation of
StatusList2021Credential
- Presentation Exchange evaluation.
- Create Verifiable Credentials with flexible data types.
- Sign credentials using decentralized identifiers (DIDs).
- Verify the integrity and authenticity of VCs encoded as JSON Web Tokens (JWTs).
- Parse JWT and JSON representations of VCs into
VerifiableCredential
instances.
Create a new VerifiableCredential
with the following parameters:
type
: Type of the credential.issuer
: Issuer URI.subject
: Subject URI.data
: Credential data.
data class StreetCredibility(val localRespect: String, val legit: Boolean)
val vc = VerifiableCredential.create(
type = "StreetCred",
issuer = "did:example:issuer",
subject = "did:example:subject",
data = StreetCredibility(localRespect = "high", legit = true)
)
Sign a VerifiableCredential
with a DID:
did
: The DID used to sign the credential.assertionMethodId
: Optional identifier for the assertion method used for signature verification.
val vcJwt = vc.sign(myDid)
Verify the integrity and authenticity of a VC JWT:
vcJwt
: The VC in JWT format as a String.
try {
VerifiableCredential.verify(signedVcJwt)
println("VC Verification successful!")
} catch (e: SignatureException) {
println("VC Verification failed: ${e.message}")
}
Parse a JWT into a VerifiableCredential
instance:
vcJwt
: The VC JWT as a String.
val vc = VerifiableCredential.parseJwt(vcJwt)
Parse a JSON string into a VerifiableCredential
instance:
vcJson
: The VC JSON as a String.
val vc = VerifiableCredential.fromJson(vcJsonString)
StatusListCredentials
allows for the creation of status list credentials, such as revocation lists, and the validation
of credentials against such lists.
- Create status list credentials with a simple API, allowing the declaration of revocation or suspension status for a list of credentials.
- Validate individual credentials against a status list to check for revocation or suspension.
Creates a new status list credential (e.g., for revocation), use the create
method:
statusListCredentialId
: The id used for the resolvable path to the status list credential.issuer
: The issuer URI of the status list credential.statusPurpose
: The status purpose of the status list cred, eg: revocation,issuedCredentials
: The credentials to be included in the status list credential, eg: revoked credentials.
val statusListCredential = StatusListCredential.create(
"http://example.com/statuslistcred/id123",
"did:example:issuer",
StatusPurpose.REVOCATION,
listOf(vc1, vc2)
)
To validate whether a credential is part of a status list, you can use the validateCredentialInStatusList method:
val isRevoked = StatusListCredential.validateCredentialInStatusList(vc1, statusListCredential)
Alternatively, to validate a credential against a status list by fetching the status list credential from a URL:
val isRevoked = StatusListCredential.validateCredentialInStatusList(vc1)
PresentationExchange
is designed to facilitate the creation of a Verifiable Presentation by providing tools to select
and validate Verifiable Credentials against defined criteria.
- Select credentials that satisfy a given presentation definition.
- Validate if a Verifiable Credential JWT satisfies a Presentation Definition.
- Validate input descriptors within Verifiable Credentials.
Select Verifiable Credentials that meet the criteria of a given presentation definition.
val selectedCredentials = PresentationExchange.selectCredentials(
credentialsList,
presentationDefinition
)
Validate if a Verifiable Credential JWT satisfies the given presentation definition.
PresentationExchange.satisfiesPresentationDefinition(vcJwt, presentationDefinition)