pub fn create_dealing(
    keygen_seed: Randomness,
    encryption_seed: Randomness,
    threshold: NumberOfNodes,
    receiver_keys: &BTreeMap<NodeIndex, FsEncryptionPublicKey>,
    epoch: Epoch,
    dealer_index: NodeIndex,
    resharing_secret: Option<ThresholdSecretKeyBytes>,
) -> Result<Dealing, CspDkgCreateReshareDealingError> {
    // Check parameters
    {
        let number_of_receivers = number_of_receivers(receiver_keys)
            .map_err(CspDkgCreateReshareDealingError::SizeError)?;
        verify_threshold(threshold, number_of_receivers)
            .map_err(CspDkgCreateReshareDealingError::InvalidThresholdError)?;
        verify_receiver_indices(receiver_keys, number_of_receivers)?;
    }

    let (public_coefficients, threshold_secret_key_shares) = {
        let selected_nodes: Vec<bool> = {
            let max_node_index = receiver_keys.keys().max();
            let mut selected =
                vec![false; max_node_index.map(|index| *index as usize + 1).unwrap_or(0)];
            for index in receiver_keys.keys() {
                selected[*index as usize] = true;
            }
            selected
        };
        if let Some(resharing_secret) = resharing_secret {
            let resharing_secret: ThresholdSecretKey =
                ThresholdSecretKey::try_from(&resharing_secret).map_err(|_| {
                    CspDkgCreateReshareDealingError::MalformedReshareSecretKeyError(
                        MalformedSecretKeyError {
                            algorithm: ALGORITHM_ID,
                            internal_error: "Malformed reshared secret key".to_string(),
                        },
                    )
                })?;

            keygen_with_secret(
                keygen_seed,
                threshold,
                &selected_nodes[..],
                &resharing_secret,
            )
            .map_err(CspDkgCreateReshareDealingError::InvalidThresholdError)
        } else {
            keygen(keygen_seed, threshold, &selected_nodes[..])
                .map_err(CspDkgCreateReshareDealingError::InvalidThresholdError)
        }
    }?;

    let public_coefficients = PublicCoefficientsBytes::from(&public_coefficients); // Internal to CSP type conversion

    let (ciphertexts, zk_proof_decryptability, zk_proof_correct_sharing) = {
        let key_message_pairs: Vec<(FsEncryptionPublicKey, FsEncryptionPlaintext)> = (0..)
            .zip(&threshold_secret_key_shares)
            .map(|(index, share)| {
                let share =
                    (*share).expect("The keys should be contiguous but we have a missing entry.");
                let share = FrBytes(fr_to_bytes(&share));
                let share = FsEncryptionPlaintext::from(&share);
                (
                    *receiver_keys
                        .get(&index)
                        .expect("There should be a public key for each share"),
                    share,
                )
            })
            .collect();
        encrypt_and_prove(
            encryption_seed,
            &key_message_pairs,
            epoch,
            &public_coefficients,
            &dealer_index.to_be_bytes(),
        )
    }?;

    let dealing = Dealing {
        public_coefficients,
        ciphertexts,
        zk_proof_decryptability,
        zk_proof_correct_sharing,
    };
    Ok(dealing)
}
/// Creates a new dealing, i.e. generates threshold keys.
///
/// # Arguments
/// * `keygen_seed` - randomness used to seed the PRNG for generating the
///   keys/shares. It must be treated as a secret.
/// * `encryption_seed` - randomness used to seed the PRNG for encrypting the
///   shares and proving their correctness. It must be treated as a secret.
/// * `threshold` - the minimum number of individual signatures that can be
///   combined into a valid threshold signature.
/// * `receiver_keys` - forward-secure encryption public keys of the receivers.
/// * `epoch` - forward-secure epoch under which the shares are encrypted.
/// * `dealer_index` - index of the dealer.
/// * `resharing_secret` - existing secret key if resharing, or `None` if not.
///
/// # Errors
/// * `CspDkgCreateReshareDealingError::SizeError` if the length of
///   `receiver_keys` isn't supported.
/// * `CspDkgCreateReshareDealingError::InvalidThresholdError` if the threshold
///   is either zero or greater than the number of receivers.
/// * `CspDkgCreateReshareDealingError::MalformedReshareSecretKeyError` if
///   `resharing_key` is malformed.
/// * `CspDkgCreateReshareDealingError::InvalidThresholdError` if key generation
///   fails.
/// * `CspDkgCreateDealingError::MalformedFsPublicKeyError` if one of the
///   `receiver_keys` is malformed.
/// * `CspDkgCreateReshareDealingError::MisnumberedReceiverError` if the
///   receiver indices are not `0..num_receivers-1 inclusive`.
///
/// # Panics:
/// * If key generation produces key shares with non-contiguous indices.
/// * If key generation produces key shares that don't match the given
///   `receiver_keys`.
/// * If the key generation produces public coefficients that are malformed.
Creates a new dealing, i.e. generates threshold keys.
Creates a new dealing i . e . generates threshold keys .
pub fn create_dealing(
    keygen_seed: Randomness,
    encryption_seed: Randomness,
    threshold: NumberOfNodes,
    receiver_keys: &BTreeMap<NodeIndex, FsEncryptionPublicKey>,
    epoch: Epoch,
    dealer_index: NodeIndex,
    resharing_secret: Option<ThresholdSecretKeyBytes>,
) -> Result<Dealing, CspDkgCreateReshareDealingError> {
    // Check parameters
    {
        let number_of_receivers = number_of_receivers(receiver_keys)
            .map_err(CspDkgCreateReshareDealingError::SizeError)?;
        verify_threshold(threshold, number_of_receivers)
            .map_err(CspDkgCreateReshareDealingError::InvalidThresholdError)?;
        verify_receiver_indices(receiver_keys, number_of_receivers)?;
    }
    let (public_coefficients, threshold_secret_key_shares) = {
        let selected_nodes: Vec<bool> = {
            let max_node_index = receiver_keys.keys().max();
            let mut selected =
                vec![false; max_node_index.map(|index| *index as usize + 1).unwrap_or(0)];
            for index in receiver_keys.keys() {
                selected[*index as usize] = true;
            }
            selected
        };
        if let Some(resharing_secret) = resharing_secret {
            let resharing_secret: ThresholdSecretKey =
                ThresholdSecretKey::try_from(&resharing_secret).map_err(|_| {
                    CspDkgCreateReshareDealingError::MalformedReshareSecretKeyError(
                        MalformedSecretKeyError {
                            algorithm: ALGORITHM_ID,
                            internal_error: "Malformed reshared secret key".to_string(),
                        },
                    )
                })?;
            keygen_with_secret(
                keygen_seed,
                threshold,
                &selected_nodes[..],
                &resharing_secret,
            )
            .map_err(CspDkgCreateReshareDealingError::InvalidThresholdError)
        } else {
            keygen(keygen_seed, threshold, &selected_nodes[..])
                .map_err(CspDkgCreateReshareDealingError::InvalidThresholdError)
        }
    }?;
    let public_coefficients = PublicCoefficientsBytes::from(&public_coefficients); // Internal to CSP type conversion
    let (ciphertexts, zk_proof_decryptability, zk_proof_correct_sharing) = {
        let key_message_pairs: Vec<(FsEncryptionPublicKey, FsEncryptionPlaintext)> = (0..)
            .zip(&threshold_secret_key_shares)
            .map(|(index, share)| {
                let share =
                    (*share).expect("The keys should be contiguous but we have a missing entry.");
                let share = FrBytes(fr_to_bytes(&share));
                let share = FsEncryptionPlaintext::from(&share);
                (
                    *receiver_keys
                        .get(&index)
                        .expect("There should be a public key for each share"),
                    share,
                )
            })
            .collect();
        encrypt_and_prove(
            encryption_seed,
            &key_message_pairs,
            epoch,
            &public_coefficients,
            &dealer_index.to_be_bytes(),
        )
    }?;
    let dealing = Dealing {
        public_coefficients,
        ciphertexts,
        zk_proof_decryptability,
        zk_proof_correct_sharing,
    };
    Ok(dealing)
}
pub fn create_dealing ( keygen_seed : Randomness , encryption_seed : Randomness , threshold : NumberOfNodes , receiver_keys : & BTreeMap < NodeIndex , FsEncryptionPublicKey > , epoch : Epoch , dealer_index : NodeIndex , resharing_secret : Option < ThresholdSecretKeyBytes > , ) -> Result < Dealing , CspDkgCreateReshareDealingError > { // Check parameters { let number_of_receivers = number_of_receivers ( receiver_keys ) . map_err ( CspDkgCreateReshareDealingError :: SizeError ) ? ; verify_threshold ( threshold , number_of_receivers ) . map_err ( CspDkgCreateReshareDealingError :: InvalidThresholdError ) ? ; verify_receiver_indices ( receiver_keys , number_of_receivers ) ? ; } let ( public_coefficients , threshold_secret_key_shares ) = { let selected_nodes : Vec < bool > = { let max_node_index = receiver_keys . keys ( ) . max ( ) ; let mut selected = vec ! [ false max_node_index map ( index index as usize 1 ) unwrap_or ( 0 ) ] ; for index in receiver_keys . keys ( ) { selected [ * index as usize ] = true ; } selected } ; if let Some ( resharing_secret ) = resharing_secret { let resharing_secret : ThresholdSecretKey = ThresholdSecretKey :: try_from ( & resharing_secret ) . map_err ( | _ | { CspDkgCreateReshareDealingError :: MalformedReshareSecretKeyError ( MalformedSecretKeyError { algorithm : ALGORITHM_ID , internal_error : " " . to_string ( ) , } , ) } ) ? ; keygen_with_secret ( keygen_seed , threshold , & selected_nodes [ .. ] , & resharing_secret , ) . map_err ( CspDkgCreateReshareDealingError :: InvalidThresholdError ) } else { keygen ( keygen_seed , threshold , & selected_nodes [ .. ] ) . map_err ( CspDkgCreateReshareDealingError :: InvalidThresholdError ) } } ? ; let public_coefficients = PublicCoefficientsBytes :: from ( & public_coefficients ) ; // Internal to CSP type conversion let ( ciphertexts , zk_proof_decryptability , zk_proof_correct_sharing ) = { let key_message_pairs : Vec < ( FsEncryptionPublicKey , FsEncryptionPlaintext ) > = ( 0 .. ) . zip ( & threshold_secret_key_shares ) . map ( | ( index , share ) | { let share = ( * share ) . expect ( " " ) ; let share = FrBytes ( fr_to_bytes ( & share ) ) ; let share = FsEncryptionPlaintext :: from ( & share ) ; ( * receiver_keys . get ( & index ) . expect ( " " ) , share , ) } ) . collect ( ) ; encrypt_and_prove ( encryption_seed , & key_message_pairs , epoch , & public_coefficients , & dealer_index . to_be_bytes ( ) , ) } ? ; let dealing = Dealing { public_coefficients , ciphertexts , zk_proof_decryptability , zk_proof_correct_sharing , } ; Ok ( dealing ) }
Creates a new dealing, i.e.
Creates a new dealing i . e .
keygen_seed
Randomness
encryption_seed
Randomness
threshold
NumberOfNodes
receiver_keys
&BTreeMap<NodeIndex, FsEncryptionPublicKey>
epoch
Epoch
dealer_index
NodeIndex
resharing_secret
Option<ThresholdSecretKeyBytes>
keygen_seed
Randomness
encryption_seed
Randomness
threshold
NumberOfNodes
receiver_keys
&BTreeMap<NodeIndex, FsEncryptionPublicKey>
epoch
Epoch
dealer_index
NodeIndex
resharing_secret
Option<ThresholdSecretKeyBytes>
errors
`CspDkgCreateReshareDealingError::SizeError` if the length of
`receiver_keys` isn't supported.
`CspDkgCreateReshareDealingError::InvalidThresholdError` if the threshold
is either zero or greater than the number of receivers.
`CspDkgCreateReshareDealingError::MalformedReshareSecretKeyError` if
`resharing_key` is malformed.
`CspDkgCreateReshareDealingError::InvalidThresholdError` if key generation
fails.
`CspDkgCreateDealingError::MalformedFsPublicKeyError` if one of the
`receiver_keys` is malformed.
`CspDkgCreateReshareDealingError::MisnumberedReceiverError` if the
receiver indices are not `0..num_receivers-1 inclusive`.
` CspDkgCreateReshareDealingError :: SizeError ` if the length of ` receiver_keys ` isn ' t supported . ` CspDkgCreateReshareDealingError :: InvalidThresholdError ` if the threshold is either zero or greater than the number of receivers . ` CspDkgCreateReshareDealingError :: MalformedReshareSecretKeyError ` if ` resharing_key ` is malformed . ` CspDkgCreateReshareDealingError :: InvalidThresholdError ` if key generation fails . ` CspDkgCreateDealingError :: MalformedFsPublicKeyError ` if one of the ` receiver_keys ` is malformed . ` CspDkgCreateReshareDealingError :: MisnumberedReceiverError ` if the receiver indices are not ` 0 .. num_receivers - 1 inclusive ` .
panics:
If key generation produces key shares with non-contiguous indices.
If key generation produces key shares that don't match the given
`receiver_keys`.
If the key generation produces public coefficients that are malformed.
If key generation produces key shares with non - contiguous indices . If key generation produces key shares that don ' t match the given ` receiver_keys ` . If the key generation produces public coefficients that are malformed .