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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::{
cmp::Ordering,
fmt::{self, Debug, Formatter},
hash::{Hash, Hasher},
};
use threshold_crypto::{PublicKeySet, SecretKeyShare};
#[derive(Clone)]
pub struct DkgResult {
pub public_key_set: PublicKeySet,
pub secret_key_share: Option<SecretKeyShare>,
}
impl DkgResult {
pub fn new(public_key_set: PublicKeySet, secret_key_share: Option<SecretKeyShare>) -> Self {
Self {
public_key_set,
secret_key_share,
}
}
}
impl Debug for DkgResult {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
write!(
formatter,
"DkgResult({:?}, {})",
self.public_key_set,
self.secret_key_share.is_some()
)
}
}
#[derive(Clone)]
pub struct DkgResultWrapper(pub DkgResult);
impl Debug for DkgResultWrapper {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
self.0.fmt(formatter)
}
}
impl DkgResultWrapper {
fn comparison_value(&self) -> &PublicKeySet {
&self.0.public_key_set
}
}
impl PartialEq for DkgResultWrapper {
fn eq(&self, rhs: &Self) -> bool {
self.comparison_value().eq(&rhs.comparison_value())
}
}
impl Eq for DkgResultWrapper {}
impl Hash for DkgResultWrapper {
fn hash<H: Hasher>(&self, state: &mut H) {
self.comparison_value().hash(state)
}
}
impl PartialOrd for DkgResultWrapper {
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering> {
self.comparison_value().partial_cmp(&rhs.comparison_value())
}
}
impl Ord for DkgResultWrapper {
fn cmp(&self, rhs: &Self) -> Ordering {
self.comparison_value().cmp(&rhs.comparison_value())
}
}
impl Serialize for DkgResultWrapper {
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
self.0.public_key_set.serialize(s)
}
}
impl<'a> Deserialize<'a> for DkgResultWrapper {
fn deserialize<D: Deserializer<'a>>(deserializer: D) -> Result<Self, D::Error> {
PublicKeySet::deserialize(deserializer).map(|public_key_set| {
DkgResultWrapper(DkgResult {
public_key_set,
secret_key_share: None,
})
})
}
}