2019-11-12 17:39:52 +00:00
# Protocol Core
2019-11-12 16:39:24 +00:00
2019-11-16 12:14:55 +00:00
- [Protocol Core ](#protocol-core )
- [Transport ](#transport )
- [Entity ID ](#entity-id )
- [BaseMessage ](#basemessage )
- [Errors ](#errors )
2019-11-17 17:07:15 +00:00
- [User devices ](#user-devices )
2019-11-17 16:56:07 +00:00
- [Account registration/login ](#account-registrationlogin )
- [Create account ](#create-account )
2019-11-17 17:07:15 +00:00
- [Login into account (by username) ](#login-into-account-by-username )
2019-11-16 12:14:55 +00:00
## Transport
For starting we simply use JSON + Websockets.
2019-11-12 16:39:24 +00:00
## Entity ID
2019-11-18 03:35:12 +00:00
* Room alias: `#<roomAlias>@<serverpart>`
2019-11-12 16:39:24 +00:00
* Username: `@<username>@<serverpart>`
2019-11-22 18:36:50 +00:00
* User ID with any 3PID: `%<type>:<data>@<serverpart>`
* Currently supported only following types: `email` and `msisdn` .
2019-11-22 18:58:11 +00:00
* Raw User ID: `@<UUID>@<serverpart>`
2019-11-18 03:35:12 +00:00
* Message ID: `&<uuid>@<serverpart (from which server the message was sent)>`
2019-11-12 16:39:24 +00:00
* Room ID: `!<roomID>@<serverpart>`
* Single server-part: `<serverpart>`
2019-11-20 13:35:38 +00:00
**Server-part**:
- hostname: `IPv4 / [IPv6] / dns-domain:<port (1-65535)>` (for end-users use)
- server ID: static SHA256 hash string from 4096 characters (for internal protocol use)
2019-11-12 16:39:24 +00:00
**Username/Room alias/RoomID** - MUST NOT be empty, and MUST contain only the characters `a-z` , `0-9` , `.` , `_` , `=` , `-` , and `/` .
2019-11-20 13:35:38 +00:00
**Special business rules**:
- RoomID SHOULD be UUID identifier.
- Servers MUST use server ID in internal purposes instead of normal server-part with hostname. Only end-users MUST use normal server-part with hostname. This is done for easy multi-domain serving.
2019-11-12 17:51:29 +00:00
## BaseMessage
BaseMessage is a basic message model, basis of the whole protocol. It is used for a very easy protocol extension process.
BaseMessage scheme:
2019-12-15 15:04:56 +00:00
```typescript
interface BaseMessage {
/**
* Message identifier (used to track the request-response chain)
*/
id: string, //
/**
* Type of message (used to determine which extension this message belongs to)
*/
type: string, //
/**
* From which entity this message is send
*/
from: EntityID, //
/**
* Message recipient
*/
to: EntityID, //
/**
* Operation success indicator (used to determine if the error happened while processing request)
*/
ok: boolean, //
/**
* Message payload (used to store extra information in message, list of permissible fields in the payload depends on "type" field)
*/
payload: Map< K , V > //
}
2019-11-16 11:56:14 +00:00
```
## Errors
Mechanism of error processing included into protocol.
Adds into type name `:error` postfix.
**Payload**:
2019-12-15 15:04:56 +00:00
```typescript
interface ErrorPayload {
/**
* Error code (defined in extensions, may be same per extensions)
*/
errCode: number,
/**
* Explanation of error in human-readable view
*/
errText: string,
/**
* Advanced error information (fields defined in extensions)
*/
errPayload: Map< K , V >
}
```
2019-11-16 11:56:14 +00:00
2019-11-17 16:56:07 +00:00
**Usecase**:
2019-11-16 11:56:14 +00:00
*Request*:
```json
{
"id": "abcd",
"type": "incorrectMessageType",
"from": "@juliet@cadmium.im",
"to": "cadmium.im",
"payload": {
"test": "test"
}
}
```
*Response*:
```json
{
"id": "abcd",
"type": "incorrectMessageType:error",
"from": "cadmium.im",
"to": "@juliet@cadmium.im",
"payload": {
"errCode": 0,
"errText": "Incorrect type of message (type isn't implemented in the server)",
"errPayload": {}
}
}
2019-11-17 16:56:07 +00:00
```
2019-11-17 17:07:15 +00:00
## User devices
`todo`
2019-11-17 16:56:07 +00:00
## Account registration/login
### Create account
**Description**: Create user account on a server
2019-11-20 13:35:38 +00:00
**Type**: `profile:register`
2019-11-17 16:56:07 +00:00
**Payload**:
2019-12-15 15:04:56 +00:00
- Request:
```typescript
interface RegistrationRequestPayload {
/**
* The username that the user wants to register
*/
username: string,
/**
* Array of user third party IDs (email and/or MSISDN)
*/
thirdPIDs: ThirdPartyID[],
/**
* Password of new account
*/
password: string
}
interface ThirdPartyID {
/**
* Type of third party ID
*/
type: string,
/**
* String contains third party ID. Examples: "juliet@capulett.com", "+1234567890".
*/
value: string
}
```
2019-11-17 16:56:07 +00:00
- Response:
2019-12-15 15:04:56 +00:00
```typescript
interface RegistrationResponsePayload {
/**
* ID of user (Username in priority. If we haven't username, then we put to this field one of user's third party IDs)
*/
userID: EntityID
}
```
2019-11-17 16:56:07 +00:00
**Errors**:
2019-11-17 17:07:15 +00:00
- 0: limit exceed
- 1: username/third party ID already taken
- 2: registration isn't allowed on a server
2019-11-17 16:56:07 +00:00
**Usecase**:
*Request*:
```json
{
"id": "abcd",
"type": "profile:register",
"to": "cadmium.org",
"payload": {
"username": "juliet",
"thirdPIDs": [
{"type":"email", "value":"juliet@capulett.com"},
{"type":"msisdn", "value":"+1234567890"},
],
"password": "romeo1"
}
}
```
*Response*:
```json
{
"id": "abcd",
"type": "profile:register",
"from": "cadmium.org",
"ok": true,
"payload": {
"userID": "@juliet@cadmium.org"
}
}
```
*< b > Error< / b > response*:
```json
{
"id": "abcd",
"type": "profile:register",
"from": "cadmium.org",
"ok": false,
"payload": {
2019-11-17 17:07:15 +00:00
"errCode": 1,
2019-11-17 16:56:07 +00:00
"errText": "{Username/email/msisdn} already taken"
}
}
```
2019-11-17 17:07:15 +00:00
**Special business rules**: none.
### Login into account (by username)
**Description**: Login into user account on a server by username
**Type**: `profile:login`
**Payload**:
2019-12-15 15:04:56 +00:00
- Request:
```typescript
interface LoginRequestPayload {
/**
* The username of account which user wants to login
*/
username: string,
/**
* Password of new account
*/
password: string
}
```
2019-11-17 17:07:15 +00:00
- Response:
2019-12-15 15:04:56 +00:00
```typescript
interface LoginResponsePayload {
/**
* Authentication token which required for various user actions (UUID)
*/
authToken: string,
/**
* Identifier of new user device (created by this login action)
*/
deviceID: string
}
```
2019-11-17 17:07:15 +00:00
**Errors**:
- 0: limit exceed
- 1: user ID/password isn't valid
**Usecase**:
*Request*:
```json
{
"id": "abcd",
"type": "profile:login",
"to": "cadmium.org",
"payload": {
"username": "juliet",
"password": "romeo1"
}
}
```
*Response*:
```json
{
"id": "abcd",
"type": "profile:login",
"from": "cadmium.org",
"ok": true,
"payload": {
"authToken": "3b5135a5-aff5-4396-a629-a254f383e82f",
"deviceID": "ABCDEFG"
}
}
```
*< b > Error< / b > response*:
```json
{
"id": "abcd",
"type": "profile:login",
"from": "cadmium.org",
"ok": false,
"payload": {
"errCode": 1,
"errText": "Username/password isn't valid"
}
}
```
**Special business rules**: none.