Bitcoin core code (27.99) HashWriter hex strings problem
I'm working on an Altcoin, and I'm getting different hashes for the same hex string when hashed using the HashWriter class of the bitcoin core code (27.99) and when hashed with the bcrypto lib of the JavaScript.
The issue is only with the hex
strings, while numbers
when hashed their hashes are matching and no problems (this proofs that the same hashing algorithm is used in both bitcoin core code and the bcrypto lib in JS
).
For numbers:
C++:
uint32_t timestamp = 1737835291;
HashWriter{} << st.timestamp).GetHash().GetHex(); // results in (85b76e3a3eeff7da605b5de8349aaee931965d611fd903cb33146982e61cbb28)
JavaScript:
bcrypto.hash256(intToBytes(1737835291)).reverse().toString("hex"); // results in (85b76e3a3eeff7da605b5de8349aaee931965d611fd903cb33146982e61cbb28)
For hex strings:
C++:
std::string hexString = "073ff90209cde3a9ce4ccd23598fd1b50e6a1fe34f30bd7240587f0bde6f65af";
(HashWriter{} << hexString ).GetHash().GetHex(); results in (73e21e5a9038727c61aeee89c899bd45d7e935a306ede80388de131a99e14a75)
JavaScript:
bcrypto.hash256(Buffer.from("073ff90209cde3a9ce4ccd23598fd1b50e6a1fe34f30bd7240587f0bde6f65af", "hex")).reverse().toString("hex"); results in (1ec6958d1fae90326d8abe7eb9950de366262ff80a730641a6acdac5dfc4ddfe) which is differs from the result of the C++
I have used an online tool to check the hash of the hex (073ff90209cde3a9ce4ccd23598fd1b50e6a1fe34f30bd7240587f0bde6f65af
) and got a result that matches the result of the JavaScript (1ec6958d1fae90326d8abe7eb9950de366262ff80a730641a6acdac5dfc4ddfe
)
I have also manipulated the hex strings encoding (hex
, utf8
/ascii
) in both C++ and JavaScript and I couldn't find a matching point between the resulted hashes of the two codes.
I have tried (In the JavaScript code) to reverse the bytes of the hex string before hashing it, and this results in a different hash but still not matching the C++ hash.
Why this happening and how to get the same hash of the hex string in both codes?
Thanks,,,
from Recent Questions - Bitcoin Stack Exchange https://ift.tt/GXeSgYp
via IFTTT