fn create_resharing_dealing(
        &self,
        algorithm_id: AlgorithmId,
        dkg_id: NiDkgId,
        dealer_resharing_index: NodeIndex,
        threshold: NumberOfNodes,
        epoch: Epoch,
        receiver_keys: BTreeMap<NodeIndex, CspFsEncryptionPublicKey>,
        resharing_public_coefficients: CspPublicCoefficients,
    ) -> Result<CspNiDkgDealing, ni_dkg_errors::CspDkgCreateReshareDealingError> {
        debug!(self.logger; crypto.method_name => "create_resharing_dealing", crypto.dkg_epoch => epoch.get());
        // Get state
        // Fetch secret key corresponding to the resharing_public_coefficients from the
        // Secret Key Store.
        let resharing_secret_key = {
            let key_id = key_id_from_csp_pub_coeffs(&resharing_public_coefficients);
            let secret_key: Option<CspSecretKey> = self.sks_read_lock().get(&key_id);
            secret_key.ok_or_else(|| {
                ni_dkg_errors::CspDkgCreateReshareDealingError::ReshareKeyNotInSecretKeyStoreError(
                    ni_dkg_errors::KeyNotFoundError {
                        internal_error: format!(
                            "Cannot find threshold key to be reshared:\n  Dkg: {}\n  Epoch:  {}",
                            dkg_id, epoch
                        ),
                        key_id,
                    },
                )
            })
        }?;
        // Specialisation to this scheme:
        match algorithm_id {
            AlgorithmId::NiDkg_Groth20_Bls12_381 => {
                let resharing_secret_key = specialise::groth20::threshold_secret_key(
                    resharing_secret_key,
                )
                .map_err(
                    ni_dkg_errors::CspDkgCreateReshareDealingError::MalformedReshareSecretKeyError,
                )?;
                let receiver_keys = specialise::groth20::receiver_keys(&receiver_keys).map_err(
                    |(receiver_index, error)| {
                        ni_dkg_errors::CspDkgCreateReshareDealingError::MalformedFsPublicKeyError {
                            receiver_index,
                            error,
                        }
                    },
                )?;
                // Stateless call to crypto lib
                // Acquire an rng lock and generate randomness before invoking create_dealing
                // because:
                // * acquiring two locks inline in the create_dealing call would lead to a
                //   deadlock.
                // * we should not hold the write lock for the whole duration of create_dealing.
                let (keygen_seed, encryption_seed) = {
                    let mut rng = self.rng_write_lock();
                    (rng.gen::<[u8; 32]>(), rng.gen::<[u8; 32]>())
                };
                let dealing = clib::create_dealing(
                    Randomness::from(keygen_seed),
                    Randomness::from(encryption_seed),
                    threshold,
                    &receiver_keys,
                    epoch,
                    dealer_resharing_index,
                    Some(resharing_secret_key),
                )?;
                // Response
                Ok(CspNiDkgDealing::Groth20_Bls12_381(dealing))
            }
            other => {
                Err(ni_dkg_errors::CspDkgCreateReshareDealingError::UnsupportedAlgorithmId(other))
            }
        }
    }
/// Creates a CSP dealing by resharing a previous secret key
Creates a CSP dealing by resharing a previous secret key
Creates a CSP dealing by resharing a previous secret key
fn create_resharing_dealing(
        &self,
        algorithm_id: AlgorithmId,
        dkg_id: NiDkgId,
        dealer_resharing_index: NodeIndex,
        threshold: NumberOfNodes,
        epoch: Epoch,
        receiver_keys: BTreeMap<NodeIndex, CspFsEncryptionPublicKey>,
        resharing_public_coefficients: CspPublicCoefficients,
    ) -> Result<CspNiDkgDealing, ni_dkg_errors::CspDkgCreateReshareDealingError> {
        debug!(self.logger; crypto.method_name => "create_resharing_dealing", crypto.dkg_epoch => epoch.get());
        // Get state
        // Fetch secret key corresponding to the resharing_public_coefficients from the
        // Secret Key Store.
        let resharing_secret_key = {
            let key_id = key_id_from_csp_pub_coeffs(&resharing_public_coefficients);
            let secret_key: Option<CspSecretKey> = self.sks_read_lock().get(&key_id);
            secret_key.ok_or_else(|| {
                ni_dkg_errors::CspDkgCreateReshareDealingError::ReshareKeyNotInSecretKeyStoreError(
                    ni_dkg_errors::KeyNotFoundError {
                        internal_error: format!(
                            "Cannot find threshold key to be reshared:\n  Dkg: {}\n  Epoch:  {}",
                            dkg_id, epoch
                        ),
                        key_id,
                    },
                )
            })
        }?;
        // Specialisation to this scheme:
        match algorithm_id {
            AlgorithmId::NiDkg_Groth20_Bls12_381 => {
                let resharing_secret_key = specialise::groth20::threshold_secret_key(
                    resharing_secret_key,
                )
                .map_err(
                    ni_dkg_errors::CspDkgCreateReshareDealingError::MalformedReshareSecretKeyError,
                )?;
                let receiver_keys = specialise::groth20::receiver_keys(&receiver_keys).map_err(
                    |(receiver_index, error)| {
                        ni_dkg_errors::CspDkgCreateReshareDealingError::MalformedFsPublicKeyError {
                            receiver_index,
                            error,
                        }
                    },
                )?;
                // Stateless call to crypto lib
                // Acquire an rng lock and generate randomness before invoking create_dealing
                // because:
                // * acquiring two locks inline in the create_dealing call would lead to a
                //   deadlock.
                // * we should not hold the write lock for the whole duration of create_dealing.
                let (keygen_seed, encryption_seed) = {
                    let mut rng = self.rng_write_lock();
                    (rng.gen::<[u8; 32]>(), rng.gen::<[u8; 32]>())
                };
                let dealing = clib::create_dealing(
                    Randomness::from(keygen_seed),
                    Randomness::from(encryption_seed),
                    threshold,
                    &receiver_keys,
                    epoch,
                    dealer_resharing_index,
                    Some(resharing_secret_key),
                )?;
                // Response
                Ok(CspNiDkgDealing::Groth20_Bls12_381(dealing))
            }
            other => {
                Err(ni_dkg_errors::CspDkgCreateReshareDealingError::UnsupportedAlgorithmId(other))
            }
        }
    }
