@nivinjoseph/n-sec 5.0.5 → 6.0.1

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 (81) hide show
  1. package/.eslintrc +13 -4
  2. package/.vscode/settings.json +103 -0
  3. package/.yarn/releases/yarn-4.0.2.cjs +893 -0
  4. package/.yarnrc.yml +3 -0
  5. package/dist/api-security/alg-type.d.ts +1 -0
  6. package/dist/api-security/alg-type.d.ts.map +1 -0
  7. package/dist/api-security/alg-type.js +2 -5
  8. package/dist/api-security/alg-type.js.map +1 -1
  9. package/dist/api-security/claim.d.ts +1 -0
  10. package/dist/api-security/claim.d.ts.map +1 -0
  11. package/dist/api-security/claim.js +5 -9
  12. package/dist/api-security/claim.js.map +1 -1
  13. package/dist/api-security/claims-identity.d.ts +2 -1
  14. package/dist/api-security/claims-identity.d.ts.map +1 -0
  15. package/dist/api-security/claims-identity.js +4 -8
  16. package/dist/api-security/claims-identity.js.map +1 -1
  17. package/dist/api-security/expired-token-exception.d.ts +1 -0
  18. package/dist/api-security/expired-token-exception.d.ts.map +1 -0
  19. package/dist/api-security/expired-token-exception.js +5 -9
  20. package/dist/api-security/expired-token-exception.js.map +1 -1
  21. package/dist/api-security/invalid-token-exception.d.ts +1 -0
  22. package/dist/api-security/invalid-token-exception.d.ts.map +1 -0
  23. package/dist/api-security/invalid-token-exception.js +7 -11
  24. package/dist/api-security/invalid-token-exception.js.map +1 -1
  25. package/dist/api-security/json-web-token.d.ts +3 -2
  26. package/dist/api-security/json-web-token.d.ts.map +1 -0
  27. package/dist/api-security/json-web-token.js +39 -43
  28. package/dist/api-security/json-web-token.js.map +1 -1
  29. package/dist/api-security/security-token.d.ts +1 -0
  30. package/dist/api-security/security-token.d.ts.map +1 -0
  31. package/dist/api-security/security-token.js +6 -10
  32. package/dist/api-security/security-token.js.map +1 -1
  33. package/dist/bin.d.ts +1 -0
  34. package/dist/bin.d.ts.map +1 -0
  35. package/dist/bin.js +15 -20
  36. package/dist/bin.js.map +1 -1
  37. package/dist/crypto/asymmetric-encryption.d.ts +2 -0
  38. package/dist/crypto/asymmetric-encryption.d.ts.map +1 -0
  39. package/dist/crypto/asymmetric-encryption.js +1 -1
  40. package/dist/crypto/asymmetric-encryption.js.map +1 -1
  41. package/dist/crypto/crypto-exception.d.ts +1 -0
  42. package/dist/crypto/crypto-exception.d.ts.map +1 -0
  43. package/dist/crypto/crypto-exception.js +2 -6
  44. package/dist/crypto/crypto-exception.js.map +1 -1
  45. package/dist/crypto/digital-signature.d.ts +2 -0
  46. package/dist/crypto/digital-signature.d.ts.map +1 -0
  47. package/dist/crypto/digital-signature.js +1 -1
  48. package/dist/crypto/digital-signature.js.map +1 -1
  49. package/dist/crypto/hash.d.ts +1 -0
  50. package/dist/crypto/hash.d.ts.map +1 -0
  51. package/dist/crypto/hash.js +7 -11
  52. package/dist/crypto/hash.js.map +1 -1
  53. package/dist/crypto/hmac.d.ts +1 -0
  54. package/dist/crypto/hmac.d.ts.map +1 -0
  55. package/dist/crypto/hmac.js +6 -10
  56. package/dist/crypto/hmac.js.map +1 -1
  57. package/dist/crypto/symmetric-encryption.d.ts +1 -0
  58. package/dist/crypto/symmetric-encryption.d.ts.map +1 -0
  59. package/dist/crypto/symmetric-encryption.js +13 -17
  60. package/dist/crypto/symmetric-encryption.js.map +1 -1
  61. package/dist/index.d.ts +13 -12
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +17 -28
  64. package/dist/index.js.map +1 -1
  65. package/dist/tsconfig.json +2 -1
  66. package/package.json +23 -24
  67. package/src/api-security/claims-identity.ts +1 -1
  68. package/src/api-security/json-web-token.ts +21 -21
  69. package/src/bin.ts +1 -1
  70. package/src/crypto/hash.ts +9 -9
  71. package/src/crypto/hmac.ts +7 -7
  72. package/src/crypto/symmetric-encryption.ts +11 -11
  73. package/src/index.ts +17 -18
  74. package/test/asymmetric-encryption.test.ts +37 -37
  75. package/test/digital-signature.test.ts +22 -22
  76. package/test/hash.test.ts +109 -109
  77. package/test/hmac.test.ts +56 -55
  78. package/test/json-web-token.test.ts +95 -95
  79. package/test/other.test.ts +8 -7
  80. package/test/symmetric-encryption.test.ts +49 -48
  81. package/tsconfig.json +8 -5
