# Path: keepkeylib/debuglink.py
# class DebugLink(object):
#     def __init__(self, transport, pin_func=pin_info, button_func=button_press):
#         self.transport = transport
#         self.verbose = False
# 
#         self.pin_func = pin_func
#         self.button_func = button_func
# 
#     def log(self, what, why):
#         if self.verbose:
#             self.log(what, why)
# 
#     def close(self):
#         self.transport.close()
# 
#     def _call(self, msg, nowait=False):
#         self.log("DEBUGLINK SEND", pprint(msg))
#         self.transport.write(msg)
#         if nowait:
#             return
#         ret = self.transport.read_blocking()
#         self.log("DEBUGLINK RECV", pprint(ret))
#         return ret
# 
#     def read_pin(self):
#         obj = self._call(proto.DebugLinkGetState())
#         self.log("Read PIN:", obj.pin)
#         self.log("Read matrix:", obj.matrix)
# 
#         return (obj.pin, obj.matrix)
# 
#     def read_pin_encoded(self):
#         pin, _ = self.read_pin()
#         pin_encoded = self.encode_pin(pin)
#         self.pin_func(pin_encoded, self.verbose)
#         return pin_encoded
# 
#     def encode_pin(self, pin):
#         _, matrix = self.read_pin()
# 
#         # Now we have real PIN and PIN matrix.
#         # We have to encode that into encoded pin,
#         # because application must send back positions
#         # on keypad, not a real PIN.
#         pin_encoded = ''.join([str(matrix.index(p) + 1) for p in pin])
# 
#         self.log("Encoded PIN:", pin_encoded)
#         return pin_encoded
# 
#     def read_layout(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.layout
# 
#     def read_mnemonic(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.mnemonic
# 
#     def read_node(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.node
# 
#     def read_recovery_word(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return (obj.recovery_fake_word, obj.recovery_word_pos)
# 
#     def read_reset_word(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.reset_word
# 
#     def read_reset_entropy(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.reset_entropy
# 
#     def read_passphrase_protection(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.passphrase_protection
# 
#     def read_recovery_cipher(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.recovery_cipher
# 
#     def read_recovery_auto_completed_word(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.recovery_auto_completed_word
# 
#     def read_memory_hashes(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return (obj.firmware_hash, obj.storage_hash)
# 
#     def fill_config(self):
#          self._call(proto.DebugLinkFillConfig(), nowait=True)
# 
#     def press_button(self, yes_no):
#         self.log("Pressing", yes_no)
#         self.button_func(yes_no, self.verbose)
#         self._call(proto.DebugLinkDecision(yes_no=yes_no), nowait=True)
# 
#     def press_yes(self):
#         self.press_button(True)
# 
#     def press_no(self):
#         self.press_button(False)
# 
#     def stop(self):
#         self._call(proto.DebugLinkStop(), nowait=True)


import os
import sys
import time
import binascii
import hashlib
import unicodedata
import json
import getpass
import copy
        import termios
        import msvcrt
    import sys, tty
from mnemonic import Mnemonic
from . import tools
from . import mapping
from . import messages_pb2 as proto
from . import messages_eos_pb2 as eos_proto
from . import messages_nano_pb2 as nano_proto
from . import messages_cosmos_pb2 as cosmos_proto
from . import messages_ripple_pb2 as ripple_proto
from . import messages_tendermint_pb2 as tendermint_proto
from . import messages_thorchain_pb2 as thorchain_proto
from . import types_pb2 as types
from . import eos
from . import nano
from .debuglink import DebugLink
        from keepkeylib.tools import int_to_big_endian
                    from copy import deepcopy
                    from copy import deepcopy
    # to automatically pass unit tests.
    #
    # This mixing should be used only for purposes
    # of unit testing, because it will fail to work
    # without special DebugLink interface provided
    # by the device.

    def __init__(self, *args, **kwargs):
        super(DebugLinkMixin, self).__init__(*args, **kwargs)
        self.debug = None
        self.in_with_statement = 0
        self.button_wait = 0
        self.screenshot_id = 0

        # Always press Yes and provide correct pin
        self.setup_debuglink(True, True)
        self.auto_button = True

        # Do not expect any specific response from device
        self.expected_responses = None

        # Use blank passphrase
        self.set_passphrase('')

    def close(self):
        super(DebugLinkMixin, self).close()
        if self.debug:
            self.debug.close()

    def set_debuglink(self, debug_transport):

