question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error `Unexpected end of data` when parsing a JWT

See original GitHub issue

Bug severity 5

Describe the bug Not able to parse a simple JWT.

To Reproduce Steps to reproduce the behaviour:

  1. Try to Handle a Message that is a self-signed JWT:
    const message: IMessage = await agent.handleMessage({
      raw: verifiableCredential.proof.jwt,
      save: false,
    });

eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QifQ.eyJ2YyI6eyJjcmVkZW50aWFsU3ViamVjdCI6eyJpZGVudGl0eUFsaWFzIjoibG9jYWxob3N0OmJjZjcxMjA0LWQzMDEtNGU3OC1iNWQ3LTViNmMyMWFjNmUwMiJ9LCJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIl19LCJuYmYiOjE2MjEzNDE3OTgsImlzcyI6ImRpZDp3ZWI6bG9jYWxob3N0OmJjZjcxMjA0LWQzMDEtNGU3OC1iNWQ3LTViNmMyMWFjNmUwMiJ9.3045022100ba25a2e0661ea63a659e19e54b36cd32f307e65fe7a44beaddfc35ea07a602670220325075c71d34d52fbc1f4abc53c655cae3748e2300b3bb990db323cfb18d1aee

Observed behaviour Getting an exception: 'Unsupported message type'

However, when debegging the following error is the actual one: 'Unexpected end of data'

stack:'SyntaxError: Unexpected end of data
    at decode (/home/muhammad/Repositories/interop-microservice/node_modules/multibase/src/rfc4648.js:52:11)
    at Object.decode (/home/muhammad/Repositories/interop-microservice/node_modules/multibase/src/rfc4648.js:118:14)
    at Base.decode (/home/muhammad/Repositories/interop-microservice/node_modules/multibase/src/base.js:46:23)
    at Object.u8a [as fromString] (/home/muhammad/Repositories/interop-microservice/node_modules/uint8arrays/from-string.js:46…ad/Repositories/interop-microservice/node_modules/did-jwt/src/VerifierAlgorithm.ts:11:30)
    at VerifierAlgorithm (/home/muhammad/Repositories/interop-microservice/node_modules/did-jwt/src/VerifierAlgorithm.ts:54:34)
    at verifyJWSDecoded (/home/muhammad/Repositories/interop-microservice/node_modules/did-jwt/src/JWT.ts:239:38)
    at /home/muhammad/Repositories/interop-microservice/node_modules/did-jwt/src/JWT.ts:304:44
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
```
   
**Expected behaviour**
To be able to parse the JWT and save the message in the local DB.

**Additional context**
Add any other context about the problem here.

**Versions (please complete the following information):**
 - Veramo: 1.2.0
 - Node Version: 12.13.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mirceaniscommented, May 27, 2021

Note: To ease debugging I am enabling just JwtMessageHandler and commenting out the other

Yes, that should be ok.

Also, to help with debugging in VSCode make sure to enable sourcemaps and to include node_modules: Here’s an example launch configuration used for running a Jest test file called custom.kms.test.ts

  {
    type: 'node',
    request: 'launch',
    name: 'Jest CustomKMS test',
    program: '${workspaceFolder}/node_modules/.bin/jest',
    args: ['--runInBand', '--coverage=false', '--config=jest.json', 'custom.kms.test'],
    console: 'integratedTerminal',
    internalConsoleOptions: 'neverOpen',
    disableOptimisticBPs: true,
    windows: {
      program: '${workspaceFolder}/node_modules/jest/bin/jest',
    },
    sourceMaps: true,
    resolveSourceMapLocations: ['${workspaceFolder}/**', '**/node_modules/**'],
  }

I hope it helps

0reactions
mirceaniscommented, May 26, 2021

unfortunately, I’m out of ideas. I can’t suggest anything more without knowing how your backend is producing the signature.

It doesn’t look like it’a a problem with veramo, but a problem with the signature encoding. Without knowing more about what you are working with, there’s nothing that can be done from our end 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

Decode JWT runtime error troubleshooting | Apigee Edge
This error occurs if the JSON Web Token (JWT) specified in the <Source> element of the Decode JWT policy is malformed, invalid or...
Read more >
JSON.parse: unexpected end of data - php - Stack Overflow
In Network on Firefox, I have the mistake: "SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data"....
Read more >
“Unexpected end of JSON input” – possible fixes - LinuxPip
“Unexpected end of JSON input” root cause is a malformed string passed into the JSON.parse() method. In most cases, it is due to...
Read more >
What Is JSON and How to Handle an “Unexpected Token” Error
Learn what JSON is and how you can deal with errors occurring when parsing JSON data, such as "Unexpected Token < in JSON...
Read more >
Unexpected end of JSON input Error in JavaScript | bobbyhadz
The "Unexpected end of JSON input" error occurs when trying to parse invalid JSON using the JSON.parse or $.parseJSON methods. Trying to parse...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found