commit 64d3a0842e641282cd017e1773987e0f55c218ed
parent a1ac0cd2c82b2d92128f74b700f0e9b0220dce5b
Author: kernelkind <kernelkind@gmail.com>
Date: Sun, 25 May 2025 18:26:44 -0400
add `NoteId::from_bech` method
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/crates/enostr/src/note.rs b/crates/enostr/src/note.rs
@@ -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