async def request_pin_ack(ctx: wire.Context, *args: Any, **kwargs: Any) -> str:
    try:
        await ctx.call(ButtonRequest(code=ButtonRequestType.Other), ButtonAck)
        pin = await ctx.wait(request_pin(*args, **kwargs))
        assert isinstance(pin, str)
        return pin
    except PinCancelled:
        raise wire.ActionCancelled("Cancelled")
Example #2
0
async def request_wordcount(ctx, title: str) -> int:
    await ctx.call(ButtonRequest(code=MnemonicWordCount), ButtonAck)

    text = Text(title, ui.ICON_RECOVERY)
    text.normal("Number of words?")
    count = await ctx.wait(WordSelector(text))

    return count
Example #3
0
async def hold_to_confirm(ctx, content, code=None, *args, **kwargs):
    if code is None:
        code = ButtonRequestType.Other
    await ctx.call(ButtonRequest(code=code), wire_types.ButtonAck)

    dialog = HoldToConfirmDialog(content, 'Hold to confirm', *args, **kwargs)

    return await ctx.wait(dialog) == CONFIRMED
Example #4
0
async def confirm(ctx, content, code=None, *args, **kwargs):
    if code is None:
        code = ButtonRequestType.Other
    await ctx.call(ButtonRequest(code=code), MessageType.ButtonAck)

    dialog = ConfirmDialog(content, *args, **kwargs)

    return await ctx.wait(dialog) == CONFIRMED
Example #5
0
async def request_wordcount(ctx):
    await ctx.call(ButtonRequest(code=MnemonicWordCount), ButtonAck)

    text = Text("Device recovery", ui.ICON_RECOVERY)
    text.normal("Number of words?")
    count = await ctx.wait(WordSelector(text))

    return count
Example #6
0
async def show_mnemonic(ctx, mnemonic: str):
    await ctx.call(
        ButtonRequest(code=ButtonRequestType.ResetDevice), wire_types.ButtonAck)
    first_page = const(0)
    words_per_page = const(4)
    words = list(enumerate(mnemonic.split()))
    pages = list(chunks(words, words_per_page))
    await paginate(show_mnemonic_page, len(pages), first_page, pages)
Example #7
0
async def request_wordcount(ctx):
    await ctx.call(ButtonRequest(code=MnemonicWordCount), ButtonAck)

    content = Text('Device recovery', ui.ICON_RECOVERY, 'Number of words?')
    select = WordSelector(content)
    count = await select

    return count
Example #8
0
async def request_pin(ctx):
    from trezor.messages.ButtonRequest import ButtonRequest
    from trezor.messages.wire_types import ButtonAck
    from apps.common.request_pin import request_pin

    await ctx.call(ButtonRequest(), ButtonAck)

    return await request_pin()
Example #9
0
async def request_pin_ack(ctx, *args, **kwargs):
    try:
        await ctx.call(
            ButtonRequest(code=ButtonRequestType.Other), MessageType.ButtonAck
        )
        return await ctx.wait(request_pin(*args, **kwargs))
    except PinCancelled:
        raise wire.ActionCancelled("Cancelled")
Example #10
0
async def request_passphrase_source(ctx: wire.Context) -> int:
    req = ButtonRequest(code=ButtonRequestType.PassphraseType)
    await ctx.call(req, ButtonAck)

    text = Text("Enter passphrase", ui.ICON_CONFIG)
    text.normal("Where to enter your", "passphrase?")
    source = PassphraseSource(text)

    return await ctx.wait(source)
Example #11
0
async def interact(
    ctx: wire.GenericContext,
    layout: LayoutType,
    brtype: str,
    brcode: EnumTypeButtonRequestType = ButtonRequestType.Other,
) -> Any:
    log.debug(__name__, "ButtonRequest.type={}".format(brtype))
    workflow.close_others()
    await ctx.call(ButtonRequest(code=brcode), ButtonAck)
    return await ctx.wait(layout)
