Trezor Development
The trezor is divided into multiple repositories:
- trezor-core - this is firmware for Trezor T, also there is an emulator for that device
- trezor-mcu - this is firmware for Trezor one
- trezor-common - contains description of messages which are used for comunication with Trezor device (it use google protobuf)
- trezor-crypto - this repo stores crypto code - so if the coin use new "algorithms" it will goes there
- python-trezor - something like cli tool for using trezor - also used for integration tests
- connect - this is js lib which can be included into website and provide api for communication with trezor from web
- trezord-go - also known as Trezor "bridge" and is needed for communication with trezor from web (it creates something like web server. This wont be needed in future as trezor also use webusb - right now only supported by chrome)
- ...some others like ui drafts... (https://github.com/trezor)
The repositories which you will need to modify depends on what kind of coins you will be adding. If it is some bitcoin / ethereum like coin then you will have less work to do, if it is something like Cardano you will have to touch more repos.
For adding Cardano you will have to modify:
- trezor-crypto - for adding custom crypto functions
- trezor-core - for adding UI and putting code from trezor-crypto together
- trezor-common - for adding "api interface" in form of protobuf messages
- python-trezor - for making your calls in trezor-core available via this cli tool and also for writing "integration tests"
- connect - something like python-trezor, just for web js interface
Fork and then clone all repositories which you need. Fork is kind of needed if you want to make PR back to the Trezor`s repository.
If you already have cloned repository - fetch and sync the newest changes from official repo (do it for all needed repositories)
- check if you have already set up upstream with
git remote -v
if there is "upstream" url for official repo, you are good to go otherwise run this command:git remote add upstream https://github.com/trezor/trezor-core.git
(https://help.github.com/articles/configuring-a-remote-for-a-fork/) - fetch the changes
git fetch upstream
,git checkout master
,git merge upstream/master
- now you should be good to go (https://help.github.com/articles/syncing-a-fork/)
- in
trezor-core
create branch from mastergit checkout master
,git checkout -b cardano-dev
- now you do the same in other repositories, but pay attention here because not always will
trezor-core
use submodules pointing to the "master" commits in other repos. you can verify it invendor
folder https://github.com/trezor/trezor-core/tree/master/vendor
In trezor core you will have to change url for submodules so it will point to your repositories where you will be making changes.
- edit
.gitmodules
file - run
git submodule sync
- run
make vendor
- go to folder
vendor/trezor-common
(or other submodule) and check that it points to the forks repo with command
git remote -v` - checkout to the fork`s development branch
url: https://github.com/trezor/trezor-crypto
Append your code to the file where it should be. If the code is custom for only the one coin it should be under #if USE_CARDANO
, if you are making new coin
do not forget to include that switch into Makefile
When you are done with implementation, write tests into tests
folder , ideally with some official test vectors.
You can build crypto with make
command run it with cd tests && ./test_check
if you encounter some errors during compilation,
just follow the instructions there - usualy you will be missing some packages so install them
url: https://github.com/trezor/trezor-core
For building and running emulator and also building firmware follow: https://github.com/trezor/trezor-core/blob/master/docs/build.md
For making your code in trezor-crypto available to the trezor-core you have to create wrappers inside embed/extmod/modtrezorcrypto
and find coresponding file.
When you do that you will be able to call your function in python.
The code for your coins UI is located in
src/apps/YOUR_COIN` and you should find there these files:
-
init.py - it maps the
trezor-common
messages to your functions, so if you will add new call to trezor you have to map it here - YOUR_FILES.py which should contains calls for trezor api interface. Your function which you mapped in the
__init__.py
will receive two arguments -context
andmessage
context is trezor application context - for UI and message is parsed protobuf message from trezor-common and also your mapped calls should return protobuf message object
When you defined new api call you have to create trezor-common
protobuf messages - see below - and when you do (commit and sync submodule) then you need to run
tools/build_protobuf
which will autogenerate python classes for you protobuf messages
Test are located in tests
folder and each app has own "unit" tests - you will need them when you want your PR to be accepted. In the same folder you will find run_test.sh
command for running the tests
- do not forget to run trezord as
trezord -e 21324
, if you installed it from package it will probably be running as service so stop it first withsudo service trezord stop
- if you want to upload your firmware to your real device the
make upload
command will only works when the device is in special bootloader? mode - you will enter it when you will be "rubbing" the display and in the same time you will connect it to pc - if you modify only some python files (other then init) you do not need to closed / open emulator as it loads the files dynamically you have
to recompile code with
make build_unix
only when you modify some c code.. - if you get segmentation fault - ./emu.sh -d it will run gdb
- if you get KeyError with some importing module name try run
make style
and look for some invalid syntax error
url: https://github.com/trezor/trezor-common
This repo contains protobuf messages used for communication
There are two files which you need to modify when adding new messages and both are located in protob
folder:
- messages-YOUR_COIN.proto - it contains definition of messages and fields for that messages
- messages.proto - it is mapping for your messages - you have to assign message number to each you message and also specify if it is input or output message
url: https://github.com/trezor/python-trezor
Follow the instructions on the readme.md, but basically its:
pip3 install --upgrade setuptools
pip3 install trezor
git submodule init
git submodule update
sudo apt-get install protobuf-compiler
python3 setup.py prebuild
if you do not have pip3 you can install it with sudo apt-get install python3-pip
or similar command on your system
url: https://github.com/trezor/connect
In order to add your calls from trezor-core to the connect you will have to add:
- types - in folder
src/js/types
- core code - in folder
src/js/core/methods
and add reference tosrc/js/core/methods/index.js
- documentation - in folder
docs/methods/
for development use yarn dev
and in your app specify window.__TREZOR_CONNECT_SRC = 'https://localhost:8088/';
and also inline it:
<script src="https://localhost:8088/5/trezor-connect.js"></script>
- (not sure about that 5 in the middle) after that you should have access to var TrezorConnect = window.TrezorConnect;
Also make sure that you will browse to the https://localhost:8088/
manually and accept unsafe certificate as it is self signed certificate...
core - test/run_test.sh
crypto - make tests, tests/test_check
python-trezor - pytest-3
- make sure that your code works and that it have tests and test are passing
- make sure that you runned
make style
command which will check styling issues and you fixed them - be nice to the Trezor people