---
allOf:
  - $ref: core-event-schema/event.yaml

description: |-
  This event type is used when sending encrypted events. It can be used either
  within a room (in which case it will have all of the normal properties in
  [Room events](/client-server-api/#room-event-format)), or
  as a [to-device](/client-server-api/#send-to-device-messaging) event.

properties:
  content:
    properties:
      algorithm:
        type: string
        enum:
          - m.olm.v1.curve25519-aes-sha2
          - m.megolm.v1.aes-sha2
        description: |-
          The encryption algorithm used to encrypt this event. The
          value of this field determines which other properties will be
          present.
      ciphertext:
        oneOf:
          - type: string
          - type: object
            additionalProperties:
              type: object
              title: CiphertextInfo
              properties:
                body:
                  type: string
                  description: The encrypted payload.
                type:
                  type: integer
                  description: The Olm message type.
        description: |-
          The encrypted content of the event. Either the encrypted payload
          itself, in the case of a Megolm event, or a map from the recipient
          Curve25519 identity key to ciphertext information, in the case of an
          Olm event. For more details, see [Messaging Algorithms](/client-server-api/#messaging-algorithms).
      sender_key:
        type: string
        x-changedInMatrixVersion:
          "1.3": |-
            Previously this field was required, however given it offers no additional
            security or privacy benefit it has been deprecated for Megolm messages.
            See [`m.megolm.v1.aes-sha2`](#mmegolmv1aes-sha2) for more information.
        description: |-
          The Curve25519 key of the sender. Required (not deprecated) if not using Megolm.

          **Deprecated**: This field provides no additional security or privacy benefit
          for Megolm messages and must not be read from if the encrypted event is using
          Megolm. It should still be included on outgoing messages, however must not be
          used to find the corresponding session. See [`m.megolm.v1.aes-sha2`](#mmegolmv1aes-sha2)
          for more information.
      device_id:
        type: string
        x-changedInMatrixVersion:
          "1.3": |-
            Previously this field was required for Megolm messages, however given it
            offers no additional security or privacy benefit it has been deprecated
            for Megolm messages. See [`m.megolm.v1.aes-sha2`](#mmegolmv1aes-sha2) for
            more information.
        description: |-
          The ID of the sending device.

          **Deprecated**: This field provides no additional security or privacy benefit
          for Megolm messages and must not be read from if the encrypted event is using
          Megolm. It should still be included on outgoing messages, however must not be
          used to find the corresponding session. See [`m.megolm.v1.aes-sha2`](#mmegolmv1aes-sha2)
          for more information.
      session_id:
        type: string
        description: |-
          The ID of the session used to encrypt the message. Required with
          Megolm.
    required:
      - algorithm
      - ciphertext
    type: object
  type:
    enum:
      - m.room.encrypted
    type: string
type: object
