/// Derives the threshold signing key share and loads it into the Secret Key
/// Store
Derives the threshold signing key share and loads it into the Secret Key
Store
Derives the threshold signing key share and loads it into the Secret Key Store
fn load_threshold_signing_key(
        &self,
        algorithm_id: AlgorithmId,
        _dkg_id: NiDkgId,
        epoch: Epoch,
        csp_transcript: CspNiDkgTranscript,
        receiver_index: NodeIndex,
    ) -> Result<(), ni_dkg_errors::CspDkgLoadPrivateKeyError> {
        debug!(self.logger; crypto.method_name => "load_threshold_signing_key", crypto.dkg_epoch => epoch.get());
        match algorithm_id {
            AlgorithmId::NiDkg_Groth20_Bls12_381 => {
                let threshold_key_id =
                    key_id_from_csp_pub_coeffs(&CspPublicCoefficients::from(&csp_transcript));
                // Convert types
                let transcript = specialise::groth20::transcript(csp_transcript)
                    .map_err(ni_dkg_errors::CspDkgLoadPrivateKeyError::MalformedTranscriptError)?;
                // Check if threshold key has been computed already
                let threshold_secret_key: Option<CspSecretKey> =
                    self.sks_read_lock().get(&threshold_key_id);
                if let Some(secret_key) = threshold_secret_key {
                    // this adds a sanity check to ensure the key is well formed:
                    return specialise::groth20::threshold_secret_key(secret_key)
                        .map(|_| ())
                        .map_err(
                            ni_dkg_errors::CspDkgLoadPrivateKeyError::MalformedSecretKeyError,
                        );
                }
                // Compute the key
                let fs_decryption_key = {
                    let key_id = self.dkg_dealing_encryption_key_id();
                    let key_set = self.sks_read_lock().get(&key_id).ok_or_else(||
                      ni_dkg_errors::CspDkgLoadPrivateKeyError::KeyNotFoundError( // TODO (CRP-820): This name is inconsistent with the other error enums, where this is now called FsKeyNotInSecretKeyStoreError or some such paragraph-of-a-name.
                        ni_dkg_errors::KeyNotFoundError {
                          internal_error: "Cannot decrypt shares if the forward secure key encryption key is missing".to_string(),
                          key_id,
                        },
                      )
                    )?;
                    let raw_fs_key_set =
                        specialise::groth20::fs_key_set(
                            specialise::fs_key_set(key_set).expect("Not a forward secure secret key; it should be impossible to retrieve a key of the wrong type.")
                        ).expect("If key generation is correct, it should be impossible to retrieve a key of the wrong type.");
                    trusted_secret_key_into_miracl(&raw_fs_key_set.secret_key)
                };
                let csp_secret_key = clib::compute_threshold_signing_key(
                    &transcript,
                    receiver_index,
                    &fs_decryption_key,
                    epoch,
                )
                .map(CspSecretKey::ThresBls12_381)?;
                match self.sks_write_lock().insert(
                    threshold_key_id,
                    csp_secret_key,
                    Some(NIDKG_THRESHOLD_SCOPE),
                ) {
                    Ok(()) => Ok(()),
                    Err(SecretKeyStoreError::DuplicateKeyId(_key_id)) => Ok(()),
                }
            }
            other => Err(ni_dkg_errors::CspDkgLoadPrivateKeyError::UnsupportedAlgorithmId(other)),
        }
    }
fn load_threshold_signing_key ( & self , algorithm_id : AlgorithmId , _dkg_id : NiDkgId , epoch : Epoch , csp_transcript : CspNiDkgTranscript , receiver_index : NodeIndex , ) -> Result < ( ) , ni_dkg_errors :: CspDkgLoadPrivateKeyError > { debug ! ( self logger crypto method_name " " crypto dkg_epoch epoch get ( ) ) ; match algorithm_id { AlgorithmId :: NiDkg_Groth20_Bls12_381 => { let threshold_key_id = key_id_from_csp_pub_coeffs ( & CspPublicCoefficients :: from ( & csp_transcript ) ) ; // Convert types let transcript = specialise :: groth20 :: transcript ( csp_transcript ) . map_err ( ni_dkg_errors :: CspDkgLoadPrivateKeyError :: MalformedTranscriptError ) ? ; // Check if threshold key has been computed already let threshold_secret_key : Option < CspSecretKey > = self . sks_read_lock ( ) . get ( & threshold_key_id ) ; if let Some ( secret_key ) = threshold_secret_key { // this adds a sanity check to ensure the key is well formed: return specialise :: groth20 :: threshold_secret_key ( secret_key ) . map ( | _ | ( ) ) . map_err ( ni_dkg_errors :: CspDkgLoadPrivateKeyError :: MalformedSecretKeyError , ) ; } // Compute the key let fs_decryption_key = { let key_id = self . dkg_dealing_encryption_key_id ( ) ; let key_set = self . sks_read_lock ( ) . get ( & key_id ) . ok_or_else ( | | ni_dkg_errors :: CspDkgLoadPrivateKeyError :: KeyNotFoundError ( // TODO (CRP-820): This name is inconsistent with the other error enums, where this is now called FsKeyNotInSecretKeyStoreError or some such paragraph-of-a-name. ni_dkg_errors :: KeyNotFoundError { internal_error : " " . to_string ( ) , key_id , } , ) ) ? ; let raw_fs_key_set = specialise :: groth20 :: fs_key_set ( specialise :: fs_key_set ( key_set ) . expect ( " " ) ) . expect ( " " ) ; trusted_secret_key_into_miracl ( & raw_fs_key_set . secret_key ) } ; let csp_secret_key = clib :: compute_threshold_signing_key ( & transcript , receiver_index , & fs_decryption_key , epoch , ) . map ( CspSecretKey :: ThresBls12_381 ) ? ; match self . sks_write_lock ( ) . insert ( threshold_key_id , csp_secret_key , Some ( NIDKG_THRESHOLD_SCOPE ) , ) { Ok ( ( ) ) => Ok ( ( ) ) , Err ( SecretKeyStoreError :: DuplicateKeyId ( _key_id ) ) => Ok ( ( ) ) , } } other => Err ( ni_dkg_errors :: CspDkgLoadPrivateKeyError :: UnsupportedAlgorithmId ( other ) ) , } }
Derives the threshold signing key share and loads it into the Secret Key
Store
Derives the threshold signing key share and loads it into the Secret Key Store
&self
algorithm_id
AlgorithmId
_dkg_id
NiDkgId
epoch
Epoch
csp_transcript
CspNiDkgTranscript
receiver_index
NodeIndex