Class VoucherSerializationUtils

java.lang.Object
xyz.tcheeric.cashu.voucher.domain.util.VoucherSerializationUtils

public final class VoucherSerializationUtils extends Object
Utility class for canonical CBOR serialization of voucher data.

Provides deterministic serialization required for voucher signature generation and verification. Uses CBOR (Concise Binary Object Representation) to ensure stable byte representation across platforms and implementations.

Thread-safe and stateless.

See Also:
  • Method Details

    • toCbor

      public static byte[] toCbor(@NonNull @NonNull Map<String,Object> data)
      Serializes a map to CBOR bytes in canonical form.

      The input map must have deterministic ordering (e.g., LinkedHashMap) to ensure consistent byte output for signature generation.

      Parameters:
      data - the map to serialize (must not be null)
      Returns:
      CBOR-encoded bytes
      Throws:
      IllegalArgumentException - if serialization fails
    • fromCbor

      public static Map<String,Object> fromCbor(@NonNull @lombok.NonNull byte[] cborBytes)
      Deserializes CBOR bytes to a map.
      Parameters:
      cborBytes - the CBOR-encoded bytes (must not be null)
      Returns:
      the deserialized map
      Throws:
      IllegalArgumentException - if deserialization fails