@nivinjoseph/n-sec 4.0.6 → 5.0.2

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 (54) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc +335 -0
  3. package/dist/api-security/alg-type.js +2 -0
  4. package/dist/api-security/alg-type.js.map +1 -1
  5. package/dist/api-security/claim.d.ts +2 -3
  6. package/dist/api-security/claim.js +3 -2
  7. package/dist/api-security/claim.js.map +1 -1
  8. package/dist/api-security/claims-identity.js +2 -1
  9. package/dist/api-security/claims-identity.js.map +1 -1
  10. package/dist/api-security/expired-token-exception.d.ts +0 -1
  11. package/dist/api-security/expired-token-exception.js +2 -2
  12. package/dist/api-security/expired-token-exception.js.map +1 -1
  13. package/dist/api-security/invalid-token-exception.d.ts +0 -1
  14. package/dist/api-security/invalid-token-exception.js +3 -3
  15. package/dist/api-security/invalid-token-exception.js.map +1 -1
  16. package/dist/api-security/json-web-token.d.ts +4 -5
  17. package/dist/api-security/json-web-token.js +88 -81
  18. package/dist/api-security/json-web-token.js.map +1 -1
  19. package/dist/api-security/security-token.js +2 -2
  20. package/dist/api-security/security-token.js.map +1 -1
  21. package/dist/crypto/asymmetric-encryption.js +49 -0
  22. package/dist/crypto/asymmetric-encryption.js.map +1 -1
  23. package/dist/crypto/crypto-exception.js +1 -0
  24. package/dist/crypto/crypto-exception.js.map +1 -1
  25. package/dist/crypto/digital-signature.js +51 -0
  26. package/dist/crypto/digital-signature.js.map +1 -1
  27. package/dist/crypto/hash.d.ts +2 -3
  28. package/dist/crypto/hash.js +5 -5
  29. package/dist/crypto/hash.js.map +1 -1
  30. package/dist/crypto/hmac.d.ts +1 -2
  31. package/dist/crypto/hmac.js +4 -4
  32. package/dist/crypto/hmac.js.map +1 -1
  33. package/dist/crypto/symmetric-encryption.d.ts +1 -2
  34. package/dist/crypto/symmetric-encryption.js +15 -20
  35. package/dist/crypto/symmetric-encryption.js.map +1 -1
  36. package/dist/index.js +2 -0
  37. package/dist/index.js.map +1 -1
  38. package/package.json +12 -11
  39. package/src/api-security/claim.ts +5 -5
  40. package/src/api-security/claims-identity.ts +1 -1
  41. package/src/api-security/expired-token-exception.ts +1 -2
  42. package/src/api-security/invalid-token-exception.ts +2 -3
  43. package/src/api-security/json-web-token.ts +80 -79
  44. package/src/crypto/hash.ts +7 -9
  45. package/src/crypto/hmac.ts +4 -5
  46. package/src/crypto/symmetric-encryption.ts +17 -27
  47. package/test/hash.test.ts +42 -41
  48. package/test/hmac.test.ts +24 -23
  49. package/test/json-web-token.test.ts +66 -61
  50. package/test/other.test.ts +3 -3
  51. package/test/symmetric-encryption.test.ts +12 -10
  52. package/tsconfig.json +9 -11
  53. package/dist/crypto/uuid.js.map +0 -1
  54. package/tslint.json +0 -64
