Nostr

Description
Rust implementation of Nostr protocol.
Getting started
[dependencies]
anyhow = "1"
nostr = "0.2"
tungstenite = { version = "0.17", features = ["rustls-tls-webpki-roots"]}
url = "2"
use std::str::FromStr;
use nostr::Event;
use nostr::key::{FromBech32, Keys};
use nostr::message::ClientMessage;
use tungstenite::{Message as WsMessage};
use url::Url;
fn main() -> anyhow::Result<()> {
let my_new_keys = Keys::generate_from_os_random();
let my_bech32_keys = Keys::from_bech32("nsec1...")?;
let my_keys = Keys::from_str("hex-secret-key")?;
let event = Event::set_metadata(
&my_keys,
Some("nostr"),
Some("Nostr SDK"),
Some("Description"),
Some("https://example.com/avatar.png"),
)?;
let (mut socket, _) = tungstenite::connect(Url::parse("wss://relay.damus.io")?).expect("Can't connect to relay");
let msg = ClientMessage::new_event(event).to_json();
socket.write_message(WsMessage::Text(msg))?;
Ok(())
}
More examples can be found in the examples directory.
NIPs
State
This library is in an ALPHA state, things that are implemented generally work but the API will change in breaking ways.
License
This project is distributed under the MIT software license - see the LICENSE file for details