Bitcoin Forum
May 22, 2024, 03:36:33 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Complicated help with crossed-client key compression.  (Read 67 times)
MrlostinBTC (OP)
Jr. Member
*
Offline Offline

Activity: 45
Merit: 29


View Profile
March 01, 2021, 06:47:10 PM
Last edit: March 01, 2021, 08:00:30 PM by MrlostinBTC
 #1

My old bitcoin wallet.dat, from client 3.24. Was mined on and before the 3.24. Wallet.dat sat for years and was accidently loaded into Doge core in 2013. I suspect it compressed my bitcoin keys. The data timestamps of btc/doge show when dumped by BTC core 13 for some reason. Clear data split by blockchain creation dates. Is there currently a way to un-compresse a Doge key/addy address? I am hoping the original data is tact. The BTC method does not work as I think it somehow changed the keys/address when Doge client got involved. Key to hex to math formula maybe?

Also having a difficult time compiling older clients, My 686 ubuntu emulation works like garbage. Any advise? Was going to try a pre-compression erra client but there are only sources online.

Also strange. 1 address is coming up different 1 digit shorter in all the dumps from BTC form.

1F2f3FubHQ7v8cvcSf81xkj4rQC4URKhF - 34 digits
18w2pc9PFUfmCaR4JdKaDery3Bentp6CYy - 35 all the rest
1LJAdG24ajwgBhitKJnFfyTiSF9NaA45Jy - 35 all the rest
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
March 01, 2021, 10:09:54 PM
Last edit: March 01, 2021, 11:38:19 PM by HCP
 #2

As I mentioned in your other thread regarding this... the private keys don't get compressed... the public keys do. As such, if you can use the --dumpwallet functionality of PyWallet, you should be able to get the raw hex values for the private keys from your wallet.dat relatively easily.

Once you have the raw hex private keys, there are lots of tools available to convert those into WIF keys that can be easily imported by most wallets. For instance, you can input the hex private keys into something like the "wallet details" tab on https://www.bitaddress.org/ (download and run offline) to get both the uncompressed and compressed addresses and WIF keys... or there are multiple python scripts/tools that should be able to do the same.

Alternatively, you can probably do the reverse... and use dumpwallet in Bitcoin Core and get the "compressed" WIF keys, put those into https://www.bitaddress.org/ and you will be able to see the "uncompressed" address and WIF key (and raw hex as well).

There are certainly tools out there that will take a WIF key, decode it from Base58check into the raw bytes, then drop the trailing checksum bytes and the leading "80" byte and give you the raw HEX private key... which you can then use to go back the other way.

