Skip to content

Commit

Permalink
Merge pull request #27 from felipemadero/apdu-wrapper-for-zemu
Browse files Browse the repository at this point in the history
add apdu wrapper to zemu
  • Loading branch information
ftheirs authored Jun 30, 2023
2 parents 4e57dab + e405dcf commit 05d2788
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions ledger_zemu.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build ledger_zemu
//go:build ledger_zemu
// +build ledger_zemu

/*******************************************************************************
* (c) 2018 - 2022 ZondaX AG
Expand All @@ -20,24 +21,26 @@ package ledger_go

import (
"context"
"errors"
"fmt"

"google.golang.org/grpc"
)

type LedgerAdminZemu struct {
grpcURL string
grpcPort string
grpcURL string
grpcPort string
}

type LedgerDeviceZemu struct {
connection *grpc.ClientConn
client ZemuCommandClient
connection *grpc.ClientConn
client ZemuCommandClient
}

func NewLedgerAdmin() *LedgerAdminZemu {
return &LedgerAdminZemu{
//TODO get this from flag value or from Zemu response
grpcURL: "localhost",
grpcURL: "localhost",
grpcPort: "3002",
}
}
Expand All @@ -54,7 +57,7 @@ func (admin *LedgerAdminZemu) CountDevices() int {
}

func (admin *LedgerAdminZemu) Connect(deviceIndex int) (*LedgerDeviceZemu, error) {
serverAddr := admin.grpcURL + ":" + admin.grpcPort
serverAddr := admin.grpcURL + ":" + admin.grpcPort
//TODO: check Dial flags
conn, err := grpc.Dial(serverAddr, grpc.WithInsecure())

Expand Down Expand Up @@ -96,7 +99,7 @@ func (ledger *LedgerDeviceZemu) Exchange(command []byte) ([]byte, error) {
sw := codec.Uint16(response[swOffset:])

if sw != 0x9000 {
return response[:swOffset], fmt.Errorf("return code with error")
return response[:swOffset], errors.New(ErrorMessage(sw))
}

return response[:swOffset], nil
Expand Down

0 comments on commit 05d2788

Please sign in to comment.