Ejemplo n.º 1
0
def test_signtx_data_pagination(client: Client, flow):
    with client:
        client.watch_layout()
        client.set_input_flow(flow(client))
        ethereum.sign_tx(
            client,
            n=parse_path("m/44h/60h/0h/0/0"),
            nonce=0x0,
            gas_price=0x14,
            gas_limit=0x14,
            to="0x1d1c328764a41bda0492b66baa30c4a339ff85ef",
            chain_id=1,
            value=0xA,
            tx_type=None,
            data=bytes.fromhex(HEXDATA),
        )

    with client, pytest.raises(exceptions.Cancelled):
        client.watch_layout()
        client.set_input_flow(flow(client, cancel=True))
        ethereum.sign_tx(
            client,
            n=parse_path("m/44h/60h/0h/0/0"),
            nonce=0x0,
            gas_price=0x14,
            gas_limit=0x14,
            to="0x1d1c328764a41bda0492b66baa30c4a339ff85ef",
            chain_id=1,
            value=0xA,
            tx_type=None,
            data=bytes.fromhex(HEXDATA),
        )
Ejemplo n.º 2
0
def test_ethereum_sign_typed_data_cancel(client: Client):
    with client, pytest.raises(exceptions.Cancelled):
        client.watch_layout()
        client.set_input_flow(input_flow_cancel(client))
        ethereum.sign_typed_data(
            client,
            parse_path("m/44h/60h/0h/0/0"),
            DATA,
            metamask_v4_compat=True,
        )
Ejemplo n.º 3
0
def test_ethereum_sign_typed_data_show_more_button(client: Client):
    with client:
        client.watch_layout()
        client.set_input_flow(input_flow_show_more(client))
        ethereum.sign_typed_data(
            client,
            parse_path("m/44h/60h/0h/0/0"),
            DATA,
            metamask_v4_compat=True,
        )
def test_invalid_seed_core(client: Client):
    def input_flow():
        yield
        layout = client.debug.wait_layout()
        assert "check the recovery seed" in layout.text.replace("\n", " ")
        client.debug.click(buttons.OK)

        yield
        layout = client.debug.wait_layout()
        assert "Select number of words" in layout.text
        client.debug.click(buttons.OK)

        yield
        layout = client.debug.wait_layout()
        assert layout.text == "WordSelector"
        # select 12 words
        client.debug.click(buttons.grid34(0, 2))

        yield
        layout = client.debug.wait_layout()
        assert "Enter recovery seed" in layout.text
        client.debug.click(buttons.OK)

        yield
        for _ in range(12):
            layout = client.debug.wait_layout()
            assert layout.text == "Bip39Keyboard"
            client.debug.input("stick")

        br = yield
        layout = client.debug.wait_layout()
        assert br.code == messages.ButtonRequestType.Warning
        assert "invalid recovery seed" in layout.text
        client.debug.click(buttons.OK)

        yield
        # retry screen
        layout = client.debug.wait_layout()
        assert "Select number of words" in layout.text
        client.debug.click(buttons.CANCEL)

        yield
        layout = client.debug.wait_layout()
        assert "abort" in layout.text
        client.debug.click(buttons.OK)

    with client:
        client.watch_layout()
        client.set_input_flow(input_flow)
        with pytest.raises(exceptions.Cancelled):
            return device.recover(client, dry_run=True)
Ejemplo n.º 5
0
def test_tt_pin_passphrase(client: Client):
    layout = client.debug.wait_layout
    mnemonic = MNEMONIC12.split(" ")

    def input_flow():
        yield
        assert "Do you really want to recover a wallet?" in layout().text
        client.debug.press_yes()

        yield
        assert layout().text == "PinDialog"
        client.debug.input("654")

        yield
        assert layout().text == "PinDialog"
        client.debug.input("654")

        yield
        assert "Select number of words" in layout().text
        client.debug.press_yes()

        yield
        assert "WordSelector" in layout().text
        client.debug.input(str(len(mnemonic)))

        yield
        assert "Enter recovery seed" in layout().text
        client.debug.press_yes()

        yield
        for word in mnemonic:
            assert layout().text == "Bip39Keyboard"
            client.debug.input(word)

        yield
        assert "You have successfully recovered your wallet." in layout().text
        client.debug.press_yes()

    with client:
        client.set_input_flow(input_flow)
        client.watch_layout()
        device.recover(
            client, pin_protection=True, passphrase_protection=True, label="hello"
        )

    assert client.debug.state().mnemonic_secret.decode() == MNEMONIC12

    assert client.features.pin_protection is True
    assert client.features.passphrase_protection is True
    assert client.features.backup_type is messages.BackupType.Bip39
    assert client.features.label == "hello"
Ejemplo n.º 6
0
def test_payment_request_details(client: Client):
    # Test that payment request details are shown when requested.
    outputs[0].payment_req_index = 0
    outputs[1].payment_req_index = 0
    outputs[2].payment_req_index = None
    nonce = misc.get_nonce(client)
    payment_reqs = [
        make_payment_request(
            client,
            recipient_name="trezor.io",
            outputs=outputs[:2],
            memos=[TextMemo("Invoice #87654321.")],
            nonce=nonce,
        )
    ]

    def input_flow():
        yield  # request to see details
        client.debug.wait_layout()
        client.debug.press_info()

        yield  # confirm first output
        layout = client.debug.wait_layout()
        assert outputs[0].address[:16] in layout.text
        client.debug.press_yes()

        yield  # confirm second output
        layout = client.debug.wait_layout()
        assert outputs[1].address[:16] in layout.text
        client.debug.press_yes()

        yield  # confirm transaction
        client.debug.press_yes()

    with client:
        client.set_input_flow(input_flow)
        client.watch_layout(True)

        _, serialized_tx = btc.sign_tx(
            client,
            "Testnet",
            inputs,
            outputs,
            prev_txes=PREV_TXES,
            payment_reqs=payment_reqs,
        )

    assert serialized_tx.hex() == SERIALIZED_TX
