toCbor

open suspend override fun toCbor(credential: VerifiableCredential): ByteArray

Convert credential to CBOR format.

Serializes the credential to JSON using kotlinx.serialization, then converts it to CBOR binary format using Jackson's CBOR dataformat. CBOR provides more compact encoding than JSON while maintaining compatibility with JSON data structures.

Implementation Details:

  • Uses kotlinx.serialization to convert VerifiableCredential to JSON string

  • Uses Jackson CBOR mapper to convert JSON string to CBOR binary format

  • Preserves all credential data including nested structures

  • More efficient than JSON for storage and transmission

Performance:

  • CBOR encoding is typically 10-20% smaller than equivalent JSON

  • Faster to parse than JSON in many cases

  • Well-suited for binary storage and network transmission

Recommended: Use the extension function credential.toCbor() instead for a more elegant API.

Return

CBOR-encoded bytes

Parameters

credential

Credential to convert

See also

For parsing CBOR-encoded credentials

Extension function