Marmot-TS
    Preparing search index...

    Function encryptMediaFile

    • Encrypts a media file for an encrypted-media-v1 attachment.

      Uses ChaCha20-Poly1305 AEAD with a random 12-byte nonce. The AAD binds the scheme version, plaintext hash, canonical MIME type, and filename. Computes ciphertextSha256 = SHA256(encrypted) and returns a MediaAttachment with locators left empty for the caller to fill after upload.

      Parameters

      • file: Uint8Array

        The plaintext file bytes to encrypt

      • fileKey: Uint8Array

        32-byte key from deriveMediaEncryptionKey

      • fields: MediaCryptoFields & Pick<Partial<MediaAttachment>, "dim" | "thumbhash">

        Provides plaintextSha256, mediaType, and filename; optional dim/thumbhash are carried through onto the result

      Returns EncryptMediaFileResult

      Encrypted blob and a populated MediaAttachment