@twin.org/web 0.0.1-next.36 → 0.0.1-next.38
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/cjs/index.cjs +103 -87
- package/dist/esm/index.mjs +104 -88
- package/dist/types/index.d.ts +2 -1
- package/dist/types/models/IJwk.d.ts +2 -58
- package/dist/types/models/IJwtHeader.d.ts +2 -18
- package/dist/types/models/IJwtPayload.d.ts +2 -33
- package/dist/types/models/jwkCryptoKey.d.ts +5 -0
- package/dist/types/utils/jwk.d.ts +13 -0
- package/dist/types/utils/jwt.d.ts +46 -28
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/Jwk.md +35 -0
- package/docs/reference/classes/Jwt.md +112 -68
- package/docs/reference/index.md +2 -2
- package/docs/reference/interfaces/IJwk.md +2 -106
- package/docs/reference/interfaces/IJwtHeader.md +4 -24
- package/docs/reference/interfaces/IJwtPayload.md +4 -56
- package/docs/reference/type-aliases/JwkCryptoKey.md +5 -0
- package/locales/en.json +5 -1
- package/package.json +5 -4
- package/dist/types/models/jwtAlgorithms.d.ts +0 -17
- package/docs/reference/type-aliases/JwtAlgorithms.md +0 -5
- package/docs/reference/variables/JwtAlgorithms.md +0 -19
|
@@ -1,37 +1,6 @@
|
|
|
1
|
+
import type { JWTPayload } from "jose";
|
|
1
2
|
/**
|
|
2
3
|
* The fields in a JSON Web Token payload.
|
|
3
4
|
*/
|
|
4
|
-
export interface IJwtPayload {
|
|
5
|
-
/**
|
|
6
|
-
* Additional fields in the payload.
|
|
7
|
-
*/
|
|
8
|
-
[key: string]: unknown;
|
|
9
|
-
/**
|
|
10
|
-
* The issuer of the token.
|
|
11
|
-
*/
|
|
12
|
-
iss?: string;
|
|
13
|
-
/**
|
|
14
|
-
* The subject of the token.
|
|
15
|
-
*/
|
|
16
|
-
sub?: string;
|
|
17
|
-
/**
|
|
18
|
-
* The audience of the token.
|
|
19
|
-
*/
|
|
20
|
-
aud?: string;
|
|
21
|
-
/**
|
|
22
|
-
* The expiration time of the token.
|
|
23
|
-
*/
|
|
24
|
-
exp?: number;
|
|
25
|
-
/**
|
|
26
|
-
* The not before time of the token.
|
|
27
|
-
*/
|
|
28
|
-
nbf?: number;
|
|
29
|
-
/**
|
|
30
|
-
* The issued at time of the token.
|
|
31
|
-
*/
|
|
32
|
-
iat?: number;
|
|
33
|
-
/**
|
|
34
|
-
* The JWT ID.
|
|
35
|
-
*/
|
|
36
|
-
jti?: string;
|
|
5
|
+
export interface IJwtPayload extends JWTPayload {
|
|
37
6
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IJwk } from "../models/IJwk";
|
|
2
|
+
import type { JwkCryptoKey } from "../models/jwkCryptoKey";
|
|
3
|
+
/**
|
|
4
|
+
* Class to handle JSON Web Keys.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Jwk {
|
|
7
|
+
/**
|
|
8
|
+
* Convert the JWK to a crypto key.
|
|
9
|
+
* @param jwk The JWK to convert.
|
|
10
|
+
* @returns The crypto key.
|
|
11
|
+
*/
|
|
12
|
+
static toCryptoKey(jwk: IJwk): Promise<JwkCryptoKey>;
|
|
13
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { IJwtHeader } from "../models/IJwtHeader";
|
|
2
2
|
import type { IJwtPayload } from "../models/IJwtPayload";
|
|
3
|
-
import {
|
|
3
|
+
import type { JwkCryptoKey } from "../models/jwkCryptoKey";
|
|
4
4
|
/**
|
|
5
|
-
* Class to
|
|
5
|
+
* Class to handle JSON Web Tokens.
|
|
6
6
|
*/
|
|
7
7
|
export declare class Jwt {
|
|
8
8
|
/**
|
|
@@ -12,7 +12,7 @@ export declare class Jwt {
|
|
|
12
12
|
* @param key The key for signing the token, can be omitted if a signer is provided.
|
|
13
13
|
* @returns The encoded token.
|
|
14
14
|
*/
|
|
15
|
-
static encode<
|
|
15
|
+
static encode<T extends IJwtHeader, U extends IJwtPayload>(header: T, payload: U, key: JwkCryptoKey): Promise<string>;
|
|
16
16
|
/**
|
|
17
17
|
* Encode a token.
|
|
18
18
|
* @param header The header to encode.
|
|
@@ -20,15 +20,15 @@ export declare class Jwt {
|
|
|
20
20
|
* @param signer Custom signer method.
|
|
21
21
|
* @returns The encoded token.
|
|
22
22
|
*/
|
|
23
|
-
static encodeWithSigner<
|
|
23
|
+
static encodeWithSigner<T extends IJwtHeader, U extends IJwtPayload>(header: T, payload: U, signer: (header: IJwtHeader, payload: IJwtPayload, key: JwkCryptoKey | undefined) => Promise<string>): Promise<string>;
|
|
24
24
|
/**
|
|
25
25
|
* Decode a token.
|
|
26
26
|
* @param token The token to decode.
|
|
27
27
|
* @returns The decoded payload.
|
|
28
28
|
*/
|
|
29
|
-
static decode<
|
|
30
|
-
header?:
|
|
31
|
-
payload?:
|
|
29
|
+
static decode<T extends IJwtHeader, U extends IJwtPayload>(token: string): Promise<{
|
|
30
|
+
header?: T;
|
|
31
|
+
payload?: U;
|
|
32
32
|
signature?: Uint8Array;
|
|
33
33
|
}>;
|
|
34
34
|
/**
|
|
@@ -37,11 +37,9 @@ export declare class Jwt {
|
|
|
37
37
|
* @param key The key for verifying the token
|
|
38
38
|
* @returns The decoded payload.
|
|
39
39
|
*/
|
|
40
|
-
static verify<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
payload?: T;
|
|
44
|
-
signature?: Uint8Array;
|
|
40
|
+
static verify<T extends IJwtHeader, U extends IJwtPayload>(token: string, key: JwkCryptoKey): Promise<{
|
|
41
|
+
header: T;
|
|
42
|
+
payload: U;
|
|
45
43
|
}>;
|
|
46
44
|
/**
|
|
47
45
|
* Verify a token.
|
|
@@ -49,37 +47,57 @@ export declare class Jwt {
|
|
|
49
47
|
* @param verifier Custom verification method.
|
|
50
48
|
* @returns The decoded payload.
|
|
51
49
|
*/
|
|
52
|
-
static verifyWithVerifier<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
static verifyWithVerifier<T extends IJwtHeader, U extends IJwtPayload>(token: string, verifier: (token: string, key: JwkCryptoKey | undefined) => Promise<{
|
|
51
|
+
header: T;
|
|
52
|
+
payload: U;
|
|
53
|
+
}>): Promise<{
|
|
54
|
+
header: T;
|
|
55
|
+
payload: U;
|
|
57
56
|
}>;
|
|
58
57
|
/**
|
|
59
58
|
* Verify a token by parts.
|
|
60
|
-
* @param
|
|
61
|
-
* @param payload The payload to verify.
|
|
62
|
-
* @param signature The signature to verify.
|
|
59
|
+
* @param token The token to verify.
|
|
63
60
|
* @param key The key for verifying the token, if not provided no verification occurs.
|
|
64
61
|
* @param verifier Custom verification method.
|
|
65
62
|
* @returns True if the parts are verified.
|
|
66
63
|
*/
|
|
67
|
-
static verifySignature<
|
|
64
|
+
static verifySignature<T extends IJwtHeader, U extends IJwtPayload>(token: string, key?: JwkCryptoKey, verifier?: (token: string, key: JwkCryptoKey | undefined) => Promise<{
|
|
65
|
+
header: T;
|
|
66
|
+
payload: U;
|
|
67
|
+
}>): Promise<{
|
|
68
|
+
header: T;
|
|
69
|
+
payload: U;
|
|
70
|
+
}>;
|
|
68
71
|
/**
|
|
69
72
|
* The default signer for the JWT.
|
|
70
|
-
* @param
|
|
71
|
-
* @param key The key to sign with.
|
|
73
|
+
* @param header The header to sign.
|
|
72
74
|
* @param payload The payload to sign.
|
|
75
|
+
* @param key The optional key to sign with.
|
|
73
76
|
* @returns The signature.
|
|
74
77
|
*/
|
|
75
|
-
static defaultSigner(
|
|
78
|
+
static defaultSigner(header: IJwtHeader, payload: IJwtPayload, key: JwkCryptoKey | undefined): Promise<string>;
|
|
76
79
|
/**
|
|
77
80
|
* The default verifier for the JWT.
|
|
78
|
-
* @param
|
|
81
|
+
* @param token The token to verify.
|
|
79
82
|
* @param key The key to verify with.
|
|
80
|
-
* @param payload The payload to verify.
|
|
81
|
-
* @param signature The signature to verify.
|
|
82
83
|
* @returns True if the signature was verified.
|
|
83
84
|
*/
|
|
84
|
-
static defaultVerifier(
|
|
85
|
+
static defaultVerifier<T extends IJwtHeader, U extends IJwtPayload>(token: string, key: JwkCryptoKey | undefined): Promise<{
|
|
86
|
+
header: T;
|
|
87
|
+
payload: U;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Create bytes for signing from header and payload.
|
|
91
|
+
* @param header The header.
|
|
92
|
+
* @param payload The payload.
|
|
93
|
+
* @returns The bytes to sign.
|
|
94
|
+
*/
|
|
95
|
+
static createSignBytes<T extends IJwtHeader, U extends IJwtPayload>(header: T, payload: U): Uint8Array;
|
|
96
|
+
/**
|
|
97
|
+
* Create token from bytes and signature.
|
|
98
|
+
* @param signedBytes The signed bytes.
|
|
99
|
+
* @param signature The signature.
|
|
100
|
+
* @returns The token.
|
|
101
|
+
*/
|
|
102
|
+
static createTokenFromBytes(signedBytes: Uint8Array, signature: Uint8Array): string;
|
|
85
103
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Class: Jwk
|
|
2
|
+
|
|
3
|
+
Class to handle JSON Web Keys.
|
|
4
|
+
|
|
5
|
+
## Constructors
|
|
6
|
+
|
|
7
|
+
### new Jwk()
|
|
8
|
+
|
|
9
|
+
> **new Jwk**(): [`Jwk`](Jwk.md)
|
|
10
|
+
|
|
11
|
+
#### Returns
|
|
12
|
+
|
|
13
|
+
[`Jwk`](Jwk.md)
|
|
14
|
+
|
|
15
|
+
## Methods
|
|
16
|
+
|
|
17
|
+
### toCryptoKey()
|
|
18
|
+
|
|
19
|
+
> `static` **toCryptoKey**(`jwk`): `Promise`\<[`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)\>
|
|
20
|
+
|
|
21
|
+
Convert the JWK to a crypto key.
|
|
22
|
+
|
|
23
|
+
#### Parameters
|
|
24
|
+
|
|
25
|
+
##### jwk
|
|
26
|
+
|
|
27
|
+
[`IJwk`](../interfaces/IJwk.md)
|
|
28
|
+
|
|
29
|
+
The JWK to convert.
|
|
30
|
+
|
|
31
|
+
#### Returns
|
|
32
|
+
|
|
33
|
+
`Promise`\<[`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)\>
|
|
34
|
+
|
|
35
|
+
The crypto key.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Class: Jwt
|
|
2
2
|
|
|
3
|
-
Class to
|
|
3
|
+
Class to handle JSON Web Tokens.
|
|
4
4
|
|
|
5
5
|
## Constructors
|
|
6
6
|
|
|
@@ -16,33 +16,33 @@ Class to encode and decode JSON Web Tokens.
|
|
|
16
16
|
|
|
17
17
|
### encode()
|
|
18
18
|
|
|
19
|
-
> `static` **encode**\<`
|
|
19
|
+
> `static` **encode**\<`T`, `U`\>(`header`, `payload`, `key`): `Promise`\<`string`\>
|
|
20
20
|
|
|
21
21
|
Encode a token.
|
|
22
22
|
|
|
23
23
|
#### Type Parameters
|
|
24
24
|
|
|
25
|
-
• **
|
|
25
|
+
• **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
|
|
26
26
|
|
|
27
|
-
• **
|
|
27
|
+
• **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
|
|
28
28
|
|
|
29
29
|
#### Parameters
|
|
30
30
|
|
|
31
31
|
##### header
|
|
32
32
|
|
|
33
|
-
`
|
|
33
|
+
`T`
|
|
34
34
|
|
|
35
35
|
The header to encode.
|
|
36
36
|
|
|
37
37
|
##### payload
|
|
38
38
|
|
|
39
|
-
`
|
|
39
|
+
`U`
|
|
40
40
|
|
|
41
41
|
The payload to encode.
|
|
42
42
|
|
|
43
43
|
##### key
|
|
44
44
|
|
|
45
|
-
`
|
|
45
|
+
[`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)
|
|
46
46
|
|
|
47
47
|
The key for signing the token, can be omitted if a signer is provided.
|
|
48
48
|
|
|
@@ -56,33 +56,33 @@ The encoded token.
|
|
|
56
56
|
|
|
57
57
|
### encodeWithSigner()
|
|
58
58
|
|
|
59
|
-
> `static` **encodeWithSigner**\<`
|
|
59
|
+
> `static` **encodeWithSigner**\<`T`, `U`\>(`header`, `payload`, `signer`): `Promise`\<`string`\>
|
|
60
60
|
|
|
61
61
|
Encode a token.
|
|
62
62
|
|
|
63
63
|
#### Type Parameters
|
|
64
64
|
|
|
65
|
-
• **
|
|
65
|
+
• **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
|
|
66
66
|
|
|
67
|
-
• **
|
|
67
|
+
• **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
|
|
68
68
|
|
|
69
69
|
#### Parameters
|
|
70
70
|
|
|
71
71
|
##### header
|
|
72
72
|
|
|
73
|
-
`
|
|
73
|
+
`T`
|
|
74
74
|
|
|
75
75
|
The header to encode.
|
|
76
76
|
|
|
77
77
|
##### payload
|
|
78
78
|
|
|
79
|
-
`
|
|
79
|
+
`U`
|
|
80
80
|
|
|
81
81
|
The payload to encode.
|
|
82
82
|
|
|
83
83
|
##### signer
|
|
84
84
|
|
|
85
|
-
(`
|
|
85
|
+
(`header`, `payload`, `key`) => `Promise`\<`string`\>
|
|
86
86
|
|
|
87
87
|
Custom signer method.
|
|
88
88
|
|
|
@@ -96,15 +96,15 @@ The encoded token.
|
|
|
96
96
|
|
|
97
97
|
### decode()
|
|
98
98
|
|
|
99
|
-
> `static` **decode**\<`
|
|
99
|
+
> `static` **decode**\<`T`, `U`\>(`token`): `Promise`\<\{ `header`: `T`; `payload`: `U`; `signature`: `Uint8Array`; \}\>
|
|
100
100
|
|
|
101
101
|
Decode a token.
|
|
102
102
|
|
|
103
103
|
#### Type Parameters
|
|
104
104
|
|
|
105
|
-
• **
|
|
105
|
+
• **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
|
|
106
106
|
|
|
107
|
-
• **
|
|
107
|
+
• **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
|
|
108
108
|
|
|
109
109
|
#### Parameters
|
|
110
110
|
|
|
@@ -116,7 +116,7 @@ The token to decode.
|
|
|
116
116
|
|
|
117
117
|
#### Returns
|
|
118
118
|
|
|
119
|
-
`Promise`\<\{ `header`: `
|
|
119
|
+
`Promise`\<\{ `header`: `T`; `payload`: `U`; `signature`: `Uint8Array`; \}\>
|
|
120
120
|
|
|
121
121
|
The decoded payload.
|
|
122
122
|
|
|
@@ -124,15 +124,15 @@ The decoded payload.
|
|
|
124
124
|
|
|
125
125
|
### verify()
|
|
126
126
|
|
|
127
|
-
> `static` **verify**\<`
|
|
127
|
+
> `static` **verify**\<`T`, `U`\>(`token`, `key`): `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
|
|
128
128
|
|
|
129
129
|
Verify a token.
|
|
130
130
|
|
|
131
131
|
#### Type Parameters
|
|
132
132
|
|
|
133
|
-
• **
|
|
133
|
+
• **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
|
|
134
134
|
|
|
135
|
-
• **
|
|
135
|
+
• **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
|
|
136
136
|
|
|
137
137
|
#### Parameters
|
|
138
138
|
|
|
@@ -144,13 +144,13 @@ The token to verify.
|
|
|
144
144
|
|
|
145
145
|
##### key
|
|
146
146
|
|
|
147
|
-
`
|
|
147
|
+
[`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)
|
|
148
148
|
|
|
149
149
|
The key for verifying the token
|
|
150
150
|
|
|
151
151
|
#### Returns
|
|
152
152
|
|
|
153
|
-
`Promise`\<\{ `
|
|
153
|
+
`Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
|
|
154
154
|
|
|
155
155
|
The decoded payload.
|
|
156
156
|
|
|
@@ -158,15 +158,15 @@ The decoded payload.
|
|
|
158
158
|
|
|
159
159
|
### verifyWithVerifier()
|
|
160
160
|
|
|
161
|
-
> `static` **verifyWithVerifier**\<`
|
|
161
|
+
> `static` **verifyWithVerifier**\<`T`, `U`\>(`token`, `verifier`): `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
|
|
162
162
|
|
|
163
163
|
Verify a token.
|
|
164
164
|
|
|
165
165
|
#### Type Parameters
|
|
166
166
|
|
|
167
|
-
• **
|
|
167
|
+
• **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
|
|
168
168
|
|
|
169
|
-
• **
|
|
169
|
+
• **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
|
|
170
170
|
|
|
171
171
|
#### Parameters
|
|
172
172
|
|
|
@@ -178,13 +178,13 @@ The token to verify.
|
|
|
178
178
|
|
|
179
179
|
##### verifier
|
|
180
180
|
|
|
181
|
-
(`
|
|
181
|
+
(`token`, `key`) => `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
|
|
182
182
|
|
|
183
183
|
Custom verification method.
|
|
184
184
|
|
|
185
185
|
#### Returns
|
|
186
186
|
|
|
187
|
-
`Promise`\<\{ `
|
|
187
|
+
`Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
|
|
188
188
|
|
|
189
189
|
The decoded payload.
|
|
190
190
|
|
|
@@ -192,51 +192,39 @@ The decoded payload.
|
|
|
192
192
|
|
|
193
193
|
### verifySignature()
|
|
194
194
|
|
|
195
|
-
> `static` **verifySignature**\<`
|
|
195
|
+
> `static` **verifySignature**\<`T`, `U`\>(`token`, `key`?, `verifier`?): `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
|
|
196
196
|
|
|
197
197
|
Verify a token by parts.
|
|
198
198
|
|
|
199
199
|
#### Type Parameters
|
|
200
200
|
|
|
201
|
-
• **
|
|
201
|
+
• **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
|
|
202
202
|
|
|
203
|
-
• **
|
|
203
|
+
• **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
|
|
204
204
|
|
|
205
205
|
#### Parameters
|
|
206
206
|
|
|
207
|
-
#####
|
|
208
|
-
|
|
209
|
-
`U`
|
|
210
|
-
|
|
211
|
-
The header to verify.
|
|
212
|
-
|
|
213
|
-
##### payload?
|
|
214
|
-
|
|
215
|
-
`T`
|
|
216
|
-
|
|
217
|
-
The payload to verify.
|
|
218
|
-
|
|
219
|
-
##### signature?
|
|
207
|
+
##### token
|
|
220
208
|
|
|
221
|
-
`
|
|
209
|
+
`string`
|
|
222
210
|
|
|
223
|
-
The
|
|
211
|
+
The token to verify.
|
|
224
212
|
|
|
225
213
|
##### key?
|
|
226
214
|
|
|
227
|
-
`
|
|
215
|
+
[`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)
|
|
228
216
|
|
|
229
217
|
The key for verifying the token, if not provided no verification occurs.
|
|
230
218
|
|
|
231
219
|
##### verifier?
|
|
232
220
|
|
|
233
|
-
(`
|
|
221
|
+
(`token`, `key`) => `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
|
|
234
222
|
|
|
235
223
|
Custom verification method.
|
|
236
224
|
|
|
237
225
|
#### Returns
|
|
238
226
|
|
|
239
|
-
`Promise
|
|
227
|
+
`Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
|
|
240
228
|
|
|
241
229
|
True if the parts are verified.
|
|
242
230
|
|
|
@@ -244,33 +232,33 @@ True if the parts are verified.
|
|
|
244
232
|
|
|
245
233
|
### defaultSigner()
|
|
246
234
|
|
|
247
|
-
> `static` **defaultSigner**(`
|
|
235
|
+
> `static` **defaultSigner**(`header`, `payload`, `key`): `Promise`\<`string`\>
|
|
248
236
|
|
|
249
237
|
The default signer for the JWT.
|
|
250
238
|
|
|
251
239
|
#### Parameters
|
|
252
240
|
|
|
253
|
-
#####
|
|
241
|
+
##### header
|
|
254
242
|
|
|
255
|
-
[`
|
|
243
|
+
[`IJwtHeader`](../interfaces/IJwtHeader.md)
|
|
256
244
|
|
|
257
|
-
The
|
|
245
|
+
The header to sign.
|
|
258
246
|
|
|
259
|
-
#####
|
|
247
|
+
##### payload
|
|
260
248
|
|
|
261
|
-
|
|
249
|
+
[`IJwtPayload`](../interfaces/IJwtPayload.md)
|
|
262
250
|
|
|
263
|
-
|
|
251
|
+
The payload to sign.
|
|
264
252
|
|
|
265
|
-
#####
|
|
253
|
+
##### key
|
|
266
254
|
|
|
267
|
-
|
|
255
|
+
The optional key to sign with.
|
|
268
256
|
|
|
269
|
-
|
|
257
|
+
`undefined` | [`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)
|
|
270
258
|
|
|
271
259
|
#### Returns
|
|
272
260
|
|
|
273
|
-
`Promise`\<`
|
|
261
|
+
`Promise`\<`string`\>
|
|
274
262
|
|
|
275
263
|
The signature.
|
|
276
264
|
|
|
@@ -278,38 +266,94 @@ The signature.
|
|
|
278
266
|
|
|
279
267
|
### defaultVerifier()
|
|
280
268
|
|
|
281
|
-
> `static` **defaultVerifier
|
|
269
|
+
> `static` **defaultVerifier**\<`T`, `U`\>(`token`, `key`): `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
|
|
282
270
|
|
|
283
271
|
The default verifier for the JWT.
|
|
284
272
|
|
|
273
|
+
#### Type Parameters
|
|
274
|
+
|
|
275
|
+
• **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
|
|
276
|
+
|
|
277
|
+
• **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
|
|
278
|
+
|
|
285
279
|
#### Parameters
|
|
286
280
|
|
|
287
|
-
#####
|
|
281
|
+
##### token
|
|
288
282
|
|
|
289
|
-
|
|
283
|
+
`string`
|
|
290
284
|
|
|
291
|
-
The
|
|
285
|
+
The token to verify.
|
|
292
286
|
|
|
293
287
|
##### key
|
|
294
288
|
|
|
295
289
|
The key to verify with.
|
|
296
290
|
|
|
297
|
-
`undefined` | `
|
|
291
|
+
`undefined` | [`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)
|
|
292
|
+
|
|
293
|
+
#### Returns
|
|
294
|
+
|
|
295
|
+
`Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
|
|
296
|
+
|
|
297
|
+
True if the signature was verified.
|
|
298
|
+
|
|
299
|
+
***
|
|
300
|
+
|
|
301
|
+
### createSignBytes()
|
|
302
|
+
|
|
303
|
+
> `static` **createSignBytes**\<`T`, `U`\>(`header`, `payload`): `Uint8Array`
|
|
304
|
+
|
|
305
|
+
Create bytes for signing from header and payload.
|
|
306
|
+
|
|
307
|
+
#### Type Parameters
|
|
308
|
+
|
|
309
|
+
• **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
|
|
310
|
+
|
|
311
|
+
• **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
|
|
312
|
+
|
|
313
|
+
#### Parameters
|
|
314
|
+
|
|
315
|
+
##### header
|
|
316
|
+
|
|
317
|
+
`T`
|
|
318
|
+
|
|
319
|
+
The header.
|
|
298
320
|
|
|
299
321
|
##### payload
|
|
300
322
|
|
|
323
|
+
`U`
|
|
324
|
+
|
|
325
|
+
The payload.
|
|
326
|
+
|
|
327
|
+
#### Returns
|
|
328
|
+
|
|
301
329
|
`Uint8Array`
|
|
302
330
|
|
|
303
|
-
The
|
|
331
|
+
The bytes to sign.
|
|
332
|
+
|
|
333
|
+
***
|
|
334
|
+
|
|
335
|
+
### createTokenFromBytes()
|
|
336
|
+
|
|
337
|
+
> `static` **createTokenFromBytes**(`signedBytes`, `signature`): `string`
|
|
338
|
+
|
|
339
|
+
Create token from bytes and signature.
|
|
340
|
+
|
|
341
|
+
#### Parameters
|
|
342
|
+
|
|
343
|
+
##### signedBytes
|
|
344
|
+
|
|
345
|
+
`Uint8Array`
|
|
346
|
+
|
|
347
|
+
The signed bytes.
|
|
304
348
|
|
|
305
349
|
##### signature
|
|
306
350
|
|
|
307
351
|
`Uint8Array`
|
|
308
352
|
|
|
309
|
-
The signature
|
|
353
|
+
The signature.
|
|
310
354
|
|
|
311
355
|
#### Returns
|
|
312
356
|
|
|
313
|
-
`
|
|
357
|
+
`string`
|
|
314
358
|
|
|
315
|
-
|
|
359
|
+
The token.
|
package/docs/reference/index.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
- [FetchError](classes/FetchError.md)
|
|
6
6
|
- [FetchHelper](classes/FetchHelper.md)
|
|
7
|
+
- [Jwk](classes/Jwk.md)
|
|
7
8
|
- [Jwt](classes/Jwt.md)
|
|
8
9
|
- [MimeTypeHelper](classes/MimeTypeHelper.md)
|
|
9
10
|
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
- [HeaderTypes](type-aliases/HeaderTypes.md)
|
|
21
22
|
- [HttpMethod](type-aliases/HttpMethod.md)
|
|
22
23
|
- [HttpStatusCode](type-aliases/HttpStatusCode.md)
|
|
23
|
-
- [
|
|
24
|
+
- [JwkCryptoKey](type-aliases/JwkCryptoKey.md)
|
|
24
25
|
- [MimeTypes](type-aliases/MimeTypes.md)
|
|
25
26
|
|
|
26
27
|
## Variables
|
|
@@ -28,5 +29,4 @@
|
|
|
28
29
|
- [HeaderTypes](variables/HeaderTypes.md)
|
|
29
30
|
- [HttpMethod](variables/HttpMethod.md)
|
|
30
31
|
- [HttpStatusCode](variables/HttpStatusCode.md)
|
|
31
|
-
- [JwtAlgorithms](variables/JwtAlgorithms.md)
|
|
32
32
|
- [MimeTypes](variables/MimeTypes.md)
|