Skip to main content

Stamp

Struct Stamp 

Source
pub struct Stamp { /* private fields */ }
Expand description

A postage stamp represents proof of payment for storing a chunk.

Stamps are created by signing a message containing the chunk address, batch ID, stamp index, and timestamp with the batch owner’s private key.

§Wire Format

A serialized stamp is 113 bytes:

  • Batch ID: 32 bytes
  • Bucket (x): 4 bytes, big-endian
  • Index (y): 4 bytes, big-endian
  • Timestamp: 8 bytes, big-endian
  • Signature: 65 bytes (r || s || v)

Implementations§

Source§

impl Stamp

Source

pub const fn new( batch: BatchId, bucket: u32, index: u32, timestamp: u64, sig: Signature, ) -> Self

Creates a new stamp with the given parameters.

Source

pub const fn with_index( batch: BatchId, index: StampIndex, timestamp: u64, sig: Signature, ) -> Self

Creates a new stamp from a stamp index.

Source

pub const fn batch(&self) -> BatchId

Returns the batch ID.

Source

pub const fn stamp_index(&self) -> StampIndex

Returns the stamp index.

Source

pub const fn bucket(&self) -> u32

Returns the collision bucket.

Source

pub const fn index(&self) -> u32

Returns the position within the bucket.

Source

pub const fn timestamp(&self) -> u64

Returns the timestamp.

Source

pub const fn signature(&self) -> &Signature

Returns the signature.

Source

pub fn to_bytes(&self) -> StampBytes

Serializes the stamp to a 113-byte array.

Source

pub fn from_bytes(bytes: &StampBytes) -> Result<Self, StampError>

Deserializes a stamp from a 113-byte array.

Returns an error if the signature bytes are invalid.

Source

pub fn try_from_slice(bytes: &[u8]) -> Result<Self, StampError>

Attempts to deserialize a stamp from a byte slice.

Returns an error if the slice is not exactly 113 bytes or if the signature is invalid.

Source

pub fn recover_signer( &self, chunk_address: &SwarmAddress, ) -> Result<Address, StampError>

Recovers the signer address from this stamp using EIP-191 message recovery.

This computes the stamp digest from the chunk address and stamp fields, then recovers the Ethereum address that signed it.

§Arguments
  • chunk_address - The address of the chunk this stamp is for
§Returns

The Ethereum address of the signer, or an error if recovery fails.

§Example
let stamp = Stamp::try_from_slice(&bytes)?;
let signer = stamp.recover_signer(&chunk_address)?;
println!("Stamp signed by: {}", signer);
Source

pub fn verify( &self, chunk_address: &SwarmAddress, owner: Address, ) -> Result<(), StampError>

Verifies this stamp was signed by the expected owner.

This is a convenience method that calls recover_signer and compares the result to the expected owner address.

§Arguments
  • chunk_address - The address of the chunk this stamp is for
  • owner - The expected owner/signer address
§Returns

Ok(()) if the stamp was signed by the expected owner, or an error if signature recovery fails or the signer doesn’t match.

§Example
let stamp = Stamp::try_from_slice(&bytes)?;
stamp.verify(&chunk_address, batch.owner())?;
Source

pub fn recover_pubkey( &self, chunk_address: &SwarmAddress, ) -> Result<VerifyingKey, StampError>

Recovers the public key from this stamp.

This is useful for caching the public key after the first verification of a batch. Subsequent stamps from the same batch can then use verify_with_pubkey which is approximately 10x faster than full signature recovery.

§Arguments
  • chunk_address - The address of the chunk this stamp is for
§Returns

The public key of the signer, or an error if recovery fails.

§Example
// First stamp: recover public key and cache it
let pubkey = first_stamp.recover_pubkey(&first_chunk_address)?;

// Subsequent stamps: fast verification with cached pubkey
for (stamp, addr) in remaining_stamps {
    stamp.verify_with_pubkey(&addr, &pubkey)?;
}
Source

pub fn verify_with_pubkey( &self, chunk_address: &SwarmAddress, pubkey: &VerifyingKey, ) -> Result<(), StampError>

Verifies this stamp using a known public key.

This is approximately 10x faster than verify or recover_signer because it avoids the expensive ECDSA public key recovery operation.

Use this when you’ve already recovered the owner’s public key from a previous stamp in the same batch (via recover_pubkey).

§Arguments
  • chunk_address - The address of the chunk this stamp is for
  • pubkey - The expected signer’s public key (cached from previous recovery)
§Returns

Ok(()) if the signature is valid for the given public key, or an error if verification fails.

§Example
// First stamp: recover and cache the public key
let pubkey = first_stamp.recover_pubkey(&first_address)?;
let owner = alloy_signer::utils::public_key_to_address(&pubkey);

// Fast verification for remaining stamps in the same batch
second_stamp.verify_with_pubkey(&second_address, &pubkey)?;
third_stamp.verify_with_pubkey(&third_address, &pubkey)?;

Trait Implementations§

Source§

impl<'a> Arbitrary<'a> for Stamp

Available on crate feature arbitrary only.
Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl Clone for Stamp

Source§

fn clone(&self) -> Stamp

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Stamp

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Stamp

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Stamp

Source§

impl From<Stamp> for StampBytes

Source§

fn from(stamp: Stamp) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Stamp

Source§

fn eq(&self, other: &Stamp) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Stamp

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Stamp

Source§

impl TryFrom<[u8; 113]> for Stamp

Source§

type Error = StampError

The type returned in the event of a conversion error.
Source§

fn try_from(bytes: StampBytes) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Stamp

§

impl RefUnwindSafe for Stamp

§

impl Send for Stamp

§

impl Sync for Stamp

§

impl Unpin for Stamp

§

impl UnsafeUnpin for Stamp

§

impl UnwindSafe for Stamp

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<'de, T> BorrowedRpcObject<'de> for T
where T: RpcBorrow<'de> + RpcSend,

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<'de, T> RpcBorrow<'de> for T
where T: Deserialize<'de> + Debug + Send + Sync + Unpin,

Source§

impl<T> RpcObject for T
where T: RpcSend + RpcRecv,

Source§

impl<T> RpcRecv for T
where T: DeserializeOwned + Debug + Send + Sync + Unpin + 'static,

Source§

impl<T> RpcSend for T
where T: Serialize + Clone + Debug + Send + Sync + Unpin,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more