NostrO2
This crate is our first approach at building simple Rust tools for interacting with the Nostr ecosystem.
Features
The library provides class-based functionality through 3 basic types: UserKeys, Notes, and Relays.
Notes
The main data structures of Nostr, as defined by NIP-01.
Implementations are split between Notes and SignedNotes,
to allow for easy interoperability with external applications like NIP-07. Both structures have full serde
serialization features and provide ready-to-send outputs for relay messages.
UserKeys
Can be created from a private key str
and will allow you to sign Nostr Notes.
let new_user = new;
let mut unsigned_note = new;
unsigned_note.tag_note;
let signed_note = user_key_pair.sign_nostr_event; // -> SignedNote
// A note object can also be parsed by a NIP 07 client
NostrRelay
Ready-to-go connection to a relay. WebSocket protocols are handled across reference
counted threads to allow you to handle multiple relays with ease. RelayEvents
provide
easy pattern-matching for relay/client communication and error-handling.
Subscriptions
You can pass any JSON filter to the subscribe
function within a NostrRelay
,
following the filter protocol in NIP-01.
// Open a connection
let ws_connection = new.await.expect;
// Subscribe to a filter
ws_connection
.subscribe
.await
.expect;
// Send notes in an async manner
ws_connection.send_note.await.expect;
// Read the responses from the relay
loop
Nostr Authentication
The SignedNotes
objects also provide a verification method for both content and signatures.
assert_eq!;
Installation
Run cargo add nostro2
to get the latest version.
You can also add nostro2
to your Cargo.toml
dependencies:
[]
= "0.1.14"