fiberx-backend-toolkit 1.0.10 → 1.0.12
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.
|
@@ -90,7 +90,7 @@ class AuthenticationMiddleWare {
|
|
|
90
90
|
}
|
|
91
91
|
const has_permission = await this.validateHasPermission(request_info, req);
|
|
92
92
|
if (!has_permission) {
|
|
93
|
-
this.logger.
|
|
93
|
+
this.logger.error(`[${this.name}] ⛔ Permission denied for request ${req.request_id} with required permission ${permission_name}`);
|
|
94
94
|
return res.errResponse(403, "unauthorized_access_permission");
|
|
95
95
|
}
|
|
96
96
|
this.logger.success(`[${this.name}] ✅ Permission granted for request ${req.request_id} with required permission ${permission_name}`);
|
|
@@ -75,7 +75,7 @@ export interface CachedContentInterface {
|
|
|
75
75
|
email?: Record<string, any>;
|
|
76
76
|
}
|
|
77
77
|
export type RSAKeySizeType = 2048 | 3072 | 4096;
|
|
78
|
-
export type HashAlgorithmType = "sha256" | "sha384" | "sha512";
|
|
78
|
+
export type HashAlgorithmType = "sha256" | "sha384" | "sha512" | "RSA-SHA256" | "RSA-SHA384" | "RSA-SHA512" | "RS256" | "RS384" | "RS512";
|
|
79
79
|
export type EncodingType = "base64" | "hex";
|
|
80
80
|
export interface RSAKeyPairResultInterface {
|
|
81
81
|
public_key: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RSAKeySizeType, HashAlgorithmType, EncodingType, RSAKeyPairResultInterface, ECKeyPairResultInterface } from "../types/util_type";
|
|
2
2
|
declare class CryptoKeyUtil {
|
|
3
3
|
private constructor();
|
|
4
|
+
static normalizeSigningAlgorithm(algorithm?: string): HashAlgorithmType;
|
|
4
5
|
static generateRSAKeyPair(modulus_length?: RSAKeySizeType): RSAKeyPairResultInterface;
|
|
5
6
|
static generateECKeyPair(named_curve?: "prime256v1" | "secp384r1" | "secp521r1"): ECKeyPairResultInterface;
|
|
6
7
|
static sign(payload: string, private_key: string, algorithm?: HashAlgorithmType, output_encoding?: EncodingType): string;
|
|
@@ -36,6 +36,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
const crypto_1 = __importStar(require("crypto"));
|
|
37
37
|
class CryptoKeyUtil {
|
|
38
38
|
constructor() { }
|
|
39
|
+
static normalizeSigningAlgorithm(algorithm) {
|
|
40
|
+
const value = algorithm?.trim();
|
|
41
|
+
const algorithm_map = {
|
|
42
|
+
RS256: "RSA-SHA256",
|
|
43
|
+
RS384: "RSA-SHA384",
|
|
44
|
+
RS512: "RSA-SHA512",
|
|
45
|
+
SHA256: "RSA-SHA256",
|
|
46
|
+
"SHA-256": "RSA-SHA256",
|
|
47
|
+
sha256: "RSA-SHA256",
|
|
48
|
+
};
|
|
49
|
+
return algorithm_map[value ?? ""] ?? "RSA-SHA256";
|
|
50
|
+
}
|
|
39
51
|
/* ============================================================
|
|
40
52
|
RSA KEY GENERATION
|
|
41
53
|
============================================================ */
|
|
@@ -74,7 +86,7 @@ class CryptoKeyUtil {
|
|
|
74
86
|
SIGNING
|
|
75
87
|
============================================================ */
|
|
76
88
|
static sign(payload, private_key, algorithm = "sha256", output_encoding = "base64") {
|
|
77
|
-
const signer = (0, crypto_1.createSign)(algorithm);
|
|
89
|
+
const signer = (0, crypto_1.createSign)(CryptoKeyUtil.normalizeSigningAlgorithm(algorithm));
|
|
78
90
|
signer.update(payload);
|
|
79
91
|
signer.end();
|
|
80
92
|
return signer.sign(private_key, output_encoding);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fiberx-backend-toolkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "A TypeScript backend toolkit providing shared domain logic, infrastructure helpers, and utilities for FiberX server-side applications and services.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|