polysig_driver/cggmp/
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
62
use k256::ecdsa::VerifyingKey;
use thiserror::Error;

/// Errors generated by the protocol.
#[derive(Debug, Error)]
pub enum Error {
    /// Error generated by the CGGMP protocol library
    /// on a local node.
    #[error("{0}")]
    LocalError(String),

    /// Error generated by the CGGMP protocol library
    /// on a remote node.
    #[error("{0}")]
    RemoteError(String),

    /// Signature verification failed.
    #[error("failed to verify generated signature")]
    VerifySignature,

    /// Could not locate ack for key init phase.
    #[error("could not find an ACK for key init phase")]
    NoKeyInitAck,

    /// Attempt to finish a protocol when another round is expected.
    #[error("protocol is not finished, another round is available")]
    NotFinished,

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

    /// Error generated converting integers.
    #[error(transparent)]
    FromInt(#[from] std::num::TryFromIntError),

    /// BIP32 library error.
    #[error(transparent)]
    Bip32(#[from] synedrion::bip32::Error),
}

impl From<synedrion::sessions::LocalError> for Error {
    fn from(value: synedrion::sessions::LocalError) -> Self {
        Error::LocalError(value.to_string())
    }
}

impl From<synedrion::sessions::RemoteError<VerifyingKey>> for Error {
    fn from(
        value: synedrion::sessions::RemoteError<VerifyingKey>,
    ) -> Self {
        Error::RemoteError(format!("{:#?}", value.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)
    }
}