polysig_driver/
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
50
51
52
53
54
55
56
57
58
59
60
61
use thiserror::Error;

/// Errors generated by the driver.
#[derive(Debug, Error)]
pub enum Error {
    /// Error when the session identifier for an incoming message
    /// does not match the session identifier assigned to the bridge.
    #[error("session identifier mismatch for incoming message")]
    SessionIdMismatch,

    /// Error generated when a session identifier is required.
    #[error("session identifier required")]
    SessionIdRequired,

    /// Signing key does not exist in list of verifying keys.
    #[error("signer is not a verifying party")]
    NotVerifyingParty,

    /// Error when noise protocol participants list does not match
    /// the number of verifying keys.
    #[error("number of participants '{0}' does not match number of verifying keys '{1}'")]
    ParticipantVerifierLength(usize, usize),

    /// JSON error.
    #[error(transparent)]
    Json(#[from] serde_json::Error),

    /// CGGMP driver errors.
    #[cfg(feature = "cggmp")]
    #[error(transparent)]
    Cggmp(#[from] crate::cggmp::Error),

    /// FROST driver errors.
    #[cfg(feature = "frost-ed25519")]
    #[error(transparent)]
    Frost(#[from] crate::frost::Error),

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

    /// ECDSA library errors.
    #[cfg(any(feature = "cggmp", feature = "ecdsa",))]
    #[error(transparent)]
    Ecdsa(#[from] k256::ecdsa::Error),

    /// Ed25519 library errors.
    // NOTE: must be boxed otherwise thiserror will compile two
    // NOTE: From implementations when the full feature is enabled
    #[cfg(any(feature = "eddsa", feature = "schnorr"))]
    #[error(transparent)]
    Ed25519(#[from] Box<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)
    }
}