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" : "1", // message type
"sn" : 412968873, // serial number (message ID in conversation)
"time" : 1545405083,
"text" : "Hey guy!"
}
Content Type
def i2s(value: int) -> str:
return '%d' % value
class ContentType:
ANY = '*'
# UNKNOWN = i2s(0x00) # 0000 0000 (Undefined)
TEXT = i2s(0x01) # 0000 0001
FILE = i2s(0x10) # 0001 0000
IMAGE = i2s(0x12) # 0001 0010
AUDIO = i2s(0x14) # 0001 0100
VIDEO = i2s(0x16) # 0001 0110
# Web Page
PAGE = i2s(0x20) # 0010 0000
# Name Card
NAME_CARD = i2s(0x33) # 0011 0011
# Quote a message before and reply it with text
QUOTE = i2s(0x37) # 0011 0111
MONEY = i2s(0x40) # 0100 0000
TRANSFER = i2s(0x41) # 0100 0001
LUCKY_MONEY = i2s(0x42) # 0100 0010
CLAIM_PAYMENT = i2s(0x48) # 0100 1000 (Claim for Payment)
SPLIT_BILL = i2s(0x49) # 0100 1001 (Split the Bill)
COMMAND = i2s(0x88) # 1000 1000
HISTORY = i2s(0x89) # 1000 1001 (Entity History Command)
# Application Customized
APPLICATION = i2s(0xA0) # 1010 0000 (Application 0nly, Reserved)
# APPLICATION_1 = i2s(0xA1) # 1010 0001 (Reserved)
# ... # 1010 ???? (Reserved)
# APPLICATION_15 = i2s(0xAF) # 1010 1111 (Reserved)
# CUSTOMIZED_0 = i2s(0xC0) # 1100 0000 (Reserved)
# CUSTOMIZED_1 = i2s(0xC1) # 1100 0001 (Reserved)
# ... # 1100 ???? (Reserved)
ARRAY = i2s(0xCA) # 1100 1010 (Content Array)
# ... # 1100 ???? (Reserved)
CUSTOMIZED = i2s(0xCC) # 1100 1100 (Customized Content)
# ... # 1100 ???? (Reserved)
COMBINE_FORWARD = i2s(0xCF) # 1100 1111 (Combine and Forward)
# Top-Secret message forward by proxy (MTA)
FORWARD = i2s(0xFF) # 1111 1111
Message
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)
Instant Message
/* example */
{
//-------- head (envelope) --------
"sender" : "moki@4WDfe3zZ4T7opFSi3iDAKiuTnUHjxmXekk",
"receiver" : "hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj",
"time" : 1545405083,
//-------- body (content) ---------
"content" : {
"type" : "1", // message type
"sn" : 412968873, // serial number (ID)
"time" : 1545405083,
"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",
"keys" : {
"hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj" : "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",
"keys" : {
"hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj" : "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)
Metadata
Release files for dkd 2.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dkd-2.5.1.tar.gz | 20.6 kB | Without provenance | Details for dkd-2.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dkd-2.5.1-py3-none-any.whl | Python 3 | none | any | Details for dkd-2.5.1-py3-none-any.whl |
Total release size: 56.9 kB
Release files / dkd-2.5.1.tar.gz
| Download URL | dkd-2.5.1.tar.gz |
|---|---|
| Size | 20.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
60048341f4b2ea69ce25ca4ba490f5d586c469c83ed7e160fd61f15de79b1475
|
|
BLAKE2b-256 checksum How to use checksums |
ca58b14067fb81cb905374e6f6381a6883a09985afc91f917fd9b287cf864b38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / dkd-2.5.1-py3-none-any.whl
| Download URL | dkd-2.5.1-py3-none-any.whl |
|---|---|
| Size | 36.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d9909199441a7e4711d0622c110d593dd128a740a038473b9dd87414b392c249
|
|
BLAKE2b-256 checksum How to use checksums |
dbc80daacdb772e036e6516e8901a330f67e65d59bde938c6b0e3b2f8ae25478
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for dkd 2.5.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.