Skip to main content

StampValidator

Trait StampValidator 

Source
pub trait StampValidator {
    type Error: From<StampError>;

    // Required method
    fn validate(
        &self,
        stamp: &Stamp,
        address: &SwarmAddress,
        state: &PostageContext,
    ) -> Result<(), Self::Error>;

    // Provided method
    fn validate_structure(
        &self,
        stamp: &Stamp,
        address: &SwarmAddress,
        state: &PostageContext,
    ) -> Result<(), Self::Error> { ... }
}
Expand description

A trait for validating postage stamps.

Implementations of this trait verify that stamps are valid for a given chunk address and postage context. Validation includes checking:

  • The batch exists and is not expired
  • The stamp index is within valid bounds
  • The chunk address matches the expected bucket
  • The signature is valid (implementation-dependent)

§Example

use nectar_postage::{StampValidator, Stamp, PostageContext};
use nectar_primitives::SwarmAddress;

struct MyValidator { /* ... */ }

impl StampValidator for MyValidator {
    type Error = nectar_postage::StampError;

    fn validate(&self, stamp: &Stamp, address: &SwarmAddress, state: &PostageContext) -> Result<(), Self::Error> {
        // Validation logic...
        Ok(())
    }
}

Required Associated Types§

Source

type Error: From<StampError>

The error type returned when validation fails.

Required Methods§

Source

fn validate( &self, stamp: &Stamp, address: &SwarmAddress, state: &PostageContext, ) -> Result<(), Self::Error>

Validates a stamp for a given chunk address.

§Arguments
  • stamp - The stamp to validate
  • address - The address of the chunk being validated
  • state - The current postage context for expiry checks
§Returns

Ok(()) if the stamp is valid, or an error describing why validation failed.

Provided Methods§

Source

fn validate_structure( &self, stamp: &Stamp, address: &SwarmAddress, state: &PostageContext, ) -> Result<(), Self::Error>

Validates only the structural properties of a stamp without signature verification.

This is useful for quick validation before performing more expensive cryptographic operations. It checks:

  • The batch exists
  • The batch is usable (enough confirmations)
  • The batch is not expired
  • The stamp index is within valid bounds
  • The chunk address matches the expected bucket

The default implementation calls validate, but implementations may override this for performance.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§