@liuhlightning/jwt 0.3.1 → 0.3.6
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.
|
@@ -88,7 +88,7 @@ export interface JWTOptions {
|
|
|
88
88
|
jwtID?: string;
|
|
89
89
|
}
|
|
90
90
|
export interface JWTHeader {
|
|
91
|
-
typ
|
|
91
|
+
typ?: string;
|
|
92
92
|
alg: JWTAlgorithm | string;
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
@@ -98,31 +98,31 @@ export interface JWTPayloadRegisteredClaims {
|
|
|
98
98
|
/**
|
|
99
99
|
* Issuer
|
|
100
100
|
*/
|
|
101
|
-
iss?: string;
|
|
101
|
+
iss?: string | undefined;
|
|
102
102
|
/**
|
|
103
103
|
* Subject
|
|
104
104
|
*/
|
|
105
|
-
sub?: string;
|
|
105
|
+
sub?: string | undefined;
|
|
106
106
|
/**
|
|
107
107
|
* Audience
|
|
108
108
|
*/
|
|
109
|
-
aud?: string;
|
|
109
|
+
aud?: string | undefined;
|
|
110
110
|
/**
|
|
111
111
|
* Expiration Time, in seconds
|
|
112
112
|
*/
|
|
113
|
-
exp?: number;
|
|
113
|
+
exp?: number | undefined;
|
|
114
114
|
/**
|
|
115
115
|
* Not Before, in seconds
|
|
116
116
|
*/
|
|
117
|
-
nbf?: number;
|
|
117
|
+
nbf?: number | undefined;
|
|
118
118
|
/**
|
|
119
119
|
* Issued At, in seconds
|
|
120
120
|
*/
|
|
121
|
-
iat?: number;
|
|
121
|
+
iat?: number | undefined;
|
|
122
122
|
/**
|
|
123
123
|
* JWT ID
|
|
124
124
|
*/
|
|
125
|
-
jti?: string;
|
|
125
|
+
jti?: string | undefined;
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* The payload of a JWT
|
|
@@ -245,13 +245,13 @@ export declare class JWT {
|
|
|
245
245
|
* @returns The current Unix timestamp in seconds.
|
|
246
246
|
*/
|
|
247
247
|
get now(): number;
|
|
248
|
-
issuer?: string;
|
|
249
|
-
subject?: string;
|
|
250
|
-
audience?: string;
|
|
251
|
-
expirationTime?: number;
|
|
252
|
-
notBefore?: number;
|
|
253
|
-
issuedAt?: number;
|
|
254
|
-
jwtID?: string;
|
|
248
|
+
issuer?: string | undefined;
|
|
249
|
+
subject?: string | undefined;
|
|
250
|
+
audience?: string | undefined;
|
|
251
|
+
expirationTime?: number | undefined;
|
|
252
|
+
notBefore?: number | undefined;
|
|
253
|
+
issuedAt?: number | undefined;
|
|
254
|
+
jwtID?: string | undefined;
|
|
255
255
|
/**
|
|
256
256
|
* Create a new JWT instance
|
|
257
257
|
* @param secret The secret used to sign the token
|
|
@@ -33,6 +33,30 @@ const JWT_HASH_ALGORITHM_MAP = {
|
|
|
33
33
|
* https://datatracker.ietf.org/doc/html/rfc7519
|
|
34
34
|
*/
|
|
35
35
|
class JWT {
|
|
36
|
+
/**
|
|
37
|
+
* The secret used to sign the token
|
|
38
|
+
*
|
|
39
|
+
* Secret is for HS256, HS384, HS512
|
|
40
|
+
*/
|
|
41
|
+
secret;
|
|
42
|
+
/**
|
|
43
|
+
* The private key used to sign the token
|
|
44
|
+
*
|
|
45
|
+
* Private key is for RS256, RS384, RS512, ES256, ES384, ES512, PS256, PS384, PS512
|
|
46
|
+
*/
|
|
47
|
+
privateKey;
|
|
48
|
+
/**
|
|
49
|
+
* The public key used to verify the token
|
|
50
|
+
*
|
|
51
|
+
* Public key is for RS256, RS384, RS512, ES256, ES384, ES512, PS256, PS384, PS512
|
|
52
|
+
*/
|
|
53
|
+
publicKey;
|
|
54
|
+
/**
|
|
55
|
+
* The algorithm used to sign the token
|
|
56
|
+
*
|
|
57
|
+
* Set in header
|
|
58
|
+
*/
|
|
59
|
+
algorithm;
|
|
36
60
|
/**
|
|
37
61
|
* Returns the current Unix timestamp in seconds.
|
|
38
62
|
* @returns The current Unix timestamp in seconds.
|
|
@@ -40,6 +64,13 @@ class JWT {
|
|
|
40
64
|
get now() {
|
|
41
65
|
return JWT.ms2s(Date.now());
|
|
42
66
|
}
|
|
67
|
+
issuer;
|
|
68
|
+
subject;
|
|
69
|
+
audience;
|
|
70
|
+
expirationTime;
|
|
71
|
+
notBefore;
|
|
72
|
+
issuedAt;
|
|
73
|
+
jwtID;
|
|
43
74
|
/**
|
|
44
75
|
* Create a new JWT instance
|
|
45
76
|
* @param secret The secret used to sign the token
|
|
@@ -48,9 +79,11 @@ class JWT {
|
|
|
48
79
|
constructor(key, options = {}) {
|
|
49
80
|
if (typeof key === "string") {
|
|
50
81
|
this.secret = (0, crypto_1.createSecretKey)(key, "utf-8");
|
|
82
|
+
this.algorithm = options.algorithm ?? "HS256";
|
|
51
83
|
}
|
|
52
84
|
else if (key instanceof Buffer) {
|
|
53
85
|
this.secret = (0, crypto_1.createSecretKey)(key);
|
|
86
|
+
this.algorithm = options.algorithm ?? "HS256";
|
|
54
87
|
}
|
|
55
88
|
else {
|
|
56
89
|
const { privateKey, publicKey } = key;
|
|
@@ -63,8 +96,8 @@ class JWT {
|
|
|
63
96
|
// only set public key
|
|
64
97
|
this.publicKey = (0, crypto_1.createPublicKey)(publicKey);
|
|
65
98
|
}
|
|
99
|
+
this.algorithm = options.algorithm ?? "RS256";
|
|
66
100
|
}
|
|
67
|
-
this.algorithm = options.algorithm ?? "HS256";
|
|
68
101
|
this.issuer = options.issuer;
|
|
69
102
|
this.subject = options.subject;
|
|
70
103
|
this.audience = options.audience;
|
|
@@ -135,8 +168,9 @@ class JWT {
|
|
|
135
168
|
return `${hp}.${s}`;
|
|
136
169
|
}
|
|
137
170
|
checkHeader(input) {
|
|
138
|
-
if (input.typ !== "JWT")
|
|
171
|
+
if (input.typ && input.typ !== "JWT") {
|
|
139
172
|
throw new error_1.JWTErrorInvalidType(input.typ);
|
|
173
|
+
}
|
|
140
174
|
}
|
|
141
175
|
checkPayload(input, options = {}) {
|
|
142
176
|
// check issuer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liuhlightning/jwt",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "json web token in full typescript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jwt",
|
|
@@ -31,7 +31,10 @@
|
|
|
31
31
|
"eslint": "^10.1.0",
|
|
32
32
|
"prettier": "^3.5.3",
|
|
33
33
|
"ts-node": "^10.9.2",
|
|
34
|
-
"typescript": "^
|
|
34
|
+
"typescript": "^5.9.3",
|
|
35
35
|
"typescript-eslint": "^8.18.0"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
36
39
|
}
|
|
37
40
|
}
|
|
File without changes
|
|
File without changes
|