@naman_deep_singh/security 1.6.0 → 1.7.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 (95) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/core/crypto/CryptoManger.js +107 -0
  3. package/dist/cjs/core/crypto/index.js +13 -26
  4. package/dist/cjs/core/index.js +44 -0
  5. package/dist/cjs/core/jwt/{jwtManager.js → JWTManager.js} +8 -8
  6. package/dist/cjs/core/jwt/decode.js +0 -1
  7. package/dist/cjs/core/jwt/generateTokens.js +6 -6
  8. package/dist/cjs/core/jwt/index.js +23 -22
  9. package/dist/cjs/core/jwt/signToken.js +2 -2
  10. package/dist/cjs/core/password/{passwordManager.js → PasswordManager.js} +3 -3
  11. package/dist/cjs/core/password/hash.js +5 -5
  12. package/dist/cjs/core/password/index.js +20 -17
  13. package/dist/cjs/index.js +4 -40
  14. package/dist/cjs/interfaces/index.js +2 -0
  15. package/dist/esm/core/crypto/CryptoManger.js +100 -0
  16. package/dist/esm/core/crypto/index.js +5 -5
  17. package/dist/esm/core/index.js +6 -0
  18. package/dist/esm/core/jwt/{jwtManager.js → JWTManager.js} +3 -3
  19. package/dist/esm/core/jwt/decode.js +0 -1
  20. package/dist/esm/core/jwt/generateTokens.js +2 -2
  21. package/dist/esm/core/jwt/index.js +8 -8
  22. package/dist/esm/core/jwt/signToken.js +1 -1
  23. package/dist/esm/core/password/{passwordManager.js → PasswordManager.js} +1 -1
  24. package/dist/esm/core/password/hash.js +3 -3
  25. package/dist/esm/core/password/index.js +5 -3
  26. package/dist/esm/index.js +4 -13
  27. package/dist/esm/interfaces/index.js +1 -0
  28. package/dist/types/core/crypto/CryptoManger.d.ts +36 -0
  29. package/dist/types/core/crypto/index.d.ts +5 -5
  30. package/dist/types/core/index.d.ts +3 -0
  31. package/dist/{esm/core/jwt/jwtManager.d.ts → types/core/jwt/JWTManager.d.ts} +1 -1
  32. package/dist/types/core/jwt/generateTokens.d.ts +1 -1
  33. package/dist/types/core/jwt/index.d.ts +9 -8
  34. package/dist/types/core/jwt/verify.d.ts +1 -1
  35. package/dist/types/core/password/{passwordManager.d.ts → PasswordManager.d.ts} +1 -1
  36. package/dist/types/core/password/index.d.ts +6 -3
  37. package/dist/types/core/password/strength.d.ts +1 -1
  38. package/dist/types/index.d.ts +1 -40
  39. package/dist/types/interfaces/index.d.ts +2 -0
  40. package/package.json +30 -4
  41. package/dist/cjs/core/crypto/cryptoManager.d.ts +0 -111
  42. package/dist/cjs/core/crypto/cryptoManager.js +0 -208
  43. package/dist/cjs/core/crypto/decrypt.d.ts +0 -1
  44. package/dist/cjs/core/crypto/encrypt.d.ts +0 -1
  45. package/dist/cjs/core/crypto/hmac.d.ts +0 -8
  46. package/dist/cjs/core/crypto/index.d.ts +0 -5
  47. package/dist/cjs/core/crypto/random.d.ts +0 -8
  48. package/dist/cjs/core/jwt/decode.d.ts +0 -12
  49. package/dist/cjs/core/jwt/extractToken.d.ts +0 -11
  50. package/dist/cjs/core/jwt/generateTokens.d.ts +0 -4
  51. package/dist/cjs/core/jwt/index.d.ts +0 -8
  52. package/dist/cjs/core/jwt/jwtManager.d.ts +0 -43
  53. package/dist/cjs/core/jwt/parseDuration.d.ts +0 -1
  54. package/dist/cjs/core/jwt/signToken.d.ts +0 -2
  55. package/dist/cjs/core/jwt/types.d.ts +0 -22
  56. package/dist/cjs/core/jwt/validateToken.d.ts +0 -16
  57. package/dist/cjs/core/jwt/verify.d.ts +0 -18
  58. package/dist/cjs/core/password/hash.d.ts +0 -10
  59. package/dist/cjs/core/password/index.d.ts +0 -3
  60. package/dist/cjs/core/password/passwordManager.d.ts +0 -29
  61. package/dist/cjs/core/password/strength.d.ts +0 -2
  62. package/dist/cjs/core/password/types.d.ts +0 -7
  63. package/dist/cjs/core/password/utils.d.ts +0 -16
  64. package/dist/cjs/core/password/verify.d.ts +0 -10
  65. package/dist/cjs/index.d.ts +0 -40
  66. package/dist/cjs/interfaces/jwt.interface.d.ts +0 -47
  67. package/dist/cjs/interfaces/password.interface.d.ts +0 -60
  68. package/dist/esm/core/crypto/cryptoManager.d.ts +0 -111
  69. package/dist/esm/core/crypto/cryptoManager.js +0 -203
  70. package/dist/esm/core/crypto/decrypt.d.ts +0 -1
  71. package/dist/esm/core/crypto/encrypt.d.ts +0 -1
  72. package/dist/esm/core/crypto/hmac.d.ts +0 -8
  73. package/dist/esm/core/crypto/index.d.ts +0 -5
  74. package/dist/esm/core/crypto/random.d.ts +0 -8
  75. package/dist/esm/core/jwt/decode.d.ts +0 -12
  76. package/dist/esm/core/jwt/extractToken.d.ts +0 -11
  77. package/dist/esm/core/jwt/generateTokens.d.ts +0 -4
  78. package/dist/esm/core/jwt/index.d.ts +0 -8
  79. package/dist/esm/core/jwt/parseDuration.d.ts +0 -1
  80. package/dist/esm/core/jwt/signToken.d.ts +0 -2
  81. package/dist/esm/core/jwt/types.d.ts +0 -22
  82. package/dist/esm/core/jwt/validateToken.d.ts +0 -16
  83. package/dist/esm/core/jwt/verify.d.ts +0 -18
  84. package/dist/esm/core/password/hash.d.ts +0 -10
  85. package/dist/esm/core/password/index.d.ts +0 -3
  86. package/dist/esm/core/password/passwordManager.d.ts +0 -29
  87. package/dist/esm/core/password/strength.d.ts +0 -2
  88. package/dist/esm/core/password/types.d.ts +0 -7
  89. package/dist/esm/core/password/utils.d.ts +0 -16
  90. package/dist/esm/core/password/verify.d.ts +0 -10
  91. package/dist/esm/index.d.ts +0 -40
  92. package/dist/esm/interfaces/jwt.interface.d.ts +0 -47
  93. package/dist/esm/interfaces/password.interface.d.ts +0 -60
  94. package/dist/types/core/crypto/cryptoManager.d.ts +0 -111
  95. package/dist/types/core/jwt/jwtManager.d.ts +0 -43
