def initialize_wallet():

    result = {}
    print "Initializing new wallet ..."
    password = "******"

    try:
        while len(password) < WALLET_PASSWORD_LENGTH:
            password = raw_input("Enter new password: "******"Password is too short. Please make it at least %s characters long" % WALLET_PASSWORD_LENGTH
            else:

                wallet = HDWallet()
                hex_password = hexlify(password)
                hex_privkey = wallet.get_master_privkey()

                data = {}
                data['encrypted_master_private_key'] = aes_encrypt(hex_privkey, hex_password)

                file = open(WALLET_PATH, 'w')
                file.write(json.dumps(data))
                file.close()

                print "Wallet created. Make sure to backup the following:"

                result['wallet_password'] = password
                result['master_private_key'] = hex_privkey

    except KeyboardInterrupt:
        print "\nExited."

    return result
Exemple #2
0
def initialize_wallet():

    result = {}
    print "Initializing new wallet ..."
    password = "******"

    try:
        while len(password) < WALLET_PASSWORD_LENGTH:
            password = getpass("Enter new password: "******"Password is too short. Please make it at"
                msg += " least %s characters long" % WALLET_PASSWORD_LENGTH
                print msg
            else:

                confirm_password = getpass("Confirm new password: "******"Passwords don't match.")

                temp_wallet = HDWallet()
                hex_privkey = temp_wallet.get_master_privkey()

                hex_password = hexlify(password)

                wallet = HDWallet(hex_privkey)
                child = wallet.get_child_keypairs(count=2)

                encrypted_key = aes_encrypt(hex_privkey, hex_password)
                wallet_file_data = {}
                wallet_file_data[
                    'encrypted_master_private_key'] = encrypted_key
                wallet_file_data['payment_addresses'] = [child[0]]
                wallet_file_data['owner_addresses'] = [child[1]]

                print "\nWallet created! Make sure to...\n", \
                      "  1. Remember your password and write it down in a safe place\n", \
                      "  2. Back up your encrypted master private key:\n\n", \
                      "     " + encrypted_key + "\n"

                input_prompt = "Have you backed up your private key? (y/n): "
                user_input = raw_input(input_prompt)
                user_input = user_input.lower()

                if user_input == 'y':
                    file = open(WALLET_PATH, 'w')
                    file.write(json.dumps(wallet_file_data))
                    file.close()
                    print ""
                else:
                    exit_with_error(
                        "Wallet could not be created. Try again and make sure to complete the backup process."
                    )

    except KeyboardInterrupt:
        exit_with_error("\nExited.")

    return result