CredentialTransformer

Credential transformer for format conversion.

Provides format conversion between different credential representations:

  • JSON-LD (default W3C VC format)

  • JWT (compact, widely supported)

  • CBOR (binary, efficient - RFC 8949 compliant)

Recommended Usage (Elegant DSL API):

// Use extension functions directly on VerifiableCredential (recommended)
val jwt = credential.toJwt()
val jsonLd = credential.toJsonLd()
val cbor = credential.toCbor()

// Convert from formats
val credential = jwtString.fromJwt()
val credential = jsonLdObject.toCredential()
val credential = cborBytes.fromCbor()

// Round-trip transformations
val recovered = credential.roundTripJwt()

Alternative Usage (Direct API):

val transformer = CredentialTransformer()
val jwt = transformer.toJwt(credential)
val credential = transformer.fromJwt(jwt)

With TrustWeave Integration:

val jwt = trustWeave.toJwt(credential)
val jsonLd = trustWeave.toJsonLd(credential)

With DSL Builder:

val jwt = credential.transform {
toJwt()
}

This public class is a thin facade over org.trustweave.credential.internal.transform.CredentialTransformer, so both entry points share one implementation (and one set of security rules).

See also

org.trustweave.credential.transform.CredentialTransformerExtensions

For extension functions

org.trustweave.credential.transform.CredentialTransformationBuilder

For DSL builder

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard

Convert CBOR bytes to credential.

Link copied to clipboard
suspend fun fromJsonLd(json: JsonObject): VerifiableCredential

Convert JSON-LD to credential.

Link copied to clipboard

Convert a JWS-secured JWT to a credential (signature not verified). Unsecured (alg: none) JWTs are rejected; see the overload with allowUnsecured.

suspend fun fromJwt(jwt: String, allowUnsecured: Boolean): VerifiableCredential

Convert a JWT to a credential, accepting unsecured (alg: none) JWTs only when allowUnsecured is true — e.g. to read back the output of toJwt.

Link copied to clipboard
suspend fun toCbor(credential: VerifiableCredential): ByteArray

Convert credential to CBOR (RFC 8949) bytes.

Link copied to clipboard
suspend fun toJsonLd(credential: VerifiableCredential): JsonObject

Convert credential to JSON-LD format.

Link copied to clipboard
suspend fun toJwt(credential: VerifiableCredential): String

Convert credential to an unsecured JWT (alg: none) with the credential in the vc claim. For signed JWTs, use CredentialService.issue().