diff --git a/types/node/crypto.d.ts b/types/node/crypto.d.ts index d17c6f6dc2..481e991421 100644 --- a/types/node/crypto.d.ts +++ b/types/node/crypto.d.ts @@ -423,8 +423,8 @@ declare module "crypto" { interface BasePrivateKeyEncodingOptions { format: T; - cipher: string; - passphrase: string; + cipher?: string; + passphrase?: string; } interface KeyPairKeyObjectResult { diff --git a/types/node/test/crypto.ts b/types/node/test/crypto.ts index 4680682b06..39c639482c 100644 --- a/types/node/test/crypto.ts +++ b/types/node/test/crypto.ts @@ -337,6 +337,21 @@ import { promisify } from 'util'; }, }); + const rsaResNoPassphrase: { + publicKey: Buffer; + privateKey: string; + } = crypto.generateKeyPairSync('rsa', { + modulusLength: 123, + publicKeyEncoding: { + format: 'der', + type: 'pkcs1', + }, + privateKeyEncoding: { + format: 'pem', + type: 'pkcs8', + }, + }); + const dsaRes: { publicKey: string; privateKey: Buffer; @@ -355,6 +370,22 @@ import { promisify } from 'util'; }, }); + const dsaResNoPassphrase: { + publicKey: string; + privateKey: Buffer; + } = crypto.generateKeyPairSync('dsa', { + modulusLength: 123, + divisorLength: 123, + publicKeyEncoding: { + format: 'pem', + type: 'spki', + }, + privateKeyEncoding: { + format: 'der', + type: 'pkcs8', + }, + }); + const ecRes: { publicKey: string; privateKey: string; @@ -371,6 +402,21 @@ import { promisify } from 'util'; type: 'pkcs8', }, }); + + const ecResNoPassphrase: { + publicKey: string; + privateKey: string; + } = crypto.generateKeyPairSync('ec', { + namedCurve: 'curve', + publicKeyEncoding: { + format: 'pem', + type: 'pkcs1', + }, + privateKeyEncoding: { + format: 'pem', + type: 'pkcs8', + }, + }); } {