#![allow(
clippy::print_stdout,
clippy::missing_assert_message,
clippy::panic_in_result_fn,
clippy::indexing_slicing,
clippy::uninlined_format_args,
clippy::useless_vec,
unused_crate_dependencies,
reason = "runnable demo: stdout output is the whole point, panic-on-failure is acceptable in a script-like context, and the binary inherits the lib's dep set"
)]
use nula_core::event::{Event, EventBuilder};
use nula_core::{JsonUtil, Keys};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let keys = Keys::generate()?;
println!("public key : {}", keys.public_key().to_hex());
let signed: Event = EventBuilder::text_note("Hello from nula-core!")
.tag(nula_core::Tag::new(["t", "intro"])?)
.sign_with_keys(&keys)?;
println!("event id : {}", signed.id.to_hex());
println!("kind : {}", signed.kind.as_u16());
println!("created_at : {}", signed.created_at.as_secs());
println!("tag count : {}", signed.tags.len());
signed.verify()?;
println!("signature : OK");
let json = signed.try_to_json()?;
println!("---\nwire JSON ({} bytes):\n{}", json.len(), json);
let reparsed = Event::from_json(&json)?;
assert_eq!(reparsed, signed, "round-trip must preserve the event");
println!("---\nround-trip : OK");
Ok(())
}