#https://github.com/meherett/python-hdwallet from hdwallet import BIP44HDWallet from hdwallet.cryptocurrencies import EthereumMainnet from hdwallet.derivations import BIP44Derivation from hdwallet.utils import generate_mnemonic from typing import Optional import hashlib import os import hashlib import base64 from Crypto.Cipher import AES from Crypto.Util.Padding import pad,unpad from Crypto.Random import get_random_bytes #only for AES CBC mode import random from tqdm import tqdm key = ''.join(random.sample('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 16)) iv = ''.join(random.sample('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 16)) def encrypt(raw): raw = pad(raw.encode(),16) #cipher = AES.new(key.encode('utf-8'), AES.MODE_ECB) cipher = AES.new(key.encode('utf-8'),AES.MODE_CBC,iv.encode('utf-8')) return base64.b64encode(cipher.encrypt(raw)) def get_mnemonic(): mnemonic = generate_mnemonic(language="english", strength=128) array_mnemonic = mnemonic.split(' ') input('print enter to get 1/2 mnemonic...') print('key',key) print('mnemonic 1/2:', array_mnemonic[:6]) input('print enter to get 2/2 mnemonic...') os.system('clear') print('iv',iv) print('mnemonic 1/2:', array_mnemonic[6:]) input('print enter to generate keys...') os.system('clear') return mnemonic def generate_key_pair(index_from, index_to, PASSPHRASE: Optional[str] = None): MNEMONIC: str = get_mnemonic() # Initialize Ethereum mainnet BIP44HDWallet bip44_hdwallet: BIP44HDWallet = BIP44HDWallet(cryptocurrency=EthereumMainnet) # Get Ethereum BIP44HDWallet from mnemonic bip44_hdwallet.from_mnemonic( mnemonic=MNEMONIC, language="english", passphrase=PASSPHRASE ) # Clean default BIP44 derivation indexes/paths bip44_hdwallet.clean_derivation() #print("Mnemonic:", bip44_hdwallet.mnemonic()) #print("Base HD Path: m/44'/60'/0'/0/{address_index}", "\n") # Get Ethereum BIP44HDWallet information's from address index fp = 'keys.csv' with open(fp, 'w') as f: for address_index in tqdm(range(index_from, index_to)): # Derivation from Ethereum BIP44 derivation path bip44_derivation: BIP44Derivation = BIP44Derivation( cryptocurrency=EthereumMainnet, account=0, change=False, address=address_index) # Drive Ethereum BIP44HDWallet bip44_hdwallet.from_path(path=bip44_derivation) # Print address_index, path, address and private_key #print(bip44_hdwallet.private_key()) encry = encrypt(bip44_hdwallet.private_key()) f.write(f'{address_index} {bip44_hdwallet.address()} {encry.decode("utf-8", "ignore")}\n') #print('encrypt_pk', encry.decode("utf-8", "ignore")) #print(f"({address_index}) {bip44_hdwallet.path()} {bip44_hdwallet.address()} 0x{bip44_hdwallet.private_key()}") # Clean derivation indexes/paths bip44_hdwallet.clean_derivation() f.close() generate_key_pair(0, 100)