sha256 – Having points correctly producing a p2pkh tackle in Rust code. (for analysis functions not for actual use)

on

|

views

and

comments


I’ve adopted the steps to generate a p2pkh compressed base58 tackle and am persistently checking it to search out that I get an invalid checksum.

I’m utilizing this python code to verify the tackle:

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 tackle and the base58 compressed key. It appears to be doing the whole lot that on-line sources say to do, however it appears as if it generates invalid checksums. I attempted to verify it towards some on-line instruments however all of them appeared to generate invalid hashes or inconsistent outcomes with each-other.

Share this
Tags

Must-read

Waymo raises $16bn to gas international robotaxi enlargement | Know-how

Self-driving automobile firm Waymo on Monday stated it raised $16bn in a funding spherical that valued the Alphabet subsidiary at $126bn.Waymo co-chief executives...

Self-driving taxis are coming to London – ought to we be anxious? | Jack Stilgoe

At the top of the nineteenth century, the world’s main cities had an issue. The streets had been flooded with manure, the unintended...

US regulators open inquiry into Waymo self-driving automobile that struck youngster in California | Expertise

The US’s federal transportation regulator stated Thursday it had opened an investigation after a Waymo self-driving car struck a toddler close to an...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here