@types/node 16.4.14 → 16.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
node/crypto.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.
4
4
  *
5
5
  * ```js
6
- * import { createHmac } from 'crypto';
6
+ * const { createHmac } = await import('crypto');
7
7
  *
8
8
  * const secret = 'abcdefg';
9
9
  * const hash = createHmac('sha256', secret)
@@ -13,19 +13,7 @@
13
13
  * // Prints:
14
14
  * // c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e
15
15
  * ```
16
- *
17
- * ```js
18
- * const crypto = require('crypto');
19
- *
20
- * const secret = 'abcdefg';
21
- * const hash = crypto.createHmac('sha256', secret)
22
- * .update('I love cupcakes')
23
- * .digest('hex');
24
- * console.log(hash);
25
- * // Prints:
26
- * // c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e
27
- * ```
28
- * @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/crypto.js)
16
+ * @see [source](https://github.com/nodejs/node/blob/v16.7.0/lib/crypto.js)
29
17
  */
30
18
  declare module 'crypto' {
31
19
  import * as stream from 'node:stream';
@@ -193,38 +181,12 @@ declare module 'crypto' {
193
181
  * import {
194
182
  * createReadStream
195
183
  * } from 'fs';
196
- *
184
+ * import { argv } from 'process';
197
185
  * const {
198
- * createHash,
186
+ * createHash
199
187
  * } = await import('crypto');
200
188
  *
201
- * const filename = process.argv[2];
202
- *
203
- * const hash = createHash('sha256');
204
- *
205
- * const input = createReadStream(filename);
206
- * input.on('readable', () => {
207
- * // Only one element is going to be produced by the
208
- * // hash stream.
209
- * const data = input.read();
210
- * if (data)
211
- * hash.update(data);
212
- * else {
213
- * console.log(`${hash.digest('hex')} ${filename}`);
214
- * }
215
- * });
216
- * ```
217
- *
218
- * ```js
219
- * const {
220
- * createReadStream,
221
- * } = require('fs');
222
- *
223
- * const {
224
- * createHash,
225
- * } = require('crypto');
226
- *
227
- * const filename = process.argv[2];
189
+ * const filename = argv[2];
228
190
  *
229
191
  * const hash = createHash('sha256');
230
192
  *
@@ -262,38 +224,12 @@ declare module 'crypto' {
262
224
  * import {
263
225
  * createReadStream
264
226
  * } from 'fs';
265
- *
227
+ * import { argv } from 'process';
266
228
  * const {
267
- * createHmac,
229
+ * createHmac
268
230
  * } = await import('crypto');
269
231
  *
270
- * const filename = process.argv[2];
271
- *
272
- * const hmac = createHmac('sha256', 'a secret');
273
- *
274
- * const input = createReadStream(filename);
275
- * input.on('readable', () => {
276
- * // Only one element is going to be produced by the
277
- * // hash stream.
278
- * const data = input.read();
279
- * if (data)
280
- * hmac.update(data);
281
- * else {
282
- * console.log(`${hmac.digest('hex')} ${filename}`);
283
- * }
284
- * });
285
- * ```
286
- *
287
- * ```js
288
- * const {
289
- * createReadStream,
290
- * } = require('fs');
291
- *
292
- * const {
293
- * createHmac,
294
- * } = require('crypto');
295
- *
296
- * const filename = process.argv[2];
232
+ * const filename = argv[2];
297
233
  *
298
234
  * const hmac = createHmac('sha256', 'a secret');
299
235
  *
@@ -334,7 +270,7 @@ declare module 'crypto' {
334
270
  *
335
271
  * ```js
336
272
  * const {
337
- * createHash,
273
+ * createHash
338
274
  * } = await import('crypto');
339
275
  *
340
276
  * const hash = createHash('sha256');
@@ -354,62 +290,24 @@ declare module 'crypto' {
354
290
  * hash.end();
355
291
  * ```
356
292
  *
357
- * ```js
358
- * const {
359
- * createHash,
360
- * } = require('crypto');
361
- *
362
- * const hash = createHash('sha256');
363
- *
364
- * hash.on('readable', () => {
365
- * // Only one element is going to be produced by the
366
- * // hash stream.
367
- * const data = hash.read();
368
- * if (data) {
369
- * console.log(data.toString('hex'));
370
- * // Prints:
371
- * // 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
372
- * }
373
- * });
374
- *
375
- * hash.write('some data to hash');
376
- * hash.end();
377
- * ```
378
- *
379
293
  * Example: Using `Hash` and piped streams:
380
294
  *
381
295
  * ```js
382
296
  * import { createReadStream } from 'fs';
383
- *
384
- * const {
385
- * createHash,
386
- * } = await import('crypto');
387
- * const hash = createHash('sha256');
388
- *
389
- * const input = createReadStream('test.js');
390
- * input.pipe(hash).setEncoding('hex').pipe(process.stdout);
391
- * ```
392
- *
393
- * ```js
394
- * const {
395
- * createReadStream,
396
- * } = require('fs');
397
- *
398
- * const {
399
- * createHash,
400
- * } = require('crypto');
297
+ * import { stdout } from 'process';
298
+ * const { createHash } = await import('crypto');
401
299
  *
402
300
  * const hash = createHash('sha256');
403
301
  *
404
302
  * const input = createReadStream('test.js');
405
- * input.pipe(hash).setEncoding('hex').pipe(process.stdout);
303
+ * input.pipe(hash).setEncoding('hex').pipe(stdout);
406
304
  * ```
407
305
  *
408
306
  * Example: Using the `hash.update()` and `hash.digest()` methods:
409
307
  *
410
308
  * ```js
411
309
  * const {
412
- * createHash,
310
+ * createHash
413
311
  * } = await import('crypto');
414
312
  *
415
313
  * const hash = createHash('sha256');
@@ -419,19 +317,6 @@ declare module 'crypto' {
419
317
  * // Prints:
420
318
  * // 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
421
319
  * ```
422
- *
423
- * ```js
424
- * const {
425
- * createHash,
426
- * } = require('crypto');
427
- *
428
- * const hash = createHash('sha256');
429
- *
430
- * hash.update('some data to hash');
431
- * console.log(hash.digest('hex'));
432
- * // Prints:
433
- * // 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
434
- * ```
435
320
  * @since v0.1.92
436
321
  */
437
322
  class Hash extends stream.Transform {
@@ -450,7 +335,7 @@ declare module 'crypto' {
450
335
  * ```js
451
336
  * // Calculate a rolling hash.
452
337
  * const {
453
- * createHash,
338
+ * createHash
454
339
  * } = await import('crypto');
455
340
  *
456
341
  * const hash = createHash('sha256');
@@ -466,26 +351,6 @@ declare module 'crypto' {
466
351
  *
467
352
  * // Etc.
468
353
  * ```
469
- *
470
- * ```js
471
- * // Calculate a rolling hash.
472
- * const {
473
- * createHash,
474
- * } = require('crypto');
475
- *
476
- * const hash = createHash('sha256');
477
- *
478
- * hash.update('one');
479
- * console.log(hash.copy().digest('hex'));
480
- *
481
- * hash.update('two');
482
- * console.log(hash.copy().digest('hex'));
483
- *
484
- * hash.update('three');
485
- * console.log(hash.copy().digest('hex'));
486
- *
487
- * // Etc.
488
- * ```
489
354
  * @since v13.1.0
490
355
  * @param options `stream.transform` options
491
356
  */
@@ -530,7 +395,7 @@ declare module 'crypto' {
530
395
  *
531
396
  * ```js
532
397
  * const {
533
- * createHmac,
398
+ * createHmac
534
399
  * } = await import('crypto');
535
400
  *
536
401
  * const hmac = createHmac('sha256', 'a secret');
@@ -550,63 +415,26 @@ declare module 'crypto' {
550
415
  * hmac.end();
551
416
  * ```
552
417
  *
553
- * ```js
554
- * const {
555
- * createHmac,
556
- * } = require('crypto');
557
- *
558
- * const hmac = createHmac('sha256', 'a secret');
559
- *
560
- * hmac.on('readable', () => {
561
- * // Only one element is going to be produced by the
562
- * // hash stream.
563
- * const data = hmac.read();
564
- * if (data) {
565
- * console.log(data.toString('hex'));
566
- * // Prints:
567
- * // 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e
568
- * }
569
- * });
570
- *
571
- * hmac.write('some data to hash');
572
- * hmac.end();
573
- * ```
574
- *
575
418
  * Example: Using `Hmac` and piped streams:
576
419
  *
577
420
  * ```js
578
421
  * import { createReadStream } from 'fs';
579
- *
422
+ * import { stdout } from 'process';
580
423
  * const {
581
- * createHmac,
424
+ * createHmac
582
425
  * } = await import('crypto');
583
426
  *
584
427
  * const hmac = createHmac('sha256', 'a secret');
585
428
  *
586
429
  * const input = createReadStream('test.js');
587
- * input.pipe(hmac).pipe(process.stdout);
588
- * ```
589
- *
590
- * ```js
591
- * const {
592
- * createReadStream,
593
- * } = require('fs');
594
- *
595
- * const {
596
- * createHmac,
597
- * } = require('crypto');
598
- *
599
- * const hmac = createHmac('sha256', 'a secret');
600
- *
601
- * const input = createReadStream('test.js');
602
- * input.pipe(hmac).pipe(process.stdout);
430
+ * input.pipe(hmac).pipe(stdout);
603
431
  * ```
604
432
  *
605
433
  * Example: Using the `hmac.update()` and `hmac.digest()` methods:
606
434
  *
607
435
  * ```js
608
436
  * const {
609
- * createHmac,
437
+ * createHmac
610
438
  * } = await import('crypto');
611
439
  *
612
440
  * const hmac = createHmac('sha256', 'a secret');
@@ -616,19 +444,6 @@ declare module 'crypto' {
616
444
  * // Prints:
617
445
  * // 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e
618
446
  * ```
619
- *
620
- * ```js
621
- * const {
622
- * createHmac,
623
- * } = require('crypto');
624
- *
625
- * const hmac = createHmac('sha256', 'a secret');
626
- *
627
- * hmac.update('some data to hash');
628
- * console.log(hmac.digest('hex'));
629
- * // Prints:
630
- * // 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e
631
- * ```
632
447
  * @since v0.1.94
633
448
  */
634
449
  class Hmac extends stream.Transform {
@@ -921,39 +736,6 @@ declare module 'crypto' {
921
736
  * });
922
737
  * ```
923
738
  *
924
- * ```js
925
- * const {
926
- * scrypt,
927
- * randomFill,
928
- * createCipheriv
929
- * } = require('crypto');
930
- *
931
- * const algorithm = 'aes-192-cbc';
932
- * const password = 'Password used to generate key';
933
- *
934
- * // First, we'll generate the key. The key length is dependent on the algorithm.
935
- * // In this case for aes192, it is 24 bytes (192 bits).
936
- * scrypt(password, 'salt', 24, (err, key) => {
937
- * if (err) throw err;
938
- * // Then, we'll generate a random initialization vector
939
- * randomFill(new Uint8Array(16), (err, iv) => {
940
- * if (err) throw err;
941
- *
942
- * // Once we have the key and iv, we can create and use the cipher...
943
- * const cipher = createCipheriv(algorithm, key, iv);
944
- *
945
- * let encrypted = '';
946
- * cipher.setEncoding('hex');
947
- *
948
- * cipher.on('data', (chunk) => encrypted += chunk);
949
- * cipher.on('end', () => console.log(encrypted));
950
- *
951
- * cipher.write('some clear text data');
952
- * cipher.end();
953
- * });
954
- * });
955
- * ```
956
- *
957
739
  * Example: Using `Cipher` and piped streams:
958
740
  *
959
741
  * ```js
@@ -969,7 +751,7 @@ declare module 'crypto' {
969
751
  * const {
970
752
  * scrypt,
971
753
  * randomFill,
972
- * createCipheriv,
754
+ * createCipheriv
973
755
  * } = await import('crypto');
974
756
  *
975
757
  * const algorithm = 'aes-192-cbc';
@@ -995,52 +777,13 @@ declare module 'crypto' {
995
777
  * });
996
778
  * ```
997
779
  *
998
- * ```js
999
- * const {
1000
- * createReadStream,
1001
- * createWriteStream,
1002
- * } = require('fs');
1003
- *
1004
- * const {
1005
- * pipeline
1006
- * } = require('stream');
1007
- *
1008
- * const {
1009
- * scrypt,
1010
- * randomFill,
1011
- * createCipheriv,
1012
- * } = require('crypto');
1013
- *
1014
- * const algorithm = 'aes-192-cbc';
1015
- * const password = 'Password used to generate key';
1016
- *
1017
- * // First, we'll generate the key. The key length is dependent on the algorithm.
1018
- * // In this case for aes192, it is 24 bytes (192 bits).
1019
- * scrypt(password, 'salt', 24, (err, key) => {
1020
- * if (err) throw err;
1021
- * // Then, we'll generate a random initialization vector
1022
- * randomFill(new Uint8Array(16), (err, iv) => {
1023
- * if (err) throw err;
1024
- *
1025
- * const cipher = createCipheriv(algorithm, key, iv);
1026
- *
1027
- * const input = createReadStream('test.js');
1028
- * const output = createWriteStream('test.enc');
1029
- *
1030
- * pipeline(input, cipher, output, (err) => {
1031
- * if (err) throw err;
1032
- * });
1033
- * });
1034
- * });
1035
- * ```
1036
- *
1037
780
  * Example: Using the `cipher.update()` and `cipher.final()` methods:
1038
781
  *
1039
782
  * ```js
1040
783
  * const {
1041
784
  * scrypt,
1042
785
  * randomFill,
1043
- * createCipheriv,
786
+ * createCipheriv
1044
787
  * } = await import('crypto');
1045
788
  *
1046
789
  * const algorithm = 'aes-192-cbc';
@@ -1062,33 +805,6 @@ declare module 'crypto' {
1062
805
  * });
1063
806
  * });
1064
807
  * ```
1065
- *
1066
- * ```js
1067
- * const {
1068
- * scrypt,
1069
- * randomFill,
1070
- * createCipheriv,
1071
- * } = require('crypto');
1072
- *
1073
- * const algorithm = 'aes-192-cbc';
1074
- * const password = 'Password used to generate key';
1075
- *
1076
- * // First, we'll generate the key. The key length is dependent on the algorithm.
1077
- * // In this case for aes192, it is 24 bytes (192 bits).
1078
- * scrypt(password, 'salt', 24, (err, key) => {
1079
- * if (err) throw err;
1080
- * // Then, we'll generate a random initialization vector
1081
- * randomFill(new Uint8Array(16), (err, iv) => {
1082
- * if (err) throw err;
1083
- *
1084
- * const cipher = createCipheriv(algorithm, key, iv);
1085
- *
1086
- * let encrypted = cipher.update('some clear text data', 'utf8', 'hex');
1087
- * encrypted += cipher.final('hex');
1088
- * console.log(encrypted);
1089
- * });
1090
- * });
1091
- * ```
1092
808
  * @since v0.1.94
1093
809
  */
1094
810
  class Cipher extends stream.Transform {
@@ -1229,9 +945,10 @@ declare module 'crypto' {
1229
945
  * Example: Using `Decipher` objects as streams:
1230
946
  *
1231
947
  * ```js
948
+ * import { Buffer } from 'buffer';
1232
949
  * const {
1233
950
  * scryptSync,
1234
- * createDecipheriv,
951
+ * createDecipheriv
1235
952
  * } = await import('crypto');
1236
953
  *
1237
954
  * const algorithm = 'aes-192-cbc';
@@ -1263,41 +980,6 @@ declare module 'crypto' {
1263
980
  * decipher.end();
1264
981
  * ```
1265
982
  *
1266
- * ```js
1267
- * const {
1268
- * scryptSync,
1269
- * createDecipheriv,
1270
- * } = require('crypto');
1271
- *
1272
- * const algorithm = 'aes-192-cbc';
1273
- * const password = 'Password used to generate key';
1274
- * // Key length is dependent on the algorithm. In this case for aes192, it is
1275
- * // 24 bytes (192 bits).
1276
- * // Use the async `crypto.scrypt()` instead.
1277
- * const key = scryptSync(password, 'salt', 24);
1278
- * // The IV is usually passed along with the ciphertext.
1279
- * const iv = Buffer.alloc(16, 0); // Initialization vector.
1280
- *
1281
- * const decipher = createDecipheriv(algorithm, key, iv);
1282
- *
1283
- * let decrypted = '';
1284
- * decipher.on('readable', () => {
1285
- * while (null !== (chunk = decipher.read())) {
1286
- * decrypted += chunk.toString('utf8');
1287
- * }
1288
- * });
1289
- * decipher.on('end', () => {
1290
- * console.log(decrypted);
1291
- * // Prints: some clear text data
1292
- * });
1293
- *
1294
- * // Encrypted with same algorithm, key and iv.
1295
- * const encrypted =
1296
- * 'e5f79c5915c02171eec6b212d5520d44480993d7d622a7c4c2da32f6efda0ffa';
1297
- * decipher.write(encrypted, 'hex');
1298
- * decipher.end();
1299
- * ```
1300
- *
1301
983
  * Example: Using `Decipher` and piped streams:
1302
984
  *
1303
985
  * ```js
@@ -1305,10 +987,10 @@ declare module 'crypto' {
1305
987
  * createReadStream,
1306
988
  * createWriteStream,
1307
989
  * } from 'fs';
1308
- *
990
+ * import { Buffer } from 'buffer';
1309
991
  * const {
1310
992
  * scryptSync,
1311
- * createDecipheriv,
993
+ * createDecipheriv
1312
994
  * } = await import('crypto');
1313
995
  *
1314
996
  * const algorithm = 'aes-192-cbc';
@@ -1326,38 +1008,13 @@ declare module 'crypto' {
1326
1008
  * input.pipe(decipher).pipe(output);
1327
1009
  * ```
1328
1010
  *
1329
- * ```js
1330
- * const {
1331
- * createReadStream,
1332
- * createWriteStream,
1333
- * } = require('fs');
1334
- *
1335
- * const {
1336
- * scryptSync,
1337
- * createDecipheriv,
1338
- * } = require('crypto');
1339
- *
1340
- * const algorithm = 'aes-192-cbc';
1341
- * const password = 'Password used to generate key';
1342
- * // Use the async `crypto.scrypt()` instead.
1343
- * const key = scryptSync(password, 'salt', 24);
1344
- * // The IV is usually passed along with the ciphertext.
1345
- * const iv = Buffer.alloc(16, 0); // Initialization vector.
1346
- *
1347
- * const decipher = createDecipheriv(algorithm, key, iv);
1348
- *
1349
- * const input = createReadStream('test.enc');
1350
- * const output = createWriteStream('test.js');
1351
- *
1352
- * input.pipe(decipher).pipe(output);
1353
- * ```
1354
- *
1355
1011
  * Example: Using the `decipher.update()` and `decipher.final()` methods:
1356
1012
  *
1357
1013
  * ```js
1014
+ * import { Buffer } from 'buffer';
1358
1015
  * const {
1359
1016
  * scryptSync,
1360
- * createDecipheriv,
1017
+ * createDecipheriv
1361
1018
  * } = await import('crypto');
1362
1019
  *
1363
1020
  * const algorithm = 'aes-192-cbc';
@@ -1377,30 +1034,6 @@ declare module 'crypto' {
1377
1034
  * console.log(decrypted);
1378
1035
  * // Prints: some clear text data
1379
1036
  * ```
1380
- *
1381
- * ```js
1382
- * const {
1383
- * scryptSync,
1384
- * createDecipheriv,
1385
- * } = require('crypto');
1386
- *
1387
- * const algorithm = 'aes-192-cbc';
1388
- * const password = 'Password used to generate key';
1389
- * // Use the async `crypto.scrypt()` instead.
1390
- * const key = scryptSync(password, 'salt', 24);
1391
- * // The IV is usually passed along with the ciphertext.
1392
- * const iv = Buffer.alloc(16, 0); // Initialization vector.
1393
- *
1394
- * const decipher = createDecipheriv(algorithm, key, iv);
1395
- *
1396
- * // Encrypted using same algorithm, key and iv.
1397
- * const encrypted =
1398
- * 'e5f79c5915c02171eec6b212d5520d44480993d7d622a7c4c2da32f6efda0ffa';
1399
- * let decrypted = decipher.update(encrypted, 'hex', 'utf8');
1400
- * decrypted += decipher.final('utf8');
1401
- * console.log(decrypted);
1402
- * // Prints: some clear text data
1403
- * ```
1404
1037
  * @since v0.1.94
1405
1038
  */
1406
1039
  class Decipher extends stream.Transform {
@@ -1481,7 +1114,7 @@ declare module 'crypto' {
1481
1114
  *
1482
1115
  * ```js
1483
1116
  * const {
1484
- * generateKey,
1117
+ * generateKey
1485
1118
  * } = await import('crypto');
1486
1119
  *
1487
1120
  * generateKey('hmac', { length: 64 }, (err, key) => {
@@ -1489,17 +1122,6 @@ declare module 'crypto' {
1489
1122
  * console.log(key.export().toString('hex')); // 46e..........620
1490
1123
  * });
1491
1124
  * ```
1492
- *
1493
- * ```js
1494
- * const {
1495
- * generateKey,
1496
- * } = require('crypto');
1497
- *
1498
- * generateKey('hmac', { length: 64 }, (err, key) => {
1499
- * if (err) throw err;
1500
- * console.log(key.export().toString('hex')); // 46e..........620
1501
- * });
1502
- * ```
1503
1125
  * @since v15.0.0
1504
1126
  * @param type The intended use of the generated secret key. Currently accepted values are `'hmac'` and `'aes'`.
1505
1127
  */
@@ -1595,7 +1217,7 @@ declare module 'crypto' {
1595
1217
  * const {
1596
1218
  * generateKeyPairSync,
1597
1219
  * createSign,
1598
- * createVerify,
1220
+ * createVerify
1599
1221
  * } = await import('crypto');
1600
1222
  *
1601
1223
  * const { privateKey, publicKey } = generateKeyPairSync('ec', {
@@ -1614,36 +1236,13 @@ declare module 'crypto' {
1614
1236
  * // Prints: true
1615
1237
  * ```
1616
1238
  *
1617
- * ```js
1618
- * const {
1619
- * generateKeyPairSync,
1620
- * createSign,
1621
- * createVerify,
1622
- * } = require('crypto');
1623
- *
1624
- * const { privateKey, publicKey } = generateKeyPairSync('ec', {
1625
- * namedCurve: 'sect239k1'
1626
- * });
1627
- *
1628
- * const sign = createSign('SHA256');
1629
- * sign.write('some data to sign');
1630
- * sign.end();
1631
- * const signature = sign.sign(privateKey, 'hex');
1632
- *
1633
- * const verify = createVerify('SHA256');
1634
- * verify.write('some data to sign');
1635
- * verify.end();
1636
- * console.log(verify.verify(publicKey, signature, 'hex'));
1637
- * // Prints: true
1638
- * ```
1639
- *
1640
1239
  * Example: Using the `sign.update()` and `verify.update()` methods:
1641
1240
  *
1642
1241
  * ```js
1643
1242
  * const {
1644
1243
  * generateKeyPairSync,
1645
1244
  * createSign,
1646
- * createVerify,
1245
+ * createVerify
1647
1246
  * } = await import('crypto');
1648
1247
  *
1649
1248
  * const { privateKey, publicKey } = generateKeyPairSync('rsa', {
@@ -1661,29 +1260,6 @@ declare module 'crypto' {
1661
1260
  * console.log(verify.verify(publicKey, signature));
1662
1261
  * // Prints: true
1663
1262
  * ```
1664
- *
1665
- * ```js
1666
- * const {
1667
- * generateKeyPairSync,
1668
- * createSign,
1669
- * createVerify,
1670
- * } = require('crypto');
1671
- *
1672
- * const { privateKey, publicKey } = generateKeyPairSync('rsa', {
1673
- * modulusLength: 2048,
1674
- * });
1675
- *
1676
- * const sign = createSign('SHA256');
1677
- * sign.update('some data to sign');
1678
- * sign.end();
1679
- * const signature = sign.sign(privateKey);
1680
- *
1681
- * const verify = createVerify('SHA256');
1682
- * verify.update('some data to sign');
1683
- * verify.end();
1684
- * console.log(verify.verify(publicKey, signature));
1685
- * // Prints: true
1686
- * ```
1687
1263
  * @since v0.1.92
1688
1264
  */
1689
1265
  class Sign extends stream.Writable {
@@ -1810,7 +1386,7 @@ declare module 'crypto' {
1810
1386
  * import assert from 'assert';
1811
1387
  *
1812
1388
  * const {
1813
- * createDiffieHellman,
1389
+ * createDiffieHellman
1814
1390
  * } = await import('crypto');
1815
1391
  *
1816
1392
  * // Generate Alice's keys...
@@ -1828,29 +1404,6 @@ declare module 'crypto' {
1828
1404
  * // OK
1829
1405
  * assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
1830
1406
  * ```
1831
- *
1832
- * ```js
1833
- * const assert = require('assert');
1834
- *
1835
- * const {
1836
- * createDiffieHellman,
1837
- * } = require('crypto');
1838
- *
1839
- * // Generate Alice's keys...
1840
- * const alice = createDiffieHellman(2048);
1841
- * const aliceKey = alice.generateKeys();
1842
- *
1843
- * // Generate Bob's keys...
1844
- * const bob = createDiffieHellman(alice.getPrime(), alice.getGenerator());
1845
- * const bobKey = bob.generateKeys();
1846
- *
1847
- * // Exchange and generate the secret...
1848
- * const aliceSecret = alice.computeSecret(bobKey);
1849
- * const bobSecret = bob.computeSecret(aliceKey);
1850
- *
1851
- * // OK
1852
- * assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
1853
- * ```
1854
1407
  * @since v0.5.0
1855
1408
  */
1856
1409
  class DiffieHellman {
@@ -1964,7 +1517,7 @@ declare module 'crypto' {
1964
1517
  *
1965
1518
  * ```js
1966
1519
  * const {
1967
- * getDiffieHellman,
1520
+ * getDiffieHellman
1968
1521
  * } = await import('crypto');
1969
1522
  * const alice = getDiffieHellman('modp14');
1970
1523
  * const bob = getDiffieHellman('modp14');
@@ -1978,24 +1531,6 @@ declare module 'crypto' {
1978
1531
  * // aliceSecret and bobSecret should be the same
1979
1532
  * console.log(aliceSecret === bobSecret);
1980
1533
  * ```
1981
- *
1982
- * ```js
1983
- * const {
1984
- * getDiffieHellman,
1985
- * } = require('crypto');
1986
- *
1987
- * const alice = getDiffieHellman('modp14');
1988
- * const bob = getDiffieHellman('modp14');
1989
- *
1990
- * alice.generateKeys();
1991
- * bob.generateKeys();
1992
- *
1993
- * const aliceSecret = alice.computeSecret(bob.getPublicKey(), null, 'hex');
1994
- * const bobSecret = bob.computeSecret(alice.getPublicKey(), null, 'hex');
1995
- *
1996
- * // aliceSecret and bobSecret should be the same
1997
- * console.log(aliceSecret === bobSecret);
1998
- * ```
1999
1534
  * @since v0.7.5
2000
1535
  */
2001
1536
  function getDiffieHellman(groupName: string): DiffieHellman;
@@ -2022,7 +1557,7 @@ declare module 'crypto' {
2022
1557
  *
2023
1558
  * ```js
2024
1559
  * const {
2025
- * pbkdf2,
1560
+ * pbkdf2
2026
1561
  * } = await import('crypto');
2027
1562
  *
2028
1563
  * pbkdf2('secret', 'salt', 100000, 64, 'sha512', (err, derivedKey) => {
@@ -2031,31 +1566,11 @@ declare module 'crypto' {
2031
1566
  * });
2032
1567
  * ```
2033
1568
  *
2034
- * ```js
2035
- * const {
2036
- * pbkdf2,
2037
- * } = require('crypto');
2038
- *
2039
- * pbkdf2('secret', 'salt', 100000, 64, 'sha512', (err, derivedKey) => {
2040
- * if (err) throw err;
2041
- * console.log(derivedKey.toString('hex')); // '3745e48...08d59ae'
2042
- * });
2043
- * ```
2044
- *
2045
1569
  * The `crypto.DEFAULT_ENCODING` property can be used to change the way the`derivedKey` is passed to the callback. This property, however, has been
2046
1570
  * deprecated and use should be avoided.
2047
1571
  *
2048
1572
  * ```js
2049
- * const crypto = await import('crypto');
2050
- * crypto.DEFAULT_ENCODING = 'hex';
2051
- * crypto.pbkdf2('secret', 'salt', 100000, 512, 'sha512', (err, derivedKey) => {
2052
- * if (err) throw err;
2053
- * console.log(derivedKey); // '3745e48...aa39b34'
2054
- * });
2055
- * ```
2056
- *
2057
- * ```js
2058
- * const crypto = require('crypto');
1573
+ * import crypto from 'crypto';
2059
1574
  * crypto.DEFAULT_ENCODING = 'hex';
2060
1575
  * crypto.pbkdf2('secret', 'salt', 100000, 512, 'sha512', (err, derivedKey) => {
2061
1576
  * if (err) throw err;
@@ -2092,34 +1607,18 @@ declare module 'crypto' {
2092
1607
  *
2093
1608
  * ```js
2094
1609
  * const {
2095
- * pbkdf2Sync,
1610
+ * pbkdf2Sync
2096
1611
  * } = await import('crypto');
2097
1612
  *
2098
1613
  * const key = pbkdf2Sync('secret', 'salt', 100000, 64, 'sha512');
2099
1614
  * console.log(key.toString('hex')); // '3745e48...08d59ae'
2100
1615
  * ```
2101
1616
  *
2102
- * ```js
2103
- * const {
2104
- * pbkdf2Sync,
2105
- * } = require('crypto');
2106
- *
2107
- * const key = pbkdf2Sync('secret', 'salt', 100000, 64, 'sha512');
2108
- * console.log(key.toString('hex')); // '3745e48...08d59ae'
2109
- * ```
2110
- *
2111
1617
  * The `crypto.DEFAULT_ENCODING` property may be used to change the way the`derivedKey` is returned. This property, however, is deprecated and use
2112
1618
  * should be avoided.
2113
1619
  *
2114
1620
  * ```js
2115
- * const crypto = await import('crypto');
2116
- * crypto.DEFAULT_ENCODING = 'hex';
2117
- * const key = crypto.pbkdf2Sync('secret', 'salt', 100000, 512, 'sha512');
2118
- * console.log(key); // '3745e48...aa39b34'
2119
- * ```
2120
- *
2121
- * ```js
2122
- * const crypto = require('crypto');
1621
+ * import crypto from 'crypto';
2123
1622
  * crypto.DEFAULT_ENCODING = 'hex';
2124
1623
  * const key = crypto.pbkdf2Sync('secret', 'salt', 100000, 512, 'sha512');
2125
1624
  * console.log(key); // '3745e48...aa39b34'
@@ -2140,7 +1639,7 @@ declare module 'crypto' {
2140
1639
  * ```js
2141
1640
  * // Asynchronous
2142
1641
  * const {
2143
- * randomBytes,
1642
+ * randomBytes
2144
1643
  * } = await import('crypto');
2145
1644
  *
2146
1645
  * randomBytes(256, (err, buf) => {
@@ -2149,18 +1648,6 @@ declare module 'crypto' {
2149
1648
  * });
2150
1649
  * ```
2151
1650
  *
2152
- * ```js
2153
- * // Asynchronous
2154
- * const {
2155
- * randomBytes,
2156
- * } = require('crypto');
2157
- *
2158
- * randomBytes(256, (err, buf) => {
2159
- * if (err) throw err;
2160
- * console.log(`${buf.length} bytes of random data: ${buf.toString('hex')}`);
2161
- * });
2162
- * ```
2163
- *
2164
1651
  * If the `callback` function is not provided, the random bytes are generated
2165
1652
  * synchronously and returned as a `Buffer`. An error will be thrown if
2166
1653
  * there is a problem generating the bytes.
@@ -2168,7 +1655,7 @@ declare module 'crypto' {
2168
1655
  * ```js
2169
1656
  * // Synchronous
2170
1657
  * const {
2171
- * randomBytes,
1658
+ * randomBytes
2172
1659
  * } = await import('crypto');
2173
1660
  *
2174
1661
  * const buf = randomBytes(256);
@@ -2176,17 +1663,6 @@ declare module 'crypto' {
2176
1663
  * `${buf.length} bytes of random data: ${buf.toString('hex')}`);
2177
1664
  * ```
2178
1665
  *
2179
- * ```js
2180
- * // Synchronous
2181
- * const {
2182
- * randomBytes,
2183
- * } = require('crypto');
2184
- *
2185
- * const buf = randomBytes(256);
2186
- * console.log(
2187
- * `${buf.length} bytes of random data: ${buf.toString('hex')}`);
2188
- * ```
2189
- *
2190
1666
  * The `crypto.randomBytes()` method will not complete until there is
2191
1667
  * sufficient entropy available.
2192
1668
  * This should normally never take longer than a few milliseconds. The only time
@@ -2221,20 +1697,8 @@ declare module 'crypto' {
2221
1697
  * ```js
2222
1698
  * // Asynchronous
2223
1699
  * const {
2224
- * randomInt,
2225
- * } = await import('crypto');
2226
- *
2227
- * randomInt(3, (err, n) => {
2228
- * if (err) throw err;
2229
- * console.log(`Random number chosen from (0, 1, 2): ${n}`);
2230
- * });
2231
- * ```
2232
- *
2233
- * ```js
2234
- * // Asynchronous
2235
- * const {
2236
- * randomInt,
2237
- * } = require('crypto');
1700
+ * randomInt
1701
+ * } = await import('crypto');
2238
1702
  *
2239
1703
  * randomInt(3, (err, n) => {
2240
1704
  * if (err) throw err;
@@ -2245,7 +1709,7 @@ declare module 'crypto' {
2245
1709
  * ```js
2246
1710
  * // Synchronous
2247
1711
  * const {
2248
- * randomInt,
1712
+ * randomInt
2249
1713
  * } = await import('crypto');
2250
1714
  *
2251
1715
  * const n = randomInt(3);
@@ -2253,34 +1717,14 @@ declare module 'crypto' {
2253
1717
  * ```
2254
1718
  *
2255
1719
  * ```js
2256
- * // Synchronous
2257
- * const {
2258
- * randomInt,
2259
- * } = require('crypto');
2260
- *
2261
- * const n = randomInt(3);
2262
- * console.log(`Random number chosen from (0, 1, 2): ${n}`);
2263
- * ```
2264
- *
2265
- * ```js
2266
1720
  * // With `min` argument
2267
1721
  * const {
2268
- * randomInt,
1722
+ * randomInt
2269
1723
  * } = await import('crypto');
2270
1724
  *
2271
1725
  * const n = randomInt(1, 7);
2272
1726
  * console.log(`The dice rolled: ${n}`);
2273
1727
  * ```
2274
- *
2275
- * ```js
2276
- * // With `min` argument
2277
- * const {
2278
- * randomInt,
2279
- * } = require('crypto');
2280
- *
2281
- * const n = randomInt(1, 7);
2282
- * console.log(`The dice rolled: ${n}`);
2283
- * ```
2284
1728
  * @since v14.10.0, v12.19.0
2285
1729
  * @param [min=0] Start of random range (inclusive).
2286
1730
  * @param max End of random range (exclusive).
@@ -2294,25 +1738,8 @@ declare module 'crypto' {
2294
1738
  * Synchronous version of {@link randomFill}.
2295
1739
  *
2296
1740
  * ```js
2297
- * const {
2298
- * randomFillSync,
2299
- * } = await import('crypto');
2300
- *
2301
- * const buf = Buffer.alloc(10);
2302
- * console.log(randomFillSync(buf).toString('hex'));
2303
- *
2304
- * randomFillSync(buf, 5);
2305
- * console.log(buf.toString('hex'));
2306
- *
2307
- * // The above is equivalent to the following:
2308
- * randomFillSync(buf, 5, 5);
2309
- * console.log(buf.toString('hex'));
2310
- * ```
2311
- *
2312
- * ```js
2313
- * const {
2314
- * randomFillSync,
2315
- * } = require('crypto');
1741
+ * import { Buffer } from 'buffer';
1742
+ * const { randomFillSync } = await import('crypto');
2316
1743
  *
2317
1744
  * const buf = Buffer.alloc(10);
2318
1745
  * console.log(randomFillSync(buf).toString('hex'));
@@ -2328,26 +1755,8 @@ declare module 'crypto' {
2328
1755
  * Any `ArrayBuffer`, `TypedArray` or `DataView` instance may be passed as`buffer`.
2329
1756
  *
2330
1757
  * ```js
2331
- * const {
2332
- * randomFillSync,
2333
- * } = await import('crypto');
2334
- *
2335
- * const a = new Uint32Array(10);
2336
- * console.log(Buffer.from(randomFillSync(a).buffer,
2337
- * a.byteOffset, a.byteLength).toString('hex'));
2338
- *
2339
- * const b = new DataView(new ArrayBuffer(10));
2340
- * console.log(Buffer.from(randomFillSync(b).buffer,
2341
- * b.byteOffset, b.byteLength).toString('hex'));
2342
- *
2343
- * const c = new ArrayBuffer(10);
2344
- * console.log(Buffer.from(randomFillSync(c)).toString('hex'));
2345
- * ```
2346
- *
2347
- * ```js
2348
- * const {
2349
- * randomFillSync,
2350
- * } = require('crypto');
1758
+ * import { Buffer } from 'buffer';
1759
+ * const { randomFillSync } = await import('crypto');
2351
1760
  *
2352
1761
  * const a = new Uint32Array(10);
2353
1762
  * console.log(Buffer.from(randomFillSync(a).buffer,
@@ -2375,32 +1784,8 @@ declare module 'crypto' {
2375
1784
  * If the `callback` function is not provided, an error will be thrown.
2376
1785
  *
2377
1786
  * ```js
2378
- * const {
2379
- * randomFill,
2380
- * } = await import('crypto');
2381
- *
2382
- * const buf = Buffer.alloc(10);
2383
- * randomFill(buf, (err, buf) => {
2384
- * if (err) throw err;
2385
- * console.log(buf.toString('hex'));
2386
- * });
2387
- *
2388
- * randomFill(buf, 5, (err, buf) => {
2389
- * if (err) throw err;
2390
- * console.log(buf.toString('hex'));
2391
- * });
2392
- *
2393
- * // The above is equivalent to the following:
2394
- * randomFill(buf, 5, 5, (err, buf) => {
2395
- * if (err) throw err;
2396
- * console.log(buf.toString('hex'));
2397
- * });
2398
- * ```
2399
- *
2400
- * ```js
2401
- * const {
2402
- * randomFill,
2403
- * } = require('crypto');
1787
+ * import { Buffer } from 'buffer';
1788
+ * const { randomFill } = await import('crypto');
2404
1789
  *
2405
1790
  * const buf = Buffer.alloc(10);
2406
1791
  * randomFill(buf, (err, buf) => {
@@ -2429,35 +1814,8 @@ declare module 'crypto' {
2429
1814
  * distribution and have no meaningful lower or upper bounds.
2430
1815
  *
2431
1816
  * ```js
2432
- * const {
2433
- * randomFill,
2434
- * } = await import('crypto');
2435
- *
2436
- * const a = new Uint32Array(10);
2437
- * randomFill(a, (err, buf) => {
2438
- * if (err) throw err;
2439
- * console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
2440
- * .toString('hex'));
2441
- * });
2442
- *
2443
- * const b = new DataView(new ArrayBuffer(10));
2444
- * randomFill(b, (err, buf) => {
2445
- * if (err) throw err;
2446
- * console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
2447
- * .toString('hex'));
2448
- * });
2449
- *
2450
- * const c = new ArrayBuffer(10);
2451
- * randomFill(c, (err, buf) => {
2452
- * if (err) throw err;
2453
- * console.log(Buffer.from(buf).toString('hex'));
2454
- * });
2455
- * ```
2456
- *
2457
- * ```js
2458
- * const {
2459
- * randomFill,
2460
- * } = require('crypto');
1817
+ * import { Buffer } from 'buffer';
1818
+ * const { randomFill } = await import('crypto');
2461
1819
  *
2462
1820
  * const a = new Uint32Array(10);
2463
1821
  * randomFill(a, (err, buf) => {
@@ -2523,7 +1881,7 @@ declare module 'crypto' {
2523
1881
  *
2524
1882
  * ```js
2525
1883
  * const {
2526
- * scrypt,
1884
+ * scrypt
2527
1885
  * } = await import('crypto');
2528
1886
  *
2529
1887
  * // Using the factory defaults.
@@ -2537,23 +1895,6 @@ declare module 'crypto' {
2537
1895
  * console.log(derivedKey.toString('hex')); // '3745e48...aa39b34'
2538
1896
  * });
2539
1897
  * ```
2540
- *
2541
- * ```js
2542
- * const {
2543
- * scrypt,
2544
- * } = require('crypto');
2545
- *
2546
- * // Using the factory defaults.
2547
- * scrypt('password', 'salt', 64, (err, derivedKey) => {
2548
- * if (err) throw err;
2549
- * console.log(derivedKey.toString('hex')); // '3745e48...08d59ae'
2550
- * });
2551
- * // Using a custom N parameter. Must be a power of two.
2552
- * scrypt('password', 'salt', 64, { N: 1024 }, (err, derivedKey) => {
2553
- * if (err) throw err;
2554
- * console.log(derivedKey.toString('hex')); // '3745e48...aa39b34'
2555
- * });
2556
- * ```
2557
1898
  * @since v10.5.0
2558
1899
  */
2559
1900
  function scrypt(password: BinaryLike, salt: BinaryLike, keylen: number, callback: (err: Error | null, derivedKey: Buffer) => void): void;
@@ -2576,7 +1917,7 @@ declare module 'crypto' {
2576
1917
  *
2577
1918
  * ```js
2578
1919
  * const {
2579
- * scryptSync,
1920
+ * scryptSync
2580
1921
  * } = await import('crypto');
2581
1922
  * // Using the factory defaults.
2582
1923
  *
@@ -2586,19 +1927,6 @@ declare module 'crypto' {
2586
1927
  * const key2 = scryptSync('password', 'salt', 64, { N: 1024 });
2587
1928
  * console.log(key2.toString('hex')); // '3745e48...aa39b34'
2588
1929
  * ```
2589
- *
2590
- * ```js
2591
- * const {
2592
- * scryptSync,
2593
- * } = require('crypto');
2594
- * // Using the factory defaults.
2595
- *
2596
- * const key1 = scryptSync('password', 'salt', 64);
2597
- * console.log(key1.toString('hex')); // '3745e48...08d59ae'
2598
- * // Using a custom N parameter. Must be a power of two.
2599
- * const key2 = scryptSync('password', 'salt', 64, { N: 1024 });
2600
- * console.log(key2.toString('hex')); // '3745e48...aa39b34'
2601
- * ```
2602
1930
  * @since v10.5.0
2603
1931
  */
2604
1932
  function scryptSync(password: BinaryLike, salt: BinaryLike, keylen: number, options?: ScryptOptions): Buffer;
@@ -2661,19 +1989,11 @@ declare module 'crypto' {
2661
1989
  /**
2662
1990
  * ```js
2663
1991
  * const {
2664
- * getCiphers,
1992
+ * getCiphers
2665
1993
  * } = await import('crypto');
2666
1994
  *
2667
1995
  * console.log(getCiphers()); // ['aes-128-cbc', 'aes-128-ccm', ...]
2668
1996
  * ```
2669
- *
2670
- * ```js
2671
- * const {
2672
- * getCiphers,
2673
- * } = require('crypto');
2674
- *
2675
- * console.log(getCiphers()); // ['aes-128-cbc', 'aes-128-ccm', ...]
2676
- * ```
2677
1997
  * @since v0.9.3
2678
1998
  * @return An array with the names of the supported cipher algorithms.
2679
1999
  */
@@ -2681,19 +2001,11 @@ declare module 'crypto' {
2681
2001
  /**
2682
2002
  * ```js
2683
2003
  * const {
2684
- * getCurves,
2004
+ * getCurves
2685
2005
  * } = await import('crypto');
2686
2006
  *
2687
2007
  * console.log(getCurves()); // ['Oakley-EC2N-3', 'Oakley-EC2N-4', ...]
2688
2008
  * ```
2689
- *
2690
- * ```js
2691
- * const {
2692
- * getCurves,
2693
- * } = require('crypto');
2694
- *
2695
- * console.log(getCurves()); // ['Oakley-EC2N-3', 'Oakley-EC2N-4', ...]
2696
- * ```
2697
2009
  * @since v2.3.0
2698
2010
  * @return An array with the names of the supported elliptic curves.
2699
2011
  */
@@ -2706,19 +2018,11 @@ declare module 'crypto' {
2706
2018
  /**
2707
2019
  * ```js
2708
2020
  * const {
2709
- * getHashes,
2021
+ * getHashes
2710
2022
  * } = await import('crypto');
2711
2023
  *
2712
2024
  * console.log(getHashes()); // ['DSA', 'DSA-SHA', 'DSA-SHA1', ...]
2713
2025
  * ```
2714
- *
2715
- * ```js
2716
- * const {
2717
- * getHashes,
2718
- * } = require('crypto');
2719
- *
2720
- * console.log(getHashes()); // ['DSA', 'DSA-SHA', 'DSA-SHA1', ...]
2721
- * ```
2722
2026
  * @since v0.9.3
2723
2027
  * @return An array of the names of the supported hash algorithms, such as `'RSA-SHA256'`. Hash algorithms are also called "digest" algorithms.
2724
2028
  */
@@ -2733,7 +2037,7 @@ declare module 'crypto' {
2733
2037
  * import assert from 'assert';
2734
2038
  *
2735
2039
  * const {
2736
- * createECDH,
2040
+ * createECDH
2737
2041
  * } = await import('crypto');
2738
2042
  *
2739
2043
  * // Generate Alice's keys...
@@ -2751,29 +2055,6 @@ declare module 'crypto' {
2751
2055
  * assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
2752
2056
  * // OK
2753
2057
  * ```
2754
- *
2755
- * ```js
2756
- * const assert = require('assert');
2757
- *
2758
- * const {
2759
- * createECDH,
2760
- * } = require('crypto');
2761
- *
2762
- * // Generate Alice's keys...
2763
- * const alice = createECDH('secp521r1');
2764
- * const aliceKey = alice.generateKeys();
2765
- *
2766
- * // Generate Bob's keys...
2767
- * const bob = createECDH('secp521r1');
2768
- * const bobKey = bob.generateKeys();
2769
- *
2770
- * // Exchange and generate the secret...
2771
- * const aliceSecret = alice.computeSecret(bobKey);
2772
- * const bobSecret = bob.computeSecret(aliceKey);
2773
- *
2774
- * assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
2775
- * // OK
2776
- * ```
2777
2058
  * @since v0.11.14
2778
2059
  */
2779
2060
  class ECDH {
@@ -2798,7 +2079,7 @@ declare module 'crypto' {
2798
2079
  * ```js
2799
2080
  * const {
2800
2081
  * createECDH,
2801
- * ECDH,
2082
+ * ECDH
2802
2083
  * } = await import('crypto');
2803
2084
  *
2804
2085
  * const ecdh = createECDH('secp256k1');
@@ -2815,27 +2096,6 @@ declare module 'crypto' {
2815
2096
  * // The converted key and the uncompressed public key should be the same
2816
2097
  * console.log(uncompressedKey === ecdh.getPublicKey('hex'));
2817
2098
  * ```
2818
- *
2819
- * ```js
2820
- * const {
2821
- * createECDH,
2822
- * ECDH,
2823
- * } = require('crypto');
2824
- *
2825
- * const ecdh = createECDH('secp256k1');
2826
- * ecdh.generateKeys();
2827
- *
2828
- * const compressedKey = ecdh.getPublicKey('hex', 'compressed');
2829
- *
2830
- * const uncompressedKey = ECDH.convertKey(compressedKey,
2831
- * 'secp256k1',
2832
- * 'hex',
2833
- * 'hex',
2834
- * 'uncompressed');
2835
- *
2836
- * // The converted key and the uncompressed public key should be the same
2837
- * console.log(uncompressedKey === ecdh.getPublicKey('hex'));
2838
- * ```
2839
2099
  * @since v10.0.0
2840
2100
  * @param inputEncoding The `encoding` of the `key` string.
2841
2101
  * @param outputEncoding The `encoding` of the return value.
@@ -3089,7 +2349,7 @@ declare module 'crypto' {
3089
2349
  *
3090
2350
  * ```js
3091
2351
  * const {
3092
- * generateKeyPairSync,
2352
+ * generateKeyPairSync
3093
2353
  * } = await import('crypto');
3094
2354
  *
3095
2355
  * const {
@@ -3110,29 +2370,6 @@ declare module 'crypto' {
3110
2370
  * });
3111
2371
  * ```
3112
2372
  *
3113
- * ```js
3114
- * const {
3115
- * generateKeyPairSync,
3116
- * } = require('crypto');
3117
- *
3118
- * const {
3119
- * publicKey,
3120
- * privateKey,
3121
- * } = generateKeyPairSync('rsa', {
3122
- * modulusLength: 4096,
3123
- * publicKeyEncoding: {
3124
- * type: 'spki',
3125
- * format: 'pem'
3126
- * },
3127
- * privateKeyEncoding: {
3128
- * type: 'pkcs8',
3129
- * format: 'pem',
3130
- * cipher: 'aes-256-cbc',
3131
- * passphrase: 'top secret'
3132
- * }
3133
- * });
3134
- * ```
3135
- *
3136
2373
  * The return value `{ publicKey, privateKey }` represents the generated key pair.
3137
2374
  * When PEM encoding was selected, the respective key will be a string, otherwise
3138
2375
  * it will be a buffer containing the data encoded as DER.
@@ -3186,7 +2423,7 @@ declare module 'crypto' {
3186
2423
  *
3187
2424
  * ```js
3188
2425
  * const {
3189
- * generateKeyPair,
2426
+ * generateKeyPair
3190
2427
  * } = await import('crypto');
3191
2428
  *
3192
2429
  * generateKeyPair('rsa', {
@@ -3206,28 +2443,6 @@ declare module 'crypto' {
3206
2443
  * });
3207
2444
  * ```
3208
2445
  *
3209
- * ```js
3210
- * const {
3211
- * generateKeyPair,
3212
- * } = require('crypto');
3213
- *
3214
- * generateKeyPair('rsa', {
3215
- * modulusLength: 4096,
3216
- * publicKeyEncoding: {
3217
- * type: 'spki',
3218
- * format: 'pem'
3219
- * },
3220
- * privateKeyEncoding: {
3221
- * type: 'pkcs8',
3222
- * format: 'pem',
3223
- * cipher: 'aes-256-cbc',
3224
- * passphrase: 'top secret'
3225
- * }
3226
- * }, (err, publicKey, privateKey) => {
3227
- * // Handle errors and use the generated key pair.
3228
- * });
3229
- * ```
3230
- *
3231
2446
  * On completion, `callback` will be called with `err` set to `undefined` and`publicKey` / `privateKey` representing the generated key pair.
3232
2447
  *
3233
2448
  * If this method is invoked as its `util.promisify()` ed version, it returns
@@ -3576,7 +2791,7 @@ declare module 'crypto' {
3576
2791
  */
3577
2792
  function getCipherInfo(nameOrNid: string | number, options?: CipherInfoOptions): CipherInfo | undefined;
3578
2793
  /**
3579
- * HKDF is a simple key derivation function defined in RFC 5869\. The given `key`,`salt` and `info` are used with the `digest` to derive a key of `keylen` bytes.
2794
+ * HKDF is a simple key derivation function defined in RFC 5869\. The given `ikm`,`salt` and `info` are used with the `digest` to derive a key of `keylen` bytes.
3580
2795
  *
3581
2796
  * The supplied `callback` function is called with two arguments: `err` and`derivedKey`. If an errors occurs while deriving the key, `err` will be set;
3582
2797
  * otherwise `err` will be `null`. The successfully generated `derivedKey` will
@@ -3584,8 +2799,9 @@ declare module 'crypto' {
3584
2799
  * of the input arguments specify invalid values or types.
3585
2800
  *
3586
2801
  * ```js
2802
+ * import { Buffer } from 'buffer';
3587
2803
  * const {
3588
- * hkdf,
2804
+ * hkdf
3589
2805
  * } = await import('crypto');
3590
2806
  *
3591
2807
  * hkdf('sha512', 'key', 'salt', 'info', 64, (err, derivedKey) => {
@@ -3593,29 +2809,18 @@ declare module 'crypto' {
3593
2809
  * console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
3594
2810
  * });
3595
2811
  * ```
3596
- *
3597
- * ```js
3598
- * const {
3599
- * hkdf,
3600
- * } = require('crypto');
3601
- *
3602
- * hkdf('sha512', 'key', 'salt', 'info', 64, (err, derivedKey) => {
3603
- * if (err) throw err;
3604
- * console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
3605
- * });
3606
- * ```
3607
2812
  * @since v15.0.0
3608
2813
  * @param digest The digest algorithm to use.
3609
- * @param key The secret key. It must be at least one byte in length.
2814
+ * @param ikm The input keying material. It must be at least one byte in length.
3610
2815
  * @param salt The salt value. Must be provided but can be zero-length.
3611
2816
  * @param info Additional info value. Must be provided but can be zero-length, and cannot be more than 1024 bytes.
3612
2817
  * @param keylen The length of the key to generate. Must be greater than 0. The maximum allowable value is `255` times the number of bytes produced by the selected digest function (e.g. `sha512`
3613
2818
  * generates 64-byte hashes, making the maximum HKDF output 16320 bytes).
3614
2819
  */
3615
- function hkdf(digest: string, key: BinaryLike | KeyObject, salt: BinaryLike, info: BinaryLike, keylen: number, callback: (err: Error | null, derivedKey: ArrayBuffer) => void): void;
2820
+ function hkdf(digest: string, irm: BinaryLike | KeyObject, salt: BinaryLike, info: BinaryLike, keylen: number, callback: (err: Error | null, derivedKey: ArrayBuffer) => void): void;
3616
2821
  /**
3617
2822
  * Provides a synchronous HKDF key derivation function as defined in RFC 5869\. The
3618
- * given `key`, `salt` and `info` are used with the `digest` to derive a key of`keylen` bytes.
2823
+ * given `ikm`, `salt` and `info` are used with the `digest` to derive a key of`keylen` bytes.
3619
2824
  *
3620
2825
  * The successfully generated `derivedKey` will be returned as an [<ArrayBuffer>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer).
3621
2826
  *
@@ -3623,31 +2828,23 @@ declare module 'crypto' {
3623
2828
  * types, or if the derived key cannot be generated.
3624
2829
  *
3625
2830
  * ```js
2831
+ * import { Buffer } from 'buffer';
3626
2832
  * const {
3627
- * hkdfSync,
2833
+ * hkdfSync
3628
2834
  * } = await import('crypto');
3629
2835
  *
3630
2836
  * const derivedKey = hkdfSync('sha512', 'key', 'salt', 'info', 64);
3631
2837
  * console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
3632
2838
  * ```
3633
- *
3634
- * ```js
3635
- * const {
3636
- * hkdfSync,
3637
- * } = require('crypto');
3638
- *
3639
- * const derivedKey = hkdfSync('sha512', 'key', 'salt', 'info', 64);
3640
- * console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
3641
- * ```
3642
2839
  * @since v15.0.0
3643
2840
  * @param digest The digest algorithm to use.
3644
- * @param key The secret key. It must be at least one byte in length.
2841
+ * @param ikm The input keying material. It must be at least one byte in length.
3645
2842
  * @param salt The salt value. Must be provided but can be zero-length.
3646
2843
  * @param info Additional info value. Must be provided but can be zero-length, and cannot be more than 1024 bytes.
3647
2844
  * @param keylen The length of the key to generate. Must be greater than 0. The maximum allowable value is `255` times the number of bytes produced by the selected digest function (e.g. `sha512`
3648
2845
  * generates 64-byte hashes, making the maximum HKDF output 16320 bytes).
3649
2846
  */
3650
- function hkdfSync(digest: string, key: BinaryLike | KeyObject, salt: BinaryLike, info: BinaryLike, keylen: number): ArrayBuffer;
2847
+ function hkdfSync(digest: string, ikm: BinaryLike | KeyObject, salt: BinaryLike, info: BinaryLike, keylen: number): ArrayBuffer;
3651
2848
  interface SecureHeapUsage {
3652
2849
  /**
3653
2850
  * The total allocated secure heap size as specified using the `--secure-heap=n` command-line flag.
@@ -3682,7 +2879,7 @@ declare module 'crypto' {
3682
2879
  disableEntropyCache?: boolean | undefined;
3683
2880
  }
3684
2881
  /**
3685
- * Generates a random [RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) Version 4 UUID. The UUID is generated using a
2882
+ * Generates a random [RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) version 4 UUID. The UUID is generated using a
3686
2883
  * cryptographic pseudorandom number generator.
3687
2884
  * @since v15.6.0
3688
2885
  */
@@ -3720,14 +2917,6 @@ declare module 'crypto' {
3720
2917
  *
3721
2918
  * console.log(x509.subject);
3722
2919
  * ```
3723
- *
3724
- * ```js
3725
- * const { X509Certificate } = require('crypto');
3726
- *
3727
- * const x509 = new X509Certificate('{... pem encoded cert ...}');
3728
- *
3729
- * console.log(x509.subject);
3730
- * ```
3731
2920
  * @since v15.6.0
3732
2921
  */
3733
2922
  class X509Certificate {
@@ -3778,7 +2967,7 @@ declare module 'crypto' {
3778
2967
  */
3779
2968
  readonly issuerCertificate?: X509Certificate | undefined;
3780
2969
  /**
3781
- * The public key `<KeyObject>` for this certificate.
2970
+ * The public key `KeyObject` for this certificate.
3782
2971
  * @since v15.6.0
3783
2972
  */
3784
2973
  readonly publicKey: KeyObject;