1 | // Type definitions for bcrypt-nodejs 0.0
|
2 | // Project: https://github.com/shaneGirish/bcrypt-nodejs
|
3 | // Definitions by: David Broder-Rodgers <https://github.com/DavidBR-SW>
|
4 | // Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
5 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
6 |
|
7 | /**
|
8 | * Generate a salt synchronously
|
9 | * @param rounds Number of rounds to process the data for (default - 10)
|
10 | * @return Generated salt
|
11 | */
|
12 | export function genSaltSync(rounds?: number): string;
|
13 |
|
14 | /**
|
15 | * Generate a salt asynchronously
|
16 | * @param rounds Number of rounds to process the data for (default - 10)
|
17 | * @param callback Callback with error and resulting salt, to be fired once the salt has been generated
|
18 | */
|
19 | export function genSalt(rounds: number, callback: (error: Error, result: string) => void): void;
|
20 |
|
21 | /**
|
22 | * Generate a hash synchronously
|
23 | * @param data Data to be encrypted
|
24 | * @param salt Salt to be used in encryption (default - new salt generated with 10 rounds)
|
25 | * @return Generated hash
|
26 | */
|
27 | export function hashSync(data: string, salt?: string): string;
|
28 |
|
29 | /**
|
30 | * Generate a hash asynchronously
|
31 | * @param data Data to be encrypted
|
32 | * @param salt Salt to be used in encryption
|
33 | * @param callback Callback with error and hashed result, to be fired once the data has been encrypted
|
34 | */
|
35 | export function hash(data: string, salt: string, callback: (error: Error, result: string) => void): void;
|
36 |
|
37 | /**
|
38 | * Generate a hash asynchronously
|
39 | * @param data Data to be encrypted
|
40 | * @param salt Salt to be used in encryption
|
41 | * @param progressCallback Callback to be fired multiple times during the hash calculation to signify progress
|
42 | * @param callback Callback with error and hashed result, to be fired once the data has been encrypted
|
43 | */
|
44 | export function hash(
|
45 | data: string,
|
46 | salt: string,
|
47 | progressCallback: null | (() => void),
|
48 | callback: (error: Error, result: string) => void,
|
49 | ): void;
|
50 |
|
51 | /**
|
52 | * Compares data with a hash synchronously
|
53 | * @param data Data to be compared
|
54 | * @param hash Hash to be compared to
|
55 | * @return true if matching, false otherwise
|
56 | */
|
57 | export function compareSync(data: string, hash: string): boolean;
|
58 |
|
59 | /**
|
60 | * Compares data with a hash asynchronously
|
61 | * @param data Data to be compared
|
62 | * @param hash Hash to be compared to
|
63 | * @param callback Callback with error and match result, to be fired once the data has been compared
|
64 | */
|
65 | export function compare(data: string, hash: string, callback: (error: Error, result: boolean) => void): void;
|
66 |
|
67 | /**
|
68 | * Get number of rounds used for hash
|
69 | * @param hash Hash from which the number of rounds used should be extracted
|
70 | * @return number of rounds used to encrypt a given hash
|
71 | */
|
72 | export function getRounds(hash: string): number;
|