/// Creates an NiDKG transcript with the same public key as an existing
/// threshold key.
///
/// # Prerequisites
/// * The dealings MUST be verified before calling this method; otherwise
///   dealers may provide receivers with invalid shares or dealers may provide
///   keys that do not preserve the public key.
///
/// # Errors
/// * `CspDkgCreateReshareTranscriptError::InsufficientDealingsError` if the
///   length of `csp_dealings` is smaller than the new threshold (set by
///   `resharing_public_coefficients`).
/// * `CspDkgCreateReshareTranscriptError::ResharingFailed` if the public key
///   created by this resharing does not match the previous public key.
/// * `CspDkgCreateTranscriptError::InvalidThresholdError` if the threshold is
///   either zero, or larger than the `number_of_receivers`.
/// * `CspDkgCreateTranscriptError::InvalidDealingError` if `csp_dealings` is
///   malformed or invalid.
///
/// # Panics
/// * If Langrange interpolation fails (because of duplicate x-coordinates).
Creates an NiDKG transcript with the same public key as an existing
threshold key.
Creates an NiDKG transcript with the same public key as an existing threshold key .
pub fn create_resharing_transcript(
    threshold: NumberOfNodes,
    number_of_receivers: NumberOfNodes,
    csp_dealings: &BTreeMap<NodeIndex, g20::Dealing>,
    resharing_public_coefficients: &PublicCoefficientsBytes,
) -> Result<g20::Transcript, CspDkgCreateReshareTranscriptError> {
    // Take the requisite number of dealings
    let resharing_threshold = resharing_public_coefficients.coefficients.len();
    if csp_dealings.len() < resharing_threshold {
        let error = InvalidArgumentError {
            message: format!(
                "Insufficient dealings ({}) to reshare keys with threshold ({}).",
                csp_dealings.len(),
                resharing_threshold
            ),
        };
        return Err(CspDkgCreateReshareTranscriptError::InsufficientDealingsError(error));
    }
    let csp_dealings = csp_dealings
        .iter()
        .take(resharing_threshold)
        .map(|(dealer_index, dealing)| (*dealer_index, dealing))
        .collect();
    // Compute the transcript
    let transcript = compute_transcript(threshold, number_of_receivers, &csp_dealings)?;
    // Verify that the public key is unchanged
    let public_coefficients = PublicCoefficientsBytes {
        coefficients: transcript.public_coefficients.coefficients.clone(),
    };
    if pub_key_bytes_from_pub_coeff_bytes(resharing_public_coefficients)
        != pub_key_bytes_from_pub_coeff_bytes(&public_coefficients)
    {
        let error = InvalidArgumentError {
            message: format!(
                "Resharing failed.  Have the dealings been verified?:\n  Old public key: {:?}\n  New public key: {:?}",
                pub_key_bytes_from_pub_coeff_bytes(resharing_public_coefficients),
                pub_key_bytes_from_pub_coeff_bytes(&public_coefficients)
            ),
        };
        return Err(CspDkgCreateReshareTranscriptError::ResharingFailed(error));
    }
    Ok(transcript)
}
pub fn create_resharing_transcript ( threshold : NumberOfNodes , number_of_receivers : NumberOfNodes , csp_dealings : & BTreeMap < NodeIndex , g20 :: Dealing > , resharing_public_coefficients : & PublicCoefficientsBytes , ) -> Result < g20 :: Transcript , CspDkgCreateReshareTranscriptError > { // Take the requisite number of dealings let resharing_threshold = resharing_public_coefficients . coefficients . len ( ) ; if csp_dealings . len ( ) < resharing_threshold { let error = InvalidArgumentError { message : format ! ( " " csp_dealings len ( ) resharing_threshold ) , } ; return Err ( CspDkgCreateReshareTranscriptError :: InsufficientDealingsError ( error ) ) ; } let csp_dealings = csp_dealings . iter ( ) . take ( resharing_threshold ) . map ( | ( dealer_index , dealing ) | ( * dealer_index , dealing ) ) . collect ( ) ; // Compute the transcript let transcript = compute_transcript ( threshold , number_of_receivers , & csp_dealings ) ? ; // Verify that the public key is unchanged let public_coefficients = PublicCoefficientsBytes { coefficients : transcript . public_coefficients . coefficients . clone ( ) , } ; if pub_key_bytes_from_pub_coeff_bytes ( resharing_public_coefficients ) != pub_key_bytes_from_pub_coeff_bytes ( & public_coefficients ) { let error = InvalidArgumentError { message : format ! ( " \n \n " pub_key_bytes_from_pub_coeff_bytes ( resharing_public_coefficients ) pub_key_bytes_from_pub_coeff_bytes ( public_coefficients ) ) , } ; return Err ( CspDkgCreateReshareTranscriptError :: ResharingFailed ( error ) ) ; } Ok ( transcript ) }
Creates an NiDKG transcript with the same public key as an existing
threshold key.
Creates an NiDKG transcript with the same public key as an existing threshold key .
threshold
NumberOfNodes
number_of_receivers
NumberOfNodes
csp_dealings
&BTreeMap<NodeIndex, g20::Dealing>
resharing_public_coefficients
&PublicCoefficientsBytes
prerequisites
The dealings MUST be verified before calling this method; otherwise
dealers may provide receivers with invalid shares or dealers may provide
keys that do not preserve the public key.
The dealings MUST be verified before calling this method ; otherwise dealers may provide receivers with invalid shares or dealers may provide keys that do not preserve the public key .
errors
`CspDkgCreateReshareTranscriptError::InsufficientDealingsError` if the
length of `csp_dealings` is smaller than the new threshold (set by
`resharing_public_coefficients`).
`CspDkgCreateReshareTranscriptError::ResharingFailed` if the public key
created by this resharing does not match the previous public key.
`CspDkgCreateTranscriptError::InvalidThresholdError` if the threshold is
either zero, or larger than the `number_of_receivers`.
`CspDkgCreateTranscriptError::InvalidDealingError` if `csp_dealings` is
malformed or invalid.
` CspDkgCreateReshareTranscriptError :: InsufficientDealingsError ` if the length of ` csp_dealings ` is smaller than the new threshold ( set by ` resharing_public_coefficients ` ) . ` CspDkgCreateReshareTranscriptError :: ResharingFailed ` if the public key created by this resharing does not match the previous public key . ` CspDkgCreateTranscriptError :: InvalidThresholdError ` if the threshold is either zero or larger than the ` number_of_receivers ` . ` CspDkgCreateTranscriptError :: InvalidDealingError ` if ` csp_dealings ` is malformed or invalid .
panics
If Langrange interpolation fails (because of duplicate x-coordinates).
If Langrange interpolation fails ( because of duplicate x - coordinates ) .