In fact, here is a Python3 script that I just wrote that does exactly that... it will take in a file of "compressed" WIF format keys... and outputs a file of "uncompressed" WIF format keys:
Code: (https://keybase.pub/hcp/compWIF_to_uncompWIF.py)
import os
import ecdsa
import hashlib
import base58
import binascii
import argparse

def decode_WIF(comp_wif):

    #WIF to bytes
    decoded_bytes = base58.b58decode(comp_wif)
    
    #bytes to string
    decoded_string = binascii.hexlify(decoded_bytes)
    
    #remove all the extra bits
    raw_hex = decoded_string[2:-10] #-10 because need to drop the trailing 01 byte indicating "compressed" priv key as well as checksum
    
    return raw_hex


def encode_WIF(hex_key):

    #add '80' byte at start
    extended_key = b'80' + hex_key
    
    #calc checksum
    first_sha256 = hashlib.sha256(binascii.unhexlify(extended_key)).hexdigest()
    second_sha256 = hashlib.sha256(binascii.unhexlify(first_sha256)).hexdigest()
    checksum = second_sha256[:8].encode('utf-8')
    
    #append checksum
    final_key = extended_key + checksum
    
    #convert to WIF
    uncompressed_WIF = base58.b58encode(binascii.unhexlify(final_key))
    
    return uncompressed_WIF

def main():

    parser = argparse.ArgumentParser(
        description='Convert file of compressed WIF\'s to uncompressed WIF\'s.',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('infile', default="compressed_wif_keys.txt", nargs='?', help='File to read compressed WIF keys from')
    parser.add_argument('outfile', default="uncompressed_wif_keys.txt", nargs='?', help='File to write uncompressed WIF keys to')
    args = parser.parse_args()

    if (os.path.exists(args.infile)):

        f = open(args.infile, "r")
        out = open(args.outfile, "w")
        for x in f:
            hex_key = decode_WIF(x)
            uncompressed_WIF = encode_WIF(hex_key)
            out.write(uncompressed_WIF.decode('utf-8'))
            out.write("\n")

        f.close()
        out.close()
    else:
        print("ERROR: File not found: " + args.infile)
        print("\n")
        print(parser.format_help())

if __name__ == "__main__":
    main()
link: https://keybase.pub/hcp/compWIF_to_uncompWIF.py


Then, if you create a text file called "compressed_wif_keys.txt" in the same location as the .py file, and copy paste the following compressed WIFs into it, and then run the script without any arguments:
Code: (https://keybase.pub/hcp/compressed_WIF_keys.txt)
L5cg8tbrDAFX6obhWSMktPrwDTcBX8dQz1AAmhRqidft81vFAoyX
L53ygZ65TrHFVxMATRurYb43Cgp13cvV6XbkFPegYN65GFUH1x8p
KzPTbNXTxrKYoSuJPKiRpymdDRt7HUoCcMaHAPDJhU49YmLrAZ69
L1U6eG1YM6oV8jQVm4PFhQ5cU459XHBWeS2E5Enqq6RfLDGxYnqF
KyPeSN7498myZbsXnnXpQXvxmLavRnVctewv9MoRH6Zp8GV2tqjL
L5WvodSV8qK5fXrrqhLiKXEMd1eYaaSjk5FjwxCdgm44VcGWH91L
L3pPYUHPPJ8tgjk75uUMzfstxYKvArjH8FFrkPbhuSKeyqBaNCpp
KzT21SoRLe34jM9cQizNzmbknFdBfqc3vxw9diBkMHJFF3w9i9Rr
L43FTBxA7ddVnxXnRxdi2nw3BM4PVnpCk1fP7z7aU1Zofd1XdqM7
L2tjSeHgNZvJp8nDoBnsyJ1T1tGyJmDSq2Nqryep4kLKuNNsMjDW
link: https://keybase.pub/hcp/compressed_WIF_keys.txt


It should produce the following "uncompressed_wif_keys.txt" output file:
Code: ("uncompressed_wif_keys.txt")
5KicbsCyTmgza2wzD7CVyWCKB5DW7pwvTxmfvB4pHgaH7c17BYk
5KbCwGszeoWWZqnoYpLE3Ayso9ZrQFUyfQhVq7wkrFJ1WooMj2P
5JXv9hDnz4UK5dgVQdsAhn2xL8T5bYg1pS41VQcQwwAKhnpHFF8
5Jn7GEphdj6YkSU5FWmTtkHuScb22RWZzsXdwtA2YjvAbHujCmF
5JJpT8xJ2Pc7UKmypXhy44qUb4Xo6AQFUZcYyisPii8tTcKdVA6
5KhK5g4xmNNKGyqTFCrnABUVgsu1MkNh3WWd1fngaUerH6awWUh
5KJzDZv6yi3EyahaYvaPRr8uZ4vgEZZguPiRsACVJKRco258WUy
5JYiv7kbWpp96WwWmoDYidqf1jjdrafkiE8HTSeKtGUUF9wRZts
5KMuDH5Ljjjhxj2zREWcaV5YJkWmX5weYwyjAjr4xWaiPRjvsUE
5K6q8d691ot3gE6G8kE7Zh6zYvJfavyHj9U9offURs9TVHWiNxX



Also strange. 1 address is coming up different 1 digit shorter in all the dumps from BTC form.

1F2f3FubHQ7v8cvcSf81xkj4rQC4URKhF - 34 digits
18w2pc9PFUfmCaR4JdKaDery3Bentp6CYy - 35 all the rest
1LJAdG24ajwgBhitKJnFfyTiSF9NaA45Jy - 35 all the rest
That's not really unusual... a Bitcoin "legacy" address (aka the "1"-type addresses) can be anywhere from 26 to 34 characters long. Most are generally 33 or 34 characters in length. For the record, the examples you listed are actually 33, 34 and 34 characters Wink

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Pages: [1]
  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!