specs/status-whisper-usage-spec.md

181 lines
6.7 KiB
Markdown
Raw Normal View History

2019-08-27 14:31:31 +00:00
# Status Whisper Usage Specification
> Version: 0.1 (Draft)
>
> Authors: Adam Babik <adam@status.im>, Corey Petty <corey@status.im>, Oskar Thorén <oskar@status.im> (alphabetical order)
2019-08-26 15:25:02 +00:00
2019-09-10 22:05:41 +00:00
- [Status Whisper Usage Specification](#status-whisper-usage-specification)
- [Abstract](#abstract)
- [Reason](#reason)
- [Terminology](#terminology)
- [Whisper node configuration](#whisper-node-configuration)
- [Topics](#topics)
- [Contact code topic](#contact-code-topic)
- [Partitioned topic](#partitioned-topic)
- [Public chats](#public-chats)
- [Personal discovery topic](#personal-discovery-topic)
- [Generic discovery topic](#generic-discovery-topic)
- [One-to-one topic](#one-to-one-topic)
- [Group chat topic](#group-chat-topic)
- [Message encryption](#message-encryption)
- [Whisper V6 extensions (or Status Whisper Node)](#whisper-v6-extensions-or-status-whisper-node)
2019-08-29 10:49:20 +00:00
## Abstract
Status uses [Whisper](https://eips.ethereum.org/EIPS/eip-627) to provide
2019-09-10 22:05:41 +00:00
privacy-preserving routing and messaging on top of devP2P. Whisper uses topics
to partition its messages, and these are leveraged for all chat capabilities. In
the case of public chats, the channel name maps directly to its Whisper topic.
This allows allows anyone to listen on a single channel.
Additionally, since anyone can receive Whisper envelopes, it relies on the
ability to decrypt messages to decide who is the correct recipient. We do
however not rely on this property, but instead implement another secure
transport layer on top of Whisper.
Finally, we use an extension of Whisper to provide the ability to do offline
messaging.
2019-08-29 10:49:20 +00:00
2019-09-10 22:05:41 +00:00
## Reason
2019-08-27 14:31:31 +00:00
Provide routing, metadata protection, topic-based multicasting and basic
encryption properties to support asynchronous chat.
2019-08-29 10:49:20 +00:00
## Terminology
2019-08-27 14:31:31 +00:00
* *Whisper node*: an Ethereum node with Whisper V6 enabled (in the case of geth, it's `--shh` option)
* *Whisper network*: a group of Whisper nodes connected together through the internet connection and forming a graph
* *Message*: decrypted Whisper message
2019-09-10 22:05:41 +00:00
* *Offline message*: an archived envelope
* *Envelope*: encrypted message with metadata like topic and Time-To-Live
2019-08-27 14:31:31 +00:00
## Whisper node configuration
2019-09-10 22:05:41 +00:00
Whisper's Proof Of Work algorithm is used to deter denial of service and various spam/flood attacks against the Whisper network. The sender of a message MUST perform some work which in this case means processing time. Because Status' main client is a mobile client, this easily leads to battery draining and poor performance of the app itself. Hence, all clients MUST use the following Whisper node settings:
2019-08-27 14:31:31 +00:00
* proof-of-work not larger than `0.002`
* time-to-live not lower than `10` (in seconds)
2019-09-10 22:05:41 +00:00
## Topics
2019-08-27 14:31:31 +00:00
2019-09-10 22:05:41 +00:00
The Status protocols uses a few particular Whisper topics to achieve its goals.
2019-08-27 14:31:31 +00:00
2019-09-10 22:05:41 +00:00
### Contact code topic
2019-08-27 14:31:31 +00:00
2019-09-10 22:05:41 +00:00
Contact code topic is used for ???
2019-08-27 14:31:31 +00:00
2019-09-10 22:05:41 +00:00
<!-- TODO: describe who should listen to it -->
2019-08-27 14:31:31 +00:00
2019-09-10 22:05:41 +00:00
It MUST be created following the algorithm below:
```golang
2019-09-10 22:05:41 +00:00
contactCode := "0x" + hexEncode(activePublicKey) + "-contact-code"
2019-08-27 14:31:31 +00:00
2019-09-10 22:05:41 +00:00
var hash []byte = keccak256(name)
var topicLen int = 4
2019-08-27 14:31:31 +00:00
2019-09-10 22:05:41 +00:00
if len(hash) < topicLen {
topicLen = len(hash)
2019-08-27 14:31:31 +00:00
}
2019-09-10 22:05:41 +00:00
var topic [4]byte
for i = 0; i < topicLen; i++ {
2019-08-27 14:31:31 +00:00
topic[i] = hash[i]
}
```
2019-09-10 22:05:41 +00:00
### Partitioned topic
2019-08-27 14:31:31 +00:00
2019-09-10 22:05:41 +00:00
Whisper is broadcast-based protocol. In theory, everyone could communicate using a single topic but that would be extremaly inefficient. Opposite would be using a unique topic for each conversation, however, this brings privacy concerns because it would be much easier to detect whether and when two parties have an active conversation.
2019-08-27 14:31:31 +00:00
2019-09-10 22:05:41 +00:00
Partitioned topics are used to broadcast private messages efficiently. By selecting a number of topic, it is possible to balance efficiency and privacy.
2019-08-27 14:31:31 +00:00
2019-09-10 22:05:41 +00:00
Currently, the number of partitioned topics is set to `5000`. They MUST be generated following the algorithm below:
```golang
var partitionsNum *big.Int = big.NewInt(5000)
var partition *big.Int = big.NewInt(0).Mod(publicKey.X, partitionsNum)
2019-09-10 22:05:41 +00:00
partitionTopic := "contact-discovery-" + strconv.FormatInt(partition.Int64(), 10)
2019-09-10 22:05:41 +00:00
var hash []byte = keccak256(partitionTopic)
var topicLen int = 4
2019-09-10 22:05:41 +00:00
if len(hash) < topicLen {
topicLen = len(hash)
}
2019-09-10 22:05:41 +00:00
var topic [4]byte
for i = 0; i < topicLen; i++ {
topic[i] = hash[i]
}
```
2019-09-10 22:05:41 +00:00
If partitioned topic support is enabled by the Status client, it MUST listen to its paritioned topic. It MUST be generated using the algorithm above and active public key.
2019-09-10 22:05:41 +00:00
### Public chats
2019-09-10 22:05:41 +00:00
A public chat MUST use a topic derived from a public chat name following the algorithm below:
```golang
var hash []byte
hash = keccak256(name)
2019-09-10 22:05:41 +00:00
topicLen = 4
if len(hash) < topicLen {
topicLen = len(hash)
}
2019-09-10 22:05:41 +00:00
var topic [4]byte
for i = 0; i < topicLen; i++ {
topic[i] = hash[i]
}
```
2019-09-10 22:05:41 +00:00
### Personal discovery topic
2019-09-10 22:05:41 +00:00
Personal discovery topic is used to ???
2019-09-10 22:05:41 +00:00
A client MUST implement it following the algorithm below:
```golang
personalDiscoveryTopic := "contact-discovery-" + hexEncode(publicKey)
2019-09-10 22:05:41 +00:00
var hash []byte = keccak256(personalDiscoveryTopic)
var topicLen int = 4
2019-09-10 22:05:41 +00:00
if len(hash) < topicLen {
topicLen = len(hash)
}
2019-09-10 22:05:41 +00:00
var topic [4]byte
for i = 0; i < topicLen; i++ {
topic[i] = hash[i]
}
```
2019-09-10 22:05:41 +00:00
Each Status Client SHOULD listen to this topic in order to receive ???
2019-09-10 22:05:41 +00:00
### Generic discovery topic
2019-09-10 22:05:41 +00:00
Generic discovery topic is a legacy topic used to handle all one-to-one chats. The newer implementation should rely on [Partitioned Topic](#partitioned-topic) and [Personal discovery topic](#personal-discovery-topic).
2019-09-10 22:05:41 +00:00
Generic discovery topic MUST be created following [Public chats](#public-chats) topic creation where `name` is equal to `contact-discovery`.
2019-09-10 22:05:41 +00:00
### One-to-one topic
2019-09-10 22:05:41 +00:00
In order to listen to one-to-one messages incoming from a public key `P`, the Status Client MUST listen to a [Contact Code Topic](#contact-code-topic) created for the publickey `P`.
2019-09-10 22:05:41 +00:00
### Group chat topic
2019-09-10 22:05:41 +00:00
TODO
2019-09-10 22:05:41 +00:00
## Message encryption
2019-09-10 22:05:41 +00:00
Even though, the protocol specifies an encryption layer that encrypts messages before passing them to the transport layer, Whisper protocol requires each Whisper message to be encrypted anyway.
2019-08-27 14:31:31 +00:00
2019-09-10 22:05:41 +00:00
Public and group messages are encrypted using symmetric encryption and the key is created from a channel name string. The implementation is available in [`shh_generateSymKeyFromPassword`](https://github.com/ethereum/go-ethereum/wiki/Whisper-v6-RPC-API#shh_generatesymkeyfrompassword) JSON-RPC method of go-ethereum Whisper implementation.
2019-08-27 14:31:31 +00:00
2019-09-10 22:05:41 +00:00
One-to-one messages are encrypted using asymmetric encryption.
2019-08-27 14:31:31 +00:00
## Whisper V6 extensions (or Status Whisper Node)
2019-08-27 14:31:31 +00:00
Outside of Whisper v6, there are some extensions, message codes and RPC methods that MAY be useful for client implementers. An implementation of this can be found in a fork of Whisper [here](https://github.com/status-im/whisper).
<!--TODO: provide a list of RPC methods from `shhext` API which are relevant to this spec, as well as motivation (rationale section) -->