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).valueContent copied to clipboard
Note: For most use cases, the direct extension functions are more elegant:
credential.toJwt()instead ofcredential.transform { toJwt() }credential.toJsonLd()instead ofcredential.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())