2021-05-07 00:43:24 +00:00
|
|
|
---
|
|
|
|
slug: 20
|
2021-06-25 03:56:11 +00:00
|
|
|
title: 20/TOY-ETH-DM
|
|
|
|
name: Toy Ethereum Direct Message
|
2021-05-07 00:43:24 +00:00
|
|
|
status: raw
|
2021-06-21 09:17:01 +00:00
|
|
|
tags: waku-application
|
2021-05-07 00:43:24 +00:00
|
|
|
editor: Franck Royer <franck@status.im>
|
|
|
|
contributors:
|
|
|
|
---
|
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
**Content Topics**:
|
|
|
|
|
|
|
|
- Public Key Broadcast: `/eth-dm/1/public-key/json`,
|
|
|
|
- Direct Message: `/eth-dm/1/direct-message/json`.
|
|
|
|
|
2021-06-25 03:56:11 +00:00
|
|
|
This specification explains the Toy Ethereum Direct Message protocol
|
|
|
|
which enables a peer to send an encrypted direct message to another peer
|
2021-05-07 00:43:24 +00:00
|
|
|
using the Waku v2 network, and the peer's Ethereum address.
|
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
The main purpose of this specification is to demonstrate how Waku v2 can be used for direct messaging purposes.
|
2021-06-25 03:56:11 +00:00
|
|
|
In the current state, the protocol has privacy and features [limitations](#limitations), has not been audited
|
|
|
|
and hence is not fit for production usage.
|
|
|
|
We hope this can be an inspiration for developers wishing to build on top of Waku v2.
|
2021-06-23 01:52:21 +00:00
|
|
|
|
2021-05-07 00:43:24 +00:00
|
|
|
# Goal
|
|
|
|
|
|
|
|
Alice wants to send an encrypted message to Bob, where only Bob can decrypt the message.
|
2021-06-23 01:52:21 +00:00
|
|
|
Alice only knows Bob's Ethereum Address.
|
2021-05-07 00:43:24 +00:00
|
|
|
|
|
|
|
# Variables
|
|
|
|
|
|
|
|
Here are the variables used in the protocol and their definition:
|
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
- `B` is Bob's Ethereum address (or account),
|
2021-05-07 00:43:24 +00:00
|
|
|
- `b` is the private key of `B`, and is only known by Bob.
|
2021-06-23 01:52:21 +00:00
|
|
|
- `B'` is Bob's Eth-DM Public Key, which has `b'` as private key.
|
2021-05-07 00:43:24 +00:00
|
|
|
|
|
|
|
# Design Requirements
|
|
|
|
|
|
|
|
The proposed protocol MUST adhere to the following design requirements:
|
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
1. Alice knows Bob's Ethereum address,
|
|
|
|
1. Bob is willing to participate to Eth-DM, and publishes `B'`,
|
|
|
|
1. Alice wants to send message `M` to Bob,
|
|
|
|
1. Bob SHOULD be able to get `M` using [10/WAKU2](/spec/13),
|
|
|
|
1. Participants only have access to their Ethereum Wallet via the Web3 API,
|
|
|
|
1. Carole MUST NOT be able to read `M`'s content even if she is storing it or relaying it,
|
|
|
|
1. ECDSA Elliptic curve cryptography is used,
|
|
|
|
1. [eth-crypto](https://www.npmjs.com/package/eth-crypto),
|
|
|
|
which uses [eccrypto](https://www.npmjs.com/package/eccrypto),
|
|
|
|
is used for encryption and decryption purposes.
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
## Limitations
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
Bob's Ethereum Address is present in clear in Direct Messages,
|
|
|
|
meaning that anyone who is monitoring the Waku network know how many messages Bob receives.
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
Alice's details are not included in the message's structure,
|
|
|
|
meaning that there is no programmatic way for Bob to reply to Alice
|
|
|
|
or verify her identity.
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
# The protocol
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
## Eth-DM Key Generation
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
First, Bob needs to generate an Eth-DM keypair.
|
|
|
|
To avoid Bob having to save an additional private key or recovery phrase for Eth-DM purposes,
|
|
|
|
we generate the Eth-DM keypair using Bob's Ethereum account.
|
|
|
|
This will allow Bob to recover his Eth-DM private key as long as he has access to his Ethereum private key.
|
2021-05-07 00:43:24 +00:00
|
|
|
|
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
To generate his Eth-DM keypair, Bob MUST use his Ethereum private key 'b' to sign the Eth-DM salt message:
|
|
|
|
`Salt for Eth-Dm, do not share a signature of this message or others could decrypt your messages`.
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
The resulting signature 's' is then concatenated with itself once and hashed using keccak256.
|
|
|
|
The resulting hash is Bob's Eth-DM private key `b'`:
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
```
|
|
|
|
b' = keccak256(s + s)
|
|
|
|
```
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
The signature process is as per the current Ethereum best practice:
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
1. Convert the salt message to a byte array using utf-8 encoding,
|
|
|
|
2. Use [`eth_sign`](https://eth.wiki/json-rpc/API#eth_sign) Ethereum JSON-RPC command or equivalent.
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
# Eth-DM Public Key Broadcast
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
For Bob to be reachable, he SHOULD broadcast his Eth-DM Public Key `B'`.
|
|
|
|
To prove that he is indeed the owner of his Ethereum account `B`, he MUST sign his Eth-DM Public Key.
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
To do so, Bob MUST format his Public Key to lower case hex (no prefix) in a JSON Object on the property `ethDmPublicKey`, e.g.:
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"ethDmPublicKey": "abcd...0123"
|
|
|
|
}
|
|
|
|
```
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
Then, Bob MUST sign the stringified JSON using [`eth_sign`](https://eth.wiki/json-rpc/API#eth_sign).
|
|
|
|
This results in the `sigEthDmPubKey` signature.
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
Bob then creates an Eth-DM Public Key Message containing:
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
- Bob's Eth-DM Public Key `B'` on property `ethDmPublicKey`,
|
|
|
|
- Bob's Ethereum Address `B` on property `ethAddress`,
|
|
|
|
- The signature of Bob's Eth-DM Public Key `sigEthDmPubKey` on property `sig`.
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
In JSON format as follows:
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"ethDmPublicKey": "abcd...0123",
|
|
|
|
"ethAddress": "0x01234...eF",
|
|
|
|
"sig": "0x2eb...a1b"
|
2021-05-07 00:43:24 +00:00
|
|
|
}
|
2021-06-23 01:52:21 +00:00
|
|
|
```
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
Finally, Bob SHOULD publish the message on Waku v2 with the Public Key Broadcast content topic.
|
|
|
|
|
|
|
|
# Send Direct Message
|
|
|
|
|
|
|
|
Alice MAY monitor the Waku v2 to collect Ethereum Address/Eth-DM Public Key tuples.
|
|
|
|
Alice SHOULD verify that the `sig` property of said message contains a valid signature as constructed above.
|
|
|
|
She SHOULD drop any message without a signature or with an invalid signature.
|
|
|
|
|
|
|
|
Using Bob's Eth-DM Public Key, retrieved via [10/WAKU2](/spec/13), Alice MAY now send an encrypted message to Bob.
|
|
|
|
|
|
|
|
If she wishes to do so, Alice MUST encrypt her message `M` using Bob's Eth-DM Public Key `B'`.
|
|
|
|
|
|
|
|
The result of the encryption is as follows
|
|
|
|
(see [eth-crypto's encryptWithPublicKey](https://www.npmjs.com/package/eth-crypto#encryptwithpublickey)):
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"iv": "...",
|
|
|
|
"ephemPublicKey": "...",
|
|
|
|
"ciphertext": "...",
|
|
|
|
"mac": "..."
|
2021-05-07 00:43:24 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
Alice MUST then set this result in a Direct Message's property `encMessage`,
|
|
|
|
with Bob's Ethereum address `B` set to property `toAddress`.
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"toAddress": "...",
|
|
|
|
"encMessage": {
|
|
|
|
"iv": "...",
|
|
|
|
"ephemPublicKey": "...",
|
|
|
|
"ciphertext": "...",
|
|
|
|
"mac": "..."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2021-05-07 00:43:24 +00:00
|
|
|
|
2021-06-23 01:52:21 +00:00
|
|
|
Alice SHOULD now publish this message on the Direct Message content topic.
|
2021-05-07 00:43:24 +00:00
|
|
|
|
|
|
|
# Copyright
|
|
|
|
|
|
|
|
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
|