Structured files/directories and nip01, nip02, nip17 implementation
This commit is contained in:
41
src/lib.rs
Normal file
41
src/lib.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
pub mod nips;
|
||||
pub mod functions; // Das neue Modul registrieren
|
||||
|
||||
use anyhow::Result;
|
||||
use nostr_sdk::prelude::*;
|
||||
|
||||
// Wir importieren die Funktionen, um Tipparbeit zu sparen
|
||||
use crate::functions::{new, messages, relays, get_contacts, create_contact};
|
||||
|
||||
pub struct EasyNostr {
|
||||
client: Client,
|
||||
}
|
||||
|
||||
impl EasyNostr {
|
||||
/// Erstellt eine neue Instanz
|
||||
pub async fn new(private_key: &str) -> Result<Self> {
|
||||
// Aufruf der Logik in functions/new.rs
|
||||
let client = new::new_client(private_key).await?;
|
||||
Ok(Self { client })
|
||||
}
|
||||
|
||||
/// Sendet eine verschlüsselte DM (NIP-17 Wrapper)
|
||||
pub async fn send_private_message(&self, receiver_pubkey: &str, message: &str) -> Result<EventId> {
|
||||
messages::send_private_message(&self.client, receiver_pubkey, message).await
|
||||
}
|
||||
|
||||
/// Fügt Relays hinzu und verbindet
|
||||
pub async fn add_relays(&self, urls: Vec<&str>) -> Result<()> {
|
||||
relays::add_relays(&self.client, urls).await
|
||||
}
|
||||
|
||||
/// Lädt die Kontaktliste (NIP-02)
|
||||
pub async fn get_contacts(&self) -> Result<Vec<Contact>> {
|
||||
get_contacts::get_contacts(&self.client).await
|
||||
}
|
||||
|
||||
/// Erstellt oder aktualisiert einen Kontakt
|
||||
pub async fn create_contact(&self, npub: &str, nickname: Option<String>) -> Result<EventId> {
|
||||
create_contact::create_contact(&self.client, npub, nickname).await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user