Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error messages in case of APDU_CODE_BAD_KEY_HANDLE #26

Merged
merged 2 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[[constraint]]
name = "github.com/zondax/ledger-go"
version = "v0.8.0"
version = "v0.9.0"

[prune]
go-tests = true
Expand Down
13 changes: 13 additions & 0 deletions user_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ func (ledger *LedgerCosmos) sign(instruction byte, bip32Path []uint32, transacti

response, err := ledger.api.Exchange(message)
if err != nil {
if err.Error() == "[APDU_CODE_BAD_KEY_HANDLE] The parameters in the data field are incorrect" {
// In this special case, we can extract additional info
errorMsg := string(response)
switch errorMsg {
case "ERROR: JSMN_ERROR_NOMEM":
return nil, fmt.Errorf("Not enough tokens were provided");
case "PARSER ERROR: JSMN_ERROR_INVAL":
return nil, fmt.Errorf("Unexpected character in JSON string");
case "PARSER ERROR: JSMN_ERROR_PART":
return nil, fmt.Errorf("The JSON string is not a complete.");
}
return nil, fmt.Errorf(errorMsg)
}
return nil, err
}

Expand Down
19 changes: 19 additions & 0 deletions user_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,22 @@ func Test_UserSign(t *testing.T) {
return
}
}

func Test_UserSign_Fails(t *testing.T) {
userApp, err := FindLedgerCosmosUserApp()
if err != nil {
t.Fatalf(err.Error())
}
defer userApp.Close()

userApp.api.Logging = true

path := []uint32{44, 118, 0, 0, 5}

message := getDummyTx()
garbage := []byte{65}
message = append(garbage, message...)

_, err = userApp.SignSECP256K1(path, message)
assert.EqualError(t, err, "Unexpected character in JSON string")
}