Skip to main content

try_decrypt_message

Function try_decrypt_message 

Source
pub async fn try_decrypt_message<W: WalletInterface>(
    wallet: &W,
    raw_body: &str,
    sender_pubkey_hex: &str,
    originator: Option<&str>,
) -> String
Expand description

Try to decrypt a message body, with graceful fallback for plaintext.

Handles three cases (matching TS listMessagesLite lines 1442-1452):

  1. JSON with a "message" wrapper key: unwrap first, then check inner content.
  2. JSON with "encryptedMessage" key: decrypt.
  3. Anything else (no encryptedMessage key, or not JSON): return original body unchanged.

Does NOT panic on parse failure — always returns a String.

NOTE: PARITY — passes originator: None inside when called from list_messages_lite. This matches a latent TS bug where listMessagesLite omits originator.