@oari/jose 0.0.0

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 (88) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +150 -0
  3. package/dist/types/index.d.ts +55 -0
  4. package/dist/types/jwe/compact/decrypt.d.ts +43 -0
  5. package/dist/types/jwe/compact/encrypt.d.ts +76 -0
  6. package/dist/types/jwe/flattened/decrypt.d.ts +53 -0
  7. package/dist/types/jwe/flattened/encrypt.d.ts +95 -0
  8. package/dist/types/jwe/general/decrypt.d.ts +64 -0
  9. package/dist/types/jwe/general/encrypt.d.ts +89 -0
  10. package/dist/types/jwk/embedded.d.ts +31 -0
  11. package/dist/types/jwk/thumbprint.d.ts +60 -0
  12. package/dist/types/jwks/local.d.ts +90 -0
  13. package/dist/types/jwks/remote.d.ts +306 -0
  14. package/dist/types/jws/compact/sign.d.ts +47 -0
  15. package/dist/types/jws/compact/verify.d.ts +45 -0
  16. package/dist/types/jws/flattened/sign.d.ts +53 -0
  17. package/dist/types/jws/flattened/verify.d.ts +50 -0
  18. package/dist/types/jws/general/sign.d.ts +67 -0
  19. package/dist/types/jws/general/verify.d.ts +61 -0
  20. package/dist/types/jwt/decrypt.d.ts +51 -0
  21. package/dist/types/jwt/encrypt.d.ts +105 -0
  22. package/dist/types/jwt/sign.d.ts +140 -0
  23. package/dist/types/jwt/unsecured.d.ts +70 -0
  24. package/dist/types/jwt/verify.d.ts +124 -0
  25. package/dist/types/key/export.d.ts +59 -0
  26. package/dist/types/key/generate_key_pair.d.ts +64 -0
  27. package/dist/types/key/generate_secret.d.ts +42 -0
  28. package/dist/types/key/import.d.ts +146 -0
  29. package/dist/types/types.d.ts +869 -0
  30. package/dist/types/util/base64url.d.ts +9 -0
  31. package/dist/types/util/decode_jwt.d.ts +25 -0
  32. package/dist/types/util/decode_protected_header.d.ts +24 -0
  33. package/dist/types/util/errors.d.ts +488 -0
  34. package/dist/webapi/index.js +32 -0
  35. package/dist/webapi/jwe/compact/decrypt.js +27 -0
  36. package/dist/webapi/jwe/compact/encrypt.js +27 -0
  37. package/dist/webapi/jwe/flattened/decrypt.js +159 -0
  38. package/dist/webapi/jwe/flattened/encrypt.js +167 -0
  39. package/dist/webapi/jwe/general/decrypt.js +31 -0
  40. package/dist/webapi/jwe/general/encrypt.js +182 -0
  41. package/dist/webapi/jwk/embedded.js +17 -0
  42. package/dist/webapi/jwk/thumbprint.js +68 -0
  43. package/dist/webapi/jwks/local.js +119 -0
  44. package/dist/webapi/jwks/remote.js +179 -0
  45. package/dist/webapi/jws/compact/sign.js +18 -0
  46. package/dist/webapi/jws/compact/verify.js +21 -0
  47. package/dist/webapi/jws/flattened/sign.js +87 -0
  48. package/dist/webapi/jws/flattened/verify.js +110 -0
  49. package/dist/webapi/jws/general/sign.js +70 -0
  50. package/dist/webapi/jws/general/verify.js +24 -0
  51. package/dist/webapi/jwt/decrypt.js +23 -0
  52. package/dist/webapi/jwt/encrypt.js +101 -0
  53. package/dist/webapi/jwt/sign.js +52 -0
  54. package/dist/webapi/jwt/unsecured.js +63 -0
  55. package/dist/webapi/jwt/verify.js +15 -0
  56. package/dist/webapi/key/export.js +11 -0
  57. package/dist/webapi/key/generate_key_pair.js +97 -0
  58. package/dist/webapi/key/generate_secret.js +40 -0
  59. package/dist/webapi/key/import.js +57 -0
  60. package/dist/webapi/lib/aesgcmkw.js +15 -0
  61. package/dist/webapi/lib/aeskw.js +25 -0
  62. package/dist/webapi/lib/asn1.js +243 -0
  63. package/dist/webapi/lib/base64.js +22 -0
  64. package/dist/webapi/lib/buffer_utils.js +43 -0
  65. package/dist/webapi/lib/check_key_type.js +127 -0
  66. package/dist/webapi/lib/content_encryption.js +217 -0
  67. package/dist/webapi/lib/crypto_key.js +136 -0
  68. package/dist/webapi/lib/deflate.js +44 -0
  69. package/dist/webapi/lib/ecdhes.js +52 -0
  70. package/dist/webapi/lib/helpers.js +19 -0
  71. package/dist/webapi/lib/invalid_key_input.js +27 -0
  72. package/dist/webapi/lib/is_key_like.js +17 -0
  73. package/dist/webapi/lib/jwk_to_key.js +107 -0
  74. package/dist/webapi/lib/jwt_claims_set.js +238 -0
  75. package/dist/webapi/lib/key_management.js +186 -0
  76. package/dist/webapi/lib/key_to_jwk.js +31 -0
  77. package/dist/webapi/lib/normalize_key.js +166 -0
  78. package/dist/webapi/lib/pbes2kw.js +42 -0
  79. package/dist/webapi/lib/rsaes.js +24 -0
  80. package/dist/webapi/lib/signing.js +74 -0
  81. package/dist/webapi/lib/type_checks.js +41 -0
  82. package/dist/webapi/lib/validate_algorithms.js +10 -0
  83. package/dist/webapi/lib/validate_crit.js +33 -0
  84. package/dist/webapi/util/base64url.js +30 -0
  85. package/dist/webapi/util/decode_jwt.js +32 -0
  86. package/dist/webapi/util/decode_protected_header.js +34 -0
  87. package/dist/webapi/util/errors.js +99 -0
  88. package/package.json +195 -0
