Skip to content

calcuis/universal-seed-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

universal-privatekey-generator

This Python code defines a simple graphical user interface (GUI) application using the Tkinter library for generating cryptocurrency seed phrases, private keys, and corresponding wallet import formats (WIFs). The application allows the user to generate seed phrases of different lengths (12, 15, 18, 21, or 24 words) and displays the corresponding hex representation of the seed, WIF, and the mnemonic words.

Let's break down the code:

import secrets, mnemonic, base58, hashlib
from tkinter import *

secrets, mnemonic, base58, and hashlib are Python libraries used for generating random data, creating mnemonic phrases, encoding/decoding in base58, and performing hash functions, respectively. Tkinter is a standard GUI (Graphical User Interface) toolkit in Python.

root = Tk()
root.title("Seed Generator")
root.columnconfigure([0, 1, 2, 3, 4], minsize=180)

Creates the main window (root) for the GUI with the title "Seed Generator" and configures the column widths.

h = Entry()
w = Entry()
e = Entry()

Creates three Tkinter Entry widgets (h, w, e) for displaying the hex seed, WIF, and mnemonic words, respectively.

def generate(number):
    language = 'english'
    seed = secrets.token_bytes(number)

    # Display the hex seed
    h.delete(0, END)
    h.insert(0, seed.hex())

    # Create the extended private key
    extended_key = '80' + seed.hex()
    first_hash = hashlib.sha256(bytes.fromhex(extended_key)).digest()
    second_hash = hashlib.sha256(first_hash).digest()
    checksum = second_hash[:4]
    extended_key += checksum.hex()

    # Convert the extended key to WIF
    wif = base58.b58encode(bytes.fromhex(extended_key)).decode()
    w.delete(0, END)
    w.insert(0, wif)

    # Convert the seed to mnemonic words
    mnemonic_words = mnemonic.Mnemonic(language).to_mnemonic(seed)
    mnemonic_word_list = " ".join(mnemonic_words.split())
    e.delete(0, END)
    e.insert(0, mnemonic_word_list)

btn_12 = Button(text="Generate 12-Word Seed", command=lambda: generate(16))
btn_15 = Button(text="Generate 15-Word Seed", command=lambda: generate(20))
btn_18 = Button(text="Generate 18-Word Seed", command=lambda: generate(24))
btn_21 = Button(text="Generate 21-Word Seed", command=lambda: generate(28))
btn_24 = Button(text="Generate 24-Word Seed", command=lambda: generate(32))

Defines a function generate that takes a parameter number, generates a random seed using secrets.token_bytes, and then updates the Entry widgets (h, w, e) with the hex seed, WIF, and mnemonic words, respectively. Creates five Tkinter Button widgets (btn_12, btn_15, btn_18, btn_21, btn_24) for generating seed phrases with different lengths. Each button is associated with the generate function and a specific seed length.

In summary, this code creates a basic GUI application for generating cryptocurrency seed phrases, displaying their hex representations, corresponding WIFs, and mnemonic words. The user can choose the length of the seed phrase by clicking on the respective buttons.