diff options
author | Guillaume Ballet <gballet@gmail.com> | 2019-05-16 20:37:36 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-06-03 21:08:03 +0800 |
commit | 4799b5abd411631920e0fcc907aba59a9fd09237 (patch) | |
tree | 9d8847ece5f923df7f99d57a8a9dd8c46553e17f /accounts/usbwallet | |
parent | 7a22da98b9f81d206eb65d1fa4f5e773d888bac3 (diff) | |
download | go-tangerine-4799b5abd411631920e0fcc907aba59a9fd09237.tar go-tangerine-4799b5abd411631920e0fcc907aba59a9fd09237.tar.gz go-tangerine-4799b5abd411631920e0fcc907aba59a9fd09237.tar.bz2 go-tangerine-4799b5abd411631920e0fcc907aba59a9fd09237.tar.lz go-tangerine-4799b5abd411631920e0fcc907aba59a9fd09237.tar.xz go-tangerine-4799b5abd411631920e0fcc907aba59a9fd09237.tar.zst go-tangerine-4799b5abd411631920e0fcc907aba59a9fd09237.zip |
accounts/usbwallet: support webusb for Trezor wallets
Diffstat (limited to 'accounts/usbwallet')
-rw-r--r-- | accounts/usbwallet/hub.go | 22 | ||||
-rw-r--r-- | accounts/usbwallet/trezor.go | 2 | ||||
-rw-r--r-- | accounts/usbwallet/wallet.go | 2 |
3 files changed, 22 insertions, 4 deletions
diff --git a/accounts/usbwallet/hub.go b/accounts/usbwallet/hub.go index fc711bb3e..35695dd1c 100644 --- a/accounts/usbwallet/hub.go +++ b/accounts/usbwallet/hub.go @@ -89,6 +89,12 @@ func NewTrezorHub() (*Hub, error) { return newHub(TrezorScheme, 0x534c, []uint16{0x0001 /* Trezor 1 */}, 0xff00, 0, newTrezorDriver) } +// NewWebUSBTrezorHub creates a new hardware wallet manager for Trezor devices with +// firmware version > 1.8.0 +func NewWebUSBTrezorHub() (*Hub, error) { + return newHub(TrezorScheme, 0x1209, []uint16{0x53c1 /* Trezor 1 WebUSB */}, 0, 0, newTrezorDriver) +} + // newHub creates a new hardware wallet manager for generic USB devices. func newHub(scheme string, vendorID uint16, productIDs []uint16, usageID uint16, endpointID int, makeDriver func(log.Logger) driver) (*Hub, error) { if !hid.Supported() { @@ -148,9 +154,19 @@ func (hub *Hub) refreshWallets() { return } } - for _, info := range hid.Enumerate(hub.vendorID, 0) { + infos, err := hid.Enumerate(hub.vendorID, 0) + if err != nil { + if runtime.GOOS == "linux" { + // See rationale before the enumeration why this is needed and only on Linux. + hub.commsLock.Unlock() + } + log.Error("error enumerating USB enumeration: ", "code", err) + return + } + for _, info := range infos { for _, id := range hub.productIDs { - if info.ProductID == id && (info.UsagePage == hub.usageID || info.Interface == hub.endpointID) { + _, pid, endpoint, _ /* FIXME usageID */ := info.IDs() + if pid == id && ( /* FIXME usageID == hub.usageID || */ endpoint == hub.endpointID) { devices = append(devices, info) break } @@ -169,7 +185,7 @@ func (hub *Hub) refreshWallets() { ) for _, device := range devices { - url := accounts.URL{Scheme: hub.scheme, Path: device.Path} + url := accounts.URL{Scheme: hub.scheme, Path: device.GetPath()} // Drop wallets in front of the next device or those that failed for some reason for len(hub.wallets) > 0 { diff --git a/accounts/usbwallet/trezor.go b/accounts/usbwallet/trezor.go index 31c2a7d8a..9453b52c3 100644 --- a/accounts/usbwallet/trezor.go +++ b/accounts/usbwallet/trezor.go @@ -36,6 +36,8 @@ import ( "github.com/golang/protobuf/proto" ) +var ErrInvalidDeviceType = errors.New("trezor: invalid device type") + // ErrTrezorPINNeeded is returned if opening the trezor requires a PIN code. In // this case, the calling application should display a pinpad and send back the // encoded passphrase. diff --git a/accounts/usbwallet/wallet.go b/accounts/usbwallet/wallet.go index 7ff9c5372..df38f953d 100644 --- a/accounts/usbwallet/wallet.go +++ b/accounts/usbwallet/wallet.go @@ -78,7 +78,7 @@ type wallet struct { url *accounts.URL // Textual URL uniquely identifying this wallet info hid.DeviceInfo // Known USB device infos about the wallet - device *hid.Device // USB device advertising itself as a hardware wallet + device hid.Device // USB device advertising itself as a hardware wallet accounts []accounts.Account // List of derive accounts pinned on the hardware wallet paths map[common.Address]accounts.DerivationPath // Known derivation paths for signing operations |