Expand description
§NpubCash SDK
Rust client SDK for the NpubCash v2 API.
§Features
- HTTP client for fetching quotes with auto-pagination
- NIP-98 and JWT authentication
- User settings management
§Quick Start
use std::sync::Arc;
use cdk_npubcash::{JwtAuthProvider, NpubCashClient};
use nostr_sdk::Keys;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create authentication provider with Nostr keys
let base_url = "https://npubx.cash".to_string();
let keys = Keys::generate();
let auth_provider = Arc::new(JwtAuthProvider::new(base_url.clone(), keys));
// Create the NpubCash client
let client = NpubCashClient::new(base_url, auth_provider);
// Fetch all quotes
let quotes = client.get_quotes(None).await?;
println!("Found {} quotes", quotes.len());
// Fetch quotes since a specific timestamp
let recent_quotes = client.get_quotes(Some(1234567890)).await?;
println!("Found {} recent quotes", recent_quotes.len());
// Update mint URL setting
client.set_mint_url("https://example-mint.tld").await?;
Ok(())
}§Authentication
The SDK uses NIP-98 HTTP authentication for initial requests and JWT tokens
for subsequent requests. The JwtAuthProvider handles this automatically,
including token caching and refresh.
§Fetching Quotes
// Fetch all quotes
let all_quotes = client.get_quotes(None).await?;
// Fetch quotes since a specific timestamp
let recent_quotes = client.get_quotes(Some(1234567890)).await?;§Managing Settings
// Set mint URL
let response = client.set_mint_url("https://my-mint.com").await?;
println!("Mint URL: {:?}", response.data.user.mint_url);
println!("Lock quote: {}", response.data.user.lock_quote);Note: Quotes are always locked by default on the NPubCash server for security.
Re-exports§
pub use auth::JwtAuthProvider;pub use client::NpubCashClient;pub use error::Error;pub use error::Result;pub use types::Metadata;pub use types::Nip98Data;pub use types::Nip98Response;pub use types::Quote;pub use types::QuotesData;pub use types::QuotesResponse;pub use types::UserData;pub use types::UserResponse;