diff --git a/docs/protocol/simplex-chat.html b/docs/protocol/simplex-chat.html index 9e58706817..9b409480a4 100644 --- a/docs/protocol/simplex-chat.html +++ b/docs/protocol/simplex-chat.html @@ -744,17 +744,20 @@ window.addEventListener('scroll',changeHeaderBg);

The scope of SimpleX Chat Protocol is application level messages, both for chat functionality, related to the conversations between the clients, and extensible for any other application functions. Currently supported chat functions:

General message format

-

SimpleX Chat protocol supports two message formats:

+

SimpleX Chat protocol supports these message formats:

+

JSON-based message format supports batching inside a single container message, by encoding list of messages as JSON array.

+

Current implementation of chat protocol in SimpleX Chat uses SimpleX File Transfer Protocol (XFTP) for file transfer, with passing file description as chat protocol messages, instead passing files in binary format via SMP connections.

JSON format for chat and application messages

This document uses JTD schemas RFC 8927 to define the properties of chat messages, with some additional restrictions on message properties included in metadata member of JTD schemas. In case of any contradiction between JSON examples and JTD schema the latter MUST be considered correct.

Whitespace is used in JSON examples for readability, SimpleX Chat Protocol clients MUST avoid using whitespace when encoding JSON messages.

@@ -791,7 +794,16 @@ window.addEventListener('scroll',changeHeaderBg);

msgId property is a 12 bytes base64url-encoded random message ID that the clients can use to reference the message in the future, e.g. when editing, quoting or deleting it.

event property is the type of the message that defines the semantics of the message and the allowed format of params property.

params property includes message data, depending on event, as defined below and in JTD schema.

+

Compressed format

+

The syntax of compressed message is defined by the following ABNF notation:

+
compressedMessage = %s"X" 1*15780 OCTET; compressed message data
+
+

