Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Private messaging between addresses #283

Open
Endogen opened this issue Jan 25, 2023 · 0 comments
Open

Feature Request: Private messaging between addresses #283

Endogen opened this issue Jan 25, 2023 · 0 comments

Comments

@Endogen
Copy link

Endogen commented Jan 25, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant