Skip to main content

TimeLockService

Trait TimeLockService 

Source
pub trait TimeLockService {
    // Required methods
    fn lock(
        &self,
        payload: &Payload,
        unlock_at: DateTime<Utc>,
    ) -> Result<TimeLockPuzzle, TimeLockError>;
    fn unlock(&self, puzzle: &TimeLockPuzzle) -> Result<Payload, TimeLockError>;
    fn try_unlock(
        &self,
        puzzle: &TimeLockPuzzle,
    ) -> Result<Option<Payload>, TimeLockError>;
}
Expand description

Rivest sequential-squaring time-lock puzzle port.

A payload cannot be decrypted before a specified time, even under compulsion.

Required Methods§

Source

fn lock( &self, payload: &Payload, unlock_at: DateTime<Utc>, ) -> Result<TimeLockPuzzle, TimeLockError>

Wrap payload in a time-lock puzzle that cannot be solved before unlock_at.

§Errors

Returns TimeLockError::ComputationFailed.

Source

fn unlock(&self, puzzle: &TimeLockPuzzle) -> Result<Payload, TimeLockError>

Solve the puzzle by sequential squaring and decrypt the payload.

Blocks until the puzzle is solved; may take significant time.

§Errors

Returns TimeLockError::ComputationFailed or TimeLockError::DecryptFailed.

Source

fn try_unlock( &self, puzzle: &TimeLockPuzzle, ) -> Result<Option<Payload>, TimeLockError>

Non-blocking puzzle check. Returns Ok(Some(payload)) if the puzzle is already solved, Ok(None) if it cannot yet be solved, or an error if the computation itself fails.

§Errors

Returns TimeLockError::ComputationFailed or TimeLockError::DecryptFailed.

Implementors§