mpc_driver/
recoverable_signature.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
//! Recoverable signature for ECDSA.
use k256::ecdsa::{RecoveryId, Signature};
use serde::{Deserialize, Serialize};

/// Recoverable signature.
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RecoverableSignature {
    /// Signature bytes.
    pub bytes: Vec<u8>,
    /// Recovery identifier.
    pub recovery_id: u8,
}

impl From<(Signature, RecoveryId)> for RecoverableSignature {
    fn from(value: (Signature, RecoveryId)) -> Self {
        Self {
            bytes: value.0.to_vec(),
            recovery_id: value.1.into(),
        }
    }
}

impl TryFrom<&RecoverableSignature> for (Signature, RecoveryId) {
    type Error = crate::Error;

    fn try_from(
        value: &RecoverableSignature,
    ) -> Result<Self, Self::Error> {
        Ok((
            Signature::from_slice(&value.bytes)?,
            value.recovery_id.try_into()?,
        ))
    }
}

impl TryFrom<RecoverableSignature> for (Signature, RecoveryId) {
    type Error = crate::Error;

    fn try_from(
        value: RecoverableSignature,
    ) -> Result<Self, Self::Error> {
        (&value).try_into()
    }
}

#[cfg(feature = "cggmp")]
impl From<synedrion::RecoverableSignature> for RecoverableSignature {
    fn from(value: synedrion::RecoverableSignature) -> Self {
        value.to_backend().into()
    }
}