Documentation ¶
Index ¶
- Constants
- type BipPath
- type ExtendedPublicKey
- type HidDevice
- type HidDeviceInfo
- type IHidDevice
- type Ledger
- func (device *Ledger) Close()
- func (device *Ledger) GetAddress(path BipPath) ([]byte, error)
- func (device *Ledger) GetExtendedPublicKey(path BipPath) (*ExtendedPublicKey, error)
- func (device *Ledger) GetHidInfo() *HidDeviceInfo
- func (device *Ledger) GetVersion() (*Version, error)
- func (device *Ledger) Open() error
- func (device *Ledger) ShowAddress(path BipPath) error
- func (device *Ledger) SignTx(path BipPath, tx []byte) ([]byte, error)
- type Version
Constants ¶
const ( // LedgerUSBVendorID allows identifying USB devices made by Ledger. LedgerUSBVendorID = 0x2c97 // ReadBuffMaxSize is the maximal number of bytes in the read buffer. ReadBuffMaxSize = 2048 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BipPath ¶
type BipPath []uint32
BipPath type
func StringToPath ¶
StringToPath Parse string to BIP32 path
type ExtendedPublicKey ¶
ExtendedPublicKey struct
type HidDevice ¶
type HidDevice struct { Info HidDeviceInfo // contains filtered or unexported fields }
HidDevice Wrapper for HIDAPI library
func (*HidDevice) Close ¶
func (device *HidDevice) Close()
Close Close communication with Ledger device.
example devices := ledger.GetDevices(0)
if devices != nil && len(devices) > 0 { device := devices[0] if err := device.Open(); err == nil { ... device.Close() } else { fmt.Printf("Open device ERROR: %v\n", err) } }
func (*HidDevice) Exchange ¶
Exchange Exchange with the device using APDU protocol. param apdu return {[]byte} apdu response return {error} Error value.
func (*HidDevice) GetInfo ¶
func (device *HidDevice) GetInfo() *HidDeviceInfo
GetInfo Get HID device info
func (*HidDevice) Open ¶
Open Open Ledger device for communication.
return {error} Error value.
example devices := ledger.GetDevices(0)
if devices != nil && len(devices) > 0 { device := devices[0] if err := device.Open(); err == nil { ... device.Close() } else { fmt.Printf("Open device ERROR: %v\n", err) } }
type HidDeviceInfo ¶
type HidDeviceInfo struct { // Platform-specific device path Path string // Device Vendor VendorID uint16 // Device Product ID ProductID uint16 // Device Release Number in binary-coded decimal, // also known as Device Version Number ReleaseNumber uint16 // Usage Page for this Device/Interface // (Windows/Mac/hidraw only) UsagePage uint16 // Usage for this Device/Interface // (Windows/Mac/hidraw only) Usage uint16 // The USB interface which this logical device // represents. // * Valid on both Linux implementations in all cases. // * Valid on the Windows implementation only if the device // contains more than one interface. // * Valid on the Mac implementation if and only if the device // is a USB HID device. InterfaceNumber int }
HidDeviceInfo hidapi info structure
type IHidDevice ¶
type IHidDevice interface { Open() error Close() Exchange(apdu []byte) ([]byte, error) GetInfo() *HidDeviceInfo }
IHidDevice HID Lenger device interface
type Ledger ¶
type Ledger struct {
// contains filtered or unexported fields
}
Ledger struct
func GetDevices ¶
GetDevices Enumerate Ledger devices.
param {int} productId USB Product ID filter, 0 - all. return {[]*HidDevice} Discovered Ledger devices.
example devices := ledger.GetDevices(0)
if devices != nil && len(devices) > 0 { device := devices[0] if err := device.Open(); err == nil { ... device.Close() } else { fmt.Printf("Open device ERROR: %v\n", err) } }
func (*Ledger) GetAddress ¶
GetAddress Gets an address from the specified BIP 32 path.
param {BipPath} path The BIP 32 path indexes. Path must begin with `44'/540'/0'/0/i` return {[]byte} The address for the given path. return {error} Error value.
example address, err := device.GetAddress(ledger.StringToPath("44'/540'/0'/0/0'"))
if err != nil { fmt.Printf("get address ERROR: %v\n", err) } else { fmt.Printf("address: %+v\n", address) }
func (*Ledger) GetExtendedPublicKey ¶
func (device *Ledger) GetExtendedPublicKey(path BipPath) (*ExtendedPublicKey, error)
GetExtendedPublicKey Get a public key from the specified BIP 32 path.
param {BipPath} path The BIP 32 path indexes. Path must begin with `44'/540'/n'`, and shuld be 5 indexes long. return {ExtendedPublicKey} The public key with chaincode for the given path. return {error} Error value.
example publicKey, err := device.GetExtendedPublicKey(ledger.StringToPath("44'/540'/0'/0/0'"))
if err != nil { fmt.Printf("get public key ERROR: %v\n", err) } else { fmt.Printf("public key: %+v\n", publicKey) }
func (*Ledger) GetHidInfo ¶
func (device *Ledger) GetHidInfo() *HidDeviceInfo
GetHidInfo Get HID device info
func (*Ledger) GetVersion ¶
GetVersion Returns an object containing the app version.
returns {Version} Result object containing the application version number. return {error} Error value.
example version, err := device.GetVersion()
if err != nil { fmt.Printf("get version ERROR: %v\n", err) } else { fmt.Printf("version: %+v\n", version) }
func (*Ledger) ShowAddress ¶
ShowAddress Show an address from the specified BIP 32 path for verify.
param {BipPath} indexes The path indexes. Path must begin with `44'/540'/0'/0/i` return {error} Error value.
example err := device.ShowAddress(ledger.StringToPath("44'/540'/0'/0/1'"))
if err != nil { fmt.Printf("show address ERROR: %v\n", err) } else { fmt.Printf("show address: OK\n") }
func (*Ledger) SignTx ¶
SignTx Sign a transaction by the specified BIP 32 path account address.
param {BipPath} path The BIP 32 path indexes. Path must begin with `44'/540'/0'/0/i` param {[]byte} tx The XDR encoded transaction data, include transaction type return {[]byte} Signed transaction. return {error} Error value
example tx := make([]byte, 0) var bin []byte bin, _ = hex.DecodeString("0000000000000000000000000000000000000000000000000000000000000000") // network id tx = append(tx, bin...) tx = append(tx, 0) // coin transaction with ed tx = append(tx, uint64_to_buf(1)...) // nonce bin, _ = hex.DecodeString("0000000000000000000000000000000000000000") // recepient tx = append(tx, bin...) tx = append(tx, uint64_to_buf(1000000)...) // gas limit tx = append(tx, uint64_to_buf(1000)...) // gas price tx = append(tx, uint64_to_buf(1000000000000)...) // amount tx = append(tx, publicKey.PublicKey...)
response, err := device.SignTx(ledger.StringToPath("44'/540'/0'/0/0'"), tx)
if err != nil { fmt.Printf("Verify coin tx ERROR: %v\n", err) } else { hash := sha512.Sum512(tx) fmt.Printf("Verify coin tx: %v\n", ed25519.Verify(publicKey.PublicKey, hash[:], response[1:65])) }