async def request_passphrase_source(ctx: wire.Context) -> int:
    req = ButtonRequest(code=ButtonRequestType.PassphraseType)
    await ctx.call(req, ButtonAck)

    text = Text("Enter passphrase", ui.ICON_CONFIG)
    text.normal("Where do you want to", "enter your passphrase?")
    source = PassphraseSource(text)

    response = await ctx.wait(source)
    assert isinstance(response, int)
    return response
Example #13
0
async def request_mnemonic(ctx, count: int) -> str:
    await ctx.call(ButtonRequest(code=MnemonicInput), ButtonAck)

    words = []
    board = MnemonicKeyboard()
    for i in range(count):
        board.prompt = "Type the %s word:" % format_ordinal(i + 1)
        word = await ctx.wait(board)
        words.append(word)

    return " ".join(words)
Example #14
0
async def hold_to_confirm(ctx, content, code=None, *args, **kwargs):
    if code is None:
        code = ButtonRequestType.Other
    await ctx.call(ButtonRequest(code=code), wire_types.ButtonAck)

    dialog = HoldToConfirmDialog(content, 'Hold to confirm', *args, **kwargs)

    if __debug__:
        waiter = loop.wait(signal, dialog)
    else:
        waiter = dialog
    return await waiter == CONFIRMED
Example #15
0
async def confirm(ctx, content, code=None, *args, **kwargs):
    if code is None:
        code = ButtonRequestType.Other
    await ctx.call(ButtonRequest(code=code), wire_types.ButtonAck)

    dialog = ConfirmDialog(content, *args, **kwargs)

    if __debug__:
        waiter = ctx.wait(signal, dialog)
    else:
        waiter = ctx.wait(dialog)
    return await waiter == CONFIRMED
async def request_passphrase_entry(ctx):
    text = Text('Enter passphrase', ui.ICON_CONFIG, 'Where to enter your',
                'passphrase?')
    text.render()

    ack = await ctx.call(ButtonRequest(code=ButtonRequestType.PassphraseType),
                         wire_types.ButtonAck, wire_types.Cancel)
    if ack.MESSAGE_WIRE_TYPE == wire_types.Cancel:
        raise wire.ActionCancelled('Passphrase cancelled')

    selector = EntrySelector(text)
    return await ctx.wait(selector)
async def show_keyboard_info(ctx):
    await ctx.call(ButtonRequest(code=ButtonRequestType.Other), ButtonAck)

    info = InfoConfirm("One more thing. "
                       "You can type the letters "
                       "the old-fashioned way "
                       "one by one or use our "
                       "T9 keyboard and press "
                       "buttons only once.")
    if __debug__:
        await ctx.wait(info, confirm_signal)
    else:
        await ctx.wait(info)
Example #18
0
async def request_mnemonic(ctx, count: int) -> str:
    await ctx.call(ButtonRequest(code=MnemonicInput), ButtonAck)

    words = []
    for i in range(count):
        keyboard = MnemonicKeyboard("Type the %s word:" % format_ordinal(i + 1))
        if __debug__:
            word = await ctx.wait(keyboard, input_signal)
        else:
            word = await ctx.wait(keyboard)
        words.append(word)

    return " ".join(words)
Example #19
0
async def request_wordcount(ctx, title: str) -> int:
    await ctx.call(ButtonRequest(code=MnemonicWordCount), ButtonAck)

    text = Text(title, ui.ICON_RECOVERY)
    text.normal("Number of words?")

    if __debug__:
        count = await ctx.wait(WordSelector(text), input_signal)
        count = int(count)  # if input_signal was triggered, count is a string
    else:
        count = await ctx.wait(WordSelector(text))

    return count
