diff --git a/Gopkg.lock b/Gopkg.lock index bb50105..6c32e3a 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -122,12 +122,12 @@ version = "v0.9.0" [[projects]] - digest = "1:f8e4c0b959174a1fa5946b12f1f2ac7ea5651bef20a9e4a8dac55dbffcaa6cd6" + digest = "1:c450d0b3b9217e3926714751c2034a9171e2d769c254ef3c74e5795ad74e1b04" name = "github.com/zondax/ledger-go" packages = ["."] pruneopts = "UT" - revision = "69c15f1333a9b6866e5f66096561c7d138894bc5" - version = "v0.8.0" + revision = "94455688b6fac63ee05a4a61f44d5a4095317f74" + version = "v0.9.0" [[projects]] digest = "1:578bbe25849cdc707dfa01cd316556198df9df317fc1608fd2bbbf8967af9785" diff --git a/Gopkg.toml b/Gopkg.toml index 284ed32..1bf0f4e 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -1,6 +1,6 @@ [[constraint]] name = "github.com/zondax/ledger-go" - version = "v0.8.0" + version = "v0.9.0" [prune] go-tests = true diff --git a/user_app.go b/user_app.go index 8174409..a51ac8c 100644 --- a/user_app.go +++ b/user_app.go @@ -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 } diff --git a/user_app_test.go b/user_app_test.go index b9460e0..62b32f5 100644 --- a/user_app_test.go +++ b/user_app_test.go @@ -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") +}