2018-11-08 17:15:49 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2018-11-08 17:15:49 +00:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# 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>.
|
|
|
|
|
2019-08-29 11:56:09 +00:00
|
|
|
from . import messages
|
2019-08-29 13:19:02 +00:00
|
|
|
from .tools import Address, expect
|
2018-06-13 17:04:18 +00:00
|
|
|
|
2019-08-29 11:56:09 +00:00
|
|
|
if False:
|
|
|
|
from .client import TrezorClient
|
2018-06-13 17:04:18 +00:00
|
|
|
|
|
|
|
|
2019-08-29 11:56:09 +00:00
|
|
|
@expect(messages.Entropy, field="entropy")
|
|
|
|
def get_entropy(client: "TrezorClient", size: int) -> messages.Entropy:
|
|
|
|
return client.call(messages.GetEntropy(size=size))
|
2018-06-13 17:04:18 +00:00
|
|
|
|
2019-08-29 11:56:09 +00:00
|
|
|
|
|
|
|
@expect(messages.SignedIdentity)
|
2018-08-13 16:21:24 +00:00
|
|
|
def sign_identity(
|
2019-08-29 11:56:09 +00:00
|
|
|
client: "TrezorClient",
|
|
|
|
identity: messages.IdentityType,
|
|
|
|
challenge_hidden: bytes,
|
|
|
|
challenge_visual: str,
|
|
|
|
ecdsa_curve_name: str = None,
|
|
|
|
) -> messages.SignedIdentity:
|
2018-08-13 16:21:24 +00:00
|
|
|
return client.call(
|
2019-08-29 11:56:09 +00:00
|
|
|
messages.SignIdentity(
|
2018-08-13 16:21:24 +00:00
|
|
|
identity=identity,
|
|
|
|
challenge_hidden=challenge_hidden,
|
|
|
|
challenge_visual=challenge_visual,
|
|
|
|
ecdsa_curve_name=ecdsa_curve_name,
|
|
|
|
)
|
|
|
|
)
|
2018-06-13 17:04:18 +00:00
|
|
|
|
2018-06-13 17:35:01 +00:00
|
|
|
|
2019-08-29 11:56:09 +00:00
|
|
|
@expect(messages.ECDHSessionKey)
|
|
|
|
def get_ecdh_session_key(
|
|
|
|
client: "TrezorClient",
|
|
|
|
identity: messages.IdentityType,
|
|
|
|
peer_public_key: bytes,
|
|
|
|
ecdsa_curve_name: str = None,
|
|
|
|
) -> messages.ECDHSessionKey:
|
2018-08-13 16:21:24 +00:00
|
|
|
return client.call(
|
2019-08-29 11:56:09 +00:00
|
|
|
messages.GetECDHSessionKey(
|
2018-08-13 16:21:24 +00:00
|
|
|
identity=identity,
|
|
|
|
peer_public_key=peer_public_key,
|
|
|
|
ecdsa_curve_name=ecdsa_curve_name,
|
|
|
|
)
|
|
|
|
)
|
2018-06-13 17:04:18 +00:00
|
|
|
|
|
|
|
|
2019-08-29 11:56:09 +00:00
|
|
|
@expect(messages.CipheredKeyValue, field="value")
|
2018-08-13 16:21:24 +00:00
|
|
|
def encrypt_keyvalue(
|
2019-08-29 11:56:09 +00:00
|
|
|
client: "TrezorClient",
|
|
|
|
n: Address,
|
|
|
|
key: str,
|
|
|
|
value: bytes,
|
|
|
|
ask_on_encrypt: bool = True,
|
|
|
|
ask_on_decrypt: bool = True,
|
|
|
|
iv: bytes = b"",
|
|
|
|
) -> messages.CipheredKeyValue:
|
2018-08-13 16:21:24 +00:00
|
|
|
return client.call(
|
2019-08-29 11:56:09 +00:00
|
|
|
messages.CipherKeyValue(
|
2018-08-13 16:21:24 +00:00
|
|
|
address_n=n,
|
|
|
|
key=key,
|
|
|
|
value=value,
|
|
|
|
encrypt=True,
|
|
|
|
ask_on_encrypt=ask_on_encrypt,
|
|
|
|
ask_on_decrypt=ask_on_decrypt,
|
|
|
|
iv=iv,
|
|
|
|
)
|
|
|
|
)
|
2018-06-13 17:35:01 +00:00
|
|
|
|
2018-06-13 17:04:18 +00:00
|
|
|
|
2019-08-29 11:56:09 +00:00
|
|
|
@expect(messages.CipheredKeyValue, field="value")
|
2018-08-13 16:21:24 +00:00
|
|
|
def decrypt_keyvalue(
|
2019-08-29 11:56:09 +00:00
|
|
|
client: "TrezorClient",
|
|
|
|
n: Address,
|
|
|
|
key: str,
|
|
|
|
value: bytes,
|
|
|
|
ask_on_encrypt: bool = True,
|
|
|
|
ask_on_decrypt: bool = True,
|
|
|
|
iv: bytes = b"",
|
|
|
|
) -> messages.CipheredKeyValue:
|
2018-08-13 16:21:24 +00:00
|
|
|
return client.call(
|
2019-08-29 11:56:09 +00:00
|
|
|
messages.CipherKeyValue(
|
2018-08-13 16:21:24 +00:00
|
|
|
address_n=n,
|
|
|
|
key=key,
|
|
|
|
value=value,
|
|
|
|
encrypt=False,
|
|
|
|
ask_on_encrypt=ask_on_encrypt,
|
|
|
|
ask_on_decrypt=ask_on_decrypt,
|
|
|
|
iv=iv,
|
|
|
|
)
|
|
|
|
)
|