update dependencies, upgrade nostr and cln dependencies

This commit is contained in:
daywalker90 2026-07-26 13:15:02 +02:00
parent 28d5781efa
commit 5ab6103b9c
No known key found for this signature in database
GPG key ID: 7AB4802ED5A639F3
7 changed files with 287 additions and 412 deletions

592
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -12,19 +12,20 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["fs", "sync", "rt-multi-thread"] }
cln-rpc = "0.6"
cln-rpc = "0.7"
# cln-rpc = { path = "../lightning/cln-rpc/", version = "^0.6" }
cln-plugin = "0.6"
cln-plugin = "0.7"
# cln-plugin = { path = "../lightning/plugins/", version = "^0.6" }
parking_lot = "0.12"
nostr-sdk = { git = "https://github.com/rust-nostr/nostr.git", rev = "6eb03213c7d3d9eaaa9b74c142f2b8eb79445af6" }
nostr = { git = "https://github.com/rust-nostr/nostr.git", rev = "6eb03213c7d3d9eaaa9b74c142f2b8eb79445af6", features = [
"nip47",
"nip04",
"nip44",
] }
# nostr-sdk = { version = "0.44", features = ["nip47", "nip04", "nip44"] }
# # nostr-sdk = { git = "https://github.com/rust-nostr/nostr.git", rev = "ff5be7d1416ea201887a02f648795010a3cbdf49" }
# nostr = { git = "https://github.com/rust-nostr/nostr.git", rev = "ff5be7d1416ea201887a02f648795010a3cbdf49", features = [
# "nip47",
# "nip04",
# "nip44",
# ] }
nostr = { version = "0.45.0-alpha.4", features = ["nip47", "nip04", "nip44"] }
nostr-sdk = { version = "0.45.0-alpha.4" }
futures = "0.3"
@ -44,6 +45,7 @@ tonic-prost = "0.14"
[build-dependencies]
tonic-prost-build = "0.14"
protoc-bin-vendored = "3"
[profile.optimized]

View file