@@ -0,0 +1,869 @@
1
+ /** Generic JSON Web Key Parameters. */
2
+ export interface JWKParameters {
3
+ /** JWK "kty" (Key Type) Parameter */
4
+ kty?: string
5
+ /**
6
+ * JWK "alg" (Algorithm) Parameter
7
+ *
8
+ * @see {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}
9
+ */
10
+ alg?: string
11
+ /** JWK "key_ops" (Key Operations) Parameter */
12
+ key_ops?: string[]
13
+ /** JWK "ext" (Extractable) Parameter */
14
+ ext?: boolean
15
+ /** JWK "use" (Public Key Use) Parameter */
16
+ use?: string
17
+ /** JWK "x5c" (X.509 Certificate Chain) Parameter */
18
+ x5c?: string[]
19
+ /** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter */
20
+ x5t?: string
21
+ /** JWK "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter */
22
+ 'x5t#S256'?: string
23
+ /** JWK "x5u" (X.509 URL) Parameter */
24
+ x5u?: string
25
+ /** JWK "kid" (Key ID) Parameter */
26
+ kid?: string
27
+ }
28
+
29
+ /** Convenience interface for Public OKP JSON Web Keys */
30
+ export interface JWK_OKP_Public extends JWKParameters {
31
+ /** OKP JWK "crv" (The Subtype of Key Pair) Parameter */
32
+ crv: string
33
+ /** OKP JWK "x" (The public key) Parameter */
34
+ x: string
35
+ }
36
+
37
+ /** Convenience interface for Private OKP JSON Web Keys */
38
+ export interface JWK_OKP_Private extends JWK_OKP_Public {
39
+ /** OKP JWK "d" (The Private Key) Parameter */
40
+ d: string
41
+ }
42
+
43
+ /** Convenience interface for Public AKP JSON Web Keys */
44
+ export interface JWK_AKP_Public extends JWKParameters {
45
+ /** JWK "alg" (Algorithm) Parameter */
46
+ alg: string
47
+ /** AKP JWK "pub" (The Public key) Parameter */
48
+ pub: string
49
+ }
50
+
51
+ /** Convenience interface for Private AKP JSON Web Keys */
52
+ export interface JWK_AKP_Private extends JWK_AKP_Public {
53
+ /** AKP JWK "priv" (The Private Key) Parameter */
54
+ priv: string
55
+ }
56
+
57
+ /** Convenience interface for Public EC JSON Web Keys */
58
+ export interface JWK_EC_Public extends JWKParameters {
59
+ /** EC JWK "crv" (Curve) Parameter */
60
+ crv: string
61
+ /** EC JWK "x" (X Coordinate) Parameter */
62
+ x: string
63
+ /** EC JWK "y" (Y Coordinate) Parameter */
64
+ y: string
65
+ }
66
+
67
+ /** Convenience interface for Private EC JSON Web Keys */
68
+ export interface JWK_EC_Private extends JWK_EC_Public {
69
+ /** EC JWK "d" (ECC Private Key) Parameter */
70
+ d: string
71
+ }
72
+
73
+ /** Convenience interface for Public RSA JSON Web Keys */
74
+ export interface JWK_RSA_Public extends JWKParameters {
75
+ /** RSA JWK "e" (Exponent) Parameter */
76
+ e: string
77
+ /** RSA JWK "n" (Modulus) Parameter */
78
+ n: string
79
+ }
80
+
81
+ /** Convenience interface for Private RSA JSON Web Keys */
82
+ export interface JWK_RSA_Private extends JWK_RSA_Public {
83
+ /** RSA JWK "d" (Private Exponent) Parameter */
84
+ d: string
85
+ /** RSA JWK "dp" (First Factor CRT Exponent) Parameter */
86
+ dp: string
87
+ /** RSA JWK "dq" (Second Factor CRT Exponent) Parameter */
88
+ dq: string
89
+ /** RSA JWK "p" (First Prime Factor) Parameter */
90
+ p: string
91
+ /** RSA JWK "q" (Second Prime Factor) Parameter */
92
+ q: string
93
+ /** RSA JWK "qi" (First CRT Coefficient) Parameter */
94
+ qi: string
95
+ }
96
+
97
+ /** Convenience interface for oct JSON Web Keys */
98
+ export interface JWK_oct extends JWKParameters {
99
+ /** Oct JWK "k" (Key Value) Parameter */
100
+ k: string
101
+ }
102
+
103
+ /**
104
+ * JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC", "OKP", "AKP", and
105
+ * "oct" key types are supported.
106
+ *
107
+ * @see {@link JWK_AKP_Public}
108
+ * @see {@link JWK_AKP_Private}
109
+ * @see {@link JWK_OKP_Public}
110
+ * @see {@link JWK_OKP_Private}
111
+ * @see {@link JWK_EC_Public}
112
+ * @see {@link JWK_EC_Private}
113
+ * @see {@link JWK_RSA_Public}
114
+ * @see {@link JWK_RSA_Private}
115
+ * @see {@link JWK_oct}
116
+ */
117
+ export interface JWK extends JWKParameters {
118
+ /**
119
+ * - EC JWK "crv" (Curve) Parameter
120
+ * - OKP JWK "crv" (The Subtype of Key Pair) Parameter
121
+ */
122
+ crv?: string
123
+ /**
124
+ * - Private RSA JWK "d" (Private Exponent) Parameter
125
+ * - Private EC JWK "d" (ECC Private Key) Parameter
126
+ * - Private OKP JWK "d" (The Private Key) Parameter
127
+ */
128
+ d?: string
129
+ /** Private RSA JWK "dp" (First Factor CRT Exponent) Parameter */
130
+ dp?: string
131
+ /** Private RSA JWK "dq" (Second Factor CRT Exponent) Parameter */
132
+ dq?: string
133
+ /** RSA JWK "e" (Exponent) Parameter */
134
+ e?: string
135
+ /** Oct JWK "k" (Key Value) Parameter */
136
+ k?: string
137
+ /** RSA JWK "n" (Modulus) Parameter */
138
+ n?: string
139
+ /** Private RSA JWK "p" (First Prime Factor) Parameter */
140
+ p?: string
141
+ /** Private RSA JWK "q" (Second Prime Factor) Parameter */
142
+ q?: string
143
+ /** Private RSA JWK "qi" (First CRT Coefficient) Parameter */
144
+ qi?: string
145
+ /**
146
+ * - EC JWK "x" (X Coordinate) Parameter
147
+ * - OKP JWK "x" (The public key) Parameter
148
+ */
149
+ x?: string
150
+ /** EC JWK "y" (Y Coordinate) Parameter */
151
+ y?: string
152
+ /** AKP JWK "pub" (Public Key) Parameter */
153
+ pub?: string
154
+ /** AKP JWK "priv" (Private key) Parameter */
155
+ priv?: string
156
+ }
157
+
158
+ /**
159
+ * Hardware-backed JSON Web Key parameters.
160
+ *
161
+ * This interface only includes public key material and metadata that can be represented for a
162
+ * hardware-backed key. Private key material remains in HSM and cannot be set.
163
+ */
164
+ export interface HardwareJWK
165
+ extends Pick<JWK, 'alg' | 'crv' | 'e' | 'kid' | 'kty' | 'n' | 'pub' | 'use' | 'x' | 'y'> {
166
+ /**
167
+ * Produces a signature for the provided JWS Signing Input using the hardware-backed private key.
168
+ *
169
+ * @param alg JWS "alg" (Algorithm) Header Parameter value to use for signing.
170
+ * @param data Binary JWS Signing Input to sign.
171
+ */
172
+ sign: (alg: string, data: Uint8Array) => Promise<Uint8Array>
173
+ }
174
+
175
+ /**
176
+ * @private
177
+ *
178
+ * @internal
179
+ */
180
+ export interface GenericGetKeyFunction<IProtectedHeader, IToken, ReturnKeyTypes> {
181
+ /**
182
+ * Dynamic key resolution function. No token components have been verified at the time of this
183
+ * function call.
184
+ *
185
+ * If a suitable key for the token cannot be matched, throw an error instead.
186
+ *
187
+ * @param protectedHeader JWE or JWS Protected Header.
188
+ * @param token The consumed JWE or JWS token.
189
+ */
190
+ (protectedHeader: IProtectedHeader, token: IToken): Promise<ReturnKeyTypes> | ReturnKeyTypes
191
+ }
192
+
193
+ /**
194
+ * Generic Interface for consuming operations dynamic key resolution.
195
+ *
196
+ * @param IProtectedHeader Type definition of the JWE or JWS Protected Header.
197
+ * @param IToken Type definition of the consumed JWE or JWS token.
198
+ */
199
+ export interface GetKeyFunction<IProtectedHeader, IToken> extends GenericGetKeyFunction<
200
+ IProtectedHeader,
201
+ IToken,
202
+ CryptoKey | KeyObject | JWK | Uint8Array
203
+ > {}
204
+
205
+ /**
206
+ * Flattened JWS definition for verify function inputs, allows payload as {@link !Uint8Array} for
207
+ * detached signature validation.
208
+ */
209
+ export interface FlattenedJWSInput {
210
+ /**
211
+ * The "header" member MUST be present and contain the value JWS Unprotected Header when the JWS
212
+ * Unprotected Header value is non- empty; otherwise, it MUST be absent. This value is represented
213
+ * as an unencoded JSON object, rather than as a string. These Header Parameter values are not
214
+ * integrity protected.
215
+ */
216
+ header?: JWSHeaderParameters
217
+
218
+ /**
219
+ * The "payload" member MUST be present and contain the value BASE64URL(JWS Payload). When RFC7797
220
+ * "b64": false is used the value passed may also be a {@link !Uint8Array}.
221
+ */
222
+ payload: string | Uint8Array
223
+
224
+ /**
225
+ * The "protected" member MUST be present and contain the value BASE64URL(UTF8(JWS Protected
226
+ * Header)) when the JWS Protected Header value is non-empty; otherwise, it MUST be absent. These
227
+ * Header Parameter values are integrity protected.
228
+ */
229
+ protected?: string
230
+
231
+ /** The "signature" member MUST be present and contain the value BASE64URL(JWS Signature). */
232
+ signature: string
233
+ }
234
+
235
+ /**
236
+ * General JWS definition for verify function inputs, allows payload as {@link !Uint8Array} for
237
+ * detached signature validation.
238
+ */
239
+ export interface GeneralJWSInput {
240
+ /**
241
+ * The "payload" member MUST be present and contain the value BASE64URL(JWS Payload). When when
242
+ * JWS Unencoded Payload ({@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}) "b64": false is
243
+ * used the value passed may also be a {@link !Uint8Array}.
244
+ */
245
+ payload: string | Uint8Array
246
+
247
+ /**
248
+ * The "signatures" member value MUST be an array of JSON objects. Each object represents a
249
+ * signature or MAC over the JWS Payload and the JWS Protected Header.
250
+ */
251
+ signatures: Omit<FlattenedJWSInput, 'payload'>[]
252
+ }
253
+
254
+ /**
255
+ * Flattened JWS JSON Serialization Syntax token. Payload is returned as an empty string when JWS
256
+ * Unencoded Payload ({@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}) is used.
257
+ */
258
+ export interface FlattenedJWS extends Partial<FlattenedJWSInput> {
259
+ payload: string
260
+ signature: string
261
+ }
262
+
263
+ /**
264
+ * General JWS JSON Serialization Syntax token. Payload is returned as an empty string when JWS
265
+ * Unencoded Payload ({@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}) is used.
266
+ */
267
+ export interface GeneralJWS {
268
+ payload: string
269
+ signatures: Omit<FlattenedJWSInput, 'payload'>[]
270
+ }
271
+
272
+ /** Header Parameters common to JWE and JWS */
273
+ export interface JoseHeaderParameters {
274
+ /** "kid" (Key ID) Header Parameter */
275
+ kid?: string
276
+
277
+ /** "x5t" (X.509 Certificate SHA-1 Thumbprint) Header Parameter */
278
+ x5t?: string
279
+
280
+ /** "x5c" (X.509 Certificate Chain) Header Parameter */
281
+ x5c?: string[]
282
+
283
+ /** "x5u" (X.509 URL) Header Parameter */
284
+ x5u?: string
285
+
286
+ /** "jku" (JWK Set URL) Header Parameter */
287
+ jku?: string
288
+
289
+ /** "jwk" (JSON Web Key) Header Parameter */
290
+ jwk?: Pick<JWK, 'kty' | 'crv' | 'x' | 'y' | 'e' | 'n' | 'alg' | 'pub'>
291
+
292
+ /** "typ" (Type) Header Parameter */
293
+ typ?: string
294
+
295
+ /** "cty" (Content Type) Header Parameter */
296
+ cty?: string
297
+ }
298
+
299
+ /** Recognized JWS Header Parameters, any other Header Members may also be present. */
300
+ export interface JWSHeaderParameters extends JoseHeaderParameters {
301
+ /**
302
+ * JWS "alg" (Algorithm) Header Parameter
303
+ *
304
+ * @see {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}
305
+ */
306
+ alg?: string
307
+
308
+ /**
309
+ * This JWS Extension Header Parameter modifies the JWS Payload representation and the JWS Signing
310
+ * Input computation as per {@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}.
311
+ */
312
+ b64?: boolean
313
+
314
+ /** JWS "crit" (Critical) Header Parameter */
315
+ crit?: string[]
316
+
317
+ /** Any other JWS Header member. */
318
+ [propName: string]: unknown
319
+ }
320
+
321
+ /** Recognized JWE Key Management-related Header Parameters. */
322
+ export interface JWEKeyManagementHeaderParameters {
323
+ /**
324
+ * ECDH-ES "apu" (Agreement PartyUInfo). This will be used as a JOSE Header Parameter and will be
325
+ * used in ECDH's ConcatKDF.
326
+ */
327
+ apu?: Uint8Array
328
+
329
+ /**
330
+ * ECDH-ES "apv" (Agreement PartyVInfo). This will be used as a JOSE Header Parameter and will be
331
+ * used in ECDH's ConcatKDF.
332
+ */
333
+ apv?: Uint8Array
334
+ /**
335
+ * @deprecated You should not use this parameter. It is only intended for testing and vector
336
+ * validation purposes.
337
+ */
338
+ p2c?: number
339
+ /**
340
+ * @deprecated You should not use this parameter. It is only intended for testing and vector
341
+ * validation purposes.
342
+ */
343
+ p2s?: Uint8Array
344
+ /**
345
+ * @deprecated You should not use this parameter. It is only intended for testing and vector
346
+ * validation purposes.
347
+ */
348
+ iv?: Uint8Array
349
+ /**
350
+ * @deprecated You should not use this parameter. It is only intended for testing and vector
351
+ * validation purposes.
352
+ */
353
+ epk?: CryptoKey | KeyObject
354
+ }
355
+
356
+ /** Flattened JWE JSON Serialization Syntax token. */
357
+ export interface FlattenedJWE {
358
+ /**
359
+ * The "aad" member MUST be present and contain the value BASE64URL(JWE AAD)) when the JWE AAD
360
+ * value is non-empty; otherwise, it MUST be absent. A JWE AAD value can be included to supply a
361
+ * base64url-encoded value to be integrity protected but not encrypted.
362
+ */
363
+ aad?: string
364
+
365
+ /** The "ciphertext" member MUST be present and contain the value BASE64URL(JWE Ciphertext). */
366
+ ciphertext: string
367
+
368
+ /**
369
+ * The "encrypted_key" member MUST be present and contain the value BASE64URL(JWE Encrypted Key)
370
+ * when the JWE Encrypted Key value is non-empty; otherwise, it MUST be absent.
371
+ */
372
+ encrypted_key?: string
373
+
374
+ /**
375
+ * The "header" member MUST be present and contain the value JWE Per- Recipient Unprotected Header
376
+ * when the JWE Per-Recipient Unprotected Header value is non-empty; otherwise, it MUST be absent.
377
+ * This value is represented as an unencoded JSON object, rather than as a string. These Header
378
+ * Parameter values are not integrity protected.
379
+ */
380
+ header?: JWEHeaderParameters
381
+
382
+ /**
383
+ * The "iv" member MUST be present and contain the value BASE64URL(JWE Initialization Vector) when
384
+ * the JWE Initialization Vector value is non-empty; otherwise, it MUST be absent.
385
+ */
386
+ iv?: string
387
+
388
+ /**
389
+ * The "protected" member MUST be present and contain the value BASE64URL(UTF8(JWE Protected
390
+ * Header)) when the JWE Protected Header value is non-empty; otherwise, it MUST be absent. These
391
+ * Header Parameter values are integrity protected.
392
+ */
393
+ protected?: string
394
+
395
+ /**
396
+ * The "tag" member MUST be present and contain the value BASE64URL(JWE Authentication Tag) when
397
+ * the JWE Authentication Tag value is non-empty; otherwise, it MUST be absent.
398
+ */
399
+ tag?: string
400
+
401
+ /**
402
+ * The "unprotected" member MUST be present and contain the value JWE Shared Unprotected Header
403
+ * when the JWE Shared Unprotected Header value is non-empty; otherwise, it MUST be absent. This
404
+ * value is represented as an unencoded JSON object, rather than as a string. These Header
405
+ * Parameter values are not integrity protected.
406
+ */
407
+ unprotected?: JWEHeaderParameters
408
+ }
409
+
410
+ /** General JWE JSON Serialization Syntax token. */
411
+ export interface GeneralJWE extends Omit<FlattenedJWE, 'encrypted_key' | 'header'> {
412
+ recipients: Pick<FlattenedJWE, 'encrypted_key' | 'header'>[]
413
+ }
414
+
415
+ /** Recognized JWE Header Parameters, any other Header members may also be present. */
416
+ export interface JWEHeaderParameters extends JoseHeaderParameters {
417
+ /**
418
+ * JWE "alg" (Algorithm) Header Parameter
419
+ *
420
+ * @see {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}
421
+ */
422
+ alg?: string
423
+
424
+ /**
425
+ * JWE "enc" (Encryption Algorithm) Header Parameter
426
+ *
427
+ * @see {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}
428
+ */
429
+ enc?: string
430
+
431
+ /** JWE "crit" (Critical) Header Parameter */
432
+ crit?: string[]
433
+
434
+ /**
435
+ * JWE "zip" (Compression Algorithm) Header Parameter.
436
+ *
437
+ * The only supported value is `"DEF"` (DEFLATE). Requires the `CompressionStream` /
438
+ * `DecompressionStream` APIs to be available in the runtime.
439
+ *
440
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7516#section-4.1.3 JWE "zip" Header Parameter}
441
+ */
442
+ zip?: string
443
+
444
+ /** Any other JWE Header member. */
445
+ [propName: string]: unknown
446
+ }
447
+
448
+ /** Shared Interface with a "crit" property for all sign, verify, encrypt and decrypt operations. */
449
+ export interface CritOption {
450
+ /**
451
+ * An object with keys representing recognized "crit" (Critical) Header Parameter names. The value
452
+ * for those is either `true` or `false`. `true` when the Header Parameter MUST be integrity
453
+ * protected, `false` when it's irrelevant.
454
+ *
455
+ * This makes the "Extension Header Parameter "..." is not recognized" error go away.
456
+ *
457
+ * Use this when a given JWS/JWT/JWE profile requires the use of proprietary non-registered "crit"
458
+ * (Critical) Header Parameters. This will only make sure the Header Parameter is syntactically
459
+ * correct when provided and that it is optionally integrity protected. It will not process the
460
+ * Header Parameter in any way or reject the operation if it is missing. You MUST still verify the
461
+ * Header Parameter was present and process it according to the profile's validation steps after
462
+ * the operation succeeds.
463
+ *
464
+ * The JWS extension Header Parameter `b64` is always recognized and processed properly. No other
465
+ * registered Header Parameters that need this kind of default built-in treatment are currently
466
+ * available.
467
+ */
468
+ crit?: {
469
+ [propName: string]: boolean
470
+ }
471
+ }
472
+
473
+ /** JWE Decryption options. */
474
+ export interface DecryptOptions extends CritOption {
475
+ /**
476
+ * A list of accepted JWE "alg" (Algorithm) Header Parameter values. By default all "alg"
477
+ * (Algorithm) Header Parameter values applicable for the used key/secret are allowed except for
478
+ * all PBES2 Key Management Algorithms, these need to be explicitly allowed using this option.
479
+ */
480
+ keyManagementAlgorithms?: string[]
481
+
482
+ /**
483
+ * A list of accepted JWE "enc" (Encryption Algorithm) Header Parameter values. By default all
484
+ * "enc" (Encryption Algorithm) values applicable for the used key/secret are allowed.
485
+ */
486
+ contentEncryptionAlgorithms?: string[]
487
+
488
+ /**
489
+ * (PBES2 Key Management Algorithms only) Maximum allowed "p2c" (PBES2 Count) Header Parameter
490
+ * value. The PBKDF2 iteration count defines the algorithm's computational expense. By default
491
+ * this value is set to 10000.
492
+ */
493
+ maxPBES2Count?: number
494
+
495
+ /**
496
+ * Maximum allowed size (in bytes) of the decompressed plaintext when the JWE `"zip"` (Compression
497
+ * Algorithm) Header Parameter is present. By default this value is set to 250000 (250 KB). The
498
+ * value must be `0`, a positive safe integer, or `Infinity`.
499
+ *
500
+ * Set to `0` to reject all compressed JWEs during decryption.
501
+ *
502
+ * Set to `Infinity` to disable the decompressed size limit.
503
+ */
504
+ maxDecompressedLength?: number
505
+ }
506
+
507
+ /** JWE Encryption options. */
508
+ export interface EncryptOptions extends CritOption {}
509
+
510
+ /** JWT Claims Set verification options. */
511
+ export interface JWTClaimVerificationOptions {
512
+ /**
513
+ * Expected JWT "aud" (Audience) Claim value(s).
514
+ *
515
+ * This option makes the JWT "aud" (Audience) Claim presence required.
516
+ */
517
+ audience?: string | string[]
518
+
519
+ /**
520
+ * Clock skew tolerance
521
+ *
522
+ * - In seconds when number (e.g. 5)
523
+ * - Resolved into a number of seconds when a string (e.g. "5 seconds", "10 minutes", "2 hours").
524
+ *
525
+ * Used when validating the JWT "nbf" (Not Before) and "exp" (Expiration Time) claims, and when
526
+ * validating the "iat" (Issued At) claim if the {@link maxTokenAge `maxTokenAge` option} is set.
527
+ */
528
+ clockTolerance?: string | number
529
+
530
+ /**
531
+ * Expected JWT "iss" (Issuer) Claim value(s).
532
+ *
533
+ * This option makes the JWT "iss" (Issuer) Claim presence required.
534
+ */
535
+ issuer?: string | string[]
536
+
537
+ /**
538
+ * Maximum time elapsed (in seconds) from the JWT "iat" (Issued At) Claim value.
539
+ *
540
+ * - In seconds when number (e.g. 5)
541
+ * - Resolved into a number of seconds when a string (e.g. "5 seconds", "10 minutes", "2 hours").
542
+ *
543
+ * This option makes the JWT "iat" (Issued At) Claim presence required.
544
+ */
545
+ maxTokenAge?: string | number
546
+
547
+ /**
548
+ * Expected JWT "sub" (Subject) Claim value.
549
+ *
550
+ * This option makes the JWT "sub" (Subject) Claim presence required.
551
+ */
552
+ subject?: string
553
+
554
+ /**
555
+ * Expected JWT "typ" (Type) Header Parameter value.
556
+ *
557
+ * This option makes the JWT "typ" (Type) Header Parameter presence required.
558
+ */
559
+ typ?: string
560
+
561
+ /** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
562
+ currentDate?: Date
563
+
564
+ /**
565
+ * Array of required Claim Names that must be present in the JWT Claims Set. Default is that: if
566
+ * the {@link issuer `issuer` option} is set, then JWT "iss" (Issuer) Claim must be present; if the
567
+ * {@link audience `audience` option} is set, then JWT "aud" (Audience) Claim must be present; if
568
+ * the {@link subject `subject` option} is set, then JWT "sub" (Subject) Claim must be present; if
569
+ * the {@link maxTokenAge `maxTokenAge` option} is set, then JWT "iat" (Issued At) Claim must be
570
+ * present.
571
+ */
572
+ requiredClaims?: string[]
573
+ }
574
+
575
+ /** JWS Verification options. */
576
+ export interface VerifyOptions extends CritOption {
577
+ /**
578
+ * A list of accepted JWS "alg" (Algorithm) Header Parameter values. By default all "alg"
579
+ * (Algorithm) values applicable for the used key/secret are allowed.
580
+ *
581
+ * > [!NOTE]\
582
+ * > Unsecured JWTs (`{ "alg": "none" }`) are never accepted by this API.
583
+ */
584
+ algorithms?: string[]
585
+ }
586
+
587
+ /** JWS Signing options. */
588
+ export interface SignOptions extends CritOption {}
589
+
590
+ /** Recognized JWT Claims Set members, any other members may also be present. */
591
+ export interface JWTPayload {
592
+ /**
593
+ * JWT Issuer
594
+ *
595
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.1 RFC7519#section-4.1.1}
596
+ */
597
+ iss?: string
598
+
599
+ /**
600
+ * JWT Subject
601
+ *
602
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.2 RFC7519#section-4.1.2}
603
+ */
604
+ sub?: string
605
+
606
+ /**
607
+ * JWT Audience
608
+ *
609
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.3 RFC7519#section-4.1.3}
610
+ */
611
+ aud?: string | string[]
612
+
613
+ /**
614
+ * JWT ID
615
+ *
616
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.7 RFC7519#section-4.1.7}
617
+ */
618
+ jti?: string
619
+
620
+ /**
621
+ * JWT Not Before
622
+ *
623
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.5 RFC7519#section-4.1.5}
624
+ */
625
+ nbf?: number
626
+
627
+ /**
628
+ * JWT Expiration Time
629
+ *
630
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4 RFC7519#section-4.1.4}
631
+ */
632
+ exp?: number
633
+
634
+ /**
635
+ * JWT Issued At
636
+ *
637
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6 RFC7519#section-4.1.6}
638
+ */
639
+ iat?: number
640
+
641
+ /** Any other JWT Claim Set member. */
642
+ [propName: string]: unknown
643
+ }
644
+
645
+ /** Flattened JWE JSON Serialization Syntax decryption result */
646
+ export interface FlattenedDecryptResult {
647
+ /** JWE AAD. */
648
+ additionalAuthenticatedData?: Uint8Array
649
+
650
+ /** Plaintext. */
651
+ plaintext: Uint8Array
652
+
653
+ /** JWE Protected Header. */
654
+ protectedHeader?: JWEHeaderParameters
655
+
656
+ /** JWE Shared Unprotected Header. */
657
+ sharedUnprotectedHeader?: JWEHeaderParameters
658
+
659
+ /** JWE Per-Recipient Unprotected Header. */
660
+ unprotectedHeader?: JWEHeaderParameters
661
+ }
662
+
663
+ /** General JWE JSON Serialization Syntax decryption result */
664
+ export interface GeneralDecryptResult extends FlattenedDecryptResult {}
665
+
666
+ /** Compact JWE decryption result */
667
+ export interface CompactDecryptResult {
668
+ /** Plaintext. */
669
+ plaintext: Uint8Array
670
+
671
+ /** JWE Protected Header. */
672
+ protectedHeader: CompactJWEHeaderParameters
673
+ }
674
+
675
+ /** Flattened JWS JSON Serialization Syntax verification result */
676
+ export interface FlattenedVerifyResult {
677
+ /** JWS Payload. */
678
+ payload: Uint8Array
679
+
680
+ /** JWS Protected Header. */
681
+ protectedHeader?: JWSHeaderParameters
682
+
683
+ /** JWS Unprotected Header. */
684
+ unprotectedHeader?: JWSHeaderParameters
685
+ }
686
+
687
+ /** General JWS JSON Serialization Syntax verification result */
688
+ export interface GeneralVerifyResult extends FlattenedVerifyResult {}
689
+
690
+ /** Compact JWS verification result */
691
+ export interface CompactVerifyResult {
692
+ /** JWS Payload. */
693
+ payload: Uint8Array
694
+
695
+ /** JWS Protected Header. */
696
+ protectedHeader: CompactJWSHeaderParameters
697
+ }
698
+
699
+ /** Signed JSON Web Token (JWT) verification result */
700
+ export interface JWTVerifyResult<PayloadType = JWTPayload> {
701
+ /** JWT Claims Set. */
702
+ payload: PayloadType & JWTPayload
703
+
704
+ /** JWS Protected Header. */
705
+ protectedHeader: JWTHeaderParameters
706
+ }
707
+
708
+ /** Encrypted JSON Web Token (JWT) decryption result */
709
+ export interface JWTDecryptResult<PayloadType = JWTPayload> {
710
+ /** JWT Claims Set. */
711
+ payload: PayloadType & JWTPayload
712
+
713
+ /** JWE Protected Header. */
714
+ protectedHeader: CompactJWEHeaderParameters
715
+ }
716
+
717
+ /** When key resolver functions are used this becomes part of successful resolves */
718
+ export interface ResolvedKey {
719
+ /** Key resolved from the key resolver function. */
720
+ key: CryptoKey | Uint8Array
721
+ }
722
+
723
+ /** Recognized Compact JWS Header Parameters, any other Header Members may also be present. */
724
+ export interface CompactJWSHeaderParameters extends JWSHeaderParameters {
725
+ alg: string
726
+ }
727
+
728
+ /** Recognized Signed JWT Header Parameters, any other Header Members may also be present. */
729
+ export interface JWTHeaderParameters extends CompactJWSHeaderParameters {
730
+ b64?: true
731
+ }
732
+
733
+ /** Recognized Compact JWE Header Parameters, any other Header Members may also be present. */
734
+ export interface CompactJWEHeaderParameters extends JWEHeaderParameters {
735
+ alg: string
736
+ enc: string
737
+ }
738
+
739
+ /** JSON Web Key Set */
740
+ export interface JSONWebKeySet {
741
+ keys: JWK[]
742
+ }
743
+
744
+ /**
745
+ * {@link !KeyObject} is a representation of a key/secret available in the Node.js runtime. You may
746
+ * use the Node.js runtime APIs {@link !createPublicKey}, {@link !createPrivateKey}, and
747
+ * {@link !createSecretKey} to obtain a {@link !KeyObject} from your existing key material.
748
+ */
749
+ export interface KeyObject {
750
+ type: string
751
+ }
752
+
753
+ /**
754
+ * {@link !CryptoKey} is a representation of a key/secret available in all supported runtimes. In
755
+ * addition to the {@link key/import Key Import Functions} you may use the
756
+ * {@link !SubtleCrypto.importKey} API to obtain a {@link !CryptoKey} from your existing key
757
+ * material.
758
+ */
759
+ export type CryptoKey = Extract<
760
+ Awaited<ReturnType<typeof crypto.subtle.generateKey>>,
761
+ { type: string }
762
+ >
763
+
764
+ /** Generic interface for JWT producing classes. */
765
+ export interface ProduceJWT {
766
+ /**
767
+ * Set the "iss" (Issuer) Claim.
768
+ *
769
+ * @param issuer "Issuer" Claim value to set on the JWT Claims Set.
770
+ */
771
+ setIssuer(issuer: string): this
772
+
773
+ /**
774
+ * Set the "sub" (Subject) Claim.
775
+ *
776
+ * @param subject "sub" (Subject) Claim value to set on the JWT Claims Set.
777
+ */
778
+ setSubject(subject: string): this
779
+
780
+ /**
781
+ * Set the "aud" (Audience) Claim.
782
+ *
783
+ * @param audience "aud" (Audience) Claim value to set on the JWT Claims Set.
784
+ */
785
+ setAudience(audience: string | string[]): this
786
+
787
+ /**
788
+ * Set the "jti" (JWT ID) Claim.
789
+ *
790
+ * @param jwtId "jti" (JWT ID) Claim value to set on the JWT Claims Set.
791
+ */
792
+ setJti(jwtId: string): this
793
+
794
+ /**
795
+ * Set the "nbf" (Not Before) Claim.
796
+ *
797
+ * - If a `number` is passed as an argument it is used as the claim directly.
798
+ * - If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the
799
+ * claim.
800
+ * - If a `string` is passed as an argument it is resolved to a time span, and then added to the
801
+ * current unix timestamp and used as the claim.
802
+ *
803
+ * Format used for time span should be a number followed by a unit, such as "5 minutes" or "1
804
+ * day".
805
+ *
806
+ * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins",
807
+ * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year",
808
+ * "years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an
809
+ * alias for a year.
810
+ *
811
+ * If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets
812
+ * subtracted from the current unix timestamp. A "from now" suffix can also be used for
813
+ * readability when adding to the current unix timestamp.
814
+ *
815
+ * @param input "nbf" (Not Before) Claim value to set on the JWT Claims Set.
816
+ */
817
+ setNotBefore(input: number | string | Date): this
818
+
819
+ /**
820
+ * Set the "exp" (Expiration Time) Claim.
821
+ *
822
+ * - If a `number` is passed as an argument it is used as the claim directly.
823
+ * - If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the
824
+ * claim.
825
+ * - If a `string` is passed as an argument it is resolved to a time span, and then added to the
826
+ * current unix timestamp and used as the claim.
827
+ *
828
+ * Format used for time span should be a number followed by a unit, such as "5 minutes" or "1
829
+ * day".
830
+ *
831
+ * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins",
832
+ * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year",
833
+ * "years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an
834
+ * alias for a year.
835
+ *
836
+ * If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets
837
+ * subtracted from the current unix timestamp. A "from now" suffix can also be used for
838
+ * readability when adding to the current unix timestamp.
839
+ *
840
+ * @param input "exp" (Expiration Time) Claim value to set on the JWT Claims Set.
841
+ */
842
+ setExpirationTime(input: number | string | Date): this
843
+
844
+ /**
845
+ * Set the "iat" (Issued At) Claim.
846
+ *
847
+ * - If no argument is used the current unix timestamp is used as the claim.
848
+ * - If a `number` is passed as an argument it is used as the claim directly.
849
+ * - If a `Date` instance is passed as an argument it is converted to unix timestamp and used as the
850
+ * claim.
851
+ * - If a `string` is passed as an argument it is resolved to a time span, and then added to the
852
+ * current unix timestamp and used as the claim.
853
+ *
854
+ * Format used for time span should be a number followed by a unit, such as "5 minutes" or "1
855
+ * day".
856
+ *
857
+ * Valid units are: "sec", "secs", "second", "seconds", "s", "minute", "minutes", "min", "mins",
858
+ * "m", "hour", "hours", "hr", "hrs", "h", "day", "days", "d", "week", "weeks", "w", "year",
859
+ * "years", "yr", "yrs", and "y". It is not possible to specify months. 365.25 days is used as an
860
+ * alias for a year.
861
+ *
862
+ * If the string is suffixed with "ago", or prefixed with a "-", the resulting time span gets
863
+ * subtracted from the current unix timestamp. A "from now" suffix can also be used for
864
+ * readability when adding to the current unix timestamp.
865
+ *
866
+ * @param input "iat" (Expiration Time) Claim value to set on the JWT Claims Set.
867
+ */
868
+ setIssuedAt(input?: number | string | Date): this
869
+ }