Stuart
(Stuart | RadixPool)
29 December 2021 19:09
1
The Radix Desktop Wallet expects messages to be hex encoded strings prefixed with 0000
For example, to send a message that will display as Hello
in the wallet, you could use the following python snippet:
"0000" + "Hello".encode('utf-8').hex()
# '000048656c6c6f'
The message field in your transaction would be: 000048656c6c6f
Message Prefix explained:
Message Type (Byte 1):
00 → Plaintext/Unencrypted
01 → Encrypted
Encryption Scheme (Byte 2):
00 → None
FF → DH_ADD_EPH_AESGCM256_SCRYPT_000
So a prefix of 0000
means a plaintext message with no encryption scheme.
minhnn
(minhnn | EasyStake.net)
31 December 2021 15:41
2
Hi Stuart, how could I use the encrypt method DH_ADD_EPH_AESGCM256_SCRYPT_000 ? could you give some python example to encrypt and decrypt the message ?
Stuart
(Stuart | RadixPool)
31 December 2021 16:11
3
I’m working on that right now
It uses a form of Elliptic Curve Integrated Encryption Scheme (ECIES) where an ephemeral key, the private key of the sender, and the public key of the receiver are combined to encrypt/decrypt the message. As soon as I have some working code I’ll create howto post.
The relevant code in Typescript from the radixdlt/radixdlt-javascript repo is in this file: messageEncryption.ts
And here’s a StackOverflow posting by the RadixDLT dev who created the scheme:
minhnn
(minhnn | EasyStake.net)
1 January 2022 17:41
4
Thanks, I will have a look at your link soon. Btw do you know which Java file also implement this encrypt/decrypt in the GitHub - radixdlt/olympia-node: Radix monorepo Java implementation?
Stuart
(Stuart | RadixPool)
1 January 2022 18:06
5
I couldn’t find a Java implementation in the GitHub - radixdlt/olympia-node: Radix monorepo unfortunately. It looks like there is only a Typescript implementation.
The good news is that I have figured out how to get decryption working with Python
I’m just working on the encryption now which shouldn’t take long and then I’ll write some howto posts.
minhnn
(minhnn | EasyStake.net)
1 January 2022 18:49
6
Thanks a lot, and I am looking forward to your howto post.
Stuart
(Stuart | RadixPool)
1 January 2022 19:24
7
Part 1: Decrypting Encrypted Messages
How to decrypt an encrypted transaction message created by the Radix Wallet
0. Introduction
The encryption scheme used by the Radix Wallet is called DH_ADD_EPH_AESGCM256_SCRYPT_000
Where:
DH → (Elliptic Curve) Diffie-Hellman (A key exchange protocol that allows untrusted parties to construct a shared secret)
ADD → Elliptic Curve Point Addition (The operation we use to create the shared secret)
EPH → Ephemeral Public Key (A temporary public key that is only used for the purpose of encrypting/d…
Part 2: Encrypting Messages
TODO: Explain process step by step
import os
import bech32
import ecdsa
import hashlib
from ecdsa.curves import SECP256k1
from ecdsa.keys import SigningKey, VerifyingKey
from Crypto.Protocol.KDF import scrypt
from Crypto.Cipher import AES
# Encrypted Message Parameters
plaintext_message=b"Hey Bob, this is Alice, you and I can read this message, but no one else."
alice_private_key_hex = "0000000000000000000000000000000000000000000000000000000000000001"
bob_wallet_address = "rdx1qspvvprlj3q76ltd…