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>
impl<P> Tss<P>
Sourcepub fn new(
peer_id: P,
members: BTreeSet<P>,
threshold: u16,
recover: Option<(SigningShare, VerifiableSecretSharingCommitment)>,
span: &Span,
) -> Self
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:
- Validates that the peer_id is part of the members.
- Converts the peer_id to a FROST identifier.
- Maps each member to their FROST identifier.
- Selects coordinators from the members.
- Determines if the current instance is a coordinator.
- If recover is provided, initializes the state with a Roast session; otherwise, initializes with a Dkg session.
- Returns the new TSS instance.
Sourcepub(crate) fn frost_to_peer(&self, frost: &Identifier) -> P
pub(crate) fn frost_to_peer(&self, frost: &Identifier) -> P
Converts a FROST identifier to the corresponding peer ID.
Flow:
- Looks up the FROST identifier in the frost_to_peer map.
- Returns the corresponding peer ID.
Sourcepub fn total_nodes(&self) -> usize
pub fn total_nodes(&self) -> usize
Returns the total number of nodes involved in the TSS process.
Sourcepub fn on_message(&mut self, peer_id: P, msg: TssMessage, span: &Span)
pub fn on_message(&mut self, peer_id: P, msg: TssMessage, span: &Span)
Handles incoming messages and updates the state accordingly.
Flow:
- Logs the receipt of the message.
- Validates that the message is not from the peer itself.
- Converts the sender to a FROST identifier and validates it.
- Processes the message based on the current state (DKG or ROAST).
- Returns the result of the processing.
Sourcepub fn on_commit(
&mut self,
commitment: VerifiableSecretSharingCommitment,
span: &Span,
)
pub fn on_commit( &mut self, commitment: VerifiableSecretSharingCommitment, span: &Span, )
Handles commit actions and updates the state accordingly.
Flow
- Logs the commit action.
- If in the DKG state, processes the commit and sets committed to true.
- Logs an error if not in the DKG state.
Sourcepub(crate) fn get_or_insert_session(&mut self, id: u64) -> Option<&mut Roast>
pub(crate) fn get_or_insert_session(&mut self, id: u64) -> Option<&mut Roast>
Retrieves or inserts a signing session.
Flow:
- If in the ROAST state, retrieves or inserts a signing session for the given ID.
- Returns the session or None if not in the ROAST state.
Sourcepub fn on_start(&mut self, id: u64, span: &Span)
pub fn on_start(&mut self, id: u64, span: &Span)
Starts a signing session for the given ID.
Flow:
- Logs the start action.
- Inserts a new session if it does not already exist.
- Logs an error if not ready to sign.
Sourcepub fn on_sign(&mut self, id: u64, data: Vec<u8>, span: &Span)
pub fn on_sign(&mut self, id: u64, data: Vec<u8>, span: &Span)
Signs data for the given session ID.
Flow:
- Logs the sign action.
- Sets the data for the session if it exists.
- Logs an error if not ready to sign.
Sourcepub fn on_complete(&mut self, id: u64, span: &Span)
pub fn on_complete(&mut self, id: u64, span: &Span)
Purpose: Completes a signing session for the given ID.
Flow:
- Logs the complete action.
- Removes the session if it exists.
- Logs an error if not ready to sign.
Sourcepub fn next_action(&mut self, span: &Span) -> Option<TssAction<P>>
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:
- If in the DKG state, returns the next DKG action.
- If in the ROAST state, returns the next ROAST action.
- 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>where
P: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more