polysig_driver/frost/
error.rs

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
use thiserror::Error;

/// Errors generated by the protocol.
#[derive(Debug, Error)]
pub enum Error {
    /// Error generated an invalid round number is encountered.
    #[error("round {0} is not supported for this protocol")]
    InvalidRound(u8),

    /// Error generated an invalid round payload is encountered.
    #[error("payload for round {0} is not of the correct type")]
    RoundPayload(u8),

    /// Error generated locating an identifier for a party number.
    #[error("party number is not a valid protocol identifier")]
    IndexIdentifier(usize),

    /// Error generated locating an identifier for a message sender.
    #[error("round {0} could not locate identifier for index {1}")]
    SenderIdentifier(u8, usize),

    /// Error generated finding a verifier for a message sender.
    #[error("could not locate a verifier for the message sender")]
    SenderVerifier,

    /// Error generated attempting to proceed to round 2 too early.
    #[error("attempt to proceed to round 2 without round 1 data")]
    Round2TooEarly,

    /// Error generated attempting to proceed to round 3 too early.
    #[error("attempt to proceed to round 3 without round 2 data")]
    Round3TooEarly,

    /// Protocol library errors.
    #[error(transparent)]
    Protocol(#[from] polysig_protocol::Error),

    /// FROST library error.
    #[error(transparent)]
    Frost(#[from] frost_ed25519::Error),
}

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
impl From<Error> for wasm_bindgen::JsValue {
    fn from(value: Error) -> Self {
        let s = value.to_string();
        wasm_bindgen::JsValue::from_str(&s)
    }
}