From 0e855f28be500d0600d365e319b70bdf42ef9807 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Tue, 14 Nov 2023 16:50:24 +0300 Subject: [PATCH 1/6] fix(node): add missing `paramEncoding` --- types/node/crypto.d.ts | 10 +++++----- types/node/ts4.8/crypto.d.ts | 10 +++++----- types/node/v16/crypto.d.ts | 10 +++++----- types/node/v16/ts4.8/crypto.d.ts | 10 +++++----- types/node/v18/crypto.d.ts | 10 +++++----- types/node/v18/ts4.8/crypto.d.ts | 10 +++++----- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/types/node/crypto.d.ts b/types/node/crypto.d.ts index bd04bf7b69b8e0..672ef093a8a3a4 100644 --- a/types/node/crypto.d.ts +++ b/types/node/crypto.d.ts @@ -2475,6 +2475,10 @@ declare module "crypto" { * Name of the curve to use */ namedCurve: string; + /** + * Must be `'named'` or `'explicit'` (EC). Default: `'named'`. + */ + paramEncoding?: "explicit" | "named"; } interface RSAKeyPairKeyObjectOptions { /** @@ -2585,11 +2589,7 @@ declare module "crypto" { type: "pkcs8"; }; } - interface ECKeyPairOptions { - /** - * Name of the curve to use. - */ - namedCurve: string; + interface ECKeyPairOptions extends ECKeyPairKeyObjectOptions { publicKeyEncoding: { type: "pkcs1" | "spki"; format: PubF; diff --git a/types/node/ts4.8/crypto.d.ts b/types/node/ts4.8/crypto.d.ts index 91d68fe0ad87fe..b94a6f53a83002 100644 --- a/types/node/ts4.8/crypto.d.ts +++ b/types/node/ts4.8/crypto.d.ts @@ -2475,6 +2475,10 @@ declare module "crypto" { * Name of the curve to use */ namedCurve: string; + /** + * Must be `'named'` or `'explicit'` (EC). Default: `'named'`. + */ + paramEncoding?: "explicit" | "named"; } interface RSAKeyPairKeyObjectOptions { /** @@ -2585,11 +2589,7 @@ declare module "crypto" { type: "pkcs8"; }; } - interface ECKeyPairOptions { - /** - * Name of the curve to use. - */ - namedCurve: string; + interface ECKeyPairOptions extends ECKeyPairKeyObjectOptions { publicKeyEncoding: { type: "pkcs1" | "spki"; format: PubF; diff --git a/types/node/v16/crypto.d.ts b/types/node/v16/crypto.d.ts index f61efbe470debe..c581f5d0eec710 100644 --- a/types/node/v16/crypto.d.ts +++ b/types/node/v16/crypto.d.ts @@ -2454,6 +2454,10 @@ declare module "crypto" { * Name of the curve to use */ namedCurve: string; + /** + * Must be `'named'` or `'explicit'` (EC). Default: `'named'`. + */ + paramEncoding?: "explicit" | "named"; } interface RSAKeyPairKeyObjectOptions { /** @@ -2564,11 +2568,7 @@ declare module "crypto" { type: "pkcs8"; }; } - interface ECKeyPairOptions { - /** - * Name of the curve to use. - */ - namedCurve: string; + interface ECKeyPairOptions extends ECKeyPairKeyObjectOptions { publicKeyEncoding: { type: "pkcs1" | "spki"; format: PubF; diff --git a/types/node/v16/ts4.8/crypto.d.ts b/types/node/v16/ts4.8/crypto.d.ts index 26a24a2d9cbc7b..4e3bdcc40c43d1 100644 --- a/types/node/v16/ts4.8/crypto.d.ts +++ b/types/node/v16/ts4.8/crypto.d.ts @@ -2452,6 +2452,10 @@ declare module "crypto" { * Name of the curve to use */ namedCurve: string; + /** + * Must be `'named'` or `'explicit'` (EC). Default: `'named'`. + */ + paramEncoding?: "explicit" | "named"; } interface RSAKeyPairKeyObjectOptions { /** @@ -2562,11 +2566,7 @@ declare module "crypto" { type: "pkcs8"; }; } - interface ECKeyPairOptions { - /** - * Name of the curve to use. - */ - namedCurve: string; + interface ECKeyPairOptions extends ECKeyPairKeyObjectOptions { publicKeyEncoding: { type: "pkcs1" | "spki"; format: PubF; diff --git a/types/node/v18/crypto.d.ts b/types/node/v18/crypto.d.ts index af9ec03ed80463..1311b663fcb734 100644 --- a/types/node/v18/crypto.d.ts +++ b/types/node/v18/crypto.d.ts @@ -2493,6 +2493,10 @@ declare module "crypto" { * Name of the curve to use */ namedCurve: string; + /** + * Must be `'named'` or `'explicit'` (EC). Default: `'named'`. + */ + paramEncoding?: "explicit" | "named"; } interface RSAKeyPairKeyObjectOptions { /** @@ -2603,11 +2607,7 @@ declare module "crypto" { type: "pkcs8"; }; } - interface ECKeyPairOptions { - /** - * Name of the curve to use. - */ - namedCurve: string; + interface ECKeyPairOptions extends ECKeyPairKeyObjectOptions { publicKeyEncoding: { type: "pkcs1" | "spki"; format: PubF; diff --git a/types/node/v18/ts4.8/crypto.d.ts b/types/node/v18/ts4.8/crypto.d.ts index 4b38c8e4eceaae..6fa99e37bd4ca9 100644 --- a/types/node/v18/ts4.8/crypto.d.ts +++ b/types/node/v18/ts4.8/crypto.d.ts @@ -2493,6 +2493,10 @@ declare module "crypto" { * Name of the curve to use */ namedCurve: string; + /** + * Must be `'named'` or `'explicit'` (EC). Default: `'named'`. + */ + paramEncoding?: "explicit" | "named"; } interface RSAKeyPairKeyObjectOptions { /** @@ -2603,11 +2607,7 @@ declare module "crypto" { type: "pkcs8"; }; } - interface ECKeyPairOptions { - /** - * Name of the curve to use. - */ - namedCurve: string; + interface ECKeyPairOptions extends ECKeyPairKeyObjectOptions { publicKeyEncoding: { type: "pkcs1" | "spki"; format: PubF; From abf19904aac1f745ef153b8ddbeacf30fde29726 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Tue, 14 Nov 2023 17:00:45 +0300 Subject: [PATCH 2/6] test(node): add ec `explicit` --- types/node/test/crypto.ts | 35 +++++++++++++++++++++++++++++ types/node/ts4.8/test/crypto.ts | 35 +++++++++++++++++++++++++++++ types/node/v16/test/crypto.ts | 35 +++++++++++++++++++++++++++++ types/node/v16/ts4.8/test/crypto.ts | 35 +++++++++++++++++++++++++++++ types/node/v18/test/crypto.ts | 35 +++++++++++++++++++++++++++++ types/node/v18/ts4.8/test/crypto.ts | 35 +++++++++++++++++++++++++++++ 6 files changed, 210 insertions(+) diff --git a/types/node/test/crypto.ts b/types/node/test/crypto.ts index b8e76922b05e11..f3f26820828824 100644 --- a/types/node/test/crypto.ts +++ b/types/node/test/crypto.ts @@ -627,6 +627,22 @@ import { promisify } from "node:util"; type: "pkcs8", }, }); + + const ecExplicit: { + publicKey: string; + privateKey: string; + } = crypto.generateKeyPairSync("ec", { + namedCurve: "curve", + paramEncoding: "explicit", + publicKeyEncoding: { + format: "pem", + type: "pkcs1", + }, + privateKeyEncoding: { + format: "pem", + type: "pkcs8", + }, + }); } { @@ -703,6 +719,25 @@ import { promisify } from "node:util"; (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {}, ); + crypto.generateKeyPair( + "ec", + { + namedCurve: "curve", + paramEncoding: "explicit", + publicKeyEncoding: { + format: "pem", + type: "pkcs1", + }, + privateKeyEncoding: { + cipher: "some-cipher", + format: "pem", + passphrase: "secret", + type: "pkcs8", + }, + }, + (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {}, + ); + crypto.generateKeyPair( "ed25519", { diff --git a/types/node/ts4.8/test/crypto.ts b/types/node/ts4.8/test/crypto.ts index 4134a5a16d2a43..95622ea42e72ca 100644 --- a/types/node/ts4.8/test/crypto.ts +++ b/types/node/ts4.8/test/crypto.ts @@ -627,6 +627,22 @@ import { promisify } from "node:util"; type: "pkcs8", }, }); + + const ecExplicit: { + publicKey: string; + privateKey: string; + } = crypto.generateKeyPairSync("ec", { + namedCurve: "curve", + paramEncoding: "explicit", + publicKeyEncoding: { + format: "pem", + type: "pkcs1", + }, + privateKeyEncoding: { + format: "pem", + type: "pkcs8", + }, + }); } { @@ -703,6 +719,25 @@ import { promisify } from "node:util"; (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {}, ); + crypto.generateKeyPair( + "ec", + { + namedCurve: "curve", + paramEncoding: "explicit", + publicKeyEncoding: { + format: "pem", + type: "pkcs1", + }, + privateKeyEncoding: { + cipher: "some-cipher", + format: "pem", + passphrase: "secret", + type: "pkcs8", + }, + }, + (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {}, + ); + crypto.generateKeyPair( "ed25519", { diff --git a/types/node/v16/test/crypto.ts b/types/node/v16/test/crypto.ts index 63c98d2745edce..d34d46372aad84 100644 --- a/types/node/v16/test/crypto.ts +++ b/types/node/v16/test/crypto.ts @@ -627,6 +627,22 @@ import { promisify } from "node:util"; type: "pkcs8", }, }); + + const ecExplicit: { + publicKey: string; + privateKey: string; + } = crypto.generateKeyPairSync("ec", { + namedCurve: "curve", + paramEncoding: "explicit", + publicKeyEncoding: { + format: "pem", + type: "pkcs1", + }, + privateKeyEncoding: { + format: "pem", + type: "pkcs8", + }, + }); } { @@ -703,6 +719,25 @@ import { promisify } from "node:util"; (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {}, ); + crypto.generateKeyPair( + "ec", + { + namedCurve: "curve", + paramEncoding: "explicit", + publicKeyEncoding: { + format: "pem", + type: "pkcs1", + }, + privateKeyEncoding: { + cipher: "some-cipher", + format: "pem", + passphrase: "secret", + type: "pkcs8", + }, + }, + (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {}, + ); + crypto.generateKeyPair( "ed25519", { diff --git a/types/node/v16/ts4.8/test/crypto.ts b/types/node/v16/ts4.8/test/crypto.ts index 4794d0de43a6e6..4878bb9608a816 100644 --- a/types/node/v16/ts4.8/test/crypto.ts +++ b/types/node/v16/ts4.8/test/crypto.ts @@ -627,6 +627,22 @@ import { promisify } from "node:util"; type: "pkcs8", }, }); + + const ecExplicit: { + publicKey: string; + privateKey: string; + } = crypto.generateKeyPairSync("ec", { + namedCurve: "curve", + paramEncoding: "explicit", + publicKeyEncoding: { + format: "pem", + type: "pkcs1", + }, + privateKeyEncoding: { + format: "pem", + type: "pkcs8", + }, + }); } { @@ -703,6 +719,25 @@ import { promisify } from "node:util"; (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {}, ); + crypto.generateKeyPair( + "ec", + { + namedCurve: "curve", + paramEncoding: "explicit", + publicKeyEncoding: { + format: "pem", + type: "pkcs1", + }, + privateKeyEncoding: { + cipher: "some-cipher", + format: "pem", + passphrase: "secret", + type: "pkcs8", + }, + }, + (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {}, + ); + crypto.generateKeyPair( "ed25519", { diff --git a/types/node/v18/test/crypto.ts b/types/node/v18/test/crypto.ts index 51f4a86f11795d..a3251c5debcfcd 100644 --- a/types/node/v18/test/crypto.ts +++ b/types/node/v18/test/crypto.ts @@ -627,6 +627,22 @@ import { promisify } from "node:util"; type: "pkcs8", }, }); + + const ecExplicit: { + publicKey: string; + privateKey: string; + } = crypto.generateKeyPairSync("ec", { + namedCurve: "curve", + paramEncoding: "explicit", + publicKeyEncoding: { + format: "pem", + type: "pkcs1", + }, + privateKeyEncoding: { + format: "pem", + type: "pkcs8", + }, + }); } { @@ -703,6 +719,25 @@ import { promisify } from "node:util"; (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {}, ); + crypto.generateKeyPair( + "ec", + { + namedCurve: "curve", + paramEncoding: "explicit", + publicKeyEncoding: { + format: "pem", + type: "pkcs1", + }, + privateKeyEncoding: { + cipher: "some-cipher", + format: "pem", + passphrase: "secret", + type: "pkcs8", + }, + }, + (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {}, + ); + crypto.generateKeyPair( "ed25519", { diff --git a/types/node/v18/ts4.8/test/crypto.ts b/types/node/v18/ts4.8/test/crypto.ts index da7cc7668f7fc8..60bfdaa20e0937 100644 --- a/types/node/v18/ts4.8/test/crypto.ts +++ b/types/node/v18/ts4.8/test/crypto.ts @@ -627,6 +627,22 @@ import { promisify } from "node:util"; type: "pkcs8", }, }); + + const ecExplicit: { + publicKey: string; + privateKey: string; + } = crypto.generateKeyPairSync("ec", { + namedCurve: "curve", + paramEncoding: "explicit", + publicKeyEncoding: { + format: "pem", + type: "pkcs1", + }, + privateKeyEncoding: { + format: "pem", + type: "pkcs8", + }, + }); } { @@ -703,6 +719,25 @@ import { promisify } from "node:util"; (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {}, ); + crypto.generateKeyPair( + "ec", + { + namedCurve: "curve", + paramEncoding: "explicit", + publicKeyEncoding: { + format: "pem", + type: "pkcs1", + }, + privateKeyEncoding: { + cipher: "some-cipher", + format: "pem", + passphrase: "secret", + type: "pkcs8", + }, + }, + (err: NodeJS.ErrnoException | null, publicKey: string, privateKey: string) => {}, + ); + crypto.generateKeyPair( "ed25519", { From 2da6f0b2dd73c3d5134494fed9b14ac31e28a28d Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Mon, 20 Nov 2023 16:12:42 +0300 Subject: [PATCH 3/6] fix(node): add the `equals` method to the `KeyObject` class --- types/node/crypto.d.ts | 6 ++++++ types/node/ts4.8/crypto.d.ts | 6 ++++++ types/node/v16/crypto.d.ts | 6 ++++++ types/node/v16/ts4.8/crypto.d.ts | 6 ++++++ types/node/v18/crypto.d.ts | 6 ++++++ types/node/v18/ts4.8/crypto.d.ts | 6 ++++++ 6 files changed, 36 insertions(+) diff --git a/types/node/crypto.d.ts b/types/node/crypto.d.ts index 672ef093a8a3a4..f05a6f38be68ba 100644 --- a/types/node/crypto.d.ts +++ b/types/node/crypto.d.ts @@ -637,6 +637,12 @@ declare module "crypto" { export(options: KeyExportOptions<"pem">): string | Buffer; export(options?: KeyExportOptions<"der">): Buffer; export(options?: JwkKeyExportOptions): JsonWebKey; + /** + * Returns `true` or `false` depending on whether the keys have exactly the same type, value, and parameters. + * This method is not [constant time](https://en.wikipedia.org/wiki/Timing_attack). + * @since v16.15.0 + */ + equals(otherKeyObject: KeyObject): boolean; /** * For secret keys, this property represents the size of the key in bytes. This * property is `undefined` for asymmetric keys. diff --git a/types/node/ts4.8/crypto.d.ts b/types/node/ts4.8/crypto.d.ts index b94a6f53a83002..c96dc2335dc662 100644 --- a/types/node/ts4.8/crypto.d.ts +++ b/types/node/ts4.8/crypto.d.ts @@ -637,6 +637,12 @@ declare module "crypto" { export(options: KeyExportOptions<"pem">): string | Buffer; export(options?: KeyExportOptions<"der">): Buffer; export(options?: JwkKeyExportOptions): JsonWebKey; + /** + * Returns `true` or `false` depending on whether the keys have exactly the same type, value, and parameters. + * This method is not [constant time](https://en.wikipedia.org/wiki/Timing_attack). + * @since v16.15.0 + */ + equals(otherKeyObject: KeyObject): boolean; /** * For secret keys, this property represents the size of the key in bytes. This * property is `undefined` for asymmetric keys. diff --git a/types/node/v16/crypto.d.ts b/types/node/v16/crypto.d.ts index c581f5d0eec710..48faed224b4e18 100644 --- a/types/node/v16/crypto.d.ts +++ b/types/node/v16/crypto.d.ts @@ -628,6 +628,12 @@ declare module "crypto" { export(options: KeyExportOptions<"pem">): string | Buffer; export(options?: KeyExportOptions<"der">): Buffer; export(options?: JwkKeyExportOptions): JsonWebKey; + /** + * Returns `true` or `false` depending on whether the keys have exactly the same type, value, and parameters. + * This method is not [constant time](https://en.wikipedia.org/wiki/Timing_attack). + * @since v16.15.0 + */ + equals(otherKeyObject: KeyObject): boolean; /** * For secret keys, this property represents the size of the key in bytes. This * property is `undefined` for asymmetric keys. diff --git a/types/node/v16/ts4.8/crypto.d.ts b/types/node/v16/ts4.8/crypto.d.ts index 4e3bdcc40c43d1..65e89c87c1beef 100644 --- a/types/node/v16/ts4.8/crypto.d.ts +++ b/types/node/v16/ts4.8/crypto.d.ts @@ -628,6 +628,12 @@ declare module "crypto" { export(options: KeyExportOptions<"pem">): string | Buffer; export(options?: KeyExportOptions<"der">): Buffer; export(options?: JwkKeyExportOptions): JsonWebKey; + /** + * Returns `true` or `false` depending on whether the keys have exactly the same type, value, and parameters. + * This method is not [constant time](https://en.wikipedia.org/wiki/Timing_attack). + * @since v16.15.0 + */ + equals(otherKeyObject: KeyObject): boolean; /** * For secret keys, this property represents the size of the key in bytes. This * property is `undefined` for asymmetric keys. diff --git a/types/node/v18/crypto.d.ts b/types/node/v18/crypto.d.ts index 1311b663fcb734..3e4558a34f0a76 100644 --- a/types/node/v18/crypto.d.ts +++ b/types/node/v18/crypto.d.ts @@ -655,6 +655,12 @@ declare module "crypto" { export(options: KeyExportOptions<"pem">): string | Buffer; export(options?: KeyExportOptions<"der">): Buffer; export(options?: JwkKeyExportOptions): JsonWebKey; + /** + * Returns `true` or `false` depending on whether the keys have exactly the same type, value, and parameters. + * This method is not [constant time](https://en.wikipedia.org/wiki/Timing_attack). + * @since v16.15.0 + */ + equals(otherKeyObject: KeyObject): boolean; /** * For secret keys, this property represents the size of the key in bytes. This * property is `undefined` for asymmetric keys. diff --git a/types/node/v18/ts4.8/crypto.d.ts b/types/node/v18/ts4.8/crypto.d.ts index 6fa99e37bd4ca9..7cc63100044810 100644 --- a/types/node/v18/ts4.8/crypto.d.ts +++ b/types/node/v18/ts4.8/crypto.d.ts @@ -655,6 +655,12 @@ declare module "crypto" { export(options: KeyExportOptions<"pem">): string | Buffer; export(options?: KeyExportOptions<"der">): Buffer; export(options?: JwkKeyExportOptions): JsonWebKey; + /** + * Returns `true` or `false` depending on whether the keys have exactly the same type, value, and parameters. + * This method is not [constant time](https://en.wikipedia.org/wiki/Timing_attack). + * @since v16.15.0 + */ + equals(otherKeyObject: KeyObject): boolean; /** * For secret keys, this property represents the size of the key in bytes. This * property is `undefined` for asymmetric keys. From a6152b9cc858b3995769c727c5477eaa237cd150 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Mon, 20 Nov 2023 16:15:51 +0300 Subject: [PATCH 4/6] test(node): add the `equals` method --- types/node/test/crypto.ts | 8 ++++++++ types/node/ts4.8/test/crypto.ts | 8 ++++++++ types/node/v16/test/crypto.ts | 8 ++++++++ types/node/v16/ts4.8/test/crypto.ts | 8 ++++++++ types/node/v18/test/crypto.ts | 8 ++++++++ types/node/v18/ts4.8/test/crypto.ts | 8 ++++++++ 6 files changed, 48 insertions(+) diff --git a/types/node/test/crypto.ts b/types/node/test/crypto.ts index f3f26820828824..1b4fa132f54271 100644 --- a/types/node/test/crypto.ts +++ b/types/node/test/crypto.ts @@ -907,6 +907,14 @@ import { promisify } from "node:util"; crypto.createSecretKey("ascii", "ascii"); } +{ + const { privateKey, publicKey } = crypto.generateKeyPairSync("ed25519"); + privateKey; // $ExpectType KeyObject + publicKey; // $ExpectType KeyObject + privateKey.equals(publicKey); // $ExpectType boolean + publicKey.equals(privateKey); // $ExpectType boolean +} + { const { privateKey, publicKey } = crypto.generateKeyPairSync("ec", { namedCurve: "sect239k1", diff --git a/types/node/ts4.8/test/crypto.ts b/types/node/ts4.8/test/crypto.ts index 95622ea42e72ca..c6193a73fbc38b 100644 --- a/types/node/ts4.8/test/crypto.ts +++ b/types/node/ts4.8/test/crypto.ts @@ -907,6 +907,14 @@ import { promisify } from "node:util"; crypto.createSecretKey("ascii", "ascii"); } +{ + const { privateKey, publicKey } = crypto.generateKeyPairSync("ed25519"); + privateKey; // $ExpectType KeyObject + publicKey; // $ExpectType KeyObject + privateKey.equals(publicKey); // $ExpectType boolean + publicKey.equals(privateKey); // $ExpectType boolean +} + { const { privateKey, publicKey } = crypto.generateKeyPairSync("ec", { namedCurve: "sect239k1", diff --git a/types/node/v16/test/crypto.ts b/types/node/v16/test/crypto.ts index d34d46372aad84..ac9fb247741f7e 100644 --- a/types/node/v16/test/crypto.ts +++ b/types/node/v16/test/crypto.ts @@ -907,6 +907,14 @@ import { promisify } from "node:util"; crypto.createSecretKey("ascii", "ascii"); } +{ + const { privateKey, publicKey } = crypto.generateKeyPairSync("ed25519"); + privateKey; // $ExpectType KeyObject + publicKey; // $ExpectType KeyObject + privateKey.equals(publicKey); // $ExpectType boolean + publicKey.equals(privateKey); // $ExpectType boolean +} + { const { privateKey, publicKey } = crypto.generateKeyPairSync("ec", { namedCurve: "sect239k1", diff --git a/types/node/v16/ts4.8/test/crypto.ts b/types/node/v16/ts4.8/test/crypto.ts index 4878bb9608a816..4c79d7ecea3d12 100644 --- a/types/node/v16/ts4.8/test/crypto.ts +++ b/types/node/v16/ts4.8/test/crypto.ts @@ -894,6 +894,14 @@ import { promisify } from "node:util"; crypto.createSecretKey("ascii", "ascii"); } +{ + const { privateKey, publicKey } = crypto.generateKeyPairSync("ed25519"); + privateKey; // $ExpectType KeyObject + publicKey; // $ExpectType KeyObject + privateKey.equals(publicKey); // $ExpectType boolean + publicKey.equals(privateKey); // $ExpectType boolean +} + { const { privateKey, publicKey } = crypto.generateKeyPairSync("ec", { namedCurve: "sect239k1", diff --git a/types/node/v18/test/crypto.ts b/types/node/v18/test/crypto.ts index a3251c5debcfcd..5e60b49b994b45 100644 --- a/types/node/v18/test/crypto.ts +++ b/types/node/v18/test/crypto.ts @@ -907,6 +907,14 @@ import { promisify } from "node:util"; crypto.createSecretKey("ascii", "ascii"); } +{ + const { privateKey, publicKey } = crypto.generateKeyPairSync("ed25519"); + privateKey; // $ExpectType KeyObject + publicKey; // $ExpectType KeyObject + privateKey.equals(publicKey); // $ExpectType boolean + publicKey.equals(privateKey); // $ExpectType boolean +} + { const { privateKey, publicKey } = crypto.generateKeyPairSync("ec", { namedCurve: "sect239k1", diff --git a/types/node/v18/ts4.8/test/crypto.ts b/types/node/v18/ts4.8/test/crypto.ts index 60bfdaa20e0937..852bc39edf0add 100644 --- a/types/node/v18/ts4.8/test/crypto.ts +++ b/types/node/v18/ts4.8/test/crypto.ts @@ -907,6 +907,14 @@ import { promisify } from "node:util"; crypto.createSecretKey("ascii", "ascii"); } +{ + const { privateKey, publicKey } = crypto.generateKeyPairSync("ed25519"); + privateKey; // $ExpectType KeyObject + publicKey; // $ExpectType KeyObject + privateKey.equals(publicKey); // $ExpectType boolean + publicKey.equals(privateKey); // $ExpectType boolean +} + { const { privateKey, publicKey } = crypto.generateKeyPairSync("ec", { namedCurve: "sect239k1", From 1ccaa57efece618b45c568d3b6e96f38aba4f4e6 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Mon, 20 Nov 2023 16:18:19 +0300 Subject: [PATCH 5/6] docs(node): remove `EC` --- types/node/crypto.d.ts | 2 +- types/node/ts4.8/crypto.d.ts | 2 +- types/node/v16/crypto.d.ts | 2 +- types/node/v16/ts4.8/crypto.d.ts | 2 +- types/node/v18/crypto.d.ts | 2 +- types/node/v18/ts4.8/crypto.d.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/types/node/crypto.d.ts b/types/node/crypto.d.ts index f05a6f38be68ba..f148e48068d077 100644 --- a/types/node/crypto.d.ts +++ b/types/node/crypto.d.ts @@ -2482,7 +2482,7 @@ declare module "crypto" { */ namedCurve: string; /** - * Must be `'named'` or `'explicit'` (EC). Default: `'named'`. + * Must be `'named'` or `'explicit'`. Default: `'named'`. */ paramEncoding?: "explicit" | "named"; } diff --git a/types/node/ts4.8/crypto.d.ts b/types/node/ts4.8/crypto.d.ts index c96dc2335dc662..45f1b1cc5c893c 100644 --- a/types/node/ts4.8/crypto.d.ts +++ b/types/node/ts4.8/crypto.d.ts @@ -2482,7 +2482,7 @@ declare module "crypto" { */ namedCurve: string; /** - * Must be `'named'` or `'explicit'` (EC). Default: `'named'`. + * Must be `'named'` or `'explicit'`. Default: `'named'`. */ paramEncoding?: "explicit" | "named"; } diff --git a/types/node/v16/crypto.d.ts b/types/node/v16/crypto.d.ts index 48faed224b4e18..9d8c474d0e61d6 100644 --- a/types/node/v16/crypto.d.ts +++ b/types/node/v16/crypto.d.ts @@ -2461,7 +2461,7 @@ declare module "crypto" { */ namedCurve: string; /** - * Must be `'named'` or `'explicit'` (EC). Default: `'named'`. + * Must be `'named'` or `'explicit'`. Default: `'named'`. */ paramEncoding?: "explicit" | "named"; } diff --git a/types/node/v16/ts4.8/crypto.d.ts b/types/node/v16/ts4.8/crypto.d.ts index 65e89c87c1beef..92229b8f30a8b6 100644 --- a/types/node/v16/ts4.8/crypto.d.ts +++ b/types/node/v16/ts4.8/crypto.d.ts @@ -2459,7 +2459,7 @@ declare module "crypto" { */ namedCurve: string; /** - * Must be `'named'` or `'explicit'` (EC). Default: `'named'`. + * Must be `'named'` or `'explicit'`. Default: `'named'`. */ paramEncoding?: "explicit" | "named"; } diff --git a/types/node/v18/crypto.d.ts b/types/node/v18/crypto.d.ts index 3e4558a34f0a76..69cf1b93386a90 100644 --- a/types/node/v18/crypto.d.ts +++ b/types/node/v18/crypto.d.ts @@ -2500,7 +2500,7 @@ declare module "crypto" { */ namedCurve: string; /** - * Must be `'named'` or `'explicit'` (EC). Default: `'named'`. + * Must be `'named'` or `'explicit'`. Default: `'named'`. */ paramEncoding?: "explicit" | "named"; } diff --git a/types/node/v18/ts4.8/crypto.d.ts b/types/node/v18/ts4.8/crypto.d.ts index 7cc63100044810..3be59b3b247ab7 100644 --- a/types/node/v18/ts4.8/crypto.d.ts +++ b/types/node/v18/ts4.8/crypto.d.ts @@ -2500,7 +2500,7 @@ declare module "crypto" { */ namedCurve: string; /** - * Must be `'named'` or `'explicit'` (EC). Default: `'named'`. + * Must be `'named'` or `'explicit'`. Default: `'named'`. */ paramEncoding?: "explicit" | "named"; } From 0af315263c09eeb627250d55967dbef00698e981 Mon Sep 17 00:00:00 2001 From: Sergey Bakulin Date: Fri, 22 Dec 2023 01:23:02 +0300 Subject: [PATCH 6/6] fix(node:crypto): add `undefined` to the `paramEncoding ` --- types/node/crypto.d.ts | 2 +- types/node/ts4.8/crypto.d.ts | 2 +- types/node/v16/crypto.d.ts | 2 +- types/node/v16/ts4.8/crypto.d.ts | 2 +- types/node/v18/crypto.d.ts | 2 +- types/node/v18/ts4.8/crypto.d.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/types/node/crypto.d.ts b/types/node/crypto.d.ts index f148e48068d077..5d5311fae8125c 100644 --- a/types/node/crypto.d.ts +++ b/types/node/crypto.d.ts @@ -2484,7 +2484,7 @@ declare module "crypto" { /** * Must be `'named'` or `'explicit'`. Default: `'named'`. */ - paramEncoding?: "explicit" | "named"; + paramEncoding?: "explicit" | "named" | undefined; } interface RSAKeyPairKeyObjectOptions { /** diff --git a/types/node/ts4.8/crypto.d.ts b/types/node/ts4.8/crypto.d.ts index 45f1b1cc5c893c..e25d99140a614d 100644 --- a/types/node/ts4.8/crypto.d.ts +++ b/types/node/ts4.8/crypto.d.ts @@ -2484,7 +2484,7 @@ declare module "crypto" { /** * Must be `'named'` or `'explicit'`. Default: `'named'`. */ - paramEncoding?: "explicit" | "named"; + paramEncoding?: "explicit" | "named" | undefined; } interface RSAKeyPairKeyObjectOptions { /** diff --git a/types/node/v16/crypto.d.ts b/types/node/v16/crypto.d.ts index 9d8c474d0e61d6..a5df7f1f8ea743 100644 --- a/types/node/v16/crypto.d.ts +++ b/types/node/v16/crypto.d.ts @@ -2463,7 +2463,7 @@ declare module "crypto" { /** * Must be `'named'` or `'explicit'`. Default: `'named'`. */ - paramEncoding?: "explicit" | "named"; + paramEncoding?: "explicit" | "named" | undefined; } interface RSAKeyPairKeyObjectOptions { /** diff --git a/types/node/v16/ts4.8/crypto.d.ts b/types/node/v16/ts4.8/crypto.d.ts index 92229b8f30a8b6..1bde5bc1286c97 100644 --- a/types/node/v16/ts4.8/crypto.d.ts +++ b/types/node/v16/ts4.8/crypto.d.ts @@ -2461,7 +2461,7 @@ declare module "crypto" { /** * Must be `'named'` or `'explicit'`. Default: `'named'`. */ - paramEncoding?: "explicit" | "named"; + paramEncoding?: "explicit" | "named" | undefined; } interface RSAKeyPairKeyObjectOptions { /** diff --git a/types/node/v18/crypto.d.ts b/types/node/v18/crypto.d.ts index 69cf1b93386a90..64cca4493afba9 100644 --- a/types/node/v18/crypto.d.ts +++ b/types/node/v18/crypto.d.ts @@ -2502,7 +2502,7 @@ declare module "crypto" { /** * Must be `'named'` or `'explicit'`. Default: `'named'`. */ - paramEncoding?: "explicit" | "named"; + paramEncoding?: "explicit" | "named" | undefined; } interface RSAKeyPairKeyObjectOptions { /** diff --git a/types/node/v18/ts4.8/crypto.d.ts b/types/node/v18/ts4.8/crypto.d.ts index 3be59b3b247ab7..3a27a20911523c 100644 --- a/types/node/v18/ts4.8/crypto.d.ts +++ b/types/node/v18/ts4.8/crypto.d.ts @@ -2502,7 +2502,7 @@ declare module "crypto" { /** * Must be `'named'` or `'explicit'`. Default: `'named'`. */ - paramEncoding?: "explicit" | "named"; + paramEncoding?: "explicit" | "named" | undefined; } interface RSAKeyPairKeyObjectOptions { /**