/// Computes the transcript using all provided dealings
///
/// Note: The caller can optimise by providing a minimal number of dealings.
///
/// # Panics
/// * If Langrange interpolation fails (because of duplicate x-coordinates).
Computes the transcript using all provided dealings
Note: The caller can optimise by providing a minimal number of dealings.
Computes the transcript using all provided dealings Note : The caller can optimise by providing a minimal number of dealings .
fn compute_transcript(
    threshold: NumberOfNodes,
    number_of_receivers: NumberOfNodes,
    csp_dealings: &BTreeMap<NodeIndex, &g20::Dealing>,
) -> Result<g20::Transcript, CspDkgCreateTranscriptError> {
    // Extract and verify the data we need from the arguments
    verify_threshold(threshold, number_of_receivers)
        .map_err(CspDkgCreateTranscriptError::InvalidThresholdError)?;
    let receiver_data: Result<BTreeMap<NodeIndex, g20::EncryptedShares>, _> = csp_dealings
        .iter()
        .map(|(dealer_index, dealing)| {
            verify_all_shares_are_present_and_well_formatted(dealing, number_of_receivers)
                .map_err(|error| CspDkgCreateTranscriptError::InvalidDealingError {
                    dealer_index: *dealer_index,
                    error,
                })?;
            verify_public_coefficients_match_threshold(dealing, threshold).map_err(|error| {
                CspDkgCreateTranscriptError::InvalidDealingError {
                    dealer_index: *dealer_index,
                    error,
                }
            })?;
            Ok((*dealer_index, dealing.ciphertexts.clone()))
        })
        .collect();
    let receiver_data = receiver_data?;
    let individual_public_coefficients: Result<
        BTreeMap<NodeIndex, threshold_types::PublicCoefficients>,
        _,
    > = csp_dealings
        .iter()
        .map(|(dealer_index, dealing)| {
            // Type conversion from crypto internal type.
            // The dealings have already been verified,
            // so we can trust the serialized coefficients.
            threshold_types::PublicCoefficients::from_trusted_bytes(&dealing.public_coefficients)
                .map(|public_coefficients| (*dealer_index, public_coefficients))
                .map_err(|crypto_error| {
                    let error = InvalidArgumentError {
                        message: format!("Invalid dealing: {:?}", crypto_error),
                    };
                    CspDkgCreateTranscriptError::InvalidDealingError {
                        dealer_index: *dealer_index,
                        error,
                    }
                })
        })
        .collect();
    let individual_public_coefficients = individual_public_coefficients?;
    // Combine the dealings
    let public_coefficients: g20::PublicCoefficientsBytes = {
        let lagrange_coefficients = {
            let reshare_x: Vec<threshold_types::SecretKey> =
                csp_dealings.keys().copied().map(x_for_index).collect();
            threshold_types::PublicCoefficients::lagrange_coefficients_at_zero(&reshare_x)
                .expect("Cannot fail because all x are distinct.")
        };
        let mut combined_public_coefficients = threshold_types::PublicCoefficients::zero();
        for ((_dealer_index, individual), factor) in individual_public_coefficients
            .into_iter()
            .zip(lagrange_coefficients)
        {
            // Aggregate the public coefficients:
            combined_public_coefficients += individual * factor;
        }
        // This type conversion is needed because of the internal/CSP type duplication.
        g20::PublicCoefficientsBytes::from(&combined_public_coefficients)
    };
    Ok(g20::Transcript {
        public_coefficients,
        receiver_data,
    })
}
fn compute_transcript ( threshold : NumberOfNodes , number_of_receivers : NumberOfNodes , csp_dealings : & BTreeMap < NodeIndex , & g20 :: Dealing > , ) -> Result < g20 :: Transcript , CspDkgCreateTranscriptError > { // Extract and verify the data we need from the arguments verify_threshold ( threshold , number_of_receivers ) . map_err ( CspDkgCreateTranscriptError :: InvalidThresholdError ) ? ; let receiver_data : Result < BTreeMap < NodeIndex , g20 :: EncryptedShares > , _ > = csp_dealings . iter ( ) . map ( | ( dealer_index , dealing ) | { verify_all_shares_are_present_and_well_formatted ( dealing , number_of_receivers ) . map_err ( | error | CspDkgCreateTranscriptError :: InvalidDealingError { dealer_index : * dealer_index , error , } ) ? ; verify_public_coefficients_match_threshold ( dealing , threshold ) . map_err ( | error | { CspDkgCreateTranscriptError :: InvalidDealingError { dealer_index : * dealer_index , error , } } ) ? ; Ok ( ( * dealer_index , dealing . ciphertexts . clone ( ) ) ) } ) . collect ( ) ; let receiver_data = receiver_data ? ; let individual_public_coefficients : Result < BTreeMap < NodeIndex , threshold_types :: PublicCoefficients > , _ , > = csp_dealings . iter ( ) . map ( | ( dealer_index , dealing ) | { // Type conversion from crypto internal type. // The dealings have already been verified, // so we can trust the serialized coefficients. threshold_types :: PublicCoefficients :: from_trusted_bytes ( & dealing . public_coefficients ) . map ( | public_coefficients | ( * dealer_index , public_coefficients ) ) . map_err ( | crypto_error | { let error = InvalidArgumentError { message : format ! ( " " crypto_error ) , } ; CspDkgCreateTranscriptError :: InvalidDealingError { dealer_index : * dealer_index , error , } } ) } ) . collect ( ) ; let individual_public_coefficients = individual_public_coefficients ? ; // Combine the dealings let public_coefficients : g20 :: PublicCoefficientsBytes = { let lagrange_coefficients = { let reshare_x : Vec < threshold_types :: SecretKey > = csp_dealings . keys ( ) . copied ( ) . map ( x_for_index ) . collect ( ) ; threshold_types :: PublicCoefficients :: lagrange_coefficients_at_zero ( & reshare_x ) . expect ( " " ) } ; let mut combined_public_coefficients = threshold_types :: PublicCoefficients :: zero ( ) ; for ( ( _dealer_index , individual ) , factor ) in individual_public_coefficients . into_iter ( ) . zip ( lagrange_coefficients ) { // Aggregate the public coefficients: combined_public_coefficients += individual * factor ; } // This type conversion is needed because of the internal/CSP type duplication. g20 :: PublicCoefficientsBytes :: from ( & combined_public_coefficients ) } ; Ok ( g20 :: Transcript { public_coefficients , receiver_data , } ) }
Computes the transcript using all provided dealings
Note: The caller can optimise by providing a minimal number of dealings.
Computes the transcript using all provided dealings Note : The caller can optimise by providing a minimal number of dealings .
threshold
NumberOfNodes
number_of_receivers
NumberOfNodes
csp_dealings
&BTreeMap<NodeIndex, &g20::Dealing>
panics
If Langrange interpolation fails (because of duplicate x-coordinates).
If Langrange interpolation fails ( because of duplicate x - coordinates ) .