blueprint_crypto_sp_core/
error.rs1use blueprint_std::string::String;
2use sp_core::crypto::SecretStringError;
3use thiserror::Error;
4
5#[derive(Debug, Clone, Error)]
6pub enum SpCoreError {
7 #[error("Invalid seed: {0}")]
8 InvalidSeed(String),
9 #[error("Invalid secret string: {0}")]
10 SecretStringError(SecretStringErrorWrapper),
11 #[error("Invalid signature: {0}")]
12 InvalidSignature(String),
13 #[error("Invalid public key: {0}")]
14 InvalidPublicKey(String),
15 #[error("Invalid input: {0}")]
16 InvalidInput(String),
17}
18
19#[derive(Debug, Clone)]
20pub struct SecretStringErrorWrapper(pub SecretStringError);
21
22impl blueprint_std::fmt::Display for SecretStringErrorWrapper {
23 fn fmt(&self, f: &mut blueprint_std::fmt::Formatter<'_>) -> blueprint_std::fmt::Result {
24 match &self.0 {
25 SecretStringError::InvalidFormat(err) => write!(f, "Invalid format: {err}"),
26 SecretStringError::InvalidPhrase => write!(f, "Invalid phrase"),
27 SecretStringError::InvalidPassword => write!(f, "Invalid password"),
28 SecretStringError::InvalidSeed => write!(f, "Invalid seed"),
29 SecretStringError::InvalidSeedLength => write!(f, "Invalid seed length"),
30 SecretStringError::InvalidPath => write!(f, "Invalid path"),
31 }
32 }
33}
34
35impl From<SecretStringError> for SecretStringErrorWrapper {
36 fn from(e: SecretStringError) -> Self {
37 SecretStringErrorWrapper(e)
38 }
39}
40
41impl From<SecretStringErrorWrapper> for SpCoreError {
42 fn from(e: SecretStringErrorWrapper) -> Self {
43 SpCoreError::SecretStringError(e)
44 }
45}
46
47pub type Result<T> = blueprint_std::result::Result<T, SpCoreError>;