0

I want to convert a TRON address in the HEX format into Base58 one without TronWeb. I can't use JS or Python either. I want to understand the algorithm to then implement it in a language of my choice.

As per https://github.com/tronprotocol/documentation/blob/master/TRX/Tron-overview.md#62-mainnet-addresses-begin-with-41

//(1)
address = 41||sha3[12,32): 415a523b449890854c8fc460ab602df9f31fe4293f 

//(2)
sha256_0 = sha256(address): 06672d677b33045c16d53dbfb1abda1902125cb3a7519dc2a6c202e3d38d3322 

//(3)
sha256_1 = sha256(sha256_0): 9b07d5619882ac91dbe59910499b6948eb3019fafc4f5d05d9ed589bb932a1b4 
checkSum = sha256_1[0, 4): 9b07d561 
addchecksum = address || checkSum: 415a523b449890854c8fc460ab602df9f31fe4293f9b07d561 

//last step
base58Address = Base58(addchecksum): TJCnKsPa7y5okkXvQAidZBzqx3QyQ6sxMW

However, SHA3-256 applied to 415a523b449890854c8fc460ab602df9f31fe4293f won't generate anything remotely similar to

//(2) 
06672d677b33045c16d53dbfb1abda1902125cb3a7519dc2a6c202e3d38d3322` 

For instance, using an online converter

https://md5calc.com/hash/sha3-256/415a523b449890854c8fc460ab602df9f31fe4293f

SHA3-256(415a523b449890854c8fc460ab602df9f31fe4293f)

will produce

64a35f3345223990cc06d1b356e5ac7421f5e15f4dbe0fd934957fb9f0aab76e

and there's no part in it iidentical to the one in TRON documenation.

What's the matter?

update1

The 1st 2 commands have produced the correct results after I've replace HEX representation with the bytes.

But the //last step still hasn't:

//actual HEX string, not bytes

Base58.encode("415a523b449890854c8fc460ab602df9f31fe4293f9b07d561") 

===> 

eJJL2m8pSeN7rACLEzRb5JMoJsZSXfFLZgGmC6LbKpdrALZMqKW6MDShkwh5xotJX4vc
Kon
  • 33
  • 1
  • 5
  • You should hash the bytes and not the hexadecimal string representation of the bytes – MSpiller Jan 16 '23 at 15:13
  • @M.Spiller Ok. The 1st 2 commands have produced the correct results. But the 3rd one not. `Base58.encode("415a523b449890854c8fc460ab602df9f31fe4293f9b07d561")` ===> `eJJL2m8pSeN7rACLEzRb5JMoJsZSXfFLZgGmC6LbKpdrALZMqKW6MDShkwh5xotJX4vc` – Kon Jan 16 '23 at 16:31
  • I'm using a HEX representation of the bytes for `Base58.encode(...)` because this is what has to be used there. Right? – Kon Jan 16 '23 at 16:33
  • Same as above... No, you should work on the bytes, not on any string representation. The doc on github also links to a Java implementation. That should make it clear. – MSpiller Jan 16 '23 at 16:36
  • @M.Spiller - finally! Victory! – Kon Jan 16 '23 at 16:39

0 Answers0