nostr_rust

My fork of nostr_rust
git clone git://jb55.com/nostr_rust
Log | Files | Refs | README

README.md (5238B)


      1 # nostr_rust
      2 
      3 [![crates.io](https://img.shields.io/crates/v/nostr_rust.svg)](https://crates.io/crates/nostr_rust)
      4 [![Documentation](https://docs.rs/nostr_rust/badge.svg)](https://docs.rs/nostr_rust)
      5 [![MIT/Apache-2 licensed](https://img.shields.io/crates/l/nostr_rust.svg)](./LICENSE.txt)
      6 [![CI](https://github.com/0xtlt/nostr_rust/actions/workflows/ci.yml/badge.svg)](https://github.com/0xtlt/nostr_rust/actions/workflows/ci.yml)
      7 [![Issues](https://img.shields.io/github/issues/0xtlt/nostr_rust)](https://img.shields.io/github/issues/0xtlt/nostr_rust)
      8 
      9 An ergonomic, Nostr API Client for Rust.
     10 
     11 - [Changelog](CHANGELOG.md)
     12 
     13 ## Example
     14 
     15 This example uses [Tungstenite](https://crates.io/crates/tungstenite) for event handling, so your `Cargo.toml` could look like this:
     16 
     17 ```toml
     18 [dependencies]
     19 nostr_rust = "0.3"
     20 tungstenite = "0.17"
     21 ```
     22 
     23 And then the code:
     24 
     25 ```rust,norun
     26 use std::{
     27     str::FromStr,
     28     sync::{Arc, Mutex},
     29     thread,
     30 };
     31 use tungstenite::Message;
     32 
     33 use nostr_rust::{nostr_client::Client, req::ReqFilter, Identity};
     34 
     35 fn handle_message(relay_url: &String, message: &Message) -> Result<(), String> {
     36     println!("Received message from {}: {:?}", relay_url, message);
     37 
     38     Ok(())
     39 }
     40 
     41 fn main() {
     42     let my_identity =
     43         Identity::from_str("your private key as hex string")
     44             .unwrap();
     45 
     46     let nostr_client = Arc::new(Mutex::new(
     47         Client::new(vec!["wss://relay.nostr.info"]).unwrap(),
     48     ));
     49 
     50     // Run a new thread to handle messages
     51     let nostr_clone = nostr_client.clone();
     52     let handle_thread = thread::spawn(move || {
     53         println!("Listening...");
     54         let events = nostr_clone.lock().unwrap().next_data().unwrap();
     55 
     56         for (relay_url, message) in events.iter() {
     57             handle_message(relay_url, message).unwrap();
     58         }
     59     });
     60 
     61     // Change metadata
     62     nostr_client
     63         .lock()
     64         .unwrap()
     65         .set_metadata(
     66             &my_identity,
     67             Some("Rust Nostr Client test account"),
     68             Some("Hello Nostr! #5"),
     69             None,
     70         )
     71         .unwrap();
     72 
     73     // Subscribe to my last text note
     74     let subscription_id = nostr_client
     75         .lock()
     76         .unwrap()
     77         .subscribe(
     78             vec![ReqFilter {
     79                 ids: None,
     80                 authors: Some(vec![
     81                     "884704bd421721e292edbff42eb77547fe115c6ff9825b08fc366be4cd69e9f6".to_string(),
     82                 ]),
     83                 kinds: None,
     84                 e: None,
     85                 p: None,
     86                 since: None,
     87                 until: None,
     88                 limit: Some(1),
     89             }],
     90         )
     91         .unwrap();
     92 
     93     // Unsubscribe
     94     nostr_client
     95         .lock()
     96         .unwrap()
     97         .unsubscribe(&subscription_id)
     98         .unwrap();
     99 
    100     // Publish a text note
    101     nostr_client
    102         .lock()
    103         .unwrap()
    104         .publish_text_note(&my_identity, "Hello Nostr! :)", &[])
    105         .unwrap();
    106 
    107     // Wait for the thread to finish
    108     handle_thread.join().unwrap();
    109 }
    110 ```
    111 
    112 ## NIPs Supported
    113 
    114 | NIP | Supported | Client Version | Description                                                  |
    115 | --- | --------- | -------------- | ------------------------------------------------------------ |
    116 | 01  | ✅        | 0.1.0          | Basic protocol flow description                              |
    117 | 02  | ✅        | 0.3.0          | Contact List and Petnames                                    |
    118 | 03  | ❌        | Not supported  | OpenTimestamps Attestations for Events                       |
    119 | 04  | ❌        | Not supported  | Encrypted Direct Message                                     |
    120 | 05  | ❌        | Not supported  | Mapping Nostr keys to DNS-based internet identifiers         |
    121 | 06  | ❌        | Not supported  | Basic key derivation from mnemonic seed phrase               |
    122 | 07  | ❌        | Not supported  | window.nostr capability for web browsers                     |
    123 | 08  | ❌        | Not supported  | Handling Mentions                                            |
    124 | 09  | ❌        | Not supported  | Event Deletion                                               |
    125 | 10  | ❌        | Not supported  | Conventions for clients' use of e and p tags in text events. |
    126 | 11  | ❌        | Not supported  | Relay Information Document                                   |
    127 | 12  | ❌        | Not supported  | Generic Tag Queries                                          |
    128 | 13  | ❌        | Not supported  | Proof of Work                                                |
    129 | 14  | ❌        | Not supported  | Subject tag in text events.                                  |
    130 | 15  | ❌        | Not supported  | End of Stored Events Notice                                  |
    131 | 16  | ❌        | Not supported  | Event Treatment                                              |
    132 | 22  | ❌        | Not supported  | Event created_at Limits                                      |
    133 | 25  | ❌        | Not supported  | Reactions                                                    |
    134 | 28  | ❌        | Not supported  | Public Chat                                                  |
    135 
    136 ## License
    137 
    138 Licensed under MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)