diff --git a/crates/nostr/src/event/unsigned.rs b/crates/nostr/src/event/unsigned.rs index dcd8ae269..bd7ab8d8b 100644 --- a/crates/nostr/src/event/unsigned.rs +++ b/crates/nostr/src/event/unsigned.rs @@ -87,6 +87,22 @@ pub struct UnsignedEvent { } impl UnsignedEvent { + /// Verify if the [`EventId`] it's composed correctly + pub fn verify_id(&self) -> Result<(), Error> { + let id: EventId = EventId::new( + &self.pubkey, + self.created_at, + &self.kind, + &self.tags, + &self.content, + ); + if id == self.id { + Ok(()) + } else { + Err(Error::Event(super::Error::InvalidId)) + } + } + /// Sign an [`UnsignedEvent`] #[cfg(feature = "std")] pub fn sign(self, keys: &Keys) -> Result {