package/.eslintignore ADDED
@@ -0,0 +1,2 @@
1
+ node_modules
2
+ dist
package/.eslintrc ADDED
@@ -0,0 +1,335 @@
1
+ {
2
+ "root": true,
3
+ "parser": "@typescript-eslint/parser",
4
+ "plugins": [
5
+ "@typescript-eslint"
6
+ ],
7
+ "extends": [
8
+ "eslint:recommended",
9
+ "plugin:@typescript-eslint/eslint-recommended",
10
+ "plugin:@typescript-eslint/recommended"
11
+ ],
12
+ "parserOptions": {
13
+ "project": "tsconfig.json"
14
+ },
15
+ "rules": {
16
+ "no-eval": "error",
17
+ "no-void": "error",
18
+ "no-with": "error",
19
+ "@typescript-eslint/adjacent-overload-signatures": "error",
20
+ "@typescript-eslint/array-type": [
21
+ "error",
22
+ {
23
+ "default": "generic",
24
+ "readonly": "generic"
25
+ }
26
+ ],
27
+ "@typescript-eslint/await-thenable": "error",
28
+ "@typescript-eslint/ban-ts-comment": [
29
+ "error",
30
+ {
31
+ "ts-expect-error": "allow-with-description",
32
+ "ts-ignore": "allow-with-description",
33
+ "ts-nocheck": true,
34
+ "ts-check": true
35
+ }
36
+ ],
37
+ "@typescript-eslint/ban-tslint-comment": "error",
38
+ "@typescript-eslint/ban-types": [
39
+ "error",
40
+ {
41
+ "extendDefaults": false,
42
+ "types": {
43
+ "String": {
44
+ "message": "Use string instead",
45
+ "fixWith": "string"
46
+ },
47
+ "Boolean": {
48
+ "message": "Use boolean instead",
49
+ "fixWith": "boolean"
50
+ },
51
+ "Number": {
52
+ "message": "Use number instead",
53
+ "fixWith": "number"
54
+ },
55
+ "Symbol": {
56
+ "message": "Use symbol instead",
57
+ "fixWith": "symbol"
58
+ }
59
+ }
60
+ }
61
+ ],
62
+ "brace-style": "off",
63
+ "@typescript-eslint/brace-style": [
64
+ "error",
65
+ "allman",
66
+ {
67
+ "allowSingleLine": true
68
+ }
69
+ ],
70
+ "@typescript-eslint/class-literal-property-style": [
71
+ "off",
72
+ "getters"
73
+ ],
74
+ "comma-dangle": "off",
75
+ "@typescript-eslint/comma-dangle": [
76
+ "error",
77
+ "never"
78
+ ],
79
+ "default-param-last": "off",
80
+ "@typescript-eslint/default-param-last": "error",
81
+ "@typescript-eslint/explicit-function-return-type": "error",
82
+ "@typescript-eslint/explicit-member-accessibility": "error",
83
+ "@typescript-eslint/explicit-module-boundary-types": "error",
84
+ "func-call-spacing": "off",
85
+ "@typescript-eslint/func-call-spacing": [
86
+ "error",
87
+ "never"
88
+ ],
89
+ "@typescript-eslint/member-delimiter-style": [
90
+ "error",
91
+ {
92
+ "multiline": {
93
+ "delimiter": "semi",
94
+ "requireLast": true
95
+ },
96
+ "singleline": {
97
+ "delimiter": "semi",
98
+ "requireLast": true
99
+ },
100
+ "multilineDetection": "brackets"
101
+ }
102
+ ],
103
+ "@typescript-eslint/member-ordering": [
104
+ "error",
105
+ {
106
+ "default": [
107
+ // Index signature
108
+ "signature",
109
+ // Fields
110
+ "private-static-field",
111
+ "protected-static-field",
112
+ "public-static-field",
113
+ // "private-decorated-field",
114
+ // "protected-decorated-field",
115
+ // "public-decorated-field",
116
+ "private-instance-field",
117
+ "protected-instance-field",
118
+ "public-instance-field",
119
+ // "public-abstract-field",
120
+ // "protected-abstract-field",
121
+ // "private-abstract-field",
122
+ // "private-field",
123
+ // "protected-field",
124
+ // "public-field",
125
+ // "static-field",
126
+ // "instance-field",
127
+ // "abstract-field",
128
+ // "decorated-field",
129
+ // "field",
130
+ // Getters
131
+ // "public-static-get",
132
+ // "protected-static-get",
133
+ // "private-static-get",
134
+ // "public-decorated-get",
135
+ // "protected-decorated-get",
136
+ // "private-decorated-get",
137
+ // "public-instance-get",
138
+ // "protected-instance-get",
139
+ // "private-instance-get",
140
+ // "public-abstract-get",
141
+ // "protected-abstract-get",
142
+ // "private-abstract-get",
143
+ // "public-get",
144
+ // "protected-get",
145
+ // "private-get",
146
+ // "static-get",
147
+ // "instance-get",
148
+ // "abstract-get",
149
+ // "decorated-get",
150
+ // "get",
151
+ // Setters
152
+ // "public-static-set",
153
+ // "protected-static-set",
154
+ // "private-static-set",
155
+ // "public-decorated-set",
156
+ // "protected-decorated-set",
157
+ // "private-decorated-set",
158
+ // "public-instance-set",
159
+ // "protected-instance-set",
160
+ // "private-instance-set",
161
+ // "public-abstract-set",
162
+ // "protected-abstract-set",
163
+ // "private-abstract-set",
164
+ // "public-set",
165
+ // "protected-set",
166
+ // "private-set",
167
+ // "static-set",
168
+ // "instance-set",
169
+ // "abstract-set",
170
+ // "decorated-set",
171
+ // "set",
172
+ // [
173
+ // "get",
174
+ // "set"
175
+ // ],
176
+ [
177
+ "private-static-get",
178
+ "private-static-set"
179
+ ],
180
+ [
181
+ "protected-static-get",
182
+ "protected-static-set"
183
+ ],
184
+ [
185
+ "public-static-get",
186
+ "public-static-set"
187
+ ],
188
+ [
189
+ "private-instance-get",
190
+ "private-instance-set"
191
+ ],
192
+ [
193
+ "protected-instance-get",
194
+ "protected-instance-set"
195
+ ],
196
+ [
197
+ "public-instance-get",
198
+ "public-instance-set"
199
+ ],
200
+ // Constructors
201
+ "public-constructor",
202
+ "protected-constructor",
203
+ "private-constructor",
204
+ // "constructor",
205
+ // Methods
206
+ "public-static-method",
207
+ "protected-static-method",
208
+ "private-static-method",
209
+ // "public-decorated-method",
210
+ // "protected-decorated-method",
211
+ // "private-decorated-method",
212
+ "public-instance-method",
213
+ "protected-instance-method",
214
+ "private-instance-method",
215
+ // "public-abstract-method",
216
+ // "protected-abstract-method",
217
+ // "private-abstract-method",
218
+ // "public-method",
219
+ // "protected-method",
220
+ // "private-method",
221
+ // "static-method",
222
+ // "instance-method",
223
+ // "abstract-method",
224
+ // "decorated-method",
225
+ // "method"
226
+ ]
227
+ }
228
+ ],
229
+ "@typescript-eslint/method-signature-style": [
230
+ "error",
231
+ "method"
232
+ ],
233
+ "@typescript-eslint/naming-convention": [
234
+ "error",
235
+ {
236
+ "selector": "memberLike",
237
+ "modifiers": [
238
+ "private"
239
+ ],
240
+ "format": [
241
+ "camelCase"
242
+ ],
243
+ "leadingUnderscore": "require"
244
+ }
245
+ ],
246
+ "@typescript-eslint/no-confusing-non-null-assertion": "error",
247
+ "@typescript-eslint/no-confusing-void-expression": [
248
+ "error",
249
+ {
250
+ "ignoreArrowShorthand": true
251
+ }
252
+ ],
253
+ "no-dupe-class-members": "off",
254
+ "@typescript-eslint/no-dupe-class-members": "error",
255
+ "@typescript-eslint/no-duplicate-enum-values": "error",
256
+ "no-duplicate-imports": "off",
257
+ "@typescript-eslint/no-duplicate-imports": "error",
258
+ "no-empty-function": "off",
259
+ "@typescript-eslint/no-empty-function": [
260
+ "error",
261
+ {
262
+ "allow": [
263
+ "private-constructors"
264
+ ]
265
+ }
266
+ ],
267
+ "@typescript-eslint/no-explicit-any": "off",
268
+ "@typescript-eslint/no-extra-non-null-assertion": "error",
269
+ "no-extra-parens": "off",
270
+ "@typescript-eslint/no-extra-parens": [
271
+ "error",
272
+ "all",
273
+ {
274
+ "nestedBinaryExpressions": false
275
+ }
276
+ ],
277
+ "no-extra-semi": "off",
278
+ "@typescript-eslint/no-extra-semi": "error",
279
+ "@typescript-eslint/no-floating-promises": "error",
280
+ "@typescript-eslint/no-for-in-array": "error",
281
+ "no-implied-eval": "off",
282
+ "@typescript-eslint/no-implied-eval": "error",
283
+ "no-invalid-this": "off",
284
+ "@typescript-eslint/no-invalid-this": "error",
285
+ "@typescript-eslint/no-invalid-void-type": "error",
286
+ "no-loop-func": "off",
287
+ "@typescript-eslint/no-loop-func": "error",
288
+ "no-loss-of-precision": "off",
289
+ "@typescript-eslint/no-loss-of-precision": "error",
290
+ "@typescript-eslint/no-meaningless-void-operator": "error",
291
+ "@typescript-eslint/no-misused-new": "error",
292
+ "@typescript-eslint/no-misused-promises": "error",
293
+ "@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error",
294
+ "@typescript-eslint/no-non-null-asserted-optional-chain": "error",
295
+ "@typescript-eslint/no-non-null-assertion": "off",
296
+ "no-redeclare": "off",
297
+ "@typescript-eslint/no-redeclare": "error",
298
+ "@typescript-eslint/no-this-alias": "error",
299
+ "@typescript-eslint/no-throw-literal": "error",
300
+ "@typescript-eslint/no-unnecessary-condition": [
301
+ "error",
302
+ {
303
+ "allowConstantLoopConditions": true
304
+ }
305
+ ],
306
+ "@typescript-eslint/no-unnecessary-type-assertion": "error",
307
+ "@typescript-eslint/no-unnecessary-type-constraint": "error",
308
+ "@typescript-eslint/no-unsafe-call": "error",
309
+ "@typescript-eslint/no-unsafe-return": "error",
310
+ "no-unused-expressions": "off",
311
+ "@typescript-eslint/no-unused-expressions": "error",
312
+ "no-unused-vars": "off",
313
+ "@typescript-eslint/no-unused-vars": "off",
314
+ "no-use-before-define": "off",
315
+ "@typescript-eslint/no-use-before-define": "off",
316
+ "no-useless-constructor": "off",
317
+ "@typescript-eslint/no-useless-constructor": "error",
318
+ "@typescript-eslint/no-useless-empty-export": "error",
319
+ "@typescript-eslint/no-var-requires": "off",
320
+ "@typescript-eslint/parameter-properties": "error",
321
+ "@typescript-eslint/prefer-enum-initializers": "error",
322
+ "@typescript-eslint/prefer-includes": "error",
323
+ "@typescript-eslint/prefer-literal-enum-member": "error",
324
+ "@typescript-eslint/prefer-readonly": "error",
325
+ "@typescript-eslint/prefer-reduce-type-parameter": "error",
326
+ "@typescript-eslint/prefer-string-starts-ends-with": "error",
327
+ "@typescript-eslint/prefer-ts-expect-error": "error",
328
+ "@typescript-eslint/require-array-sort-compare": "error",
329
+ "no-return-await": "off",
330
+ "@typescript-eslint/return-await": "error",
331
+ "semi": "off",
332
+ "@typescript-eslint/semi": "error",
333
+ "@typescript-eslint/unbound-method": "error"
334
+ }
335
+ }
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AlgType = void 0;
4
+ // public
4
5
  var AlgType;
