ismx-nexo-node-app 0.4.199 → 0.4.201

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,7 +83,7 @@ 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
  }
@@ -92,7 +92,7 @@ class CryptoUtils {
92
92
  * Se recomienda un tamaño de 32 bytes para asegurar suficiente entropía.
93
93
  */
94
94
  static challenge() {
95
- return (0, node_crypto_2.randomBytes)(32).toString('hex');
95
+ return (0, node_crypto_1.randomBytes)(32).toString('hex');
96
96
  }
97
97
  /**
98
98
  * Verifica si el desafío firmado criptográficamente coincide con la clave generadora.
@@ -103,9 +103,10 @@ class CryptoUtils {
103
103
  */
104
104
  static verify(challenge, signature, key, format = 'base64') {
105
105
  try {
106
- const verifier = (0, node_crypto_2.createVerify)('sha256');
107
- verifier.update(Buffer.from(challenge, 'hex'));
108
- return verifier.verify(key, signature, format);
106
+ const pemKey = `-----BEGIN PUBLIC KEY-----\n${key.match(/.{1,64}/g).join('\n')}\n-----END PUBLIC KEY-----`;
107
+ const verifier = (0, node_crypto_1.createVerify)('sha256');
108
+ verifier.update(challenge);
109
+ return verifier.verify(pemKey, signature, format);
109
110
  }
110
111
  catch (error) {
111
112
  console.log(error);
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.201",
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 {
@@ -80,9 +80,10 @@ export default abstract class CryptoUtils {
80
80
  static verify(challenge: string, signature: string, key: string, format: BinaryToTextEncoding = 'base64'): boolean
81
81
  {
82
82
  try {
83
+ const pemKey = `-----BEGIN PUBLIC KEY-----\n${key.match(/.{1,64}/g)!.join('\n')}\n-----END PUBLIC KEY-----`;
83
84
  const verifier = createVerify('sha256');
84
- verifier.update(Buffer.from(challenge, 'hex'));
85
- return verifier.verify(key, signature, format);
85
+ verifier.update(challenge);
86
+ return verifier.verify(pemKey, signature, format);
86
87
 
87
88
  } catch (error) { console.log(error); return false; }
88
89
  }
@@ -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
-