0

I have code which generates WIF keys from hex keys. It just need a few more lines to generate WIF addresses.

------------------------

import binascii, hashlib, base58, sys

def convert(z):

private_key_static = z

extended_key = "80"+private_key_static+"01"

first_sha256 = hashlib.sha256(binascii.unhexlify(extended_key)).hexdigest()

second_sha256 = hashlib.sha256(binascii.unhexlify(first_sha256)).hexdigest()

final_key = extended_key+second_sha256[:8]

WIF = base58.b58encode(binascii.unhexlify(final_key)).decode ('ascii')

print (WIF)

with open("HEX.txt") as file: for line in file: convert(str.strip(line))

1 Answer 1

1

Note: WIF is a format for private keys, not addresses. There are multiple address formats, but the most common is P2PKH (hash of a public key).

I recommend looking that the code for Electrum to learn about how to work with public keys and addresses in Python, (check out bitcoin.py). It contains everything you need and is reliable code used by many thousands of users to secure their bitcoin.

1
  • TY You're right. I'm a beginner at this.
    – user104853
    Commented Apr 12, 2020 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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