# Path: bit/base58.py
# BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
# 
# def b58encode_check(bytestr):
#     return b58encode(bytestr + double_sha256_checksum(bytestr))
# 
# Path: bit/crypto.py
# def sha256(bytestr):
# def double_sha256(bytestr):
# def double_sha256_checksum(bytestr):
# def ripemd160_sha256(bytestr):
# 
# Path: bit/format.py
# def bytes_to_wif(private_key, version='main', compressed=False):
# 
#     if version == 'test':
#         prefix = TEST_PRIVATE_KEY
#     else:
#         prefix = MAIN_PRIVATE_KEY
# 
#     if compressed:
#         suffix = PRIVATE_KEY_COMPRESSED_PUBKEY
#     else:
#         suffix = b''
# 
#     private_key = prefix + private_key + suffix
# 
#     return b58encode_check(private_key)
# 
# def public_key_to_address(public_key, version='main'):
# 
#     if version == 'test':
#         version = TEST_PUBKEY_HASH
#     else:
#         version = MAIN_PUBKEY_HASH
# 
#     length = len(public_key)
# 
#     if length not in (33, 65):
#         raise ValueError('{} is an invalid length for a public key.'.format(length))
# 
#     return b58encode_check(version + ripemd160_sha256(public_key))


import sys
import time
from multiprocessing import Event, Process, Queue, Value, cpu_count
from coincurve import Context
from bit.base58 import BASE58_ALPHABET, b58encode_check
from bit.crypto import ECPrivateKey, ripemd160_sha256
from bit.format import bytes_to_wif, public_key_to_address
    elif 0 < int(cores) <= available_cores:
        cores = int(cores)
    else:
        cores = 1

    counter = Value('i')
    match = Event()
    queue = Queue()

    workers = []
    for _ in range(cores):
        workers.append(Process(target=generate_key_address_pairs, args=(prefix, counter, match, queue)))

    for worker in workers:
        worker.start()

    keys_generated = 0
    while True:
        time.sleep(1)
        current = counter.value
        if current == keys_generated:
            if current == 0:
                continue
            break
        keys_generated = current
        s = 'Keys generated: {}\r'.format(keys_generated)
        sys.stdout.write(s)
        sys.stdout.flush()

    private_key, address = queue.get()

# Path: bit/base58.py
# BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
# 
# def b58encode_check(bytestr):
#     return b58encode(bytestr + double_sha256_checksum(bytestr))
# 
# Path: bit/crypto.py
# def sha256(bytestr):
# def double_sha256(bytestr):
# def double_sha256_checksum(bytestr):
# def ripemd160_sha256(bytestr):
# 
# Path: bit/format.py
# def bytes_to_wif(private_key, version='main', compressed=False):
# 
#     if version == 'test':
#         prefix = TEST_PRIVATE_KEY
#     else:
#         prefix = MAIN_PRIVATE_KEY
# 
#     if compressed:
#         suffix = PRIVATE_KEY_COMPRESSED_PUBKEY
#     else:
#         suffix = b''
# 
#     private_key = prefix + private_key + suffix
# 
#     return b58encode_check(private_key)
# 
# def public_key_to_address(public_key, version='main'):
# 
#     if version == 'test':
#         version = TEST_PUBKEY_HASH
#     else:
#         version = MAIN_PUBKEY_HASH
# 
#     length = len(public_key)
# 
#     if length not in (33, 65):
#         raise ValueError('{} is an invalid length for a public key.'.format(length))
# 
#     return b58encode_check(version + ripemd160_sha256(public_key))


# Path: bit/keygen.py
import sys
import time
from multiprocessing import Event, Process, Queue, Value, cpu_count
from coincurve import Context
from bit.base58 import BASE58_ALPHABET, b58encode_check
from bit.crypto import ECPrivateKey, ripemd160_sha256
from bit.format import bytes_to_wif, public_key_to_address

    elif 0 < int(cores) <= available_cores:
        cores = int(cores)
    else:
        cores = 1

    counter = Value('i')
    match = Event()
    queue = Queue()

    workers = []
    for _ in range(cores):
        workers.append(Process(target=generate_key_address_pairs, args=(prefix, counter, match, queue)))

    for worker in workers:
        worker.start()

    keys_generated = 0
    while True:
        time.sleep(1)
        current = counter.value
        if current == keys_generated:
            if current == 0:
                continue
            break
        keys_generated = current
        s = 'Keys generated: {}\r'.format(keys_generated)
        sys.stdout.write(s)
        sys.stdout.flush()

    private_key, address = queue.get()

    print('\n\n' 'WIF: {}\n' 'Address: {}'.format(bytes_to_wif(private_key), address))