Back to: How To Secure Messages On EOS
Read from messages
table, if to
matches read_msg_to
, decrypt a message and then delete it.
def read_and_delete_msg(private_key_file, read_msg_to): privkey_bytes = read_privkey_file(private_key_file) privkey = keys.UmbralPrivateKey.from_bytes(privkey_bytes) payload = '{"scope":"' + DEFAULT_ACCOUNT + '","code":"' + DEFAULT_ACCOUNT + '","table": "' + DEFAULT_TABLE+ '", "json":"true"}' response = requests.request("POST", DEFAULT_URL, data=payload) found = False for msg in response.json()['rows']: if msg['to'] == read_msg_to: ciphertext = msg['ciphertext'] capsule = msg['capsule'] msg_id = msg['msg_id'] found = True break if found: capule = pre.Capsule.from_bytes(bytes.fromhex(capsule), privkey.params) cleartext = pre.decrypt( ciphertext = bytes.fromhex(ciphertext), capsule = capule, decrypting_key = privkey) print('Cleartext: {}'.format(cleartext)) print('Deleting msg_id: {}'.format(msg_id)) data = '{"to":"' + read_msg_to + '", "msg_id":"' + str(msg_id) + '"}' subprocess.call(['cleos', 'push', 'action', DEFAULT_ACCOUNT, 'deletemsg', data , '-p', read_msg_to])