ledger_goclient

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2018 License: Apache-2.0 Imports: 6 Imported by: 5

README

ledger-goclient

CircleCI Build status Build Status

This project is work in progress. Some aspects are subject to change.

Get source

Apart from cloning, be sure you install dep dependency management tool https://github.com/golang/dep

Setup

Update dependencies using the following:

dep ensure 

Building

go build ledger.go

Running

./ledger

Make sure that the app is launched in the Ledger before starting this command and Ledger is connected to the USB port. This command line tool will try to send a simple json transaction and will return a signature when user agrees to sign.

Documentation

Index

Constants

View Source
const (
	VendorLedger    = 0x2c97
	UsagePageLedger = 0xffa0
	//ProductNano     = 1
	Channel    = 0x0101
	PacketSize = 64
	CLA        = 0x55

	INSGetVersion         = 0
	INSPublicKeySECP256K1 = 1
	INSPublicKeyED25519   = 2

	// Sign sdk.Msg (transaction part of the message)
	INSSignSECP256K1 = 3
	INSSignED25519   = 4

	// Sign sdk.StdSignMsg (full message)
	INSSignSECP256K1_StdSignMsg = 5
	INSSignED25519_StdSignMsg   = 6

	INSHash                   = 100
	INSPublicKeySECP256K1Test = 101
	INSPublicKeyED25519Test   = 102
	INSSignSECP256K1Test      = 103
	INSSignED25519Test        = 104

	MessageChunkSize = 250
)

Variables

This section is empty.

Functions

func DeserializePacket

func DeserializePacket(
	channel uint16,
	buffer []byte,
	sequenceIdx uint16,
	ble bool) (result []byte, totalResponseLength uint16, err error)

func ListDevices

func ListDevices()

func SerializePacket

func SerializePacket(
	channel uint16,
	command []byte,
	packetSize int,
	sequenceIdx uint16,
	ble bool) (result []byte, offset int, err error)

func UnwrapResponseAPDU

func UnwrapResponseAPDU(channel uint16, pipe <-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) (result []byte, err error)

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 {
	Logging bool
	// contains filtered or unexported fields
}

func FindLedger

func FindLedger() (*Ledger, error)

func NewLedger

func NewLedger(dev Device) *Ledger

func (*Ledger) Exchange

func (ledger *Ledger) Exchange(command []byte) ([]byte, error)

func (*Ledger) GetPublicKeyED25519

func (ledger *Ledger) GetPublicKeyED25519(bip32_path []uint32) ([]byte, error)

func (*Ledger) GetPublicKeySECP256K1

func (ledger *Ledger) GetPublicKeySECP256K1(bip32_path []uint32) ([]byte, error)

func (*Ledger) GetVersion

func (ledger *Ledger) GetVersion() (*VersionInfo, error)

func (*Ledger) Hash

func (ledger *Ledger) Hash(transaction []byte) ([]byte, error)

func (*Ledger) SignED25519

func (ledger *Ledger) SignED25519(bip32_path []uint32, transaction []byte) ([]byte, error)

func (*Ledger) SignED25519_StdSignMsg

func (ledger *Ledger) SignED25519_StdSignMsg(bip32_path []uint32, transaction []byte) ([]byte, error)

func (*Ledger) SignSECP256K1

func (ledger *Ledger) SignSECP256K1(bip32_path []uint32, transaction []byte) ([]byte, error)

func (*Ledger) SignSECP256K1_StdSignMsg

func (ledger *Ledger) SignSECP256K1_StdSignMsg(bip32_path []uint32, transaction []byte) ([]byte, error)

func (*Ledger) TestGetPublicKeyED25519

func (ledger *Ledger) TestGetPublicKeyED25519() ([]byte, error)

func (*Ledger) TestGetPublicKeySECP256K1

func (ledger *Ledger) TestGetPublicKeySECP256K1() ([]byte, error)

func (*Ledger) TestSignED25519

func (ledger *Ledger) TestSignED25519(transaction []byte) ([]byte, error)

func (*Ledger) TestSignSECP256K1

func (ledger *Ledger) TestSignSECP256K1(transaction []byte) ([]byte, error)

type VersionInfo

type VersionInfo struct {
	AppId uint8
	Major uint8
	Minor uint8
	Patch uint8
}

Jump to

Keyboard shortcuts

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