github.com/mprishchepo/go-ethereum@v1.9.7-0.20191031044858-21506be82b68/accounts/usbwallet/trezor/trezor.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 // This file contains the implementation for interacting with the Trezor hardware 18 // wallets. The wire protocol spec can be found on the SatoshiLabs website: 19 // https://wiki.trezor.io/Developers_guide-Message_Workflows 20 21 // !!! STAHP !!! 22 // 23 // Before you touch the protocol files, you need to be aware of a breaking change 24 // that occurred between firmware versions 1.7.3->1.8.0 (Model One) and 2.0.10-> 25 // 2.1.0 (Model T). The Ethereum address representation was changed from the 20 26 // byte binary blob to a 42 byte hex string. The upstream protocol buffer files 27 // only support the new format, so blindly pulling in a new spec will break old 28 // devices! 29 // 30 // The Trezor devs had the foresight to add the string version as a new message 31 // code instead of replacing the binary one. This means that the proto file can 32 // actually define both the old and the new versions as optional. Please ensure 33 // that you add back the old addresses everywhere (to avoid name clash. use the 34 // addressBin and addressHex names). 35 // 36 // If in doubt, reach out to @karalabe. 37 38 // To regenerate the protocol files in this package: 39 // - Download the latest protoc https://github.com/protocolbuffers/protobuf/releases 40 // - Build with the usual `./configure && make` and ensure it's on your $PATH 41 // - Delete all the .proto and .pb.go files, pull in fresh ones from Trezor 42 // - Grab the latest Go plugin `go get -u github.com/golang/protobuf/protoc-gen-go` 43 // - Vendor in the latest Go plugin `govendor fetch github.com/golang/protobuf/...` 44 45 //go:generate protoc -I/usr/local/include:. --go_out=import_path=trezor:. messages.proto messages-common.proto messages-management.proto messages-ethereum.proto 46 47 // Package trezor contains the wire protocol. 48 package trezor 49 50 import ( 51 "reflect" 52 53 "github.com/golang/protobuf/proto" 54 ) 55 56 // Type returns the protocol buffer type number of a specific message. If the 57 // message is nil, this method panics! 58 func Type(msg proto.Message) uint16 { 59 return uint16(MessageType_value["MessageType_"+reflect.TypeOf(msg).Elem().Name()]) 60 } 61 62 // Name returns the friendly message type name of a specific protocol buffer 63 // type number. 64 func Name(kind uint16) string { 65 name := MessageType_name[int32(kind)] 66 if len(name) < 12 { 67 return name 68 } 69 return name[12:] 70 }