UNPKG

47.2 kBTypeScriptView Raw
1declare module 'crypto' {
2 import * as stream from 'stream';
3
4 interface Certificate {
5 /**
6 * @param spkac
7 * @returns The challenge component of the `spkac` data structure,
8 * which includes a public key and a challenge.
9 */
10 exportChallenge(spkac: BinaryLike): Buffer;
11 /**
12 * @param spkac
13 * @param encoding The encoding of the spkac string.
14 * @returns The public key component of the `spkac` data structure,
15 * which includes a public key and a challenge.
16 */
17 exportPublicKey(spkac: BinaryLike, encoding?: string): Buffer;
18 /**
19 * @param spkac
20 * @returns `true` if the given `spkac` data structure is valid,
21 * `false` otherwise.
22 */
23 verifySpkac(spkac: NodeJS.ArrayBufferView): boolean;
24 }
25 const Certificate: Certificate & {
26 /** @deprecated since v14.9.0 - Use static methods of `crypto.Certificate` instead. */
27 new (): Certificate;
28 /** @deprecated since v14.9.0 - Use static methods of `crypto.Certificate` instead. */
29 (): Certificate;
30 };
31
32 namespace constants {
33 // https://nodejs.org/dist/latest-v10.x/docs/api/crypto.html#crypto_crypto_constants
34 const OPENSSL_VERSION_NUMBER: number;
35
36 /** Applies multiple bug workarounds within OpenSSL. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html for detail. */
37 const SSL_OP_ALL: number;
38 /** Allows legacy insecure renegotiation between OpenSSL and unpatched clients or servers. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html. */
39 const SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: number;
40 /** Attempts to use the server's preferences instead of the client's when selecting a cipher. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html. */
41 const SSL_OP_CIPHER_SERVER_PREFERENCE: number;
42 /** Instructs OpenSSL to use Cisco's "speshul" version of DTLS_BAD_VER. */
43 const SSL_OP_CISCO_ANYCONNECT: number;
44 /** Instructs OpenSSL to turn on cookie exchange. */
45 const SSL_OP_COOKIE_EXCHANGE: number;
46 /** Instructs OpenSSL to add server-hello extension from an early version of the cryptopro draft. */
47 const SSL_OP_CRYPTOPRO_TLSEXT_BUG: number;
48 /** Instructs OpenSSL to disable a SSL 3.0/TLS 1.0 vulnerability workaround added in OpenSSL 0.9.6d. */
49 const SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: number;
50 /** Instructs OpenSSL to always use the tmp_rsa key when performing RSA operations. */
51 const SSL_OP_EPHEMERAL_RSA: number;
52 /** Allows initial connection to servers that do not support RI. */
53 const SSL_OP_LEGACY_SERVER_CONNECT: number;
54 const SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER: number;
55 const SSL_OP_MICROSOFT_SESS_ID_BUG: number;
56 /** Instructs OpenSSL to disable the workaround for a man-in-the-middle protocol-version vulnerability in the SSL 2.0 server implementation. */
57 const SSL_OP_MSIE_SSLV2_RSA_PADDING: number;
58 const SSL_OP_NETSCAPE_CA_DN_BUG: number;
59 const SSL_OP_NETSCAPE_CHALLENGE_BUG: number;
60 const SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG: number;
61 const SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG: number;
62 /** Instructs OpenSSL to disable support for SSL/TLS compression. */
63 const SSL_OP_NO_COMPRESSION: number;
64 const SSL_OP_NO_QUERY_MTU: number;
65 /** Instructs OpenSSL to always start a new session when performing renegotiation. */
66 const SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: number;
67 const SSL_OP_NO_SSLv2: number;
68 const SSL_OP_NO_SSLv3: number;
69 const SSL_OP_NO_TICKET: number;
70 const SSL_OP_NO_TLSv1: number;
71 const SSL_OP_NO_TLSv1_1: number;
72 const SSL_OP_NO_TLSv1_2: number;
73 const SSL_OP_PKCS1_CHECK_1: number;
74 const SSL_OP_PKCS1_CHECK_2: number;
75 /** Instructs OpenSSL to always create a new key when using temporary/ephemeral DH parameters. */
76 const SSL_OP_SINGLE_DH_USE: number;
77 /** Instructs OpenSSL to always create a new key when using temporary/ephemeral ECDH parameters. */
78 const SSL_OP_SINGLE_ECDH_USE: number;
79 const SSL_OP_SSLEAY_080_CLIENT_DH_BUG: number;
80 const SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG: number;
81 const SSL_OP_TLS_BLOCK_PADDING_BUG: number;
82 const SSL_OP_TLS_D5_BUG: number;
83 /** Instructs OpenSSL to disable version rollback attack detection. */
84 const SSL_OP_TLS_ROLLBACK_BUG: number;
85
86 const ENGINE_METHOD_RSA: number;
87 const ENGINE_METHOD_DSA: number;
88 const ENGINE_METHOD_DH: number;
89 const ENGINE_METHOD_RAND: number;
90 const ENGINE_METHOD_EC: number;
91 const ENGINE_METHOD_CIPHERS: number;
92 const ENGINE_METHOD_DIGESTS: number;
93 const ENGINE_METHOD_PKEY_METHS: number;
94 const ENGINE_METHOD_PKEY_ASN1_METHS: number;
95 const ENGINE_METHOD_ALL: number;
96 const ENGINE_METHOD_NONE: number;
97
98 const DH_CHECK_P_NOT_SAFE_PRIME: number;
99 const DH_CHECK_P_NOT_PRIME: number;
100 const DH_UNABLE_TO_CHECK_GENERATOR: number;
101 const DH_NOT_SUITABLE_GENERATOR: number;
102
103 const ALPN_ENABLED: number;
104
105 const RSA_PKCS1_PADDING: number;
106 const RSA_SSLV23_PADDING: number;
107 const RSA_NO_PADDING: number;
108 const RSA_PKCS1_OAEP_PADDING: number;
109 const RSA_X931_PADDING: number;
110 const RSA_PKCS1_PSS_PADDING: number;
111 /** Sets the salt length for RSA_PKCS1_PSS_PADDING to the digest size when signing or verifying. */
112 const RSA_PSS_SALTLEN_DIGEST: number;
113 /** Sets the salt length for RSA_PKCS1_PSS_PADDING to the maximum permissible value when signing data. */
114 const RSA_PSS_SALTLEN_MAX_SIGN: number;
115 /** Causes the salt length for RSA_PKCS1_PSS_PADDING to be determined automatically when verifying a signature. */
116 const RSA_PSS_SALTLEN_AUTO: number;
117
118 const POINT_CONVERSION_COMPRESSED: number;
119 const POINT_CONVERSION_UNCOMPRESSED: number;
120 const POINT_CONVERSION_HYBRID: number;
121
122 /** Specifies the built-in default cipher list used by Node.js (colon-separated values). */
123 const defaultCoreCipherList: string;
124 /** Specifies the active default cipher list used by the current Node.js process (colon-separated values). */
125 const defaultCipherList: string;
126 }
127
128 interface HashOptions extends stream.TransformOptions {
129 /**
130 * For XOF hash functions such as `shake256`, the
131 * outputLength option can be used to specify the desired output length in bytes.
132 */
133 outputLength?: number | undefined;
134 }
135
136 /** @deprecated since v10.0.0 */
137 const fips: boolean;
138
139 function createHash(algorithm: string, options?: HashOptions): Hash;
140 function createHmac(algorithm: string, key: BinaryLike | KeyObject, options?: stream.TransformOptions): Hmac;
141
142 // https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings
143 type BinaryToTextEncoding = 'base64' | 'hex';
144 type CharacterEncoding = 'utf8' | 'utf-8' | 'utf16le' | 'latin1';
145 type LegacyCharacterEncoding = 'ascii' | 'binary' | 'ucs2' | 'ucs-2';
146
147 type Encoding = BinaryToTextEncoding | CharacterEncoding | LegacyCharacterEncoding;
148
149 type ECDHKeyFormat = 'compressed' | 'uncompressed' | 'hybrid';
150
151 class Hash extends stream.Transform {
152 private constructor();
153 copy(): Hash;
154 update(data: BinaryLike): Hash;
155 update(data: string, input_encoding: Encoding): Hash;
156 digest(): Buffer;
157 digest(encoding: BinaryToTextEncoding): string;
158 }
159 class Hmac extends stream.Transform {
160 private constructor();
161 update(data: BinaryLike): Hmac;
162 update(data: string, input_encoding: Encoding): Hmac;
163 digest(): Buffer;
164 digest(encoding: BinaryToTextEncoding): string;
165 }
166
167 type KeyObjectType = 'secret' | 'public' | 'private';
168
169 interface KeyExportOptions<T extends KeyFormat> {
170 type: 'pkcs1' | 'spki' | 'pkcs8' | 'sec1';
171 format: T;
172 cipher?: string | undefined;
173 passphrase?: string | Buffer | undefined;
174 }
175
176 class KeyObject {
177 private constructor();
178 asymmetricKeyType?: KeyType | undefined;
179 /**
180 * For asymmetric keys, this property represents the size of the embedded key in
181 * bytes. This property is `undefined` for symmetric keys.
182 */
183 asymmetricKeySize?: number | undefined;
184 export(options: KeyExportOptions<'pem'>): string | Buffer;
185 export(options?: KeyExportOptions<'der'>): Buffer;
186 symmetricKeySize?: number | undefined;
187 type: KeyObjectType;
188 }
189
190 type CipherCCMTypes = 'aes-128-ccm' | 'aes-192-ccm' | 'aes-256-ccm' | 'chacha20-poly1305';
191 type CipherGCMTypes = 'aes-128-gcm' | 'aes-192-gcm' | 'aes-256-gcm';
192
193 type BinaryLike = string | NodeJS.ArrayBufferView;
194
195 type CipherKey = BinaryLike | KeyObject;
196
197 interface CipherCCMOptions extends stream.TransformOptions {
198 authTagLength: number;
199 }
200 interface CipherGCMOptions extends stream.TransformOptions {
201 authTagLength?: number | undefined;
202 }
203 /** @deprecated since v10.0.0 use `createCipheriv()` */
204 function createCipher(algorithm: CipherCCMTypes, password: BinaryLike, options: CipherCCMOptions): CipherCCM;
205 /** @deprecated since v10.0.0 use `createCipheriv()` */
206 function createCipher(algorithm: CipherGCMTypes, password: BinaryLike, options?: CipherGCMOptions): CipherGCM;
207 /** @deprecated since v10.0.0 use `createCipheriv()` */
208 function createCipher(algorithm: string, password: BinaryLike, options?: stream.TransformOptions): Cipher;
209
210 function createCipheriv(
211 algorithm: CipherCCMTypes,
212 key: CipherKey,
213 iv: BinaryLike | null,
214 options: CipherCCMOptions,
215 ): CipherCCM;
216 function createCipheriv(
217 algorithm: CipherGCMTypes,
218 key: CipherKey,
219 iv: BinaryLike | null,
220 options?: CipherGCMOptions,
221 ): CipherGCM;
222 function createCipheriv(
223 algorithm: string,
224 key: CipherKey,
225 iv: BinaryLike | null,
226 options?: stream.TransformOptions,
227 ): Cipher;
228
229 class Cipher extends stream.Transform {
230 private constructor();
231 update(data: BinaryLike): Buffer;
232 update(data: string, input_encoding: Encoding): Buffer;
233 update(data: NodeJS.ArrayBufferView, input_encoding: undefined, output_encoding: Encoding): string;
234 update(data: string, input_encoding: Encoding | undefined, output_encoding: Encoding): string;
235 final(): Buffer;
236 final(output_encoding: BufferEncoding): string;
237 setAutoPadding(auto_padding?: boolean): this;
238 // getAuthTag(): Buffer;
239 // setAAD(buffer: NodeJS.ArrayBufferView): this;
240 }
241 interface CipherCCM extends Cipher {
242 setAAD(buffer: NodeJS.ArrayBufferView, options: { plaintextLength: number }): this;
243 getAuthTag(): Buffer;
244 }
245 interface CipherGCM extends Cipher {
246 setAAD(buffer: NodeJS.ArrayBufferView, options?: { plaintextLength: number }): this;
247 getAuthTag(): Buffer;
248 }
249 /** @deprecated since v10.0.0 use `createDecipheriv()` */
250 function createDecipher(algorithm: CipherCCMTypes, password: BinaryLike, options: CipherCCMOptions): DecipherCCM;
251 /** @deprecated since v10.0.0 use `createDecipheriv()` */
252 function createDecipher(algorithm: CipherGCMTypes, password: BinaryLike, options?: CipherGCMOptions): DecipherGCM;
253 /** @deprecated since v10.0.0 use `createDecipheriv()` */
254 function createDecipher(algorithm: string, password: BinaryLike, options?: stream.TransformOptions): Decipher;
255
256 function createDecipheriv(
257 algorithm: CipherCCMTypes,
258 key: CipherKey,
259 iv: BinaryLike | null,
260 options: CipherCCMOptions,
261 ): DecipherCCM;
262 function createDecipheriv(
263 algorithm: CipherGCMTypes,
264 key: CipherKey,
265 iv: BinaryLike | null,
266 options?: CipherGCMOptions,
267 ): DecipherGCM;
268 function createDecipheriv(
269 algorithm: string,
270 key: CipherKey,
271 iv: BinaryLike | null,
272 options?: stream.TransformOptions,
273 ): Decipher;
274
275 class Decipher extends stream.Transform {
276 private constructor();
277 update(data: NodeJS.ArrayBufferView): Buffer;
278 update(data: string, input_encoding: Encoding): Buffer;
279 update(data: NodeJS.ArrayBufferView, input_encoding: undefined, output_encoding: Encoding): string;
280 update(data: string, input_encoding: Encoding | undefined, output_encoding: Encoding): string;
281 final(): Buffer;
282 final(output_encoding: BufferEncoding): string;
283 setAutoPadding(auto_padding?: boolean): this;
284 // setAuthTag(tag: NodeJS.ArrayBufferView): this;
285 // setAAD(buffer: NodeJS.ArrayBufferView): this;
286 }
287 interface DecipherCCM extends Decipher {
288 setAuthTag(buffer: NodeJS.ArrayBufferView): this;
289 setAAD(buffer: NodeJS.ArrayBufferView, options: { plaintextLength: number }): this;
290 }
291 interface DecipherGCM extends Decipher {
292 setAuthTag(buffer: NodeJS.ArrayBufferView): this;
293 setAAD(buffer: NodeJS.ArrayBufferView, options?: { plaintextLength: number }): this;
294 }
295
296 interface PrivateKeyInput {
297 key: string | Buffer;
298 format?: KeyFormat | undefined;
299 type?: 'pkcs1' | 'pkcs8' | 'sec1' | undefined;
300 passphrase?: string | Buffer | undefined;
301 }
302
303 interface PublicKeyInput {
304 key: string | Buffer;
305 format?: KeyFormat | undefined;
306 type?: 'pkcs1' | 'spki' | undefined;
307 }
308
309 function createPrivateKey(key: PrivateKeyInput | string | Buffer): KeyObject;
310 function createPublicKey(key: PublicKeyInput | string | Buffer | KeyObject): KeyObject;
311 function createSecretKey(key: NodeJS.ArrayBufferView): KeyObject;
312
313 function createSign(algorithm: string, options?: stream.WritableOptions): Signer;
314
315 type DSAEncoding = 'der' | 'ieee-p1363';
316
317 interface SigningOptions {
318 /**
319 * @See crypto.constants.RSA_PKCS1_PADDING
320 */
321 padding?: number | undefined;
322 saltLength?: number | undefined;
323 dsaEncoding?: DSAEncoding | undefined;
324 }
325
326 interface SignPrivateKeyInput extends PrivateKeyInput, SigningOptions {}
327 interface SignKeyObjectInput extends SigningOptions {
328 key: KeyObject;
329 }
330 interface VerifyPublicKeyInput extends PublicKeyInput, SigningOptions {}
331 interface VerifyKeyObjectInput extends SigningOptions {
332 key: KeyObject;
333 }
334
335 type KeyLike = string | Buffer | KeyObject;
336
337 class Signer extends stream.Writable {
338 private constructor();
339
340 update(data: BinaryLike): Signer;
341 update(data: string, input_encoding: Encoding): Signer;
342 sign(private_key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput): Buffer;
343 sign(
344 private_key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput,
345 output_format: BinaryToTextEncoding,
346 ): string;
347 }
348
349 function createVerify(algorithm: string, options?: stream.WritableOptions): Verify;
350 class Verify extends stream.Writable {
351 private constructor();
352
353 update(data: BinaryLike): Verify;
354 update(data: string, input_encoding: Encoding): Verify;
355 verify(
356 object: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput,
357 signature: NodeJS.ArrayBufferView,
358 ): boolean;
359 verify(
360 object: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput,
361 signature: string,
362 signature_format?: BinaryToTextEncoding,
363 ): boolean;
364 // https://nodejs.org/api/crypto.html#crypto_verifier_verify_object_signature_signature_format
365 // The signature field accepts a TypedArray type, but it is only available starting ES2017
366 }
367 function createDiffieHellman(prime_length: number, generator?: number | NodeJS.ArrayBufferView): DiffieHellman;
368 function createDiffieHellman(prime: NodeJS.ArrayBufferView): DiffieHellman;
369 function createDiffieHellman(prime: string, prime_encoding: BinaryToTextEncoding): DiffieHellman;
370 function createDiffieHellman(
371 prime: string,
372 prime_encoding: BinaryToTextEncoding,
373 generator: number | NodeJS.ArrayBufferView,
374 ): DiffieHellman;
375 function createDiffieHellman(
376 prime: string,
377 prime_encoding: BinaryToTextEncoding,
378 generator: string,
379 generator_encoding: BinaryToTextEncoding,
380 ): DiffieHellman;
381 class DiffieHellman {
382 private constructor();
383 generateKeys(): Buffer;
384 generateKeys(encoding: BinaryToTextEncoding): string;
385 computeSecret(other_public_key: NodeJS.ArrayBufferView): Buffer;
386 computeSecret(other_public_key: string, input_encoding: BinaryToTextEncoding): Buffer;
387 computeSecret(other_public_key: NodeJS.ArrayBufferView, output_encoding: BinaryToTextEncoding): string;
388 computeSecret(
389 other_public_key: string,
390 input_encoding: BinaryToTextEncoding,
391 output_encoding: BinaryToTextEncoding,
392 ): string;
393 getPrime(): Buffer;
394 getPrime(encoding: BinaryToTextEncoding): string;
395 getGenerator(): Buffer;
396 getGenerator(encoding: BinaryToTextEncoding): string;
397 getPublicKey(): Buffer;
398 getPublicKey(encoding: BinaryToTextEncoding): string;
399 getPrivateKey(): Buffer;
400 getPrivateKey(encoding: BinaryToTextEncoding): string;
401 setPublicKey(public_key: NodeJS.ArrayBufferView): void;
402 setPublicKey(public_key: string, encoding: BufferEncoding): void;
403 setPrivateKey(private_key: NodeJS.ArrayBufferView): void;
404 setPrivateKey(private_key: string, encoding: BufferEncoding): void;
405 verifyError: number;
406 }
407 function getDiffieHellman(group_name: string): DiffieHellman;
408 function pbkdf2(
409 password: BinaryLike,
410 salt: BinaryLike,
411 iterations: number,
412 keylen: number,
413 digest: string,
414 callback: (err: Error | null, derivedKey: Buffer) => any,
415 ): void;
416 function pbkdf2Sync(
417 password: BinaryLike,
418 salt: BinaryLike,
419 iterations: number,
420 keylen: number,
421 digest: string,
422 ): Buffer;
423
424 function randomBytes(size: number): Buffer;
425 function randomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void;
426 function pseudoRandomBytes(size: number): Buffer;
427 function pseudoRandomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void;
428
429 function randomInt(max: number): number;
430 function randomInt(min: number, max: number): number;
431 function randomInt(max: number, callback: (err: Error | null, value: number) => void): void;
432 function randomInt(min: number, max: number, callback: (err: Error | null, value: number) => void): void;
433
434 function randomFillSync<T extends NodeJS.ArrayBufferView>(buffer: T, offset?: number, size?: number): T;
435 function randomFill<T extends NodeJS.ArrayBufferView>(
436 buffer: T,
437 callback: (err: Error | null, buf: T) => void,
438 ): void;
439 function randomFill<T extends NodeJS.ArrayBufferView>(
440 buffer: T,
441 offset: number,
442 callback: (err: Error | null, buf: T) => void,
443 ): void;
444 function randomFill<T extends NodeJS.ArrayBufferView>(
445 buffer: T,
446 offset: number,
447 size: number,
448 callback: (err: Error | null, buf: T) => void,
449 ): void;
450
451 interface RandomUUIDOptions {
452 /**
453 * By default, to improve performance,
454 * Node.js will pre-emptively generate and persistently cache enough
455 * random data to generate up to 128 random UUIDs. To generate a UUID
456 * without using the cache, set `disableEntropyCache` to `true`.
457 *
458 * @default `false`
459 */
460 disableEntropyCache?: boolean | undefined;
461 }
462
463 function randomUUID(options?: RandomUUIDOptions): string;
464
465 interface ScryptOptions {
466 cost?: number | undefined;
467 blockSize?: number | undefined;
468 parallelization?: number | undefined;
469 N?: number | undefined;
470 r?: number | undefined;
471 p?: number | undefined;
472 maxmem?: number | undefined;
473 }
474 function scrypt(
475 password: BinaryLike,
476 salt: BinaryLike,
477 keylen: number,
478 callback: (err: Error | null, derivedKey: Buffer) => void,
479 ): void;
480 function scrypt(
481 password: BinaryLike,
482 salt: BinaryLike,
483 keylen: number,
484 options: ScryptOptions,
485 callback: (err: Error | null, derivedKey: Buffer) => void,
486 ): void;
487 function scryptSync(password: BinaryLike, salt: BinaryLike, keylen: number, options?: ScryptOptions): Buffer;
488
489 interface RsaPublicKey {
490 key: KeyLike;
491 padding?: number | undefined;
492 }
493 interface RsaPrivateKey {
494 key: KeyLike;
495 passphrase?: string | undefined;
496 /**
497 * @default 'sha1'
498 */
499 oaepHash?: string | undefined;
500 oaepLabel?: NodeJS.TypedArray | undefined;
501 padding?: number | undefined;
502 }
503 function publicEncrypt(key: RsaPublicKey | RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
504 function publicDecrypt(key: RsaPublicKey | RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
505 function privateDecrypt(private_key: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
506 function privateEncrypt(private_key: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
507 function getCiphers(): string[];
508 function getCurves(): string[];
509 function getFips(): 1 | 0;
510 function getHashes(): string[];
511 class ECDH {
512 private constructor();
513 static convertKey(
514 key: BinaryLike,
515 curve: string,
516 inputEncoding?: BinaryToTextEncoding,
517 outputEncoding?: 'latin1' | 'hex' | 'base64',
518 format?: 'uncompressed' | 'compressed' | 'hybrid',
519 ): Buffer | string;
520 generateKeys(): Buffer;
521 generateKeys(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string;
522 computeSecret(other_public_key: NodeJS.ArrayBufferView): Buffer;
523 computeSecret(other_public_key: string, input_encoding: BinaryToTextEncoding): Buffer;
524 computeSecret(other_public_key: NodeJS.ArrayBufferView, output_encoding: BinaryToTextEncoding): string;
525 computeSecret(
526 other_public_key: string,
527 input_encoding: BinaryToTextEncoding,
528 output_encoding: BinaryToTextEncoding,
529 ): string;
530 getPrivateKey(): Buffer;
531 getPrivateKey(encoding: BinaryToTextEncoding): string;
532 getPublicKey(): Buffer;
533 getPublicKey(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string;
534 setPrivateKey(private_key: NodeJS.ArrayBufferView): void;
535 setPrivateKey(private_key: string, encoding: BinaryToTextEncoding): void;
536 }
537 function createECDH(curve_name: string): ECDH;
538 function timingSafeEqual(a: NodeJS.ArrayBufferView, b: NodeJS.ArrayBufferView): boolean;
539 /** @deprecated since v10.0.0 */
540 const DEFAULT_ENCODING: BufferEncoding;
541
542 type KeyType = 'rsa' | 'dsa' | 'ec' | 'ed25519' | 'ed448' | 'x25519' | 'x448';
543 type KeyFormat = 'pem' | 'der';
544
545 interface BasePrivateKeyEncodingOptions<T extends KeyFormat> {
546 format: T;
547 cipher?: string | undefined;
548 passphrase?: string | undefined;
549 }
550
551 interface KeyPairKeyObjectResult {
552 publicKey: KeyObject;
553 privateKey: KeyObject;
554 }
555
556 interface ED25519KeyPairKeyObjectOptions {
557 /**
558 * No options.
559 */
560 }
561
562 interface ED448KeyPairKeyObjectOptions {
563 /**
564 * No options.
565 */
566 }
567
568 interface X25519KeyPairKeyObjectOptions {
569 /**
570 * No options.
571 */
572 }
573
574 interface X448KeyPairKeyObjectOptions {
575 /**
576 * No options.
577 */
578 }
579
580 interface ECKeyPairKeyObjectOptions {
581 /**
582 * Name of the curve to use.
583 */
584 namedCurve: string;
585 }
586
587 interface RSAKeyPairKeyObjectOptions {
588 /**
589 * Key size in bits
590 */
591 modulusLength: number;
592
593 /**
594 * @default 0x10001
595 */
596 publicExponent?: number | undefined;
597 }
598
599 interface DSAKeyPairKeyObjectOptions {
600 /**
601 * Key size in bits
602 */
603 modulusLength: number;
604
605 /**
606 * Size of q in bits
607 */
608 divisorLength: number;
609 }
610
611 interface RSAKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
612 /**
613 * Key size in bits
614 */
615 modulusLength: number;
616 /**
617 * @default 0x10001
618 */
619 publicExponent?: number | undefined;
620
621 publicKeyEncoding: {
622 type: 'pkcs1' | 'spki';
623 format: PubF;
624 };
625 privateKeyEncoding: BasePrivateKeyEncodingOptions<PrivF> & {
626 type: 'pkcs1' | 'pkcs8';
627 };
628 }
629
630 interface DSAKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
631 /**
632 * Key size in bits
633 */
634 modulusLength: number;
635 /**
636 * Size of q in bits
637 */
638 divisorLength: number;
639
640 publicKeyEncoding: {
641 type: 'spki';
642 format: PubF;
643 };
644 privateKeyEncoding: BasePrivateKeyEncodingOptions<PrivF> & {
645 type: 'pkcs8';
646 };
647 }
648
649 interface ECKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
650 /**
651 * Name of the curve to use.
652 */
653 namedCurve: string;
654
655 publicKeyEncoding: {
656 type: 'pkcs1' | 'spki';
657 format: PubF;
658 };
659 privateKeyEncoding: BasePrivateKeyEncodingOptions<PrivF> & {
660 type: 'sec1' | 'pkcs8';
661 };
662 }
663
664 interface ED25519KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
665 publicKeyEncoding: {
666 type: 'spki';
667 format: PubF;
668 };
669 privateKeyEncoding: BasePrivateKeyEncodingOptions<PrivF> & {
670 type: 'pkcs8';
671 };
672 }
673
674 interface ED448KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
675 publicKeyEncoding: {
676 type: 'spki';
677 format: PubF;
678 };
679 privateKeyEncoding: BasePrivateKeyEncodingOptions<PrivF> & {
680 type: 'pkcs8';
681 };
682 }
683
684 interface X25519KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
685 publicKeyEncoding: {
686 type: 'spki';
687 format: PubF;
688 };
689 privateKeyEncoding: BasePrivateKeyEncodingOptions<PrivF> & {
690 type: 'pkcs8';
691 };
692 }
693
694 interface X448KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
695 publicKeyEncoding: {
696 type: 'spki';
697 format: PubF;
698 };
699 privateKeyEncoding: BasePrivateKeyEncodingOptions<PrivF> & {
700 type: 'pkcs8';
701 };
702 }
703
704 interface KeyPairSyncResult<T1 extends string | Buffer, T2 extends string | Buffer> {
705 publicKey: T1;
706 privateKey: T2;
707 }
708
709 function generateKeyPairSync(
710 type: 'rsa',
711 options: RSAKeyPairOptions<'pem', 'pem'>,
712 ): KeyPairSyncResult<string, string>;
713 function generateKeyPairSync(
714 type: 'rsa',
715 options: RSAKeyPairOptions<'pem', 'der'>,
716 ): KeyPairSyncResult<string, Buffer>;
717 function generateKeyPairSync(
718 type: 'rsa',
719 options: RSAKeyPairOptions<'der', 'pem'>,
720 ): KeyPairSyncResult<Buffer, string>;
721 function generateKeyPairSync(
722 type: 'rsa',
723 options: RSAKeyPairOptions<'der', 'der'>,
724 ): KeyPairSyncResult<Buffer, Buffer>;
725 function generateKeyPairSync(type: 'rsa', options: RSAKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
726
727 function generateKeyPairSync(
728 type: 'dsa',
729 options: DSAKeyPairOptions<'pem', 'pem'>,
730 ): KeyPairSyncResult<string, string>;
731 function generateKeyPairSync(
732 type: 'dsa',
733 options: DSAKeyPairOptions<'pem', 'der'>,
734 ): KeyPairSyncResult<string, Buffer>;
735 function generateKeyPairSync(
736 type: 'dsa',
737 options: DSAKeyPairOptions<'der', 'pem'>,
738 ): KeyPairSyncResult<Buffer, string>;
739 function generateKeyPairSync(
740 type: 'dsa',
741 options: DSAKeyPairOptions<'der', 'der'>,
742 ): KeyPairSyncResult<Buffer, Buffer>;
743 function generateKeyPairSync(type: 'dsa', options: DSAKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
744
745 function generateKeyPairSync(
746 type: 'ec',
747 options: ECKeyPairOptions<'pem', 'pem'>,
748 ): KeyPairSyncResult<string, string>;
749 function generateKeyPairSync(
750 type: 'ec',
751 options: ECKeyPairOptions<'pem', 'der'>,
752 ): KeyPairSyncResult<string, Buffer>;
753 function generateKeyPairSync(
754 type: 'ec',
755 options: ECKeyPairOptions<'der', 'pem'>,
756 ): KeyPairSyncResult<Buffer, string>;
757 function generateKeyPairSync(
758 type: 'ec',
759 options: ECKeyPairOptions<'der', 'der'>,
760 ): KeyPairSyncResult<Buffer, Buffer>;
761 function generateKeyPairSync(type: 'ec', options: ECKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
762
763 function generateKeyPairSync(
764 type: 'ed25519',
765 options: ED25519KeyPairOptions<'pem', 'pem'>,
766 ): KeyPairSyncResult<string, string>;
767 function generateKeyPairSync(
768 type: 'ed25519',
769 options: ED25519KeyPairOptions<'pem', 'der'>,
770 ): KeyPairSyncResult<string, Buffer>;
771 function generateKeyPairSync(
772 type: 'ed25519',
773 options: ED25519KeyPairOptions<'der', 'pem'>,
774 ): KeyPairSyncResult<Buffer, string>;
775 function generateKeyPairSync(
776 type: 'ed25519',
777 options: ED25519KeyPairOptions<'der', 'der'>,
778 ): KeyPairSyncResult<Buffer, Buffer>;
779 function generateKeyPairSync(type: 'ed25519', options?: ED25519KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
780
781 function generateKeyPairSync(
782 type: 'ed448',
783 options: ED448KeyPairOptions<'pem', 'pem'>,
784 ): KeyPairSyncResult<string, string>;
785 function generateKeyPairSync(
786 type: 'ed448',
787 options: ED448KeyPairOptions<'pem', 'der'>,
788 ): KeyPairSyncResult<string, Buffer>;
789 function generateKeyPairSync(
790 type: 'ed448',
791 options: ED448KeyPairOptions<'der', 'pem'>,
792 ): KeyPairSyncResult<Buffer, string>;
793 function generateKeyPairSync(
794 type: 'ed448',
795 options: ED448KeyPairOptions<'der', 'der'>,
796 ): KeyPairSyncResult<Buffer, Buffer>;
797 function generateKeyPairSync(type: 'ed448', options?: ED448KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
798
799 function generateKeyPairSync(
800 type: 'x25519',
801 options: X25519KeyPairOptions<'pem', 'pem'>,
802 ): KeyPairSyncResult<string, string>;
803 function generateKeyPairSync(
804 type: 'x25519',
805 options: X25519KeyPairOptions<'pem', 'der'>,
806 ): KeyPairSyncResult<string, Buffer>;
807 function generateKeyPairSync(
808 type: 'x25519',
809 options: X25519KeyPairOptions<'der', 'pem'>,
810 ): KeyPairSyncResult<Buffer, string>;
811 function generateKeyPairSync(
812 type: 'x25519',
813 options: X25519KeyPairOptions<'der', 'der'>,
814 ): KeyPairSyncResult<Buffer, Buffer>;
815 function generateKeyPairSync(type: 'x25519', options?: X25519KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
816
817 function generateKeyPairSync(
818 type: 'x448',
819 options: X448KeyPairOptions<'pem', 'pem'>,
820 ): KeyPairSyncResult<string, string>;
821 function generateKeyPairSync(
822 type: 'x448',
823 options: X448KeyPairOptions<'pem', 'der'>,
824 ): KeyPairSyncResult<string, Buffer>;
825 function generateKeyPairSync(
826 type: 'x448',
827 options: X448KeyPairOptions<'der', 'pem'>,
828 ): KeyPairSyncResult<Buffer, string>;
829 function generateKeyPairSync(
830 type: 'x448',
831 options: X448KeyPairOptions<'der', 'der'>,
832 ): KeyPairSyncResult<Buffer, Buffer>;
833 function generateKeyPairSync(type: 'x448', options?: X448KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
834
835 function generateKeyPair(
836 type: 'rsa',
837 options: RSAKeyPairOptions<'pem', 'pem'>,
838 callback: (err: Error | null, publicKey: string, privateKey: string) => void,
839 ): void;
840 function generateKeyPair(
841 type: 'rsa',
842 options: RSAKeyPairOptions<'pem', 'der'>,
843 callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
844 ): void;
845 function generateKeyPair(
846 type: 'rsa',
847 options: RSAKeyPairOptions<'der', 'pem'>,
848 callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
849 ): void;
850 function generateKeyPair(
851 type: 'rsa',
852 options: RSAKeyPairOptions<'der', 'der'>,
853 callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
854 ): void;
855 function generateKeyPair(
856 type: 'rsa',
857 options: RSAKeyPairKeyObjectOptions,
858 callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
859 ): void;
860
861 function generateKeyPair(
862 type: 'dsa',
863 options: DSAKeyPairOptions<'pem', 'pem'>,
864 callback: (err: Error | null, publicKey: string, privateKey: string) => void,
865 ): void;
866 function generateKeyPair(
867 type: 'dsa',
868 options: DSAKeyPairOptions<'pem', 'der'>,
869 callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
870 ): void;
871 function generateKeyPair(
872 type: 'dsa',
873 options: DSAKeyPairOptions<'der', 'pem'>,
874 callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
875 ): void;
876 function generateKeyPair(
877 type: 'dsa',
878 options: DSAKeyPairOptions<'der', 'der'>,
879 callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
880 ): void;
881 function generateKeyPair(
882 type: 'dsa',
883 options: DSAKeyPairKeyObjectOptions,
884 callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
885 ): void;
886
887 function generateKeyPair(
888 type: 'ec',
889 options: ECKeyPairOptions<'pem', 'pem'>,
890 callback: (err: Error | null, publicKey: string, privateKey: string) => void,
891 ): void;
892 function generateKeyPair(
893 type: 'ec',
894 options: ECKeyPairOptions<'pem', 'der'>,
895 callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
896 ): void;
897 function generateKeyPair(
898 type: 'ec',
899 options: ECKeyPairOptions<'der', 'pem'>,
900 callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
901 ): void;
902 function generateKeyPair(
903 type: 'ec',
904 options: ECKeyPairOptions<'der', 'der'>,
905 callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
906 ): void;
907 function generateKeyPair(
908 type: 'ec',
909 options: ECKeyPairKeyObjectOptions,
910 callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
911 ): void;
912
913 function generateKeyPair(
914 type: 'ed25519',
915 options: ED25519KeyPairOptions<'pem', 'pem'>,
916 callback: (err: Error | null, publicKey: string, privateKey: string) => void,
917 ): void;
918 function generateKeyPair(
919 type: 'ed25519',
920 options: ED25519KeyPairOptions<'pem', 'der'>,
921 callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
922 ): void;
923 function generateKeyPair(
924 type: 'ed25519',
925 options: ED25519KeyPairOptions<'der', 'pem'>,
926 callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
927 ): void;
928 function generateKeyPair(
929 type: 'ed25519',
930 options: ED25519KeyPairOptions<'der', 'der'>,
931 callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
932 ): void;
933 function generateKeyPair(
934 type: 'ed25519',
935 options: ED25519KeyPairKeyObjectOptions | undefined,
936 callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
937 ): void;
938
939 function generateKeyPair(
940 type: 'ed448',
941 options: ED448KeyPairOptions<'pem', 'pem'>,
942 callback: (err: Error | null, publicKey: string, privateKey: string) => void,
943 ): void;
944 function generateKeyPair(
945 type: 'ed448',
946 options: ED448KeyPairOptions<'pem', 'der'>,
947 callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
948 ): void;
949 function generateKeyPair(
950 type: 'ed448',
951 options: ED448KeyPairOptions<'der', 'pem'>,
952 callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
953 ): void;
954 function generateKeyPair(
955 type: 'ed448',
956 options: ED448KeyPairOptions<'der', 'der'>,
957 callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
958 ): void;
959 function generateKeyPair(
960 type: 'ed448',
961 options: ED448KeyPairKeyObjectOptions | undefined,
962 callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
963 ): void;
964
965 function generateKeyPair(
966 type: 'x25519',
967 options: X25519KeyPairOptions<'pem', 'pem'>,
968 callback: (err: Error | null, publicKey: string, privateKey: string) => void,
969 ): void;
970 function generateKeyPair(
971 type: 'x25519',
972 options: X25519KeyPairOptions<'pem', 'der'>,
973 callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
974 ): void;
975 function generateKeyPair(
976 type: 'x25519',
977 options: X25519KeyPairOptions<'der', 'pem'>,
978 callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
979 ): void;
980 function generateKeyPair(
981 type: 'x25519',
982 options: X25519KeyPairOptions<'der', 'der'>,
983 callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
984 ): void;
985 function generateKeyPair(
986 type: 'x25519',
987 options: X25519KeyPairKeyObjectOptions | undefined,
988 callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
989 ): void;
990
991 function generateKeyPair(
992 type: 'x448',
993 options: X448KeyPairOptions<'pem', 'pem'>,
994 callback: (err: Error | null, publicKey: string, privateKey: string) => void,
995 ): void;
996 function generateKeyPair(
997 type: 'x448',
998 options: X448KeyPairOptions<'pem', 'der'>,
999 callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
1000 ): void;
1001 function generateKeyPair(
1002 type: 'x448',
1003 options: X448KeyPairOptions<'der', 'pem'>,
1004 callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
1005 ): void;
1006 function generateKeyPair(
1007 type: 'x448',
1008 options: X448KeyPairOptions<'der', 'der'>,
1009 callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
1010 ): void;
1011 function generateKeyPair(
1012 type: 'x448',
1013 options: X448KeyPairKeyObjectOptions | undefined,
1014 callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
1015 ): void;
1016
1017 namespace generateKeyPair {
1018 function __promisify__(
1019 type: 'rsa',
1020 options: RSAKeyPairOptions<'pem', 'pem'>,
1021 ): Promise<{ publicKey: string; privateKey: string }>;
1022 function __promisify__(
1023 type: 'rsa',
1024 options: RSAKeyPairOptions<'pem', 'der'>,
1025 ): Promise<{ publicKey: string; privateKey: Buffer }>;
1026 function __promisify__(
1027 type: 'rsa',
1028 options: RSAKeyPairOptions<'der', 'pem'>,
1029 ): Promise<{ publicKey: Buffer; privateKey: string }>;
1030 function __promisify__(
1031 type: 'rsa',
1032 options: RSAKeyPairOptions<'der', 'der'>,
1033 ): Promise<{ publicKey: Buffer; privateKey: Buffer }>;
1034 function __promisify__(type: 'rsa', options: RSAKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
1035
1036 function __promisify__(
1037 type: 'dsa',
1038 options: DSAKeyPairOptions<'pem', 'pem'>,
1039 ): Promise<{ publicKey: string; privateKey: string }>;
1040 function __promisify__(
1041 type: 'dsa',
1042 options: DSAKeyPairOptions<'pem', 'der'>,
1043 ): Promise<{ publicKey: string; privateKey: Buffer }>;
1044 function __promisify__(
1045 type: 'dsa',
1046 options: DSAKeyPairOptions<'der', 'pem'>,
1047 ): Promise<{ publicKey: Buffer; privateKey: string }>;
1048 function __promisify__(
1049 type: 'dsa',
1050 options: DSAKeyPairOptions<'der', 'der'>,
1051 ): Promise<{ publicKey: Buffer; privateKey: Buffer }>;
1052 function __promisify__(type: 'dsa', options: DSAKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
1053
1054 function __promisify__(
1055 type: 'ec',
1056 options: ECKeyPairOptions<'pem', 'pem'>,
1057 ): Promise<{ publicKey: string; privateKey: string }>;
1058 function __promisify__(
1059 type: 'ec',
1060 options: ECKeyPairOptions<'pem', 'der'>,
1061 ): Promise<{ publicKey: string; privateKey: Buffer }>;
1062 function __promisify__(
1063 type: 'ec',
1064 options: ECKeyPairOptions<'der', 'pem'>,
1065 ): Promise<{ publicKey: Buffer; privateKey: string }>;
1066 function __promisify__(
1067 type: 'ec',
1068 options: ECKeyPairOptions<'der', 'der'>,
1069 ): Promise<{ publicKey: Buffer; privateKey: Buffer }>;
1070 function __promisify__(type: 'ec', options: ECKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
1071
1072 function __promisify__(
1073 type: 'ed25519',
1074 options: ED25519KeyPairOptions<'pem', 'pem'>,
1075 ): Promise<{ publicKey: string; privateKey: string }>;
1076 function __promisify__(
1077 type: 'ed25519',
1078 options: ED25519KeyPairOptions<'pem', 'der'>,
1079 ): Promise<{ publicKey: string; privateKey: Buffer }>;
1080 function __promisify__(
1081 type: 'ed25519',
1082 options: ED25519KeyPairOptions<'der', 'pem'>,
1083 ): Promise<{ publicKey: Buffer; privateKey: string }>;
1084 function __promisify__(
1085 type: 'ed25519',
1086 options: ED25519KeyPairOptions<'der', 'der'>,
1087 ): Promise<{ publicKey: Buffer; privateKey: Buffer }>;
1088 function __promisify__(
1089 type: 'ed25519',
1090 options?: ED25519KeyPairKeyObjectOptions,
1091 ): Promise<KeyPairKeyObjectResult>;
1092
1093 function __promisify__(
1094 type: 'ed448',
1095 options: ED448KeyPairOptions<'pem', 'pem'>,
1096 ): Promise<{ publicKey: string; privateKey: string }>;
1097 function __promisify__(
1098 type: 'ed448',
1099 options: ED448KeyPairOptions<'pem', 'der'>,
1100 ): Promise<{ publicKey: string; privateKey: Buffer }>;
1101 function __promisify__(
1102 type: 'ed448',
1103 options: ED448KeyPairOptions<'der', 'pem'>,
1104 ): Promise<{ publicKey: Buffer; privateKey: string }>;
1105 function __promisify__(
1106 type: 'ed448',
1107 options: ED448KeyPairOptions<'der', 'der'>,
1108 ): Promise<{ publicKey: Buffer; privateKey: Buffer }>;
1109 function __promisify__(type: 'ed448', options?: ED448KeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
1110
1111 function __promisify__(
1112 type: 'x25519',
1113 options: X25519KeyPairOptions<'pem', 'pem'>,
1114 ): Promise<{ publicKey: string; privateKey: string }>;
1115 function __promisify__(
1116 type: 'x25519',
1117 options: X25519KeyPairOptions<'pem', 'der'>,
1118 ): Promise<{ publicKey: string; privateKey: Buffer }>;
1119 function __promisify__(
1120 type: 'x25519',
1121 options: X25519KeyPairOptions<'der', 'pem'>,
1122 ): Promise<{ publicKey: Buffer; privateKey: string }>;
1123 function __promisify__(
1124 type: 'x25519',
1125 options: X25519KeyPairOptions<'der', 'der'>,
1126 ): Promise<{ publicKey: Buffer; privateKey: Buffer }>;
1127 function __promisify__(
1128 type: 'x25519',
1129 options?: X25519KeyPairKeyObjectOptions,
1130 ): Promise<KeyPairKeyObjectResult>;
1131
1132 function __promisify__(
1133 type: 'x448',
1134 options: X448KeyPairOptions<'pem', 'pem'>,
1135 ): Promise<{ publicKey: string; privateKey: string }>;
1136 function __promisify__(
1137 type: 'x448',
1138 options: X448KeyPairOptions<'pem', 'der'>,
1139 ): Promise<{ publicKey: string; privateKey: Buffer }>;
1140 function __promisify__(
1141 type: 'x448',
1142 options: X448KeyPairOptions<'der', 'pem'>,
1143 ): Promise<{ publicKey: Buffer; privateKey: string }>;
1144 function __promisify__(
1145 type: 'x448',
1146 options: X448KeyPairOptions<'der', 'der'>,
1147 ): Promise<{ publicKey: Buffer; privateKey: Buffer }>;
1148 function __promisify__(type: 'x448', options?: X448KeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
1149 }
1150
1151 /**
1152 * Calculates and returns the signature for `data` using the given private key and
1153 * algorithm. If `algorithm` is `null` or `undefined`, then the algorithm is
1154 * dependent upon the key type (especially Ed25519 and Ed448).
1155 *
1156 * If `key` is not a [`KeyObject`][], this function behaves as if `key` had been
1157 * passed to [`crypto.createPrivateKey()`][].
1158 */
1159 function sign(
1160 algorithm: string | null | undefined,
1161 data: NodeJS.ArrayBufferView,
1162 key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput,
1163 ): Buffer;
1164
1165 /**
1166 * Calculates and returns the signature for `data` using the given private key and
1167 * algorithm. If `algorithm` is `null` or `undefined`, then the algorithm is
1168 * dependent upon the key type (especially Ed25519 and Ed448).
1169 *
1170 * If `key` is not a [`KeyObject`][], this function behaves as if `key` had been
1171 * passed to [`crypto.createPublicKey()`][].
1172 */
1173 function verify(
1174 algorithm: string | null | undefined,
1175 data: NodeJS.ArrayBufferView,
1176 key: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput,
1177 signature: NodeJS.ArrayBufferView,
1178 ): boolean;
1179
1180 /**
1181 * Computes the Diffie-Hellman secret based on a privateKey and a publicKey.
1182 * Both keys must have the same asymmetricKeyType, which must be one of
1183 * 'dh' (for Diffie-Hellman), 'ec' (for ECDH), 'x448', or 'x25519' (for ECDH-ES).
1184 */
1185 function diffieHellman(options: { privateKey: KeyObject; publicKey: KeyObject }): Buffer;
1186}