@naman_deep_singh/security 1.0.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.
@@ -0,0 +1,5 @@
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 ADDED
@@ -0,0 +1,17 @@
1
+ import jwt from "jsonwebtoken";
2
+ import bcrypt from "bcryptjs";
3
+ // 🧱 Password helpers
4
+ export const hashPassword = async (password) => {
5
+ const salt = await bcrypt.genSalt(10);
6
+ return bcrypt.hash(password, salt);
7
+ };
8
+ export const comparePassword = async (password, hash) => {
9
+ return bcrypt.compare(password, hash);
10
+ };
11
+ // 🧩 JWT helpers
12
+ export const signToken = (payload, secret, expiresIn = "1h") => {
13
+ return jwt.sign(payload, secret, { expiresIn, algorithm: "HS256" });
14
+ };
15
+ export const verifyToken = (token, secret) => {
16
+ return jwt.verify(token, secret);
17
+ };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@naman_deep_singh/security",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc"
9
+ },
10
+ "keywords": [],
11
+ "author": "",
12
+ "license": "ISC",
13
+ "packageManager": "pnpm@10.20.0",
14
+ "dependencies": {
15
+ "bcryptjs": "^3.0.3",
16
+ "jsonwebtoken": "^9.0.2"
17
+ },
18
+ "devDependencies": {
19
+ "@types/jsonwebtoken": "^9.0.10",
20
+ "typescript": "^5.9.3"
21
+ }
22
+ }
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
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 ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "declaration": true,
6
+ "outDir": "dist",
7
+ "rootDir": "src",
8
+ "moduleResolution": "node",
9
+ "esModuleInterop": true,
10
+ "strict": true,
11
+ "skipLibCheck": true
12
+ },
13
+ "include": ["src"]
14
+ }