Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#71619 add type declarations for s-salt-pep…
Browse files Browse the repository at this point in the history
…per by @kguzek
  • Loading branch information
kguzek authored Jan 15, 2025
1 parent 76993a0 commit 4682c14
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 0 deletions.
5 changes: 5 additions & 0 deletions types/s-salt-pepper/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
42 changes: 42 additions & 0 deletions types/s-salt-pepper/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/** Gets and sets the salt length.
* @param saltLength default: 32
* @returns the salt length
*/
export function saltLength(saltLength?: number): number;
/** Gets and sets the number of hash iterations to make.
* @param iterations default: 1000000
* @returns the number of hash iterations
*/
export function iterations(iterations?: number): number;
/** Gets and sets the key length.
* @param keyLength default: 128
* @returns the key length
*/
export function keyLength(keyLength?: number): number;
/** Gets and sets the digest algorithm.
* @param digest default: "sha512"
* @returns the digest algorithm
*/
export function digest(digest?: string): string;
/** Gets and sets the pepper value, which will be concatenated to any salts used from now.
* @param pepper default: ""
* @returns the pepper value
*/
export function pepper(pepper?: string): string;

/** Hashes a password.
* @param password the password to hash
* @returns a promise that resolves to an object containing the base 64 salt and hash
*/
export function hash(password: string): Promise<{ salt: string; hash: string }>;

/** Compares a password with a salt and hash.
* @param password the unhashed password
* @param salt the salt with which to hash the password
* @param hash the hash to compare the password against
* @returns true if hashing the password with the salt produces the hash, false otherwise
*/
export function compare(password: string, { salt, hash }: { salt: string; hash: string }): Promise<boolean>;

/** s-salt-pepper provides password hashing with salt and variable iterations of pbkdf2. */
export as namespace password;
17 changes: 17 additions & 0 deletions types/s-salt-pepper/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"private": true,
"name": "@types/s-salt-pepper",
"version": "3.0.9999",
"projects": [
"https://github.com/sebastiansandqvist/s-salt-pepper"
],
"devDependencies": {
"@types/s-salt-pepper": "workspace:."
},
"owners": [
{
"name": "Konrad Guzek",
"githubUsername": "kguzek"
}
]
}
37 changes: 37 additions & 0 deletions types/s-salt-pepper/s-salt-pepper-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import password from "s-salt-pepper";

// $ExpectType number
password.saltLength();

// $ExpectType number
password.saltLength(32);

// $ExpectType number
password.iterations();

// $ExpectType number
password.iterations(1000000);

// $ExpectType number
password.keyLength();

// $ExpectType number
password.keyLength(128);

// $ExpectType string
password.digest();

// $ExpectType string
password.digest("sha512");

// $ExpectType string
password.pepper();

// $ExpectType string
password.pepper("");

// $ExpectType Promise<{ salt: string; hash: string; }>
password.hash("password");

// $ExpectType Promise<boolean>
password.compare("password", { salt: "salt", hash: "hash" });
19 changes: 19 additions & 0 deletions types/s-salt-pepper/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "node16",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"s-salt-pepper-tests.ts"
]
}

0 comments on commit 4682c14

Please sign in to comment.