@naman_deep_singh/security 1.3.2 → 1.4.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.
Files changed (52) hide show
  1. package/README.md +153 -355
  2. package/dist/cjs/core/crypto/cryptoManager.d.ts +5 -5
  3. package/dist/cjs/core/crypto/cryptoManager.js +42 -25
  4. package/dist/cjs/core/jwt/decode.js +4 -1
  5. package/dist/cjs/core/jwt/generateTokens.d.ts +1 -1
  6. package/dist/cjs/core/jwt/generateTokens.js +7 -4
  7. package/dist/cjs/core/jwt/jwtManager.d.ts +19 -43
  8. package/dist/cjs/core/jwt/jwtManager.js +72 -202
  9. package/dist/cjs/core/jwt/parseDuration.js +3 -2
  10. package/dist/cjs/core/jwt/signToken.js +2 -1
  11. package/dist/cjs/core/jwt/validateToken.d.ts +10 -7
  12. package/dist/cjs/core/jwt/validateToken.js +14 -11
  13. package/dist/cjs/core/jwt/verify.d.ts +9 -10
  14. package/dist/cjs/core/jwt/verify.js +57 -14
  15. package/dist/cjs/core/password/hash.js +4 -4
  16. package/dist/cjs/core/password/passwordManager.d.ts +2 -2
  17. package/dist/cjs/core/password/passwordManager.js +43 -82
  18. package/dist/cjs/core/password/strength.js +5 -5
  19. package/dist/cjs/core/password/utils.d.ts +12 -0
  20. package/dist/cjs/core/password/utils.js +16 -1
  21. package/dist/cjs/core/password/verify.js +5 -5
  22. package/dist/cjs/index.d.ts +2 -7
  23. package/dist/esm/core/crypto/cryptoManager.d.ts +5 -5
  24. package/dist/esm/core/crypto/cryptoManager.js +42 -25
  25. package/dist/esm/core/jwt/decode.js +4 -1
  26. package/dist/esm/core/jwt/generateTokens.d.ts +1 -1
  27. package/dist/esm/core/jwt/generateTokens.js +7 -4
  28. package/dist/esm/core/jwt/jwtManager.d.ts +19 -43
  29. package/dist/esm/core/jwt/jwtManager.js +73 -203
  30. package/dist/esm/core/jwt/parseDuration.js +3 -2
  31. package/dist/esm/core/jwt/signToken.js +2 -1
  32. package/dist/esm/core/jwt/validateToken.d.ts +10 -7
  33. package/dist/esm/core/jwt/validateToken.js +14 -11
  34. package/dist/esm/core/jwt/verify.d.ts +9 -10
  35. package/dist/esm/core/jwt/verify.js +55 -12
  36. package/dist/esm/core/password/hash.js +4 -4
  37. package/dist/esm/core/password/passwordManager.d.ts +2 -2
  38. package/dist/esm/core/password/passwordManager.js +43 -82
  39. package/dist/esm/core/password/strength.js +5 -5
  40. package/dist/esm/core/password/utils.d.ts +12 -0
  41. package/dist/esm/core/password/utils.js +16 -1
  42. package/dist/esm/core/password/verify.js +5 -5
  43. package/dist/esm/index.d.ts +2 -7
  44. package/dist/types/core/crypto/cryptoManager.d.ts +5 -5
  45. package/dist/types/core/jwt/generateTokens.d.ts +1 -1
  46. package/dist/types/core/jwt/jwtManager.d.ts +19 -43
  47. package/dist/types/core/jwt/validateToken.d.ts +10 -7
  48. package/dist/types/core/jwt/verify.d.ts +9 -10
  49. package/dist/types/core/password/passwordManager.d.ts +2 -2
  50. package/dist/types/core/password/utils.d.ts +12 -0
  51. package/dist/types/index.d.ts +2 -7
  52. package/package.json +2 -2
@@ -1,19 +1,18 @@
1
- import type jwt from 'jsonwebtoken';
2
- import { type JwtPayload, type Secret } from 'jsonwebtoken';
3
- import type { VerificationResult } from './types';
1
+ import { type JwtPayload, type Secret, VerifyOptions } from 'jsonwebtoken';
2
+ import { VerificationResult } from './types';
4
3
  /**
5
- * Verify token (throws if invalid or expired)
4
+ * Verify token (throws UnauthorizedError if invalid or expired)
6
5
  */
7
6
  export declare const verifyToken: (token: string, secret: Secret) => string | JwtPayload;
8
7
  /**
9
- * Safe verify never throws, returns structured result
8
+ * Verify token with options
10
9
  */
11
- export declare const safeVerifyToken: (token: string, secret: Secret) => VerificationResult;
10
+ export declare const verifyTokenWithOptions: (token: string, secret: Secret, options?: VerifyOptions) => string | JwtPayload;
12
11
  /**
13
- * Verify token with validation options
12
+ * Safe verify — never throws, returns structured result with UnauthorizedError on failure
14
13
  */
