vortez 5.0.0-dev.15 → 5.0.0-dev.16

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.
Files changed (149) hide show
  1. package/.gitignore +0 -0
  2. package/LICENSE +0 -0
  3. package/README.md +0 -0
  4. package/build/Template.d.ts +1 -1
  5. package/build/Template.js +1 -1
  6. package/build/Template.js.map +0 -0
  7. package/build/Vortez.d.ts +1 -1
  8. package/build/Vortez.js +1 -1
  9. package/build/Vortez.js.map +0 -0
  10. package/build/beta/Beta.d.ts +2 -2
  11. package/build/beta/Beta.js +2 -2
  12. package/build/beta/Beta.js.map +1 -1
  13. package/build/beta/JwtManager/Jwt.d.ts +32 -0
  14. package/build/beta/JwtManager/Jwt.js +33 -0
  15. package/build/beta/JwtManager/Jwt.js.map +1 -0
  16. package/build/beta/JwtManager/JwtManager.d.ts +49 -0
  17. package/build/beta/JwtManager/JwtManager.js +74 -0
  18. package/build/beta/JwtManager/JwtManager.js.map +1 -0
  19. package/build/beta/JwtManager/JwtUtils.d.ts +32 -0
  20. package/build/beta/JwtManager/JwtUtils.js +50 -0
  21. package/build/beta/JwtManager/JwtUtils.js.map +1 -0
  22. package/build/beta/JwtManager/KeyGenerator.d.ts +47 -0
  23. package/build/beta/JwtManager/KeyGenerator.js +92 -0
  24. package/build/beta/JwtManager/KeyGenerator.js.map +1 -0
  25. package/build/beta/JwtManager/algorithm/Algorithm.d.ts +68 -0
  26. package/build/beta/JwtManager/algorithm/Algorithm.js +82 -0
  27. package/build/beta/JwtManager/algorithm/Algorithm.js.map +1 -0
  28. package/build/beta/JwtManager/algorithm/ECDSA.d.ts +18 -0
  29. package/build/beta/JwtManager/algorithm/ECDSA.js +46 -0
  30. package/build/beta/JwtManager/algorithm/ECDSA.js.map +1 -0
  31. package/build/beta/JwtManager/algorithm/HMAC.d.ts +24 -0
  32. package/build/beta/JwtManager/algorithm/HMAC.js +38 -0
  33. package/build/beta/JwtManager/algorithm/HMAC.js.map +1 -0
  34. package/build/beta/JwtManager/algorithm/RSA.d.ts +24 -0
  35. package/build/beta/JwtManager/algorithm/RSA.js +52 -0
  36. package/build/beta/JwtManager/algorithm/RSA.js.map +1 -0
  37. package/build/beta/JwtManager/algorithm/RSAPSS.d.ts +24 -0
  38. package/build/beta/JwtManager/algorithm/RSAPSS.js +55 -0
  39. package/build/beta/JwtManager/algorithm/RSAPSS.js.map +1 -0
  40. package/build/beta/Mail.d.ts +1 -1
  41. package/build/beta/Mail.js +1 -1
  42. package/build/beta/Mail.js.map +0 -0
  43. package/build/logger/Debug.d.ts +1 -1
  44. package/build/logger/Debug.js +1 -1
  45. package/build/logger/Debug.js.map +0 -0
  46. package/build/logger/Logger.d.ts +1 -1
  47. package/build/logger/Logger.js +1 -1
  48. package/build/logger/Logger.js.map +0 -0
  49. package/build/server/BodyParser.d.ts +1 -1
  50. package/build/server/BodyParser.js +1 -1
  51. package/build/server/BodyParser.js.map +0 -0
  52. package/build/server/Cookie.d.ts +1 -1
  53. package/build/server/Cookie.js +1 -1
  54. package/build/server/Cookie.js.map +0 -0
  55. package/build/server/LoggerManager.d.ts +1 -1
  56. package/build/server/LoggerManager.js +1 -1
  57. package/build/server/LoggerManager.js.map +0 -0
  58. package/build/server/Request.d.ts +1 -1
  59. package/build/server/Request.js +1 -1
  60. package/build/server/Request.js.map +0 -0
  61. package/build/server/Response.d.ts +1 -1
  62. package/build/server/Response.js +1 -1
  63. package/build/server/Response.js.map +0 -0
  64. package/build/server/Server.d.ts +1 -1
  65. package/build/server/Server.js +1 -1
  66. package/build/server/Server.js.map +0 -0
  67. package/build/server/ServerDebug.d.ts +1 -1
  68. package/build/server/ServerDebug.js +1 -1
  69. package/build/server/ServerDebug.js.map +0 -0
  70. package/build/server/ServerError.d.ts +0 -0
  71. package/build/server/ServerError.js +0 -0
  72. package/build/server/ServerError.js.map +0 -0
  73. package/build/server/Session.d.ts +1 -1
  74. package/build/server/Session.js +1 -1
  75. package/build/server/Session.js.map +0 -0
  76. package/build/server/config/Config.d.ts +1 -1
  77. package/build/server/config/Config.js +1 -1
  78. package/build/server/config/Config.js.map +0 -0
  79. package/build/server/config/ConfigLoader.d.ts +1 -1
  80. package/build/server/config/ConfigLoader.js +1 -1
  81. package/build/server/config/ConfigLoader.js.map +0 -0
  82. package/build/server/config/ConfigValidator.d.ts +1 -1
  83. package/build/server/config/ConfigValidator.js +1 -1
  84. package/build/server/config/ConfigValidator.js.map +0 -0
  85. package/build/server/router/HttpRule.d.ts +0 -0
  86. package/build/server/router/HttpRule.js +0 -0
  87. package/build/server/router/HttpRule.js.map +0 -0
  88. package/build/server/router/Router.d.ts +1 -1
  89. package/build/server/router/Router.js +1 -1
  90. package/build/server/router/Router.js.map +0 -0
  91. package/build/server/router/Rule.d.ts +1 -1
  92. package/build/server/router/Rule.js +1 -1
  93. package/build/server/router/Rule.js.map +0 -0
  94. package/build/server/router/WsRule.d.ts +0 -0
  95. package/build/server/router/WsRule.js +0 -0
  96. package/build/server/router/WsRule.js.map +0 -0
  97. package/build/server/router/middleware/HttpMiddleware.d.ts +1 -1
  98. package/build/server/router/middleware/HttpMiddleware.js +1 -1
  99. package/build/server/router/middleware/HttpMiddleware.js.map +0 -0
  100. package/build/server/router/middleware/Middleware.d.ts +1 -1
  101. package/build/server/router/middleware/Middleware.js +1 -1
  102. package/build/server/router/middleware/Middleware.js.map +0 -0
  103. package/build/server/router/middleware/WsMiddleware.d.ts +1 -1
  104. package/build/server/router/middleware/WsMiddleware.js +1 -1
  105. package/build/server/router/middleware/WsMiddleware.js.map +0 -0
  106. package/build/server/websocket/Chunk.d.ts +1 -1
  107. package/build/server/websocket/Chunk.js +1 -1
  108. package/build/server/websocket/Chunk.js.map +0 -0
  109. package/build/server/websocket/Websocket.d.ts +1 -1
  110. package/build/server/websocket/Websocket.js +1 -1
  111. package/build/server/websocket/Websocket.js.map +0 -0
  112. package/build/utilities/ConsoleUI.d.ts +1 -1
  113. package/build/utilities/ConsoleUI.js +1 -1
  114. package/build/utilities/ConsoleUI.js.map +0 -0
  115. package/build/utilities/DebugUI.d.ts +1 -1
  116. package/build/utilities/DebugUI.js +1 -1
  117. package/build/utilities/DebugUI.js.map +0 -0
  118. package/build/utilities/Env.d.ts +0 -0
  119. package/build/utilities/Env.js +0 -0
  120. package/build/utilities/Env.js.map +0 -0
  121. package/build/utilities/Path.d.ts +0 -0
  122. package/build/utilities/Path.js +0 -0
  123. package/build/utilities/Path.js.map +0 -0
  124. package/build/utilities/Utilities.d.ts +1 -1
  125. package/build/utilities/Utilities.js +1 -1
  126. package/build/utilities/Utilities.js.map +0 -0
  127. package/changes.md +0 -0
  128. package/examples/in-docs.js +0 -0
  129. package/global/Source/Logo_960.png +0 -0
  130. package/global/Source/Logo_SM_960.png +0 -0
  131. package/global/Style/Template/Error.css +0 -0
  132. package/global/Style/Template/Folder.css +0 -0
  133. package/global/Style/Template/Template.css +0 -0
  134. package/global/Template/Error.vhtml +0 -0
  135. package/global/Template/Folder.vhtml +0 -0
  136. package/package.json +13 -9
  137. package/tests/Template/template.js +0 -0
  138. package/tests/Template/template.txt +0 -0
  139. package/tests/Template/template.vhtml +0 -0
  140. package/tests/debug.js +0 -0
  141. package/tests/jwtManager/jwtManager.js +46 -78
  142. package/tests/test.js +0 -0
  143. package/tests/test.vhtml +0 -0
  144. package/tests/utilities.js +0 -0
  145. package/tests/websocket.vhtml +0 -0
  146. package/build/beta/JwtManager.d.ts +0 -114
  147. package/build/beta/JwtManager.js +0 -249
  148. package/build/beta/JwtManager.js.map +0 -1
  149. package/tests/test.env +0 -0
