Class VoucherValidator
java.lang.Object
xyz.tcheeric.cashu.voucher.domain.VoucherValidator
Validates vouchers for correctness and authenticity.
This class provides comprehensive validation logic for signed vouchers, including:
- Cryptographic signature verification
- Expiry validation
- Face value validation
- Business rule validation
Validation Rules
A voucher is considered valid if ALL of the following conditions are met:
- The issuer's signature is cryptographically valid (ED25519 verification)
- The voucher has not expired (if expiry is set)
- The face value is positive
Usage Examples
// Basic validation
ValidationResult result = VoucherValidator.validate(signedVoucher);
if (result.isValid()) {
// Proceed with redemption
} else {
// Handle errors
result.getErrors().forEach(System.err::println);
}
// Validation with issuer check
ValidationResult result = VoucherValidator.validateWithIssuer(
signedVoucher,
expectedIssuerId
);
Thread Safety
All methods are stateless and thread-safe.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classResult of voucher validation containing status and error messages. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisValid(@NonNull SignedVoucher voucher) Quick check if a voucher is valid (no detailed errors).validate(@NonNull SignedVoucher voucher) Validates a signed voucher.validateExpiryOnly(@NonNull SignedVoucher voucher) Validates just the expiry of a voucher.validateSignatureOnly(@NonNull SignedVoucher voucher) Validates just the cryptographic signature of a voucher.validateWithIssuer(@NonNull SignedVoucher voucher, @NonNull String expectedIssuerId) Validates a signed voucher and checks that it was issued by the expected issuer.
-
Method Details
-
validate
Validates a signed voucher.Performs comprehensive validation including:
- Signature verification
- Expiry check
- Face value validation
- Parameters:
voucher- the signed voucher to validate (must not be null)- Returns:
- validation result with success status and any errors
-
validateWithIssuer
public static VoucherValidator.ValidationResult validateWithIssuer(@NonNull @NonNull SignedVoucher voucher, @NonNull @NonNull String expectedIssuerId) Validates a signed voucher and checks that it was issued by the expected issuer.This is useful for merchant-side validation to ensure the voucher was issued by their own merchant account.
- Parameters:
voucher- the signed voucher to validate (must not be null)expectedIssuerId- the expected issuer ID (must not be null)- Returns:
- validation result with success status and any errors
-
validateSignatureOnly
public static VoucherValidator.ValidationResult validateSignatureOnly(@NonNull @NonNull SignedVoucher voucher) Validates just the cryptographic signature of a voucher.This is a lightweight check that only verifies the signature, without checking expiry or other business rules.
- Parameters:
voucher- the signed voucher to validate (must not be null)- Returns:
- validation result for signature only
-
validateExpiryOnly
public static VoucherValidator.ValidationResult validateExpiryOnly(@NonNull @NonNull SignedVoucher voucher) Validates just the expiry of a voucher.This is useful for periodic checks of voucher validity without re-verifying the signature.
- Parameters:
voucher- the signed voucher to validate (must not be null)- Returns:
- validation result for expiry only
-
isValid
Quick check if a voucher is valid (no detailed errors).This is a convenience method equivalent to
validate(voucher).isValid().- Parameters:
voucher- the signed voucher to check (must not be null)- Returns:
- true if voucher is valid, false otherwise
-