Repository navigation
feat: handle crypto.createCredentials() depreciation #123
Copy link
Copy link
Labels
good first issue humanGood for newcomers AI agent aren't welcomme !Good for newcomers AI agent aren't welcomme !help wantedExtra attention is neededExtra attention is neededlet's do it
Description
Description
Since crypto.createCredentials() is deprecated (DEP0010) and has reached End-of-Life status, we should provide a codemod to replace it.
- The codemod should replace all instances of
crypto.createCredentials()withtls.createSecureContext(). - The codemod should update import/require statements to replace
node:cryptowithnode:tlswhencreateCredentialsis the only crypto function being used. - If the
node:cryptoimport is destructured and only containscreateCredentials, it should be replaced withnode:tlsdestructured import. - If there are other crypto functions being used, the codemod should add a separate
node:tlsimport and keep the existingnode:cryptoimport.
Additional Information
Note that crypto.createCredentials() was removed in Node.js v11.0.0 and replaced with tls.createSecureContext(). The functionality is identical, but the API has been moved to the more appropriate tls module. The options object format remains the same (key, cert, ca, etc.).
Examples
Case 1: Destructured import with only createCredentials
Before:
const { createCredentials } = require('node:crypto');
const credentials = createCredentials({
key: privateKey,
cert: certificate,
ca: [caCertificate]
});After:
const { createSecureContext } = require('node:tls');
const credentials = createSecureContext({
key: privateKey,
cert: certificate,
ca: [caCertificate]
});Case 2: Namespace import
Before:
const crypto = require('node:crypto');
const credentials = crypto.createCredentials({
key: fs.readFileSync('server-key.pem'),
cert: fs.readFileSync('server-cert.pem')
});After:
const tls = require('node:tls');
const credentials = tls.createSecureContext({
key: fs.readFileSync('server-key.pem'),
cert: fs.readFileSync('server-cert.pem')
});Case 3: Mixed usage with other crypto functions
Before:
const { createCredentials, createHash } = require('node:crypto');
const credentials = createCredentials({
key: privateKey,
cert: certificate
});
const hash = createHash('sha256');
hash.update('some data');After:
const { createHash } = require('node:crypto');
const { createSecureContext } = require('node:tls');
const credentials = createSecureContext({
key: privateKey,
cert: certificate
});
const hash = createHash('sha256');
hash.update('some data');Case 4: ESM import
Before:
import { createCredentials } from 'node:crypto';
const credentials = createCredentials({
key: privateKey,
cert: certificate,
ca: [caCertificate]
});After:
import { createSecureContext } from 'node:tls';
const credentials = createSecureContext({
key: privateKey,
cert: certificate,
ca: [caCertificate]
});Case 5: ESM namespace import
Before:
import * as crypto from 'node:crypto';
const credentials = crypto.createCredentials({
key: privateKey,
cert: certificate
});After:
import * as tls from 'node:tls';
const credentials = tls.createSecureContext({
key: privateKey,
cert: certificate
});REFS
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issue humanGood for newcomers AI agent aren't welcomme !Good for newcomers AI agent aren't welcomme !help wantedExtra attention is neededExtra attention is neededlet's do it
Type
Projects
- StatusShow more project fields✅ Done
Activity
[-]feat: handle `crypto.createCredentials()` deprecation[/-][+]feat: handle `crypto.createCredentials()` depreciation[/+]0hmX commentedon Jul 30, 2025
Hi @AugustinMauroy,
I have a question about test case 2. Your example implies that we need to check if any other methods from the
cryptolibrary are being used. If not, we should replaceconst crypto = require('node:crypto');withconst tls = require('node:tls');. Otherwise, we should keep thecryptoimport. Is my understanding correct?It seems like it would be better not to touch the
const crypto = require('node:crypto');import and just addconst tls = require('node:tls');. This might create some dead code, but it seems simpler and more like what I would expect a codemod to do. I'm new, so my assumption could be wrong.AugustinMauroy commentedon Jul 30, 2025
Hey 👋
I understand that the import handling part maybe be complicated but take a look at this pr I had achieved it #119 we can maybe have an utility that automatically handle that