ismx-nexo-node-app 0.4.197 → 0.4.198
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
|
|
35
|
+
const node_crypto_2 = 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,
|
|
78
|
+
const encrypted = (0, node_crypto_2.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,
|
|
86
|
+
const decrypted = (0, node_crypto_2.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,
|
|
95
|
+
return (0, node_crypto_2.randomBytes)(32).toString('hex');
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
98
|
* Verifica si el desafío firmado criptográficamente coincide con la clave generadora.
|
|
@@ -103,11 +103,13 @@ class CryptoUtils {
|
|
|
103
103
|
*/
|
|
104
104
|
static verify(challenge, signature, key, format = 'base64') {
|
|
105
105
|
try {
|
|
106
|
-
const
|
|
107
|
-
verifier.
|
|
108
|
-
|
|
106
|
+
const pemKey = `-----BEGIN PUBLIC KEY-----\n${key.match(/.{1,64}/g).join('\n')}\n-----END PUBLIC KEY-----`;
|
|
107
|
+
const verifier = (0, node_crypto_2.createVerify)('sha256');
|
|
108
|
+
verifier.update(Buffer.from(challenge, 'hex'));
|
|
109
|
+
return verifier.verify(pemKey, signature, format);
|
|
109
110
|
}
|
|
110
111
|
catch (error) {
|
|
112
|
+
console.log(error);
|
|
111
113
|
return false;
|
|
112
114
|
}
|
|
113
115
|
}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {createVerify, privateDecrypt, publicEncrypt, randomBytes} from "node:crypto";
|
|
1
|
+
import node_crypto_1, {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,11 +80,12 @@ 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(challenge);
|
|
85
|
-
return verifier.verify(
|
|
85
|
+
verifier.update(Buffer.from(challenge, 'hex'));
|
|
86
|
+
return verifier.verify(pemKey, signature, format);
|
|
86
87
|
|
|
87
|
-
} catch (error) { return false; }
|
|
88
|
+
} catch (error) { console.log(error); return false; }
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
private static async sha256Sign(merchantKey: string, orderId: string, encodedOrder: string) {
|