How to calculate the hash of an offstream data chunk?

+1 vote


I'm trying to calculate the hash of an offstream data chunk.

Executing storechunk "deadbeef" with MultiChain 2.0 alpha 3 returns the hash c5f5b0af4c574b80644f7079a447a6553ca714d63de77f866ebc566f0fd51d28. Digging through MultiChain's source code, I got the impression that this is the result of hashing the data two times with sha256. However, using these bash commands, I get a different result:
printf "deadbeef" | xxd -r -p | sha256sum | xxd -r -p | sha256sum

How is the hash calculated? What am I doing wrong?


asked Jul 28, 2018 by hendrikcech

1 Answer

0 votes
Best answer
You're almost there. Following bitcoin's tradition, MultiChain's API outputs hashes in little endian order, so the bytes (i.e. every pair of hexadecimal characters) are reversed.
answered Jul 30, 2018 by MultiChain
selected Aug 20, 2018 by hendrikcech
Thanks! For reference, this works:

$ printf "deadbeef" | xxd -r -p | sha256sum | xxd -r -p | sha256sum | fold -w2 | tac | tr -d '\n' | awk '{print $2}'
Great - thanks for making this available. Also note that on some versions, sha256sum will output more than just the hash, so you might need to add this into the series of operations:

head -c 64