add NoteId::from_bech method

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-05-25 18:26:44 -04:00
parent a1ac0cd2c8
commit 64d3a0842e

View File

@@ -36,6 +36,16 @@ impl NoteId {
pub fn to_bech(&self) -> Option<String> {
bech32::encode::<bech32::Bech32>(HRP_NOTE, &self.0).ok()
}
pub fn from_bech(bech: &str) -> Option<Self> {
let (hrp, data) = bech32::decode(bech).ok()?;
if hrp != HRP_NOTE {
return None;
}
Some(NoteId::new(data.try_into().ok()?))
}
}
/// Event is the struct used to represent a Nostr event