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]) 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)?;