ismx-nexo-node-app 0.4.117 → 0.4.119

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.
@@ -37,7 +37,7 @@ class CryptoUtils {
37
37
  const pad = Buffer.alloc((blocksize - (buf.length % blocksize)) % blocksize, 0);
38
38
  return Buffer.concat([buf, pad]);
39
39
  }
40
- static encrypt3DES(key, message) {
40
+ static symEncrypt(key, message) {
41
41
  return __awaiter(this, void 0, void 0, function* () {
42
42
  var _a;
43
43
  let crypto = (_a = this.crypto) !== null && _a !== void 0 ? _a : (yield Promise.resolve().then(() => __importStar(require("crypto")))).default;
@@ -54,11 +54,27 @@ class CryptoUtils {
54
54
  return encryptedBuf.slice(0, maxLength);
55
55
  });
56
56
  }
57
+ static symDecrypt(key, encrypted) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ var _a;
60
+ let crypto = (_a = this.crypto) !== null && _a !== void 0 ? _a : (yield Promise.resolve().then(() => __importStar(require("crypto")))).default;
61
+ const keyBuf = Buffer.from(key, 'base64');
62
+ const iv = Buffer.alloc(8, 0);
63
+ const decipher = crypto.createDecipheriv('des-ede3-cbc', keyBuf, iv);
64
+ decipher.setAutoPadding(false);
65
+ const decryptedBuf = Buffer.concat([
66
+ decipher.update(encrypted),
67
+ decipher.final()
68
+ ]);
69
+ // Remove zero padding
70
+ return decryptedBuf.toString('utf8').replace(/\x00+$/g, '');
71
+ });
72
+ }
57
73
  static sha256Sign(merchantKey, orderId, encodedOrder) {
58
74
  return __awaiter(this, void 0, void 0, function* () {
59
75
  var _a;
60
76
  let crypto = (_a = this.crypto) !== null && _a !== void 0 ? _a : (yield Promise.resolve().then(() => __importStar(require("crypto")))).default;
61
- const orderKeyBuf = yield CryptoUtils.encrypt3DES(merchantKey, orderId);
77
+ const orderKeyBuf = yield CryptoUtils.symEncrypt(merchantKey, orderId);
62
78
  return crypto.createHmac('sha256', orderKeyBuf).update(encodedOrder).digest('base64');
63
79
  });
64
80
  }
@@ -237,7 +237,7 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
237
237
  return __awaiter(this, arguments, void 0, function* (name, params = [], filters = {}) {
238
238
  var _a;
239
239
  let { where, values } = this.anyWhere(filters);
240
- let placeholders = (_a = params === null || params === void 0 ? void 0 : params.map((_, index) => "$" + (index + 1 + where.length))) !== null && _a !== void 0 ? _a : [];
240
+ let placeholders = (_a = params === null || params === void 0 ? void 0 : params.map((_, index) => "$" + (index + 1 + values.length))) !== null && _a !== void 0 ? _a : [];
241
241
  let query = `SELECT ${name}(${placeholders.join(',')}) WHERE ${where}`;
242
242
  return this.query(query, [...values, ...params]);
243
243
  });
@@ -1,6 +1,7 @@
1
1
  export default abstract class CryptoUtils {
2
2
  private static crypto;
3
3
  static zeroPad(buf: Buffer, blocksize: number): Buffer;
4
- static encrypt3DES(key: string, message: string): Promise<Buffer>;
4
+ static symEncrypt(key: string, message: string): Promise<Buffer>;
5
+ static symDecrypt(key: string, encrypted: Buffer): Promise<string>;
5
6
  static sha256Sign(merchantKey: string, orderId: string, encodedOrder: string): Promise<string>;
6
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.117",
3
+ "version": "0.4.119",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -7,7 +7,7 @@ export default abstract class CryptoUtils {
7
7
  return Buffer.concat([buf, pad]);
8
8
  }
9
9
 
10
- static async encrypt3DES(key: string, message: string)
10
+ static async symEncrypt(key: string, message: string): Promise<Buffer>
11
11
  {
12
12
  let crypto = this.crypto ?? (await import("crypto")).default;
13
13
 
@@ -27,9 +27,27 @@ export default abstract class CryptoUtils {
27
27
  return encryptedBuf.slice(0, maxLength);
28
28
  }
29
29
 
30
+ static async symDecrypt(key: string, encrypted: Buffer): Promise<string> {
31
+ let crypto = this.crypto ?? (await import("crypto")).default;
32
+
33
+ const keyBuf = Buffer.from(key, 'base64');
34
+ const iv = Buffer.alloc(8, 0);
35
+
36
+ const decipher = crypto.createDecipheriv('des-ede3-cbc', keyBuf, iv);
37
+ decipher.setAutoPadding(false);
38
+
39
+ const decryptedBuf = Buffer.concat([
40
+ decipher.update(encrypted),
41
+ decipher.final()
42
+ ]);
43
+
44
+ // Remove zero padding
45
+ return decryptedBuf.toString('utf8').replace(/\x00+$/g, '');
46
+ }
47
+
30
48
  static async sha256Sign(merchantKey: string, orderId: string, encodedOrder: string) {
31
49
  let crypto = this.crypto ?? (await import("crypto")).default;
32
- const orderKeyBuf = await CryptoUtils.encrypt3DES(merchantKey, orderId);
50
+ const orderKeyBuf = await CryptoUtils.symEncrypt(merchantKey, orderId);
33
51
  return crypto.createHmac('sha256', orderKeyBuf).update(encodedOrder).digest('base64');
34
52
  }
35
53
  }
@@ -207,7 +207,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
207
207
  async run<T>(name: string, params: Valuable[] = [], filters: Partial<T> = {}): Promise<T[]>
208
208
  {
209
209
  let { where, values } = this.anyWhere(filters as any);
210
- let placeholders = params?.map((_, index) => "$"+(index+1+where.length)) ?? [];
210
+ let placeholders = params?.map((_, index) => "$"+(index+1+values.length)) ?? [];
211
211
  let query = `SELECT ${name}(${placeholders.join(',')}) WHERE ${where}`;
212
212
  return this.query<any>(query, [ ...values, ...params ])
213
213
  }