Expand description
§NostrO2
Simple yet powerful Rust library for the Nostr protocol.
nostro2 provides the core data structures and types for working with Nostr,
as defined in NIP-01. It focuses on type safety, ergonomics, and performance
with zero-copy operations where possible.
§Quick Start
§Creating Notes
use nostro2::{NostrNote, NostrNoteBuilder};
// Simple text note
let note = NostrNoteBuilder::text_note("Hello, Nostr!").build();
// Using the builder
let note = NostrNoteBuilder::new()
.content("Hello, Nostr!")
.kind(1)
.tag_pubkey("abc123...")
.build();
// Metadata note
let metadata = r#"{"name":"Alice","about":"Nostr user"}"#;
let note = NostrNoteBuilder::metadata(metadata).build();§Creating Subscriptions
use nostro2::NostrSubscription;
// Filter for text notes from specific authors
let filter = NostrSubscription::new()
.kind(1)
.author("pubkey1...")
.author("pubkey2...")
.limit(10);§Working with Tags
use nostro2::NostrTags;
let mut tags = NostrTags::new();
tags.add_pubkey_tag("abc123...", None);
tags.add_event_tag("event123...");
tags.add_custom_tag("t", "nostr");
assert_eq!(tags.len(), 3);§Validation
use nostro2::validation::NostrValidate;
if "abc123...".is_valid_pubkey() {
// Valid hex-encoded public key
}§Features
- NIP-01 Data Structures: Complete implementation of core Nostr types
- Fast JSON: Type-driven serialization via bourne (no serde)
- Builder Patterns: Ergonomic APIs for constructing notes and filters
- Type Safety: Strong typing with comprehensive error handling
- WASM Compatible: Works in browser environments
- Zero-Copy Operations: Non-allocating variants for performance
§Error Handling
The crate uses a Result type alias for convenience:
use nostro2::{NostrNote, NostrNoteBuilder, Result};
fn create_note() -> Result<NostrNote> {
let mut note = NostrNoteBuilder::text_note("Hello").build();
note.serialize_id()?;
Ok(note)
}Re-exports§
pub use event::NostrEvent;pub use view::NostrClientEventView;pub use view::NostrNoteView;pub use view::NostrRelayEventView;pub use view::NostrSubscriptionView;pub use view::TagsView;
Modules§
- errors
- Error types for the nostro2 crate
- event
- Shared verification trait for owned and borrowed Nostr events.
- validation
- Validation helpers for Nostr data — exposed as an extension trait on
str. - view
- Zero-allocation borrowed mirrors of owned Nostr types for relay-style consumers that only parse and forward events, never mutate them.
Structs§
- Nostr
Note - Nostr
Note Builder - Nostr
Subscription - Nostr
Tags - Collection of tags attached to a Nostr note.
Enums§
- Nostr
Client Event - Nostr
Relay Event - Relay
Event Tag - NIP-01 relay message tags. Wire form is uppercase (
"EVENT","OK", …). - Signer
Error - Re-export of the signer traits. Defined in
nostro2-traitsso protocol crates (nostro2-nips) and signer impls (nostro2-signer) can share the surface without depending onnostro2’s data structures. Errors returned by signing and key-derivation operations.
Traits§
- Nostr
Keypair - Re-export of the signer traits. Defined in
nostro2-traitsso protocol crates (nostro2-nips) and signer impls (nostro2-signer) can share the surface without depending onnostro2’s data structures. Extended interface for signers that hold raw secret material in process, adding key export, ECDH, and local key generation. - Nostr
Signer - Re-export of the signer traits. Defined in
nostro2-traitsso protocol crates (nostro2-nips) and signer impls (nostro2-signer) can share the surface without depending onnostro2’s data structures. Minimal signing surface: produce a Schnorr signature over a 32-byte prehash and expose the x-only public key. All hex/bech32 conversions are default methods on top.
Type Aliases§
- Result
- Convenience type alias for Results with
NostrErrors