Compressed message is required to fit into 13388 bytes, accounting for agent overhead (see Protocol's maxCompressedMsgLength).

+

The actual JSON message is required to fit into 15610 bytes, accounting for group message forwarding (x.grp.msg.forward) overhead (see Protocol's maxEncodedMsgLength).

Binary format for sending files

+
+

Note: Planned to be deprecated. No longer used for file transfer in SimpleX Chat implementation of chat protocol.

+

SimpleX Chat clients use separate connections to send files using a binary format. File chunk size send in each message MUST NOT be bigger than 15,780 bytes to fit into 16kb (16384 bytes) transport block.

The syntax of each message used to send files is defined by the following ABNF notation:

fileMessage = fileChunk / cancelFile
@@ -817,7 +829,9 @@ eventWord = 1* ALPHA
 
  • x.contact - contact profile and additional data sent as part of contact request to a long-term contact address.
  • x.info* - messages to send, update and de-duplicate contact profiles.
  • x.msg.* - messages to create, update and delete content chat items.
  • +
  • x.msg.file.descr - message to transfer XFTP file description.
  • x.file.* - messages to accept and cancel sending files (see files sub-protocol).
  • +
  • x.direct.del - message to notify about contact deletion.
  • x.grp.* - messages used to manage groups and group members (see group sub-protocol).
  • x.call.* - messages to invite to WebRTC calls and send signalling messages.
  • x.ok - message sent during connection handshake.
  • @@ -841,6 +855,8 @@ eventWord = 1* ALPHA
  • text - no file attachment is expected for this format, text property MUST be non-empty.
  • file - attached file is required, text property MAY be empty.
  • image - attached file is required, text property MAY be empty.
  • +
  • video - attached file is required, text property MAY be empty.
  • +
  • voice - attached file is required, text property MAY be empty.
  • link - no file attachment is expected, text property MUST be non-empty. preview property contains information about link preview.
  • See /definition/msgContent in JTD schema for message container format.

    @@ -855,6 +871,7 @@ eventWord = 1* ALPHA

    x.file.acpt message is used to accept the file in case when file connection address was included in the message (that is the case when the file invitation was sent in direct message). It is sent as part of file connection handshake via file connection, that is why this message contains no reference to the file - the used connection provides sufficient context for the sender.

    x.file.acpt.inv message is used to accept the file in group conversations, it includes the connection address. It is sent in the same connection where the file was offered and must reference the original message.

    x.file.cancel message is sent to notify the recipient that sending of the file was cancelled. It is sent in response to accepting the file with x.file.acpt.inv message. It is sent in the same connection where the file was offered.

    +

    x.msg.file.descr message is used to send XFTP file description. File descriptions that don't fit into a single chat protocol message are sent in parts, with messages including part number (fileDescrPartNo) and description completion marker (fileDescrComplete). Recipient client accumulates description parts and starts file download upon completing file description.

    Sub-protocol for chat groups

    Decentralized design for chat groups

    SimpleX Chat groups are fully decentralized and do not have any globally unique group identifiers - they are only defined on client devices as a group profile and a set of bi-directional SimpleX connections with other group members. When a new member accepts group invitation, the inviting member introduces a new member to all existing members and forwards the connection addresses so that they can establish direct and group member connections.

    @@ -863,21 +880,28 @@ eventWord = 1* ALPHA

    Each member in the group is identified by a group-wide unique identifier used by all members in the group. This is to allow referencing members in the messages and to allow group message integrity validation.

    The diagram below shows the sequence of messages sent between the users' clients to add the new member to the group.

    Adding member to the group

    +

    While introduced members establish connection inside group, inviting member forwards messages between them by sending x.grp.msg.forward messages. When introduced members finalize connection, they notify inviting member to stop forwarding via x.grp.mem.con message.

    Member roles

    Currently members can have one of three roles - owner, admin and member. The user that created the group is self-assigned owner role, the new members are assigned role by the member who adds them - only owner and admin members can add new members; only owner members can add members with owner role.

    Messages to manage groups and add members

    x.grp.inv message is sent to invite contact to the group via contact's direct connection and includes group member connection address. This message MUST only be sent by members with admin or owner role. Optional groupLinkId is included when this message is sent to contacts connected via the user's group link. This identifier is a random byte sequence, with no global or even local uniqueness - it is only used for the user's invitations to a given group to provide confirmation to the contact that the group invitation is for the same group the contact was connecting to via the group link, so that the invitation can be automatically accepted by the contact - the contact compares it with the group link id contained in the group link uri's data field.

    x.grp.acpt message is sent as part of group member connection handshake, only to the inviting user.

    +

    x.grp.link.inv message is sent as part of connection handshake to member joining via group link, and contains group profile and initial information about inviting and joining member.

    +

    x.grp.link.mem message is sent as part of connection handshake to member joining via group link, and contains remaining information about inviting member.

    x.grp.mem.new message is sent by the inviting user to all connected members (and scheduled as pending to all announced but not yet connected members) to announce a new member to the existing members. This message MUST only be sent by members with admin or owner role. Receiving clients MUST ignore this message if it is received from member with member role.

    x.grp.mem.intro messages are sent by the inviting user to the invited member, via their group member connection, one message for each existing member. When this messageĀ is sent by any other member than the one who invited the recipient it MUST be ignored.

    x.grp.mem.inv messages are sent by the invited user to the inviting user, one message for each existing member previously introduced with x.grp.mem.intro message. When this messageĀ is sent by any other member than the one who was invited by the recipient it MUST be ignored.

    x.grp.mem.fwd message is used by the inviting user to forward the invitations received from invited member in x.grp.mem.inv messages to all other members. This message can only be sent by the member who previously announced the new member, otherwise the recipients MUST ignore it.

    x.grp.mem.info this message is sent as part of member connection handshake - it includes group member profile.

    x.grp.mem.role message is sent to update group member role - it is sent to all members by the member who updated the role of the member referenced in this message. This message MUST only be sent by members with admin or owner role. Receiving clients MUST ignore this message if it is received from member with role less than admin.

    +

    x.grp.mem.restrict message is sent to group members to communicate group member restrictions, such as member being blocked for sending messages.

    +

    x.grp.mem.con message is sent by members connecting inside group to inviting member, to notify the inviting member they have completed the connection and no longer require forwarding messages between them.

    x.grp.mem.del message is sent to delete a member - it is sent to all members by the member who deletes the member referenced in this message. This message MUST only be sent by members with admin or owner role. Receiving clients MUST ignore this message if it is received from member with member role.

    x.grp.leave message is sent to all members by the member leaving the group. If the only group owner leaves the group, it will not be possible to delete it with x.grp.del message - but all members can still leave the group with x.grp.leave message and then delete a local copy of the group.

    x.grp.del message is sent to all members by the member who deletes the group. Clients who received this message SHOULD keep a local copy of the deleted group, until it is deleted by the user. This message MUST only be sent by members with owner role. Receiving clients MUST ignore this message if it is received from member other than with owner role.

    x.grp.info message is sent to all members by the member who updated group profile. Only group owners can update group profiles. Clients MAY implement some conflict resolution strategy - it is currently not implemented by SimpleX Chat client. This message MUST only be sent by members with owner role. Receiving clients MUST ignore this message if it is received from member other than with owner role.

    +

    x.grp.direct.inv message is sent to a group member to propose establishing a direct connection between members, thus creating a contact with another member.

    +

    x.grp.msg.forward message is sent by inviting member to forward messages between introduced members, while they are connecting.

    Sub-protocol for WebRTC audio/video calls

    This sub-protocol is used to send call invitations and to negotiate end-to-end encryption keys and pass WebRTC signalling information.

    These message are used for WebRTC calls: