@naman_deep_singh/security 1.0.1 → 1.0.3

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 ADDED
@@ -0,0 +1,42 @@
1
+ # @naman_deep_singh/security
2
+
3
+ Security utilities for password hashing and JWT token management.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @naman_deep_singh/security
9
+ or
10
+ pnpm add @naman_deep_singh/security
11
+ or
12
+ yarn add @naman_deep_singh/security
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import { hashPassword, verifyPassword, generateToken, verifyToken } from '@naman_deep_singh/security';
19
+
20
+ // Password hashing
21
+ const hashedPassword = await hashPassword('mypassword');
22
+ const isValid = await verifyPassword('mypassword', hashedPassword);
23
+
24
+ // JWT tokens
25
+ const token = generateToken({ userId: 1 }, 'your-secret-key');
26
+ const decoded = verifyToken(token, 'your-secret-key');
27
+ ```
28
+
29
+ ## API
30
+
31
+ ### Password Functions
32
+ - `hashPassword(password: string): Promise<string>` - Hash a password using bcrypt
33
+ - `verifyPassword(password: string, hash: string): Promise<boolean>` - Verify password against hash
34
+
35
+ ### JWT Functions
36
+ - `generateToken(payload: object, secret: string, expiresIn?: string): string` - Generate JWT token
37
+ - `verifyToken(token: string, secret: string): any` - Verify and decode JWT token
38
+
39
+ ## Dependencies
40
+
41
+ - bcryptjs - For password hashing
42
+ - jsonwebtoken - For JWT token management
package/dist/index.js CHANGED
@@ -1,17 +1,27 @@
1
- import jwt from "jsonwebtoken";
2
- import bcrypt from "bcryptjs";
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"));
3
9
  // 🧱 Password helpers
4
- export const hashPassword = async (password) => {
5
- const salt = await bcrypt.genSalt(10);
6
- return bcrypt.hash(password, salt);
10
+ const hashPassword = async (password) => {
11
+ const salt = await bcryptjs_1.default.genSalt(10);
12
+ return bcryptjs_1.default.hash(password, salt);
7
13
  };
8
- export const comparePassword = async (password, hash) => {
9
- return bcrypt.compare(password, hash);
14
+ exports.hashPassword = hashPassword;
15
+ const comparePassword = async (password, hash) => {
16
+ return bcryptjs_1.default.compare(password, hash);
10
17
  };
18
+ exports.comparePassword = comparePassword;
11
19
  // 🧩 JWT helpers
12
- export const signToken = (payload, secret, expiresIn = "1h") => {
13
- return jwt.sign(payload, secret, { expiresIn, algorithm: "HS256" });
20
+ const signToken = (payload, secret, expiresIn = "1h") => {
21
+ return jsonwebtoken_1.default.sign(payload, secret, { expiresIn, algorithm: "HS256" });
14
22
  };
15
- export const verifyToken = (token, secret) => {
16
- return jwt.verify(token, secret);
23
+ exports.signToken = signToken;
24
+ const verifyToken = (token, secret) => {
25
+ return jsonwebtoken_1.default.verify(token, secret);
17
26
  };
27
+ exports.verifyToken = verifyToken;
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@naman_deep_singh/security",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
- "type": "module",
6
5
  "main": "dist/index.js",
7
6
  "types": "dist/index.d.ts",
8
7
  "scripts": {
package/tsconfig.json CHANGED
@@ -1,14 +1,20 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2020",
4
- "module": "ESNext",
5
- "declaration": true,
6
- "outDir": "dist",
7
- "rootDir": "src",
4
+ "module": "CommonJS",
8
5
  "moduleResolution": "node",
9
- "esModuleInterop": true,
6
+ "rootDir": "src",
7
+ "outDir": "dist",
10
8
  "strict": true,
11
- "skipLibCheck": true
9
+ "esModuleInterop": true,
10
+ "allowSyntheticDefaultImports": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "baseUrl": ".",
14
+ "paths": {
15
+ "*": ["*", "*.ts", "*.js"]
16
+ }
12
17
  },
13
- "include": ["src"]
18
+ "include": ["src"],
19
+ "exclude": ["node_modules"]
14
20
  }