From b93dc24e1bb336852b9ad97509b84b90afe4e28a Mon Sep 17 00:00:00 2001 From: Peter Safranek Date: Thu, 24 Nov 2016 00:50:58 -0800 Subject: [PATCH] Add typings for argon2. --- argon2/argon2-tests.ts | 35 +++++++++++++++++++++++++++++++++ argon2/index.d.ts | 44 ++++++++++++++++++++++++++++++++++++++++++ argon2/tsconfig.json | 19 ++++++++++++++++++ argon2/tslint.json | 1 + 4 files changed, 99 insertions(+) create mode 100644 argon2/argon2-tests.ts create mode 100644 argon2/index.d.ts create mode 100644 argon2/tsconfig.json create mode 100644 argon2/tslint.json diff --git a/argon2/argon2-tests.ts b/argon2/argon2-tests.ts new file mode 100644 index 0000000000..566292b4fa --- /dev/null +++ b/argon2/argon2-tests.ts @@ -0,0 +1,35 @@ + +import { defaults, limits, hash, verify, generateSalt } from 'argon2'; + +main(); + +async function main() { + + const defaultTimeCost: number = defaults.timeCost; + const defaultMemoryCost: number = defaults.memoryCost; + const defaultParallelism: number = defaults.parallelism; + const defaultArgon2d: boolean = defaults.argon2d; + + const minMemoryCost: number = limits.memoryCost.min; + const maxMemoryCost: number = limits.memoryCost.max; + const minTimeCost: number = limits.timeCost.min; + const maxTimeCost: number = limits.timeCost.max; + const minParallelism: number = limits.parallelism.min; + const maxParallelism: number = limits.parallelism.max; + + const options = { + timeCost: 4, + memoryCost: 13, + parallelism: 2, + argon2d: true, + }; + + const hash1: string = await hash('secret', new Buffer(''), options); + const hash2: string = await hash('secret', new Buffer(''), {}); + const hash3: string = await hash('secret', new Buffer('')); + + const verified: boolean = await verify('long-hash', 'secret'); + + const salt1: Buffer = await generateSalt(); + const salt2: Buffer = await generateSalt(32); +} diff --git a/argon2/index.d.ts b/argon2/index.d.ts new file mode 100644 index 0000000000..f4e4c41d1f --- /dev/null +++ b/argon2/index.d.ts @@ -0,0 +1,44 @@ +// Type definitions for argon2 0.14 +// Project: https://github.com/ranisalt/node-argon2#readme +// Definitions by: Peter Safranek +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare namespace argon2 { + + export var defaults: { + timeCost: number; + memoryCost: number; + parallelism: number; + argon2d: boolean; + }; + + export var limits: { + memoryCost: { + min: number; + max: number; + }; + timeCost: { + min: number; + max: number; + }; + parallelism: { + min: number; + max: number; + }; + }; + + export function hash(plain: string, salt: Buffer, options?: { + timeCost?: number; + memoryCost?: number; + parallelism?: number; + argon2d?: boolean; + }): Promise; + + export function verify(hash: string, plain: string): Promise; + + export function generateSalt(length?: number): Promise; +} + +export = argon2; diff --git a/argon2/tsconfig.json b/argon2/tsconfig.json new file mode 100644 index 0000000000..5af6cc5d73 --- /dev/null +++ b/argon2/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "argon2-tests.ts" + ] +} diff --git a/argon2/tslint.json b/argon2/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/argon2/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }