pub fn verify_dealing(
    threshold: NumberOfNodes,
    receiver_keys: &[Option<(EphemeralPublicKeyBytes, EphemeralPopBytes)>],
    dealing: CLibDealingBytes,
) -> Result<(), DkgVerifyDealingError> {
    // Parse inputs:
    let CLibDealingBytes {
        public_coefficients,
        receiver_data,
    } = dealing;
    let public_coefficients: PublicCoefficients =
        (&public_coefficients).try_into().map_err(|_| {
            DkgVerifyDealingError::MalformedDealingError(MalformedDataError {
                algorithm: AlgorithmId::Secp256k1,
                internal_error: "public coefficients could not be parsed".to_string(),
                data: None,
            })
        })?;
    let receiver_data: Result<Vec<Option<ThresholdSecretKey>>, _> = receiver_data
        .iter()
        .map(|share_maybe| share_maybe.map(ThresholdSecretKey::try_from).transpose())
        .collect();
    let receiver_data = receiver_data.map_err(DkgVerifyDealingError::MalformedDealingError)?;

    // The public coefficients should match the threshold.
    let public_coefficients_threshold =
        NumberOfNodes::try_from(&public_coefficients).map_err(|_| {
            DkgVerifyDealingError::SizeError(SizeError {
                message: format!(
                    "More receivers than this machine can handle: {}",
                    public_coefficients.coefficients.len()
                ),
            })
        })?;
    if public_coefficients_threshold != threshold {
        return Err(DkgVerifyDealingError::InvalidDealingError(
            InvalidArgumentError {
                message: format!(
                    "Incorrect threshold: dealing threshold={} != {}=expected threshold",
                    public_coefficients_threshold, threshold
                ),
            },
        ));
    }

    // The number of receiver slots should match.
    if receiver_data.len() != receiver_keys.len() {
        return Err(DkgVerifyDealingError::InvalidDealingError(
            InvalidArgumentError {
                message: format!(
                    "Incorrect share vector length: share slots={} != {}=receiver slots",
                    receiver_data.len(),
                    receiver_keys.len()
                ),
            },
        ));
    }

    // Every receiver that has keys should have a share:
    if let Some((index, (data, key))) = receiver_data
        .iter()
        .zip(receiver_keys)
        .enumerate()
        .find(|(_index, (data, key))| data.is_some() != key.is_some())
    {
        return Err(DkgVerifyDealingError::InvalidDealingError(
            InvalidArgumentError {
                message: format!(
                    "Receiver {} has key={} != {}=has share",
                    index,
                    data.is_some(),
                    key.is_some()
                ),
            },
        ));
    }
    Ok(())
}
/// Verifies the public parameters of the dealing (degree and group size)
///
/// # Arguments
/// * `threshold` - the minimum number of receivers needed to sign a valid
///   threshold signature.
/// * `receiver_keys` - 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.
/// * `dealing` - the dealing being verified.
/// # Panics
/// This method is not expected to panic
/// # Errors
/// This method returns an error if:
/// * the public coefficients or receiver data are malformed;
/// * the number of public coefficients does not match the threshold;
/// * the length of `dealing.receiver_data` is not the same as the length of
///   `receiver_keys`;
/// * the set of receivers with a share does not match the set with public keys,
///   i.e. `dealing.receiver_data[i]` is `Some` where `receiver_keys[i]` is None
///   or vice versa.
Verifies the public parameters of the dealing (degree and group size)
Verifies the public parameters of the dealing ( degree and group size )
pub fn verify_dealing(
    threshold: NumberOfNodes,
    receiver_keys: &[Option<(EphemeralPublicKeyBytes, EphemeralPopBytes)>],
    dealing: CLibDealingBytes,
) -> Result<(), DkgVerifyDealingError> {
    // Parse inputs:
    let CLibDealingBytes {
        public_coefficients,
        receiver_data,
    } = dealing;
    let public_coefficients: PublicCoefficients =
        (&public_coefficients).try_into().map_err(|_| {
            DkgVerifyDealingError::MalformedDealingError(MalformedDataError {
                algorithm: AlgorithmId::Secp256k1,
                internal_error: "public coefficients could not be parsed".to_string(),
                data: None,
            })
        })?;
    let receiver_data: Result<Vec<Option<ThresholdSecretKey>>, _> = receiver_data
        .iter()
        .map(|share_maybe| share_maybe.map(ThresholdSecretKey::try_from).transpose())
        .collect();
    let receiver_data = receiver_data.map_err(DkgVerifyDealingError::MalformedDealingError)?;
    // The public coefficients should match the threshold.
    let public_coefficients_threshold =
        NumberOfNodes::try_from(&public_coefficients).map_err(|_| {
            DkgVerifyDealingError::SizeError(SizeError {
                message: format!(
                    "More receivers than this machine can handle: {}",
                    public_coefficients.coefficients.len()
                ),
            })
        })?;
    if public_coefficients_threshold != threshold {
        return Err(DkgVerifyDealingError::InvalidDealingError(
            InvalidArgumentError {
                message: format!(
                    "Incorrect threshold: dealing threshold={} != {}=expected threshold",
                    public_coefficients_threshold, threshold
                ),
            },
        ));
    }
    // The number of receiver slots should match.
    if receiver_data.len() != receiver_keys.len() {
        return Err(DkgVerifyDealingError::InvalidDealingError(
            InvalidArgumentError {
                message: format!(
                    "Incorrect share vector length: share slots={} != {}=receiver slots",
                    receiver_data.len(),
                    receiver_keys.len()
                ),
            },
        ));
    }
    // Every receiver that has keys should have a share:
    if let Some((index, (data, key))) = receiver_data
        .iter()
        .zip(receiver_keys)
        .enumerate()
        .find(|(_index, (data, key))| data.is_some() != key.is_some())
    {
        return Err(DkgVerifyDealingError::InvalidDealingError(
            InvalidArgumentError {
                message: format!(
                    "Receiver {} has key={} != {}=has share",
                    index,
                    data.is_some(),
                    key.is_some()
                ),
            },
        ));
    }
    Ok(())
}
pub fn verify_dealing ( threshold : NumberOfNodes , receiver_keys : & [ Option < ( EphemeralPublicKeyBytes , EphemeralPopBytes ) > ] , dealing : CLibDealingBytes , ) -> Result < ( ) , DkgVerifyDealingError > { // Parse inputs: let CLibDealingBytes { public_coefficients , receiver_data , } = dealing ; let public_coefficients : PublicCoefficients = ( & public_coefficients ) . try_into ( ) . map_err ( | _ | { DkgVerifyDealingError :: MalformedDealingError ( MalformedDataError { algorithm : AlgorithmId :: Secp256k1 , internal_error : " " . to_string ( ) , data : None , } ) } ) ? ; let receiver_data : Result < Vec < Option < ThresholdSecretKey > > , _ > = receiver_data . iter ( ) . map ( | share_maybe | share_maybe . map ( ThresholdSecretKey :: try_from ) . transpose ( ) ) . collect ( ) ; let receiver_data = receiver_data . map_err ( DkgVerifyDealingError :: MalformedDealingError ) ? ; // The public coefficients should match the threshold. let public_coefficients_threshold = NumberOfNodes :: try_from ( & public_coefficients ) . map_err ( | _ | { DkgVerifyDealingError :: SizeError ( SizeError { message : format ! ( " " public_coefficients coefficients len ( ) ) , } ) } ) ? ; if public_coefficients_threshold != threshold { return Err ( DkgVerifyDealingError :: InvalidDealingError ( InvalidArgumentError { message : format ! ( " " public_coefficients_threshold threshold ) , } , ) ) ; } // The number of receiver slots should match. if receiver_data . len ( ) != receiver_keys . len ( ) { return Err ( DkgVerifyDealingError :: InvalidDealingError ( InvalidArgumentError { message : format ! ( " " receiver_data len ( ) receiver_keys len ( ) ) , } , ) ) ; } // Every receiver that has keys should have a share: if let Some ( ( index , ( data , key ) ) ) = receiver_data . iter ( ) . zip ( receiver_keys ) . enumerate ( ) . find ( | ( _index , ( data , key ) ) | data . is_some ( ) != key . is_some ( ) ) { return Err ( DkgVerifyDealingError :: InvalidDealingError ( InvalidArgumentError { message : format ! ( " " index data is_some ( ) key is_some ( ) ) , } , ) ) ; } Ok ( ( ) ) }
Verifies the public parameters of the dealing (degree and group size)
Verifies the public parameters of the dealing ( degree and group size )
threshold
NumberOfNodes
receiver_keys
&[Option<(EphemeralPublicKeyBytes, EphemeralPopBytes)>]
dealing
CLibDealingBytes
threshold
NumberOfNodes
receiver_keys
&[Option<(EphemeralPublicKeyBytes, EphemeralPopBytes)>]
dealing
CLibDealingBytes
panics
This method is not expected to panic
This method is not expected to panic
errors
This method returns an error if:
the public coefficients or receiver data are malformed;
the number of public coefficients does not match the threshold;
the length of `dealing.receiver_data` is not the same as the length of
`receiver_keys`;
the set of receivers with a share does not match the set with public keys,
i.e. `dealing.receiver_data[i]` is `Some` where `receiver_keys[i]` is None
or vice versa.
This method returns an error if : the public coefficients or receiver data are malformed ; the number of public coefficients does not match the threshold ; the length of ` dealing . receiver_data ` is not the same as the length of ` receiver_keys ` ; the set of receivers with a share does not match the set with public keys i . e . ` dealing . receiver_data [ i ] ` is ` Some ` where ` receiver_keys [ i ] ` is None or vice versa .