54 releases (34 breaking)
0.36.0 | Nov 5, 2024 |
---|---|
0.34.1 | Aug 28, 2024 |
0.33.0 | Jul 16, 2024 |
0.29.1 | Mar 31, 2024 |
0.5.1 | Nov 14, 2022 |
#78 in Web programming
8,784 downloads per month
Used in 59 crates
(38 directly)
750KB
18K
SLoC
Nostr
Description
Rust implementation of Nostr protocol.
You may be interested in:
nostr-sdk
if you want to write a typical Nostr client or botnostr-relay-pool
: Nostr Relay Poolnostr-connect
: Nostr Connect (NIP46)nwc
: Nostr Wallet Connect (NWC) client
Getting started
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 rust-nostr", []).to_event(&my_keys)?;
// New POW text note
let event: Event = EventBuilder::text_note("My first POW text note from rust-nostr", []).pow(20).to_event(&my_keys)?;
// 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 |
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
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–23MB
~284K SLoC