Rust implementation of Nostr protocol.
toml
[dependencies]
anyhow = "1"
nostr = "0.2"
tungstenite = { version = "0.17", features = ["rustls-tls-webpki-roots"]}
url = "2"
```rust,no_run 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<()> { // Generate new random keys let mynewkeys = Keys::generatefromos_random();
// Use your already existing bec32 keys
let my_bech32_keys = Keys::from_bech32("nsec1...")?;
// Use your already existing keys
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"),
)?;
// Connect to relay
let (mut socket, _) = tungstenite::connect(Url::parse("wss://relay.damus.io")?).expect("Can't connect to relay");
// Send msg
let msg = ClientMessage::new_event(event).to_json();
socket.write_message(WsMessage::Text(msg))?;
Ok(())
} ```
More examples can be found in the examples directory.
| Supported | NIP |
|:----------:| ---------------------------------------------------------------------------------------------------------------------------------- |
| ✅ | 01 - Basic protocol flow description |
| ✅ | 02 - Contact List and Petnames |
| ❌ | 03 - OpenTimestamps Attestations for Events |
| ✅ | 04 - Encrypted Direct Message |
| ❌ | 05 - Mapping Nostr keys to DNS-based internet identifiers |
| ✅ | 06 - Basic key derivation from mnemonic seed phrase |
| ❌ | 08 - Handling Mentions |
| ✅ | 09 - Event Deletion |
| ❌ | 10 - Conventions for clients' use of e
and p
tags in text events |
| ✅ | 11 - Relay Information Document |
| ❌ | 12 - Generic Tag Queries |
| ✅ | 13 - Proof of Work |
| ❌ | 14 - Subject tag in text events |
| ✅ | 15 - End of Stored Events Notice |
| ❌ | 16 - Event Treatment |
| ❌ | 22 - Event created_at Limits |
| ✅ | 25 - Reactions |
| ✅ | 28 - Public Chat |
This library is in an ALPHA state, things that are implemented generally work but the API will change in breaking ways.
This project is distributed under the MIT software license - see the LICENSE file for details