use alloc::string::{String, ToString};
use core::fmt;
use crate::signer::SignerError;
#[derive(Debug, PartialEq)]
pub enum Error {
Json(String),
Signer(String),
Hex(faster_hex::Error),
UnknownKey(String),
InvalidId,
InvalidSignature,
}
impl core::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Json(e) => e.fmt(f),
Self::Signer(e) => e.fmt(f),
Self::Hex(e) => e.fmt(f),
Self::UnknownKey(key) => write!(f, "Unknown key: {key}"),
Self::InvalidId => f.write_str("Invalid event ID"),
Self::InvalidSignature => f.write_str("Invalid signature"),
}
}
}
impl From<serde_json::Error> for Error {
fn from(e: serde_json::Error) -> Self {
Self::Json(e.to_string())
}
}
impl From<SignerError> for Error {
fn from(e: SignerError) -> Self {
Self::Signer(e.to_string())
}
}
impl From<faster_hex::Error> for Error {
fn from(e: faster_hex::Error) -> Self {
Self::Hex(e)
}
}