@@ -1,5 +1,5 @@
1
- export { decrypt } from './decrypt';
2
- export { encrypt } from './encrypt';
3
- export { hmacSign, hmacVerify } from './hmac';
4
- export { randomToken, generateStrongPassword } from './random';
5
- export * from './cryptoManager';
1
+ export { CryptoManager } from './CryptoManger.js';
2
+ export { encrypt } from './encrypt.js';
3
+ export { decrypt } from './decrypt.js';
4
+ export { hmacSign, hmacVerify } from './hmac.js';
5
+ export { randomToken, generateStrongPassword } from './random.js';
@@ -0,0 +1,6 @@
1
+ // Re-export everything from crypto module
2
+ export { CryptoManager, encrypt, decrypt, hmacSign, hmacVerify, randomToken, generateStrongPassword, } from './crypto/index.js';
3
+ // Re-export everything from jwt module
4
+ export { decodeToken, decodeTokenStrict, extractToken, generateTokens, rotateRefreshToken, parseDuration, signToken, validateTokenPayload, isTokenExpired, verifyToken, verifyTokenWithOptions, safeVerifyToken, safeVerifyTokenWithOptions, JWTManager, } from './jwt/index.js';
5
+ // Re-export everything from password module
6
+ export { hashPassword, hashPasswordWithPepper, hashPasswordSync, hashPasswordWithPepperSync, isPasswordStrong, verifyPassword, verifyPasswordWithPepper, verifyPasswordSync, verifyPasswordWithPepperSync, PasswordManager, ensureValidPassword, safeCompare, estimatePasswordEntropy, normalizePassword, } from './password/index.js';
@@ -1,8 +1,8 @@
1
- import jwt from 'jsonwebtoken';
2
- import { signToken } from './signToken';
3
- import { safeVerifyToken } from './verify';
4
1
  import { BadRequestError, UnauthorizedError, ValidationError, } from '@naman_deep_singh/errors';
