Skip to content

Commit

Permalink
chore: upgrade deps (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood authored Dec 14, 2024
1 parent 2db5f94 commit c9fd3b6
Show file tree
Hide file tree
Showing 18 changed files with 146 additions and 208 deletions.
30 changes: 0 additions & 30 deletions .eslintrc.js

This file was deleted.

9 changes: 1 addition & 8 deletions benchmarks/auth0.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@

import { isMainThread } from 'worker_threads'

import {
tokens,
privateKeys,
publicKeys,
compareSigning,
compareVerifying,
saveLogs
} from './utils.mjs'
import { tokens, privateKeys, publicKeys, compareSigning, compareVerifying, saveLogs } from './utils.mjs'

async function runSuites() {
if (!isMainThread) {
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/clinic-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ const authRoute = {

fastify.post('/sign-jwt', {
...signRoute,
async handler(request, reply) {
async handler(request) {
return { token: signerJwt(request.query, key, { algorithm: 'HS256' }) }
}
})

fastify.post('/sign-fast', {
...signRoute,
async handler(request, reply) {
async handler(request) {
return { token: await signerFast(request.query) }
}
})

fastify.get('/auth-jwt', {
...authRoute,
async handler(request, reply) {
async handler(request) {
return {
payload: verifierJwt(request.query.token, key, { algorithm: 'HS256' })
}
Expand All @@ -89,7 +89,7 @@ fastify.get('/auth-jwt', {

fastify.get('/auth-fast', {
...authRoute,
async handler(request, reply) {
async handler(request) {
return { payload: await verifierFast(request.query.token) }
}
})
Expand Down
5 changes: 1 addition & 4 deletions benchmarks/decode.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict'

import {
compareDecoding,
saveLogs
} from './utils.mjs'
import { compareDecoding, saveLogs } from './utils.mjs'

// Regenerate this token after regenerating the keys by running `npm run generate-tokens` and getting the RS512 token
const rsToken =
Expand Down
7 changes: 1 addition & 6 deletions benchmarks/sign.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
'use strict'

import { isMainThread } from 'worker_threads'
import {
privateKeys,
publicKeys,
compareSigning,
saveLogs
} from './utils.mjs'
import { privateKeys, publicKeys, compareSigning, saveLogs } from './utils.mjs'

async function runSuites() {
if (!isMainThread) {
Expand Down
79 changes: 32 additions & 47 deletions benchmarks/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,15 @@ import { fileURLToPath } from 'url'

import jwt from 'jsonwebtoken'

import {
JWK as JWKJose,
JWT as JWTJose
} from 'jose'
import { JWK as JWKJose, JWT as JWTJose } from 'jose'

import {
createDecoder,
createSigner,
createVerifier
} from '../src/index.js'
import { createDecoder, createSigner, createVerifier } from '../src/index.js'

const __dirname = dirname(fileURLToPath(import.meta.url))

const {
sign: jsonwebtokenSign,
decode: jsonwebtokenDecode,
verify: jsonwebtokenVerify
} = jwt
const { sign: jsonwebtokenSign, decode: jsonwebtokenDecode, verify: jsonwebtokenVerify } = jwt

const {
sign: nodeRsSign,
signSync: nodeRsSignSync,
verifySync: nodeRsVerifySync
} = nodeRsJwt
const { sign: nodeRsSign, signSync: nodeRsSignSync, verifySync: nodeRsVerifySync } = nodeRsJwt

const { sign: joseSign, verify: joseVerify, decode: joseDecode } = JWTJose
const { asKey } = JWKJose
Expand Down Expand Up @@ -88,17 +73,13 @@ export const publicKeys = {
}

export async function saveLogs(type) {
const now = new Date()
.toISOString()
.replace(/[-:]/g, '')
.replace('T', '-')
.slice(0, 15)
const now = new Date().toISOString().replace(/[-:]/g, '').replace('T', '-').slice(0, 15)

const directory = resolve(__dirname, 'logs')

try {
await mkdir(directory)
} catch (e) {
} catch {
// No-op
}

Expand All @@ -125,22 +106,22 @@ export function compareDecoding(token, algorithm) {

return cronometro(
{
[`${algorithm} - fast-jwt`]: function() {
[`${algorithm} - fast-jwt`]: function () {
fastjwtDecoder(token)
},
[`${algorithm} - fast-jwt (complete)`]: function() {
[`${algorithm} - fast-jwt (complete)`]: function () {
fastjwtCompleteDecoder(token)
},
[`${algorithm} - jsonwebtoken`]: function() {
[`${algorithm} - jsonwebtoken`]: function () {
jsonwebtokenDecode(token)
},
[`${algorithm} - jsonwebtoken (complete)`]: function() {
[`${algorithm} - jsonwebtoken (complete)`]: function () {
jsonwebtokenDecode(token, { complete: true })
},
[`${algorithm} - jose`]: function() {
[`${algorithm} - jose`]: function () {
joseDecode(token)
},
[`${algorithm} - jose (complete)`]: function() {
[`${algorithm} - jose (complete)`]: function () {
joseDecode(token, { complete: true })
}
},
Expand All @@ -167,7 +148,9 @@ export async function compareSigning(payload, algorithm, privateKey, publicKey)
if ((process.env.NODE_DEBUG || '').includes('fast-jwt')) {
const fastjwtGenerated = fastjwtSign(payload)
const joseGenerated = joseSign(payload, josePrivateKey, joseOptions)
const nodeRsGenerated = nodeRsSignSync({ data: payload, exp: Date.now() }, privateKey, { algorithm: Algorithm[algorithm.toUpperCase()] })
const nodeRsGenerated = nodeRsSignSync({ data: payload, exp: Date.now() }, privateKey, {
algorithm: Algorithm[algorithm.toUpperCase()]
})
const jsonwebtokenGenerated = isEdDSA
? null
: jsonwebtokenSign(payload, privateKey, { algorithm, noTimestamp: true })
Expand All @@ -186,41 +169,43 @@ export async function compareSigning(payload, algorithm, privateKey, publicKey)
}
log(` jose: ${JSON.stringify(joseVerify(joseGenerated, asKey(publicKey)))}`)
log(` fastjwt: ${JSON.stringify(fastjwtVerify(fastjwtGenerated))}`)
log(`@node-rs/jsonwebtoken: ${JSON.stringify(nodeRsVerifySync(nodeRsGenerated, publicKey, { algorithms: [Algorithm[algorithm.toUpperCase()]] }))}`)
log(
`@node-rs/jsonwebtoken: ${JSON.stringify(nodeRsVerifySync(nodeRsGenerated, publicKey, { algorithms: [Algorithm[algorithm.toUpperCase()]] }))}`
)
log('-------')
}

const tests = {
[`${algorithm} - jose (sync)`]: function() {
[`${algorithm} - jose (sync)`]: function () {
joseSign(payload, josePrivateKey, joseOptions)
}
}

if (!isEdDSA) {
Object.assign(tests, {
[`${algorithm} - jsonwebtoken (sync)`]: function() {
[`${algorithm} - jsonwebtoken (sync)`]: function () {
jsonwebtokenSign(payload, privateKey, { algorithm, noTimestamp: true })
},
[`${algorithm} - jsonwebtoken (async)`]: function(done) {
[`${algorithm} - jsonwebtoken (async)`]: function (done) {
jsonwebtokenSign(payload, privateKey, { algorithm, noTimestamp: true }, done)
}
})
}

Object.assign(tests, {
[`${algorithm} - fast-jwt (sync)`]: function() {
[`${algorithm} - fast-jwt (sync)`]: function () {
fastjwtSign(payload)
},
[`${algorithm} - fast-jwt (async)`]: function(done) {
[`${algorithm} - fast-jwt (async)`]: function (done) {
fastjwtSignAsync(payload, done)
}
})

Object.assign(tests, {
[`${algorithm} - @node-rs/jsonwebtoken (sync)`]: function() {
[`${algorithm} - @node-rs/jsonwebtoken (sync)`]: function () {
nodeRsSignSync({ data: payload }, privateKey, { algorithm: Algorithm[algorithm.toUpperCase()] })
},
[`${algorithm} - @node-rs/jsonwebtoken (async)`]: function(done) {
[`${algorithm} - @node-rs/jsonwebtoken (async)`]: function (done) {
nodeRsSign({ data: payload }, privateKey, { algorithm: Algorithm[algorithm.toUpperCase()] }).then(() => done())
}
})
Expand Down Expand Up @@ -252,28 +237,28 @@ export function compareVerifying(token, algorithm, publicKey) {
}

const tests = {
[`${algorithm} - fast-jwt (sync)`]: function() {
[`${algorithm} - fast-jwt (sync)`]: function () {
fastjwtVerify(token)
},
[`${algorithm} - fast-jwt (async)`]: function(done) {
[`${algorithm} - fast-jwt (async)`]: function (done) {
fastjwtVerifyAsync(token, done)
},
[`${algorithm} - fast-jwt (sync with cache)`]: function() {
[`${algorithm} - fast-jwt (sync with cache)`]: function () {
fastjwtCachedVerify(token)
},
[`${algorithm} - fast-jwt (async with cache)`]: function(done) {
[`${algorithm} - fast-jwt (async with cache)`]: function (done) {
fastjwtCachedVerifyAsync(token, done)
},
[`${algorithm} - jose (sync)`]: function() {
[`${algorithm} - jose (sync)`]: function () {
joseVerify(token, josePublicKey)
}
}

if (!isEdDSA) {
tests[`${algorithm} - jsonwebtoken (sync)`] = function() {
tests[`${algorithm} - jsonwebtoken (sync)`] = function () {
jsonwebtokenVerify(token, publicKey)
}
tests[`${algorithm} - jsonwebtoken (async)`] = function(done) {
tests[`${algorithm} - jsonwebtoken (async)`] = function (done) {
jsonwebtokenVerify(token, publicKey, done)
}
}
Expand Down
7 changes: 1 addition & 6 deletions benchmarks/verify.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
'use strict'

import { isMainThread } from 'worker_threads'
import {
tokens,
publicKeys,
compareVerifying,
saveLogs
} from './utils.mjs'
import { tokens, publicKeys, compareVerifying, saveLogs } from './utils.mjs'

async function runSuites() {
if (!isMainThread) {
Expand Down
25 changes: 25 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const js = require('@eslint/js')
const prettierRecommended = require('eslint-plugin-prettier/recommended')
const globals = require('globals')
const tseslint = require('typescript-eslint')

module.exports = tseslint.config(
js.configs.recommended,
prettierRecommended,
{
files: ['*.ts'],
extends: [tseslint.configs.recommended],
rules: {
'@typescript-eslint/no-explicit-any': 'off'
}
},
{
languageOptions: {
globals: {
...globals.node
},
ecmaVersion: 'latest',
sourceType: 'module'
}
}
)
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
],
"scripts": {
"postpublish": "git push origin && git push origin -f --tags",
"lint": "eslint src/**/*.js test/**/*.js src/**/*.ts test/**/*.ts",
"lint": "eslint .",
"test": "node --test --experimental-test-coverage && tsd",
"test:ci": "npm run lint && npm run test",
"test:watch": "node --test --watch --experimental-test-coverage",
Expand All @@ -51,29 +51,29 @@
"benchmark:auth0": "node benchmarks/auth0.mjs"
},
"dependencies": {
"@lukeed/ms": "^2.0.1",
"@lukeed/ms": "^2.0.2",
"asn1.js": "^5.4.1",
"ecdsa-sig-formatter": "^1.0.11",
"mnemonist": "^0.39.5"
"mnemonist": "^0.39.8"
},
"devDependencies": {
"@node-rs/jsonwebtoken": "^0.5.6",
"@sinonjs/fake-timers": "^13.0.1",
"@types/node": "^22.0.0",
"@typescript-eslint/eslint-plugin": "^5.49.0",
"@typescript-eslint/parser": "^5.49.0",
"@node-rs/jsonwebtoken": "^0.5.9",
"@sinonjs/fake-timers": "^13.0.5",
"@types/node": "^22.10.2",
"cronometro": "^4.0.0",
"eslint": "^8.33.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^16.0.0",
"eslint-plugin-promise": "^6.1.1",
"fastify": "^5.0.0",
"jose": "^2.0.6",
"jsonwebtoken": "^9.0.0",
"prettier": "^3.0.0",
"tsd": "^0.31.0",
"typescript": "^5.0.2"
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-n": "^17.15.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^7.2.1",
"fastify": "^5.2.0",
"jose": "^2.0.7",
"jsonwebtoken": "^9.0.2",
"prettier": "^3.4.2",
"tsd": "^0.31.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.0"
},
"engines": {
"node": ">=20"
Expand Down
Loading

0 comments on commit c9fd3b6

Please sign in to comment.