A common message module
Project description
Dao Ke Dao (道可道) -- Message Module (Python)
This document introduces a common Message Module for decentralized instant messaging.
Features
- Envelope
- Sender
- Receiver
- Time (same value from content.time)
- Content
- Type
- Serial Number
- Time
- Group (Optional)
- Message
Envelope
Message Envelope
/* example */
{
"sender" : "moki@4WDfe3zZ4T7opFSi3iDAKiuTnUHjxmXekk",
"receiver" : "hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj",
"time" : 1545405083
}
Content
/* example */
{
"type" : 0x01, // message type
"sn" : 412968873, // serial number (message ID in conversation)
"text" : "Hey guy!"
}
Content Type
class ContentType(IntEnum):
ANY = 0x00 # 0000 0000 (Undefined)
TEXT = 0x01 # 0000 0001
FILE = 0x10 # 0001 0000
IMAGE = 0x12 # 0001 0010
AUDIO = 0x14 # 0001 0100
VIDEO = 0x16 # 0001 0110
# Web Page
PAGE = 0x20 # 0010 0000
# Name Card for sharing contact
NAME_CARD = 0x33 # 0011 0011
# Quote a message before and reply it with text
QUOTE = 0x37 # 0011 0111
# Money
MONEY = 0x40 # 0100 0000
TRANSFER = 0x41 # 0100 0001
LUCKY_MONEY = 0x42 # 0100 0010
CLAIM_PAYMENT = 0x48 # 0100 1000 (Claim for Payment)
SPLIT_BILL = 0x49 # 0100 1001 (Split the Bill)
# Command
COMMAND = 0x88 # 1000 1000
HISTORY = 0x89 # 1000 1001 (Entity History Command)
# Application Customized
APPLICATION = 0xA0 # 1010 0000 (Application 0nly, Reserved)
# APPLICATION_1 = 0xA1 # 1010 0001 (Reserved)
# ... # 1010 ???? (Reserved)
# APPLICATION_15 = 0xAF # 1010 1111 (Reserved)
# CUSTOMIZED_0 = 0xC0 # 1100 0000 (Reserved)
# CUSTOMIZED_1 = 0xC1 # 1100 0001 (Reserved)
# ... # 1100 ???? (Reserved)
ARRAY = 0xCA # 1100 1010 (Content Array)
# ... # 1100 ???? (Reserved)
CUSTOMIZED = 0xCC # 1100 1100 (Customized Content)
# ... # 1100 ???? (Reserved)
COMBINE_FORWARD = 0xCF # 1100 1111 (Combine and Forward)
# Top-Secret message forward by proxy (MTA)
FORWARD = 0xFF # 1111 1111
Message
When the user want to send out a message, the client needs TWO steps before sending it:
- Encrypt the
Instant Message
toSecure Message
; - Sign the
Secure Message
toReliable Message
.
Accordingly, when the client received a message, it needs TWO steps to extract the content:
- Verify the
Reliable Message
toSecure Message
; - Decrypt the
Secure Message
toInstant Message
.
Message Transforming
~~~~~~~~~~~~~~~~~~~~
Instant Message <--> Secure Message <--> Reliable Message
+-------------+ +------------+ +--------------+
| sender | | sender | | sender |
| receiver | | receiver | | receiver |
| time | | time | | time |
| | | | | |
| content | | data | | data |
+-------------+ | key/keys | | key/keys |
+------------+ | signature |
+--------------+
Algorithm:
data = password.encrypt(content)
key = receiver.public_key.encrypt(password)
signature = sender.private_key.sign(data)
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dkd-2.3.0.tar.gz
(11.3 kB
view details)
Built Distribution
dkd-2.3.0-py3-none-any.whl
(19.9 kB
view details)
File details
Details for the file dkd-2.3.0.tar.gz
.
File metadata
- Download URL: dkd-2.3.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/68.0.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.0b3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
f6d21c1fa893125d76144863527a5d0e85d67db10bab9bc3db15ff5e4dbf1ad4
|
|
MD5 |
ab2e57893339f7c8984e843e2ac478c2
|
|
BLAKE2b-256 |
c2b5813a696ff67df19085cf4360d385e8eb666a78471e333364dda40df5c47d
|
File details
Details for the file dkd-2.3.0-py3-none-any.whl
.
File metadata
- Download URL: dkd-2.3.0-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/68.0.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.0b3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
6ee68252471312ac15735db207a0f700c7b9d108147b825b9bc612843a2735cf
|
|
MD5 |
609afc04d4e2ea0ac8df8179ea54b7c3
|
|
BLAKE2b-256 |
13048726ae331217c477fc12ba18b6fe24b7846fa7a51b8b9f0e8281a394d32a
|