Skip to main content

Timelock

Struct Timelock 

Source
pub struct Timelock<'a, S>
where S: Scheme,
{ /* private fields */ }
Expand description

Encrypts and decrypts messages for one drand chain.

Construct the chain info with an independently pinned chain hash. A verified beacon from that chain is required for decryption.

Implementations§

Source§

impl<'a, S> Timelock<'a, S>
where S: Scheme,

Source

pub const fn new(chain_info: &'a ChainInfo<S>) -> Timelock<'a, S>

Creates a timelock using chain_info.

This does not check a pinned chain hash. Use ChainInfo::new_pinned when obtaining chain info from a relay.

Source

pub const fn chain_info(&self) -> &ChainInfo<S>

Returns the chain info used by this timelock.

Source§

impl Timelock<'_, PedersenBlsUnchained>

Source

pub fn encrypt<const N: usize>( &self, rng: &mut impl CryptoRng, round: Round, msg: &[u8; N], ) -> Result<Ciphertext<G1Projective, N>, Error>

Encrypts msg for round using fresh randomness from rng.

N must be between 16 and 32, inclusive; other lengths fail to compile.

§Errors

Returns Error::InvalidPublicKey if the chain’s public key is invalid.

§Panics

Panics if the RNG panics or scalar rejection sampling is exhausted.

Source

pub fn decrypt<const N: usize>( &self, ciphertext: &Ciphertext<G1Projective, N>, beacon: &VerifiedBeacon<PedersenBlsUnchained>, ) -> Result<Zeroizing<[u8; N]>, Error>

Decrypts ciphertext using the target round’s verified beacon.

N must be between 16 and 32, inclusive; other lengths fail to compile. The returned plaintext is cleared on drop.

§Errors

Returns an error if the round or chain differs, the beacon signature is malformed, or the ciphertext fails its integrity check.

§Panics

Panics if scalar rejection sampling is exhausted.

Source§

impl Timelock<'_, BlsUnchainedOnG1>

Source

pub fn encrypt<const N: usize>( &self, rng: &mut impl CryptoRng, round: Round, msg: &[u8; N], ) -> Result<Ciphertext<G2Projective, N>, Error>

Encrypts msg for round using fresh randomness from rng.

This legacy scheme uses drand’s non-RFC-9380 domain separation tag. N must be between 16 and 32, inclusive; other lengths fail to compile.

§Errors

Returns Error::InvalidPublicKey if the chain’s public key is invalid.

§Panics

Panics if the RNG panics or scalar rejection sampling is exhausted.

Source

pub fn decrypt<const N: usize>( &self, ciphertext: &Ciphertext<G2Projective, N>, beacon: &VerifiedBeacon<BlsUnchainedOnG1>, ) -> Result<Zeroizing<[u8; N]>, Error>

Decrypts ciphertext using the target round’s verified beacon.

N must be between 16 and 32, inclusive; other lengths fail to compile. The returned plaintext is cleared on drop.

§Errors

Returns an error if the round or chain differs, the beacon signature is malformed, or the ciphertext fails its integrity check.

§Panics

Panics if scalar rejection sampling is exhausted.

Source§

impl Timelock<'_, BlsUnchainedG1Rfc9380>

Source

pub fn encrypt<const N: usize>( &self, rng: &mut impl CryptoRng, round: Round, msg: &[u8; N], ) -> Result<Ciphertext<G2Projective, N>, Error>

Encrypts msg for round using fresh randomness from rng.

N must be between 16 and 32, inclusive; other lengths fail to compile.

§Errors

Returns Error::InvalidPublicKey if the chain’s public key is invalid.

§Panics

Panics if the RNG panics or scalar rejection sampling is exhausted.

Source

pub fn decrypt<const N: usize>( &self, ciphertext: &Ciphertext<G2Projective, N>, beacon: &VerifiedBeacon<BlsUnchainedG1Rfc9380>, ) -> Result<Zeroizing<[u8; N]>, Error>

Decrypts ciphertext using the target round’s verified beacon.

N must be between 16 and 32, inclusive; other lengths fail to compile. The returned plaintext is cleared on drop.

§Errors

Returns an error if the round or chain differs, the beacon signature is malformed, or the ciphertext fails its integrity check.

§Panics

Panics if scalar rejection sampling is exhausted.

Trait Implementations§

Source§

impl<'a, S> Clone for Timelock<'a, S>
where S: Clone + Scheme,

Source§

fn clone(&self) -> Timelock<'a, S>

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<'a, S> Copy for Timelock<'a, S>
where S: Copy + Scheme,

Source§

impl<'a, S> Debug for Timelock<'a, S>
where S: Debug + Scheme,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, S> Forget for Timelock<'a, S>

§

impl<'a, S> Freeze for Timelock<'a, S>
where &'a ChainInfo<S>: Freeze,

§

impl<'a, S> RefUnwindSafe for Timelock<'a, S>
where &'a ChainInfo<S>: RefUnwindSafe,

§

impl<'a, S> Send for Timelock<'a, S>
where &'a ChainInfo<S>: Send,

§

impl<'a, S> Sync for Timelock<'a, S>
where &'a ChainInfo<S>: Sync,

§

impl<'a, S> Unpin for Timelock<'a, S>
where &'a ChainInfo<S>: Unpin,

§

impl<'a, S> UnsafeUnpin for Timelock<'a, S>
where &'a ChainInfo<S>: UnsafeUnpin,

§

impl<'a, S> UnwindSafe for Timelock<'a, S>
where &'a ChainInfo<S>: UnwindSafe,

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<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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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<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