Example #20
0
async def _request_on_device(ctx: wire.Context) -> str:
    await ctx.call(ButtonRequest(code=ButtonRequestType.PassphraseEntry), ButtonAck)

    keyboard = PassphraseKeyboard("Enter passphrase", _MAX_PASSPHRASE_LEN)
    if __debug__:
        passphrase = await ctx.wait(keyboard, input_signal())
    else:
        passphrase = await ctx.wait(keyboard)
    if passphrase is CANCELLED:
        raise wire.ActionCancelled("Passphrase entry cancelled")

    assert isinstance(passphrase, str)

    return passphrase
Example #21
0
async def hold_to_confirm(ctx, content, code=None, *args, **kwargs):
    from trezor.ui.confirm import HoldToConfirmDialog, CONFIRMED
    from trezor.messages.ButtonRequest import ButtonRequest
    from trezor.messages.ButtonRequestType import Other
    from trezor.messages.wire_types import ButtonAck

    ui.display.clear()

    dialog = HoldToConfirmDialog(content, 'Hold to confirm', *args, **kwargs)

    if code is None:
        code = Other
    await ctx.call(ButtonRequest(code=code), ButtonAck)
    return await loop.Wait((signal, dialog)) == CONFIRMED
Example #22
0
async def show_keyboard_info(ctx: wire.Context) -> None:
    await ctx.call(ButtonRequest(code=ButtonRequestType.Other), ButtonAck)

    info = InfoConfirm(
        "Did you know? "
        "You can type the letters "
        "one by one or use it like "
        "a T9 keyboard.",
        "Great!",
    )
    if __debug__:
        await ctx.wait(info, confirm_signal)
    else:
        await ctx.wait(info)
Example #23
0
async def confirm(session_id, content, code=None, *args, **kwargs):
    from trezor.ui.confirm import ConfirmDialog, CONFIRMED
    from trezor.messages.ButtonRequest import ButtonRequest
    from trezor.messages.ButtonRequestType import Other
    from trezor.messages.wire_types import ButtonAck

    ui.display.clear()
    dialog = ConfirmDialog(content, *args, **kwargs)
    dialog.render()

    if code is None:
        code = Other
    await wire.call(session_id, ButtonRequest(code=code), ButtonAck)
    return await loop.Wait((signal, dialog)) == CONFIRMED
Example #24
0
async def confirm_action_sellram(ctx, msg: EosActionSellRam):
    await ctx.call(ButtonRequest(code=ButtonRequestType.ConfirmOutput),
                   MessageType.ButtonAck)

    text = "Sell RAM"
    fields = []
    fields.append("Receiver:")
    fields.append(helpers.eos_name_to_string(msg.account))
    fields.append("Bytes:")
    fields.append(str(msg.bytes))

    pages = list(chunks(fields, _TWO_FIELDS_PER_PAGE))
    paginator = paginate(show_lines_page, len(pages), _FIRST_PAGE, pages, text)

    await ctx.wait(paginator)
Example #25
0
async def request_passphrase_entry(ctx):
    text = Text("Enter passphrase", ui.ICON_CONFIG)
    text.normal("Where to enter your", "passphrase?")
    text.render()

    ack = await ctx.call(
        ButtonRequest(code=ButtonRequestType.PassphraseType),
        MessageType.ButtonAck,
        MessageType.Cancel,
    )
    if ack.MESSAGE_WIRE_TYPE == MessageType.Cancel:
        raise wire.ActionCancelled("Passphrase cancelled")

    selector = EntrySelector(text)
    return await ctx.wait(selector)
Example #26
0
async def request_word_count(ctx: wire.Context, dry_run: bool) -> int:
    await ctx.call(ButtonRequest(code=ButtonRequestType.MnemonicWordCount), ButtonAck)

    if dry_run:
        text = Text("Seed check", ui.ICON_RECOVERY)
    else:
        text = Text("Recovery mode", ui.ICON_RECOVERY)
    text.normal("Number of words?")

    if __debug__:
        count = await ctx.wait(WordSelector(text), input_signal())
        count = int(count)  # if input_signal was triggered, count is a string
    else:
        count = await ctx.wait(WordSelector(text))

    return count