package/.gitignore CHANGED
File without changes
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
File without changes
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @author NetFeez <codefeez.dev@gmail.com>
2
+ * @author NetFeez <netfeez.dev@gmail.com>
3
3
  * @description Add the HNetFeez-Labs template engine to the Vortez.
4
4
  * @license Apache-2.0
5
5
  */
package/build/Template.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @author NetFeez <codefeez.dev@gmail.com>
2
+ * @author NetFeez <netfeez.dev@gmail.com>
3
3
  * @description Add the HNetFeez-Labs template engine to the Vortez.
4
4
  * @license Apache-2.0
5
5
  */
File without changes
package/build/Vortez.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @author NetFeez <codefeez.dev@gmail.com>
2
+ * @author NetFeez <netfeez.dev@gmail.com>
3
3
  * @description Provides the Vortez functionalities and utilities for building robust applications.
4
4
  * @module NetFeez-Labs.Vortez
5
5
  * @license Apache-2.0
package/build/Vortez.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @author NetFeez <codefeez.dev@gmail.com>
2
+ * @author NetFeez <netfeez.dev@gmail.com>
3
3
  * @description Provides the Vortez functionalities and utilities for building robust applications.
4
4
  * @module NetFeez-Labs.Vortez
5
5
  * @license Apache-2.0
