use blueprint_std::boxed::Box;
use blueprint_std::string::String;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
#[rustfmt::skip]
#[non_exhaustive]
pub enum Error {
#[error("Storage not supported")]
StorageNotSupported,
#[error(transparent)]
Io(#[from] blueprint_std::io::Error),
#[error("Invalid remote config")]
InvalidConfig,
#[error("Keystore lock error")]
KeystoreLockError,
#[error("Key type not supported")]
KeyTypeNotSupported,
#[error("Keystore operation not supported")]
KeystoreOperationNotSupported,
#[error("Key not found")]
KeyNotFound,
#[error("Invalid message length")]
InvalidMessageLength,
#[error("Invalid hex decoding")]
InvalidHexDecoding,
#[error("Failed to deserialize key: {0}")]
KeyDeserialization(#[from] serde::de::value::Error),
#[error("Invalid seed: {0}")]
InvalidSeed(String),
#[error("Signature failed: {0}")]
SignatureFailed(String),
#[error("Remote key fetch failed: {0}")]
RemoteKeyFetchFailed(String),
#[error(transparent)]
Crypto(#[from] blueprint_crypto::CryptoCoreError),
#[cfg(feature = "aws-signer")]
#[error(transparent)]
AwsSigner(#[from] alloy_signer_aws::AwsSignerError),
#[cfg(feature = "gcp-signer")]
#[error(transparent)]
GCloud(#[from] gcloud_sdk::error::Error),
#[cfg(feature = "gcp-signer")]
#[error(transparent)]
GcpSigner(#[from] alloy_signer_gcp::GcpSignerError),
#[cfg(any(feature = "ledger-node", feature = "ledger-browser"))]
#[error(transparent)]
Ledger(#[from] alloy_signer_ledger::LedgerError),
#[error(transparent)]
#[cfg(feature = "std")]
SerdeJsonError(#[from] serde_json::Error),
#[error("sr25519: {0}")]
#[cfg(feature = "sr25519-schnorrkel")]
SchnorrkelSr25519(String),
#[error("ecdsa: {0}")]
#[cfg(feature = "ecdsa")]
Ecdsa(#[from] k256::ecdsa::Error),
#[error("ed25519: {0}")]
#[cfg(feature = "zebra")]
Ed25519(#[from] ed25519_zebra::Error),
#[error("bls: {0}")]
#[cfg(feature = "bls")]
Bls(String),
#[error("bls_bn254: {0}")]
#[cfg(feature = "bn254")]
BlsBn254(String),
#[error("{0}")]
Other(String),
#[error(transparent)]
#[cfg(feature = "evm")]
AlloySigner(#[from] alloy_signer::Error),
#[error(transparent)]
#[cfg(feature = "evm")]
LocalSignerError(#[from] alloy_signer_local::LocalSignerError),
}
#[macro_export]
macro_rules! impl_from_for_boxed_error {
($error_type:ty, $variant:ident) => {
impl From<$error_type> for Box<Error> {
fn from(e: $error_type) -> Self {
Box::new(Error::$variant(e))
}
}
};
}
impl_from_for_boxed_error!(blueprint_std::io::Error, Io);
impl_from_for_boxed_error!(serde::de::value::Error, KeyDeserialization);
impl_from_for_boxed_error!(blueprint_crypto::CryptoCoreError, Crypto);
#[cfg(feature = "aws-signer")]
impl_from_for_boxed_error!(alloy_signer_aws::AwsSignerError, AwsSigner);
#[cfg(feature = "gcp-signer")]
impl_from_for_boxed_error!(gcloud_sdk::error::Error, GCloud);
#[cfg(feature = "gcp-signer")]
impl_from_for_boxed_error!(alloy_signer_gcp::GcpSignerError, GcpSigner);
#[cfg(any(feature = "ledger-node", feature = "ledger-browser"))]
impl_from_for_boxed_error!(alloy_signer_ledger::LedgerError, Ledger);
#[cfg(feature = "std")]
impl_from_for_boxed_error!(serde_json::Error, SerdeJsonError);
#[cfg(feature = "ecdsa")]
impl_from_for_boxed_error!(k256::ecdsa::Error, Ecdsa);
#[cfg(feature = "zebra")]
impl_from_for_boxed_error!(ed25519_zebra::Error, Ed25519);
#[cfg(feature = "evm")]
impl_from_for_boxed_error!(alloy_signer::Error, AlloySigner);
#[cfg(feature = "evm")]
impl_from_for_boxed_error!(alloy_signer_local::LocalSignerError, LocalSignerError);
#[cfg(feature = "sr25519-schnorrkel")]
impl From<schnorrkel::errors::SignatureError> for Error {
fn from(v: schnorrkel::errors::SignatureError) -> Self {
Self::SchnorrkelSr25519(v.to_string())
}
}