/// Create the receiver data which contains the encrypted threshold secret keys
/// for all eligible receivers.
///
/// # Arguments
/// * `dkg_id` is the identifier of the DKG instance.
/// * `dealer_secret_key_bytes` is the dealer's ephemeral secret key, used to
///   encrypt shares.
/// * `receiver_keys` is the ephemeral public keys of the receivers, used to
///   encrypt their shares.  Given that some receivers may be ineligible this
///   takes the standard form `<Vec<Option<EphemeralPublicKey>>`, where:
///     * the index in the vector corresponds to the receiver index
///     * the `Option` is set to `None` for ineligible, discredited or otherwise
///       non-participating receivers.
/// * `threshold_secret_keys` is the threshold secret keys of the receivers to
///   be encrypted.
/// # Panics
/// * Threshold keys should be generated for every participating receiver.  This
///   method panics if there is a mismatch, i.e.:
///   * there is a receiver with an ephemeral key for which no threshold key is
///     generated, OR
///   * there is a a receiver with no ephemeral key for which a threshold key is
///     generated.
/// # Errors
/// * The public keys must be well formed, otherwise this MUST return an error.
/// # Returns
/// The encrypted threshold secret keys of eligible receivers.  
/// Each encrypted secret key can be decrypted by the corresponding receiver.
Create the receiver data which contains the encrypted threshold secret keys
for all eligible receivers.
Create the receiver data which contains the encrypted threshold secret keys for all eligible receivers .
fn create_receiver_data(
    dkg_id: IDkgId,
    dealer_ephemeral_secret_key_bytes: EphemeralSecretKeyBytes,
    receiver_keys: &[Option<(EphemeralPublicKeyBytes, EphemeralPopBytes)>],
    threshold_secret_keys: &[Option<ThresholdSecretKey>],
) -> Result<Vec<Option<EncryptedShareBytes>>, DkgCreateDealingError> {
    let dealer_secret_key = EphemeralSecretKey::try_from(dealer_ephemeral_secret_key_bytes)
        .map_err(DkgCreateDealingError::MalformedSecretKeyError)?;
    let dealer_public_key = EphemeralPublicKey::from(&dealer_secret_key); // TODO(DFN-845): Store the public key with the secret key to avoid recomputing
                                                                          // it.
    receiver_keys
        .iter()
        .zip(threshold_secret_keys)
        .map(|(receiver_key_maybe, bls_secret_key_maybe)| {
            match (receiver_key_maybe, bls_secret_key_maybe) {
                (None, None) => Ok(None),
                (None, Some(_)) => panic!("No receiver for threshold key"),
                (Some(_), None) => panic!("No threshold key for receiver"),
                (Some((receiver_key_bytes, _pop)), Some(bls_secret_key)) => {
                    EphemeralPublicKey::try_from(receiver_key_bytes)
                        .map_err(DkgCreateDealingError::MalformedPublicKeyError)
                        .map(|receiver_public_key: EphemeralPublicKey| {
                            let dh_secret = receiver_public_key.clone() * &dealer_secret_key;
                            let encrypted_share = EncryptedShareBytes::from(&dh::encrypt_share(
                                dkg_id,
                                &dealer_public_key,
                                &receiver_public_key,
                                &dh_secret,
                                *bls_secret_key,
                            ));
                            Some(encrypted_share)
                        })
                }
            }
        })
        .collect()
}
fn create_receiver_data ( dkg_id : IDkgId , dealer_ephemeral_secret_key_bytes : EphemeralSecretKeyBytes , receiver_keys : & [ Option < ( EphemeralPublicKeyBytes , EphemeralPopBytes ) > ] , threshold_secret_keys : & [ Option < ThresholdSecretKey > ] , ) -> Result < Vec < Option < EncryptedShareBytes > > , DkgCreateDealingError > { let dealer_secret_key = EphemeralSecretKey :: try_from ( dealer_ephemeral_secret_key_bytes ) . map_err ( DkgCreateDealingError :: MalformedSecretKeyError ) ? ; let dealer_public_key = EphemeralPublicKey :: from ( & dealer_secret_key ) ; // TODO(DFN-845): Store the public key with the secret key to avoid recomputing // it. receiver_keys . iter ( ) . zip ( threshold_secret_keys ) . map ( | ( receiver_key_maybe , bls_secret_key_maybe ) | { match ( receiver_key_maybe , bls_secret_key_maybe ) { ( None , None ) => Ok ( None ) , ( None , Some ( _ ) ) => panic ! ( " " ) , ( Some ( _ ) , None ) => panic ! ( " " ) , ( Some ( ( receiver_key_bytes , _pop ) ) , Some ( bls_secret_key ) ) => { EphemeralPublicKey :: try_from ( receiver_key_bytes ) . map_err ( DkgCreateDealingError :: MalformedPublicKeyError ) . map ( | receiver_public_key : EphemeralPublicKey | { let dh_secret = receiver_public_key . clone ( ) * & dealer_secret_key ; let encrypted_share = EncryptedShareBytes :: from ( & dh :: encrypt_share ( dkg_id , & dealer_public_key , & receiver_public_key , & dh_secret , * bls_secret_key , ) ) ; Some ( encrypted_share ) } ) } } } ) . collect ( ) }
Create the receiver data which contains the encrypted threshold secret keys
for all eligible receivers.
Create the receiver data which contains the encrypted threshold secret keys for all eligible receivers .
The encrypted threshold secret keys of eligible receivers.
Each encrypted secret key can be decrypted by the corresponding receiver.
The encrypted threshold secret keys of eligible receivers . Each encrypted secret key can be decrypted by the corresponding receiver .
dkg_id
IDkgId
dealer_ephemeral_secret_key_bytes
EphemeralSecretKeyBytes
receiver_keys
&[Option<(EphemeralPublicKeyBytes, EphemeralPopBytes)>]
threshold_secret_keys
&[Option<ThresholdSecretKey>]
panics
Threshold keys should be generated for every participating receiver.  This
method panics if there is a mismatch, i.e.:
there is a receiver with an ephemeral key for which no threshold key is
generated, OR
there is a a receiver with no ephemeral key for which a threshold key is
generated.
Threshold keys should be generated for every participating receiver . This method panics if there is a mismatch i . e . : there is a receiver with an ephemeral key for which no threshold key is generated OR there is a a receiver with no ephemeral key for which a threshold key is generated .
errors
The public keys must be well formed, otherwise this MUST return an error.
The public keys must be well formed otherwise this MUST return an error .