Skip to content

Commit

Permalink
Verify unsigned event ids
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Jan 19, 2024
1 parent b8d2670 commit 81bb46e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/nostr/src/event/unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event, Error> {
Expand Down

0 comments on commit 81bb46e

Please sign in to comment.