def do_recover_core(client: Client, mnemonic, **kwargs):
    def input_flow():
        yield
        layout = client.debug.wait_layout()
        assert "check the recovery seed" in layout.text.replace("\n", " ")
        client.debug.click(buttons.OK)

        yield
        layout = client.debug.wait_layout()
        assert "Select number of words" in layout.text
        client.debug.click(buttons.OK)

        yield
        layout = client.debug.wait_layout()
        assert layout.text == "WordSelector"
        # click the number
        word_option_offset = 6
        word_options = (12, 18, 20, 24, 33)
        index = word_option_offset + word_options.index(len(mnemonic))
        client.debug.click(buttons.grid34(index % 3, index // 3))

        yield
        layout = client.debug.wait_layout()
        assert "Enter recovery seed" in layout.text
        client.debug.click(buttons.OK)

        yield
        for word in mnemonic:
            client.debug.wait_layout()
            client.debug.input(word)

        yield
        client.debug.wait_layout()
        client.debug.click(buttons.OK)

    with client:
        client.watch_layout()
        client.set_input_flow(input_flow)
        return device.recover(client, dry_run=True, **kwargs)
Ejemplo n.º 8
0
def call_sign_tx(client: Client, parameters, input_flow=None):
    client.init_device(new_session=True, derive_cardano=True)

    signing_mode = messages.CardanoTxSigningMode.__members__[
        parameters["signing_mode"]]
    inputs = [cardano.parse_input(i) for i in parameters["inputs"]]
    outputs = [cardano.parse_output(o) for o in parameters["outputs"]]
    certificates = [
        cardano.parse_certificate(c) for c in parameters["certificates"]
    ]
    withdrawals = [
        cardano.parse_withdrawal(w) for w in parameters["withdrawals"]
    ]
    auxiliary_data = cardano.parse_auxiliary_data(parameters["auxiliary_data"])
    mint = cardano.parse_mint(parameters["mint"])
    script_data_hash = cardano.parse_script_data_hash(
        parameters["script_data_hash"])
    collateral_inputs = [
        cardano.parse_collateral_input(i)
        for i in parameters["collateral_inputs"]
    ]
    required_signers = [
        cardano.parse_required_signer(s)
        for s in parameters["required_signers"]
    ]
    collateral_return = (cardano.parse_output(parameters["collateral_return"])
                         if parameters["collateral_return"] is not None else
                         None)
    reference_inputs = [
        cardano.parse_reference_input(i)
        for i in parameters["reference_inputs"]
    ]
    additional_witness_requests = [
        cardano.parse_additional_witness_request(p)
        for p in parameters["additional_witness_requests"]
    ]

    if parameters.get("security_checks") == "prompt":
        device.apply_settings(
            client, safety_checks=messages.SafetyCheckLevel.PromptTemporarily)
    else:
        device.apply_settings(client,
                              safety_checks=messages.SafetyCheckLevel.Strict)

    with client:
        if input_flow is not None:
            client.watch_layout()
            client.set_input_flow(input_flow(client))

        return cardano.sign_tx(
            client=client,
            signing_mode=signing_mode,
            inputs=inputs,
            outputs=outputs,
            fee=parameters["fee"],
            ttl=parameters["ttl"],
            validity_interval_start=parameters["validity_interval_start"],
            certificates=certificates,
            withdrawals=withdrawals,
            protocol_magic=parameters["protocol_magic"],
            network_id=parameters["network_id"],
            auxiliary_data=auxiliary_data,
            mint=mint,
            script_data_hash=script_data_hash,
            collateral_inputs=collateral_inputs,
            required_signers=required_signers,
            collateral_return=collateral_return,
            total_collateral=parameters["total_collateral"],
            reference_inputs=reference_inputs,
            additional_witness_requests=additional_witness_requests,
            include_network_id=parameters["include_network_id"],
        )
Ejemplo n.º 9
0
def test_sd_protect_unlock(client: Client):
    def input_flow_enable_sd_protect():
        yield  # Enter PIN to unlock device
        assert "PinDialog" == client.debug.wait_layout().text
        client.debug.input("1234")

        yield  # do you really want to enable SD protection
        assert "SD card protection" in client.debug.wait_layout().text
        client.debug.press_yes()

        yield  # enter current PIN
        assert "PinDialog" == client.debug.wait_layout().text
        client.debug.input("1234")

        yield  # you have successfully enabled SD protection
        assert "Success" in client.debug.wait_layout().text
        client.debug.press_yes()

    with client:
        client.watch_layout()
        client.set_input_flow(input_flow_enable_sd_protect)
        device.sd_protect(client, Op.ENABLE)

    def input_flow_change_pin():
        yield  # do you really want to change PIN?
        assert "Change PIN" in client.debug.wait_layout().text
        client.debug.press_yes()

        yield  # enter current PIN
        assert "PinDialog" == client.debug.wait_layout().text
        client.debug.input("1234")

        yield  # enter new PIN
        assert "PinDialog" == client.debug.wait_layout().text
        client.debug.input("1234")

        yield  # enter new PIN again
        assert "PinDialog" == client.debug.wait_layout().text
        client.debug.input("1234")

        yield  # Pin change successful
        assert "Success" in client.debug.wait_layout().text
        client.debug.press_yes()

    with client:
        client.watch_layout()
        client.set_input_flow(input_flow_change_pin)
        device.change_pin(client)

    client.debug.erase_sd_card(format=False)

    def input_flow_change_pin_format():
        yield  # do you really want to change PIN?
        assert "Change PIN" in client.debug.wait_layout().text
        client.debug.press_yes()

        yield  # enter current PIN
        assert "PinDialog" == client.debug.wait_layout().text
        client.debug.input("1234")

        yield  # SD card problem
        assert "Wrong SD card" in client.debug.wait_layout().text
        client.debug.press_no()  # close

    with client, pytest.raises(TrezorFailure) as e:
        client.watch_layout()
        client.set_input_flow(input_flow_change_pin_format)
        device.change_pin(client)

    assert e.value.code == messages.FailureType.ProcessError