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 wraps a VoucherSecret that stores the signature and public key as NUT-10 compliant tags.

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.getIssuerId(). They cannot be redeemed at the mint.

See Also:
  • Constructor Details

    • SignedVoucher

      public SignedVoucher(@NonNull @NonNull xyz.tcheeric.cashu.common.nut18.VoucherSecret secret)
      Creates a signed voucher from a VoucherSecret that already has signature and public key set.
      Parameters:
      secret - the voucher secret with signature and public key tags set
      Throws:
      IllegalArgumentException - if the secret doesn't have signature or public key
    • SignedVoucher

      public SignedVoucher(@NonNull @NonNull xyz.tcheeric.cashu.common.nut18.VoucherSecret secret, @NonNull @lombok.NonNull byte[] issuerSignature, @NonNull @NonNull String issuerPublicKey)
      Creates a signed voucher from components (for deserialization compatibility).
      Parameters:
      secret - the voucher secret
      issuerSignature - the issuer's signature (64 bytes for Schnorr)
      issuerPublicKey - the issuer's public key hex string
      Throws:
      IllegalArgumentException - if any parameter is invalid
  • Method Details

    • create

      public static SignedVoucher create(@NonNull @NonNull UUID voucherId, @NonNull @NonNull String issuerId, @NonNull @NonNull String unit, long faceValue, Long expiresAt, String memo, @NonNull @NonNull BackingStrategy backingStrategy, double issuanceRatio, int faceDecimals, @NonNull @NonNull String issuerSignature, @NonNull @NonNull String issuerPublicKey)
      Creates a signed voucher with all voucher details.
      Parameters:
      voucherId - unique voucher identifier
      issuerId - merchant identifier
      unit - currency unit
      faceValue - face value in smallest unit
      expiresAt - optional expiry timestamp
      memo - optional description
      backingStrategy - backing strategy
      issuanceRatio - issuance ratio
      faceDecimals - decimal places
      issuerSignature - hex-encoded signature
      issuerPublicKey - hex-encoded public key
      Returns:
      new SignedVoucher instance
    • verify

      public boolean verify()
      Verifies the cryptographic signature of this voucher.
      Returns:
      true if the signature is valid, false otherwise
    • isExpired

      public boolean isExpired()
      Checks if this voucher has expired.
      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).
      Returns:
      true if signature is valid and voucher not expired, false otherwise
    • getIssuerSignature

      public byte[] getIssuerSignature()
      Returns the issuer signature as bytes.
      Returns:
      signature bytes (64 bytes), or null if not set
    • getIssuerPublicKey

      public String getIssuerPublicKey()
      Returns the issuer public key.
      Returns:
      hex-encoded public key
    • getVoucherId

      public UUID getVoucherId()
    • getIssuerId

      public String getIssuerId()
    • getUnit

      public String getUnit()
    • getFaceValue

      public Long getFaceValue()
    • getExpiresAt

      public Long getExpiresAt()
    • getMemo

      public String getMemo()
    • getBackingStrategy

      public BackingStrategy getBackingStrategy()
    • getIssuanceRatio

      public double getIssuanceRatio()
    • getFaceDecimals

      public int getFaceDecimals()
    • 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