From 81bb46ed7be0a088d8fe2083c5b01596cdb7d6b0 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Fri, 19 Jan 2024 15:48:18 +0000 Subject: [PATCH] Verify unsigned event ids --- crates/nostr/src/event/unsigned.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 {