This document introduces a common Message Module for decentralized instant messaging.
- Envelope
- Sender
- Receiver
- Time (same value from content.time)
- Content
- Type
- Serial Number
- Time
- Group (Optional)
- Message
/* example */
{
"sender" : "moki@4WDfe3zZ4T7opFSi3iDAKiuTnUHjxmXekk",
"receiver" : "hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj",
"time" : 1545405083
}/* example */
{
"type" : "1", // message type
"sn" : 412968873, // serial number (message ID in conversation)
"text" : "Hey guy!"
}public interface ContentType {
String ANY = "*";
//String UNKNOWN = "" + (0x00); // 0000 0000 (Undefined)
String TEXT = "" + (0x01); // 0000 0001
String FILE = "" + (0x10); // 0001 0000
String IMAGE = "" + (0x12); // 0001 0010
String AUDIO = "" + (0x14); // 0001 0100
String VIDEO = "" + (0x16); // 0001 0110
/// Web Page
String PAGE = "" + (0x20); // 0010 0000
/// Name Card
String NAME_CARD = "" + (0x33); // 0011 0011
/// Quote a message before and reply it with text
String QUOTE = "" + (0x37); // 0011 0111
String MONEY = "" + (0x40); // 0100 0000
String TRANSFER = "" + (0x41); // 0100 0001
String LUCKY_MONEY = "" + (0x42); // 0100 0010
String CLAIM_PAYMENT = "" + (0x48); // 0100 1000 (Claim for Payment)
String SPLIT_BILL = "" + (0x49); // 0100 1001 (Split the Bill)
String COMMAND = "" + (0x88); // 1000 1000
String HISTORY = "" + (0x89); // 1000 1001 (Entity History Command)
/// Application Customized
String APPLICATION = "" + (0xA0); // 1010 0000 (Application 0nly, Reserved)
// String APPLICATION_1 = "" + (0xA1); // 1010 0001 (Reserved)
// ... // 1010 ???? (Reserved)
// String APPLICATION_15 = "" + (0xAF); // 1010 1111 (Reserved)
// String CUSTOMIZED_0 = "" + (0xC0); // 1100 0000 (Reserved)
// String CUSTOMIZED_1 = "" + (0xC1); // 1100 0001 (Reserved)
// ...... // 1100 ???? (Reserved)
String ARRAY = "" + (0xCA); // 1100 1010 (Content Array)
// ... // 1100 ???? (Reserved)
String CUSTOMIZED = "" + (0xCC); // 1100 1100 (Customized Content)
// ... // 1100 ???? (Reserved)
String COMBINE_FORWARD = "" + (0xCF); // 1100 1111 (Combine and Forward)
/// Top-Secret message forward by proxy (MTA)
String FORWARD = "" + (0xFF); // 1111 1111
}When the user want to send out a message, the client needs TWO steps before sending it:
- Encrypt the
Instant MessagetoSecure Message; - Sign the
Secure MessagetoReliable Message.
Accordingly, when the client received a message, it needs TWO steps to extract the content:
- Verify the
Reliable MessagetoSecure Message; - Decrypt the
Secure MessagetoInstant Message.
Message Transforming
~~~~~~~~~~~~~~~~~~~~
Instant Message <--> Secure Message <--> Reliable Message
+-------------+ +------------+ +--------------+
| sender | | sender | | sender |
| receiver | | receiver | | receiver |
| time | | time | | time |
| | | | | |
| content | | data | | data |
+-------------+ | keys | | keys |
+------------+ | signature |
+--------------+
Algorithm:
data = password.encrypt(content)
key = receiver.public_key.encrypt(password)
signature = sender.private_key.sign(data)
/* example */
{
//-------- head (envelope) --------
"sender" : "moki@4WDfe3zZ4T7opFSi3iDAKiuTnUHjxmXekk",
"receiver" : "hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj",
"time" : 1545405083,
//-------- body (content) ---------
"content" : {
"type" : "1", // message type
"sn" : 412968873, // serial number (ID)
"text" : "Hey guy!"
}
}content -> JsON string: {"sn":412968873,"text":"Hey guy!","type":1}
/**
* 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="
}/**
* 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 encoded with BASE64 algorithm as default)