1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 12:28:09 +00:00
trezor-firmware/python
grdddj 1a0b590914 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-26 16:28:49 +01:00
..
.changelog.d feat(common): Add no_script_type option to SignMessage. 2021-11-10 17:35:57 +01:00
bash_completion.d MONOREPO MERGE python-trezor 2019-04-15 19:15:12 +02:00
docs feat(python): support Cardano derivation type arguments 2021-11-10 13:57:57 +01:00
helper-scripts feat(python): add full type information 2021-11-26 16:28:49 +01:00
src/trezorlib feat(python): add full type information 2021-11-26 16:28:49 +01:00
tests refactor(python/stellar): Since the firmware does not support MuxedAccount, we refuse to process this type of transaction. 2021-11-04 13:16:29 +01:00
tools feat(python): add full type information 2021-11-26 16:28:49 +01:00
.gitignore feat(python): add full type information 2021-11-26 16:28:49 +01:00
.towncrier.template.md docs(python): use towncrier for generating CHANGELOG.md 2021-05-04 14:18:01 +02:00
AUTHORS feat(python/trezorctl): improving and refactoring firmware CLI commands 2021-07-07 10:33:03 +02:00
CHANGELOG.md fix(python/trezorctl): fix "invalid value" of ChoiceType with default 2021-09-07 13:37:23 +02:00
CHANGELOG.unreleased docs(core): use towncrier for generating CHANGELOG.md 2021-05-04 14:18:01 +02:00
COPYING MONOREPO MERGE python-trezor 2019-04-15 19:15:12 +02:00
default.nix Drop pyargs 2020-01-02 12:55:35 +01:00
Makefile build(python): drop changelog target from makefile 2021-07-29 15:32:42 +02:00
MANIFEST.in python: restructure package 2019-08-12 12:57:25 +02:00
README.md refactor(python/stellar): Use Stellar Python SDK to parse Stellar transactions. 2021-08-06 13:14:57 +02:00
requirements-optional.txt chore(python/stellar): bump stellar-sdk to 5.0.0. 2021-11-04 13:16:29 +01:00
requirements.txt chore(python): increasing mnemonic version to 0.20 2021-11-26 16:28:49 +01:00
setup.cfg chore(python): replacing attrs with dataclasses 2021-11-26 16:28:49 +01:00
setup.py chore(python): increasing mnemonic version to 0.20 2021-11-26 16:28:49 +01:00
towncrier.toml docs(python): use towncrier for generating CHANGELOG.md 2021-05-04 14:18:01 +02:00
tox.ini refactor(python/stellar): Use Stellar Python SDK to parse Stellar transactions. 2021-08-06 13:14:57 +02:00

trezorlib

repology image

Python library and command-line client for communicating with Trezor Hardware Wallet.

See https://trezor.io for more information.

Install

Python Trezor tools require Python 3.5 or higher, and libusb 1.0. The easiest way to install it is with pip. The rest of this guide assumes you have a working pip; if not, you can refer to this guide.

On a typical system, you already have all you need. Install trezor with:

pip3 install trezor

On Windows, you also need to either install Trezor Bridge, or libusb and the appropriate drivers.

Firmware version requirements

Current trezorlib version supports Trezor One version 1.8.0 and up, and Trezor T version 2.1.0 and up.

For firmware versions below 1.8.0 and 2.1.0 respectively, the only supported operation is "upgrade firmware".

Trezor One with firmware older than 1.7.0 (including firmware-less out-of-the-box units) will not be recognized, unless you install HIDAPI support (see below).

Installation options

  • Firmware-less Trezor One: If you are setting up a brand new Trezor One without firmware, you will need HIDAPI support. On Linux, you will need the following packages (or their equivalents) as prerequisites: python3-dev, cython3, libusb-1.0-0-dev, libudev-dev.

    Install with:

    pip3 install trezor[hidapi]
    
  • Ethereum: To support Ethereum signing from command line, additional packages are needed. Install with:

    pip3 install trezor[ethereum]
    
  • Stellar: To support Stellar signing from command line, additional packages are needed. Install with:

    pip3 install trezor[stellar]
    

To install all three, use pip3 install trezor[hidapi,ethereum,stellar].

Distro packages

Check out Repology to see if your operating system has an up-to-date python-trezor package.

Installing latest version from GitHub

pip3 install "git+https://github.com/trezor/trezor-firmware#egg=trezor&subdirectory=python"

Running from source

Install the Poetry tool, checkout trezor-firmware from git, and enter the poetry shell:

pip3 install poetry
git clone https://github.com/trezor/trezor-firmware
cd trezor-firmware
poetry install
poetry shell

In this environment, trezorlib and the trezorctl tool is running from the live sources, so your changes are immediately effective.

Command line client (trezorctl)

The included trezorctl python script can perform various tasks such as changing setting in the Trezor, signing transactions, retrieving account info and addresses. See the docs/ sub folder for detailed examples and options.

NOTE: An older version of the trezorctl command is available for Debian Stretch (and comes pre-installed on Tails OS).

Python Library

You can use this python library to interact with a Trezor and use its capabilities in your application. See examples here in the tools/ sub folder.

PIN Entering

When you are asked for PIN, you have to enter scrambled PIN. Follow the numbers shown on Trezor display and enter the their positions using the numeric keyboard mapping:

7 8 9
4 5 6
1 2 3

Example: your PIN is 1234 and Trezor is displaying the following:

2 8 3
5 4 6
7 9 1

You have to enter: 3795

Contributing

If you want to change protobuf or coin definitions, you will need to regenerate definitions in the python/ subdirectory.

First, make sure your submodules are up-to-date with:

git submodule update --init --recursive

Then, rebuild the protobuf messages by running, from the trezor-firmware top-level directory:

make gen

To get support for BTC-like coins, these steps are enough and no further changes to the library are necessary.