From 9ddc0d43f44fecf31c984535afc56c23136c4a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Thu, 16 Oct 2025 12:52:11 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#73874=20node:?= =?UTF-8?q?=20v24.8=20by=20@Renegade334?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/node/crypto.d.ts | 381 ++++++++++++++++++++++++++-- types/node/diagnostics_channel.d.ts | 2 - types/node/http2.d.ts | 170 +++++++++++-- types/node/package.json | 2 +- types/node/sea.d.ts | 9 + types/node/stream.d.ts | 10 +- types/node/test/crypto.ts | 47 ++++ types/node/test/http2.ts | 20 +- types/node/test/sea.ts | 5 +- types/node/test/stream.ts | 7 +- types/node/test/vm.ts | 58 ++++- types/node/test/worker_threads.ts | 3 + types/node/v8.d.ts | 16 ++ types/node/vm.d.ts | 166 +++++++++--- types/node/worker_threads.d.ts | 40 ++- 15 files changed, 830 insertions(+), 106 deletions(-) diff --git a/types/node/crypto.d.ts b/types/node/crypto.d.ts index 237368ad376a34..d7c605b98c0f16 100644 --- a/types/node/crypto.d.ts +++ b/types/node/crypto.d.ts @@ -1310,6 +1310,7 @@ declare module "crypto" { * @since v0.1.92 * @param options `stream.Writable` options */ + // TODO: signing algorithm type function createSign(algorithm: string, options?: stream.WritableOptions): Sign; type DSAEncoding = "der" | "ieee-p1363"; interface SigningOptions { @@ -1319,6 +1320,7 @@ declare module "crypto" { padding?: number | undefined; saltLength?: number | undefined; dsaEncoding?: DSAEncoding | undefined; + context?: ArrayBuffer | NodeJS.ArrayBufferView | undefined; } interface SignPrivateKeyInput extends PrivateKeyInput, SigningOptions {} interface SignKeyObjectInput extends SigningOptions { @@ -2460,6 +2462,18 @@ declare module "crypto" { | "ml-kem-768" | "rsa-pss" | "rsa" + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s" | "x25519" | "x448"; type KeyFormat = "pem" | "der" | "jwk"; @@ -2478,6 +2492,7 @@ declare module "crypto" { interface X448KeyPairKeyObjectOptions {} interface MLDSAKeyPairKeyObjectOptions {} interface MLKEMKeyPairKeyObjectOptions {} + interface SLHDSAKeyPairKeyObjectOptions {} interface ECKeyPairKeyObjectOptions { /** * Name of the curve to use @@ -2660,6 +2675,15 @@ declare module "crypto" { type: "pkcs8"; }; } + interface SLHDSAKeyPairOptions { + publicKeyEncoding: { + type: "spki"; + format: PubF; + }; + privateKeyEncoding: BasePrivateKeyEncodingOptions & { + type: "pkcs8"; + }; + } interface KeyPairSyncResult { publicKey: T1; privateKey: T2; @@ -2882,6 +2906,86 @@ declare module "crypto" { type: "ml-kem-1024" | "ml-kem-512" | "ml-kem-768", options?: MLKEMKeyPairKeyObjectOptions, ): KeyPairKeyObjectResult; + function generateKeyPairSync( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options: SLHDSAKeyPairOptions<"pem", "pem">, + ): KeyPairSyncResult; + function generateKeyPairSync( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options: SLHDSAKeyPairOptions<"pem", "der">, + ): KeyPairSyncResult; + function generateKeyPairSync( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options: SLHDSAKeyPairOptions<"der", "pem">, + ): KeyPairSyncResult; + function generateKeyPairSync( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options: SLHDSAKeyPairOptions<"der", "der">, + ): KeyPairSyncResult; + function generateKeyPairSync( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options?: SLHDSAKeyPairKeyObjectOptions, + ): KeyPairKeyObjectResult; /** * Generates a new asymmetric key pair of the given `type`. RSA, RSA-PSS, DSA, EC, * Ed25519, Ed448, X25519, X448, and DH are currently supported. @@ -3172,6 +3276,91 @@ declare module "crypto" { options: MLKEMKeyPairKeyObjectOptions | undefined, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void, ): void; + function generateKeyPair( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options: SLHDSAKeyPairOptions<"pem", "pem">, + callback: (err: Error | null, publicKey: string, privateKey: string) => void, + ): void; + function generateKeyPair( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options: SLHDSAKeyPairOptions<"pem", "der">, + callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void, + ): void; + function generateKeyPair( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options: SLHDSAKeyPairOptions<"der", "pem">, + callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void, + ): void; + function generateKeyPair( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options: SLHDSAKeyPairOptions<"der", "der">, + callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void, + ): void; + function generateKeyPair( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options: SLHDSAKeyPairKeyObjectOptions | undefined, + callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void, + ): void; namespace generateKeyPair { function __promisify__( type: "rsa", @@ -3478,6 +3667,98 @@ declare module "crypto" { type: "ml-kem-1024" | "ml-kem-512" | "ml-kem-768", options?: MLKEMKeyPairKeyObjectOptions, ): Promise; + function __promisify__( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options: SLHDSAKeyPairOptions<"pem", "pem">, + ): Promise<{ + publicKey: string; + privateKey: string; + }>; + function __promisify__( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options: SLHDSAKeyPairOptions<"pem", "der">, + ): Promise<{ + publicKey: string; + privateKey: Buffer; + }>; + function __promisify__( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options: SLHDSAKeyPairOptions<"der", "pem">, + ): Promise<{ + publicKey: Buffer; + privateKey: string; + }>; + function __promisify__( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options: SLHDSAKeyPairOptions<"der", "der">, + ): Promise<{ + publicKey: Buffer; + privateKey: Buffer; + }>; + function __promisify__( + type: + | "slh-dsa-sha2-128f" + | "slh-dsa-sha2-128s" + | "slh-dsa-sha2-192f" + | "slh-dsa-sha2-192s" + | "slh-dsa-sha2-256f" + | "slh-dsa-sha2-256s" + | "slh-dsa-shake-128f" + | "slh-dsa-shake-128s" + | "slh-dsa-shake-192f" + | "slh-dsa-shake-192s" + | "slh-dsa-shake-256f" + | "slh-dsa-shake-256s", + options?: SLHDSAKeyPairKeyObjectOptions, + ): Promise; } /** * Calculates and returns the signature for `data` using the given private key and @@ -4433,6 +4714,15 @@ declare module "crypto" { interface Algorithm { name: string; } + interface Argon2Params extends Algorithm { + associatedData?: BufferSource; + memory: number; + nonce: BufferSource; + parallelism: number; + passes: number; + secretValue?: BufferSource; + version?: number; + } interface CShakeParams extends Algorithm { customization?: BufferSource; functionName?: BufferSource; @@ -4456,9 +4746,6 @@ declare module "crypto" { interface EcdsaParams extends Algorithm { hash: HashAlgorithmIdentifier; } - interface Ed448Params extends Algorithm { - context?: BufferSource; - } interface HkdfParams extends Algorithm { hash: HashAlgorithmIdentifier; info: BufferSource; @@ -4499,6 +4786,19 @@ declare module "crypto" { interface KeyAlgorithm { name: string; } + interface KmacImportParams extends Algorithm { + length?: number; + } + interface KmacKeyAlgorithm extends KeyAlgorithm { + length: number; + } + interface KmacKeyGenParams extends Algorithm { + length?: number; + } + interface KmacParams extends Algorithm { + customization?: BufferSource; + length: number; + } interface Pbkdf2Params extends Algorithm { hash: HashAlgorithmIdentifier; iterations: number; @@ -4628,6 +4928,10 @@ declare module "crypto" { */ interface SubtleCrypto { /** + * A message recipient uses their asymmetric private key to decrypt an + * "encapsulated key" (ciphertext), thereby recovering a temporary symmetric + * key (represented as `ArrayBuffer`) which is then used to decrypt a message. + * * The algorithms currently supported include: * * * `'ML-KEM-512'` @@ -4642,6 +4946,10 @@ declare module "crypto" { ciphertext: BufferSource, ): Promise; /** + * A message recipient uses their asymmetric private key to decrypt an + * "encapsulated key" (ciphertext), thereby recovering a temporary symmetric + * key (represented as `CryptoKey`) which is then used to decrypt a message. + * * The algorithms currently supported include: * * * `'ML-KEM-512'` @@ -4655,13 +4963,13 @@ declare module "crypto" { decapsulationAlgorithm: AlgorithmIdentifier, decapsulationKey: CryptoKey, ciphertext: BufferSource, - sharedKeyAlgorithm: AlgorithmIdentifier | HmacImportParams | AesDerivedKeyParams, + sharedKeyAlgorithm: AlgorithmIdentifier | HmacImportParams | AesDerivedKeyParams | KmacImportParams, extractable: boolean, usages: KeyUsage[], ): Promise; /** * Using the method and parameters specified in `algorithm` and the keying material provided by `key`, - * `subtle.decrypt()` attempts to decipher the provided `data`. If successful, + * this method attempts to decipher the provided `data`. If successful, * the returned promise will be resolved with an `` containing the plaintext result. * * The algorithms currently supported include: @@ -4681,7 +4989,7 @@ declare module "crypto" { ): Promise; /** * Using the method and parameters specified in `algorithm` and the keying material provided by `baseKey`, - * `subtle.deriveBits()` attempts to generate `length` bits. + * this method attempts to generate `length` bits. * The Node.js implementation requires that when `length` is a number it must be multiple of `8`. * When `length` is `null` the maximum number of bits for a given algorithm is generated. This is allowed * for the `'ECDH'`, `'X25519'`, and `'X448'` algorithms. @@ -4689,6 +4997,9 @@ declare module "crypto" { * * The algorithms currently supported include: * + * * `'Argon2d'` + * * `'Argon2i'` + * * `'Argon2id'` * * `'ECDH'` * * `'HKDF'` * * `'PBKDF2'` @@ -4702,19 +5013,22 @@ declare module "crypto" { length?: number | null, ): Promise; deriveBits( - algorithm: EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params, + algorithm: EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params | Argon2Params, baseKey: CryptoKey, length: number, ): Promise; /** * Using the method and parameters specified in `algorithm`, and the keying material provided by `baseKey`, - * `subtle.deriveKey()` attempts to generate a new ` based on the method and parameters in `derivedKeyAlgorithm`. + * this method attempts to generate a new ` based on the method and parameters in `derivedKeyAlgorithm`. * * Calling `subtle.deriveKey()` is equivalent to calling `subtle.deriveBits()` to generate raw keying material, * then passing the result into the `subtle.importKey()` method using the `deriveKeyAlgorithm`, `extractable`, and `keyUsages` parameters as input. * * The algorithms currently supported include: * + * * `'Argon2d'` + * * `'Argon2i'` + * * `'Argon2id'` * * `'ECDH'` * * `'HKDF'` * * `'PBKDF2'` @@ -4724,9 +5038,9 @@ declare module "crypto" { * @since v15.0.0 */ deriveKey( - algorithm: EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params, + algorithm: EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params | Argon2Params, baseKey: CryptoKey, - derivedKeyAlgorithm: AlgorithmIdentifier | HmacImportParams | AesDerivedKeyParams, + derivedKeyAlgorithm: AlgorithmIdentifier | HmacImportParams | AesDerivedKeyParams | KmacImportParams, extractable: boolean, keyUsages: readonly KeyUsage[], ): Promise; @@ -4751,6 +5065,9 @@ declare module "crypto" { */ digest(algorithm: AlgorithmIdentifier | CShakeParams, data: BufferSource): Promise; /** + * Uses a message recipient's asymmetric public key to encrypt a temporary symmetric key. + * This encrypted key is the "encapsulated key" represented as `EncapsulatedBits`. + * * The algorithms currently supported include: * * * `'ML-KEM-512'` @@ -4764,6 +5081,9 @@ declare module "crypto" { encapsulationKey: CryptoKey, ): Promise; /** + * Uses a message recipient's asymmetric public key to encrypt a temporary symmetric key. + * This encrypted key is the "encapsulated key" represented as `EncapsulatedKey`. + * * The algorithms currently supported include: * * * `'ML-KEM-512'` @@ -4776,13 +5096,13 @@ declare module "crypto" { encapsulateKey( encapsulationAlgorithm: AlgorithmIdentifier, encapsulationKey: CryptoKey, - sharedKeyAlgorithm: AlgorithmIdentifier | HmacImportParams | AesDerivedKeyParams, + sharedKeyAlgorithm: AlgorithmIdentifier | HmacImportParams | AesDerivedKeyParams | KmacImportParams, extractable: boolean, usages: KeyUsage[], ): Promise; /** * Using the method and parameters specified by `algorithm` and the keying material provided by `key`, - * `subtle.encrypt()` attempts to encipher `data`. If successful, + * this method attempts to encipher `data`. If successful, * the returned promise is resolved with an `` containing the encrypted result. * * The algorithms currently supported include: @@ -4841,7 +5161,7 @@ declare module "crypto" { * * `'X25519'` * * `'X448'` * - * The {CryptoKey} (secret key) generating algorithms supported include: + * The `CryptoKey` (secret key) generating algorithms supported include: * * `'AES-CBC'` * * `'AES-CTR'` * * `'AES-GCM'` @@ -4849,6 +5169,8 @@ declare module "crypto" { * * `'AES-OCB'` * * `'ChaCha20-Poly1305'` * * `'HMAC'` + * * `'KMAC128'` + * * `'KMAC256'` * @param keyUsages See {@link https://nodejs.org/docs/latest/api/webcrypto.html#cryptokeyusages Key usages}. * @since v15.0.0 */ @@ -4858,7 +5180,7 @@ declare module "crypto" { keyUsages: readonly KeyUsage[], ): Promise; generateKey( - algorithm: AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params, + algorithm: AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params | KmacKeyGenParams, extractable: boolean, keyUsages: readonly KeyUsage[], ): Promise; @@ -4880,7 +5202,7 @@ declare module "crypto" { * to create a `` instance using the provided `algorithm`, `extractable`, and `keyUsages` arguments. * If the import is successful, the returned promise will be resolved with the created ``. * - * If importing a `'PBKDF2'` key, `extractable` must be `false`. + * If importing KDF algorithm keys, `extractable` must be `false`. * @param format Must be one of `'raw'`, `'pkcs8'`, `'spki'`, `'jwk'`, `'raw-secret'`, * `'raw-public'`, or `'raw-seed'`. * @param keyUsages See {@link https://nodejs.org/docs/latest/api/webcrypto.html#cryptokeyusages Key usages}. @@ -4894,7 +5216,8 @@ declare module "crypto" { | RsaHashedImportParams | EcKeyImportParams | HmacImportParams - | AesKeyAlgorithm, + | AesKeyAlgorithm + | KmacImportParams, extractable: boolean, keyUsages: readonly KeyUsage[], ): Promise; @@ -4906,13 +5229,14 @@ declare module "crypto" { | RsaHashedImportParams | EcKeyImportParams | HmacImportParams - | AesKeyAlgorithm, + | AesKeyAlgorithm + | KmacImportParams, extractable: boolean, keyUsages: KeyUsage[], ): Promise; /** * Using the method and parameters given by `algorithm` and the keying material provided by `key`, - * `subtle.sign()` attempts to generate a cryptographic signature of `data`. If successful, + * this method attempts to generate a cryptographic signature of `data`. If successful, * the returned promise is resolved with an `` containing the generated signature. * * The algorithms currently supported include: @@ -4921,6 +5245,8 @@ declare module "crypto" { * * `'Ed25519'` * * `'Ed448'` * * `'HMAC'` + * * `'KMAC128'` + * * `'KMAC256'` * * `'ML-DSA-44'` * * `'ML-DSA-65'` * * `'ML-DSA-87'` @@ -4929,13 +5255,13 @@ declare module "crypto" { * @since v15.0.0 */ sign( - algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams | Ed448Params | ContextParams, + algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams | ContextParams | KmacParams, key: CryptoKey, data: BufferSource, ): Promise; /** * In cryptography, "wrapping a key" refers to exporting and then encrypting the keying material. - * The `subtle.unwrapKey()` method attempts to decrypt a wrapped key and create a `` instance. + * This method attempts to decrypt a wrapped key and create a `` instance. * It is equivalent to calling `subtle.decrypt()` first on the encrypted key data (using the `wrappedKey`, `unwrapAlgo`, and `unwrappingKey` arguments as input) * then passing the results in to the `subtle.importKey()` method using the `unwrappedKeyAlgo`, `extractable`, and `keyUsages` arguments as inputs. * If successful, the returned promise is resolved with a `` object. @@ -4963,6 +5289,8 @@ declare module "crypto" { * * `'Ed25519'` * * `'Ed448'` * * `'HMAC'` + * * `'KMAC128'` + * * `'KMAC256'` * * `'ML-DSA-44'` * * `'ML-DSA-65'` * * `'ML-DSA-87'` @@ -4989,21 +5317,24 @@ declare module "crypto" { | RsaHashedImportParams | EcKeyImportParams | HmacImportParams - | AesKeyAlgorithm, + | AesKeyAlgorithm + | KmacImportParams, extractable: boolean, keyUsages: KeyUsage[], ): Promise; /** * Using the method and parameters given in `algorithm` and the keying material provided by `key`, - * `subtle.verify()` attempts to verify that `signature` is a valid cryptographic signature of `data`. + * This method attempts to verify that `signature` is a valid cryptographic signature of `data`. * The returned promise is resolved with either `true` or `false`. * * The algorithms currently supported include: * * * `'ECDSA'` * * `'Ed25519'` - * * `'Ed448'`[^secure-curves] + * * `'Ed448'` * * `'HMAC'` + * * `'KMAC128'` + * * `'KMAC256'` * * `'ML-DSA-44'` * * `'ML-DSA-65'` * * `'ML-DSA-87'` @@ -5012,14 +5343,14 @@ declare module "crypto" { * @since v15.0.0 */ verify( - algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams | Ed448Params | ContextParams, + algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams | ContextParams | KmacParams, key: CryptoKey, signature: BufferSource, data: BufferSource, ): Promise; /** * In cryptography, "wrapping a key" refers to exporting and then encrypting the keying material. - * The `subtle.wrapKey()` method exports the keying material into the format identified by `format`, + * This method exports the keying material into the format identified by `format`, * then encrypts it using the method and parameters specified by `wrapAlgo` and the keying material provided by `wrappingKey`. * It is the equivalent to calling `subtle.exportKey()` using `format` and `key` as the arguments, * then passing the result to the `subtle.encrypt()` method using `wrappingKey` and `wrapAlgo` as inputs. diff --git a/types/node/diagnostics_channel.d.ts b/types/node/diagnostics_channel.d.ts index fa5ed691b04d83..025847de1b38b4 100644 --- a/types/node/diagnostics_channel.d.ts +++ b/types/node/diagnostics_channel.d.ts @@ -189,7 +189,6 @@ declare module "diagnostics_channel" { * }); * ``` * @since v15.1.0, v14.17.0 - * @deprecated Since v18.7.0,v16.17.0 - Use {@link subscribe(name, onMessage)} * @param onMessage The handler to receive channel messages */ subscribe(onMessage: ChannelListener): void; @@ -210,7 +209,6 @@ declare module "diagnostics_channel" { * channel.unsubscribe(onMessage); * ``` * @since v15.1.0, v14.17.0 - * @deprecated Since v18.7.0,v16.17.0 - Use {@link unsubscribe(name, onMessage)} * @param onMessage The previous subscribed handler to remove * @return `true` if the handler was found, `false` otherwise. */ diff --git a/types/node/http2.d.ts b/types/node/http2.d.ts index 2ba2464aeb5eb9..bfe10cdea6faa6 100644 --- a/types/node/http2.d.ts +++ b/types/node/http2.d.ts @@ -284,61 +284,111 @@ declare module "http2" { addListener(event: "continue", listener: () => {}): this; addListener( event: "headers", - listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void, + listener: ( + headers: IncomingHttpHeaders & IncomingHttpStatusHeader, + flags: number, + rawHeaders: string[], + ) => void, ): this; addListener(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this; addListener( event: "response", - listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void, + listener: ( + headers: IncomingHttpHeaders & IncomingHttpStatusHeader, + flags: number, + rawHeaders: string[], + ) => void, ): this; addListener(event: string | symbol, listener: (...args: any[]) => void): this; emit(event: "continue"): boolean; - emit(event: "headers", headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number): boolean; + emit( + event: "headers", + headers: IncomingHttpHeaders & IncomingHttpStatusHeader, + flags: number, + rawHeaders: string[], + ): boolean; emit(event: "push", headers: IncomingHttpHeaders, flags: number): boolean; - emit(event: "response", headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number): boolean; + emit( + event: "response", + headers: IncomingHttpHeaders & IncomingHttpStatusHeader, + flags: number, + rawHeaders: string[], + ): boolean; emit(event: string | symbol, ...args: any[]): boolean; on(event: "continue", listener: () => {}): this; on( event: "headers", - listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void, + listener: ( + headers: IncomingHttpHeaders & IncomingHttpStatusHeader, + flags: number, + rawHeaders: string[], + ) => void, ): this; on(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this; on( event: "response", - listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void, + listener: ( + headers: IncomingHttpHeaders & IncomingHttpStatusHeader, + flags: number, + rawHeaders: string[], + ) => void, ): this; on(event: string | symbol, listener: (...args: any[]) => void): this; once(event: "continue", listener: () => {}): this; once( event: "headers", - listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void, + listener: ( + headers: IncomingHttpHeaders & IncomingHttpStatusHeader, + flags: number, + rawHeaders: string[], + ) => void, ): this; once(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this; once( event: "response", - listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void, + listener: ( + headers: IncomingHttpHeaders & IncomingHttpStatusHeader, + flags: number, + rawHeaders: string[], + ) => void, ): this; once(event: string | symbol, listener: (...args: any[]) => void): this; prependListener(event: "continue", listener: () => {}): this; prependListener( event: "headers", - listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void, + listener: ( + headers: IncomingHttpHeaders & IncomingHttpStatusHeader, + flags: number, + rawHeaders: string[], + ) => void, ): this; prependListener(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this; prependListener( event: "response", - listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void, + listener: ( + headers: IncomingHttpHeaders & IncomingHttpStatusHeader, + flags: number, + rawHeaders: string[], + ) => void, ): this; prependListener(event: string | symbol, listener: (...args: any[]) => void): this; prependOnceListener(event: "continue", listener: () => {}): this; prependOnceListener( event: "headers", - listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void, + listener: ( + headers: IncomingHttpHeaders & IncomingHttpStatusHeader, + flags: number, + rawHeaders: string[], + ) => void, ): this; prependOnceListener(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this; prependOnceListener( event: "response", - listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void, + listener: ( + headers: IncomingHttpHeaders & IncomingHttpStatusHeader, + flags: number, + rawHeaders: string[], + ) => void, ): this; prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; } @@ -976,6 +1026,7 @@ declare module "http2" { stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number, + rawHeaders: string[], ) => void, ): this; addListener(event: string | symbol, listener: (...args: any[]) => void): this; @@ -987,6 +1038,7 @@ declare module "http2" { stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number, + rawHeaders: string[], ): boolean; emit(event: string | symbol, ...args: any[]): boolean; on(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this; @@ -998,6 +1050,7 @@ declare module "http2" { stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number, + rawHeaders: string[], ) => void, ): this; on(event: string | symbol, listener: (...args: any[]) => void): this; @@ -1013,6 +1066,7 @@ declare module "http2" { stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number, + rawHeaders: string[], ) => void, ): this; once(event: string | symbol, listener: (...args: any[]) => void): this; @@ -1028,6 +1082,7 @@ declare module "http2" { stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number, + rawHeaders: string[], ) => void, ): this; prependListener(event: string | symbol, listener: (...args: any[]) => void): this; @@ -1043,6 +1098,7 @@ declare module "http2" { stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number, + rawHeaders: string[], ) => void, ): this; prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; @@ -1160,7 +1216,12 @@ declare module "http2" { ): this; addListener( event: "stream", - listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void, + listener: ( + stream: ServerHttp2Stream, + headers: IncomingHttpHeaders, + flags: number, + rawHeaders: string[], + ) => void, ): this; addListener(event: string | symbol, listener: (...args: any[]) => void): this; emit( @@ -1168,7 +1229,13 @@ declare module "http2" { session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket, ): boolean; - emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean; + emit( + event: "stream", + stream: ServerHttp2Stream, + headers: IncomingHttpHeaders, + flags: number, + rawHeaders: string[], + ): boolean; emit(event: string | symbol, ...args: any[]): boolean; on( event: "connect", @@ -1179,7 +1246,12 @@ declare module "http2" { ): this; on( event: "stream", - listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void, + listener: ( + stream: ServerHttp2Stream, + headers: IncomingHttpHeaders, + flags: number, + rawHeaders: string[], + ) => void, ): this; on(event: string | symbol, listener: (...args: any[]) => void): this; once( @@ -1191,7 +1263,12 @@ declare module "http2" { ): this; once( event: "stream", - listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void, + listener: ( + stream: ServerHttp2Stream, + headers: IncomingHttpHeaders, + flags: number, + rawHeaders: string[], + ) => void, ): this; once(event: string | symbol, listener: (...args: any[]) => void): this; prependListener( @@ -1203,7 +1280,12 @@ declare module "http2" { ): this; prependListener( event: "stream", - listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void, + listener: ( + stream: ServerHttp2Stream, + headers: IncomingHttpHeaders, + flags: number, + rawHeaders: string[], + ) => void, ): this; prependListener(event: string | symbol, listener: (...args: any[]) => void): this; prependOnceListener( @@ -1215,7 +1297,12 @@ declare module "http2" { ): this; prependOnceListener( event: "stream", - listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void, + listener: ( + stream: ServerHttp2Stream, + headers: IncomingHttpHeaders, + flags: number, + rawHeaders: string[], + ) => void, ): this; prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; } @@ -1384,7 +1471,12 @@ declare module "http2" { addListener(event: "sessionError", listener: (err: Error) => void): this; addListener( event: "stream", - listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void, + listener: ( + stream: ServerHttp2Stream, + headers: IncomingHttpHeaders, + flags: number, + rawHeaders: string[], + ) => void, ): this; addListener(event: "timeout", listener: () => void): this; addListener(event: string | symbol, listener: (...args: any[]) => void): this; @@ -1399,7 +1491,13 @@ declare module "http2" { session: ServerHttp2Session, ): boolean; emit(event: "sessionError", err: Error): boolean; - emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean; + emit( + event: "stream", + stream: ServerHttp2Stream, + headers: IncomingHttpHeaders, + flags: number, + rawHeaders: string[], + ): boolean; emit(event: "timeout"): boolean; emit(event: string | symbol, ...args: any[]): boolean; on( @@ -1417,7 +1515,12 @@ declare module "http2" { on(event: "sessionError", listener: (err: Error) => void): this; on( event: "stream", - listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void, + listener: ( + stream: ServerHttp2Stream, + headers: IncomingHttpHeaders, + flags: number, + rawHeaders: string[], + ) => void, ): this; on(event: "timeout", listener: () => void): this; on(event: string | symbol, listener: (...args: any[]) => void): this; @@ -1436,7 +1539,12 @@ declare module "http2" { once(event: "sessionError", listener: (err: Error) => void): this; once( event: "stream", - listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void, + listener: ( + stream: ServerHttp2Stream, + headers: IncomingHttpHeaders, + flags: number, + rawHeaders: string[], + ) => void, ): this; once(event: "timeout", listener: () => void): this; once(event: string | symbol, listener: (...args: any[]) => void): this; @@ -1455,7 +1563,12 @@ declare module "http2" { prependListener(event: "sessionError", listener: (err: Error) => void): this; prependListener( event: "stream", - listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void, + listener: ( + stream: ServerHttp2Stream, + headers: IncomingHttpHeaders, + flags: number, + rawHeaders: string[], + ) => void, ): this; prependListener(event: "timeout", listener: () => void): this; prependListener(event: string | symbol, listener: (...args: any[]) => void): this; @@ -1474,7 +1587,12 @@ declare module "http2" { prependOnceListener(event: "sessionError", listener: (err: Error) => void): this; prependOnceListener( event: "stream", - listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void, + listener: ( + stream: ServerHttp2Stream, + headers: IncomingHttpHeaders, + flags: number, + rawHeaders: string[], + ) => void, ): this; prependOnceListener(event: "timeout", listener: () => void): this; prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; @@ -2195,8 +2313,8 @@ declare module "http2" { * will result in a `TypeError` being thrown. * @since v8.4.0 */ - writeHead(statusCode: number, headers?: OutgoingHttpHeaders): this; - writeHead(statusCode: number, statusMessage: string, headers?: OutgoingHttpHeaders): this; + writeHead(statusCode: number, headers?: OutgoingHttpHeaders | readonly string[]): this; + writeHead(statusCode: number, statusMessage: string, headers?: OutgoingHttpHeaders | readonly string[]): this; /** * Call `http2stream.pushStream()` with the given headers, and wrap the * given `Http2Stream` on a newly created `Http2ServerResponse` as the callback diff --git a/types/node/package.json b/types/node/package.json index 5bb3786a227210..10a75314bcdd5d 100644 --- a/types/node/package.json +++ b/types/node/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@types/node", - "version": "24.7.9999", + "version": "24.8.9999", "nonNpm": "conflict", "nonNpmDescription": "Node.js", "projects": [ diff --git a/types/node/sea.d.ts b/types/node/sea.d.ts index 5119ede087d0b6..870c30452d860d 100644 --- a/types/node/sea.d.ts +++ b/types/node/sea.d.ts @@ -150,4 +150,13 @@ declare module "node:sea" { * @since v20.12.0 */ function getRawAsset(key: AssetKey): ArrayBuffer; + /** + * This method can be used to retrieve an array of all the keys of assets + * embedded into the single-executable application. + * An error is thrown when not running inside a single-executable application. + * @since v24.8.0 + * @returns An array containing all the keys of the assets + * embedded in the executable. If no assets are embedded, returns an empty array. + */ + function getAssetKeys(): string[]; } diff --git a/types/node/stream.d.ts b/types/node/stream.d.ts index e42224c1c21695..3b38302b9adfa0 100644 --- a/types/node/stream.d.ts +++ b/types/node/stream.d.ts @@ -1656,6 +1656,7 @@ declare module "stream" { ref(): void; unref(): void; } + // TODO: these should all take webstream arguments /** * Returns whether the stream has encountered an error. * @since v17.3.0, v16.14.0 @@ -1664,8 +1665,15 @@ declare module "stream" { /** * Returns whether the stream is readable. * @since v17.4.0, v16.14.0 + * @returns Only returns `null` if `stream` is not a valid `Readable`, `Duplex` or `ReadableStream`. */ - function isReadable(stream: Readable | NodeJS.ReadableStream): boolean; + function isReadable(stream: Readable | NodeJS.ReadableStream): boolean | null; + /** + * Returns whether the stream is writable. + * @since v20.0.0 + * @returns Only returns `null` if `stream` is not a valid `Writable`, `Duplex` or `WritableStream`. + */ + function isWritable(stream: Writable | NodeJS.WritableStream): boolean | null; } export = Stream; } diff --git a/types/node/test/crypto.ts b/types/node/test/crypto.ts index 5d4c7851b874a5..d0cb7be8ff4b39 100644 --- a/types/node/test/crypto.ts +++ b/types/node/test/crypto.ts @@ -787,6 +787,22 @@ import { promisify } from "node:util"; type: "pkcs8", }, }); + + const slhdsaRes: { + publicKey: Buffer; + privateKey: string; + } = crypto.generateKeyPairSync("slh-dsa-sha2-128s", { + publicKeyEncoding: { + format: "der", + type: "spki", + }, + privateKeyEncoding: { + cipher: "some-cipher", + format: "pem", + passphrase: "secret", + type: "pkcs8", + }, + }); } { @@ -941,6 +957,21 @@ import { promisify } from "node:util"; }, (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {}, ); + + crypto.generateKeyPair( + "slh-dsa-sha2-128s", + { + publicKeyEncoding: { + format: "pem", + type: "spki", + }, + privateKeyEncoding: { + format: "pem", + type: "pkcs8", + }, + }, + (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {}, + ); } { @@ -1070,6 +1101,20 @@ import { promisify } from "node:util"; type: "pkcs8", }, }); + + const slhdsaRes: Promise<{ + publicKey: string; + privateKey: string; + }> = generateKeyPairPromisified("slh-dsa-sha2-128s", { + publicKeyEncoding: { + format: "pem", + type: "spki", + }, + privateKeyEncoding: { + format: "pem", + type: "pkcs8", + }, + }); } { @@ -1348,6 +1393,8 @@ import { promisify } from "node:util"; key: jwk, dsaEncoding: "der", }); + + crypto.sign("slh-dsa-sha2-128s", Buffer.from("asd"), { key, context: Uint8Array.of(1, 2, 3, 4).buffer }); } { diff --git a/types/node/test/http2.ts b/types/node/test/http2.ts index 1509ba1d621711..0756727505d02f 100644 --- a/types/node/test/http2.ts +++ b/types/node/test/http2.ts @@ -71,7 +71,10 @@ import { URL } from "node:url"; http2Session.on("goaway", (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => {}); http2Session.on("localSettings", (settings: Settings) => {}); http2Session.on("remoteSettings", (settings: Settings) => {}); - http2Session.on("stream", (stream: Http2Stream, headers: IncomingHttpHeaders, flags: number) => {}); + http2Session.on( + "stream", + (stream: Http2Stream, headers: IncomingHttpHeaders, flags: number, rawHeaders: string[]) => {}, + ); http2Session.on("timeout", () => {}); http2Session.on("ping", () => {}); @@ -179,9 +182,12 @@ import { URL } from "node:url"; const clientHttp2Stream: ClientHttp2Stream = {} as any; clientHttp2Stream.on("headers", (headers: IncomingHttpHeaders, flags: number) => {}); clientHttp2Stream.on("push", (headers: IncomingHttpHeaders, flags: number) => {}); - clientHttp2Stream.on("response", (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => { - const s: number = headers[":status"]!; - }); + clientHttp2Stream.on( + "response", + (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number, rawHeaders: string[]) => { + const s: number = headers[":status"]!; + }, + ); // ServerHttp2Stream const serverHttp2Stream: ServerHttp2Stream = {} as any; @@ -237,7 +243,10 @@ import { URL } from "node:url"; server.on("sessionError", (err: Error) => {}); server.on("session", (session: ServerHttp2Session) => {}); server.on("checkContinue", (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => {}); - server.on("stream", (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => {}); + server.on( + "stream", + (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number, rawHeaders: string[]) => {}, + ); server.on("request", (request: Http2ServerRequest, response: Http2ServerResponse) => {}); server.on("timeout", () => {}); server.setTimeout().setTimeout(5).setTimeout(5, () => {}); @@ -336,6 +345,7 @@ import { URL } from "node:url"; response.writeHead(200, outgoingHeaders); response.writeHead(200, "OK", outgoingHeaders); response.writeHead(200, "OK"); + response.writeHead(200, ["x-dts-library", "@types/node"]); response.write(""); response.write("", (err: Error) => {}); response.write("", "utf8"); diff --git a/types/node/test/sea.ts b/types/node/test/sea.ts index a73e559e8f2703..9feae9a6e0bc8d 100644 --- a/types/node/test/sea.ts +++ b/types/node/test/sea.ts @@ -1,4 +1,4 @@ -import { getAsset, getAssetAsBlob, getRawAsset, isSea } from "node:sea"; +import { getAsset, getAssetAsBlob, getAssetKeys, getRawAsset, isSea } from "node:sea"; { // $ExpectType boolean @@ -14,4 +14,7 @@ import { getAsset, getAssetAsBlob, getRawAsset, isSea } from "node:sea"; // $ExpectType ArrayBuffer getRawAsset("d.webm"); + + // $ExpectType string[] + getAssetKeys(); } diff --git a/types/node/test/stream.ts b/types/node/test/stream.ts index 06c175e392cb3a..5c49fb38725938 100644 --- a/types/node/test/stream.ts +++ b/types/node/test/stream.ts @@ -6,6 +6,7 @@ import { finished, isErrored, isReadable, + isWritable, pipeline, Readable, Transform, @@ -571,8 +572,10 @@ addAbortSignal(new AbortSignal(), new Readable()); } { - isReadable(new Readable()); // $ExpectType boolean - isReadable(new Duplex()); // $ExpectType boolean + isReadable(new Readable()); // $ExpectType boolean | null + isReadable(new Duplex()); // $ExpectType boolean | null + isWritable(new Writable()); // $ExpectType boolean | null + isWritable(new Duplex()); // $ExpectType boolean | null } { diff --git a/types/node/test/vm.ts b/types/node/test/vm.ts index 713980c23cfbae..199604adb1b0a2 100644 --- a/types/node/test/vm.ts +++ b/types/node/test/vm.ts @@ -147,10 +147,10 @@ import { if (specifier === "foo") { return new SourceTextModule( ` - // The "secret" variable refers to the global variable we added to - // "contextifiedObject" when creating the context. - export default secret; - `, + // The "secret" variable refers to the global variable we added to + // "contextifiedObject" when creating the context. + export default secret; + `, { context: referencingModule.context }, ); } @@ -169,6 +169,56 @@ import { } }); +(async () => { + const contextifiedObject = createContext({ + secret: 42, + print: console.log, + }); + + const rootModule = new SourceTextModule( + ` + import s from 'foo'; + s; + print(s); + `, + { context: contextifiedObject }, + ); + + const moduleMap = new Map([ + ["root", rootModule], + ]); + + function resolveAndLinkDependencies(module: SourceTextModule) { + const requestedModules = module.moduleRequests.map((request) => { + const specifier = request.specifier; + + let requestedModule = moduleMap.get(specifier); + if (requestedModule === undefined) { + requestedModule = new SourceTextModule( + ` + // The "secret" variable refers to the global variable we added to + // "contextifiedObject" when creating the context. + export default secret; + `, + { context: rootModule.context }, + ); + moduleMap.set(specifier, requestedModule); + + resolveAndLinkDependencies(requestedModule); + } + + return requestedModule; + }); + + module.linkRequests(requestedModules); + } + + resolveAndLinkDependencies(rootModule); + rootModule.instantiate(); + + await rootModule.evaluate(); +}); + (async () => { const source = "{ \"a\": 1 }"; const module = new SyntheticModule(["default"], function() { diff --git a/types/node/test/worker_threads.ts b/types/node/test/worker_threads.ts index 8953aeba30d497..afba6c5a3312e8 100644 --- a/types/node/test/worker_threads.ts +++ b/types/node/test/worker_threads.ts @@ -76,6 +76,9 @@ import { createContext } from "node:vm"; w.getHeapStatistics().then(statistics => { statistics; // $ExpectType HeapInfo }); + w.startCpuProfile().then(handle => { + handle.stop().then(JSON.parse); + }); w.terminate().then(() => { // woot }); diff --git a/types/node/v8.d.ts b/types/node/v8.d.ts index 40c58af818cd69..038fcda4eca611 100644 --- a/types/node/v8.d.ts +++ b/types/node/v8.d.ts @@ -400,6 +400,22 @@ declare module "v8" { * @since v12.8.0 */ function getHeapCodeStatistics(): HeapCodeStatistics; + /** + * @since v24.8.0 + */ + interface CPUProfileHandle { + /** + * Stopping collecting the profile, then return a Promise that fulfills with an error or the + * profile data. + * @since v24.8.0 + */ + stop(): Promise; + /** + * Stopping collecting the profile and the profile will be discarded. + * @since v24.8.0 + */ + [Symbol.asyncDispose](): Promise; + } /** * V8 only supports `Latin-1/ISO-8859-1` and `UTF16` as the underlying representation of a string. * If the `content` uses `Latin-1/ISO-8859-1` as the underlying representation, this function will return true; diff --git a/types/node/vm.d.ts b/types/node/vm.d.ts index 06a5343da5f1cd..bf36187a6a77cc 100644 --- a/types/node/vm.d.ts +++ b/types/node/vm.d.ts @@ -676,14 +676,12 @@ declare module "vm" { * flag enabled. * * The `vm.Module` class provides a low-level interface for using - * ECMAScript modules in VM contexts. It is the counterpart of the `vm.Script` class that closely mirrors [Module Record](https://262.ecma-international.org/14.0/#sec-abstract-module-records) s as - * defined in the ECMAScript + * ECMAScript modules in VM contexts. It is the counterpart of the `vm.Script` + * class that closely mirrors [Module Record](https://tc39.es/ecma262/#sec-abstract-module-records)s as defined in the ECMAScript * specification. * * Unlike `vm.Script` however, every `vm.Module` object is bound to a context from - * its creation. Operations on `vm.Module` objects are intrinsically asynchronous, - * in contrast with the synchronous nature of `vm.Script` objects. The use of - * 'async' functions can help with manipulating `vm.Module` objects. + * its creation. * * Using a `vm.Module` object requires three distinct steps: creation/parsing, * linking, and evaluation. These three steps are illustrated in the following @@ -711,7 +709,7 @@ declare module "vm" { * // Here, we attempt to obtain the default export from the module "foo", and * // put it into local binding "secret". * - * const bar = new vm.SourceTextModule(` + * const rootModule = new vm.SourceTextModule(` * import s from 'foo'; * s; * print(s); @@ -721,39 +719,48 @@ declare module "vm" { * // * // "Link" the imported dependencies of this Module to it. * // - * // The provided linking callback (the "linker") accepts two arguments: the - * // parent module (`bar` in this case) and the string that is the specifier of - * // the imported module. The callback is expected to return a Module that - * // corresponds to the provided specifier, with certain requirements documented - * // in `module.link()`. - * // - * // If linking has not started for the returned Module, the same linker - * // callback will be called on the returned Module. + * // Obtain the requested dependencies of a SourceTextModule by + * // `sourceTextModule.moduleRequests` and resolve them. * // * // Even top-level Modules without dependencies must be explicitly linked. The - * // callback provided would never be called, however. - * // - * // The link() method returns a Promise that will be resolved when all the - * // Promises returned by the linker resolve. + * // array passed to `sourceTextModule.linkRequests(modules)` can be + * // empty, however. * // - * // Note: This is a contrived example in that the linker function creates a new - * // "foo" module every time it is called. In a full-fledged module system, a - * // cache would probably be used to avoid duplicated modules. + * // Note: This is a contrived example in that the resolveAndLinkDependencies + * // creates a new "foo" module every time it is called. In a full-fledged + * // module system, a cache would probably be used to avoid duplicated modules. + * + * const moduleMap = new Map([ + * ['root', rootModule], + * ]); * - * async function linker(specifier, referencingModule) { - * if (specifier === 'foo') { - * return new vm.SourceTextModule(` - * // The "secret" variable refers to the global variable we added to - * // "contextifiedObject" when creating the context. - * export default secret; - * `, { context: referencingModule.context }); + * function resolveAndLinkDependencies(module) { + * const requestedModules = module.moduleRequests.map((request) => { + * // In a full-fledged module system, the resolveAndLinkDependencies would + * // resolve the module with the module cache key `[specifier, attributes]`. + * // In this example, we just use the specifier as the key. + * const specifier = request.specifier; * - * // Using `contextifiedObject` instead of `referencingModule.context` - * // here would work as well. - * } - * throw new Error(`Unable to resolve dependency: ${specifier}`); + * let requestedModule = moduleMap.get(specifier); + * if (requestedModule === undefined) { + * requestedModule = new vm.SourceTextModule(` + * // The "secret" variable refers to the global variable we added to + * // "contextifiedObject" when creating the context. + * export default secret; + * `, { context: referencingModule.context }); + * moduleMap.set(specifier, linkedModule); + * // Resolve the dependencies of the new module as well. + * resolveAndLinkDependencies(requestedModule); + * } + * + * return requestedModule; + * }); + * + * module.linkRequests(requestedModules); * } - * await bar.link(linker); + * + * resolveAndLinkDependencies(rootModule); + * rootModule.instantiate(); * * // Step 3 * // @@ -761,7 +768,7 @@ declare module "vm" { * // resolve after the module has finished evaluating. * * // Prints 42. - * await bar.evaluate(); + * await rootModule.evaluate(); * ``` * @since v13.0.0, v12.16.0 * @experimental @@ -831,6 +838,10 @@ declare module "vm" { * Link module dependencies. This method must be called before evaluation, and * can only be called once per module. * + * Use `sourceTextModule.linkRequests(modules)` and + * `sourceTextModule.instantiate()` to link modules either synchronously or + * asynchronously. + * * The function is expected to return a `Module` object or a `Promise` that * eventually resolves to a `Module` object. The returned `Module` must satisfy the * following two invariants: @@ -911,6 +922,39 @@ declare module "vm" { class SourceTextModule extends Module { /** * Creates a new `SourceTextModule` instance. + * + * Properties assigned to the `import.meta` object that are objects may + * allow the module to access information outside the specified `context`. Use + * `vm.runInContext()` to create objects in a specific context. + * + * ```js + * import vm from 'node:vm'; + * + * const contextifiedObject = vm.createContext({ secret: 42 }); + * + * const module = new vm.SourceTextModule( + * 'Object.getPrototypeOf(import.meta.prop).secret = secret;', + * { + * initializeImportMeta(meta) { + * // Note: this object is created in the top context. As such, + * // Object.getPrototypeOf(import.meta.prop) points to the + * // Object.prototype in the top context rather than that in + * // the contextified object. + * meta.prop = {}; + * }, + * }); + * // The module has an empty `moduleRequests` array. + * module.linkRequests([]); + * module.instantiate(); + * await module.evaluate(); + * + * // Now, Object.prototype.secret will be equal to 42. + * // + * // To fix this problem, replace + * // meta.prop = {}; + * // above with + * // meta.prop = vm.runInContext('{}', contextifiedObject); + * ``` * @param code JavaScript Module code to parse */ constructor(code: string, options?: SourceTextModuleOptions); @@ -918,6 +962,55 @@ declare module "vm" { * @deprecated Use `sourceTextModule.moduleRequests` instead. */ readonly dependencySpecifiers: readonly string[]; + /** + * Instantiate the module with the linked requested modules. + * + * This resolves the imported bindings of the module, including re-exported + * binding names. When there are any bindings that cannot be resolved, + * an error would be thrown synchronously. + * + * If the requested modules include cyclic dependencies, the + * `sourceTextModule.linkRequests(modules)` method must be called on all + * modules in the cycle before calling this method. + * @since v24.8.0 + */ + instantiate(): void; + /** + * Link module dependencies. This method must be called before evaluation, and + * can only be called once per module. + * + * The order of the module instances in the `modules` array should correspond to the order of + * `sourceTextModule.moduleRequests` being resolved. If two module requests have the same + * specifier and import attributes, they must be resolved with the same module instance or an + * `ERR_MODULE_LINK_MISMATCH` would be thrown. For example, when linking requests for this + * module: + * + * ```js + * import foo from 'foo'; + * import source Foo from 'foo'; + * ``` + * + * The `modules` array must contain two references to the same instance, because the two + * module requests are identical but in two phases. + * + * If the module has no dependencies, the `modules` array can be empty. + * + * Users can use `sourceTextModule.moduleRequests` to implement the host-defined + * [HostLoadImportedModule](https://tc39.es/ecma262/#sec-HostLoadImportedModule) abstract operation in the ECMAScript specification, + * and using `sourceTextModule.linkRequests()` to invoke specification defined + * [FinishLoadingImportedModule](https://tc39.es/ecma262/#sec-FinishLoadingImportedModule), on the module with all dependencies in a batch. + * + * It's up to the creator of the `SourceTextModule` to determine if the resolution + * of the dependencies is synchronous or asynchronous. + * + * After each module in the `modules` array is linked, call + * `sourceTextModule.instantiate()`. + * @since v24.8.0 + * @param modules Array of `vm.Module` objects that this module depends on. + * The order of the modules in the array is the order of + * `sourceTextModule.moduleRequests`. + */ + linkRequests(modules: readonly Module[]): void; /** * The requested import dependencies of this module. The returned array is frozen * to disallow any changes to it. @@ -1013,9 +1106,7 @@ declare module "vm" { options?: SyntheticModuleOptions, ); /** - * This method is used after the module is linked to set the values of exports. If - * it is called before the module is linked, an `ERR_VM_MODULE_STATUS` error - * will be thrown. + * This method sets the module export binding slots with the given value. * * ```js * import vm from 'node:vm'; @@ -1024,7 +1115,6 @@ declare module "vm" { * m.setExport('x', 1); * }); * - * await m.link(() => {}); * await m.evaluate(); * * assert.strictEqual(m.namespace.x, 1); diff --git a/types/node/worker_threads.d.ts b/types/node/worker_threads.d.ts index e3350f3df1f427..e6b45159decd67 100644 --- a/types/node/worker_threads.d.ts +++ b/types/node/worker_threads.d.ts @@ -62,7 +62,7 @@ declare module "worker_threads" { import { Readable, Writable } from "node:stream"; import { ReadableStream, TransformStream, WritableStream } from "node:stream/web"; import { URL } from "node:url"; - import { HeapInfo } from "node:v8"; + import { CPUProfileHandle, HeapInfo } from "node:v8"; import { MessageEvent } from "undici-types"; const isInternalThread: boolean; const isMainThread: boolean; @@ -469,6 +469,44 @@ declare module "worker_threads" { * @since v24.0.0 */ getHeapStatistics(): Promise; + /** + * Starting a CPU profile then return a Promise that fulfills with an error + * or an `CPUProfileHandle` object. This API supports `await using` syntax. + * + * ```js + * const { Worker } = require('node:worker_threads'); + * + * const worker = new Worker(` + * const { parentPort } = require('worker_threads'); + * parentPort.on('message', () => {}); + * `, { eval: true }); + * + * worker.on('online', async () => { + * const handle = await worker.startCpuProfile(); + * const profile = await handle.stop(); + * console.log(profile); + * worker.terminate(); + * }); + * ``` + * + * `await using` example. + * + * ```js + * const { Worker } = require('node::worker_threads'); + * + * const w = new Worker(` + * const { parentPort } = require('worker_threads'); + * parentPort.on('message', () => {}); + * `, { eval: true }); + * + * w.on('online', async () => { + * // Stop profile automatically when return and profile will be discarded + * await using handle = await w.startCpuProfile(); + * }); + * ``` + * @since v24.8.0 + */ + startCpuProfile(): Promise; /** * Calls `worker.terminate()` when the dispose scope is exited. * From e588e0e39ea08be956f5c54aa7a4271918d6704a Mon Sep 17 00:00:00 2001 From: Rachel Conn Date: Thu, 16 Oct 2025 07:52:21 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#73902=20[pdfma?= =?UTF-8?q?ke]=20Make=20TableCell=20definition=20more=20strict=20to=20prev?= =?UTF-8?q?ent=20unsafe=20use=20by=20@rachelconn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rachel Conn --- types/pdfmake/interfaces.d.ts | 2 +- types/pdfmake/test/pdfmake-interfaces-tests.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/types/pdfmake/interfaces.d.ts b/types/pdfmake/interfaces.d.ts index 6f7f106c3dbac5..5b958b7fbdb718 100755 --- a/types/pdfmake/interfaces.d.ts +++ b/types/pdfmake/interfaces.d.ts @@ -521,7 +521,7 @@ export interface TableCellProperties { * - Use empty objects (`{}`) as placeholders for cells that are covered by other cells * spanning multiple rows or columns. */ -export type TableCell = {} | (Content & TableCellProperties); +export type TableCell = Record | (Content & TableCellProperties); /** * A table. diff --git a/types/pdfmake/test/pdfmake-interfaces-tests.ts b/types/pdfmake/test/pdfmake-interfaces-tests.ts index 18496f9fdbf498..b31372a4d6e157 100644 --- a/types/pdfmake/test/pdfmake-interfaces-tests.ts +++ b/types/pdfmake/test/pdfmake-interfaces-tests.ts @@ -8,6 +8,7 @@ import { ContentUnorderedList, CustomTableLayout, Table, + TableCell, TDocumentDefinitions, } from "pdfmake/interfaces"; @@ -293,6 +294,18 @@ const tableHeights: Table = { heights: [100, "auto"], }; +const tableCells: TableCell[] = [ + {}, + "test", + 100, + { text: "test" }, + { ol: [] }, + // @ts-expect-error + { invalidContentProperty: "" }, + // @ts-expect-error + Promise.resolve("test"), +]; + // via https://pdfmake.github.io/docs/0.1/document-definition-object/patterns/ const tilingPatterns: TDocumentDefinitions = { content: [