%global _empty_manifest_terminate_build 0
Name: python-dkd
Version: 0.12.7
Release: 1
Summary: A common message module
License: MIT
URL: https://github.com/dimchat/dkd-py
Source0: https://mirrors.aliyun.com/pypi/web/packages/c3/48/cb5ec1ed4929201036c39d722d0e9a10f320a2c9fea617930ac594b1c3c7/dkd-0.12.7.tar.gz
BuildArch: noarch
Requires: python3-mkm
%description
# Dao Ke Dao (道可道) -- Message Module (Python)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/dimchat/dkd-py/blob/master/LICENSE)
[![Version](https://img.shields.io/badge/alpha-0.10.12-red.svg)](https://github.com/dimchat/dkd-py/wiki)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/dimchat/dkd-py/pulls)
[![Platform](https://img.shields.io/badge/Platform-Python%203-brightgreen.svg)](https://github.com/dimchat/dkd-py/wiki)
This [document](https://github.com/dimchat/DIMP/blob/master/DaoKeDao-Message.md) introduces a common **Message Module** for decentralized instant messaging.
Copyright © 2018-2019 Albert Moky
- [Envelope](#envelope)
- Sender
- Receiver
- Time
- [Content](#content)
- [Type](#content-type)
- Serial Number
- [Message](#message)
- [Instant Message](#instant-message)
- [Secure Message](#secure-message)
- [Reliable Message](#reliable-message)
## 0. Envelope
### Message Envelope
```javascript
/* example */
{
"sender" : "moki@4WDfe3zZ4T7opFSi3iDAKiuTnUHjxmXekk",
"receiver" : "hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj",
"time" : 1545405083
}
```
## 1. Content
```javascript
/* example */
{
"type" : 0x01, // message type
"sn" : 412968873, // serial number (message ID in conversation)
"text" : "Hey guy!"
}
```
### Message Content Type
```python
class ContentType(IntEnum):
TEXT = 0x01 # 0000 0001
FILE = 0x10 # 0001 0000
IMAGE = 0x12 # 0001 0010
AUDIO = 0x14 # 0001 0100
VIDEO = 0x16 # 0001 0110
PAGE = 0x20 # 0010 0000
# quote a message before and reply it with text
QUOTE = 0x37 # 0011 0111
MONEY = 0x40 # 0100 0000
# TRANSFER = 0x41 # 0100 0001
# LUCKY_MONEY = 0x42 # 0100 0010
COMMAND = 0x88 # 1000 1000
HISTORY = 0x89 # 1000 1001 (Entity history command)
# top-secret message forward by proxy (Service Provider)
FORWARD = 0xFF # 1111 1111
```
## 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**.
```javascript
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
```javascript
/* 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
```javascript
/**
* 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
```javascript
/**
* 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)
%package -n python3-dkd
Summary: A common message module
Provides: python-dkd
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-dkd
# Dao Ke Dao (道可道) -- Message Module (Python)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/dimchat/dkd-py/blob/master/LICENSE)
[![Version](https://img.shields.io/badge/alpha-0.10.12-red.svg)](https://github.com/dimchat/dkd-py/wiki)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/dimchat/dkd-py/pulls)
[![Platform](https://img.shields.io/badge/Platform-Python%203-brightgreen.svg)](https://github.com/dimchat/dkd-py/wiki)
This [document](https://github.com/dimchat/DIMP/blob/master/DaoKeDao-Message.md) introduces a common **Message Module** for decentralized instant messaging.
Copyright © 2018-2019 Albert Moky
- [Envelope](#envelope)
- Sender
- Receiver
- Time
- [Content](#content)
- [Type](#content-type)
- Serial Number
- [Message](#message)
- [Instant Message](#instant-message)
- [Secure Message](#secure-message)
- [Reliable Message](#reliable-message)
## 0. Envelope
### Message Envelope
```javascript
/* example */
{
"sender" : "moki@4WDfe3zZ4T7opFSi3iDAKiuTnUHjxmXekk",
"receiver" : "hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj",
"time" : 1545405083
}
```
## 1. Content
```javascript
/* example */
{
"type" : 0x01, // message type
"sn" : 412968873, // serial number (message ID in conversation)
"text" : "Hey guy!"
}
```
### Message Content Type
```python
class ContentType(IntEnum):
TEXT = 0x01 # 0000 0001
FILE = 0x10 # 0001 0000
IMAGE = 0x12 # 0001 0010
AUDIO = 0x14 # 0001 0100
VIDEO = 0x16 # 0001 0110
PAGE = 0x20 # 0010 0000
# quote a message before and reply it with text
QUOTE = 0x37 # 0011 0111
MONEY = 0x40 # 0100 0000
# TRANSFER = 0x41 # 0100 0001
# LUCKY_MONEY = 0x42 # 0100 0010
COMMAND = 0x88 # 1000 1000
HISTORY = 0x89 # 1000 1001 (Entity history command)
# top-secret message forward by proxy (Service Provider)
FORWARD = 0xFF # 1111 1111
```
## 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**.
```javascript
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
```javascript
/* 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
```javascript
/**
* 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
```javascript
/**
* 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)
%package help
Summary: Development documents and examples for dkd
Provides: python3-dkd-doc
%description help
# Dao Ke Dao (道可道) -- Message Module (Python)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/dimchat/dkd-py/blob/master/LICENSE)
[![Version](https://img.shields.io/badge/alpha-0.10.12-red.svg)](https://github.com/dimchat/dkd-py/wiki)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/dimchat/dkd-py/pulls)
[![Platform](https://img.shields.io/badge/Platform-Python%203-brightgreen.svg)](https://github.com/dimchat/dkd-py/wiki)
This [document](https://github.com/dimchat/DIMP/blob/master/DaoKeDao-Message.md) introduces a common **Message Module** for decentralized instant messaging.
Copyright © 2018-2019 Albert Moky
- [Envelope](#envelope)
- Sender
- Receiver
- Time
- [Content](#content)
- [Type](#content-type)
- Serial Number
- [Message](#message)
- [Instant Message](#instant-message)
- [Secure Message](#secure-message)
- [Reliable Message](#reliable-message)
## 0. Envelope
### Message Envelope
```javascript
/* example */
{
"sender" : "moki@4WDfe3zZ4T7opFSi3iDAKiuTnUHjxmXekk",
"receiver" : "hulk@4YeVEN3aUnvC1DNUufCq1bs9zoBSJTzVEj",
"time" : 1545405083
}
```
## 1. Content
```javascript
/* example */
{
"type" : 0x01, // message type
"sn" : 412968873, // serial number (message ID in conversation)
"text" : "Hey guy!"
}
```
### Message Content Type
```python
class ContentType(IntEnum):
TEXT = 0x01 # 0000 0001
FILE = 0x10 # 0001 0000
IMAGE = 0x12 # 0001 0010
AUDIO = 0x14 # 0001 0100
VIDEO = 0x16 # 0001 0110
PAGE = 0x20 # 0010 0000
# quote a message before and reply it with text
QUOTE = 0x37 # 0011 0111
MONEY = 0x40 # 0100 0000
# TRANSFER = 0x41 # 0100 0001
# LUCKY_MONEY = 0x42 # 0100 0010
COMMAND = 0x88 # 1000 1000
HISTORY = 0x89 # 1000 1001 (Entity history command)
# top-secret message forward by proxy (Service Provider)
FORWARD = 0xFF # 1111 1111
```
## 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**.
```javascript
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
```javascript
/* 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
```javascript
/**
* 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
```javascript
/**
* 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)
%prep
%autosetup -n dkd-0.12.7
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-dkd -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Fri Jun 09 2023 Python_Bot - 0.12.7-1
- Package Spec generated