1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-20 21:38:26 +00:00
trezor-firmware/python
matejcik ed79d35de9 feat(python): make webusb transport more resilient
* convert more USB errors into TransportExceptions
* add a timeout + infinite loop for read/write operations,
  so that they are interruptible by Python, instead of leaving
  the interface in a bad state when hard-killed
* (also ctrl+c now works if the process is waiting for usb)
2024-08-28 00:08:48 +02:00
..
.changelog.d feat(python): make webusb transport more resilient 2024-08-28 00:08:48 +02:00
bash_completion.d MONOREPO MERGE python-trezor 2019-04-15 19:15:12 +02:00
docs chore(python): regenerate documentation 2024-06-25 13:43:13 +02:00
helper-scripts tools(python): update relicensing script 2022-11-01 14:56:00 +01:00
src/trezorlib feat(python): make webusb transport more resilient 2024-08-28 00:08:48 +02:00
stubs/PIL style(python): upgrade to pyright 1.1.361 2024-05-07 11:57:10 +02:00
tests refactor(core): move vendor headers to model specific directories 2024-07-16 15:56:28 +02:00
tools feat: Remove display_random feature. 2024-08-27 19:33:23 +02: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 docs(python): changelog for 0.13.9 2024-06-25 13:43:13 +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 style(python): extend style checks to more targets 2023-08-16 13:29:51 +02:00
MANIFEST.in build(python): update setuptools manifest 2024-06-25 13:43:13 +02:00
pyrightconfig.json style(python): upgrade to pyright 1.1.361 2024-05-07 11:57:10 +02:00
README.md docs(python): update README 2024-06-25 13:43:13 +02:00
requirements-optional.txt chore(python): annotate package with minimum python 3.8 2024-06-25 13:43:13 +02:00
requirements.txt chore(python): annotate package with minimum python 3.8 2024-06-25 13:43:13 +02:00
setup.cfg chore: upgrade style checkers 2024-02-29 13:08:18 +01:00
setup.py chore(python): annotate package with minimum python 3.8 2024-06-25 13:43:13 +02:00
towncrier.toml docs(python): generate changelog for 0.13.8 2023-10-20 15:45:32 +02:00
tox.ini chore(python): drop source support for Python 3.6 and 3.7 2024-02-12 14:49:32 +01: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.8 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 and bootloader older than 1.6.0 (including pre-2021 fresh-out-of-the-box units) will not be recognized, unless you install HIDAPI support (see below).

Installation options

  • 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]
    
  • Extended device authentication: For user-friendly device authentication for Trezor Safe 3 and newer models (trezorctl device authenticate command), additional packages are needed. Install with:

    pip3 install trezor[authentication]
    
  • Firmware-less Trezor One: If you are setting up a brand new Trezor One manufactured before 2021 (with pre-installed bootloader older than 1.6.0), 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]
    

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

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 python/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 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