Marmot-TS
    Preparing search index...

    Function decryptMediaFile

    • Decrypts a media file received in a Marmot group message (MIP-04 v2).

      Verifies the ChaCha20-Poly1305 authentication tag and then confirms the SHA-256 of the decrypted content matches the sha256 field from the attachment, as required by MIP-04.

      The sha256, type, filename, and nonce fields must all be present. Parse these from the imeta tag using getFileMetadataFromImetaTag from applesauce, then cast/extend to MediaAttachment.

      Parameters

      • encrypted: Uint8Array

        The encrypted blob downloaded from Blossom

      • fileKey: Uint8Array

        32-byte key from deriveMediaEncryptionKey

      • attachment: MediaAttachment

        The MIP-04 attachment from the group message's imeta tag

      Returns Uint8Array

      The decrypted file bytes

      If AEAD authentication fails, required fields are missing, or the decrypted content hash does not match attachment.sha256