@bearei/server-common 0.0.75 → 0.0.77

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.
@@ -1,3 +1,3 @@
1
- export declare const processSignString: (object: Record<string, string>) => string;
2
- export declare const hash: (saltOrRounds?: string | number) => (object: Record<string, string>) => Promise<string>;
3
- export declare const compare: (data: Record<string, string> | string) => (encrypted: string) => Promise<boolean>;
1
+ export declare const processSignString: (object: Record<string, string | number>) => string;
2
+ export declare const sign: (saltRounds?: number) => (object: Record<string, string>) => Promise<string>;
3
+ export declare const signCompare: (data: Record<string, string> | string) => (hash: string) => Promise<boolean>;
@@ -1,23 +1,54 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.compare = exports.hash = exports.processSignString = void 0;
7
- const bcrypt_1 = __importDefault(require("bcrypt"));
8
- const processSignString = (object) => Object.entries(object)
9
- .sort((a, b) => a[0].toLowerCase().localeCompare(b[0].toLowerCase()))
10
- .reduce((accumulator, [key, value]) => [...accumulator, `${key}:${value}`], [])
11
- .join(':');
26
+ exports.signCompare = exports.sign = exports.processSignString = void 0;
27
+ const bcrypt = __importStar(require("bcrypt"));
28
+ const app_interface_1 = require("../app.interface");
29
+ const error_util_1 = require("./error.util");
30
+ const processSignString = (object) => {
31
+ const signString = `${Object.entries(object)
32
+ .sort((a, b) => a[0].toLowerCase().localeCompare(b[0].toLowerCase()))
33
+ .reduce((accumulator, [_, value]) => (value ? [...accumulator, value] : accumulator), [])
34
+ .join('&')}`;
35
+ signString.length > 56 &&
36
+ (0, error_util_1.throwAPIError)({
37
+ code: '400005',
38
+ message: 'The maximum length of the signature string is more than 56 strings'
39
+ })(app_interface_1.APIError.BAD_REQUEST);
40
+ return signString;
41
+ };
12
42
  exports.processSignString = processSignString;
13
- const hash = (saltOrRounds = 10) => async (object) => {
14
- const bcryptData = (0, exports.processSignString)(object);
15
- return bcrypt_1.default.hash(bcryptData, saltOrRounds);
43
+ const sign = (saltRounds = 10) => async (object) => {
44
+ const sign = (0, exports.processSignString)(object);
45
+ const salt = await bcrypt.genSalt(saltRounds);
46
+ return bcrypt.hash(sign, salt);
16
47
  };
17
- exports.hash = hash;
18
- const compare = (data) => {
19
- const bcryptData = typeof data === 'string' ? data : (0, exports.processSignString)(data);
20
- return async (encrypted) => bcrypt_1.default.compare(bcryptData, encrypted);
48
+ exports.sign = sign;
49
+ const signCompare = (data) => {
50
+ const sign = typeof data === 'string' ? data : (0, exports.processSignString)(data);
51
+ return async (hash) => bcrypt.compare(sign, hash);
21
52
  };
22
- exports.compare = compare;
53
+ exports.signCompare = signCompare;
23
54
  //# sourceMappingURL=sign.util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sign.util.js","sourceRoot":"","sources":["../../src/util/sign.util.ts"],"names":[],"mappings":";;;;;;AAAA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C,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,yBAAiB,EAAC,IAAI,CAAC,CAAA;IAEtE,OAAO,KAAK,EAAE,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AAC7D,CAAC,CAAA;AAJY,QAAA,WAAW,eAIvB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bearei/server-common",
3
- "version": "0.0.75",
3
+ "version": "0.0.77",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "bearei <bear_ei@outlook.com>",