File without changes
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @author NetFeez <codefeez.dev@gmail.com>
2
+ * @author NetFeez <netfeez.dev@gmail.com>
3
3
  * @description Provides the beta functions and utilities.
4
4
  * @module NetFeez-Labs.Vortez
5
5
  * @license Apache-2.0
6
6
  */
7
- export { JwtManager } from './JwtManager.js';
7
+ export { JwtManager } from './JwtManager/JwtManager.js';
8
8
  export { Mail } from './Mail.js';
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @author NetFeez <codefeez.dev@gmail.com>
2
+ * @author NetFeez <netfeez.dev@gmail.com>
3
3
  * @description Provides the beta functions and utilities.
4
4
  * @module NetFeez-Labs.Vortez
5
5
  * @license Apache-2.0
6
6
  */
7
- export { JwtManager } from './JwtManager.js';
7
+ export { JwtManager } from './JwtManager/JwtManager.js';
8
8
  export { Mail } from './Mail.js';
9
9
  //# sourceMappingURL=Beta.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Beta.js","sourceRoot":"","sources":["../../src/beta/Beta.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"Beta.js","sourceRoot":"","sources":["../../src/beta/Beta.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type JwtManager from './JwtManager.js';
2
+ export declare class Jwt implements Jwt.Jwt {
3
+ readonly header: Jwt.Header;
4
+ readonly payload: Jwt.Payload;
5
+ readonly signature: string;
6
+ protected readonly manager: JwtManager;
7
+ constructor(header: Jwt.Header, payload: Jwt.Payload, signature: string, manager: JwtManager);
8
+ /**
9
+ * Checks if the JWT has expired based on the `exp` claim in the payload. If the `exp` claim is not present, it returns `false`, indicating that the token is not considered expired. If the `exp` claim is present, it compares the current time (in seconds since the Unix epoch) with the expiration time specified in the `exp` claim and returns `true` if the token has expired, or `false` otherwise.
10
+ * @returns `true` if the JWT has expired; otherwise, `false`.
11
+ */
12
+ expired(): boolean;
13
+ toJSON(): Jwt.Jwt;
14
+ toString(): string;
15
+ }
16
+ export declare namespace Jwt {
17
+ interface Jwt {
18
+ header: Header;
19
+ payload: Payload;
20
+ signature: string;
21
+ }
22
+ interface Header {
23
+ alg: JwtManager.AlgorithmName;
24
+ typ: 'jwt';
25
+ exp?: number;
26
+ [key: string]: any;
27
+ }
28
+ interface Payload {
29
+ [key: string]: any;
30
+ }
31
+ }
32
+ export default Jwt;
@@ -0,0 +1,33 @@
1
+ import JwtUtils from './JwtUtils.js';
2
+ export class Jwt {
3
+ header;
4
+ payload;
5
+ signature;
6
+ manager;
7
+ constructor(header, payload, signature, manager) {
8
+ this.header = header;
9
+ this.payload = payload;
10
+ this.signature = signature;
11
+ this.manager = manager;
12
+ }
13
+ /**
14
+ * Checks if the JWT has expired based on the `exp` claim in the payload. If the `exp` claim is not present, it returns `false`, indicating that the token is not considered expired. If the `exp` claim is present, it compares the current time (in seconds since the Unix epoch) with the expiration time specified in the `exp` claim and returns `true` if the token has expired, or `false` otherwise.
15
+ * @returns `true` if the JWT has expired; otherwise, `false`.
16
+ */
17
+ expired() {
18
+ if (!this.header.exp)
19
+ return false;
20
+ const now = Math.floor(Date.now() / 1000);
21
+ return now >= this.header.exp;
22
+ }
23
+ toJSON() {
24
+ return { header: this.header, payload: this.payload, signature: this.signature };
25
+ }
26
+ toString() {
27
+ const encodedHeader = JwtUtils.objectToBase64Url(this.header);
28
+ const encodedPayload = JwtUtils.objectToBase64Url(this.payload);
29
+ return `${encodedHeader}.${encodedPayload}.${this.signature}`;
30
+ }
31
+ }
32
+ export default Jwt;
33
+ //# sourceMappingURL=Jwt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Jwt.js","sourceRoot":"","sources":["../../../src/beta/JwtManager/Jwt.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,eAAe,CAAC;AAErC,MAAM,OAAO,GAAG;IAEQ;IACA;IACA;IACG;IAJvB,YACoB,MAAkB,EAClB,OAAoB,EACpB,SAAiB,EACd,OAAmB;QAHtB,WAAM,GAAN,MAAM,CAAY;QAClB,YAAO,GAAP,OAAO,CAAa;QACpB,cAAS,GAAT,SAAS,CAAQ;QACd,YAAO,GAAP,OAAO,CAAY;IACvC,CAAC;IACJ;;;OAGG;IACI,OAAO;QACV,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG;YAAE,OAAO,KAAK,CAAC;QACnC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;QAC1C,OAAO,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;IAClC,CAAC;IAEM,MAAM;QACT,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;IACrF,CAAC;IACM,QAAQ;QACX,MAAM,aAAa,GAAG,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9D,MAAM,cAAc,GAAG,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChE,OAAO,GAAG,aAAa,IAAI,cAAc,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;IAClE,CAAC;CACJ;AAiBD,eAAe,GAAG,CAAC"}
@@ -0,0 +1,49 @@
1
+ import RSA from "./algorithm/RSA.js";
2
+ import HMAC from "./algorithm/HMAC.js";
3
+ import ECDSA from "./algorithm/ECDSA.js";
4
+ import RSAPSS from "./algorithm/RSAPSS.js";
5
+ import _KeyGenerator from "./KeyGenerator.js";
6
+ import _JwtUtils from "./JwtUtils.js";
7
+ import _Algorithm from "./algorithm/Algorithm.js";
8
+ import _Jwt from "./Jwt.js";
9
+ export { KeyGenerator } from "./KeyGenerator.js";
10
+ export { Algorithm } from "./algorithm/Algorithm.js";
11
+ export { JwtUtils } from "./JwtUtils.js";
12
+ export { Jwt } from "./Jwt.js";
13
+ export declare const AlgorithmMap: {
14
+ HS: typeof HMAC;
15
+ RS: typeof RSA;
16
+ PS: typeof RSAPSS;
17
+ ES: typeof ECDSA;
18
+ };
19
+ export declare class JwtManager {
20
+ readonly algorithmName: JwtManager.AlgorithmName;
21
+ protected readonly algorithm: JwtManager.Algorithm;
22
+ constructor(algorithmName: JwtManager.AlgorithmName, key: JwtManager.Algorithm.Key | JwtManager.Algorithm.KeyOptions);
23
+ /**
24
+ * Signs the given payload with the specified header using the configured algorithm and key.
25
+ * @param payload The payload to be signed, represented as a JavaScript object.
26
+ * @param header The header to be included in the JWT, represented as a JavaScript object. The `alg` property will be automatically set based on the manager's algorithm.
27
+ * @returns The complete JWT as a string, consisting of the base64url-encoded header, payload, and signature.
28
+ */
29
+ sign(payload: JwtManager.Jwt.Payload, header: Partial<JwtManager.Jwt.Header>): string;
30
+ parse(token: string): JwtManager.Jwt;
31
+ toJSON(): object;
32
+ toString(): string;
33
+ /**
34
+ * Determines the appropriate algorithm class based on the provided options and creates an instance of it.
35
+ * @param algorithm The name of the algorithm to be used for signing and verifying JWTs (e.g., "HS256", "RS384", "ES512").
36
+ * @param key The secret key or private key to be used for signing and verifying JWTs.
37
+ * @returns An instance of the corresponding Algorithm subclass.
38
+ */
39
+ protected static getAlgorithm(algorithm: JwtManager.AlgorithmName, key: JwtManager.Algorithm.Key | JwtManager.Algorithm.KeyOptions): JwtManager.Algorithm;
40
+ }
41
+ export declare namespace JwtManager {
42
+ export import Algorithm = _Algorithm;
43
+ export import KeyGenerator = _KeyGenerator;
44
+ export import JwtUtils = _JwtUtils;
45
+ export import Jwt = _Jwt;
46
+ type AlgPrefix = 'HS' | 'RS' | 'ES' | 'PS';
47
+ type AlgorithmName = `${AlgPrefix}${JwtManager.Algorithm.HashLength}`;
48
+ }
49
+ export default JwtManager;
@@ -0,0 +1,74 @@
1
+ import RSA from "./algorithm/RSA.js";
2
+ import HMAC from "./algorithm/HMAC.js";
3
+ import ECDSA from "./algorithm/ECDSA.js";
4
+ import RSAPSS from "./algorithm/RSAPSS.js";
5
+ import _KeyGenerator from "./KeyGenerator.js";
6
+ import _JwtUtils from "./JwtUtils.js";
7
+ import _Algorithm from "./algorithm/Algorithm.js";
8
+ import _Jwt from "./Jwt.js";
9
+ export { KeyGenerator } from "./KeyGenerator.js";
10
+ export { Algorithm } from "./algorithm/Algorithm.js";
11
+ export { JwtUtils } from "./JwtUtils.js";
12
+ export { Jwt } from "./Jwt.js";
13
+ export const AlgorithmMap = {
14
+ HS: HMAC,
15
+ RS: RSA,
16
+ PS: RSAPSS,
17
+ ES: ECDSA
18
+ };
19
+ export class JwtManager {
20
+ algorithmName;
21
+ algorithm;
22
+ constructor(algorithmName, key) {
23
+ this.algorithmName = algorithmName;
24
+ this.algorithm = JwtManager.getAlgorithm(algorithmName, key);
25
+ }
26
+ /**
27
+ * Signs the given payload with the specified header using the configured algorithm and key.
28
+ * @param payload The payload to be signed, represented as a JavaScript object.
29
+ * @param header The header to be included in the JWT, represented as a JavaScript object. The `alg` property will be automatically set based on the manager's algorithm.
30
+ * @returns The complete JWT as a string, consisting of the base64url-encoded header, payload, and signature.
31
+ */
32
+ sign(payload, header) {
33
+ header = { ...header, alg: this.algorithmName };
34
+ const encodedHeader = JwtManager.JwtUtils.objectToBase64Url(header);
35
+ const encodedPayload = JwtManager.JwtUtils.objectToBase64Url(payload);
36
+ const content = `${encodedHeader}.${encodedPayload}`;
37
+ const signature = this.algorithm.sign(content);
38
+ return `${content}.${signature}`;
39
+ }
40
+ parse(token) {
41
+ const parts = token.split('.');
42
+ if (parts.length !== 3)
43
+ throw new Error('Invalid JWT format');
44
+ const [encodedHeader, encodedPayload, signature] = parts;
45
+ const verified = this.algorithm.verify(`${encodedHeader}.${encodedPayload}`, signature);
46
+ if (!verified)
47
+ throw new Error('Invalid JWT signature');
48
+ const header = JwtManager.JwtUtils.base64UrlToObject(encodedHeader);
49
+ const payload = JwtManager.JwtUtils.base64UrlToObject(encodedPayload);
50
+ return new JwtManager.Jwt(header, payload, signature, this);
51
+ }
52
+ toJSON() { return { algorithm: this.algorithmName }; }
53
+ toString() { return `Jwt manager with algorithm ${this.algorithmName}`; }
54
+ /**
55
+ * Determines the appropriate algorithm class based on the provided options and creates an instance of it.
56
+ * @param algorithm The name of the algorithm to be used for signing and verifying JWTs (e.g., "HS256", "RS384", "ES512").
57
+ * @param key The secret key or private key to be used for signing and verifying JWTs.
58
+ * @returns An instance of the corresponding Algorithm subclass.
59
+ */
60
+ static getAlgorithm(algorithm, key) {
61
+ const prefix = JwtManager.JwtUtils.getAlgPrefix(algorithm);
62
+ const hashLength = JwtManager.JwtUtils.getHashLength(algorithm);
63
+ const alg = AlgorithmMap[prefix];
64
+ return new alg(hashLength, key);
65
+ }
66
+ }
67
+ (function (JwtManager) {
68
+ JwtManager.Algorithm = _Algorithm;
69
+ JwtManager.KeyGenerator = _KeyGenerator;
70
+ JwtManager.JwtUtils = _JwtUtils;
71
+ JwtManager.Jwt = _Jwt;
72
+ })(JwtManager || (JwtManager = {}));
73
+ export default JwtManager;
74
+ //# sourceMappingURL=JwtManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JwtManager.js","sourceRoot":"","sources":["../../../src/beta/JwtManager/JwtManager.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,32 @@
1
+ import type Algorithm from "./algorithm/Algorithm.js";
2
+ import type JwtManager from "./JwtManager.js";
3
+ export declare class JwtUtils {
4
+ /**
5
+ * Converts a JavaScript object to a base64url-encoded string.
6
+ * @param obj The object to be converted.
7
+ * @returns The base64url-encoded string representation of the object.
8
+ */
9
+ static objectToBase64Url(obj: object): string;
10
+ /**
11
+ * Converts a base64url-encoded string back to a JavaScript object.
12
+ * @param base64Url The base64url-encoded string to be converted.
13
+ * @returns The JavaScript object represented by the base64url string.
14
+ */
15
+ static base64UrlToObject<T>(base64Url: string): T;
16
+ /**
17
+ * Extracts the algorithm prefix from the given algorithm name and validates it.
18
+ * @param alg The algorithm name (e.g., "HS256", "RS384", "ES512").
19
+ * @returns The algorithm prefix (e.g., "HS", "RS", "ES", "PS").
20
+ * @throws An error if the algorithm is unsupported.
21
+ */
22
+ static getAlgPrefix(alg: JwtManager.AlgorithmName): JwtManager.AlgPrefix;
23
+ /**
24
+ * Extracts the hash length from the given algorithm name and validates it.
25
+ * @param alg The algorithm name (e.g., "HS256", "RS384", "ES512").
26
+ * @returns The hash length as a string ("256", "384", or "512").
27
+ * @throws An error if the algorithm is unsupported or if the hash length is invalid.
28
+ */
29
+ static getHashLength(alg: JwtManager.AlgorithmName): Algorithm.HashLength;
30
+ }
31
+ export declare namespace JwtUtils { }
32
+ export default JwtUtils;
@@ -0,0 +1,50 @@
1
+ export class JwtUtils {
2
+ /**
3
+ * Converts a JavaScript object to a base64url-encoded string.
4
+ * @param obj The object to be converted.
5
+ * @returns The base64url-encoded string representation of the object.
6
+ */
7
+ static objectToBase64Url(obj) {
8
+ const jsonString = JSON.stringify(obj);
9
+ const buffer = Buffer.from(jsonString, 'utf-8');
10
+ return buffer.toString('base64url');
11
+ }
12
+ /**
13
+ * Converts a base64url-encoded string back to a JavaScript object.
14
+ * @param base64Url The base64url-encoded string to be converted.
15
+ * @returns The JavaScript object represented by the base64url string.
16
+ */
17
+ static base64UrlToObject(base64Url) {
18
+ const buffer = Buffer.from(base64Url, 'base64url');
19
+ const jsonString = buffer.toString('utf-8');
20
+ return JSON.parse(jsonString);
21
+ }
22
+ /**
23
+ * Extracts the algorithm prefix from the given algorithm name and validates it.
24
+ * @param alg The algorithm name (e.g., "HS256", "RS384", "ES512").
25
+ * @returns The algorithm prefix (e.g., "HS", "RS", "ES", "PS").
26
+ * @throws An error if the algorithm is unsupported.
27
+ */
28
+ static getAlgPrefix(alg) {
29
+ const prefix = alg.slice(0, 2);
30
+ if (!['HS', 'RS', 'ES', 'PS'].includes(prefix)) {
31
+ throw new Error(`Unsupported algorithm: ${alg}`);
32
+ }
33
+ return prefix;
34
+ }
35
+ /**
36
+ * Extracts the hash length from the given algorithm name and validates it.
37
+ * @param alg The algorithm name (e.g., "HS256", "RS384", "ES512").
38
+ * @returns The hash length as a string ("256", "384", or "512").
39
+ * @throws An error if the algorithm is unsupported or if the hash length is invalid.
40
+ */
41
+ static getHashLength(alg) {
42
+ const hashLength = alg.slice(2);
43
+ if (!['256', '384', '512'].includes(hashLength)) {
44
+ throw new Error(`Unsupported algorithm: ${alg}`);
45
+ }
46
+ return hashLength;
47
+ }
48
+ }
49
+ export default JwtUtils;
50
+ //# sourceMappingURL=JwtUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JwtUtils.js","sourceRoot":"","sources":["../../../src/beta/JwtManager/JwtUtils.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,QAAQ;IACjB;;;;OAIG;IACI,MAAM,CAAC,iBAAiB,CAAC,GAAW;QACvC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACvC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAChD,OAAO,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACxC,CAAC;IACD;;;;OAIG;IACI,MAAM,CAAC,iBAAiB,CAAI,SAAiB;QAChD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QACnD,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAM,CAAC;IACvC,CAAC;IACD;;;;;OAKG;IACI,MAAM,CAAC,YAAY,CAAC,GAA6B;QACpD,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/B,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7C,MAAM,IAAI,KAAK,CAAC,0BAA0B,GAAG,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,MAA8B,CAAC;IAC1C,CAAC;IACD;;;;;OAKG;IACI,MAAM,CAAC,aAAa,CAAC,GAA6B;QACrD,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,0BAA0B,GAAG,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,UAAkC,CAAC;IAC9C,CAAC;CACJ;AAED,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type Algorithm from "./algorithm/Algorithm.js";
2
+ export declare class KeyGenerator {
3
+ /**
4
+ * Generates a key or key pair based on the specified type and options. The generated key(s) can be used for signing and verifying JWTs with various algorithms.
5
+ * @param type The type of key to generate. Supported types include:
6
+ * - 'secret': Generates a random secret key for HMAC algorithms (e.g., HS256). The key is a base64url-encoded string.
7
+ * - 'rsa': Generates an RSA key pair for RSASSA-PKCS1-v1_5 algorithms (e.g., RS256). The keys are returned in PEM format.
8
+ * - 'rsa-pss': Generates an RSA key pair for RSASSA-PSS algorithms (e.g., PS256). The keys are returned in PEM format.
9
+ * - 'ec': Generates an Elliptic Curve (EC) key pair for ECDSA algorithms (e.g., ES256). The keys are returned in PEM format.
10
+ * @param options Optional parameters for key generation, such as modulus length for RSA keys or named curve for EC keys.
11
+ * @returns An object containing the generated private key ("key
12
+ */
13
+ static generate(type: KeyGenerator.Type, options?: KeyGenerator.Options): KeyGenerator.KeyObject;
14
+ /**
15
+ * Generates an RSA key pair with the specified modulus length.
16
+ * If no modulus length is provided, it defaults to 2048 bits.
17
+ * @param modulusLength The length of the RSA modulus in bits (e.g., 2048, 4096). Defaults to 2048 if not specified.
18
+ * @returns An object containing the generated private key ("key") and public key ("pub") as strings, both in PEM format.
19
+ */
20
+ protected static RSA(modulusLength?: number): KeyGenerator.KeyObject;
21
+ /**
22
+ * Generates an RSA-PSS key pair with the specified modulus length.
23
+ * If no modulus length is provided, it defaults to 2048 bits.
24
+ * @param modulusLength The length of the RSA modulus in bits (e.g., 2048, 4096). Defaults to 2048 if not specified.
25
+ * @returns An object containing the generated private key ("key") and public key ("pub") as strings, both in PEM format.
26
+ */
27
+ protected static RSAPSS(modulusLength?: number): KeyGenerator.KeyObject;
28
+ /**
29
+ * Generates an Elliptic Curve (EC) key pair using the specified named curve.
30
+ * If no named curve is provided, it defaults to 'P-256'.
31
+ * @param namedCurve The name of the elliptic curve to use (e.g., 'P-256', 'P-384', 'P-521'). Defaults to 'P-256' if not specified.
32
+ * @returns An object containing the generated private key ("key") and public key ("pub") as strings, both in PEM format.
33
+ */
34
+ protected static EC(namedCurve?: string): KeyGenerator.KeyObject;
35
+ }
36
+ export declare namespace KeyGenerator {
37
+ type Type = 'secret' | 'rsa' | 'rsa-pss' | 'ec';
38
+ interface KeyObject {
39
+ key: Algorithm.Key;
40
+ pub: Algorithm.Key;
41
+ }
42
+ interface Options {
43
+ namedCurve?: string;
44
+ modulusLength?: number;
45
+ }
46
+ }
47
+ export default KeyGenerator;
@@ -0,0 +1,92 @@
1
+ import { generateKeyPairSync, randomBytes } from "crypto";
2
+ export class KeyGenerator {
3
+ /**
4
+ * Generates a key or key pair based on the specified type and options. The generated key(s) can be used for signing and verifying JWTs with various algorithms.
5
+ * @param type The type of key to generate. Supported types include:
6
+ * - 'secret': Generates a random secret key for HMAC algorithms (e.g., HS256). The key is a base64url-encoded string.
7
+ * - 'rsa': Generates an RSA key pair for RSASSA-PKCS1-v1_5 algorithms (e.g., RS256). The keys are returned in PEM format.
8
+ * - 'rsa-pss': Generates an RSA key pair for RSASSA-PSS algorithms (e.g., PS256). The keys are returned in PEM format.
9
+ * - 'ec': Generates an Elliptic Curve (EC) key pair for ECDSA algorithms (e.g., ES256). The keys are returned in PEM format.
10
+ * @param options Optional parameters for key generation, such as modulus length for RSA keys or named curve for EC keys.
11
+ * @returns An object containing the generated private key ("key
12
+ */
13
+ static generate(type, options = {}) {
14
+ let privateKey;
15
+ let publicKey;
16
+ switch (type) {
17
+ case 'secret': {
18
+ const secret = randomBytes(options.modulusLength || 32).toString('base64url');
19
+ privateKey = publicKey = secret;
20
+ break;
21
+ }
22
+ case 'rsa': {
23
+ const { key, pub } = KeyGenerator.RSA(options.modulusLength);
24
+ privateKey = key;
25
+ publicKey = pub;
26
+ break;
27
+ }
28
+ case 'rsa-pss': {
29
+ const { key, pub } = KeyGenerator.RSAPSS(options.modulusLength);
30
+ privateKey = key;
31
+ publicKey = pub;
32
+ break;
33
+ }
34
+ case 'ec': {
35
+ const { key, pub } = KeyGenerator.EC(options.namedCurve);
36
+ privateKey = key;
37
+ publicKey = pub;
38
+ break;
39
+ }
40
+ default: throw new Error(`Unsupported key type: ${type}`);
41
+ }
42
+ return { key: privateKey, pub: publicKey };
43
+ }
44
+ /**
45
+ * Generates an RSA key pair with the specified modulus length.
46
+ * If no modulus length is provided, it defaults to 2048 bits.
47
+ * @param modulusLength The length of the RSA modulus in bits (e.g., 2048, 4096). Defaults to 2048 if not specified.
48
+ * @returns An object containing the generated private key ("key") and public key ("pub") as strings, both in PEM format.
49
+ */
50
+ static RSA(modulusLength = 2048) {
51
+ const { privateKey, publicKey } = generateKeyPairSync('rsa', {
52
+ modulusLength: modulusLength,
53
+ publicKeyEncoding: { type: 'spki', format: 'pem' },
54
+ privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
55
+ });
56
+ return { key: privateKey, pub: publicKey };
57
+ }
58
+ /**
59
+ * Generates an RSA-PSS key pair with the specified modulus length.
60
+ * If no modulus length is provided, it defaults to 2048 bits.
61
+ * @param modulusLength The length of the RSA modulus in bits (e.g., 2048, 4096). Defaults to 2048 if not specified.
62
+ * @returns An object containing the generated private key ("key") and public key ("pub") as strings, both in PEM format.
63
+ */
64
+ static RSAPSS(modulusLength = 2048) {
65
+ return this.RSA(modulusLength);
66
+ // Standard jwt libraries typically use the same RSA key pair for both RSASSA-PKCS1-v1_5 and RSASSA-PSS algorithms, as the key generation process is the same for both.
67
+ // The difference lies in how the signature is created and verified, not in the key itself.
68
+ // Therefore, we can reuse the RSA key generation method for RSAPSS as well.
69
+ const { privateKey, publicKey } = generateKeyPairSync('rsa-pss', {
70
+ modulusLength: modulusLength,
71
+ publicKeyEncoding: { type: 'spki', format: 'pem' },
72
+ privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
73
+ });
74
+ return { key: privateKey, pub: publicKey };
75
+ }
76
+ /**
77
+ * Generates an Elliptic Curve (EC) key pair using the specified named curve.
78
+ * If no named curve is provided, it defaults to 'P-256'.
79
+ * @param namedCurve The name of the elliptic curve to use (e.g., 'P-256', 'P-384', 'P-521'). Defaults to 'P-256' if not specified.
80
+ * @returns An object containing the generated private key ("key") and public key ("pub") as strings, both in PEM format.
81
+ */
82
+ static EC(namedCurve = 'P-256') {
83
+ const { privateKey, publicKey } = generateKeyPairSync('ec', {
84
+ namedCurve: namedCurve,
85
+ publicKeyEncoding: { type: 'spki', format: 'pem' },
86
+ privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
87
+ });
88
+ return { key: privateKey, pub: publicKey };
89
+ }
90
+ }
91
+ export default KeyGenerator;
92
+ //# sourceMappingURL=KeyGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyGenerator.js","sourceRoot":"","sources":["../../../src/beta/JwtManager/KeyGenerator.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,68 @@
1
+ import { AsymmetricKeyType, KeyObject } from 'crypto';
2
+ export declare abstract class Algorithm {
3
+ protected readonly hashLength: Algorithm.HashLength;
4
+ /** The private key used for signing and verification. */
5
+ protected readonly key: Algorithm.Key | null;
6
+ /** The public key used for verification. */
7
+ protected readonly pub: Algorithm.Key | null;
8
+ readonly role: Algorithm.Role;
9
+ constructor(hashLength: Algorithm.HashLength, secret: Algorithm.Key | Algorithm.KeyOptions);
10
+ protected normalizeKey(key: Algorithm.Key | Algorithm.KeyOptions): Algorithm.KeyObject;
11
+ /** Gets the name of the hash algorithm based on the specified hash length. */
12
+ get hashName(): Algorithm.ShaName;
13
+ /**
14
+ * Signs the given payload using the specific algorithm and the provided key.
15
+ * @param payload The payload to be signed.
16
+ * @returns The signature of the payload, encoded in base64.
17
+ */
18
+ abstract sign(payload: string): string;
19
+ /**
20
+ * Verifies that the provided signature matches the expected signature for the given payload.
21
+ * @param payload The payload whose signature is to be verified.
22
+ * @param signature The signature to be verified, encoded in base64.
23
+ * @returns `true` if the signature is valid; otherwise, `false`.
24
+ */
25
+ abstract verify(payload: string, signature: string): boolean;
26
+ toJSON(): object;
27
+ toString(): string;
28
+ /**
29
+ * Normalizes the provided key input into a consistent format, ensuring that both the private and public keys are available as Buffers.
30
+ * @param key The key input, which can be either a string, a Buffer, or an object containing "key" and/or "pub" properties.
31
+ * @returns An object containing the normalized private key ("key") and public key ("pub") as Buffers. If only one key is provided, it will be used for both.
32
+ */
33
+ static normalizeKey(key: Algorithm.Key | Algorithm.KeyOptions): Algorithm.KeyObject;
34
+ /**
35
+ * Converts a key, which can be either a string or a Buffer, into a Buffer format.
36
+ * @param key The key to be converted, which can be a string or a Buffer.
37
+ * @returns The key in Buffer format.
38
+ */
39
+ static keyToBuffer(key: Algorithm.Key): Buffer;
40
+ /**
41
+ * Asserts that the provided key is a valid Buffer. If the key is not valid, an error is thrown with the specified message.
42
+ * @param key The key to be validated, which can be of any type.
43
+ * @param message The error message to be thrown if the key is not a valid Buffer.
44
+ * @throws Will throw an error if the key is not provided or if it is not a Buffer.
45
+ */
46
+ static assertKey(key: any, message: string): asserts key is Buffer;
47
+ /**
48
+ * Asserts that the provided key is of the expected asymmetric key type (e.g., "rsa", "ec").
49
+ * If the key is not of the expected type, an error is thrown with the specified message.
50
+ * @param key The key to be validated, which should be a Buffer containing the key data.
51
+ * @param expected The expected asymmetric key type (e.g., "rsa", "ec").
52
+ * @param message The error message to be thrown if the key is not of the expected type.
53
+ * @throws Will throw an error if the key is not a valid asymmetric key of the expected type.
54
+ */
55
+ static assertKeyType(key: Algorithm.Key, expected: AsymmetricKeyType, message: string): KeyObject;
56
+ }
57
+ export declare namespace Algorithm {
58
+ type Role = 'signer' | 'verifier';
59
+ type HashLength = '256' | '384' | '512';
60
+ type ShaName = `SHA-${HashLength}`;
61
+ type Key = string;
62
+ interface KeyObject {
63
+ key: Key | null;
64
+ pub: Key | null;
65
+ }
66
+ type KeyOptions = Partial<KeyObject>;
67
+ }
68
+ export default Algorithm;