@twin.org/web 0.0.1-next.5 → 0.0.1-next.51

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 (33) hide show
  1. package/dist/cjs/index.cjs +271 -96
  2. package/dist/esm/index.mjs +272 -98
  3. package/dist/types/index.d.ts +3 -1
  4. package/dist/types/models/IJwk.d.ts +2 -58
  5. package/dist/types/models/IJwtHeader.d.ts +2 -18
  6. package/dist/types/models/IJwtPayload.d.ts +2 -33
  7. package/dist/types/models/headerTypes.d.ts +8 -8
  8. package/dist/types/models/jwkCryptoKey.d.ts +4 -0
  9. package/dist/types/models/mimeTypes.d.ts +4 -0
  10. package/dist/types/utils/fetchHelper.d.ts +7 -0
  11. package/dist/types/utils/jwk.d.ts +34 -0
  12. package/dist/types/utils/jws.d.ts +22 -0
  13. package/dist/types/utils/jwt.d.ts +67 -29
  14. package/docs/changelog.md +31 -1
  15. package/docs/reference/classes/FetchError.md +13 -5
  16. package/docs/reference/classes/FetchHelper.md +85 -19
  17. package/docs/reference/classes/Jwk.md +101 -0
  18. package/docs/reference/classes/Jws.md +81 -0
  19. package/docs/reference/classes/Jwt.md +222 -102
  20. package/docs/reference/classes/MimeTypeHelper.md +6 -2
  21. package/docs/reference/index.md +3 -2
  22. package/docs/reference/interfaces/IHttpHeaders.md +1 -1
  23. package/docs/reference/interfaces/IJwk.md +2 -106
  24. package/docs/reference/interfaces/IJwtHeader.md +4 -24
  25. package/docs/reference/interfaces/IJwtPayload.md +4 -56
  26. package/docs/reference/type-aliases/JwkCryptoKey.md +5 -0
  27. package/docs/reference/variables/HeaderTypes.md +8 -8
  28. package/docs/reference/variables/MimeTypes.md +6 -0
  29. package/locales/en.json +11 -1
  30. package/package.json +7 -6
  31. package/dist/types/models/jwtAlgorithms.d.ts +0 -17
  32. package/docs/reference/type-aliases/JwtAlgorithms.md +0 -5
  33. package/docs/reference/variables/JwtAlgorithms.md +0 -19
@@ -0,0 +1,81 @@
1
+ # Class: Jws
2
+
3
+ Class to handle JSON Web Signatures.
4
+
5
+ ## Constructors
6
+
7
+ ### new Jws()
8
+
9
+ > **new Jws**(): [`Jws`](Jws.md)
10
+
11
+ #### Returns
12
+
13
+ [`Jws`](Jws.md)
14
+
15
+ ## Methods
16
+
17
+ ### create()
18
+
19
+ > `static` **create**(`privateKey`, `hash`, `algOverride`?): `Promise`\<`string`\>
20
+
21
+ Create a signature.
22
+
23
+ #### Parameters
24
+
25
+ ##### privateKey
26
+
27
+ [`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)
28
+
29
+ The private key to use.
30
+
31
+ ##### hash
32
+
33
+ `Uint8Array`
34
+
35
+ The hash to sign.
36
+
37
+ ##### algOverride?
38
+
39
+ `string`
40
+
41
+ An optional algorithm override.
42
+
43
+ #### Returns
44
+
45
+ `Promise`\<`string`\>
46
+
47
+ The signature.
48
+
49
+ ***
50
+
51
+ ### verify()
52
+
53
+ > `static` **verify**(`jws`, `publicKey`, `hash`): `Promise`\<`boolean`\>
54
+
55
+ Verify a signature.
56
+
57
+ #### Parameters
58
+
59
+ ##### jws
60
+
61
+ `string`
62
+
63
+ The signature to verify.
64
+
65
+ ##### publicKey
66
+
67
+ [`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)
68
+
69
+ The public key to verify the signature with.
70
+
71
+ ##### hash
72
+
73
+ `Uint8Array`
74
+
75
+ The hash to verify.
76
+
77
+ #### Returns
78
+
79
+ `Promise`\<`boolean`\>
80
+
81
+ True if the signature was verified.
@@ -1,6 +1,6 @@
1
1
  # Class: Jwt