@ -1,4 +1,6 @@
fn main() {
let protoc = protoc_bin_vendored::protoc_bin_path().unwrap();
unsafe { std::env::set_var("PROTOC", protoc) };
tonic_prost_build::configure()
.protoc_arg("--experimental_allow_proto3_optional")
.compile_protos(&["protos/hold.proto"], &["protos"])

View file

@ -165,7 +165,7 @@ async fn shutdown_handler(
_args: serde_json::Value,
) -> Result<(), anyhow::Error> {
let mut locked_handles = plugin.state().handles.lock().await;
for (_x, (client, _client_pubkey)) in locked_handles.drain() {
for (_x, (client, _client_pubkey, _wallet_keys)) in locked_handles.drain() {
client.shutdown().await;
}
std::process::exit(0)

View file

@ -14,11 +14,12 @@ use nostr::{
SecretKey,
Tag,
Timestamp,
event::FinalizeEventAsync,
nips::{nip04, nip44, nip47},
signer::SignerError,
};
use nostr_sdk::{
client::{self, Client, ClientNotification, Error},
client::{self, Client, ClientNotification},
error::Error,
relay::RelayStatus,
};
use tokio::{sync::oneshot, time};
@ -49,13 +50,10 @@ pub async fn run_nwc(
) -> Result<(), Error> {
let (method_capabilities, _) = build_capabilities(is_read_only_nwc(&nwc_store), &plugin);
let wallet_keys = Keys::new(
SecretKey::from_hex(&nwc_store.walletkey)
.map_err(|e| Error::Signer(SignerError::backend(e)))?,
);
let client_pubkey = Keys::new(nwc_store.uri.secret.clone()).public_key();
let wallet_keys = Keys::new(SecretKey::from_hex(&nwc_store.walletkey)?);
let client_keys = Keys::new(nwc_store.uri.secret.clone());
let nostr_client = Client::builder().signer(wallet_keys.clone()).build();
let nostr_client = Client::new();
log::debug!("relay_count:{}", nwc_store.uri.relays.len());
@ -71,6 +69,8 @@ pub async fn run_nwc(
let nostr_client_clone = nostr_client.clone();
let plugin_clone = plugin.clone();
let label_clone = label.clone();
let client_keys_clone = client_keys.clone();
let wallet_keys_clone = wallet_keys.clone();
tokio::spawn(async move {
loop {
nostr_client_clone
@ -100,7 +100,7 @@ pub async fn run_nwc(
plugin_clone.clone(),
nostr_client_clone.clone(),
method_capabilities.clone(),
wallet_keys.clone(),
wallet_keys_clone.clone(),
)
.await
{
@ -112,7 +112,7 @@ pub async fn run_nwc(
let filter = Filter::new()
.kind(Kind::WalletConnectRequest)
.author(client_pubkey)
.author(client_keys_clone.public_key())
.since(Timestamp::now() - STARTUP_DELAY - 1);
let mut notifications = nostr_client_clone.notifications();
@ -140,8 +140,8 @@ pub async fn run_nwc(
&nostr_client_clone,
&plugin_clone,
&label_clone,
&wallet_keys,
client_pubkey,
&wallet_keys_clone,
client_keys_clone.public_key(),
)
.await
{
@ -156,7 +156,7 @@ pub async fn run_nwc(
let mut locked_handles = plugin.state().handles.lock().await;
locked_handles.insert(
label.clone(),
(nostr_client, Keys::new(nwc_store.uri.secret).public_key()),
(nostr_client, client_keys.public_key(), wallet_keys),
);
Ok(())
}
@ -180,7 +180,7 @@ pub async fn send_nwc_info_event(
.tag(Tag::parse(vec!["notifications", &notification_capabilities]).unwrap());
}
let info_event = match info_event_builder.sign_with_keys(&wallet_keys) {
let info_event = match info_event_builder.finalize_async(&wallet_keys).await {
Ok(o) => o,
Err(e) => {
return Err(anyhow!("Could not sign info_event! {e}"));
@ -208,7 +208,7 @@ pub async fn send_nwc_info_event(
pub async fn stop_nwc(plugin: Plugin<PluginState>, label: &String) {
let mut locked_handles = plugin.state().handles.lock().await;
if let Some((client, _client_pubkey)) = locked_handles.remove(label) {
if let Some((client, _client_pubkey, _wallet_secret)) = locked_handles.remove(label) {
client.shutdown().await;
}
@ -299,7 +299,7 @@ async fn nwc_request_handler(
};
let response_event =
match build_response_event(event.id, content, wallet_keys, client_pubkey, id) {
match build_response_event(event.id, content, wallet_keys, client_pubkey, id).await {
Ok(o) => o,
Err(e) => {
log::warn!("Error signing reponse event! {e}");
@ -427,7 +427,7 @@ fn encrypt_response_content(
}
}
fn build_response_event(
async fn build_response_event(
event_id: EventId,
content: String,
wallet_keys: &Keys,
@ -440,7 +440,7 @@ fn build_response_event(
if let Some(i) = id {
response_builder = response_builder.tag(Tag::identifier(i));
}
match response_builder.sign_with_keys(wallet_keys) {
match response_builder.finalize_async(wallet_keys).await {
Ok(o) => Ok(o),
Err(e) => Err(e.into()),
}

View file

@ -16,7 +16,15 @@ use cln_rpc::{
},
primitives::Sha256,
};
use nostr::{EventBuilder, Kind, Tag, Timestamp, key::PublicKey, nips::nip47};
use nostr::{
EventBuilder,
Kind,
Tag,
Timestamp,
event::FinalizeEventAsync,
key::{Keys, PublicKey, SecretKey},
nips::{nip04, nip44, nip47},
};
use nostr_sdk::client::Client;
use crate::{
@ -75,8 +83,8 @@ pub async fn payment_received_handler(
let clients = plugin.state().handles.lock().await;
for (client, client_pubkey) in clients.values() {
send_notification(&notification, client, client_pubkey).await?;
for (client, client_pubkey, wallet_secret) in clients.values() {
send_notification(&notification, client, client_pubkey.clone(), wallet_secret).await?;
}
Ok(())
@ -212,8 +220,8 @@ pub async fn payment_sent_handler(
let clients = plugin.state().handles.lock().await;
for (client, client_pubkey) in clients.values() {
send_notification(&notification, client, client_pubkey).await?;
for (client, client_pubkey, wallet_secret) in clients.values() {
send_notification(&notification, client, client_pubkey.clone(), wallet_secret).await?;
}
Ok(())
@ -335,14 +343,15 @@ async fn make_payment_sent_from_listpays(
async fn send_notification(
notification: &String,
client: &Client,
client_pubkey: &PublicKey,
client_pubkey: PublicKey,
wallet_secret: &Keys,
) -> Result<(), anyhow::Error> {
let signer = client.signer().unwrap().clone();
log::debug!("NOTIFICATION: {notification}");
let content_encrypted_nip04 = signer.nip04_encrypt(client_pubkey, notification).await?;
let content_encrypted_nip04 =
nip04::encrypt(wallet_secret.secret_key(), &client_pubkey, notification)?;
let event_nip04 = EventBuilder::new(Kind::from_u16(23196), content_encrypted_nip04)
.tag(Tag::public_key(*client_pubkey))
.sign_async(&signer)
.tag(Tag::public_key(client_pubkey))
.finalize_async(wallet_secret)
.await?;
let nip04_result = client.send_event(&event_nip04).await?;
if nip04_result.success.is_empty() {
@ -357,10 +366,15 @@ async fn send_notification(
}
log::debug!("NIP04 NOTIFICATION SENT: {event_nip04:?}");
let content_encrypted_nip44 = signer.nip44_encrypt(client_pubkey, notification).await?;
let content_encrypted_nip44 = nip44::encrypt(
wallet_secret.secret_key(),
&client_pubkey,
notification,
nip44::Version::V2,
)?;
let event_nip44 = EventBuilder::new(Kind::from_u16(23197), content_encrypted_nip44)
.tag(Tag::public_key(*client_pubkey))
.sign_async(&signer)
.tag(Tag::public_key(client_pubkey))
.finalize_async(wallet_secret)
.await?;
let nip44_result = client.send_event(&event_nip44).await?;
if nip44_result.success.is_empty() {
@ -500,8 +514,8 @@ pub async fn holdinvoice_accepted_handler(
};
let notification = serde_json::to_string(&content).unwrap();
for (client, client_pubkey) in clients.values() {
send_notification(&notification, client, client_pubkey).await?;
for (client, client_pubkey, wallet_secret) in clients.values() {
send_notification(&notification, client, client_pubkey.clone(), wallet_secret).await?;
}
Ok(())
}

View file

@ -15,7 +15,8 @@ pub const NOT_INV_ERR: &str = "Not an invoice or invalid invoice";
#[derive(Clone)]
pub struct PluginState {
pub config: Arc<Mutex<Config>>,
pub handles: Arc<tokio::sync::Mutex<HashMap<String, (client::Client, nostr::PublicKey)>>>,
pub handles:
Arc<tokio::sync::Mutex<HashMap<String, (client::Client, nostr::PublicKey, nostr::Keys)>>>,
pub rpc_lock: Arc<tokio::sync::Mutex<ClnRpc>>,
pub budget_jobs: Arc<Mutex<HashMap<String, oneshot::Sender<()>>>>,
pub hold_client: Arc<Mutex<Option<HoldClient<Channel>>>>,