Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(python): introduce Trezor models
This keeps information about vendors and USB IDs in one place, and allows us to extend with model-specific information later. By default, this should be backwards-compatible -- TrezorClient can optionally accept model information, and if not, it will try to guess based on Features. It is possible to specify which models to look for in transport enumeration. Bridge and UDP transports ignore the parameter, because they can't know what model is on the other side. supersedes #1448 and #1449
- Loading branch information
Showing
8 changed files
with
108 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from dataclasses import dataclass | ||
from typing import Collection, Optional, Tuple | ||
|
||
from . import mapping | ||
|
||
UsbId = Tuple[int, int] | ||
|
||
VENDORS = ("bitcointrezor.com", "trezor.io") | ||
|
||
|
||
@dataclass(eq=True, frozen=True) | ||
class TrezorModel: | ||
name: str | ||
minimum_version: Tuple[int, int, int] | ||
vendors: Collection[str] | ||
usb_ids: Collection[UsbId] | ||
default_mapping: mapping.ProtobufMapping | ||
|
||
|
||
MODEL_ONE = TrezorModel( | ||
name="1", | ||
minimum_version=(1, 8, 0), | ||
vendors=VENDORS, | ||
usb_ids=((0x534C, 0x0001),), | ||
default_mapping=mapping.DEFAULT_MAPPING, | ||
) | ||
|
||
MODEL_T = TrezorModel( | ||
name="T", | ||
minimum_version=(2, 1, 0), | ||
vendors=VENDORS, | ||
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)), | ||
default_mapping=mapping.DEFAULT_MAPPING, | ||
) | ||
|
||
TREZORS = {MODEL_ONE, MODEL_T} | ||
|
||
|
||
def by_name(name: str) -> Optional[TrezorModel]: | ||
for model in TREZORS: | ||
if model.name == name: | ||
return model | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters