5

So I have a compressed private key. Is it possible to get the uncompressed version of it? If yes, how? Examples in Javascript would be much appreciated.

3

Ok I answered my own question. From: https://github.com/pointbiz/bitaddress.org/blob/master/src/bitcoinjs-lib.eckey.js#L186-L222

bytes = Bitcoin.Base58.decode(compressed_or_uncompressed_private_key);

After some processing, this bytes-array can then be re-encoded into a compressed or uncompressed private key.

1

I know this is an old post. But according to documentation (https://en.bitcoin.it/wiki/Wallet_import_format)

Add a 0x01 byte at the end if the private key will correspond to a compressed public key a compressed private key should have a 01 flag at the end... If it corresponded to a compressed public key, the WIF string will have started with K or L instead of 5 (or c instead of 9 on testnet).

Taking the key from the example on the site

5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ

The key should be derived by decoding the key using Base58, removing the last 4 bytes (8 characters) corresponding to the checksum.

800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d507a5b8d

For the compressed version add a 01 byte at the end

800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d01

And re derive the double SHA256 hash for the checksum. Using Python (http://www.herongyang.com/Bitcoin/Block-Data-Calculate-Double-SHA256-with-Python.html) or (https://learnmeabitcoin.com/guide/checksum) result is:

a62019d20340a1de1b5f254f07f2f6c96ad5165218459ab4f3c8f5a7c0e12183

Take the first 4 bytes from the hash (a62019d2) and add it to the key after the 01 byte.

800c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d507a5b8d01a62019d2

Encode the result in Base58 and you should have the compressed key.

KwdMAjGmerYanjeui5SHS7JkmpZvVipYvB2LJGU1ZxJwYvP98617

Notice the key begins with K. I was unable to confirm with any other info published on the internet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.