2022-10-21 08:29:54 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012-2022 SatoshiLabs and contributors
|
|
|
|
#
|
|
|
|
# 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>.
|
|
|
|
|
2021-11-26 15:31:35 +00:00
|
|
|
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
|
2023-08-15 10:10:32 +00:00
|
|
|
internal_name: str
|
2021-11-26 15:31:35 +00:00
|
|
|
minimum_version: Tuple[int, int, int]
|
|
|
|
vendors: Collection[str]
|
|
|
|
usb_ids: Collection[UsbId]
|
|
|
|
default_mapping: mapping.ProtobufMapping
|
|
|
|
|
|
|
|
|
2023-10-16 10:38:24 +00:00
|
|
|
# ==== internal names ====
|
|
|
|
|
|
|
|
T1B1 = TrezorModel(
|
2021-11-26 15:31:35 +00:00
|
|
|
name="1",
|
2023-08-15 10:10:32 +00:00
|
|
|
internal_name="T1B1",
|
2021-11-26 15:31:35 +00:00
|
|
|
minimum_version=(1, 8, 0),
|
|
|
|
vendors=VENDORS,
|
|
|
|
usb_ids=((0x534C, 0x0001),),
|
|
|
|
default_mapping=mapping.DEFAULT_MAPPING,
|
|
|
|
)
|
|
|
|
|
2023-10-16 10:38:24 +00:00
|
|
|
T2T1 = TrezorModel(
|
2021-11-26 15:31:35 +00:00
|
|
|
name="T",
|
2023-08-15 10:10:32 +00:00
|
|
|
internal_name="T2T1",
|
2021-11-26 15:31:35 +00:00
|
|
|
minimum_version=(2, 1, 0),
|
|
|
|
vendors=VENDORS,
|
|
|
|
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)),
|
|
|
|
default_mapping=mapping.DEFAULT_MAPPING,
|
|
|
|
)
|
|
|
|
|
2023-10-16 10:38:24 +00:00
|
|
|
T2B1 = TrezorModel(
|
2023-08-15 10:11:37 +00:00
|
|
|
name="Safe 3",
|
2023-08-15 10:10:32 +00:00
|
|
|
internal_name="T2B1",
|
2022-05-01 12:10:39 +00:00
|
|
|
minimum_version=(2, 1, 0),
|
|
|
|
vendors=VENDORS,
|
|
|
|
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)),
|
|
|
|
default_mapping=mapping.DEFAULT_MAPPING,
|
|
|
|
)
|
|
|
|
|
2023-08-24 09:33:50 +00:00
|
|
|
T3T1 = TrezorModel(
|
2024-03-04 15:12:11 +00:00
|
|
|
name="Safe 5",
|
2023-08-24 09:33:50 +00:00
|
|
|
internal_name="T3T1",
|
|
|
|
minimum_version=(2, 1, 0),
|
|
|
|
vendors=VENDORS,
|
|
|
|
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)),
|
|
|
|
default_mapping=mapping.DEFAULT_MAPPING,
|
|
|
|
)
|
|
|
|
|
2023-10-16 10:38:24 +00:00
|
|
|
DISC1 = TrezorModel(
|
2023-02-09 22:56:03 +00:00
|
|
|
name="DISC1",
|
2023-08-15 10:10:32 +00:00
|
|
|
internal_name="D001",
|
2023-02-09 22:56:03 +00:00
|
|
|
minimum_version=(2, 1, 0),
|
|
|
|
vendors=VENDORS,
|
|
|
|
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)),
|
|
|
|
default_mapping=mapping.DEFAULT_MAPPING,
|
|
|
|
)
|
|
|
|
|
2023-06-28 08:51:37 +00:00
|
|
|
DISC2 = TrezorModel(
|
|
|
|
name="DISC2",
|
|
|
|
internal_name="D002",
|
|
|
|
minimum_version=(2, 1, 0),
|
|
|
|
vendors=VENDORS,
|
|
|
|
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)),
|
|
|
|
default_mapping=mapping.DEFAULT_MAPPING,
|
|
|
|
)
|
|
|
|
|
2023-10-16 10:38:24 +00:00
|
|
|
# ==== model based names ====
|
|
|
|
|
|
|
|
TREZOR_ONE = T1B1
|
|
|
|
TREZOR_T = T2T1
|
|
|
|
TREZOR_R = T2B1
|
|
|
|
TREZOR_SAFE3 = T2B1
|
2024-03-04 15:12:11 +00:00
|
|
|
TREZOR_SAFE5 = T3T1
|
2023-10-16 10:38:24 +00:00
|
|
|
TREZOR_DISC1 = DISC1
|
2023-06-28 08:51:37 +00:00
|
|
|
TREZOR_DISC2 = DISC2
|
2023-10-16 10:38:24 +00:00
|
|
|
|
2023-08-24 09:33:50 +00:00
|
|
|
TREZORS = {T1B1, T2T1, T2B1, T3T1, DISC1, DISC2}
|
2021-11-26 15:31:35 +00:00
|
|
|
|
|
|
|
|
2023-02-17 10:44:20 +00:00
|
|
|
def by_name(name: Optional[str]) -> Optional[TrezorModel]:
|
|
|
|
if name is None:
|
2023-10-16 10:38:24 +00:00
|
|
|
return T1B1
|
2021-11-26 15:31:35 +00:00
|
|
|
for model in TREZORS:
|
|
|
|
if model.name == name:
|
|
|
|
return model
|
|
|
|
return None
|
2023-08-15 10:10:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def by_internal_name(name: Optional[str]) -> Optional[TrezorModel]:
|
|
|
|
if name is None:
|
|
|
|
return None
|
|
|
|
for model in TREZORS:
|
|
|
|
if model.internal_name == name:
|
|
|
|
return model
|
|
|
|
return None
|