5
6
  (function (AlgType) {
6
7
  AlgType[AlgType["hmac"] = 1] = "hmac";
8
+ // dsig = 2
7
9
  })(AlgType = exports.AlgType || (exports.AlgType = {}));
8
10
  //# sourceMappingURL=alg-type.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"alg-type.js","sourceRoot":"","sources":["../../src/api-security/alg-type.ts"],"names":[],"mappings":";;;AACA,IAAY,OAIX;AAJD,WAAY,OAAO;IAEf,qCAAQ,CAAA;AAEZ,CAAC,EAJW,OAAO,GAAP,eAAO,KAAP,eAAO,QAIlB"}
1
+ {"version":3,"file":"alg-type.js","sourceRoot":"","sources":["../../src/api-security/alg-type.ts"],"names":[],"mappings":";;;AAAA,SAAS;AACT,IAAY,OAIX;AAJD,WAAY,OAAO;IAEf,qCAAQ,CAAA;IACR,WAAW;AACf,CAAC,EAJW,OAAO,GAAP,eAAO,KAAP,eAAO,QAIlB"}
@@ -1,9 +1,8 @@
1
- import "@nivinjoseph/n-ext";
2
1
  export declare class Claim {
3
2
  private readonly _type;
4
3
  private readonly _value;
5
4
  get type(): string;
6
- get value(): any;
7
- constructor(type: string, value: any);
5
+ get value(): unknown;
6
+ constructor(type: string, value: unknown);
8
7
  equals(claim: Claim): boolean;
9
8
  }
