#protocols #no-std

no-std nostr

Rust implementation of the Nostr protocol

57 releases (37 breaking)

0.39.0 Jan 31, 2025
0.38.0 Dec 31, 2024
0.37.0 Nov 27, 2024
0.33.0 Jul 16, 2024
0.5.1 Nov 14, 2022

#102 in Web programming

Download history 1822/week @ 2024-11-22 1886/week @ 2024-11-29 2302/week @ 2024-12-06 2276/week @ 2024-12-13 963/week @ 2024-12-20 1145/week @ 2024-12-27 2025/week @ 2025-01-03 2297/week @ 2025-01-10 2780/week @ 2025-01-17 3702/week @ 2025-01-24 5277/week @ 2025-01-31 4746/week @ 2025-02-07 1462/week @ 2025-02-14 1676/week @ 2025-02-21 1206/week @ 2025-02-28 1112/week @ 2025-03-07

6,684 downloads per month
Used in 61 crates (38 directly)

MIT license

1MB
19K SLoC

Nostr

crates.io crates.io - Downloads Documentation CI MIT

Description

Rust implementation of Nostr protocol.

You may be interested in:

Getting started

use nostr::prelude::*;

fn main() -> Result<()> {
    // Generate new random keys
    let keys = Keys::generate();

    // Or use your already existing (from hex or bech32)
    let keys = Keys::parse("hex-or-bech32-secret-key")?;

    // Convert public key to bech32
    println!("Public key: {}", keys.public_key().to_bech32()?);

    let metadata = Metadata::new()
        .name("username")
        .display_name("My Username")
        .about("Description")
        .picture(Url::parse("https://example.com/avatar.png")?)
        .banner(Url::parse("https://example.com/banner.png")?)
        .nip05("username@example.com")
        .lud16("pay@yukikishimoto.com")
        .custom_field("custom_field", "my value");

    let event: Event = EventBuilder::metadata(&metadata).sign_with_keys(&keys)?;

    // New text note
    let event: Event = EventBuilder::text_note("Hello from rust-nostr").sign_with_keys(&keys)?;

    // New POW text note
    let event: Event = EventBuilder::text_note("POW text note from rust-nostr").pow(20).sign_with_keys(&keys)?;

    // Convert client message to JSON
    let json = ClientMessage::event(event).as_json();
    println!("{json}");

    Ok(())
}

More examples can be found in the examples/ directory.

WASM

This crate supports the wasm32 targets.

On macOS you need to install llvm:

brew install llvm
LLVM_PATH=$(brew --prefix llvm)
AR="${LLVM_PATH}/bin/llvm-ar" CC="${LLVM_PATH}/bin/clang" cargo build --target wasm32-unknown-unknown

NOTE: Currently nip03 feature not support WASM.

Embedded

This crate support no_std environments.

Check the example in the embedded/ directory.

Crate Feature Flags

The following crate feature flags are available:

Feature Default Description
std Yes Enable std library
alloc No Needed to use this library in no_std context
all-nips No Enable all NIPs
nip03 No Enable NIP-03: OpenTimestamps Attestations for Events
nip04 No Enable NIP-04: Encrypted Direct Message
nip05 No Enable NIP-05: Mapping Nostr keys to DNS-based internet identifiers
nip06 No Enable NIP-06: Basic key derivation from mnemonic seed phrase
nip07 No Enable NIP-07: window.nostr capability for web browsers (available only for wasm32!)
nip11 No Enable NIP-11: Relay Information Document
nip44 No Enable NIP-44: Encrypted Payloads (Versioned)
nip46 No Enable NIP-46: Nostr Connect
nip47 No Enable NIP-47: Nostr Wallet Connect
nip49 No Enable NIP-49: Private Key Encryption
nip57 No Enable NIP-57: Zaps
nip59 No Enable NIP-59: Gift Wrap

Supported NIPs

Supported NIP
01 - Basic protocol flow description
02 - Follow List
03 - OpenTimestamps Attestations for Events
04 - Encrypted Direct Message
05 - Mapping Nostr keys to DNS-based internet ids
06 - Basic key derivation from mnemonic seed phrase
07 - window.nostr capability for web browsers
09 - Event Deletion
10 - Use of e and p tags in text events
11 - Relay Information Document
13 - Proof of Work
14 - Subject tag in text events
15 - Nostr Marketplace
17 - Private Direct Messages
18 - Reposts
19 - bech32-encoded entities
21 - URI scheme
22 - Comment
23 - Long-form Content
24 - Extra metadata fields and tags
25 - Reactions
26 - Delegated Event Signing
27 - Text Note References
28 - Public Chat
29 - Relay-based Groups
30 - Custom Emoji
31 - Dealing with Unknown Events
32 - Labeling
34 - git stuff
35 - Torrents
36 - Sensitive Content
38 - User Statuses
39 - External Identities in Profiles
40 - Expiration Timestamp
42 - Authentication of clients to relays
44 - Encrypted Payloads (Versioned)
45 - Event Counts
46 - Nostr Connect
47 - Wallet Connect
48 - Proxy Tags
49 - Private Key Encryption
50 - Search Capability
51 - Lists
52 - Calendar Events
53 - Live Activities
54 - Wiki
- 55 - Android Signer Application
56 - Reporting
57 - Lightning Zaps
58 - Badges
59 - Gift Wrap
65 - Relay List Metadata
70 - Protected Events
71 - Video Events
72 - Moderated Communities
73 - External Content IDs
75 - Zap Goals
78 - Arbitrary custom app data
89 - Recommended Application Handlers
90 - Data Vending Machine
92 - Media Attachments
94 - File Metadata
96 - HTTP File Storage Integration
98 - HTTP Auth
99 - Classified Listings

State

This library is in an ALPHA state, things that are implemented generally work but the API will change in breaking ways.

Donations

rust-nostr is free and open-source. This means we do not earn any revenue by selling it. Instead, we rely on your financial support. If you actively use any of the rust-nostr libs/software/services, then please donate.

License

This project is distributed under the MIT software license - see the LICENSE file for details

Dependencies

~6–21MB
~255K SLoC