@h3ravel/hashing 0.1.12 → 0.1.15

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/dist/index.cjs CHANGED
@@ -301,7 +301,7 @@ var ArgonHasher = class extends AbstractHasher {
301
301
  };
302
302
 
303
303
  //#endregion
304
- //#region ../../node_modules/.pnpm/bcryptjs@3.0.3/node_modules/bcryptjs/index.js
304
+ //#region ../../node_modules/.pnpm/bcryptjs@3.0.2/node_modules/bcryptjs/index.js
305
305
  /**
306
306
  * The random implementation to use as a fallback.
307
307
  * @type {?function(number):!Array.<number>}
@@ -530,12 +530,12 @@ function truncates(password) {
530
530
  return utf8Length(password) > 72;
531
531
  }
532
532
  /**
533
- * Continues with the callback after yielding to the event loop.
533
+ * Continues with the callback on the next tick.
534
534
  * @function
535
535
  * @param {function(...[*])} callback Callback to execute
536
536
  * @inner
537
537
  */
538
- var nextTick = typeof setImmediate === "function" ? setImmediate : typeof scheduler === "object" && typeof scheduler.postTask === "function" ? scheduler.postTask.bind(scheduler) : setTimeout;
538
+ var nextTick = typeof process !== "undefined" && process && typeof process.nextTick === "function" ? typeof setImmediate === "function" ? setImmediate : process.nextTick : setTimeout;
539
539
  /** Calculates the byte length of a string encoded as UTF8. */
540
540
  function utf8Length(string) {
541
541
  var len = 0, c = 0;
@@ -2333,7 +2333,7 @@ var Manager = class {
2333
2333
  * @returns
2334
2334
  */
2335
2335
  async init(basePath = process.cwd()) {
2336
- const jsPath = node_path.default.resolve(basePath, "hashing.config.mjs");
2336
+ const jsPath = node_path.default.resolve(basePath, "hashing.config.js");
2337
2337
  const tsPath = node_path.default.resolve(basePath, "hashing.config.ts");
2338
2338
  if ((0, node_fs.existsSync)(jsPath)) {
2339
2339
  this.config = (await import(jsPath)).default ?? {};
@@ -239,7 +239,7 @@ declare abstract class Manager {
239
239
  * @return string
240
240
  */
241
241
  getDefaultDriver(): HashAlgorithm;
242
- protected createDriver(driver: HashAlgorithm): BcryptHasher | ArgonHasher | Argon2idHasher;
242
+ protected createDriver(driver: HashAlgorithm): Argon2idHasher | BcryptHasher | ArgonHasher;
243
243
  /**
244
244
  * Determine if a given string is already hashed.
245
245
  *
@@ -334,7 +334,7 @@ declare class HashManager extends Manager {
334
334
  *
335
335
  * @throws InvalidArgumentException
336
336
  */
337
- driver(driver?: HashAlgorithm): BcryptHasher | ArgonHasher | Argon2idHasher;
337
+ driver(driver?: HashAlgorithm): Argon2idHasher | BcryptHasher | ArgonHasher;
338
338
  }
339
339
  declare const defineConfig: (config: Configuration) => Configuration;
340
340
  //#endregion
@@ -275,7 +275,7 @@ var ArgonHasher = class extends AbstractHasher {
275
275
  };
276
276
 
277
277
  //#endregion
278
- //#region ../../node_modules/.pnpm/bcryptjs@3.0.3/node_modules/bcryptjs/index.js
278
+ //#region ../../node_modules/.pnpm/bcryptjs@3.0.2/node_modules/bcryptjs/index.js
279
279
  /**
280
280
  * The random implementation to use as a fallback.
281
281
  * @type {?function(number):!Array.<number>}
@@ -504,12 +504,12 @@ function truncates(password) {
504
504
  return utf8Length(password) > 72;
505
505
  }
506
506
  /**
507
- * Continues with the callback after yielding to the event loop.
507
+ * Continues with the callback on the next tick.
508
508
  * @function
509
509
  * @param {function(...[*])} callback Callback to execute
510
510
  * @inner
511
511
  */
512
- var nextTick = typeof setImmediate === "function" ? setImmediate : typeof scheduler === "object" && typeof scheduler.postTask === "function" ? scheduler.postTask.bind(scheduler) : setTimeout;
512
+ var nextTick = typeof process !== "undefined" && process && typeof process.nextTick === "function" ? typeof setImmediate === "function" ? setImmediate : process.nextTick : setTimeout;
513
513
  /** Calculates the byte length of a string encoded as UTF8. */
514
514
  function utf8Length(string) {
515
515
  var len = 0, c = 0;
@@ -2307,7 +2307,7 @@ var Manager = class {
2307
2307
  * @returns
2308
2308
  */
2309
2309
  async init(basePath = process.cwd()) {
2310
- const jsPath = path.resolve(basePath, "hashing.config.mjs");
2310
+ const jsPath = path.resolve(basePath, "hashing.config.js");
2311
2311
  const tsPath = path.resolve(basePath, "hashing.config.ts");
2312
2312
  if (existsSync(jsPath)) {
2313
2313
  this.config = (await import(jsPath)).default ?? {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/hashing",
3
- "version": "0.1.12",
3
+ "version": "0.1.15",
4
4
  "description": "Secure framework-agnostic Bcrypt and Argon2 hashing for storing user passwords in H3ravel and node Apps.",
5
5
  "h3ravel": {
6
6
  "providers": [
@@ -8,15 +8,15 @@
8
8
  ]
9
9
  },
10
10
  "type": "module",
11
- "main": "./dist/index.mjs",
12
- "types": "./dist/index.d.mts",
13
- "module": "./dist/index.mjs",
11
+ "main": "./dist/index.cjs",
12
+ "types": "./dist/index.d.ts",
13
+ "module": "./dist/index.js",
14
14
  "exports": {
15
15
  ".": {
16
- "types": "./dist/index.d.mts",
17
- "import": "./dist/index.mjs",
16
+ "import": "./dist/index.js",
18
17
  "require": "./dist/index.cjs"
19
- }
18
+ },
19
+ "./*": "./*"
20
20
  },
21
21
  "files": [
22
22
  "dist"
@@ -48,8 +48,8 @@
48
48
  "typescript": "^5.4.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "@h3ravel/core": "^1.21.3",
52
- "@h3ravel/support": "^0.15.3"
51
+ "@h3ravel/support": "^0.15.6",
52
+ "@h3ravel/core": "^1.21.6"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
55
  "@h3ravel/core": {
@@ -60,9 +60,10 @@
60
60
  "argon2": "^0.44.0"
61
61
  },
62
62
  "scripts": {
63
+ "barrel": "barrelsby --directory src --delete --singleQuotes",
63
64
  "build": "tsdown --config-loader unconfig",
64
65
  "dev": "tsx watch src/index.ts",
65
- "start": "node dist/index.mjs",
66
+ "start": "node dist/index.js",
66
67
  "lint": "eslint . --ext .ts",
67
68
  "test": "jest --passWithNoTests",
68
69
  "version-patch": "pnpm version patch"
package/dist/index.d.mts DELETED
@@ -1,434 +0,0 @@
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 };