2018-06-21 14:28:34 +00:00
|
|
|
# This file is part of the Trezor project.
|
2017-12-19 18:24:18 +00:00
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2017-12-19 18:24:18 +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-12-19 18:24:18 +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-12-19 18:24:18 +00:00
|
|
|
|
2019-08-22 16:55:20 +00:00
|
|
|
import pytest
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
from trezorlib import btc, messages
|
2022-01-31 12:25:30 +00:00
|
|
|
from trezorlib.debuglink import TrezorClientDebugLink as Client
|
2020-10-26 15:35:55 +00:00
|
|
|
from trezorlib.exceptions import TrezorFailure
|
2018-04-18 13:53:40 +00:00
|
|
|
from trezorlib.tools import parse_path
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2021-08-07 13:20:09 +00:00
|
|
|
VECTORS = ( # coin, path, script_type, address
|
|
|
|
(
|
|
|
|
"Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/84h/1h/0h/0/0",
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.InputScriptType.SPENDWITNESS,
|
2021-08-07 13:20:09 +00:00
|
|
|
"tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/84h/1h/0h/1/0",
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.InputScriptType.SPENDWITNESS,
|
2021-08-07 13:20:09 +00:00
|
|
|
"tb1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt96jk9x",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"Bitcoin",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/84h/0h/0h/0/0",
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.InputScriptType.SPENDWITNESS,
|
2021-08-07 13:20:09 +00:00
|
|
|
"bc1qannfxke2tfd4l7vhepehpvt05y83v3qsf6nfkk",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"Bitcoin",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/84h/0h/0h/1/0",
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.InputScriptType.SPENDWITNESS,
|
2021-08-07 13:20:09 +00:00
|
|
|
"bc1qktmhrsmsenepnnfst8x6j27l0uqv7ggrg8x38q",
|
|
|
|
),
|
2021-11-10 12:15:20 +00:00
|
|
|
(
|
2021-09-26 18:45:17 +00:00
|
|
|
"Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/86h/1h/0h/0/0",
|
2021-11-29 11:00:01 +00:00
|
|
|
messages.InputScriptType.SPENDTAPROOT,
|
2021-09-26 18:45:17 +00:00
|
|
|
"tb1pswrqtykue8r89t9u4rprjs0gt4qzkdfuursfnvqaa3f2yql07zmq8s8a5u",
|
|
|
|
),
|
2021-11-10 12:15:20 +00:00
|
|
|
(
|
2021-09-26 18:45:17 +00:00
|
|
|
"Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/86h/1h/0h/1/0",
|
2021-11-29 11:00:01 +00:00
|
|
|
messages.InputScriptType.SPENDTAPROOT,
|
2021-09-26 18:45:17 +00:00
|
|
|
"tb1pn2d0yjeedavnkd8z8lhm566p0f2utm3lgvxrsdehnl94y34txmts5s7t4c",
|
|
|
|
),
|
2021-11-10 12:15:20 +00:00
|
|
|
(
|
2021-09-26 18:45:17 +00:00
|
|
|
"Bitcoin",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/86h/0h/0h/0/0",
|
2021-11-29 11:00:01 +00:00
|
|
|
messages.InputScriptType.SPENDTAPROOT,
|
2021-09-26 18:45:17 +00:00
|
|
|
"bc1ptxs597p3fnpd8gwut5p467ulsydae3rp9z75hd99w8k3ljr9g9rqx6ynaw",
|
|
|
|
),
|
2021-11-10 12:15:20 +00:00
|
|
|
(
|
2021-09-26 18:45:17 +00:00
|
|
|
"Bitcoin",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/86h/0h/0h/1/0",
|
2021-11-29 11:00:01 +00:00
|
|
|
messages.InputScriptType.SPENDTAPROOT,
|
2021-09-26 18:45:17 +00:00
|
|
|
"bc1pgypgja2hmcx2l6s2ssq75k6ev68ved6nujcspt47dgvkp8euc70s6uegk6",
|
|
|
|
),
|
2021-12-20 14:52:33 +00:00
|
|
|
pytest.param(
|
|
|
|
"Groestlcoin Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/84h/1h/0h/0/0",
|
2021-12-20 14:52:33 +00:00
|
|
|
messages.InputScriptType.SPENDWITNESS,
|
|
|
|
"tgrs1qkvwu9g3k2pdxewfqr7syz89r3gj557l3ued7ja",
|
|
|
|
marks=pytest.mark.altcoin,
|
|
|
|
),
|
|
|
|
pytest.param(
|
|
|
|
"Groestlcoin Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/84h/1h/0h/1/0",
|
2021-12-20 14:52:33 +00:00
|
|
|
messages.InputScriptType.SPENDWITNESS,
|
|
|
|
"tgrs1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt9lkd57",
|
|
|
|
marks=pytest.mark.altcoin,
|
|
|
|
),
|
2021-08-07 13:20:09 +00:00
|
|
|
pytest.param(
|
|
|
|
"Groestlcoin",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/84h/17h/0h/0/0",
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.InputScriptType.SPENDWITNESS,
|
2021-08-07 13:20:09 +00:00
|
|
|
"grs1qw4teyraux2s77nhjdwh9ar8rl9dt7zww8r6lne",
|
|
|
|
marks=pytest.mark.altcoin,
|
|
|
|
),
|
2021-12-20 14:52:33 +00:00
|
|
|
pytest.param(
|
|
|
|
"Groestlcoin",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/84h/17h/0h/1/0",
|
2021-12-20 14:52:33 +00:00
|
|
|
messages.InputScriptType.SPENDWITNESS,
|
|
|
|
"grs1qzfpwn55tvkxcw0xwfa0g8k2gtlzlgkcq3z000e",
|
|
|
|
marks=pytest.mark.altcoin,
|
|
|
|
),
|
|
|
|
pytest.param(
|
|
|
|
"Groestlcoin Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/86h/1h/0h/0/0",
|
2021-12-20 14:52:33 +00:00
|
|
|
messages.InputScriptType.SPENDTAPROOT,
|
|
|
|
"tgrs1pswrqtykue8r89t9u4rprjs0gt4qzkdfuursfnvqaa3f2yql07zmq5v2q7z",
|
|
|
|
marks=pytest.mark.altcoin,
|
|
|
|
),
|
|
|
|
pytest.param(
|
|
|
|
"Groestlcoin",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/86h/17h/0h/0/0",
|
2021-12-20 14:52:33 +00:00
|
|
|
messages.InputScriptType.SPENDTAPROOT,
|
|
|
|
"grs1pnacleslusvh6gdjd3j2y5kv3drq09038sww2zx4za68jssndmu6qkm698g",
|
|
|
|
marks=pytest.mark.altcoin,
|
|
|
|
),
|
2021-08-07 13:20:09 +00:00
|
|
|
pytest.param(
|
|
|
|
"Elements",
|
2022-01-31 12:25:30 +00:00
|
|
|
"m/84h/1h/0h/0/0",
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.InputScriptType.SPENDWITNESS,
|
2021-08-07 13:20:09 +00:00
|
|
|
"ert1qkvwu9g3k2pdxewfqr7syz89r3gj557l3xp9k2v",
|
|
|
|
marks=pytest.mark.altcoin,
|
|
|
|
),
|
|
|
|
)
|
2017-05-12 22:59:39 +00:00
|
|
|
|
2021-08-07 13:20:09 +00:00
|
|
|
|
2021-10-14 19:25:06 +00:00
|
|
|
BIP86_VECTORS = ( # path, address for "abandon ... abandon about" seed
|
2022-01-31 12:25:30 +00:00
|
|
|
(
|
|
|
|
"m/86h/0h/0h/0/0",
|
|
|
|
"bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"m/86h/0h/0h/0/1",
|
|
|
|
"bc1p4qhjn9zdvkux4e44uhx8tc55attvtyu358kutcqkudyccelu0was9fqzwh",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"m/86h/0h/0h/1/0",
|
|
|
|
"bc1p3qkhfews2uk44qtvauqyr2ttdsw7svhkl9nkm9s9c3x4ax5h60wqwruhk7",
|
|
|
|
),
|
2021-10-14 19:25:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-08-07 13:20:09 +00:00
|
|
|
@pytest.mark.parametrize("show_display", (True, False))
|
|
|
|
@pytest.mark.parametrize("coin, path, script_type, address", VECTORS)
|
2023-09-14 10:22:18 +00:00
|
|
|
def test_show_segwit(
|
|
|
|
client: Client,
|
|
|
|
show_display: bool,
|
|
|
|
coin: str,
|
|
|
|
path: str,
|
|
|
|
script_type: messages.InputScriptType,
|
|
|
|
address: str,
|
|
|
|
):
|
2021-08-07 13:20:09 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
coin,
|
|
|
|
parse_path(path),
|
|
|
|
show_display,
|
|
|
|
None,
|
|
|
|
script_type=script_type,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2021-08-07 13:20:09 +00:00
|
|
|
== address
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-10-14 19:25:06 +00:00
|
|
|
# Tests https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki#test-vectors
|
|
|
|
@pytest.mark.setup_client(
|
|
|
|
mnemonic="abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
|
|
|
)
|
|
|
|
@pytest.mark.parametrize("path, address", BIP86_VECTORS)
|
2023-09-14 10:22:18 +00:00
|
|
|
def test_bip86(client: Client, path: str, address: str):
|
2021-10-14 19:25:06 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Bitcoin",
|
|
|
|
parse_path(path),
|
|
|
|
False,
|
|
|
|
None,
|
2021-11-29 11:00:01 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDTAPROOT,
|
2021-10-14 19:25:06 +00:00
|
|
|
)
|
|
|
|
== address
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-08-07 13:20:09 +00:00
|
|
|
@pytest.mark.multisig
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_show_multisig_3(client: Client):
|
2021-08-07 13:20:09 +00:00
|
|
|
nodes = [
|
|
|
|
btc.get_public_node(
|
2022-01-31 12:25:30 +00:00
|
|
|
client, parse_path(f"m/84h/1h/{index}h"), coin_name="Testnet"
|
2021-08-07 13:20:09 +00:00
|
|
|
).node
|
|
|
|
for index in range(1, 4)
|
|
|
|
]
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig1 = messages.MultisigRedeemScriptType(
|
2021-08-07 13:20:09 +00:00
|
|
|
nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2
|
|
|
|
)
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig2 = messages.MultisigRedeemScriptType(
|
2021-08-07 13:20:09 +00:00
|
|
|
nodes=nodes, address_n=[0, 1], signatures=[b"", b"", b""], m=2
|
|
|
|
)
|
|
|
|
for i in [1, 2, 3]:
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
|
|
|
btc.get_address(
|
2019-08-27 14:58:59 +00:00
|
|
|
client,
|
2018-08-13 16:21:24 +00:00
|
|
|
"Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
parse_path(f"m/84h/1h/{i}h/0/1"),
|
2018-08-13 16:21:24 +00:00
|
|
|
False,
|
2021-08-07 13:20:09 +00:00
|
|
|
multisig2,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDWITNESS,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2021-08-07 13:20:09 +00:00
|
|
|
== "tb1qauuv4e2pwjkr4ws5f8p20hu562jlqpe5h74whxqrwf7pufsgzcms9y8set"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
2019-08-27 14:58:59 +00:00
|
|
|
client,
|
2018-08-13 16:21:24 +00:00
|
|
|
"Testnet",
|
2022-01-31 12:25:30 +00:00
|
|
|
parse_path(f"m/84h/1h/{i}h/0/0"),
|
2018-08-13 16:21:24 +00:00
|
|
|
False,
|
2021-08-07 13:20:09 +00:00
|
|
|
multisig1,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDWITNESS,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2021-08-07 13:20:09 +00:00
|
|
|
== "tb1qgvn67p4twmpqhs8c39tukmu9geamtf7x0z3flwf9rrw4ff3h6d2qt0czq3"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2019-08-22 16:47:01 +00:00
|
|
|
|
2021-08-07 13:20:09 +00:00
|
|
|
|
2024-09-12 22:50:37 +00:00
|
|
|
@pytest.mark.multisig
|
2024-09-16 15:16:48 +00:00
|
|
|
@pytest.mark.models(skip=["legacy"])
|
2024-09-12 22:50:37 +00:00
|
|
|
def test_show_multisig_taproot_3(client: Client):
|
|
|
|
nodes = [
|
|
|
|
btc.get_public_node(
|
|
|
|
client, parse_path(f"m/86h/1h/{index}h"), coin_name="Testnet"
|
|
|
|
).node
|
|
|
|
for index in range(1, 4)
|
|
|
|
]
|
|
|
|
multisig1 = messages.MultisigRedeemScriptType(
|
|
|
|
nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2
|
|
|
|
)
|
|
|
|
multisig2 = messages.MultisigRedeemScriptType(
|
|
|
|
nodes=nodes, address_n=[0, 1], signatures=[b"", b"", b""], m=2
|
|
|
|
)
|
|
|
|
for i in [1, 2, 3]:
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Testnet",
|
|
|
|
parse_path(f"m/86h/1h/{i}h/0/1"),
|
|
|
|
False,
|
|
|
|
multisig2,
|
|
|
|
script_type=messages.InputScriptType.SPENDTAPROOT,
|
|
|
|
)
|
|
|
|
== "tb1p8wk2er5shm22z5mqy3qn2al7gz62csw75uh4ag8wluzptgr387tqeynquu"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
btc.get_address(
|
|
|
|
client,
|
|
|
|
"Testnet",
|
|
|
|
parse_path(f"m/86h/1h/{i}h/0/0"),
|
|
|
|
False,
|
|
|
|
multisig1,
|
|
|
|
script_type=messages.InputScriptType.SPENDTAPROOT,
|
|
|
|
)
|
|
|
|
== "tb1ph9e923j4w40nhr4v9fqz4pdn09tphdagrcx997qhe2fezgs2dqlqv9r8hl"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-08-07 13:20:09 +00:00
|
|
|
@pytest.mark.multisig
|
|
|
|
@pytest.mark.parametrize("show_display", (True, False))
|
2023-09-14 10:22:18 +00:00
|
|
|
def test_multisig_missing(client: Client, show_display: bool):
|
2021-08-07 13:20:09 +00:00
|
|
|
# Multisig with global suffix specification.
|
|
|
|
# Use account numbers 1, 2 and 3 to create a valid multisig,
|
|
|
|
# but not containing the keys from account 0 used below.
|
|
|
|
nodes = [
|
2022-01-31 12:25:30 +00:00
|
|
|
btc.get_public_node(client, parse_path(f"m/84h/0h/{i}h")).node
|
2021-08-07 13:20:09 +00:00
|
|
|
for i in range(1, 4)
|
|
|
|
]
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig1 = messages.MultisigRedeemScriptType(
|
2021-08-07 13:20:09 +00:00
|
|
|
nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2
|
|
|
|
)
|
|
|
|
|
|
|
|
# Multisig with per-node suffix specification.
|
|
|
|
node = btc.get_public_node(
|
2022-01-31 12:25:30 +00:00
|
|
|
client, parse_path("m/84h/0h/0h/0"), coin_name="Bitcoin"
|
2021-08-07 13:20:09 +00:00
|
|
|
).node
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig2 = messages.MultisigRedeemScriptType(
|
2021-08-07 13:20:09 +00:00
|
|
|
pubkeys=[
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.HDNodePathType(node=node, address_n=[1]),
|
|
|
|
messages.HDNodePathType(node=node, address_n=[2]),
|
|
|
|
messages.HDNodePathType(node=node, address_n=[3]),
|
2021-08-07 13:20:09 +00:00
|
|
|
],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
|
|
|
|
|
|
|
for multisig in (multisig1, multisig2):
|
|
|
|
with pytest.raises(TrezorFailure):
|
2019-06-08 14:39:12 +00:00
|
|
|
btc.get_address(
|
2019-08-27 14:58:59 +00:00
|
|
|
client,
|
2021-08-07 13:20:09 +00:00
|
|
|
"Bitcoin",
|
2022-01-31 12:25:30 +00:00
|
|
|
parse_path("m/84h/0h/0h/0/0"),
|
2021-08-07 13:20:09 +00:00
|
|
|
show_display=show_display,
|
|
|
|
multisig=multisig,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDWITNESS,
|
2019-06-08 14:39:12 +00:00
|
|
|
)
|