fjrojasgarcia / trezord-go

:smiling_imp: TREZOR Communication Daemon (written in Go)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

trezord-go

Build Status gitter

TREZOR Communication Daemon aka TREZOR Bridge (written in Go)

Only compatible with Chrome (version 53 or later) and Firefox (version 55 or later).

status: spec Chrome Firefox Edge

Install and run from source

go get github.com/trezor/trezord-go
go build github.com/trezor/trezord-go
./trezord-go -h

Guide to compiling packages

Prerequisites:

  • go get github.com/karalabe/xgo
  • docker pull karalabe/xgo-latest
  • make sure xgo and docker are in $PATH
  • cd release && make all; the installers are in installers

Quick guide to cross-compiling

Prerequisites:

  • go get github.com/karalabe/xgo
  • docker pull karalabe/xgo-latest

Compiling for officially supported platforms:

  • $GOPATH/bin/xgo -targets=windows/amd64,windows/386,darwin/amd64,linux/amd64,linux/386 .

Emulator support

Trezord supports emulators for both Trezor versions. However, you need to enable it manually; it is disabled by default. After enabling, services that work with emulator can work with all services that support trezord.

To enable emulator, run trezord with a parameter -e followed by port, for every emulator with an enabled port

./trezord -e 21324

If you want to run this automatically on linux, do

sudo systemctl edit --full trezord.service

and edit the service file (and maybe restart the trezord service). On mac, you will need to edit

/Library/LaunchAgents/com.bitcointrezor.trezorBridge.trezord.plist

and edit the last <string> in the plist. (And also probably restart the pc.)

You can disable all USB in order to run on some virtuaized environments, for example Travis

./trezord -e 21324 -u=false

API documentation

trezord-go starts a HTTP server on http://localhost:21325. AJAX calls are only enabled from trezor.io subdomains.

Server supports following API calls:

url
method
parameters result type description
/
POST
{version: string} Returns current version of bridge
/enumerate
POST
Array<{path: string,
session: string | null}>
Lists devices.
path uniquely defines device between more connected devices. It might or might not be unique over time; on some platform it changes, on others given USB port always returns the same path.
If session is null, nobody else is using the device; if it's string, it identifies who is using it.
/listen
POST
request body: previous, as JSON like enumerate Listen to changes and returns either on change or after 30 second timeout. Compares change from previous that is sent as a parameter. "Change" is both connecting/disconnecting and session change.
/acquire/PATH/PREVIOUS
POST
PATH: path of device
PREVIOUS: previous session (or string "null")
{session: string} Acquires the device at PATH. By "acquiring" the device, you are claiming the device for yourself.
Before acquiring, checks that the current session is PREVIOUS.
If two applications call acquire on a newly connected device at the same time, only one of them succeed.
/release/SESSION
POST
SESSION: session to release {} Releases the device with the given session.
By "releasing" the device, you claim that you don't want to use the device anymore.
/call/SESSION
POST
SESSION: session to call

request body: hexadecimal string
hexadecimal string Both input and output are hexadecimal, encoded in following way:
first 2 bytes (4 characters in the hexadecimal) is the message type
next 4 bytes (8 in hex) is length of the data
the rest is the actual encoded protobuf data.
Protobuf messages are defined in this protobuf file and the app, calling trezord, should encode/decode it itself.
/post/SESSION
POST
SESSION: session to call

request body: hexadecimal string
0 Similar to call, just doesn't read response back. Usable mainly for debug link, currently working only with emulator.

Copyright

  • (C) 2018 Karel Bilek, Jan Pochyla
  • CORS Copyright (c) 2013 The Gorilla Handlers Authors, BSD license
  • Licensed under LGPLv3

About

:smiling_imp: TREZOR Communication Daemon (written in Go)

License:GNU Lesser General Public License v3.0


Languages

Language:C++ 49.8%Language:Go 23.0%Language:Perl 20.5%Language:Shell 3.1%Language:C 2.2%Language:Makefile 1.4%