@liuhlightning/jwt 0.1.3 → 0.2.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.
- package/dist/index.d.ts +0 -18
- package/dist/index.js +6 -32
- package/dist/parse.d.ts +7 -0
- package/dist/parse.js +16 -0
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -284,24 +284,6 @@ export declare class JWT {
|
|
|
284
284
|
* @returns The payload of the token
|
|
285
285
|
*/
|
|
286
286
|
verify<T extends JWTPayload = JWTPayload>(input: string, options?: JWTVerifyOptions): T;
|
|
287
|
-
/**
|
|
288
|
-
* Parse the token
|
|
289
|
-
* @param input The token to parse
|
|
290
|
-
* @returns The header, payload, and signature of the token
|
|
291
|
-
*/
|
|
292
|
-
static parse(input: string): [string, string, string];
|
|
293
|
-
/**
|
|
294
|
-
* Decode header or payload
|
|
295
|
-
* @param input The input to decode
|
|
296
|
-
* @returns The decoded input
|
|
297
|
-
*/
|
|
298
|
-
static decode<T>(input: string): T;
|
|
299
|
-
/**
|
|
300
|
-
* Encode data
|
|
301
|
-
* @param data The data to encode
|
|
302
|
-
* @returns The encoded data
|
|
303
|
-
*/
|
|
304
|
-
static encode(data: unknown): string;
|
|
305
287
|
}
|
|
306
288
|
export * from "./error";
|
|
307
289
|
export default JWT;
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ const crypto_1 = require("crypto");
|
|
|
19
19
|
const decode_1 = require("./decode");
|
|
20
20
|
const encode_1 = require("./encode");
|
|
21
21
|
const error_1 = require("./error");
|
|
22
|
+
const parse_1 = require("./parse");
|
|
22
23
|
const time_1 = require("./time");
|
|
23
24
|
/**
|
|
24
25
|
* A class to create and verify JSON Web Tokens
|
|
@@ -82,18 +83,15 @@ class JWT {
|
|
|
82
83
|
aud: this.audience ?? options.audience,
|
|
83
84
|
exp: this.expirationTime ?? options.expirationTime,
|
|
84
85
|
nbf: this.notBefore ?? options.notBefore,
|
|
85
|
-
iat: this.issuedAt ?? options.issuedAt,
|
|
86
|
+
iat: this.issuedAt ?? options.issuedAt ?? (0, time_1.now)(),
|
|
86
87
|
jti: this.jwtID ?? options.jwtID,
|
|
87
88
|
};
|
|
88
|
-
if (rc.exp)
|
|
89
|
+
if (rc.exp)
|
|
89
90
|
rc.exp = (0, time_1.buildTime)(rc.exp);
|
|
90
|
-
|
|
91
|
-
if (rc.nbf) {
|
|
91
|
+
if (rc.nbf)
|
|
92
92
|
rc.nbf = (0, time_1.buildTime)(rc.nbf);
|
|
93
|
-
|
|
94
|
-
if (rc.iat) {
|
|
93
|
+
if (rc.iat)
|
|
95
94
|
rc.iat = (0, time_1.buildTime)(rc.iat);
|
|
96
|
-
}
|
|
97
95
|
return { ...rc, ...input };
|
|
98
96
|
}
|
|
99
97
|
/**
|
|
@@ -189,7 +187,7 @@ class JWT {
|
|
|
189
187
|
* @returns The payload of the token
|
|
190
188
|
*/
|
|
191
189
|
verify(input, options = {}) {
|
|
192
|
-
const [header, payload, signature] =
|
|
190
|
+
const [header, payload, signature] = (0, parse_1.parse)(input);
|
|
193
191
|
// check header
|
|
194
192
|
const h = (0, decode_1.decode)(header);
|
|
195
193
|
this.checkHeader(h);
|
|
@@ -201,30 +199,6 @@ class JWT {
|
|
|
201
199
|
this.checkSignature(signature, s1, h.alg);
|
|
202
200
|
return p;
|
|
203
201
|
}
|
|
204
|
-
/**
|
|
205
|
-
* Parse the token
|
|
206
|
-
* @param input The token to parse
|
|
207
|
-
* @returns The header, payload, and signature of the token
|
|
208
|
-
*/
|
|
209
|
-
static parse(input) {
|
|
210
|
-
return input.split(".", 3);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Decode header or payload
|
|
214
|
-
* @param input The input to decode
|
|
215
|
-
* @returns The decoded input
|
|
216
|
-
*/
|
|
217
|
-
static decode(input) {
|
|
218
|
-
return (0, decode_1.decode)(input);
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Encode data
|
|
222
|
-
* @param data The data to encode
|
|
223
|
-
* @returns The encoded data
|
|
224
|
-
*/
|
|
225
|
-
static encode(data) {
|
|
226
|
-
return (0, encode_1.encode)(data);
|
|
227
|
-
}
|
|
228
202
|
}
|
|
229
203
|
exports.JWT = JWT;
|
|
230
204
|
__exportStar(require("./error"), exports);
|
package/dist/parse.d.ts
ADDED
package/dist/parse.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = parse;
|
|
4
|
+
const error_1 = require("./error");
|
|
5
|
+
/**
|
|
6
|
+
* Parse the token
|
|
7
|
+
* @param input The token to parse
|
|
8
|
+
* @returns The header, payload, and signature of the token
|
|
9
|
+
*/
|
|
10
|
+
function parse(input) {
|
|
11
|
+
const r = input.split(".", 3);
|
|
12
|
+
if (r.length !== 3)
|
|
13
|
+
throw new error_1.JWTError(`Token parts is not 3 ${input}`);
|
|
14
|
+
return r;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=parse.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liuhlightning/jwt",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "json web token in full typescript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jwt",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"packageManager": "yarn@1.22.19",
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "tsc -p tsconfig.build.json",
|
|
25
|
-
"push": "yarn version --patch && git push",
|
|
25
|
+
"push": "yarn version --patch && git push && git push --tags",
|
|
26
26
|
"test": "ts-node ./tests/index.test.ts"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"typescript": "^
|
|
29
|
+
"@eslint/js": "^9.29.0",
|
|
30
|
+
"@types/node": "^22.13.14",
|
|
31
|
+
"eslint": "^9.29.0",
|
|
32
|
+
"prettier": "^3.5.3",
|
|
33
|
+
"ts-node": "^10.9.2",
|
|
34
|
+
"typescript": "^5.8.3",
|
|
35
|
+
"typescript-eslint": "^8.18.0"
|
|
36
36
|
}
|
|
37
37
|
}
|