From bbfeda18fd69b12b04fac988e0ea697fdca21a03 Mon Sep 17 00:00:00 2001 From: Jeff Gardner <202880+erskingardner@users.noreply.github.com> Date: Sun, 29 Dec 2024 11:25:04 +0100 Subject: [PATCH 1/2] Update NostrConnect event handling to try both NIP-04 and NIP-44 decryption --- crates/nostr-connect/src/error.rs | 5 ++++- crates/nostr-connect/src/signer.rs | 21 ++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/crates/nostr-connect/src/error.rs b/crates/nostr-connect/src/error.rs index b655a2019..efdd898f9 100644 --- a/crates/nostr-connect/src/error.rs +++ b/crates/nostr-connect/src/error.rs @@ -7,7 +7,7 @@ use std::convert::Infallible; use nostr::event::builder; -use nostr::nips::{nip04, nip46}; +use nostr::nips::{nip04, nip44, nip46}; use nostr::PublicKey; use thiserror::Error; use tokio::sync::SetError; @@ -21,6 +21,9 @@ pub enum Error { /// NIP04 error #[error(transparent)] NIP04(#[from] nip04::Error), + /// NIP44 error + #[error(transparent)] + NIP44(#[from] nip44::Error), /// NIP46 error #[error(transparent)] NIP46(#[from] nip46::Error), diff --git a/crates/nostr-connect/src/signer.rs b/crates/nostr-connect/src/signer.rs index 1ffdf9e84..c9b03ba25 100644 --- a/crates/nostr-connect/src/signer.rs +++ b/crates/nostr-connect/src/signer.rs @@ -163,11 +163,22 @@ impl NostrConnectRemoteSigner { .handle_notifications(|notification| async { if let RelayPoolNotification::Event { event, .. } = notification { if event.kind == Kind::NostrConnect { - if let Ok(msg) = nip04::decrypt( - self.keys.signer.secret_key(), - &event.pubkey, - event.content, - ) { + let decrypted_msg = if event.content.contains("?iv=") { + nip04::decrypt( + self.keys.signer.secret_key(), + &event.pubkey, + event.content.as_str(), + ) + .map_err(Error::from) + } else { + nip44::decrypt( + self.keys.signer.secret_key(), + &event.pubkey, + event.content.as_str(), + ) + .map_err(Error::from) + }; + if let Ok(msg) = decrypted_msg { tracing::debug!("New Nostr Connect message received: {msg}"); let msg: Message = Message::from_json(msg)?; From db066403c26c57c5ab32466a8bc5043e19c68709 Mon Sep 17 00:00:00 2001 From: Jeff Gardner <202880+erskingardner@users.noreply.github.com> Date: Sun, 29 Dec 2024 11:51:51 +0100 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 383e34bf0..bd0d72c8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ ### Changed +* nostr-connect: add NIP44 decryption support ([erskingardner]) * Bump `async-utility` to 0.3, `async-wsocket` to 0.11 and `atomic-destructor` to 0.3 ([Yuki Kishimoto]) * nostr: remove self-tagging when building events ([Yuki Kishimoto]) * nostr: don't set root tags when the root is null ([Yuki Kishimoto])