diff --git a/Cargo.toml b/Cargo.toml index 6adecc8..af42ac3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/events.rs b/src/events.rs index 97a8901..d613056 100644 --- a/src/events.rs +++ b/src/events.rs @@ -137,6 +137,7 @@ impl EventPrepare { tags: self.tags.clone(), content: self.content.clone(), sig: signature, + ots: None, } } } @@ -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, } #[derive(Error, Debug, Eq, PartialEq)] pub enum EventError { #[error("Secp256k1 Error: {}", _0)] Secp256k1Error(secp256k1::Error), + + #[error("Ots error: {0}")] + Ots(String), } impl From for EventError { @@ -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 {