Skip to content

Feature Request: Private messaging between addresses #283

@Endogen

Description

@Endogen

Allow sending encrypted on-chain messages from one address to another via wallet.

  1. Extend wallet so that user1 can enter a cleartext message and a recipient address (user2)
  2. Cleartext message gets encrypted by recipient address
  3. Encrypted message gets submitted to contract con_message_store (just an example)
storage = Hash()

@export
def store_msg(recipient_address: str, msg: str):
    td = now - datetime.datetime(1970, 1, 1, 0, 0, 0)
    storage[recipient_address, td.seconds] = msg
  1. Wallet of user2 receives new transaction from block service
  2. Wallet checks incoming tx
  3. If tx is successful and contract_name = con_message_store and function = store_msg and param recipient_address matches one of the existing addresses in the wallet
  4. Decrypt content of param msg with private key of matching address
  5. If successful, save message in cleartext, together with sender address of tx, in message list (new view in wallet) and notify user via browser notification

Encrypt message:

from nacl.public import SealedBox, PublicKey

receiver_address = input('Recipient address ')
receiver_address = PublicKey(bytes.fromhex(receiver_address))

plaintext_msg = input('Cleartext msg ')
plaintext_msg = plaintext_msg.encode('utf-8')

sealed_box = SealedBox(receiver_address)
encrypted = sealed_box.encrypt(plaintext_msg)
print('Encrypted msg', encrypted.hex())

Decrypt message:

from nacl.public import SealedBox, PrivateKey

own_privkey = input('Own private key ')
own_privkey = PrivateKey(bytes.fromhex(own_privkey))

encrypted = input('Encrypted msg ')

sealed_box = SealedBox(own_privkey)
plaintext = sealed_box.decrypt(bytes.fromhex(encrypted))
print('Decrypted msg', plaintext.decode('utf-8'))

Thanks https://t.me/OnlyLuck77 for simplified SealedBox code!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions