Pattern β : Bob hasn't done the initial DMTP setup
Until Bob finishes the initial setup, the messages to Bob are encrypted with the shared key (Alice & DMTP) and stored. At this time, the messages are not E2EE and we (DMTP) can see the messages.
Once Bob finishes the initial setup and generates keys, DMTP encrypts the messages with the shared key (Bob & DMTP) and delivers it to Bob. Bob re-encrypts the messages with the shared key (Alice & Bob). Finally, those messages are stored in DB and others encrypted with the DMTP shared key are deleted. This makes them E2EE and no one can decrypt them. even later.
Now let's take a look at the detailed flow
Sending Messages
DMTP server verifies the signature and prove that DMTP key pair haven't been manipulated.
Alice client retrieves
DMTP's pubKey
from the DBAlice decrypts
Alice’s DMTP_priKey
with her wallet.Alice generates the
combined secret
fromAlice’s DMTP_priKey
andDMTP’s DMTP_pubKey
Alice encrypts messages with
combined key (Alice & DMTP)
Store the
encrypted messages
in the DB and IPFSThe data to be stored will look something like this.
The CID of message data is stored in
Message
table in DB andCID
table in DB【Messages Table】 ⇒ CID
【CIDs Table】 ⇒ [CID, CID, CID, CID, CID, CID]
The Message table is stored in
Processing Chats
in 【Users Table】【Users Table】⇒
Processing Chats
[ Room ID, Room ID, Room ID]Periodically, sync all data in
CID
table to IPFS and get CIDAll CIDs are stored in this file
This CID is stored in the blockchain (Polygon)
After Bob's initial DMTP setup is complete
Once Bob's initial DMTP setup is complete, DMTP server retrieves all message data and Bob's DMTP_pubKey
DMTP server verifies the signature and prove that DMTP key pair haven't been manipulated.
DMTP server generates the combined key from
DMTP’s priKey
andAlice's DMTP_pubKey
and decrypts all messages with that.DMTP server generates the combined key from
DMTP’s priKey
&Bob's DMTP_pubKey
,and encrypts all messages with that. The encrypted message is updated in DBBob client retrieves the encrypted message (DMTP & Bob) & DMTP key pair
Decrypts
the encrypted DMTP_priKey
withBob’s priKey
Generates
the combine secret
fromBob’s DMTP_prikey
&DMTP’s DMTP_pubKey
Use
the combined secret(Bob & DMTP)
to decrypt all messagesGenerates
the combine secret
fromBob’s DMTP_prikey
&Alice’s DMTP_pubKey
Use
the combined secret (Alice & Bob)
to decrypt all messages
Update message data stored in DB
Store new message data in IPFS and get CID
Store CID in DB
Periodically, sync all data in
CID
table to IPFS and get CIDAll CIDs are stored in this file
This CID is stored in the blockchain (Polygon)
Last updated