Skip to content

Remove jsonwebtoken and base64url in favor of native crypto (#318) - #441

Open
shubhransh-gupta wants to merge 1 commit into
apple:mainfrom
shubhransh-gupta:replace-jsonwebtoken
Open

Remove jsonwebtoken and base64url in favor of native crypto (#318)#441
shubhransh-gupta wants to merge 1 commit into
apple:mainfrom
shubhransh-gupta:replace-jsonwebtoken

Conversation

@shubhransh-gupta

Copy link
Copy Markdown

Summary

Replaces jsonwebtoken and base64url dependencies with Node.js built-in crypto (sign, verify, and Buffer.from(..., 'base64url')).

Fixes #318

Motivation & Problem

jsonwebtoken has unmaintained transitive dependencies (jws, jwa, ecdsa-sig-formatter, safe-buffer) that cause compatibility and packaging errors when used with modern ESM bundlers (such as esbuild, Vite, Rollup, webpack) and alternative runtimes (such as Bun).

By using standard Node.js built-in crypto primitives:

  1. Zero JWT runtime dependencies: Completely drops jsonwebtoken, @types/jsonwebtoken, base64url, and their 20+ transitive dependencies.
  2. ESM / Bundler Compatibility: Eliminates bundler errors caused by legacy CommonJS sub-dependencies like safe-buffer.
  3. No breaking changes: All public methods and signatures retain identical behavior and synchronous/asynchronous contracts.

What Changed

  • index.ts: Implemented createBearerToken() using Node's sign('SHA256', ..., { key, dsaEncoding: 'ieee-p1363' }).
  • jws_signature_creator.ts: Implemented internalCreateSignature() using Node's built-in crypto.sign and Buffer.from(..., 'base64url').
  • jws_verification.ts: Decodes JWT headers and payloads using native base64url buffer conversions, and verifies ES256 signatures with Node's verify('SHA256', ..., { key: publicKey, dsaEncoding: 'ieee-p1363' }, ...).
  • package.json & yarn.lock: Removed jsonwebtoken, @types/jsonwebtoken, and base64url.
  • NOTICE.txt: Updated third-party notices accordingly.
  • Tests (api_client.test.ts, jws_signature_creator.test.ts, util.ts): Updated test utilities and mocks to use native crypto / base64url decoding.

Test Plan

  • npm run build (tsc -p .) builds cleanly with zero errors.
  • npm test passes all 22 test suites and 344/344 unit tests.
  • npm run build-docs generates TypeDoc documentation with 0 errors.

@shubhransh-gupta

Copy link
Copy Markdown
Author

Hi @alexanderjordanbaker — Friendly reminder on this PR when you have time for a review. It resolves #318 by migrating from jsonwebtoken and base64url to Node.js native crypto. Full TypeScript build and test suite pass with 100% test coverage. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use jose instead of jsonwebtoken

1 participant