5
2
  import { LRUCache } from '@naman_deep_singh/utils';
3
+ import jwt from 'jsonwebtoken';
4
+ import { signToken } from './signToken.js';
5
+ import { safeVerifyToken } from './verify.js';
6
6
  export class JWTManager {
7
7
  constructor(config) {
8
8
  this.accessSecret = config.accessSecret;
@@ -1,5 +1,4 @@
1
1
  import { BadRequestError } from '@naman_deep_singh/errors';
2
- // src/jwt/decodeToken.ts
3
2
  import { decode } from 'jsonwebtoken';
4
3
  /**
5
4
  * Flexible decode
@@ -1,6 +1,6 @@
1
1
  import { TokenMalformedError } from '@naman_deep_singh/errors';
2
- import { signToken } from './signToken';
3
- import { verifyToken } from './verify';
2
+ import { signToken } from './signToken.js';
3
+ import { verifyToken } from './verify.js';
4
4
  // Helper function to create branded tokens
5
5
  /* const createBrandedToken = <T extends string>(token: string, _brand: T): T => {
6
6
  return token as T
@@ -1,8 +1,8 @@
1
- export * from './decode';
2
- export * from './extractToken';
3
- export * from './generateTokens';
4
- export * from './parseDuration';
5
- export * from './signToken';
6
- export * from './types';
7
- export * from './validateToken';
8
- export * from './verify';
1
+ export { decodeToken, decodeTokenStrict } from './decode.js';
2
+ export { extractToken } from './extractToken.js';
3
+ export { generateTokens, rotateRefreshToken } from './generateTokens.js';
4
+ export { parseDuration } from './parseDuration.js';
5
+ export { signToken } from './signToken.js';
6
+ export { validateTokenPayload, isTokenExpired, } from './validateToken.js';
7
+ export { verifyToken, verifyTokenWithOptions, safeVerifyToken, safeVerifyTokenWithOptions, } from './verify.js';
8
+ export { JWTManager } from './JWTManager.js';
@@ -1,6 +1,6 @@
1
1
  import { ValidationError } from '@naman_deep_singh/errors';
2
2
  import { sign } from 'jsonwebtoken';
3
- import { parseDuration } from './parseDuration';
3
+ import { parseDuration } from './parseDuration.js';
4
4
  function getExpiryTimestamp(seconds) {
5
5
  return Math.floor(Date.now() / 1000) + seconds;
6
6
  }
@@ -1,7 +1,7 @@
1
1
  import crypto from 'crypto';
2
2
  import bcrypt from 'bcryptjs';
3
3
  import { BadRequestError, ValidationError } from '@naman_deep_singh/errors';
4
- import { ensureValidPassword, estimatePasswordEntropy } from './utils';
4
+ import { ensureValidPassword, estimatePasswordEntropy } from './utils.js';
5
5
  export class PasswordManager {
6
6
  constructor(config = {}) {
7
7
  this.defaultConfig = {
@@ -1,6 +1,6 @@
1
1
  import { InternalServerError } from '@naman_deep_singh/errors';
2
2
  import bcrypt from 'bcryptjs';
3
- import { ensureValidPassword } from './utils';
3
+ import { ensureValidPassword } from './utils.js';
4
4
  /**
5
5
  * Hash a password asynchronously using bcrypt.
6
6
  */
@@ -11,7 +11,7 @@ export const hashPassword = async (password, saltRounds = 10) => {
11
11
  return bcrypt.hash(password, salt);
12
12
  }
13
13
  catch (error) {
14
- throw new InternalServerError({ reason: 'Password hashing failed' }, error instanceof Error ? error : undefined);
14
+ throw new InternalServerError(undefined, { reason: 'Password hashing failed' }, error instanceof Error ? error : undefined);
15
15
  }
16
16
  };
17
17
  export function hashPasswordWithPepper(password, pepper) {
@@ -27,7 +27,7 @@ export const hashPasswordSync = (password, saltRounds = 10) => {
27
27
  return bcrypt.hashSync(password, salt);
28
28
  }
29
29
  catch (error) {
30
- throw new InternalServerError({ reason: 'Password hashing failed' }, error instanceof Error ? error : undefined);
30
+ throw new InternalServerError(undefined, { reason: 'Password hashing failed' }, error instanceof Error ? error : undefined);
31
31
  }
32
32
  };
33
33
  export function hashPasswordWithPepperSync(password, pepper) {
@@ -1,3 +1,5 @@
1
- export * from './hash';
2
- export * from './strength';
3
- export * from './verify';
1
+ export { hashPassword, hashPasswordWithPepper, hashPasswordSync, hashPasswordWithPepperSync, } from './hash.js';
2
+ export { isPasswordStrong } from './strength.js';
3
+ export { verifyPassword, verifyPasswordWithPepper, verifyPasswordSync, verifyPasswordWithPepperSync, } from './verify.js';
4
+ export { PasswordManager } from './PasswordManager.js';
5
+ export { ensureValidPassword, safeCompare, estimatePasswordEntropy, normalizePassword, } from './utils.js';
package/dist/esm/index.js CHANGED
@@ -1,13 +1,4 @@
1
- export * from './core/password';
2
- export * from './core/jwt';
3
- export * from './core/crypto';
4
- // Re-export common errors for convenience
5
- export { BadRequestError, UnauthorizedError, ValidationError, InternalServerError, } from '@naman_deep_singh/errors';
6
- import * as CryptoUtils from './core/crypto';
7
- import * as JWTUtils from './core/jwt';
8
- import * as PasswordUtils from './core/password';
9
- export default {
10
- ...PasswordUtils,
11
- ...JWTUtils,
12
- ...CryptoUtils,
13
- };
1
+ // Core modules
2
+ export * from './core/index.js';
3
+ // Public interfaces
4
+ // export * from './interfaces/index.js'
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * High-level cryptography manager
3
+ * Wraps encryption, decryption, HMAC, and random utilities
4
+ */
5
+ export declare class CryptoManager {
6
+ private readonly secret;
7
+ constructor(secret: string);
8
+ /**
9
+ * Encrypt data using AES-256-GCM
10
+ */
11
+ encrypt(data: string): string;
12
+ /**
13
+ * Decrypt AES-256-GCM encrypted data
14
+ */
15
+ decrypt(encrypted: string): string;
16
+ /**
17
+ * Create HMAC SHA-256 signature
18
+ */
19
+ createHMAC(message: string): string;
20
+ /**
21
+ * Verify HMAC SHA-256 signature
22
+ */
23
+ verifyHMAC(message: string, signature: string): boolean;
24
+ /**
25
+ * Generate cryptographically secure random bytes
26
+ */
27
+ generateRandomBytes(length?: number): Buffer;
28
+ /**
29
+ * Generate secure random hex string
30
+ */
31
+ generateRandomHex(length?: number): string;
32
+ /**
33
+ * Generate secure random string (URL-safe base64)
34
+ */
35
+ generateRandomString(length?: number): string;
36
+ }
@@ -1,5 +1,5 @@
1
- export { decrypt } from './decrypt';
2
- export { encrypt } from './encrypt';
3
- export { hmacSign, hmacVerify } from './hmac';
4
- export { randomToken, generateStrongPassword } from './random';
5
- export * from './cryptoManager';
1
+ export { CryptoManager } from './CryptoManger.js';
2
+ export { encrypt } from './encrypt.js';
3
+ export { decrypt } from './decrypt.js';
4
+ export { hmacSign, hmacVerify } from './hmac.js';
5
+ export { randomToken, generateStrongPassword } from './random.js';
@@ -0,0 +1,3 @@
1
+ export { CryptoManager, encrypt, decrypt, hmacSign, hmacVerify, randomToken, generateStrongPassword, } from './crypto/index.js';
2
+ export { decodeToken, decodeTokenStrict, extractToken, generateTokens, rotateRefreshToken, parseDuration, signToken, validateTokenPayload, isTokenExpired, verifyToken, verifyTokenWithOptions, safeVerifyToken, safeVerifyTokenWithOptions, JWTManager, type TokenSources, type AccessToken, type RefreshToken, type TokenPair, type VerificationResult, type TokenValidationOptions, type TokenRequirements, } from './jwt/index.js';
3
+ export { hashPassword, hashPasswordWithPepper, hashPasswordSync, hashPasswordWithPepperSync, isPasswordStrong, verifyPassword, verifyPasswordWithPepper, verifyPasswordSync, verifyPasswordWithPepperSync, PasswordManager, type PasswordStrengthOptions, ensureValidPassword, safeCompare, estimatePasswordEntropy, normalizePassword, } from './password/index.js';
@@ -1,5 +1,5 @@
1
1
  import { type JwtPayload, type Secret } from 'jsonwebtoken';
2
- import type { AccessToken, ITokenManager, JWTConfig, RefreshToken, TokenPair } from '../../interfaces/jwt.interface';
2
+ import type { AccessToken, ITokenManager, JWTConfig, RefreshToken, TokenPair } from '../../interfaces/jwt.interface.js';
3
3
  export declare class JWTManager implements ITokenManager {
4
4
  private accessSecret;
5
5
  private refreshSecret;
@@ -1,4 +1,4 @@
1
1
  import type { Secret } from 'jsonwebtoken';
2
- import type { RefreshToken, TokenPair } from './types';
2
+ import type { RefreshToken, TokenPair } from './types.js';
3
3
  export declare const generateTokens: (payload: Record<string, unknown>, accessSecret: Secret, refreshSecret: Secret, accessExpiry?: string | number, refreshExpiry?: string | number) => TokenPair;
4
4
  export declare function rotateRefreshToken(oldToken: string, secret: Secret): RefreshToken;
@@ -1,8 +1,9 @@
1
- export * from './decode';
2
- export * from './extractToken';
3
- export * from './generateTokens';
4
- export * from './parseDuration';
5
- export * from './signToken';
6
- export * from './types';
7
- export * from './validateToken';
8
- export * from './verify';
1
+ export { decodeToken, decodeTokenStrict } from './decode.js';
2
+ export { extractToken, type TokenSources } from './extractToken.js';
3
+ export { generateTokens, rotateRefreshToken } from './generateTokens.js';
4
+ export { parseDuration } from './parseDuration.js';
5
+ export { signToken } from './signToken.js';
6
+ export { type AccessToken, type RefreshToken, type TokenPair, type VerificationResult, type TokenValidationOptions, } from './types.js';
7
+ export { validateTokenPayload, isTokenExpired, type TokenRequirements, } from './validateToken.js';
8
+ export { verifyToken, verifyTokenWithOptions, safeVerifyToken, safeVerifyTokenWithOptions, } from './verify.js';
9
+ export { JWTManager } from './JWTManager.js';
@@ -1,5 +1,5 @@
1
1
  import { type JwtPayload, type Secret, type VerifyOptions } from 'jsonwebtoken';
2
- import type { VerificationResult } from './types';
2
+ import type { VerificationResult } from './types.js';
3
3
  /**
4
4
  * Verify token (throws UnauthorizedError if invalid or expired)
5
5
  */
@@ -1,4 +1,4 @@
1
- import type { HashedPassword, IPasswordManager, PasswordConfig, PasswordStrength, PasswordValidationResult } from '../../interfaces/password.interface';
1
+ import type { HashedPassword, IPasswordManager, PasswordConfig, PasswordStrength, PasswordValidationResult } from '../../interfaces/password.interface.js';
2
2
  export declare class PasswordManager implements IPasswordManager {
3
3
  private defaultConfig;
4
4
  constructor(config?: PasswordConfig);
@@ -1,3 +1,6 @@
1
- export * from './hash';
2
- export * from './strength';
3
- export * from './verify';
1
+ export { hashPassword, hashPasswordWithPepper, hashPasswordSync, hashPasswordWithPepperSync, } from './hash.js';
2
+ export { isPasswordStrong } from './strength.js';
3
+ export { verifyPassword, verifyPasswordWithPepper, verifyPasswordSync, verifyPasswordWithPepperSync, } from './verify.js';
4
+ export { PasswordManager } from './PasswordManager.js';
5
+ export { type PasswordStrengthOptions } from './types.js';
6
+ export { ensureValidPassword, safeCompare, estimatePasswordEntropy, normalizePassword, } from './utils.js';
@@ -1,2 +1,2 @@
1
- import type { PasswordStrengthOptions } from './types';
1
+ import type { PasswordStrengthOptions } from './types.js';
2
2
  export declare const isPasswordStrong: (password: string, options?: PasswordStrengthOptions) => boolean;
@@ -1,40 +1 @@
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';
5
- import * as CryptoUtils from './core/crypto';
6
- import * as JWTUtils from './core/jwt';
7
- declare const _default: {
8
- decrypt: (data: string, secret: string) => string;
9
- encrypt: (text: string, secret: string) => string;
10
- hmacSign: (message: string, secret: string) => string;
11
- hmacVerify: (message: string, secret: string, signature: string) => boolean;
12
- randomToken: (length?: number) => string;
13
- generateStrongPassword: (length?: number) => string;
14
- CryptoManager: typeof CryptoUtils.CryptoManager;
15
- createCryptoManager: (config?: CryptoUtils.CryptoManagerConfig) => CryptoUtils.CryptoManager;
16
- cryptoManager: CryptoUtils.CryptoManager;
17
- decodeToken(token: string): null | string | import("node_modules/@types/jsonwebtoken").JwtPayload;
18
- decodeTokenStrict(token: string): import("node_modules/@types/jsonwebtoken").JwtPayload;
19
- extractToken(sources: JWTUtils.TokenSources): string | null;
20
- rotateRefreshToken(oldToken: string, secret: import("node_modules/@types/jsonwebtoken").Secret): JWTUtils.RefreshToken;
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
- parseDuration(input: string | number): number;
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): void;
25
- isTokenExpired(payload: import("node_modules/@types/jsonwebtoken").JwtPayload): boolean;
26
- verifyToken: (token: string, secret: import("node_modules/@types/jsonwebtoken").Secret) => string | import("node_modules/@types/jsonwebtoken").JwtPayload;
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;
29
- safeVerifyTokenWithOptions: (token: string, secret: import("node_modules/@types/jsonwebtoken").Secret, options?: import("node_modules/@types/jsonwebtoken").VerifyOptions) => JWTUtils.VerificationResult;
30
- hashPasswordWithPepper(password: string, pepper: string): Promise<string>;
31
- hashPasswordWithPepperSync(password: string, pepper: string): string;
32
- hashPassword: (password: string, saltRounds?: number) => Promise<string>;
33
- hashPasswordSync: (password: string, saltRounds?: number) => string;
34
- isPasswordStrong: (password: string, options?: import("./core/password/types").PasswordStrengthOptions) => boolean;
35
- verifyPasswordWithPepper(password: string, pepper: string, hash: string): Promise<boolean>;
36
- verifyPasswordWithPepperSync(password: string, pepper: string, hash: string): Promise<boolean>;
37
- verifyPassword: (password: string, hash: string) => Promise<boolean>;
38
- verifyPasswordSync: (password: string, hash: string) => boolean;
39
- };
40
- export default _default;
1
+ export * from './core/index.js';
@@ -0,0 +1,2 @@
1
+ export type { AccessToken, RefreshToken, TokenPair, JWTConfig, TokenValidationOptions, TokenGenerationOptions, ITokenManager, } from './jwt.interface.js';
2
+ export type { PasswordConfig, PasswordRule, PasswordStrength, PasswordValidationResult, HashedPassword, IPasswordManager, IPasswordStrengthChecker, } from './password.interface.js';
package/package.json CHANGED
@@ -1,15 +1,41 @@
1
1
  {
2
2
  "name": "@naman_deep_singh/security",
3
- "version": "1.6.0",
3
+ "version": "1.7.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",
7
7
  "module": "./dist/esm/index.js",
8
+ "types": "./dist/types/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
11
  "import": "./dist/esm/index.js",
11
12
  "require": "./dist/cjs/index.js",
12
13
  "types": "./dist/types/index.d.ts"
14
+ },
15
+ "./core": {
16
+ "import": "./dist/esm/core/index.js",
17
+ "require": "./dist/cjs/core/index.js",
18
+ "types": "./dist/types/core/index.d.ts"
19
+ },
20
+ "./core/crypto": {
21
+ "import": "./dist/esm/core/crypto/index.js",
22
+ "require": "./dist/cjs/core/crypto/index.js",
23
+ "types": "./dist/types/core/crypto/index.d.ts"
24
+ },
25
+ "./core/jwt": {
26
+ "import": "./dist/esm/core/jwt/index.js",
27
+ "require": "./dist/cjs/core/jwt/index.js",
28
+ "types": "./dist/types/core/jwt/index.d.ts"
29
+ },
30
+ "./core/password": {
31
+ "import": "./dist/esm/core/password/index.js",
32
+ "require": "./dist/cjs/core/password/index.js",
33
+ "types": "./dist/types/core/password/index.d.ts"
34
+ },
35
+ "./interfaces": {
36
+ "import": "./dist/esm/interfaces/index.js",
37
+ "require": "./dist/cjs/interfaces/index.js",
38
+ "types": "./dist/types/interfaces/index.d.ts"
13
39
  }
14
40
  },
15
41
  "sideEffects": false,
@@ -28,8 +54,8 @@
28
54
  "author": "Naman Deep Singh",
29
55
  "license": "ISC",
30
56
  "dependencies": {
31
- "@naman_deep_singh/errors": "^2.1.0",
32
- "@naman_deep_singh/utils": "^2.1.1",
57
+ "@naman_deep_singh/errors": "^2.3.0",
58
+ "@naman_deep_singh/utils": "^2.4.0",
33
59
  "bcryptjs": "^3.0.3",
34
60
  "jsonwebtoken": "^9.0.2"
35
61
  },
@@ -44,7 +70,7 @@
44
70
  },
45
71
  "scripts": {
46
72
  "build": "pnpm run build:types && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json",
47
- "build:types": "tsc -p tsconfig.base.json --emitDeclarationOnly --outDir dist/types",
73
+ "build:types": "tsc -p tsconfig.types.json",
48
74
  "clean": "rimraf dist"
49
75
  }
50
76
  }