fn create_resharing_dealing ( & self , algorithm_id : AlgorithmId , dkg_id : NiDkgId , dealer_resharing_index : NodeIndex , threshold : NumberOfNodes , epoch : Epoch , receiver_keys : BTreeMap < NodeIndex , CspFsEncryptionPublicKey > , resharing_public_coefficients : CspPublicCoefficients , ) -> Result < CspNiDkgDealing , ni_dkg_errors :: CspDkgCreateReshareDealingError > { debug ! ( self logger crypto method_name " " crypto dkg_epoch epoch get ( ) ) ; // Get state // Fetch secret key corresponding to the resharing_public_coefficients from the // Secret Key Store. let resharing_secret_key = { let key_id = key_id_from_csp_pub_coeffs ( & resharing_public_coefficients ) ; let secret_key : Option < CspSecretKey > = self . sks_read_lock ( ) . get ( & key_id ) ; secret_key . ok_or_else ( | | { ni_dkg_errors :: CspDkgCreateReshareDealingError :: ReshareKeyNotInSecretKeyStoreError ( ni_dkg_errors :: KeyNotFoundError { internal_error : format ! ( " \n \n " dkg_id epoch ) , key_id , } , ) } ) } ? ; // Specialisation to this scheme: match algorithm_id { AlgorithmId :: NiDkg_Groth20_Bls12_381 => { let resharing_secret_key = specialise :: groth20 :: threshold_secret_key ( resharing_secret_key , ) . map_err ( ni_dkg_errors :: CspDkgCreateReshareDealingError :: MalformedReshareSecretKeyError , ) ? ; let receiver_keys = specialise :: groth20 :: receiver_keys ( & receiver_keys ) . map_err ( | ( receiver_index , error ) | { ni_dkg_errors :: CspDkgCreateReshareDealingError :: MalformedFsPublicKeyError { receiver_index , error , } } , ) ? ; // Stateless call to crypto lib // Acquire an rng lock and generate randomness before invoking create_dealing // because: // * acquiring two locks inline in the create_dealing call would lead to a //   deadlock. // * we should not hold the write lock for the whole duration of create_dealing. let ( keygen_seed , encryption_seed ) = { let mut rng = self . rng_write_lock ( ) ; ( rng . gen :: < [ u8 ; 32 ] > ( ) , rng . gen :: < [ u8 ; 32 ] > ( ) ) } ; let dealing = clib :: create_dealing ( Randomness :: from ( keygen_seed ) , Randomness :: from ( encryption_seed ) , threshold , & receiver_keys , epoch , dealer_resharing_index , Some ( resharing_secret_key ) , ) ? ; // Response Ok ( CspNiDkgDealing :: Groth20_Bls12_381 ( dealing ) ) } other => { Err ( ni_dkg_errors :: CspDkgCreateReshareDealingError :: UnsupportedAlgorithmId ( other ) ) } } }
Creates a CSP dealing by resharing a previous secret key
Creates a CSP dealing by resharing a previous secret key
&self
algorithm_id
AlgorithmId
dkg_id
NiDkgId
dealer_resharing_index
NodeIndex
threshold
NumberOfNodes
epoch
Epoch
receiver_keys
BTreeMap<NodeIndex, CspFsEncryptionPublicKey>
resharing_public_coefficients
CspPublicCoefficients
&self
algorithm_id
AlgorithmId
dkg_id
NiDkgId
dealer_resharing_index
NodeIndex
threshold
NumberOfNodes
epoch
Epoch
receiver_keys
BTreeMap<NodeIndex, CspFsEncryptionPublicKey>
resharing_public_coefficients
CspPublicCoefficients