16
16
#![ forbid( unused_crate_dependencies) ]
17
17
#![ cfg_attr( docsrs, feature( doc_auto_cfg) ) ]
18
18
19
+ use core:: ops;
20
+
19
21
use generic_ec:: { serde:: CurveName , Curve , NonZero , Point , Scalar , SecretScalar } ;
20
22
use generic_ec_zkp:: polynomial:: lagrange_coefficient;
21
23
22
24
mod utils;
23
25
mod valid;
24
26
25
- pub use self :: valid:: { Valid , ValidProjection , Validate , ValidateError , ValidateFromParts } ;
27
+ pub use self :: valid:: { Valid , Validate , ValidateError , ValidateFromParts } ;
26
28
27
29
/// Core key share
28
30
///
@@ -92,6 +94,23 @@ pub struct DirtyCoreKeyShare<E: Curve> {
92
94
pub curve : CurveName < E > ,
93
95
/// Index of local party in key generation protocol
94
96
pub i : u16 ,
97
+ /// Public key info
98
+ #[ cfg_attr( feature = "serde" , serde( flatten) ) ]
99
+ pub key_info : DirtyKeyInfo < E > ,
100
+ /// Secret share $x_i$
101
+ #[ cfg_attr( feature = "serde" , serde( with = "As::<generic_ec::serde::Compact>" ) ) ]
102
+ pub x : SecretScalar < E > ,
103
+ }
104
+
105
+ /// Public Key Info
106
+ ///
107
+ /// Contains public information about the TSS key, including shared public key, commitments to
108
+ /// secret shares and etc.
109
+ #[ derive( Clone , Debug ) ]
110
+ #[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
111
+ #[ cfg_attr( feature = "serde" , serde( bound = "" ) ) ]
112
+ #[ cfg_attr( feature = "udigest" , derive( udigest:: Digestable ) ) ]
113
+ pub struct DirtyKeyInfo < E : Curve > {
95
114
/// Public key corresponding to shared secret key. Corresponds to _X_ in paper.
96
115
#[ cfg_attr( feature = "serde" , serde( with = "As::<generic_ec::serde::Compact>" ) ) ]
97
116
pub shared_public_key : Point < E > ,
@@ -112,10 +131,8 @@ pub struct DirtyCoreKeyShare<E: Curve> {
112
131
serde( default ) ,
113
132
serde( with = "As::<Option<utils::HexOrBin>>" )
114
133
) ]
134
+ #[ cfg_attr( feature = "udigest" , udigest( with = utils:: encoding:: maybe_bytes) ) ]
115
135
pub chain_code : Option < slip_10:: ChainCode > ,
116
- /// Secret share $x_i$
117
- #[ cfg_attr( feature = "serde" , serde( with = "As::<generic_ec::serde::Compact>" ) ) ]
118
- pub x : SecretScalar < E > ,
119
136
}
120
137
121
138
#[ derive( Debug , Clone , PartialEq , Eq ) ]
@@ -134,42 +151,6 @@ pub struct VssSetup<E: Curve> {
134
151
pub I : Vec < NonZero < Scalar < E > > > ,
135
152
}
136
153
137
- /// Public Key Info
138
- ///
139
- /// Contains public information about the TSS key, including shared public key, commitments to
140
- /// secret shares and etc.
141
- #[ derive( Clone , Debug ) ]
142
- #[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
143
- #[ cfg_attr( feature = "serde" , serde( bound = "" ) ) ]
144
- #[ cfg_attr( feature = "udigest" , derive( udigest:: Digestable ) ) ]
145
- pub struct DirtyKeyInfo < E : Curve > {
146
- /// Guard that ensures curve consistency for deseraization
147
- #[ cfg_attr( feature = "udigest" , udigest( with = utils:: encoding:: curve_name) ) ]
148
- pub curve : CurveName < E > ,
149
- /// Public key corresponding to shared secret key. Corresponds to _X_ in paper.
150
- #[ cfg_attr( feature = "serde" , serde( with = "As::<generic_ec::serde::Compact>" ) ) ]
151
- pub shared_public_key : Point < E > ,
152
- /// Public shares of all signers sharing the key
153
- ///
154
- /// `public_shares[i]` corresponds to public share (or public commitment) of $\ith$ party.
155
- #[ cfg_attr(
156
- feature = "serde" ,
157
- serde( with = "As::<Vec<generic_ec::serde::Compact>>" )
158
- ) ]
159
- pub public_shares : Vec < Point < E > > ,
160
- /// Verifiable secret sharing setup, present if key was generated using VSS scheme
161
- pub vss_setup : Option < VssSetup < E > > ,
162
- /// Chain code associated with the key, if HD wallets support was enabled
163
- #[ cfg( feature = "hd-wallets" ) ]
164
- #[ cfg_attr(
165
- feature = "serde" ,
166
- serde( default ) ,
167
- serde( with = "As::<Option<utils::HexOrBin>>" )
168
- ) ]
169
- #[ cfg_attr( feature = "udigest" , udigest( with = utils:: encoding:: maybe_bytes) ) ]
170
- pub chain_code : Option < slip_10:: ChainCode > ,
171
- }
172
-
173
154
impl < E : Curve > Validate for DirtyCoreKeyShare < E > {
174
155
type Error = InvalidCoreShare ;
175
156
@@ -182,12 +163,7 @@ impl<E: Curve> Validate for DirtyCoreKeyShare<E> {
182
163
return Err ( InvalidShareReason :: PartySecretShareDoesntMatchPublicShare . into ( ) ) ;
183
164
}
184
165
185
- match & self . vss_setup {
186
- Some ( vss_setup) => {
187
- validate_vss_key_info ( self . shared_public_key , & self . public_shares , vss_setup) ?
188
- }
189
- None => validate_non_vss_key_info ( self . shared_public_key , & self . public_shares ) ?,
190
- }
166
+ self . key_info . is_valid ( ) ?;
191
167
192
168
Ok ( ( ) )
193
169
}
@@ -391,34 +367,18 @@ impl<E: Curve> CoreKeyShare<E> {
391
367
}
392
368
}
393
369
394
- impl < E : Curve > From < & DirtyCoreKeyShare < E > > for DirtyKeyInfo < E > {
395
- fn from ( key_share : & DirtyCoreKeyShare < E > ) -> Self {
396
- DirtyKeyInfo {
397
- curve : key_share. curve ,
398
- shared_public_key : key_share. shared_public_key ,
399
- public_shares : key_share. public_shares . clone ( ) ,
400
- vss_setup : key_share. vss_setup . clone ( ) ,
401
- #[ cfg( feature = "hd-wallets" ) ]
402
- chain_code : key_share. chain_code ,
403
- }
370
+ impl < E : Curve > ops:: Deref for DirtyCoreKeyShare < E > {
371
+ type Target = DirtyKeyInfo < E > ;
372
+ fn deref ( & self ) -> & Self :: Target {
373
+ & self . key_info
404
374
}
405
375
}
406
- impl < E : Curve > From < DirtyCoreKeyShare < E > > for DirtyKeyInfo < E > {
407
- fn from ( key_share : DirtyCoreKeyShare < E > ) -> Self {
408
- DirtyKeyInfo {
409
- curve : key_share. curve ,
410
- shared_public_key : key_share. shared_public_key ,
411
- public_shares : key_share. public_shares ,
412
- vss_setup : key_share. vss_setup ,
413
- #[ cfg( feature = "hd-wallets" ) ]
414
- chain_code : key_share. chain_code ,
415
- }
376
+ impl < E : Curve > AsRef < DirtyKeyInfo < E > > for DirtyCoreKeyShare < E > {
377
+ fn as_ref ( & self ) -> & DirtyKeyInfo < E > {
378
+ & self . key_info
416
379
}
417
380
}
418
381
419
- impl < E : Curve > ValidProjection < DirtyCoreKeyShare < E > > for DirtyKeyInfo < E > { }
420
- impl < E : Curve > ValidProjection < & DirtyCoreKeyShare < E > > for DirtyKeyInfo < E > { }
421
-
422
382
/// Error indicating that key share is not valid
423
383
#[ derive( Debug , thiserror:: Error ) ]
424
384
#[ error( transparent) ]
0 commit comments