I am attempting to create a 2 of 3 multi-sig address in C++. The example I am using is from
http://www.soroushjp.com/2014/12/20/bitcoin-multisig-the-hard-way-understanding-raw-multisignature-bitcoin-transactions/. I generate the script okay with the keys provided. But when I generate the address, it is wrong.
Briefly in psuedocode I am trying to do this:
We define intermediate with:
intermediate = 5 concat ( ripemd( sha256( script_bytes ) ) )
Then the address is encodeBase58( intermediate concat sha256( sha256( intermediate ) )[0..3] )
Is this psuedocode wrong? Here is the C++ code:
hash_digest lh0 = generate_sha256_hash(calculated_script);
data_chunk d1;
for (int i = 0; i < lh0.size(); ++i)
d1.push_back(lh0[i]);
short_hash sh2 = generate_ripemd_hash(d1);
data_chunk d3;
data_chunk& addy= d3;
d3.push_back((unsigned char)5);
for (int i = 0; i < sh2.size(); ++i)
d3.push_back(sh2[i]);
hash_digest lh4 = generate_sha256_hash(d3);
data_chunk d5;
for (int i = 0; i < lh4.size(); ++i)
d5.push_back(lh4[i]);
hash_digest lh6 = generate_sha256_hash(d5);
for (int i = 0; i < 4; ++i)
d3.push_back(lh6[i]);
calculated_address = encode_base58(addy);
I am looking at this page and the code I have here, they look the same. The addresses do not match in the end though.