@@ -1,18 +1,18 @@
1
- import * as Assert from "assert";
2
- import { JsonWebToken } from "./../src/api-security/json-web-token";
3
- import { Claim } from "../src/api-security/claim";
4
- import { SymmetricEncryption } from "../src/index";
5
- import { InvalidTokenException } from "../src/api-security/invalid-token-exception";
6
- import { ExpiredTokenException } from "../src/api-security/expired-token-exception";
7
- // import { AsymmetricEncryption } from "../src/index";
1
+ import { describe, test } from "node:test";
2
+ import assert from "node:assert";
3
+ import { JsonWebToken } from "./../src/api-security/json-web-token.js";
4
+ import { Claim } from "../src/api-security/claim.js";
5
+ import { SymmetricEncryption } from "../src/index.js";
6
+ import { InvalidTokenException } from "../src/api-security/invalid-token-exception.js";
7
+ import { ExpiredTokenException } from "../src/api-security/expired-token-exception.js";
8
8
 
9
9
 
10
- suite("Json Web Token ", () =>
10
+ await describe("Json Web Token ", async () =>
11
11
  {
12
- suite("Hmac", () =>
12
+ await describe("Hmac", async () =>
13
13
  {
14
-
15
- test("should successfully create a token using hmac with one claim", async () =>
14
+
15
+ await test("should successfully create a token using hmac with one claim", async () =>
16
16
  {
17
17
  const claim = new Claim("this_claim", "ThisValue");
18
18
  const key = await SymmetricEncryption.generateKey();
@@ -20,14 +20,14 @@ suite("Json Web Token ", () =>
20
20
  const token = JsonWebToken.fromClaims("issuer1", 1, key, time + 10000000, [claim]).generateToken();
21
21
  const jwt = JsonWebToken.fromToken("issuer1", 1, key, token);
22
22
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
23
- Assert.ok(jwt !== null || jwt !== undefined);
24
- Assert.strictEqual(jwt.issuer, "issuer1");
25
- Assert.strictEqual(jwt.algType, 1);
26
- Assert.strictEqual(jwt.expiry, time + 10000000);
27
- Assert.deepStrictEqual(jwt.claims, [claim]);
23
+ assert.ok(jwt !== null || jwt !== undefined);
24
+ assert.strictEqual(jwt.issuer, "issuer1");
25
+ assert.strictEqual(jwt.algType, 1);
26
+ assert.strictEqual(jwt.expiry, time + 10000000);
27
+ assert.deepStrictEqual(jwt.claims, [claim]);
28
28
  });
29
29
 
30
- test("should successfully create a token using hmac with 2 claims", async () =>
30
+ await test("should successfully create a token using hmac with 2 claims", async () =>
31
31
  {
32
32
  const claim1 = new Claim("this_claim", "ThisValue");
33
33
  const claim2 = new Claim("that_claim", "ThatValue");
@@ -36,14 +36,14 @@ suite("Json Web Token ", () =>
36
36
  const token = JsonWebToken.fromClaims("issuer1", 1, key, time + 10000000, [claim1, claim2]).generateToken();
37
37
  const jwt = JsonWebToken.fromToken("issuer1", 1, key, token);
38
38
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
39
- Assert.ok(jwt !== null || jwt !== undefined);
40
- Assert.strictEqual(jwt.issuer, "issuer1");
41
- Assert.strictEqual(jwt.algType, 1);
42
- Assert.strictEqual(jwt.expiry, time + 10000000);
43
- Assert.deepStrictEqual(jwt.claims, [claim1, claim2]);
39
+ assert.ok(jwt !== null || jwt !== undefined);
40
+ assert.strictEqual(jwt.issuer, "issuer1");
41
+ assert.strictEqual(jwt.algType, 1);
42
+ assert.strictEqual(jwt.expiry, time + 10000000);
43
+ assert.deepStrictEqual(jwt.claims, [claim1, claim2]);
44
44
  });
45
45
 
46
- test("should successfully create a token using hmac with 2 claims", async () =>
46
+ await test("should successfully create a token using hmac with 2 claims", async () =>
47
47
  {
48
48
  const claim1 = new Claim("this_claim", "ThisValue");
49
49
  const claim2 = new Claim("that_claim", "ThatValue");
@@ -52,14 +52,14 @@ suite("Json Web Token ", () =>
52
52
  const token = JsonWebToken.fromClaims("issuer1", 1, key, time + 10000000, [claim1, claim2]).generateToken();
53
53
  const jwt = JsonWebToken.fromToken("issuer1", 1, key, token);
54
54
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
55
- Assert.ok(jwt !== null || jwt !== undefined);
56
- Assert.strictEqual(jwt.issuer, "issuer1");
57
- Assert.strictEqual(jwt.algType, 1);
58
- Assert.strictEqual(jwt.expiry, time + 10000000);
59
- Assert.deepStrictEqual(jwt.claims, [claim1, claim2]);
55
+ assert.ok(jwt !== null || jwt !== undefined);
56
+ assert.strictEqual(jwt.issuer, "issuer1");
57
+ assert.strictEqual(jwt.algType, 1);
58
+ assert.strictEqual(jwt.expiry, time + 10000000);
59
+ assert.deepStrictEqual(jwt.claims, [claim1, claim2]);
60
60
  });
61
61
 
62
- test("should throw an exception when getting JWT with a different issuer that what was user to generate token", async () =>
62
+ await test("should throw an exception when getting JWT with a different issuer that what was user to generate token", async () =>
63
63
  {
64
64
  const claim1 = new Claim("this_claim", "ThisValue");
65
65
  const claim2 = new Claim("that_claim", "ThatValue");
@@ -72,14 +72,14 @@ suite("Json Web Token ", () =>
72
72
  }
73
73
  catch (exp)
74
74
  {
75
- Assert.ok(exp instanceof InvalidTokenException);
76
- Assert.equal(exp.message, `Token '${token}' is invalid because iss was expected to be 'notTheIssuer' but instead was 'issuer1'.`);
75
+ assert.ok(exp instanceof InvalidTokenException);
76
+ assert.equal(exp.message, `Token '${token}' is invalid because iss was expected to be 'notTheIssuer' but instead was 'issuer1'.`);
77
77
  return;
78
78
  }
79
- Assert.ok(false);
79
+ assert.ok(false);
80
80
  });
81
-
82
- test("should throw an exception when getting JWT when the token is expired", async () =>
81
+
82
+ await test("should throw an exception when getting JWT when the token is expired", async () =>
83
83
  {
84
84
  const claim1 = new Claim("this_claim", "ThisValue");
85
85
  const claim2 = new Claim("that_claim", "ThatValue");
@@ -92,15 +92,15 @@ suite("Json Web Token ", () =>
92
92
  }
93
93
  catch (exp)
94
94
  {
95
- Assert.ok(exp instanceof ExpiredTokenException);
96
- Assert.equal(exp.message, `Token '${token}' is expired.`);
95
+ assert.ok(exp instanceof ExpiredTokenException);
96
+ assert.equal(exp.message, `Token '${token}' is expired.`);
97
97
  return;
98
98
  }
99
- Assert.ok(false);
99
+ assert.ok(false);
100
100
  });
101
-
101
+
102
102
  // TODO: right now we only support one alg type. When we support others, we should uncomment this test
103
- // test("should throw an exception when getting JWT algorithm given is different than what was used for the token generation", async () =>
103
+ // await test("should throw an exception when getting JWT algorithm given is different than what was used for the token generation", async () =>
104
104
  // {
105
105
  // let claim1 = new Claim("this_claim", "ThisValue");
106
106
  // let claim2 = new Claim("that_claim", "ThatValue");
@@ -114,14 +114,14 @@ suite("Json Web Token ", () =>
114
114
  // catch (exp)
115
115
  // {
116
116
  // console.log(exp);
117
- // Assert.ok(exp instanceof InvalidTokenException);
118
- // Assert.equal(exp.message, `Token '${token}' is invalid because alg was expected to be '${2}' but instead was '${1}'.`);
117
+ // assert.ok(exp instanceof InvalidTokenException);
118
+ // assert.equal(exp.message, `Token '${token}' is invalid because alg was expected to be '${2}' but instead was '${1}'.`);
119
119
  // return;
120
120
  // }
121
- // Assert.ok(false);
121
+ // assert.ok(false);
122
122
  // });
123
-
124
- test("should throw an exception when getting JWT key given is different than what was used for the token generation", async () =>
123
+
124
+ await test("should throw an exception when getting JWT key given is different than what was used for the token generation", async () =>
125
125
  {
126
126
  const claim1 = new Claim("this_claim", "ThisValue");
127
127
  const claim2 = new Claim("that_claim", "ThatValue");
@@ -135,14 +135,14 @@ suite("Json Web Token ", () =>
135
135
  }
136
136
  catch (exp)
137
137
  {
138
- Assert.ok(exp instanceof InvalidTokenException);
139
- Assert.equal(exp.message, `Token '${token}' is invalid because signature could not be verified.`);
138
+ assert.ok(exp instanceof InvalidTokenException);
139
+ assert.equal(exp.message, `Token '${token}' is invalid because signature could not be verified.`);
140
140
  return;
141
141
  }
142
- Assert.ok(false);
142
+ assert.ok(false);
143
143
  });
144
-
145
- test("should throw an exception when getting JWT when the token is tampered with", async () =>
144
+
145
+ await test("should throw an exception when getting JWT when the token is tampered with", async () =>
146
146
  {
147
147
  const claim1 = new Claim("this_claim", "ThisValue");
148
148
  const claim2 = new Claim("that_claim", "ThatValue");
@@ -156,31 +156,31 @@ suite("Json Web Token ", () =>
156
156
  }
157
157
  catch (exp)
158
158
  {
159
- Assert.ok(exp instanceof InvalidTokenException);
160
- Assert.equal(exp.message, `Token '${token}' is invalid because signature could not be verified.`);
159
+ assert.ok(exp instanceof InvalidTokenException);
160
+ assert.equal(exp.message, `Token '${token}' is invalid because signature could not be verified.`);
161
161
  return;
162
162
  }
163
- Assert.ok(false);
163
+ assert.ok(false);
164
164
  });
165
- });
166
-
167
- // suite("digital Signature", () =>
165
+ });
166
+
167
+ // await describe("digital Signature", () =>
168
168
  // {
169
- // test("should successfully create a token using keyPair using digital Signature with one claim and get jwt using keyPair", async () =>
169
+ // await test("should successfully create a token using keyPair using digital Signature with one claim and get jwt using keyPair", async () =>
170
170
  // {
171
171
  // let keyPair = await AsymmetricEncryption.generateKeyPair();
172
172
  // let claim = new Claim("this_claim", "ThisValue");
173
173
  // let time = Date.now();
174
174
  // let token = await JsonWebToken.fromClaims("issuer1", 2, keyPair, time + 10000000, [claim]).generateToken();
175
175
  // let jwt = await JsonWebToken.fromToken("issuer1", 2, keyPair, token);
176
- // Assert.ok(jwt !== null || jwt !== undefined);
177
- // Assert.strictEqual(jwt.issuer, "issuer1");
178
- // Assert.strictEqual(jwt.algType, 2);
179
- // Assert.strictEqual(jwt.expiry, time + 10000000);
180
- // Assert.deepStrictEqual(jwt.claims, [claim]);
176
+ // assert.ok(jwt !== null || jwt !== undefined);
177
+ // assert.strictEqual(jwt.issuer, "issuer1");
178
+ // assert.strictEqual(jwt.algType, 2);
179
+ // assert.strictEqual(jwt.expiry, time + 10000000);
180
+ // assert.deepStrictEqual(jwt.claims, [claim]);
181
181
  // });
182
-
183
- // test("should successfully create a token using keyPair using digital Signature with one claim and get jwt using public key", async () =>
182
+
183
+ // await test("should successfully create a token using keyPair using digital Signature with one claim and get jwt using public key", async () =>
184
184
  // {
185
185
  // let keyPair = await AsymmetricEncryption.generateKeyPair();
186
186
  // let pubKey = await AsymmetricEncryption.getPublicKey(keyPair);
@@ -188,14 +188,14 @@ suite("Json Web Token ", () =>
188
188
  // let time = Date.now();
189
189
  // let token = await JsonWebToken.fromClaims("issuer1", 2, keyPair, time + 10000000, [claim]).generateToken();
190
190
  // let jwt = await JsonWebToken.fromToken("issuer1", 2, pubKey, token);
191
- // Assert.ok(jwt !== null || jwt !== undefined);
192
- // Assert.strictEqual(jwt.issuer, "issuer1");
193
- // Assert.strictEqual(jwt.algType, 2);
194
- // Assert.strictEqual(jwt.expiry, time + 10000000);
195
- // Assert.deepStrictEqual(jwt.claims, [claim]);
191
+ // assert.ok(jwt !== null || jwt !== undefined);
192
+ // assert.strictEqual(jwt.issuer, "issuer1");
193
+ // assert.strictEqual(jwt.algType, 2);
194
+ // assert.strictEqual(jwt.expiry, time + 10000000);
195
+ // assert.deepStrictEqual(jwt.claims, [claim]);
196
196
  // });
197
-
198
- // test("should throw an exception when getting JWT with a different issuer that what was user to generate token", async () =>
197
+
198
+ // await test("should throw an exception when getting JWT with a different issuer that what was user to generate token", async () =>
199
199
  // {
200
200
  // let keyPair = await AsymmetricEncryption.generateKeyPair();
201
201
  // let pubKey = await AsymmetricEncryption.getPublicKey(keyPair);
@@ -208,14 +208,14 @@ suite("Json Web Token ", () =>
208
208
  // }
209
209
  // catch (exp)
210
210
  // {
211
- // Assert.ok(exp instanceof InvalidTokenException);
212
- // Assert.equal(exp.message, `Token '${token}' is invalid because iss was expected to be 'notTheIssuer' but instead was 'issuer1'.`);
211
+ // assert.ok(exp instanceof InvalidTokenException);
212
+ // assert.equal(exp.message, `Token '${token}' is invalid because iss was expected to be 'notTheIssuer' but instead was 'issuer1'.`);
213
213
  // return;
214
214
  // }
215
- // Assert.ok(false);
215
+ // assert.ok(false);
216
216
  // });
217
-
218
- // test("should throw an exception when getting JWT algorithm given is different than what was used for the token generation", async () =>
217
+
218
+ // await test("should throw an exception when getting JWT algorithm given is different than what was used for the token generation", async () =>
219
219
  // {
220
220
  // let claim1 = new Claim("this_claim", "ThisValue");
221
221
  // let claim2 = new Claim("that_claim", "ThatValue");
@@ -229,14 +229,14 @@ suite("Json Web Token ", () =>
229
229
  // }
230
230
  // catch (exp)
231
231
  // {
232
- // Assert.ok(exp instanceof InvalidTokenException);
233
- // Assert.equal(exp.message, `Token '${token}' is invalid because alg was expected to be '${1}' but instead was '${2}'.`);
232
+ // assert.ok(exp instanceof InvalidTokenException);
233
+ // assert.equal(exp.message, `Token '${token}' is invalid because alg was expected to be '${1}' but instead was '${2}'.`);
234
234
  // return;
235
235
  // }
236
- // Assert.ok(false);
236
+ // assert.ok(false);
237
237
  // });
238
-
239
- // test("should throw an exception when getting JWT algorithm given is different than what was used for the token generation", async () =>
238
+
239
+ // await test("should throw an exception when getting JWT algorithm given is different than what was used for the token generation", async () =>
240
240
  // {
241
241
  // let claim1 = new Claim("this_claim", "ThisValue");
242
242
  // let claim2 = new Claim("that_claim", "ThatValue");
@@ -250,14 +250,14 @@ suite("Json Web Token ", () =>
250
250
  // }
251
251
  // catch (exp)
252
252
  // {
253
- // Assert.ok(exp instanceof ExpiredTokenException);
254
- // Assert.equal(exp.message, `Token '${token}' is expired.`);
253
+ // assert.ok(exp instanceof ExpiredTokenException);
254
+ // assert.equal(exp.message, `Token '${token}' is expired.`);
255
255
  // return;
256
256
  // }
257
- // Assert.ok(false);
257
+ // assert.ok(false);
258
258
  // });
259
-
260
- // test("should throw an exception when getting JWT key given is different than what was used for the token generation", async () =>
259
+
260
+ // await test("should throw an exception when getting JWT key given is different than what was used for the token generation", async () =>
261
261
  // {
262
262
  // let claim1 = new Claim("this_claim", "ThisValue");
263
263
  // let claim2 = new Claim("that_claim", "ThatValue");
@@ -271,15 +271,15 @@ suite("Json Web Token ", () =>
271
271
  // }
272
272
  // catch (exp)
273
273
  // {
274
- // Assert.ok(exp instanceof InvalidTokenException);
275
- // Assert.equal(exp.message, `Token '${token}' is invalid because signature could not be verified.`);
274
+ // assert.ok(exp instanceof InvalidTokenException);
275
+ // assert.equal(exp.message, `Token '${token}' is invalid because signature could not be verified.`);
276
276
  // return;
277
277
  // }
278
- // Assert.ok(false);
278
+ // assert.ok(false);
279
279
  // });
280
-
281
-
282
- // test("should throw an exception when getting JWT when the token is tampered with", async () =>
280
+
281
+
282
+ // await test("should throw an exception when getting JWT when the token is tampered with", async () =>
283
283
  // {
284
284
  // let claim1 = new Claim("this_claim", "ThisValue");
285
285
  // let claim2 = new Claim("that_claim", "ThatValue");
@@ -293,12 +293,12 @@ suite("Json Web Token ", () =>
293
293
  // }
294
294
  // catch (exp)
295
295
  // {
296
- // Assert.ok(exp instanceof InvalidTokenException);
297
- // Assert.equal(exp.message, `Token '${token}' is invalid because signature could not be verified.`);
296
+ // assert.ok(exp instanceof InvalidTokenException);
297
+ // assert.equal(exp.message, `Token '${token}' is invalid because signature could not be verified.`);
298
298
  // return;
299
299
  // }
300
- // Assert.ok(false);
300
+ // assert.ok(false);
301
301
  // });
302
302
  // });
303
-
303
+
304
304
  });
@@ -1,15 +1,16 @@
1
- import * as Assert from "assert";
1
+ import assert from "node:assert";
2
+ import { describe, test } from "node:test";
2
3
 
3
- suite("Other", () =>
4
+ await describe("Other", async () =>
4
5
  {
5
- test("encoding decoding", () =>
6
+ await test("encoding decoding", () =>
6
7
  {
7
8
  const text = "moonlight43iuj90/;msdnnksdkdkdk[[[][][";
8
9
  const encodedText = Buffer.from(text, "utf8").toString("base64");
9
- Assert.notStrictEqual(encodedText, text);
10
-
10
+ assert.notStrictEqual(encodedText, text);
11
+
11
12
  const decodedText = Buffer.from(encodedText, "base64").toString("utf8");
12
- Assert.notStrictEqual(decodedText, encodedText);
13
- Assert.strictEqual(decodedText, text);
13
+ assert.notStrictEqual(decodedText, encodedText);
14
+ assert.strictEqual(decodedText, text);
14
15
  });
15
16
  });
@@ -1,43 +1,44 @@
1
- import * as Assert from "assert";
2
- import { SymmetricEncryption } from "./../src/index";
1
+ import assert from "node:assert";
2
+ import { describe, test } from "node:test";
3
+ import { SymmetricEncryption } from "./../src/index.js";
3
4
  // import { CryptoException } from "./../src/crypto-exception";
4
5
  import "@nivinjoseph/n-ext";
5
6
 
6
7
 
7
- suite("SymmetricEncryption", () =>
8
+ await describe("SymmetricEncryption", async () =>
8
9
  {
9
- suite("generateKey", () =>
10
- {
11
- test("must return string value that is not null, empty or whitespace", async () =>
10
+ await describe("generateKey", async () =>
11
+ {
12
+ await test("must return string value that is not null, empty or whitespace", async () =>
12
13
  {
13
14
  const key = await SymmetricEncryption.generateKey();
14
15
  console.log("key", key);
15
16
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
16
- Assert.ok(key !== null && !key.isEmptyOrWhiteSpace());
17
+ assert.ok(key !== null && !key.isEmptyOrWhiteSpace());
17
18
  });
18
-
19
-
20
- test("consecutive calls must yield unique values", async () =>
19
+
20
+
21
+ await test("consecutive calls must yield unique values", async () =>
21
22
  {
22
23
  const key1 = await SymmetricEncryption.generateKey();
23
24
  const key2 = await SymmetricEncryption.generateKey();
24
- Assert.notStrictEqual(key1, key2);
25
+ assert.notStrictEqual(key1, key2);
25
26
  });
26
- });
27
-
28
- suite("encrypt", () =>
29
- {
30
- test("must return cipher text value when called with key and plain text value", async () =>
27
+ });
28
+
29
+ await describe("encrypt", async () =>
30
+ {
31
+ await test("must return cipher text value when called with key and plain text value", async () =>
31
32
  {
32
33
  const key = "E25B269440F88601C453CD171D76EDDC11D8CF33230742DF8CAD5873D28F78B2";
33
34
  const value = "password";
34
35
  const encrypted = await SymmetricEncryption.encrypt(key, value);
35
36
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
36
- Assert.ok(encrypted !== null);
37
- Assert.notStrictEqual(encrypted, value);
37
+ assert.ok(encrypted !== null);
38
+ assert.notStrictEqual(encrypted, value);
38
39
  });
39
40
 
40
- // test("encrypt with key as null throws CryptoException", async () =>
41
+ // await test("encrypt with key as null throws CryptoException", async () =>
41
42
  // {
42
43
  // try
43
44
  // {
@@ -52,7 +53,7 @@ suite("SymmetricEncryption", () =>
52
53
 
53
54
  // });
54
55
 
55
- // test("encrypt with key as undefined throws CryptoException", async () =>
56
+ // await test("encrypt with key as undefined throws CryptoException", async () =>
56
57
  // {
57
58
  // try
58
59
  // {
@@ -65,8 +66,8 @@ suite("SymmetricEncryption", () =>
65
66
  // }
66
67
  // assert.ok(false);
67
68
  // });
68
-
69
- // test("encrypt", async () =>
69
+
70
+ // await test("encrypt", async () =>
70
71
  // {
71
72
  // let key = await SymmetricEncryption.generateKey();
72
73
  // let value = "password";
@@ -75,7 +76,7 @@ suite("SymmetricEncryption", () =>
75
76
  // assert.notStrictEqual(value, encrypted);
76
77
  // });
77
78
 
78
- // test("encrypt with key as null throws CryptoException", async () =>
79
+ // await test("encrypt with key as null throws CryptoException", async () =>
79
80
  // {
80
81
  // try
81
82
  // {
@@ -91,7 +92,7 @@ suite("SymmetricEncryption", () =>
91
92
 
92
93
  // });
93
94
 
94
- // test("encrypt with value as null throws CryptoException", async () =>
95
+ // await test("encrypt with value as null throws CryptoException", async () =>
95
96
  // {
96
97
  // try
97
98
  // {
@@ -106,8 +107,8 @@ suite("SymmetricEncryption", () =>
106
107
  // }
107
108
  // assert.ok(false);
108
109
  // });
109
-
110
- // test("encrypt with value as undefined throws CryptoException", async () =>
110
+
111
+ // await test("encrypt with value as undefined throws CryptoException", async () =>
111
112
  // {
112
113
  // try
113
114
  // {
@@ -122,8 +123,8 @@ suite("SymmetricEncryption", () =>
122
123
  // }
123
124
  // assert.ok(false);
124
125
  // });
125
-
126
- // test("encrypt with value as empty string throws CryptoException", async () =>
126
+
127
+ // await test("encrypt with value as empty string throws CryptoException", async () =>
127
128
  // {
128
129
  // try
129
130
  // {
@@ -138,8 +139,8 @@ suite("SymmetricEncryption", () =>
138
139
  // }
139
140
  // assert.ok(false);
140
141
  // });
141
-
142
- // test("encrypt with key as empty string throws CryptoException", async () =>
142
+
143
+ // await test("encrypt with key as empty string throws CryptoException", async () =>
143
144
  // {
144
145
  // try
145
146
  // {
@@ -153,8 +154,8 @@ suite("SymmetricEncryption", () =>
153
154
  // }
154
155
  // assert.ok(false);
155
156
  // });
156
-
157
- // test("encrypt with invalid key as empty string throws CryptoException", async () =>
157
+
158
+ // await test("encrypt with invalid key as empty string throws CryptoException", async () =>
158
159
  // {
159
160
  // try
160
161
  // {
@@ -168,27 +169,27 @@ suite("SymmetricEncryption", () =>
168
169
  // assert.ok(false);
169
170
  // });
170
171
  });
171
-
172
- suite("decrypt", () =>
172
+
173
+ await describe("decrypt", async () =>
173
174
  {
174
- test("must return plain text value when called with key and cipher text value", async () =>
175
+ await test("must return plain text value when called with key and cipher text value", async () =>
175
176
  {
176
177
  const key = await SymmetricEncryption.generateKey();
177
178
  const value = "password";
178
179
  const encrypted = await SymmetricEncryption.encrypt(key, value);
179
180
  const decrypted = SymmetricEncryption.decrypt(key, encrypted);
180
- Assert.strictEqual(decrypted, value);
181
+ assert.strictEqual(decrypted, value);
181
182
  });
182
-
183
- // test("decrypt with a valid encryption key", async () =>
183
+
184
+ // await test("decrypt with a valid encryption key", async () =>
184
185
  // {
185
186
  // let key = await SymmetricEncryption.generateKey();
186
187
  // let encryption = await SymmetricEncryption.encrypt(key, "password");
187
188
  // let decryption = await SymmetricEncryption.decrypt(key, encryption);
188
189
  // assert.strictEqual(decryption, "password");
189
190
  // });
190
-
191
- // test("decrypt with an invalid encryption key", async () =>
191
+
192
+ // await test("decrypt with an invalid encryption key", async () =>
192
193
  // {
193
194
  // let key = await SymmetricEncryption.generateKey();
194
195
  // let key2 = await SymmetricEncryption.generateKey();
@@ -196,8 +197,8 @@ suite("SymmetricEncryption", () =>
196
197
  // let decryption = await SymmetricEncryption.decrypt(key2, encryption);
197
198
  // assert.notStrictEqual(decryption, "password");
198
199
  // });
199
-
200
- // test("throws an CryptoException when key is null", async () =>
200
+
201
+ // await test("throws an CryptoException when key is null", async () =>
201
202
  // {
202
203
  // try
203
204
  // {
@@ -209,8 +210,8 @@ suite("SymmetricEncryption", () =>
209
210
  // assert.strictEqual(exception.message, "Parameter count mismatch.");
210
211
  // }
211
212
  // });
212
-
213
- // test("throws an CryptoException when value is null", async () =>
213
+
214
+ // await test("throws an CryptoException when value is null", async () =>
214
215
  // {
215
216
  // try
216
217
  // {
@@ -223,8 +224,8 @@ suite("SymmetricEncryption", () =>
223
224
  // assert.strictEqual(exception.message, "Parameter count mismatch.");
224
225
  // }
225
226
  // });
226
-
227
- // test("throws an CryptoException when value is empty string", async () =>
227
+
228
+ // await test("throws an CryptoException when value is empty string", async () =>
228
229
  // {
229
230
  // try
230
231
  // {
@@ -237,8 +238,8 @@ suite("SymmetricEncryption", () =>
237
238
  // assert.strictEqual(exception.message, "Parameter count mismatch.");
238
239
  // }
239
240
  // });
240
-
241
- // test("throws an CryptoException when key and value is empty string", async () =>
241
+
242
+ // await test("throws an CryptoException when key and value is empty string", async () =>
242
243
  // {
243
244
  // try
244
245
  // {
package/tsconfig.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "module": "commonjs",
4
- "target": "es2015",
3
+ "module": "NodeNext",
4
+ "target": "ES2017",
5
+ "lib": [
6
+ "ES2023"
7
+ ],
5
8
  "strict": true,
6
9
  "strictNullChecks": true,
7
10
  "strictFunctionTypes": true,
@@ -12,8 +15,6 @@
12
15
  "noFallthroughCasesInSwitch": true,
13
16
  "noEmitOnError": true,
14
17
  "sourceMap": true,
15
- "experimentalDecorators": true,
16
- "emitDecoratorMetadata": true,
17
18
  "removeComments": false,
18
19
  "forceConsistentCasingInFileNames": true,
19
20
  "incremental": false,
@@ -21,6 +22,8 @@
21
22
  "importHelpers": true,
22
23
  "noEmitHelpers": true,
23
24
  "noImplicitOverride": true,
24
- "pretty": true
25
+ "pretty": true,
26
+ "esModuleInterop": false,
27
+ "allowSyntheticDefaultImports": true
25
28
  }
26
29
  }