I’ve adopted the steps to generate a p2pkh compressed base58 deal with and am constantly checking it to search out that I get an invalid checksum.
I’m utilizing this python code to examine the deal with:
import base58
adr="1AMGLbW71pvdMuRWkDdmZWibmzRkxa6LVt"
adr160 = base58.b58decode_check(adr).encode('hex')[2:]
print(adr160)
Right here is the Rust operate to hash a public key:
fn hashPubKey(publicKeyStr: String) -> (String, String)
{
let sha256_1 = digest(publicKeyStr.as_bytes());
let mut ripemd160 = Ripemd160::new();
ripemd160.replace(sha256_1.as_bytes());
let ripe = format!("{:x}", ripemd160.finalize());
let network_byte_key = format!("{:0>42}", ripe.clone());
let sha256_2 = digest(network_byte_key.as_bytes().clone());
let sha256_3 = digest(sha256_2.as_bytes());
let mut checksum = String::new();
for i in 0..8
{
checksum.push(sha256_3.chars().nth(i).unwrap());
}
let checkKey = network_byte_key.clone() + &checksum;
let pubkeyint = big_hex::hex_to_int(checkKey.clone());
let compressedKey = base58_encode(pubkeyint.clone());
let pubkeyint_check: BigInt = base58_decode(compressedKey.clone());
assert!(pubkeyint == pubkeyint_check, "error in base58 encoding/decoding");
return (ripe, compressedKey);
}
The operate returns the hash160 deal with and the base58 compressed key. It appears to be doing every part that on-line assets say to do, however it appears as if it generates invalid checksums. I attempted to examine it in opposition to some on-line instruments however all of them appeared to generate invalid hashes or inconsistent outcomes with each-other.