15
- export declare const verifyTokenWithOptions: (token: string, secret: Secret, options?: jwt.VerifyOptions) => string | JwtPayload;
14
+ export declare const safeVerifyToken: (token: string, secret: Secret) => VerificationResult;
16
15
  /**
17
- * Safe verify with validation options
16
+ * Safe verify with options — never throws, returns structured result with UnauthorizedError on failure
18
17
  */
19
- export declare const safeVerifyTokenWithOptions: (token: string, secret: Secret, options?: jwt.VerifyOptions) => VerificationResult;
18
+ export declare const safeVerifyTokenWithOptions: (token: string, secret: Secret, options?: VerifyOptions) => VerificationResult;
@@ -23,7 +23,7 @@ export declare class PasswordManager implements IPasswordManager {
23
23
  */
24
24
  checkStrength(password: string): PasswordStrength;
25
25
  /**
26
- * Check if password hash needs upgrade (different salt rounds)
26
+ * Check if password hash needs upgrade (saltRounds change)
27
27
  */
28
- needsUpgrade(hash: string, currentConfig: PasswordConfig): boolean;
28
+ needsUpgrade(_hash: string, _currentConfig: PasswordConfig): boolean;
29
29
  }
@@ -1,4 +1,16 @@
1
+ /**
2
+ * Ensure password is a valid non-empty string
3
+ */
1
4
  export declare function ensureValidPassword(password: string): void;
5
+ /**
6
+ * Timing-safe comparison between two strings
7
+ */
2
8
  export declare function safeCompare(a: string, b: string): boolean;
9
+ /**
10
+ * Estimate password entropy based on character pool
11
+ */
3
12
  export declare function estimatePasswordEntropy(password: string): number;
13
+ /**
14
+ * Normalize password string to a consistent form
15
+ */
4
16
  export declare function normalizePassword(password: string): string;
@@ -21,16 +21,11 @@ declare const _default: {
21
21
  generateTokens: (payload: Record<string, unknown>, accessSecret: import("node_modules/@types/jsonwebtoken").Secret, refreshSecret: import("node_modules/@types/jsonwebtoken").Secret, accessExpiry?: string | number, refreshExpiry?: string | number) => JWTUtils.TokenPair;
22
22
  parseDuration(input: string | number): number;
23
23
  signToken: (payload: Record<string, unknown>, secret: import("node_modules/@types/jsonwebtoken").Secret, expiresIn?: string | number, options?: import("node_modules/@types/jsonwebtoken").SignOptions) => string;
24
- validateTokenPayload(payload: Record<string, unknown>, rules?: JWTUtils.TokenRequirements): {
25
- valid: true;
26
- } | {
27
- valid: false;
28
- error: string;
29
- };
24
+ validateTokenPayload(payload: Record<string, unknown>, rules?: JWTUtils.TokenRequirements): void;
30
25
  isTokenExpired(payload: import("node_modules/@types/jsonwebtoken").JwtPayload): boolean;
31
26
  verifyToken: (token: string, secret: import("node_modules/@types/jsonwebtoken").Secret) => string | import("node_modules/@types/jsonwebtoken").JwtPayload;
32
- safeVerifyToken: (token: string, secret: import("node_modules/@types/jsonwebtoken").Secret) => JWTUtils.VerificationResult;
33
27
  verifyTokenWithOptions: (token: string, secret: import("node_modules/@types/jsonwebtoken").Secret, options?: import("node_modules/@types/jsonwebtoken").VerifyOptions) => string | import("node_modules/@types/jsonwebtoken").JwtPayload;
28
+ safeVerifyToken: (token: string, secret: import("node_modules/@types/jsonwebtoken").Secret) => JWTUtils.VerificationResult;
34
29
  safeVerifyTokenWithOptions: (token: string, secret: import("node_modules/@types/jsonwebtoken").Secret, options?: import("node_modules/@types/jsonwebtoken").VerifyOptions) => JWTUtils.VerificationResult;
35
30
  hashPasswordWithPepper(password: string, pepper: string): Promise<string>;
36
31
  hashPasswordWithPepperSync(password: string, pepper: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naman_deep_singh/security",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "description": "Security utilities for password hashing and JWT token management with TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -28,7 +28,7 @@
28
28
  "author": "Naman Deep Singh",
29
29
  "license": "ISC",
30
30
  "dependencies": {
31
- "@naman_deep_singh/errors-utils": "^1.1.1",
31
+ "@naman_deep_singh/errors-utils": "^1.3.4",
32
32
  "@naman_deep_singh/js-extensions": "^1.3.2",
33
33
  "bcryptjs": "^3.0.3",
34
34
  "jsonwebtoken": "^9.0.2"