fix(node): fix ECDH.converKey()

This commit is contained in:
islishude
2018-06-17 10:58:28 +08:00
parent 10fe633823
commit 9e33d7d953
2 changed files with 15 additions and 2 deletions
+2 -2
View File
@@ -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;
+13
View File
@@ -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");
}
}
//////////////////////////////////////////////////