How to use trezor - 10 common examples

To help you get started, we’ve selected a few trezor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github trezor / trezor-firmware / src / apps / fido_u2f / u2f.py View on Github external
def layout_u2f():

    if appid in knownapps.knownapps:
        appname = knownapps.knownapps[appid]
        appicon = res.load('apps/fido_u2f/res/u2f_%s.toif' %
                           appname.lower().replace(' ', '_'))
    else:
        appname = hexlify(appid[:4]) + '...' + hexlify(appid[-4:])
        appicon = res.load('apps/fido_u2f/res/u2f_unknown.toif')

    # paint background black
    ui.display.bar(0, 0, 240, 240, ui.BLACK)

    # top header bar
    ui.display.text(10, 28, 'U2F Login', ui.BOLD, ui.WHITE, ui.BLACK)

    # content
    ui.display.text_center(120, 70, '%s:' % action, ui.BOLD, ui.GREY, ui.BLACK)
    ui.display.image((240 - 64) // 2, 90, appicon)
    ui.display.text_center(120, 185, appname, ui.MONO, ui.WHITE, ui.BLACK)

    yield loop.Wait([])
github trezor / trezor-firmware / core / src / trezor / ui / passphrase.py View on Github external
ty = ay + ah // 2 + 8  # y-offset of the content
        maxlen = const(14)  # maximum text length

        # input content
        if len(t) > maxlen:
            t = "<" + t[-maxlen:]  # too long, align to the right
        width = display.text_width(t, text_style)
        display.text(tx, ty, t, text_style, fg_color, bg_color)

        if p:  # pending marker
            pw = display.text_width(t[-1:], text_style)
            px = tx + width - pw
            display.bar(px, ty + 2, pw + 1, 3, fg_color)
        else:  # cursor
            cx = tx + width + 1
            display.bar(cx, ty - 18, 2, 22, fg_color)
github trezor / trezor-core / src / trezor / ui / pin.py View on Github external
y = const(20)
            size = const(10)
            padding = const(14)
            box_w = const(240)
            x = (box_w - l * padding) // 2
            for i in range(0, l):
                ui.display.bar_radius(x + i * padding, y, size, size, ui.GREY, ui.BG, 4)
        elif self.sublabel:
            # input line with header label and sublabel
            display.text_center(ui.WIDTH // 2, 20, self.label, ui.BOLD, ui.GREY, ui.BG)
            display.text_center(
                ui.WIDTH // 2, 46, self.sublabel, ui.NORMAL, ui.GREY, ui.BG
            )
        else:
            # input line with header label
            display.text_center(ui.WIDTH // 2, 36, self.label, ui.BOLD, ui.GREY, ui.BG)

        self.tainted = False
github trezor / trezor-core / src / boot.py View on Github external
if not label:
        label = "My TREZOR"
    if not image:
        image = res.load("apps/homescreen/res/bg.toif")

    await ui.backlight_slide(ui.BACKLIGHT_DIM)

    ui.display.clear()
    ui.display.avatar(48, 48, image, ui.TITLE_GREY, ui.BG)
    ui.display.text_center(ui.WIDTH // 2, 35, label, ui.BOLD, ui.TITLE_GREY, ui.BG)

    ui.display.bar_radius(40, 100, 160, 40, ui.TITLE_GREY, ui.BG, 4)
    ui.display.bar_radius(42, 102, 156, 36, ui.BG, ui.TITLE_GREY, 4)
    ui.display.text_center(ui.WIDTH // 2, 128, "Locked", ui.BOLD, ui.TITLE_GREY, ui.BG)

    ui.display.text_center(
        ui.WIDTH // 2 + 10, 220, "Tap to unlock", ui.BOLD, ui.TITLE_GREY, ui.BG
    )
    ui.display.icon(45, 202, res.load(ui.ICON_CLICK), ui.TITLE_GREY, ui.BG)

    await ui.backlight_slide(ui.BACKLIGHT_NORMAL)
    await ui.click()
github trezor / trezor-firmware / core / src / apps / monero / layout / confirms.py View on Github external
def on_render(self):
        current = self.current
        total_num = self.total_num
        ui.header("Syncing", ui.ICON_SEND, ui.TITLE_GREY, ui.BG, ui.BLUE)
        p = (1000 * (current + 1) // total_num) if total_num > 0 else 0
        ui.display.loader(p, False, 18, ui.WHITE, ui.BG)
github trezor / trezor-firmware / core / src / apps / homescreen / homescreen.py View on Github external
def on_render(self) -> None:
        if not self.repaint:
            return

        image = None
        if not storage.is_initialized():
            label = "Go to trezor.io/start"
        else:
            label = storage.device.get_label() or "My Trezor"
            image = storage.device.get_homescreen()

        if not image:
            image = res.load("apps/homescreen/res/bg.toif")

        if storage.is_initialized() and storage.device.no_backup():
            ui.header_error("SEEDLESS")
        elif storage.is_initialized() and storage.device.unfinished_backup():
            ui.header_error("BACKUP FAILED!")
        elif storage.is_initialized() and storage.device.needs_backup():
            ui.header_warning("NEEDS BACKUP!")
        elif storage.is_initialized() and not config.has_pin():
            ui.header_warning("PIN NOT SET!")
        else:
            ui.display.bar(0, 0, ui.WIDTH, ui.HEIGHT, ui.BG)
        ui.display.avatar(48, 48 - 10, image, ui.WHITE, ui.BLACK)
        ui.display.text_center(ui.WIDTH // 2, 220, label, ui.BOLD, ui.FG, ui.BG)

        self.repaint = False
github trezor / trezor-firmware / src / apps / homescreen / homescreen.py View on Github external
async def display_homescreen():
    from apps.common import storage

    if not storage.is_initialized():
        label = 'Open trezor.io/start'
        image = None
    else:
        label = storage.get_label() or 'My TREZOR'
        image = storage.get_homescreen()

    if not image:
        image = res.load('apps/homescreen/res/homescreen.toif')

    ui.display.bar(0, 0, ui.SCREEN, ui.SCREEN, ui.BG)
    ui.display.avatar((ui.SCREEN - 144) // 2, (ui.SCREEN - 144) // 2 - 10, image, ui.WHITE, ui.BLACK)
    ui.display.text_center(ui.SCREEN // 2, ui.SCREEN - 20, label, ui.BOLD, ui.FG, ui.BG)

    await dim_screen()
github trezor / trezor-firmware / core / src / apps / monero / layout / confirms.py View on Github external
def on_render(self):
        state = self.state
        info = self.info
        ui.header("Signing transaction", ui.ICON_SEND, ui.TITLE_GREY, ui.BG, ui.BLUE)
        p = 1000 * state.progress_cur // state.progress_total
        ui.display.loader(p, False, -4, ui.WHITE, ui.BG)
        ui.display.text_center(ui.WIDTH // 2, 210, info[0], ui.NORMAL, ui.FG, ui.BG)
        if len(info) > 1:
            ui.display.text_center(ui.WIDTH // 2, 235, info[1], ui.NORMAL, ui.FG, ui.BG)
github trezor / trezor-core / src / trezor / pin.py View on Github external
def show_pin_timeout(seconds: int, progress: int, message: str) -> bool:
    global _previous_progress

    if progress == 0:
        if progress != _previous_progress:
            # avoid overdraw in case of repeated progress calls
            ui.display.clear()
        ui.display.text_center(
            ui.WIDTH // 2, 37, message, ui.BOLD, ui.FG, ui.BG, ui.WIDTH
        )
    ui.display.loader(progress, 0, ui.FG, ui.BG)
    if seconds == 0:
        ui.display.text_center(
            ui.WIDTH // 2, ui.HEIGHT - 22, "Done", ui.BOLD, ui.FG, ui.BG, ui.WIDTH
        )
    elif seconds == 1:
        ui.display.text_center(
            ui.WIDTH // 2,
            ui.HEIGHT - 22,
            "1 second left",
            ui.BOLD,
            ui.FG,
            ui.BG,
            ui.WIDTH,
        )
    else:
        ui.display.text_center(
            ui.WIDTH // 2,
            ui.HEIGHT - 22,
github trezor / trezor-core / src / apps / homescreen / homescreen.py View on Github external
elif storage.is_initialized() and storage.needs_backup():
        ui.display.bar(0, 0, ui.WIDTH, 30, ui.YELLOW)
        ui.display.text_center(
            ui.WIDTH // 2, 22, "NEEDS BACKUP!", ui.BOLD, ui.BLACK, ui.YELLOW
        )
        ui.display.bar(0, 30, ui.WIDTH, ui.HEIGHT - 30, ui.BG)
    elif storage.is_initialized() and not config.has_pin():
        ui.display.bar(0, 0, ui.WIDTH, 30, ui.YELLOW)
        ui.display.text_center(
            ui.WIDTH // 2, 22, "PIN NOT SET!", ui.BOLD, ui.BLACK, ui.YELLOW
        )
        ui.display.bar(0, 30, ui.WIDTH, ui.HEIGHT - 30, ui.BG)
    else:
        ui.display.bar(0, 0, ui.WIDTH, ui.HEIGHT, ui.BG)
    ui.display.avatar(48, 48 - 10, image, ui.WHITE, ui.BLACK)
    ui.display.text_center(ui.WIDTH // 2, 220, label, ui.BOLD, ui.FG, ui.BG)