jose 4.5.2 → 4.6.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/browser/jwe/general/encrypt.js +8 -1
- package/dist/browser/jwks/local.js +2 -1
- package/dist/browser/lib/buffer_utils.js +5 -11
- package/dist/browser/lib/crypto_key.js +1 -1
- package/dist/browser/lib/decrypt_key_management.js +1 -1
- package/dist/browser/lib/encrypt_key_management.js +1 -1
- package/dist/browser/runtime/base64url.js +6 -3
- package/dist/browser/runtime/ecdhes.js +2 -5
- package/dist/browser/runtime/fetch_jwks.js +0 -9
- package/dist/browser/runtime/pbes2kw.js +1 -1
- package/dist/node/cjs/jwe/general/encrypt.js +8 -1
- package/dist/node/cjs/jwks/local.js +2 -1
- package/dist/node/cjs/lib/buffer_utils.js +5 -11
- package/dist/node/cjs/lib/crypto_key.js +1 -1
- package/dist/node/cjs/lib/decrypt_key_management.js +1 -1
- package/dist/node/cjs/lib/encrypt_key_management.js +1 -1
- package/dist/node/cjs/runtime/ecdhes.js +2 -2
- package/dist/node/cjs/runtime/generate.js +3 -2
- package/dist/node/cjs/runtime/pbes2kw.js +1 -1
- package/dist/node/esm/jwe/general/encrypt.js +8 -1
- package/dist/node/esm/jwks/local.js +2 -1
- package/dist/node/esm/lib/buffer_utils.js +5 -11
- package/dist/node/esm/lib/crypto_key.js +1 -1
- package/dist/node/esm/lib/decrypt_key_management.js +1 -1
- package/dist/node/esm/lib/encrypt_key_management.js +1 -1
- package/dist/node/esm/runtime/ecdhes.js +2 -2
- package/dist/node/esm/runtime/generate.js +3 -2
- package/dist/node/esm/runtime/pbes2kw.js +1 -1
- package/dist/types/jwe/compact/decrypt.d.ts +26 -0
- package/dist/types/jwe/compact/encrypt.d.ts +56 -0
- package/dist/types/jwe/flattened/decrypt.d.ts +39 -0
- package/dist/types/jwe/flattened/encrypt.d.ts +77 -0
- package/dist/types/jwe/general/decrypt.d.ts +43 -0
- package/dist/types/jwe/general/encrypt.d.ts +63 -0
- package/dist/types/jwk/embedded.d.ts +20 -0
- package/dist/types/jwk/thumbprint.d.ts +19 -0
- package/dist/types/jwks/local.d.ts +42 -0
- package/dist/types/jwks/remote.d.ts +44 -0
- package/dist/types/jws/compact/sign.d.ts +30 -0
- package/dist/types/jws/compact/verify.d.ts +29 -0
- package/dist/types/jws/flattened/sign.d.ts +35 -0
- package/dist/types/jws/flattened/verify.d.ts +34 -0
- package/dist/types/jws/general/sign.d.ts +50 -0
- package/dist/types/jws/general/verify.d.ts +37 -0
- package/dist/types/jwt/decrypt.d.ts +32 -0
- package/dist/types/jwt/encrypt.d.ts +68 -0
- package/dist/types/jwt/produce.d.ts +46 -0
- package/dist/types/jwt/sign.d.ts +28 -0
- package/dist/types/jwt/unsecured.d.ts +34 -0
- package/dist/types/jwt/verify.d.ts +35 -0
- package/dist/types/key/export.d.ts +38 -0
- package/dist/types/key/generate_key_pair.d.ts +38 -0
- package/dist/types/key/generate_secret.d.ts +20 -0
- package/dist/types/key/import.d.ts +96 -0
- package/dist/types/types.d.ts +499 -2
- package/dist/types/util/base64url.d.ts +10 -0
- package/dist/types/util/decode_jwt.d.ts +14 -0
- package/dist/types/util/decode_protected_header.d.ts +11 -0
- package/dist/types/util/errors.d.ts +65 -0
- package/package.json +1 -1
package/dist/types/types.d.ts
CHANGED
|
@@ -87,17 +87,37 @@
|
|
|
87
87
|
* ```
|
|
88
88
|
*/
|
|
89
89
|
export type KeyLike = { type: string }
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* JSON Web Key ([JWK](https://www.rfc-editor.org/rfc/rfc7517)).
|
|
93
|
+
* "RSA", "EC", "OKP", and "oct" key types are supported.
|
|
94
|
+
*/
|
|
90
95
|
export interface JWK {
|
|
96
|
+
/**
|
|
97
|
+
* JWK "alg" (Algorithm) Parameter.
|
|
98
|
+
*/
|
|
91
99
|
alg?: string
|
|
92
100
|
crv?: string
|
|
93
101
|
d?: string
|
|
94
102
|
dp?: string
|
|
95
103
|
dq?: string
|
|
96
104
|
e?: string
|
|
105
|
+
/**
|
|
106
|
+
* JWK "ext" (Extractable) Parameter.
|
|
107
|
+
*/
|
|
97
108
|
ext?: boolean
|
|
98
109
|
k?: string
|
|
110
|
+
/**
|
|
111
|
+
* JWK "key_ops" (Key Operations) Parameter.
|
|
112
|
+
*/
|
|
99
113
|
key_ops?: string[]
|
|
114
|
+
/**
|
|
115
|
+
* JWK "kid" (Key ID) Parameter.
|
|
116
|
+
*/
|
|
100
117
|
kid?: string
|
|
118
|
+
/**
|
|
119
|
+
* JWK "kty" (Key Type) Parameter.
|
|
120
|
+
*/
|
|
101
121
|
kty?: string
|
|
102
122
|
n?: string
|
|
103
123
|
oth?: Array<{
|
|
@@ -108,166 +128,643 @@ export interface JWK {
|
|
|
108
128
|
p?: string
|
|
109
129
|
q?: string
|
|
110
130
|
qi?: string
|
|
131
|
+
/**
|
|
132
|
+
* JWK "use" (Public Key Use) Parameter.
|
|
133
|
+
*/
|
|
111
134
|
use?: string
|
|
112
135
|
x?: string
|
|
113
136
|
y?: string
|
|
137
|
+
/**
|
|
138
|
+
* JWK "x5c" (X.509 Certificate Chain) Parameter.
|
|
139
|
+
*/
|
|
114
140
|
x5c?: string[]
|
|
141
|
+
/**
|
|
142
|
+
* JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter.
|
|
143
|
+
*/
|
|
115
144
|
x5t?: string
|
|
145
|
+
/**
|
|
146
|
+
* "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter.
|
|
147
|
+
*/
|
|
116
148
|
'x5t#S256'?: string
|
|
149
|
+
/**
|
|
150
|
+
* JWK "x5u" (X.509 URL) Parameter.
|
|
151
|
+
*/
|
|
117
152
|
x5u?: string
|
|
153
|
+
|
|
118
154
|
[propName: string]: unknown
|
|
119
155
|
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Generic Interface for consuming operations dynamic key resolution.
|
|
159
|
+
* No token components have been verified at the time of this function call.
|
|
160
|
+
*
|
|
161
|
+
* If you cannot match a key suitable for the token, throw an error instead.
|
|
162
|
+
*
|
|
163
|
+
* @param protectedHeader JWE or JWS Protected Header.
|
|
164
|
+
* @param token The consumed JWE or JWS token.
|
|
165
|
+
*/
|
|
120
166
|
export interface GetKeyFunction<T, T2> {
|
|
121
167
|
(protectedHeader: T, token: T2): Promise<KeyLike | Uint8Array> | KeyLike | Uint8Array
|
|
122
168
|
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Flattened JWS definition for verify function inputs, allows payload as
|
|
172
|
+
* Uint8Array for detached signature validation.
|
|
173
|
+
*/
|
|
123
174
|
export interface FlattenedJWSInput {
|
|
175
|
+
/**
|
|
176
|
+
* The "header" member MUST be present and contain the value JWS
|
|
177
|
+
* Unprotected Header when the JWS Unprotected Header value is non-
|
|
178
|
+
* empty; otherwise, it MUST be absent. This value is represented as
|
|
179
|
+
* an unencoded JSON object, rather than as a string. These Header
|
|
180
|
+
* Parameter values are not integrity protected.
|
|
181
|
+
*/
|
|
124
182
|
header?: JWSHeaderParameters
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* The "payload" member MUST be present and contain the value
|
|
186
|
+
* BASE64URL(JWS Payload). When RFC7797 "b64": false is used
|
|
187
|
+
* the value passed may also be a Uint8Array.
|
|
188
|
+
*/
|
|
125
189
|
payload: string | Uint8Array
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The "protected" member MUST be present and contain the value
|
|
193
|
+
* BASE64URL(UTF8(JWS Protected Header)) when the JWS Protected
|
|
194
|
+
* Header value is non-empty; otherwise, it MUST be absent. These
|
|
195
|
+
* Header Parameter values are integrity protected.
|
|
196
|
+
*/
|
|
126
197
|
protected?: string
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* The "signature" member MUST be present and contain the value
|
|
201
|
+
* BASE64URL(JWS Signature).
|
|
202
|
+
*/
|
|
127
203
|
signature: string
|
|
128
204
|
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* General JWS definition for verify function inputs, allows payload as
|
|
208
|
+
* Uint8Array for detached signature validation.
|
|
209
|
+
*/
|
|
129
210
|
export interface GeneralJWSInput {
|
|
211
|
+
/**
|
|
212
|
+
* The "payload" member MUST be present and contain the value
|
|
213
|
+
* BASE64URL(JWS Payload). When RFC7797 "b64": false is used
|
|
214
|
+
* the value passed may also be a Uint8Array.
|
|
215
|
+
*/
|
|
130
216
|
payload: string | Uint8Array
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* The "signatures" member value MUST be an array of JSON objects.
|
|
220
|
+
* Each object represents a signature or MAC over the JWS Payload and
|
|
221
|
+
* the JWS Protected Header.
|
|
222
|
+
*/
|
|
131
223
|
signatures: Omit<FlattenedJWSInput, 'payload'>[]
|
|
132
224
|
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Flattened JWS definition. Payload is returned as an empty
|
|
228
|
+
* string when JWS Unencoded Payload Option
|
|
229
|
+
* [RFC7797](https://www.rfc-editor.org/rfc/rfc7797) is used.
|
|
230
|
+
*/
|
|
133
231
|
export interface FlattenedJWS extends Partial<FlattenedJWSInput> {
|
|
134
232
|
payload: string
|
|
135
233
|
signature: string
|
|
136
234
|
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* General JWS definition. Payload is returned as an empty
|
|
238
|
+
* string when JWS Unencoded Payload Option
|
|
239
|
+
* [RFC7797](https://www.rfc-editor.org/rfc/rfc7797) is used.
|
|
240
|
+
*/
|
|
137
241
|
export interface GeneralJWS {
|
|
138
242
|
payload: string
|
|
139
243
|
signatures: Omit<FlattenedJWSInput, 'payload'>[]
|
|
140
244
|
}
|
|
245
|
+
|
|
141
246
|
export interface JoseHeaderParameters {
|
|
247
|
+
/**
|
|
248
|
+
* "kid" (Key ID) Header Parameter.
|
|
249
|
+
*/
|
|
142
250
|
kid?: string
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* "x5t" (X.509 Certificate SHA-1 Thumbprint) Header Parameter.
|
|
254
|
+
*/
|
|
143
255
|
x5t?: string
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* "x5c" (X.509 Certificate Chain) Header Parameter.
|
|
259
|
+
*/
|
|
144
260
|
x5c?: string[]
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* "x5u" (X.509 URL) Header Parameter.
|
|
264
|
+
*/
|
|
145
265
|
x5u?: string
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* "jku" (JWK Set URL) Header Parameter.
|
|
269
|
+
*/
|
|
146
270
|
jku?: string
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* "jwk" (JSON Web Key) Header Parameter.
|
|
274
|
+
*/
|
|
147
275
|
jwk?: Pick<JWK, 'kty' | 'crv' | 'x' | 'y' | 'e' | 'n'>
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* "typ" (Type) Header Parameter.
|
|
279
|
+
*/
|
|
148
280
|
typ?: string
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* "cty" (Content Type) Header Parameter.
|
|
284
|
+
*/
|
|
149
285
|
cty?: string
|
|
150
286
|
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Recognized JWS Header Parameters, any other Header Members
|
|
290
|
+
* may also be present.
|
|
291
|
+
*/
|
|
151
292
|
export interface JWSHeaderParameters extends JoseHeaderParameters {
|
|
293
|
+
/**
|
|
294
|
+
* JWS "alg" (Algorithm) Header Parameter.
|
|
295
|
+
*/
|
|
152
296
|
alg?: string
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* This JWS Extension Header Parameter modifies the JWS Payload
|
|
300
|
+
* representation and the JWS Signing Input computation as per
|
|
301
|
+
* [RFC7797](https://www.rfc-editor.org/rfc/rfc7797).
|
|
302
|
+
*/
|
|
153
303
|
b64?: boolean
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* JWS "crit" (Critical) Header Parameter.
|
|
307
|
+
*/
|
|
154
308
|
crit?: string[]
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Any other JWS Header member.
|
|
312
|
+
*/
|
|
155
313
|
[propName: string]: unknown
|
|
156
314
|
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Recognized JWE Key Management-related Header Parameters.
|
|
318
|
+
*/
|
|
157
319
|
export interface JWEKeyManagementHeaderParameters {
|
|
158
320
|
apu?: Uint8Array
|
|
159
321
|
apv?: Uint8Array
|
|
160
|
-
|
|
161
|
-
|
|
322
|
+
/**
|
|
323
|
+
* @deprecated You should not use this parameter. It is only really intended
|
|
324
|
+
* for test and vector validation purposes.
|
|
325
|
+
*/
|
|
162
326
|
p2c?: number
|
|
327
|
+
/**
|
|
328
|
+
* @deprecated You should not use this parameter. It is only really intended
|
|
329
|
+
* for test and vector validation purposes.
|
|
330
|
+
*/
|
|
163
331
|
p2s?: Uint8Array
|
|
332
|
+
/**
|
|
333
|
+
* @deprecated You should not use this parameter. It is only really intended
|
|
334
|
+
* for test and vector validation purposes.
|
|
335
|
+
*/
|
|
336
|
+
iv?: Uint8Array
|
|
337
|
+
/**
|
|
338
|
+
* @deprecated You should not use this parameter. It is only really intended
|
|
339
|
+
* for test and vector validation purposes.
|
|
340
|
+
*/
|
|
341
|
+
epk?: KeyLike
|
|
164
342
|
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Flattened JWE definition.
|
|
346
|
+
*/
|
|
165
347
|
export interface FlattenedJWE {
|
|
348
|
+
/**
|
|
349
|
+
* The "aad" member MUST be present and contain the value
|
|
350
|
+
* BASE64URL(JWE AAD)) when the JWE AAD value is non-empty;
|
|
351
|
+
* otherwise, it MUST be absent. A JWE AAD value can be included to
|
|
352
|
+
* supply a base64url-encoded value to be integrity protected but not
|
|
353
|
+
* encrypted.
|
|
354
|
+
*/
|
|
166
355
|
aad?: string
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* The "ciphertext" member MUST be present and contain the value
|
|
359
|
+
* BASE64URL(JWE Ciphertext).
|
|
360
|
+
*/
|
|
167
361
|
ciphertext: string
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* The "encrypted_key" member MUST be present and contain the value
|
|
365
|
+
* BASE64URL(JWE Encrypted Key) when the JWE Encrypted Key value is
|
|
366
|
+
* non-empty; otherwise, it MUST be absent.
|
|
367
|
+
*/
|
|
168
368
|
encrypted_key?: string
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* The "header" member MUST be present and contain the value JWE Per-
|
|
372
|
+
* Recipient Unprotected Header when the JWE Per-Recipient
|
|
373
|
+
* Unprotected Header value is non-empty; otherwise, it MUST be
|
|
374
|
+
* absent. This value is represented as an unencoded JSON object,
|
|
375
|
+
* rather than as a string. These Header Parameter values are not
|
|
376
|
+
* integrity protected.
|
|
377
|
+
*/
|
|
169
378
|
header?: JWEHeaderParameters
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* The "iv" member MUST be present and contain the value
|
|
382
|
+
* BASE64URL(JWE Initialization Vector) when the JWE Initialization
|
|
383
|
+
* Vector value is non-empty; otherwise, it MUST be absent.
|
|
384
|
+
*/
|
|
170
385
|
iv: string
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* The "protected" member MUST be present and contain the value
|
|
389
|
+
* BASE64URL(UTF8(JWE Protected Header)) when the JWE Protected
|
|
390
|
+
* Header value is non-empty; otherwise, it MUST be absent. These
|
|
391
|
+
* Header Parameter values are integrity protected.
|
|
392
|
+
*/
|
|
171
393
|
protected?: string
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* The "tag" member MUST be present and contain the value
|
|
397
|
+
* BASE64URL(JWE Authentication Tag) when the JWE Authentication Tag
|
|
398
|
+
* value is non-empty; otherwise, it MUST be absent.
|
|
399
|
+
*/
|
|
172
400
|
tag: string
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* The "unprotected" member MUST be present and contain the value JWE
|
|
404
|
+
* Shared Unprotected Header when the JWE Shared Unprotected Header
|
|
405
|
+
* value is non-empty; otherwise, it MUST be absent. This value is
|
|
406
|
+
* represented as an unencoded JSON object, rather than as a string.
|
|
407
|
+
* These Header Parameter values are not integrity protected.
|
|
408
|
+
*/
|
|
173
409
|
unprotected?: JWEHeaderParameters
|
|
174
410
|
}
|
|
411
|
+
|
|
175
412
|
export interface GeneralJWE extends Omit<FlattenedJWE, 'encrypted_key' | 'header'> {
|
|
176
413
|
recipients: Pick<FlattenedJWE, 'encrypted_key' | 'header'>[]
|
|
177
414
|
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Recognized JWE Header Parameters, any other Header members
|
|
418
|
+
* may also be present.
|
|
419
|
+
*/
|
|
178
420
|
export interface JWEHeaderParameters extends JoseHeaderParameters {
|
|
421
|
+
/**
|
|
422
|
+
* JWE "alg" (Algorithm) Header Parameter.
|
|
423
|
+
*/
|
|
179
424
|
alg?: string
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* JWE "enc" (Encryption Algorithm) Header Parameter.
|
|
428
|
+
*/
|
|
180
429
|
enc?: string
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* JWE "crit" (Critical) Header Parameter.
|
|
433
|
+
*/
|
|
181
434
|
crit?: string[]
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* JWE "zip" (Compression Algorithm) Header Parameter.
|
|
438
|
+
*/
|
|
182
439
|
zip?: string
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Any other JWE Header member.
|
|
443
|
+
*/
|
|
183
444
|
[propName: string]: unknown
|
|
184
445
|
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Shared Interface with a "crit" property for all sign, verify, encrypt and decrypt
|
|
449
|
+
* operations.
|
|
450
|
+
*/
|
|
185
451
|
export interface CritOption {
|
|
452
|
+
/**
|
|
453
|
+
* An object with keys representing recognized "crit" (Critical) Header Parameter
|
|
454
|
+
* names. The value for those is either `true` or `false`. `true` when the
|
|
455
|
+
* Header Parameter MUST be integrity protected, `false` when it's irrelevant.
|
|
456
|
+
*
|
|
457
|
+
* This makes the "Extension Header Parameter "${parameter}" is not recognized"
|
|
458
|
+
* error go away.
|
|
459
|
+
*
|
|
460
|
+
* Use this when a given JWS/JWT/JWE profile requires the use of proprietary
|
|
461
|
+
* non-registered "crit" (Critical) Header Parameters. This will only make sure
|
|
462
|
+
* the Header Parameter is syntactically correct when provided and that it is
|
|
463
|
+
* optionally integrity protected. It will not process the Header Parameter in
|
|
464
|
+
* any way or reject the operation if it is missing. You MUST still
|
|
465
|
+
* verify the Header Parameter was present and process it according to the
|
|
466
|
+
* profile's validation steps after the operation succeeds.
|
|
467
|
+
*
|
|
468
|
+
* The JWS extension Header Parameter `b64` is always recognized and processed
|
|
469
|
+
* properly. No other registered Header Parameters that need this kind of
|
|
470
|
+
* default built-in treatment are currently available.
|
|
471
|
+
*/
|
|
186
472
|
crit?: {
|
|
187
473
|
[propName: string]: boolean
|
|
188
474
|
}
|
|
189
475
|
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* JWE Decryption options.
|
|
479
|
+
*/
|
|
190
480
|
export interface DecryptOptions extends CritOption {
|
|
481
|
+
/**
|
|
482
|
+
* A list of accepted JWE "alg" (Algorithm) Header Parameter values.
|
|
483
|
+
*/
|
|
191
484
|
keyManagementAlgorithms?: string[]
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* A list of accepted JWE "enc" (Encryption Algorithm) Header Parameter values.
|
|
488
|
+
* By default all "enc" (Encryption Algorithm) values applicable for the used
|
|
489
|
+
* key/secret are allowed.
|
|
490
|
+
*/
|
|
192
491
|
contentEncryptionAlgorithms?: string[]
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* In a browser runtime you have to provide an implementation for Inflate Raw
|
|
495
|
+
* when you expect JWEs with compressed plaintext.
|
|
496
|
+
*/
|
|
193
497
|
inflateRaw?: InflateFunction
|
|
194
498
|
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* JWE Deflate option.
|
|
502
|
+
*/
|
|
195
503
|
export interface DeflateOption {
|
|
504
|
+
/**
|
|
505
|
+
* In a browser runtime you have to provide an implementation for Deflate Raw
|
|
506
|
+
* when you will be producing JWEs with compressed plaintext.
|
|
507
|
+
*/
|
|
196
508
|
deflateRaw?: DeflateFunction
|
|
197
509
|
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* JWE Encryption options.
|
|
513
|
+
*/
|
|
198
514
|
export interface EncryptOptions extends CritOption, DeflateOption {}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* JWT Claims Set verification options.
|
|
518
|
+
*/
|
|
199
519
|
export interface JWTClaimVerificationOptions {
|
|
520
|
+
/**
|
|
521
|
+
* Expected JWT "aud" (Audience) Claim value(s).
|
|
522
|
+
*/
|
|
200
523
|
audience?: string | string[]
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Expected clock tolerance
|
|
527
|
+
* - in seconds when number (e.g. 5)
|
|
528
|
+
* - parsed as seconds when a string (e.g. "5 seconds", "10 minutes", "2 hours").
|
|
529
|
+
*/
|
|
201
530
|
clockTolerance?: string | number
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Expected JWT "iss" (Issuer) Claim value(s).
|
|
534
|
+
*/
|
|
202
535
|
issuer?: string | string[]
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Maximum time elapsed (in seconds) from the JWT "iat" (Issued At) Claim value.
|
|
539
|
+
* - in seconds when number (e.g. 5)
|
|
540
|
+
* - parsed as seconds when a string (e.g. "5 seconds", "10 minutes", "2 hours").
|
|
541
|
+
*/
|
|
203
542
|
maxTokenAge?: string | number
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Expected JWT "sub" (Subject) Claim value.
|
|
546
|
+
*/
|
|
204
547
|
subject?: string
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Expected JWT "typ" (Type) Header Parameter value.
|
|
551
|
+
*/
|
|
205
552
|
typ?: string
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Date to use when comparing NumericDate claims, defaults to `new Date()`.
|
|
556
|
+
*/
|
|
206
557
|
currentDate?: Date
|
|
207
558
|
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* JWS Verification options.
|
|
562
|
+
*/
|
|
208
563
|
export interface VerifyOptions extends CritOption {
|
|
564
|
+
/**
|
|
565
|
+
* A list of accepted JWS "alg" (Algorithm) Header Parameter values.
|
|
566
|
+
* By default all "alg" (Algorithm) values applicable for the used
|
|
567
|
+
* key/secret are allowed. Note: "none" is never accepted.
|
|
568
|
+
*/
|
|
209
569
|
algorithms?: string[]
|
|
210
570
|
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* JWS Signing options.
|
|
574
|
+
*/
|
|
211
575
|
export interface SignOptions extends CritOption {}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Recognized JWT Claims Set members, any other members
|
|
579
|
+
* may also be present.
|
|
580
|
+
*/
|
|
212
581
|
export interface JWTPayload {
|
|
582
|
+
/**
|
|
583
|
+
* JWT Issuer - [RFC7519#section-4.1.1](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.1).
|
|
584
|
+
*/
|
|
213
585
|
iss?: string
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* JWT Subject - [RFC7519#section-4.1.2](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.2).
|
|
589
|
+
*/
|
|
214
590
|
sub?: string
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* JWT Audience [RFC7519#section-4.1.3](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.3).
|
|
594
|
+
*/
|
|
215
595
|
aud?: string | string[]
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* JWT ID - [RFC7519#section-4.1.7](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.7).
|
|
599
|
+
*/
|
|
216
600
|
jti?: string
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* JWT Not Before - [RFC7519#section-4.1.5](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.5).
|
|
604
|
+
*/
|
|
217
605
|
nbf?: number
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* JWT Expiration Time - [RFC7519#section-4.1.4](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4).
|
|
609
|
+
*/
|
|
218
610
|
exp?: number
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* JWT Issued At - [RFC7519#section-4.1.6](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6).
|
|
614
|
+
*/
|
|
219
615
|
iat?: number
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Any other JWT Claim Set member.
|
|
619
|
+
*/
|
|
220
620
|
[propName: string]: unknown
|
|
221
621
|
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Deflate Raw implementation, e.g. promisified [zlib.deflateRaw](https://nodejs.org/api/zlib.html#zlib_zlib_deflateraw_buffer_options_callback).
|
|
625
|
+
*/
|
|
222
626
|
export interface DeflateFunction {
|
|
223
627
|
(input: Uint8Array): Promise<Uint8Array>
|
|
224
628
|
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Inflate Raw implementation, e.g. promisified [zlib.inflateRaw](https://nodejs.org/api/zlib.html#zlib_zlib_inflateraw_buffer_options_callback).
|
|
632
|
+
*/
|
|
225
633
|
export interface InflateFunction {
|
|
226
634
|
(input: Uint8Array): Promise<Uint8Array>
|
|
227
635
|
}
|
|
636
|
+
|
|
228
637
|
export interface FlattenedDecryptResult {
|
|
638
|
+
/**
|
|
639
|
+
* JWE AAD.
|
|
640
|
+
*/
|
|
229
641
|
additionalAuthenticatedData?: Uint8Array
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Plaintext.
|
|
645
|
+
*/
|
|
230
646
|
plaintext: Uint8Array
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* JWE Protected Header.
|
|
650
|
+
*/
|
|
231
651
|
protectedHeader?: JWEHeaderParameters
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* JWE Shared Unprotected Header.
|
|
655
|
+
*/
|
|
232
656
|
sharedUnprotectedHeader?: JWEHeaderParameters
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* JWE Per-Recipient Unprotected Header.
|
|
660
|
+
*/
|
|
233
661
|
unprotectedHeader?: JWEHeaderParameters
|
|
234
662
|
}
|
|
663
|
+
|
|
235
664
|
export interface GeneralDecryptResult extends FlattenedDecryptResult {}
|
|
665
|
+
|
|
236
666
|
export interface CompactDecryptResult {
|
|
667
|
+
/**
|
|
668
|
+
* Plaintext.
|
|
669
|
+
*/
|
|
237
670
|
plaintext: Uint8Array
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* JWE Protected Header.
|
|
674
|
+
*/
|
|
238
675
|
protectedHeader: CompactJWEHeaderParameters
|
|
239
676
|
}
|
|
677
|
+
|
|
240
678
|
export interface FlattenedVerifyResult {
|
|
679
|
+
/**
|
|
680
|
+
* JWS Payload.
|
|
681
|
+
*/
|
|
241
682
|
payload: Uint8Array
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* JWS Protected Header.
|
|
686
|
+
*/
|
|
242
687
|
protectedHeader?: JWSHeaderParameters
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* JWS Unprotected Header.
|
|
691
|
+
*/
|
|
243
692
|
unprotectedHeader?: JWSHeaderParameters
|
|
244
693
|
}
|
|
694
|
+
|
|
245
695
|
export interface GeneralVerifyResult extends FlattenedVerifyResult {}
|
|
696
|
+
|
|
246
697
|
export interface CompactVerifyResult {
|
|
698
|
+
/**
|
|
699
|
+
* JWS Payload.
|
|
700
|
+
*/
|
|
247
701
|
payload: Uint8Array
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* JWS Protected Header.
|
|
705
|
+
*/
|
|
248
706
|
protectedHeader: CompactJWSHeaderParameters
|
|
249
707
|
}
|
|
708
|
+
|
|
250
709
|
export interface JWTVerifyResult {
|
|
710
|
+
/**
|
|
711
|
+
* JWT Claims Set.
|
|
712
|
+
*/
|
|
251
713
|
payload: JWTPayload
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* JWS Protected Header.
|
|
717
|
+
*/
|
|
252
718
|
protectedHeader: JWTHeaderParameters
|
|
253
719
|
}
|
|
720
|
+
|
|
254
721
|
export interface JWTDecryptResult {
|
|
722
|
+
/**
|
|
723
|
+
* JWT Claims Set.
|
|
724
|
+
*/
|
|
255
725
|
payload: JWTPayload
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* JWE Protected Header.
|
|
729
|
+
*/
|
|
256
730
|
protectedHeader: CompactJWEHeaderParameters
|
|
257
731
|
}
|
|
732
|
+
|
|
258
733
|
export interface ResolvedKey {
|
|
734
|
+
/**
|
|
735
|
+
* Key resolved from the key resolver function.
|
|
736
|
+
*/
|
|
259
737
|
key: KeyLike | Uint8Array
|
|
260
738
|
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Recognized Compact JWS Header Parameters, any other Header Members
|
|
742
|
+
* may also be present.
|
|
743
|
+
*/
|
|
261
744
|
export interface CompactJWSHeaderParameters extends JWSHeaderParameters {
|
|
262
745
|
alg: string
|
|
263
746
|
}
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Recognized Signed JWT Header Parameters, any other Header Members
|
|
750
|
+
* may also be present.
|
|
751
|
+
*/
|
|
264
752
|
export interface JWTHeaderParameters extends CompactJWSHeaderParameters {
|
|
265
753
|
b64?: true
|
|
266
754
|
}
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* Recognized Compact JWE Header Parameters, any other Header Members
|
|
758
|
+
* may also be present.
|
|
759
|
+
*/
|
|
267
760
|
export interface CompactJWEHeaderParameters extends JWEHeaderParameters {
|
|
268
761
|
alg: string
|
|
269
762
|
enc: string
|
|
270
763
|
}
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* JSON Web Key Set
|
|
767
|
+
*/
|
|
271
768
|
export interface JSONWebKeySet {
|
|
272
769
|
keys: JWK[]
|
|
273
770
|
}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility function to encode a string or Uint8Array as a base64url string.
|
|
3
|
+
*
|
|
4
|
+
* @param input Value that will be base64url-encoded.
|
|
5
|
+
*/
|
|
1
6
|
interface Base64UrlEncode {
|
|
2
7
|
(input: Uint8Array | string): string;
|
|
3
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Utility function to decode a base64url encoded string.
|
|
11
|
+
*
|
|
12
|
+
* @param input Value that will be base64url-decoded.
|
|
13
|
+
*/
|
|
4
14
|
interface Base64UrlDecode {
|
|
5
15
|
(input: Uint8Array | string): Uint8Array;
|
|
6
16
|
}
|
|
@@ -1,2 +1,16 @@
|
|
|
1
1
|
import type { JWTPayload } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Decodes a signed JSON Web Token payload. This does not validate the JWT Claims Set
|
|
4
|
+
* types or values. This does not validate the JWS Signature. For a proper
|
|
5
|
+
* Signed JWT Claims Set validation and JWS signature verification use `jose.jwtVerify()`.
|
|
6
|
+
* For an encrypted JWT Claims Set validation and JWE decryption use `jose.jwtDecrypt()`.
|
|
7
|
+
*
|
|
8
|
+
* @param jwt JWT token in compact JWS serialization.
|
|
9
|
+
*
|
|
10
|
+
* @example Usage
|
|
11
|
+
* ```js
|
|
12
|
+
* const claims = jose.decodeJwt(token)
|
|
13
|
+
* console.log(claims)
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
2
16
|
export declare function decodeJwt(jwt: string): JWTPayload;
|