ismx-nexo-node-app 0.4.197 → 0.4.199
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,12 @@ class CryptoUtils {
|
|
|
103
103
|
*/
|
|
104
104
|
static verify(challenge, signature, key, format = 'base64') {
|
|
105
105
|
try {
|
|
106
|
-
const verifier = (0,
|
|
107
|
-
verifier.update(challenge);
|
|
106
|
+
const verifier = (0, node_crypto_2.createVerify)('sha256');
|
|
107
|
+
verifier.update(Buffer.from(challenge, 'hex'));
|
|
108
108
|
return verifier.verify(key, signature, format);
|
|
109
109
|
}
|
|
110
110
|
catch (error) {
|
|
111
|
+
console.log(error);
|
|
111
112
|
return false;
|
|
112
113
|
}
|
|
113
114
|
}
|
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 {
|
|
@@ -81,10 +81,10 @@ export default abstract class CryptoUtils {
|
|
|
81
81
|
{
|
|
82
82
|
try {
|
|
83
83
|
const verifier = createVerify('sha256');
|
|
84
|
-
verifier.update(challenge);
|
|
84
|
+
verifier.update(Buffer.from(challenge, 'hex'));
|
|
85
85
|
return verifier.verify(key, signature, format);
|
|
86
86
|
|
|
87
|
-
} catch (error) { return false; }
|
|
87
|
+
} catch (error) { console.log(error); return false; }
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
private static async sha256Sign(merchantKey: string, orderId: string, encodedOrder: string) {
|