2018-09-05 12:56:31 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
2021-11-26 14:50:43 +00:00
|
|
|
# Copyright (C) 2012-2022 SatoshiLabs and contributors
|
2018-09-05 12:56:31 +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>.
|
|
|
|
|
2020-09-29 18:23:25 +00:00
|
|
|
from ipaddress import ip_address
|
2021-06-30 12:13:43 +00:00
|
|
|
from itertools import chain
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
from typing import (
|
|
|
|
TYPE_CHECKING,
|
|
|
|
Any,
|
|
|
|
Dict,
|
|
|
|
Iterable,
|
|
|
|
Iterator,
|
|
|
|
List,
|
|
|
|
Optional,
|
|
|
|
Sequence,
|
|
|
|
Tuple,
|
2022-06-07 15:14:30 +00:00
|
|
|
Type,
|
|
|
|
TypeVar,
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
Union,
|
|
|
|
)
|
2018-09-05 12:56:31 +00:00
|
|
|
|
2021-02-19 21:13:39 +00:00
|
|
|
from . import exceptions, messages, tools
|
2020-07-01 13:43:02 +00:00
|
|
|
from .tools import expect
|
2018-09-05 12:56:31 +00:00
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from .client import TrezorClient
|
|
|
|
from .protobuf import MessageType
|
|
|
|
|
2022-02-15 09:59:11 +00:00
|
|
|
PROTOCOL_MAGICS = {"mainnet": 764824073, "testnet": 1097911063}
|
2020-07-23 13:54:49 +00:00
|
|
|
NETWORK_IDS = {"mainnet": 1, "testnet": 0}
|
2020-07-01 13:43:02 +00:00
|
|
|
|
2022-06-07 15:14:30 +00:00
|
|
|
MAX_CHUNK_SIZE = 1024
|
|
|
|
|
2020-07-01 13:43:02 +00:00
|
|
|
REQUIRED_FIELDS_TRANSACTION = ("inputs", "outputs")
|
2020-09-29 18:23:25 +00:00
|
|
|
REQUIRED_FIELDS_INPUT = ("prev_hash", "prev_index")
|
|
|
|
REQUIRED_FIELDS_CERTIFICATE = ("type",)
|
|
|
|
REQUIRED_FIELDS_POOL_PARAMETERS = (
|
|
|
|
"pool_id",
|
|
|
|
"vrf_key_hash",
|
|
|
|
"pledge",
|
|
|
|
"cost",
|
|
|
|
"margin",
|
|
|
|
"reward_account",
|
|
|
|
"owners",
|
|
|
|
)
|
2021-01-25 16:12:32 +00:00
|
|
|
REQUIRED_FIELDS_TOKEN_GROUP = ("policy_id", "tokens")
|
2021-03-26 07:46:14 +00:00
|
|
|
REQUIRED_FIELDS_CATALYST_REGISTRATION = (
|
|
|
|
"voting_public_key",
|
|
|
|
"staking_path",
|
|
|
|
"nonce",
|
|
|
|
"reward_address_parameters",
|
|
|
|
)
|
2018-09-05 12:56:31 +00:00
|
|
|
|
2020-07-23 13:54:49 +00:00
|
|
|
INCOMPLETE_OUTPUT_ERROR_MESSAGE = "The output is missing some fields"
|
|
|
|
|
2021-01-25 16:12:32 +00:00
|
|
|
INVALID_OUTPUT_TOKEN_BUNDLE_ENTRY = "The output's token_bundle entry is invalid"
|
2021-07-23 12:54:32 +00:00
|
|
|
INVALID_MINT_TOKEN_BUNDLE_ENTRY = "The mint token_bundle entry is invalid"
|
2021-01-25 16:12:32 +00:00
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
InputWithPath = Tuple[messages.CardanoTxInput, List[int]]
|
2021-10-21 17:43:10 +00:00
|
|
|
CollateralInputWithPath = Tuple[messages.CardanoTxCollateralInput, List[int]]
|
2021-06-30 12:13:43 +00:00
|
|
|
AssetGroupWithTokens = Tuple[messages.CardanoAssetGroup, List[messages.CardanoToken]]
|
2022-06-07 15:14:30 +00:00
|
|
|
OutputWithData = Tuple[
|
|
|
|
messages.CardanoTxOutput,
|
|
|
|
List[AssetGroupWithTokens],
|
|
|
|
List[messages.CardanoTxInlineDatumChunk],
|
|
|
|
List[messages.CardanoTxReferenceScriptChunk],
|
|
|
|
]
|
2021-06-30 12:13:43 +00:00
|
|
|
OutputItem = Union[
|
2022-06-07 15:14:30 +00:00
|
|
|
messages.CardanoTxOutput,
|
|
|
|
messages.CardanoAssetGroup,
|
|
|
|
messages.CardanoToken,
|
|
|
|
messages.CardanoTxInlineDatumChunk,
|
|
|
|
messages.CardanoTxReferenceScriptChunk,
|
2021-06-30 12:13:43 +00:00
|
|
|
]
|
|
|
|
CertificateItem = Union[
|
|
|
|
messages.CardanoTxCertificate,
|
|
|
|
messages.CardanoPoolOwner,
|
|
|
|
messages.CardanoPoolRelayParameters,
|
|
|
|
]
|
2021-07-23 12:54:32 +00:00
|
|
|
MintItem = Union[
|
|
|
|
messages.CardanoTxMint, messages.CardanoAssetGroup, messages.CardanoToken
|
|
|
|
]
|
2021-06-30 12:13:43 +00:00
|
|
|
PoolOwnersAndRelays = Tuple[
|
|
|
|
List[messages.CardanoPoolOwner], List[messages.CardanoPoolRelayParameters]
|
|
|
|
]
|
|
|
|
CertificateWithPoolOwnersAndRelays = Tuple[
|
|
|
|
messages.CardanoTxCertificate, Optional[PoolOwnersAndRelays]
|
|
|
|
]
|
|
|
|
Path = List[int]
|
|
|
|
Witness = Tuple[Path, bytes]
|
|
|
|
AuxiliaryDataSupplement = Dict[str, Union[int, bytes]]
|
|
|
|
SignTxResponse = Dict[str, Union[bytes, List[Witness], AuxiliaryDataSupplement]]
|
2022-06-07 15:14:30 +00:00
|
|
|
Chunk = TypeVar(
|
|
|
|
"Chunk",
|
|
|
|
bound=Union[
|
|
|
|
messages.CardanoTxInlineDatumChunk, messages.CardanoTxReferenceScriptChunk
|
|
|
|
],
|
|
|
|
)
|
2021-06-30 12:13:43 +00:00
|
|
|
|
2020-07-23 13:54:49 +00:00
|
|
|
|
2021-07-23 09:42:38 +00:00
|
|
|
def parse_optional_bytes(value: Optional[str]) -> Optional[bytes]:
|
|
|
|
return bytes.fromhex(value) if value is not None else None
|
|
|
|
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
def parse_optional_int(value: Optional[str]) -> Optional[int]:
|
2021-07-23 09:42:38 +00:00
|
|
|
return int(value) if value is not None else None
|
|
|
|
|
|
|
|
|
2020-07-23 13:54:49 +00:00
|
|
|
def create_address_parameters(
|
|
|
|
address_type: messages.CardanoAddressType,
|
|
|
|
address_n: List[int],
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
address_n_staking: Optional[List[int]] = None,
|
|
|
|
staking_key_hash: Optional[bytes] = None,
|
|
|
|
block_index: Optional[int] = None,
|
|
|
|
tx_index: Optional[int] = None,
|
|
|
|
certificate_index: Optional[int] = None,
|
|
|
|
script_payment_hash: Optional[bytes] = None,
|
|
|
|
script_staking_hash: Optional[bytes] = None,
|
2020-07-23 13:54:49 +00:00
|
|
|
) -> messages.CardanoAddressParametersType:
|
|
|
|
certificate_pointer = None
|
|
|
|
|
2021-07-23 10:14:29 +00:00
|
|
|
if address_type in (
|
|
|
|
messages.CardanoAddressType.POINTER,
|
|
|
|
messages.CardanoAddressType.POINTER_SCRIPT,
|
|
|
|
):
|
2021-04-08 05:06:10 +00:00
|
|
|
certificate_pointer = _create_certificate_pointer(
|
2020-07-23 13:54:49 +00:00
|
|
|
block_index, tx_index, certificate_index
|
|
|
|
)
|
|
|
|
|
|
|
|
return messages.CardanoAddressParametersType(
|
|
|
|
address_type=address_type,
|
|
|
|
address_n=address_n,
|
|
|
|
address_n_staking=address_n_staking,
|
|
|
|
staking_key_hash=staking_key_hash,
|
|
|
|
certificate_pointer=certificate_pointer,
|
2021-07-23 10:14:29 +00:00
|
|
|
script_payment_hash=script_payment_hash,
|
|
|
|
script_staking_hash=script_staking_hash,
|
2020-07-23 13:54:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-04-08 05:06:10 +00:00
|
|
|
def _create_certificate_pointer(
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
block_index: Optional[int],
|
|
|
|
tx_index: Optional[int],
|
|
|
|
certificate_index: Optional[int],
|
2020-07-23 13:54:49 +00:00
|
|
|
) -> messages.CardanoBlockchainPointerType:
|
|
|
|
if block_index is None or tx_index is None or certificate_index is None:
|
|
|
|
raise ValueError("Invalid pointer parameters")
|
|
|
|
|
|
|
|
return messages.CardanoBlockchainPointerType(
|
|
|
|
block_index=block_index, tx_index=tx_index, certificate_index=certificate_index
|
|
|
|
)
|
|
|
|
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
def parse_input(tx_input: dict) -> InputWithPath:
|
2020-09-29 18:23:25 +00:00
|
|
|
if not all(k in tx_input for k in REQUIRED_FIELDS_INPUT):
|
2020-07-23 13:54:49 +00:00
|
|
|
raise ValueError("The input is missing some fields")
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
path = tools.parse_path(tx_input.get("path", ""))
|
2021-06-30 12:13:43 +00:00
|
|
|
return (
|
|
|
|
messages.CardanoTxInput(
|
|
|
|
prev_hash=bytes.fromhex(tx_input["prev_hash"]),
|
|
|
|
prev_index=tx_input["prev_index"],
|
|
|
|
),
|
|
|
|
path,
|
2020-07-23 13:54:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-06-07 15:14:30 +00:00
|
|
|
def parse_output(output: dict) -> OutputWithData:
|
2020-07-29 07:53:00 +00:00
|
|
|
contains_address = "address" in output
|
|
|
|
contains_address_type = "addressType" in output
|
2020-07-23 13:54:49 +00:00
|
|
|
|
2020-07-29 07:53:00 +00:00
|
|
|
if "amount" not in output:
|
2020-07-23 13:54:49 +00:00
|
|
|
raise ValueError(INCOMPLETE_OUTPUT_ERROR_MESSAGE)
|
|
|
|
if not (contains_address or contains_address_type):
|
|
|
|
raise ValueError(INCOMPLETE_OUTPUT_ERROR_MESSAGE)
|
|
|
|
|
2021-10-12 11:33:24 +00:00
|
|
|
address = output.get("address")
|
2021-04-26 10:45:56 +00:00
|
|
|
|
2021-10-12 11:33:24 +00:00
|
|
|
address_parameters = None
|
2021-04-26 10:45:56 +00:00
|
|
|
if contains_address_type:
|
2021-07-23 12:54:32 +00:00
|
|
|
address_parameters = _parse_address_parameters(
|
|
|
|
output, INCOMPLETE_OUTPUT_ERROR_MESSAGE
|
|
|
|
)
|
2021-01-25 16:12:32 +00:00
|
|
|
|
2021-10-12 11:33:24 +00:00
|
|
|
token_bundle = []
|
2021-01-25 16:12:32 +00:00
|
|
|
if "token_bundle" in output:
|
2021-07-23 12:54:32 +00:00
|
|
|
token_bundle = _parse_token_bundle(output["token_bundle"], is_mint=False)
|
2021-01-25 16:12:32 +00:00
|
|
|
|
2021-10-12 11:33:24 +00:00
|
|
|
datum_hash = parse_optional_bytes(output.get("datum_hash"))
|
|
|
|
|
2022-06-07 15:14:30 +00:00
|
|
|
serialization_format = messages.CardanoTxOutputSerializationFormat.ARRAY_LEGACY
|
|
|
|
if "format" in output:
|
|
|
|
serialization_format = output["format"]
|
|
|
|
|
|
|
|
inline_datum_size, inline_datum_chunks = _parse_chunkable_data(
|
|
|
|
parse_optional_bytes(output.get("inline_datum")),
|
|
|
|
messages.CardanoTxInlineDatumChunk,
|
|
|
|
)
|
|
|
|
|
|
|
|
reference_script_size, reference_script_chunks = _parse_chunkable_data(
|
|
|
|
parse_optional_bytes(output.get("reference_script")),
|
|
|
|
messages.CardanoTxReferenceScriptChunk,
|
|
|
|
)
|
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
return (
|
|
|
|
messages.CardanoTxOutput(
|
|
|
|
address=address,
|
|
|
|
address_parameters=address_parameters,
|
|
|
|
amount=int(output["amount"]),
|
|
|
|
asset_groups_count=len(token_bundle),
|
2021-10-12 11:33:24 +00:00
|
|
|
datum_hash=datum_hash,
|
2022-06-07 15:14:30 +00:00
|
|
|
format=serialization_format,
|
|
|
|
inline_datum_size=inline_datum_size,
|
|
|
|
reference_script_size=reference_script_size,
|
2021-06-30 12:13:43 +00:00
|
|
|
),
|
|
|
|
token_bundle,
|
2022-06-07 15:14:30 +00:00
|
|
|
inline_datum_chunks,
|
|
|
|
reference_script_chunks,
|
2021-01-25 16:12:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
def _parse_token_bundle(
|
|
|
|
token_bundle: Iterable[dict], is_mint: bool
|
|
|
|
) -> List[AssetGroupWithTokens]:
|
2021-07-23 12:54:32 +00:00
|
|
|
error_message: str
|
|
|
|
if is_mint:
|
|
|
|
error_message = INVALID_MINT_TOKEN_BUNDLE_ENTRY
|
|
|
|
else:
|
|
|
|
error_message = INVALID_OUTPUT_TOKEN_BUNDLE_ENTRY
|
|
|
|
|
2021-01-25 16:12:32 +00:00
|
|
|
result = []
|
|
|
|
for token_group in token_bundle:
|
|
|
|
if not all(k in token_group for k in REQUIRED_FIELDS_TOKEN_GROUP):
|
2021-07-23 12:54:32 +00:00
|
|
|
raise ValueError(error_message)
|
2021-01-25 16:12:32 +00:00
|
|
|
|
2021-07-23 12:54:32 +00:00
|
|
|
tokens = _parse_tokens(token_group["tokens"], is_mint)
|
2021-06-30 12:13:43 +00:00
|
|
|
|
2021-01-25 16:12:32 +00:00
|
|
|
result.append(
|
2021-06-30 12:13:43 +00:00
|
|
|
(
|
|
|
|
messages.CardanoAssetGroup(
|
|
|
|
policy_id=bytes.fromhex(token_group["policy_id"]),
|
|
|
|
tokens_count=len(tokens),
|
|
|
|
),
|
|
|
|
tokens,
|
2021-01-25 16:12:32 +00:00
|
|
|
)
|
|
|
|
)
|
2020-07-23 13:54:49 +00:00
|
|
|
|
2021-01-25 16:12:32 +00:00
|
|
|
return result
|
2020-07-23 13:54:49 +00:00
|
|
|
|
2021-01-25 16:12:32 +00:00
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
def _parse_tokens(tokens: Iterable[dict], is_mint: bool) -> List[messages.CardanoToken]:
|
2021-07-23 12:54:32 +00:00
|
|
|
error_message: str
|
|
|
|
if is_mint:
|
|
|
|
error_message = INVALID_MINT_TOKEN_BUNDLE_ENTRY
|
|
|
|
else:
|
|
|
|
error_message = INVALID_OUTPUT_TOKEN_BUNDLE_ENTRY
|
|
|
|
|
2021-01-25 16:12:32 +00:00
|
|
|
result = []
|
|
|
|
for token in tokens:
|
2021-07-23 12:54:32 +00:00
|
|
|
if "asset_name_bytes" not in token:
|
|
|
|
raise ValueError(error_message)
|
|
|
|
|
|
|
|
mint_amount = None
|
|
|
|
amount = None
|
|
|
|
if is_mint:
|
|
|
|
if "mint_amount" not in token:
|
|
|
|
raise ValueError(error_message)
|
|
|
|
mint_amount = int(token["mint_amount"])
|
|
|
|
else:
|
|
|
|
if "amount" not in token:
|
|
|
|
raise ValueError(error_message)
|
|
|
|
amount = int(token["amount"])
|
2021-01-25 16:12:32 +00:00
|
|
|
|
|
|
|
result.append(
|
2021-06-30 12:13:43 +00:00
|
|
|
messages.CardanoToken(
|
2021-01-25 16:12:32 +00:00
|
|
|
asset_name_bytes=bytes.fromhex(token["asset_name_bytes"]),
|
2021-07-23 12:54:32 +00:00
|
|
|
amount=amount,
|
|
|
|
mint_amount=mint_amount,
|
2021-01-25 16:12:32 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2021-04-08 05:06:10 +00:00
|
|
|
def _parse_address_parameters(
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
address_parameters: dict, error_message: str
|
2021-01-25 16:12:32 +00:00
|
|
|
) -> messages.CardanoAddressParametersType:
|
2021-07-23 10:14:29 +00:00
|
|
|
if "addressType" not in address_parameters:
|
2021-07-23 12:54:32 +00:00
|
|
|
raise ValueError(error_message)
|
2020-07-23 13:54:49 +00:00
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
payment_path = tools.parse_path(address_parameters.get("path", ""))
|
|
|
|
staking_path = tools.parse_path(address_parameters.get("stakingPath", ""))
|
2021-07-23 10:14:29 +00:00
|
|
|
staking_key_hash_bytes = parse_optional_bytes(
|
|
|
|
address_parameters.get("stakingKeyHash")
|
|
|
|
)
|
|
|
|
script_payment_hash = parse_optional_bytes(
|
|
|
|
address_parameters.get("scriptPaymentHash")
|
|
|
|
)
|
|
|
|
script_staking_hash = parse_optional_bytes(
|
|
|
|
address_parameters.get("scriptStakingHash")
|
|
|
|
)
|
2020-07-23 13:54:49 +00:00
|
|
|
|
2021-01-25 16:12:32 +00:00
|
|
|
return create_address_parameters(
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
messages.CardanoAddressType(address_parameters["addressType"]),
|
2021-07-23 12:54:32 +00:00
|
|
|
payment_path,
|
2021-07-23 10:14:29 +00:00
|
|
|
staking_path,
|
2020-07-23 13:54:49 +00:00
|
|
|
staking_key_hash_bytes,
|
2021-03-26 07:46:14 +00:00
|
|
|
address_parameters.get("blockIndex"),
|
|
|
|
address_parameters.get("txIndex"),
|
|
|
|
address_parameters.get("certificateIndex"),
|
2021-07-23 10:14:29 +00:00
|
|
|
script_payment_hash,
|
|
|
|
script_staking_hash,
|
2020-07-23 13:54:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-06-07 15:14:30 +00:00
|
|
|
def _parse_chunkable_data(
|
|
|
|
data: Optional[bytes], chunk_type: Type[Chunk]
|
|
|
|
) -> Tuple[int, List[Chunk]]:
|
|
|
|
if data is None:
|
|
|
|
return 0, []
|
|
|
|
data_size = len(data)
|
|
|
|
data_chunks = [chunk_type(data=chunk) for chunk in _create_data_chunks(data)]
|
|
|
|
return data_size, data_chunks
|
|
|
|
|
|
|
|
|
|
|
|
def _create_data_chunks(data: bytes) -> Iterator[bytes]:
|
|
|
|
processed_size = 0
|
|
|
|
while processed_size < len(data):
|
|
|
|
yield data[processed_size : (processed_size + MAX_CHUNK_SIZE)]
|
|
|
|
processed_size += MAX_CHUNK_SIZE
|
|
|
|
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
def parse_native_script(native_script: dict) -> messages.CardanoNativeScript:
|
2021-07-23 09:42:38 +00:00
|
|
|
if "type" not in native_script:
|
|
|
|
raise ValueError("Script is missing some fields")
|
|
|
|
|
|
|
|
type = native_script["type"]
|
|
|
|
scripts = [
|
|
|
|
parse_native_script(sub_script)
|
|
|
|
for sub_script in native_script.get("scripts", ())
|
|
|
|
]
|
|
|
|
|
2021-07-23 10:14:29 +00:00
|
|
|
key_hash = parse_optional_bytes(native_script.get("key_hash"))
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
key_path = tools.parse_path(native_script.get("key_path", ""))
|
2021-07-23 09:42:38 +00:00
|
|
|
required_signatures_count = parse_optional_int(
|
|
|
|
native_script.get("required_signatures_count")
|
|
|
|
)
|
|
|
|
invalid_before = parse_optional_int(native_script.get("invalid_before"))
|
|
|
|
invalid_hereafter = parse_optional_int(native_script.get("invalid_hereafter"))
|
|
|
|
|
|
|
|
return messages.CardanoNativeScript(
|
|
|
|
type=type,
|
|
|
|
scripts=scripts,
|
|
|
|
key_hash=key_hash,
|
|
|
|
key_path=key_path,
|
|
|
|
required_signatures_count=required_signatures_count,
|
|
|
|
invalid_before=invalid_before,
|
|
|
|
invalid_hereafter=invalid_hereafter,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
def parse_certificate(certificate: dict) -> CertificateWithPoolOwnersAndRelays:
|
2020-09-29 18:23:25 +00:00
|
|
|
CERTIFICATE_MISSING_FIELDS_ERROR = ValueError(
|
|
|
|
"The certificate is missing some fields"
|
|
|
|
)
|
|
|
|
|
2020-07-29 07:53:00 +00:00
|
|
|
if not all(k in certificate for k in REQUIRED_FIELDS_CERTIFICATE):
|
2020-09-29 18:23:25 +00:00
|
|
|
raise CERTIFICATE_MISSING_FIELDS_ERROR
|
2020-07-27 10:52:02 +00:00
|
|
|
|
|
|
|
certificate_type = certificate["type"]
|
|
|
|
|
|
|
|
if certificate_type == messages.CardanoCertificateType.STAKE_DELEGATION:
|
2020-07-29 07:53:00 +00:00
|
|
|
if "pool" not in certificate:
|
2020-09-29 18:23:25 +00:00
|
|
|
raise CERTIFICATE_MISSING_FIELDS_ERROR
|
2020-07-27 10:52:02 +00:00
|
|
|
|
2021-11-05 17:30:35 +00:00
|
|
|
path, script_hash, key_hash = _parse_credential(
|
2021-07-23 12:54:32 +00:00
|
|
|
certificate, CERTIFICATE_MISSING_FIELDS_ERROR
|
|
|
|
)
|
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
return (
|
|
|
|
messages.CardanoTxCertificate(
|
|
|
|
type=certificate_type,
|
2021-07-23 12:54:32 +00:00
|
|
|
path=path,
|
2021-06-30 12:13:43 +00:00
|
|
|
pool=bytes.fromhex(certificate["pool"]),
|
2021-07-23 12:54:32 +00:00
|
|
|
script_hash=script_hash,
|
2021-11-05 17:30:35 +00:00
|
|
|
key_hash=key_hash,
|
2021-06-30 12:13:43 +00:00
|
|
|
),
|
|
|
|
None,
|
2020-07-27 10:52:02 +00:00
|
|
|
)
|
2020-09-29 18:23:25 +00:00
|
|
|
elif certificate_type in (
|
|
|
|
messages.CardanoCertificateType.STAKE_REGISTRATION,
|
|
|
|
messages.CardanoCertificateType.STAKE_DEREGISTRATION,
|
2020-07-27 10:52:02 +00:00
|
|
|
):
|
2021-11-05 17:30:35 +00:00
|
|
|
path, script_hash, key_hash = _parse_credential(
|
2021-07-23 12:54:32 +00:00
|
|
|
certificate, CERTIFICATE_MISSING_FIELDS_ERROR
|
|
|
|
)
|
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
return (
|
|
|
|
messages.CardanoTxCertificate(
|
2021-11-05 17:30:35 +00:00
|
|
|
type=certificate_type,
|
|
|
|
path=path,
|
|
|
|
script_hash=script_hash,
|
|
|
|
key_hash=key_hash,
|
2021-06-30 12:13:43 +00:00
|
|
|
),
|
|
|
|
None,
|
2020-09-29 18:23:25 +00:00
|
|
|
)
|
|
|
|
elif certificate_type == messages.CardanoCertificateType.STAKE_POOL_REGISTRATION:
|
|
|
|
pool_parameters = certificate["pool_parameters"]
|
|
|
|
|
|
|
|
if any(
|
|
|
|
required_param not in pool_parameters
|
|
|
|
for required_param in REQUIRED_FIELDS_POOL_PARAMETERS
|
|
|
|
):
|
|
|
|
raise CERTIFICATE_MISSING_FIELDS_ERROR
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
pool_metadata: Optional[messages.CardanoPoolMetadataType]
|
2020-09-29 18:23:25 +00:00
|
|
|
if pool_parameters.get("metadata") is not None:
|
|
|
|
pool_metadata = messages.CardanoPoolMetadataType(
|
|
|
|
url=pool_parameters["metadata"]["url"],
|
|
|
|
hash=bytes.fromhex(pool_parameters["metadata"]["hash"]),
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
pool_metadata = None
|
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
owners = [
|
|
|
|
_parse_pool_owner(pool_owner)
|
|
|
|
for pool_owner in pool_parameters.get("owners", [])
|
|
|
|
]
|
|
|
|
relays = [
|
|
|
|
_parse_pool_relay(pool_relay)
|
|
|
|
for pool_relay in pool_parameters.get("relays", [])
|
|
|
|
]
|
|
|
|
|
|
|
|
return (
|
|
|
|
messages.CardanoTxCertificate(
|
|
|
|
type=certificate_type,
|
|
|
|
pool_parameters=messages.CardanoPoolParametersType(
|
|
|
|
pool_id=bytes.fromhex(pool_parameters["pool_id"]),
|
|
|
|
vrf_key_hash=bytes.fromhex(pool_parameters["vrf_key_hash"]),
|
|
|
|
pledge=int(pool_parameters["pledge"]),
|
|
|
|
cost=int(pool_parameters["cost"]),
|
|
|
|
margin_numerator=int(pool_parameters["margin"]["numerator"]),
|
|
|
|
margin_denominator=int(pool_parameters["margin"]["denominator"]),
|
|
|
|
reward_account=pool_parameters["reward_account"],
|
|
|
|
metadata=pool_metadata,
|
|
|
|
owners_count=len(owners),
|
|
|
|
relays_count=len(relays),
|
|
|
|
),
|
2020-09-29 18:23:25 +00:00
|
|
|
),
|
2021-06-30 12:13:43 +00:00
|
|
|
(owners, relays),
|
2020-07-27 10:52:02 +00:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
raise ValueError("Unknown certificate type")
|
|
|
|
|
|
|
|
|
2021-11-05 17:30:35 +00:00
|
|
|
def _parse_credential(
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
obj: dict, error: ValueError
|
2021-11-05 17:30:35 +00:00
|
|
|
) -> Tuple[List[int], Optional[bytes], Optional[bytes]]:
|
|
|
|
if not any(k in obj for k in ("path", "script_hash", "key_hash")):
|
2021-07-23 12:54:32 +00:00
|
|
|
raise error
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
path = tools.parse_path(obj.get("path", ""))
|
2021-07-23 12:54:32 +00:00
|
|
|
script_hash = parse_optional_bytes(obj.get("script_hash"))
|
2021-11-05 17:30:35 +00:00
|
|
|
key_hash = parse_optional_bytes(obj.get("key_hash"))
|
2021-07-23 12:54:32 +00:00
|
|
|
|
2021-11-05 17:30:35 +00:00
|
|
|
return path, script_hash, key_hash
|
2021-07-23 12:54:32 +00:00
|
|
|
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
def _parse_pool_owner(pool_owner: dict) -> messages.CardanoPoolOwner:
|
2020-09-29 18:23:25 +00:00
|
|
|
if "staking_key_path" in pool_owner:
|
2021-06-30 12:13:43 +00:00
|
|
|
return messages.CardanoPoolOwner(
|
2020-09-29 18:23:25 +00:00
|
|
|
staking_key_path=tools.parse_path(pool_owner["staking_key_path"])
|
|
|
|
)
|
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
return messages.CardanoPoolOwner(
|
2020-09-29 18:23:25 +00:00
|
|
|
staking_key_hash=bytes.fromhex(pool_owner["staking_key_hash"])
|
|
|
|
)
|
|
|
|
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
def _parse_pool_relay(pool_relay: dict) -> messages.CardanoPoolRelayParameters:
|
|
|
|
pool_relay_type = messages.CardanoPoolRelayType(pool_relay["type"])
|
2020-09-29 18:23:25 +00:00
|
|
|
|
|
|
|
if pool_relay_type == messages.CardanoPoolRelayType.SINGLE_HOST_IP:
|
|
|
|
ipv4_address_packed = (
|
|
|
|
ip_address(pool_relay["ipv4_address"]).packed
|
|
|
|
if "ipv4_address" in pool_relay
|
|
|
|
else None
|
|
|
|
)
|
|
|
|
ipv6_address_packed = (
|
|
|
|
ip_address(pool_relay["ipv6_address"]).packed
|
|
|
|
if "ipv6_address" in pool_relay
|
|
|
|
else None
|
|
|
|
)
|
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
return messages.CardanoPoolRelayParameters(
|
2020-09-29 18:23:25 +00:00
|
|
|
type=pool_relay_type,
|
|
|
|
port=int(pool_relay["port"]),
|
|
|
|
ipv4_address=ipv4_address_packed,
|
|
|
|
ipv6_address=ipv6_address_packed,
|
|
|
|
)
|
|
|
|
elif pool_relay_type == messages.CardanoPoolRelayType.SINGLE_HOST_NAME:
|
2021-06-30 12:13:43 +00:00
|
|
|
return messages.CardanoPoolRelayParameters(
|
2020-09-29 18:23:25 +00:00
|
|
|
type=pool_relay_type,
|
|
|
|
port=int(pool_relay["port"]),
|
|
|
|
host_name=pool_relay["host_name"],
|
|
|
|
)
|
|
|
|
elif pool_relay_type == messages.CardanoPoolRelayType.MULTIPLE_HOST_NAME:
|
2021-06-30 12:13:43 +00:00
|
|
|
return messages.CardanoPoolRelayParameters(
|
2020-09-29 18:23:25 +00:00
|
|
|
type=pool_relay_type,
|
|
|
|
host_name=pool_relay["host_name"],
|
|
|
|
)
|
|
|
|
|
|
|
|
raise ValueError("Unknown pool relay type")
|
|
|
|
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
def parse_withdrawal(withdrawal: dict) -> messages.CardanoTxWithdrawal:
|
2021-07-23 12:54:32 +00:00
|
|
|
WITHDRAWAL_MISSING_FIELDS_ERROR = ValueError(
|
|
|
|
"The withdrawal is missing some fields"
|
|
|
|
)
|
|
|
|
|
|
|
|
if "amount" not in withdrawal:
|
|
|
|
raise WITHDRAWAL_MISSING_FIELDS_ERROR
|
|
|
|
|
2021-11-05 17:30:35 +00:00
|
|
|
path, script_hash, key_hash = _parse_credential(
|
2021-07-23 12:54:32 +00:00
|
|
|
withdrawal, WITHDRAWAL_MISSING_FIELDS_ERROR
|
|
|
|
)
|
2020-07-27 10:52:02 +00:00
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
return messages.CardanoTxWithdrawal(
|
2021-07-23 12:54:32 +00:00
|
|
|
path=path,
|
2020-09-25 11:59:16 +00:00
|
|
|
amount=int(withdrawal["amount"]),
|
2021-07-23 12:54:32 +00:00
|
|
|
script_hash=script_hash,
|
2021-11-05 17:30:35 +00:00
|
|
|
key_hash=key_hash,
|
2020-07-27 10:52:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
def parse_auxiliary_data(
|
|
|
|
auxiliary_data: Optional[dict],
|
|
|
|
) -> Optional[messages.CardanoTxAuxiliaryData]:
|
2021-03-26 07:46:14 +00:00
|
|
|
if auxiliary_data is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
AUXILIARY_DATA_MISSING_FIELDS_ERROR = ValueError(
|
|
|
|
"Auxiliary data is missing some fields"
|
|
|
|
)
|
|
|
|
|
|
|
|
# include all provided fields so we can test validation in FW
|
2021-07-23 09:42:38 +00:00
|
|
|
hash = parse_optional_bytes(auxiliary_data.get("hash"))
|
2021-03-26 07:46:14 +00:00
|
|
|
|
|
|
|
catalyst_registration_parameters = None
|
|
|
|
if "catalyst_registration_parameters" in auxiliary_data:
|
|
|
|
catalyst_registration = auxiliary_data["catalyst_registration_parameters"]
|
|
|
|
if not all(
|
|
|
|
k in catalyst_registration for k in REQUIRED_FIELDS_CATALYST_REGISTRATION
|
|
|
|
):
|
|
|
|
raise AUXILIARY_DATA_MISSING_FIELDS_ERROR
|
|
|
|
|
|
|
|
catalyst_registration_parameters = (
|
|
|
|
messages.CardanoCatalystRegistrationParametersType(
|
|
|
|
voting_public_key=bytes.fromhex(
|
|
|
|
catalyst_registration["voting_public_key"]
|
|
|
|
),
|
|
|
|
staking_path=tools.parse_path(catalyst_registration["staking_path"]),
|
|
|
|
nonce=catalyst_registration["nonce"],
|
2021-04-08 05:06:10 +00:00
|
|
|
reward_address_parameters=_parse_address_parameters(
|
2021-07-23 12:54:32 +00:00
|
|
|
catalyst_registration["reward_address_parameters"],
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
str(AUXILIARY_DATA_MISSING_FIELDS_ERROR),
|
2021-03-26 07:46:14 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
if hash is None and catalyst_registration_parameters is None:
|
2021-03-26 07:46:14 +00:00
|
|
|
raise AUXILIARY_DATA_MISSING_FIELDS_ERROR
|
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
return messages.CardanoTxAuxiliaryData(
|
|
|
|
hash=hash,
|
2021-03-26 07:46:14 +00:00
|
|
|
catalyst_registration_parameters=catalyst_registration_parameters,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
def parse_mint(mint: Iterable[dict]) -> List[AssetGroupWithTokens]:
|
2021-07-23 12:54:32 +00:00
|
|
|
return _parse_token_bundle(mint, is_mint=True)
|
|
|
|
|
|
|
|
|
2021-10-12 11:33:24 +00:00
|
|
|
def parse_script_data_hash(script_data_hash: Optional[str]) -> Optional[bytes]:
|
|
|
|
return parse_optional_bytes(script_data_hash)
|
|
|
|
|
|
|
|
|
2021-10-21 17:43:10 +00:00
|
|
|
def parse_collateral_input(collateral_input: dict) -> CollateralInputWithPath:
|
|
|
|
if not all(k in collateral_input for k in REQUIRED_FIELDS_INPUT):
|
|
|
|
raise ValueError("The collateral input is missing some fields")
|
|
|
|
|
|
|
|
path = tools.parse_path(collateral_input.get("path", ""))
|
|
|
|
return (
|
|
|
|
messages.CardanoTxCollateralInput(
|
|
|
|
prev_hash=bytes.fromhex(collateral_input["prev_hash"]),
|
|
|
|
prev_index=collateral_input["prev_index"],
|
|
|
|
),
|
|
|
|
path,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def parse_required_signer(required_signer: dict) -> messages.CardanoTxRequiredSigner:
|
|
|
|
key_hash = parse_optional_bytes(required_signer.get("key_hash"))
|
|
|
|
key_path = tools.parse_path(required_signer.get("key_path", ""))
|
|
|
|
return messages.CardanoTxRequiredSigner(
|
|
|
|
key_hash=key_hash,
|
|
|
|
key_path=key_path,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-06-07 15:14:30 +00:00
|
|
|
def parse_reference_input(reference_input: dict) -> messages.CardanoTxReferenceInput:
|
|
|
|
if not all(k in reference_input for k in REQUIRED_FIELDS_INPUT):
|
|
|
|
raise ValueError("The reference input is missing some fields")
|
|
|
|
|
|
|
|
return messages.CardanoTxReferenceInput(
|
|
|
|
prev_hash=bytes.fromhex(reference_input["prev_hash"]),
|
|
|
|
prev_index=reference_input["prev_index"],
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-07-23 12:54:32 +00:00
|
|
|
def parse_additional_witness_request(
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
additional_witness_request: dict,
|
2021-07-23 12:54:32 +00:00
|
|
|
) -> Path:
|
|
|
|
if "path" not in additional_witness_request:
|
|
|
|
raise ValueError("Invalid additional witness request")
|
|
|
|
|
|
|
|
return tools.parse_path(additional_witness_request["path"])
|
|
|
|
|
|
|
|
|
|
|
|
def _get_witness_requests(
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
inputs: Sequence[InputWithPath],
|
|
|
|
certificates: Sequence[CertificateWithPoolOwnersAndRelays],
|
|
|
|
withdrawals: Sequence[messages.CardanoTxWithdrawal],
|
2021-10-21 17:43:10 +00:00
|
|
|
collateral_inputs: Sequence[CollateralInputWithPath],
|
|
|
|
required_signers: Sequence[messages.CardanoTxRequiredSigner],
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
additional_witness_requests: Sequence[Path],
|
2021-07-23 12:54:32 +00:00
|
|
|
signing_mode: messages.CardanoTxSigningMode,
|
|
|
|
) -> List[messages.CardanoTxWitnessRequest]:
|
2021-06-30 12:13:43 +00:00
|
|
|
paths = set()
|
|
|
|
|
2021-07-23 12:54:32 +00:00
|
|
|
# don't gather paths from tx elements in MULTISIG_TRANSACTION signing mode
|
|
|
|
if signing_mode != messages.CardanoTxSigningMode.MULTISIG_TRANSACTION:
|
|
|
|
for _, path in inputs:
|
|
|
|
if path:
|
|
|
|
paths.add(tuple(path))
|
|
|
|
for certificate, pool_owners_and_relays in certificates:
|
|
|
|
if (
|
|
|
|
certificate.type
|
|
|
|
in (
|
|
|
|
messages.CardanoCertificateType.STAKE_DEREGISTRATION,
|
|
|
|
messages.CardanoCertificateType.STAKE_DELEGATION,
|
|
|
|
)
|
|
|
|
and certificate.path
|
|
|
|
):
|
|
|
|
paths.add(tuple(certificate.path))
|
|
|
|
elif (
|
|
|
|
certificate.type
|
|
|
|
== messages.CardanoCertificateType.STAKE_POOL_REGISTRATION
|
|
|
|
and pool_owners_and_relays is not None
|
|
|
|
):
|
|
|
|
owners, _ = pool_owners_and_relays
|
|
|
|
for pool_owner in owners:
|
|
|
|
if pool_owner.staking_key_path:
|
|
|
|
paths.add(tuple(pool_owner.staking_key_path))
|
|
|
|
for withdrawal in withdrawals:
|
|
|
|
if withdrawal.path:
|
|
|
|
paths.add(tuple(withdrawal.path))
|
|
|
|
|
2021-10-21 17:43:10 +00:00
|
|
|
# gather Plutus-related paths
|
|
|
|
if signing_mode == messages.CardanoTxSigningMode.PLUTUS_TRANSACTION:
|
|
|
|
for _, path in collateral_inputs:
|
|
|
|
if path:
|
|
|
|
paths.add(tuple(path))
|
|
|
|
|
2022-06-09 12:57:30 +00:00
|
|
|
# add required_signers and additional_witness_requests in all cases
|
|
|
|
for required_signer in required_signers:
|
|
|
|
if required_signer.key_path:
|
|
|
|
paths.add(tuple(required_signer.key_path))
|
2021-07-23 12:54:32 +00:00
|
|
|
for additional_witness_request in additional_witness_requests:
|
|
|
|
paths.add(tuple(additional_witness_request))
|
|
|
|
|
|
|
|
sorted_paths = sorted([list(path) for path in paths])
|
|
|
|
return [messages.CardanoTxWitnessRequest(path=path) for path in sorted_paths]
|
2021-06-30 12:13:43 +00:00
|
|
|
|
|
|
|
|
2022-06-07 15:14:30 +00:00
|
|
|
def _get_inputs_items(inputs: List[InputWithPath]) -> Iterator[messages.CardanoTxInput]:
|
2021-06-30 12:13:43 +00:00
|
|
|
for input, _ in inputs:
|
|
|
|
yield input
|
|
|
|
|
|
|
|
|
2022-06-07 15:14:30 +00:00
|
|
|
def _get_outputs_items(outputs: List[OutputWithData]) -> Iterator[OutputItem]:
|
|
|
|
for output_with_data in outputs:
|
|
|
|
yield from _get_output_items(output_with_data)
|
|
|
|
|
|
|
|
|
|
|
|
def _get_output_items(output_with_data: OutputWithData) -> Iterator[OutputItem]:
|
|
|
|
(
|
|
|
|
output,
|
|
|
|
asset_groups,
|
|
|
|
inline_datum_chunks,
|
|
|
|
reference_script_chunks,
|
|
|
|
) = output_with_data
|
|
|
|
yield output
|
|
|
|
for asset_group, tokens in asset_groups:
|
|
|
|
yield asset_group
|
|
|
|
yield from tokens
|
|
|
|
yield from inline_datum_chunks
|
|
|
|
yield from reference_script_chunks
|
2021-06-30 12:13:43 +00:00
|
|
|
|
|
|
|
|
2022-06-07 15:14:30 +00:00
|
|
|
def _get_certificates_items(
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
certificates: Sequence[CertificateWithPoolOwnersAndRelays],
|
2021-06-30 12:13:43 +00:00
|
|
|
) -> Iterator[CertificateItem]:
|
|
|
|
for certificate, pool_owners_and_relays in certificates:
|
|
|
|
yield certificate
|
|
|
|
if pool_owners_and_relays is not None:
|
|
|
|
owners, relays = pool_owners_and_relays
|
|
|
|
yield from owners
|
|
|
|
yield from relays
|
|
|
|
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
def _get_mint_items(mint: Sequence[AssetGroupWithTokens]) -> Iterator[MintItem]:
|
2021-10-21 17:43:10 +00:00
|
|
|
if not mint:
|
|
|
|
return
|
2021-07-23 12:54:32 +00:00
|
|
|
yield messages.CardanoTxMint(asset_groups_count=len(mint))
|
|
|
|
for asset_group, tokens in mint:
|
|
|
|
yield asset_group
|
|
|
|
yield from tokens
|
|
|
|
|
|
|
|
|
2022-06-07 15:14:30 +00:00
|
|
|
def _get_collateral_inputs_items(
|
2021-10-21 17:43:10 +00:00
|
|
|
collateral_inputs: Sequence[CollateralInputWithPath],
|
|
|
|
) -> Iterator[messages.CardanoTxCollateralInput]:
|
|
|
|
for collateral_input, _ in collateral_inputs:
|
|
|
|
yield collateral_input
|
|
|
|
|
|
|
|
|
2020-07-23 13:54:49 +00:00
|
|
|
# ====== Client functions ====== #
|
|
|
|
|
2018-09-05 12:56:31 +00:00
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
@expect(messages.CardanoAddress, field="address", ret_type=str)
|
2020-07-01 13:43:02 +00:00
|
|
|
def get_address(
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
client: "TrezorClient",
|
2020-07-23 13:54:49 +00:00
|
|
|
address_parameters: messages.CardanoAddressParametersType,
|
2020-07-28 13:33:12 +00:00
|
|
|
protocol_magic: int = PROTOCOL_MAGICS["mainnet"],
|
|
|
|
network_id: int = NETWORK_IDS["mainnet"],
|
|
|
|
show_display: bool = False,
|
2021-10-22 14:04:43 +00:00
|
|
|
derivation_type: messages.CardanoDerivationType = messages.CardanoDerivationType.ICARUS,
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
) -> "MessageType":
|
2018-09-05 12:56:31 +00:00
|
|
|
return client.call(
|
2020-07-01 13:43:02 +00:00
|
|
|
messages.CardanoGetAddress(
|
2020-07-23 13:54:49 +00:00
|
|
|
address_parameters=address_parameters,
|
2020-07-01 13:43:02 +00:00
|
|
|
protocol_magic=protocol_magic,
|
2020-07-23 13:54:49 +00:00
|
|
|
network_id=network_id,
|
2020-07-01 13:43:02 +00:00
|
|
|
show_display=show_display,
|
2021-10-22 14:04:43 +00:00
|
|
|
derivation_type=derivation_type,
|
2020-07-01 13:43:02 +00:00
|
|
|
)
|
2018-09-05 12:56:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@expect(messages.CardanoPublicKey)
|
2021-10-22 14:04:43 +00:00
|
|
|
def get_public_key(
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
client: "TrezorClient",
|
2021-10-22 14:04:43 +00:00
|
|
|
address_n: List[int],
|
|
|
|
derivation_type: messages.CardanoDerivationType = messages.CardanoDerivationType.ICARUS,
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
) -> "MessageType":
|
2021-10-22 14:04:43 +00:00
|
|
|
return client.call(
|
|
|
|
messages.CardanoGetPublicKey(
|
|
|
|
address_n=address_n, derivation_type=derivation_type
|
|
|
|
)
|
|
|
|
)
|
2018-09-05 12:56:31 +00:00
|
|
|
|
|
|
|
|
2021-07-23 09:42:38 +00:00
|
|
|
@expect(messages.CardanoNativeScriptHash)
|
|
|
|
def get_native_script_hash(
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
client: "TrezorClient",
|
2021-07-23 09:42:38 +00:00
|
|
|
native_script: messages.CardanoNativeScript,
|
|
|
|
display_format: messages.CardanoNativeScriptHashDisplayFormat = messages.CardanoNativeScriptHashDisplayFormat.HIDE,
|
2021-10-22 14:04:43 +00:00
|
|
|
derivation_type: messages.CardanoDerivationType = messages.CardanoDerivationType.ICARUS,
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
) -> "MessageType":
|
2021-07-23 09:42:38 +00:00
|
|
|
return client.call(
|
|
|
|
messages.CardanoGetNativeScriptHash(
|
|
|
|
script=native_script,
|
|
|
|
display_format=display_format,
|
2021-10-22 14:04:43 +00:00
|
|
|
derivation_type=derivation_type,
|
2021-07-23 09:42:38 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-09-05 12:56:31 +00:00
|
|
|
def sign_tx(
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
client: "TrezorClient",
|
2021-06-30 12:13:43 +00:00
|
|
|
signing_mode: messages.CardanoTxSigningMode,
|
|
|
|
inputs: List[InputWithPath],
|
2022-06-07 15:14:30 +00:00
|
|
|
outputs: List[OutputWithData],
|
2020-07-01 13:43:02 +00:00
|
|
|
fee: int,
|
2021-01-25 16:12:32 +00:00
|
|
|
ttl: Optional[int],
|
|
|
|
validity_interval_start: Optional[int],
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
certificates: Sequence[CertificateWithPoolOwnersAndRelays] = (),
|
|
|
|
withdrawals: Sequence[messages.CardanoTxWithdrawal] = (),
|
2020-07-28 13:33:12 +00:00
|
|
|
protocol_magic: int = PROTOCOL_MAGICS["mainnet"],
|
|
|
|
network_id: int = NETWORK_IDS["mainnet"],
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
auxiliary_data: Optional[messages.CardanoTxAuxiliaryData] = None,
|
|
|
|
mint: Sequence[AssetGroupWithTokens] = (),
|
2021-10-12 11:33:24 +00:00
|
|
|
script_data_hash: Optional[bytes] = None,
|
2021-10-21 17:43:10 +00:00
|
|
|
collateral_inputs: Sequence[CollateralInputWithPath] = (),
|
|
|
|
required_signers: Sequence[messages.CardanoTxRequiredSigner] = (),
|
2022-06-07 15:14:30 +00:00
|
|
|
collateral_return: Optional[OutputWithData] = None,
|
|
|
|
total_collateral: Optional[int] = None,
|
|
|
|
reference_inputs: Sequence[messages.CardanoTxReferenceInput] = (),
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
additional_witness_requests: Sequence[Path] = (),
|
2021-10-22 14:04:43 +00:00
|
|
|
derivation_type: messages.CardanoDerivationType = messages.CardanoDerivationType.ICARUS,
|
2022-01-12 14:45:37 +00:00
|
|
|
include_network_id: bool = False,
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
) -> Dict[str, Any]:
|
2021-06-30 12:13:43 +00:00
|
|
|
UNEXPECTED_RESPONSE_ERROR = exceptions.TrezorException("Unexpected response")
|
|
|
|
|
2021-07-23 12:54:32 +00:00
|
|
|
witness_requests = _get_witness_requests(
|
2021-10-21 17:43:10 +00:00
|
|
|
inputs,
|
|
|
|
certificates,
|
|
|
|
withdrawals,
|
|
|
|
collateral_inputs,
|
|
|
|
required_signers,
|
|
|
|
additional_witness_requests,
|
|
|
|
signing_mode,
|
2021-07-23 12:54:32 +00:00
|
|
|
)
|
2021-06-30 12:13:43 +00:00
|
|
|
|
2018-09-05 12:56:31 +00:00
|
|
|
response = client.call(
|
2021-06-30 12:13:43 +00:00
|
|
|
messages.CardanoSignTxInit(
|
|
|
|
signing_mode=signing_mode,
|
|
|
|
inputs_count=len(inputs),
|
|
|
|
outputs_count=len(outputs),
|
2020-07-01 13:43:02 +00:00
|
|
|
fee=fee,
|
|
|
|
ttl=ttl,
|
2021-01-25 16:12:32 +00:00
|
|
|
validity_interval_start=validity_interval_start,
|
2021-06-30 12:13:43 +00:00
|
|
|
certificates_count=len(certificates),
|
|
|
|
withdrawals_count=len(withdrawals),
|
2018-11-30 11:14:46 +00:00
|
|
|
protocol_magic=protocol_magic,
|
2020-07-23 13:54:49 +00:00
|
|
|
network_id=network_id,
|
2021-06-30 12:13:43 +00:00
|
|
|
has_auxiliary_data=auxiliary_data is not None,
|
2021-07-23 12:54:32 +00:00
|
|
|
minting_asset_groups_count=len(mint),
|
2021-10-12 11:33:24 +00:00
|
|
|
script_data_hash=script_data_hash,
|
2021-10-21 17:43:10 +00:00
|
|
|
collateral_inputs_count=len(collateral_inputs),
|
|
|
|
required_signers_count=len(required_signers),
|
2022-06-07 15:14:30 +00:00
|
|
|
has_collateral_return=collateral_return is not None,
|
|
|
|
total_collateral=total_collateral,
|
|
|
|
reference_inputs_count=len(reference_inputs),
|
2021-07-23 12:54:32 +00:00
|
|
|
witness_requests_count=len(witness_requests),
|
2021-10-22 14:04:43 +00:00
|
|
|
derivation_type=derivation_type,
|
2022-01-12 14:45:37 +00:00
|
|
|
include_network_id=include_network_id,
|
2018-09-05 12:56:31 +00:00
|
|
|
)
|
|
|
|
)
|
2021-06-30 12:13:43 +00:00
|
|
|
if not isinstance(response, messages.CardanoTxItemAck):
|
|
|
|
raise UNEXPECTED_RESPONSE_ERROR
|
|
|
|
|
|
|
|
for tx_item in chain(
|
2022-06-07 15:14:30 +00:00
|
|
|
_get_inputs_items(inputs),
|
|
|
|
_get_outputs_items(outputs),
|
|
|
|
_get_certificates_items(certificates),
|
2021-06-30 12:13:43 +00:00
|
|
|
withdrawals,
|
|
|
|
):
|
|
|
|
response = client.call(tx_item)
|
|
|
|
if not isinstance(response, messages.CardanoTxItemAck):
|
|
|
|
raise UNEXPECTED_RESPONSE_ERROR
|
|
|
|
|
feat(python): add full type information
WIP - typing the trezorctl apps
typing functions trezorlib/cli
addressing most of mypy issue for trezorlib apps and _internal folder
fixing broken device tests by changing asserts in debuglink.py
addressing most of mypy issues in trezorlib/cli folder
adding types to some untyped functions, mypy section in setup.cfg
typing what can be typed, some mypy fixes, resolving circular import issues
importing type objects in "if TYPE_CHECKING:" branch
fixing CI by removing assert in emulator, better ignore comments
CI assert fix, style fixes, new config options
fixup! CI assert fix, style fixes, new config options
type fixes after rebasing on master
fixing python3.6 and 3.7 unittests by importing Literal from typing_extensions
couple mypy and style fixes
fixes and improvements from code review
silencing all but one mypy issues
trial of typing the tools.expect function
fixup! trial of typing the tools.expect function
@expect and @session decorators correctly type-checked
Optional args in CLI where relevant, not using general list/tuple/dict where possible
python/Makefile commands, adding them into CI, ignoring last mypy issue
documenting overload for expect decorator, two mypy fixes coming from that
black style fix
improved typing of decorators, pyright config file
addressing or ignoring pyright errors, replacing mypy in CI by pyright
fixing incomplete assert causing device tests to fail
pyright issue that showed in CI but not locally, printing pyright version in CI
fixup! pyright issue that showed in CI but not locally, printing pyright version in CI
unifying type:ignore statements for pyright usage
resolving PIL.Image issues, pyrightconfig not excluding anything
replacing couple asserts with TypeGuard on safe_issubclass
better error handling of usb1 import for webusb
better error handling of hid import
small typing details found out by strict pyright mode
improvements from code review
chore(python): changing List to Sequence for protobuf messages
small code changes to reflect the protobuf change to Sequence
importing TypedDict from typing_extensions to support 3.6 and 3.7
simplify _format_access_list function
fixup! simplify _format_access_list function
typing tools folder
typing helper-scripts folder
some click typing
enforcing all functions to have typed arguments
reverting the changed argument name in tools
replacing TransportType with Transport
making PinMatrixRequest.type protobuf attribute required
reverting the protobuf change, making argument into get_pin Optional
small fixes in asserts
solving the session decorator type issues
fixup! solving the session decorator type issues
improvements from code review
fixing new pyright errors introduced after version increase
changing -> Iterable to -> Sequence in enumerate_devices, change in wait_for_devices
style change in debuglink.py
chore(python): adding type annotation to Sequences in messages.py
better "self and cls" types on Transport
fixup! better "self and cls" types on Transport
fixing some easy things from strict pyright run
2021-11-03 22:12:53 +00:00
|
|
|
sign_tx_response: Dict[str, Any] = {}
|
2018-09-05 12:56:31 +00:00
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
if auxiliary_data is not None:
|
|
|
|
auxiliary_data_supplement = client.call(auxiliary_data)
|
|
|
|
if not isinstance(
|
|
|
|
auxiliary_data_supplement, messages.CardanoTxAuxiliaryDataSupplement
|
|
|
|
):
|
|
|
|
raise UNEXPECTED_RESPONSE_ERROR
|
|
|
|
if (
|
|
|
|
auxiliary_data_supplement.type
|
|
|
|
!= messages.CardanoTxAuxiliaryDataSupplementType.NONE
|
|
|
|
):
|
|
|
|
sign_tx_response[
|
|
|
|
"auxiliary_data_supplement"
|
|
|
|
] = auxiliary_data_supplement.__dict__
|
|
|
|
|
|
|
|
response = client.call(messages.CardanoTxHostAck())
|
|
|
|
if not isinstance(response, messages.CardanoTxItemAck):
|
|
|
|
raise UNEXPECTED_RESPONSE_ERROR
|
|
|
|
|
2021-10-21 17:43:10 +00:00
|
|
|
for tx_item in chain(
|
|
|
|
_get_mint_items(mint),
|
2022-06-07 15:14:30 +00:00
|
|
|
_get_collateral_inputs_items(collateral_inputs),
|
2021-10-21 17:43:10 +00:00
|
|
|
required_signers,
|
|
|
|
):
|
|
|
|
response = client.call(tx_item)
|
|
|
|
if not isinstance(response, messages.CardanoTxItemAck):
|
2022-06-07 15:14:30 +00:00
|
|
|
raise UNEXPECTED_RESPONSE_ERROR
|
|
|
|
|
|
|
|
if collateral_return is not None:
|
|
|
|
for tx_item in _get_output_items(collateral_return):
|
|
|
|
response = client.call(tx_item)
|
|
|
|
if not isinstance(response, messages.CardanoTxItemAck):
|
|
|
|
raise UNEXPECTED_RESPONSE_ERROR
|
|
|
|
|
|
|
|
for reference_input in reference_inputs:
|
|
|
|
response = client.call(reference_input)
|
|
|
|
if not isinstance(response, messages.CardanoTxItemAck):
|
2021-10-21 17:43:10 +00:00
|
|
|
raise UNEXPECTED_RESPONSE_ERROR
|
2021-07-23 12:54:32 +00:00
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
sign_tx_response["witnesses"] = []
|
2021-07-23 12:54:32 +00:00
|
|
|
for witness_request in witness_requests:
|
|
|
|
response = client.call(witness_request)
|
2021-06-30 12:13:43 +00:00
|
|
|
if not isinstance(response, messages.CardanoTxWitnessResponse):
|
|
|
|
raise UNEXPECTED_RESPONSE_ERROR
|
|
|
|
sign_tx_response["witnesses"].append(
|
|
|
|
{
|
|
|
|
"type": response.type,
|
|
|
|
"pub_key": response.pub_key,
|
|
|
|
"signature": response.signature,
|
|
|
|
"chain_code": response.chain_code,
|
|
|
|
}
|
|
|
|
)
|
2021-02-19 21:13:39 +00:00
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
response = client.call(messages.CardanoTxHostAck())
|
|
|
|
if not isinstance(response, messages.CardanoTxBodyHash):
|
|
|
|
raise UNEXPECTED_RESPONSE_ERROR
|
|
|
|
sign_tx_response["tx_hash"] = response.tx_hash
|
2021-02-19 21:13:39 +00:00
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
response = client.call(messages.CardanoTxHostAck())
|
|
|
|
if not isinstance(response, messages.CardanoSignTxFinished):
|
|
|
|
raise UNEXPECTED_RESPONSE_ERROR
|
2021-02-19 21:13:39 +00:00
|
|
|
|
2021-06-30 12:13:43 +00:00
|
|
|
return sign_tx_response
|