@naman_deep_singh/security 1.3.3 → 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.
- package/README.md +153 -355
- package/dist/cjs/core/crypto/cryptoManager.js +34 -17
- package/dist/cjs/core/jwt/decode.js +4 -1
- package/dist/cjs/core/jwt/generateTokens.js +4 -1
- package/dist/cjs/core/jwt/jwtManager.d.ts +19 -43
- package/dist/cjs/core/jwt/jwtManager.js +72 -206
- package/dist/cjs/core/jwt/parseDuration.js +3 -2
- package/dist/cjs/core/jwt/signToken.js +2 -1
- package/dist/cjs/core/jwt/validateToken.d.ts +10 -7
- package/dist/cjs/core/jwt/validateToken.js +14 -11
- package/dist/cjs/core/jwt/verify.d.ts +9 -10
- package/dist/cjs/core/jwt/verify.js +57 -14
- package/dist/cjs/core/password/hash.js +2 -2
- package/dist/cjs/core/password/passwordManager.d.ts +1 -1
- package/dist/cjs/core/password/passwordManager.js +35 -87
- package/dist/cjs/core/password/strength.js +5 -5
- package/dist/cjs/core/password/utils.d.ts +12 -0
- package/dist/cjs/core/password/utils.js +16 -1
- package/dist/cjs/core/password/verify.js +4 -4
- package/dist/cjs/index.d.ts +2 -7
- package/dist/esm/core/crypto/cryptoManager.js +34 -17
- package/dist/esm/core/jwt/decode.js +4 -1
- package/dist/esm/core/jwt/generateTokens.js +4 -1
- package/dist/esm/core/jwt/jwtManager.d.ts +19 -43
- package/dist/esm/core/jwt/jwtManager.js +73 -207
- package/dist/esm/core/jwt/parseDuration.js +3 -2
- package/dist/esm/core/jwt/signToken.js +2 -1
- package/dist/esm/core/jwt/validateToken.d.ts +10 -7
- package/dist/esm/core/jwt/validateToken.js +14 -11
- package/dist/esm/core/jwt/verify.d.ts +9 -10
- package/dist/esm/core/jwt/verify.js +55 -12
- package/dist/esm/core/password/hash.js +2 -2
- package/dist/esm/core/password/passwordManager.d.ts +1 -1
- package/dist/esm/core/password/passwordManager.js +35 -87
- package/dist/esm/core/password/strength.js +5 -5
- package/dist/esm/core/password/utils.d.ts +12 -0
- package/dist/esm/core/password/utils.js +16 -1
- package/dist/esm/core/password/verify.js +4 -4
- package/dist/esm/index.d.ts +2 -7
- package/dist/types/core/jwt/jwtManager.d.ts +19 -43
- package/dist/types/core/jwt/validateToken.d.ts +10 -7
- package/dist/types/core/jwt/verify.d.ts +9 -10
- package/dist/types/core/password/passwordManager.d.ts +1 -1
- package/dist/types/core/password/utils.d.ts +12 -0
- package/dist/types/index.d.ts +2 -7
- package/package.json +2 -2
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import type { JwtPayload } from '
|
|
1
|
+
import type { JwtPayload } from 'jsonwebtoken';
|
|
2
2
|
export interface TokenRequirements {
|
|
3
3
|
requiredFields?: string[];
|
|
4
4
|
forbiddenFields?: string[];
|
|
5
5
|
validateTypes?: Record<string, 'string' | 'number' | 'boolean'>;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Validates a JWT payload according to the provided rules.
|
|
9
|
+
* Throws ValidationError if validation fails.
|
|
10
|
+
*/
|
|
11
|
+
export declare function validateTokenPayload(payload: Record<string, unknown>, rules?: TokenRequirements): void;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a JWT payload is expired.
|
|
14
|
+
* Returns true if expired or missing 'exp'.
|
|
15
|
+
*/
|
|
13
16
|
export declare function isTokenExpired(payload: JwtPayload): boolean;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
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
|
-
*
|
|
8
|
+
* Verify token with options
|
|
10
9
|
*/
|
|
11
|
-
export declare const
|
|
10
|
+
export declare const verifyTokenWithOptions: (token: string, secret: Secret, options?: VerifyOptions) => string | JwtPayload;
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
12
|
+
* Safe verify — never throws, returns structured result with UnauthorizedError on failure
|
|
14
13
|
*/
|
|
15
|
-
export declare const
|
|
14
|
+
export declare const safeVerifyToken: (token: string, secret: Secret) => VerificationResult;
|
|
16
15
|
/**
|
|
17
|
-
* Safe verify with
|
|
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?:
|
|
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 (
|
|
26
|
+
* Check if password hash needs upgrade (saltRounds change)
|
|
27
27
|
*/
|
|
28
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;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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
|
+
"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.
|
|
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"
|