ledger

package module
v0.0.0-...-f7f2f05 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2017 License: Apache-2.0 Imports: 4 Imported by: 9

README

Go bindings for Ledger Nano

These are simple go bindings to communicate with custom Ledger Nano apps. This wraps the USB HID layer and handles the ledger specific communication.

CLI Usage

Send bytes to ledger (app 0x80, op 0x02, payload 0xf00d)

make vendor
make install
ledger 8002F00D

API Usage

import "github.com/ethanfrey/ledger"

func PingLedger(msg []byte) ([]byte, error) {
    device, err := ledger.FindLedger()
    if err != nil {
        return nil, err
    }
    return device.Exchange(msg, 0)
}

TODO

  • Actually use the timeout parameter
  • Build higher level constructs for other apps

Documentation

Index

Constants

View Source
const (
	VendorLedger = 0x2c97
	ProductNano  = 1
	Channel      = 0x0101
	PacketSize   = 64
)

Variables

This section is empty.

Functions

func UnwrapResponseAPDU

func UnwrapResponseAPDU(channel uint16, dev <-chan []byte, packetSize int, ble bool) ([]byte, error)

UnwrapResponseAPDU parses a response of 64 byte packets into the real data

func WrapCommandAPDU

func WrapCommandAPDU(channel uint16, command []byte, packetSize int, ble bool) []byte

WrapCommandAPDU turns the command into a sequence of 64 byte packets

Types

type Device

type Device interface {
	// Close closes the device and associated resources.
	Close()

	// Write writes an output report to device. The first byte must be the
	// report number to write, zero if the device does not use numbered reports.
	Write([]byte) error

	// ReadCh returns a channel that will be sent input reports from the device.
	// If the device uses numbered reports, the first byte will be the report
	// number.
	ReadCh() <-chan []byte

	// ReadError returns the read error, if any after the channel returned from
	// ReadCh has been closed.
	ReadError() error
}

A Device provides access to a HID device.

type Ledger

type Ledger struct {
	// contains filtered or unexported fields
}

func FindLedger

func FindLedger() (*Ledger, error)

func NewLedger

func NewLedger(dev Device) *Ledger

func (*Ledger) Exchange

func (l *Ledger) Exchange(command []byte, timeout int) ([]byte, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL