From 21924e59bb00837f18fa7140f8a87043fe0bbc24 Mon Sep 17 00:00:00 2001 From: Alex Wendland Date: Fri, 16 Jun 2017 16:03:01 -0400 Subject: [PATCH] cryptiles: add initial typing for 3.1 --- types/cryptiles/cryptiles-tests.ts | 5 +++++ types/cryptiles/index.d.ts | 21 +++++++++++++++++++++ types/cryptiles/tsconfig.json | 22 ++++++++++++++++++++++ types/cryptiles/tslint.json | 1 + 4 files changed, 49 insertions(+) create mode 100644 types/cryptiles/cryptiles-tests.ts create mode 100644 types/cryptiles/index.d.ts create mode 100644 types/cryptiles/tsconfig.json create mode 100644 types/cryptiles/tslint.json diff --git a/types/cryptiles/cryptiles-tests.ts b/types/cryptiles/cryptiles-tests.ts new file mode 100644 index 0000000000..b4d6eb1340 --- /dev/null +++ b/types/cryptiles/cryptiles-tests.ts @@ -0,0 +1,5 @@ +import * as cryptiles from "cryptiles"; + +cryptiles.randomString(0); // $ExpectType string +cryptiles.randomDigits(0); // $ExpectType string +cryptiles.fixedTimeComparison("", ""); // $ExpectTpe boolean diff --git a/types/cryptiles/index.d.ts b/types/cryptiles/index.d.ts new file mode 100644 index 0000000000..31a7972a58 --- /dev/null +++ b/types/cryptiles/index.d.ts @@ -0,0 +1,21 @@ +// Type definitions for cryptiles 3.1 +// Project: https://github.com/hapijs/cryptiles +// Definitions by: Alex Wendland +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * Returns a cryptographically strong pseudo-random data string. Takes a size argument for the length of the string. + */ +export function randomString(size: number): string; + +/** + * Returns a cryptographically strong pseudo-random data string consisting of only numerical digits (0-9). + * Takes a size argument for the length of the string. + */ +export function randomDigits(size: number): string; + +/** + * Compare two strings using fixed time algorithm (to prevent time-based analysis of MAC digest match). + * Returns true if the strings match, false if they differ. + */ +export function fixedTimeComparison(a: string, b: string): boolean; diff --git a/types/cryptiles/tsconfig.json b/types/cryptiles/tsconfig.json new file mode 100644 index 0000000000..2515c735a4 --- /dev/null +++ b/types/cryptiles/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "cryptiles-tests.ts" + ] +} diff --git a/types/cryptiles/tslint.json b/types/cryptiles/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/cryptiles/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }