|
| 1 | +// Type definitions for bcryptjs v2.3.0 |
| 2 | +// Project: https://github.com/dcodeIO/bcrypt.js |
| 3 | +// Definitions by: Joshua Filby <https://github.com/Joshua-F/> |
| 4 | +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped |
| 5 | + |
| 6 | +declare module "bcryptjs" { |
| 7 | + |
| 8 | + /** |
| 9 | + * Sets the pseudo random number generator to use as a fallback if neither node's crypto module nor the Web Crypto API is available. |
| 10 | + * Please note: It is highly important that the PRNG used is cryptographically secure and that it is seeded properly! |
| 11 | + * @param random Function taking the number of bytes to generate as its sole argument, returning the corresponding array of cryptographically secure random byte values. |
| 12 | + */ |
| 13 | + export function setRandomFallback(random: (random: number) => number[]): void; |
| 14 | + |
| 15 | + /** |
| 16 | + * Synchronously generates a salt. |
| 17 | + * @param rounds Number of rounds to use, defaults to 10 if omitted |
| 18 | + * @return Resulting salt |
| 19 | + */ |
| 20 | + export function genSaltSync(rounds?: number): string; |
| 21 | + |
| 22 | + /** |
| 23 | + * Asynchronously generates a salt. |
| 24 | + * @param callback Callback receiving the error, if any, and the resulting salt |
| 25 | + */ |
| 26 | + export function genSalt(callback: (err: Error, salt: string) => void): void; |
| 27 | + |
| 28 | + /** |
| 29 | + * Asynchronously generates a salt. |
| 30 | + * @param rounds Number of rounds to use, defaults to 10 if omitted |
| 31 | + * @param callback Callback receiving the error, if any, and the resulting salt |
| 32 | + */ |
| 33 | + export function genSalt(rounds: number, callback: (err: Error, salt: string) => void): void; |
| 34 | + |
| 35 | + /** |
| 36 | + * Synchronously generates a hash for the given string. |
| 37 | + * @param s String to hash |
| 38 | + * @param salt Salt length to generate or salt to use, default to 10 |
| 39 | + * @return Resulting hash |
| 40 | + */ |
| 41 | + export function hashSync(s: string, salt?: number | string): string; |
| 42 | + |
| 43 | + /** |
| 44 | + * Asynchronously generates a hash for the given string. |
| 45 | + * @param s String to hash |
| 46 | + * @param salt Salt length to generate or salt to use |
| 47 | + * @param callback Callback receiving the error, if any, and the resulting hash |
| 48 | + * @param progressCallback Callback successively called with the percentage of rounds completed (0.0 - 1.0), maximally once per MAX_EXECUTION_TIME = 100 ms. |
| 49 | + */ |
| 50 | + export function hash(s: string, salt: number | string, callback: (err: Error, hash: string) => void, progressCallback?: (percent: number) => void): void; |
| 51 | + |
| 52 | + /** |
| 53 | + * Synchronously tests a string against a hash. |
| 54 | + * @param s String to compare |
| 55 | + * @param hash Hash to test against |
| 56 | + * @return true if matching, otherwise false |
| 57 | + */ |
| 58 | + export function compareSync(s: string, hash: string): boolean; |
| 59 | + |
| 60 | + /** |
| 61 | + * Asynchronously compares the given data against the given hash. |
| 62 | + * @param s Data to compare |
| 63 | + * @param hash Data to be compared to |
| 64 | + * @param callback Callback receiving the error, if any, otherwise the result |
| 65 | + * @param progressCallback Callback successively called with the percentage of rounds completed (0.0 - 1.0), maximally once per MAX_EXECUTION_TIME = 100 ms. |
| 66 | + */ |
| 67 | + export function compare(s: string, hash: string, callback: (err: Error, success: boolean) => void, progressCallback?: (percent: number) => void): void; |
| 68 | + |
| 69 | + /** |
| 70 | + * Gets the number of rounds used to encrypt the specified hash. |
| 71 | + * @param hash Hash to extract the used number of rounds from |
| 72 | + * @return Number of rounds used |
| 73 | + */ |
| 74 | + export function getRounds(hash: string): number; |
| 75 | + |
| 76 | + /** |
| 77 | + * Gets the salt portion from a hash. Does not validate the hash. |
| 78 | + * @param hash Hash to extract the salt from |
| 79 | + * @return Extracted salt part |
| 80 | + */ |
| 81 | + export function getSalt(hash: string): string; |
| 82 | +} |
0 commit comments