Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions crates/cdk-ffi/src/wallet_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,46 @@ impl WalletRepository {
}
}

/// Get the NUT-27 mint backup public key as hex.
pub fn mint_backup_public_key(&self) -> Result<String, FfiError> {
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<String>,
options: BackupOptions,
) -> Result<BackupResult, FfiError> {
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<String>,
add_mints: bool,
options: RestoreOptions,
) -> Result<RestoreResult, FfiError> {
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<String>,
options: RestoreOptions,
) -> Result<MintBackup, FfiError> {
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<HashMap<WalletKey, Amount>, FfiError> {
let balances = self.inner.get_balances().await?;
Expand Down
4 changes: 2 additions & 2 deletions crates/cdk/examples/nostr_backup.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion crates/cdk/src/wallet/nostr_backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -126,7 +127,12 @@ impl WalletRepository {
let keys = self.backup_keys()?;

let wallets = self.get_wallets().await;
let mint_urls: Vec<MintUrl> = wallets.iter().map(|w| w.mint_url.clone()).collect();
let mint_urls: Vec<MintUrl> = wallets
.iter()
.map(|w| w.mint_url.clone())
.collect::<BTreeSet<_>>()
.into_iter()
.collect();

let backup = MintBackup::new(mint_urls.clone());

Expand Down
Loading