diff --git a/types/node/index.d.ts b/types/node/index.d.ts index 5d6b9e9d79..69018ec5f0 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -5836,8 +5836,8 @@ declare module "crypto" { export function getCiphers(): string[]; export function getCurves(): string[]; export function getHashes(): string[]; - export interface ECDH { - convertKey(key: string | Buffer /*| TypedArray*/ | DataView, curve: string, inputEncoding?: string, outputEncoding?: string, format?: string): Buffer | string; + export class ECDH { + static convertKey(key: string | Buffer /*| TypedArray*/ | DataView, curve: string, inputEncoding?: "latin1" | "hex" | "base64", outputEncoding?: "latin1" | "hex" | "base64", format?: "uncompressed" | "compressed" | "hybrid"): Buffer | string; generateKeys(): Buffer; generateKeys(encoding: HexBase64Latin1Encoding, format?: ECDHKeyFormat): string; computeSecret(other_public_key: Buffer): Buffer; diff --git a/types/node/node-tests.ts b/types/node/node-tests.ts index c8f61b948a..a4850ff4ef 100644 --- a/types/node/node-tests.ts +++ b/types/node/node-tests.ts @@ -1151,6 +1151,19 @@ namespace crypto_tests { crypto.randomFill(arr, 2, (err: Error, buf: Uint8Array) => void {}); crypto.randomFill(arr, 2, 3, (err: Error, buf: Uint8Array) => void {}); } + + { + let key: string | Buffer = Buffer.from("buf"); + let curve = "secp256k1"; + let ret: string | Buffer = crypto.ECDH.convertKey(key, curve); + key = "0xfff"; + ret = crypto.ECDH.convertKey(key, curve); + ret = crypto.ECDH.convertKey(key, curve, "hex"); + ret = crypto.ECDH.convertKey(key, curve, "hex", "hex"); + ret = crypto.ECDH.convertKey(key, curve, "hex", "hex", "uncompressed"); + ret = crypto.ECDH.convertKey(key, curve, "hex", "hex", "compressed"); + ret = crypto.ECDH.convertKey(key, curve, "hex", "hex", "hybrid"); + } } //////////////////////////////////////////////////