@@ -2,16 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Claim = void 0;
4
4
  const n_defensive_1 = require("@nivinjoseph/n-defensive");
5
- require("@nivinjoseph/n-ext");
5
+ // public
6
6
  class Claim {
7
7
  constructor(type, value) {
8
- n_defensive_1.given(type, "type").ensureHasValue().ensure(t => !t.isEmptyOrWhiteSpace());
8
+ (0, n_defensive_1.given)(type, "type").ensureHasValue().ensureIsString();
9
9
  this._type = type.trim();
10
10
  this._value = value;
11
11
  }
12
12
  get type() { return this._type; }
13
13
  get value() { return this._value; }
14
14
  equals(claim) {
15
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
15
16
  if (claim == null)
16
17
  return false;
17
18
  if (claim === this)
@@ -1 +1 @@
1
- {"version":3,"file":"claim.js","sourceRoot":"","sources":["../../src/api-security/claim.ts"],"names":[],"mappings":";;;AAAA,0DAAiD;AACjD,8BAA4B;AAI5B,MAAa,KAAK;IAUd,YAAmB,IAAY,EAAE,KAAU;QAEvC,mBAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,mBAAmB,EAAE,CAAC,CAAC;QAE3E,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IAVD,IAAW,IAAI,KAAa,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,IAAW,KAAK,KAAU,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAYxC,MAAM,CAAC,KAAY;QAEtB,IAAI,KAAK,IAAI,IAAI;YACb,OAAO,KAAK,CAAC;QAEjB,IAAI,KAAK,KAAK,IAAI;YACd,OAAO,IAAI,CAAC;QAEhB,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC;IAClE,CAAC;CACJ;AA7BD,sBA6BC"}
1
+ {"version":3,"file":"claim.js","sourceRoot":"","sources":["../../src/api-security/claim.ts"],"names":[],"mappings":";;;AAAA,0DAAiD;AAGjD,SAAS;AACT,MAAa,KAAK;IAUd,YAAmB,IAAY,EAAE,KAAc;QAE3C,IAAA,mBAAK,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC,cAAc,EAAE,CAAC,cAAc,EAAE,CAAC;QAEtD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IAVD,IAAW,IAAI,KAAa,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,IAAW,KAAK,KAAc,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAY5C,MAAM,CAAC,KAAY;QAEtB,uEAAuE;QACvE,IAAI,KAAK,IAAI,IAAI;YACb,OAAO,KAAK,CAAC;QAEjB,IAAI,KAAK,KAAK,IAAI;YACd,OAAO,IAAI,CAAC;QAEhB,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC;IAClE,CAAC;CACJ;AA9BD,sBA8BC"}
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ClaimsIdentity = void 0;
4
4
  const n_defensive_1 = require("@nivinjoseph/n-defensive");
5
+ // public
5
6
  class ClaimsIdentity {
6
7
  constructor(claims) {
7
- n_defensive_1.given(claims, "claims").ensureHasValue();
8
+ (0, n_defensive_1.given)(claims, "claims").ensureHasValue().ensureIsArray();
8
9
  this._claims = [...claims];
9
10
  }
10
11
  get claims() { return this._claims; }
@@ -1 +1 @@
1
- {"version":3,"file":"claims-identity.js","sourceRoot":"","sources":["../../src/api-security/claims-identity.ts"],"names":[],"mappings":";;;AACA,0DAAiD;AAIjD,MAAa,cAAc;IAQvB,YAAmB,MAA4B;QAE3C,mBAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,cAAc,EAAE,CAAC;QAEzC,IAAI,CAAC,OAAO,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;IAC/B,CAAC;IARD,IAAW,MAAM,KAA2B,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAW3D,QAAQ,CAAC,KAAY;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD,CAAC;CACJ;AApBD,wCAoBC"}
1
+ {"version":3,"file":"claims-identity.js","sourceRoot":"","sources":["../../src/api-security/claims-identity.ts"],"names":[],"mappings":";;;AACA,0DAAiD;AAGjD,SAAS;AACT,MAAa,cAAc;IAQvB,YAAmB,MAA4B;QAE3C,IAAA,mBAAK,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,cAAc,EAAE,CAAC,aAAa,EAAE,CAAC;QAEzD,IAAI,CAAC,OAAO,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;IAC/B,CAAC;IARD,IAAW,MAAM,KAA2B,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAW3D,QAAQ,CAAC,KAAY;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD,CAAC;CACJ;AApBD,wCAoBC"}
@@ -1,5 +1,4 @@
1
1
  import { Exception } from "@nivinjoseph/n-exception";
2
- import "@nivinjoseph/n-ext";
3
2
  export declare class ExpiredTokenException extends Exception {
4
3
  private readonly _token;
5
4
  get token(): string;
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ExpiredTokenException = void 0;
4
4
  const n_exception_1 = require("@nivinjoseph/n-exception");
5
5
  const n_defensive_1 = require("@nivinjoseph/n-defensive");
6
- require("@nivinjoseph/n-ext");
6
+ // public
7
7
  class ExpiredTokenException extends n_exception_1.Exception {
8
8
  constructor(token) {
9
- n_defensive_1.given(token, "token").ensureHasValue().ensure(t => !t.isEmptyOrWhiteSpace());
9
+ (0, n_defensive_1.given)(token, "token").ensureHasValue().ensureIsString();
10
10
  token = token.trim();
11
11
  super(`Token '${token}' is expired.`);
12
12
  this._token = token;
@@ -1 +1 @@
1
- {"version":3,"file":"expired-token-exception.js","sourceRoot":"","sources":["../../src/api-security/expired-token-exception.ts"],"names":[],"mappings":";;;AAAA,0DAAqD;AACrD,0DAAiD;AACjD,8BAA4B;AAI5B,MAAa,qBAAsB,SAAQ,uBAAS;IAQhD,YAAmB,KAAa;QAE5B,mBAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,mBAAmB,EAAE,CAAC,CAAC;QAC7E,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QACrB,KAAK,CAAC,UAAU,KAAK,eAAe,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IATD,IAAW,KAAK,KAAa,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;CAUrD;AAfD,sDAeC"}
1
+ {"version":3,"file":"expired-token-exception.js","sourceRoot":"","sources":["../../src/api-security/expired-token-exception.ts"],"names":[],"mappings":";;;AAAA,0DAAqD;AACrD,0DAAiD;AAGjD,SAAS;AACT,MAAa,qBAAsB,SAAQ,uBAAS;IAQhD,YAAmB,KAAa;QAE5B,IAAA,mBAAK,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC,cAAc,EAAE,CAAC,cAAc,EAAE,CAAC;QACxD,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QACrB,KAAK,CAAC,UAAU,KAAK,eAAe,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IATD,IAAW,KAAK,KAAa,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;CAUrD;AAfD,sDAeC"}
@@ -1,5 +1,4 @@
1
1
  import { Exception } from "@nivinjoseph/n-exception";
2
- import "@nivinjoseph/n-ext";
3
2
  export declare class InvalidTokenException extends Exception {
4
3
  private readonly _token;
5
4
  private readonly _reason;
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InvalidTokenException = void 0;
4
4
  const n_exception_1 = require("@nivinjoseph/n-exception");
5
5
  const n_defensive_1 = require("@nivinjoseph/n-defensive");
6
- require("@nivinjoseph/n-ext");
6
+ // public
7
7
  class InvalidTokenException extends n_exception_1.Exception {
8
8
  constructor(token, reason) {
9
- n_defensive_1.given(token, "token").ensureHasValue().ensure(t => !t.isEmptyOrWhiteSpace());
10
- n_defensive_1.given(reason, "reason").ensureHasValue().ensure(t => !t.isEmptyOrWhiteSpace());
9
+ (0, n_defensive_1.given)(token, "token").ensureHasValue().ensureIsString();
10
+ (0, n_defensive_1.given)(reason, "reason").ensureHasValue().ensureIsString();
11
11
  token = token.trim();
12
12
  super(`Token '${token}' is invalid because ${reason}.`);
13
13
  this._token = token;
@@ -1 +1 @@
1
- {"version":3,"file":"invalid-token-exception.js","sourceRoot":"","sources":["../../src/api-security/invalid-token-exception.ts"],"names":[],"mappings":";;;AAAA,0DAAqD;AACrD,0DAAiD;AACjD,8BAA4B;AAI5B,MAAa,qBAAsB,SAAQ,uBAAS;IAUhD,YAAmB,KAAa,EAAE,MAAc;QAE5C,mBAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,mBAAmB,EAAE,CAAC,CAAC;QAC7E,mBAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,mBAAmB,EAAE,CAAC,CAAC;QAE/E,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QACrB,KAAK,CAAC,UAAU,KAAK,wBAAwB,MAAM,GAAG,CAAC,CAAC;QACxD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAbD,IAAW,KAAK,KAAa,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,IAAW,MAAM,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;CAavD;AApBD,sDAoBC"}
1
+ {"version":3,"file":"invalid-token-exception.js","sourceRoot":"","sources":["../../src/api-security/invalid-token-exception.ts"],"names":[],"mappings":";;;AAAA,0DAAqD;AACrD,0DAAiD;AAGjD,SAAS;AACT,MAAa,qBAAsB,SAAQ,uBAAS;IAUhD,YAAmB,KAAa,EAAE,MAAc;QAE5C,IAAA,mBAAK,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC,cAAc,EAAE,CAAC,cAAc,EAAE,CAAC;QACxD,IAAA,mBAAK,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,cAAc,EAAE,CAAC,cAAc,EAAE,CAAC;QAE1D,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QACrB,KAAK,CAAC,UAAU,KAAK,wBAAwB,MAAM,GAAG,CAAC,CAAC;QACxD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAbD,IAAW,KAAK,KAAa,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,IAAW,MAAM,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;CAavD;AApBD,sDAoBC"}
@@ -1,5 +1,4 @@
1
1
  import { Claim } from "./claim";
2
- import "@nivinjoseph/n-ext";
3
2
  import { AlgType } from "./alg-type";
4
3
  export declare class JsonWebToken {
5
4
  private readonly _issuer;
@@ -16,9 +15,9 @@ export declare class JsonWebToken {
16
15
  get isExpired(): boolean;
17
16
  get claims(): ReadonlyArray<Claim>;
18
17
  private constructor();
19
- generateToken(): Promise<string>;
20
18
  static fromClaims(issuer: string, algType: AlgType, key: string, expiry: number, claims: Array<Claim>): JsonWebToken;
21
- static fromToken(issuer: string, algType: AlgType, key: string, token: string): Promise<JsonWebToken>;
22
- private toHex;
23
- private static toObject;
19
+ static fromToken(issuer: string, algType: AlgType, key: string, token: string): JsonWebToken;
20
+ private static _toObject;
21
+ generateToken(): string;
22
+ private _toHex;
24
23
  }