if you want to convert a compressed WIF to an uncompressed WIF, you would need to:
- decode the compressed WIF
- extract the private key
- remove the suffix
- recompute the checksum
- encode it back in base58
Here’s one way you can implement it:
def decompress_WIF(compressed_wif):
hex_data = binascii.b2a_hex(base58.b58decode(compressed_wif)).decode()
if len(hex_data) != 76:
raise ValueError("Invalid length for a compressed WIF")
prefix = hex_data[:2]
suffix = hex_data[-10:-8]
original_checksum = hex_data[-8:]
xpriv = hex_data[2:-10]
if suffix != "01":
raise ValueError("The provided WIF is not a compressed key")
if checksum(prefix + xpriv + suffix) != original_checksum:
raise ValueError("Invalid checksum in the provided WIF")
new_checksum = checksum(prefix + xpriv)
uncompressed_wif = base58.b58encode(binascii.a2b_hex(prefix + xpriv + new_checksum)).decode()
return uncompressed_wif
Note that this code does not check the version byte at all