I am engaged on an Altcoin, and I am getting totally different hashes for a similar hex string when hashed utilizing the HashWriter class of the bitcoin core code (27.99) and when hashed with the bcrypto lib of the JavaScript.
The difficulty is simply with the hex
strings, whereas numbers
when hashed their hashes are matching and no issues (this proofs that the identical hashing algorithm is utilized in each bitcoin core code and the bcrypto lib in JS
).
For numbers:
C++:
uint32_t timestamp = 1737835291;
HashWriter{} << st.timestamp).GetHash().GetHex(); // leads to (85b76e3a3eeff7da605b5de8349aaee931965d611fd903cb33146982e61cbb28)
JavaScript:
bcrypto.hash256(intToBytes(1737835291)).reverse().toString("hex"); // leads to (85b76e3a3eeff7da605b5de8349aaee931965d611fd903cb33146982e61cbb28)
For hex strings:
C++:
std::string hexString = "073ff90209cde3a9ce4ccd23598fd1b50e6a1fe34f30bd7240587f0bde6f65af";
(HashWriter{} << hexString ).GetHash().GetHex(); leads to (73e21e5a9038727c61aeee89c899bd45d7e935a306ede80388de131a99e14a75)
JavaScript:
bcrypto.hash256(Buffer.from("073ff90209cde3a9ce4ccd23598fd1b50e6a1fe34f30bd7240587f0bde6f65af", "hex")).reverse().toString("hex"); leads to (1ec6958d1fae90326d8abe7eb9950de366262ff80a730641a6acdac5dfc4ddfe) which is differs from the results of the C++
I’ve used a web based software to examine the hash of the hex (073ff90209cde3a9ce4ccd23598fd1b50e6a1fe34f30bd7240587f0bde6f65af
) and obtained a outcome that matches the results of the JavaScript (1ec6958d1fae90326d8abe7eb9950de366262ff80a730641a6acdac5dfc4ddfe
)
I’ve additionally manipulated the hex strings encoding (hex
, utf8
/ascii
) in each C++ and JavaScript and I could not discover a matching level between the resulted hashes of the 2 codes.
I’ve tried (Within the JavaScript code) to reverse the bytes of the hex string earlier than hashing it, and this leads to a special hash however nonetheless not matching the C++ hash.
Why this occurring and tips on how to get the identical hash of the hex string in each codes?
Thanks,,,