What is the algorithm used to encode Bech32 address? Is it sha256? When calculated it is different

Hi friends,

Why is my Bech32 address that I hash is different from Typescript SDK?
This is my Bech32 address:
fuel1hsz5yuunlese5r7fnt9eyw9ha5qwwugc64m72slv4a5zwpkzja0sq0prdn

I was playing with the Fuel dAPP example from typescript and noticed that the displayed address is this. Is it sha256 encoded? I used cyberchef, and apparently the address is completely different. Did I hash it incorrectly?
0xbc05427393fe619a0fc99acb9238b7ed00e77118d577e543ecaf682706c2975f

Fuel Blockchain design the address documentation.

Cyberchef Hash

There are a couple of reasons why your Bech32 address might be different from the one generated by the Typescript SDK:

  1. Hashing vs. Encoding: Bech32 addresses are not created by simply hashing a public key. They involve a specific encoding scheme that combines parts of the public key with a human-readable prefix to improve error detection. While SHA256 hashing might be a step involved in the process, it’s not the sole method.
  2. Checksum: Bech32 addresses include a checksum to detect typos or errors during address transmission. The Typescript SDK likely implements the correct logic to generate the checksum, whereas your hashing method might be missing this step.
  3. Library Differences: The Typescript SDK might be using a specific library for Bech32 address generation that follows the Fuel Blockchain’s address documentation. Your manual hashing approach might not be following the same standards.

Here’s what you can do to resolve the discrepancy:

  • Consult Fuel Blockchain Documentation: Refer to the official Fuel Blockchain documentation for Bech32 address generation. This will provide the exact steps and libraries recommended for creating valid addresses.
  • Use the Typescript SDK Function: If the SDK provides a function for generating Bech32 addresses, it’s recommended to use that function as it will ensure adherence to Fuel Blockchain’s specifications.
  • Debug Your Hashing Method: If you’re set on manually generating the address, double-check your hashing method to ensure it follows the Bech32 encoding scheme, including checksum generation. Consider using a library specifically designed for Bech32 encoding/decoding.

By following these steps, you should be able to generate a Bech32 address that matches the one produced by the Typescript SDK.

1 Like

Ah makes sense, it would be awesome to have the steps to reverse engineer in the documentation.