@liuhlightning/jwt 0.1.1 → 0.1.3
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 +18 -0
- package/dist/index.js +25 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -284,6 +284,24 @@ 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;
|
|
287
305
|
}
|
|
288
306
|
export * from "./error";
|
|
289
307
|
export default JWT;
|
package/dist/index.js
CHANGED
|
@@ -189,7 +189,7 @@ class JWT {
|
|
|
189
189
|
* @returns The payload of the token
|
|
190
190
|
*/
|
|
191
191
|
verify(input, options = {}) {
|
|
192
|
-
const [header, payload, signature] =
|
|
192
|
+
const [header, payload, signature] = JWT.parse(input);
|
|
193
193
|
// check header
|
|
194
194
|
const h = (0, decode_1.decode)(header);
|
|
195
195
|
this.checkHeader(h);
|
|
@@ -201,6 +201,30 @@ class JWT {
|
|
|
201
201
|
this.checkSignature(signature, s1, h.alg);
|
|
202
202
|
return p;
|
|
203
203
|
}
|
|
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
|
+
}
|
|
204
228
|
}
|
|
205
229
|
exports.JWT = JWT;
|
|
206
230
|
__exportStar(require("./error"), exports);
|