diff --git a/crates/subspace-farmer/src/single_disk_farm/identity.rs b/crates/subspace-farmer/src/single_disk_farm/identity.rs index a95b87b709..1804c1e693 100644 --- a/crates/subspace-farmer/src/single_disk_farm/identity.rs +++ b/crates/subspace-farmer/src/single_disk_farm/identity.rs @@ -32,6 +32,9 @@ pub enum IdentityError { /// I/O error occurred #[error("Identity I/O error: {0}")] Io(#[from] io::Error), + /// Invalid contents + #[error("Invalid contents")] + InvalidContents, /// Decoding error #[error("Decoding error: {0}")] Decoding(#[from] parity_scale_codec::Error), @@ -95,6 +98,10 @@ impl Identity { let IdentityFileContents { entropy } = IdentityFileContents::decode(&mut bytes.as_ref())?; + if entropy.len() != ENTROPY_LENGTH { + return Err(IdentityError::InvalidContents); + } + Ok(Some(Self { keypair: Zeroizing::new(keypair_from_entropy(&entropy)), entropy: Zeroizing::new(entropy), @@ -124,29 +131,6 @@ impl Identity { }) } - /// Create identity from given entropy, overrides identity that might already exist. - /// - /// Primarily used for testing. - #[doc(hidden)] - pub fn from_entropy>( - base_directory: B, - entropy: Vec, - ) -> Result { - let identity_file = base_directory.as_ref().join(Self::FILE_NAME); - debug!("Creating identity from provided entropy"); - - let identity_file_contents = IdentityFileContents { entropy }; - fs::write(identity_file, identity_file_contents.encode())?; - - let IdentityFileContents { entropy } = identity_file_contents; - - Ok(Self { - keypair: Zeroizing::new(keypair_from_entropy(&entropy)), - entropy: Zeroizing::new(entropy), - substrate_ctx: schnorrkel::context::signing_context(REWARD_SIGNING_CONTEXT), - }) - } - /// Returns the public key of the identity. pub fn public_key(&self) -> &PublicKey { &self.keypair.public