CredentialBuilder

Credential Builder DSL.

Provides a fluent API for creating verifiable credentials with minimal boilerplate.

Example Usage:

val credential = credential {
id("https://example.edu/credentials/123")
type(CredentialType.Degree, CredentialType.Custom("BachelorDegreeCredential"))
issuer("did:key:university")
subject {
id("did:key:student")
"degree" {
"type" to "BachelorDegree"
"name" to "Bachelor of Science"
"university" to "Example University"
}
}
issued(Instant.now())
expires(Clock.System.now() + 3650.days) // ~10 years
schema("https://example.edu/schemas/degree.json")
}

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard

Build the verifiable credential.

Link copied to clipboard
fun evidence(block: EvidenceBuilder.() -> Unit)

Add evidence.

Link copied to clipboard
fun expires(duration: Duration)

Set expiration date as duration from now.

fun expires(date: Instant)

Set expiration date.

Link copied to clipboard
fun expiresIn(duration: Duration)

Set expiration date as duration from now (convenience alias).

Link copied to clipboard
fun id(id: String)

Set credential ID.

Link copied to clipboard
fun issued(date: Instant)

Set issuance date.

Link copied to clipboard
fun issuer(did: String)

Set issuer DID.

fun issuer(did: Did)

Set credential issuer DID.

Link copied to clipboard
fun refreshService(id: String, type: String)

Set refresh service.

Link copied to clipboard
fun schema(schemaId: String, type: String = "JsonSchemaValidator2018")

Set credential schema.

Link copied to clipboard

Set credential status (for revocation).

Link copied to clipboard
fun subject(block: SubjectBuilder.() -> Unit)

Configure credential subject.

fun subject(iri: String, block: SubjectBuilder.() -> Unit = {})

Configure credential subject with IRI string.

fun subject(did: Did, block: SubjectBuilder.() -> Unit = {})

Configure credential subject with DID.

Link copied to clipboard

Set terms of use.

Link copied to clipboard
fun type(vararg types: String)

Add credential type(s) using string values (for backward compatibility). "VerifiableCredential" is automatically added.

fun type(vararg types: CredentialType)

Add credential type(s) using type-safe CredentialType instances. "VerifiableCredential" is automatically added.

Link copied to clipboard
fun validFrom(date: Instant)

Set validFrom date (VC 2.0).

Link copied to clipboard
fun validUntil(date: Instant)

Set validUntil date (VC 2.0).