Documentation
¶
Overview ¶
Package ledger provides hardware wallet integration for TRON signing.
Index ¶
- Variables
- func GetAddress() string
- func SignTx(tx []byte) ([]byte, error)
- type APDU
- type Device
- type ErrCode
- type MockDevice
- type NanoS
- func (n *NanoS) Close() error
- func (n *NanoS) Exchange(cmd byte, p1, p2 byte, data []byte) (resp []byte, err error)
- func (n *NanoS) GetAddress() (addr string, err error)
- func (n *NanoS) GetVersion() (version string, err error)
- func (n *NanoS) SignTransaction(_ context.Context, tx []byte) ([]byte, error)
- func (n *NanoS) SignTxn(txn []byte) (sig [signatureSize]byte, err error)
Constants ¶
This section is empty.
Variables ¶
var DEBUG bool
DEBUG enables verbose HID frame logging when true.
Functions ¶
func GetAddress ¶
func GetAddress() string
GetAddress returns the TRON address from the connected Ledger device. Deprecated: Use OpenDevice() and call GetAddress() on the Device instead.
Types ¶
type Device ¶ added in v0.26.0
type Device interface {
// GetAddress returns the TRON address from the device.
GetAddress() (string, error)
// SignTransaction signs a raw transaction and returns the signature.
SignTransaction(ctx context.Context, tx []byte) ([]byte, error)
// Close releases the device connection.
Close() error
}
Device abstracts a hardware wallet for testability and multi-device support.
func OpenDevice ¶ added in v0.26.0
OpenDevice opens a Ledger Nano S and returns it as a Device. This is the recommended entry point for callers.
type MockDevice ¶ added in v0.26.0
type MockDevice struct {
// GetAddressFn is called by GetAddress. When nil, the stored Address
// and Err fields are returned instead.
GetAddressFn func() (string, error)
// SignTransactionFn is called by SignTransaction. When nil, the stored
// Signature and Err fields are returned instead.
SignTransactionFn func(ctx context.Context, tx []byte) ([]byte, error)
// CloseFn is called by Close. When nil, nil is returned.
CloseFn func() error
// Address is returned by GetAddress when GetAddressFn is nil.
Address string
// Signature is returned by SignTransaction when SignTransactionFn is nil.
Signature []byte
// Err is returned by both GetAddress and SignTransaction when their
// respective function fields are nil.
Err error
}
MockDevice is a test double that implements the Device interface. Callers can set the function fields to control return values; unset fields return zero values.
func (*MockDevice) Close ¶ added in v0.26.0
func (m *MockDevice) Close() error
Close calls CloseFn if set, otherwise returns nil.
func (*MockDevice) GetAddress ¶ added in v0.26.0
func (m *MockDevice) GetAddress() (string, error)
GetAddress returns the configured address or calls GetAddressFn.
func (*MockDevice) SignTransaction ¶ added in v0.26.0
SignTransaction returns the configured signature or calls SignTransactionFn.
type NanoS ¶
type NanoS struct {
// contains filtered or unexported fields
}
NanoS represents a connection to a Ledger Nano S hardware wallet.
func (*NanoS) GetAddress ¶
GetAddress returns the TRON address from the Ledger device.
func (*NanoS) GetVersion ¶
GetVersion returns the TRON app version running on the Ledger device.
func (*NanoS) SignTransaction ¶ added in v0.26.0
SignTransaction signs the given raw transaction bytes using the Ledger device. It returns the 65-byte signature after verifying via ecrecover.