示例#1
0
def read_and_confirm_mnemonic():
    client = DebugLink(get_device().find_debug())
    client.open()
    time.sleep(SLEEP)
    client.press_yes()
    time.sleep(SLEEP)

    # it appears that doing read_mnemonic_secret also skips otherwise necessary "swiping"
    mnem = client.read_mnemonic_secret().decode("utf-8")
    mnemonic = mnem.split()
    time.sleep(SLEEP)

    index = client.read_reset_word_pos()
    client.input(mnemonic[index])
    time.sleep(SLEEP)

    index = client.read_reset_word_pos()
    client.input(mnemonic[index])
    time.sleep(SLEEP)

    index = client.read_reset_word_pos()
    client.input(mnemonic[index])
    time.sleep(SLEEP)

    client.press_yes()
    client.press_yes()
    client.close()
示例#2
0
def decision():
    client = DebugLink(get_device().find_debug())
    client.open()
    time.sleep(SLEEP)
    client.press_yes()
    # time.sleep(SLEEP)
    client.close()
示例#3
0
def start(
    version: str,
    wipe: bool,
    output_to_logfile: bool = True,
    save_screenshots: bool = False,
) -> None:
    global version_running
    global EMULATOR

    if EMULATOR is not None:
        log(
            f"Before starting a new emulator - version {version}, "
            f"killing the already running one - version {version_running}",
            "red",
        )
        stop()

    # Conditionally redirecting the output to a logfile instead of terminal/stdout
    if output_to_logfile:
        logfile = open(helpers.EMU_BRIDGE_LOG, "a")
    else:
        logfile = sys.stdout

    if version[0] == "2":
        EMULATOR = CoreEmulator(
            FIRMWARE_DIR / f"trezor-emu-core-v{version}",
            profile_dir=FIRMWARE_DIR,
            logfile=logfile,
        )
    elif version[0] == "1":
        os.environ["TREZOR_OLED_SCALE"] = str(TREZOR_ONE_OLED_SCALE)
        EMULATOR = LegacyEmulator(
            FIRMWARE_DIR / f"trezor-emu-legacy-v{version}",
            profile_dir=FIRMWARE_DIR,
            logfile=logfile,
        )
    else:
        raise RuntimeError("Version can start only with 1 or 2")

    if wipe and EMULATOR.storage.exists():
        EMULATOR.storage.unlink()

    EMULATOR.start()

    version_running = version

    # Optionally saving the screenshots on any screen-change, so we can send the
    # current screen on demand
    # Only applicable to TT, T1 is not capable of screenshotting
    if save_screenshots and version[0] == "2":
        time.sleep(1)
        client = DebugLink(get_device().find_debug())
        client.open()
        client.start_recording(str(SCREEN_DIR))
def find_debug():
    for device in enumerate_devices():
        try:
            debug_transport = device.find_debug()
            debug = DebugLink(debug_transport, auto_interact=False)
            debug.open()
            return debug
        except Exception:
            continue
    else:
        print("No suitable Trezor device found")
        sys.exit(1)
示例#5
0
def find_debug():
    for device in enumerate_devices():
        try:
            debug_transport = device.find_debug()
            debug = DebugLink(debug_transport, auto_interact=False)
            debug.open()
            return debug
        except Exception:
            continue
    else:
        print("No suitable Trezor device found")
        sys.exit(1)
示例#6
0
def swipe(direction: str) -> None:
    client = DebugLink(get_device().find_debug())
    client.open()
    time.sleep(SLEEP)
    if direction == "up":
        client.swipe_up()
    elif direction == "right":
        client.swipe_right()
    elif direction == "down":
        client.swipe_down()
    elif direction == "left":
        client.swipe_left()
    client.close()
示例#7
0
def swipe(direction):
    client = DebugLink(get_device().find_debug())
    client.open()
    time.sleep(SLEEP)
    if direction == 'up':
        client.swipe_up()
    elif direction == 'right':
        client.swipe_right()
    elif direction == 'down':
        client.swipe_down()
    elif direction == 'left':
        client.swipe_left()
    client.close()
示例#8
0
def read_and_confirm_mnemonic() -> None:
    # Connecting to the device
    client = DebugLink(get_device().find_debug())
    client.open()
    time.sleep(SLEEP)

    # Clicking continue button
    client.press_yes()
    time.sleep(SLEEP)

    # Scrolling through all the 12 words on next three pages
    for _ in range(3):
        client.swipe_up()
        time.sleep(SLEEP)

    # Confirming that I have written the seed down
    client.press_yes()
    time.sleep(SLEEP)

    # Retrieving the seed words for next "quiz"
    mnem = client.state().mnemonic_secret.decode("utf-8")
    mnemonic = mnem.split()
    time.sleep(SLEEP)

    # Answering 3 questions asking for a specific word
    for _ in range(3):
        index = client.read_reset_word_pos()
        client.input(mnemonic[index])
        time.sleep(SLEEP)

    # Click Continue to finish the quiz
    client.press_yes()
    time.sleep(SLEEP)

    # Click Continue to finish the backup
    client.press_yes()
    time.sleep(SLEEP)

    client.close()
