tss

Struct Tss

Source
pub struct Tss<P> {
    pub(crate) peer_id: P,
    pub(crate) frost_id: Identifier,
    pub(crate) frost_to_peer: BTreeMap<Identifier, P>,
    pub(crate) threshold: u16,
    pub(crate) coordinators: BTreeSet<Identifier>,
    pub(crate) state: TssState,
    pub(crate) committed: bool,
}
Expand description

Tss state machine.

Fields§

§peer_id: P§frost_id: Identifier§frost_to_peer: BTreeMap<Identifier, P>§threshold: u16§coordinators: BTreeSet<Identifier>§state: TssState§committed: bool

Implementations§

Source§

impl<P> Tss<P>

Source

pub fn new( peer_id: P, members: BTreeSet<P>, threshold: u16, recover: Option<(SigningShare, VerifiableSecretSharingCommitment)>, span: &Span, ) -> Self

Initializes a new TSS instance with the given parameters.

Flow:

  1. Validates that the peer_id is part of the members.
  2. Converts the peer_id to a FROST identifier.
  3. Maps each member to their FROST identifier.
  4. Selects coordinators from the members.
  5. Determines if the current instance is a coordinator.
  6. If recover is provided, initializes the state with a Roast session; otherwise, initializes with a Dkg session.
  7. Returns the new TSS instance.
Source

pub fn peer_id(&self) -> &P

Returns the peer ID of the TSS instance.

Source

pub(crate) fn frost_to_peer(&self, frost: &Identifier) -> P

Converts a FROST identifier to the corresponding peer ID.

Flow:

  1. Looks up the FROST identifier in the frost_to_peer map.
  2. Returns the corresponding peer ID.
Source

pub fn total_nodes(&self) -> usize

Returns the total number of nodes involved in the TSS process.

Source

pub fn threshold(&self) -> usize

Returns the threshold value for the TSS process.

Source

pub fn committed(&self) -> bool

Checks if the TSS instance has committed.

Source

pub fn on_message(&mut self, peer_id: P, msg: TssMessage, span: &Span)

Handles incoming messages and updates the state accordingly.

Flow:

  1. Logs the receipt of the message.
  2. Validates that the message is not from the peer itself.
  3. Converts the sender to a FROST identifier and validates it.
  4. Processes the message based on the current state (DKG or ROAST).
  5. Returns the result of the processing.
Source

pub fn on_commit( &mut self, commitment: VerifiableSecretSharingCommitment, span: &Span, )

Handles commit actions and updates the state accordingly.

Flow

  1. Logs the commit action.
  2. If in the DKG state, processes the commit and sets committed to true.
  3. Logs an error if not in the DKG state.
Source

pub(crate) fn get_or_insert_session(&mut self, id: u64) -> Option<&mut Roast>

Retrieves or inserts a signing session.

Flow:

  1. If in the ROAST state, retrieves or inserts a signing session for the given ID.
  2. Returns the session or None if not in the ROAST state.
Source

pub fn on_start(&mut self, id: u64, span: &Span)

Starts a signing session for the given ID.

Flow:

  1. Logs the start action.
  2. Inserts a new session if it does not already exist.
  3. Logs an error if not ready to sign.
Source

pub fn on_sign(&mut self, id: u64, data: Vec<u8>, span: &Span)

Signs data for the given session ID.

Flow:

  1. Logs the sign action.
  2. Sets the data for the session if it exists.
  3. Logs an error if not ready to sign.
Source

pub fn on_complete(&mut self, id: u64, span: &Span)

Purpose: Completes a signing session for the given ID.

Flow:

  1. Logs the complete action.
  2. Removes the session if it exists.
  3. Logs an error if not ready to sign.
Source

pub fn next_action(&mut self, span: &Span) -> Option<TssAction<P>>

Retrieves the next action to be performed by the TSS state machine. This could be a message to send, a commitment to make, or a signature to produce. Flow:

  1. If in the DKG state, returns the next DKG action.
  2. If in the ROAST state, returns the next ROAST action.
  3. Returns None if no action is available.

Auto Trait Implementations§

§

impl<P> Freeze for Tss<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for Tss<P>
where P: RefUnwindSafe,

§

impl<P> Send for Tss<P>
where P: Send,

§

impl<P> Sync for Tss<P>
where P: Sync,

§

impl<P> Unpin for Tss<P>
where P: Unpin,

§

impl<P> UnwindSafe for Tss<P>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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