Skip to content

Commit

Permalink
Feat/nwc support (#89)
Browse files Browse the repository at this point in the history
* secrets: add way to manage nwc store given account

this commit aims to store in kechain the nostr wallet connect secret for each account

* secrets: use option return instead of error on nwc

* secrets: rename nostr wallet connect uri

* commands: add management nwc secret

adds has nwc secret for active account, set secret and remove secret

* front+settings: add lightning configuration page

* chore: add vitest

* store: add nostr wallet connect validation

* store: nwc could have multiple relays

also they could have different protocols

* refactor(nwc-uri-validation): divide long method in smaller ones

* chore: add nwc dependency

* nwc: check connection before storing nwc

* feat(commands/groups): add bolt11 tag on events with an invoice in their content

* chore: add lightning invoices

* payments: add pay invoice command

* payments: fixes expired at invoices

* chat: add a little demo on chat paying invoices

* payment: glow pay button

* chat: use bolt11 tag for payments

* chat: only enable payment if nwc is set up

* Changelog: update with nwc-support

* style(accounts payments): fix minor lint issues

---------

Co-authored-by: Maurice Poirrier Chuden <[email protected]>
Co-authored-by: josefinalliende <[email protected]>
  • Loading branch information
3 people authored Feb 21, 2025
1 parent 0b7b96a commit 468df27
Show file tree
Hide file tree
Showing 18 changed files with 1,038 additions and 19 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Added a copy npub button in settings page([josefinalliende])

### Added

- Search for contacts by npub or hex pubkey ([erskingardner])
- Copy npub button in settings page([josefinalliende])
- Basic NWC support for paying invoices in messages ([a-mpch], [F3r10], [jgmontoya], [josefinalliende])

### Changed


- Better handling of long messages in chat ([josefinalliende])

## [v0.1.0-alpha.3] - 2025-02-20

Expand Down Expand Up @@ -88,6 +90,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[hodlbod]: <https://github.com/staab> (nostr:npub1jlrs53pkdfjnts29kveljul2sm0actt6n8dxrrzqcersttvcuv3qdjynqn)
[dmcarrington]: <https://github.com/dmcarrington>
[josefinalliende]: <https://github.com/josefinalliende>
[jgmontoya]: <https://github.com/jgmontoya> (nostr:npub1jgm0ntzjr03wuzj5788llhed7l6fst05um4ej2r86ueaa08etv6sgd669p)
[a-mpch]: <https://github.com/a-mpch> (nostr:npub1mpchxagw3kaglylnyajzjmghdj63vly9q5eu7d62fl72f2gz8xfqk6nwkd)
[F3r10]: <https://github.com/F3r10>



Expand Down
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"tailwindcss": "^3.4.17",
"tslib": "^2.8.1",
"typescript": "^5.7.3",
"vite": "^6.0.11"
"vite": "^6.0.11",
"vitest": "^3.0.6"
}
}
45 changes: 45 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ base64 = "0.22"
nostr-openmls = { version = "0.1.0", git="https://github.com/erskingardner/nostr-openmls", branch="master" }
tauri-plugin-clipboard-manager = "2.2.1"
tauri-plugin-notification = "2.2.1"
nwc = { version = "0.38" }
lightning-invoice = "0.33.1"

