@idlebox/stripe-node-types 24.0.14-patch.0

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