2018-06-21 14:28:34 +00:00
|
|
|
# This file is part of the Trezor project.
|
2017-01-03 18:40:05 +00:00
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2017-01-03 18:40:05 +00:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
2018-06-21 14:28:34 +00:00
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
2017-01-03 18:40:05 +00:00
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
2018-06-21 14:28:34 +00:00
|
|
|
# You should have received a copy of the License along with this library.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
2017-01-03 18:40:05 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
import pytest
|
|
|
|
|
2020-03-04 14:12:30 +00:00
|
|
|
from trezorlib import btc, messages, tools
|
2022-01-31 12:25:30 +00:00
|
|
|
from trezorlib.debuglink import TrezorClientDebugLink as Client
|
2023-02-14 22:47:20 +00:00
|
|
|
from trezorlib.exceptions import Cancelled, TrezorFailure
|
2018-08-13 16:21:24 +00:00
|
|
|
|
2024-05-21 21:49:08 +00:00
|
|
|
from ...common import is_core
|
2023-05-04 12:18:55 +00:00
|
|
|
from ...input_flows import (
|
2024-05-21 21:49:08 +00:00
|
|
|
InputFlowConfirmAllWarnings,
|
2023-05-04 12:18:55 +00:00
|
|
|
InputFlowShowAddressQRCode,
|
|
|
|
InputFlowShowAddressQRCodeCancel,
|
|
|
|
InputFlowShowMultisigXPUBs,
|
|
|
|
)
|
|
|
|
|
2020-05-13 09:36:03 +00:00
|
|
|
VECTORS = ( # path, script_type, address
|
|
|
|
(
|
|
|
|
"m/44h/0h/12h/0/0",
|
|
|
|
messages.InputScriptType.SPENDADDRESS,
|
|
|
|
"1FM6Kz3oT3GoGv65jNpU8AFFun8nHAXrPk",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"m/49h/0h/12h/0/0",
|
|
|
|
messages.InputScriptType.SPENDP2SHWITNESS,
|
|
|
|
"3HfEUkuwmtZ87XzowkiD5nMp5Q3hqKXZ2i",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"m/84h/0h/12h/0/0",
|
|
|
|
messages.InputScriptType.SPENDWITNESS,
|
|
|
|
"bc1qduvap743hcl7twn8u6f9l0u8y7x83965xy0raj",
|
|
|
|
),
|
2022-08-31 10:16:14 +00:00
|
|
|
(
|
|
|
|
"m/86h/0h/12h/0/0",
|
|
|
|
messages.InputScriptType.SPENDTAPROOT,
|
|
|
|
"bc1pnzsh9t0n0vjanwgkuf9cyrp6j6lhfe63xaekuu7qxkse93vkyvgqxn4hff",
|
|
|
|
),
|
2020-05-13 09:36:03 +00:00
|
|
|
)
|
|
|
|
|
2023-02-14 22:47:20 +00:00
|
|
|
|
2024-09-02 11:01:16 +00:00
|
|
|
@pytest.mark.models("legacy")
|
2020-05-13 09:36:03 +00:00
|
|
|
@pytest.mark.parametrize("path, script_type, address", VECTORS)
|
2023-02-14 22:47:20 +00:00
|
|
|
def test_show_t1(
|
2022-10-25 13:08:19 +00:00
|
|
|
client: Client, path: str, script_type: messages.InputScriptType, address: str
|
|
|
|
):
|
2023-05-04 12:18:55 +00:00
|
|
|
def input_flow_t1():
|
2022-03-09 09:00:24 +00:00
|
|
|
yield
|
|
|
|
client.debug.press_no()
|
|
|
|
yield
|
|
|
|
client.debug.press_yes()
|
|
|
|
|
|
|
|
with client:
|
2023-05-04 12:18:55 +00:00
|
|
|
# This is the only place where even T1 is using input flow
|
|
|
|
client.set_input_flow(input_flow_t1)
|
2022-03-09 09:00:24 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
tools.parse_path(path),
|
|
|
|
script_type=script_type,
|
|
|
|
show_display=True,
|
|
|
|
)
|
|
|
|
== address
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2020-05-13 09:36:03 +00:00
|
|
|
|
|
|
|
|
2024-09-02 11:01:16 +00:00
|
|
|
@pytest.mark.models("core")
|
2023-09-14 10:22:18 +00:00
|
|
|
@pytest.mark.parametrize("chunkify", (True, False))
|
2023-02-14 22:47:20 +00:00
|
|
|
@pytest.mark.parametrize("path, script_type, address", VECTORS)
|
|
|
|
def test_show_tt(
|
2023-09-14 10:22:18 +00:00
|
|
|
client: Client,
|
|
|
|
chunkify: bool,
|
|
|
|
path: str,
|
|
|
|
script_type: messages.InputScriptType,
|
|
|
|
address: str,
|
2023-02-14 22:47:20 +00:00
|
|
|
):
|
|
|
|
with client:
|
2023-05-04 12:18:55 +00:00
|
|
|
IF = InputFlowShowAddressQRCode(client)
|
|
|
|
client.set_input_flow(IF.get())
|
2023-02-14 22:47:20 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
tools.parse_path(path),
|
|
|
|
script_type=script_type,
|
|
|
|
show_display=True,
|
2023-09-14 10:22:18 +00:00
|
|
|
chunkify=chunkify,
|
2023-02-14 22:47:20 +00:00
|
|
|
)
|
|
|
|
== address
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-09-02 11:01:16 +00:00
|
|
|
@pytest.mark.models("core")
|
2023-02-14 22:47:20 +00:00
|
|
|
@pytest.mark.parametrize("path, script_type, address", VECTORS)
|
|
|
|
def test_show_cancel(
|
|
|
|
client: Client, path: str, script_type: messages.InputScriptType, address: str
|
|
|
|
):
|
|
|
|
with client, pytest.raises(Cancelled):
|
2023-05-04 12:18:55 +00:00
|
|
|
IF = InputFlowShowAddressQRCodeCancel(client)
|
|
|
|
client.set_input_flow(IF.get())
|
2023-02-14 22:47:20 +00:00
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
tools.parse_path(path),
|
|
|
|
script_type=script_type,
|
|
|
|
show_display=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_show_unrecognized_path(client: Client):
|
2021-06-23 15:28:50 +00:00
|
|
|
with pytest.raises(TrezorFailure):
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
tools.parse_path("m/24684621h/516582h/5156h/21/856"),
|
|
|
|
script_type=messages.InputScriptType.SPENDWITNESS,
|
|
|
|
show_display=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-05-13 09:36:03 +00:00
|
|
|
@pytest.mark.multisig
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_show_multisig_3(client: Client):
|
2024-11-14 17:43:59 +00:00
|
|
|
nodes = [
|
|
|
|
btc.get_public_node(
|
|
|
|
client, tools.parse_path(f"m/45h/{i}"), coin_name="Bitcoin"
|
|
|
|
).node
|
|
|
|
for i in [1, 2, 3]
|
|
|
|
]
|
|
|
|
|
|
|
|
# Multisig with global suffix specification.
|
|
|
|
multisig1 = messages.MultisigRedeemScriptType(
|
|
|
|
nodes=nodes, signatures=[b"", b"", b""], m=2, address_n=[0, 0]
|
|
|
|
)
|
|
|
|
|
|
|
|
# Multisig with per-node suffix specification.
|
|
|
|
multisig2 = messages.MultisigRedeemScriptType(
|
2020-05-13 09:36:03 +00:00
|
|
|
pubkeys=[
|
2024-11-14 17:43:59 +00:00
|
|
|
messages.HDNodePathType(node=node, address_n=[0, 0]) for node in nodes
|
2020-05-13 09:36:03 +00:00
|
|
|
],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
|
|
|
|
2024-11-14 17:43:59 +00:00
|
|
|
for multisig in (multisig1, multisig2):
|
|
|
|
for i in [1, 2, 3]:
|
|
|
|
with client:
|
|
|
|
if is_core(client):
|
|
|
|
IF = InputFlowConfirmAllWarnings(client)
|
|
|
|
client.set_input_flow(IF.get())
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
tools.parse_path(f"m/45h/{i}/0/0"),
|
|
|
|
show_display=True,
|
|
|
|
multisig=multisig,
|
|
|
|
script_type=messages.InputScriptType.SPENDMULTISIG,
|
|
|
|
)
|
|
|
|
== "3FQJAFhGpgryDeYh5trpFJTCvN3H5aX2Cg"
|
2024-05-21 21:49:08 +00:00
|
|
|
)
|
2014-12-10 14:42:38 +00:00
|
|
|
|
2014-12-10 17:03:54 +00:00
|
|
|
|
2021-07-30 15:39:14 +00:00
|
|
|
VECTORS_MULTISIG = ( # script_type, bip48_type, address, xpubs, ignore_xpub_magic
|
2021-01-14 16:37:39 +00:00
|
|
|
(
|
|
|
|
messages.InputScriptType.SPENDMULTISIG,
|
|
|
|
0,
|
|
|
|
"33TU5DyVi2kFSGQUfmZxNHgPDPqruwdesY",
|
|
|
|
[
|
|
|
|
"xpub6EgGHjcvovyMw8xyoJw9ZRUfjGLS1KUmbjVqMKSNfM6E8hq4EbQ3CpBxfGCPsdxzXtCFuKCxYarzY1TYCG1cmPwq9ep548cM9Ws9rB8V8E8",
|
|
|
|
"xpub6EexEtC6c2rN5QCpzrL2nUNGDfxizCi3kM1C2Mk5a6PfQs4H3F72C642M3XbnzycvvtD4U6vzn1nYPpH8VUmiREc2YuXP3EFgN1uLTrVEj4",
|
|
|
|
"xpub6F6Tq7sVLDrhuV3SpvsVKrKofF6Hx7oKxWLFkN6dbepuMhuYueKUnQo7E972GJyeRHqPKu44V1C9zBL6KW47GXjuprhbNrPQahWAFKoL2rN",
|
|
|
|
],
|
|
|
|
False,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
messages.InputScriptType.SPENDMULTISIG,
|
|
|
|
0,
|
|
|
|
"33TU5DyVi2kFSGQUfmZxNHgPDPqruwdesY",
|
|
|
|
[
|
|
|
|
"x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NfHXPsQrQMUkTvKSAzGkhRaJsgeo6AuEFZAi3bv7AkupGAt826Mt",
|
|
|
|
"xpub6EexEtC6c2rN75CLpLv7hp12esw1ospU4PyX4DmUC5cuvCRWkmY7PsdzmN7yhAmKB2iqa1eLqEPFUc1LGd1Py6iHzzbbXykYPadbh8xQonD",
|
|
|
|
"xpub6F6Tq7sVLDrhvq2kvj72MTttotm3ExftN1Yxbc2BYioUkFGNcTNgdEs48ZhfkLatd8DpgKjDnWiMM1f1Wj9GnfK6KWTzbT8J72afkGf7Y9T",
|
|
|
|
],
|
|
|
|
True,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
messages.InputScriptType.SPENDWITNESS,
|
|
|
|
2,
|
|
|
|
"bc1qqn9s63wly66rhzyz36hwzsa83augj5lve3ucqk5cpt5yvvze5ctsdfcg88",
|
|
|
|
[
|
|
|
|
"Zpub75Et2JhCgFchAwrkdQ2PWeCiEnLmQ8R8a8aANPL5r9a6L4VC9amvLtbmnZaEnS7m3YHd1ZnSYjKp1rFTZLm2cQ2CAuiEyNYaYWyeWEFGEmP",
|
|
|
|
"Zpub75DZyTGNUMVhGRgG7GsoF2FrsAAM48dPMMfYSo9G7iRxUg9FyuG3nMUSeYMXSF2rHtDNpv8skZZyDNzBq5x5znFtsPSDoaAXk5zBUBfdhSh",
|
|
|
|
"Zpub75f5ZgwmCYW37REirFNaE8DBg9qKJznqD498DsTAbX89Lk6tA98huCGM29mHAhwYTo1PSbWLQHXvsmMhDB8W9dFt3Eb2o6hT7HLDrcPebM5",
|
|
|
|
],
|
|
|
|
False,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
messages.InputScriptType.SPENDWITNESS,
|
|
|
|
2,
|
|
|
|
"bc1qqn9s63wly66rhzyz36hwzsa83augj5lve3ucqk5cpt5yvvze5ctsdfcg88",
|
|
|
|
[
|
|
|
|
"xpub6EgGHjcvovyN3nK921zAGPfuB41cJXkYRdt3tLGmiMyvbgHpss4X1eRZwShbEBb1znz2e2bCkCED87QZpin3sSYKbmCzQ9Sc7LaV98ngdeX",
|
|
|
|
"xpub6EexEtC6c2rN9G8eVtqZzmj3oRqBxXxoCryRxk5wyvqnkHwtiBYeT7JEoRUsszW7F8unTNwdx2UNKe9J6Ty7Fpn2JEvyEM4ZJub274iiT1V",
|
|
|
|
"xpub6F6Tq7sVLDrhzFh7EsLLysgNcRWADQ8F4ZT1jpPrTjXycMuWtRRJZx69B2tdcTQoR3ho54K6bkSKz2WoUZ9XQfn1U65nDsbUg6w4VZ5HWdA",
|
|
|
|
],
|
|
|
|
True,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-09-02 11:01:16 +00:00
|
|
|
@pytest.mark.models("core")
|
2020-05-13 09:36:03 +00:00
|
|
|
@pytest.mark.multisig
|
2021-01-14 16:37:39 +00:00
|
|
|
@pytest.mark.parametrize(
|
2021-07-30 15:39:14 +00:00
|
|
|
"script_type, bip48_type, address, xpubs, ignore_xpub_magic", VECTORS_MULTISIG
|
2021-01-14 16:37:39 +00:00
|
|
|
)
|
|
|
|
def test_show_multisig_xpubs(
|
2022-10-25 13:08:19 +00:00
|
|
|
client: Client,
|
|
|
|
script_type: messages.InputScriptType,
|
|
|
|
bip48_type: int,
|
|
|
|
address: str,
|
|
|
|
xpubs: list[str],
|
|
|
|
ignore_xpub_magic: bool,
|
2021-01-14 16:37:39 +00:00
|
|
|
):
|
2020-05-13 09:36:03 +00:00
|
|
|
nodes = [
|
|
|
|
btc.get_public_node(
|
2021-01-14 16:37:39 +00:00
|
|
|
client,
|
2022-01-31 12:25:30 +00:00
|
|
|
tools.parse_path(f"m/48h/0h/{i}h/{bip48_type}h"),
|
2021-01-14 16:37:39 +00:00
|
|
|
coin_name="Bitcoin",
|
2020-05-13 09:36:03 +00:00
|
|
|
)
|
|
|
|
for i in range(3)
|
|
|
|
]
|
|
|
|
multisig = messages.MultisigRedeemScriptType(
|
|
|
|
nodes=[n.node for n in nodes],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
address_n=[0, 0],
|
|
|
|
m=2,
|
|
|
|
)
|
|
|
|
|
|
|
|
for i in range(3):
|
|
|
|
with client:
|
2023-05-04 12:18:55 +00:00
|
|
|
IF = InputFlowShowMultisigXPUBs(client, address, xpubs, i)
|
|
|
|
client.set_input_flow(IF.get())
|
2023-03-21 09:44:50 +00:00
|
|
|
client.debug.synchronize_at("Homescreen")
|
|
|
|
client.watch_layout()
|
2020-05-13 09:36:03 +00:00
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
2022-01-31 12:25:30 +00:00
|
|
|
tools.parse_path(f"m/48h/0h/{i}h/{bip48_type}h/0/0"),
|
2020-05-13 09:36:03 +00:00
|
|
|
show_display=True,
|
|
|
|
multisig=multisig,
|
2021-01-14 16:37:39 +00:00
|
|
|
script_type=script_type,
|
|
|
|
ignore_xpub_magic=ignore_xpub_magic,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2014-12-10 18:53:24 +00:00
|
|
|
|
2020-02-20 11:47:29 +00:00
|
|
|
|
2020-05-13 09:36:03 +00:00
|
|
|
@pytest.mark.multisig
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_show_multisig_15(client: Client):
|
2024-11-14 17:43:59 +00:00
|
|
|
nodes = [
|
|
|
|
btc.get_public_node(
|
|
|
|
client, tools.parse_path(f"m/45h/{i}"), coin_name="Bitcoin"
|
|
|
|
).node
|
|
|
|
for i in range(15)
|
|
|
|
]
|
2014-12-12 21:31:40 +00:00
|
|
|
|
2024-11-14 17:43:59 +00:00
|
|
|
# Multisig with global suffix specification.
|
|
|
|
multisig1 = messages.MultisigRedeemScriptType(
|
|
|
|
nodes=nodes, signatures=[b"", b"", b""], m=2, address_n=[0, 0]
|
|
|
|
)
|
2014-12-12 21:31:40 +00:00
|
|
|
|
2024-11-14 17:43:59 +00:00
|
|
|
# Multisig with per-node suffix specification.
|
|
|
|
multisig2 = messages.MultisigRedeemScriptType(
|
|
|
|
pubkeys=[
|
|
|
|
messages.HDNodePathType(node=node, address_n=[0, 0]) for node in nodes
|
|
|
|
],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
2020-05-13 09:36:03 +00:00
|
|
|
)
|
2014-12-10 18:53:24 +00:00
|
|
|
|
2024-11-14 17:43:59 +00:00
|
|
|
for multisig in [multisig1, multisig2]:
|
|
|
|
for i in range(15):
|
|
|
|
with client:
|
|
|
|
if is_core(client):
|
|
|
|
IF = InputFlowConfirmAllWarnings(client)
|
|
|
|
client.set_input_flow(IF.get())
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
tools.parse_path(f"m/45h/{i}/0/0"),
|
|
|
|
show_display=True,
|
|
|
|
multisig=multisig,
|
|
|
|
script_type=messages.InputScriptType.SPENDMULTISIG,
|
|
|
|
)
|
|
|
|
== "3A8zs8W98A7n1zCWSvVzodiBsaHBYzAhzb"
|
2024-05-21 21:49:08 +00:00
|
|
|
)
|