ismx-nexo-node-app 0.4.199 → 0.4.203

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.
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- const node_crypto_2 = require("node:crypto");
35
+ const node_crypto_1 = require("node:crypto");
36
36
  class CryptoUtils {
37
37
  static zeroPad(buf, blocksize) {
38
38
  const pad = Buffer.alloc((blocksize - (buf.length % blocksize)) % blocksize, 0);
@@ -75,7 +75,7 @@ class CryptoUtils {
75
75
  static asymEncrypt(value, publicKey) {
76
76
  return __awaiter(this, void 0, void 0, function* () {
77
77
  const buffer = Buffer.from(value, 'utf8');
78
- const encrypted = (0, node_crypto_2.publicEncrypt)(publicKey, buffer);
78
+ const encrypted = (0, node_crypto_1.publicEncrypt)(publicKey, buffer);
79
79
  return encrypted.toString('base64');
80
80
  });
81
81
  }
@@ -83,16 +83,25 @@ class CryptoUtils {
83
83
  static asymDecrypt(hash, privateKey) {
84
84
  return __awaiter(this, void 0, void 0, function* () {
85
85
  const buffer = Buffer.from(hash, 'base64');
86
- const decrypted = (0, node_crypto_2.privateDecrypt)(privateKey, buffer);
86
+ const decrypted = (0, node_crypto_1.privateDecrypt)(privateKey, buffer);
87
87
  return decrypted.toString('utf8');
88
88
  });
89
89
  }
90
+ static otpGen() {
91
+ return "";
92
+ }
93
+ static otpLink() {
94
+ return "";
95
+ }
96
+ static otp(code, secret) {
97
+ return "";
98
+ }
90
99
  /**
91
100
  * Genera un desafío (challenge) aleatorio y seguro.
92
101
  * Se recomienda un tamaño de 32 bytes para asegurar suficiente entropía.
93
102
  */
94
103
  static challenge() {
95
- return (0, node_crypto_2.randomBytes)(32).toString('hex');
104
+ return (0, node_crypto_1.randomBytes)(32).toString('hex');
96
105
  }
97
106
  /**
98
107
  * Verifica si el desafío firmado criptográficamente coincide con la clave generadora.
@@ -103,9 +112,10 @@ class CryptoUtils {
103
112
  */
104
113
  static verify(challenge, signature, key, format = 'base64') {
105
114
  try {
106
- const verifier = (0, node_crypto_2.createVerify)('sha256');
107
- verifier.update(Buffer.from(challenge, 'hex'));
108
- return verifier.verify(key, signature, format);
115
+ const pemKey = `-----BEGIN PUBLIC KEY-----\n${key.match(/.{1,64}/g).join('\n')}\n-----END PUBLIC KEY-----`;
116
+ const verifier = (0, node_crypto_1.createVerify)('sha256');
117
+ verifier.update(challenge);
118
+ return verifier.verify(pemKey, signature, format);
109
119
  }
110
120
  catch (error) {
111
121
  console.log(error);
@@ -25,7 +25,7 @@ class PostgresUtils {
25
25
  });
26
26
  }
27
27
  static isReservedWord(word) {
28
- const reservedWords = new Set(['select', 'from', 'where', 'join', 'table', 'user', 'group', 'order', 'limit', 'offset', 'insert', 'update', 'delete', 'to']);
28
+ const reservedWords = new Set(['select', 'from', 'where', 'join', 'table', 'user', 'group', 'order', 'limit', 'offset', 'insert', 'sort', 'update', 'delete', 'to']);
29
29
  return reservedWords.has(word.toLowerCase());
30
30
  }
31
31
  static bindOrDefault(table, object, startIndex) {
@@ -8,6 +8,9 @@ export default abstract class CryptoUtils {
8
8
  static asymEncrypt(value: string, publicKey: RsaPrivateKey | KeyLike): Promise<string>;
9
9
  /** Asymmetric decryption (RSA) */
10
10
  static asymDecrypt(hash: string, privateKey: RsaPrivateKey | KeyLike): Promise<string>;
11
+ static otpGen(): string;
12
+ static otpLink(): string;
13
+ static otp(code: string, secret: string): any;
11
14
  /**
12
15
  * Genera un desafío (challenge) aleatorio y seguro.
13
16
  * Se recomienda un tamaño de 32 bytes para asegurar suficiente entropía.
package/jest.config.ts ADDED
@@ -0,0 +1,56 @@
1
+ import type { Config } from 'jest';
2
+
3
+ const config: Config = {
4
+ // 1. Motor de compilación: Usamos ts-jest para transformar archivos .ts
5
+ preset: 'ts-jest',
6
+
7
+ // 2. Entorno de ejecución: 'node' es el correcto para backend (evita cargar APIs de navegador)
8
+ testEnvironment: 'node',
9
+
10
+ // 3. Aliases de rutas (Crucial para tus imports como #src/...)
11
+ // Esto debe coincidir con lo que tienes en tu tsconfig.json
12
+ moduleNameMapper: {
13
+ '^#src/(.*)$': '<rootDir>/src/$1',
14
+ '^#test/(.*)$': '<rootDir>/test/$1',
15
+ },
16
+
17
+ // 4. Archivos que Jest debe buscar
18
+ testMatch: [
19
+ '**/test/**/*.test.ts',
20
+ '**/?(*.)+(spec|test).ts'
21
+ ],
22
+
23
+ // 5. Transformación de archivos
24
+ transform: {
25
+ '^.+\\.ts$': [
26
+ 'ts-jest',
27
+ {
28
+ tsconfig: 'tsconfig.json',
29
+ isolatedModules: true, // Acelera los tests al no hacer chequeo de tipos exhaustivo (opcional)
30
+ },
31
+ ],
32
+ },
33
+
34
+ // 6. Cobertura de código (Coverage)
35
+ collectCoverage: true,
36
+ coverageDirectory: 'coverage',
37
+ coveragePathIgnorePatterns: [
38
+ '/node_modules/',
39
+ '/dist/',
40
+ '/test/'
41
+ ],
42
+ coverageReporters: ['text', 'lcov', 'html'],
43
+
44
+ // 7. Configuración de salida y limpieza
45
+ verbose: true,
46
+ clearMocks: true,
47
+ restoreMocks: true,
48
+
49
+ // 8. Extensiones que reconoce
50
+ moduleFileExtensions: ['ts', 'js', 'json', 'node'],
51
+
52
+ // 9. Root directory
53
+ rootDir: './',
54
+ };
55
+
56
+ export default config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.199",
3
+ "version": "0.4.203",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -14,8 +14,7 @@
14
14
  "author": "",
15
15
  "license": "ISC",
16
16
  "dependencies": {
17
- "@types/multer": "^2.0.0",
18
- "esbuild": "^0.23.1"
17
+ "esbuild": "0.25.0"
19
18
  },
20
19
  "reqDependencies": {
21
20
  "cors": "^2.8.5",
@@ -28,9 +27,14 @@
28
27
  "devDependencies": {
29
28
  "@types/cors": "^2.8.17",
30
29
  "@types/express": "^5.0.0",
31
- "@types/node": "^14.0.5",
30
+ "@types/jest": "^30.0.0",
31
+ "@types/multer": "^2.0.0",
32
+ "@types/node": "^25.3.3",
32
33
  "@types/node-fetch": "^2.6.11",
33
34
  "@types/pg": "^8.11.10",
35
+ "jest": "^30.2.0",
36
+ "ts-jest": "^29.4.6",
37
+ "ts-node": "^10.9.2",
34
38
  "tsx": "^4.19.1",
35
39
  "typescript": "^5.6.3"
36
40
  }
@@ -1,4 +1,4 @@
1
- import node_crypto_1, {createVerify, privateDecrypt, publicEncrypt, randomBytes} from "node:crypto";
1
+ import {createVerify, privateDecrypt, publicEncrypt, randomBytes} from "node:crypto";
2
2
  import {BinaryToTextEncoding, KeyLike, RsaPrivateKey} from "crypto";
3
3
 
4
4
  export default abstract class CryptoUtils {
@@ -62,6 +62,18 @@ export default abstract class CryptoUtils {
62
62
  return decrypted.toString('utf8');
63
63
  }
64
64
 
65
+ static otpGen(): string {
66
+ return ""
67
+ }
68
+
69
+ static otpLink() {
70
+ return ""
71
+ }
72
+
73
+ static otp(code: string, secret: string): any {
74
+ return ""
75
+ }
76
+
65
77
  /**
66
78
  * Genera un desafío (challenge) aleatorio y seguro.
67
79
  * Se recomienda un tamaño de 32 bytes para asegurar suficiente entropía.
@@ -80,9 +92,10 @@ export default abstract class CryptoUtils {
80
92
  static verify(challenge: string, signature: string, key: string, format: BinaryToTextEncoding = 'base64'): boolean
81
93
  {
82
94
  try {
95
+ const pemKey = `-----BEGIN PUBLIC KEY-----\n${key.match(/.{1,64}/g)!.join('\n')}\n-----END PUBLIC KEY-----`;
83
96
  const verifier = createVerify('sha256');
84
- verifier.update(Buffer.from(challenge, 'hex'));
85
- return verifier.verify(key, signature, format);
97
+ verifier.update(challenge);
98
+ return verifier.verify(pemKey, signature, format);
86
99
 
87
100
  } catch (error) { console.log(error); return false; }
88
101
  }
@@ -37,7 +37,7 @@ export default abstract class PostgresUtils
37
37
  }
38
38
 
39
39
  static isReservedWord(word: string): boolean {
40
- const reservedWords = new Set(['select', 'from', 'where', 'join', 'table', 'user', 'group', 'order', 'limit', 'offset', 'insert', 'update', 'delete', 'to']);
40
+ const reservedWords = new Set(['select', 'from', 'where', 'join', 'table', 'user', 'group', 'order', 'limit', 'offset', 'insert', 'sort', 'update', 'delete', 'to']);
41
41
  return reservedWords.has(word.toLowerCase());
42
42
  }
43
43
 
@@ -0,0 +1,14 @@
1
+ import CryptoUtils from "../../../main/node/business/utils/CryptoUtils";
2
+
3
+ describe('CryptoUtils Biometric Verification', () => {
4
+
5
+ it('verificar la firma usando el string UTF-8 crudo', () => {
6
+
7
+ const challenge = "b3dfe9158b1a55486c0d126ebcd8c8c17dd0f5100d4924259d087fdd11fab052";
8
+ const signature = "HOEjjCQEsCnMpV88TsOzRovDeG55Cc+k9HE7B9YyVN7ivLont1PUAO1GQ1ezQ6XUJs8thDuloYY8dretduys3nqScekHqDVdMEKmEwiPBURGXvZTvOKbj0ddy1W+16dH5NFNOEIguZUzeZ+5QRbgTDpHdUK94shA/0i2XktQK1FD8ZrVKs3iUUIih3sfexwtzbXPh/ofPJ0nIu9HxY9V8I6FTmNSJKvvHZ1TSPRYvh9YNxVLJqyPvzb5sKgwtRQQY/e50gioAszfQpsTK/sfc5jxGMmtdJRu884XiyRAcFPNlfHlQn6Cfm0xTsg0sfJ2LJJJpYjpXxTLcy/tHleHQA==";
9
+ const key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1oI5IKyCMrMtTzQwI0+azMsKQNIBfnVvYTM2fZvZ7aR43yog0aRcyX2eJDk484c70VxbQSe5HJfL7GYZW6+uLm/xtV/9HS+UAXug5jGOzlYW4d2E8xu1V3DLO3Bq4ij42pOlIF/EWDRgRjsAjqRihfhfVu1H+GRHaHPHBUj3up8EXYsu/QeXOX56dSfrCQYt+sGLBYvopKw4HVHDJF3De3z4xiUjyUWdf0TJHHub8pigWxFi/Lk937PqrKJdW4f+kVwrlJezRsh4ULai623yT4ooxEuQIXdIuJg1s+8izXCfXQkg9SJbMmayaqCrqgjipoeQSRpn4PYEcSJPjhaj0QIDAQAB";
10
+
11
+ const isValid = CryptoUtils.verify(challenge, signature, key);
12
+ expect(isValid).toBe(true);
13
+ });
14
+ });
package/tsconfig.json CHANGED
@@ -3,6 +3,7 @@
3
3
  "target": "es6", // Versión de ECMAScript de salida
4
4
  "module": "commonjs", // Sistema de módulos a usar
5
5
  "moduleResolution": "node",
6
+ "isolatedModules": true,
6
7
  "declaration": true, // Generar archivos de declaración (.d.ts)
7
8
  "declarationDir": "./dist/types", // Generar archivos de declaración (.d.ts)
8
9
  "outDir": "./dist/js", // Directorio de salida para los archivos compilados
@@ -15,4 +16,3 @@
15
16
  "include": ["src/main/node/**/*"], // Incluir todos los archivos en src
16
17
  "exclude": ["node_modules", "dist"] // Excluir node_modules y dist
17
18
  }
18
-