-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
connect: support both NIP04 and NIP44 for message decryption
This updates the NIP46 message handling to use either NIP04 or NIP44 decryption by checking for `?iv=` in the event content. Closes #697 Co-authored-by: Yuki Kishimoto <yukikishimoto@protonmail.com> Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
- Loading branch information
1 parent
c665521
commit 6ae5c67
Showing
6 changed files
with
37 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ pub mod client; | |
pub mod error; | ||
pub mod prelude; | ||
pub mod signer; | ||
mod util; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) 2022-2023 Yuki Kishimoto | ||
// Copyright (c) 2023-2024 Rust Nostr Developers | ||
// Distributed under the MIT software license | ||
|
||
use nostr::nips::{nip04, nip44}; | ||
use nostr::{Event, SecretKey}; | ||
|
||
use crate::error::Error; | ||
|
||
/// Decrypt a NIP46 message. Support both NIP04 and NIP44. | ||
pub fn decrypt(secret_key: &SecretKey, event: &Event) -> Result<String, Error> { | ||
if event.content.contains("?iv=") { | ||
Ok(nip04::decrypt( | ||
secret_key, | ||
&event.pubkey, | ||
event.content.as_str(), | ||
)?) | ||
} else { | ||
Ok(nip44::decrypt( | ||
secret_key, | ||
&event.pubkey, | ||
event.content.as_str(), | ||
)?) | ||
} | ||
} |