mina_p2p_messages/
keys.rs

1use ark_ff::fields::arithmetic::InvalidBigInt;
2
3impl TryFrom<crate::v2::NonZeroCurvePointUncompressedStableV1> for mina_signer::CompressedPubKey {
4    type Error = InvalidBigInt;
5
6    fn try_from(
7        val: crate::v2::NonZeroCurvePointUncompressedStableV1,
8    ) -> Result<Self, Self::Error> {
9        Ok(mina_signer::CompressedPubKey {
10            x: val.x.try_into()?,
11            is_odd: val.is_odd,
12        })
13    }
14}
15
16impl From<mina_signer::CompressedPubKey> for crate::v2::NonZeroCurvePointUncompressedStableV1 {
17    fn from(v: mina_signer::CompressedPubKey) -> crate::v2::NonZeroCurvePointUncompressedStableV1 {
18        Self {
19            x: v.x.into(),
20            is_odd: v.is_odd,
21        }
22    }
23}
24impl TryFrom<&crate::v2::NonZeroCurvePointUncompressedStableV1> for mina_signer::CompressedPubKey {
25    type Error = InvalidBigInt;
26
27    fn try_from(
28        val: &crate::v2::NonZeroCurvePointUncompressedStableV1,
29    ) -> Result<Self, Self::Error> {
30        Ok(mina_signer::CompressedPubKey {
31            x: (&val.x).try_into()?,
32            is_odd: val.is_odd,
33        })
34    }
35}
36
37impl From<&mina_signer::CompressedPubKey> for crate::v2::NonZeroCurvePointUncompressedStableV1 {
38    fn from(v: &mina_signer::CompressedPubKey) -> crate::v2::NonZeroCurvePointUncompressedStableV1 {
39        Self {
40            x: v.x.into(),
41            is_odd: v.is_odd,
42        }
43    }
44}
45
46impl TryFrom<&crate::v2::NonZeroCurvePoint> for mina_signer::CompressedPubKey {
47    type Error = InvalidBigInt;
48
49    fn try_from(val: &crate::v2::NonZeroCurvePoint) -> Result<Self, Self::Error> {
50        Ok(mina_signer::CompressedPubKey {
51            x: (&val.x).try_into()?,
52            is_odd: val.is_odd,
53        })
54    }
55}
56
57impl From<&mina_signer::CompressedPubKey> for crate::v2::NonZeroCurvePoint {
58    fn from(v: &mina_signer::CompressedPubKey) -> crate::v2::NonZeroCurvePoint {
59        let key = crate::v2::NonZeroCurvePointUncompressedStableV1 {
60            x: (&v.x).into(),
61            is_odd: v.is_odd,
62        };
63        key.into()
64    }
65}
66
67impl From<&mina_signer::Signature> for crate::v2::MinaBaseSignatureStableV1 {
68    fn from(value: &mina_signer::Signature) -> Self {
69        Self(value.rx.into(), value.s.into())
70    }
71}
72
73impl TryFrom<&crate::v2::MinaBaseSignatureStableV1> for mina_signer::Signature {
74    type Error = InvalidBigInt;
75
76    fn try_from(value: &crate::v2::MinaBaseSignatureStableV1) -> Result<Self, Self::Error> {
77        Ok(Self {
78            rx: value.0.to_field()?,
79            s: value.1.to_field()?,
80        })
81    }
82}