示例#9
0
def read_and_confirm_mnemonic():
    client = DebugLink(get_device().find_debug())
    client.open()
    time.sleep(SLEEP)

    client.press_yes()
    time.sleep(SLEEP)

    mnem = client.state().mnemonic_secret.decode("utf-8")
    mnemonic = mnem.split()
    time.sleep(SLEEP)

    client.swipe_up()
    time.sleep(SLEEP)

    client.swipe_up()
    time.sleep(SLEEP)

    client.swipe_up()
    time.sleep(SLEEP)

    client.press_yes()
    time.sleep(SLEEP)

    index = client.read_reset_word_pos()
    client.input(mnemonic[index])
    time.sleep(SLEEP)

    index = client.read_reset_word_pos()
    client.input(mnemonic[index])
    time.sleep(SLEEP)

    index = client.read_reset_word_pos()
    client.input(mnemonic[index])
    time.sleep(SLEEP)

    client.press_yes()
    client.press_yes()
    client.close()
示例#10
0
def select_num_of_words(num_of_words: int = 12) -> None:
    client = DebugLink(get_device().find_debug())
    client.open()
    time.sleep(SLEEP)
    client.input(str(num_of_words))
    client.close()
示例#11
0
def read_and_confirm_shamir_mnemonic(shares: int = 1, threshold: int = 1) -> None:
    """Performs a walkthrough of the whole Shamir backup on the device.

    NOTE: does not support Super Shamir.
    """
    MIN_SHARES = 1
    MAX_SHARES = 16
    if shares < MIN_SHARES or shares > MAX_SHARES:
        raise RuntimeError(
            f"Number of shares must be between {MIN_SHARES} and {MAX_SHARES}."
        )
    if threshold > shares:
        raise RuntimeError("Threshold cannot be bigger than number of shares.")

    # For setting the right amount of shares/thresholds, we need location of buttons
    MINUS_BUTTON_COORDS = (60, 70)
    PLUS_BUTTON_COORDS = (180, 70)

    # Connecting to the device
    client = DebugLink(get_device().find_debug())
    client.open()
    time.sleep(SLEEP)

    # Click Continue to begin Shamir setup process
    client.press_yes()
    time.sleep(SLEEP)

    # Clicking the minus/plus button to set right number of shares (it starts at 5)
    DEFAULT_SHARES = 5
    needed_clicks = abs(shares - DEFAULT_SHARES)
    if needed_clicks > 0:
        if shares < DEFAULT_SHARES:
            button_coords_to_click = MINUS_BUTTON_COORDS
        else:
            button_coords_to_click = PLUS_BUTTON_COORDS

        for _ in range(needed_clicks):
            client.click(button_coords_to_click)
            time.sleep(SLEEP)

    # Click Continue to confirm the number of shares
    client.press_yes()
    time.sleep(SLEEP)

    # Click Continue to set threshold
    client.press_yes()
    time.sleep(SLEEP)

    # When we have 1 or 2 shares, the threshold is set and cannot be changed
    # (it will be 1 and 2 respectively)
    # Otherise assign it correctly by clicking the plus/minus button
    if shares not in [1, 2]:
        # Default threshold can be calculated from the share number
        default_threshold = shares // 2 + 1
        needed_clicks = abs(threshold - default_threshold)
        if needed_clicks > 0:
            if threshold < default_threshold:
                button_coords_to_click = MINUS_BUTTON_COORDS
            else:
                button_coords_to_click = PLUS_BUTTON_COORDS

            for _ in range(needed_clicks):
                client.click(button_coords_to_click)
                time.sleep(SLEEP)

    # Click Continue to confirm our chosen threshold
    client.press_yes()
    time.sleep(SLEEP)

    # Click Continue to continue
    client.press_yes()
    time.sleep(SLEEP)

    # Click I understand
    client.press_yes()
    time.sleep(SLEEP)

    # Loop through all the shares and fulfill all checks
    for _ in range(shares):
        # Scrolling through all the 20 words on next 5 pages
        # While doing so, saving all the words on the screen for the "quiz" later
        mnemonic = []
        for _ in range(5):
            mnemonic.extend(client.read_reset_word().split())
            client.swipe_up()
            time.sleep(SLEEP)

        mnemonic.extend(client.read_reset_word().split())
        assert len(mnemonic) == 20

        # Confirming that I have written the seed down
        client.press_yes()
        time.sleep(SLEEP)

        # Answering 3 questions asking for a specific word
        for _ in range(3):
            index = client.read_reset_word_pos()
            client.input(mnemonic[index])
            time.sleep(SLEEP)

        # Click Continue to finish this quiz
        client.press_yes()
        time.sleep(SLEEP)

    # Click Continue to finish the backup
    client.press_yes()
    time.sleep(SLEEP)

    client.close()
示例#12
0
def click(x: int, y: int) -> None:
    client = DebugLink(get_device().find_debug())
    client.open()
    time.sleep(SLEEP)
    client.click((x, y))
    client.close()
示例#13
0
def input(value: str) -> None:
    client = DebugLink(get_device().find_debug())
    client.open()
    time.sleep(SLEEP)
    client.input(value)
    client.close()
示例#14
0
def press_no() -> None:
    client = DebugLink(get_device().find_debug())
    client.open()
    time.sleep(SLEEP)
    client.press_no()
    client.close()