HomePhabricator

[Cashtab] Option to send encrypted messages

Description

[Cashtab] Option to send encrypted messages

Summary:
This diff builds on the standardized prefix approach in D10628 by introducing a Cashtab encryption prefix prior to the encrypted hex. The encryption prefix flags whether this OP_RETURN message has been encrypted or not.

The ecies-lite library is used, which is an elliptic curve cryptography library that encrypts and decrypts messages using the same eliptic curve cryptography used by Bitcoin.

End to end encryption summary:

Sender's side

  1. Send.js flags to useBch() whether the user wants to encrypt the message or not.
  2. If the encryption flag is true, useBCH.js' sendXec() function retrieves the public key corresponding to the recipient's address and then calls on ecies-lite to encrypt the message based on that public key.
  3. The encrypted string is then added to the OP_RETURN script after all the preceding prefixes.

Recipient's side

  1. As a routine tx history update, useBCH.js' parseTx() function checks if the message is an encrypted cashtab message, and if so, extract the encrypted string from the output hex, which should match the string from step 3.
  2. The ecies-lite library is then called to decrypt the encrypted message using the recipient's private key. The private key is obtained via wallet.state.slpBalancesAndUtxos.nonSlpUtxos[0].wif
  3. If the encryption is successful, the decrypted message is sent up to Tx.js for rendering. Otherwise, it is assumed the user is not authorised to view the message, which is then overwritten by a default placeholder text for Tx.js.

Sample breakdown of output hex

6a = OP_RETURN
04 = bytecount
65746162 = cashtab encryption prefix
4c = OP_PUSHDATA1
91 = bytecount
0422609b9c1ee6dd93cd332edcb809c326c14b3f663a47556ae6d7d8a6e2cd6f7ecebcff96d6de0bf697353edbf98bd792ca1e6b3842251d4c95cd3ba7856bc794e9f82a8f443681c2cb2366794b760515f58942ce880923eb084ed80c216cd256265c2e608ae20db6d53c51f954049dfdd106bfcd800936c3353f7182469326aa38d6b427d68335466b87c1abaeda275d = encrypted message

Test Plan:
npm start

  1. send a normal XEC tx with no message to ensure no regression
  2. send an unencrypted message from wallet A to wallet B, ensure no regression and both wallets can view the message in tx history
  3. send an encrypted message from wallet A to wallet B, ensure only wallet B can view the decrypted message in tx history and that wallet A sees an "Only the message recipient can view this" message in red italics, and wallet B sees the decrypted message in normal black font.
  4. send a short 3 character message in encrypted mode to wallet B
  5. send a long 94 character message in encrypted mode to wallet B
  6. input a 160 character message in unencrypted mode then switch to encrypted mode and ensure the input is truncated up to the allowed 94 character limit. Send this message and ensure the underlying message sent is the 94 character message.
  7. Repeat step 5 except send it in unencrypted form and ensure the full 160 characters is sent despite switching to the truncated encrypted view.
  8. send an encrypted message to a newly created wallet with no transactions and ensure the 'Cannot send an encrypted message to a wallet with no outgoing transactions' error is displayed.
  9. send an encrypted message to a newly created wallet with incoming transactions but no outbound transactions and ensure the 'Cannot send an encrypted message to a wallet with no outgoing transactions' error is displayed.
  10. use the newly created wallet to send an outbound XEC transaction. Then ensure wallet A is able to now successfully send an encrypted message to this newly created wallet and wallet B can decrypt successfully.
  11. send an encrypted message from wallet A to wallet A, ensure wallet A can view an encrypted message to itself in tx history
  12. switch to multiple recipients mode and ensure the encryption switch and the alert is not rendered
  13. send multi recipient tx and ensure no unintended encryption
  14. send multi recipient tx with a message and ensure no unintended encryption
  15. check the TX ID for one of the above encrypted messages in blockchain, abc explorer and be.cash explorer, and ensure the message is not legible

Reviewers: bytesofman, #bitcoin_abc

Reviewed By: bytesofman, #bitcoin_abc

Subscribers: hungsam

Differential Revision: https://reviews.bitcoinabc.org/D10692

Details

Provenance
emackAuthored on Dec 18 2021, 03:06
emackPushed on Dec 30 2021, 11:05
Reviewer
Restricted Project
Differential Revision
D10692: [Cashtab] Option to send encrypted messages
Parents
rABC384c87d0a66c: [Automated] Update timing.json
Branches
Unknown
Tags
Unknown