2
2
 
3
- Class to encode and decode JSON Web Tokens.
3
+ Class to handle JSON Web Tokens.
4
4
 
5
5
  ## Constructors
6
6
 
@@ -16,27 +16,33 @@ Class to encode and decode JSON Web Tokens.
16
16
 
17
17
  ### encode()
18
18
 
19
- > `static` **encode**\<`U`, `T`\>(`header`, `payload`, `key`): `Promise`\<`string`\>
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
- • **U** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
25
+ • **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
26
26
 
27
- • **T** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
27
+ • **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
28
28
 
29
29
  #### Parameters
30
30
 
31
- **header**: `U`
31
+ ##### header
32
+
33
+ `T`
32
34
 
33
35
  The header to encode.
34
36
 
35
- **payload**: `T`
37
+ ##### payload
38
+
39
+ `U`
36
40
 
37
41
  The payload to encode.
38
42
 
39
- **key**: `Uint8Array`
43
+ ##### key
44
+
45
+ [`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)
40
46
 
41
47
  The key for signing the token, can be omitted if a signer is provided.
42
48
 
@@ -50,27 +56,33 @@ The encoded token.
50
56
 
51
57
  ### encodeWithSigner()
52
58
 
53
- > `static` **encodeWithSigner**\<`U`, `T`\>(`header`, `payload`, `signer`): `Promise`\<`string`\>
59
+ > `static` **encodeWithSigner**\<`T`, `U`\>(`header`, `payload`, `signer`): `Promise`\<`string`\>
54
60
 
55
61
  Encode a token.
56
62
 
57
63
  #### Type Parameters
58
64
 
59
- • **U** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
65
+ • **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
60
66
 
61
- • **T** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
67
+ • **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
62
68
 
63
69
  #### Parameters
64
70
 
65
- **header**: `U`
71
+ ##### header
72
+
73
+ `T`
66
74
 
67
75
  The header to encode.
68
76
 
69
- **payload**: `T`
77
+ ##### payload
78
+
79
+ `U`
70
80
 
71
81
  The payload to encode.
72
82
 
73
- **signer**
83
+ ##### signer
84
+
85
+ (`header`, `payload`, `key`) => `Promise`\<`string`\>
74
86
 
75
87
  Custom signer method.
76
88
 
@@ -84,230 +96,338 @@ The encoded token.
84
96
 
85
97
  ### decode()
86
98
 
87
- > `static` **decode**\<`U`, `T`\>(`token`): `Promise`\<`object`\>
99
+ > `static` **decode**\<`T`, `U`\>(`token`): `Promise`\<\{ `header`: `T`; `payload`: `U`; `signature`: `Uint8Array`\<`ArrayBufferLike`\>; \}\>
88
100
 
89
101
  Decode a token.
90
102
 
91
103
  #### Type Parameters
92
104
 
93
- • **U** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
105
+ • **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
94
106
 
95
- • **T** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
107
+ • **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
96
108
 
97
109
  #### Parameters
98
110
 
99
- **token**: `string`
111
+ ##### token
112
+
113
+ `string`
100
114
 
101
115
  The token to decode.
102
116
 
103
117
  #### Returns
104
118
 
105
- `Promise`\<`object`\>
119
+ `Promise`\<\{ `header`: `T`; `payload`: `U`; `signature`: `Uint8Array`\<`ArrayBufferLike`\>; \}\>
106
120
 
107
121
  The decoded payload.
108
122
 
109
- ##### header?
123
+ ***
124
+
125
+ ### verify()
126
+
127
+ > `static` **verify**\<`T`, `U`\>(`token`, `key`): `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
128
+
129
+ Verify a token.
130
+
131
+ #### Type Parameters
110
132
 
111
- > `optional` **header**: `U`
133
+ **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
112
134
 
113
- ##### payload?
135
+ **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
114
136
 
115
- > `optional` **payload**: `T`
137
+ #### Parameters
116
138
 
117
- ##### signature?
139
+ ##### token
118
140
 
119
- > `optional` **signature**: `Uint8Array`
141
+ `string`
142
+
143
+ The token to verify.
144
+
145
+ ##### key
146
+
147
+ [`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)
148
+
149
+ The key for verifying the token
150
+
151
+ #### Returns
152
+
153
+ `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
154
+
155
+ The decoded payload.
120
156
 
121
157
  ***
122
158
 
123
- ### verify()
159
+ ### verifyWithVerifier()
124
160
 
125
- > `static` **verify**\<`U`, `T`\>(`token`, `key`): `Promise`\<`object`\>
161
+ > `static` **verifyWithVerifier**\<`T`, `U`\>(`token`, `verifier`): `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
126
162
 
127
163
  Verify a token.
128
164
 
129
165
  #### Type Parameters
130
166
 
131
- • **U** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
167
+ • **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
132
168
 
133
- • **T** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
169
+ • **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
134
170
 
135
171
  #### Parameters
136
172
 
137
- **token**: `string`
173
+ ##### token
174
+
175
+ `string`
138
176
 
139
177
  The token to verify.
140
178
 
141
- **key**: `Uint8Array`
179
+ ##### verifier
142
180
 
143
- The key for verifying the token
181
+ (`token`, `key`) => `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
182
+
183
+ Custom verification method.
144
184
 
145
185
  #### Returns
146
186
 
147
- `Promise`\<`object`\>
187
+ `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
148
188
 
149
189
  The decoded payload.
150
190
 
151
- ##### verified
191
+ ***
192
+
193
+ ### verifySignature()
194
+
195
+ > `static` **verifySignature**\<`T`, `U`\>(`token`, `key`?, `verifier`?): `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
196
+
197
+ Verify a token by parts.
198
+
199
+ #### Type Parameters
200
+
201
+ • **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
202
+
203
+ • **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
204
+
205
+ #### Parameters
206
+
207
+ ##### token
152
208
 
153
- > **verified**: `boolean`
209
+ `string`
154
210
 
155
- ##### header?
211
+ The token to verify.
212
+
213
+ ##### key?
214
+
215
+ [`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)
216
+
217
+ The key for verifying the token, if not provided no verification occurs.
156
218
 
157
- > `optional` **header**: `U`
219
+ ##### verifier?
158
220
 
159
- ##### payload?
221
+ (`token`, `key`) => `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
160
222
 
161
- > `optional` **payload**: `T`
223
+ Custom verification method.
162
224
 
163
- ##### signature?
225
+ #### Returns
164
226
 
165
- > `optional` **signature**: `Uint8Array`
227
+ `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
228
+
229
+ True if the parts are verified.
166
230
 
167
231
  ***
168
232
 
169
- ### verifyWithVerifier()
233
+ ### defaultSigner()
170
234
 
171
- > `static` **verifyWithVerifier**\<`U`, `T`\>(`token`, `verifier`): `Promise`\<`object`\>
235
+ > `static` **defaultSigner**(`header`, `payload`, `key`): `Promise`\<`string`\>
172
236
 
173
- Verify a token.
237
+ The default signer for the JWT.
238
+
239
+ #### Parameters
240
+
241
+ ##### header
242
+
243
+ [`IJwtHeader`](../interfaces/IJwtHeader.md)
244
+
245
+ The header to sign.
246
+
247
+ ##### payload
248
+
249
+ [`IJwtPayload`](../interfaces/IJwtPayload.md)
250
+
251
+ The payload to sign.
252
+
253
+ ##### key
254
+
255
+ The optional key to sign with.
256
+
257
+ `undefined` | [`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)
258
+
259
+ #### Returns
260
+
261
+ `Promise`\<`string`\>
262
+
263
+ The signature.
264
+
265
+ ***
266
+
267
+ ### defaultVerifier()
268
+
269
+ > `static` **defaultVerifier**\<`T`, `U`\>(`token`, `key`): `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
270
+
271
+ The default verifier for the JWT.
174
272
 
175
273
  #### Type Parameters
176
274
 
177
- • **U** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
275
+ • **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
178
276
 
179
- • **T** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
277
+ • **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
180
278
 
181
279
  #### Parameters
182
280
 
183
- **token**: `string`
281
+ ##### token
282
+
283
+ `string`
184
284
 
185
285
  The token to verify.
186
286
 
187
- **verifier**
287
+ ##### key
188
288
 
189
- Custom verification method.
289
+ The key to verify with.
290
+
291
+ `undefined` | [`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)
190
292
 
191
293
  #### Returns
192
294
 
193
- `Promise`\<`object`\>
295
+ `Promise`\<\{ `header`: `T`; `payload`: `U`; \}\>
194
296
 
195
- The decoded payload.
297
+ The header and payload if verification successful.
298
+
299
+ ***
196
300
 
197
- ##### verified
301
+ ### toSigningBytes()
198
302
 
199
- > **verified**: `boolean`
303
+ > `static` **toSigningBytes**\<`T`, `U`\>(`header`, `payload`): `Uint8Array`
200
304
 
201
- ##### header?
305
+ Create bytes for signing from header and payload.
202
306
 
203
- > `optional` **header**: `U`
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
204
316
 
205
- ##### payload?
317
+ `T`
206
318
 
207
- > `optional` **payload**: `T`
319
+ The header.
208
320
 
209
- ##### signature?
321
+ ##### payload
210
322
 
211
- > `optional` **signature**: `Uint8Array`
323
+ `U`
324
+
325
+ The payload.
326
+
327
+ #### Returns
328
+
329
+ `Uint8Array`
330
+
331
+ The bytes to sign.
212
332
 
213
333
  ***
214
334
 
215
- ### verifySignature()
335
+ ### fromSigningBytes()
216
336
 
217
- > `static` **verifySignature**\<`U`, `T`\>(`header`?, `payload`?, `signature`?, `key`?, `verifier`?): `Promise`\<`boolean`\>
337
+ > `static` **fromSigningBytes**\<`T`, `U`\>(`signingBytes`): `object`
218
338
 
219
- Verify a token by parts.
339
+ Create header and payload from signing bytes.
220
340
 
221
341
  #### Type Parameters
222
342
 
223
- • **U** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
343
+ • **T** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
224
344
 
225
- • **T** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
345
+ • **U** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
226
346
 
227
347
  #### Parameters
228
348
 
229
- **header?**: `U`
230
-
231
- The header to verify.
349
+ ##### signingBytes
232
350
 
233
- • **payload?**: `T`
351
+ `Uint8Array`
234
352
 
235
- The payload to verify.
353
+ The signing bytes from a token.
236
354
 
237
- **signature?**: `Uint8Array`
355
+ #### Returns
238
356
 
239
- The signature to verify.
357
+ `object`
240
358
 
241
- **key?**: `Uint8Array`
359
+ The header and payload.
242
360
 
243
- The key for verifying the token, if not provided no verification occurs.
361
+ ##### header
244
362
 
245
- **verifier?**
363
+ > **header**: `T`
246
364
 
247
- Custom verification method.
365
+ ##### payload
248
366
 
249
- #### Returns
367
+ > **payload**: `U`
250
368
 
251
- `Promise`\<`boolean`\>
369
+ #### Throws
252
370
 
253
- True if the parts are verified.
371
+ If the signing bytes are invalid
254
372
 
255
373
  ***
256
374
 
257
- ### defaultSigner()
375
+ ### tokenFromBytes()
258
376
 
259
- > `static` **defaultSigner**(`alg`, `key`, `payload`): `Promise`\<`Uint8Array`\>
377
+ > `static` **tokenFromBytes**(`signingBytes`, `signature`): `string`
260
378
 
261
- The default signer for the JWT.
379
+ Convert signed bytes and signature bytes to token.
262
380
 
263
381
  #### Parameters
264
382
 
265
- **alg**: [`JwtAlgorithms`](../type-aliases/JwtAlgorithms.md)
383
+ ##### signingBytes
266
384
 
267
- The algorithm to use.
385
+ `Uint8Array`
268
386
 
269
- **key**: `undefined` \| `Uint8Array`
387
+ The signed bytes.
270
388
 
271
- The key to sign with.
389
+ ##### signature
272
390
 
273
- • **payload**: `Uint8Array`
391
+ `Uint8Array`
274
392
 
275
- The payload to sign.
393
+ The signature.
276
394
 
277
395
  #### Returns
278
396
 
279
- `Promise`\<`Uint8Array`\>
397
+ `string`
280
398
 
281
- The signature.
399
+ The token.
282
400
 
283
401
  ***
284
402
 
285
- ### defaultVerifier()
403
+ ### tokenToBytes()
286
404
 
287
- > `static` **defaultVerifier**(`alg`, `key`, `payload`, `signature`): `Promise`\<`boolean`\>
405
+ > `static` **tokenToBytes**(`token`): `object`
288
406
 
289
- The default verifier for the JWT.
407
+ Convert the token to signing bytes and signature bytes.
290
408
 
291
409
  #### Parameters
292
410
 
293
- **alg**: [`JwtAlgorithms`](../type-aliases/JwtAlgorithms.md)
411
+ ##### token
294
412
 
295
- The algorithm to use.
413
+ `string`
296
414
 
297
- **key**: `undefined` \| `Uint8Array`
415
+ The token to convert to bytes.
298
416
 
299
- The key to verify with.
417
+ #### Returns
300
418
 
301
- • **payload**: `Uint8Array`
419
+ `object`
302
420
 
303
- The payload to verify.
421
+ The decoded bytes.
304
422
 
305
- **signature**: `Uint8Array`
423
+ ##### signingBytes
306
424
 
307
- The signature to verify.
425
+ > **signingBytes**: `Uint8Array`
308
426
 
309
- #### Returns
427
+ ##### signature
428
+
429
+ > **signature**: `Uint8Array`
310
430
 
311
- `Promise`\<`boolean`\>
431
+ #### Throws
312
432
 
313
- True if the signature was verified.
433
+ If the token is invalid.
@@ -22,7 +22,9 @@ Detect the mime type from a byte array.
22
22
 
23
23
  #### Parameters
24
24
 
25
- **data**: `Uint8Array`
25
+ ##### data
26
+
27
+ `Uint8Array`
26
28
 
27
29
  The data to test.
28
30
 
@@ -42,10 +44,12 @@ Return the default extension for a mime type.
42
44
 
43
45
  #### Parameters
44
46
 
45
- **mimeType**: `undefined` \| `string`
47
+ ##### mimeType
46
48
 
47
49
  The mimetype to get the extension for.
48
50
 
51
+ `undefined` | `string`
52
+
49
53
  #### Returns
50
54
 
51
55
  `undefined` \| `string`
@@ -4,6 +4,8 @@
4
4
 
5
5
  - [FetchError](classes/FetchError.md)
6
6
  - [FetchHelper](classes/FetchHelper.md)
7
+ - [Jwk](classes/Jwk.md)
8
+ - [Jws](classes/Jws.md)
7
9
  - [Jwt](classes/Jwt.md)
8
10
  - [MimeTypeHelper](classes/MimeTypeHelper.md)
9
11
 
@@ -20,7 +22,7 @@
20
22
  - [HeaderTypes](type-aliases/HeaderTypes.md)
21
23
  - [HttpMethod](type-aliases/HttpMethod.md)
22
24
  - [HttpStatusCode](type-aliases/HttpStatusCode.md)
23
- - [JwtAlgorithms](type-aliases/JwtAlgorithms.md)
25
+ - [JwkCryptoKey](type-aliases/JwkCryptoKey.md)
24
26
  - [MimeTypes](type-aliases/MimeTypes.md)
25
27
 
26
28
  ## Variables
@@ -28,5 +30,4 @@
28
30
  - [HeaderTypes](variables/HeaderTypes.md)
29
31
  - [HttpMethod](variables/HttpMethod.md)
30
32
  - [HttpStatusCode](variables/HttpStatusCode.md)
31
- - [JwtAlgorithms](variables/JwtAlgorithms.md)
32
33
  - [MimeTypes](variables/MimeTypes.md)
@@ -4,4 +4,4 @@ Model used for Http headers parameter.
4
4
 
5
5
  ## Indexable
6
6
 
7
- \[`key`: `string`\]: `string` \| `string`[]
7
+ \[`key`: `string`\]: `string` \| `string`[]