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
|
2018-08-13 16:21:24 +00:00
|
|
|
from trezorlib.tools import H_, CallException
|
2018-03-05 16:37:36 +00:00
|
|
|
|
2019-09-11 12:43:32 +00:00
|
|
|
from ..common import MNEMONIC12
|
2018-03-05 16:37:36 +00:00
|
|
|
|
|
|
|
|
2019-09-11 12:29:39 +00:00
|
|
|
class TestMsgGetpublickeyCurve:
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
|
|
|
def test_default_curve(self, client):
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
2019-08-27 14:58:59 +00:00
|
|
|
btc.get_public_node(client, [H_(111), 42]).node.public_key.hex()
|
2018-09-12 18:34:26 +00:00
|
|
|
== "02e7fcec053f0df94d88c86447970743e8a1979d242d09338dcf8687a9966f7fbc"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
assert (
|
2019-08-27 14:58:59 +00:00
|
|
|
btc.get_public_node(client, [H_(111), H_(42)]).node.public_key.hex()
|
2018-09-12 18:34:26 +00:00
|
|
|
== "03ce7b690969d773ba9ed212464eb2b534b87b9b8a9383300bddabe1f093f79220"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-03-05 16:37:36 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
|
|
|
def test_secp256k1_curve(self, client):
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
2018-09-12 18:34:26 +00:00
|
|
|
btc.get_public_node(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, [H_(111), 42], ecdsa_curve_name="secp256k1"
|
2018-09-12 18:34:26 +00:00
|
|
|
).node.public_key.hex()
|
|
|
|
== "02e7fcec053f0df94d88c86447970743e8a1979d242d09338dcf8687a9966f7fbc"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
assert (
|
2018-09-12 18:34:26 +00:00
|
|
|
btc.get_public_node(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, [H_(111), H_(42)], ecdsa_curve_name="secp256k1"
|
2018-09-12 18:34:26 +00:00
|
|
|
).node.public_key.hex()
|
|
|
|
== "03ce7b690969d773ba9ed212464eb2b534b87b9b8a9383300bddabe1f093f79220"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-03-05 16:37:36 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
|
|
|
def test_nist256p1_curve(self, client):
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
2018-09-12 18:34:26 +00:00
|
|
|
btc.get_public_node(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, [H_(111), 42], ecdsa_curve_name="nist256p1"
|
2018-09-12 18:34:26 +00:00
|
|
|
).node.public_key.hex()
|
|
|
|
== "02a9ce59b32bd64a70bc52aca96e5d09af65c6b9593ba2a60af8fccfe1437f2129"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
assert (
|
2018-09-12 18:34:26 +00:00
|
|
|
btc.get_public_node(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, [H_(111), H_(42)], ecdsa_curve_name="nist256p1"
|
2018-09-12 18:34:26 +00:00
|
|
|
).node.public_key.hex()
|
|
|
|
== "026fe35d8afed67dbf0561a1d32922e8ad0cd0d86effbc82be970cbed7d9bab2c2"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-03-05 16:37:36 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
|
|
|
def test_ed25519_curve(self, client):
|
2018-03-07 13:34:08 +00:00
|
|
|
# ed25519 curve does not support public derivation, so test only private derivation paths
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
2018-09-12 18:34:26 +00:00
|
|
|
btc.get_public_node(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, [H_(111), H_(42)], ecdsa_curve_name="ed25519"
|
2018-09-12 18:34:26 +00:00
|
|
|
).node.public_key.hex()
|
|
|
|
== "0069a14b478e508eab6e93303f4e6f5c50b8136627830f2ed5c3a835fc6c0ea2b7"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
assert (
|
2018-09-12 18:34:26 +00:00
|
|
|
btc.get_public_node(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, [H_(111), H_(65535)], ecdsa_curve_name="ed25519"
|
2018-09-12 18:34:26 +00:00
|
|
|
).node.public_key.hex()
|
|
|
|
== "00514f73a05184458611b14c348fee4fd988d36cf3aee7207737861bac611de991"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-03-07 13:34:08 +00:00
|
|
|
# test failure when using public derivation
|
|
|
|
with pytest.raises(CallException):
|
2019-08-27 14:58:59 +00:00
|
|
|
btc.get_public_node(client, [H_(111), 42], ecdsa_curve_name="ed25519")
|