@naman_deep_singh/security 1.0.3 → 1.1.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 +329 -24
- package/dist/cjs/core/crypto/decrypt.d.ts +1 -0
- package/dist/cjs/core/crypto/decrypt.js +21 -0
- package/dist/cjs/core/crypto/encrypt.d.ts +1 -0
- package/dist/cjs/core/crypto/encrypt.js +16 -0
- package/dist/cjs/core/crypto/hmac.d.ts +8 -0
- package/dist/cjs/core/crypto/hmac.js +24 -0
- package/dist/cjs/core/crypto/index.d.ts +4 -0
- package/dist/cjs/core/crypto/index.js +20 -0
- package/dist/cjs/core/crypto/random.d.ts +8 -0
- package/dist/cjs/core/crypto/random.js +21 -0
- package/dist/cjs/core/jwt/decode.d.ts +12 -0
- package/dist/cjs/core/jwt/decode.js +25 -0
- package/dist/cjs/core/jwt/extractToken.d.ts +11 -0
- package/dist/cjs/core/jwt/extractToken.js +49 -0
- package/dist/cjs/core/jwt/generateTokens.d.ts +7 -0
- package/dist/cjs/core/jwt/generateTokens.js +23 -0
- package/dist/cjs/core/jwt/index.d.ts +7 -0
- package/dist/cjs/core/jwt/index.js +23 -0
- package/dist/cjs/core/jwt/parseDuration.d.ts +1 -0
- package/dist/cjs/core/jwt/parseDuration.js +29 -0
- package/dist/cjs/core/jwt/signToken.d.ts +2 -0
- package/dist/cjs/core/jwt/signToken.js +26 -0
- package/dist/cjs/core/jwt/validateToken.d.ts +13 -0
- package/dist/cjs/core/jwt/validateToken.js +37 -0
- package/dist/cjs/core/jwt/verify.d.ts +13 -0
- package/dist/cjs/core/jwt/verify.js +24 -0
- package/dist/cjs/core/password/hash.d.ts +10 -0
- package/dist/cjs/core/password/hash.js +45 -0
- package/dist/cjs/core/password/index.d.ts +3 -0
- package/dist/cjs/core/password/index.js +19 -0
- package/dist/cjs/core/password/strength.d.ts +2 -0
- package/dist/cjs/core/password/strength.js +21 -0
- package/dist/cjs/core/password/types.d.ts +7 -0
- package/dist/cjs/core/password/types.js +2 -0
- package/dist/cjs/core/password/utils.d.ts +4 -0
- package/dist/cjs/core/password/utils.js +38 -0
- package/dist/cjs/core/password/verify.d.ts +10 -0
- package/dist/cjs/core/password/verify.js +46 -0
- package/dist/cjs/index.d.ts +43 -0
- package/dist/cjs/index.js +56 -0
- package/dist/esm/core/crypto/decrypt.d.ts +1 -0
- package/dist/esm/core/crypto/decrypt.js +14 -0
- package/dist/esm/core/crypto/encrypt.d.ts +1 -0
- package/dist/esm/core/crypto/encrypt.js +9 -0
- package/dist/esm/core/crypto/hmac.d.ts +8 -0
- package/dist/esm/core/crypto/hmac.js +16 -0
- package/dist/esm/core/crypto/index.d.ts +4 -0
- package/dist/esm/core/crypto/index.js +4 -0
- package/dist/esm/core/crypto/random.d.ts +8 -0
- package/dist/esm/core/crypto/random.js +13 -0
- package/dist/esm/core/jwt/decode.d.ts +12 -0
- package/dist/esm/core/jwt/decode.js +21 -0
- package/dist/esm/core/jwt/extractToken.d.ts +11 -0
- package/dist/esm/core/jwt/extractToken.js +46 -0
- package/dist/esm/core/jwt/generateTokens.d.ts +7 -0
- package/dist/esm/core/jwt/generateTokens.js +18 -0
- package/dist/esm/core/jwt/index.d.ts +7 -0
- package/dist/esm/core/jwt/index.js +7 -0
- package/dist/esm/core/jwt/parseDuration.d.ts +1 -0
- package/dist/esm/core/jwt/parseDuration.js +26 -0
- package/dist/esm/core/jwt/signToken.d.ts +2 -0
- package/dist/esm/core/jwt/signToken.js +22 -0
- package/dist/esm/core/jwt/validateToken.d.ts +13 -0
- package/dist/esm/core/jwt/validateToken.js +33 -0
- package/dist/esm/core/jwt/verify.d.ts +13 -0
- package/dist/esm/core/jwt/verify.js +19 -0
- package/dist/esm/core/password/hash.d.ts +10 -0
- package/dist/esm/core/password/hash.js +35 -0
- package/dist/esm/core/password/index.d.ts +3 -0
- package/dist/esm/core/password/index.js +3 -0
- package/dist/esm/core/password/strength.d.ts +2 -0
- package/dist/esm/core/password/strength.js +17 -0
- package/dist/esm/core/password/types.d.ts +7 -0
- package/dist/esm/core/password/types.js +1 -0
- package/dist/esm/core/password/utils.d.ts +4 -0
- package/dist/esm/core/password/utils.js +29 -0
- package/dist/esm/core/password/verify.d.ts +10 -0
- package/dist/esm/core/password/verify.js +36 -0
- package/dist/esm/index.d.ts +43 -0
- package/dist/esm/index.js +13 -0
- package/dist/types/core/crypto/decrypt.d.ts +1 -0
- package/dist/types/core/crypto/encrypt.d.ts +1 -0
- package/dist/types/core/crypto/hmac.d.ts +8 -0
- package/dist/types/core/crypto/index.d.ts +4 -0
- package/dist/types/core/crypto/random.d.ts +8 -0
- package/dist/types/core/jwt/decode.d.ts +12 -0
- package/dist/types/core/jwt/extractToken.d.ts +11 -0
- package/dist/types/core/jwt/generateTokens.d.ts +7 -0
- package/dist/types/core/jwt/index.d.ts +7 -0
- package/dist/types/core/jwt/parseDuration.d.ts +1 -0
- package/dist/types/core/jwt/signToken.d.ts +2 -0
- package/dist/types/core/jwt/validateToken.d.ts +13 -0
- package/dist/types/core/jwt/verify.d.ts +13 -0
- package/dist/types/core/password/hash.d.ts +10 -0
- package/dist/types/core/password/index.d.ts +3 -0
- package/dist/types/core/password/strength.d.ts +2 -0
- package/dist/types/core/password/types.d.ts +7 -0
- package/dist/types/core/password/utils.d.ts +4 -0
- package/dist/types/core/password/verify.d.ts +10 -0
- package/dist/types/index.d.ts +43 -0
- package/package.json +34 -10
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -27
- package/src/index.ts +0 -21
- package/tsconfig.json +0 -20
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export * from "./core/password";
|
|
2
|
+
export * from "./core/jwt";
|
|
3
|
+
export * from "./core/crypto";
|
|
4
|
+
export { BadRequestError, UnauthorizedError, ValidationError, InternalServerError } from "@naman_deep_singh/errors-utils";
|
|
5
|
+
import * as JWTUtils from "./core/jwt";
|
|
6
|
+
declare const _default: {
|
|
7
|
+
decrypt: (data: string, secret: string) => string;
|
|
8
|
+
encrypt: (text: string, secret: string) => string;
|
|
9
|
+
hmacSign: (message: string, secret: string) => string;
|
|
10
|
+
hmacVerify: (message: string, secret: string, signature: string) => boolean;
|
|
11
|
+
randomToken: (length?: number) => string;
|
|
12
|
+
generateStrongPassword: (length?: number) => string;
|
|
13
|
+
decodeToken(token: string): null | string | import("node_modules/@types/jsonwebtoken").JwtPayload;
|
|
14
|
+
decodeTokenStrict(token: string): import("node_modules/@types/jsonwebtoken").JwtPayload;
|
|
15
|
+
extractToken(sources: JWTUtils.TokenSources): string | null;
|
|
16
|
+
rotateRefreshToken(oldToken: string, secret: import("node_modules/@types/jsonwebtoken").Secret): string;
|
|
17
|
+
generateTokens: (payload: object, accessSecret: import("node_modules/@types/jsonwebtoken").Secret, refreshSecret: import("node_modules/@types/jsonwebtoken").Secret, accessExpiry?: string | number, refreshExpiry?: string | number) => JWTUtils.TokenPair;
|
|
18
|
+
parseDuration(input: string | number): number;
|
|
19
|
+
signToken: (payload: Record<string, any>, secret: import("node_modules/@types/jsonwebtoken").Secret, expiresIn?: string | number, options?: import("node_modules/@types/jsonwebtoken").SignOptions) => string;
|
|
20
|
+
validateTokenPayload(payload: Record<string, any>, rules?: JWTUtils.TokenRequirements): {
|
|
21
|
+
valid: true;
|
|
22
|
+
} | {
|
|
23
|
+
valid: false;
|
|
24
|
+
error: string;
|
|
25
|
+
};
|
|
26
|
+
isTokenExpired(payload: import("node_modules/@types/jsonwebtoken").JwtPayload): boolean;
|
|
27
|
+
verifyToken: (token: string, secret: import("node_modules/@types/jsonwebtoken").Secret) => string | import("node_modules/@types/jsonwebtoken").JwtPayload;
|
|
28
|
+
safeVerifyToken: (token: string, secret: import("node_modules/@types/jsonwebtoken").Secret) => {
|
|
29
|
+
valid: boolean;
|
|
30
|
+
payload?: string | import("node_modules/@types/jsonwebtoken").JwtPayload;
|
|
31
|
+
error?: unknown;
|
|
32
|
+
};
|
|
33
|
+
hashPasswordWithPepper(password: string, pepper: string): Promise<string>;
|
|
34
|
+
hashPasswordWithPepperSync(password: string, pepper: string): string;
|
|
35
|
+
hashPassword: (password: string, saltRounds?: number) => Promise<string>;
|
|
36
|
+
hashPasswordSync: (password: string, saltRounds?: number) => string;
|
|
37
|
+
isPasswordStrong: (password: string, options?: import("./core/password/types").PasswordStrengthOptions) => boolean;
|
|
38
|
+
verifyPasswordWithPepper(password: string, pepper: string, hash: string): Promise<boolean>;
|
|
39
|
+
verifyPasswordWithPepperSync(password: string, pepper: string, hash: string): Promise<boolean>;
|
|
40
|
+
verifyPassword: (password: string, hash: string) => Promise<boolean>;
|
|
41
|
+
verifyPasswordSync: (password: string, hash: string) => boolean;
|
|
42
|
+
};
|
|
43
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -1,22 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naman_deep_singh/security",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Security utilities for password hashing and JWT token management with TypeScript",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.js",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/esm/index.js",
|
|
11
|
+
"require": "./dist/cjs/index.js",
|
|
12
|
+
"types": "./dist/types/index.d.ts"
|
|
13
|
+
}
|
|
9
14
|
},
|
|
10
|
-
"
|
|
11
|
-
"
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"security",
|
|
22
|
+
"jwt",
|
|
23
|
+
"bcrypt",
|
|
24
|
+
"authentication",
|
|
25
|
+
"password",
|
|
26
|
+
"token"
|
|
27
|
+
],
|
|
28
|
+
"author": "Naman Deep Singh",
|
|
12
29
|
"license": "ISC",
|
|
13
|
-
"packageManager": "pnpm@10.20.0",
|
|
14
30
|
"dependencies": {
|
|
31
|
+
"@naman_deep_singh/errors-utils": "^1.0.0",
|
|
15
32
|
"bcryptjs": "^3.0.3",
|
|
16
33
|
"jsonwebtoken": "^9.0.2"
|
|
17
34
|
},
|
|
18
35
|
"devDependencies": {
|
|
36
|
+
"@types/bcryptjs": "^2.4.6",
|
|
19
37
|
"@types/jsonwebtoken": "^9.0.10",
|
|
20
|
-
"typescript": "^5.9.3"
|
|
38
|
+
"typescript": "^5.9.3",
|
|
39
|
+
"rimraf": "^5.0.5"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "pnpm run build:types && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json",
|
|
43
|
+
"build:types": "tsc -p tsconfig.base.json --emitDeclarationOnly --outDir dist/types",
|
|
44
|
+
"clean": "rimraf dist"
|
|
21
45
|
}
|
|
22
46
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Secret } from "jsonwebtoken";
|
|
2
|
-
export declare const hashPassword: (password: string) => Promise<string>;
|
|
3
|
-
export declare const comparePassword: (password: string, hash: string) => Promise<boolean>;
|
|
4
|
-
export declare const signToken: (payload: object, secret: Secret, expiresIn?: string) => string;
|
|
5
|
-
export declare const verifyToken: (token: string, secret: Secret) => object | string;
|
package/dist/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.verifyToken = exports.signToken = exports.comparePassword = exports.hashPassword = void 0;
|
|
7
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
-
const bcryptjs_1 = __importDefault(require("bcryptjs"));
|
|
9
|
-
// 🧱 Password helpers
|
|
10
|
-
const hashPassword = async (password) => {
|
|
11
|
-
const salt = await bcryptjs_1.default.genSalt(10);
|
|
12
|
-
return bcryptjs_1.default.hash(password, salt);
|
|
13
|
-
};
|
|
14
|
-
exports.hashPassword = hashPassword;
|
|
15
|
-
const comparePassword = async (password, hash) => {
|
|
16
|
-
return bcryptjs_1.default.compare(password, hash);
|
|
17
|
-
};
|
|
18
|
-
exports.comparePassword = comparePassword;
|
|
19
|
-
// 🧩 JWT helpers
|
|
20
|
-
const signToken = (payload, secret, expiresIn = "1h") => {
|
|
21
|
-
return jsonwebtoken_1.default.sign(payload, secret, { expiresIn, algorithm: "HS256" });
|
|
22
|
-
};
|
|
23
|
-
exports.signToken = signToken;
|
|
24
|
-
const verifyToken = (token, secret) => {
|
|
25
|
-
return jsonwebtoken_1.default.verify(token, secret);
|
|
26
|
-
};
|
|
27
|
-
exports.verifyToken = verifyToken;
|
package/src/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import jwt, { Secret } from "jsonwebtoken";
|
|
2
|
-
import bcrypt from "bcryptjs";
|
|
3
|
-
|
|
4
|
-
// 🧱 Password helpers
|
|
5
|
-
export const hashPassword = async (password: string): Promise<string> => {
|
|
6
|
-
const salt = await bcrypt.genSalt(10);
|
|
7
|
-
return bcrypt.hash(password, salt);
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const comparePassword = async (password: string, hash: string): Promise<boolean> => {
|
|
11
|
-
return bcrypt.compare(password, hash);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
// 🧩 JWT helpers
|
|
15
|
-
export const signToken = (payload: object, secret: Secret, expiresIn = "1h"): string => {
|
|
16
|
-
return jwt.sign(payload, secret, { expiresIn, algorithm: "HS256" } as jwt.SignOptions);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const verifyToken = (token: string, secret: Secret): object | string => {
|
|
20
|
-
return jwt.verify(token, secret);
|
|
21
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "CommonJS",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"rootDir": "src",
|
|
7
|
-
"outDir": "dist",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"allowSyntheticDefaultImports": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"forceConsistentCasingInFileNames": true,
|
|
13
|
-
"baseUrl": ".",
|
|
14
|
-
"paths": {
|
|
15
|
-
"*": ["*", "*.ts", "*.js"]
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"include": ["src"],
|
|
19
|
-
"exclude": ["node_modules"]
|
|
20
|
-
}
|