@devshopapp/common 1.0.7 → 1.0.8

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
+ export interface JwtPayload {
2
+ email: string;
3
+ userId: string;
4
+ }
5
+ //# sourceMappingURL=global.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../../src/constants/global.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAClB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.js","sourceRoot":"","sources":["../../../src/constants/global.ts"],"names":[],"mappings":""}
@@ -9,4 +9,5 @@ export * from './errors/not.found.error.js';
9
9
  export * from './errors/custom.errors.js';
10
10
  export * from './errors/request.validation.error.js';
11
11
  export * from './constants/auth/user.interfaces.js';
12
+ export * from './services/authentication.service.js';
12
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gDAAgD,CAAC;AAE/D,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uCAAuC,CAAC;AACtD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sCAAsC,CAAC;AAErD,cAAc,qCAAqC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gDAAgD,CAAC;AAE/D,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uCAAuC,CAAC;AACtD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sCAAsC,CAAC;AAErD,cAAc,qCAAqC,CAAA;AAEnD,cAAc,sCAAsC,CAAA"}
@@ -9,4 +9,5 @@ export * from './errors/not.found.error.js';
9
9
  export * from './errors/custom.errors.js';
10
10
  export * from './errors/request.validation.error.js';
11
11
  export * from './constants/auth/user.interfaces.js';
12
+ export * from './services/authentication.service.js';
12
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gDAAgD,CAAC;AAE/D,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uCAAuC,CAAC;AACtD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sCAAsC,CAAC;AAErD,cAAc,qCAAqC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gDAAgD,CAAC;AAE/D,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uCAAuC,CAAC;AACtD,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sCAAsC,CAAC;AAErD,cAAc,qCAAqC,CAAA;AAEnD,cAAc,sCAAsC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { JwtPayload } from '../constants/global.js';
2
+ export declare class AuthenticationService {
3
+ private static encryptPassword;
4
+ generateJwt(payload: JwtPayload, JWT_KEY: string): string;
5
+ pwdToHash(password: string): Promise<string>;
6
+ pwdCompare(storedPassword: string, suppliedPassword: string): Promise<boolean>;
7
+ }
8
+ //# sourceMappingURL=authentication.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.service.d.ts","sourceRoot":"","sources":["../../../src/services/authentication.service.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,qBAAa,qBAAqB;mBACT,eAAe;IAIpC,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM;IAI1C,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAM5C,UAAU,CAAC,cAAc,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAQvF"}
@@ -0,0 +1,27 @@
1
+ import jwt from 'jsonwebtoken';
2
+ import { scrypt, randomBytes, timingSafeEqual } from "crypto";
3
+ import { promisify } from "util";
4
+ const scryptAsync = promisify(scrypt);
5
+ export class AuthenticationService {
6
+ static async encryptPassword(password, salt, length = 64) {
7
+ return (await scryptAsync(password, salt, length));
8
+ }
9
+ generateJwt(payload, JWT_KEY) {
10
+ return jwt.sign(payload, JWT_KEY);
11
+ }
12
+ async pwdToHash(password) {
13
+ const salt = randomBytes(16).toString("hex");
14
+ const buf = await AuthenticationService.encryptPassword(password, salt);
15
+ return `${buf.toString("hex")}.${salt}`;
16
+ }
17
+ async pwdCompare(storedPassword, suppliedPassword) {
18
+ const parts = storedPassword.split(".");
19
+ if (parts.length !== 2)
20
+ return false;
21
+ const [hashedPassword, salt] = parts;
22
+ const buf = await AuthenticationService.encryptPassword(suppliedPassword, salt);
23
+ const hashedBuffer = Buffer.from(hashedPassword, "hex");
24
+ return timingSafeEqual(buf, hashedBuffer);
25
+ }
26
+ }
27
+ //# sourceMappingURL=authentication.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.service.js","sourceRoot":"","sources":["../../../src/services/authentication.service.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAIjC,MAAM,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAEtC,MAAM,OAAO,qBAAqB;IACtB,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,QAAgB,EAAE,IAAY,EAAE,SAAiB,EAAE;QACpF,OAAO,CAAC,MAAM,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAW,CAAC;IACjE,CAAC;IAED,WAAW,CAAC,OAAmB,EAAE,OAAe;QAC5C,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,QAAgB;QAC5B,MAAM,IAAI,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC7C,MAAM,GAAG,GAAG,MAAM,qBAAqB,CAAC,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACxE,OAAO,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,cAAsB,EAAE,gBAAwB;QAC7D,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACxC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACrC,MAAM,CAAC,cAAc,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC;QACrC,MAAM,GAAG,GAAG,MAAM,qBAAqB,CAAC,eAAe,CAAC,gBAAgB,EAAE,IAAK,CAAC,CAAC;QACjF,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,cAAe,EAAE,KAAK,CAAC,CAAC;QACzD,OAAO,eAAe,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IAC9C,CAAC;CACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devshopapp/common",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "A common utils package for the different services in the shopping application",
5
5
  "type": "module",
6
6
  "types": "./build/src/index.d.ts",