@h3ravel/hashing 0.1.15 → 0.2.0-alpha.10
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 +30 -26
- package/dist/index.d.ts +51 -107
- package/dist/index.js +17 -17
- package/package.json +8 -5
- package/dist/app.globals.d.ts +0 -7
package/dist/index.cjs
CHANGED
|
@@ -6,12 +6,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
return to;
|
|
17
21
|
};
|
|
@@ -21,15 +25,18 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
25
|
}) : target, mod));
|
|
22
26
|
|
|
23
27
|
//#endregion
|
|
28
|
+
let __h3ravel_contracts = require("@h3ravel/contracts");
|
|
24
29
|
let __h3ravel_support = require("@h3ravel/support");
|
|
25
30
|
let argon2 = require("argon2");
|
|
26
31
|
argon2 = __toESM(argon2);
|
|
27
|
-
let
|
|
28
|
-
crypto =
|
|
32
|
+
let __h3ravel_shared = require("@h3ravel/shared");
|
|
33
|
+
let crypto$1 = require("crypto");
|
|
34
|
+
crypto$1 = __toESM(crypto$1);
|
|
29
35
|
let node_path = require("node:path");
|
|
30
36
|
node_path = __toESM(node_path);
|
|
31
37
|
let node_fs = require("node:fs");
|
|
32
|
-
let
|
|
38
|
+
let __h3ravel_foundation = require("@h3ravel/foundation");
|
|
39
|
+
let __h3ravel_support_facades = require("@h3ravel/support/facades");
|
|
33
40
|
|
|
34
41
|
//#region src/Utils/ParseInfo.ts
|
|
35
42
|
var ParseInfo = class {
|
|
@@ -61,7 +68,7 @@ var ParseInfo = class {
|
|
|
61
68
|
|
|
62
69
|
//#endregion
|
|
63
70
|
//#region src/Drivers/AbstractHasher.ts
|
|
64
|
-
var AbstractHasher = class {
|
|
71
|
+
var AbstractHasher = class extends __h3ravel_contracts.IAbstractHasher {
|
|
65
72
|
/**
|
|
66
73
|
* Get information about the given hashed value.
|
|
67
74
|
*
|
|
@@ -86,7 +93,7 @@ var AbstractHasher = class {
|
|
|
86
93
|
|
|
87
94
|
//#endregion
|
|
88
95
|
//#region src/Drivers/Argon2idHasher.ts
|
|
89
|
-
var Argon2idHasher = class extends AbstractHasher {
|
|
96
|
+
var Argon2idHasher = class extends (0, __h3ravel_shared.mix)(AbstractHasher, __h3ravel_contracts.IArgon2idHasher) {
|
|
90
97
|
memory = 65536;
|
|
91
98
|
verifyAlgorithm = true;
|
|
92
99
|
threads = 1;
|
|
@@ -194,7 +201,7 @@ var Argon2idHasher = class extends AbstractHasher {
|
|
|
194
201
|
|
|
195
202
|
//#endregion
|
|
196
203
|
//#region src/Drivers/ArgonHasher.ts
|
|
197
|
-
var ArgonHasher = class extends AbstractHasher {
|
|
204
|
+
var ArgonHasher = class extends (0, __h3ravel_shared.mix)(AbstractHasher, __h3ravel_contracts.IArgonHasher) {
|
|
198
205
|
memory = 65536;
|
|
199
206
|
verifyAlgorithm = true;
|
|
200
207
|
threads = 1;
|
|
@@ -321,7 +328,7 @@ function randomBytes(len) {
|
|
|
321
328
|
return crypto.getRandomValues(new Uint8Array(len));
|
|
322
329
|
} catch {}
|
|
323
330
|
try {
|
|
324
|
-
return crypto.default.randomBytes(len);
|
|
331
|
+
return crypto$1.default.randomBytes(len);
|
|
325
332
|
} catch {}
|
|
326
333
|
if (!randomFallback) throw Error("Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative");
|
|
327
334
|
return randomFallback(len);
|
|
@@ -2195,7 +2202,7 @@ var bcryptjs_default = {
|
|
|
2195
2202
|
|
|
2196
2203
|
//#endregion
|
|
2197
2204
|
//#region src/Drivers/BcryptHasher.ts
|
|
2198
|
-
var BcryptHasher = class extends AbstractHasher {
|
|
2205
|
+
var BcryptHasher = class extends (0, __h3ravel_shared.mix)(AbstractHasher, __h3ravel_contracts.IBcryptHasher) {
|
|
2199
2206
|
rounds = 12;
|
|
2200
2207
|
verifyAlgorithm = true;
|
|
2201
2208
|
limit = null;
|
|
@@ -2301,8 +2308,9 @@ var BcryptHasher = class extends AbstractHasher {
|
|
|
2301
2308
|
|
|
2302
2309
|
//#endregion
|
|
2303
2310
|
//#region src/Utils/Manager.ts
|
|
2304
|
-
var Manager = class {
|
|
2311
|
+
var Manager = class extends __h3ravel_contracts.IBaseHashManager {
|
|
2305
2312
|
constructor(config = {}) {
|
|
2313
|
+
super();
|
|
2306
2314
|
this.config = config;
|
|
2307
2315
|
}
|
|
2308
2316
|
/**
|
|
@@ -2342,14 +2350,14 @@ var Manager = class {
|
|
|
2342
2350
|
if ((0, node_fs.existsSync)(tsPath)) if (process.env.NODE_ENV !== "production") {
|
|
2343
2351
|
this.config = (await import(tsPath)).default ?? {};
|
|
2344
2352
|
return this;
|
|
2345
|
-
} else throw new
|
|
2353
|
+
} else throw new __h3ravel_foundation.ConfigException("hashing.config.ts found in production without build step");
|
|
2346
2354
|
return this;
|
|
2347
2355
|
}
|
|
2348
2356
|
};
|
|
2349
2357
|
|
|
2350
2358
|
//#endregion
|
|
2351
2359
|
//#region src/HashManager.ts
|
|
2352
|
-
var HashManager = class extends Manager {
|
|
2360
|
+
var HashManager = class extends (0, __h3ravel_shared.mix)(Manager, __h3ravel_contracts.IHashManager) {
|
|
2353
2361
|
drivers = {};
|
|
2354
2362
|
/**
|
|
2355
2363
|
* Create an instance of the Bcrypt hash Driver.
|
|
@@ -2459,7 +2467,7 @@ const defineConfig = (config) => {
|
|
|
2459
2467
|
|
|
2460
2468
|
//#endregion
|
|
2461
2469
|
//#region src/Helpers.ts
|
|
2462
|
-
var Hash = class {
|
|
2470
|
+
var Hash = class Hash {
|
|
2463
2471
|
/**
|
|
2464
2472
|
* Hash the given value.
|
|
2465
2473
|
*
|
|
@@ -2528,11 +2536,11 @@ var Hash = class {
|
|
|
2528
2536
|
*
|
|
2529
2537
|
* @returns
|
|
2530
2538
|
*
|
|
2531
|
-
* @throws
|
|
2539
|
+
* @throws {RuntimeException}
|
|
2532
2540
|
*/
|
|
2533
2541
|
static driver() {
|
|
2534
|
-
if (typeof
|
|
2535
|
-
return
|
|
2542
|
+
if (typeof Hash === "undefined") throw new __h3ravel_support.RuntimeException("The Hash helper is only available on H3ravel, use the HashManager class instead.");
|
|
2543
|
+
return __h3ravel_support_facades.Hash;
|
|
2536
2544
|
}
|
|
2537
2545
|
};
|
|
2538
2546
|
|
|
@@ -2541,14 +2549,10 @@ var Hash = class {
|
|
|
2541
2549
|
/**
|
|
2542
2550
|
* Register HashManager.
|
|
2543
2551
|
*/
|
|
2544
|
-
var HashingServiceProvider = class {
|
|
2552
|
+
var HashingServiceProvider = class extends __h3ravel_support.ServiceProvider {
|
|
2545
2553
|
static priority = 991;
|
|
2546
|
-
constructor(app) {
|
|
2547
|
-
this.app = app;
|
|
2548
|
-
}
|
|
2549
2554
|
register() {
|
|
2550
2555
|
const manager = new HashManager(this.app.make("config").get("hashing"));
|
|
2551
|
-
globalThis.Hash = manager;
|
|
2552
2556
|
this.app.singleton("hash", () => {
|
|
2553
2557
|
return manager;
|
|
2554
2558
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,100 +1,43 @@
|
|
|
1
1
|
/// <reference path="./app.globals.d.ts" />
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
2
|
+
import * as _h3ravel_contracts0 from "@h3ravel/contracts";
|
|
3
|
+
import { HashAlgorithm, HashConfiguration, HashInfo, HashOptions, IAbstractHasher, IArgon2idHasher, IArgonHasher, IBaseHashManager, IBcryptHasher, IHashManager } from "@h3ravel/contracts";
|
|
4
|
+
import { ServiceProvider } from "@h3ravel/support";
|
|
5
|
+
|
|
64
6
|
//#region src/Drivers/AbstractHasher.d.ts
|
|
65
|
-
declare
|
|
7
|
+
declare class AbstractHasher extends IAbstractHasher {
|
|
66
8
|
/**
|
|
67
9
|
* Get information about the given hashed value.
|
|
68
10
|
*
|
|
69
11
|
* @param hashedValue
|
|
70
12
|
* @returns
|
|
71
13
|
*/
|
|
72
|
-
info(hashedValue: string):
|
|
14
|
+
info(hashedValue: string): HashInfo;
|
|
73
15
|
}
|
|
74
16
|
//#endregion
|
|
75
17
|
//#region src/Drivers/Argon2idHasher.d.ts
|
|
76
|
-
declare
|
|
18
|
+
declare const Argon2idHasher_base: typeof AbstractHasher & typeof IArgon2idHasher & (new (...args: any[]) => AbstractHasher & IArgon2idHasher);
|
|
19
|
+
declare class Argon2idHasher extends Argon2idHasher_base {
|
|
77
20
|
private memory;
|
|
78
21
|
private verifyAlgorithm;
|
|
79
22
|
private threads;
|
|
80
23
|
private time;
|
|
81
|
-
constructor(options?:
|
|
24
|
+
constructor(options?: HashConfiguration["argon"]);
|
|
82
25
|
/**
|
|
83
26
|
* Hash the given value using Argon2id.
|
|
84
27
|
*/
|
|
85
|
-
make(value: string, options?:
|
|
28
|
+
make(value: string, options?: HashConfiguration["argon"]): Promise<string>;
|
|
86
29
|
/**
|
|
87
30
|
* Check the given plain value against a hash.
|
|
88
31
|
*/
|
|
89
|
-
check(value: string, hashedValue?: string | null, _options?:
|
|
32
|
+
check(value: string, hashedValue?: string | null, _options?: HashConfiguration["argon"]): Promise<boolean>;
|
|
90
33
|
/**
|
|
91
34
|
* Get information about the given hashed value.
|
|
92
35
|
*/
|
|
93
|
-
info(hashedValue: string):
|
|
36
|
+
info(hashedValue: string): HashInfo;
|
|
94
37
|
/**
|
|
95
38
|
* Check if the given hash needs to be rehashed based on current options.
|
|
96
39
|
*/
|
|
97
|
-
needsRehash(hashedValue: string, options?:
|
|
40
|
+
needsRehash(hashedValue: string, options?: HashConfiguration["argon"]): boolean;
|
|
98
41
|
/**
|
|
99
42
|
* Verify that the hash configuration does not exceed the configured limits.
|
|
100
43
|
*/
|
|
@@ -114,28 +57,29 @@ declare class Argon2idHasher extends AbstractHasher {
|
|
|
114
57
|
}
|
|
115
58
|
//#endregion
|
|
116
59
|
//#region src/Drivers/ArgonHasher.d.ts
|
|
117
|
-
declare
|
|
60
|
+
declare const ArgonHasher_base: typeof AbstractHasher & typeof IArgonHasher & (new (...args: any[]) => AbstractHasher & IArgonHasher);
|
|
61
|
+
declare class ArgonHasher extends ArgonHasher_base {
|
|
118
62
|
private memory;
|
|
119
63
|
private verifyAlgorithm;
|
|
120
64
|
private threads;
|
|
121
65
|
private time;
|
|
122
|
-
constructor(options?:
|
|
66
|
+
constructor(options?: HashConfiguration["argon"]);
|
|
123
67
|
/**
|
|
124
68
|
* Hash the given value using Argon2i.
|
|
125
69
|
*/
|
|
126
|
-
make(value: string, options?:
|
|
70
|
+
make(value: string, options?: HashConfiguration["argon"]): Promise<string>;
|
|
127
71
|
/**
|
|
128
72
|
* Check the given plain value against a hash.
|
|
129
73
|
*/
|
|
130
|
-
check(value: string, hashedValue?: string | null, _options?:
|
|
74
|
+
check(value: string, hashedValue?: string | null, _options?: HashConfiguration["argon"]): Promise<boolean>;
|
|
131
75
|
/**
|
|
132
76
|
* Get information about the given hashed value.
|
|
133
77
|
*/
|
|
134
|
-
info(hashedValue: string):
|
|
78
|
+
info(hashedValue: string): HashInfo;
|
|
135
79
|
/**
|
|
136
80
|
* Check if the given hash needs to be rehashed based on current options.
|
|
137
81
|
*/
|
|
138
|
-
needsRehash(hashedValue: string, options?:
|
|
82
|
+
needsRehash(hashedValue: string, options?: HashConfiguration["argon"]): boolean;
|
|
139
83
|
/**
|
|
140
84
|
* Verify that the hash configuration does not exceed the configured limits.
|
|
141
85
|
*/
|
|
@@ -155,11 +99,12 @@ declare class ArgonHasher extends AbstractHasher {
|
|
|
155
99
|
}
|
|
156
100
|
//#endregion
|
|
157
101
|
//#region src/Drivers/BcryptHasher.d.ts
|
|
158
|
-
declare
|
|
102
|
+
declare const BcryptHasher_base: typeof AbstractHasher & typeof IBcryptHasher & (new (...args: any[]) => AbstractHasher & IBcryptHasher);
|
|
103
|
+
declare class BcryptHasher extends BcryptHasher_base {
|
|
159
104
|
private rounds;
|
|
160
105
|
private verifyAlgorithm;
|
|
161
106
|
private limit;
|
|
162
|
-
constructor(options?:
|
|
107
|
+
constructor(options?: HashConfiguration["bcrypt"]);
|
|
163
108
|
/**
|
|
164
109
|
* Hash the given value.
|
|
165
110
|
*
|
|
@@ -168,7 +113,7 @@ declare class BcryptHasher extends AbstractHasher {
|
|
|
168
113
|
*
|
|
169
114
|
* @return {String}
|
|
170
115
|
*/
|
|
171
|
-
make(value: string, options?:
|
|
116
|
+
make(value: string, options?: HashConfiguration["bcrypt"]): Promise<string>;
|
|
172
117
|
/**
|
|
173
118
|
* Check the given plain value against a hash.
|
|
174
119
|
*
|
|
@@ -177,7 +122,7 @@ declare class BcryptHasher extends AbstractHasher {
|
|
|
177
122
|
* @param options
|
|
178
123
|
* @returns
|
|
179
124
|
*/
|
|
180
|
-
check(value: string, hashedValue?: string | null, _options?:
|
|
125
|
+
check(value: string, hashedValue?: string | null, _options?: HashConfiguration["bcrypt"]): Promise<boolean>;
|
|
181
126
|
/**
|
|
182
127
|
* Get information about the given hashed value.
|
|
183
128
|
*
|
|
@@ -185,7 +130,7 @@ declare class BcryptHasher extends AbstractHasher {
|
|
|
185
130
|
*
|
|
186
131
|
* @return {Object}
|
|
187
132
|
*/
|
|
188
|
-
info(hashedValue: string):
|
|
133
|
+
info(hashedValue: string): HashInfo;
|
|
189
134
|
/**
|
|
190
135
|
* Check if the given hash has been hashed using the given options.
|
|
191
136
|
*
|
|
@@ -194,7 +139,7 @@ declare class BcryptHasher extends AbstractHasher {
|
|
|
194
139
|
*
|
|
195
140
|
* @return {Boolean}
|
|
196
141
|
*/
|
|
197
|
-
needsRehash(hashedValue: string, options?:
|
|
142
|
+
needsRehash(hashedValue: string, options?: HashConfiguration["bcrypt"]): boolean;
|
|
198
143
|
/**
|
|
199
144
|
* Verify the hashed value's options.
|
|
200
145
|
*
|
|
@@ -222,13 +167,13 @@ declare class BcryptHasher extends AbstractHasher {
|
|
|
222
167
|
* @param options
|
|
223
168
|
* @return int
|
|
224
169
|
*/
|
|
225
|
-
protected cost(options?:
|
|
170
|
+
protected cost(options?: HashConfiguration["bcrypt"]): number;
|
|
226
171
|
}
|
|
227
172
|
//#endregion
|
|
228
173
|
//#region src/Utils/Manager.d.ts
|
|
229
|
-
declare abstract class Manager {
|
|
230
|
-
config:
|
|
231
|
-
constructor(config?:
|
|
174
|
+
declare abstract class Manager extends IBaseHashManager {
|
|
175
|
+
config: HashConfiguration;
|
|
176
|
+
constructor(config?: HashConfiguration);
|
|
232
177
|
abstract driver(): BcryptHasher | ArgonHasher | Argon2idHasher;
|
|
233
178
|
createBcryptDriver?(): BcryptHasher;
|
|
234
179
|
createArgonDriver?(): ArgonHasher;
|
|
@@ -239,7 +184,7 @@ declare abstract class Manager {
|
|
|
239
184
|
* @return string
|
|
240
185
|
*/
|
|
241
186
|
getDefaultDriver(): HashAlgorithm;
|
|
242
|
-
protected createDriver(driver: HashAlgorithm): Argon2idHasher |
|
|
187
|
+
protected createDriver(driver: HashAlgorithm): Argon2idHasher | ArgonHasher | BcryptHasher;
|
|
243
188
|
/**
|
|
244
189
|
* Determine if a given string is already hashed.
|
|
245
190
|
*
|
|
@@ -256,7 +201,8 @@ declare abstract class Manager {
|
|
|
256
201
|
}
|
|
257
202
|
//#endregion
|
|
258
203
|
//#region src/HashManager.d.ts
|
|
259
|
-
declare
|
|
204
|
+
declare const HashManager_base: typeof Manager & typeof IHashManager & (new (...args: any[]) => Manager & IHashManager);
|
|
205
|
+
declare class HashManager extends HashManager_base {
|
|
260
206
|
private drivers;
|
|
261
207
|
/**
|
|
262
208
|
* Create an instance of the Bcrypt hash Driver.
|
|
@@ -284,14 +230,14 @@ declare class HashManager extends Manager {
|
|
|
284
230
|
*
|
|
285
231
|
* @returns
|
|
286
232
|
*/
|
|
287
|
-
make(value: string, options?:
|
|
233
|
+
make(value: string, options?: HashOptions): Promise<string>;
|
|
288
234
|
/**
|
|
289
235
|
* Get information about the given hashed value.
|
|
290
236
|
*
|
|
291
237
|
* @param hashedValue
|
|
292
238
|
* @returns
|
|
293
239
|
*/
|
|
294
|
-
info(hashedValue: string):
|
|
240
|
+
info(hashedValue: string): _h3ravel_contracts0.HashInfo;
|
|
295
241
|
/**
|
|
296
242
|
* Check the given plain value against a hash.
|
|
297
243
|
*
|
|
@@ -300,7 +246,7 @@ declare class HashManager extends Manager {
|
|
|
300
246
|
* @param options
|
|
301
247
|
* @returns
|
|
302
248
|
*/
|
|
303
|
-
check(value: string, hashedValue?: string, options?:
|
|
249
|
+
check(value: string, hashedValue?: string, options?: HashOptions): Promise<boolean>;
|
|
304
250
|
/**
|
|
305
251
|
* Check if the given hash has been hashed using the given options.
|
|
306
252
|
*
|
|
@@ -308,7 +254,7 @@ declare class HashManager extends Manager {
|
|
|
308
254
|
* @param options
|
|
309
255
|
* @returns
|
|
310
256
|
*/
|
|
311
|
-
needsRehash(hashedValue: string, options?:
|
|
257
|
+
needsRehash(hashedValue: string, options?: HashOptions): boolean;
|
|
312
258
|
/**
|
|
313
259
|
* Determine if a given string is already hashed.
|
|
314
260
|
*
|
|
@@ -334,9 +280,9 @@ declare class HashManager extends Manager {
|
|
|
334
280
|
*
|
|
335
281
|
* @throws InvalidArgumentException
|
|
336
282
|
*/
|
|
337
|
-
driver(driver?: HashAlgorithm): Argon2idHasher |
|
|
283
|
+
driver(driver?: HashAlgorithm): Argon2idHasher | ArgonHasher | BcryptHasher;
|
|
338
284
|
}
|
|
339
|
-
declare const defineConfig: (config:
|
|
285
|
+
declare const defineConfig: (config: HashConfiguration) => HashConfiguration;
|
|
340
286
|
//#endregion
|
|
341
287
|
//#region src/Helpers.d.ts
|
|
342
288
|
declare class Hash {
|
|
@@ -348,14 +294,14 @@ declare class Hash {
|
|
|
348
294
|
*
|
|
349
295
|
* @returns
|
|
350
296
|
*/
|
|
351
|
-
static make(value: string, options?:
|
|
297
|
+
static make(value: string, options?: HashOptions): Promise<string>;
|
|
352
298
|
/**
|
|
353
299
|
* Get information about the given hashed value.
|
|
354
300
|
*
|
|
355
301
|
* @param hashedValue
|
|
356
302
|
* @returns
|
|
357
303
|
*/
|
|
358
|
-
static info(hashedValue: string):
|
|
304
|
+
static info(hashedValue: string): _h3ravel_contracts0.HashInfo;
|
|
359
305
|
/**
|
|
360
306
|
* Check the given plain value against a hash.
|
|
361
307
|
*
|
|
@@ -364,7 +310,7 @@ declare class Hash {
|
|
|
364
310
|
* @param options
|
|
365
311
|
* @returns
|
|
366
312
|
*/
|
|
367
|
-
static check(value: string, hashedValue?: string, options?:
|
|
313
|
+
static check(value: string, hashedValue?: string, options?: HashOptions): Promise<boolean>;
|
|
368
314
|
/**
|
|
369
315
|
* Check if the given hash has been hashed using the given options.
|
|
370
316
|
*
|
|
@@ -372,14 +318,14 @@ declare class Hash {
|
|
|
372
318
|
* @param options
|
|
373
319
|
* @returns
|
|
374
320
|
*/
|
|
375
|
-
static needsRehash(hashedValue: string, options?:
|
|
321
|
+
static needsRehash(hashedValue: string, options?: HashOptions): boolean;
|
|
376
322
|
/**
|
|
377
323
|
* Determine if a given string is already hashed.
|
|
378
324
|
*
|
|
379
325
|
* @param string value
|
|
380
326
|
* @returns
|
|
381
327
|
*/
|
|
382
|
-
static isHashed(value: string):
|
|
328
|
+
static isHashed(value: string): boolean;
|
|
383
329
|
/**
|
|
384
330
|
* Verifies that the configuration is less than or equal to what is configured.
|
|
385
331
|
*
|
|
@@ -388,7 +334,7 @@ declare class Hash {
|
|
|
388
334
|
*
|
|
389
335
|
* @internal
|
|
390
336
|
*/
|
|
391
|
-
static verifyConfiguration(value: string):
|
|
337
|
+
static verifyConfiguration(value: string): boolean;
|
|
392
338
|
/**
|
|
393
339
|
* Get a driver instance.
|
|
394
340
|
*
|
|
@@ -396,19 +342,17 @@ declare class Hash {
|
|
|
396
342
|
*
|
|
397
343
|
* @returns
|
|
398
344
|
*
|
|
399
|
-
* @throws
|
|
345
|
+
* @throws {RuntimeException}
|
|
400
346
|
*/
|
|
401
|
-
static driver():
|
|
347
|
+
static driver(): IHashManager;
|
|
402
348
|
}
|
|
403
349
|
//#endregion
|
|
404
350
|
//#region src/Providers/HashingServiceProvider.d.ts
|
|
405
351
|
/**
|
|
406
352
|
* Register HashManager.
|
|
407
353
|
*/
|
|
408
|
-
declare class HashingServiceProvider {
|
|
409
|
-
private app;
|
|
354
|
+
declare class HashingServiceProvider extends ServiceProvider {
|
|
410
355
|
static priority: number;
|
|
411
|
-
constructor(app: any);
|
|
412
356
|
register(): void;
|
|
413
357
|
}
|
|
414
358
|
//#endregion
|
|
@@ -428,7 +372,7 @@ declare class ParseInfo {
|
|
|
428
372
|
timeCost?: number | undefined;
|
|
429
373
|
threads?: number | undefined;
|
|
430
374
|
};
|
|
431
|
-
static bcrypt(hashed: string):
|
|
375
|
+
static bcrypt(hashed: string): HashInfo['options'];
|
|
432
376
|
}
|
|
433
377
|
//#endregion
|
|
434
|
-
export { AbstractHasher,
|
|
378
|
+
export { AbstractHasher, Argon2idHasher, ArgonHasher, BcryptHasher, Hash, HashManager, HashingServiceProvider, Manager, ParseInfo, defineConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IAbstractHasher, IArgon2idHasher, IArgonHasher, IBaseHashManager, IBcryptHasher, IHashManager } from "@h3ravel/contracts";
|
|
2
|
+
import { InvalidArgumentException, RuntimeException, ServiceProvider, Str } from "@h3ravel/support";
|
|
2
3
|
import argon from "argon2";
|
|
4
|
+
import { mix } from "@h3ravel/shared";
|
|
3
5
|
import nodeCrypto from "crypto";
|
|
4
6
|
import path from "node:path";
|
|
5
7
|
import { existsSync } from "node:fs";
|
|
6
|
-
import { ConfigException } from "@h3ravel/
|
|
8
|
+
import { ConfigException } from "@h3ravel/foundation";
|
|
9
|
+
import { Hash as Hash$1 } from "@h3ravel/support/facades";
|
|
7
10
|
|
|
8
11
|
//#region src/Utils/ParseInfo.ts
|
|
9
12
|
var ParseInfo = class {
|
|
@@ -35,7 +38,7 @@ var ParseInfo = class {
|
|
|
35
38
|
|
|
36
39
|
//#endregion
|
|
37
40
|
//#region src/Drivers/AbstractHasher.ts
|
|
38
|
-
var AbstractHasher = class {
|
|
41
|
+
var AbstractHasher = class extends IAbstractHasher {
|
|
39
42
|
/**
|
|
40
43
|
* Get information about the given hashed value.
|
|
41
44
|
*
|
|
@@ -60,7 +63,7 @@ var AbstractHasher = class {
|
|
|
60
63
|
|
|
61
64
|
//#endregion
|
|
62
65
|
//#region src/Drivers/Argon2idHasher.ts
|
|
63
|
-
var Argon2idHasher = class extends AbstractHasher {
|
|
66
|
+
var Argon2idHasher = class extends mix(AbstractHasher, IArgon2idHasher) {
|
|
64
67
|
memory = 65536;
|
|
65
68
|
verifyAlgorithm = true;
|
|
66
69
|
threads = 1;
|
|
@@ -168,7 +171,7 @@ var Argon2idHasher = class extends AbstractHasher {
|
|
|
168
171
|
|
|
169
172
|
//#endregion
|
|
170
173
|
//#region src/Drivers/ArgonHasher.ts
|
|
171
|
-
var ArgonHasher = class extends AbstractHasher {
|
|
174
|
+
var ArgonHasher = class extends mix(AbstractHasher, IArgonHasher) {
|
|
172
175
|
memory = 65536;
|
|
173
176
|
verifyAlgorithm = true;
|
|
174
177
|
threads = 1;
|
|
@@ -2169,7 +2172,7 @@ var bcryptjs_default = {
|
|
|
2169
2172
|
|
|
2170
2173
|
//#endregion
|
|
2171
2174
|
//#region src/Drivers/BcryptHasher.ts
|
|
2172
|
-
var BcryptHasher = class extends AbstractHasher {
|
|
2175
|
+
var BcryptHasher = class extends mix(AbstractHasher, IBcryptHasher) {
|
|
2173
2176
|
rounds = 12;
|
|
2174
2177
|
verifyAlgorithm = true;
|
|
2175
2178
|
limit = null;
|
|
@@ -2275,8 +2278,9 @@ var BcryptHasher = class extends AbstractHasher {
|
|
|
2275
2278
|
|
|
2276
2279
|
//#endregion
|
|
2277
2280
|
//#region src/Utils/Manager.ts
|
|
2278
|
-
var Manager = class {
|
|
2281
|
+
var Manager = class extends IBaseHashManager {
|
|
2279
2282
|
constructor(config = {}) {
|
|
2283
|
+
super();
|
|
2280
2284
|
this.config = config;
|
|
2281
2285
|
}
|
|
2282
2286
|
/**
|
|
@@ -2323,7 +2327,7 @@ var Manager = class {
|
|
|
2323
2327
|
|
|
2324
2328
|
//#endregion
|
|
2325
2329
|
//#region src/HashManager.ts
|
|
2326
|
-
var HashManager = class extends Manager {
|
|
2330
|
+
var HashManager = class extends mix(Manager, IHashManager) {
|
|
2327
2331
|
drivers = {};
|
|
2328
2332
|
/**
|
|
2329
2333
|
* Create an instance of the Bcrypt hash Driver.
|
|
@@ -2433,7 +2437,7 @@ const defineConfig = (config) => {
|
|
|
2433
2437
|
|
|
2434
2438
|
//#endregion
|
|
2435
2439
|
//#region src/Helpers.ts
|
|
2436
|
-
var Hash = class {
|
|
2440
|
+
var Hash = class Hash {
|
|
2437
2441
|
/**
|
|
2438
2442
|
* Hash the given value.
|
|
2439
2443
|
*
|
|
@@ -2502,11 +2506,11 @@ var Hash = class {
|
|
|
2502
2506
|
*
|
|
2503
2507
|
* @returns
|
|
2504
2508
|
*
|
|
2505
|
-
* @throws
|
|
2509
|
+
* @throws {RuntimeException}
|
|
2506
2510
|
*/
|
|
2507
2511
|
static driver() {
|
|
2508
|
-
if (typeof
|
|
2509
|
-
return
|
|
2512
|
+
if (typeof Hash === "undefined") throw new RuntimeException("The Hash helper is only available on H3ravel, use the HashManager class instead.");
|
|
2513
|
+
return Hash$1;
|
|
2510
2514
|
}
|
|
2511
2515
|
};
|
|
2512
2516
|
|
|
@@ -2515,14 +2519,10 @@ var Hash = class {
|
|
|
2515
2519
|
/**
|
|
2516
2520
|
* Register HashManager.
|
|
2517
2521
|
*/
|
|
2518
|
-
var HashingServiceProvider = class {
|
|
2522
|
+
var HashingServiceProvider = class extends ServiceProvider {
|
|
2519
2523
|
static priority = 991;
|
|
2520
|
-
constructor(app) {
|
|
2521
|
-
this.app = app;
|
|
2522
|
-
}
|
|
2523
2524
|
register() {
|
|
2524
2525
|
const manager = new HashManager(this.app.make("config").get("hashing"));
|
|
2525
|
-
globalThis.Hash = manager;
|
|
2526
2526
|
this.app.singleton("hash", () => {
|
|
2527
2527
|
return manager;
|
|
2528
2528
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h3ravel/hashing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-alpha.10",
|
|
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": [
|
|
@@ -48,8 +48,10 @@
|
|
|
48
48
|
"typescript": "^5.4.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@h3ravel/
|
|
52
|
-
"@h3ravel/
|
|
51
|
+
"@h3ravel/core": "^1.22.0-alpha.10",
|
|
52
|
+
"@h3ravel/foundation": "^0.1.0-alpha.10",
|
|
53
|
+
"@h3ravel/shared": "^0.29.0-alpha.10",
|
|
54
|
+
"@h3ravel/support": "^0.17.0-alpha.10"
|
|
53
55
|
},
|
|
54
56
|
"peerDependenciesMeta": {
|
|
55
57
|
"@h3ravel/core": {
|
|
@@ -57,10 +59,11 @@
|
|
|
57
59
|
}
|
|
58
60
|
},
|
|
59
61
|
"dependencies": {
|
|
60
|
-
"argon2": "^0.44.0"
|
|
62
|
+
"argon2": "^0.44.0",
|
|
63
|
+
"@h3ravel/contracts": "^0.29.0-alpha.10",
|
|
64
|
+
"@h3ravel/foundation": "^0.1.0-alpha.10"
|
|
61
65
|
},
|
|
62
66
|
"scripts": {
|
|
63
|
-
"barrel": "barrelsby --directory src --delete --singleQuotes",
|
|
64
67
|
"build": "tsdown --config-loader unconfig",
|
|
65
68
|
"dev": "tsx watch src/index.ts",
|
|
66
69
|
"start": "node dist/index.js",
|