45 releases (28 breaking)

0.30.0 Apr 12, 2024
0.29.1 Mar 31, 2024
0.28.1 Feb 19, 2024
0.26.0 Dec 21, 2023
0.5.1 Nov 14, 2022

#51 in Web programming

Download history 607/week @ 2024-01-25 545/week @ 2024-02-01 596/week @ 2024-02-08 1486/week @ 2024-02-15 800/week @ 2024-02-22 576/week @ 2024-02-29 650/week @ 2024-03-07 836/week @ 2024-03-14 871/week @ 2024-03-21 1014/week @ 2024-03-28 939/week @ 2024-04-04 1174/week @ 2024-04-11 935/week @ 2024-04-18 744/week @ 2024-04-25 902/week @ 2024-05-02 904/week @ 2024-05-09

3,634 downloads per month
Used in 43 crates (29 directly)

MIT license

650KB
16K SLoC

Nostr

crates.io crates.io - Downloads Documentation Rustc Version 1.64.0+ CI MIT

Description

Rust implementation of Nostr protocol.

You may be interested in:

Getting started

[dependencies]
nostr = "0.30"
use nostr::prelude::*;

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

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

    // Show bech32 public key
    let bech32_pubkey: String = my_keys.public_key().to_bech32()?;
    println!("Bech32 PubKey: {}", bech32_pubkey);

    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("yuki@getalby.com")
        .custom_field("custom_field", "my value");

    let event: Event = EventBuilder::metadata(&metadata).to_event(&my_keys)?;

    // New text note
    let event: Event = EventBuilder::text_note("Hello from Nostr SDK", []).to_event(&my_keys)?;

    // New POW text note
    let event: Event = EventBuilder::text_note("My first POW text note from Nostr SDK", []).to_pow_event(&my_keys, 20)?;

    // Convert client nessage 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
blocking No Needed to use NIP-05 and NIP-11 features in not async/await context
all-nips Yes Enable all NIPs
nip03 No Enable NIP-03: OpenTimestamps Attestations for Events
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
nip07 Yes Enable NIP-07: window.nostr capability for web browsers (available only for wasm32!)
nip11 Yes Enable NIP-11: Relay Information Document
nip44 Yes Enable NIP-44: Encrypted Payloads (Versioned)
nip46 Yes Enable NIP-46: Nostr Connect
nip47 Yes Enable NIP-47: Nostr Wallet Connect
nip49 Yes Enable NIP-49: Private Key Encryption
nip57 Yes Enable NIP-57: Zaps
nip59 Yes Enable NIP-59: Gift Wrap

Supported NIPs

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 ids
06 - Basic key derivation from mnemonic seed phrase
07 - window.nostr capability for web browsers
09 - Event Deletion
10 - On "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 - Nostr Marketplace
16 - Event Treatment
18 - Reposts
19 - bech32-encoded entities
20 - Command Results
21 - URI scheme
23 - Long-form Content
25 - Reactions
26 - Delegated Event Signing
27 - Text Note References
28 - Public Chat
30 - Custom Emoji
31 - Dealing with Unknown Events
32 - Labeling
36 - Sensitive Content
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 - Keywords filter
51 - Lists
53 - Live Activities
56 - Reporting
57 - Lightning Zaps
58 - Badges
59 - Gift Wrap
65 - Relay List Metadata
78 - Arbitrary custom app data
89 - Recommended Application Handlers
90 - Data Vending Machine
94 - File Metadata
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

~8–24MB
~281K SLoC