[password-hash-and-salt] Add typings (#16073)

* Add password-hash-and-salt typings

* Fix lint error

* Improve export semantics
This commit is contained in:
Ali Taheri Moghaddar
2017-05-01 19:14:25 +04:30
committed by Andy
parent 6c0036b881
commit 992ef67dcb
4 changed files with 60 additions and 0 deletions

14
types/password-hash-and-salt/index.d.ts vendored Normal file
View File

@@ -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 <https://github.com/alitaheri>
// 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;

View File

@@ -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!
}
});
});

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }