[BREAKING] Modernize node-jwa: ESM + Web Crypto API#56
Open
jimmywarting wants to merge 2 commits intoauth0:masterfrom
Open
[BREAKING] Modernize node-jwa: ESM + Web Crypto API#56jimmywarting wants to merge 2 commits intoauth0:masterfrom
jimmywarting wants to merge 2 commits intoauth0:masterfrom
Conversation
Rewrite library to ES Modules and Web Crypto API: convert index.js to ESM, replace Node crypto APIs with SubtleCrypto, add a small DER->JOSE ECDSA parser, and make all sign/verify functions async (return Promises). Update package.json for v4.0.0 (type: module, exports, node>=18), remove legacy dependencies and CI (.travis.yml), and update Makefile to use `node --test`. Tests and examples migrated to node:test and ESM, README updated for breaking changes, and PR.md added documenting the modernization and migration notes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request modernizes the node-jwa library to align with current JavaScript standards and best practices:
cryptomodule with the standards-based Web Crypto APIecdsa-sig-formatterdependency with a custom, lightweight DER parser (just to get rid of safe-buffer)Motivation
The library was built on Node.js 0.11 APIs that are now outdated. This modernization:
ecdsa-sig-formatterpackage entirely (~200 lines + safe-buffer size → ~50 lines custom code)Major Changes
Breaking Changes (v2.x → v3.x)
1. ESM Only
2. Async Operations
All
sign()andverify()methods now return Promises:3. Web Crypto API
Uses
globalThis.crypto.subtleinstead ofrequire('crypto'):Bufferin the implementationMinor Changes
Uint8Array.toBase64()/fromBase64()with fallbacks for older environmentsUint8Arraythroughout, better cross compatibilityBenefits
For Users
For Maintainers
Testing
All 5 RFC 7515 test vectors pass:
npm test ✔ A.1, A.2, A.3, A.4, A.5 (5 tests pass)Migration Guide for Users
Step 1: Update package.json
Step 2: Update imports
Step 3: Update API calls
Step 4: Use in async context
Requirements
Algorithm Support (Unchanged)
All existing algorithms continue to work:
Implementation Details
DER Parser for ECDSA
Replaced the entire
ecdsa-sig-formatterdependency with a custom ~50-line parser that:Base64URL Encoding
Uses native methods with fallbacks:
Files Changed
index.js- Complete rewrite with Web Crypto APIpackage.json- Updated to v3.0.0, removed dependenciesREADME.md- Updated examples and documentationtest/*.js- Updated to use async/await and named importssync.js(experimental worker-based wrapper)No Production Dependencies
{ "dependencies": {}, "devDependencies": { "jwk-to-pem": "^2.0.5" } }Backward Compatibility
This is a breaking change. Projects using node-jwa will need to:
require(esm)A v3.x branch can be maintained if long-term compatibility is needed.
Questions?
This modernization aligns node-jwa with:
The implementation maintains 100% compatibility with RFC 7515 test vectors while providing a cleaner, standards-based API.