dkls23/keygen/
mod.rs

1// Copyright (c) Silence Laboratories Pte. Ltd. All Rights Reserved.
2// This software is licensed under the Silence Laboratories License Agreement.
3
4//! This module implements a distributed key generation protocol that allows multiple parties
5//! to collaboratively generate a shared secret key without any single party learning the
6//! complete secret. The protocol includes several sub-protocols for key refresh, quorum
7//! changes, and migration from other protocols.
8//!
9//! # Submodules
10//! * `dkg` - Core distributed key generation protocol
11//! * `types` - Common types used across the protocol
12//! * `utils` - Utility functions and helpers
13//! * `key_refresh` - Protocol for refreshing existing keys
14//! * `keyshare` - Key share management and related definitions
15//! * `constants` - Protocol constants and configuration
16//! * `migration` - Migration utilities to DKLS23 protocol
17//! * `quorum_change` - Protocol for changing the quorum of participants
18
19pub mod dkg;
20pub mod types;
21
22/// Misc reusable code
23pub mod utils;
24
25pub use dkg::*;
26pub use types::*;
27
28pub mod key_refresh;
29
30mod messages;
31
32pub mod keyshare;
33
34pub mod constants;
35
36pub mod migration;
37
38pub mod quorum_change;
39
40pub use keyshare::Keyshare;
41
42use sl_mpc_mate::message::MsgId;
43
44use crate::setup::{ProtocolParticipant, ABORT_MESSAGE_TAG};
45
46/// Generates a map of message receivers for the DKG protocol.
47///
48/// This function iterates through all other parties in the protocol and calls the provided
49/// closure for each message ID and corresponding verifier key. It handles all message types
50/// used in the DKG protocol, including abort messages and messages for each round.
51///
52/// # Arguments
53/// * `setup` - The protocol participant setup containing party information
54/// * `msg_receiver` - A closure that will be called for each (message_id, verifier) pair
55///
56/// # Message Types
57/// The function handles the following message types:
58/// * `ABORT_MESSAGE_TAG` - Protocol abort messages
59/// * `DKG_MSG_R1` - Round 1 messages
60/// * `DKG_MSG_R2` - Round 2 messages
61/// * `DKG_MSG_OT1` - Oblivious transfer messages
62/// * `DKG_MSG_R3` - Round 3 messages
63/// * `DKG_MSG_R4` - Round 4 messages
64pub fn message_receivers<S, F>(setup: &S, mut msg_receiver: F)
65where
66    S: ProtocolParticipant,
67    F: FnMut(MsgId, &S::MessageVerifier),
68{
69    setup.all_other_parties().for_each(|p| {
70        let vk = setup.verifier(p);
71
72        msg_receiver(setup.msg_id(None, ABORT_MESSAGE_TAG), vk);
73        msg_receiver(setup.msg_id(None, constants::DKG_MSG_R1), vk);
74        msg_receiver(setup.msg_id(None, constants::DKG_MSG_R2), vk);
75        msg_receiver(setup.msg_id(Some(p), constants::DKG_MSG_OT1), vk);
76        msg_receiver(setup.msg_id(Some(p), constants::DKG_MSG_R3), vk);
77        msg_receiver(setup.msg_id(None, constants::DKG_MSG_R4), vk);
78    })
79}