use alloc::string::{String, ToString};
#[cfg(feature = "std")]
use anyhow::Error as AnyhowError;
use core::result::Result as CoreResult;
#[cfg(feature = "std")]
use std::io;
pub type Result<T> = CoreResult<T, SignerError>;
#[derive(Debug, thiserror::Error)]
pub enum SignerError {
#[error("Key not found: {0}")]
KeyNotFound(String),
#[cfg(feature = "std")]
#[error("Storage error: {0}")]
Storage(#[from] io::Error),
#[error("Invalid key: {0}")]
InvalidKey(String),
#[error("Invalid signature: {0}")]
InvalidSignature(String),
#[error("Signature verification failed")]
VerificationFailed,
#[error("Serialization error: {0}")]
Serialization(String),
#[error("Cryptographic error: {0}")]
Crypto(String),
#[error("Invalid address: {0}")]
InvalidAddress(String),
#[error("Feature not enabled: {0}")]
FeatureNotEnabled(&'static str),
#[error("{0}")]
Other(String),
}
#[cfg(feature = "std")]
impl From<serde_json::Error> for SignerError {
fn from(err: serde_json::Error) -> Self {
SignerError::Serialization(err.to_string())
}
}
impl From<hex::FromHexError> for SignerError {
fn from(err: hex::FromHexError) -> Self {
SignerError::InvalidKey(err.to_string())
}
}
#[cfg(feature = "sr25519")]
impl From<schnorrkel::SignatureError> for SignerError {
fn from(err: schnorrkel::SignatureError) -> Self {
SignerError::Crypto(err.to_string())
}
}
#[cfg(feature = "std")]
impl From<AnyhowError> for SignerError {
fn from(err: AnyhowError) -> Self {
SignerError::Other(err.to_string())
}
}