LOCAL RELAY MODEL IS WORKING

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-02-09 16:59:49 -08:00
parent 4a9af5561a
commit f323fe7379
7 changed files with 204 additions and 149 deletions

View File

@@ -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()?))
}
}