diff --git a/crates/cdk-ffi/src/wallet_repository.rs b/crates/cdk-ffi/src/wallet_repository.rs index 447f32a3c8..970ce5ebe0 100644 --- a/crates/cdk-ffi/src/wallet_repository.rs +++ b/crates/cdk-ffi/src/wallet_repository.rs @@ -183,6 +183,46 @@ impl WalletRepository { } } + /// Get the NUT-27 mint backup public key as hex. + pub fn mint_backup_public_key(&self) -> Result { + let keys = self.inner.backup_keys()?; + Ok(keys.public_key().to_hex()) + } + + /// Backup the current mint list to Nostr relays using NUT-27. + pub async fn backup_mints( + &self, + relays: Vec, + options: BackupOptions, + ) -> Result { + let result = self.inner.backup_mints(relays, options.into()).await?; + Ok(result.into()) + } + + /// Restore the mint list from Nostr relays using NUT-27. + pub async fn restore_mints( + &self, + relays: Vec, + add_mints: bool, + options: RestoreOptions, + ) -> Result { + let result = self + .inner + .restore_mints(relays, add_mints, options.into()) + .await?; + Ok(result.into()) + } + + /// Fetch the NUT-27 mint backup without adding mints to the repository. + pub async fn fetch_mint_backup( + &self, + relays: Vec, + options: RestoreOptions, + ) -> Result { + let backup = self.inner.fetch_backup(relays, options.into()).await?; + Ok(backup.into()) + } + /// Get wallet balances for all mints pub async fn get_balances(&self) -> Result, FfiError> { let balances = self.inner.get_balances().await?; diff --git a/crates/cdk/examples/nostr_backup.rs b/crates/cdk/examples/nostr_backup.rs index 689a220db6..fa544bc12c 100644 --- a/crates/cdk/examples/nostr_backup.rs +++ b/crates/cdk/examples/nostr_backup.rs @@ -1,4 +1,4 @@ -//! # Nostr Mint Backup Example (NUT-XX) +//! # Nostr Mint Backup Example (NUT-27) //! //! This example demonstrates how to backup and restore your mint list //! to/from Nostr relays using the WalletRepository. @@ -35,7 +35,7 @@ async fn main() -> anyhow::Result<()> { .with_max_level(tracing::Level::ERROR) .init(); - println!("NUT-XX Nostr Mint Backup Example"); + println!("NUT-27 Nostr Mint Backup Example"); println!("=================================\n"); // Generate a random seed for the wallet diff --git a/crates/cdk/src/wallet/nostr_backup.rs b/crates/cdk/src/wallet/nostr_backup.rs index 404453c437..0b4b5422f9 100644 --- a/crates/cdk/src/wallet/nostr_backup.rs +++ b/crates/cdk/src/wallet/nostr_backup.rs @@ -3,6 +3,7 @@ //! This module provides functionality to backup and restore the mint list //! to/from Nostr relays using NUT-27 specification. +use std::collections::BTreeSet; use std::time::Duration; use nostr_sdk::prelude::*; @@ -126,7 +127,12 @@ impl WalletRepository { let keys = self.backup_keys()?; let wallets = self.get_wallets().await; - let mint_urls: Vec = wallets.iter().map(|w| w.mint_url.clone()).collect(); + let mint_urls: Vec = wallets + .iter() + .map(|w| w.mint_url.clone()) + .collect::>() + .into_iter() + .collect(); let backup = MintBackup::new(mint_urls.clone());