mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-10 22:44:43 +08:00
[password-hash-and-salt] Add typings (#16073)
* Add password-hash-and-salt typings * Fix lint error * Improve export semantics
This commit is contained in:
committed by
Andy
parent
6c0036b881
commit
992ef67dcb
14
types/password-hash-and-salt/index.d.ts
vendored
Normal file
14
types/password-hash-and-salt/index.d.ts
vendored
Normal 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;
|
||||
23
types/password-hash-and-salt/password-hash-and-salt-tests.ts
Normal file
23
types/password-hash-and-salt/password-hash-and-salt-tests.ts
Normal 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!
|
||||
}
|
||||
});
|
||||
});
|
||||
22
types/password-hash-and-salt/tsconfig.json
Normal file
22
types/password-hash-and-salt/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/password-hash-and-salt/tslint.json
Normal file
1
types/password-hash-and-salt/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user