chie-crypto 0.2.0

Cryptographic primitives for CHIE Protocol
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
//! Multi-party key generation ceremony support.
//!
//! This module provides a high-level ceremony orchestration layer on top of
//! the existing DKG (Distributed Key Generation) implementation. It handles:
//!
//! - Ceremony coordination across multiple rounds
//! - Participant management and verification
//! - State management and persistence
//! - Communication message routing
//! - Error handling and recovery
//! - Ceremony attestation and audit trail
//!
//! # Example
//!
//! ```
//! use chie_crypto::keygen_ceremony::*;
//!
//! // Create a ceremony for 3 participants with 2-of-3 threshold
//! let mut ceremony = KeygenCeremony::new(
//!     CeremonyConfig::new(3, 2, "test-ceremony".to_string())
//! ).unwrap();
//!
//! // Each participant joins the ceremony
//! let participant_ids: Vec<_> = (0..3)
//!     .map(|i| ceremony.add_participant(format!("participant-{}", i)).unwrap())
//!     .collect();
//!
//! // Mark all participants as ready
//! for id in &participant_ids {
//!     ceremony.mark_ready(id).unwrap();
//! }
//!
//! // Start the ceremony
//! ceremony.start().unwrap();
//!
//! // Ceremony proceeds through rounds until complete
//! assert_eq!(ceremony.state(), CeremonyState::InProgress);
//! ```

use crate::dkg::DkgParams;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::time::SystemTime;
use thiserror::Error;

/// Errors that can occur during key generation ceremony.
#[derive(Debug, Error)]
pub enum CeremonyError {
    #[error("Invalid ceremony configuration: {0}")]
    InvalidConfig(String),

    #[error("Ceremony not in correct state: expected {expected}, got {actual}")]
    InvalidState { expected: String, actual: String },

    #[error("Participant not found: {0}")]
    ParticipantNotFound(String),

    #[error("Participant already exists: {0}")]
    ParticipantAlreadyExists(String),

    #[error("Invalid participant count: expected {expected}, got {actual}")]
    InvalidParticipantCount { expected: usize, actual: usize },

    #[error("Round {0} not yet complete")]
    RoundIncomplete(usize),

    #[error("Ceremony timeout: {0}")]
    Timeout(String),

    #[error("DKG error: {0}")]
    DkgError(String),

    #[error("Serialization error: {0}")]
    SerializationError(String),

    #[error("Verification failed: {0}")]
    VerificationFailed(String),
}

/// Result type for ceremony operations.
pub type CeremonyResult<T> = Result<T, CeremonyError>;

/// Ceremony state.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum CeremonyState {
    /// Ceremony is being configured
    Setup,
    /// Waiting for all participants to join
    WaitingForParticipants,
    /// Ceremony is in progress
    InProgress,
    /// Ceremony completed successfully
    Completed,
    /// Ceremony was aborted
    Aborted,
    /// Ceremony failed
    Failed,
}

impl std::fmt::Display for CeremonyState {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Setup => write!(f, "Setup"),
            Self::WaitingForParticipants => write!(f, "WaitingForParticipants"),
            Self::InProgress => write!(f, "InProgress"),
            Self::Completed => write!(f, "Completed"),
            Self::Aborted => write!(f, "Aborted"),
            Self::Failed => write!(f, "Failed"),
        }
    }
}

/// Participant information.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParticipantInfo {
    /// Unique participant ID
    pub id: String,
    /// Participant index (0-based)
    pub index: usize,
    /// When the participant joined (Unix timestamp)
    pub joined_at: u64,
    /// Whether the participant is ready
    pub ready: bool,
    /// Metadata
    pub metadata: HashMap<String, String>,
}

impl ParticipantInfo {
    /// Create new participant info
    pub fn new(id: String, index: usize) -> Self {
        Self {
            id,
            index,
            joined_at: SystemTime::now()
                .duration_since(SystemTime::UNIX_EPOCH)
                .unwrap_or_default()
                .as_secs(),
            ready: false,
            metadata: HashMap::new(),
        }
    }

    /// Add metadata
    pub fn with_metadata(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
        self.metadata.insert(key.into(), value.into());
        self
    }
}

