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