Hey everyone. Just curious if there's a tool or script to get the uncompressed public key from a Bitcoin address. Heard you can find it if the address has sent funds but I'm lost on how to do this. Any help is appreciated. Thanks!
Methods for uncovering the public key of a Bitcoin address
23 replies 278 views
So the deal is that a Bitcoin address is basically a hash of the public key. And since hashing is a one-way street, there’s no way to reverse it. When you send bitcoins, you're signing a message with your private key and this reveals your public key to let others verify you have rights to those coins.
I think I asked about this before.
Just want to point out that in a P2PKH transaction, the signature script includes the signature followed by the public key. Extract the sigscript, find the signature, and look for OP_Pushbytes_65 (that’s the uncompressed key in hex). You can write a script to get the public key from there.
That's interesting but I thought sigscript was the only way to get it.
Quick note: the full public key is actually 130 characters. Is the lead 65 characters the x-value or what?
If an address hasn’t spent any coins, its public key stays hidden. The public key is hashed to create the address. Here’s basically how it works:
1. Generate a 256-bit private key.
2. Use ECDSA for the public key (which is usually compressed).
3. Hash the public key multiple times to get the address.
Yeah, I'm talking about addresses that have spent coins, so the public key is out there.
Checking this address: 1MsHWS1BnwMc3tLE8G35UXsS58fKipzB7a
Here’s the TXID: 3410bc9f7671d30225678a870f8d695cad1af6f64b0a319a487d3b86540794ab
The ScriptSig looks like this: 48 gives you the signature, and then you get the 41 for the public key. Pretty straight-up.
So the public key is the last 130 characters, right?
I'm trying to figure out how to reverse it get the address from an uncompressed public key. Any tips on how to make sure the public key I’m gathering is right?
You can use a tool for that. Just ignore the private key box and put your public key in the right spot. It'll walk you through the steps and spit out the address.
A full public key equals 130 hexadecimal characters, while a compressed one is 66 hexadecimal characters. The coords don’t just pop out, you have to derive them based on whether y is even or odd.
This is helpful but I’m struggling. When I pull the last 130 hex from a transaction and use these tools, it often doesn't relate to the address or is an invalid key.
Are you sure it's uncompressed? Most keys are compressed nowadays, so look for 66 characters. Could you show a transaction example?
Just saying... if you're jumping into random transactions, you’ll keep getting confused. Start by learning transaction structures and Bitcoin scripts first.
pixel_stakeSenior Member
Posts: 23 · Reputation: 1132
#16Jul 27, 2023, 12:11 AM
Let’s look at this recent transaction:
Check the sigscript: the last 130 chars didn’t start with '04', so it’s not uncompressed. Surprising, considering how recent it is. Then we check the last 66 chars which started with '02', indicating it’s likely compressed.
Thanks for clarifying. If I have a transaction where I see no output, how do I get the public key if I only have a HASH160?
Be careful! You can only derive a public key if an address has output transactions. If it hasn't sent BTC, you’re outta luck.
pixel_stakeSenior Member
Posts: 23 · Reputation: 1132
#19Jul 27, 2023, 09:44 AM
Hash algorithms aren't reversible, so you can't nail down the public key from a hash directly.
Alright.