Documentation
¶
Index ¶
- Constants
- Variables
- func BuildChunkedAPDU(cla, ins, p1, p2 byte, data []byte) []byte
- func DeserializePacket(channel uint16, packet []byte, sequenceIdx uint16) ([]byte, uint16, bool, error)
- func ErrorMessage(errorCode uint16) string
- func PrepareChunks(bip44PathBytes []byte, transaction []byte) [][]byte
- func ProcessChunks(device LedgerDevice, chunks [][]byte, cla, instruction, p2 byte, ...) ([]byte, error)
- func ProcessChunksSimple(device LedgerDevice, chunks [][]byte, cla, instruction, p2 byte) ([]byte, error)
- func RegisterZemuCommandServer(s *grpc.Server, srv ZemuCommandServer)
- func SerializePacket(channel uint16, command []byte, packetSize int, sequenceIdx uint16) ([]byte, int, error)
- func UnwrapResponseAPDU(channel uint16, pipe <-chan []byte, packetSize int) ([]byte, error)
- func WrapCommandAPDU(channel uint16, command []byte, packetSize int) ([]byte, error)
- type ErrorHandler
- type ExchangeReply
- type ExchangeRequest
- type LedgerAdmin
- type LedgerAdminHID
- type LedgerDevice
- type LedgerDeviceHID
- type UnimplementedZemuCommandServer
- type ZemuCommandClient
- type ZemuCommandServer
Constants ¶
const ( MinPacketSize = 3 TagValue = 0x05 )
const ( ErrMsgPacketSize = "packet size must be at least 3" ErrMsgInvalidChannel = "invalid channel" ErrMsgInvalidTag = "invalid tag" ErrMsgWrongSequenceIdx = "wrong sequenceIdx" )
const ( // DefaultChunkSize is the standard chunk size used across all Ledger apps // This replaces userMessageChunkSize from individual apps DefaultChunkSize = 48 // Chunk payload descriptors ChunkInit = 0 ChunkAdd = 1 ChunkLast = 2 )
const ( VendorLedger = 0x2c97 UsagePageLedgerNanoS = 0xffa0 Channel = 0x0101 PacketSize = 64 )
Variables ¶
var ( ErrPacketSize = errors.New(ErrMsgPacketSize) ErrInvalidChannel = errors.New(ErrMsgInvalidChannel) ErrInvalidTag = errors.New(ErrMsgInvalidTag) ErrWrongSequenceIdx = errors.New(ErrMsgWrongSequenceIdx) )
var File_zemu_proto protoreflect.FileDescriptor
Functions ¶
func BuildChunkedAPDU ¶
BuildChunkedAPDU builds an APDU command for chunked data transmission cla is the APDU class byte ins is the APDU instruction byte p1 is the APDU P1 parameter (typically the chunk descriptor) p2 is the APDU P2 parameter data is the chunk data to send
func DeserializePacket ¶
func DeserializePacket( channel uint16, packet []byte, sequenceIdx uint16) ([]byte, uint16, bool, error)
DeserializePacket deserializes a packet into its original command.
func ErrorMessage ¶
ErrorMessage returns a human-readable error message for a given APDU error code.
func PrepareChunks ¶
PrepareChunks splits the transaction data into chunks for sending to the Ledger device This matches the exact implementation from ledger-filecoin-go and ledger-avalanche-go
func ProcessChunks ¶
func ProcessChunks(device LedgerDevice, chunks [][]byte, cla, instruction, p2 byte, errorHandler ErrorHandler) ([]byte, error)
ProcessChunks sends chunks to the Ledger device and collects the response This supports both Avalanche and Filecoin error handling patterns via the optional errorHandler
func ProcessChunksSimple ¶
func ProcessChunksSimple(device LedgerDevice, chunks [][]byte, cla, instruction, p2 byte) ([]byte, error)
ProcessChunksSimple sends chunks to the Ledger device with basic error handling This is a convenience function for apps that don't need custom error handling
func RegisterZemuCommandServer ¶
func RegisterZemuCommandServer(s *grpc.Server, srv ZemuCommandServer)
func SerializePacket ¶
func SerializePacket( channel uint16, command []byte, packetSize int, sequenceIdx uint16) ([]byte, int, error)
SerializePacket serializes a command into a packet for transmission.
func UnwrapResponseAPDU ¶
UnwrapResponseAPDU parses a response of 64 byte packets into the real data.
Types ¶
type ErrorHandler ¶
ErrorHandler is a function type for custom error handling in ProcessChunks
type ExchangeReply ¶
type ExchangeReply struct {
Reply []byte `protobuf:"bytes,1,opt,name=reply,proto3" json:"reply,omitempty"`
// contains filtered or unexported fields
}
func (*ExchangeReply) Descriptor
deprecated
func (*ExchangeReply) Descriptor() ([]byte, []int)
Deprecated: Use ExchangeReply.ProtoReflect.Descriptor instead.
func (*ExchangeReply) GetReply ¶
func (x *ExchangeReply) GetReply() []byte
func (*ExchangeReply) ProtoMessage ¶
func (*ExchangeReply) ProtoMessage()
func (*ExchangeReply) ProtoReflect ¶
func (x *ExchangeReply) ProtoReflect() protoreflect.Message
func (*ExchangeReply) Reset ¶
func (x *ExchangeReply) Reset()
func (*ExchangeReply) String ¶
func (x *ExchangeReply) String() string
type ExchangeRequest ¶
type ExchangeRequest struct {
Command []byte `protobuf:"bytes,1,opt,name=command,proto3" json:"command,omitempty"`
// contains filtered or unexported fields
}
func (*ExchangeRequest) Descriptor
deprecated
func (*ExchangeRequest) Descriptor() ([]byte, []int)
Deprecated: Use ExchangeRequest.ProtoReflect.Descriptor instead.
func (*ExchangeRequest) GetCommand ¶
func (x *ExchangeRequest) GetCommand() []byte
func (*ExchangeRequest) ProtoMessage ¶
func (*ExchangeRequest) ProtoMessage()
func (*ExchangeRequest) ProtoReflect ¶
func (x *ExchangeRequest) ProtoReflect() protoreflect.Message
func (*ExchangeRequest) Reset ¶
func (x *ExchangeRequest) Reset()
func (*ExchangeRequest) String ¶
func (x *ExchangeRequest) String() string
type LedgerAdmin ¶
type LedgerAdmin interface {
CountDevices() int
ListDevices() ([]string, error)
Connect(deviceIndex int) (LedgerDevice, error)
}
LedgerAdmin defines the interface for managing Ledger devices.
func NewLedgerAdmin ¶
func NewLedgerAdmin() LedgerAdmin
type LedgerAdminHID ¶
type LedgerAdminHID struct{}
func (*LedgerAdminHID) Connect ¶
func (admin *LedgerAdminHID) Connect(requiredIndex int) (LedgerDevice, error)
func (*LedgerAdminHID) CountDevices ¶
func (admin *LedgerAdminHID) CountDevices() int
func (*LedgerAdminHID) ListDevices ¶
func (admin *LedgerAdminHID) ListDevices() ([]string, error)
type LedgerDevice ¶
type LedgerDevice interface {
ExchangeNoCheck(command []byte) ([]byte, uint16, error)
Exchange(command []byte) ([]byte, error)
Close() error
}
LedgerDevice defines the interface for interacting with a Ledger device.
type LedgerDeviceHID ¶
type LedgerDeviceHID struct {
// contains filtered or unexported fields
}
func (*LedgerDeviceHID) Close ¶
func (ledger *LedgerDeviceHID) Close() error
func (*LedgerDeviceHID) Exchange ¶
func (ledger *LedgerDeviceHID) Exchange(command []byte) ([]byte, error)
func (*LedgerDeviceHID) ExchangeNoCheck ¶
func (ledger *LedgerDeviceHID) ExchangeNoCheck(command []byte) ([]byte, uint16, error)
func (*LedgerDeviceHID) Read ¶
func (ledger *LedgerDeviceHID) Read() <-chan []byte
type UnimplementedZemuCommandServer ¶
type UnimplementedZemuCommandServer struct {
}
UnimplementedZemuCommandServer can be embedded to have forward compatible implementations.
func (*UnimplementedZemuCommandServer) Exchange ¶
func (*UnimplementedZemuCommandServer) Exchange(context.Context, *ExchangeRequest) (*ExchangeReply, error)
type ZemuCommandClient ¶
type ZemuCommandClient interface {
Exchange(ctx context.Context, in *ExchangeRequest, opts ...grpc.CallOption) (*ExchangeReply, error)
}
ZemuCommandClient is the client API for ZemuCommand service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
func NewZemuCommandClient ¶
func NewZemuCommandClient(cc grpc.ClientConnInterface) ZemuCommandClient
type ZemuCommandServer ¶
type ZemuCommandServer interface {
Exchange(context.Context, *ExchangeRequest) (*ExchangeReply, error)
}
ZemuCommandServer is the server API for ZemuCommand service.