/// Ceremony configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CeremonyConfig {
    /// Total number of participants (N)
    pub total_participants: usize,
    /// Threshold (M in M-of-N)
    pub threshold: usize,
    /// Ceremony ID
    pub ceremony_id: String,
    /// Timeout in seconds (0 = no timeout)
    pub timeout_seconds: u64,
    /// Require all participants to be ready before starting
    pub require_ready_check: bool,
    /// Metadata
    pub metadata: HashMap<String, String>,
}

impl CeremonyConfig {
    /// Create new ceremony configuration
    pub fn new(total_participants: usize, threshold: usize, ceremony_id: String) -> Self {
        Self {
            total_participants,
            threshold,
            ceremony_id,
            timeout_seconds: 300, // 5 minutes default
            require_ready_check: true,
            metadata: HashMap::new(),
        }
    }

    /// Set timeout
    pub fn with_timeout(mut self, seconds: u64) -> Self {
        self.timeout_seconds = seconds;
        self
    }

    /// Disable ready check
    pub fn without_ready_check(mut self) -> Self {
        self.require_ready_check = false;
        self
    }

    /// Add metadata
    pub fn with_metadata(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
        self.metadata.insert(key.into(), value.into());
        self
    }

    /// Validate configuration
    pub fn validate(&self) -> CeremonyResult<()> {
        if self.total_participants < 2 {
            return Err(CeremonyError::InvalidConfig(
                "At least 2 participants required".to_string(),
            ));
        }

        if self.threshold < 1 || self.threshold > self.total_participants {
            return Err(CeremonyError::InvalidConfig(format!(
                "Threshold must be between 1 and {}, got {}",
                self.total_participants, self.threshold
            )));
        }

        if self.ceremony_id.is_empty() {
            return Err(CeremonyError::InvalidConfig(
                "Ceremony ID cannot be empty".to_string(),
            ));
        }

        Ok(())
    }
}

/// Ceremony attestation record.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CeremonyAttestation {
    /// Ceremony ID
    pub ceremony_id: String,
    /// Configuration used
    pub config: CeremonyConfig,
    /// Participants who participated
    pub participants: Vec<ParticipantInfo>,
    /// Start timestamp (Unix seconds)
    pub started_at: u64,
    /// Completion timestamp (Unix seconds)
    pub completed_at: Option<u64>,
    /// Final state
    pub final_state: CeremonyState,
    /// Audit log
    pub audit_log: Vec<String>,
}

impl CeremonyAttestation {
    /// Create new attestation
    pub fn new(ceremony_id: String, config: CeremonyConfig) -> Self {
        Self {
            ceremony_id,
            config,
            participants: Vec::new(),
            started_at: SystemTime::now()
                .duration_since(SystemTime::UNIX_EPOCH)
                .unwrap_or_default()
                .as_secs(),
            completed_at: None,
            final_state: CeremonyState::Setup,
            audit_log: Vec::new(),
        }
    }

    /// Add audit log entry
    pub fn log(&mut self, entry: impl Into<String>) {
        self.audit_log.push(entry.into());
    }

    /// Mark as completed
    pub fn complete(&mut self, state: CeremonyState) {
        self.completed_at = Some(
            SystemTime::now()
                .duration_since(SystemTime::UNIX_EPOCH)
                .unwrap_or_default()
                .as_secs(),
        );
        self.final_state = state;
    }
}

/// Key generation ceremony orchestrator.
pub struct KeygenCeremony {
    config: CeremonyConfig,
    state: CeremonyState,
    participants: HashMap<String, ParticipantInfo>,
    dkg_params: Option<DkgParams>,
    current_round: usize,
    attestation: CeremonyAttestation,
}

impl KeygenCeremony {
    /// Create a new ceremony
    pub fn new(config: CeremonyConfig) -> CeremonyResult<Self> {
        config.validate()?;

        let attestation = CeremonyAttestation::new(config.ceremony_id.clone(), config.clone());

        Ok(Self {
            config,
            state: CeremonyState::Setup,
            participants: HashMap::new(),
            dkg_params: None,
            current_round: 0,
            attestation,
        })
    }

    /// Get current state
    pub fn state(&self) -> CeremonyState {
        self.state
    }

    /// Get ceremony ID
    pub fn ceremony_id(&self) -> &str {
        &self.config.ceremony_id
    }

    /// Add a participant to the ceremony
    pub fn add_participant(&mut self, id: String) -> CeremonyResult<String> {
        // Check if ceremony is in correct state
        if self.state != CeremonyState::Setup && self.state != CeremonyState::WaitingForParticipants
        {
            return Err(CeremonyError::InvalidState {
                expected: "Setup or WaitingForParticipants".to_string(),
                actual: self.state.to_string(),
            });
        }

        // Check if participant already exists
        if self.participants.contains_key(&id) {
            return Err(CeremonyError::ParticipantAlreadyExists(id));
        }

        // Check if we've reached the limit
        if self.participants.len() >= self.config.total_participants {
            return Err(CeremonyError::InvalidParticipantCount {
                expected: self.config.total_participants,
                actual: self.participants.len() + 1,
            });
        }

        let index = self.participants.len();
        let participant = ParticipantInfo::new(id.clone(), index);

        self.participants.insert(id.clone(), participant.clone());
        self.attestation.participants.push(participant);
        self.attestation
            .log(format!("Participant {} joined (index {})", id, index));

        // Transition to waiting state if this is the first participant
        if self.state == CeremonyState::Setup {
            self.state = CeremonyState::WaitingForParticipants;
        }

        Ok(id)
    }

    /// Mark a participant as ready
    pub fn mark_ready(&mut self, participant_id: &str) -> CeremonyResult<()> {
        let participant = self
            .participants
            .get_mut(participant_id)
            .ok_or_else(|| CeremonyError::ParticipantNotFound(participant_id.to_string()))?;

        participant.ready = true;
        self.attestation
            .log(format!("Participant {} marked ready", participant_id));

        Ok(())
    }

    /// Check if all participants have joined and are ready
    pub fn all_ready(&self) -> bool {
        if self.participants.len() != self.config.total_participants {
            return false;
        }

        if self.config.require_ready_check {
            self.participants.values().all(|p| p.ready)
        } else {
            true
        }
    }

    /// Start the ceremony
    pub fn start(&mut self) -> CeremonyResult<()> {
        // Check state
        if self.state != CeremonyState::WaitingForParticipants {
            return Err(CeremonyError::InvalidState {
                expected: "WaitingForParticipants".to_string(),
                actual: self.state.to_string(),
            });
        }

        // Check if all participants are ready
        if !self.all_ready() {
            return Err(CeremonyError::InvalidState {
                expected: "All participants ready".to_string(),
                actual: format!(
                    "{}/{} participants ready",
                    self.participants.values().filter(|p| p.ready).count(),
                    self.config.total_participants
                ),
            });
        }

        // Initialize DKG parameters
        let params = DkgParams::new(self.config.total_participants, self.config.threshold);

        self.dkg_params = Some(params);
        self.state = CeremonyState::InProgress;
        self.current_round = 1;
        self.attestation.log("Ceremony started".to_string());

        Ok(())
    }

    /// Abort the ceremony
    pub fn abort(&mut self, reason: impl Into<String>) {
        let reason = reason.into();
        self.state = CeremonyState::Aborted;
        self.attestation
            .log(format!("Ceremony aborted: {}", reason));
        self.attestation.complete(CeremonyState::Aborted);
    }

    /// Mark ceremony as completed
    pub fn complete(&mut self) -> CeremonyResult<()> {
        if self.state != CeremonyState::InProgress {
            return Err(CeremonyError::InvalidState {
                expected: "InProgress".to_string(),
                actual: self.state.to_string(),
            });
        }

        self.state = CeremonyState::Completed;
        self.attestation
            .log("Ceremony completed successfully".to_string());
        self.attestation.complete(CeremonyState::Completed);

        Ok(())
    }

    /// Get attestation record
    pub fn attestation(&self) -> &CeremonyAttestation {
        &self.attestation
    }

    /// Get participant info
    pub fn get_participant(&self, id: &str) -> Option<&ParticipantInfo> {
        self.participants.get(id)
    }

    /// List all participants
    pub fn list_participants(&self) -> Vec<&ParticipantInfo> {
        self.participants.values().collect()
    }

    /// Get current round number
    pub fn current_round(&self) -> usize {
        self.current_round
    }

    /// Get DKG parameters
    pub fn dkg_params(&self) -> Option<&DkgParams> {
        self.dkg_params.as_ref()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_ceremony_config_validation() {
        // Valid config
        let config = CeremonyConfig::new(3, 2, "test".to_string());
        assert!(config.validate().is_ok());

        // Invalid: too few participants
        let config = CeremonyConfig::new(1, 1, "test".to_string());
        assert!(config.validate().is_err());

        // Invalid: threshold too high
        let config = CeremonyConfig::new(3, 4, "test".to_string());
        assert!(config.validate().is_err());

        // Invalid: threshold zero
        let config = CeremonyConfig::new(3, 0, "test".to_string());
        assert!(config.validate().is_err());

        // Invalid: empty ceremony ID
        let config = CeremonyConfig::new(3, 2, "".to_string());
        assert!(config.validate().is_err());
    }

    #[test]
    fn test_ceremony_lifecycle() {
        let config = CeremonyConfig::new(3, 2, "test-ceremony".to_string());
        let mut ceremony = KeygenCeremony::new(config).unwrap();

        assert_eq!(ceremony.state(), CeremonyState::Setup);

        // Add participants
        let p1 = ceremony.add_participant("alice".to_string()).unwrap();
        assert_eq!(ceremony.state(), CeremonyState::WaitingForParticipants);

        let p2 = ceremony.add_participant("bob".to_string()).unwrap();
        let p3 = ceremony.add_participant("charlie".to_string()).unwrap();

        // Cannot add more participants
        let result = ceremony.add_participant("dave".to_string());
        assert!(result.is_err());

        // Mark all as ready
        ceremony.mark_ready(&p1).unwrap();
        ceremony.mark_ready(&p2).unwrap();
        ceremony.mark_ready(&p3).unwrap();

        assert!(ceremony.all_ready());

        // Start ceremony
        ceremony.start().unwrap();
        assert_eq!(ceremony.state(), CeremonyState::InProgress);
        assert_eq!(ceremony.current_round(), 1);

        // Complete ceremony
        ceremony.complete().unwrap();
        assert_eq!(ceremony.state(), CeremonyState::Completed);
    }

    #[test]
    fn test_ceremony_abort() {
        let config = CeremonyConfig::new(2, 2, "abort-test".to_string());
        let mut ceremony = KeygenCeremony::new(config).unwrap();

        ceremony.add_participant("alice".to_string()).unwrap();
        ceremony.abort("Testing abort");

        assert_eq!(ceremony.state(), CeremonyState::Aborted);

        let attestation = ceremony.attestation();
        assert_eq!(attestation.final_state, CeremonyState::Aborted);
        assert!(attestation.completed_at.is_some());
    }

    #[test]
    fn test_participant_management() {
        let config = CeremonyConfig::new(3, 2, "participants-test".to_string());
        let mut ceremony = KeygenCeremony::new(config).unwrap();

        // Add participants
        ceremony.add_participant("alice".to_string()).unwrap();
        ceremony.add_participant("bob".to_string()).unwrap();

        // Get participant
        let alice = ceremony.get_participant("alice").unwrap();
        assert_eq!(alice.id, "alice");
        assert_eq!(alice.index, 0);
        assert!(!alice.ready);

        // List participants
        let participants = ceremony.list_participants();
        assert_eq!(participants.len(), 2);

        // Participant not found
        assert!(ceremony.get_participant("charlie").is_none());
    }

    #[test]
    fn test_ready_check() {
        let config = CeremonyConfig::new(2, 2, "ready-test".to_string());
        let mut ceremony = KeygenCeremony::new(config).unwrap();

        ceremony.add_participant("alice".to_string()).unwrap();
        ceremony.add_participant("bob".to_string()).unwrap();

        assert!(!ceremony.all_ready());

        ceremony.mark_ready("alice").unwrap();
        assert!(!ceremony.all_ready());

        ceremony.mark_ready("bob").unwrap();
        assert!(ceremony.all_ready());
    }

    #[test]
    fn test_ready_check_disabled() {
        let config = CeremonyConfig::new(2, 2, "no-ready-test".to_string()).without_ready_check();
        let mut ceremony = KeygenCeremony::new(config).unwrap();

        ceremony.add_participant("alice".to_string()).unwrap();
        ceremony.add_participant("bob".to_string()).unwrap();

        // Should be ready even though no one marked ready
        assert!(ceremony.all_ready());
    }

    #[test]
    fn test_attestation() {
        let config = CeremonyConfig::new(2, 2, "attestation-test".to_string());
        let mut ceremony = KeygenCeremony::new(config).unwrap();

        ceremony.add_participant("alice".to_string()).unwrap();
        ceremony.add_participant("bob".to_string()).unwrap();
        ceremony.mark_ready("alice").unwrap();
        ceremony.mark_ready("bob").unwrap();
        ceremony.start().unwrap();
        ceremony.complete().unwrap();

        let attestation = ceremony.attestation();
        assert_eq!(attestation.ceremony_id, "attestation-test");
        assert_eq!(attestation.participants.len(), 2);
        assert_eq!(attestation.final_state, CeremonyState::Completed);
        assert!(attestation.completed_at.is_some());
        assert!(!attestation.audit_log.is_empty());
    }

    #[test]
    fn test_dkg_params_initialization() {
        let config = CeremonyConfig::new(3, 2, "dkg-test".to_string());
        let mut ceremony = KeygenCeremony::new(config).unwrap();

        // DKG params should not be set until ceremony starts
        assert!(ceremony.dkg_params().is_none());

        ceremony.add_participant("alice".to_string()).unwrap();
        ceremony.add_participant("bob".to_string()).unwrap();
        ceremony.add_participant("charlie".to_string()).unwrap();
        ceremony.mark_ready("alice").unwrap();
        ceremony.mark_ready("bob").unwrap();
        ceremony.mark_ready("charlie").unwrap();

        ceremony.start().unwrap();

        // DKG params should now be set
        let params = ceremony.dkg_params().unwrap();
        assert_eq!(params.threshold, 2);
        assert_eq!(params.total_parties, 3);
    }

    #[test]
    fn test_ceremony_state_transitions() {
        let config = CeremonyConfig::new(2, 2, "state-test".to_string());
        let mut ceremony = KeygenCeremony::new(config).unwrap();

        // Setup -> WaitingForParticipants (when first participant joins)
        assert_eq!(ceremony.state(), CeremonyState::Setup);
        ceremony.add_participant("alice".to_string()).unwrap();
        assert_eq!(ceremony.state(), CeremonyState::WaitingForParticipants);

        // Cannot start before all ready
        let result = ceremony.start();
        assert!(result.is_err());

        ceremony.add_participant("bob".to_string()).unwrap();
        ceremony.mark_ready("alice").unwrap();
        ceremony.mark_ready("bob").unwrap();

        // WaitingForParticipants -> InProgress
        ceremony.start().unwrap();
        assert_eq!(ceremony.state(), CeremonyState::InProgress);

        // InProgress -> Completed
        ceremony.complete().unwrap();
        assert_eq!(ceremony.state(), CeremonyState::Completed);
    }

    #[test]
    fn test_config_builder() {
        let config = CeremonyConfig::new(5, 3, "builder-test".to_string())
            .with_timeout(600)
            .without_ready_check()
            .with_metadata("purpose", "testing")
            .with_metadata("version", "1.0");

        assert_eq!(config.timeout_seconds, 600);
        assert!(!config.require_ready_check);
        assert_eq!(config.metadata.get("purpose"), Some(&"testing".to_string()));
        assert_eq!(config.metadata.get("version"), Some(&"1.0".to_string()));
    }

    #[test]
    fn test_participant_info_metadata() {
        let participant = ParticipantInfo::new("alice".to_string(), 0)
            .with_metadata("role", "coordinator")
            .with_metadata("location", "US");

        assert_eq!(participant.id, "alice");
        assert_eq!(participant.index, 0);
        assert_eq!(
            participant.metadata.get("role"),
            Some(&"coordinator".to_string())
        );
        assert_eq!(
            participant.metadata.get("location"),
            Some(&"US".to_string())
        );
    }

    #[test]
    fn test_duplicate_participant() {
        let config = CeremonyConfig::new(3, 2, "dup-test".to_string());
        let mut ceremony = KeygenCeremony::new(config).unwrap();

        ceremony.add_participant("alice".to_string()).unwrap();

        // Try to add same participant again
        let result = ceremony.add_participant("alice".to_string());
        assert!(matches!(
            result,
            Err(CeremonyError::ParticipantAlreadyExists(_))
        ));
    }

    #[test]
    fn test_mark_ready_nonexistent_participant() {
        let config = CeremonyConfig::new(2, 2, "nonexistent-test".to_string());
        let mut ceremony = KeygenCeremony::new(config).unwrap();

        let result = ceremony.mark_ready("alice");
        assert!(matches!(result, Err(CeremonyError::ParticipantNotFound(_))));
    }
}