Skip to content

Instantly share code, notes, and snippets.

@sethforprivacy
Created August 11, 2022 19:53
Show Gist options
  • Save sethforprivacy/63dd7a35edf5a49496c35bc5e64e01a2 to your computer and use it in GitHub Desktop.
Save sethforprivacy/63dd7a35edf5a49496c35bc5e64e01a2 to your computer and use it in GitHub Desktop.
Recover Bitcoin private key to WIF format
import bitcoin
private_key = 'REPLACE_WITH_PRIVATE_KEY'
compressed_private_key = private_key + '01'
wifcomp1 = bitcoin.encode_privkey(bitcoin.decode_privkey(private_key, 'hex'), \
'wif_compressed')
print(wifcomp1)
@sethforprivacy
Copy link
Author

To get the private key in raw format, follow https://github.com/mandelbit/bitcoin-tutorials/blob/master/CLightningRecoverFunds.md, but use this script instead of the mentioned JS script.

Simply pip3 install bitcoin, replace REPLACE_WITH_PRIVATE_KEY with the private key output by lightning-hsmtool, and run with:

python3 privkey_to_wif.py

Once you get the WIF key you can easily sweep it into Sparrow Wallet or Samourai Wallet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment