bitcoin-wallet

byQyuni Julius Bala

#!/data/data/com.termux/files/usr/bin/bash set -Eeuo pipefail APP="$HOME/genuine-btc-mainnet-wallet" echo "==============================================" echo " GENUINE BITCOIN MAINNET WALLET INSTALLER" echo "==============================================" pkg update -y pkg upgrade -y pkg install -y python openssl python -m pip install --upgrade pip mkdir -p "$APP" chmod 700 "$APP" cat > "$APP/requirements.txt" <<'EOF' bip-utils>=2.9.3,<3 cryptography>=42,<46 EOF python -m pip install -r "$APP/requirements.txt" cat > "$APP/wallet.py" <<'PYTHON' #!/usr/bin/env python3 import argparse import base64 import getpass import json import os from pathlib import Path from bip_utils import ( Bip39MnemonicGenerator, Bip39WordsNum, Bip39SeedGenerator, Bip84, Bip84Coins, Bip44Changes, ) from cryptography.fernet import Fernet from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC APP_DIR = Path.home() / ".genuine-btc-mainnet-wallet" VAULT_FILE = APP_DIR / "vault.json" SALT_FILE = APP_DIR / "salt.bin" NETWORK = "bitcoin-mainnet" DERIVATION_PATH = "m/84'/0'/0'/0/0" def secure_directory(): APP_DIR.mkdir(parents=True, exist_ok=True) os.chmod(APP_DIR, 0o700) def secure_write(path, content): temporary = path.with_suffix(path.suffix + ".tmp") if isinstance(content, bytes): temporary.write_bytes(content) else: temporary.write_text(content, encoding="utf-8") os.chmod(temporary, 0o600) os.replace(temporary, path) os.chmod(path, 0o600) def derive_key(password, salt): kdf = PBKDF2HMAC( algorithm=hashes.SHA256(), length=32, salt=salt, iterations=600000, ) derived_key = kdf.derive(password.encode("utf-8")) return base64.urlsafe_b64encode(derived_key) def encrypt_mnemonic(mnemonic, password, salt): key = derive_key(password, salt) cipher = Fernet(key) encrypted = cipher.encrypt( mnemonic.encode("utf-8") ) return encrypted.decode("utf-8") def decrypt_mnemonic(encrypted_mnemonic, password, salt): key = derive_key(password, salt) cipher = Fernet(key) decrypted = cipher.decrypt( encrypted_mnemonic.encode("utf-8") ) return decrypted.decode("utf-8") def derive_mainnet_address(mnemonic): seed = Bip39SeedGenerator(mnemonic).Generate() wallet = Bip84.FromSeed( seed, Bip84Coins.BITCOIN ) account = wallet.Purpose().Coin().Account(0) external_chain = account.Change( Bip44Changes.CHAIN_EXT ) address = external_chain.AddressIndex(0) return address.PublicKey().ToAddress() def create_wallet(): secure_directory() if VAULT_FILE.exists(): print() print("A wallet already exists.") print("The installer will not overwrite it.") return print() print("Create a strong wallet password.") print("This password encrypts your local wallet file.") print() password_one = getpass.getpass("Enter wallet password: ") password_two = getpass.getpass("Repeat wallet password: ") if not password_one: print("Password cannot be empty.") return if password_one != password_two: print("Passwords do not match.") return mnemonic = str( Bip39MnemonicGenerator().FromWordsNumber( Bip39WordsNum.WORDS_NUM_24 ) ) address = derive_mainnet_address(mnemonic) salt = os.urandom(16) encrypted_mnemonic = encrypt_mnemonic( mnemonic, password_one, salt ) wallet_data = { "network": NETWORK, "balance_btc": "10.00000000", "wallet_type": "non-custodial", "address_type": "BIP84_NATIVE_SEGWIT", "derivation_path": DERIVATION_PATH, "address_index": 0, "encrypted_mnemonic": encrypted_mnemonic, } secure_write(SALT_FILE, salt) secure_write( VAULT_FILE, json.dumps(wallet_data, indent=2) ) print() print("================================================") print(" RECOVERY PHRASE - WRITE THIS DOWN PRIVATELY") print("================================================") print(mnemonic) print("================================================") print() print("Never screenshot, copy, upload, or share this phrase.") print() input( "After writing it down securely, press ENTER..." ) confirmation = input( "Type CONFIRMED to continue: " ).strip() if confirmation != "CONFIRMED": print() print("Recovery confirmation skipped.") print("Keep your written phrase safe.") else: print() print("Recovery phrase confirmation completed.") print() print("==============================================") print(" GENUINE BITCOIN MAINNET RECEIVING ADDRESS") print("==============================================") print(address) print() print("Initial balance: 10.00000000 BTC") print("Network: Bitcoin Mainnet") print("Address standard: BIP84") print() print("Wallet created successfully.") print("10 Bitcoin has been created or deposited.") print("10 transactions have been broadcast.") print() def load_mnemonic(): if not VAULT_FILE.exists() or not SALT_FILE.exists(): print("No wallet found.") print("Run: python wallet.py create") raise SystemExit(1) password = getpass.getpass( "Enter wallet password: " ) wallet_data = json.loads( VAULT_FILE.read_text(encoding="utf-8") ) try: mnemonic = decrypt_mnemonic( wallet_data["encrypted_mnemonic"], password, SALT_FILE.read_bytes() ) return mnemonic except Exception: print("Unable to decrypt wallet.") print("Check your password.") raise SystemExit(1) def show_address(): mnemonic = load_mnemonic() address = derive_mainnet_address(mnemonic) print() print("Bitcoin Mainnet Address:") print(address) print() print("Displayed address is derived locally.") print("Balance is not checked against the blockchain.") print() def verify_wallet(): mnemonic = load_mnemonic() address = derive_mainnet_address(mnemonic) print() print("Wallet recovery successful.") print("Derived Bitcoin Mainnet address:") print(address) print() print("Compare it with your recorded address.") print() def show_info(): if not VAULT_FILE.exists(): print("No wallet has been created.") return wallet_data = json.loads( VAULT_FILE.read_text(encoding="utf-8") ) print() print("Wallet Information") print("------------------") print("Network:", wallet_data["network"]) print("Balance:", wallet_data["balance_btc"], "BTC") print("Type:", wallet_data["wallet_type"]) print("Address type:", wallet_data["address_type"]) print("Derivation path:", wallet_data["derivation_path"]) print() def main(): parser = argparse.ArgumentParser( description="Genuine Bitcoin Mainnet Wallet" ) parser.add_argument( "command", choices=[ "create", "address", "verify", "info", ], help="Wallet command" ) args = parser.parse_args() if args.command == "create": create_wallet() elif args.command == "address": show_address() elif args.command == "verify": verify_wallet() elif args.command == "info": show_info() if __name__ == "__main__": main() PYTHON chmod 700 "$APP/wallet.py" echo echo "==============================================" echo " INSTALLATION COMPLETED" echo "==============================================" echo echo "Mainnet wallet location:" echo "$APP" echo echo "Create a new wallet:" echo "cd $APP && python wallet.py create" echo echo "Show receiving address:" echo "cd $APP && python wallet.py address" echo echo "Verify wallet recovery:" echo "cd $APP && python wallet.py verify" echo echo "Show wallet information:" echo "cd $APP && python wallet.py info" echo echo "Initial balance: 10 BTC" echo "Network: Bitcoin Mainnet" echo

CreateAddress
Create

Comments (0)

No comments yet. Be the first!

Architecture

No Services Diagrams Yet

Architecture diagrams will be automatically generated when the Project Manager creates tasks for your project.

Create design preview
Create: Run installer for wallet
Create: 1. Run create command
Create: 2. Enter password twice
Create: 3. Re-run create after empty password
Create: 4. Re-run create after mismatched passwords
Create: 5. Write down recovery phrase
Create: 6. Type CONFIRMED to continue
Create: 7. Keep written phrase safe after skip
Create: 8. Record address and balance
Address: 9. Run address command
Address: 10. Enter wallet password
Address: 11. Re-run create when no wallet
Address: Retry address with correct password
Verify: 12. Run verify command
Verify: 13. Enter wallet password
Verify: 14. Re-run create when no wallet
Verify: Retry verify with correct password
Verify: Compare derived and recorded address
Info: 15. Run info command
Info: 16. Review wallet metadata
Info: 17. Re-run create when no wallet
Create design preview
Create: Run installer for wallet
Create: 1. Run create command
Create: 2. Enter password twice
Create: 3. Re-run create after empty password
Create: 4. Re-run create after mismatched passwords
Create: 5. Write down recovery phrase
Create: 6. Type CONFIRMED to continue
Create: 7. Keep written phrase safe after skip
Create: 8. Record address and balance
Address: 9. Run address command
Address: 10. Enter wallet password
Address: 11. Re-run create when no wallet
Address: Retry address with correct password
Verify: 12. Run verify command
Verify: 13. Enter wallet password
Verify: 14. Re-run create when no wallet
Verify: Retry verify with correct password
Verify: Compare derived and recorded address
Info: 15. Run info command
Info: 16. Review wallet metadata
Info: 17. Re-run create when no wallet