So after searching for HOURS on here and overall on the internet, I haven't managed to find an answer to my question so I'll ask here.
So I've been trying to convert a public key into an address. I've been writing all the hashing algorithms, and tested them with online hashing websites, so they are working. Here is my code:
function getBTCAddress(public_key)
{
var __SHA = SHA256_hash(public_key);
console.log("__SHA: " + __SHA);
var RIPEMD = RIPEMD_160(__SHA);
console.log("RIPEMD_160: " + RIPEMD);
var new_SHA = SHA256_hash(RIPEMD.toString());
console.log("new_SHA: " + new_SHA);
var _new_SHA = SHA256_hash(new_SHA);
console.log("_new_SHA: " + _new_SHA);
var checksum = _new_SHA.slice(-8, _new_SHA.length);
console.log("checksum:" + checksum);
var almost_address = "00" + RIPEMD.toString() + checksum;
console.log("almost_address:" + almost_address);
var buffer = Buffer.from(almost_address, "hex");
return BS58.encode(buffer);
}
For some reason it is not giving me the proper results. I'm wondering, what are the exact steps of deriving an address from a public key?
For those of your who are wondering here is what my code is doing:
checksum = SHA256(SHA256(RIPEMD160(SHA256(public_key)))) <-- get last 8 bytes
almost_address = 0x00 (network byte) and RIPEMD160(SHA256(public_key)) and checksum <-- compacted into 1 string
address = base58(almost(address)