Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NIP-44 decryption support to NostrConnect #697

Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
5 changes: 4 additions & 1 deletion crates/nostr-connect/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand Down
21 changes: 16 additions & 5 deletions crates/nostr-connect/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
Loading