2018-06-21 14:28:34 +00:00
|
|
|
# This file is part of the Trezor project.
|
2018-03-05 16:37:36 +00:00
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2018-03-05 16:37:36 +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.
|
2018-03-05 16:37:36 +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>.
|
2018-03-05 16:37:36 +00:00
|
|
|
|
2018-04-18 13:53:40 +00:00
|
|
|
import pytest
|
|
|
|
|
2018-08-10 12:04:58 +00:00
|
|
|
from trezorlib import btc
|
2020-03-24 13:18:08 +00:00
|
|
|
from trezorlib.exceptions import TrezorFailure
|
2020-05-13 09:36:03 +00:00
|
|
|
from trezorlib.tools import parse_path
|
2018-03-05 16:37:36 +00:00
|
|
|
|
2020-05-13 09:36:03 +00:00
|
|
|
PATH_PRIVATE = parse_path("m/17h/0h/1h/2h/3h")
|
|
|
|
PATH_PUBLIC = parse_path("m/17h/0h/1h/2h/3h/42")
|
2018-03-05 16:37:36 +00:00
|
|
|
|
2020-05-13 09:36:03 +00:00
|
|
|
VECTORS = ( # curve, path, pubkey
|
|
|
|
(
|
|
|
|
"secp256k1",
|
|
|
|
PATH_PRIVATE,
|
|
|
|
"02f65ce170451f66f46daf9486b0cf266bd199a3e67f734e469556745a78d254ee",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"secp256k1",
|
|
|
|
PATH_PUBLIC,
|
|
|
|
"0212f4629f4f224db0f778ca68abd1c53e21dd02e76dbd1f7312788544b5b1e042",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"nist256p1",
|
|
|
|
PATH_PRIVATE,
|
|
|
|
"0324c6860c25cdf7a8c103666662ac6183bf5a181a3341ea4130dcc6fdee7919e4",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"nist256p1",
|
|
|
|
PATH_PUBLIC,
|
|
|
|
"03b93f7e6c777143ad4eeb590aaa7cdcd95980cf68d3f75dc2c31ca637ec50c49b",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"ed25519",
|
|
|
|
PATH_PRIVATE,
|
|
|
|
"002e28dc0346d6d30d4e33f53c47f2fa97f3cfb5e80fc30fa3570fccf30652718a",
|
|
|
|
),
|
|
|
|
)
|
2018-03-05 16:37:36 +00:00
|
|
|
|
|
|
|
|
2020-05-13 09:36:03 +00:00
|
|
|
@pytest.mark.parametrize("curve, path, pubkey", VECTORS)
|
|
|
|
def test_publickey_curve(client, curve, path, pubkey):
|
|
|
|
resp = btc.get_public_node(client, path, ecdsa_curve_name=curve)
|
|
|
|
assert resp.node.public_key.hex() == pubkey
|
2018-03-05 16:37:36 +00:00
|
|
|
|
2020-05-13 09:36:03 +00:00
|
|
|
|
|
|
|
def test_ed25519_public(client):
|
|
|
|
with pytest.raises(TrezorFailure):
|
|
|
|
btc.get_public_node(client, PATH_PUBLIC, ecdsa_curve_name="ed25519")
|
|
|
|
|
|
|
|
|
2020-05-26 13:37:06 +00:00
|
|
|
@pytest.mark.xfail(reason="Currently path validation on get_public_node is disabled.")
|
2020-05-13 09:36:03 +00:00
|
|
|
def test_coin_and_curve(client):
|
|
|
|
with pytest.raises(
|
|
|
|
TrezorFailure, match="Cannot use coin_name or script_type with ecdsa_curve_name"
|
|
|
|
):
|
|
|
|
btc.get_public_node(
|
|
|
|
client, PATH_PRIVATE, coin_name="Bitcoin", ecdsa_curve_name="ed25519"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|