@veloxts/auth 0.3.3 → 0.3.5

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.
Files changed (66) hide show
  1. package/README.md +1157 -30
  2. package/dist/__integration__/fixtures.d.ts +41 -0
  3. package/dist/__integration__/fixtures.d.ts.map +1 -0
  4. package/dist/__integration__/fixtures.js +79 -0
  5. package/dist/__integration__/fixtures.js.map +1 -0
  6. package/dist/__integration__/setup.d.ts +26 -0
  7. package/dist/__integration__/setup.d.ts.map +1 -0
  8. package/dist/__integration__/setup.js +28 -0
  9. package/dist/__integration__/setup.js.map +1 -0
  10. package/dist/adapter.d.ts +710 -0
  11. package/dist/adapter.d.ts.map +1 -0
  12. package/dist/adapter.js +581 -0
  13. package/dist/adapter.js.map +1 -0
  14. package/dist/adapters/better-auth.d.ts +271 -0
  15. package/dist/adapters/better-auth.d.ts.map +1 -0
  16. package/dist/adapters/better-auth.js +341 -0
  17. package/dist/adapters/better-auth.js.map +1 -0
  18. package/dist/adapters/index.d.ts +28 -0
  19. package/dist/adapters/index.d.ts.map +1 -0
  20. package/dist/adapters/index.js +28 -0
  21. package/dist/adapters/index.js.map +1 -0
  22. package/dist/csrf.d.ts +300 -0
  23. package/dist/csrf.d.ts.map +1 -0
  24. package/dist/csrf.js +402 -0
  25. package/dist/csrf.js.map +1 -0
  26. package/dist/guards.d.ts +142 -0
  27. package/dist/guards.d.ts.map +1 -0
  28. package/dist/guards.js +259 -0
  29. package/dist/guards.js.map +1 -0
  30. package/dist/hash.d.ts +91 -0
  31. package/dist/hash.d.ts.map +1 -0
  32. package/dist/hash.js +236 -0
  33. package/dist/hash.js.map +1 -0
  34. package/dist/index.d.ts +27 -32
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +94 -36
  37. package/dist/index.js.map +1 -1
  38. package/dist/jwt.d.ts +157 -0
  39. package/dist/jwt.d.ts.map +1 -0
  40. package/dist/jwt.js +489 -0
  41. package/dist/jwt.js.map +1 -0
  42. package/dist/middleware.d.ts +99 -0
  43. package/dist/middleware.d.ts.map +1 -0
  44. package/dist/middleware.js +253 -0
  45. package/dist/middleware.js.map +1 -0
  46. package/dist/plugin.d.ts +125 -0
  47. package/dist/plugin.d.ts.map +1 -0
  48. package/dist/plugin.js +193 -0
  49. package/dist/plugin.js.map +1 -0
  50. package/dist/policies.d.ts +137 -0
  51. package/dist/policies.d.ts.map +1 -0
  52. package/dist/policies.js +240 -0
  53. package/dist/policies.js.map +1 -0
  54. package/dist/rate-limit.d.ts +231 -0
  55. package/dist/rate-limit.d.ts.map +1 -0
  56. package/dist/rate-limit.js +352 -0
  57. package/dist/rate-limit.js.map +1 -0
  58. package/dist/session.d.ts +500 -0
  59. package/dist/session.d.ts.map +1 -0
  60. package/dist/session.js +801 -0
  61. package/dist/session.js.map +1 -0
  62. package/dist/types.d.ts +261 -0
  63. package/dist/types.d.ts.map +1 -0
  64. package/dist/types.js +33 -0
  65. package/dist/types.js.map +1 -0
  66. package/package.json +61 -7
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csrf.js","sourceRoot":"","sources":["../src/csrf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AA0BvE,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,kBAAkB,GAAG,IAAI,CAAC,CAAC,SAAS;AAC1C,MAAM,mBAAmB,GAAG,cAAc,CAAC;AAC3C,MAAM,kBAAkB,GAAG,OAAO,CAAC;AACnC,MAAM,mBAAmB,GAAG,YAAY,CAAC;AACzC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAC;AAkBjE;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,K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K,CAAC;wBACjD,KAAK;qBACN;iBACF;aACF,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,SAAS,OAAO;QAMd,OAAO,KAAK,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE;YAC7B,MAAM,KAAK,GAAG,GAAG,CAAC,KAA2C,CAAC;YAE9D,OAAO,IAAI,CAAC;gBACV,GAAG,EAAE;oBACH,GAAG,GAAG;oBACN,IAAI,EAAE;wBACJ,aAAa,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC;wBACjD,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,SAAS;qBACtD;iBACF;aACF,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IAED,OAAO;QACL,4BAA4B;QAC5B,OAAO;QACP,+CAA+C;QAC/C,OAAO;QACP,kDAAkD;QAClD,OAAO;QACP,8BAA8B;QAC9B,aAAa,EAAE,CAAC,KAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC;QAC/E,8BAA8B;QAC9B,aAAa,EAAE,CAAC,OAAkC,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC;QACrF,wBAAwB;QACxB,WAAW,EAAE,CAAC,KAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC;KAC5E,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,cAAc,CAAC"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Authorization guards for @veloxts/auth
3
+ * @module auth/guards
4
+ */
5
+ import type { FastifyReply, FastifyRequest } from 'fastify';
6
+ import type { AuthContext, GuardDefinition, GuardFunction, User } from './types.js';
7
+ /**
8
+ * Creates a guard definition from a check function
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const isAdmin = defineGuard({
13
+ * name: 'isAdmin',
14
+ * check: (ctx) => ctx.user?.role === 'admin',
15
+ * message: 'Admin access required',
16
+ * });
17
+ * ```
18
+ */
19
+ export declare function defineGuard<TContext = unknown>(definition: GuardDefinition<TContext>): GuardDefinition<TContext>;
20
+ /**
21
+ * Creates a simple guard from a check function
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const isActive = guard('isActive', (ctx) => ctx.user?.status === 'active');
26
+ * ```
27
+ */
28
+ export declare function guard<TContext = unknown>(name: string, check: GuardFunction<TContext>): GuardDefinition<TContext>;
29
+ /**
30
+ * Guard that requires authentication
31
+ * Rejects requests without a valid user
32
+ */
33
+ export declare const authenticated: GuardDefinition<{
34
+ auth?: AuthContext;
35
+ }>;
36
+ /**
37
+ * Guard that requires a verified email
38
+ */
39
+ export declare const emailVerified: GuardDefinition<{
40
+ user?: User;
41
+ }>;
42
+ /**
43
+ * Creates a guard that checks if user has a specific role
44
+ *
45
+ * Checks if the user has ANY of the specified roles.
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const adminOnly = hasRole('admin');
50
+ * const moderatorOrAdmin = hasRole(['admin', 'moderator']);
51
+ *
52
+ * // User with multiple roles
53
+ * const user = { id: '1', email: 'a@b.com', roles: ['editor', 'moderator'] };
54
+ * hasRole('moderator') // passes - user has 'moderator' role
55
+ * hasRole(['admin', 'editor']) // passes - user has 'editor' role
56
+ * ```
57
+ */
58
+ export declare function hasRole(roles: string | string[]): GuardDefinition<{
59
+ user?: User;
60
+ }>;
61
+ /**
62
+ * Creates a guard that checks if user has specific permissions
63
+ *
64
+ * Requires ALL specified permissions (AND logic).
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const canEdit = hasPermission('posts.edit');
69
+ * const canManageUsers = hasPermission(['users.create', 'users.delete']);
70
+ * ```
71
+ */
72
+ export declare function hasPermission(permissions: string | string[]): GuardDefinition<{
73
+ user?: User;
74
+ }>;
75
+ /**
76
+ * Creates a guard that checks if user has ANY of the specified permissions
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const canViewOrEdit = hasAnyPermission(['posts.view', 'posts.edit']);
81
+ * ```
82
+ */
83
+ export declare function hasAnyPermission(permissions: string[]): GuardDefinition<{
84
+ user?: User;
85
+ }>;
86
+ /**
87
+ * Creates a guard that checks a custom condition on the user
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const isPremium = userCan((user) => user.subscription === 'premium');
92
+ * ```
93
+ */
94
+ export declare function userCan(check: (user: User) => boolean | Promise<boolean>, name?: string): GuardDefinition<{
95
+ user?: User;
96
+ }>;
97
+ /**
98
+ * Creates a guard that combines multiple guards with AND logic
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const adminWithPermission = allOf([hasRole('admin'), hasPermission('users.delete')]);
103
+ * ```
104
+ */
105
+ export declare function allOf<TContext = unknown>(guards: GuardDefinition<TContext>[]): GuardDefinition<TContext>;
106
+ /**
107
+ * Creates a guard that passes if ANY of the guards pass
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * const adminOrModerator = anyOf([hasRole('admin'), hasRole('moderator')]);
112
+ * ```
113
+ */
114
+ export declare function anyOf<TContext = unknown>(guards: GuardDefinition<TContext>[]): GuardDefinition<TContext>;
115
+ /**
116
+ * Creates a guard that inverts another guard
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * const notAdmin = not(hasRole('admin'));
121
+ * ```
122
+ */
123
+ export declare function not<TContext = unknown>(guard: GuardDefinition<TContext>): GuardDefinition<TContext>;
124
+ /**
125
+ * Executes a guard and returns the result
126
+ */
127
+ export declare function executeGuard<TContext>(guard: GuardDefinition<TContext>, ctx: TContext, request: FastifyRequest, reply: FastifyReply): Promise<{
128
+ passed: boolean;
129
+ message?: string;
130
+ statusCode?: number;
131
+ }>;
132
+ /**
133
+ * Executes multiple guards in sequence
134
+ * Returns on first failure
135
+ */
136
+ export declare function executeGuards<TContext>(guards: GuardDefinition<TContext>[], ctx: TContext, request: FastifyRequest, reply: FastifyReply): Promise<{
137
+ passed: boolean;
138
+ failedGuard?: string;
139
+ message?: string;
140
+ statusCode?: number;
141
+ }>;
142
+ //# sourceMappingURL=guards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAMpF;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,QAAQ,GAAG,OAAO,EAC5C,UAAU,EAAE,eAAe,CAAC,QAAQ,CAAC,GACpC,eAAe,CAAC,QAAQ,CAAC,CAK3B;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,QAAQ,GAAG,OAAO,EACtC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC,GAC7B,eAAe,CAAC,QAAQ,CAAC,CAE3B;AAMD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC;IAAE,IAAI,CAAC,EAAE,WAAW,CAAA;CAAE,CAKhE,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC;IAAE,IAAI,CAAC,EAAE,IAAI,CAAA;CAAE,CAKzD,CAAC;AAEH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,eAAe,CAAC;IAAE,IAAI,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC,CAclF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,eAAe,CAAC;IAAE,IAAI,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC,CAc9F;AAED;;;;;;;GAOG;AACH,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K,EAAE,YAAY,GAClB,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAc3F"}
package/dist/guards.js ADDED
@@ -0,0 +1,259 @@
1
+ /**
2
+ * Authorization guards for @veloxts/auth
3
+ * @module auth/guards
4
+ */
5
+ // ============================================================================
6
+ // Guard Factory
7
+ // ============================================================================
8
+ /**
9
+ * Creates a guard definition from a check function
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const isAdmin = defineGuard({
14
+ * name: 'isAdmin',
15
+ * check: (ctx) => ctx.user?.role === 'admin',
16
+ * message: 'Admin access required',
17
+ * });
18
+ * ```
19
+ */
20
+ export function defineGuard(definition) {
21
+ return {
22
+ statusCode: 403,
23
+ ...definition,
24
+ };
25
+ }
26
+ /**
27
+ * Creates a simple guard from a check function
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const isActive = guard('isActive', (ctx) => ctx.user?.status === 'active');
32
+ * ```
33
+ */
34
+ export function guard(name, check) {
35
+ return defineGuard({ name, check });
36
+ }
37
+ // ============================================================================
38
+ // Built-in Guards
39
+ // ============================================================================
40
+ /**
41
+ * Guard that requires authentication
42
+ * Rejects requests without a valid user
43
+ */
44
+ export const authenticated = defineGuard({
45
+ name: 'authenticated',
46
+ check: (ctx) => ctx.auth?.isAuthenticated === true,
47
+ message: 'Authentication required',
48
+ statusCode: 401,
49
+ });
50
+ /**
51
+ * Guard that requires a verified email
52
+ */
53
+ export const emailVerified = defineGuard({
54
+ name: 'emailVerified',
55
+ check: (ctx) => ctx.user?.emailVerified === true,
56
+ message: 'Email verification required',
57
+ statusCode: 403,
58
+ });
59
+ /**
60
+ * Creates a guard that checks if user has a specific role
61
+ *
62
+ * Checks if the user has ANY of the specified roles.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const adminOnly = hasRole('admin');
67
+ * const moderatorOrAdmin = hasRole(['admin', 'moderator']);
68
+ *
69
+ * // User with multiple roles
70
+ * const user = { id: '1', email: 'a@b.com', roles: ['editor', 'moderator'] };
71
+ * hasRole('moderator') // passes - user has 'moderator' role
72
+ * hasRole(['admin', 'editor']) // passes - user has 'editor' role
73
+ * ```
74
+ */
75
+ export function hasRole(roles) {
76
+ const requiredRoles = Array.isArray(roles) ? roles : [roles];
77
+ return defineGuard({
78
+ name: `hasRole:${requiredRoles.join(',')}`,
79
+ check: (ctx) => {
80
+ const userRoles = ctx.user?.roles;
81
+ if (!Array.isArray(userRoles) || userRoles.length === 0) {
82
+ return false;
83
+ }
84
+ return requiredRoles.some((role) => userRoles.includes(role));
85
+ },
86
+ message: `Required role: ${requiredRoles.join(' or ')}`,
87
+ });
88
+ }
89
+ /**
90
+ * Creates a guard that checks if user has specific permissions
91
+ *
92
+ * Requires ALL specified permissions (AND logic).
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const canEdit = hasPermission('posts.edit');
97
+ * const canManageUsers = hasPermission(['users.create', 'users.delete']);
98
+ * ```
99
+ */
100
+ export function hasPermission(permissions) {
101
+ const required = Array.isArray(permissions) ? permissions : [permissions];
102
+ return defineGuard({
103
+ name: `hasPermission:${required.join(',')}`,
104
+ check: (ctx) => {
105
+ const userPermissions = ctx.user?.permissions;
106
+ if (!Array.isArray(userPermissions)) {
107
+ return false;
108
+ }
109
+ return required.every((p) => userPermissions.includes(p));
110
+ },
111
+ message: `Required permissions: ${required.join(', ')}`,
112
+ });
113
+ }
114
+ /**
115
+ * Creates a guard that checks if user has ANY of the specified permissions
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * const canViewOrEdit = hasAnyPermission(['posts.view', 'posts.edit']);
120
+ * ```
121
+ */
122
+ export function hasAnyPermission(permissions) {
123
+ return defineGuard({
124
+ name: `hasAnyPermission:${permissions.join(',')}`,
125
+ check: (ctx) => {
126
+ const userPermissions = ctx.user?.permissions;
127
+ if (!Array.isArray(userPermissions)) {
128
+ return false;
129
+ }
130
+ return permissions.some((p) => userPermissions.includes(p));
131
+ },
132
+ message: `Required one of: ${permissions.join(', ')}`,
133
+ });
134
+ }
135
+ /**
136
+ * Creates a guard that checks a custom condition on the user
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * const isPremium = userCan((user) => user.subscription === 'premium');
141
+ * ```
142
+ */
143
+ export function userCan(check, name = 'custom') {
144
+ return defineGuard({
145
+ name: `userCan:${name}`,
146
+ check: async (ctx) => {
147
+ if (!ctx.user) {
148
+ return false;
149
+ }
150
+ return check(ctx.user);
151
+ },
152
+ });
153
+ }
154
+ /**
155
+ * Creates a guard that combines multiple guards with AND logic
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const adminWithPermission = allOf([hasRole('admin'), hasPermission('users.delete')]);
160
+ * ```
161
+ */
162
+ export function allOf(guards) {
163
+ return defineGuard({
164
+ name: `allOf:${guards.map((g) => g.name).join(',')}`,
165
+ check: async (ctx, request, reply) => {
166
+ for (const guard of guards) {
167
+ const result = await guard.check(ctx, request, reply);
168
+ if (!result) {
169
+ return false;
170
+ }
171
+ }
172
+ return true;
173
+ },
174
+ message: `All conditions required: ${guards.map((g) => g.name).join(', ')}`,
175
+ });
176
+ }
177
+ /**
178
+ * Creates a guard that passes if ANY of the guards pass
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * const adminOrModerator = anyOf([hasRole('admin'), hasRole('moderator')]);
183
+ * ```
184
+ */
185
+ export function anyOf(guards) {
186
+ return defineGuard({
187
+ name: `anyOf:${guards.map((g) => g.name).join(',')}`,
188
+ check: async (ctx, request, reply) => {
189
+ for (const guard of guards) {
190
+ const result = await guard.check(ctx, request, reply);
191
+ if (result) {
192
+ return true;
193
+ }
194
+ }
195
+ return false;
196
+ },
197
+ message: `One of required: ${guards.map((g) => g.name).join(', ')}`,
198
+ });
199
+ }
200
+ /**
201
+ * Creates a guard that inverts another guard
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * const notAdmin = not(hasRole('admin'));
206
+ * ```
207
+ */
208
+ export function not(guard) {
209
+ return defineGuard({
210
+ name: `not:${guard.name}`,
211
+ check: async (ctx, request, reply) => {
212
+ const result = await guard.check(ctx, request, reply);
213
+ return !result;
214
+ },
215
+ message: `Condition must not be met: ${guard.name}`,
216
+ });
217
+ }
218
+ // ============================================================================
219
+ // Guard Execution
220
+ // ============================================================================
221
+ /**
222
+ * Executes a guard and returns the result
223
+ */
224
+ export async function executeGuard(guard, ctx, request, reply) {
225
+ try {
226
+ const passed = await guard.check(ctx, request, reply);
227
+ return {
228
+ passed,
229
+ message: passed ? undefined : guard.message,
230
+ statusCode: passed ? undefined : guard.statusCode,
231
+ };
232
+ }
233
+ catch (error) {
234
+ return {
235
+ passed: false,
236
+ message: error instanceof Error ? error.message : 'Guard check failed',
237
+ statusCode: 500,
238
+ };
239
+ }
240
+ }
241
+ /**
242
+ * Executes multiple guards in sequence
243
+ * Returns on first failure
244
+ */
245
+ export async function executeGuards(guards, ctx, request, reply) {
246
+ for (const guard of guards) {
247
+ const result = await executeGuard(guard, ctx, request, reply);
248
+ if (!result.passed) {
249
+ return {
250
+ passed: false,
251
+ failedGuard: guard.name,
252
+ message: result.message,
253
+ statusCode: result.statusCode,
254
+ };
255
+ }
256
+ }
257
+ return { passed: true };
258
+ }
259
+ //# sourceMappingURL=guards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards.js","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,+EAA+E;AAC/E,gBAAgB;AAChB,+EAA+E;AAE/E;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CACzB,UAAqC;IAErC,OAAO;QACL,UAAU,EAAE,GAAG;QACf,GAAG,UAAU;KACd,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,KAAK,CACnB,IAAY,EACZ,KAA8B;IAE9B,OAAO,WAAW,CAAC,EAAE,IAAI,EAAE,KAAK,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 import type { HashConfig } from './types.js';
6
+ /**
7
+ * Password hasher with configurable algorithms
8
+ *
9
+ * Supports bcrypt and argon2 algorithms. Falls back to scrypt-based
10
+ * implementation when native modules are not available.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const hasher = new PasswordHasher({ algorithm: 'bcrypt', bcryptRounds: 12 });
15
+ *
16
+ * // Hash a password
17
+ * const hash = await hasher.hash('mypassword123');
18
+ *
19
+ * // Verify a password
20
+ * const isValid = await hasher.verify('mypassword123', hash);
21
+ * ```
22
+ */
23
+ export declare class PasswordHasher {
24
+ private readonly config;
25
+ private bcrypt;
26
+ private argon2;
27
+ constructor(config?: HashConfig);
28
+ /**
29
+ * Lazily load bcrypt module
30
+ */
31
+ private loadBcrypt;
32
+ /**
33
+ * Lazily load argon2 module
34
+ */
35
+ private loadArgon2;
36
+ /**
37
+ * Hash a password using the configured algorithm
38
+ */
39
+ hash(password: string): Promise<string>;
40
+ /**
41
+ * Verify a password against a hash
42
+ */
43
+ verify(password: string, hash: string): Promise<boolean>;
44
+ /**
45
+ * Hash using bcrypt
46
+ */
47
+ private hashWithBcrypt;
48
+ /**
49
+ * Verify using bcrypt
50
+ */
51
+ private verifyWithBcrypt;
52
+ /**
53
+ * Hash using argon2
54
+ */
55
+ private hashWithArgon2;
56
+ /**
57
+ * Verify using argon2
58
+ */
59
+ private verifyWithArgon2;
60
+ /**
61
+ * Hash using Node.js built-in scrypt (fallback)
62
+ */
63
+ private hashWithScrypt;
64
+ /**
65
+ * Verify using scrypt
66
+ */
67
+ private verifyWithScrypt;
68
+ /**
69
+ * Check if a hash needs rehashing (algorithm or cost changed)
70
+ */
71
+ needsRehash(hash: string): boolean;
72
+ }
73
+ /**
74
+ * Creates a new password hasher instance (succinct API)
75
+ */
76
+ export declare function passwordHasher(config?: HashConfig): PasswordHasher;
77
+ /**
78
+ * Creates a new password hasher instance
79
+ *
80
+ * @deprecated Use `passwordHasher()` instead. Will be removed in v0.9.
81
+ */
82
+ export declare const createPasswordHasher: typeof passwordHasher;
83
+ /**
84
+ * Hash a password using the default hasher
85
+ */
86
+ export declare function hashPassword(password: string): Promise<string>;
87
+ /**
88
+ * Verify a password using the default hasher
89
+ */
90
+ export declare function verifyPassword(password: string, hash: string): Promise<boolean>;
91
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAiB7C;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,MAAM,CAAwC;IACtD,OAAO,CAAC,MAAM,CAAwC;gBAE1C,MAAM,GAAE,UAAe;IAUnC;;OAEG;YACW,UAAU;IAaxB;;OAEG;YACW,UAAU;IAWxB;;OAEG;IACG,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO7C;;OAEG;IACG,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAe9D;;OAEG;YACW,cAAc;IAc5B;;OAEG;YACW,gBAAgB;IAK9B;;OAEG;YACW,cAAc;IAmB5B;;OAEG;YACW,gBAAgB;IAK9B;;OAEG;YACW,cAAc;IAM5B;;OAEG;YACW,gBAAgB;IAa9B;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CA0BnC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,cAAc,CAElE;AAED;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,uBAAiB,CAAC;AAOnD;;GAEG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAKpE;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAKrF"}