@node-red/editor-client 3.0.2 → 3.1.0-beta.2

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.
Files changed (127) hide show
  1. package/locales/de/editor.json +2 -0
  2. package/locales/de/infotips.json +0 -0
  3. package/locales/de/jsonata.json +0 -0
  4. package/locales/en-US/editor.json +37 -6
  5. package/locales/en-US/infotips.json +0 -0
  6. package/locales/en-US/jsonata.json +0 -0
  7. package/locales/fr/editor.json +1238 -0
  8. package/locales/fr/infotips.json +23 -0
  9. package/locales/fr/jsonata.json +274 -0
  10. package/locales/ja/editor.json +48 -9
  11. package/locales/ko/editor.json +233 -31
  12. package/locales/ko/infotips.json +0 -0
  13. package/locales/ko/jsonata.json +0 -0
  14. package/locales/pt-BR/editor.json +1208 -0
  15. package/locales/pt-BR/infotips.json +23 -0
  16. package/locales/pt-BR/jsonata.json +274 -0
  17. package/locales/ru/editor.json +2 -0
  18. package/locales/ru/infotips.json +0 -0
  19. package/locales/ru/jsonata.json +0 -0
  20. package/locales/zh-CN/editor.json +1175 -1049
  21. package/locales/zh-TW/editor.json +3 -0
  22. package/package.json +1 -1
  23. package/public/red/about +140 -0
  24. package/public/red/red.js +2699 -1397
  25. package/public/red/red.min.js +4 -3
  26. package/public/red/style.min.css +1 -1
  27. package/public/red/tours/3.0/images/context-menu.png +0 -0
  28. package/public/red/tours/3.0/welcome.js +155 -0
  29. package/public/red/tours/images/context-menu.png +0 -0
  30. package/public/red/tours/images/global-env-vars.png +0 -0
  31. package/public/red/tours/images/hiding-flows.png +0 -0
  32. package/public/red/tours/images/locking-flows.png +0 -0
  33. package/public/red/tours/images/mermaid.png +0 -0
  34. package/public/red/tours/images/node-help.png +0 -0
  35. package/public/red/tours/images/tab-changes.png +0 -0
  36. package/public/red/tours/welcome.js +111 -94
  37. package/public/types/node/assert/strict.d.ts +11 -0
  38. package/public/types/node/assert.d.ts +898 -64
  39. package/public/types/node/async_hooks.d.ts +362 -94
  40. package/public/types/node/buffer.d.ts +2158 -14
  41. package/public/types/node/child_process.d.ts +1109 -257
  42. package/public/types/node/cluster.d.ts +349 -200
  43. package/public/types/node/console.d.ts +313 -43
  44. package/public/types/node/crypto.d.ts +3329 -656
  45. package/public/types/node/dgram.d.ts +459 -58
  46. package/public/types/node/diagnostics_channel.d.ts +155 -0
  47. package/public/types/node/dns/promises.d.ts +371 -0
  48. package/public/types/node/dns.d.ts +532 -265
  49. package/public/types/node/domain.d.ts +159 -16
  50. package/public/types/node/events.d.ts +589 -30
  51. package/public/types/node/fs/promises.d.ts +1097 -0
  52. package/public/types/node/fs.d.ts +2484 -958
  53. package/public/types/node/globals.d.ts +43 -503
  54. package/public/types/node/http.d.ts +1156 -145
  55. package/public/types/node/http2.d.ts +1610 -470
  56. package/public/types/node/https.d.ts +462 -72
  57. package/public/types/node/module.d.ts +72 -13
  58. package/public/types/node/net.d.ts +663 -131
  59. package/public/types/node/os.d.ts +238 -25
  60. package/public/types/node/path.d.ts +57 -23
  61. package/public/types/node/perf_hooks.d.ts +424 -112
  62. package/public/types/node/process.d.ts +1261 -193
  63. package/public/types/node/querystring.d.ts +107 -7
  64. package/public/types/node/readline.d.ts +443 -74
  65. package/public/types/node/stream/consumers.d.ts +15 -0
  66. package/public/types/node/stream/promises.d.ts +45 -0
  67. package/public/types/node/stream/web.d.ts +395 -0
  68. package/public/types/node/stream.d.ts +1081 -177
  69. package/public/types/node/string_decoder.d.ts +57 -0
  70. package/public/types/node/test.d.ts +193 -0
  71. package/public/types/node/timers/promises.d.ts +96 -0
  72. package/public/types/node/timers.d.ts +87 -12
  73. package/public/types/node/tls.d.ts +457 -222
  74. package/public/types/node/trace_events.d.ts +107 -10
  75. package/public/types/node/tty.d.ts +158 -23
  76. package/public/types/node/url.d.ts +734 -28
  77. package/public/types/node/util.d.ts +1542 -164
  78. package/public/types/node/v8.d.ts +261 -73
  79. package/public/types/node/vm.d.ts +384 -32
  80. package/public/types/node/wasi.d.ts +92 -23
  81. package/public/types/node/worker_threads.d.ts +531 -123
  82. package/public/types/node/zlib.d.ts +216 -63
  83. package/public/types/node-red/func.d.ts +3 -0
  84. package/public/vendor/jquery/css/base/images/ui-icons_444444_256x240.png +0 -0
  85. package/public/vendor/jquery/css/base/images/ui-icons_555555_256x240.png +0 -0
  86. package/public/vendor/jquery/css/base/images/ui-icons_777620_256x240.png +0 -0
  87. package/public/vendor/jquery/css/base/images/ui-icons_777777_256x240.png +0 -0
  88. package/public/vendor/jquery/css/base/images/ui-icons_cc0000_256x240.png +0 -0
  89. package/public/vendor/jquery/css/base/images/ui-icons_ffffff_256x240.png +0 -0
  90. package/public/vendor/jquery/css/base/jquery-ui.min.css +4 -4
  91. package/public/vendor/mermaid/mermaid.min.js +1284 -0
  92. package/public/vendor/monaco/dist/{ade705761eb7e702770d.ttf → 7064e66c3890a12c47b4.ttf} +0 -0
  93. package/public/vendor/monaco/dist/css.worker.js +1 -1
  94. package/public/vendor/monaco/dist/css.worker.js.LICENSE.txt +1 -1
  95. package/public/vendor/monaco/dist/editor.js +1 -1
  96. package/public/vendor/monaco/dist/editor.js.LICENSE.txt +5 -1
  97. package/public/vendor/monaco/dist/editor.worker.js +1 -1
  98. package/public/vendor/monaco/dist/html.worker.js +1 -1
  99. package/public/vendor/monaco/dist/html.worker.js.LICENSE.txt +1 -1
  100. package/public/vendor/monaco/dist/json.worker.js +1 -1
  101. package/public/vendor/monaco/dist/json.worker.js.LICENSE.txt +1 -1
  102. package/public/vendor/monaco/dist/locale/cs.js +319 -71
  103. package/public/vendor/monaco/dist/locale/de.js +323 -75
  104. package/public/vendor/monaco/dist/locale/es.js +318 -70
  105. package/public/vendor/monaco/dist/locale/fr.js +327 -79
  106. package/public/vendor/monaco/dist/locale/it.js +325 -77
  107. package/public/vendor/monaco/dist/locale/ja.js +337 -89
  108. package/public/vendor/monaco/dist/locale/ko.js +324 -76
  109. package/public/vendor/monaco/dist/locale/pl.js +322 -74
  110. package/public/vendor/monaco/dist/locale/pt-br.js +321 -73
  111. package/public/vendor/monaco/dist/locale/qps-ploc.js +1580 -1332
  112. package/public/vendor/monaco/dist/locale/ru.js +324 -76
  113. package/public/vendor/monaco/dist/locale/tr.js +326 -78
  114. package/public/vendor/monaco/dist/locale/zh-hans.js +328 -80
  115. package/public/vendor/monaco/dist/locale/zh-hant.js +321 -73
  116. package/public/vendor/monaco/dist/theme/forge.json +236 -0
  117. package/public/vendor/monaco/dist/theme/github-dark.json +348 -0
  118. package/public/vendor/monaco/dist/theme/github-light.json +348 -0
  119. package/public/vendor/monaco/dist/theme/nord.json +93 -0
  120. package/public/vendor/monaco/dist/ts.worker.js +1 -1
  121. package/public/vendor/monaco/dist/ts.worker.js.LICENSE.txt +14 -6
  122. package/public/vendor/vendor.js +9 -15
  123. /package/public/red/tours/{images → 3.0/images}/continuous-search.png +0 -0
  124. /package/public/red/tours/{images → 3.0/images}/debug-path-tooltip.png +0 -0
  125. /package/public/red/tours/{images → 3.0/images}/junction-quick-add.png +0 -0
  126. /package/public/red/tours/{images → 3.0/images}/junction-slice.gif +0 -0
  127. /package/public/red/tours/{images → 3.0/images}/split-wire-with-links.gif +0 -0
@@ -1,17 +1,36 @@
1
1
 
2
2
  /* NOTE: Do not edit directly! This file is generated using `npm run update-types` in https://github.com/Steve-Mcl/monaco-editor-esm-i18n */
3
3
 
