diff --git a/types/password-hash-and-salt/index.d.ts b/types/password-hash-and-salt/index.d.ts new file mode 100644 index 0000000000..710e18631c --- /dev/null +++ b/types/password-hash-and-salt/index.d.ts @@ -0,0 +1,14 @@ +// Type definitions for password-hash-and-salt 0.1 +// Project: https://github.com/florianheinemann/password-hash-and-salt +// Definitions by: Ali Taheri +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface Password { + hash(cb: (error: string, hash: string) => void): void; + verifyAgainst(hash: string, cb: (error: string, verified: boolean) => void): void; +} + +declare function password(password: string): Password; +declare namespace password {} + +export = password; diff --git a/types/password-hash-and-salt/password-hash-and-salt-tests.ts b/types/password-hash-and-salt/password-hash-and-salt-tests.ts new file mode 100644 index 0000000000..4865cf0eed --- /dev/null +++ b/types/password-hash-and-salt/password-hash-and-salt-tests.ts @@ -0,0 +1,23 @@ +import * as password from 'password-hash-and-salt'; + +const myuser: { hash: string } = { hash: '' }; + +// Creating hash and salt +password('mysecret').hash((error, hash) => { + if (error) + throw new Error('Something went wrong!'); + + // Store hash (incl. algorithm, iterations, and salt) + myuser.hash = hash; + + // Verifying a hash + password('hack').verifyAgainst(myuser.hash, (error, verified) => { + if (error) + throw new Error('Something went wrong!'); + if (!verified) { + // Wrong! + } else { + // Correct! + } + }); +}); diff --git a/types/password-hash-and-salt/tsconfig.json b/types/password-hash-and-salt/tsconfig.json new file mode 100644 index 0000000000..27c9ff3242 --- /dev/null +++ b/types/password-hash-and-salt/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", + "password-hash-and-salt-tests.ts" + ] +} \ No newline at end of file diff --git a/types/password-hash-and-salt/tslint.json b/types/password-hash-and-salt/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/password-hash-and-salt/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }