Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ reqwest = { version = "0.11", default-features = false, features = ["json", "rus
tokio = { version = "1.24", optional = true, features = ["macros"] }
futures-util = { version = "0.3", optional = true }
futures = { version = "0.3", optional = true }
nostr-ots = "0.1.1"
15 changes: 15 additions & 0 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl EventPrepare {
tags: self.tags.clone(),
content: self.content.clone(),
sig: signature,
ots: None,
}
}
}
Expand All @@ -160,12 +161,18 @@ pub struct Event {
pub content: String,
/// 64-bytes signature of the sha256 hash of the serialized event data, which is the same as the "id" field
pub sig: String,
/// OpenTimestamps proof serialized in base64
#[serde(skip_serializing_if = "Option::is_none")]
pub ots: Option<String>,
}

#[derive(Error, Debug, Eq, PartialEq)]
pub enum EventError {
#[error("Secp256k1 Error: {}", _0)]
Secp256k1Error(secp256k1::Error),

#[error("Ots error: {0}")]
Ots(String),
}

impl From<secp256k1::Error> for EventError {
Expand Down Expand Up @@ -254,6 +261,14 @@ impl Event {
)?;
Ok(())
}

/// Initialize the ots optional field in this event with the OpenTimestamps proof,
/// according to NIP-03
pub fn timestamp(&mut self) -> Result<(), EventError> {
let ots = nostr_ots::timestamp_event(&self.id).map_err(|e| EventError::Ots(e.to_string()))?;
self.ots = Some(ots);
Ok(())
}
}

impl fmt::Display for Event {
Expand Down