Mailchain users can send messages to any Substrate account address. This section details how the Substrate implementation of the Message Flow is achieved.
Mailchain plans to support substrate networks that have the Contract Substrate Runtime Module Library enabled (srml_contracts).
To send an encrypted message, a public key is required. Mailchain uses the public key associated with an address to encrypt the data, and if specified by the envelope, the message contents. This ensures the recipient is also the owner of the private key and only they can decrypt data. The public key finder decodes a recipient address from base58 and extracting the public key (dropping the first byte and last two bytes before prepending '0x').
Field | Example |
Address (base58 encoded) |
|
Decoded Address (from Base58) |
|
Extracting Public Key |
|
Public Key |
|
The public key for an account address can either be calculated from an address or supplied by that account holder.
Using the same private key to generate addresses on different networks produces the same public key, but a different public address.
Mailchain uses the functionality provided by the Contract module (srml_contracts) `call` function which is similar to a standard Substrate transaction (signed extrinsic) with the addition of a data field (Vec<u8>). A substrate parachain (or parathread) with the Contract module enabled permits sending transactions with an envelope containing a message.
Contract transactions (signed calls) contain a data
field that stores the envelope. Bytes can be stored in the data
field and must be hexadecimal encoded, prefixed with 0x
. Data stored in a transaction must follow the Mailchain standard encoding format:[protocol-prefix]+[mailchain-prefix]+[envelope]
.
​
Field | Example | Notes |
protocol-prefix | 0x | Required Contract SRML |
mailchain-identifier |
| "mailchain" encoded as hexadecimal |
envelope |
| Envelope encoded as hexadecimal |
TODO
An example of transaction data for a Mailchain message sent on Edgeware is as follows:
?????
The same transaction and data can be viewed on here on Subscan.
/TODO
To send a message the following transaction fields must be specified.
Once the fields have been populated, the extrinsic must be signed using the sender private key. The signed extrinsic bytes can then be transmitted to the substrate network over JSON-RPC using the Contract module call
function.
To read Mailchain messages for a specific address, Contract calls sent to that address need to be identified.
Substrate does not natively support an address index or similar functionality that identifies all transactions sent to or from a specific address. Third parties provide some of this information through a web interface (including Subscan.io) but as of August 2020, no APIs consistently provide a transaction index for received transactions and their data fields.
Transaction Indexer
Mailchain provides a simple transaction indexer which listens for transactions and filters mailchain messages for the recipient. Further details and instructions for running it can be found here: Substrate Transaction Indexer.
​
​