import bech32
wallet_address = "rdx1q...."
_hrp, wallet_readdr_5bit = bech32.bech32_decode(wallet_address)
wallet_readdr = bech32.convertbits(wallet_readdr_5bit, 5, 8, pad=False)
# Remove the Radix Engine Address 04 prefix byte
wallet_public_key = wallet_readdr[1:34]
print("Wallet Public Key:", bytes(wallet_public_key).hex())
Is this also the correct way to validate an Radix address? Is there any other methods to check to make sure an Radix address is valid or not?
The Bech32 algorithm has 6 character checksum that “gives a chance of less than 1 in a billion that an invalid address is deemed correct”.
So given a Radix wallet address, you can validate it by using the Bech32 decode function and then:
- Checking the data part is 34 bytes long
- Checking that the first byte is
04
- which defines it as a Radix Engine Address - Checking that the second byte is either
02
or03
- to indicate that it is a compressed public key
Further Reading:
https://medium.com/@meshcollider/some-of-the-math-behind-bech32-addresses-cf03c7496285
Thanks for your reply, I also add the checking for _hrp (returned by method bech32_decode) to make sure it is “rdx”
here are the hrp’s of addresses olympia-node/radixdlt-java-common/src/main/java/com/radixdlt/networks/Network.java at main · radixdlt/olympia-node · GitHub