LOCAL RELAY MODEL IS WORKING
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use nostr::prelude::secp256k1;
|
||||
use serde_json;
|
||||
use std::array::TryFromSliceError;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -7,6 +8,7 @@ pub enum Error {
|
||||
Empty,
|
||||
DecodeFailed,
|
||||
HexDecodeFailed,
|
||||
InvalidByteSize,
|
||||
InvalidSignature,
|
||||
Secp(secp256k1::Error),
|
||||
Json(serde_json::Error),
|
||||
@@ -20,6 +22,7 @@ impl std::cmp::PartialEq for Error {
|
||||
(Error::DecodeFailed, Error::DecodeFailed) => true,
|
||||
(Error::HexDecodeFailed, Error::HexDecodeFailed) => true,
|
||||
(Error::InvalidSignature, Error::InvalidSignature) => true,
|
||||
(Error::InvalidByteSize, Error::InvalidByteSize) => true,
|
||||
// This is slightly wrong but whatevs
|
||||
(Error::Json(..), Error::Json(..)) => true,
|
||||
(Error::Generic(left), Error::Generic(right)) => left == right,
|
||||
@@ -36,6 +39,7 @@ impl fmt::Display for Error {
|
||||
Self::DecodeFailed => write!(f, "decoding failed"),
|
||||
Self::InvalidSignature => write!(f, "invalid signature"),
|
||||
Self::HexDecodeFailed => write!(f, "hex decoding failed"),
|
||||
Self::InvalidByteSize => write!(f, "invalid byte size"),
|
||||
Self::Secp(e) => write!(f, "{e}"),
|
||||
Self::Json(e) => write!(f, "{e}"),
|
||||
Self::Generic(e) => write!(f, "{e}"),
|
||||
@@ -51,6 +55,12 @@ impl From<String> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TryFromSliceError> for Error {
|
||||
fn from(_e: TryFromSliceError) -> Self {
|
||||
Error::InvalidByteSize
|
||||
}
|
||||
}
|
||||
|
||||
impl From<hex::FromHexError> for Error {
|
||||
fn from(_e: hex::FromHexError) -> Self {
|
||||
Error::HexDecodeFailed
|
||||
|
||||
@@ -7,21 +7,23 @@ use nostr::key::XOnlyPublicKey;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Hash)]
|
||||
pub struct Pubkey(XOnlyPublicKey);
|
||||
pub struct Pubkey([u8; 32]);
|
||||
|
||||
impl Pubkey {
|
||||
pub fn new(data: &[u8; 32]) -> Self {
|
||||
Self(*data)
|
||||
}
|
||||
|
||||
pub fn hex(&self) -> String {
|
||||
hex::encode(self.bytes())
|
||||
}
|
||||
|
||||
pub fn bytes(&self) -> [u8; 32] {
|
||||
self.0.serialize()
|
||||
pub fn bytes(&self) -> &[u8; 32] {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn from_hex(hex_str: &str) -> Result<Self, Error> {
|
||||
Ok(Pubkey(XOnlyPublicKey::from_slice(
|
||||
hex::decode(hex_str)?.as_slice(),
|
||||
)?))
|
||||
Ok(Pubkey(hex::decode(hex_str)?.as_slice().try_into()?))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user