Class SignedVoucher

java.lang.Object
xyz.tcheeric.cashu.voucher.domain.SignedVoucher

public final class SignedVoucher extends Object
A voucher secret with an issuer's cryptographic signature.

SignedVoucher represents a complete voucher that has been cryptographically signed by the issuing merchant. It combines the voucher secret with the issuer's ED25519 signature and public key for verification.

Verification

The signature can be verified using verify() which delegates to VoucherSignatureService. A voucher is considered fully valid if:

  • The signature is cryptographically valid (verify() returns true)
  • The voucher has not expired (isExpired() returns false)

Model B Constraint

Signed vouchers are only redeemable with the issuing merchant identified by secret.issuerId. They cannot be redeemed at the mint.

Immutability

This class is immutable once created. All fields are final.

See Also:
  • Constructor Details

    • SignedVoucher

      public SignedVoucher(@NonNull @NonNull VoucherSecret secret, @NonNull @lombok.NonNull byte[] issuerSignature, @NonNull @NonNull String issuerPublicKey)
      Creates a signed voucher.
      Parameters:
      secret - the voucher secret (must not be null)
      issuerSignature - the issuer's signature (must not be null, 64 bytes for ED25519)
      issuerPublicKey - the issuer's public key hex string (must not be null)
      Throws:
      IllegalArgumentException - if any parameter is invalid
  • Method Details

    • verify

      public boolean verify()
      Verifies the cryptographic signature of this voucher.

      Delegates to VoucherSignatureService.verify(VoucherSecret, byte[], String) to perform ED25519 signature verification.

      Returns:
      true if the signature is valid, false otherwise
    • isExpired

      public boolean isExpired()
      Checks if this voucher has expired.

      Delegates to VoucherSecret.isExpired().

      Returns:
      true if expired, false if valid or no expiry set
    • isValid

      public boolean isValid()
      Checks if this voucher is fully valid (signature valid AND not expired).

      A voucher is considered valid if:

      • The signature verifies correctly
      • The voucher has not expired
      Returns:
      true if signature is valid and voucher not expired, false otherwise
    • getIssuerSignature

      public byte[] getIssuerSignature()
      Returns a defensive copy of the signature bytes.
      Returns:
      copy of the signature bytes
    • toString

      public String toString()
      Returns a string representation for debugging.
      Overrides:
      toString in class Object
      Returns:
      human-readable string with voucher metadata
    • toStringWithMetadata

      public String toStringWithMetadata()
      Returns a detailed string representation including full secret metadata.
      Returns:
      detailed human-readable string
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object