@btffamily/chekaam 1.0.1
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/build/brokers/nats/listener.ev.d.ts +29 -0
- package/build/brokers/nats/listener.ev.js +44 -0
- package/build/brokers/nats/publisher.ev.d.ts +19 -0
- package/build/brokers/nats/publisher.ev.js +28 -0
- package/build/brokers/nats/subjects.ev.d.ts +84 -0
- package/build/brokers/nats/subjects.ev.js +91 -0
- package/build/brokers/rabbitMQ/consumer.d.ts +35 -0
- package/build/brokers/rabbitMQ/consumer.js +74 -0
- package/build/brokers/rabbitMQ/exchanges.d.ts +54 -0
- package/build/brokers/rabbitMQ/exchanges.js +61 -0
- package/build/brokers/rabbitMQ/producer.d.ts +17 -0
- package/build/brokers/rabbitMQ/producer.js +40 -0
- package/build/dtos/auth.dto.d.ts +5 -0
- package/build/dtos/auth.dto.js +2 -0
- package/build/dtos/word.dto.d.ts +11 -0
- package/build/dtos/word.dto.js +2 -0
- package/build/index.d.ts +15 -0
- package/build/index.js +110 -0
- package/build/middleware/async.mw.d.ts +3 -0
- package/build/middleware/async.mw.js +4 -0
- package/build/middleware/auth.mw.d.ts +4 -0
- package/build/middleware/auth.mw.js +91 -0
- package/build/middleware/db.mw.d.ts +6 -0
- package/build/middleware/db.mw.js +43 -0
- package/build/middleware/redis.mw.d.ts +19 -0
- package/build/middleware/redis.mw.js +28 -0
- package/build/middleware/role.mw.d.ts +4 -0
- package/build/middleware/role.mw.js +19 -0
- package/build/services/auth.service.d.ts +13 -0
- package/build/services/auth.service.js +37 -0
- package/build/services/mongo.service.d.ts +7 -0
- package/build/services/mongo.service.js +14 -0
- package/build/services/random.service.d.ts +8 -0
- package/build/services/random.service.js +30 -0
- package/build/services/word.service.d.ts +8 -0
- package/build/services/word.service.js +73 -0
- package/build/src/ca-certificate.crt +32 -0
- package/build/src/index.ts +196 -0
- package/build/utils/cache.util.d.ts +3 -0
- package/build/utils/cache.util.js +7 -0
- package/build/utils/encryption.util.d.ts +66 -0
- package/build/utils/encryption.util.js +208 -0
- package/build/utils/functions.util.d.ts +134 -0
- package/build/utils/functions.util.js +1039 -0
- package/build/utils/interfaces.util.d.ts +25 -0
- package/build/utils/interfaces.util.js +2 -0
- package/build/utils/snippets/decryption.snippet.d.ts +0 -0
- package/build/utils/snippets/decryption.snippet.js +255 -0
- package/build/utils/types.util.d.ts +58 -0
- package/build/utils/types.util.js +2 -0
- package/package.json +49 -0
- package/readme.md +0 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import asyncHandler from './middleware/async.mw'
|
|
2
|
+
import { protect, authorize, permit } from './middleware/auth.mw'
|
|
3
|
+
import { Subjects, STGSubjects, DEVSubjects } from './brokers/nats/subjects.ev'
|
|
4
|
+
import { Exchanges, STGSExchanges, DEVExchanges } from './brokers/rabbitMQ/exchanges'
|
|
5
|
+
import Publisher from './brokers/nats/publisher.ev'
|
|
6
|
+
import Listener from './brokers/nats/publisher.ev'
|
|
7
|
+
import Consumer from './brokers/rabbitMQ/consumer'
|
|
8
|
+
import Producer from './brokers/rabbitMQ/producer'
|
|
9
|
+
import Random from './services/random.service'
|
|
10
|
+
import Mongo from './services/mongo.service'
|
|
11
|
+
import Encryption from './utils/encryption.util'
|
|
12
|
+
import { SyncAction, SyncType, SyncNotify, IDateToday, IDatesSplit, IMonthsSplit, DateCompare } from './utils/types.util';
|
|
13
|
+
import { IPermitOptions, IRedisConnOptions, IRedisData, IVerifyJWT } from './utils/interfaces.util'
|
|
14
|
+
import {
|
|
15
|
+
|
|
16
|
+
isObject,
|
|
17
|
+
isString,
|
|
18
|
+
isArray,
|
|
19
|
+
strToArray,
|
|
20
|
+
strToArrayEs6,
|
|
21
|
+
strIncludes,
|
|
22
|
+
strIncludesEs6,
|
|
23
|
+
arrayIncludes,
|
|
24
|
+
arrayIncludesEs6,
|
|
25
|
+
listIncludes,
|
|
26
|
+
timeToMinutes,
|
|
27
|
+
rangeFromMinutes,
|
|
28
|
+
dateToWord,
|
|
29
|
+
dateToWordRaw,
|
|
30
|
+
leadingNum,
|
|
31
|
+
dateToday,
|
|
32
|
+
isEmptyObject,
|
|
33
|
+
convertUrlToBase64,
|
|
34
|
+
urlToBase64,
|
|
35
|
+
sortData,
|
|
36
|
+
rearrangeArray,
|
|
37
|
+
isObjectId,
|
|
38
|
+
isPos,
|
|
39
|
+
isNeg,
|
|
40
|
+
isNumber,
|
|
41
|
+
isZero,
|
|
42
|
+
checkDateFormat,
|
|
43
|
+
checkTimeFormat,
|
|
44
|
+
dateIsToday,
|
|
45
|
+
dateIsYesterday,
|
|
46
|
+
dateIsEqual,
|
|
47
|
+
generate,
|
|
48
|
+
notDefined,
|
|
49
|
+
UIID,
|
|
50
|
+
compareISODate,
|
|
51
|
+
getWeeksDates,
|
|
52
|
+
getDatesInRange,
|
|
53
|
+
getWeeksInMonth,
|
|
54
|
+
validateBase64,
|
|
55
|
+
getCodeFromName,
|
|
56
|
+
getDaysFromDates,
|
|
57
|
+
lastDayOfMonth,
|
|
58
|
+
firstDayOfMonth,
|
|
59
|
+
isBase64,
|
|
60
|
+
getBase64Mime,
|
|
61
|
+
daysOfWeek,
|
|
62
|
+
monthsOfYear,
|
|
63
|
+
capitalize,
|
|
64
|
+
isPrecise,
|
|
65
|
+
hasDecimal,
|
|
66
|
+
formatISO,
|
|
67
|
+
hasSAC,
|
|
68
|
+
toDecimal,
|
|
69
|
+
charLen,
|
|
70
|
+
wordLen,
|
|
71
|
+
slugit,
|
|
72
|
+
isDefined,
|
|
73
|
+
objectToArray,
|
|
74
|
+
isJson,
|
|
75
|
+
arrayToObject,
|
|
76
|
+
formatDate,
|
|
77
|
+
arrayToSingleObject,
|
|
78
|
+
dateIsPast,
|
|
79
|
+
dateIsFuture,
|
|
80
|
+
yesterdayFromDate,
|
|
81
|
+
daysFromDates,
|
|
82
|
+
enumToArray,
|
|
83
|
+
stringToBase64,
|
|
84
|
+
base64ToString,
|
|
85
|
+
dateFromWeekNumber,
|
|
86
|
+
weekStartDate,
|
|
87
|
+
weekEndDate,
|
|
88
|
+
toMongoId,
|
|
89
|
+
pickFrom
|
|
90
|
+
} from './utils/functions.util'
|
|
91
|
+
|
|
92
|
+
export {
|
|
93
|
+
|
|
94
|
+
Subjects,
|
|
95
|
+
Publisher,
|
|
96
|
+
Listener,
|
|
97
|
+
STGSubjects,
|
|
98
|
+
DEVSubjects,
|
|
99
|
+
Consumer,
|
|
100
|
+
Producer,
|
|
101
|
+
Exchanges,
|
|
102
|
+
STGSExchanges,
|
|
103
|
+
DEVExchanges,
|
|
104
|
+
SyncAction,
|
|
105
|
+
SyncType,
|
|
106
|
+
SyncNotify,
|
|
107
|
+
Random,
|
|
108
|
+
Mongo,
|
|
109
|
+
asyncHandler,
|
|
110
|
+
protect,
|
|
111
|
+
authorize,
|
|
112
|
+
permit,
|
|
113
|
+
IPermitOptions,
|
|
114
|
+
IRedisConnOptions,
|
|
115
|
+
IRedisData,
|
|
116
|
+
IVerifyJWT,
|
|
117
|
+
IDateToday,
|
|
118
|
+
IDatesSplit,
|
|
119
|
+
IMonthsSplit,
|
|
120
|
+
DateCompare,
|
|
121
|
+
Encryption,
|
|
122
|
+
isObject,
|
|
123
|
+
isObjectId,
|
|
124
|
+
isPos,
|
|
125
|
+
isNeg,
|
|
126
|
+
isNumber,
|
|
127
|
+
isString,
|
|
128
|
+
isArray,
|
|
129
|
+
isBase64,
|
|
130
|
+
getBase64Mime,
|
|
131
|
+
strToArray,
|
|
132
|
+
strToArrayEs6,
|
|
133
|
+
strIncludes,
|
|
134
|
+
strIncludesEs6,
|
|
135
|
+
arrayIncludes,
|
|
136
|
+
arrayIncludesEs6,
|
|
137
|
+
listIncludes,
|
|
138
|
+
timeToMinutes,
|
|
139
|
+
rangeFromMinutes,
|
|
140
|
+
dateToWord,
|
|
141
|
+
dateToWordRaw,
|
|
142
|
+
leadingNum,
|
|
143
|
+
formatDate,
|
|
144
|
+
dateToday,
|
|
145
|
+
isEmptyObject,
|
|
146
|
+
convertUrlToBase64,
|
|
147
|
+
urlToBase64,
|
|
148
|
+
sortData,
|
|
149
|
+
rearrangeArray,
|
|
150
|
+
isZero,
|
|
151
|
+
checkDateFormat,
|
|
152
|
+
checkTimeFormat,
|
|
153
|
+
dateIsToday,
|
|
154
|
+
dateIsYesterday,
|
|
155
|
+
dateIsEqual,
|
|
156
|
+
dateIsPast,
|
|
157
|
+
dateIsFuture,
|
|
158
|
+
yesterdayFromDate,
|
|
159
|
+
generate,
|
|
160
|
+
notDefined,
|
|
161
|
+
isDefined,
|
|
162
|
+
UIID,
|
|
163
|
+
compareISODate,
|
|
164
|
+
getWeeksDates,
|
|
165
|
+
getDatesInRange,
|
|
166
|
+
getWeeksInMonth,
|
|
167
|
+
validateBase64,
|
|
168
|
+
getCodeFromName,
|
|
169
|
+
getDaysFromDates,
|
|
170
|
+
lastDayOfMonth,
|
|
171
|
+
firstDayOfMonth,
|
|
172
|
+
daysOfWeek,
|
|
173
|
+
monthsOfYear,
|
|
174
|
+
capitalize,
|
|
175
|
+
isPrecise,
|
|
176
|
+
hasDecimal,
|
|
177
|
+
toDecimal,
|
|
178
|
+
formatISO,
|
|
179
|
+
hasSAC,
|
|
180
|
+
charLen,
|
|
181
|
+
wordLen,
|
|
182
|
+
slugit,
|
|
183
|
+
objectToArray,
|
|
184
|
+
isJson,
|
|
185
|
+
arrayToObject,
|
|
186
|
+
arrayToSingleObject,
|
|
187
|
+
enumToArray,
|
|
188
|
+
stringToBase64,
|
|
189
|
+
base64ToString,
|
|
190
|
+
dateFromWeekNumber,
|
|
191
|
+
daysFromDates,
|
|
192
|
+
weekStartDate,
|
|
193
|
+
weekEndDate,
|
|
194
|
+
toMongoId,
|
|
195
|
+
pickFrom
|
|
196
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
interface IResult {
|
|
4
|
+
error: boolean;
|
|
5
|
+
message: string;
|
|
6
|
+
code?: number;
|
|
7
|
+
salt?: string;
|
|
8
|
+
authTag?: string;
|
|
9
|
+
vector: string;
|
|
10
|
+
data: any;
|
|
11
|
+
}
|
|
12
|
+
declare class Encryption {
|
|
13
|
+
private KEY_LENGTH;
|
|
14
|
+
private HASH_TYPE;
|
|
15
|
+
private ITERATIONS;
|
|
16
|
+
private GCM2_IV_LENGTH;
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* @name getAlgorithm
|
|
20
|
+
* @description Get encryption/decryption algorithm
|
|
21
|
+
* @param type
|
|
22
|
+
* @returns {string} see string
|
|
23
|
+
*/
|
|
24
|
+
private getAlgorithm;
|
|
25
|
+
deriveKeyFromPassword(password: string): string;
|
|
26
|
+
deriveKeyFromPassword(password: string, salt: Buffer): Promise<Buffer>;
|
|
27
|
+
/**
|
|
28
|
+
* @name encryptAESGCM
|
|
29
|
+
* @description Encrypt data using AES-CBC algorithm with preferred password
|
|
30
|
+
* @param data
|
|
31
|
+
* @param password
|
|
32
|
+
* @returns {IResult} see IResult
|
|
33
|
+
*/
|
|
34
|
+
encryptAESGCM(data: any, password: string): IResult;
|
|
35
|
+
/**
|
|
36
|
+
* @name decryptAESGCM
|
|
37
|
+
* @description Encrypt data using AES-CBC algorithm with encrypted password
|
|
38
|
+
* @param encrypted
|
|
39
|
+
* @param vector
|
|
40
|
+
* @param password
|
|
41
|
+
* @returns {IResult} see IResult
|
|
42
|
+
*/
|
|
43
|
+
decryptAESGCM(encrypted: any, vector: string, password: string): IResult;
|
|
44
|
+
/**
|
|
45
|
+
* @name encryptAESGCM2
|
|
46
|
+
* @description Encrypts data string using AES-GCM
|
|
47
|
+
* @param data
|
|
48
|
+
* @param password
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
encryptAESGCM2(data: any, password: string): Promise<IResult>;
|
|
52
|
+
/**
|
|
53
|
+
* @name decryptAESGCM2
|
|
54
|
+
* @description Decrypts an encrypted data using AES-GCM
|
|
55
|
+
* @param data
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
decryptAESGCM2(data: {
|
|
59
|
+
encrypted: any;
|
|
60
|
+
salt: string;
|
|
61
|
+
vector: string;
|
|
62
|
+
password: string;
|
|
63
|
+
}): Promise<IResult>;
|
|
64
|
+
}
|
|
65
|
+
declare const _default: Encryption;
|
|
66
|
+
export default _default;
|
|
@@ -0,0 +1,208 @@
|
|
|
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
|
+
const console_1 = require("console");
|
|
7
|
+
const functions_util_1 = require("./functions.util");
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
class Encryption {
|
|
10
|
+
KEY_LENGTH;
|
|
11
|
+
HASH_TYPE;
|
|
12
|
+
ITERATIONS;
|
|
13
|
+
// GCM-Based properties
|
|
14
|
+
GCM2_IV_LENGTH;
|
|
15
|
+
constructor() {
|
|
16
|
+
this.KEY_LENGTH = 32;
|
|
17
|
+
this.HASH_TYPE = 'sha512';
|
|
18
|
+
this.ITERATIONS = 100000;
|
|
19
|
+
/*
|
|
20
|
+
GCM and some othere mode requires 12 bytes for the IV
|
|
21
|
+
*/
|
|
22
|
+
this.GCM2_IV_LENGTH = 12;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @name getAlgorithm
|
|
26
|
+
* @description Get encryption/decryption algorithm
|
|
27
|
+
* @param type
|
|
28
|
+
* @returns {string} see string
|
|
29
|
+
*/
|
|
30
|
+
getAlgorithm(type) {
|
|
31
|
+
let algorithm = '';
|
|
32
|
+
if (type === 'cbc') {
|
|
33
|
+
algorithm = 'aes-256-cbc';
|
|
34
|
+
}
|
|
35
|
+
if (type === 'gcm') {
|
|
36
|
+
algorithm = 'aes-256-gcm';
|
|
37
|
+
}
|
|
38
|
+
return algorithm;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @name deriveKeyFromPassword
|
|
42
|
+
* @description Derive 256 bit encryption key from password, using salt and iterations -> 32 bytes
|
|
43
|
+
* @param password
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
deriveKeyFromPassword(password, salt) {
|
|
47
|
+
let key = '';
|
|
48
|
+
if (salt) {
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
crypto_1.default.pbkdf2(password, salt, this.ITERATIONS, this.KEY_LENGTH, this.HASH_TYPE, (err, derivedKey) => {
|
|
51
|
+
if (err)
|
|
52
|
+
reject(err);
|
|
53
|
+
resolve(derivedKey);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
key = crypto_1.default.createHash('sha512').update(password).digest('hex').substring(0, 32);
|
|
59
|
+
}
|
|
60
|
+
return key;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @name encryptAESGCM
|
|
64
|
+
* @description Encrypt data using AES-CBC algorithm with preferred password
|
|
65
|
+
* @param data
|
|
66
|
+
* @param password
|
|
67
|
+
* @returns {IResult} see IResult
|
|
68
|
+
*/
|
|
69
|
+
encryptAESGCM(data, password) {
|
|
70
|
+
let result = { error: false, message: '', code: 200, vector: '', data: null };
|
|
71
|
+
try {
|
|
72
|
+
if ((0, functions_util_1.isObject)(data)) {
|
|
73
|
+
data = JSON.stringify(data);
|
|
74
|
+
}
|
|
75
|
+
let IV = crypto_1.default.randomBytes(16);
|
|
76
|
+
let cipher = crypto_1.default.createCipheriv(this.getAlgorithm('cbc'), this.deriveKeyFromPassword(password), IV);
|
|
77
|
+
let encrypted = cipher.update(data);
|
|
78
|
+
encrypted = Buffer.concat([encrypted, cipher.final()]);
|
|
79
|
+
result = {
|
|
80
|
+
error: false,
|
|
81
|
+
message: 'encryption successful',
|
|
82
|
+
vector: IV.toString('hex'),
|
|
83
|
+
data: encrypted.toString('hex')
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
console.log(error);
|
|
88
|
+
result = {
|
|
89
|
+
error: true,
|
|
90
|
+
message: 'could not encrypt data',
|
|
91
|
+
data: null,
|
|
92
|
+
vector: ''
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @name decryptAESGCM
|
|
99
|
+
* @description Encrypt data using AES-CBC algorithm with encrypted password
|
|
100
|
+
* @param encrypted
|
|
101
|
+
* @param vector
|
|
102
|
+
* @param password
|
|
103
|
+
* @returns {IResult} see IResult
|
|
104
|
+
*/
|
|
105
|
+
decryptAESGCM(encrypted, vector, password) {
|
|
106
|
+
let result = { error: false, message: '', vector: '', code: 200, data: null };
|
|
107
|
+
try {
|
|
108
|
+
let IV = Buffer.from(vector, 'hex');
|
|
109
|
+
let encryptedText = Buffer.from(encrypted, 'hex');
|
|
110
|
+
let decipher = crypto_1.default.createDecipheriv(this.getAlgorithm('cbc'), this.deriveKeyFromPassword(password), IV);
|
|
111
|
+
let decrypted = decipher.update(encryptedText);
|
|
112
|
+
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
113
|
+
result = {
|
|
114
|
+
error: false,
|
|
115
|
+
message: 'decryption successful',
|
|
116
|
+
data: decrypted.toString(),
|
|
117
|
+
vector: IV.toString('hex')
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
console.log(error);
|
|
122
|
+
result = {
|
|
123
|
+
error: true,
|
|
124
|
+
message: 'could not decrypt data',
|
|
125
|
+
data: null,
|
|
126
|
+
vector: ''
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @name encryptAESGCM2
|
|
133
|
+
* @description Encrypts data string using AES-GCM
|
|
134
|
+
* @param data
|
|
135
|
+
* @param password
|
|
136
|
+
* @returns
|
|
137
|
+
*/
|
|
138
|
+
async encryptAESGCM2(data, password) {
|
|
139
|
+
let result = { error: false, message: '', code: 200, vector: '', data: null };
|
|
140
|
+
try {
|
|
141
|
+
if ((0, functions_util_1.isObject)(data)) {
|
|
142
|
+
data = JSON.stringify(data);
|
|
143
|
+
}
|
|
144
|
+
const SALT = crypto_1.default.randomBytes(16); // 16 bytes is a common salt length
|
|
145
|
+
let PASSKEY = await this.deriveKeyFromPassword(password, SALT);
|
|
146
|
+
let IV = crypto_1.default.randomBytes(this.GCM2_IV_LENGTH);
|
|
147
|
+
let cipher = crypto_1.default.createCipheriv(this.getAlgorithm('gcm'), PASSKEY, IV);
|
|
148
|
+
// cipher.getAuthTag();
|
|
149
|
+
let encrypted = cipher.update(data);
|
|
150
|
+
encrypted = Buffer.concat([encrypted, cipher.final()]);
|
|
151
|
+
result = {
|
|
152
|
+
error: false,
|
|
153
|
+
message: 'encryption successful',
|
|
154
|
+
salt: SALT.toString('base64'),
|
|
155
|
+
vector: IV.toString('base64'),
|
|
156
|
+
data: encrypted.toString('base64')
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
catch (err) {
|
|
160
|
+
console.log(console_1.error);
|
|
161
|
+
result = {
|
|
162
|
+
error: true,
|
|
163
|
+
message: 'could not encrypt data',
|
|
164
|
+
data: null,
|
|
165
|
+
vector: ''
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* @name decryptAESGCM2
|
|
172
|
+
* @description Decrypts an encrypted data using AES-GCM
|
|
173
|
+
* @param data
|
|
174
|
+
* @returns
|
|
175
|
+
*/
|
|
176
|
+
async decryptAESGCM2(data) {
|
|
177
|
+
let result = { error: false, message: '', code: 200, vector: '', data: null };
|
|
178
|
+
const { encrypted, salt, vector, password } = data;
|
|
179
|
+
try {
|
|
180
|
+
let SALT = Buffer.from(salt, 'base64');
|
|
181
|
+
let IV = Buffer.from(vector, 'base64');
|
|
182
|
+
let encryptedText = Buffer.from(encrypted, 'base64');
|
|
183
|
+
let PASSKEY = await this.deriveKeyFromPassword(password, SALT);
|
|
184
|
+
let decipher = crypto_1.default.createDecipheriv(this.getAlgorithm('gcm'), PASSKEY, IV);
|
|
185
|
+
// decipher.setAuthTag();
|
|
186
|
+
let decrypted = decipher.update(encryptedText);
|
|
187
|
+
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
188
|
+
result = {
|
|
189
|
+
error: false,
|
|
190
|
+
vector: IV.toString('base64'),
|
|
191
|
+
salt: SALT.toString('base64'),
|
|
192
|
+
message: 'decryption successful',
|
|
193
|
+
data: decrypted.toString('utf8'),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
console.log(err);
|
|
198
|
+
result = {
|
|
199
|
+
error: true,
|
|
200
|
+
message: 'could not decrypt data',
|
|
201
|
+
data: null,
|
|
202
|
+
vector: ''
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.default = new Encryption();
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { DateCompare, IArrayToObject, IBase64ToString, IDateToday, IDateIsPast, IDatesSplit, IMonthsSplit, ISlugit, IStringToBase64, FormatDateType } from './types.util';
|
|
3
|
+
import { AxiosRequestConfig } from 'axios';
|
|
4
|
+
export declare const slugit: (payload: ISlugit) => string;
|
|
5
|
+
export declare const charLen: (data: string) => number;
|
|
6
|
+
export declare const wordLen: (data: string) => number;
|
|
7
|
+
export declare const isObject: (arg: any) => boolean;
|
|
8
|
+
export declare const isString: (arg: any) => boolean;
|
|
9
|
+
export declare const isArray: (arg: any) => boolean;
|
|
10
|
+
export declare const strToArray: (arg: string, split: string) => Array<string>;
|
|
11
|
+
export declare const strToArrayEs6: (arg: string, split: string) => Array<string>;
|
|
12
|
+
export declare const strIncludes: (arg: any, inc: string) => boolean;
|
|
13
|
+
export declare const strIncludesEs6: (arg: any, inc: string) => boolean;
|
|
14
|
+
export declare const arrayIncludesEs6: (arr: Array<any>, inc: string) => boolean;
|
|
15
|
+
export declare const arrayIncludes: (arr: Array<any>, inc: string) => boolean;
|
|
16
|
+
export declare const listIncludes: (data: {
|
|
17
|
+
arr: Array<string>;
|
|
18
|
+
list: Array<string>;
|
|
19
|
+
type: 'some' | 'every';
|
|
20
|
+
}) => boolean;
|
|
21
|
+
export declare const timeToMinutes: (data: {
|
|
22
|
+
hr: number;
|
|
23
|
+
min: number;
|
|
24
|
+
sec: number;
|
|
25
|
+
}) => number;
|
|
26
|
+
export declare const rangeFromMinutes: (dur: number) => {
|
|
27
|
+
start: Date;
|
|
28
|
+
end: Date;
|
|
29
|
+
diff: number;
|
|
30
|
+
};
|
|
31
|
+
export declare const dateToWord: (date: any) => string;
|
|
32
|
+
export declare const dateToWordRaw: () => string;
|
|
33
|
+
export declare const isEmptyObject: (obj: object) => boolean;
|
|
34
|
+
export declare const isBase64: (data: string) => boolean;
|
|
35
|
+
export declare const getBase64Mime: (data: string) => string;
|
|
36
|
+
export declare const capitalize: (word: string, each?: boolean) => string;
|
|
37
|
+
export declare const convertUrlToBase64: (url: string) => Promise<any>;
|
|
38
|
+
export declare const urlToBase64: (url: string, headers?: AxiosRequestConfig['headers']) => Promise<string | undefined>;
|
|
39
|
+
export declare const leadingNum: (val: number, length?: number, pad?: string) => string;
|
|
40
|
+
export declare const daysOfWeek: () => Array<{
|
|
41
|
+
id: number;
|
|
42
|
+
name: string;
|
|
43
|
+
}>;
|
|
44
|
+
export declare const monthsOfYear: () => Array<{
|
|
45
|
+
id: number;
|
|
46
|
+
name: string;
|
|
47
|
+
}>;
|
|
48
|
+
export declare const formatDate: (date: any, type: FormatDateType) => string;
|
|
49
|
+
export declare const dateToday: (d?: any) => IDateToday;
|
|
50
|
+
export declare const sortData: (data: Array<any>, prop?: string) => Array<any>;
|
|
51
|
+
export declare const rearrangeArray: (from: number, to: number, arr: Array<any>) => Array<any>;
|
|
52
|
+
export declare const isObjectId: (val: string) => boolean;
|
|
53
|
+
export declare const isPos: (val: number) => boolean;
|
|
54
|
+
export declare const isNeg: (val: number) => boolean;
|
|
55
|
+
export declare const isNumber: (val: any) => boolean;
|
|
56
|
+
export declare const isZero: (val: any) => boolean;
|
|
57
|
+
export declare const checkDateFormat: (date: string) => boolean;
|
|
58
|
+
export declare const checkTimeFormat: (time: string) => boolean;
|
|
59
|
+
export declare const dateIsToday: (date: string) => boolean;
|
|
60
|
+
export declare const dateIsYesterday: (date: string) => boolean;
|
|
61
|
+
export declare const dateIsEqual: (fDate: string, lDate: string) => boolean;
|
|
62
|
+
export declare const dateIsPast: (data: IDateIsPast) => boolean;
|
|
63
|
+
export declare const dateIsFuture: (today: string, date: string) => boolean;
|
|
64
|
+
export declare const yesterdayFromDate: (date: string) => string;
|
|
65
|
+
export declare const daysFromDates: (data: {
|
|
66
|
+
start: string;
|
|
67
|
+
end: string;
|
|
68
|
+
dir: 'default' | 'reverse';
|
|
69
|
+
}) => number;
|
|
70
|
+
export declare const generate: (size: number, options: {
|
|
71
|
+
type: 'code' | 'alpha' | 'num';
|
|
72
|
+
alpha: boolean;
|
|
73
|
+
}) => string;
|
|
74
|
+
export declare const notDefined: (val: any, truthy?: boolean) => boolean;
|
|
75
|
+
export declare const isDefined: (val: any, truthy?: boolean) => boolean;
|
|
76
|
+
export declare const isPrecise: (data: {
|
|
77
|
+
value: number | string;
|
|
78
|
+
length: number;
|
|
79
|
+
}) => boolean;
|
|
80
|
+
export declare const hasDecimal: (value: number | string) => boolean;
|
|
81
|
+
export declare const toDecimal: (value: number, places: number) => number;
|
|
82
|
+
export declare const UIID: (batch?: number) => string;
|
|
83
|
+
export declare const compareISODate: (dateA: string, dateB: string, type: DateCompare) => boolean;
|
|
84
|
+
export declare const getWeeksDates: (year: number, month: number, data: Array<IMonthsSplit>) => Array<IDatesSplit>;
|
|
85
|
+
export declare const getDatesInRange: (start: string, end: string) => Array<string>;
|
|
86
|
+
export declare const getWeeksInMonth: (year: number, month: number) => Array<IMonthsSplit>;
|
|
87
|
+
export declare const validateBase64: (data: string) => boolean;
|
|
88
|
+
export declare const getCodeFromName: (name: string) => string;
|
|
89
|
+
/**
|
|
90
|
+
* @name getDaysFromDates
|
|
91
|
+
* @param prev
|
|
92
|
+
* @param next
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
export declare const getDaysFromDates: (then: string, now: string) => number;
|
|
96
|
+
/**
|
|
97
|
+
* @name firstDayOfMonth
|
|
98
|
+
* @param d
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
export declare const firstDayOfMonth: (d?: string) => {
|
|
102
|
+
date: Date;
|
|
103
|
+
converted: IDateToday;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* @name lastDayOfMonth
|
|
107
|
+
* @param d
|
|
108
|
+
* @returns
|
|
109
|
+
*/
|
|
110
|
+
export declare const lastDayOfMonth: (d?: string) => {
|
|
111
|
+
date: Date;
|
|
112
|
+
converted: IDateToday;
|
|
113
|
+
};
|
|
114
|
+
export declare const formatISO: (ISO: string) => {
|
|
115
|
+
date: string;
|
|
116
|
+
time: string;
|
|
117
|
+
};
|
|
118
|
+
export declare const hasSAC: (value: string) => boolean;
|
|
119
|
+
export declare const enumToArray: (data: Object, type: 'all' | 'values-only' | 'keys-only') => any[];
|
|
120
|
+
export declare const objectToArray: (data: Object) => {
|
|
121
|
+
key: any;
|
|
122
|
+
value: any;
|
|
123
|
+
type: any;
|
|
124
|
+
}[];
|
|
125
|
+
export declare const isJson: (value: string) => boolean;
|
|
126
|
+
export declare const arrayToObject: (data: Array<IArrayToObject>) => any;
|
|
127
|
+
export declare const arrayToSingleObject: (data: Array<any>) => any;
|
|
128
|
+
export declare const stringToBase64: (data: IStringToBase64) => string;
|
|
129
|
+
export declare const base64ToString: (data: IBase64ToString) => string;
|
|
130
|
+
export declare const dateFromWeekNumber: (weekNum: number) => IDateToday;
|
|
131
|
+
export declare const weekStartDate: (date: string) => IDateToday;
|
|
132
|
+
export declare const weekEndDate: (date: string) => IDateToday;
|
|
133
|
+
export declare const toMongoId: (id: string) => mongoose.Types.ObjectId;
|
|
134
|
+
export declare const pickFrom: <T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]) => Pick<T, K>;
|