@@ -147,16 +147,16 @@ pub fn export_secret_package<R: RngCore + CryptoRng>(
147
147
pkg : & SecretPackage ,
148
148
identity : & Identity ,
149
149
csrng : R ,
150
- ) -> io :: Result < Vec < u8 > > {
150
+ ) -> Result < Vec < u8 > , IronfishFrostError > {
151
151
let serializable = SerializableSecretPackage :: from ( pkg. clone ( ) ) ;
152
152
if serializable. identifier != identity. to_frost_identifier ( ) {
153
- return Err ( io:: Error :: other ( "identity mismatch" ) ) ;
153
+ return Err ( IronfishFrostError :: InvalidInput (
154
+ "identity mismatch" . to_string ( ) ,
155
+ ) ) ;
154
156
}
155
157
156
158
let mut serialized = Vec :: new ( ) ;
157
- serializable
158
- . serialize_into ( & mut serialized)
159
- . expect ( "serialization failed" ) ;
159
+ serializable. serialize_into ( & mut serialized) ?;
160
160
Ok ( multienc:: encrypt ( & serialized, [ identity] , csrng) )
161
161
}
162
162
@@ -441,30 +441,38 @@ where
441
441
}
442
442
443
443
// Sanity check
444
- assert_eq ! ( round1_public_packages. len( ) , identities. len( ) ) ;
445
- assert_eq ! ( round1_public_packages. len( ) , round1_frost_packages. len( ) ) ;
444
+ if round1_public_packages. len ( ) != identities. len ( )
445
+ || round1_public_packages. len ( ) != round1_frost_packages. len ( )
446
+ {
447
+ return Err ( IronfishFrostError :: InvalidInput (
448
+ "incorrect number of packages or identities provided" . to_string ( ) ,
449
+ ) ) ;
450
+ }
446
451
447
452
// The public package for `self_identity` must be excluded from `frost::keys::dkg::part2`
448
453
// inputs
449
454
round1_frost_packages
450
455
. remove ( & self_identity. to_frost_identifier ( ) )
451
- . expect ( "missing public package for self_identity" ) ;
456
+ . ok_or ( IronfishFrostError :: InvalidInput (
457
+ "missing public package for self_identity" . to_string ( ) ,
458
+ ) ) ?;
452
459
453
460
// Run the FROST DKG round 2
454
461
let ( round2_secret_package, round2_packages) =
455
462
frost:: keys:: dkg:: part2 ( round1_secret_package. clone ( ) , & round1_frost_packages) ?;
456
463
457
464
// Encrypt the secret package
458
465
let encrypted_secret_package =
459
- export_secret_package ( & round2_secret_package, & self_identity, & mut csrng)
460
- . map_err ( IronfishFrostError :: EncryptionError ) ?;
466
+ export_secret_package ( & round2_secret_package, & self_identity, & mut csrng) ?;
461
467
462
468
// Convert the Identifier->Package map to an Identity->PublicPackage map
463
469
let mut round2_public_packages = Vec :: new ( ) ;
464
470
for ( identifier, package) in round2_packages {
465
471
let identity = * identities
466
472
. get ( & identifier)
467
- . expect ( "round2 generated package for unknown identifier" ) ;
473
+ . ok_or ( IronfishFrostError :: InvalidInput (
474
+ "round2 generated package for unknown identifier" . to_string ( ) ,
475
+ ) ) ?;
468
476
469
477
let public_package = PublicPackage :: new (
470
478
self_identity. clone ( ) ,
@@ -520,7 +528,9 @@ where
520
528
let identity = Identity :: deserialize_from ( participant) ?;
521
529
let round2_public_package = round2_packages
522
530
. remove ( & identity. to_frost_identifier ( ) )
523
- . expect ( "missing round 2 public package for participant" ) ;
531
+ . ok_or ( IronfishFrostError :: InvalidInput (
532
+ "missing round 2 public package for particiant" . to_string ( ) ,
533
+ ) ) ?;
524
534
round2_public_packages. push ( round2_public_package) ;
525
535
}
526
536
0 commit comments