1 | /**
|
2 | * Sets the pseudo random number generator to use as a fallback if neither node's crypto module nor the Web Crypto API is available.
|
3 | * Please note: It is highly important that the PRNG used is cryptographically secure and that it is seeded properly!
|
4 | * @param random Function taking the number of bytes to generate as its sole argument, returning the corresponding array of cryptographically secure random byte values.
|
5 | */
|
6 | export declare function setRandomFallback(random: (random: number) => number[]): void;
|
7 |
|
8 | /**
|
9 | * Synchronously generates a salt.
|
10 | * @param rounds Number of rounds to use, defaults to 10 if omitted
|
11 | * @return Resulting salt
|
12 | * @throws If a random fallback is required but not set
|
13 | */
|
14 | export declare function genSaltSync(rounds?: number): string;
|
15 |
|
16 | /**
|
17 | * Asynchronously generates a salt.
|
18 | * @param rounds Number of rounds to use, defaults to 10 if omitted
|
19 | * @return Promise with resulting salt, if callback has been omitted
|
20 | */
|
21 | export declare function genSalt(rounds?: number): Promise<string>;
|
22 |
|
23 | /**
|
24 | * Asynchronously generates a salt.
|
25 | * @param callback Callback receiving the error, if any, and the resulting salt
|
26 | */
|
27 | export declare function genSalt(callback: (err: Error | null, salt: string) => void): void;
|
28 |
|
29 | /**
|
30 | * Asynchronously generates a salt.
|
31 | * @param rounds Number of rounds to use, defaults to 10 if omitted
|
32 | * @param callback Callback receiving the error, if any, and the resulting salt
|
33 | */
|
34 | export declare function genSalt(rounds: number, callback: (err: Error | null, salt: string) => void): void;
|
35 |
|
36 | /**
|
37 | * Synchronously generates a hash for the given string.
|
38 | * @param s String to hash
|
39 | * @param salt Salt length to generate or salt to use, default to 10
|
40 | * @return Resulting hash
|
41 | */
|
42 | export declare function hashSync(s: string, salt?: number | string): string;
|
43 |
|
44 | /**
|
45 | * Asynchronously generates a hash for the given string.
|
46 | * @param s String to hash
|
47 | * @param salt Salt length to generate or salt to use
|
48 | * @return Promise with resulting hash, if callback has been omitted
|
49 | */
|
50 | export declare function hash(s: string, salt: number | string): Promise<string>;
|
51 |
|
52 | /**
|
53 | * Asynchronously generates a hash for the given string.
|
54 | * @param s String to hash
|
55 | * @param salt Salt length to generate or salt to use
|
56 | * @param callback Callback receiving the error, if any, and the resulting hash
|
57 | * @param progressCallback Callback successively called with the percentage of rounds completed (0.0 - 1.0), maximally once per MAX_EXECUTION_TIME = 100 ms.
|
58 | */
|
59 | export declare function hash(
|
60 | s: string,
|
61 | salt: number | string,
|
62 | callback?: (err: Error | null, hash: string) => void,
|
63 | progressCallback?: (percent: number) => void,
|
64 | ): void;
|
65 |
|
66 | /**
|
67 | * Synchronously tests a string against a hash.
|
68 | * @param s String to compare
|
69 | * @param hash Hash to test against
|
70 | * @return true if matching, otherwise false
|
71 | */
|
72 | export declare function compareSync(s: string, hash: string): boolean;
|
73 |
|
74 | /**
|
75 | * Asynchronously compares the given data against the given hash.
|
76 | * @param s Data to compare
|
77 | * @param hash Data to be compared to
|
78 | * @return Promise, if callback has been omitted
|
79 | */
|
80 | export declare function compare(s: string, hash: string): Promise<boolean>;
|
81 |
|
82 | /**
|
83 | * Asynchronously compares the given data against the given hash.
|
84 | * @param s Data to compare
|
85 | * @param hash Data to be compared to
|
86 | * @param callback Callback receiving the error, if any, otherwise the result
|
87 | * @param progressCallback Callback successively called with the percentage of rounds completed (0.0 - 1.0), maximally once per MAX_EXECUTION_TIME = 100 ms.
|
88 | */
|
89 | export declare function compare(
|
90 | s: string,
|
91 | hash: string,
|
92 | callback?: (err: Error | null, success: boolean) => void,
|
93 | progressCallback?: (percent: number) => void,
|
94 | ): void;
|
95 |
|
96 | /**
|
97 | * Gets the number of rounds used to encrypt the specified hash.
|
98 | * @param hash Hash to extract the used number of rounds from
|
99 | * @return Number of rounds used
|
100 | */
|
101 | export declare function getRounds(hash: string): number;
|
102 |
|
103 | /**
|
104 | * Gets the salt portion from a hash. Does not validate the hash.
|
105 | * @param hash Hash to extract the salt from
|
106 | * @return Extracted salt part
|
107 | */
|
108 | export declare function getSalt(hash: string): string;
|
109 |
|
110 | /**
|
111 | * Encodes a byte array to base64 with up to len bytes of input, using the custom bcrypt alphabet.
|
112 | * @function
|
113 | * @param b Byte array
|
114 | * @param len Maximum input length
|
115 | */
|
116 | export declare function encodeBase64(b: Readonly<ArrayLike<number>>, len: number): string;
|
117 |
|
118 | /**
|
119 | * Decodes a base64 encoded string to up to len bytes of output, using the custom bcrypt alphabet.
|
120 | * @function
|
121 | * @param s String to decode
|
122 | * @param len Maximum output length
|
123 | */
|
124 | export declare function decodeBase64(s: string, len: number): number[];
|