# Path: keepkeylib/debuglink.py
# class DebugLink(object):
#     def __init__(self, transport, pin_func=pin_info, button_func=button_press):
#         self.transport = transport
#         self.verbose = False
# 
#         self.pin_func = pin_func
#         self.button_func = button_func
# 
#     def log(self, what, why):
#         if self.verbose:
#             self.log(what, why)
# 
#     def close(self):
#         self.transport.close()
# 
#     def _call(self, msg, nowait=False):
#         self.log("DEBUGLINK SEND", pprint(msg))
#         self.transport.write(msg)
#         if nowait:
#             return
#         ret = self.transport.read_blocking()
#         self.log("DEBUGLINK RECV", pprint(ret))
#         return ret
# 
#     def read_pin(self):
#         obj = self._call(proto.DebugLinkGetState())
#         self.log("Read PIN:", obj.pin)
#         self.log("Read matrix:", obj.matrix)
# 
#         return (obj.pin, obj.matrix)
# 
#     def read_pin_encoded(self):
#         pin, _ = self.read_pin()
#         pin_encoded = self.encode_pin(pin)
#         self.pin_func(pin_encoded, self.verbose)
#         return pin_encoded
# 
#     def encode_pin(self, pin):
#         _, matrix = self.read_pin()
# 
#         # Now we have real PIN and PIN matrix.
#         # We have to encode that into encoded pin,
#         # because application must send back positions
#         # on keypad, not a real PIN.
#         pin_encoded = ''.join([str(matrix.index(p) + 1) for p in pin])
# 
#         self.log("Encoded PIN:", pin_encoded)
#         return pin_encoded
# 
#     def read_layout(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.layout
# 
#     def read_mnemonic(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.mnemonic
# 
#     def read_node(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.node
# 
#     def read_recovery_word(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return (obj.recovery_fake_word, obj.recovery_word_pos)
# 
#     def read_reset_word(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.reset_word
# 
#     def read_reset_entropy(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.reset_entropy
# 
#     def read_passphrase_protection(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.passphrase_protection
# 
#     def read_recovery_cipher(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.recovery_cipher
# 
#     def read_recovery_auto_completed_word(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return obj.recovery_auto_completed_word
# 
#     def read_memory_hashes(self):
#         obj = self._call(proto.DebugLinkGetState())
#         return (obj.firmware_hash, obj.storage_hash)
# 
#     def fill_config(self):
#          self._call(proto.DebugLinkFillConfig(), nowait=True)
# 
#     def press_button(self, yes_no):
#         self.log("Pressing", yes_no)
#         self.button_func(yes_no, self.verbose)
#         self._call(proto.DebugLinkDecision(yes_no=yes_no), nowait=True)
# 
#     def press_yes(self):
#         self.press_button(True)
# 
#     def press_no(self):
#         self.press_button(False)
# 
#     def stop(self):
#         self._call(proto.DebugLinkStop(), nowait=True)


# Path: keepkeylib/client.py
import os
import sys
import time
import binascii
import hashlib
import unicodedata
import json
import getpass
import copy
        import termios
        import msvcrt
    import sys, tty
from mnemonic import Mnemonic
from . import tools
from . import mapping
from . import messages_pb2 as proto
from . import messages_eos_pb2 as eos_proto
from . import messages_nano_pb2 as nano_proto
from . import messages_cosmos_pb2 as cosmos_proto
from . import messages_ripple_pb2 as ripple_proto
from . import messages_tendermint_pb2 as tendermint_proto
from . import messages_thorchain_pb2 as thorchain_proto
from . import types_pb2 as types
from . import eos
from . import nano
from .debuglink import DebugLink
        from keepkeylib.tools import int_to_big_endian
                    from copy import deepcopy
                    from copy import deepcopy

    # to automatically pass unit tests.
    #
    # This mixing should be used only for purposes
    # of unit testing, because it will fail to work
    # without special DebugLink interface provided
    # by the device.

    def __init__(self, *args, **kwargs):
        super(DebugLinkMixin, self).__init__(*args, **kwargs)
        self.debug = None
        self.in_with_statement = 0
        self.button_wait = 0
        self.screenshot_id = 0

        # Always press Yes and provide correct pin
        self.setup_debuglink(True, True)
        self.auto_button = True

        # Do not expect any specific response from device
        self.expected_responses = None

        # Use blank passphrase
        self.set_passphrase('')

    def close(self):
        super(DebugLinkMixin, self).close()
        if self.debug:
            self.debug.close()

    def set_debuglink(self, debug_transport):

        self.debug = DebugLink(debug_transport)