namirasoft-node 1.4.126 → 1.4.128

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,6 @@
1
+ export declare class EncryptionOperation {
2
+ private static encrypt;
3
+ private static decrypt;
4
+ static AES256GCMEncrypt<T>(secret: string, message: T): string;
5
+ static AES256GCMDecrypt<T>(secret: string, message: string): T;
6
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
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 () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.EncryptionOperation = void 0;
37
+ const crypto = __importStar(require("node:crypto"));
38
+ class EncryptionOperation {
39
+ static encrypt(algorithm, secret, message) {
40
+ if (secret.length != 32)
41
+ throw new Error("Secret length must be exactly 32");
42
+ const secretBytes = Buffer.from(secret);
43
+ const iv = crypto.randomBytes(16);
44
+ const cipher = crypto.createCipheriv(algorithm, secretBytes, iv);
45
+ const encrypted = Buffer.concat([cipher.update(JSON.stringify(message), 'utf8'), cipher.final()]);
46
+ const authTag = cipher.getAuthTag();
47
+ const ivHex = iv.toString('hex');
48
+ const authTagHex = authTag.toString('hex');
49
+ const encryptedHex = encrypted.toString('hex');
50
+ return [ivHex, authTagHex, encryptedHex].join(";");
51
+ }
52
+ static decrypt(algorithm, secret, message) {
53
+ const [ivHex, authTagHex, encryptedHex] = message.split(';');
54
+ const iv = Buffer.from(ivHex, 'hex');
55
+ const authTag = Buffer.from(authTagHex, 'hex');
56
+ const encrypte = Buffer.from(encryptedHex, 'hex');
57
+ const decipher = crypto.createDecipheriv(algorithm, secret, iv);
58
+ decipher.setAuthTag(authTag);
59
+ let decrypted = decipher.update(encrypte);
60
+ decrypted = Buffer.concat([decrypted, decipher.final()]);
61
+ return JSON.parse(decrypted.toString());
62
+ }
63
+ static AES256GCMEncrypt(secret, message) {
64
+ return EncryptionOperation.encrypt("aes-256-gcm", secret, message);
65
+ }
66
+ static AES256GCMDecrypt(secret, message) {
67
+ return EncryptionOperation.decrypt("aes-256-gcm", secret, message);
68
+ }
69
+ }
70
+ exports.EncryptionOperation = EncryptionOperation;
71
+ //# sourceMappingURL=EncryptionOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptionOperation.js","sourceRoot":"","sources":["../src/EncryptionOperation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AAEtC,MAAa,mBAAmB;IAEpB,MAAM,CAAC,OAAO,CAAI,SAAiB,EAAE,MAAc,EAAE,OAAU;QAEnE,IAAI,MAAM,CAAC,MAAM,IAAI,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,kC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AC,SAAS,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QAC/D,QAAgB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAEtC,IAAI,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1C,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACzD,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC5C,CAAC;IACD,MAAM,CAAC,gBAAgB,CAAI,MAAc,EAAE,OAAU;QAEjD,OAAO,mBAAmB,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACvE,CAAC;IACD,MAAM,CAAC,gBAAgB,CAAI,MAAc,EAAE,OAAe;QAEtD,OAAO,mBAAmB,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACvE,CAAC;CACJ;AAtCD,kDAsCC"}
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export * from "./BaseFilterItemBuilderObject";
11
11
  export * from "./BaseTable";
12
12
  export * from "./BaseTableColumnOptions";
13
13
  export * from "./CommandOperation";
14
+ export * from "./EncryptionOperation";
14
15
  export * from "./GmailService";
15
16
  export * from "./IDatabase";
16
17
  export * from "./IPOperation";
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ __exportStar(require("./BaseFilterItemBuilderObject"), exports);
27
27
  __exportStar(require("./BaseTable"), exports);
28
28
  __exportStar(require("./BaseTableColumnOptions"), exports);
29
29
  __exportStar(require("./CommandOperation"), exports);
30
+ __exportStar(require("./EncryptionOperation"), exports);
30
31
  __exportStar(require("./GmailService"), exports);
31
32
  __exportStar(require("./IDatabase"), exports);
32
33
  __exportStar(require("./IPOperation"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,oDAAkC;AAClC,wDAAsC;AACtC,mDAAiC;AACjC,6CAA2B;AAC3B,iDAA+B;AAC/B,qDAAmC;AACnC,0DAAwC;AACxC,kEAAgD;AAChD,gEAA8C;AAC9C,8CAA4B;AAC5B,2DAAyC;AACzC,qDAAmC;AACnC,iDAA+B;AAC/B,8CAA4B;AAC5B,gDAA8B;AAC9B,yCAAuB;AACvB,iDAA+B;AAC/B,yDAAuC;AACvC,4DAA0C;AAC1C,gDAA8B;AAC9B,0CAAwB;AACxB,8CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,oDAAkC;AAClC,wDAAsC;AACtC,mDAAiC;AACjC,6CAA2B;AAC3B,iDAA+B;AAC/B,qDAAmC;AACnC,0DAAwC;AACxC,kEAAgD;AAChD,gEAA8C;AAC9C,8CAA4B;AAC5B,2DAAyC;AACzC,qDAAmC;AACnC,wDAAsC;AACtC,iDAA+B;AAC/B,8CAA4B;AAC5B,gDAA8B;AAC9B,yCAAuB;AACvB,iDAA+B;AAC/B,yDAAuC;AACvC,4DAA0C;AAC1C,gDAA8B;AAC9B,0CAAwB;AACxB,8CAA4B"}
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "framework": "npm",
9
9
  "application": "package",
10
10
  "private": false,
11
- "version": "1.4.126",
11
+ "version": "1.4.128",
12
12
  "author": "Amir Abolhasani",
13
13
  "license": "MIT",
14
14
  "main": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  "@supercharge/request-ip": "^1.2.0",
21
21
  "@types/cors": "^2.8.19",
22
22
  "@types/express": "^5.0.3",
23
- "@types/node": "^24.6.0",
23
+ "@types/node": "^24.7.0",
24
24
  "@types/node-cron": "^3.0.11",
25
25
  "@types/nodemailer": "^7.0.2",
26
26
  "@types/nodemailer-smtp-transport": "^2.7.8",
@@ -30,11 +30,11 @@
30
30
  "cors": "^2.8.5",
31
31
  "express": "^5.1.0",
32
32
  "joi": "^18.0.1",
33
- "namirasoft-core": "^1.4.92",
34
- "namirasoft-log": "^1.4.35",
33
+ "namirasoft-core": "^1.4.95",
34
+ "namirasoft-log": "^1.4.37",
35
35
  "namirasoft-schema": "^1.4.25",
36
36
  "node-cron": "^4.2.1",
37
- "nodemailer": "^7.0.6",
37
+ "nodemailer": "^7.0.7",
38
38
  "nodemailer-smtp-transport": "^2.7.4",
39
39
  "request-ip": "^3.3.0",
40
40
  "serve-index": "^1.9.1",
@@ -0,0 +1,41 @@
1
+ import * as crypto from 'node:crypto';
2
+
3
+ export class EncryptionOperation
4
+ {
5
+ private static encrypt<T>(algorithm: string, secret: string, message: T): string
6
+ {
7
+ if (secret.length != 32)
8
+ throw new Error("Secret length must be exactly 32");
9
+ const secretBytes = Buffer.from(secret);
10
+ const iv = crypto.randomBytes(16);
11
+ const cipher = crypto.createCipheriv(algorithm, secretBytes, iv);
12
+ const encrypted = Buffer.concat([cipher.update(JSON.stringify(message), 'utf8'), cipher.final()]);
13
+ const authTag = (cipher as any).getAuthTag();
14
+ const ivHex = iv.toString('hex');
15
+ const authTagHex = authTag.toString('hex');
16
+ const encryptedHex = encrypted.toString('hex');
17
+ return [ivHex, authTagHex, encryptedHex].join(";");
18
+ }
19
+ private static decrypt<T>(algorithm: string, secret: string, message: string): T
20
+ {
21
+ const [ivHex, authTagHex, encryptedHex] = message.split(';');
22
+ const iv = Buffer.from(ivHex, 'hex');
23
+ const authTag = Buffer.from(authTagHex, 'hex');
24
+ const encrypte = Buffer.from(encryptedHex, 'hex');
25
+
26
+ const decipher = crypto.createDecipheriv(algorithm, secret, iv);
27
+ (decipher as any).setAuthTag(authTag);
28
+
29
+ let decrypted = decipher.update(encrypte);
30
+ decrypted = Buffer.concat([decrypted, decipher.final()]);
31
+ return JSON.parse(decrypted.toString());
32
+ }
33
+ static AES256GCMEncrypt<T>(secret: string, message: T): string
34
+ {
35
+ return EncryptionOperation.encrypt("aes-256-gcm", secret, message);
36
+ }
37
+ static AES256GCMDecrypt<T>(secret: string, message: string): T
38
+ {
39
+ return EncryptionOperation.decrypt("aes-256-gcm", secret, message);
40
+ }
41
+ }
package/src/index.ts CHANGED
@@ -11,6 +11,7 @@ export * from "./BaseFilterItemBuilderObject";
11
11
  export * from "./BaseTable";
12
12
  export * from "./BaseTableColumnOptions";
13
13
  export * from "./CommandOperation";
14
+ export * from "./EncryptionOperation";
14
15
  export * from "./GmailService";
15
16
  export * from "./IDatabase";
16
17
  export * from "./IPOperation";