Removed qr-code generation from btc wallet script. Saved Chatgtp plan about creating general purpose btc application for ondemand key generation and signing.

This commit is contained in:
kalzu
2023-05-23 10:49:19 +03:00
parent 5361afec07
commit b866ac06b4
2 changed files with 63 additions and 28 deletions

View File

@ -9,43 +9,26 @@ of the seed phrase. The database file is password protected to ensure the securi
Usage: ./generate_btc_wallet.py
"""
import base64
import gc
from getpass import getpass
import qrcode
from mnemonic import Mnemonic
from bitcoinlib.keys import HDKey
from pykeepass import create_database
MNEMONIC_STRENGTH=256
SUBKEY_PATH="m/0/0"
# Generate a BIP-0039 mnemonic seed phrase
mnemonic = Mnemonic("english")
SEED_PHRASE = mnemonic.generate(strength=128)
SEED_PHRASE = mnemonic.generate(strength=MNEMONIC_STRENGTH)
# Derive the HDKey from the seed phrase
hd_key = HDKey.from_passphrase(SEED_PHRASE)
# Derive the Bitcoin address from the HDKey
child_key = hd_key.subkey_for_path("m/0/0")
child_key = hd_key.subkey_for_path(SUBKEY_PATH)
address = child_key.address()
# Create a QR code instance
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_H,
box_size=10,
border=4,
)
# Add the data to the QR code
qr.add_data(SEED_PHRASE)
# Generate the QR code image
qr.make(fit=True)
QR_IMAGE = qr.make_image(fill_color="black", back_color="white")
# Convert the QR code image to base64
qr_base64 = base64.b64encode(QR_IMAGE.tobytes()).decode()
# Prompt for custom name for the wallet
wallet_name = input(
"Whould you like to name this wallet? (empty for using the address as name): "
@ -66,18 +49,16 @@ try:
# Create a KeePassXC database file
db = create_database(db_filename, password=passphrase)
# Create an entry in the root group
entry = db.add_entry(db.root_group, wallet_name, username=address, password=SEED_PHRASE)
# Add the QR code as a note (base64 encoded)
entry.notes = qr_base64
# Create an entrys in the root group
address_and_path_entry = db.add_entry(db.root_group, wallet_name, username=address, password=SUBKEY_PATH)
seed_phrase_entry = db.add_entry(db.root_group, "Bitcoin Master Seed", username="put me in safe", password=SEED_PHRASE)
# Save the database
db.save()
except Exception as e:
print("Error while creating keepassxc database. Disk full? Readonly?")
finally:
del SEED_PHRASE, address, hd_key, passphrase, QR_IMAGE, qr_base64, mnemonic
del SEED_PHRASE, address, hd_key, passphrase, mnemonic
gc.collect()
print("---")