Nostr

Description
Rust implementation of Nostr protocol.
Getting started
[dependencies]
nostr = "0.8"
tungstenite = { version = "0.17", features = ["rustls-tls-webpki-roots"]}
use nostr::{Event, EventBuilder, Metadata, Keys, Result};
use nostr::message::ClientMessage;
use nostr::url::Url;
use tungstenite::{Message as WsMessage};
fn main() -> Result<()> {
let my_keys = Keys::generate_from_os_random();
let metadata = Metadata::new()
.name("username")
.display_name("My Username")
.about("Description")
.picture(Url::parse("https://example.com/avatar.png")?)
.nip05("username@example.com");
let event: Event = EventBuilder::set_metadata(metadata)?.to_event(&my_keys)?;
let event: Event = EventBuilder::new_text_note("Hello from Nostr SDK", &[]).to_event(&my_keys)?;
let event: Event = EventBuilder::new_text_note("My first POW text note from Nostr SDK", &[]).to_pow_event(&my_keys, 20)?;
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)).expect("Impossible to send message");
Ok(())
}
More examples can be found in the examples directory.
Crate Feature Flags
The following crate feature flags are available:
| Feature |
Default |
Description |
all-nips |
Yes |
Enable all NIPs |
nip04 |
Yes |
Enable NIP-04: Encrypted Direct Message |
nip05 |
Yes |
Enable NIP-05: Mapping Nostr keys to DNS-based internet identifiers |
nip06 |
Yes |
Enable NIP-06: Basic key derivation from mnemonic seed phrase |
nip11 |
Yes |
Enable NIP-11: Relay Information Document |
Supported 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