CredentialTransformationBuilder

class CredentialTransformationBuilder(credential: VerifiableCredential, transformer: CredentialTransformer = CredentialTransformer())

DSL builder for credential transformations.

Provides a fluent, builder-style API for credential format conversions. This is useful for complex transformation scenarios or when you want to use a builder pattern for consistency with other TrustWeave DSLs.

Example Usage:

// Simple transformation
val jwt = credential.transform {
toJwt()
}

// Pattern-match on the typed result
when (val result = credential.transform { toJwt() }) {
is TransformResult.Jwt -> println(result.value)
is TransformResult.JsonLd -> println(result.value)
is TransformResult.Cbor -> println(result.value.size)
}

// JSON-LD transformation
val jsonLd = (credential.transform { toJsonLd() } as TransformResult.JsonLd).value

// CBOR transformation
val cbor = (credential.transform { toCbor() } as TransformResult.Cbor).value

Note: For most use cases, the direct extension functions are more elegant:

  • credential.toJwt() instead of credential.transform { toJwt() }

  • credential.toJsonLd() instead of credential.transform { toJsonLd() }

Use this builder when you need conditional transformations or want to integrate with other builder-based DSLs.

Constructors

Link copied to clipboard
constructor(credential: VerifiableCredential, transformer: CredentialTransformer = CredentialTransformer())

Functions

Link copied to clipboard

Get the transformation result.

Link copied to clipboard
suspend fun toCbor(): ByteArray

Transform credential to CBOR format.

Link copied to clipboard
suspend fun toJsonLd(): JsonObject

Transform credential to JSON-LD format.

Link copied to clipboard
suspend fun toJwt(): String

Transform credential to JWT format.