@h3ravel/hashing 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/app.globals.d.ts +7 -0
- package/dist/index.cjs +10870 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +435 -0
- package/dist/index.d.ts +435 -0
- package/dist/index.js +10856 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
/// <reference path="./app.globals.d.ts" />
|
|
2
|
+
//#region src/Contracts/ManagerContract.d.ts
|
|
3
|
+
type HashAlgorithm = 'bcrypt' | 'argon' | 'argon2id';
|
|
4
|
+
interface Configuration {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
/**
|
|
7
|
+
* Default Hash Driver
|
|
8
|
+
* -------------------
|
|
9
|
+
* This option controls the default hash driver that will be used to hash
|
|
10
|
+
* passwords for your application. By default, the bcrypt algorithm is
|
|
11
|
+
* used; however, you remain free to modify this option if you wish.
|
|
12
|
+
*/
|
|
13
|
+
driver: HashAlgorithm;
|
|
14
|
+
/**
|
|
15
|
+
* Bcrypt Options
|
|
16
|
+
* --------------
|
|
17
|
+
* Here you may specify the configuration options that should be used when
|
|
18
|
+
* passwords are hashed using the Bcrypt algorithm. This will allow you
|
|
19
|
+
* to control the amount of time it takes to hash the given password.
|
|
20
|
+
*/
|
|
21
|
+
bcrypt: {
|
|
22
|
+
rounds: number;
|
|
23
|
+
verify: boolean;
|
|
24
|
+
limit: number | null;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Argon Options
|
|
28
|
+
* -------------
|
|
29
|
+
* Here you may specify the configuration options that should be used when
|
|
30
|
+
* passwords are hashed using the Argon algorithm. These will allow you
|
|
31
|
+
* to control the amount of time it takes to hash the given password.
|
|
32
|
+
*/
|
|
33
|
+
argon: {
|
|
34
|
+
memory: number;
|
|
35
|
+
threads: number;
|
|
36
|
+
time: number;
|
|
37
|
+
verify: boolean;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
type Options = Partial<Configuration['bcrypt'] & Configuration['argon']>;
|
|
41
|
+
interface BcryptOptions {
|
|
42
|
+
cost: number;
|
|
43
|
+
}
|
|
44
|
+
interface Argon2Options {
|
|
45
|
+
memoryCost: number;
|
|
46
|
+
timeCost: number;
|
|
47
|
+
threads: number;
|
|
48
|
+
}
|
|
49
|
+
interface UnknownOptions {
|
|
50
|
+
[key: string]: any;
|
|
51
|
+
}
|
|
52
|
+
interface Info {
|
|
53
|
+
algo: number;
|
|
54
|
+
algoName: HashAlgorithm;
|
|
55
|
+
options: {
|
|
56
|
+
cost?: number | undefined;
|
|
57
|
+
memoryCost?: number | undefined;
|
|
58
|
+
timeCost?: number | undefined;
|
|
59
|
+
threads?: number | undefined;
|
|
60
|
+
[key: string]: number | undefined;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/Drivers/AbstractHasher.d.ts
|
|
65
|
+
declare abstract class AbstractHasher {
|
|
66
|
+
/**
|
|
67
|
+
* Get information about the given hashed value.
|
|
68
|
+
*
|
|
69
|
+
* @param hashedValue
|
|
70
|
+
* @returns
|
|
71
|
+
*/
|
|
72
|
+
info(hashedValue: string): Info;
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/Drivers/Argon2idHasher.d.ts
|
|
76
|
+
declare class Argon2idHasher extends AbstractHasher {
|
|
77
|
+
private memory;
|
|
78
|
+
private verifyAlgorithm;
|
|
79
|
+
private threads;
|
|
80
|
+
private time;
|
|
81
|
+
constructor(options?: Configuration["argon"]);
|
|
82
|
+
/**
|
|
83
|
+
* Hash the given value using Argon2id.
|
|
84
|
+
*/
|
|
85
|
+
make(value: string, options?: Configuration["argon"]): Promise<string>;
|
|
86
|
+
/**
|
|
87
|
+
* Check the given plain value against a hash.
|
|
88
|
+
*/
|
|
89
|
+
check(value: string, hashedValue?: string | null, _options?: Configuration["argon"]): Promise<boolean>;
|
|
90
|
+
/**
|
|
91
|
+
* Get information about the given hashed value.
|
|
92
|
+
*/
|
|
93
|
+
info(hashedValue: string): Info;
|
|
94
|
+
/**
|
|
95
|
+
* Check if the given hash needs to be rehashed based on current options.
|
|
96
|
+
*/
|
|
97
|
+
needsRehash(hashedValue: string, options?: Configuration["argon"]): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Verify that the hash configuration does not exceed the configured limits.
|
|
100
|
+
*/
|
|
101
|
+
verifyConfiguration(hashedValue: string): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Verify the hashed value's options.
|
|
104
|
+
*/
|
|
105
|
+
protected isUsingValidOptions(hashedValue: string): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Verify the hashed value's algorithm.
|
|
108
|
+
*/
|
|
109
|
+
protected isUsingCorrectAlgorithm(hashedValue: string): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Extract Argon parameters from the hash.
|
|
112
|
+
*/
|
|
113
|
+
protected parseInfo(hashedValue: string): Record<string, number | undefined>;
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/Drivers/ArgonHasher.d.ts
|
|
117
|
+
declare class ArgonHasher extends AbstractHasher {
|
|
118
|
+
private memory;
|
|
119
|
+
private verifyAlgorithm;
|
|
120
|
+
private threads;
|
|
121
|
+
private time;
|
|
122
|
+
constructor(options?: Configuration["argon"]);
|
|
123
|
+
/**
|
|
124
|
+
* Hash the given value using Argon2i.
|
|
125
|
+
*/
|
|
126
|
+
make(value: string, options?: Configuration["argon"]): Promise<string>;
|
|
127
|
+
/**
|
|
128
|
+
* Check the given plain value against a hash.
|
|
129
|
+
*/
|
|
130
|
+
check(value: string, hashedValue?: string | null, _options?: Configuration["argon"]): Promise<boolean>;
|
|
131
|
+
/**
|
|
132
|
+
* Get information about the given hashed value.
|
|
133
|
+
*/
|
|
134
|
+
info(hashedValue: string): Info;
|
|
135
|
+
/**
|
|
136
|
+
* Check if the given hash needs to be rehashed based on current options.
|
|
137
|
+
*/
|
|
138
|
+
needsRehash(hashedValue: string, options?: Configuration["argon"]): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Verify that the hash configuration does not exceed the configured limits.
|
|
141
|
+
*/
|
|
142
|
+
verifyConfiguration(hashedValue: string): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Verify the hashed value's options.
|
|
145
|
+
*/
|
|
146
|
+
protected isUsingValidOptions(hashedValue: string): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Verify the hashed value's algorithm.
|
|
149
|
+
*/
|
|
150
|
+
protected isUsingCorrectAlgorithm(hashedValue: string): boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Extract Argon parameters from the hash.
|
|
153
|
+
*/
|
|
154
|
+
protected parseInfo(hashedValue: string): Record<string, number | undefined>;
|
|
155
|
+
}
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/Drivers/BcryptHasher.d.ts
|
|
158
|
+
declare class BcryptHasher extends AbstractHasher {
|
|
159
|
+
private rounds;
|
|
160
|
+
private verifyAlgorithm;
|
|
161
|
+
private limit;
|
|
162
|
+
constructor(options?: Configuration["bcrypt"]);
|
|
163
|
+
/**
|
|
164
|
+
* Hash the given value.
|
|
165
|
+
*
|
|
166
|
+
* @param value
|
|
167
|
+
* @param options
|
|
168
|
+
*
|
|
169
|
+
* @return {String}
|
|
170
|
+
*/
|
|
171
|
+
make(value: string, options?: Configuration["bcrypt"]): Promise<string>;
|
|
172
|
+
/**
|
|
173
|
+
* Check the given plain value against a hash.
|
|
174
|
+
*
|
|
175
|
+
* @param value
|
|
176
|
+
* @param hashedValue
|
|
177
|
+
* @param options
|
|
178
|
+
* @returns
|
|
179
|
+
*/
|
|
180
|
+
check(value: string, hashedValue?: string | null, _options?: Configuration["bcrypt"]): Promise<boolean>;
|
|
181
|
+
/**
|
|
182
|
+
* Get information about the given hashed value.
|
|
183
|
+
*
|
|
184
|
+
* @param hashedValue
|
|
185
|
+
*
|
|
186
|
+
* @return {Object}
|
|
187
|
+
*/
|
|
188
|
+
info(hashedValue: string): Info;
|
|
189
|
+
/**
|
|
190
|
+
* Check if the given hash has been hashed using the given options.
|
|
191
|
+
*
|
|
192
|
+
* @param hashedValue
|
|
193
|
+
* @param options
|
|
194
|
+
*
|
|
195
|
+
* @return {Boolean}
|
|
196
|
+
*/
|
|
197
|
+
needsRehash(hashedValue: string, options?: Configuration["bcrypt"]): boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Verify the hashed value's options.
|
|
200
|
+
*
|
|
201
|
+
* @param hashedValue
|
|
202
|
+
* @return
|
|
203
|
+
*/
|
|
204
|
+
protected isUsingValidOptions(hashedValue: string): boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Verifies that the configuration is less than or equal to what is configured.
|
|
207
|
+
*
|
|
208
|
+
* @private
|
|
209
|
+
*/
|
|
210
|
+
verifyConfiguration(value: string): boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Verify the hashed value's algorithm.
|
|
213
|
+
*
|
|
214
|
+
* @param hashedValue
|
|
215
|
+
*
|
|
216
|
+
* @returns
|
|
217
|
+
*/
|
|
218
|
+
protected isUsingCorrectAlgorithm(hashedValue: string): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Extract the cost value from the options object.
|
|
221
|
+
*
|
|
222
|
+
* @param options
|
|
223
|
+
* @return int
|
|
224
|
+
*/
|
|
225
|
+
protected cost(options?: Configuration["bcrypt"]): number;
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/Utils/Manager.d.ts
|
|
229
|
+
declare abstract class Manager {
|
|
230
|
+
config: Configuration;
|
|
231
|
+
constructor(config?: Configuration);
|
|
232
|
+
abstract driver(): BcryptHasher | ArgonHasher | Argon2idHasher;
|
|
233
|
+
createBcryptDriver?(): BcryptHasher;
|
|
234
|
+
createArgonDriver?(): ArgonHasher;
|
|
235
|
+
createArgon2idDriver?(): Argon2idHasher;
|
|
236
|
+
/**
|
|
237
|
+
* Get the default driver name.
|
|
238
|
+
*
|
|
239
|
+
* @return string
|
|
240
|
+
*/
|
|
241
|
+
getDefaultDriver(): HashAlgorithm;
|
|
242
|
+
protected createDriver(driver: HashAlgorithm): BcryptHasher | ArgonHasher | Argon2idHasher;
|
|
243
|
+
/**
|
|
244
|
+
* Determine if a given string is already hashed.
|
|
245
|
+
*
|
|
246
|
+
* @param value
|
|
247
|
+
* @returns
|
|
248
|
+
*/
|
|
249
|
+
isHashed(value: string): boolean;
|
|
250
|
+
/**
|
|
251
|
+
* Autoload config and initialize library
|
|
252
|
+
*
|
|
253
|
+
* @returns
|
|
254
|
+
*/
|
|
255
|
+
init(basePath?: string): Promise<this>;
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/HashManager.d.ts
|
|
259
|
+
declare class HashManager extends Manager {
|
|
260
|
+
private drivers;
|
|
261
|
+
/**
|
|
262
|
+
* Create an instance of the Bcrypt hash Driver.
|
|
263
|
+
*
|
|
264
|
+
* @return BcryptHasher
|
|
265
|
+
*/
|
|
266
|
+
createBcryptDriver(): BcryptHasher;
|
|
267
|
+
/**
|
|
268
|
+
* Create an instance of the Argon hash Driver.
|
|
269
|
+
*
|
|
270
|
+
* @return ArgonHasher
|
|
271
|
+
*/
|
|
272
|
+
createArgonDriver(): ArgonHasher;
|
|
273
|
+
/**
|
|
274
|
+
* Create an instance of the Argon2id hash Driver.
|
|
275
|
+
*
|
|
276
|
+
* @return Argon2idHasher
|
|
277
|
+
*/
|
|
278
|
+
createArgon2idDriver(): Argon2idHasher;
|
|
279
|
+
/**
|
|
280
|
+
* Hash the given value.
|
|
281
|
+
*
|
|
282
|
+
* @param value
|
|
283
|
+
* @param options
|
|
284
|
+
*
|
|
285
|
+
* @returns
|
|
286
|
+
*/
|
|
287
|
+
make(value: string, options?: Options): Promise<string>;
|
|
288
|
+
/**
|
|
289
|
+
* Get information about the given hashed value.
|
|
290
|
+
*
|
|
291
|
+
* @param hashedValue
|
|
292
|
+
* @returns
|
|
293
|
+
*/
|
|
294
|
+
info(hashedValue: string): Info;
|
|
295
|
+
/**
|
|
296
|
+
* Check the given plain value against a hash.
|
|
297
|
+
*
|
|
298
|
+
* @param value
|
|
299
|
+
* @param hashedValue
|
|
300
|
+
* @param options
|
|
301
|
+
* @returns
|
|
302
|
+
*/
|
|
303
|
+
check(value: string, hashedValue?: string, options?: Options): Promise<boolean>;
|
|
304
|
+
/**
|
|
305
|
+
* Check if the given hash has been hashed using the given options.
|
|
306
|
+
*
|
|
307
|
+
* @param hashedValue
|
|
308
|
+
* @param options
|
|
309
|
+
* @returns
|
|
310
|
+
*/
|
|
311
|
+
needsRehash(hashedValue: string, options?: Options): boolean;
|
|
312
|
+
/**
|
|
313
|
+
* Determine if a given string is already hashed.
|
|
314
|
+
*
|
|
315
|
+
* @param string value
|
|
316
|
+
* @returns
|
|
317
|
+
*/
|
|
318
|
+
isHashed(value: string): boolean;
|
|
319
|
+
/**
|
|
320
|
+
* Verifies that the configuration is less than or equal to what is configured.
|
|
321
|
+
*
|
|
322
|
+
* @param value
|
|
323
|
+
* @return bool
|
|
324
|
+
*
|
|
325
|
+
* @internal
|
|
326
|
+
*/
|
|
327
|
+
verifyConfiguration(value: string): boolean;
|
|
328
|
+
/**
|
|
329
|
+
* Get a driver instance.
|
|
330
|
+
*
|
|
331
|
+
* @param driver
|
|
332
|
+
*
|
|
333
|
+
* @returns
|
|
334
|
+
*
|
|
335
|
+
* @throws InvalidArgumentException
|
|
336
|
+
*/
|
|
337
|
+
driver(driver?: HashAlgorithm): BcryptHasher | ArgonHasher | Argon2idHasher;
|
|
338
|
+
}
|
|
339
|
+
declare const defineConfig: (config: Configuration) => Configuration;
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region src/Helpers.d.ts
|
|
342
|
+
declare class Hash {
|
|
343
|
+
/**
|
|
344
|
+
* Hash the given value.
|
|
345
|
+
*
|
|
346
|
+
* @param value
|
|
347
|
+
* @param options
|
|
348
|
+
*
|
|
349
|
+
* @returns
|
|
350
|
+
*/
|
|
351
|
+
static make(value: string, options?: Options): any;
|
|
352
|
+
/**
|
|
353
|
+
* Get information about the given hashed value.
|
|
354
|
+
*
|
|
355
|
+
* @param hashedValue
|
|
356
|
+
* @returns
|
|
357
|
+
*/
|
|
358
|
+
static info(hashedValue: string): any;
|
|
359
|
+
/**
|
|
360
|
+
* Check the given plain value against a hash.
|
|
361
|
+
*
|
|
362
|
+
* @param value
|
|
363
|
+
* @param hashedValue
|
|
364
|
+
* @param options
|
|
365
|
+
* @returns
|
|
366
|
+
*/
|
|
367
|
+
static check(value: string, hashedValue?: string, options?: Options): any;
|
|
368
|
+
/**
|
|
369
|
+
* Check if the given hash has been hashed using the given options.
|
|
370
|
+
*
|
|
371
|
+
* @param hashedValue
|
|
372
|
+
* @param options
|
|
373
|
+
* @returns
|
|
374
|
+
*/
|
|
375
|
+
static needsRehash(hashedValue: string, options?: Options): any;
|
|
376
|
+
/**
|
|
377
|
+
* Determine if a given string is already hashed.
|
|
378
|
+
*
|
|
379
|
+
* @param string value
|
|
380
|
+
* @returns
|
|
381
|
+
*/
|
|
382
|
+
static isHashed(value: string): any;
|
|
383
|
+
/**
|
|
384
|
+
* Verifies that the configuration is less than or equal to what is configured.
|
|
385
|
+
*
|
|
386
|
+
* @param value
|
|
387
|
+
* @return bool
|
|
388
|
+
*
|
|
389
|
+
* @internal
|
|
390
|
+
*/
|
|
391
|
+
static verifyConfiguration(value: string): any;
|
|
392
|
+
/**
|
|
393
|
+
* Get a driver instance.
|
|
394
|
+
*
|
|
395
|
+
* @param driver
|
|
396
|
+
*
|
|
397
|
+
* @returns
|
|
398
|
+
*
|
|
399
|
+
* @throws InvalidArgumentException
|
|
400
|
+
*/
|
|
401
|
+
static driver(): any;
|
|
402
|
+
}
|
|
403
|
+
//#endregion
|
|
404
|
+
//#region src/Providers/HashingServiceProvider.d.ts
|
|
405
|
+
/**
|
|
406
|
+
* Register HashManager.
|
|
407
|
+
*/
|
|
408
|
+
declare class HashingServiceProvider {
|
|
409
|
+
private app;
|
|
410
|
+
static priority: number;
|
|
411
|
+
constructor(app: any);
|
|
412
|
+
register(): void;
|
|
413
|
+
}
|
|
414
|
+
//#endregion
|
|
415
|
+
//#region src/Utils/ParseInfo.d.ts
|
|
416
|
+
declare class ParseInfo {
|
|
417
|
+
static getInfo(hashed: string, algo?: HashAlgorithm): {
|
|
418
|
+
[key: string]: number | undefined;
|
|
419
|
+
cost?: number | undefined;
|
|
420
|
+
memoryCost?: number | undefined;
|
|
421
|
+
timeCost?: number | undefined;
|
|
422
|
+
threads?: number | undefined;
|
|
423
|
+
};
|
|
424
|
+
static argon2(hashed: string): {
|
|
425
|
+
[key: string]: number | undefined;
|
|
426
|
+
cost?: number | undefined;
|
|
427
|
+
memoryCost?: number | undefined;
|
|
428
|
+
timeCost?: number | undefined;
|
|
429
|
+
threads?: number | undefined;
|
|
430
|
+
};
|
|
431
|
+
static bcrypt(hashed: string): Info['options'];
|
|
432
|
+
}
|
|
433
|
+
//#endregion
|
|
434
|
+
export { AbstractHasher, Argon2Options, Argon2idHasher, ArgonHasher, BcryptHasher, BcryptOptions, Configuration, Hash, HashAlgorithm, HashManager, HashingServiceProvider, Info, Manager, Options, ParseInfo, UnknownOptions, defineConfig };
|
|
435
|
+
//# sourceMappingURL=index.d.ts.map
|