@@ -1,111 +0,0 @@
1
- /**
2
- * Configuration options for CryptoManager
3
- */
4
- export interface CryptoManagerConfig {
5
- defaultAlgorithm?: string;
6
- defaultEncoding?: BufferEncoding;
7
- hmacAlgorithm?: string;
8
- }
9
- /**
10
- * CryptoManager - Class-based wrapper for all cryptographic operations
11
- * Provides a consistent interface for encryption, decryption, HMAC generation, and secure random generation
12
- */
13
- export declare class CryptoManager {
14
- private config;
15
- constructor(config?: CryptoManagerConfig);
16
- /**
17
- * Update configuration
18
- */
19
- updateConfig(config: Partial<CryptoManagerConfig>): void;
20
- /**
21
- * Get current configuration
22
- */
23
- getConfig(): Required<CryptoManagerConfig>;
24
- /**
25
- * Encrypt data using the default or specified algorithm
26
- */
27
- encrypt(plaintext: string, key: string, _options?: {
28
- algorithm?: string;
29
- encoding?: BufferEncoding;
30
- iv?: string;
31
- }): string;
32
- /**
33
- * Decrypt data using the default or specified algorithm
34
- */
35
- decrypt(encryptedData: string, key: string, _options?: {
36
- algorithm?: string;
37
- encoding?: BufferEncoding;
38
- iv?: string;
39
- }): string;
40
- /**
41
- * Generate HMAC signature
42
- */
43
- generateHmac(data: string, secret: string, _options?: {
44
- algorithm?: string;
45
- encoding?: BufferEncoding;
46
- }): string;
47
- /**
48
- * Generate cryptographically secure random bytes
49
- */
50
- generateSecureRandom(length: number, _encoding?: BufferEncoding): string;
51
- /**
52
- * Verify HMAC signature
53
- */
54
- verifyHmac(data: string, secret: string, signature: string, _options?: {
55
- algorithm?: string;
56
- encoding?: BufferEncoding;
57
- }): boolean;
58
- /**
59
- * Create a key derivation function using PBKDF2
60
- */
61
- deriveKey(password: string, salt: string, iterations?: number, keyLength?: number): Promise<string>;
62
- /**
63
- * Hash data using SHA-256
64
- */
65
- sha256(data: string, encoding?: BufferEncoding): string;
66
- /**
67
- * Hash data using SHA-512
68
- */
69
- sha512(data: string, encoding?: BufferEncoding): string;
70
- /**
71
- * Generate a secure key pair for asymmetric encryption
72
- */
73
- generateKeyPair(options?: {
74
- modulusLength?: number;
75
- publicKeyEncoding?: {
76
- type: string;
77
- format: string;
78
- };
79
- privateKeyEncoding?: {
80
- type: string;
81
- format: string;
82
- };
83
- }): Promise<{
84
- publicKey: string;
85
- privateKey: string;
86
- }>;
87
- /**
88
- * Encrypt data using RSA public key
89
- */
90
- rsaEncrypt(data: string, publicKey: string): Promise<string>;
91
- /**
92
- * Decrypt data using RSA private key
93
- */
94
- rsaDecrypt(encryptedData: string, privateKey: string): Promise<string>;
95
- /**
96
- * Create digital signature using RSA private key
97
- */
98
- rsaSign(data: string, privateKey: string, algorithm?: string): Promise<string>;
99
- /**
100
- * Verify digital signature using RSA public key
101
- */
102
- rsaVerify(data: string, signature: string, publicKey: string, algorithm?: string): Promise<boolean>;
103
- }
104
- /**
105
- * Create a CryptoManager instance with default configuration
106
- */
107
- export declare const createCryptoManager: (config?: CryptoManagerConfig) => CryptoManager;
108
- /**
109
- * Default CryptoManager instance
110
- */
111
- export declare const cryptoManager: CryptoManager;