4
+ /**
5
+ * The `crypto` module provides cryptographic functionality that includes a set of
6
+ * wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.
7
+ *
8
+ * ```js
9
+ * const { createHmac } = await import('crypto');
10
+ *
11
+ * const secret = 'abcdefg';
12
+ * const hash = createHmac('sha256', secret)
13
+ * .update('I love cupcakes')
14
+ * .digest('hex');
15
+ * console.log(hash);
16
+ * // Prints:
17
+ * // c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e
18
+ * ```
19
+ * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/crypto.js)
20
+ */
4
21
  declare module 'crypto' {
5
- import * as stream from 'stream';
6
-
22
+ import * as stream from 'node:stream';
23
+ import { PeerCertificate } from 'node:tls';
7
24
  interface Certificate {
8
25
  /**
26
+ * @deprecated
9
27
  * @param spkac
10
28
  * @returns The challenge component of the `spkac` data structure,
11
29
  * which includes a public key and a challenge.
12
30
  */
13
31
  exportChallenge(spkac: BinaryLike): Buffer;
14
32
  /**
33
+ * @deprecated
15
34
  * @param spkac
16
35
  * @param encoding The encoding of the spkac string.
17
36
  * @returns The public key component of the `spkac` data structure,
@@ -19,6 +38,7 @@ declare module 'crypto' {
19
38
  */
20
39
  exportPublicKey(spkac: BinaryLike, encoding?: string): Buffer;
21
40
  /**
41
+ * @deprecated
22
42
  * @param spkac
23
43
  * @returns `true` if the given `spkac` data structure is valid,
24
44
  * `false` otherwise.
@@ -30,12 +50,29 @@ declare module 'crypto' {
30
50
  new (): Certificate;
31
51
  /** @deprecated since v14.9.0 - Use static methods of `crypto.Certificate` instead. */
32
52
  (): Certificate;
53
+ /**
54
+ * @param spkac
55
+ * @returns The challenge component of the `spkac` data structure,
56
+ * which includes a public key and a challenge.
57
+ */
58
+ exportChallenge(spkac: BinaryLike): Buffer;
59
+ /**
60
+ * @param spkac
61
+ * @param encoding The encoding of the spkac string.
62
+ * @returns The public key component of the `spkac` data structure,
63
+ * which includes a public key and a challenge.
64
+ */
65
+ exportPublicKey(spkac: BinaryLike, encoding?: string): Buffer;
66
+ /**
67
+ * @param spkac
68
+ * @returns `true` if the given `spkac` data structure is valid,
69
+ * `false` otherwise.
70
+ */
71
+ verifySpkac(spkac: NodeJS.ArrayBufferView): boolean;
33
72
  };
34
-
35
73
  namespace constants {
36
74
  // https://nodejs.org/dist/latest-v10.x/docs/api/crypto.html#crypto_crypto_constants
37
75
  const OPENSSL_VERSION_NUMBER: number;
38
-
39
76
  /** Applies multiple bug workarounds within OpenSSL. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html for detail. */
40
77
  const SSL_OP_ALL: number;
41
78
  /** 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. */
@@ -85,7 +122,6 @@ declare module 'crypto' {
85
122
  const SSL_OP_TLS_D5_BUG: number;
86
123
  /** Instructs OpenSSL to disable version rollback attack detection. */
87
124
  const SSL_OP_TLS_ROLLBACK_BUG: number;
88
-
89
125
  const ENGINE_METHOD_RSA: number;
90
126
  const ENGINE_METHOD_DSA: number;
91
127
  const ENGINE_METHOD_DH: number;
@@ -97,14 +133,11 @@ declare module 'crypto' {
97
133
  const ENGINE_METHOD_PKEY_ASN1_METHS: number;
98
134
  const ENGINE_METHOD_ALL: number;
99
135
  const ENGINE_METHOD_NONE: number;
100
-
101
136
  const DH_CHECK_P_NOT_SAFE_PRIME: number;
102
137
  const DH_CHECK_P_NOT_PRIME: number;
103
138
  const DH_UNABLE_TO_CHECK_GENERATOR: number;
104
139
  const DH_NOT_SUITABLE_GENERATOR: number;
105
-
106
140
  const ALPN_ENABLED: number;
107
-
108
141
  const RSA_PKCS1_PADDING: number;
109
142
  const RSA_SSLV23_PADDING: number;
110
143
  const RSA_NO_PADDING: number;
@@ -117,17 +150,14 @@ declare module 'crypto' {
117
150
  const RSA_PSS_SALTLEN_MAX_SIGN: number;
118
151
  /** Causes the salt length for RSA_PKCS1_PSS_PADDING to be determined automatically when verifying a signature. */
119
152
  const RSA_PSS_SALTLEN_AUTO: number;
120
-
121
153
  const POINT_CONVERSION_COMPRESSED: number;
122
154
  const POINT_CONVERSION_UNCOMPRESSED: number;
123
155
  const POINT_CONVERSION_HYBRID: number;
124
-
125
156
  /** Specifies the built-in default cipher list used by Node.js (colon-separated values). */
126
157
  const defaultCoreCipherList: string;
127
158
  /** Specifies the active default cipher list used by the current Node.js process (colon-separated values). */
128
159
  const defaultCipherList: string;
129
160
  }
130
-
131
161
  interface HashOptions extends stream.TransformOptions {
132
162
  /**
133
163
  * For XOF hash functions such as `shake256`, the
@@ -135,188 +165,1104 @@ declare module 'crypto' {
135
165
  */
136
166
  outputLength?: number | undefined;
137
167
  }
138
-
139
168
  /** @deprecated since v10.0.0 */
140
169
  const fips: boolean;
141
-
170
+ /**
171
+ * Creates and returns a `Hash` object that can be used to generate hash digests
172
+ * using the given `algorithm`. Optional `options` argument controls stream
173
+ * behavior. For XOF hash functions such as `'shake256'`, the `outputLength` option
174
+ * can be used to specify the desired output length in bytes.
175
+ *
176
+ * The `algorithm` is dependent on the available algorithms supported by the
177
+ * version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc.
178
+ * On recent releases of OpenSSL, `openssl list -digest-algorithms`(`openssl list-message-digest-algorithms` for older versions of OpenSSL) will
179
+ * display the available digest algorithms.
180
+ *
181
+ * Example: generating the sha256 sum of a file
182
+ *
183
+ * ```js
184
+ * import {
185
+ * createReadStream
186
+ * } from 'fs';
187
+ * import { argv } from 'process';
188
+ * const {
189
+ * createHash
190
+ * } = await import('crypto');
191
+ *
192
+ * const filename = argv[2];
193
+ *
194
+ * const hash = createHash('sha256');
195
+ *
196
+ * const input = createReadStream(filename);
197
+ * input.on('readable', () => {
198
+ * // Only one element is going to be produced by the
199
+ * // hash stream.
200
+ * const data = input.read();
201
+ * if (data)
202
+ * hash.update(data);
203
+ * else {
204
+ * console.log(`${hash.digest('hex')} ${filename}`);
205
+ * }
206
+ * });
207
+ * ```
208
+ * @since v0.1.92
209
+ * @param options `stream.transform` options
210
+ */
142
211
  function createHash(algorithm: string, options?: HashOptions): Hash;
212
+ /**
213
+ * Creates and returns an `Hmac` object that uses the given `algorithm` and `key`.
214
+ * Optional `options` argument controls stream behavior.
215
+ *
216
+ * The `algorithm` is dependent on the available algorithms supported by the
217
+ * version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc.
218
+ * On recent releases of OpenSSL, `openssl list -digest-algorithms`(`openssl list-message-digest-algorithms` for older versions of OpenSSL) will
219
+ * display the available digest algorithms.
220
+ *
221
+ * The `key` is the HMAC key used to generate the cryptographic HMAC hash. If it is
222
+ * a `KeyObject`, its type must be `secret`.
223
+ *
224
+ * Example: generating the sha256 HMAC of a file
225
+ *
226
+ * ```js
227
+ * import {
228
+ * createReadStream
229
+ * } from 'fs';
230
+ * import { argv } from 'process';
231
+ * const {
232
+ * createHmac
233
+ * } = await import('crypto');
234
+ *
235
+ * const filename = argv[2];
236
+ *
237
+ * const hmac = createHmac('sha256', 'a secret');
238
+ *
239
+ * const input = createReadStream(filename);
240
+ * input.on('readable', () => {
241
+ * // Only one element is going to be produced by the
242
+ * // hash stream.
243
+ * const data = input.read();
244
+ * if (data)
245
+ * hmac.update(data);
246
+ * else {
247
+ * console.log(`${hmac.digest('hex')} ${filename}`);
248
+ * }
249
+ * });
250
+ * ```
251
+ * @since v0.1.94
252
+ * @param options `stream.transform` options
253
+ */
143
254
  function createHmac(algorithm: string, key: BinaryLike | KeyObject, options?: stream.TransformOptions): Hmac;
144
-
145
255
  // https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings
146
256
  type BinaryToTextEncoding = 'base64' | 'base64url' | 'hex';
147
257
  type CharacterEncoding = 'utf8' | 'utf-8' | 'utf16le' | 'latin1';
148
258
  type LegacyCharacterEncoding = 'ascii' | 'binary' | 'ucs2' | 'ucs-2';
149
-
150
259
  type Encoding = BinaryToTextEncoding | CharacterEncoding | LegacyCharacterEncoding;
151
-
152
260
  type ECDHKeyFormat = 'compressed' | 'uncompressed' | 'hybrid';
153
-
261
+ /**
262
+ * The `Hash` class is a utility for creating hash digests of data. It can be
263
+ * used in one of two ways:
264
+ *
265
+ * * As a `stream` that is both readable and writable, where data is written
266
+ * to produce a computed hash digest on the readable side, or
267
+ * * Using the `hash.update()` and `hash.digest()` methods to produce the
268
+ * computed hash.
269
+ *
270
+ * The {@link createHash} method is used to create `Hash` instances. `Hash`objects are not to be created directly using the `new` keyword.
271
+ *
272
+ * Example: Using `Hash` objects as streams:
273
+ *
274
+ * ```js
275
+ * const {
276
+ * createHash
277
+ * } = await import('crypto');
278
+ *
279
+ * const hash = createHash('sha256');
280
+ *
281
+ * hash.on('readable', () => {
282
+ * // Only one element is going to be produced by the
283
+ * // hash stream.
284
+ * const data = hash.read();
285
+ * if (data) {
286
+ * console.log(data.toString('hex'));
287
+ * // Prints:
288
+ * // 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
289
+ * }
290
+ * });
291
+ *
292
+ * hash.write('some data to hash');
293
+ * hash.end();
294
+ * ```
295
+ *
296
+ * Example: Using `Hash` and piped streams:
297
+ *
298
+ * ```js
299
+ * import { createReadStream } from 'fs';
300
+ * import { stdout } from 'process';
301
+ * const { createHash } = await import('crypto');
302
+ *
303
+ * const hash = createHash('sha256');
304
+ *
305
+ * const input = createReadStream('test.js');
306
+ * input.pipe(hash).setEncoding('hex').pipe(stdout);
307
+ * ```
308
+ *
309
+ * Example: Using the `hash.update()` and `hash.digest()` methods:
310
+ *
311
+ * ```js
312
+ * const {
313
+ * createHash
314
+ * } = await import('crypto');
315
+ *
316
+ * const hash = createHash('sha256');
317
+ *
318
+ * hash.update('some data to hash');
319
+ * console.log(hash.digest('hex'));
320
+ * // Prints:
321
+ * // 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
322
+ * ```
323
+ * @since v0.1.92
324
+ */
154
325
  class Hash extends stream.Transform {
155
326
  private constructor();
156
- copy(): Hash;
327
+ /**
328
+ * Creates a new `Hash` object that contains a deep copy of the internal state
329
+ * of the current `Hash` object.
330
+ *
331
+ * The optional `options` argument controls stream behavior. For XOF hash
332
+ * functions such as `'shake256'`, the `outputLength` option can be used to
333
+ * specify the desired output length in bytes.
334
+ *
335
+ * An error is thrown when an attempt is made to copy the `Hash` object after
336
+ * its `hash.digest()` method has been called.
337
+ *
338
+ * ```js
339
+ * // Calculate a rolling hash.
340
+ * const {
341
+ * createHash
342
+ * } = await import('crypto');
343
+ *
344
+ * const hash = createHash('sha256');
345
+ *
346
+ * hash.update('one');
347
+ * console.log(hash.copy().digest('hex'));
348
+ *
349
+ * hash.update('two');
350
+ * console.log(hash.copy().digest('hex'));
351
+ *
352
+ * hash.update('three');
353
+ * console.log(hash.copy().digest('hex'));
354
+ *
355
+ * // Etc.
356
+ * ```
357
+ * @since v13.1.0
358
+ * @param options `stream.transform` options
359
+ */
360
+ copy(options?: stream.TransformOptions): Hash;
361
+ /**
362
+ * Updates the hash content with the given `data`, the encoding of which
363
+ * is given in `inputEncoding`.
364
+ * If `encoding` is not provided, and the `data` is a string, an
365
+ * encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
366
+ *
367
+ * This can be called many times with new data as it is streamed.
368
+ * @since v0.1.92
369
+ * @param inputEncoding The `encoding` of the `data` string.
370
+ */
157
371
  update(data: BinaryLike): Hash;
158
- update(data: string, input_encoding: Encoding): Hash;
372
+ update(data: string, inputEncoding: Encoding): Hash;
373
+ /**
374
+ * Calculates the digest of all of the data passed to be hashed (using the `hash.update()` method).
375
+ * If `encoding` is provided a string will be returned; otherwise
376
+ * a `Buffer` is returned.
377
+ *
378
+ * The `Hash` object can not be used again after `hash.digest()` method has been
379
+ * called. Multiple calls will cause an error to be thrown.
380
+ * @since v0.1.92
381
+ * @param encoding The `encoding` of the return value.
382
+ */
159
383
  digest(): Buffer;
160
384
  digest(encoding: BinaryToTextEncoding): string;
161
385
  }
386
+ /**
387
+ * The `Hmac` class is a utility for creating cryptographic HMAC digests. It can
388
+ * be used in one of two ways:
389
+ *
390
+ * * As a `stream` that is both readable and writable, where data is written
391
+ * to produce a computed HMAC digest on the readable side, or
392
+ * * Using the `hmac.update()` and `hmac.digest()` methods to produce the
393
+ * computed HMAC digest.
394
+ *
395
+ * The {@link createHmac} method is used to create `Hmac` instances. `Hmac`objects are not to be created directly using the `new` keyword.
396
+ *
397
+ * Example: Using `Hmac` objects as streams:
398
+ *
399
+ * ```js
400
+ * const {
401
+ * createHmac
402
+ * } = await import('crypto');
403
+ *
404
+ * const hmac = createHmac('sha256', 'a secret');
405
+ *
406
+ * hmac.on('readable', () => {
407
+ * // Only one element is going to be produced by the
408
+ * // hash stream.
409
+ * const data = hmac.read();
410
+ * if (data) {
411
+ * console.log(data.toString('hex'));
412
+ * // Prints:
413
+ * // 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e
414
+ * }
415
+ * });
416
+ *
417
+ * hmac.write('some data to hash');
418
+ * hmac.end();
419
+ * ```
420
+ *
421
+ * Example: Using `Hmac` and piped streams:
422
+ *
423
+ * ```js
424
+ * import { createReadStream } from 'fs';
425
+ * import { stdout } from 'process';
426
+ * const {
427
+ * createHmac
428
+ * } = await import('crypto');
429
+ *
430
+ * const hmac = createHmac('sha256', 'a secret');
431
+ *
432
+ * const input = createReadStream('test.js');
433
+ * input.pipe(hmac).pipe(stdout);
434
+ * ```
435
+ *
436
+ * Example: Using the `hmac.update()` and `hmac.digest()` methods:
437
+ *
438
+ * ```js
439
+ * const {
440
+ * createHmac
441
+ * } = await import('crypto');
442
+ *
443
+ * const hmac = createHmac('sha256', 'a secret');
444
+ *
445
+ * hmac.update('some data to hash');
446
+ * console.log(hmac.digest('hex'));
447
+ * // Prints:
448
+ * // 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e
449
+ * ```
450
+ * @since v0.1.94
451
+ */
162
452
  class Hmac extends stream.Transform {
163
453
  private constructor();
454
+ /**
455
+ * Updates the `Hmac` content with the given `data`, the encoding of which
456
+ * is given in `inputEncoding`.
457
+ * If `encoding` is not provided, and the `data` is a string, an
458
+ * encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
459
+ *
460
+ * This can be called many times with new data as it is streamed.
461
+ * @since v0.1.94
462
+ * @param inputEncoding The `encoding` of the `data` string.
463
+ */
164
464
  update(data: BinaryLike): Hmac;
165
- update(data: string, input_encoding: Encoding): Hmac;
465
+ update(data: string, inputEncoding: Encoding): Hmac;
466
+ /**
467
+ * Calculates the HMAC digest of all of the data passed using `hmac.update()`.
468
+ * If `encoding` is
469
+ * provided a string is returned; otherwise a `Buffer` is returned;
470
+ *
471
+ * The `Hmac` object can not be used again after `hmac.digest()` has been
472
+ * called. Multiple calls to `hmac.digest()` will result in an error being thrown.
473
+ * @since v0.1.94
474
+ * @param encoding The `encoding` of the return value.
475
+ */
166
476
  digest(): Buffer;
167
477
  digest(encoding: BinaryToTextEncoding): string;
168
478
  }
169
-
170
479
  type KeyObjectType = 'secret' | 'public' | 'private';
171
-
172
480
  interface KeyExportOptions<T extends KeyFormat> {
173
481
  type: 'pkcs1' | 'spki' | 'pkcs8' | 'sec1';
174
482
  format: T;
175
483
  cipher?: string | undefined;
176
484
  passphrase?: string | Buffer | undefined;
177
485
  }
178
-
486
+ interface JwkKeyExportOptions {
487
+ format: 'jwk';
488
+ }
489
+ interface JsonWebKey {
490
+ crv?: string | undefined;
491
+ d?: string | undefined;
492
+ dp?: string | undefined;
493
+ dq?: string | undefined;
494
+ e?: string | undefined;
495
+ k?: string | undefined;
496
+ kty?: string | undefined;
497
+ n?: string | undefined;
498
+ p?: string | undefined;
499
+ q?: string | undefined;
500
+ qi?: string | undefined;
501
+ x?: string | undefined;
502
+ y?: string | undefined;
503
+ [key: string]: unknown;
504
+ }
505
+ interface AsymmetricKeyDetails {
506
+ /**
507
+ * Key size in bits (RSA, DSA).
508
+ */
509
+ modulusLength?: number | undefined;
510
+ /**
511
+ * Public exponent (RSA).
512
+ */
513
+ publicExponent?: bigint | undefined;
514
+ /**
515
+ * Name of the message digest (RSA-PSS).
516
+ */
517
+ hashAlgorithm?: string | undefined;
518
+ /**
519
+ * Name of the message digest used by MGF1 (RSA-PSS).
520
+ */
521
+ mgf1HashAlgorithm?: string | undefined;
522
+ /**
523
+ * Minimal salt length in bytes (RSA-PSS).
524
+ */
525
+ saltLength?: number | undefined;
526
+ /**
527
+ * Size of q in bits (DSA).
528
+ */
529
+ divisorLength?: number | undefined;
530
+ /**
531
+ * Name of the curve (EC).
532
+ */
533
+ namedCurve?: string | undefined;
534
+ }
535
+ /**
536
+ * Node.js uses a `KeyObject` class to represent a symmetric or asymmetric key,
537
+ * and each kind of key exposes different functions. The {@link createSecretKey}, {@link createPublicKey} and {@link createPrivateKey} methods are used to create `KeyObject`instances. `KeyObject`
538
+ * objects are not to be created directly using the `new`keyword.
539
+ *
540
+ * Most applications should consider using the new `KeyObject` API instead of
541
+ * passing keys as strings or `Buffer`s due to improved security features.
542
+ *
543
+ * `KeyObject` instances can be passed to other threads via `postMessage()`.
544
+ * The receiver obtains a cloned `KeyObject`, and the `KeyObject` does not need to
545
+ * be listed in the `transferList` argument.
546
+ * @since v11.6.0
547
+ */
179
548
  class KeyObject {
180
549
  private constructor();
550
+ /**
551
+ * Example: Converting a `CryptoKey` instance to a `KeyObject`:
552
+ *
553
+ * ```js
554
+ * const { webcrypto, KeyObject } = await import('crypto');
555
+ * const { subtle } = webcrypto;
556
+ *
557
+ * const key = await subtle.generateKey({
558
+ * name: 'HMAC',
559
+ * hash: 'SHA-256',
560
+ * length: 256
561
+ * }, true, ['sign', 'verify']);
562
+ *
563
+ * const keyObject = KeyObject.from(key);
564
+ * console.log(keyObject.symmetricKeySize);
565
+ * // Prints: 32 (symmetric key size in bytes)
566
+ * ```
567
+ * @since v15.0.0
568
+ */
569
+ static from(key: webcrypto.CryptoKey): KeyObject;
570
+ /**
571
+ * For asymmetric keys, this property represents the type of the key. Supported key
572
+ * types are:
573
+ *
574
+ * * `'rsa'` (OID 1.2.840.113549.1.1.1)
575
+ * * `'rsa-pss'` (OID 1.2.840.113549.1.1.10)
576
+ * * `'dsa'` (OID 1.2.840.10040.4.1)
577
+ * * `'ec'` (OID 1.2.840.10045.2.1)
578
+ * * `'x25519'` (OID 1.3.101.110)
579
+ * * `'x448'` (OID 1.3.101.111)
580
+ * * `'ed25519'` (OID 1.3.101.112)
581
+ * * `'ed448'` (OID 1.3.101.113)
582
+ * * `'dh'` (OID 1.2.840.113549.1.3.1)
583
+ *
584
+ * This property is `undefined` for unrecognized `KeyObject` types and symmetric
585
+ * keys.
586
+ * @since v11.6.0
587
+ */
181
588
  asymmetricKeyType?: KeyType | undefined;
182
589
  /**
183
590
  * For asymmetric keys, this property represents the size of the embedded key in
184
591
  * bytes. This property is `undefined` for symmetric keys.
185
592
  */
186
593
  asymmetricKeySize?: number | undefined;
594
+ /**
595
+ * This property exists only on asymmetric keys. Depending on the type of the key,
596
+ * this object contains information about the key. None of the information obtained
597
+ * through this property can be used to uniquely identify a key or to compromise
598
+ * the security of the key.
599
+ *
600
+ * For RSA-PSS keys, if the key material contains a `RSASSA-PSS-params` sequence,
601
+ * the `hashAlgorithm`, `mgf1HashAlgorithm`, and `saltLength` properties will be
602
+ * set.
603
+ *
604
+ * Other key details might be exposed via this API using additional attributes.
605
+ * @since v15.7.0
606
+ */
607
+ asymmetricKeyDetails?: AsymmetricKeyDetails | undefined;
608
+ /**
609
+ * For symmetric keys, the following encoding options can be used:
610
+ *
611
+ * For public keys, the following encoding options can be used:
612
+ *
613
+ * For private keys, the following encoding options can be used:
614
+ *
615
+ * The result type depends on the selected encoding format, when PEM the
616
+ * result is a string, when DER it will be a buffer containing the data
617
+ * encoded as DER, when [JWK](https://tools.ietf.org/html/rfc7517) it will be an object.
618
+ *
619
+ * When [JWK](https://tools.ietf.org/html/rfc7517) encoding format was selected, all other encoding options are
620
+ * ignored.
621
+ *
622
+ * PKCS#1, SEC1, and PKCS#8 type keys can be encrypted by using a combination of
623
+ * the `cipher` and `format` options. The PKCS#8 `type` can be used with any`format` to encrypt any key algorithm (RSA, EC, or DH) by specifying a`cipher`. PKCS#1 and SEC1 can only be
624
+ * encrypted by specifying a `cipher`when the PEM `format` is used. For maximum compatibility, use PKCS#8 for
625
+ * encrypted private keys. Since PKCS#8 defines its own
626
+ * encryption mechanism, PEM-level encryption is not supported when encrypting
627
+ * a PKCS#8 key. See [RFC 5208](https://www.rfc-editor.org/rfc/rfc5208.txt) for PKCS#8 encryption and [RFC 1421](https://www.rfc-editor.org/rfc/rfc1421.txt) for
628
+ * PKCS#1 and SEC1 encryption.
629
+ * @since v11.6.0
630
+ */
187
631
  export(options: KeyExportOptions<'pem'>): string | Buffer;
188
632
  export(options?: KeyExportOptions<'der'>): Buffer;
633
+ export(options?: JwkKeyExportOptions): JsonWebKey;
634
+ /**
635
+ * For secret keys, this property represents the size of the key in bytes. This
636
+ * property is `undefined` for asymmetric keys.
637
+ * @since v11.6.0
638
+ */
189
639
  symmetricKeySize?: number | undefined;
640
+ /**
641
+ * Depending on the type of this `KeyObject`, this property is either`'secret'` for secret (symmetric) keys, `'public'` for public (asymmetric) keys
642
+ * or `'private'` for private (asymmetric) keys.
643
+ * @since v11.6.0
644
+ */
190
645
  type: KeyObjectType;
191
646
  }
192
-
193
647
  type CipherCCMTypes = 'aes-128-ccm' | 'aes-192-ccm' | 'aes-256-ccm' | 'chacha20-poly1305';
194
648
  type CipherGCMTypes = 'aes-128-gcm' | 'aes-192-gcm' | 'aes-256-gcm';
195
-
649
+ type CipherOCBTypes = 'aes-128-ocb' | 'aes-192-ocb' | 'aes-256-ocb';
196
650
  type BinaryLike = string | NodeJS.ArrayBufferView;
197
-
198
651
  type CipherKey = BinaryLike | KeyObject;
199
-
200
652
  interface CipherCCMOptions extends stream.TransformOptions {
201
653
  authTagLength: number;
202
654
  }
203
655
  interface CipherGCMOptions extends stream.TransformOptions {
204
656
  authTagLength?: number | undefined;
205
657
  }
206
- /** @deprecated since v10.0.0 use `createCipheriv()` */
658
+ interface CipherOCBOptions extends stream.TransformOptions {
659
+ authTagLength: number;
660
+ }
661
+ /**
662
+ * Creates and returns a `Cipher` object that uses the given `algorithm` and`password`.
663
+ *
664
+ * The `options` argument controls stream behavior and is optional except when a
665
+ * cipher in CCM or OCB mode is used (e.g. `'aes-128-ccm'`). In that case, the`authTagLength` option is required and specifies the length of the
666
+ * authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength`option is not required but can be used to set the length of the authentication
667
+ * tag that will be returned by `getAuthTag()` and defaults to 16 bytes.
668
+ *
669
+ * The `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On
670
+ * recent OpenSSL releases, `openssl list -cipher-algorithms`(`openssl list-cipher-algorithms` for older versions of OpenSSL) will
671
+ * display the available cipher algorithms.
672
+ *
673
+ * The `password` is used to derive the cipher key and initialization vector (IV).
674
+ * The value must be either a `'latin1'` encoded string, a `Buffer`, a`TypedArray`, or a `DataView`.
675
+ *
676
+ * The implementation of `crypto.createCipher()` derives keys using the OpenSSL
677
+ * function [`EVP_BytesToKey`](https://www.openssl.org/docs/man1.1.0/crypto/EVP_BytesToKey.html) with the digest algorithm set to MD5, one
678
+ * iteration, and no salt. The lack of salt allows dictionary attacks as the same
679
+ * password always creates the same key. The low iteration count and
680
+ * non-cryptographically secure hash algorithm allow passwords to be tested very
681
+ * rapidly.
682
+ *
683
+ * In line with OpenSSL's recommendation to use a more modern algorithm instead of [`EVP_BytesToKey`](https://www.openssl.org/docs/man1.1.0/crypto/EVP_BytesToKey.html) it is recommended that
684
+ * developers derive a key and IV on
685
+ * their own using {@link scrypt} and to use {@link createCipheriv} to create the `Cipher` object. Users should not use ciphers with counter mode
686
+ * (e.g. CTR, GCM, or CCM) in `crypto.createCipher()`. A warning is emitted when
687
+ * they are used in order to avoid the risk of IV reuse that causes
688
+ * vulnerabilities. For the case when IV is reused in GCM, see [Nonce-Disrespecting Adversaries](https://github.com/nonce-disrespect/nonce-disrespect) for details.
689
+ * @since v0.1.94
690
+ * @deprecated Since v10.0.0 - Use {@link createCipheriv} instead.
691
+ * @param options `stream.transform` options
692
+ */
207
693
  function createCipher(algorithm: CipherCCMTypes, password: BinaryLike, options: CipherCCMOptions): CipherCCM;
208
694
  /** @deprecated since v10.0.0 use `createCipheriv()` */
209
695
  function createCipher(algorithm: CipherGCMTypes, password: BinaryLike, options?: CipherGCMOptions): CipherGCM;
210
696
  /** @deprecated since v10.0.0 use `createCipheriv()` */
211
697
  function createCipher(algorithm: string, password: BinaryLike, options?: stream.TransformOptions): Cipher;
212
-
213
- function createCipheriv(
214
- algorithm: CipherCCMTypes,
215
- key: CipherKey,
216
- iv: BinaryLike | null,
217
- options: CipherCCMOptions,
218
- ): CipherCCM;
219
- function createCipheriv(
220
- algorithm: CipherGCMTypes,
221
- key: CipherKey,
222
- iv: BinaryLike | null,
223
- options?: CipherGCMOptions,
224
- ): CipherGCM;
225
- function createCipheriv(
226
- algorithm: string,
227
- key: CipherKey,
228
- iv: BinaryLike | null,
229
- options?: stream.TransformOptions,
230
- ): Cipher;
231
-
698
+ /**
699
+ * Creates and returns a `Cipher` object, with the given `algorithm`, `key` and
700
+ * initialization vector (`iv`).
701
+ *
702
+ * The `options` argument controls stream behavior and is optional except when a
703
+ * cipher in CCM or OCB mode is used (e.g. `'aes-128-ccm'`). In that case, the`authTagLength` option is required and specifies the length of the
704
+ * authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength`option is not required but can be used to set the length of the authentication
705
+ * tag that will be returned by `getAuthTag()` and defaults to 16 bytes.
706
+ *
707
+ * The `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On
708
+ * recent OpenSSL releases, `openssl list -cipher-algorithms`(`openssl list-cipher-algorithms` for older versions of OpenSSL) will
709
+ * display the available cipher algorithms.
710
+ *
711
+ * The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded
712
+ * strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be
713
+ * a `KeyObject` of type `secret`. If the cipher does not need
714
+ * an initialization vector, `iv` may be `null`.
715
+ *
716
+ * When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`.
717
+ *
718
+ * Initialization vectors should be unpredictable and unique; ideally, they will be
719
+ * cryptographically random. They do not have to be secret: IVs are typically just
720
+ * added to ciphertext messages unencrypted. It may sound contradictory that
721
+ * something has to be unpredictable and unique, but does not have to be secret;
722
+ * remember that an attacker must not be able to predict ahead of time what a
723
+ * given IV will be.
724
+ * @since v0.1.94
725
+ * @param options `stream.transform` options
726
+ */
727
+ function createCipheriv(algorithm: CipherCCMTypes, key: CipherKey, iv: BinaryLike, options: CipherCCMOptions): CipherCCM;
728
+ function createCipheriv(algorithm: CipherOCBTypes, key: CipherKey, iv: BinaryLike, options: CipherOCBOptions): CipherOCB;
729
+ function createCipheriv(algorithm: CipherGCMTypes, key: CipherKey, iv: BinaryLike, options?: CipherGCMOptions): CipherGCM;
730
+ function createCipheriv(algorithm: string, key: CipherKey, iv: BinaryLike | null, options?: stream.TransformOptions): Cipher;
731
+ /**
732
+ * Instances of the `Cipher` class are used to encrypt data. The class can be
733
+ * used in one of two ways:
734
+ *
735
+ * * As a `stream` that is both readable and writable, where plain unencrypted
736
+ * data is written to produce encrypted data on the readable side, or
737
+ * * Using the `cipher.update()` and `cipher.final()` methods to produce
738
+ * the encrypted data.
739
+ *
740
+ * The {@link createCipher} or {@link createCipheriv} methods are
741
+ * used to create `Cipher` instances. `Cipher` objects are not to be created
742
+ * directly using the `new` keyword.
743
+ *
744
+ * Example: Using `Cipher` objects as streams:
745
+ *
746
+ * ```js
747
+ * const {
748
+ * scrypt,
749
+ * randomFill,
750
+ * createCipheriv
751
+ * } = await import('crypto');
752
+ *
753
+ * const algorithm = 'aes-192-cbc';
754
+ * const password = 'Password used to generate key';
755
+ *
756
+ * // First, we'll generate the key. The key length is dependent on the algorithm.
757
+ * // In this case for aes192, it is 24 bytes (192 bits).
758
+ * scrypt(password, 'salt', 24, (err, key) => {
759
+ * if (err) throw err;
760
+ * // Then, we'll generate a random initialization vector
761
+ * randomFill(new Uint8Array(16), (err, iv) => {
762
+ * if (err) throw err;
763
+ *
764
+ * // Once we have the key and iv, we can create and use the cipher...
765
+ * const cipher = createCipheriv(algorithm, key, iv);
766
+ *
767
+ * let encrypted = '';
768
+ * cipher.setEncoding('hex');
769
+ *
770
+ * cipher.on('data', (chunk) => encrypted += chunk);
771
+ * cipher.on('end', () => console.log(encrypted));
772
+ *
773
+ * cipher.write('some clear text data');
774
+ * cipher.end();
775
+ * });
776
+ * });
777
+ * ```
778
+ *
779
+ * Example: Using `Cipher` and piped streams:
780
+ *
781
+ * ```js
782
+ * import {
783
+ * createReadStream,
784
+ * createWriteStream,
785
+ * } from 'fs';
786
+ *
787
+ * import {
788
+ * pipeline
789
+ * } from 'stream';
790
+ *
791
+ * const {
792
+ * scrypt,
793
+ * randomFill,
794
+ * createCipheriv
795
+ * } = await import('crypto');
796
+ *
797
+ * const algorithm = 'aes-192-cbc';
798
+ * const password = 'Password used to generate key';
799
+ *
800
+ * // First, we'll generate the key. The key length is dependent on the algorithm.
801
+ * // In this case for aes192, it is 24 bytes (192 bits).
802
+ * scrypt(password, 'salt', 24, (err, key) => {
803
+ * if (err) throw err;
804
+ * // Then, we'll generate a random initialization vector
805
+ * randomFill(new Uint8Array(16), (err, iv) => {
806
+ * if (err) throw err;
807
+ *
808
+ * const cipher = createCipheriv(algorithm, key, iv);
809
+ *
810
+ * const input = createReadStream('test.js');
811
+ * const output = createWriteStream('test.enc');
812
+ *
813
+ * pipeline(input, cipher, output, (err) => {
814
+ * if (err) throw err;
815
+ * });
816
+ * });
817
+ * });
818
+ * ```
819
+ *
820
+ * Example: Using the `cipher.update()` and `cipher.final()` methods:
821
+ *
822
+ * ```js
823
+ * const {
824
+ * scrypt,
825
+ * randomFill,
826
+ * createCipheriv
827
+ * } = await import('crypto');
828
+ *
829
+ * const algorithm = 'aes-192-cbc';
830
+ * const password = 'Password used to generate key';
831
+ *
832
+ * // First, we'll generate the key. The key length is dependent on the algorithm.
833
+ * // In this case for aes192, it is 24 bytes (192 bits).
834
+ * scrypt(password, 'salt', 24, (err, key) => {
835
+ * if (err) throw err;
836
+ * // Then, we'll generate a random initialization vector
837
+ * randomFill(new Uint8Array(16), (err, iv) => {
838
+ * if (err) throw err;
839
+ *
840
+ * const cipher = createCipheriv(algorithm, key, iv);
841
+ *
842
+ * let encrypted = cipher.update('some clear text data', 'utf8', 'hex');
843
+ * encrypted += cipher.final('hex');
844
+ * console.log(encrypted);
845
+ * });
846
+ * });
847
+ * ```
848
+ * @since v0.1.94
849
+ */
232
850
  class Cipher extends stream.Transform {
233
851
  private constructor();
852
+ /**
853
+ * Updates the cipher with `data`. If the `inputEncoding` argument is given,
854
+ * the `data`argument is a string using the specified encoding. If the `inputEncoding`argument is not given, `data` must be a `Buffer`, `TypedArray`, or`DataView`. If `data` is a `Buffer`,
855
+ * `TypedArray`, or `DataView`, then`inputEncoding` is ignored.
856
+ *
857
+ * The `outputEncoding` specifies the output format of the enciphered
858
+ * data. If the `outputEncoding`is specified, a string using the specified encoding is returned. If no`outputEncoding` is provided, a `Buffer` is returned.
859
+ *
860
+ * The `cipher.update()` method can be called multiple times with new data until `cipher.final()` is called. Calling `cipher.update()` after `cipher.final()` will result in an error being
861
+ * thrown.
862
+ * @since v0.1.94
863
+ * @param inputEncoding The `encoding` of the data.
864
+ * @param outputEncoding The `encoding` of the return value.
865
+ */
234
866
  update(data: BinaryLike): Buffer;
235
- update(data: string, input_encoding: Encoding): Buffer;
236
- update(data: NodeJS.ArrayBufferView, input_encoding: undefined, output_encoding: Encoding): string;
237
- update(data: string, input_encoding: Encoding | undefined, output_encoding: Encoding): string;
867
+ update(data: string, inputEncoding: Encoding): Buffer;
868
+ update(data: NodeJS.ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding): string;
869
+ update(data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding): string;
870
+ /**
871
+ * Once the `cipher.final()` method has been called, the `Cipher` object can no
872
+ * longer be used to encrypt data. Attempts to call `cipher.final()` more than
873
+ * once will result in an error being thrown.
874
+ * @since v0.1.94
875
+ * @param outputEncoding The `encoding` of the return value.
876
+ * @return Any remaining enciphered contents. If `outputEncoding` is specified, a string is returned. If an `outputEncoding` is not provided, a {@link Buffer} is returned.
877
+ */
238
878
  final(): Buffer;
239
- final(output_encoding: BufferEncoding): string;
240
- setAutoPadding(auto_padding?: boolean): this;
241
- // getAuthTag(): Buffer;
242
- // setAAD(buffer: NodeJS.ArrayBufferView): this;
879
+ final(outputEncoding: BufferEncoding): string;
880
+ /**
881
+ * When using block encryption algorithms, the `Cipher` class will automatically
882
+ * add padding to the input data to the appropriate block size. To disable the
883
+ * default padding call `cipher.setAutoPadding(false)`.
884
+ *
885
+ * When `autoPadding` is `false`, the length of the entire input data must be a
886
+ * multiple of the cipher's block size or `cipher.final()` will throw an error.
887
+ * Disabling automatic padding is useful for non-standard padding, for instance
888
+ * using `0x0` instead of PKCS padding.
889
+ *
890
+ * The `cipher.setAutoPadding()` method must be called before `cipher.final()`.
891
+ * @since v0.7.1
892
+ * @param [autoPadding=true]
893
+ * @return for method chaining.
894
+ */
895
+ setAutoPadding(autoPadding?: boolean): this;
243
896
  }
244
897
  interface CipherCCM extends Cipher {
245
- setAAD(buffer: NodeJS.ArrayBufferView, options: { plaintextLength: number }): this;
898
+ setAAD(
899
+ buffer: NodeJS.ArrayBufferView,
900
+ options: {
901
+ plaintextLength: number;
902
+ }
903
+ ): this;
246
904
  getAuthTag(): Buffer;
247
905
  }
248
906
  interface CipherGCM extends Cipher {
249
- setAAD(buffer: NodeJS.ArrayBufferView, options?: { plaintextLength: number }): this;
907
+ setAAD(
908
+ buffer: NodeJS.ArrayBufferView,
909
+ options?: {
910
+ plaintextLength: number;
911
+ }
912
+ ): this;
250
913
  getAuthTag(): Buffer;
251
914
  }
252
- /** @deprecated since v10.0.0 use `createDecipheriv()` */
915
+ interface CipherOCB extends Cipher {
916
+ setAAD(
917
+ buffer: NodeJS.ArrayBufferView,
918
+ options?: {
919
+ plaintextLength: number;
920
+ }
921
+ ): this;
922
+ getAuthTag(): Buffer;
923
+ }
924
+ /**
925
+ * Creates and returns a `Decipher` object that uses the given `algorithm` and`password` (key).
926
+ *
927
+ * The `options` argument controls stream behavior and is optional except when a
928
+ * cipher in CCM or OCB mode is used (e.g. `'aes-128-ccm'`). In that case, the`authTagLength` option is required and specifies the length of the
929
+ * authentication tag in bytes, see `CCM mode`.
930
+ *
931
+ * The implementation of `crypto.createDecipher()` derives keys using the OpenSSL
932
+ * function [`EVP_BytesToKey`](https://www.openssl.org/docs/man1.1.0/crypto/EVP_BytesToKey.html) with the digest algorithm set to MD5, one
933
+ * iteration, and no salt. The lack of salt allows dictionary attacks as the same
934
+ * password always creates the same key. The low iteration count and
935
+ * non-cryptographically secure hash algorithm allow passwords to be tested very
936
+ * rapidly.
937
+ *
938
+ * In line with OpenSSL's recommendation to use a more modern algorithm instead of [`EVP_BytesToKey`](https://www.openssl.org/docs/man1.1.0/crypto/EVP_BytesToKey.html) it is recommended that
939
+ * developers derive a key and IV on
940
+ * their own using {@link scrypt} and to use {@link createDecipheriv} to create the `Decipher` object.
941
+ * @since v0.1.94
942
+ * @deprecated Since v10.0.0 - Use {@link createDecipheriv} instead.
943
+ * @param options `stream.transform` options
944
+ */
253
945
  function createDecipher(algorithm: CipherCCMTypes, password: BinaryLike, options: CipherCCMOptions): DecipherCCM;
254
946
  /** @deprecated since v10.0.0 use `createDecipheriv()` */
255
947
  function createDecipher(algorithm: CipherGCMTypes, password: BinaryLike, options?: CipherGCMOptions): DecipherGCM;
256
948
  /** @deprecated since v10.0.0 use `createDecipheriv()` */
257
949
  function createDecipher(algorithm: string, password: BinaryLike, options?: stream.TransformOptions): Decipher;
258
-
259
- function createDecipheriv(
260
- algorithm: CipherCCMTypes,
261
- key: CipherKey,
262
- iv: BinaryLike | null,
263
- options: CipherCCMOptions,
264
- ): DecipherCCM;
265
- function createDecipheriv(
266
- algorithm: CipherGCMTypes,
267
- key: CipherKey,
268
- iv: BinaryLike | null,
269
- options?: CipherGCMOptions,
270
- ): DecipherGCM;
271
- function createDecipheriv(
272
- algorithm: string,
273
- key: CipherKey,
274
- iv: BinaryLike | null,
275
- options?: stream.TransformOptions,
276
- ): Decipher;
277
-
950
+ /**
951
+ * Creates and returns a `Decipher` object that uses the given `algorithm`, `key`and initialization vector (`iv`).
952
+ *
953
+ * The `options` argument controls stream behavior and is optional except when a
954
+ * cipher in CCM or OCB mode is used (e.g. `'aes-128-ccm'`). In that case, the`authTagLength` option is required and specifies the length of the
955
+ * authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength`option is not required but can be used to restrict accepted authentication tags
956
+ * to those with the specified length.
957
+ *
958
+ * The `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On
959
+ * recent OpenSSL releases, `openssl list -cipher-algorithms`(`openssl list-cipher-algorithms` for older versions of OpenSSL) will
960
+ * display the available cipher algorithms.
961
+ *
962
+ * The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded
963
+ * strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be
964
+ * a `KeyObject` of type `secret`. If the cipher does not need
965
+ * an initialization vector, `iv` may be `null`.
966
+ *
967
+ * When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`.
968
+ *
969
+ * Initialization vectors should be unpredictable and unique; ideally, they will be
970
+ * cryptographically random. They do not have to be secret: IVs are typically just
971
+ * added to ciphertext messages unencrypted. It may sound contradictory that
972
+ * something has to be unpredictable and unique, but does not have to be secret;
973
+ * remember that an attacker must not be able to predict ahead of time what a given
974
+ * IV will be.
975
+ * @since v0.1.94
976
+ * @param options `stream.transform` options
977
+ */
978
+ function createDecipheriv(algorithm: CipherCCMTypes, key: CipherKey, iv: BinaryLike, options: CipherCCMOptions): DecipherCCM;
979
+ function createDecipheriv(algorithm: CipherOCBTypes, key: CipherKey, iv: BinaryLike, options: CipherOCBOptions): DecipherOCB;
980
+ function createDecipheriv(algorithm: CipherGCMTypes, key: CipherKey, iv: BinaryLike, options?: CipherGCMOptions): DecipherGCM;
981
+ function createDecipheriv(algorithm: string, key: CipherKey, iv: BinaryLike | null, options?: stream.TransformOptions): Decipher;
982
+ /**
983
+ * Instances of the `Decipher` class are used to decrypt data. The class can be
984
+ * used in one of two ways:
985
+ *
986
+ * * As a `stream` that is both readable and writable, where plain encrypted
987
+ * data is written to produce unencrypted data on the readable side, or
988
+ * * Using the `decipher.update()` and `decipher.final()` methods to
989
+ * produce the unencrypted data.
990
+ *
991
+ * The {@link createDecipher} or {@link createDecipheriv} methods are
992
+ * used to create `Decipher` instances. `Decipher` objects are not to be created
993
+ * directly using the `new` keyword.
994
+ *
995
+ * Example: Using `Decipher` objects as streams:
996
+ *
997
+ * ```js
998
+ * import { Buffer } from 'buffer';
999
+ * const {
1000
+ * scryptSync,
1001
+ * createDecipheriv
1002
+ * } = await import('crypto');
1003
+ *
1004
+ * const algorithm = 'aes-192-cbc';
1005
+ * const password = 'Password used to generate key';
1006
+ * // Key length is dependent on the algorithm. In this case for aes192, it is
1007
+ * // 24 bytes (192 bits).
1008
+ * // Use the async `crypto.scrypt()` instead.
1009
+ * const key = scryptSync(password, 'salt', 24);
1010
+ * // The IV is usually passed along with the ciphertext.
1011
+ * const iv = Buffer.alloc(16, 0); // Initialization vector.
1012
+ *
1013
+ * const decipher = createDecipheriv(algorithm, key, iv);
1014
+ *
1015
+ * let decrypted = '';
1016
+ * decipher.on('readable', () => {
1017
+ * while (null !== (chunk = decipher.read())) {
1018
+ * decrypted += chunk.toString('utf8');
1019
+ * }
1020
+ * });
1021
+ * decipher.on('end', () => {
1022
+ * console.log(decrypted);
1023
+ * // Prints: some clear text data
1024
+ * });
1025
+ *
1026
+ * // Encrypted with same algorithm, key and iv.
1027
+ * const encrypted =
1028
+ * 'e5f79c5915c02171eec6b212d5520d44480993d7d622a7c4c2da32f6efda0ffa';
1029
+ * decipher.write(encrypted, 'hex');
1030
+ * decipher.end();
1031
+ * ```
1032
+ *
1033
+ * Example: Using `Decipher` and piped streams:
1034
+ *
1035
+ * ```js
1036
+ * import {
1037
+ * createReadStream,
1038
+ * createWriteStream,
1039
+ * } from 'fs';
1040
+ * import { Buffer } from 'buffer';
1041
+ * const {
1042
+ * scryptSync,
1043
+ * createDecipheriv
1044
+ * } = await import('crypto');
1045
+ *
1046
+ * const algorithm = 'aes-192-cbc';
1047
+ * const password = 'Password used to generate key';
1048
+ * // Use the async `crypto.scrypt()` instead.
1049
+ * const key = scryptSync(password, 'salt', 24);
1050
+ * // The IV is usually passed along with the ciphertext.
1051
+ * const iv = Buffer.alloc(16, 0); // Initialization vector.
1052
+ *
1053
+ * const decipher = createDecipheriv(algorithm, key, iv);
1054
+ *
1055
+ * const input = createReadStream('test.enc');
1056
+ * const output = createWriteStream('test.js');
1057
+ *
1058
+ * input.pipe(decipher).pipe(output);
1059
+ * ```
1060
+ *
1061
+ * Example: Using the `decipher.update()` and `decipher.final()` methods:
1062
+ *
1063
+ * ```js
1064
+ * import { Buffer } from 'buffer';
1065
+ * const {
1066
+ * scryptSync,
1067
+ * createDecipheriv
1068
+ * } = await import('crypto');
1069
+ *
1070
+ * const algorithm = 'aes-192-cbc';
1071
+ * const password = 'Password used to generate key';
1072
+ * // Use the async `crypto.scrypt()` instead.
1073
+ * const key = scryptSync(password, 'salt', 24);
1074
+ * // The IV is usually passed along with the ciphertext.
1075
+ * const iv = Buffer.alloc(16, 0); // Initialization vector.
1076
+ *
1077
+ * const decipher = createDecipheriv(algorithm, key, iv);
1078
+ *
1079
+ * // Encrypted using same algorithm, key and iv.
1080
+ * const encrypted =
1081
+ * 'e5f79c5915c02171eec6b212d5520d44480993d7d622a7c4c2da32f6efda0ffa';
1082
+ * let decrypted = decipher.update(encrypted, 'hex', 'utf8');
1083
+ * decrypted += decipher.final('utf8');
1084
+ * console.log(decrypted);
1085
+ * // Prints: some clear text data
1086
+ * ```
1087
+ * @since v0.1.94
1088
+ */
278
1089
  class Decipher extends stream.Transform {
279
1090
  private constructor();
1091
+ /**
1092
+ * Updates the decipher with `data`. If the `inputEncoding` argument is given,
1093
+ * the `data`argument is a string using the specified encoding. If the `inputEncoding`argument is not given, `data` must be a `Buffer`. If `data` is a `Buffer` then `inputEncoding` is
1094
+ * ignored.
1095
+ *
1096
+ * The `outputEncoding` specifies the output format of the enciphered
1097
+ * data. If the `outputEncoding`is specified, a string using the specified encoding is returned. If no`outputEncoding` is provided, a `Buffer` is returned.
1098
+ *
1099
+ * The `decipher.update()` method can be called multiple times with new data until `decipher.final()` is called. Calling `decipher.update()` after `decipher.final()` will result in an error
1100
+ * being thrown.
1101
+ * @since v0.1.94
1102
+ * @param inputEncoding The `encoding` of the `data` string.
1103
+ * @param outputEncoding The `encoding` of the return value.
1104
+ */
280
1105
  update(data: NodeJS.ArrayBufferView): Buffer;
281
- update(data: string, input_encoding: Encoding): Buffer;
282
- update(data: NodeJS.ArrayBufferView, input_encoding: undefined, output_encoding: Encoding): string;
283
- update(data: string, input_encoding: Encoding | undefined, output_encoding: Encoding): string;
1106
+ update(data: string, inputEncoding: Encoding): Buffer;
1107
+ update(data: NodeJS.ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding): string;
1108
+ update(data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding): string;
1109
+ /**
1110
+ * Once the `decipher.final()` method has been called, the `Decipher` object can
1111
+ * no longer be used to decrypt data. Attempts to call `decipher.final()` more
1112
+ * than once will result in an error being thrown.
1113
+ * @since v0.1.94
1114
+ * @param outputEncoding The `encoding` of the return value.
1115
+ * @return Any remaining deciphered contents. If `outputEncoding` is specified, a string is returned. If an `outputEncoding` is not provided, a {@link Buffer} is returned.
1116
+ */
284
1117
  final(): Buffer;
285
- final(output_encoding: BufferEncoding): string;
1118
+ final(outputEncoding: BufferEncoding): string;
1119
+ /**
1120
+ * When data has been encrypted without standard block padding, calling`decipher.setAutoPadding(false)` will disable automatic padding to prevent `decipher.final()` from checking for and
1121
+ * removing padding.
1122
+ *
1123
+ * Turning auto padding off will only work if the input data's length is a
1124
+ * multiple of the ciphers block size.
1125
+ *
1126
+ * The `decipher.setAutoPadding()` method must be called before `decipher.final()`.
1127
+ * @since v0.7.1
1128
+ * @param [autoPadding=true]
1129
+ * @return for method chaining.
1130
+ */
286
1131
  setAutoPadding(auto_padding?: boolean): this;
287
- // setAuthTag(tag: NodeJS.ArrayBufferView): this;
288
- // setAAD(buffer: NodeJS.ArrayBufferView): this;
289
1132
  }
290
1133
  interface DecipherCCM extends Decipher {
291
1134
  setAuthTag(buffer: NodeJS.ArrayBufferView): this;
292
- setAAD(buffer: NodeJS.ArrayBufferView, options: { plaintextLength: number }): this;
1135
+ setAAD(
1136
+ buffer: NodeJS.ArrayBufferView,
1137
+ options: {
1138
+ plaintextLength: number;
1139
+ }
1140
+ ): this;
293
1141
  }
294
1142
  interface DecipherGCM extends Decipher {
295
1143
  setAuthTag(buffer: NodeJS.ArrayBufferView): this;
296
- setAAD(buffer: NodeJS.ArrayBufferView, options?: { plaintextLength: number }): this;
1144
+ setAAD(
1145
+ buffer: NodeJS.ArrayBufferView,
1146
+ options?: {
1147
+ plaintextLength: number;
1148
+ }
1149
+ ): this;
1150
+ }
1151
+ interface DecipherOCB extends Decipher {
1152
+ setAuthTag(buffer: NodeJS.ArrayBufferView): this;
1153
+ setAAD(
1154
+ buffer: NodeJS.ArrayBufferView,
1155
+ options?: {
1156
+ plaintextLength: number;
1157
+ }
1158
+ ): this;
297
1159
  }
298
-
299
1160
  interface PrivateKeyInput {
300
1161
  key: string | Buffer;
301
1162
  format?: KeyFormat | undefined;
302
1163
  type?: 'pkcs1' | 'pkcs8' | 'sec1' | undefined;
303
1164
  passphrase?: string | Buffer | undefined;
1165
+ encoding?: string | undefined;
304
1166
  }
305
-
306
1167
  interface PublicKeyInput {
307
1168
  key: string | Buffer;
308
1169
  format?: KeyFormat | undefined;
309
1170
  type?: 'pkcs1' | 'spki' | undefined;
1171
+ encoding?: string | undefined;
310
1172
  }
311
-
312
- function createPrivateKey(key: PrivateKeyInput | string | Buffer): KeyObject;
313
- function createPublicKey(key: PublicKeyInput | string | Buffer | KeyObject): KeyObject;
1173
+ /**
1174
+ * Asynchronously generates a new random secret key of the given `length`. The`type` will determine which validations will be performed on the `length`.
1175
+ *
1176
+ * ```js
1177
+ * const {
1178
+ * generateKey
1179
+ * } = await import('crypto');
1180
+ *
1181
+ * generateKey('hmac', { length: 64 }, (err, key) => {
1182
+ * if (err) throw err;
1183
+ * console.log(key.export().toString('hex')); // 46e..........620
1184
+ * });
1185
+ * ```
1186
+ * @since v15.0.0
1187
+ * @param type The intended use of the generated secret key. Currently accepted values are `'hmac'` and `'aes'`.
1188
+ */
1189
+ function generateKey(
1190
+ type: 'hmac' | 'aes',
1191
+ options: {
1192
+ length: number;
1193
+ },
1194
+ callback: (err: Error | null, key: KeyObject) => void
1195
+ ): void;
1196
+ /**
1197
+ * Synchronously generates a new random secret key of the given `length`. The`type` will determine which validations will be performed on the `length`.
1198
+ *
1199
+ * ```js
1200
+ * const {
1201
+ * generateKeySync
1202
+ * } = await import('crypto');
1203
+ *
1204
+ * const key = generateKeySync('hmac', { length: 64 });
1205
+ * console.log(key.export().toString('hex')); // e89..........41e
1206
+ * ```
1207
+ * @since v15.0.0
1208
+ * @param type The intended use of the generated secret key. Currently accepted values are `'hmac'` and `'aes'`.
1209
+ */
1210
+ function generateKeySync(
1211
+ type: 'hmac' | 'aes',
1212
+ options: {
1213
+ length: number;
1214
+ }
1215
+ ): KeyObject;
1216
+ interface JsonWebKeyInput {
1217
+ key: JsonWebKey;
1218
+ format: 'jwk';
1219
+ }
1220
+ /**
1221
+ * Creates and returns a new key object containing a private key. If `key` is a
1222
+ * string or `Buffer`, `format` is assumed to be `'pem'`; otherwise, `key`must be an object with the properties described above.
1223
+ *
1224
+ * If the private key is encrypted, a `passphrase` must be specified. The length
1225
+ * of the passphrase is limited to 1024 bytes.
1226
+ * @since v11.6.0
1227
+ */
1228
+ function createPrivateKey(key: PrivateKeyInput | string | Buffer | JsonWebKeyInput): KeyObject;
1229
+ /**
1230
+ * Creates and returns a new key object containing a public key. If `key` is a
1231
+ * string or `Buffer`, `format` is assumed to be `'pem'`; if `key` is a `KeyObject`with type `'private'`, the public key is derived from the given private key;
1232
+ * otherwise, `key` must be an object with the properties described above.
1233
+ *
1234
+ * If the format is `'pem'`, the `'key'` may also be an X.509 certificate.
1235
+ *
1236
+ * Because public keys can be derived from private keys, a private key may be
1237
+ * passed instead of a public key. In that case, this function behaves as if {@link createPrivateKey} had been called, except that the type of the
1238
+ * returned `KeyObject` will be `'public'` and that the private key cannot be
1239
+ * extracted from the returned `KeyObject`. Similarly, if a `KeyObject` with type`'private'` is given, a new `KeyObject` with type `'public'` will be returned
1240
+ * and it will be impossible to extract the private key from the returned object.
1241
+ * @since v11.6.0
1242
+ */
1243
+ function createPublicKey(key: PublicKeyInput | string | Buffer | KeyObject | JsonWebKeyInput): KeyObject;
1244
+ /**
1245
+ * Creates and returns a new key object containing a secret key for symmetric
1246
+ * encryption or `Hmac`.
1247
+ * @since v11.6.0
1248
+ * @param encoding The string encoding when `key` is a string.
1249
+ */
314
1250
  function createSecretKey(key: NodeJS.ArrayBufferView): KeyObject;
315
-
316
- function createSign(algorithm: string, options?: stream.WritableOptions): Signer;
317
-
1251
+ function createSecretKey(key: string, encoding: BufferEncoding): KeyObject;
1252
+ /**
1253
+ * Creates and returns a `Sign` object that uses the given `algorithm`. Use {@link getHashes} to obtain the names of the available digest algorithms.
1254
+ * Optional `options` argument controls the `stream.Writable` behavior.
1255
+ *
1256
+ * In some cases, a `Sign` instance can be created using the name of a signature
1257
+ * algorithm, such as `'RSA-SHA256'`, instead of a digest algorithm. This will use
1258
+ * the corresponding digest algorithm. This does not work for all signature
1259
+ * algorithms, such as `'ecdsa-with-SHA256'`, so it is best to always use digest
1260
+ * algorithm names.
1261
+ * @since v0.1.92
1262
+ * @param options `stream.Writable` options
1263
+ */
1264
+ function createSign(algorithm: string, options?: stream.WritableOptions): Sign;
318
1265
  type DSAEncoding = 'der' | 'ieee-p1363';
319
-
320
1266
  interface SigningOptions {
321
1267
  /**
322
1268
  * @See crypto.constants.RSA_PKCS1_PADDING
@@ -325,7 +1271,6 @@ declare module 'crypto' {
325
1271
  saltLength?: number | undefined;
326
1272
  dsaEncoding?: DSAEncoding | undefined;
327
1273
  }
328
-
329
1274
  interface SignPrivateKeyInput extends PrivateKeyInput, SigningOptions {}
330
1275
  interface SignKeyObjectInput extends SigningOptions {
331
1276
  key: KeyObject;
@@ -334,137 +1279,697 @@ declare module 'crypto' {
334
1279
  interface VerifyKeyObjectInput extends SigningOptions {
335
1280
  key: KeyObject;
336
1281
  }
337
-
338
1282
  type KeyLike = string | Buffer | KeyObject;
339
-
340
- class Signer extends stream.Writable {
1283
+ /**
1284
+ * The `Sign` class is a utility for generating signatures. It can be used in one
1285
+ * of two ways:
1286
+ *
1287
+ * * As a writable `stream`, where data to be signed is written and the `sign.sign()` method is used to generate and return the signature, or
1288
+ * * Using the `sign.update()` and `sign.sign()` methods to produce the
1289
+ * signature.
1290
+ *
1291
+ * The {@link createSign} method is used to create `Sign` instances. The
1292
+ * argument is the string name of the hash function to use. `Sign` objects are not
1293
+ * to be created directly using the `new` keyword.
1294
+ *
1295
+ * Example: Using `Sign` and `Verify` objects as streams:
1296
+ *
1297
+ * ```js
1298
+ * const {
1299
+ * generateKeyPairSync,
1300
+ * createSign,
1301
+ * createVerify
1302
+ * } = await import('crypto');
1303
+ *
1304
+ * const { privateKey, publicKey } = generateKeyPairSync('ec', {
1305
+ * namedCurve: 'sect239k1'
1306
+ * });
1307
+ *
1308
+ * const sign = createSign('SHA256');
1309
+ * sign.write('some data to sign');
1310
+ * sign.end();
1311
+ * const signature = sign.sign(privateKey, 'hex');
1312
+ *
1313
+ * const verify = createVerify('SHA256');
1314
+ * verify.write('some data to sign');
1315
+ * verify.end();
1316
+ * console.log(verify.verify(publicKey, signature, 'hex'));
1317
+ * // Prints: true
1318
+ * ```
1319
+ *
1320
+ * Example: Using the `sign.update()` and `verify.update()` methods:
1321
+ *
1322
+ * ```js
1323
+ * const {
1324
+ * generateKeyPairSync,
1325
+ * createSign,
1326
+ * createVerify
1327
+ * } = await import('crypto');
1328
+ *
1329
+ * const { privateKey, publicKey } = generateKeyPairSync('rsa', {
1330
+ * modulusLength: 2048,
1331
+ * });
1332
+ *
1333
+ * const sign = createSign('SHA256');
1334
+ * sign.update('some data to sign');
1335
+ * sign.end();
1336
+ * const signature = sign.sign(privateKey);
1337
+ *
1338
+ * const verify = createVerify('SHA256');
1339
+ * verify.update('some data to sign');
1340
+ * verify.end();
1341
+ * console.log(verify.verify(publicKey, signature));
1342
+ * // Prints: true
1343
+ * ```
1344
+ * @since v0.1.92
1345
+ */
1346
+ class Sign extends stream.Writable {
341
1347
  private constructor();
342
-
343
- update(data: BinaryLike): Signer;
344
- update(data: string, input_encoding: Encoding): Signer;
345
- sign(private_key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput): Buffer;
346
- sign(
347
- private_key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput,
348
- output_format: BinaryToTextEncoding,
349
- ): string;
1348
+ /**
1349
+ * Updates the `Sign` content with the given `data`, the encoding of which
1350
+ * is given in `inputEncoding`.
1351
+ * If `encoding` is not provided, and the `data` is a string, an
1352
+ * encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
1353
+ *
1354
+ * This can be called many times with new data as it is streamed.
1355
+ * @since v0.1.92
1356
+ * @param inputEncoding The `encoding` of the `data` string.
1357
+ */
1358
+ update(data: BinaryLike): this;
1359
+ update(data: string, inputEncoding: Encoding): this;
1360
+ /**
1361
+ * Calculates the signature on all the data passed through using either `sign.update()` or `sign.write()`.
1362
+ *
1363
+ * If `privateKey` is not a `KeyObject`, this function behaves as if`privateKey` had been passed to {@link createPrivateKey}. If it is an
1364
+ * object, the following additional properties can be passed:
1365
+ *
1366
+ * If `outputEncoding` is provided a string is returned; otherwise a `Buffer` is returned.
1367
+ *
1368
+ * The `Sign` object can not be again used after `sign.sign()` method has been
1369
+ * called. Multiple calls to `sign.sign()` will result in an error being thrown.
1370
+ * @since v0.1.92
1371
+ */
1372
+ sign(privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput): Buffer;
1373
+ sign(privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput, outputFormat: BinaryToTextEncoding): string;
350
1374
  }
351
-
1375
+ /**
1376
+ * Creates and returns a `Verify` object that uses the given algorithm.
1377
+ * Use {@link getHashes} to obtain an array of names of the available
1378
+ * signing algorithms. Optional `options` argument controls the`stream.Writable` behavior.
1379
+ *
1380
+ * In some cases, a `Verify` instance can be created using the name of a signature
1381
+ * algorithm, such as `'RSA-SHA256'`, instead of a digest algorithm. This will use
1382
+ * the corresponding digest algorithm. This does not work for all signature
1383
+ * algorithms, such as `'ecdsa-with-SHA256'`, so it is best to always use digest
1384
+ * algorithm names.
1385
+ * @since v0.1.92
1386
+ * @param options `stream.Writable` options
1387
+ */
352
1388
  function createVerify(algorithm: string, options?: stream.WritableOptions): Verify;
1389
+ /**
1390
+ * The `Verify` class is a utility for verifying signatures. It can be used in one
1391
+ * of two ways:
1392
+ *
1393
+ * * As a writable `stream` where written data is used to validate against the
1394
+ * supplied signature, or
1395
+ * * Using the `verify.update()` and `verify.verify()` methods to verify
1396
+ * the signature.
1397
+ *
1398
+ * The {@link createVerify} method is used to create `Verify` instances.`Verify` objects are not to be created directly using the `new` keyword.
1399
+ *
1400
+ * See `Sign` for examples.
1401
+ * @since v0.1.92
1402
+ */
353
1403
  class Verify extends stream.Writable {
354
1404
  private constructor();
355
-
1405
+ /**
1406
+ * Updates the `Verify` content with the given `data`, the encoding of which
1407
+ * is given in `inputEncoding`.
1408
+ * If `inputEncoding` is not provided, and the `data` is a string, an
1409
+ * encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
1410
+ *
1411
+ * This can be called many times with new data as it is streamed.
1412
+ * @since v0.1.92
1413
+ * @param inputEncoding The `encoding` of the `data` string.
1414
+ */
356
1415
  update(data: BinaryLike): Verify;
357
- update(data: string, input_encoding: Encoding): Verify;
358
- verify(
359
- object: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput,
360
- signature: NodeJS.ArrayBufferView,
361
- ): boolean;
362
- verify(
363
- object: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput,
364
- signature: string,
365
- signature_format?: BinaryToTextEncoding,
366
- ): boolean;
367
- // https://nodejs.org/api/crypto.html#crypto_verifier_verify_object_signature_signature_format
368
- // The signature field accepts a TypedArray type, but it is only available starting ES2017
1416
+ update(data: string, inputEncoding: Encoding): Verify;
1417
+ /**
1418
+ * Verifies the provided data using the given `object` and `signature`.
1419
+ *
1420
+ * If `object` is not a `KeyObject`, this function behaves as if`object` had been passed to {@link createPublicKey}. If it is an
1421
+ * object, the following additional properties can be passed:
1422
+ *
1423
+ * The `signature` argument is the previously calculated signature for the data, in
1424
+ * the `signatureEncoding`.
1425
+ * If a `signatureEncoding` is specified, the `signature` is expected to be a
1426
+ * string; otherwise `signature` is expected to be a `Buffer`,`TypedArray`, or `DataView`.
1427
+ *
1428
+ * The `verify` object can not be used again after `verify.verify()` has been
1429
+ * called. Multiple calls to `verify.verify()` will result in an error being
1430
+ * thrown.
1431
+ *
1432
+ * Because public keys can be derived from private keys, a private key may
1433
+ * be passed instead of a public key.
1434
+ * @since v0.1.92
1435
+ */
1436
+ verify(object: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput, signature: NodeJS.ArrayBufferView): boolean;
1437
+ verify(object: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput, signature: string, signature_format?: BinaryToTextEncoding): boolean;
369
1438
  }
370
- function createDiffieHellman(prime_length: number, generator?: number | NodeJS.ArrayBufferView): DiffieHellman;
1439
+ /**
1440
+ * Creates a `DiffieHellman` key exchange object using the supplied `prime` and an
1441
+ * optional specific `generator`.
1442
+ *
1443
+ * The `generator` argument can be a number, string, or `Buffer`. If`generator` is not specified, the value `2` is used.
1444
+ *
1445
+ * If `primeEncoding` is specified, `prime` is expected to be a string; otherwise
1446
+ * a `Buffer`, `TypedArray`, or `DataView` is expected.
1447
+ *
1448
+ * If `generatorEncoding` is specified, `generator` is expected to be a string;
1449
+ * otherwise a number, `Buffer`, `TypedArray`, or `DataView` is expected.
1450
+ * @since v0.11.12
1451
+ * @param primeEncoding The `encoding` of the `prime` string.
1452
+ * @param [generator=2]
1453
+ * @param generatorEncoding The `encoding` of the `generator` string.
1454
+ */
1455
+ function createDiffieHellman(primeLength: number, generator?: number | NodeJS.ArrayBufferView): DiffieHellman;
371
1456
  function createDiffieHellman(prime: NodeJS.ArrayBufferView): DiffieHellman;
372
- function createDiffieHellman(prime: string, prime_encoding: BinaryToTextEncoding): DiffieHellman;
373
- function createDiffieHellman(
374
- prime: string,
375
- prime_encoding: BinaryToTextEncoding,
376
- generator: number | NodeJS.ArrayBufferView,
377
- ): DiffieHellman;
378
- function createDiffieHellman(
379
- prime: string,
380
- prime_encoding: BinaryToTextEncoding,
381
- generator: string,
382
- generator_encoding: BinaryToTextEncoding,
383
- ): DiffieHellman;
1457
+ function createDiffieHellman(prime: string, primeEncoding: BinaryToTextEncoding): DiffieHellman;
1458
+ function createDiffieHellman(prime: string, primeEncoding: BinaryToTextEncoding, generator: number | NodeJS.ArrayBufferView): DiffieHellman;
1459
+ function createDiffieHellman(prime: string, primeEncoding: BinaryToTextEncoding, generator: string, generatorEncoding: BinaryToTextEncoding): DiffieHellman;
1460
+ /**
1461
+ * The `DiffieHellman` class is a utility for creating Diffie-Hellman key
1462
+ * exchanges.
1463
+ *
1464
+ * Instances of the `DiffieHellman` class can be created using the {@link createDiffieHellman} function.
1465
+ *
1466
+ * ```js
1467
+ * import assert from 'assert';
1468
+ *
1469
+ * const {
1470
+ * createDiffieHellman
1471
+ * } = await import('crypto');
1472
+ *
1473
+ * // Generate Alice's keys...
1474
+ * const alice = createDiffieHellman(2048);
1475
+ * const aliceKey = alice.generateKeys();
1476
+ *
1477
+ * // Generate Bob's keys...
1478
+ * const bob = createDiffieHellman(alice.getPrime(), alice.getGenerator());
1479
+ * const bobKey = bob.generateKeys();
1480
+ *
1481
+ * // Exchange and generate the secret...
1482
+ * const aliceSecret = alice.computeSecret(bobKey);
1483
+ * const bobSecret = bob.computeSecret(aliceKey);
1484
+ *
1485
+ * // OK
1486
+ * assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
1487
+ * ```
1488
+ * @since v0.5.0
1489
+ */
384
1490
  class DiffieHellman {
385
1491
  private constructor();
1492
+ /**
1493
+ * Generates private and public Diffie-Hellman key values, and returns
1494
+ * the public key in the specified `encoding`. This key should be
1495
+ * transferred to the other party.
1496
+ * If `encoding` is provided a string is returned; otherwise a `Buffer` is returned.
1497
+ * @since v0.5.0
1498
+ * @param encoding The `encoding` of the return value.
1499
+ */
386
1500
  generateKeys(): Buffer;
387
1501
  generateKeys(encoding: BinaryToTextEncoding): string;
388
- computeSecret(other_public_key: NodeJS.ArrayBufferView): Buffer;
389
- computeSecret(other_public_key: string, input_encoding: BinaryToTextEncoding): Buffer;
390
- computeSecret(other_public_key: NodeJS.ArrayBufferView, output_encoding: BinaryToTextEncoding): string;
391
- computeSecret(
392
- other_public_key: string,
393
- input_encoding: BinaryToTextEncoding,
394
- output_encoding: BinaryToTextEncoding,
395
- ): string;
1502
+ /**
1503
+ * Computes the shared secret using `otherPublicKey` as the other
1504
+ * party's public key and returns the computed shared secret. The supplied
1505
+ * key is interpreted using the specified `inputEncoding`, and secret is
1506
+ * encoded using specified `outputEncoding`.
1507
+ * If the `inputEncoding` is not
1508
+ * provided, `otherPublicKey` is expected to be a `Buffer`,`TypedArray`, or `DataView`.
1509
+ *
1510
+ * If `outputEncoding` is given a string is returned; otherwise, a `Buffer` is returned.
1511
+ * @since v0.5.0
1512
+ * @param inputEncoding The `encoding` of an `otherPublicKey` string.
1513
+ * @param outputEncoding The `encoding` of the return value.
1514
+ */
1515
+ computeSecret(otherPublicKey: NodeJS.ArrayBufferView, inputEncoding?: null, outputEncoding?: null): Buffer;
1516
+ computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding, outputEncoding?: null): Buffer;
1517
+ computeSecret(otherPublicKey: NodeJS.ArrayBufferView, inputEncoding: null, outputEncoding: BinaryToTextEncoding): string;
1518
+ computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding, outputEncoding: BinaryToTextEncoding): string;
1519
+ /**
1520
+ * Returns the Diffie-Hellman prime in the specified `encoding`.
1521
+ * If `encoding` is provided a string is
1522
+ * returned; otherwise a `Buffer` is returned.
1523
+ * @since v0.5.0
1524
+ * @param encoding The `encoding` of the return value.
1525
+ */
396
1526
  getPrime(): Buffer;
397
1527
  getPrime(encoding: BinaryToTextEncoding): string;
1528
+ /**
1529
+ * Returns the Diffie-Hellman generator in the specified `encoding`.
1530
+ * If `encoding` is provided a string is
1531
+ * returned; otherwise a `Buffer` is returned.
1532
+ * @since v0.5.0
1533
+ * @param encoding The `encoding` of the return value.
1534
+ */
398
1535
  getGenerator(): Buffer;
399
1536
  getGenerator(encoding: BinaryToTextEncoding): string;
1537
+ /**
1538
+ * Returns the Diffie-Hellman public key in the specified `encoding`.
1539
+ * If `encoding` is provided a
1540
+ * string is returned; otherwise a `Buffer` is returned.
1541
+ * @since v0.5.0
1542
+ * @param encoding The `encoding` of the return value.
1543
+ */
400
1544
  getPublicKey(): Buffer;
401
1545
  getPublicKey(encoding: BinaryToTextEncoding): string;
1546
+ /**
1547
+ * Returns the Diffie-Hellman private key in the specified `encoding`.
1548
+ * If `encoding` is provided a
1549
+ * string is returned; otherwise a `Buffer` is returned.
1550
+ * @since v0.5.0
1551
+ * @param encoding The `encoding` of the return value.
1552
+ */
402
1553
  getPrivateKey(): Buffer;
403
1554
  getPrivateKey(encoding: BinaryToTextEncoding): string;
404
- setPublicKey(public_key: NodeJS.ArrayBufferView): void;
405
- setPublicKey(public_key: string, encoding: BufferEncoding): void;
406
- setPrivateKey(private_key: NodeJS.ArrayBufferView): void;
407
- setPrivateKey(private_key: string, encoding: BufferEncoding): void;
1555
+ /**
1556
+ * Sets the Diffie-Hellman public key. If the `encoding` argument is provided,`publicKey` is expected
1557
+ * to be a string. If no `encoding` is provided, `publicKey` is expected
1558
+ * to be a `Buffer`, `TypedArray`, or `DataView`.
1559
+ * @since v0.5.0
1560
+ * @param encoding The `encoding` of the `publicKey` string.
1561
+ */
1562
+ setPublicKey(publicKey: NodeJS.ArrayBufferView): void;
1563
+ setPublicKey(publicKey: string, encoding: BufferEncoding): void;
1564
+ /**
1565
+ * Sets the Diffie-Hellman private key. If the `encoding` argument is provided,`privateKey` is expected
1566
+ * to be a string. If no `encoding` is provided, `privateKey` is expected
1567
+ * to be a `Buffer`, `TypedArray`, or `DataView`.
1568
+ * @since v0.5.0
1569
+ * @param encoding The `encoding` of the `privateKey` string.
1570
+ */
1571
+ setPrivateKey(privateKey: NodeJS.ArrayBufferView): void;
1572
+ setPrivateKey(privateKey: string, encoding: BufferEncoding): void;
1573
+ /**
1574
+ * A bit field containing any warnings and/or errors resulting from a check
1575
+ * performed during initialization of the `DiffieHellman` object.
1576
+ *
1577
+ * The following values are valid for this property (as defined in `constants`module):
1578
+ *
1579
+ * * `DH_CHECK_P_NOT_SAFE_PRIME`
1580
+ * * `DH_CHECK_P_NOT_PRIME`
1581
+ * * `DH_UNABLE_TO_CHECK_GENERATOR`
1582
+ * * `DH_NOT_SUITABLE_GENERATOR`
1583
+ * @since v0.11.12
1584
+ */
408
1585
  verifyError: number;
409
1586
  }
410
- function getDiffieHellman(group_name: string): DiffieHellman;
411
- function pbkdf2(
412
- password: BinaryLike,
413
- salt: BinaryLike,
414
- iterations: number,
415
- keylen: number,
416
- digest: string,
417
- callback: (err: Error | null, derivedKey: Buffer) => any,
418
- ): void;
419
- function pbkdf2Sync(
420
- password: BinaryLike,
421
- salt: BinaryLike,
422
- iterations: number,
423
- keylen: number,
424
- digest: string,
425
- ): Buffer;
426
-
1587
+ /**
1588
+ * The `DiffieHellmanGroup` class takes a well-known modp group as its argument.
1589
+ * It works the same as `DiffieHellman`, except that it does not allow changing its keys after creation.
1590
+ * In other words, it does not implement `setPublicKey()` or `setPrivateKey()` methods.
1591
+ *
1592
+ * ```js
1593
+ * const { createDiffieHellmanGroup } = await import('node:crypto');
1594
+ * const dh = createDiffieHellmanGroup('modp1');
1595
+ * ```
1596
+ * The name (e.g. `'modp1'`) is taken from [RFC 2412](https://www.rfc-editor.org/rfc/rfc2412.txt) (modp1 and 2) and [RFC 3526](https://www.rfc-editor.org/rfc/rfc3526.txt):
1597
+ * ```bash
1598
+ * $ perl -ne 'print "$1\n" if /"(modp\d+)"/' src/node_crypto_groups.h
1599
+ * modp1 # 768 bits
1600
+ * modp2 # 1024 bits
1601
+ * modp5 # 1536 bits
1602
+ * modp14 # 2048 bits
1603
+ * modp15 # etc.
1604
+ * modp16
1605
+ * modp17
1606
+ * modp18
1607
+ * ```
1608
+ * @since v0.7.5
1609
+ */
1610
+ const DiffieHellmanGroup: DiffieHellmanGroupConstructor;
1611
+ interface DiffieHellmanGroupConstructor {
1612
+ new(name: string): DiffieHellmanGroup;
1613
+ (name: string): DiffieHellmanGroup;
1614
+ readonly prototype: DiffieHellmanGroup;
1615
+ }
1616
+ type DiffieHellmanGroup = Omit<DiffieHellman, 'setPublicKey' | 'setPrivateKey'>;
1617
+ /**
1618
+ * Creates a predefined `DiffieHellmanGroup` key exchange object. The
1619
+ * supported groups are: `'modp1'`, `'modp2'`, `'modp5'` (defined in [RFC 2412](https://www.rfc-editor.org/rfc/rfc2412.txt), but see `Caveats`) and `'modp14'`, `'modp15'`,`'modp16'`, `'modp17'`,
1620
+ * `'modp18'` (defined in [RFC 3526](https://www.rfc-editor.org/rfc/rfc3526.txt)). The
1621
+ * returned object mimics the interface of objects created by {@link createDiffieHellman}, but will not allow changing
1622
+ * the keys (with `diffieHellman.setPublicKey()`, for example). The
1623
+ * advantage of using this method is that the parties do not have to
1624
+ * generate nor exchange a group modulus beforehand, saving both processor
1625
+ * and communication time.
1626
+ *
1627
+ * Example (obtaining a shared secret):
1628
+ *
1629
+ * ```js
1630
+ * const {
1631
+ * getDiffieHellman
1632
+ * } = await import('crypto');
1633
+ * const alice = getDiffieHellman('modp14');
1634
+ * const bob = getDiffieHellman('modp14');
1635
+ *
1636
+ * alice.generateKeys();
1637
+ * bob.generateKeys();
1638
+ *
1639
+ * const aliceSecret = alice.computeSecret(bob.getPublicKey(), null, 'hex');
1640
+ * const bobSecret = bob.computeSecret(alice.getPublicKey(), null, 'hex');
1641
+ *
1642
+ * // aliceSecret and bobSecret should be the same
1643
+ * console.log(aliceSecret === bobSecret);
1644
+ * ```
1645
+ * @since v0.7.5
1646
+ */
1647
+ function getDiffieHellman(groupName: string): DiffieHellmanGroup;
1648
+ /**
1649
+ * An alias for {@link getDiffieHellman}
1650
+ * @since v0.9.3
1651
+ */
1652
+ function createDiffieHellmanGroup(name: string): DiffieHellmanGroup;
1653
+ /**
1654
+ * Provides an asynchronous Password-Based Key Derivation Function 2 (PBKDF2)
1655
+ * implementation. A selected HMAC digest algorithm specified by `digest` is
1656
+ * applied to derive a key of the requested byte length (`keylen`) from the`password`, `salt` and `iterations`.
1657
+ *
1658
+ * The supplied `callback` function is called with two arguments: `err` and`derivedKey`. If an error occurs while deriving the key, `err` will be set;
1659
+ * otherwise `err` will be `null`. By default, the successfully generated`derivedKey` will be passed to the callback as a `Buffer`. An error will be
1660
+ * thrown if any of the input arguments specify invalid values or types.
1661
+ *
1662
+ * If `digest` is `null`, `'sha1'` will be used. This behavior is deprecated,
1663
+ * please specify a `digest` explicitly.
1664
+ *
1665
+ * The `iterations` argument must be a number set as high as possible. The
1666
+ * higher the number of iterations, the more secure the derived key will be,
1667
+ * but will take a longer amount of time to complete.
1668
+ *
1669
+ * The `salt` should be as unique as possible. It is recommended that a salt is
1670
+ * random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
1671
+ *
1672
+ * When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
1673
+ *
1674
+ * ```js
1675
+ * const {
1676
+ * pbkdf2
1677
+ * } = await import('crypto');
1678
+ *
1679
+ * pbkdf2('secret', 'salt', 100000, 64, 'sha512', (err, derivedKey) => {
1680
+ * if (err) throw err;
1681
+ * console.log(derivedKey.toString('hex')); // '3745e48...08d59ae'
1682
+ * });
1683
+ * ```
1684
+ *
1685
+ * The `crypto.DEFAULT_ENCODING` property can be used to change the way the`derivedKey` is passed to the callback. This property, however, has been
1686
+ * deprecated and use should be avoided.
1687
+ *
1688
+ * ```js
1689
+ * import crypto from 'crypto';
1690
+ * crypto.DEFAULT_ENCODING = 'hex';
1691
+ * crypto.pbkdf2('secret', 'salt', 100000, 512, 'sha512', (err, derivedKey) => {
1692
+ * if (err) throw err;
1693
+ * console.log(derivedKey); // '3745e48...aa39b34'
1694
+ * });
1695
+ * ```
1696
+ *
1697
+ * An array of supported digest functions can be retrieved using {@link getHashes}.
1698
+ *
1699
+ * This API uses libuv's threadpool, which can have surprising and
1700
+ * negative performance implications for some applications; see the `UV_THREADPOOL_SIZE` documentation for more information.
1701
+ * @since v0.5.5
1702
+ */
1703
+ function pbkdf2(password: BinaryLike, salt: BinaryLike, iterations: number, keylen: number, digest: string, callback: (err: Error | null, derivedKey: Buffer) => void): void;
1704
+ /**
1705
+ * Provides a synchronous Password-Based Key Derivation Function 2 (PBKDF2)
1706
+ * implementation. A selected HMAC digest algorithm specified by `digest` is
1707
+ * applied to derive a key of the requested byte length (`keylen`) from the`password`, `salt` and `iterations`.
1708
+ *
1709
+ * If an error occurs an `Error` will be thrown, otherwise the derived key will be
1710
+ * returned as a `Buffer`.
1711
+ *
1712
+ * If `digest` is `null`, `'sha1'` will be used. This behavior is deprecated,
1713
+ * please specify a `digest` explicitly.
1714
+ *
1715
+ * The `iterations` argument must be a number set as high as possible. The
1716
+ * higher the number of iterations, the more secure the derived key will be,
1717
+ * but will take a longer amount of time to complete.
1718
+ *
1719
+ * The `salt` should be as unique as possible. It is recommended that a salt is
1720
+ * random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
1721
+ *
1722
+ * When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
1723
+ *
1724
+ * ```js
1725
+ * const {
1726
+ * pbkdf2Sync
1727
+ * } = await import('crypto');
1728
+ *
1729
+ * const key = pbkdf2Sync('secret', 'salt', 100000, 64, 'sha512');
1730
+ * console.log(key.toString('hex')); // '3745e48...08d59ae'
1731
+ * ```
1732
+ *
1733
+ * The `crypto.DEFAULT_ENCODING` property may be used to change the way the`derivedKey` is returned. This property, however, is deprecated and use
1734
+ * should be avoided.
1735
+ *
1736
+ * ```js
1737
+ * import crypto from 'crypto';
1738
+ * crypto.DEFAULT_ENCODING = 'hex';
1739
+ * const key = crypto.pbkdf2Sync('secret', 'salt', 100000, 512, 'sha512');
1740
+ * console.log(key); // '3745e48...aa39b34'
1741
+ * ```
1742
+ *
1743
+ * An array of supported digest functions can be retrieved using {@link getHashes}.
1744
+ * @since v0.9.3
1745
+ */
1746
+ function pbkdf2Sync(password: BinaryLike, salt: BinaryLike, iterations: number, keylen: number, digest: string): Buffer;
1747
+ /**
1748
+ * Generates cryptographically strong pseudorandom data. The `size` argument
1749
+ * is a number indicating the number of bytes to generate.
1750
+ *
1751
+ * If a `callback` function is provided, the bytes are generated asynchronously
1752
+ * and the `callback` function is invoked with two arguments: `err` and `buf`.
1753
+ * If an error occurs, `err` will be an `Error` object; otherwise it is `null`. The`buf` argument is a `Buffer` containing the generated bytes.
1754
+ *
1755
+ * ```js
1756
+ * // Asynchronous
1757
+ * const {
1758
+ * randomBytes
1759
+ * } = await import('crypto');
1760
+ *
1761
+ * randomBytes(256, (err, buf) => {
1762
+ * if (err) throw err;
1763
+ * console.log(`${buf.length} bytes of random data: ${buf.toString('hex')}`);
1764
+ * });
1765
+ * ```
1766
+ *
1767
+ * If the `callback` function is not provided, the random bytes are generated
1768
+ * synchronously and returned as a `Buffer`. An error will be thrown if
1769
+ * there is a problem generating the bytes.
1770
+ *
1771
+ * ```js
1772
+ * // Synchronous
1773
+ * const {
1774
+ * randomBytes
1775
+ * } = await import('crypto');
1776
+ *
1777
+ * const buf = randomBytes(256);
1778
+ * console.log(
1779
+ * `${buf.length} bytes of random data: ${buf.toString('hex')}`);
1780
+ * ```
1781
+ *
1782
+ * The `crypto.randomBytes()` method will not complete until there is
1783
+ * sufficient entropy available.
1784
+ * This should normally never take longer than a few milliseconds. The only time
1785
+ * when generating the random bytes may conceivably block for a longer period of
1786
+ * time is right after boot, when the whole system is still low on entropy.
1787
+ *
1788
+ * This API uses libuv's threadpool, which can have surprising and
1789
+ * negative performance implications for some applications; see the `UV_THREADPOOL_SIZE` documentation for more information.
1790
+ *
1791
+ * The asynchronous version of `crypto.randomBytes()` is carried out in a single
1792
+ * threadpool request. To minimize threadpool task length variation, partition
1793
+ * large `randomBytes` requests when doing so as part of fulfilling a client
1794
+ * request.
1795
+ * @since v0.5.8
1796
+ * @param size The number of bytes to generate. The `size` must not be larger than `2**31 - 1`.
1797
+ * @return if the `callback` function is not provided.
1798
+ */
427
1799
  function randomBytes(size: number): Buffer;
428
1800
  function randomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void;
429
1801
  function pseudoRandomBytes(size: number): Buffer;
430
1802
  function pseudoRandomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void;
431
-
1803
+ /**
1804
+ * Return a random integer `n` such that `min <= n < max`. This
1805
+ * implementation avoids [modulo bias](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Modulo_bias).
1806
+ *
1807
+ * The range (`max - min`) must be less than `2**48`. `min` and `max` must
1808
+ * be [safe integers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger).
1809
+ *
1810
+ * If the `callback` function is not provided, the random integer is
1811
+ * generated synchronously.
1812
+ *
1813
+ * ```js
1814
+ * // Asynchronous
1815
+ * const {
1816
+ * randomInt
1817
+ * } = await import('crypto');
1818
+ *
1819
+ * randomInt(3, (err, n) => {
1820
+ * if (err) throw err;
1821
+ * console.log(`Random number chosen from (0, 1, 2): ${n}`);
1822
+ * });
1823
+ * ```
1824
+ *
1825
+ * ```js
1826
+ * // Synchronous
1827
+ * const {
1828
+ * randomInt
1829
+ * } = await import('crypto');
1830
+ *
1831
+ * const n = randomInt(3);
1832
+ * console.log(`Random number chosen from (0, 1, 2): ${n}`);
1833
+ * ```
1834
+ *
1835
+ * ```js
1836
+ * // With `min` argument
1837
+ * const {
1838
+ * randomInt
1839
+ * } = await import('crypto');
1840
+ *
1841
+ * const n = randomInt(1, 7);
1842
+ * console.log(`The dice rolled: ${n}`);
1843
+ * ```
1844
+ * @since v14.10.0, v12.19.0
1845
+ * @param [min=0] Start of random range (inclusive).
1846
+ * @param max End of random range (exclusive).
1847
+ * @param callback `function(err, n) {}`.
1848
+ */
432
1849
  function randomInt(max: number): number;
433
1850
  function randomInt(min: number, max: number): number;
434
1851
  function randomInt(max: number, callback: (err: Error | null, value: number) => void): void;
435
1852
  function randomInt(min: number, max: number, callback: (err: Error | null, value: number) => void): void;
436
-
1853
+ /**
1854
+ * Synchronous version of {@link randomFill}.
1855
+ *
1856
+ * ```js
1857
+ * import { Buffer } from 'buffer';
1858
+ * const { randomFillSync } = await import('crypto');
1859
+ *
1860
+ * const buf = Buffer.alloc(10);
1861
+ * console.log(randomFillSync(buf).toString('hex'));
1862
+ *
1863
+ * randomFillSync(buf, 5);
1864
+ * console.log(buf.toString('hex'));
1865
+ *
1866
+ * // The above is equivalent to the following:
1867
+ * randomFillSync(buf, 5, 5);
1868
+ * console.log(buf.toString('hex'));
1869
+ * ```
1870
+ *
1871
+ * Any `ArrayBuffer`, `TypedArray` or `DataView` instance may be passed as`buffer`.
1872
+ *
1873
+ * ```js
1874
+ * import { Buffer } from 'buffer';
1875
+ * const { randomFillSync } = await import('crypto');
1876
+ *
1877
+ * const a = new Uint32Array(10);
1878
+ * console.log(Buffer.from(randomFillSync(a).buffer,
1879
+ * a.byteOffset, a.byteLength).toString('hex'));
1880
+ *
1881
+ * const b = new DataView(new ArrayBuffer(10));
1882
+ * console.log(Buffer.from(randomFillSync(b).buffer,
1883
+ * b.byteOffset, b.byteLength).toString('hex'));
1884
+ *
1885
+ * const c = new ArrayBuffer(10);
1886
+ * console.log(Buffer.from(randomFillSync(c)).toString('hex'));
1887
+ * ```
1888
+ * @since v7.10.0, v6.13.0
1889
+ * @param buffer Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`.
1890
+ * @param [offset=0]
1891
+ * @param [size=buffer.length - offset]
1892
+ * @return The object passed as `buffer` argument.
1893
+ */
437
1894
  function randomFillSync<T extends NodeJS.ArrayBufferView>(buffer: T, offset?: number, size?: number): T;
438
- function randomFill<T extends NodeJS.ArrayBufferView>(
439
- buffer: T,
440
- callback: (err: Error | null, buf: T) => void,
441
- ): void;
442
- function randomFill<T extends NodeJS.ArrayBufferView>(
443
- buffer: T,
444
- offset: number,
445
- callback: (err: Error | null, buf: T) => void,
446
- ): void;
447
- function randomFill<T extends NodeJS.ArrayBufferView>(
448
- buffer: T,
449
- offset: number,
450
- size: number,
451
- callback: (err: Error | null, buf: T) => void,
452
- ): void;
453
-
454
- interface RandomUUIDOptions {
455
- /**
456
- * By default, to improve performance,
457
- * Node.js will pre-emptively generate and persistently cache enough
458
- * random data to generate up to 128 random UUIDs. To generate a UUID
459
- * without using the cache, set `disableEntropyCache` to `true`.
460
- *
461
- * @default `false`
462
- */
463
- disableEntropyCache?: boolean | undefined;
464
- }
465
-
466
- function randomUUID(options?: RandomUUIDOptions): string;
467
-
1895
+ /**
1896
+ * This function is similar to {@link randomBytes} but requires the first
1897
+ * argument to be a `Buffer` that will be filled. It also
1898
+ * requires that a callback is passed in.
1899
+ *
1900
+ * If the `callback` function is not provided, an error will be thrown.
1901
+ *
1902
+ * ```js
1903
+ * import { Buffer } from 'buffer';
1904
+ * const { randomFill } = await import('crypto');
1905
+ *
1906
+ * const buf = Buffer.alloc(10);
1907
+ * randomFill(buf, (err, buf) => {
1908
+ * if (err) throw err;
1909
+ * console.log(buf.toString('hex'));
1910
+ * });
1911
+ *
1912
+ * randomFill(buf, 5, (err, buf) => {
1913
+ * if (err) throw err;
1914
+ * console.log(buf.toString('hex'));
1915
+ * });
1916
+ *
1917
+ * // The above is equivalent to the following:
1918
+ * randomFill(buf, 5, 5, (err, buf) => {
1919
+ * if (err) throw err;
1920
+ * console.log(buf.toString('hex'));
1921
+ * });
1922
+ * ```
1923
+ *
1924
+ * Any `ArrayBuffer`, `TypedArray`, or `DataView` instance may be passed as`buffer`.
1925
+ *
1926
+ * While this includes instances of `Float32Array` and `Float64Array`, this
1927
+ * function should not be used to generate random floating-point numbers. The
1928
+ * result may contain `+Infinity`, `-Infinity`, and `NaN`, and even if the array
1929
+ * contains finite numbers only, they are not drawn from a uniform random
1930
+ * distribution and have no meaningful lower or upper bounds.
1931
+ *
1932
+ * ```js
1933
+ * import { Buffer } from 'buffer';
1934
+ * const { randomFill } = await import('crypto');
1935
+ *
1936
+ * const a = new Uint32Array(10);
1937
+ * randomFill(a, (err, buf) => {
1938
+ * if (err) throw err;
1939
+ * console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
1940
+ * .toString('hex'));
1941
+ * });
1942
+ *
1943
+ * const b = new DataView(new ArrayBuffer(10));
1944
+ * randomFill(b, (err, buf) => {
1945
+ * if (err) throw err;
1946
+ * console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
1947
+ * .toString('hex'));
1948
+ * });
1949
+ *
1950
+ * const c = new ArrayBuffer(10);
1951
+ * randomFill(c, (err, buf) => {
1952
+ * if (err) throw err;
1953
+ * console.log(Buffer.from(buf).toString('hex'));
1954
+ * });
1955
+ * ```
1956
+ *
1957
+ * This API uses libuv's threadpool, which can have surprising and
1958
+ * negative performance implications for some applications; see the `UV_THREADPOOL_SIZE` documentation for more information.
1959
+ *
1960
+ * The asynchronous version of `crypto.randomFill()` is carried out in a single
1961
+ * threadpool request. To minimize threadpool task length variation, partition
1962
+ * large `randomFill` requests when doing so as part of fulfilling a client
1963
+ * request.
1964
+ * @since v7.10.0, v6.13.0
1965
+ * @param buffer Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`.
1966
+ * @param [offset=0]
1967
+ * @param [size=buffer.length - offset]
1968
+ * @param callback `function(err, buf) {}`.
1969
+ */
1970
+ function randomFill<T extends NodeJS.ArrayBufferView>(buffer: T, callback: (err: Error | null, buf: T) => void): void;
1971
+ function randomFill<T extends NodeJS.ArrayBufferView>(buffer: T, offset: number, callback: (err: Error | null, buf: T) => void): void;
1972
+ function randomFill<T extends NodeJS.ArrayBufferView>(buffer: T, offset: number, size: number, callback: (err: Error | null, buf: T) => void): void;
468
1973
  interface ScryptOptions {
469
1974
  cost?: number | undefined;
470
1975
  blockSize?: number | undefined;
@@ -474,21 +1979,73 @@ declare module 'crypto' {
474
1979
  p?: number | undefined;
475
1980
  maxmem?: number | undefined;
476
1981
  }
477
- function scrypt(
478
- password: BinaryLike,
479
- salt: BinaryLike,
480
- keylen: number,
481
- callback: (err: Error | null, derivedKey: Buffer) => void,
482
- ): void;
483
- function scrypt(
484
- password: BinaryLike,
485
- salt: BinaryLike,
486
- keylen: number,
487
- options: ScryptOptions,
488
- callback: (err: Error | null, derivedKey: Buffer) => void,
489
- ): void;
1982
+ /**
1983
+ * Provides an asynchronous [scrypt](https://en.wikipedia.org/wiki/Scrypt) implementation. Scrypt is a password-based
1984
+ * key derivation function that is designed to be expensive computationally and
1985
+ * memory-wise in order to make brute-force attacks unrewarding.
1986
+ *
1987
+ * The `salt` should be as unique as possible. It is recommended that a salt is
1988
+ * random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
1989
+ *
1990
+ * When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
1991
+ *
1992
+ * The `callback` function is called with two arguments: `err` and `derivedKey`.`err` is an exception object when key derivation fails, otherwise `err` is`null`. `derivedKey` is passed to the
1993
+ * callback as a `Buffer`.
1994
+ *
1995
+ * An exception is thrown when any of the input arguments specify invalid values
1996
+ * or types.
1997
+ *
1998
+ * ```js
1999
+ * const {
2000
+ * scrypt
2001
+ * } = await import('crypto');
2002
+ *
2003
+ * // Using the factory defaults.
2004
+ * scrypt('password', 'salt', 64, (err, derivedKey) => {
2005
+ * if (err) throw err;
2006
+ * console.log(derivedKey.toString('hex')); // '3745e48...08d59ae'
2007
+ * });
2008
+ * // Using a custom N parameter. Must be a power of two.
2009
+ * scrypt('password', 'salt', 64, { N: 1024 }, (err, derivedKey) => {
2010
+ * if (err) throw err;
2011
+ * console.log(derivedKey.toString('hex')); // '3745e48...aa39b34'
2012
+ * });
2013
+ * ```
2014
+ * @since v10.5.0
2015
+ */
2016
+ function scrypt(password: BinaryLike, salt: BinaryLike, keylen: number, callback: (err: Error | null, derivedKey: Buffer) => void): void;
2017
+ function scrypt(password: BinaryLike, salt: BinaryLike, keylen: number, options: ScryptOptions, callback: (err: Error | null, derivedKey: Buffer) => void): void;
2018
+ /**
2019
+ * Provides a synchronous [scrypt](https://en.wikipedia.org/wiki/Scrypt) implementation. Scrypt is a password-based
2020
+ * key derivation function that is designed to be expensive computationally and
2021
+ * memory-wise in order to make brute-force attacks unrewarding.
2022
+ *
2023
+ * The `salt` should be as unique as possible. It is recommended that a salt is
2024
+ * random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
2025
+ *
2026
+ * When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
2027
+ *
2028
+ * An exception is thrown when key derivation fails, otherwise the derived key is
2029
+ * returned as a `Buffer`.
2030
+ *
2031
+ * An exception is thrown when any of the input arguments specify invalid values
2032
+ * or types.
2033
+ *
2034
+ * ```js
2035
+ * const {
2036
+ * scryptSync
2037
+ * } = await import('crypto');
2038
+ * // Using the factory defaults.
2039
+ *
2040
+ * const key1 = scryptSync('password', 'salt', 64);
2041
+ * console.log(key1.toString('hex')); // '3745e48...08d59ae'
2042
+ * // Using a custom N parameter. Must be a power of two.
2043
+ * const key2 = scryptSync('password', 'salt', 64, { N: 1024 });
2044
+ * console.log(key2.toString('hex')); // '3745e48...aa39b34'
2045
+ * ```
2046
+ * @since v10.5.0
2047
+ */
490
2048
  function scryptSync(password: BinaryLike, salt: BinaryLike, keylen: number, options?: ScryptOptions): Buffer;
491
-
492
2049
  interface RsaPublicKey {
493
2050
  key: KeyLike;
494
2051
  padding?: number | undefined;
@@ -503,124 +2060,350 @@ declare module 'crypto' {
503
2060
  oaepLabel?: NodeJS.TypedArray | undefined;
504
2061
  padding?: number | undefined;
505
2062
  }
2063
+ /**
2064
+ * Encrypts the content of `buffer` with `key` and returns a new `Buffer` with encrypted content. The returned data can be decrypted using
2065
+ * the corresponding private key, for example using {@link privateDecrypt}.
2066
+ *
2067
+ * If `key` is not a `KeyObject`, this function behaves as if`key` had been passed to {@link createPublicKey}. If it is an
2068
+ * object, the `padding` property can be passed. Otherwise, this function uses`RSA_PKCS1_OAEP_PADDING`.
2069
+ *
2070
+ * Because RSA public keys can be derived from private keys, a private key may
2071
+ * be passed instead of a public key.
2072
+ * @since v0.11.14
2073
+ */
506
2074
  function publicEncrypt(key: RsaPublicKey | RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
2075
+ /**
2076
+ * Decrypts `buffer` with `key`.`buffer` was previously encrypted using
2077
+ * the corresponding private key, for example using {@link privateEncrypt}.
2078
+ *
2079
+ * If `key` is not a `KeyObject`, this function behaves as if`key` had been passed to {@link createPublicKey}. If it is an
2080
+ * object, the `padding` property can be passed. Otherwise, this function uses`RSA_PKCS1_PADDING`.
2081
+ *
2082
+ * Because RSA public keys can be derived from private keys, a private key may
2083
+ * be passed instead of a public key.
2084
+ * @since v1.1.0
2085
+ */
507
2086
  function publicDecrypt(key: RsaPublicKey | RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
508
- function privateDecrypt(private_key: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
509
- function privateEncrypt(private_key: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
510
- function getCiphers(): string[];
511
- function getCurves(): string[];
2087
+ /**
2088
+ * Decrypts `buffer` with `privateKey`. `buffer` was previously encrypted using
2089
+ * the corresponding public key, for example using {@link publicEncrypt}.
2090
+ *
2091
+ * If `privateKey` is not a `KeyObject`, this function behaves as if`privateKey` had been passed to {@link createPrivateKey}. If it is an
2092
+ * object, the `padding` property can be passed. Otherwise, this function uses`RSA_PKCS1_OAEP_PADDING`.
2093
+ * @since v0.11.14
2094
+ */
2095
+ function privateDecrypt(privateKey: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
2096
+ /**
2097
+ * Encrypts `buffer` with `privateKey`. The returned data can be decrypted using
2098
+ * the corresponding public key, for example using {@link publicDecrypt}.
2099
+ *
2100
+ * If `privateKey` is not a `KeyObject`, this function behaves as if`privateKey` had been passed to {@link createPrivateKey}. If it is an
2101
+ * object, the `padding` property can be passed. Otherwise, this function uses`RSA_PKCS1_PADDING`.
2102
+ * @since v1.1.0
2103
+ */
2104
+ function privateEncrypt(privateKey: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
2105
+ /**
2106
+ * ```js
2107
+ * const {
2108
+ * getCiphers
2109
+ * } = await import('crypto');
2110
+ *
2111
+ * console.log(getCiphers()); // ['aes-128-cbc', 'aes-128-ccm', ...]
2112
+ * ```
2113
+ * @since v0.9.3
2114
+ * @return An array with the names of the supported cipher algorithms.
2115
+ */
2116
+ function getCiphers(): string[];
2117
+ /**
2118
+ * ```js
2119
+ * const {
2120
+ * getCurves
2121
+ * } = await import('crypto');
2122
+ *
2123
+ * console.log(getCurves()); // ['Oakley-EC2N-3', 'Oakley-EC2N-4', ...]
2124
+ * ```
2125
+ * @since v2.3.0
2126
+ * @return An array with the names of the supported elliptic curves.
2127
+ */
2128
+ function getCurves(): string[];
2129
+ /**
2130
+ * @since v10.0.0
2131
+ * @return `1` if and only if a FIPS compliant crypto provider is currently in use, `0` otherwise. A future semver-major release may change the return type of this API to a {boolean}.
2132
+ */
512
2133
  function getFips(): 1 | 0;
2134
+ /**
2135
+ * Enables the FIPS compliant crypto provider in a FIPS-enabled Node.js build. Throws an error if FIPS mode is not available.
2136
+ * @since v10.0.0
2137
+ * @param bool `true` to enable FIPS mode.
2138
+ */
2139
+ function setFips(bool: boolean): void;
2140
+ /**
2141
+ * ```js
2142
+ * const {
2143
+ * getHashes
2144
+ * } = await import('crypto');
2145
+ *
2146
+ * console.log(getHashes()); // ['DSA', 'DSA-SHA', 'DSA-SHA1', ...]
2147
+ * ```
2148
+ * @since v0.9.3
2149
+ * @return An array of the names of the supported hash algorithms, such as `'RSA-SHA256'`. Hash algorithms are also called "digest" algorithms.
2150
+ */
513
2151
  function getHashes(): string[];
2152
+ /**
2153
+ * The `ECDH` class is a utility for creating Elliptic Curve Diffie-Hellman (ECDH)
2154
+ * key exchanges.
2155
+ *
2156
+ * Instances of the `ECDH` class can be created using the {@link createECDH} function.
2157
+ *
2158
+ * ```js
2159
+ * import assert from 'assert';
2160
+ *
2161
+ * const {
2162
+ * createECDH
2163
+ * } = await import('crypto');
2164
+ *
2165
+ * // Generate Alice's keys...
2166
+ * const alice = createECDH('secp521r1');
2167
+ * const aliceKey = alice.generateKeys();
2168
+ *
2169
+ * // Generate Bob's keys...
2170
+ * const bob = createECDH('secp521r1');
2171
+ * const bobKey = bob.generateKeys();
2172
+ *
2173
+ * // Exchange and generate the secret...
2174
+ * const aliceSecret = alice.computeSecret(bobKey);
2175
+ * const bobSecret = bob.computeSecret(aliceKey);
2176
+ *
2177
+ * assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
2178
+ * // OK
2179
+ * ```
2180
+ * @since v0.11.14
2181
+ */
514
2182
  class ECDH {
515
2183
  private constructor();
2184
+ /**
2185
+ * Converts the EC Diffie-Hellman public key specified by `key` and `curve` to the
2186
+ * format specified by `format`. The `format` argument specifies point encoding
2187
+ * and can be `'compressed'`, `'uncompressed'` or `'hybrid'`. The supplied key is
2188
+ * interpreted using the specified `inputEncoding`, and the returned key is encoded
2189
+ * using the specified `outputEncoding`.
2190
+ *
2191
+ * Use {@link getCurves} to obtain a list of available curve names.
2192
+ * On recent OpenSSL releases, `openssl ecparam -list_curves` will also display
2193
+ * the name and description of each available elliptic curve.
2194
+ *
2195
+ * If `format` is not specified the point will be returned in `'uncompressed'`format.
2196
+ *
2197
+ * If the `inputEncoding` is not provided, `key` is expected to be a `Buffer`,`TypedArray`, or `DataView`.
2198
+ *
2199
+ * Example (uncompressing a key):
2200
+ *
2201
+ * ```js
2202
+ * const {
2203
+ * createECDH,
2204
+ * ECDH
2205
+ * } = await import('crypto');
2206
+ *
2207
+ * const ecdh = createECDH('secp256k1');
2208
+ * ecdh.generateKeys();
2209
+ *
2210
+ * const compressedKey = ecdh.getPublicKey('hex', 'compressed');
2211
+ *
2212
+ * const uncompressedKey = ECDH.convertKey(compressedKey,
2213
+ * 'secp256k1',
2214
+ * 'hex',
2215
+ * 'hex',
2216
+ * 'uncompressed');
2217
+ *
2218
+ * // The converted key and the uncompressed public key should be the same
2219
+ * console.log(uncompressedKey === ecdh.getPublicKey('hex'));
2220
+ * ```
2221
+ * @since v10.0.0
2222
+ * @param inputEncoding The `encoding` of the `key` string.
2223
+ * @param outputEncoding The `encoding` of the return value.
2224
+ * @param [format='uncompressed']
2225
+ */
516
2226
  static convertKey(
517
2227
  key: BinaryLike,
518
2228
  curve: string,
519
2229
  inputEncoding?: BinaryToTextEncoding,
520
2230
  outputEncoding?: 'latin1' | 'hex' | 'base64' | 'base64url',
521
- format?: 'uncompressed' | 'compressed' | 'hybrid',
2231
+ format?: 'uncompressed' | 'compressed' | 'hybrid'
522
2232
  ): Buffer | string;
2233
+ /**
2234
+ * Generates private and public EC Diffie-Hellman key values, and returns
2235
+ * the public key in the specified `format` and `encoding`. This key should be
2236
+ * transferred to the other party.
2237
+ *
2238
+ * The `format` argument specifies point encoding and can be `'compressed'` or`'uncompressed'`. If `format` is not specified, the point will be returned in`'uncompressed'` format.
2239
+ *
2240
+ * If `encoding` is provided a string is returned; otherwise a `Buffer` is returned.
2241
+ * @since v0.11.14
2242
+ * @param encoding The `encoding` of the return value.
2243
+ * @param [format='uncompressed']
2244
+ */
523
2245
  generateKeys(): Buffer;
524
2246
  generateKeys(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string;
525
- computeSecret(other_public_key: NodeJS.ArrayBufferView): Buffer;
526
- computeSecret(other_public_key: string, input_encoding: BinaryToTextEncoding): Buffer;
527
- computeSecret(other_public_key: NodeJS.ArrayBufferView, output_encoding: BinaryToTextEncoding): string;
528
- computeSecret(
529
- other_public_key: string,
530
- input_encoding: BinaryToTextEncoding,
531
- output_encoding: BinaryToTextEncoding,
532
- ): string;
2247
+ /**
2248
+ * Computes the shared secret using `otherPublicKey` as the other
2249
+ * party's public key and returns the computed shared secret. The supplied
2250
+ * key is interpreted using specified `inputEncoding`, and the returned secret
2251
+ * is encoded using the specified `outputEncoding`.
2252
+ * If the `inputEncoding` is not
2253
+ * provided, `otherPublicKey` is expected to be a `Buffer`, `TypedArray`, or`DataView`.
2254
+ *
2255
+ * If `outputEncoding` is given a string will be returned; otherwise a `Buffer` is returned.
2256
+ *
2257
+ * `ecdh.computeSecret` will throw an`ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY` error when `otherPublicKey`lies outside of the elliptic curve. Since `otherPublicKey` is
2258
+ * usually supplied from a remote user over an insecure network,
2259
+ * be sure to handle this exception accordingly.
2260
+ * @since v0.11.14
2261
+ * @param inputEncoding The `encoding` of the `otherPublicKey` string.
2262
+ * @param outputEncoding The `encoding` of the return value.
2263
+ */
2264
+ computeSecret(otherPublicKey: NodeJS.ArrayBufferView): Buffer;
2265
+ computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding): Buffer;
2266
+ computeSecret(otherPublicKey: NodeJS.ArrayBufferView, outputEncoding: BinaryToTextEncoding): string;
2267
+ computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding, outputEncoding: BinaryToTextEncoding): string;
2268
+ /**
2269
+ * If `encoding` is specified, a string is returned; otherwise a `Buffer` is
2270
+ * returned.
2271
+ * @since v0.11.14
2272
+ * @param encoding The `encoding` of the return value.
2273
+ * @return The EC Diffie-Hellman in the specified `encoding`.
2274
+ */
533
2275
  getPrivateKey(): Buffer;
534
2276
  getPrivateKey(encoding: BinaryToTextEncoding): string;
2277
+ /**
2278
+ * The `format` argument specifies point encoding and can be `'compressed'` or`'uncompressed'`. If `format` is not specified the point will be returned in`'uncompressed'` format.
2279
+ *
2280
+ * If `encoding` is specified, a string is returned; otherwise a `Buffer` is
2281
+ * returned.
2282
+ * @since v0.11.14
2283
+ * @param encoding The `encoding` of the return value.
2284
+ * @param [format='uncompressed']
2285
+ * @return The EC Diffie-Hellman public key in the specified `encoding` and `format`.
2286
+ */
535
2287
  getPublicKey(): Buffer;
536
2288
  getPublicKey(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string;
537
- setPrivateKey(private_key: NodeJS.ArrayBufferView): void;
538
- setPrivateKey(private_key: string, encoding: BinaryToTextEncoding): void;
2289
+ /**
2290
+ * Sets the EC Diffie-Hellman private key.
2291
+ * If `encoding` is provided, `privateKey` is expected
2292
+ * to be a string; otherwise `privateKey` is expected to be a `Buffer`,`TypedArray`, or `DataView`.
2293
+ *
2294
+ * If `privateKey` is not valid for the curve specified when the `ECDH` object was
2295
+ * created, an error is thrown. Upon setting the private key, the associated
2296
+ * public point (key) is also generated and set in the `ECDH` object.
2297
+ * @since v0.11.14
2298
+ * @param encoding The `encoding` of the `privateKey` string.
2299
+ */
2300
+ setPrivateKey(privateKey: NodeJS.ArrayBufferView): void;
2301
+ setPrivateKey(privateKey: string, encoding: BinaryToTextEncoding): void;
539
2302
  }
540
- function createECDH(curve_name: string): ECDH;
2303
+ /**
2304
+ * Creates an Elliptic Curve Diffie-Hellman (`ECDH`) key exchange object using a
2305
+ * predefined curve specified by the `curveName` string. Use {@link getCurves} to obtain a list of available curve names. On recent
2306
+ * OpenSSL releases, `openssl ecparam -list_curves` will also display the name
2307
+ * and description of each available elliptic curve.
2308
+ * @since v0.11.14
2309
+ */
2310
+ function createECDH(curveName: string): ECDH;
2311
+ /**
2312
+ * This function is based on a constant-time algorithm.
2313
+ * Returns true if `a` is equal to `b`, without leaking timing information that
2314
+ * would allow an attacker to guess one of the values. This is suitable for
2315
+ * comparing HMAC digests or secret values like authentication cookies or [capability urls](https://www.w3.org/TR/capability-urls/).
2316
+ *
2317
+ * `a` and `b` must both be `Buffer`s, `TypedArray`s, or `DataView`s, and they
2318
+ * must have the same byte length.
2319
+ *
2320
+ * If at least one of `a` and `b` is a `TypedArray` with more than one byte per
2321
+ * entry, such as `Uint16Array`, the result will be computed using the platform
2322
+ * byte order.
2323
+ *
2324
+ * Use of `crypto.timingSafeEqual` does not guarantee that the _surrounding_ code
2325
+ * is timing-safe. Care should be taken to ensure that the surrounding code does
2326
+ * not introduce timing vulnerabilities.
2327
+ * @since v6.6.0
2328
+ */
541
2329
  function timingSafeEqual(a: NodeJS.ArrayBufferView, b: NodeJS.ArrayBufferView): boolean;
542
2330
  /** @deprecated since v10.0.0 */
543
2331
  const DEFAULT_ENCODING: BufferEncoding;
544
-
545
- type KeyType = 'rsa' | 'dsa' | 'ec' | 'ed25519' | 'ed448' | 'x25519' | 'x448';
546
- type KeyFormat = 'pem' | 'der';
547
-
2332
+ type KeyType = 'rsa' | 'rsa-pss' | 'dsa' | 'ec' | 'ed25519' | 'ed448' | 'x25519' | 'x448';
2333
+ type KeyFormat = 'pem' | 'der' | 'jwk';
548
2334
  interface BasePrivateKeyEncodingOptions<T extends KeyFormat> {
549
2335
  format: T;
550
2336
  cipher?: string | undefined;
551
2337
  passphrase?: string | undefined;
552
2338
  }
553
-
554
2339
  interface KeyPairKeyObjectResult {
555
2340
  publicKey: KeyObject;
556
2341
  privateKey: KeyObject;
557
2342
  }
558
-
559
- interface ED25519KeyPairKeyObjectOptions {
560
- /**
561
- * No options.
562
- */
563
- }
564
-
565
- interface ED448KeyPairKeyObjectOptions {
566
- /**
567
- * No options.
568
- */
569
- }
570
-
571
- interface X25519KeyPairKeyObjectOptions {
2343
+ interface ED25519KeyPairKeyObjectOptions {}
2344
+ interface ED448KeyPairKeyObjectOptions {}
2345
+ interface X25519KeyPairKeyObjectOptions {}
2346
+ interface X448KeyPairKeyObjectOptions {}
2347
+ interface ECKeyPairKeyObjectOptions {
572
2348
  /**
573
- * No options.
2349
+ * Name of the curve to use
574
2350
  */
2351
+ namedCurve: string;
575
2352
  }
576
-
577
- interface X448KeyPairKeyObjectOptions {
2353
+ interface RSAKeyPairKeyObjectOptions {
578
2354
  /**
579
- * No options.
2355
+ * Key size in bits
580
2356
  */
581
- }
582
-
583
- interface ECKeyPairKeyObjectOptions {
2357
+ modulusLength: number;
584
2358
  /**
585
- * Name of the curve to use.
2359
+ * Public exponent
2360
+ * @default 0x10001
586
2361
  */
587
- namedCurve: string;
2362
+ publicExponent?: number | undefined;
588
2363
  }
589
-
590
- interface RSAKeyPairKeyObjectOptions {
2364
+ interface RSAPSSKeyPairKeyObjectOptions {
591
2365
  /**
592
2366
  * Key size in bits
593
2367
  */
594
2368
  modulusLength: number;
595
-
596
2369
  /**
2370
+ * Public exponent
597
2371
  * @default 0x10001
598
2372
  */
599
2373
  publicExponent?: number | undefined;
2374
+ /**
2375
+ * Name of the message digest
2376
+ */
2377
+ hashAlgorithm?: string;
2378
+ /**
2379
+ * Name of the message digest used by MGF1
2380
+ */
2381
+ mgf1HashAlgorithm?: string;
2382
+ /**
2383
+ * Minimal salt length in bytes
2384
+ */
2385
+ saltLength?: string;
600
2386
  }
601
-
602
2387
  interface DSAKeyPairKeyObjectOptions {
603
2388
  /**
604
2389
  * Key size in bits
605
2390
  */
606
2391
  modulusLength: number;
607
-
608
2392
  /**
609
2393
  * Size of q in bits
610
2394
  */
611
2395
  divisorLength: number;
612
2396
  }
613
-
614
2397
  interface RSAKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
615
2398
  /**
616
2399
  * Key size in bits
617
2400
  */
618
2401
  modulusLength: number;
619
2402
  /**
2403
+ * Public exponent
620
2404
  * @default 0x10001
621
2405
  */
622
2406
  publicExponent?: number | undefined;
623
-
624
2407
  publicKeyEncoding: {
625
2408
  type: 'pkcs1' | 'spki';
626
2409
  format: PubF;
@@ -629,7 +2412,36 @@ declare module 'crypto' {
629
2412
  type: 'pkcs1' | 'pkcs8';
630
2413
  };
631
2414
  }
632
-
2415
+ interface RSAPSSKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
2416
+ /**
2417
+ * Key size in bits
2418
+ */
2419
+ modulusLength: number;
2420
+ /**
2421
+ * Public exponent
2422
+ * @default 0x10001
2423
+ */
2424
+ publicExponent?: number | undefined;
2425
+ /**
2426
+ * Name of the message digest
2427
+ */
2428
+ hashAlgorithm?: string;
2429
+ /**
2430
+ * Name of the message digest used by MGF1
2431
+ */
2432
+ mgf1HashAlgorithm?: string;
2433
+ /**
2434
+ * Minimal salt length in bytes
2435
+ */
2436
+ saltLength?: string;
2437
+ publicKeyEncoding: {
2438
+ type: 'spki';
2439
+ format: PubF;
2440
+ };
2441
+ privateKeyEncoding: BasePrivateKeyEncodingOptions<PrivF> & {
2442
+ type: 'pkcs8';
2443
+ };
2444
+ }
633
2445
  interface DSAKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
634
2446
  /**
635
2447
  * Key size in bits
@@ -639,7 +2451,6 @@ declare module 'crypto' {
639
2451
  * Size of q in bits
640
2452
  */
641
2453
  divisorLength: number;
642
-
643
2454
  publicKeyEncoding: {
644
2455
  type: 'spki';
645
2456
  format: PubF;
@@ -648,13 +2459,11 @@ declare module 'crypto' {
648
2459
  type: 'pkcs8';
649
2460
  };
650
2461
  }
651
-
652
2462
  interface ECKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
653
2463
  /**
654
2464
  * Name of the curve to use.
655
2465
  */
656
2466
  namedCurve: string;
657
-
658
2467
  publicKeyEncoding: {
659
2468
  type: 'pkcs1' | 'spki';
660
2469
  format: PubF;
@@ -663,7 +2472,6 @@ declare module 'crypto' {
663
2472
  type: 'sec1' | 'pkcs8';
664
2473
  };
665
2474
  }
666
-
667
2475
  interface ED25519KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
668
2476
  publicKeyEncoding: {
669
2477
  type: 'spki';
@@ -673,7 +2481,6 @@ declare module 'crypto' {
673
2481
  type: 'pkcs8';
674
2482
  };
675
2483
  }
676
-
677
2484
  interface ED448KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
678
2485
  publicKeyEncoding: {
679
2486
  type: 'spki';
@@ -683,7 +2490,6 @@ declare module 'crypto' {
683
2490
  type: 'pkcs8';
684
2491
  };
685
2492
  }
686
-
687
2493
  interface X25519KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
688
2494
  publicKeyEncoding: {
689
2495
  type: 'spki';
@@ -693,7 +2499,6 @@ declare module 'crypto' {
693
2499
  type: 'pkcs8';
694
2500
  };
695
2501
  }
696
-
697
2502
  interface X448KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
698
2503
  publicKeyEncoding: {
699
2504
  type: 'spki';
@@ -703,489 +2508,1357 @@ declare module 'crypto' {
703
2508
  type: 'pkcs8';
704
2509
  };
705
2510
  }
706
-
707
2511
  interface KeyPairSyncResult<T1 extends string | Buffer, T2 extends string | Buffer> {
708
2512
  publicKey: T1;
709
2513
  privateKey: T2;
710
2514
  }
711
-
712
- function generateKeyPairSync(
713
- type: 'rsa',
714
- options: RSAKeyPairOptions<'pem', 'pem'>,
715
- ): KeyPairSyncResult<string, string>;
716
- function generateKeyPairSync(
717
- type: 'rsa',
718
- options: RSAKeyPairOptions<'pem', 'der'>,
719
- ): KeyPairSyncResult<string, Buffer>;
720
- function generateKeyPairSync(
721
- type: 'rsa',
722
- options: RSAKeyPairOptions<'der', 'pem'>,
723
- ): KeyPairSyncResult<Buffer, string>;
724
- function generateKeyPairSync(
725
- type: 'rsa',
726
- options: RSAKeyPairOptions<'der', 'der'>,
727
- ): KeyPairSyncResult<Buffer, Buffer>;
2515
+ /**
2516
+ * Generates a new asymmetric key pair of the given `type`. RSA, RSA-PSS, DSA, EC,
2517
+ * Ed25519, Ed448, X25519, X448, and DH are currently supported.
2518
+ *
2519
+ * If a `publicKeyEncoding` or `privateKeyEncoding` was specified, this function
2520
+ * behaves as if `keyObject.export()` had been called on its result. Otherwise,
2521
+ * the respective part of the key is returned as a `KeyObject`.
2522
+ *
2523
+ * When encoding public keys, it is recommended to use `'spki'`. When encoding
2524
+ * private keys, it is recommended to use `'pkcs8'` with a strong passphrase,
2525
+ * and to keep the passphrase confidential.
2526
+ *
2527
+ * ```js
2528
+ * const {
2529
+ * generateKeyPairSync
2530
+ * } = await import('crypto');
2531
+ *
2532
+ * const {
2533
+ * publicKey,
2534
+ * privateKey,
2535
+ * } = generateKeyPairSync('rsa', {
2536
+ * modulusLength: 4096,
2537
+ * publicKeyEncoding: {
2538
+ * type: 'spki',
2539
+ * format: 'pem'
2540
+ * },
2541
+ * privateKeyEncoding: {
2542
+ * type: 'pkcs8',
2543
+ * format: 'pem',
2544
+ * cipher: 'aes-256-cbc',
2545
+ * passphrase: 'top secret'
2546
+ * }
2547
+ * });
2548
+ * ```
2549
+ *
2550
+ * The return value `{ publicKey, privateKey }` represents the generated key pair.
2551
+ * When PEM encoding was selected, the respective key will be a string, otherwise
2552
+ * it will be a buffer containing the data encoded as DER.
2553
+ * @since v10.12.0
2554
+ * @param type Must be `'rsa'`, `'rsa-pss'`, `'dsa'`, `'ec'`, `'ed25519'`, `'ed448'`, `'x25519'`, `'x448'`, or `'dh'`.
2555
+ */
2556
+ function generateKeyPairSync(type: 'rsa', options: RSAKeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
2557
+ function generateKeyPairSync(type: 'rsa', options: RSAKeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
2558
+ function generateKeyPairSync(type: 'rsa', options: RSAKeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
2559
+ function generateKeyPairSync(type: 'rsa', options: RSAKeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
728
2560
  function generateKeyPairSync(type: 'rsa', options: RSAKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
729
-
730
- function generateKeyPairSync(
731
- type: 'dsa',
732
- options: DSAKeyPairOptions<'pem', 'pem'>,
733
- ): KeyPairSyncResult<string, string>;
734
- function generateKeyPairSync(
735
- type: 'dsa',
736
- options: DSAKeyPairOptions<'pem', 'der'>,
737
- ): KeyPairSyncResult<string, Buffer>;
738
- function generateKeyPairSync(
739
- type: 'dsa',
740
- options: DSAKeyPairOptions<'der', 'pem'>,
741
- ): KeyPairSyncResult<Buffer, string>;
742
- function generateKeyPairSync(
743
- type: 'dsa',
744
- options: DSAKeyPairOptions<'der', 'der'>,
745
- ): KeyPairSyncResult<Buffer, Buffer>;
2561
+ function generateKeyPairSync(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
2562
+ function generateKeyPairSync(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
2563
+ function generateKeyPairSync(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
2564
+ function generateKeyPairSync(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
2565
+ function generateKeyPairSync(type: 'rsa-pss', options: RSAPSSKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
2566
+ function generateKeyPairSync(type: 'dsa', options: DSAKeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
2567
+ function generateKeyPairSync(type: 'dsa', options: DSAKeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
2568
+ function generateKeyPairSync(type: 'dsa', options: DSAKeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
2569
+ function generateKeyPairSync(type: 'dsa', options: DSAKeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
746
2570
  function generateKeyPairSync(type: 'dsa', options: DSAKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
747
-
748
- function generateKeyPairSync(
749
- type: 'ec',
750
- options: ECKeyPairOptions<'pem', 'pem'>,
751
- ): KeyPairSyncResult<string, string>;
752
- function generateKeyPairSync(
753
- type: 'ec',
754
- options: ECKeyPairOptions<'pem', 'der'>,
755
- ): KeyPairSyncResult<string, Buffer>;
756
- function generateKeyPairSync(
757
- type: 'ec',
758
- options: ECKeyPairOptions<'der', 'pem'>,
759
- ): KeyPairSyncResult<Buffer, string>;
760
- function generateKeyPairSync(
761
- type: 'ec',
762
- options: ECKeyPairOptions<'der', 'der'>,
763
- ): KeyPairSyncResult<Buffer, Buffer>;
2571
+ function generateKeyPairSync(type: 'ec', options: ECKeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
2572
+ function generateKeyPairSync(type: 'ec', options: ECKeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
2573
+ function generateKeyPairSync(type: 'ec', options: ECKeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
2574
+ function generateKeyPairSync(type: 'ec', options: ECKeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
764
2575
  function generateKeyPairSync(type: 'ec', options: ECKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
765
-
766
- function generateKeyPairSync(
767
- type: 'ed25519',
768
- options: ED25519KeyPairOptions<'pem', 'pem'>,
769
- ): KeyPairSyncResult<string, string>;
770
- function generateKeyPairSync(
771
- type: 'ed25519',
772
- options: ED25519KeyPairOptions<'pem', 'der'>,
773
- ): KeyPairSyncResult<string, Buffer>;
774
- function generateKeyPairSync(
775
- type: 'ed25519',
776
- options: ED25519KeyPairOptions<'der', 'pem'>,
777
- ): KeyPairSyncResult<Buffer, string>;
778
- function generateKeyPairSync(
779
- type: 'ed25519',
780
- options: ED25519KeyPairOptions<'der', 'der'>,
781
- ): KeyPairSyncResult<Buffer, Buffer>;
2576
+ function generateKeyPairSync(type: 'ed25519', options: ED25519KeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
2577
+ function generateKeyPairSync(type: 'ed25519', options: ED25519KeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
2578
+ function generateKeyPairSync(type: 'ed25519', options: ED25519KeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
2579
+ function generateKeyPairSync(type: 'ed25519', options: ED25519KeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
782
2580
  function generateKeyPairSync(type: 'ed25519', options?: ED25519KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
783
-
784
- function generateKeyPairSync(
785
- type: 'ed448',
786
- options: ED448KeyPairOptions<'pem', 'pem'>,
787
- ): KeyPairSyncResult<string, string>;
788
- function generateKeyPairSync(
789
- type: 'ed448',
790
- options: ED448KeyPairOptions<'pem', 'der'>,
791
- ): KeyPairSyncResult<string, Buffer>;
792
- function generateKeyPairSync(
793
- type: 'ed448',
794
- options: ED448KeyPairOptions<'der', 'pem'>,
795
- ): KeyPairSyncResult<Buffer, string>;
796
- function generateKeyPairSync(
797
- type: 'ed448',
798
- options: ED448KeyPairOptions<'der', 'der'>,
799
- ): KeyPairSyncResult<Buffer, Buffer>;
2581
+ function generateKeyPairSync(type: 'ed448', options: ED448KeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
2582
+ function generateKeyPairSync(type: 'ed448', options: ED448KeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
2583
+ function generateKeyPairSync(type: 'ed448', options: ED448KeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
2584
+ function generateKeyPairSync(type: 'ed448', options: ED448KeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
800
2585
  function generateKeyPairSync(type: 'ed448', options?: ED448KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
801
-
802
- function generateKeyPairSync(
803
- type: 'x25519',
804
- options: X25519KeyPairOptions<'pem', 'pem'>,
805
- ): KeyPairSyncResult<string, string>;
806
- function generateKeyPairSync(
807
- type: 'x25519',
808
- options: X25519KeyPairOptions<'pem', 'der'>,
809
- ): KeyPairSyncResult<string, Buffer>;
810
- function generateKeyPairSync(
811
- type: 'x25519',
812
- options: X25519KeyPairOptions<'der', 'pem'>,
813
- ): KeyPairSyncResult<Buffer, string>;
814
- function generateKeyPairSync(
815
- type: 'x25519',
816
- options: X25519KeyPairOptions<'der', 'der'>,
817
- ): KeyPairSyncResult<Buffer, Buffer>;
2586
+ function generateKeyPairSync(type: 'x25519', options: X25519KeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
2587
+ function generateKeyPairSync(type: 'x25519', options: X25519KeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
2588
+ function generateKeyPairSync(type: 'x25519', options: X25519KeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
2589
+ function generateKeyPairSync(type: 'x25519', options: X25519KeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
818
2590
  function generateKeyPairSync(type: 'x25519', options?: X25519KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
819
-
820
- function generateKeyPairSync(
821
- type: 'x448',
822
- options: X448KeyPairOptions<'pem', 'pem'>,
823
- ): KeyPairSyncResult<string, string>;
824
- function generateKeyPairSync(
825
- type: 'x448',
826
- options: X448KeyPairOptions<'pem', 'der'>,
827
- ): KeyPairSyncResult<string, Buffer>;
828
- function generateKeyPairSync(
829
- type: 'x448',
830
- options: X448KeyPairOptions<'der', 'pem'>,
831
- ): KeyPairSyncResult<Buffer, string>;
832
- function generateKeyPairSync(
833
- type: 'x448',
834
- options: X448KeyPairOptions<'der', 'der'>,
835
- ): KeyPairSyncResult<Buffer, Buffer>;
2591
+ function generateKeyPairSync(type: 'x448', options: X448KeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
2592
+ function generateKeyPairSync(type: 'x448', options: X448KeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
2593
+ function generateKeyPairSync(type: 'x448', options: X448KeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
2594
+ function generateKeyPairSync(type: 'x448', options: X448KeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
836
2595
  function generateKeyPairSync(type: 'x448', options?: X448KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
837
-
838
- function generateKeyPair(
839
- type: 'rsa',
840
- options: RSAKeyPairOptions<'pem', 'pem'>,
841
- callback: (err: Error | null, publicKey: string, privateKey: string) => void,
842
- ): void;
843
- function generateKeyPair(
844
- type: 'rsa',
845
- options: RSAKeyPairOptions<'pem', 'der'>,
846
- callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
847
- ): void;
848
- function generateKeyPair(
849
- type: 'rsa',
850
- options: RSAKeyPairOptions<'der', 'pem'>,
851
- callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
852
- ): void;
853
- function generateKeyPair(
854
- type: 'rsa',
855
- options: RSAKeyPairOptions<'der', 'der'>,
856
- callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
857
- ): void;
858
- function generateKeyPair(
859
- type: 'rsa',
860
- options: RSAKeyPairKeyObjectOptions,
861
- callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
862
- ): void;
863
-
864
- function generateKeyPair(
865
- type: 'dsa',
866
- options: DSAKeyPairOptions<'pem', 'pem'>,
867
- callback: (err: Error | null, publicKey: string, privateKey: string) => void,
868
- ): void;
869
- function generateKeyPair(
870
- type: 'dsa',
871
- options: DSAKeyPairOptions<'pem', 'der'>,
872
- callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
873
- ): void;
874
- function generateKeyPair(
875
- type: 'dsa',
876
- options: DSAKeyPairOptions<'der', 'pem'>,
877
- callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
878
- ): void;
879
- function generateKeyPair(
880
- type: 'dsa',
881
- options: DSAKeyPairOptions<'der', 'der'>,
882
- callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
883
- ): void;
884
- function generateKeyPair(
885
- type: 'dsa',
886
- options: DSAKeyPairKeyObjectOptions,
887
- callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
888
- ): void;
889
-
890
- function generateKeyPair(
891
- type: 'ec',
892
- options: ECKeyPairOptions<'pem', 'pem'>,
893
- callback: (err: Error | null, publicKey: string, privateKey: string) => void,
894
- ): void;
895
- function generateKeyPair(
896
- type: 'ec',
897
- options: ECKeyPairOptions<'pem', 'der'>,
898
- callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
899
- ): void;
900
- function generateKeyPair(
901
- type: 'ec',
902
- options: ECKeyPairOptions<'der', 'pem'>,
903
- callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
904
- ): void;
905
- function generateKeyPair(
906
- type: 'ec',
907
- options: ECKeyPairOptions<'der', 'der'>,
908
- callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
909
- ): void;
910
- function generateKeyPair(
911
- type: 'ec',
912
- options: ECKeyPairKeyObjectOptions,
913
- callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
914
- ): void;
915
-
916
- function generateKeyPair(
917
- type: 'ed25519',
918
- options: ED25519KeyPairOptions<'pem', 'pem'>,
919
- callback: (err: Error | null, publicKey: string, privateKey: string) => void,
920
- ): void;
921
- function generateKeyPair(
922
- type: 'ed25519',
923
- options: ED25519KeyPairOptions<'pem', 'der'>,
924
- callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
925
- ): void;
926
- function generateKeyPair(
927
- type: 'ed25519',
928
- options: ED25519KeyPairOptions<'der', 'pem'>,
929
- callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
930
- ): void;
931
- function generateKeyPair(
932
- type: 'ed25519',
933
- options: ED25519KeyPairOptions<'der', 'der'>,
934
- callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
935
- ): void;
936
- function generateKeyPair(
937
- type: 'ed25519',
938
- options: ED25519KeyPairKeyObjectOptions | undefined,
939
- callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
940
- ): void;
941
-
942
- function generateKeyPair(
943
- type: 'ed448',
944
- options: ED448KeyPairOptions<'pem', 'pem'>,
945
- callback: (err: Error | null, publicKey: string, privateKey: string) => void,
946
- ): void;
947
- function generateKeyPair(
948
- type: 'ed448',
949
- options: ED448KeyPairOptions<'pem', 'der'>,
950
- callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
951
- ): void;
952
- function generateKeyPair(
953
- type: 'ed448',
954
- options: ED448KeyPairOptions<'der', 'pem'>,
955
- callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
956
- ): void;
957
- function generateKeyPair(
958
- type: 'ed448',
959
- options: ED448KeyPairOptions<'der', 'der'>,
960
- callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
961
- ): void;
962
- function generateKeyPair(
963
- type: 'ed448',
964
- options: ED448KeyPairKeyObjectOptions | undefined,
965
- callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
966
- ): void;
967
-
968
- function generateKeyPair(
969
- type: 'x25519',
970
- options: X25519KeyPairOptions<'pem', 'pem'>,
971
- callback: (err: Error | null, publicKey: string, privateKey: string) => void,
972
- ): void;
973
- function generateKeyPair(
974
- type: 'x25519',
975
- options: X25519KeyPairOptions<'pem', 'der'>,
976
- callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
977
- ): void;
978
- function generateKeyPair(
979
- type: 'x25519',
980
- options: X25519KeyPairOptions<'der', 'pem'>,
981
- callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
982
- ): void;
983
- function generateKeyPair(
984
- type: 'x25519',
985
- options: X25519KeyPairOptions<'der', 'der'>,
986
- callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
987
- ): void;
988
- function generateKeyPair(
989
- type: 'x25519',
990
- options: X25519KeyPairKeyObjectOptions | undefined,
991
- callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
992
- ): void;
993
-
994
- function generateKeyPair(
995
- type: 'x448',
996
- options: X448KeyPairOptions<'pem', 'pem'>,
997
- callback: (err: Error | null, publicKey: string, privateKey: string) => void,
998
- ): void;
999
- function generateKeyPair(
1000
- type: 'x448',
1001
- options: X448KeyPairOptions<'pem', 'der'>,
1002
- callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
1003
- ): void;
1004
- function generateKeyPair(
1005
- type: 'x448',
1006
- options: X448KeyPairOptions<'der', 'pem'>,
1007
- callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
1008
- ): void;
1009
- function generateKeyPair(
1010
- type: 'x448',
1011
- options: X448KeyPairOptions<'der', 'der'>,
1012
- callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
1013
- ): void;
1014
- function generateKeyPair(
1015
- type: 'x448',
1016
- options: X448KeyPairKeyObjectOptions | undefined,
1017
- callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
1018
- ): void;
1019
-
2596
+ /**
2597
+ * Generates a new asymmetric key pair of the given `type`. RSA, RSA-PSS, DSA, EC,
2598
+ * Ed25519, Ed448, X25519, X448, and DH are currently supported.
2599
+ *
2600
+ * If a `publicKeyEncoding` or `privateKeyEncoding` was specified, this function
2601
+ * behaves as if `keyObject.export()` had been called on its result. Otherwise,
2602
+ * the respective part of the key is returned as a `KeyObject`.
2603
+ *
2604
+ * It is recommended to encode public keys as `'spki'` and private keys as`'pkcs8'` with encryption for long-term storage:
2605
+ *
2606
+ * ```js
2607
+ * const {
2608
+ * generateKeyPair
2609
+ * } = await import('crypto');
2610
+ *
2611
+ * generateKeyPair('rsa', {
2612
+ * modulusLength: 4096,
2613
+ * publicKeyEncoding: {
2614
+ * type: 'spki',
2615
+ * format: 'pem'
2616
+ * },
2617
+ * privateKeyEncoding: {
2618
+ * type: 'pkcs8',
2619
+ * format: 'pem',
2620
+ * cipher: 'aes-256-cbc',
2621
+ * passphrase: 'top secret'
2622
+ * }
2623
+ * }, (err, publicKey, privateKey) => {
2624
+ * // Handle errors and use the generated key pair.
2625
+ * });
2626
+ * ```
2627
+ *
2628
+ * On completion, `callback` will be called with `err` set to `undefined` and`publicKey` / `privateKey` representing the generated key pair.
2629
+ *
2630
+ * If this method is invoked as its `util.promisify()` ed version, it returns
2631
+ * a `Promise` for an `Object` with `publicKey` and `privateKey` properties.
2632
+ * @since v10.12.0
2633
+ * @param type Must be `'rsa'`, `'rsa-pss'`, `'dsa'`, `'ec'`, `'ed25519'`, `'ed448'`, `'x25519'`, `'x448'`, or `'dh'`.
2634
+ */
2635
+ function generateKeyPair(type: 'rsa', options: RSAKeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
2636
+ function generateKeyPair(type: 'rsa', options: RSAKeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
2637
+ function generateKeyPair(type: 'rsa', options: RSAKeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
2638
+ function generateKeyPair(type: 'rsa', options: RSAKeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
2639
+ function generateKeyPair(type: 'rsa', options: RSAKeyPairKeyObjectOptions, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
2640
+ function generateKeyPair(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
2641
+ function generateKeyPair(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
2642
+ function generateKeyPair(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
2643
+ function generateKeyPair(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
2644
+ function generateKeyPair(type: 'rsa-pss', options: RSAPSSKeyPairKeyObjectOptions, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
2645
+ function generateKeyPair(type: 'dsa', options: DSAKeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
2646
+ function generateKeyPair(type: 'dsa', options: DSAKeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
2647
+ function generateKeyPair(type: 'dsa', options: DSAKeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
2648
+ function generateKeyPair(type: 'dsa', options: DSAKeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
2649
+ function generateKeyPair(type: 'dsa', options: DSAKeyPairKeyObjectOptions, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
2650
+ function generateKeyPair(type: 'ec', options: ECKeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
2651
+ function generateKeyPair(type: 'ec', options: ECKeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
2652
+ function generateKeyPair(type: 'ec', options: ECKeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
2653
+ function generateKeyPair(type: 'ec', options: ECKeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
2654
+ function generateKeyPair(type: 'ec', options: ECKeyPairKeyObjectOptions, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
2655
+ function generateKeyPair(type: 'ed25519', options: ED25519KeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
2656
+ function generateKeyPair(type: 'ed25519', options: ED25519KeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
2657
+ function generateKeyPair(type: 'ed25519', options: ED25519KeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
2658
+ function generateKeyPair(type: 'ed25519', options: ED25519KeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
2659
+ function generateKeyPair(type: 'ed25519', options: ED25519KeyPairKeyObjectOptions | undefined, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
2660
+ function generateKeyPair(type: 'ed448', options: ED448KeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
2661
+ function generateKeyPair(type: 'ed448', options: ED448KeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
2662
+ function generateKeyPair(type: 'ed448', options: ED448KeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
2663
+ function generateKeyPair(type: 'ed448', options: ED448KeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
2664
+ function generateKeyPair(type: 'ed448', options: ED448KeyPairKeyObjectOptions | undefined, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
2665
+ function generateKeyPair(type: 'x25519', options: X25519KeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
2666
+ function generateKeyPair(type: 'x25519', options: X25519KeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
2667
+ function generateKeyPair(type: 'x25519', options: X25519KeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
2668
+ function generateKeyPair(type: 'x25519', options: X25519KeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
2669
+ function generateKeyPair(type: 'x25519', options: X25519KeyPairKeyObjectOptions | undefined, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
2670
+ function generateKeyPair(type: 'x448', options: X448KeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
2671
+ function generateKeyPair(type: 'x448', options: X448KeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
2672
+ function generateKeyPair(type: 'x448', options: X448KeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
2673
+ function generateKeyPair(type: 'x448', options: X448KeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
2674
+ function generateKeyPair(type: 'x448', options: X448KeyPairKeyObjectOptions | undefined, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
1020
2675
  namespace generateKeyPair {
1021
2676
  function __promisify__(
1022
2677
  type: 'rsa',
1023
- options: RSAKeyPairOptions<'pem', 'pem'>,
1024
- ): Promise<{ publicKey: string; privateKey: string }>;
2678
+ options: RSAKeyPairOptions<'pem', 'pem'>
2679
+ ): Promise<{
2680
+ publicKey: string;
2681
+ privateKey: string;
2682
+ }>;
1025
2683
  function __promisify__(
1026
2684
  type: 'rsa',
1027
- options: RSAKeyPairOptions<'pem', 'der'>,
1028
- ): Promise<{ publicKey: string; privateKey: Buffer }>;
2685
+ options: RSAKeyPairOptions<'pem', 'der'>
2686
+ ): Promise<{
2687
+ publicKey: string;
2688
+ privateKey: Buffer;
2689
+ }>;
1029
2690
  function __promisify__(
1030
2691
  type: 'rsa',
1031
- options: RSAKeyPairOptions<'der', 'pem'>,
1032
- ): Promise<{ publicKey: Buffer; privateKey: string }>;
2692
+ options: RSAKeyPairOptions<'der', 'pem'>
2693
+ ): Promise<{
2694
+ publicKey: Buffer;
2695
+ privateKey: string;
2696
+ }>;
1033
2697
  function __promisify__(
1034
2698
  type: 'rsa',
1035
- options: RSAKeyPairOptions<'der', 'der'>,
1036
- ): Promise<{ publicKey: Buffer; privateKey: Buffer }>;
2699
+ options: RSAKeyPairOptions<'der', 'der'>
2700
+ ): Promise<{
2701
+ publicKey: Buffer;
2702
+ privateKey: Buffer;
2703
+ }>;
1037
2704
  function __promisify__(type: 'rsa', options: RSAKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
1038
-
2705
+ function __promisify__(
2706
+ type: 'rsa-pss',
2707
+ options: RSAPSSKeyPairOptions<'pem', 'pem'>
2708
+ ): Promise<{
2709
+ publicKey: string;
2710
+ privateKey: string;
2711
+ }>;
2712
+ function __promisify__(
2713
+ type: 'rsa-pss',
2714
+ options: RSAPSSKeyPairOptions<'pem', 'der'>
2715
+ ): Promise<{
2716
+ publicKey: string;
2717
+ privateKey: Buffer;
2718
+ }>;
2719
+ function __promisify__(
2720
+ type: 'rsa-pss',
2721
+ options: RSAPSSKeyPairOptions<'der', 'pem'>
2722
+ ): Promise<{
2723
+ publicKey: Buffer;
2724
+ privateKey: string;
2725
+ }>;
2726
+ function __promisify__(
2727
+ type: 'rsa-pss',
2728
+ options: RSAPSSKeyPairOptions<'der', 'der'>
2729
+ ): Promise<{
2730
+ publicKey: Buffer;
2731
+ privateKey: Buffer;
2732
+ }>;
2733
+ function __promisify__(type: 'rsa-pss', options: RSAPSSKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
1039
2734
  function __promisify__(
1040
2735
  type: 'dsa',
1041
- options: DSAKeyPairOptions<'pem', 'pem'>,
1042
- ): Promise<{ publicKey: string; privateKey: string }>;
2736
+ options: DSAKeyPairOptions<'pem', 'pem'>
2737
+ ): Promise<{
2738
+ publicKey: string;
2739
+ privateKey: string;
2740
+ }>;
1043
2741
  function __promisify__(
1044
2742
  type: 'dsa',
1045
- options: DSAKeyPairOptions<'pem', 'der'>,
1046
- ): Promise<{ publicKey: string; privateKey: Buffer }>;
2743
+ options: DSAKeyPairOptions<'pem', 'der'>
2744
+ ): Promise<{
2745
+ publicKey: string;
2746
+ privateKey: Buffer;
2747
+ }>;
1047
2748
  function __promisify__(
1048
2749
  type: 'dsa',
1049
- options: DSAKeyPairOptions<'der', 'pem'>,
1050
- ): Promise<{ publicKey: Buffer; privateKey: string }>;
2750
+ options: DSAKeyPairOptions<'der', 'pem'>
2751
+ ): Promise<{
2752
+ publicKey: Buffer;
2753
+ privateKey: string;
2754
+ }>;
1051
2755
  function __promisify__(
1052
2756
  type: 'dsa',
1053
- options: DSAKeyPairOptions<'der', 'der'>,
1054
- ): Promise<{ publicKey: Buffer; privateKey: Buffer }>;
2757
+ options: DSAKeyPairOptions<'der', 'der'>
2758
+ ): Promise<{
2759
+ publicKey: Buffer;
2760
+ privateKey: Buffer;
2761
+ }>;
1055
2762
  function __promisify__(type: 'dsa', options: DSAKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
1056
-
1057
2763
  function __promisify__(
1058
2764
  type: 'ec',
1059
- options: ECKeyPairOptions<'pem', 'pem'>,
1060
- ): Promise<{ publicKey: string; privateKey: string }>;
2765
+ options: ECKeyPairOptions<'pem', 'pem'>
2766
+ ): Promise<{
2767
+ publicKey: string;
2768
+ privateKey: string;
2769
+ }>;
1061
2770
  function __promisify__(
1062
2771
  type: 'ec',
1063
- options: ECKeyPairOptions<'pem', 'der'>,
1064
- ): Promise<{ publicKey: string; privateKey: Buffer }>;
2772
+ options: ECKeyPairOptions<'pem', 'der'>
2773
+ ): Promise<{
2774
+ publicKey: string;
2775
+ privateKey: Buffer;
2776
+ }>;
1065
2777
  function __promisify__(
1066
2778
  type: 'ec',
1067
- options: ECKeyPairOptions<'der', 'pem'>,
1068
- ): Promise<{ publicKey: Buffer; privateKey: string }>;
2779
+ options: ECKeyPairOptions<'der', 'pem'>
2780
+ ): Promise<{
2781
+ publicKey: Buffer;
2782
+ privateKey: string;
2783
+ }>;
1069
2784
  function __promisify__(
1070
2785
  type: 'ec',
1071
- options: ECKeyPairOptions<'der', 'der'>,
1072
- ): Promise<{ publicKey: Buffer; privateKey: Buffer }>;
2786
+ options: ECKeyPairOptions<'der', 'der'>
2787
+ ): Promise<{
2788
+ publicKey: Buffer;
2789
+ privateKey: Buffer;
2790
+ }>;
1073
2791
  function __promisify__(type: 'ec', options: ECKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
1074
-
1075
- function __promisify__(
1076
- type: 'ed25519',
1077
- options: ED25519KeyPairOptions<'pem', 'pem'>,
1078
- ): Promise<{ publicKey: string; privateKey: string }>;
1079
2792
  function __promisify__(
1080
2793
  type: 'ed25519',
1081
- options: ED25519KeyPairOptions<'pem', 'der'>,
1082
- ): Promise<{ publicKey: string; privateKey: Buffer }>;
2794
+ options: ED25519KeyPairOptions<'pem', 'pem'>
2795
+ ): Promise<{
2796
+ publicKey: string;
2797
+ privateKey: string;
2798
+ }>;
1083
2799
  function __promisify__(
1084
2800
  type: 'ed25519',
1085
- options: ED25519KeyPairOptions<'der', 'pem'>,
1086
- ): Promise<{ publicKey: Buffer; privateKey: string }>;
2801
+ options: ED25519KeyPairOptions<'pem', 'der'>
2802
+ ): Promise<{
2803
+ publicKey: string;
2804
+ privateKey: Buffer;
2805
+ }>;
1087
2806
  function __promisify__(
1088
2807
  type: 'ed25519',
1089
- options: ED25519KeyPairOptions<'der', 'der'>,
1090
- ): Promise<{ publicKey: Buffer; privateKey: Buffer }>;
2808
+ options: ED25519KeyPairOptions<'der', 'pem'>
2809
+ ): Promise<{
2810
+ publicKey: Buffer;
2811
+ privateKey: string;
2812
+ }>;
1091
2813
  function __promisify__(
1092
2814
  type: 'ed25519',
1093
- options?: ED25519KeyPairKeyObjectOptions,
1094
- ): Promise<KeyPairKeyObjectResult>;
1095
-
2815
+ options: ED25519KeyPairOptions<'der', 'der'>
2816
+ ): Promise<{
2817
+ publicKey: Buffer;
2818
+ privateKey: Buffer;
2819
+ }>;
2820
+ function __promisify__(type: 'ed25519', options?: ED25519KeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
1096
2821
  function __promisify__(
1097
2822
  type: 'ed448',
1098
- options: ED448KeyPairOptions<'pem', 'pem'>,
1099
- ): Promise<{ publicKey: string; privateKey: string }>;
2823
+ options: ED448KeyPairOptions<'pem', 'pem'>
2824
+ ): Promise<{
2825
+ publicKey: string;
2826
+ privateKey: string;
2827
+ }>;
1100
2828
  function __promisify__(
1101
2829
  type: 'ed448',
1102
- options: ED448KeyPairOptions<'pem', 'der'>,
1103
- ): Promise<{ publicKey: string; privateKey: Buffer }>;
2830
+ options: ED448KeyPairOptions<'pem', 'der'>
2831
+ ): Promise<{
2832
+ publicKey: string;
2833
+ privateKey: Buffer;
2834
+ }>;
1104
2835
  function __promisify__(
1105
2836
  type: 'ed448',
1106
- options: ED448KeyPairOptions<'der', 'pem'>,
1107
- ): Promise<{ publicKey: Buffer; privateKey: string }>;
2837
+ options: ED448KeyPairOptions<'der', 'pem'>
2838
+ ): Promise<{
2839
+ publicKey: Buffer;
2840
+ privateKey: string;
2841
+ }>;
1108
2842
  function __promisify__(
1109
2843
  type: 'ed448',
1110
- options: ED448KeyPairOptions<'der', 'der'>,
1111
- ): Promise<{ publicKey: Buffer; privateKey: Buffer }>;
2844
+ options: ED448KeyPairOptions<'der', 'der'>
2845
+ ): Promise<{
2846
+ publicKey: Buffer;
2847
+ privateKey: Buffer;
2848
+ }>;
1112
2849
  function __promisify__(type: 'ed448', options?: ED448KeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
1113
-
1114
2850
  function __promisify__(
1115
2851
  type: 'x25519',
1116
- options: X25519KeyPairOptions<'pem', 'pem'>,
1117
- ): Promise<{ publicKey: string; privateKey: string }>;
2852
+ options: X25519KeyPairOptions<'pem', 'pem'>
2853
+ ): Promise<{
2854
+ publicKey: string;
2855
+ privateKey: string;
2856
+ }>;
1118
2857
  function __promisify__(
1119
2858
  type: 'x25519',
1120
- options: X25519KeyPairOptions<'pem', 'der'>,
1121
- ): Promise<{ publicKey: string; privateKey: Buffer }>;
2859
+ options: X25519KeyPairOptions<'pem', 'der'>
2860
+ ): Promise<{
2861
+ publicKey: string;
2862
+ privateKey: Buffer;
2863
+ }>;
1122
2864
  function __promisify__(
1123
2865
  type: 'x25519',
1124
- options: X25519KeyPairOptions<'der', 'pem'>,
1125
- ): Promise<{ publicKey: Buffer; privateKey: string }>;
2866
+ options: X25519KeyPairOptions<'der', 'pem'>
2867
+ ): Promise<{
2868
+ publicKey: Buffer;
2869
+ privateKey: string;
2870
+ }>;
1126
2871
  function __promisify__(
1127
2872
  type: 'x25519',
1128
- options: X25519KeyPairOptions<'der', 'der'>,
1129
- ): Promise<{ publicKey: Buffer; privateKey: Buffer }>;
1130
- function __promisify__(
1131
- type: 'x25519',
1132
- options?: X25519KeyPairKeyObjectOptions,
1133
- ): Promise<KeyPairKeyObjectResult>;
1134
-
2873
+ options: X25519KeyPairOptions<'der', 'der'>
2874
+ ): Promise<{
2875
+ publicKey: Buffer;
2876
+ privateKey: Buffer;
2877
+ }>;
2878
+ function __promisify__(type: 'x25519', options?: X25519KeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
1135
2879
  function __promisify__(
1136
2880
  type: 'x448',
1137
- options: X448KeyPairOptions<'pem', 'pem'>,
1138
- ): Promise<{ publicKey: string; privateKey: string }>;
2881
+ options: X448KeyPairOptions<'pem', 'pem'>
2882
+ ): Promise<{
2883
+ publicKey: string;
2884
+ privateKey: string;
2885
+ }>;
1139
2886
  function __promisify__(
1140
2887
  type: 'x448',
1141
- options: X448KeyPairOptions<'pem', 'der'>,
1142
- ): Promise<{ publicKey: string; privateKey: Buffer }>;
2888
+ options: X448KeyPairOptions<'pem', 'der'>
2889
+ ): Promise<{
2890
+ publicKey: string;
2891
+ privateKey: Buffer;
2892
+ }>;
1143
2893
  function __promisify__(
1144
2894
  type: 'x448',
1145
- options: X448KeyPairOptions<'der', 'pem'>,
1146
- ): Promise<{ publicKey: Buffer; privateKey: string }>;
2895
+ options: X448KeyPairOptions<'der', 'pem'>
2896
+ ): Promise<{
2897
+ publicKey: Buffer;
2898
+ privateKey: string;
2899
+ }>;
1147
2900
  function __promisify__(
1148
2901
  type: 'x448',
1149
- options: X448KeyPairOptions<'der', 'der'>,
1150
- ): Promise<{ publicKey: Buffer; privateKey: Buffer }>;
2902
+ options: X448KeyPairOptions<'der', 'der'>
2903
+ ): Promise<{
2904
+ publicKey: Buffer;
2905
+ privateKey: Buffer;
2906
+ }>;
1151
2907
  function __promisify__(type: 'x448', options?: X448KeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
1152
2908
  }
1153
-
1154
2909
  /**
1155
2910
  * Calculates and returns the signature for `data` using the given private key and
1156
2911
  * algorithm. If `algorithm` is `null` or `undefined`, then the algorithm is
1157
2912
  * dependent upon the key type (especially Ed25519 and Ed448).
1158
2913
  *
1159
- * If `key` is not a [`KeyObject`][], this function behaves as if `key` had been
1160
- * passed to [`crypto.createPrivateKey()`][].
2914
+ * If `key` is not a `KeyObject`, this function behaves as if `key` had been
2915
+ * passed to {@link createPrivateKey}. If it is an object, the following
2916
+ * additional properties can be passed:
2917
+ *
2918
+ * If the `callback` function is provided this function uses libuv's threadpool.
2919
+ * @since v12.0.0
1161
2920
  */
2921
+ function sign(algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput): Buffer;
1162
2922
  function sign(
1163
2923
  algorithm: string | null | undefined,
1164
2924
  data: NodeJS.ArrayBufferView,
1165
2925
  key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput,
1166
- ): Buffer;
1167
-
2926
+ callback: (error: Error | null, data: Buffer) => void
2927
+ ): void;
1168
2928
  /**
1169
- * Calculates and returns the signature for `data` using the given private key and
1170
- * algorithm. If `algorithm` is `null` or `undefined`, then the algorithm is
1171
- * dependent upon the key type (especially Ed25519 and Ed448).
2929
+ * Verifies the given signature for `data` using the given key and algorithm. If`algorithm` is `null` or `undefined`, then the algorithm is dependent upon the
2930
+ * key type (especially Ed25519 and Ed448).
2931
+ *
2932
+ * If `key` is not a `KeyObject`, this function behaves as if `key` had been
2933
+ * passed to {@link createPublicKey}. If it is an object, the following
2934
+ * additional properties can be passed:
2935
+ *
2936
+ * The `signature` argument is the previously calculated signature for the `data`.
2937
+ *
2938
+ * Because public keys can be derived from private keys, a private key or a public
2939
+ * key may be passed for `key`.
1172
2940
  *
1173
- * If `key` is not a [`KeyObject`][], this function behaves as if `key` had been
1174
- * passed to [`crypto.createPublicKey()`][].
2941
+ * If the `callback` function is provided this function uses libuv's threadpool.
2942
+ * @since v12.0.0
1175
2943
  */
2944
+ function verify(algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput, signature: NodeJS.ArrayBufferView): boolean;
1176
2945
  function verify(
1177
2946
  algorithm: string | null | undefined,
1178
2947
  data: NodeJS.ArrayBufferView,
1179
2948
  key: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput,
1180
2949
  signature: NodeJS.ArrayBufferView,
1181
- ): boolean;
1182
-
2950
+ callback: (error: Error | null, result: boolean) => void
2951
+ ): void;
1183
2952
  /**
1184
- * Computes the Diffie-Hellman secret based on a privateKey and a publicKey.
1185
- * Both keys must have the same asymmetricKeyType, which must be one of
1186
- * 'dh' (for Diffie-Hellman), 'ec' (for ECDH), 'x448', or 'x25519' (for ECDH-ES).
2953
+ * Computes the Diffie-Hellman secret based on a `privateKey` and a `publicKey`.
2954
+ * Both keys must have the same `asymmetricKeyType`, which must be one of `'dh'`(for Diffie-Hellman), `'ec'` (for ECDH), `'x448'`, or `'x25519'` (for ECDH-ES).
2955
+ * @since v13.9.0, v12.17.0
1187
2956
  */
1188
2957
  function diffieHellman(options: { privateKey: KeyObject; publicKey: KeyObject }): Buffer;
2958
+ type CipherMode = 'cbc' | 'ccm' | 'cfb' | 'ctr' | 'ecb' | 'gcm' | 'ocb' | 'ofb' | 'stream' | 'wrap' | 'xts';
2959
+ interface CipherInfoOptions {
2960
+ /**
2961
+ * A test key length.
2962
+ */
2963
+ keyLength?: number | undefined;
2964
+ /**
2965
+ * A test IV length.
2966
+ */
2967
+ ivLength?: number | undefined;
2968
+ }
2969
+ interface CipherInfo {
2970
+ /**
2971
+ * The name of the cipher.
2972
+ */
2973
+ name: string;
2974
+ /**
2975
+ * The nid of the cipher.
2976
+ */
2977
+ nid: number;
2978
+ /**
2979
+ * The block size of the cipher in bytes.
2980
+ * This property is omitted when mode is 'stream'.
2981
+ */
2982
+ blockSize?: number | undefined;
2983
+ /**
2984
+ * The expected or default initialization vector length in bytes.
2985
+ * This property is omitted if the cipher does not use an initialization vector.
2986
+ */
2987
+ ivLength?: number | undefined;
2988
+ /**
2989
+ * The expected or default key length in bytes.
2990
+ */
2991
+ keyLength: number;
2992
+ /**
2993
+ * The cipher mode.
2994
+ */
2995
+ mode: CipherMode;
2996
+ }
2997
+ /**
2998
+ * Returns information about a given cipher.
2999
+ *
3000
+ * Some ciphers accept variable length keys and initialization vectors. By default,
3001
+ * the `crypto.getCipherInfo()` method will return the default values for these
3002
+ * ciphers. To test if a given key length or iv length is acceptable for given
3003
+ * cipher, use the `keyLength` and `ivLength` options. If the given values are
3004
+ * unacceptable, `undefined` will be returned.
3005
+ * @since v15.0.0
3006
+ * @param nameOrNid The name or nid of the cipher to query.
3007
+ */
3008
+ function getCipherInfo(nameOrNid: string | number, options?: CipherInfoOptions): CipherInfo | undefined;
3009
+ /**
3010
+ * 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.
3011
+ *
3012
+ * The supplied `callback` function is called with two arguments: `err` and`derivedKey`. If an errors occurs while deriving the key, `err` will be set;
3013
+ * otherwise `err` will be `null`. The successfully generated `derivedKey` will
3014
+ * be passed to the callback as an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). An error will be thrown if any
3015
+ * of the input arguments specify invalid values or types.
3016
+ *
3017
+ * ```js
3018
+ * import { Buffer } from 'buffer';
3019
+ * const {
3020
+ * hkdf
3021
+ * } = await import('crypto');
3022
+ *
3023
+ * hkdf('sha512', 'key', 'salt', 'info', 64, (err, derivedKey) => {
3024
+ * if (err) throw err;
3025
+ * console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
3026
+ * });
3027
+ * ```
3028
+ * @since v15.0.0
3029
+ * @param digest The digest algorithm to use.
3030
+ * @param ikm The input keying material. It must be at least one byte in length.
3031
+ * @param salt The salt value. Must be provided but can be zero-length.
3032
+ * @param info Additional info value. Must be provided but can be zero-length, and cannot be more than 1024 bytes.
3033
+ * @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`
3034
+ * generates 64-byte hashes, making the maximum HKDF output 16320 bytes).
3035
+ */
3036
+ function hkdf(digest: string, irm: BinaryLike | KeyObject, salt: BinaryLike, info: BinaryLike, keylen: number, callback: (err: Error | null, derivedKey: ArrayBuffer) => void): void;
3037
+ /**
3038
+ * Provides a synchronous HKDF key derivation function as defined in RFC 5869\. The
3039
+ * given `ikm`, `salt` and `info` are used with the `digest` to derive a key of`keylen` bytes.
3040
+ *
3041
+ * The successfully generated `derivedKey` will be returned as an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer).
3042
+ *
3043
+ * An error will be thrown if any of the input arguments specify invalid values or
3044
+ * types, or if the derived key cannot be generated.
3045
+ *
3046
+ * ```js
3047
+ * import { Buffer } from 'buffer';
3048
+ * const {
3049
+ * hkdfSync
3050
+ * } = await import('crypto');
3051
+ *
3052
+ * const derivedKey = hkdfSync('sha512', 'key', 'salt', 'info', 64);
3053
+ * console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
3054
+ * ```
3055
+ * @since v15.0.0
3056
+ * @param digest The digest algorithm to use.
3057
+ * @param ikm The input keying material. It must be at least one byte in length.
3058
+ * @param salt The salt value. Must be provided but can be zero-length.
3059
+ * @param info Additional info value. Must be provided but can be zero-length, and cannot be more than 1024 bytes.
3060
+ * @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`
3061
+ * generates 64-byte hashes, making the maximum HKDF output 16320 bytes).
3062
+ */
3063
+ function hkdfSync(digest: string, ikm: BinaryLike | KeyObject, salt: BinaryLike, info: BinaryLike, keylen: number): ArrayBuffer;
3064
+ interface SecureHeapUsage {
3065
+ /**
3066
+ * The total allocated secure heap size as specified using the `--secure-heap=n` command-line flag.
3067
+ */
3068
+ total: number;
3069
+ /**
3070
+ * The minimum allocation from the secure heap as specified using the `--secure-heap-min` command-line flag.
3071
+ */
3072
+ min: number;
3073
+ /**
3074
+ * The total number of bytes currently allocated from the secure heap.
3075
+ */
3076
+ used: number;
3077
+ /**
3078
+ * The calculated ratio of `used` to `total` allocated bytes.
3079
+ */
3080
+ utilization: number;
3081
+ }
3082
+ /**
3083
+ * @since v15.6.0
3084
+ */
3085
+ function secureHeapUsed(): SecureHeapUsage;
3086
+ interface RandomUUIDOptions {
3087
+ /**
3088
+ * By default, to improve performance,
3089
+ * Node.js will pre-emptively generate and persistently cache enough
3090
+ * random data to generate up to 128 random UUIDs. To generate a UUID
3091
+ * without using the cache, set `disableEntropyCache` to `true`.
3092
+ *
3093
+ * @default `false`
3094
+ */
3095
+ disableEntropyCache?: boolean | undefined;
3096
+ }
3097
+ /**
3098
+ * Generates a random [RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) version 4 UUID. The UUID is generated using a
3099
+ * cryptographic pseudorandom number generator.
3100
+ * @since v15.6.0
3101
+ */
3102
+ function randomUUID(options?: RandomUUIDOptions): string;
3103
+ interface X509CheckOptions {
3104
+ /**
3105
+ * @default 'always'
3106
+ */
3107
+ subject?: 'always' | 'default' | 'never';
3108
+ /**
3109
+ * @default true
3110
+ */
3111
+ wildcards?: boolean;
3112
+ /**
3113
+ * @default true
3114
+ */
3115
+ partialWildcards?: boolean;
3116
+ /**
3117
+ * @default false
3118
+ */
3119
+ multiLabelWildcards?: boolean;
3120
+ /**
3121
+ * @default false
3122
+ */
3123
+ singleLabelSubdomains?: boolean;
3124
+ }
3125
+ /**
3126
+ * Encapsulates an X509 certificate and provides read-only access to
3127
+ * its information.
3128
+ *
3129
+ * ```js
3130
+ * const { X509Certificate } = await import('crypto');
3131
+ *
3132
+ * const x509 = new X509Certificate('{... pem encoded cert ...}');
3133
+ *
3134
+ * console.log(x509.subject);
3135
+ * ```
3136
+ * @since v15.6.0
3137
+ */
3138
+ class X509Certificate {
3139
+ /**
3140
+ * Will be \`true\` if this is a Certificate Authority (ca) certificate.
3141
+ * @since v15.6.0
3142
+ */
3143
+ readonly ca: boolean;
3144
+ /**
3145
+ * The SHA-1 fingerprint of this certificate.
3146
+ * @since v15.6.0
3147
+ */
3148
+ readonly fingerprint: string;
3149
+ /**
3150
+ * The SHA-256 fingerprint of this certificate.
3151
+ * @since v15.6.0
3152
+ */
3153
+ readonly fingerprint256: string;
3154
+ /**
3155
+ * The SHA-512 fingerprint of this certificate.
3156
+ * @since v16.14.0
3157
+ */
3158
+ readonly fingerprint512: string;
3159
+ /**
3160
+ * The complete subject of this certificate.
3161
+ * @since v15.6.0
3162
+ */
3163
+ readonly subject: string;
3164
+ /**
3165
+ * The subject alternative name specified for this certificate or `undefined`
3166
+ * if not available.
3167
+ * @since v15.6.0
3168
+ */
3169
+ readonly subjectAltName: string | undefined;
3170
+ /**
3171
+ * The information access content of this certificate or `undefined` if not
3172
+ * available.
3173
+ * @since v15.6.0
3174
+ */
3175
+ readonly infoAccess: string | undefined;
3176
+ /**
3177
+ * An array detailing the key usages for this certificate.
3178
+ * @since v15.6.0
3179
+ */
3180
+ readonly keyUsage: string[];
3181
+ /**
3182
+ * The issuer identification included in this certificate.
3183
+ * @since v15.6.0
3184
+ */
3185
+ readonly issuer: string;
3186
+ /**
3187
+ * The issuer certificate or `undefined` if the issuer certificate is not
3188
+ * available.
3189
+ * @since v15.9.0
3190
+ */
3191
+ readonly issuerCertificate?: X509Certificate | undefined;
3192
+ /**
3193
+ * The public key `KeyObject` for this certificate.
3194
+ * @since v15.6.0
3195
+ */
3196
+ readonly publicKey: KeyObject;
3197
+ /**
3198
+ * A `Buffer` containing the DER encoding of this certificate.
3199
+ * @since v15.6.0
3200
+ */
3201
+ readonly raw: Buffer;
3202
+ /**
3203
+ * The serial number of this certificate.
3204
+ * @since v15.6.0
3205
+ */
3206
+ readonly serialNumber: string;
3207
+ /**
3208
+ * The date/time from which this certificate is considered valid.
3209
+ * @since v15.6.0
3210
+ */
3211
+ readonly validFrom: string;
3212
+ /**
3213
+ * The date/time until which this certificate is considered valid.
3214
+ * @since v15.6.0
3215
+ */
3216
+ readonly validTo: string;
3217
+ constructor(buffer: BinaryLike);
3218
+ /**
3219
+ * Checks whether the certificate matches the given email address.
3220
+ * @since v15.6.0
3221
+ * @return Returns `email` if the certificate matches, `undefined` if it does not.
3222
+ */
3223
+ checkEmail(email: string, options?: Pick<X509CheckOptions, 'subject'>): string | undefined;
3224
+ /**
3225
+ * Checks whether the certificate matches the given host name.
3226
+ * @since v15.6.0
3227
+ * @return Returns `name` if the certificate matches, `undefined` if it does not.
3228
+ */
3229
+ checkHost(name: string, options?: X509CheckOptions): string | undefined;
3230
+ /**
3231
+ * Checks whether the certificate matches the given IP address (IPv4 or IPv6).
3232
+ * @since v15.6.0
3233
+ * @return Returns `ip` if the certificate matches, `undefined` if it does not.
3234
+ */
3235
+ checkIP(ip: string): string | undefined;
3236
+ /**
3237
+ * Checks whether this certificate was issued by the given `otherCert`.
3238
+ * @since v15.6.0
3239
+ */
3240
+ checkIssued(otherCert: X509Certificate): boolean;
3241
+ /**
3242
+ * Checks whether the public key for this certificate is consistent with
3243
+ * the given private key.
3244
+ * @since v15.6.0
3245
+ * @param privateKey A private key.
3246
+ */
3247
+ checkPrivateKey(privateKey: KeyObject): boolean;
3248
+ /**
3249
+ * There is no standard JSON encoding for X509 certificates. The`toJSON()` method returns a string containing the PEM encoded
3250
+ * certificate.
3251
+ * @since v15.6.0
3252
+ */
3253
+ toJSON(): string;
3254
+ /**
3255
+ * Returns information about this certificate using the legacy `certificate object` encoding.
3256
+ * @since v15.6.0
3257
+ */
3258
+ toLegacyObject(): PeerCertificate;
3259
+ /**
3260
+ * Returns the PEM-encoded certificate.
3261
+ * @since v15.6.0
3262
+ */
3263
+ toString(): string;
3264
+ /**
3265
+ * Verifies that this certificate was signed by the given public key.
3266
+ * Does not perform any other validation checks on the certificate.
3267
+ * @since v15.6.0
3268
+ * @param publicKey A public key.
3269
+ */
3270
+ verify(publicKey: KeyObject): boolean;
3271
+ }
3272
+ type LargeNumberLike = NodeJS.ArrayBufferView | SharedArrayBuffer | ArrayBuffer | bigint;
3273
+ interface GeneratePrimeOptions {
3274
+ add?: LargeNumberLike | undefined;
3275
+ rem?: LargeNumberLike | undefined;
3276
+ /**
3277
+ * @default false
3278
+ */
3279
+ safe?: boolean | undefined;
3280
+ bigint?: boolean | undefined;
3281
+ }
3282
+ interface GeneratePrimeOptionsBigInt extends GeneratePrimeOptions {
3283
+ bigint: true;
3284
+ }
3285
+ interface GeneratePrimeOptionsArrayBuffer extends GeneratePrimeOptions {
3286
+ bigint?: false | undefined;
3287
+ }
3288
+ /**
3289
+ * Generates a pseudorandom prime of `size` bits.
3290
+ *
3291
+ * If `options.safe` is `true`, the prime will be a safe prime -- that is,`(prime - 1) / 2` will also be a prime.
3292
+ *
3293
+ * The `options.add` and `options.rem` parameters can be used to enforce additional
3294
+ * requirements, e.g., for Diffie-Hellman:
3295
+ *
3296
+ * * If `options.add` and `options.rem` are both set, the prime will satisfy the
3297
+ * condition that `prime % add = rem`.
3298
+ * * If only `options.add` is set and `options.safe` is not `true`, the prime will
3299
+ * satisfy the condition that `prime % add = 1`.
3300
+ * * If only `options.add` is set and `options.safe` is set to `true`, the prime
3301
+ * will instead satisfy the condition that `prime % add = 3`. This is necessary
3302
+ * because `prime % add = 1` for `options.add > 2` would contradict the condition
3303
+ * enforced by `options.safe`.
3304
+ * * `options.rem` is ignored if `options.add` is not given.
3305
+ *
3306
+ * Both `options.add` and `options.rem` must be encoded as big-endian sequences
3307
+ * if given as an `ArrayBuffer`, `SharedArrayBuffer`, `TypedArray`, `Buffer`, or`DataView`.
3308
+ *
3309
+ * By default, the prime is encoded as a big-endian sequence of octets
3310
+ * in an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). If the `bigint` option is `true`, then a
3311
+ * [bigint](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) is provided.
3312
+ * @since v15.8.0
3313
+ * @param size The size (in bits) of the prime to generate.
3314
+ */
3315
+ function generatePrime(size: number, callback: (err: Error | null, prime: ArrayBuffer) => void): void;
3316
+ function generatePrime(size: number, options: GeneratePrimeOptionsBigInt, callback: (err: Error | null, prime: bigint) => void): void;
3317
+ function generatePrime(size: number, options: GeneratePrimeOptionsArrayBuffer, callback: (err: Error | null, prime: ArrayBuffer) => void): void;
3318
+ function generatePrime(size: number, options: GeneratePrimeOptions, callback: (err: Error | null, prime: ArrayBuffer | bigint) => void): void;
3319
+ /**
3320
+ * Generates a pseudorandom prime of `size` bits.
3321
+ *
3322
+ * If `options.safe` is `true`, the prime will be a safe prime -- that is,`(prime - 1) / 2` will also be a prime.
3323
+ *
3324
+ * The `options.add` and `options.rem` parameters can be used to enforce additional
3325
+ * requirements, e.g., for Diffie-Hellman:
3326
+ *
3327
+ * * If `options.add` and `options.rem` are both set, the prime will satisfy the
3328
+ * condition that `prime % add = rem`.
3329
+ * * If only `options.add` is set and `options.safe` is not `true`, the prime will
3330
+ * satisfy the condition that `prime % add = 1`.
3331
+ * * If only `options.add` is set and `options.safe` is set to `true`, the prime
3332
+ * will instead satisfy the condition that `prime % add = 3`. This is necessary
3333
+ * because `prime % add = 1` for `options.add > 2` would contradict the condition
3334
+ * enforced by `options.safe`.
3335
+ * * `options.rem` is ignored if `options.add` is not given.
3336
+ *
3337
+ * Both `options.add` and `options.rem` must be encoded as big-endian sequences
3338
+ * if given as an `ArrayBuffer`, `SharedArrayBuffer`, `TypedArray`, `Buffer`, or`DataView`.
3339
+ *
3340
+ * By default, the prime is encoded as a big-endian sequence of octets
3341
+ * in an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). If the `bigint` option is `true`, then a
3342
+ * [bigint](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) is provided.
3343
+ * @since v15.8.0
3344
+ * @param size The size (in bits) of the prime to generate.
3345
+ */
3346
+ function generatePrimeSync(size: number): ArrayBuffer;
3347
+ function generatePrimeSync(size: number, options: GeneratePrimeOptionsBigInt): bigint;
3348
+ function generatePrimeSync(size: number, options: GeneratePrimeOptionsArrayBuffer): ArrayBuffer;
3349
+ function generatePrimeSync(size: number, options: GeneratePrimeOptions): ArrayBuffer | bigint;
3350
+ interface CheckPrimeOptions {
3351
+ /**
3352
+ * The number of Miller-Rabin probabilistic primality iterations to perform.
3353
+ * When the value is 0 (zero), a number of checks is used that yields a false positive rate of at most `2**-64` for random input.
3354
+ * Care must be used when selecting a number of checks.
3355
+ * Refer to the OpenSSL documentation for the BN_is_prime_ex function nchecks options for more details.
3356
+ *
3357
+ * @default 0
3358
+ */
3359
+ checks?: number | undefined;
3360
+ }
3361
+ /**
3362
+ * Checks the primality of the `candidate`.
3363
+ * @since v15.8.0
3364
+ * @param candidate A possible prime encoded as a sequence of big endian octets of arbitrary length.
3365
+ */
3366
+ function checkPrime(value: LargeNumberLike, callback: (err: Error | null, result: boolean) => void): void;
3367
+ function checkPrime(value: LargeNumberLike, options: CheckPrimeOptions, callback: (err: Error | null, result: boolean) => void): void;
3368
+ /**
3369
+ * Checks the primality of the `candidate`.
3370
+ * @since v15.8.0
3371
+ * @param candidate A possible prime encoded as a sequence of big endian octets of arbitrary length.
3372
+ * @return `true` if the candidate is a prime with an error probability less than `0.25 ** options.checks`.
3373
+ */
3374
+ function checkPrimeSync(candidate: LargeNumberLike, options?: CheckPrimeOptions): boolean;
3375
+ /**
3376
+ * Load and set the `engine` for some or all OpenSSL functions (selected by flags).
3377
+ *
3378
+ * `engine` could be either an id or a path to the engine's shared library.
3379
+ *
3380
+ * The optional `flags` argument uses `ENGINE_METHOD_ALL` by default.
3381
+ * The `flags` is a bit field taking one of or a mix of the following flags (defined in `crypto.constants`):
3382
+ *
3383
+ * - `crypto.constants.ENGINE_METHOD_RSA`
3384
+ * - `crypto.constants.ENGINE_METHOD_DSA`
3385
+ * - `crypto.constants.ENGINE_METHOD_DH`
3386
+ * - `crypto.constants.ENGINE_METHOD_RAND`
3387
+ * - `crypto.constants.ENGINE_METHOD_EC`
3388
+ * - `crypto.constants.ENGINE_METHOD_CIPHERS`
3389
+ * - `crypto.constants.ENGINE_METHOD_DIGESTS`
3390
+ * - `crypto.constants.ENGINE_METHOD_PKEY_METHS`
3391
+ * - `crypto.constants.ENGINE_METHOD_PKEY_ASN1_METHS`
3392
+ * - `crypto.constants.ENGINE_METHOD_ALL`
3393
+ * - `crypto.constants.ENGINE_METHOD_NONE`
3394
+ *
3395
+ * The flags below are deprecated in OpenSSL-1.1.0.
3396
+ *
3397
+ * - `crypto.constants.ENGINE_METHOD_ECDH`
3398
+ * - `crypto.constants.ENGINE_METHOD_ECDSA`
3399
+ * - `crypto.constants.ENGINE_METHOD_STORE`
3400
+ * @since v0.11.11
3401
+ * @param [flags=crypto.constants.ENGINE_METHOD_ALL]
3402
+ */
3403
+ function setEngine(engine: string, flags?: number): void;
3404
+ /**
3405
+ * An implementation of the Web Crypto API standard.
3406
+ *
3407
+ * See the {@link https://nodejs.org/docs/latest/api/webcrypto.html Web Crypto API documentation} for details.
3408
+ * @since v15.0.0
3409
+ */
3410
+ const webcrypto: webcrypto.Crypto;
3411
+ namespace webcrypto {
3412
+ type BufferSource = ArrayBufferView | ArrayBuffer;
3413
+ type KeyFormat = 'jwk' | 'pkcs8' | 'raw' | 'spki';
3414
+ type KeyType = 'private' | 'public' | 'secret';
3415
+ type KeyUsage = 'decrypt' | 'deriveBits' | 'deriveKey' | 'encrypt' | 'sign' | 'unwrapKey' | 'verify' | 'wrapKey';
3416
+ type AlgorithmIdentifier = Algorithm | string;
3417
+ type HashAlgorithmIdentifier = AlgorithmIdentifier;
3418
+ type NamedCurve = string;
3419
+ type BigInteger = Uint8Array;
3420
+ interface AesCbcParams extends Algorithm {
3421
+ iv: BufferSource;
3422
+ }
3423
+ interface AesCtrParams extends Algorithm {
3424
+ counter: BufferSource;
3425
+ length: number;
3426
+ }
3427
+ interface AesDerivedKeyParams extends Algorithm {
3428
+ length: number;
3429
+ }
3430
+ interface AesGcmParams extends Algorithm {
3431
+ additionalData?: BufferSource;
3432
+ iv: BufferSource;
3433
+ tagLength?: number;
3434
+ }
3435
+ interface AesKeyAlgorithm extends KeyAlgorithm {
3436
+ length: number;
3437
+ }
3438
+ interface AesKeyGenParams extends Algorithm {
3439
+ length: number;
3440
+ }
3441
+ interface Algorithm {
3442
+ name: string;
3443
+ }
3444
+ interface EcKeyAlgorithm extends KeyAlgorithm {
3445
+ namedCurve: NamedCurve;
3446
+ }
3447
+ interface EcKeyGenParams extends Algorithm {
3448
+ namedCurve: NamedCurve;
3449
+ }
3450
+ interface EcKeyImportParams extends Algorithm {
3451
+ namedCurve: NamedCurve;
3452
+ }
3453
+ interface EcdhKeyDeriveParams extends Algorithm {
3454
+ public: CryptoKey;
3455
+ }
3456
+ interface EcdsaParams extends Algorithm {
3457
+ hash: HashAlgorithmIdentifier;
3458
+ }
3459
+ interface Ed448Params extends Algorithm {
3460
+ context?: BufferSource;
3461
+ }
3462
+ interface HkdfParams extends Algorithm {
3463
+ hash: HashAlgorithmIdentifier;
3464
+ info: BufferSource;
3465
+ salt: BufferSource;
3466
+ }
3467
+ interface HmacImportParams extends Algorithm {
3468
+ hash: HashAlgorithmIdentifier;
3469
+ length?: number;
3470
+ }
3471
+ interface HmacKeyAlgorithm extends KeyAlgorithm {
3472
+ hash: KeyAlgorithm;
3473
+ length: number;
3474
+ }
3475
+ interface HmacKeyGenParams extends Algorithm {
3476
+ hash: HashAlgorithmIdentifier;
3477
+ length?: number;
3478
+ }
3479
+ interface JsonWebKey {
3480
+ alg?: string;
3481
+ crv?: string;
3482
+ d?: string;
3483
+ dp?: string;
3484
+ dq?: string;
3485
+ e?: string;
3486
+ ext?: boolean;
3487
+ k?: string;
3488
+ key_ops?: string[];
3489
+ kty?: string;
3490
+ n?: string;
3491
+ oth?: RsaOtherPrimesInfo[];
3492
+ p?: string;
3493
+ q?: string;
3494
+ qi?: string;
3495
+ use?: string;
3496
+ x?: string;
3497
+ y?: string;
3498
+ }
3499
+ interface KeyAlgorithm {
3500
+ name: string;
3501
+ }
3502
+ interface Pbkdf2Params extends Algorithm {
3503
+ hash: HashAlgorithmIdentifier;
3504
+ iterations: number;
3505
+ salt: BufferSource;
3506
+ }
3507
+ interface RsaHashedImportParams extends Algorithm {
3508
+ hash: HashAlgorithmIdentifier;
3509
+ }
3510
+ interface RsaHashedKeyAlgorithm extends RsaKeyAlgorithm {
3511
+ hash: KeyAlgorithm;
3512
+ }
3513
+ interface RsaHashedKeyGenParams extends RsaKeyGenParams {
3514
+ hash: HashAlgorithmIdentifier;
3515
+ }
3516
+ interface RsaKeyAlgorithm extends KeyAlgorithm {
3517
+ modulusLength: number;
3518
+ publicExponent: BigInteger;
3519
+ }
3520
+ interface RsaKeyGenParams extends Algorithm {
3521
+ modulusLength: number;
3522
+ publicExponent: BigInteger;
3523
+ }
3524
+ interface RsaOaepParams extends Algorithm {
3525
+ label?: BufferSource;
3526
+ }
3527
+ interface RsaOtherPrimesInfo {
3528
+ d?: string;
3529
+ r?: string;
3530
+ t?: string;
3531
+ }
3532
+ interface RsaPssParams extends Algorithm {
3533
+ saltLength: number;
3534
+ }
3535
+ /**
3536
+ * Calling `require('node:crypto').webcrypto` returns an instance of the `Crypto` class.
3537
+ * `Crypto` is a singleton that provides access to the remainder of the crypto API.
3538
+ * @since v15.0.0
3539
+ */
3540
+ interface Crypto {
3541
+ /**
3542
+ * Provides access to the `SubtleCrypto` API.
3543
+ * @since v15.0.0
3544
+ */
3545
+ readonly subtle: SubtleCrypto;
3546
+ /**
3547
+ * Generates cryptographically strong random values.
3548
+ * The given `typedArray` is filled with random values, and a reference to `typedArray` is returned.
3549
+ *
3550
+ * The given `typedArray` must be an integer-based instance of {@link NodeJS.TypedArray}, i.e. `Float32Array` and `Float64Array` are not accepted.
3551
+ *
3552
+ * An error will be thrown if the given `typedArray` is larger than 65,536 bytes.
3553
+ * @since v15.0.0
3554
+ */
3555
+ getRandomValues<T extends Exclude<NodeJS.TypedArray, Float32Array | Float64Array>>(typedArray: T): T;
3556
+ /**
3557
+ * Generates a random {@link https://www.rfc-editor.org/rfc/rfc4122.txt RFC 4122} version 4 UUID.
3558
+ * The UUID is generated using a cryptographic pseudorandom number generator.
3559
+ * @since v16.7.0
3560
+ */
3561
+ randomUUID(): string;
3562
+ CryptoKey: CryptoKeyConstructor;
3563
+ }
3564
+ // This constructor throws ILLEGAL_CONSTRUCTOR so it should not be newable.
3565
+ interface CryptoKeyConstructor {
3566
+ /** Illegal constructor */
3567
+ (_: { readonly _: unique symbol }): never; // Allows instanceof to work but not be callable by the user.
3568
+ readonly length: 0;
3569
+ readonly name: 'CryptoKey';
3570
+ readonly prototype: CryptoKey;
3571
+ }
3572
+ /**
3573
+ * @since v15.0.0
3574
+ */
3575
+ interface CryptoKey {
3576
+ /**
3577
+ * An object detailing the algorithm for which the key can be used along with additional algorithm-specific parameters.
3578
+ * @since v15.0.0
3579
+ */
3580
+ readonly algorithm: KeyAlgorithm;
3581
+ /**
3582
+ * When `true`, the {@link CryptoKey} can be extracted using either `subtleCrypto.exportKey()` or `subtleCrypto.wrapKey()`.
3583
+ * @since v15.0.0
3584
+ */
3585
+ readonly extractable: boolean;
3586
+ /**
3587
+ * A string identifying whether the key is a symmetric (`'secret'`) or asymmetric (`'private'` or `'public'`) key.
3588
+ * @since v15.0.0
3589
+ */
3590
+ readonly type: KeyType;
3591
+ /**
3592
+ * An array of strings identifying the operations for which the key may be used.
3593
+ *
3594
+ * The possible usages are:
3595
+ * - `'encrypt'` - The key may be used to encrypt data.
3596
+ * - `'decrypt'` - The key may be used to decrypt data.
3597
+ * - `'sign'` - The key may be used to generate digital signatures.
3598
+ * - `'verify'` - The key may be used to verify digital signatures.
3599
+ * - `'deriveKey'` - The key may be used to derive a new key.
3600
+ * - `'deriveBits'` - The key may be used to derive bits.
3601
+ * - `'wrapKey'` - The key may be used to wrap another key.
3602
+ * - `'unwrapKey'` - The key may be used to unwrap another key.
3603
+ *
3604
+ * Valid key usages depend on the key algorithm (identified by `cryptokey.algorithm.name`).
3605
+ * @since v15.0.0
3606
+ */
3607
+ readonly usages: KeyUsage[];
3608
+ }
3609
+ /**
3610
+ * The `CryptoKeyPair` is a simple dictionary object with `publicKey` and `privateKey` properties, representing an asymmetric key pair.
3611
+ * @since v15.0.0
3612
+ */
3613
+ interface CryptoKeyPair {
3614
+ /**
3615
+ * A {@link CryptoKey} whose type will be `'private'`.
3616
+ * @since v15.0.0
3617
+ */
3618
+ privateKey: CryptoKey;
3619
+ /**
3620
+ * A {@link CryptoKey} whose type will be `'public'`.
3621
+ * @since v15.0.0
3622
+ */
3623
+ publicKey: CryptoKey;
3624
+ }
3625
+ /**
3626
+ * @since v15.0.0
3627
+ */
3628
+ interface SubtleCrypto {
3629
+ /**
3630
+ * Using the method and parameters specified in `algorithm` and the keying material provided by `key`,
3631
+ * `subtle.decrypt()` attempts to decipher the provided `data`. If successful,
3632
+ * the returned promise will be resolved with an `<ArrayBuffer>` containing the plaintext result.
3633
+ *
3634
+ * The algorithms currently supported include:
3635
+ *
3636
+ * - `'RSA-OAEP'`
3637
+ * - `'AES-CTR'`
3638
+ * - `'AES-CBC'`
3639
+ * - `'AES-GCM'`
3640
+ * @since v15.0.0
3641
+ */
3642
+ decrypt(algorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
3643
+ /**
3644
+ * Using the method and parameters specified in `algorithm` and the keying material provided by `baseKey`,
3645
+ * `subtle.deriveBits()` attempts to generate `length` bits.
3646
+ * The Node.js implementation requires that `length` is a multiple of `8`.
3647
+ * If successful, the returned promise will be resolved with an `<ArrayBuffer>` containing the generated data.
3648
+ *
3649
+ * The algorithms currently supported include:
3650
+ *
3651
+ * - `'ECDH'`
3652
+ * - `'HKDF'`
3653
+ * - `'PBKDF2'`
3654
+ * @since v15.0.0
3655
+ */
3656
+ deriveBits(algorithm: AlgorithmIdentifier | EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params, baseKey: CryptoKey, length: number): Promise<ArrayBuffer>;
3657
+ /**
3658
+ * Using the method and parameters specified in `algorithm`, and the keying material provided by `baseKey`,
3659
+ * `subtle.deriveKey()` attempts to generate a new <CryptoKey>` based on the method and parameters in `derivedKeyAlgorithm`.
3660
+ *
3661
+ * Calling `subtle.deriveKey()` is equivalent to calling `subtle.deriveBits()` to generate raw keying material,
3662
+ * then passing the result into the `subtle.importKey()` method using the `deriveKeyAlgorithm`, `extractable`, and `keyUsages` parameters as input.
3663
+ *
3664
+ * The algorithms currently supported include:
3665
+ *
3666
+ * - `'ECDH'`
3667
+ * - `'HKDF'`
3668
+ * - `'PBKDF2'`
3669
+ * @param keyUsages See {@link https://nodejs.org/docs/latest/api/webcrypto.html#cryptokeyusages Key usages}.
3670
+ * @since v15.0.0
3671
+ */
3672
+ deriveKey(
3673
+ algorithm: AlgorithmIdentifier | EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params,
3674
+ baseKey: CryptoKey,
3675
+ derivedKeyAlgorithm: AlgorithmIdentifier | AesDerivedKeyParams | HmacImportParams | HkdfParams | Pbkdf2Params,
3676
+ extractable: boolean,
3677
+ keyUsages: ReadonlyArray<KeyUsage>
3678
+ ): Promise<CryptoKey>;
3679
+ /**
3680
+ * Using the method identified by `algorithm`, `subtle.digest()` attempts to generate a digest of `data`.
3681
+ * If successful, the returned promise is resolved with an `<ArrayBuffer>` containing the computed digest.
3682
+ *
3683
+ * If `algorithm` is provided as a `<string>`, it must be one of:
3684
+ *
3685
+ * - `'SHA-1'`
3686
+ * - `'SHA-256'`
3687
+ * - `'SHA-384'`
3688
+ * - `'SHA-512'`
3689
+ *
3690
+ * If `algorithm` is provided as an `<Object>`, it must have a `name` property whose value is one of the above.
3691
+ * @since v15.0.0
3692
+ */
3693
+ digest(algorithm: AlgorithmIdentifier, data: BufferSource): Promise<ArrayBuffer>;
3694
+ /**
3695
+ * Using the method and parameters specified by `algorithm` and the keying material provided by `key`,
3696
+ * `subtle.encrypt()` attempts to encipher `data`. If successful,
3697
+ * the returned promise is resolved with an `<ArrayBuffer>` containing the encrypted result.
3698
+ *
3699
+ * The algorithms currently supported include:
3700
+ *
3701
+ * - `'RSA-OAEP'`
3702
+ * - `'AES-CTR'`
3703
+ * - `'AES-CBC'`
3704
+ * - `'AES-GCM'`
3705
+ * @since v15.0.0
3706
+ */
3707
+ encrypt(algorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
3708
+ /**
3709
+ * Exports the given key into the specified format, if supported.
3710
+ *
3711
+ * If the `<CryptoKey>` is not extractable, the returned promise will reject.
3712
+ *
3713
+ * When `format` is either `'pkcs8'` or `'spki'` and the export is successful,
3714
+ * the returned promise will be resolved with an `<ArrayBuffer>` containing the exported key data.
3715
+ *
3716
+ * When `format` is `'jwk'` and the export is successful, the returned promise will be resolved with a
3717
+ * JavaScript object conforming to the {@link https://tools.ietf.org/html/rfc7517 JSON Web Key} specification.
3718
+ * @param format Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
3719
+ * @returns `<Promise>` containing `<ArrayBuffer>`.
3720
+ * @since v15.0.0
3721
+ */
3722
+ exportKey(format: 'jwk', key: CryptoKey): Promise<JsonWebKey>;
3723
+ exportKey(format: Exclude<KeyFormat, 'jwk'>, key: CryptoKey): Promise<ArrayBuffer>;
3724
+ /**
3725
+ * Using the method and parameters provided in `algorithm`,
3726
+ * `subtle.generateKey()` attempts to generate new keying material.
3727
+ * Depending the method used, the method may generate either a single `<CryptoKey>` or a `<CryptoKeyPair>`.
3728
+ *
3729
+ * The `<CryptoKeyPair>` (public and private key) generating algorithms supported include:
3730
+ *
3731
+ * - `'RSASSA-PKCS1-v1_5'`
3732
+ * - `'RSA-PSS'`
3733
+ * - `'RSA-OAEP'`
3734
+ * - `'ECDSA'`
3735
+ * - `'ECDH'`
3736
+ * The `<CryptoKey>` (secret key) generating algorithms supported include:
3737
+ *
3738
+ * - `'HMAC'`
3739
+ * - `'AES-CTR'`
3740
+ * - `'AES-CBC'`
3741
+ * - `'AES-GCM'`
3742
+ * - `'AES-KW'`
3743
+ * @param keyUsages See {@link https://nodejs.org/docs/latest/api/webcrypto.html#cryptokeyusages Key usages}.
3744
+ * @since v15.0.0
3745
+ */
3746
+ generateKey(algorithm: RsaHashedKeyGenParams | EcKeyGenParams, extractable: boolean, keyUsages: ReadonlyArray<KeyUsage>): Promise<CryptoKeyPair>;
3747
+ generateKey(algorithm: AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params, extractable: boolean, keyUsages: ReadonlyArray<KeyUsage>): Promise<CryptoKey>;
3748
+ generateKey(algorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair | CryptoKey>;
3749
+ /**
3750
+ * The `subtle.importKey()` method attempts to interpret the provided `keyData` as the given `format`
3751
+ * to create a `<CryptoKey>` instance using the provided `algorithm`, `extractable`, and `keyUsages` arguments.
3752
+ * If the import is successful, the returned promise will be resolved with the created `<CryptoKey>`.
3753
+ *
3754
+ * If importing a `'PBKDF2'` key, `extractable` must be `false`.
3755
+ * @param format Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
3756
+ * @param keyUsages See {@link https://nodejs.org/docs/latest/api/webcrypto.html#cryptokeyusages Key usages}.
3757
+ * @since v15.0.0
3758
+ */
3759
+ importKey(
3760
+ format: 'jwk',
3761
+ keyData: JsonWebKey,
3762
+ algorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm,
3763
+ extractable: boolean,
3764
+ keyUsages: ReadonlyArray<KeyUsage>
3765
+ ): Promise<CryptoKey>;
3766
+ importKey(
3767
+ format: Exclude<KeyFormat, 'jwk'>,
3768
+ keyData: BufferSource,
3769
+ algorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm,
3770
+ extractable: boolean,
3771
+ keyUsages: KeyUsage[]
3772
+ ): Promise<CryptoKey>;
3773
+ /**
3774
+ * Using the method and parameters given by `algorithm` and the keying material provided by `key`,
3775
+ * `subtle.sign()` attempts to generate a cryptographic signature of `data`. If successful,
3776
+ * the returned promise is resolved with an `<ArrayBuffer>` containing the generated signature.
3777
+ *
3778
+ * The algorithms currently supported include:
3779
+ *
3780
+ * - `'RSASSA-PKCS1-v1_5'`
3781
+ * - `'RSA-PSS'`
3782
+ * - `'ECDSA'`
3783
+ * - `'HMAC'`
3784
+ * @since v15.0.0
3785
+ */
3786
+ sign(algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams | Ed448Params, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>;
3787
+ /**
3788
+ * In cryptography, "wrapping a key" refers to exporting and then encrypting the keying material.
3789
+ * The `subtle.unwrapKey()` method attempts to decrypt a wrapped key and create a `<CryptoKey>` instance.
3790
+ * It is equivalent to calling `subtle.decrypt()` first on the encrypted key data (using the `wrappedKey`, `unwrapAlgo`, and `unwrappingKey` arguments as input)
3791
+ * then passing the results in to the `subtle.importKey()` method using the `unwrappedKeyAlgo`, `extractable`, and `keyUsages` arguments as inputs.
3792
+ * If successful, the returned promise is resolved with a `<CryptoKey>` object.
3793
+ *
3794
+ * The wrapping algorithms currently supported include:
3795
+ *
3796
+ * - `'RSA-OAEP'`
3797
+ * - `'AES-CTR'`
3798
+ * - `'AES-CBC'`
3799
+ * - `'AES-GCM'`
3800
+ * - `'AES-KW'`
3801
+ *
3802
+ * The unwrapped key algorithms supported include:
3803
+ *
3804
+ * - `'RSASSA-PKCS1-v1_5'`
3805
+ * - `'RSA-PSS'`
3806
+ * - `'RSA-OAEP'`
3807
+ * - `'ECDSA'`
3808
+ * - `'ECDH'`
3809
+ * - `'HMAC'`
3810
+ * - `'AES-CTR'`
3811
+ * - `'AES-CBC'`
3812
+ * - `'AES-GCM'`
3813
+ * - `'AES-KW'`
3814
+ * @param format Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
3815
+ * @param keyUsages See {@link https://nodejs.org/docs/latest/api/webcrypto.html#cryptokeyusages Key usages}.
3816
+ * @since v15.0.0
3817
+ */
3818
+ unwrapKey(
3819
+ format: KeyFormat,
3820
+ wrappedKey: BufferSource,
3821
+ unwrappingKey: CryptoKey,
3822
+ unwrapAlgorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams,
3823
+ unwrappedKeyAlgorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm,
3824
+ extractable: boolean,
3825
+ keyUsages: KeyUsage[]
3826
+ ): Promise<CryptoKey>;
3827
+ /**
3828
+ * Using the method and parameters given in `algorithm` and the keying material provided by `key`,
3829
+ * `subtle.verify()` attempts to verify that `signature` is a valid cryptographic signature of `data`.
3830
+ * The returned promise is resolved with either `true` or `false`.
3831
+ *
3832
+ * The algorithms currently supported include:
3833
+ *
3834
+ * - `'RSASSA-PKCS1-v1_5'`
3835
+ * - `'RSA-PSS'`
3836
+ * - `'ECDSA'`
3837
+ * - `'HMAC'`
3838
+ * @since v15.0.0
3839
+ */
3840
+ verify(algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams | Ed448Params, key: CryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>;
3841
+ /**
3842
+ * In cryptography, "wrapping a key" refers to exporting and then encrypting the keying material.
3843
+ * The `subtle.wrapKey()` method exports the keying material into the format identified by `format`,
3844
+ * then encrypts it using the method and parameters specified by `wrapAlgo` and the keying material provided by `wrappingKey`.
3845
+ * It is the equivalent to calling `subtle.exportKey()` using `format` and `key` as the arguments,
3846
+ * then passing the result to the `subtle.encrypt()` method using `wrappingKey` and `wrapAlgo` as inputs.
3847
+ * If successful, the returned promise will be resolved with an `<ArrayBuffer>` containing the encrypted key data.
3848
+ *
3849
+ * The wrapping algorithms currently supported include:
3850
+ *
3851
+ * - `'RSA-OAEP'`
3852
+ * - `'AES-CTR'`
3853
+ * - `'AES-CBC'`
3854
+ * - `'AES-GCM'`
3855
+ * - `'AES-KW'`
3856
+ * @param format Must be one of `'raw'`, `'pkcs8'`, `'spki'`, or `'jwk'`.
3857
+ * @since v15.0.0
3858
+ */
3859
+ wrapKey(format: KeyFormat, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams): Promise<ArrayBuffer>;
3860
+ }
3861
+ }
1189
3862
  }
1190
3863
  declare module 'node:crypto' {
1191
3864
  export * from 'crypto';