Skip to content

Commit 0314c97

Browse files
refactor: complete TypeScript migration and add synchronous API with security hardening
- Remove all JavaScript source files and legacy tests - Add synchronous versions of sign and verify functions - Reorganize test structure into unit tests with TypeScript - Update build configuration for dual CommonJS/ESM support - Add shared utility modules for better code organization - Improve algorithm implementations with better type safety - Enhance security with stricter input validation and error handling - Harden against timing attacks in signature verification - Add comprehensive type guards for JWT payload validation - Update documentation with new API references BREAKING CHANGE: This completes the v10 migration to TypeScript with new synchronous APIs and reorganized module structure
1 parent 812f3f7 commit 0314c97

File tree

157 files changed

+13029
-7555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+13029
-7555
lines changed

MIGRATION_GUIDE_V10.md

Lines changed: 0 additions & 210 deletions
This file was deleted.

MIGRATION_SUMMARY.md

Lines changed: 0 additions & 63 deletions
This file was deleted.

README.md

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ npm install jsonwebtoken
1515

1616
## Documentation
1717

18-
📚 **[View the complete documentation in our Wiki](https://github.com/auth0/node-jsonwebtoken/wiki)**
18+
📚 **[View the complete documentation in our Wiki](https://github.com/interpret-tech/node-jsonwebtoken/wiki)**
1919

2020
The Wiki includes:
21-
- [Getting Started Guide](https://github.com/auth0/node-jsonwebtoken/wiki/Installation-&-Setup)
22-
- [API Reference](https://github.com/auth0/node-jsonwebtoken/wiki)
23-
- [Migration Guides](https://github.com/auth0/node-jsonwebtoken/wiki/Migration-Guide-v10)
24-
- [TypeScript Examples](https://github.com/auth0/node-jsonwebtoken/wiki/Usage-Examples#typescript-examples)
25-
- [Security Best Practices](https://github.com/auth0/node-jsonwebtoken/wiki/Security-&-Algorithms)
21+
- [Getting Started Guide](https://github.com/interpret-tech/node-jsonwebtoken/wiki/Installation-&-Setup)
22+
- [API Reference](https://github.com/interpret-tech/node-jsonwebtoken/wiki)
23+
- [Migration Guides](https://github.com/interpret-tech/node-jsonwebtoken/wiki/Migration-Guide-v10)
24+
- [TypeScript Examples](https://github.com/interpret-tech/node-jsonwebtoken/wiki/Usage-Examples#typescript-examples)
25+
- [Security Best Practices](https://github.com/interpret-tech/node-jsonwebtoken/wiki/Security-&-Algorithms)
2626

2727
## Quick Start
2828

29+
### Asynchronous (Promise-based)
2930
```javascript
3031
const jwt = require('jsonwebtoken');
3132

@@ -37,6 +38,34 @@ const decoded = await jwt.verify(token, 'secret');
3738
console.log(decoded.foo) // 'bar'
3839
```
3940

41+
### Synchronous
42+
```javascript
43+
const jwt = require('jsonwebtoken');
44+
45+
// Sign a token
46+
const token = jwt.signSync({ foo: 'bar' }, 'secret');
47+
48+
// Verify a token
49+
const decoded = jwt.verifySync(token, 'secret');
50+
console.log(decoded.foo) // 'bar'
51+
```
52+
53+
### Callback-based
54+
```javascript
55+
const jwt = require('jsonwebtoken');
56+
57+
// Sign a token
58+
jwt.sign({ foo: 'bar' }, 'secret', (err, token) => {
59+
if (err) throw err;
60+
61+
// Verify the token
62+
jwt.verify(token, 'secret', (err, decoded) => {
63+
if (err) throw err;
64+
console.log(decoded.foo) // 'bar'
65+
});
66+
});
67+
```
68+
4069
## Requirements
4170

4271
- **Node.js** >= 20

decode.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

eslint.config.js renamed to eslint.config.cjs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module.exports = [
22
{
3-
ignores: ["node_modules/**", "coverage/**", "dist/**", ".nyc_output/**"]
3+
ignores: ["node_modules/**", "coverage/**", "dist/**", ".nyc_output/**", "convert-tests-to-async.js"]
44
},
55
{
66
files: ["**/*.js"],
77
languageOptions: {
88
ecmaVersion: 2022,
9-
sourceType: "commonjs",
9+
sourceType: "script",
1010
globals: {
1111
Buffer: "readonly",
1212
process: "readonly",
@@ -42,6 +42,18 @@ module.exports = [
4242
"object-shorthand": ["warn", "always"]
4343
}
4444
},
45+
{
46+
files: ["test/compatibility-esm.test.js"],
47+
languageOptions: {
48+
ecmaVersion: 2022,
49+
sourceType: "module",
50+
globals: {
51+
Buffer: "readonly",
52+
process: "readonly",
53+
console: "readonly"
54+
}
55+
}
56+
},
4557
{
4658
files: ["test/**/*.js"],
4759
languageOptions: {

index.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)