diff --git a/crates/enostr/src/note.rs b/crates/enostr/src/note.rs index cfd75509..ed178488 100644 --- a/crates/enostr/src/note.rs +++ b/crates/enostr/src/note.rs @@ -36,6 +36,16 @@ impl NoteId { pub fn to_bech(&self) -> Option { bech32::encode::(HRP_NOTE, &self.0).ok() } + + pub fn from_bech(bech: &str) -> Option { + 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