[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
nostr-sdk = { version = "0.38", features = [
"ndb", # Use NDB for macOS and iOS
"nip04",
"nip44",
"nip47",
"nip59",
] }

Expand All @@ -55,6 +58,7 @@ nostr-sdk = { version = "0.38", features = [
"lmdb", # Use LMDB for all other platforms
"nip04",
"nip44",
"nip47",
"nip59",
] }

Expand Down
22 changes: 22 additions & 0 deletions src-tauri/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,4 +684,26 @@ impl Account {
txn.commit().await?;
Ok(())
}

/// Stores a Nostr Wallet Connect URI for this account
pub fn store_nostr_wallet_connect_uri(&self, nostr_wallet_connect_uri: &str, wn: tauri::State<'_, Whitenoise>) -> Result<()> {
secrets_store::store_nostr_wallet_connect_uri(&self.pubkey.to_hex(), nostr_wallet_connect_uri, &wn.data_dir)
.map_err(AccountError::SecretsStoreError)
}

/// Retrieves the Nostr Wallet Connect URI for this account
///
/// # Returns
/// * `Result<Option<String>>` - Some(uri) if a URI is stored, None if no URI is stored,
/// or an error if the operation fails
pub fn get_nostr_wallet_connect_uri(&self, wn: tauri::State<'_, Whitenoise>) -> Result<Option<String>> {
secrets_store::get_nostr_wallet_connect_uri(&self.pubkey.to_hex(), &wn.data_dir)
.map_err(AccountError::SecretsStoreError)
}

/// Removes the Nostr Wallet Connect URI for this account
pub fn remove_nostr_wallet_connect_uri(&self, wn: tauri::State<'_, Whitenoise>) -> Result<()> {
secrets_store::remove_nostr_wallet_connect_uri(&self.pubkey.to_hex(), &wn.data_dir)
.map_err(AccountError::SecretsStoreError)
}
}
79 changes: 79 additions & 0 deletions src-tauri/src/commands/accounts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::accounts::Account;
use crate::whitenoise::Whitenoise;
use nostr_sdk::prelude::*;
use nwc::prelude::*;

/// Lists all accounts.
///
Expand Down Expand Up @@ -183,3 +184,81 @@ pub async fn update_account_onboarding(
.map_err(|e| format!("Error saving account: {}", e))?;
Ok(account)
}

/// Checks if a Nostr Wallet Connect URI is configured for the active account.
///
/// # Arguments
///
/// * `wn` - A reference to the Whitenoise state
///
/// # Returns
///
/// * `Ok(bool)` - true if a NWC URI is configured, false otherwise
/// * `Err(String)` - An error message if there was an issue checking the NWC URI
#[tauri::command]
pub async fn has_nostr_wallet_connect_uri(
wn: tauri::State<'_, Whitenoise>,
) -> Result<bool, String> {
let active_account = Account::get_active(wn.clone())
.await
.map_err(|e| format!("Error getting active account: {}", e))?;

active_account
.get_nostr_wallet_connect_uri(wn.clone())
.map(|opt| opt.is_some())
.map_err(|e| format!("Error checking NWC URI: {}", e))
}

/// Sets the Nostr Wallet Connect URI for the active account.
///
/// # Arguments
///
/// * `nostr_wallet_connect_uri` - The NWC URI to store
/// * `wn` - A reference to the Whitenoise state
///
/// # Returns
///
/// * `Ok(())` - If the URI was stored successfully
/// * `Err(String)` - An error message if there was an issue storing the URI
#[tauri::command]
pub async fn set_nostr_wallet_connect_uri(
nostr_wallet_connect_uri: String,
wn: tauri::State<'_, Whitenoise>,
) -> Result<(), String> {
let active_account = Account::get_active(wn.clone())
.await
.map_err(|e| format!("Error getting active account: {}", e))?;
let uri: NostrWalletConnectURI =
NostrWalletConnectURI::parse(&nostr_wallet_connect_uri).expect("Failed to parse NWC URI");
let nwc: NWC = NWC::new(uri);
nwc.get_info()
.await
.map_err(|e| format!("Error getting NWC info: {}", e))?;

active_account
.store_nostr_wallet_connect_uri(&nostr_wallet_connect_uri, wn.clone())
.map_err(|e| format!("Error storing NWC URI: {}", e))
}

/// Removes the Nostr Wallet Connect URI for the active account.
///
/// # Arguments
///
/// * `wn` - A reference to the Whitenoise state
///
/// # Returns
///
/// * `Ok(())` - If the URI was removed successfully
/// * `Err(String)` - An error message if there was an issue removing the URI
#[tauri::command]
pub async fn remove_nostr_wallet_connect_uri(
wn: tauri::State<'_, Whitenoise>,
) -> Result<(), String> {
let active_account = Account::get_active(wn.clone())
.await
.map_err(|e| format!("Error getting active account: {}", e))?;

active_account
.remove_nostr_wallet_connect_uri(wn.clone())
.map_err(|e| format!("Error removing NWC URI: {}", e))
}
Loading

0 comments on commit 468df27

Please sign in to comment.