lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

error.rs (4314B)


      1 //! Normalized Nostr adapter failures.
      2 //!
      3 //! Errors describe stable failure categories without retaining secret keys,
      4 //! passwords, plaintext messages, or caller-supplied credential strings.
      5 
      6 #[cfg(feature = "events")]
      7 use alloc::boxed::Box;
      8 use alloc::string::String;
      9 use thiserror::Error;
     10 
     11 #[derive(Debug, Error)]
     12 pub enum Error {
     13     #[error("invalid Nostr public key")]
     14     InvalidPublicKey,
     15 
     16     #[error("invalid NIP-19 npub public key")]
     17     InvalidNpub,
     18 
     19     #[cfg(feature = "signing")]
     20     #[error("invalid Nostr secret key")]
     21     InvalidSecretKey,
     22 
     23     #[cfg(feature = "signing")]
     24     #[error("invalid NIP-49 encrypted secret key")]
     25     InvalidEncryptedSecretKey,
     26 
     27     #[cfg(feature = "signing")]
     28     #[error("NIP-49 secret-key encryption failed")]
     29     SecretKeyEncryption,
     30 
     31     #[cfg(feature = "signing")]
     32     #[error("NIP-49 secret-key decryption failed")]
     33     SecretKeyDecryption,
     34 
     35     #[error("Nostr event kind {kind} exceeds {max}")]
     36     KindOutOfRange { kind: u32, max: u16 },
     37 
     38     #[error("Radroots event field {field} cannot be represented by Nostr")]
     39     EventConversion { field: &'static str },
     40 
     41     #[error("Radroots event coordinate cannot be represented by Nostr")]
     42     CoordinateConversion,
     43 
     44     #[error("Radroots event tag cannot be represented by Nostr")]
     45     TagConversion,
     46 
     47     #[error("Nostr event kind {kind} requires typed authoring")]
     48     TypedAuthoringRequired { kind: u16 },
     49 
     50     #[error("External signing author mismatch: expected {expected}, got {actual}")]
     51     ExternalSigningAuthorMismatch {
     52         expected: nostr::PublicKey,
     53         actual: nostr::PublicKey,
     54     },
     55 
     56     #[error("External signing event ID mismatch: expected {expected}, got {actual}")]
     57     ExternalSigningEventIdMismatch {
     58         expected: nostr::EventId,
     59         actual: nostr::EventId,
     60     },
     61 
     62     #[error("External signing event is invalid: {0}")]
     63     ExternalSigningEventInvalid(#[cfg_attr(feature = "std", source)] nostr::event::Error),
     64 
     65     #[error("External signing result does not match authored plan field `{field}`")]
     66     ExternalSigningPlanMismatch { field: &'static str },
     67 
     68     #[error("Event error: {0}")]
     69     EventError(#[cfg_attr(feature = "std", source)] nostr::event::Error),
     70 
     71     #[error("Event builder failure: {0}")]
     72     EventBuildError(#[cfg_attr(feature = "std", source)] nostr::event::builder::Error),
     73 
     74     #[cfg(feature = "events")]
     75     #[error("Draft error: {0}")]
     76     DraftError(#[from] radroots_event::draft::DraftError),
     77 
     78     #[cfg(feature = "events")]
     79     #[error("Event wire error: {0}")]
     80     EventWire(#[from] radroots_event::wire::EventWireError),
     81 
     82     #[cfg(feature = "events")]
     83     #[error("FoodAvailability encoding error: {0}")]
     84     FoodAvailabilityEncode(
     85         #[from]
     86         radroots_event_codec::encode::food_availability::RadrootsFoodAvailabilityEncodeError,
     87     ),
     88 
     89     #[cfg(feature = "events")]
     90     #[error("Profile encoding error: {0}")]
     91     ProfileEncode(
     92         #[from] radroots_event_codec::encode::profile::RadrootsAuthoredProfileEncodeError,
     93     ),
     94 
     95     #[cfg(feature = "events")]
     96     #[error("Authored plan error: {0}")]
     97     AuthoredPlan(#[from] radroots_event_codec::authoring::AuthoredPlanError),
     98 
     99     #[cfg(feature = "events")]
    100     #[error("Signed event error: {0}")]
    101     SignedEvent(#[from] radroots_event::draft::SignedEventError),
    102 
    103     #[error("Key error: {0}")]
    104     KeyError(#[cfg_attr(feature = "std", source)] nostr::key::Error),
    105 
    106     #[error("Filter tag error: {0}")]
    107     FilterTagError(String),
    108 }
    109 
    110 impl From<nostr::event::Error> for Error {
    111     fn from(error: nostr::event::Error) -> Self {
    112         Self::EventError(error)
    113     }
    114 }
    115 
    116 impl From<nostr::event::builder::Error> for Error {
    117     fn from(error: nostr::event::builder::Error) -> Self {
    118         Self::EventBuildError(error)
    119     }
    120 }
    121 
    122 impl From<nostr::key::Error> for Error {
    123     fn from(error: nostr::key::Error) -> Self {
    124         Self::KeyError(error)
    125     }
    126 }
    127 
    128 #[cfg(feature = "events")]
    129 #[derive(Debug, Error)]
    130 pub enum ResolveError {
    131     #[error("Missing public key 'p' tag in encrypted event: {0:?}")]
    132     MissingPTag(Box<nostr::Event>),
    133 
    134     #[error("Encrypted event recipient mismatch")]
    135     NotRecipient,
    136 
    137     #[error("Decryption error: {0}")]
    138     DecryptionError(String),
    139 
    140     #[error("Failed to parse decrypted tag JSON: {0}")]
    141     ParseError(#[from] serde_json::Error),
    142 }