Skip to content

Commit

Permalink
perf: use node: prefix to bypass require.cache call for builtins (#375
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Fdawgs authored Sep 18, 2023
1 parent 6e5242b commit f836ce1
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions benchmarks/keys/generate-keys.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node

const { generateKeyPair } = require('crypto')
const { writeFileSync } = require('fs')
const { resolve } = require('path')
const { generateKeyPair } = require('node:crypto')
const { writeFileSync } = require('node:fs')
const { resolve } = require('node:path')

const passProtectedKeyPassphrase = 'secret'
const configurations = {
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/keys/generate-tokens.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { readFileSync } = require('fs')
const { resolve } = require('path')
const { readFileSync } = require('node:fs')
const { resolve } = require('node:path')

const { createSigner } = require('../../src')

Expand Down
4 changes: 2 additions & 2 deletions src/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const {
RSA_PSS_SALTLEN_MAX_SIGN,
RSA_PSS_SALTLEN_AUTO
}
} = require('crypto')
let { sign: directSign, verify: directVerify } = require('crypto')
} = require('node:crypto')
let { sign: directSign, verify: directVerify } = require('node:crypto')
const { joseToDer, derToJose } = require('ecdsa-sig-formatter')
const Cache = require('mnemonist/lru-cache')
const { TokenError } = require('./error')
Expand Down
2 changes: 1 addition & 1 deletion src/signer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {
} = require('./crypto')
const { TokenError } = require('./error')
const { getAsyncKey, ensurePromiseCallback } = require('./utils')
const { createPrivateKey, createSecretKey } = require('crypto')
const { createPrivateKey, createSecretKey } = require('node:crypto')
const { parse: parseMs } = require('@lukeed/ms')

const supportedAlgorithms = new Set([...hsAlgorithms, ...esAlgorithms, ...rsaAlgorithms, ...edAlgorithms, 'none'])
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { createHash } = require('crypto')
const { createHash } = require('node:crypto')
const algorithmMatcher = /"alg"\s*:\s*"[HERP]S(256|384)"/m
const edAlgorithmMatcher = /"alg"\s*:\s*"EdDSA"/m
const ed448CurveMatcher = /"crv"\s*:\s*"Ed448"/m
Expand Down
2 changes: 1 addition & 1 deletion src/verifier.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { createPublicKey, createSecretKey } = require('crypto')
const { createPublicKey, createSecretKey } = require('node:crypto')
const Cache = require('mnemonist/lru-cache')

const { useNewCrypto, hsAlgorithms, verifySignature, detectPublicKeyAlgorithms } = require('./crypto')
Expand Down
4 changes: 2 additions & 2 deletions test/compatibility.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

const { readFileSync } = require('fs')
const { readFileSync } = require('node:fs')
const { sign: jsonwebtokenSign, verify: jsonwebtokenVerify } = require('jsonwebtoken')
const {
JWT: { sign: joseSign, verify: joseVerify },
JWK: { asKey }
} = require('jose')
const { resolve } = require('path')
const { resolve } = require('node:path')
const { test } = require('tap')

const { createSigner, createVerifier } = require('../src')
Expand Down
4 changes: 2 additions & 2 deletions test/crypto.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const { test } = require('tap')
const { readFileSync } = require('fs')
const { resolve } = require('path')
const { readFileSync } = require('node:fs')
const { resolve } = require('node:path')

const { createVerifier, createSigner } = require('../src')
const {
Expand Down
4 changes: 2 additions & 2 deletions test/signer.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { readFileSync } = require('fs')
const { resolve } = require('path')
const { readFileSync } = require('node:fs')
const { resolve } = require('node:path')
const { test } = require('tap')

const { createSigner, createVerifier, TokenError, createDecoder } = require('../src')
Expand Down
6 changes: 3 additions & 3 deletions test/verifier.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const { createHash } = require('crypto')
const { readFileSync } = require('fs')
const { resolve } = require('path')
const { createHash } = require('node:crypto')
const { readFileSync } = require('node:fs')
const { resolve } = require('node:path')
const { test } = require('tap')
const { install: fakeTime } = require('@sinonjs/fake-timers')

Expand Down

0 comments on commit f836ce1

Please sign in to comment.