Post
Topic
Board Development & Technical Discussion
Merits 8 from 3 users
Re: Creating a Bitcoin Core seed using base 6 number (Dice roll)
by
BlackHatCoiner
on 07/09/2023, 16:45:17 UTC
⭐ Merited by o_e_l_e_o (4) ,ETFbitcoin (2) ,NeuroticFish (2)
Then you can import that private address into a new descriptor wallet.
You cannot import a seed manually with sethdseed in a descriptor wallet. It has to be a legacy wallet, otherwise you'll encounter the error:
Quote
Only legacy wallets are supported by this command (code -4)

[...]
Here's a quick Python program for you:
Code:
import hashlib
import base58

def private_key_to_wif(private_key_hex, network_byte=0x80):
    # convert private key from hex to bytes
    private_key_bytes = bytes.fromhex(private_key_hex)

    # add network byte prefix
    extended_key = bytes([network_byte]) + private_key_bytes

    # checksum = :4 from sha256(sha256(key))
    checksum = hashlib.sha256(hashlib.sha256(extended_key).digest()).digest()[:4]

    # append the checksum to the extended key
    extended_key += checksum

    # convert to base58
    wif = base58.b58encode(extended_key)

    return wif.decode('utf-8')

if __name__ == "__main__":
    private_key_hex = input("Enter the Bitcoin private key in hex format: ")
   
    try:
        wif = private_key_to_wif(private_key_hex)
        print("WIF:", wif)
    except ValueError:
        print("Invalid private key input.")

It takes as input a 256-bit private key, and converts it to WIF. You can create a new file, paste it there and run it with python3 file.py. Note that you must have base58 installed. To do it, run pip install base58 from the terminal.