enostr: add Deref trait for Pubkey

This commit is contained in:
William Casarin
2024-11-18 17:08:58 -08:00
parent de8029d60f
commit bdea3da5f0

View File

@@ -3,6 +3,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use crate::Error;
use nostr::bech32::Hrp;
use std::fmt;
use std::ops::Deref;
use tracing::debug;
#[derive(Eq, PartialEq, Clone, Copy, Hash)]
@@ -10,6 +11,14 @@ pub struct Pubkey([u8; 32]);
static HRP_NPUB: Hrp = Hrp::parse_unchecked("npub");
impl Deref for Pubkey {
type Target = [u8; 32];
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Pubkey {
pub fn new(data: [u8; 32]) -> Self {
Self(data)