-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
Allow sending encrypted on-chain messages from one address to another via wallet.
- Extend wallet so that user1 can enter a cleartext message and a recipient address (user2)
- Cleartext message gets encrypted by recipient address
- 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- Wallet of user2 receives new transaction from block service
- Wallet checks incoming tx
- If tx is successful and
contract_name=con_message_storeandfunction=store_msgand paramrecipient_addressmatches one of the existing addresses in the wallet - Decrypt content of param
msgwith private key of matching address - 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
Labels
No labels