Generation of DMTP key pairs

First you connect your wallet to DMTP, you have to do initial setting. The initial set up has two flows「Generate DMTP key pair」and 「Sign to DMTP key」

Generate DMTP key pair

You have to generate DMTP key pair that are used to encrypt and decrypt messages. These keys are not directly related to the wallet keys, so you don't have to care the risk of compromising your wallet. DMTP key pair are generated by the algorithm of Elliptic Curve Diffie-Hellman. DHKE generates key pair public key and private key as same as the normal public key encryption. In this model, combined secret generated by (Alice's pubKey & Bob's priKey) and (Alice's priKey & Bob's pubKey) will be same. This model realizes the E2EE model of P2P messaging. DMTP client generates these key pair automatically, so you don't need do any special setting at this section.

From security perspective we shouldn't store DMTP_priKey low data. Thus users encrypt it with public key of their wallet so only wallet holder can decrypt it and see messages.

Sign to the DMTP_pubKey

In this section you sign to the DMTP_pubKey to prove that the wallet address of yours andDMTP_pubKey of yours are actually linked.

DMTP_pubKey encrypted DMTP_priKey signature are stored in DB. We describe you the detailed flow using some diagrams and code.

Flow

  1. Alice connect her wallet to DMTP

  2. Client generates DMTP key-pair that is used for en/de crypt messeges in DMTP. We name them DMTP_pubKey and DMTP_priKey.

  3. Alice encrypts her DMTP_priKey with her wallet's public key.

  4. Alice sign DMTP_pubKey with her wallet. This signature proves DMTP_pubKey is linked to Alice’s wallet.

  5. Store DMTP_pubKey & encrypted DMTP_priKey & Signature in DB and IPFS The stored data is like this.

    {
      "DMTPpubKey": "DMTP_PUBLIC_KEY",
      "DMTPpriKey": "ENCRYPTED_DMTP_PRIVATE_KEY",
      "Signature": "SIGNATURE",
    }
  6. Store the CID of keys in the blockchain and DB The CID of keys is stored in DMTPkeys like this so anyone can find DMTP_pubkey from the contract.

    mapping(address => string) DMTPkeys;
    
    function addKey(address _user, string _cid)public onlyOwner{
      DMTPkeys[_user] = _cid
    }

Last updated