Example #27
0
async def request_mnemonic(ctx: wire.Context, count: int, slip39: bool) -> str:
    await ctx.call(ButtonRequest(code=ButtonRequestType.MnemonicInput), ButtonAck)

    words = []
    for i in range(count):
        if slip39:
            keyboard = Slip39Keyboard("Type word %s of %s:" % (i + 1, count))
        else:
            keyboard = Bip39Keyboard("Type word %s of %s:" % (i + 1, count))
        if __debug__:
            word = await ctx.wait(keyboard, input_signal)
        else:
            word = await ctx.wait(keyboard)
        words.append(word)

    return " ".join(words)
Example #28
0
async def request_mnemonic(
    ctx: wire.Context,
    word_count: int,
    mnemonic_type: int,
    mnemonics: List[str],
    advanced_shamir: bool = False,
) -> str:
    await ctx.call(ButtonRequest(code=ButtonRequestType.MnemonicInput),
                   ButtonAck)

    words = []
    for i in range(word_count):
        if mnemonic_type == mnemonic.TYPE_SLIP39:
            keyboard = Slip39Keyboard("Type word %s of %s:" %
                                      (i + 1, word_count))
        else:
            keyboard = Bip39Keyboard("Type word %s of %s:" %
                                     (i + 1, word_count))
        if __debug__:
            word = await ctx.wait(keyboard, input_signal())
        else:
            word = await ctx.wait(keyboard)

        if mnemonic_type == mnemonic.TYPE_SLIP39 and mnemonics:
            if not advanced_shamir:
                # check if first 3 words of mnemonic match
                # we can check against the first one, others were checked already
                if i < 3:
                    share_list = mnemonics[0].split(" ")
                    if share_list[i] != word:
                        raise IdentifierMismatchError()
                elif i == 3:
                    for share in mnemonics:
                        share_list = share.split(" ")
                        # check if the fourth word is different from previous shares
                        if share_list[i] == word:
                            raise ShareAlreadyAddedError()
            else:
                # in case of advanced shamir recovery we only check 2 words
                if i < 2:
                    share_list = mnemonics[0].split(" ")
                    if share_list[i] != word:
                        raise IdentifierMismatchError()

        words.append(word)

    return " ".join(words)
Example #29
0
async def confirm_action_unknown(ctx, action, checksum):
    await ctx.call(ButtonRequest(code=ButtonRequestType.ConfirmOutput),
                   MessageType.ButtonAck)
    text = "Arbitrary data"
    fields = []
    fields.append("Contract:")
    fields.append(helpers.eos_name_to_string(action.account))
    fields.append("Action Name:")
    fields.append(helpers.eos_name_to_string(action.name))

    fields.append("Checksum: ")
    fields += split_data(hexlify(checksum).decode("ascii"))

    pages = list(chunks(fields, _FIVE_FIELDS_PER_PAGE))
    paginator = paginate(show_lines_page, len(pages), _FIRST_PAGE, pages, text)

    await ctx.wait(paginator)
Example #30
0
async def confirm_action_buyrambytes(ctx, msg: EosActionBuyRamBytes):
    await ctx.call(ButtonRequest(code=ButtonRequestType.ConfirmOutput),
                   MessageType.ButtonAck)

    text = "Buy RAM"
    fields = []
    fields.append("Payer:")
    fields.append(helpers.eos_name_to_string(msg.payer))
    fields.append("Receiver:")
    fields.append(helpers.eos_name_to_string(msg.receiver))
    fields.append("Bytes:")
    fields.append(str(msg.bytes))

    pages = list(chunks(fields, _FOUR_FIELDS_PER_PAGE))
    paginator = paginate(show_lines_page, len(pages), _FIRST_PAGE, pages, text)

    await ctx.wait(paginator)