Skip to main content

A common message module

Project description

Dao Ke Dao (道可道) -- Message Module

license Version

This document introduces a common Message Module for decentralized instant messaging.

Copyright © 2018 Albert Moky

0. Envelope

Message Envelope

/* example */
{
    sender   : "moki@4WDfe3zZ4T7opFSi3iDAKiuTnUHjxmXekk",
    receiver : "hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj",
    time     : 1545405083
}

1. Content

/* example */
{
    type     : 0x01,      // message type
    sn       : 412968873, // serial number (message ID in conversation)

    text     : "Hey guy!"
}

Message Content Type

enum {
    DIMMessageType_Unknown = 0x00,

    DIMMessageType_Text    = 0x01,

    DIMMessageType_File    = 0x10,
    DIMMessageType_Image   = 0x12, // photo
    DIMMessageType_Audio   = 0x14, // voice
    DIMMessageType_Video   = 0x16,

    DIMMessageType_Page    = 0x20, // web page

    // quote an exists message and reply it with text
    DIMMessageType_Quote   = 0x37,

    // system command
    DIMMessageType_Command = 0x88,

    // top-secret message forwarded by proxy(account or station)
    DIMMessageType_Forward = 0xFF
};

2. Message

When the user want to send out a message, the client needs TWO steps before sending it:

  1. Encrypt the Instant Message to Secure Message;
  2. Sign the Secure Message to Reliable Message.

Accordingly, when the client received a message, it needs TWO steps to extract the content:

  1. Verify the Reliable Message to Secure Message;
  2. Decrypt the Secure Message to Instant Message.

Instant Message

/* example */
{
    //-------- head (envelope) --------
    sender   : "moki@4WDfe3zZ4T7opFSi3iDAKiuTnUHjxmXekk",
    receiver : "hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj",
    time     : 1545405083,

    //-------- body (content) ---------
    content  : {
        type : 0x01,      // message type
        sn   : 412968873, // serial number (ID)
        text : "Hey guy!"
    }
}

content -> JsON string: {"sn":412968873,"text":"Hey guy!","type":1}

Secure Message

/**
 *  Algorithm:
 *      string = json(content);
 *      PW     = random();
 *      data   = encrpyt(string, PW);      // Symmetric
 *      key    = encrypt(PW, receiver.PK); // Asymmetric
 */
{
    //-------- head (envelope) --------
    sender   : "moki@4WDfe3zZ4T7opFSi3iDAKiuTnUHjxmXekk",
    receiver : "hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj",
    time     : 1545405083,

    //-------- body (content) ---------
    data     : "9cjCKG99ULCCxbL2mkc/MgF1saeRqJaCc+S12+HCqmsuF7TWK61EwTQWZSKskUeF",
    key      : "WH/wAcu+HfpaLq+vRblNnYufkyjTm4FgYyzW3wBDeRtXs1TeDmRxKVu7nQI/sdIALGLXrY+O5mlRfhU8f8TuIBilZUlX/eIUpL4uSDYKVLaRG9pOcrCHKevjUpId9x/8KBEiMIL5LB0Vo7sKrvrqosCnIgNfHbXMKvMzwcqZEU8="
}

Reliable Message

/**
 *  Algorithm:
 *      signature = sign(data, sender.SK);
 */
{
    //-------- head (envelope) --------
    sender   : "moki@4WDfe3zZ4T7opFSi3iDAKiuTnUHjxmXekk",
    receiver : "hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj",
    time     : 1545405083,

    //-------- body (content) ---------
    data      : "9cjCKG99ULCCxbL2mkc/MgF1saeRqJaCc+S12+HCqmsuF7TWK61EwTQWZSKskUeF",
    key       : "WH/wAcu+HfpaLq+vRblNnYufkyjTm4FgYyzW3wBDeRtXs1TeDmRxKVu7nQI/sdIALGLXrY+O5mlRfhU8f8TuIBilZUlX/eIUpL4uSDYKVLaRG9pOcrCHKevjUpId9x/8KBEiMIL5LB0Vo7sKrvrqosCnIgNfHbXMKvMzwcqZEU8=",
    signature : "Yo+hchWsQlWHtc8iMGS7jpn/i9pOLNq0E3dTNsx80QdBboTLeKoJYAg/lI+kZL+g7oWJYpD4qKemOwzI+9pxdMuZmPycG+0/VM3HVSMcguEOqOH9SElp/fYVnm4aSjAJk2vBpARzMT0aRNp/jTFLawmMDuIlgWhBfXvH7bT7rDI="
}

(All data encode with BASE64 algorithm as default)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
dkd-0.1.3-py3-none-any.whl (13.3 kB) Copy SHA256 hash SHA256 Wheel py3
dkd-0.1.3.tar.gz (10.5 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page