diff --git a/crates/nostr/src/nips/nip04.rs b/crates/nostr/src/nips/nip04.rs index 58763e518..1d058e333 100644 --- a/crates/nostr/src/nips/nip04.rs +++ b/crates/nostr/src/nips/nip04.rs @@ -106,12 +106,12 @@ where )) } -/// Decrypt -pub fn decrypt( +/// Decrypts content to bytes +pub fn decrypt_to_bytes( sk: &SecretKey, pk: &XOnlyPublicKey, encrypted_content: S, -) -> Result +) -> Result, Error> where S: Into, { @@ -134,6 +134,19 @@ where .decrypt_padded_vec_mut::(&encrypted_content) .map_err(|_| Error::WrongBlockMode)?; + Ok(result) +} + +/// Decrypts content to a UTF-8 string +pub fn decrypt( + sk: &SecretKey, + pk: &XOnlyPublicKey, + encrypted_content: S, +) -> Result +where + S: Into, +{ + let result = decrypt_to_bytes(sk, pk, encrypted_content)?; String::from_utf8(result).map_err(|_| Error::Utf8Encode) }