initial nostr code

This commit is contained in:
William Casarin
2022-12-11 15:46:18 -08:00
parent b6f5d8dc03
commit e6571d8847
16 changed files with 1434 additions and 41 deletions

38
enostr/src/error.rs Normal file
View File

@@ -0,0 +1,38 @@
use serde_json;
#[derive(Debug)]
pub enum Error {
MessageEmpty,
MessageDecodeFailed,
InvalidSignature,
Json(serde_json::Error),
Generic(String),
}
impl std::cmp::PartialEq for Error {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Error::MessageEmpty, Error::MessageEmpty) => true,
(Error::MessageDecodeFailed, Error::MessageDecodeFailed) => true,
(Error::InvalidSignature, Error::InvalidSignature) => true,
// This is slightly wrong but whatevs
(Error::Json(..), Error::Json(..)) => true,
(Error::Generic(left), Error::Generic(right)) => left == right,
_ => false,
}
}
}
impl std::cmp::Eq for Error {}
impl From<String> for Error {
fn from(s: String) -> Self {
Error::Generic(s)
}
}
impl From<serde_json::Error> for Error {
fn from(e: serde_json::Error) -> Self {
Error::Json(e)
}
}