From 382f56c51db25a117595250c8a020c98a6e6b0ef Mon Sep 17 00:00:00 2001 From: Gerhard Stoebich Date: Tue, 26 Jun 2018 14:02:05 +0200 Subject: [PATCH] [node] add crypto.scrypt and crypto.scryptSync --- package.json | 2 +- types/node/index.d.ts | 12 +++++++++++- types/node/node-tests.ts | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c5b1b03057..d985e39d01 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "scripts": { "compile-scripts": "tsc -p scripts", "not-needed": "node scripts/not-needed.js", - "test": "node node_modules/types-publisher/bin/tester/test.js --run-from-definitely-typed", + "test": "node node_modules/types-publisher/bin/tester/test.js --run-from-definitely-typed --nProcesses 2", "lint": "dtslint types" }, "devDependencies": { diff --git a/types/node/index.d.ts b/types/node/index.d.ts index 2d0b97d932..f7699a7361 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Node.js 10.3.x +// Type definitions for Node.js 10.5.x // Project: http://nodejs.org/ // Definitions by: Microsoft TypeScript // DefinitelyTyped @@ -5899,6 +5899,16 @@ declare module "crypto" { export function randomFill(buffer: ArrayBufferView, offset: number, callback: (err: Error | null, buf: ArrayBufferView) => void): void; export function randomFill(buffer: ArrayBufferView, offset: number, size: number, callback: (err: Error | null, buf: ArrayBufferView) => void): void; + export interface ScryptOptions { + N?: number; + r?: number; + p?: number; + maxmem?: number; + } + export function scrypt(password: string | ArrayBufferView, salt: string | ArrayBufferView, keylen: number, callback: (err: Error | null, derivedKey: Buffer) => void): void; + export function scrypt(password: string | ArrayBufferView, salt: string | ArrayBufferView, keylen: number, options: ScryptOptions, callback: (err: Error | null, derivedKey: Buffer) => void): void; + export function scryptSync(password: string | ArrayBufferView, salt: string | ArrayBufferView, keylen: number, options?: ScryptOptions): Buffer; + export interface RsaPublicKey { key: string; padding?: number; diff --git a/types/node/node-tests.ts b/types/node/node-tests.ts index e5887b17c4..e9319d705d 100644 --- a/types/node/node-tests.ts +++ b/types/node/node-tests.ts @@ -1263,6 +1263,24 @@ namespace crypto_tests { crypto.randomFill(i32arr, 2, 3, (err: Error, buf: ArrayBufferView) => void {}); } + { + // scrypt + const pwd: string | Buffer | Int32Array | DataView = Buffer.alloc(16); + const salt: string | Buffer | Int32Array | DataView = Buffer.alloc(16); + crypto.scrypt(pwd, salt, 64, (err: Error | null, derivedKey: Buffer): void => {}); + const opts: crypto.ScryptOptions = { + N: 16384, + r: 8, + p: 1, + maxmem: 32 * 1024 * 1024 + }; + crypto.scrypt(pwd, salt, 64, opts, (err: Error | null, derivedKey: Buffer): void => {}); + crypto.scrypt(pwd, salt, 64, { maxmem: 16 * 1024 * 1024 }, (err: Error | null, derivedKey: Buffer): void => {}); + let buf: Buffer = crypto.scryptSync(pwd, salt, 64); + buf = crypto.scryptSync(pwd, salt, 64, opts); + buf = crypto.scryptSync(pwd, salt, 64, { N: 1024 }); + } + { let key: string | Buffer = Buffer.from("buf"); let curve = "secp256k1";