Bitcoin Forum
August 03, 2025, 07:41:13 PM *
News: Latest Bitcoin Core release: 29.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: My private key doesn't link to my corresponding bitcoin adddress - please help!  (Read 234 times)
Unaccomplished_fox (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 12


View Profile
November 12, 2024, 09:03:26 AM
Merited by OmegaStarScream (8)
 #1

Hello, I have a technical issue i'd really appreciate your help with. I've scoured the internet and forums to find a similar situation but I can't find one. I've tried my best to explain the situation as clearly as possible below but apologies in advance if i seem confused or an idiot......I am both!

I created a blockchain.info account/wallet in 2013 to which I sent a small amount of bitcoin. I received the bitcoin into to my wallet by making a bank transfer to the corresponding bitcoin address. I still have the confirmation email and can see the amount on the blockchain, which hasn't moved since I originally sent it. I can't remember if I had a blockchain.info wallet or an account as I didn't really understand the process at the time (and still barely do).

I recently retrieved my login details for blockchain.info and logged back into my blockchain account (now blockchain.com).

There is a zero bitcoin balance displayed under both the 'Account' and 'Defi Wallet' tabs. However, when i go to 'Settings' -> 'Wallets and Addresses' -> 'Imported Bitcoin addresses' there is my Bitcoin address and BTC balance displayed. Great so far!

Directly to the right of my displayed BTC balance i can then select Actions -> Manage -> Private Key. After clicking through the warning about not sharing my private key with anyone this brings up a box with QR code, Balance, Address (which matches my original confirmation email for the transfer and the address with the positive BTC balance), Private Key (WIF) and Private Key (Base-58). However, the balance on this box says 0 BTC even though the address directly below it (and on the 'Imported Bitcoin addresses' screen) has a positive BTC balance on it.

The address with the bitcoin balance is a legacy bitcoin address that starts with 1. The address definitely has a positive BTC on it. The corresponding WIF private key is 52 characters and starts with L.

So now i was slightly worried about getting access to my BTC because it was so long ago and i don't really understand the process. I tried to explain the situation to blockchain.com support but they either send generic responses or take forever to respond and don't seem to understand the situation....probably partly my fault as i don't really understand myself!

My next step after hours and hours of research was to try to sweep the private keys to an Exodus wallet. So i downloaded the android version and imported my private key from blockchain.com but it also says there is no BTC at the address corresponding to the private key. I tried both the WIF private key and the QR code.

I am now even more worried. I contacted Exodus support and they were responsive at least but once they realised it was an issue with my private keys from blockchain.com (and blockchain.com wasn't bothering to respond) they also stopped responding.

So that has lead me to this bitcoin forum and the hope that someone here understands and can help explain the situation.....and if i have any hope of retrieving my bitcoin? I am currently making my way through the five stages of grief and am somewhere between bargaining and depression.

I still have the wallet backup email from blockchain.info that says it includes all the information i need to restore my bitcoin balance, with a wallet.aes.json file attached. I have seen in some forums that there is a way to import this to restore the wallet. However, i'm not sure this will help because the wallet ID in the email matches the wallet ID of my blockchain.com account....so it seems like the wallet has already been imported? I have also read that legacy wallets were imported as Bitcoin addresses to blockchain.com when it changed from blockchain.info?

Is it possible for a private key to somehow not match the corresponding bitcoin address when blockchain.info moved across to blockchain.com?

I'd really appreciate if someone could help me or explain what has happened? Or any avenues i could explore?

This has been a real roller coaster of emotions from the joy of remembering my account details and seeing my bitcoin balance to the heartbreak of not having access to it. It is not a life changing amount but I am not a rich person and it would really appreciate any help someone can give.

I don't want to sell the bitcoin but I would like to have access to it to move it to a safe wallet. On blockchain.com it says 'Imported funds are not protected by your Recovery Phrase. To ensure these funds are secured, please transfer them directly into your wallet.' But i can't move it because the private key doesn't seem to match the corresponding address.

If you got this far thanks for reading and please let me know if you have any ideas what is going on. Even if it is to tell me i'm a confused idiot!

Cheers
LoyceV
Legendary
*
Offline Offline

Activity: 3752
Merit: 19436


Thick-Skinned Gang Leader and Golden Feather 2021


View Profile WWW
November 12, 2024, 09:14:44 AM
Last edit: November 12, 2024, 12:32:26 PM by LoyceV
Merited by OmegaStarScream (2), ABCbits (2), Charles-Tim (1)
 #2

I only read through your long story quickly. It helps to stick to the point.

Here's what I'd do: Stop messing with private keys on an online system!
Get another computer, download Tails OS. Install it on a USB stick. Boot from that stick. Start Electrum. Don't setup networking. Create a new wallet, choose "Import Bitcoin addresses or private keys". Type your private key, but start with p2pkh: in front of it. Check the Addresses tab: if it shows the same address that you saw has funds, it is the correct private key.
Once this works, you can do offline signing. But first, do all this. It's a bit of work, don't rush yourself, but it sure as hell beats making a mistake online and losing your coins.

¡uʍop ǝpᴉsdn pɐǝɥ ɹnoʎ ɥʇᴉʍ ʎuunɟ ʞool no⅄
OmegaStarScream
Staff
Legendary
*
Offline Offline

Activity: 3920
Merit: 6860


♻️ Automatic Exchange


View Profile
November 12, 2024, 09:24:38 AM
Merited by ABCbits (1)
 #3

Did exodus show you the address associated with the private key? Or they just said it doesn't contain any funds?

Have you also tried to double check a blockexplorer like Blockchair.com or mempool.space just to see if the address indeed contains the funds?

Here's is a visual guide to what Loyce has suggested above (only the part that involves setting up electrum and importing the keys):

https://bitcoinelectrum.com/importing-your-private-keys-into-electrum/



░░░░▄▄████████████▄
▄████████████████▀
▄████████████████▀▄█▄
▄██████▀▀░░▄███▀▄████▄
▄██████▀░░░▄███▀▀██████▄
██████▀░░▄████▄░░░▀██████
██████░░▀▀▀▀▄▄▄▄░░██████
██████▄░░░▀████▀░░▄██████
▀██████▄▄███▀░░░▄██████▀
▀████▀▄████░░▄▄███████▀
▀█▀▄████████████████▀
▄████████████████▀
▀████████████▀▀░░░░
 
 CCECASH 
 
    ANN THREAD    
 
      TUTORIAL      
Unaccomplished_fox (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 12


View Profile
November 12, 2024, 09:55:31 AM
Last edit: November 17, 2024, 09:08:39 PM by Mr. Big
 #4

Hi, thank you both for your replies - I really appreciate it.

Yes, I checked both those bitcoin explorers and there is a confirmed balance on the address. This exactly matches the balance shown on blockchain.com under my 'imported Bitcoin addresses', which is the same address shown in my private key window.

I'll buy a new usb stick tomorrow and try the desktop version of exodus as suggested. The simple steps and guide are really helpful.

I will let you know how I go.



...and to answer the first question - exodus on android didn't show me the address related to the private key I entered. After I entered my private key and hit enter it just said there were no funds at the BTC address (without giving me the BTC address to check if it matched)
OmegaStarScream
Staff
Legendary
*
Offline Offline

Activity: 3920
Merit: 6860


♻️ Automatic Exchange


View Profile
November 12, 2024, 11:04:40 AM
 #5

Hi, thank you both for your replies - I really appreciate it.

Yes, I checked both those bitcoin explorers and there is a confirmed balance on the address. This exactly matches the balance shown on blockchain.com under my 'imported Bitcoin addresses', which is the same address shown in my private key window.

I will let you know how I go.

I'm guessing you're referring to Loyce's suggestion? If so, then he never mentioned Exodus desktop. He was suggesting you use Electrum desktop and so does the guide I sent above.

░░░░▄▄████████████▄
▄████████████████▀
▄████████████████▀▄█▄
▄██████▀▀░░▄███▀▄████▄
▄██████▀░░░▄███▀▀██████▄
██████▀░░▄████▄░░░▀██████
██████░░▀▀▀▀▄▄▄▄░░██████
██████▄░░░▀████▀░░▄██████
▀██████▄▄███▀░░░▄██████▀
▀████▀▄████░░▄▄███████▀
▀█▀▄████████████████▀
▄████████████████▀
▀████████████▀▀░░░░
 
 CCECASH 
 
    ANN THREAD    
 
      TUTORIAL      
hosemary
Legendary
*
Offline Offline

Activity: 2842
Merit: 6313



View Profile
November 12, 2024, 11:53:11 AM
 #6

Any bitcoin private key can generate three types of addresses. A legacy address that start with 1, a nested segwit address that start with 3 and a native segwit address that start with bc1.
I don't know how exodus sweep works. Maybe, it only derives the segwit address from the private key and that's why it couldn't sweep your fund.

As suggested by LoyceV, you can use electrum. Electrum allows you to derive a legacy address from your private key and should give you access to your fund, if there's any.


Type your private key, but start with start with p2pkh: in front of it.
It may worth mentioning that electrum derives a legacy address from your private key, if you don't specify the script type and just enter the private key.

CLOUDBET
▀██████▄██████████████▐███████▌██████████████▄██████▀
▀████████████████▌█████████████▐████████████████▀
▀█████████▐█████████████████████████▌█████████▀
▐█████▌████████████▐█████▌████████████▐█████▌
█████████▐█████▌██▐█████▌██▐█████▌█████████
█████████▐█████▌███████████▐█████▌█████████
█████████▐█████▌███████████▐█████▌█████████
█████████▐█████▌███████████▐█████▌█████████
█████████▐█████▌██▐█████▌██▐█████▌█████████
▐█████▌████████████▐█████▌████████████▐█████▌
▄█████████▐█████████████████████████▌█████████▄
▄████████████████▌█████████████▐████████████████▄
▄██████▀██████████████▐███████▌██████████████▀██████▄
█████████████████████████████
 

 
WELCOME     
OFFER
█████████████████████████████
█████████████████████████████
 
 
  PLAY NOW  
Unaccomplished_fox (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 12


View Profile
November 12, 2024, 12:18:57 PM
 #7

Thanks again to you all. And, yes I meant I'll download Electrum desktop.

Currently having a few issues downloading tails OS for windows (from tails.net, which seems to be the latest official site) where it fails when using the 'Download Tails 6.9 USB image (1.5 GB)' button - basically times out and says site can't be reached. I also tried the BitTorrent download but step 2. verification fails. I'll investigate a bit more about the issues and hopefully get it to work soon.
LoyceV
Legendary
*
Offline Offline

Activity: 3752
Merit: 19436


Thick-Skinned Gang Leader and Golden Feather 2021


View Profile WWW
November 12, 2024, 12:37:25 PM
 #8

Currently having a few issues downloading tails OS for windows (from tails.net, which seems to be the latest official site) where it fails when using the 'Download Tails 6.9 USB image (1.5 GB)' button - basically times out and says site can't be reached.
For what it's worth: I get the same failure. Just try again later.

¡uʍop ǝpᴉsdn pɐǝɥ ɹnoʎ ɥʇᴉʍ ʎuunɟ ʞool no⅄
BitMaxz
Legendary
*
Offline Offline

Activity: 3696
Merit: 3391


Greediness makes you blind.


View Profile WWW
November 12, 2024, 02:24:59 PM
Merited by LoyceV (4)
 #9

Currently having a few issues downloading tails OS for windows (from tails.net, which seems to be the latest official site) where it fails when using the 'Download Tails 6.9 USB image (1.5 GB)' button - basically times out and says site can't be reached.
For what it's worth: I get the same failure. Just try again later.

The tails.net download link seems dead but there's alternative source from their old archive on torproject.org.

@Unaccomplished_fox
For alternative link, check this link below and then verify it from tails.net here: https://tails.net/install/download/index.en.html to make sure if it's genuine and safe.

- https://archive.torproject.org/amnesia.boum.org/tails/stable/

.
 betpanda.io 
 
ANONYMOUS & INSTANT
.......ONLINE CASINO.......
▄███████████████████████▄
█████████████████████████
█████████████████████████
████████▀▀▀▀▀▀███████████
████▀▀▀█░▀▀░░░░░░▄███████
████░▄▄█▄▄▀█▄░░░█▄░▄█████
████▀██▀░▄█▀░░░█▀░░██████
██████░░▄▀░░░░▐░░░▐█▄████
██████▄▄█░▀▀░░░█▄▄▄██████
█████████████████████████
█████████████████████████
█████████████████████████
▀███████████████████████▀
▄███████████████████████▄
█████████████████████████
██████████▀░░░▀██████████
█████████░░░░░░░█████████
███████░░░░░░░░░███████
████████░░░░░░░░░████████
█████████▄░░░░░▄█████████
███████▀▀▀█▄▄▄█▀▀▀███████
██████░░░░▄░▄░▄░░░░██████
██████░░░░█▀█▀█░░░░██████
██████░░░░░░░░░░░░░██████
█████████████████████████
▀███████████████████████▀
▄███████████████████████▄
█████████████████████████
██████████▀▀▀▀▀▀█████████
███████▀▀░░░░░░░░░███████
██████░░░░░░░░░░░░▀█████
██████░░░░░░░░░░░░░░▀████
██████▄░░░░░░▄▄░░░░░░████
████▀▀▀▀▀░░░█░░█░░░░░████
████░▀░▀░░░░░▀▀░░░░░█████
████░▀░▀▄░░░░░░▄▄▄▄██████
█████░▀░█████████████████
█████████████████████████
▀███████████████████████▀
.
SLOT GAMES
....SPORTS....
LIVE CASINO
▄░░▄█▄░░▄
▀█▀░▄▀▄░▀█▀
▄▄▄▄▄▄▄▄▄▄▄   
█████████████
█░░░░░░░░░░░█
█████████████

▄▀▄██▀▄▄▄▄▄███▄▀▄
▄▀▄█████▄██▄▀▄
▄▀▄▐▐▌▐▐▌▄▀▄
▄▀▄█▀██▀█▄▀▄
▄▀▄█████▀▄████▄▀▄
▀▄▀▄▀█████▀▄▀▄▀
▀▀▀▄█▀█▄▀▄▀▀

Regional Sponsor of the
Argentina National Team
LoyceV
Legendary
*
Offline Offline

Activity: 3752
Merit: 19436


Thick-Skinned Gang Leader and Golden Feather 2021


View Profile WWW
November 12, 2024, 02:56:37 PM
Merited by Cricktor (1)
 #10

That worked Smiley
Here's mine (scheduled to be deleted in 28 days): tmp.loyce.club/tails-amd64-6.9.img.
Code:
sha256sum  tails-amd64-6.9.img 
3e2f1ac3ecf7a93a12972ca1540d7ed986fc14e91b3061d87eecae8db15a448c  tails-amd64-6.9.img

And:
verify it from tails.net
Do it. There's no need to trust me or anyone but the official site.

¡uʍop ǝpᴉsdn pɐǝɥ ɹnoʎ ɥʇᴉʍ ʎuunɟ ʞool no⅄
Unaccomplished_fox (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 12


View Profile
November 13, 2024, 02:00:34 AM
 #11

Thanks again everyone, I used @BitMaxz link to download Tails OS and verified it on tails.net successfully. I have now booted my computer on tails os from the usb.

I have also downloaded Electrum and can create a new wallet by selecting 'Import Bitcoin addresses or private keys'. I just wanted to check one thing before I do.

When I start Electrum it has a message box that states 'Persistence is disabled for Electrum - when you reboot Tails, all of Electrum data will be lost including your Bitcoin wallet etc.' And it recommends only running Electrum when persistence feature is activated, which i don't know how to do.

If I import my private key is this just going to create a watch feature in the Electrum wallet to confirm there are funds at the corresponding bitcoin address? Which I can then check against the Bitcoin address with the funds on my blockchain.com account to confirm they match? I just don't want to sweep the BTC from my blockchain.com account and then not have access to the funds at the new Electrum wallet if it gets deleted when rebooting tails.
nc50lc
Legendary
*
Offline Offline

Activity: 2856
Merit: 7452


Self-proclaimed Genius


View Profile
November 13, 2024, 04:56:10 AM
Merited by LoyceV (12), hosemary (4), PowerGlove (4)
 #12

The address with the bitcoin balance is a legacy bitcoin address that starts with 1. The address definitely has a positive BTC on it. The corresponding WIF private key is 52 characters and starts with L.
Since you never mentioned the address' format after importing its WIF: if the non-matching imported address also starts with '1';
There's a chance here that Blockchain messed-up the WIF private key's encoding where it should be without the compressed byte flag.
a.k.a: uncompressed WIF private key, starts with '5'.

To encode it into the old format, you may use various offline tools but I'd recommend iancoleman's compression tool
Link (do not use this online version, read "Offline Usage" below it): https://iancoleman.io/bitcoin-key-compression/
Then use the "Private Key (WIF)" under "Uncompressed".

LoyceV
Legendary
*
Offline Offline

Activity: 3752
Merit: 19436


Thick-Skinned Gang Leader and Golden Feather 2021


View Profile WWW
November 13, 2024, 06:38:13 AM
 #13

If I import my private key is this just going to create a watch feature in the Electrum wallet to confirm there are funds at the corresponding bitcoin address?
Yes.

Quote
Which I can then check against the Bitcoin address with the funds on my blockchain.com account to confirm they match?
Yes.

Quote
I just don't want to sweep the BTC from my blockchain.com account and then not have access to the funds at the new Electrum wallet if it gets deleted when rebooting tails.
You're not even give Tails internet access. So it can't sweep anything.

¡uʍop ǝpᴉsdn pɐǝɥ ɹnoʎ ɥʇᴉʍ ʎuunɟ ʞool no⅄
Unaccomplished_fox (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 12


View Profile
November 13, 2024, 08:19:54 AM
 #14

I imported my blockchain.com WIF bitcoin private key to Electrum and the address doesn't match the related bitcoin address with the balance. The address that Electrum returns for the private key does start with a '1' though.

I'm hoping to try @nc50lc advice about using the bitcoin key compression tool. I'll try to do this offline but i don't think i can run it on my work laptop so will have to reconnect my personal laptop to the internet.

Am I just copying in the WIF private key as my input key and this will output a compressed and uncompressed version of the address and private key? And hopefully the uncompressed address matches my one on blockchain.com with the BTC balance? Or is there another step e.g. plug the uncompressed private key back into electrum?

Thanks in advance
LoyceV
Legendary
*
Offline Offline

Activity: 3752
Merit: 19436


Thick-Skinned Gang Leader and Golden Feather 2021


View Profile WWW
November 13, 2024, 08:32:07 AM
 #15

I'm hoping to try @nc50lc advice about using the bitcoin key compression tool. I'll try to do this offline but i don't think i can run it on my work laptop so will have to reconnect my personal laptop to the internet.
Just save that webpage on a USB stick, and load it in a browser on Tails. You don't need internet to use it.

¡uʍop ǝpᴉsdn pɐǝɥ ɹnoʎ ɥʇᴉʍ ʎuunɟ ʞool no⅄
Unaccomplished_fox (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 12


View Profile
November 13, 2024, 10:07:20 AM
Merited by LoyceV (4)
 #16

Thanks so much @LoyceV @nc50lc and everyone that helped - I think that worked!

I entered my compressed WIF private key as an input and the uncompressed address matches my address with the BTC balance. The uncompressed WIF private key starts with a 5 and is 51 characters long.

Does this mean that I can use this uncompressed WIF private key to sweep my bitcoin to a new wallet?
LoyceV
Legendary
*
Offline Offline

Activity: 3752
Merit: 19436


Thick-Skinned Gang Leader and Golden Feather 2021


View Profile WWW
November 13, 2024, 10:53:33 AM
 #17

I entered my compressed WIF private key as an input and the uncompressed address matches my address with the BTC balance. The uncompressed WIF private key starts with a 5 and is 51 characters long.
I knew private keys can produce 2 different legacy addresses, but I didn't know the blockchain website messed this up.

Quote
Does this mean that I can use this uncompressed WIF private key to sweep my bitcoin to a new wallet?
Yes. Or, you can use it to sign offline signing from Electrum on offline Tails. It depends on how much money is involved: if it's small, I'd risk it. If it's a lot, I wouldn't risk it.

After you've moved your Bitcoin out of that address, you should read my Fork claiming guide. The numbers are outdated, but there's still value in there. But don't even think about this before moving your Bitcoin, there's no need to risk losing them to a compromised Fork wallet.

¡uʍop ǝpᴉsdn pɐǝɥ ɹnoʎ ɥʇᴉʍ ʎuunɟ ʞool no⅄
Unaccomplished_fox (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 12


View Profile
November 13, 2024, 12:26:39 PM
 #18

Hi, just wanted to say thanks again for everyone's help on here, i managed to sweep my BTC to a new wallet!

Thanks for the information about forks as well.....I did see the BTC address had a mirrored BCH address with a small balance so will definitely look into it
LoyceV
Legendary
*
Offline Offline

Activity: 3752
Merit: 19436


Thick-Skinned Gang Leader and Golden Feather 2021


View Profile WWW
November 13, 2024, 02:35:50 PM
 #19

I did see the BTC address had a mirrored BCH address with a small balance so will definitely look into it
Note:
Don't be like the guy who lost a small fortune in Forkcoins by sending one of them to Coinbase and losing another to the lack of replay protection.

¡uʍop ǝpᴉsdn pɐǝɥ ɹnoʎ ɥʇᴉʍ ʎuunɟ ʞool no⅄
PowerGlove
Hero Member
*****
hacker
Offline Offline

Activity: 658
Merit: 6236



View Profile
November 14, 2024, 02:44:43 AM
Last edit: November 17, 2024, 02:39:56 PM by PowerGlove
Merited by Cricktor (1)
 #20

There's a chance here that Blockchain messed-up the WIF private key's encoding where it should be without the compressed byte flag.
Nice catch!

For the next time this comes up, I wrote a little standard-library-only Python script that converts a compressed WIF into an uncompressed one:

Code:
#!/usr/bin/env python3

# uncompress_wif.py v2024.11.17 (https://bitcointalk.org/index.php?topic=5517924.msg64736869#msg64736869)

import sys, functools, hashlib

def main(args: list[str]) -> None:

    alphabet: str = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'

    if len(args) != 1 or not all(char in alphabet for char in args[0]) or len(args[0]) != 52 or args[0][0] not in {'K', 'L'}:

        sys.exit('Huh? Gimme a compressed WIF.')

    unbased: int = functools.reduce(lambda a, b: a * 58 + b, (alphabet.index(char) for char in args[0]))

    if unbased & 2**32-1 != int.from_bytes(hashlib.sha256(hashlib.sha256((unbased >> 32).to_bytes(34, 'big')).digest()).digest()[:4], 'big'):

        sys.exit('Bad checksum. Maybe you mistyped your WIF?')

    scalar: int = unbased >> 40 & 2**256-1

    versioned: int = 0x80 << 256 | scalar

    checksum: int = int.from_bytes(hashlib.sha256(hashlib.sha256(versioned.to_bytes(33, 'big')).digest()).digest()[:4], 'big')

    combined: int = versioned << 32 | checksum

    output: str = ''.join(alphabet[scale % 58] for scale in (combined // 58**index for index in range(51)))[::-1]

    print(f'Uncompressed WIF: {output}')

if __name__ == '__main__':

    main(sys.argv[1:])

That Ian Coleman page/tool you pointed to works well, but, for this particular problem, it's both massive (~2 megs of code to check/audit), and it's just too tempting to use while still online...

Really, all OP needed was a concise, offline-only tool to correct Blockchain.com's (stupid) mistake. So, what they could have done is booted into Tails (making sure at the welcome screen to select "Disable all networking" under "Additional Settings -> Offline Mode"), and then used the above script (copied into /home/amnesia from a second USB stick) to get the correct WIF, like this:

Code:
$ python3 uncompress_wif.py KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn

Which yields:

Code:
Uncompressed WIF: 5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf

Edit: For the sake of completeness, here's the above script's "partner" (that is, one that goes from uncompressed WIF to compressed WIF; I also added type annotations to both scripts):

Code:
#!/usr/bin/env python3

# compress_wif.py v2024.11.17 (https://bitcointalk.org/index.php?topic=5517924.msg64736869#msg64736869)

import sys, functools, hashlib

def main(args: list[str]) -> None:

    alphabet: str = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'

    if len(args) != 1 or not all(char in alphabet for char in args[0]) or len(args[0]) != 51 or args[0][0] != '5':

        sys.exit('Huh? Gimme an uncompressed WIF.')

    unbased: int = functools.reduce(lambda a, b: a * 58 + b, (alphabet.index(char) for char in args[0]))

    if unbased & 2**32-1 != int.from_bytes(hashlib.sha256(hashlib.sha256((unbased >> 32).to_bytes(33, 'big')).digest()).digest()[:4], 'big'):

        sys.exit('Bad checksum. Maybe you mistyped your WIF?')

    scalar: int = unbased >> 32 & 2**256-1

    versioned: int = 0x80 << 264 | scalar << 8 | 1

    checksum: int = int.from_bytes(hashlib.sha256(hashlib.sha256(versioned.to_bytes(34, 'big')).digest()).digest()[:4], 'big')

    combined: int = versioned << 32 | checksum

    output: str = ''.join(alphabet[scale % 58] for scale in (combined // 58**index for index in range(52)))[::-1]

    print(f'Compressed WIF: {output}')

if __name__ == '__main__':

    main(sys.argv[1:])
Pages: [1] 2 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!