unjwt 0.5.38 → 0.5.40

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 (41) hide show
  1. package/README.md +148 -670
  2. package/dist/_chunks/chunk.mjs +13 -0
  3. package/dist/_chunks/index.d.mts +558 -0
  4. package/dist/_chunks/index2.d.mts +108 -0
  5. package/dist/_chunks/jwe.d.mts +43 -0
  6. package/dist/_chunks/jwe.mjs +132 -0
  7. package/dist/_chunks/jwk.d.mts +611 -0
  8. package/dist/_chunks/jwk.mjs +1592 -0
  9. package/dist/_chunks/jws.d.mts +242 -0
  10. package/dist/_chunks/jws.mjs +2070 -0
  11. package/dist/_chunks/jws2.mjs +598 -0
  12. package/dist/_chunks/utils.mjs +375 -0
  13. package/dist/adapters/h3.d.mts +3 -267
  14. package/dist/adapters/h3.mjs +3 -704
  15. package/dist/adapters/h3v1.d.mts +3 -8
  16. package/dist/adapters/h3v1.mjs +3 -7
  17. package/dist/adapters/h3v2.d.mts +145 -147
  18. package/dist/adapters/h3v2.mjs +501 -594
  19. package/dist/index.d.mts +6 -8
  20. package/dist/index.mjs +5 -4
  21. package/dist/jwe.d.mts +3 -4
  22. package/dist/jwe.mjs +2 -3
  23. package/dist/jwk.d.mts +3 -2
  24. package/dist/jwk.mjs +2 -2
  25. package/dist/jws.d.mts +3 -3
  26. package/dist/jws.mjs +2 -3
  27. package/dist/utils.d.mts +3 -3
  28. package/dist/utils.mjs +2 -1
  29. package/package.json +33 -31
  30. package/dist/shared/unjwt.4JQCoID_.d.mts +0 -161
  31. package/dist/shared/unjwt.B-v62plj.mjs +0 -249
  32. package/dist/shared/unjwt.BCi3FEWr.d.mts +0 -328
  33. package/dist/shared/unjwt.BYDTEWa-.d.mts +0 -269
  34. package/dist/shared/unjwt.Be8NxwFK.mjs +0 -438
  35. package/dist/shared/unjwt.BqdNUKDr.d.mts +0 -64
  36. package/dist/shared/unjwt.CMNtw8ek.d.mts +0 -155
  37. package/dist/shared/unjwt.Cy2MlkUe.d.mts +0 -174
  38. package/dist/shared/unjwt.D0_ccT7g.d.mts +0 -166
  39. package/dist/shared/unjwt.DdLN9vwI.mjs +0 -163
  40. package/dist/shared/unjwt.Dpl__ZAR.mjs +0 -2121
  41. package/dist/shared/unjwt.JdKqVANs.d.mts +0 -5
@@ -0,0 +1,611 @@
1
+ //#region src/core/types/jwk.d.ts
2
+ /** Structure returned for composite AES-CBC + HMAC keys. */
3
+ type CompositeKey = {
4
+ /** The AES-CBC encryption/decryption key. */encryptionKey: CryptoKey; /** The HMAC key for integrity/authentication. */
5
+ macKey: CryptoKey;
6
+ };
7
+ type GenerateKeyAlgorithm = Exclude<JWKAlgorithm, "none" | "dir" | JWK_PBES2>;
8
+ /** Options for the generateKey function. */
9
+ interface GenerateKeyOptions {
10
+ /** Key usages for the generated key(s). Note: For composite keys (CBC), default usages are applied separately. */
11
+ keyUsage?: KeyUsage[];
12
+ /** Mark the key(s) as extractable. Defaults to true. */
13
+ extractable?: boolean;
14
+ /** RSA modulus length. Defaults to 2048. */
15
+ modulusLength?: number;
16
+ /** RSA public exponent. Defaults to 65537 (0x010001). */
17
+ publicExponent?: Uint8Array<ArrayBuffer>;
18
+ /** Named curve for EC or OKP keys. Defaults to "P-256" for EC and "Ed25519" for OKP. */
19
+ namedCurve?: "P-256" | "P-384" | "P-521" | "X25519" | "Ed25519" | "Ed448";
20
+ /** Export the generated key(s) as JWK. If true, the key(s) will be returned in JWK format. */
21
+ toJWK?: undefined | boolean | Omit<JWKParameters, "alg" | "kty" | "key_ops" | "ext">;
22
+ }
23
+ type GenerateKeyReturnJWK<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_Asymmetric_Algorithm ? TAlg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC ? {
24
+ privateKey: JWK_RSA_Private;
25
+ publicKey: JWK_RSA_Public;
26
+ } : TAlg extends JWK_ECDSA | JWK_ECDH_ES ? {
27
+ privateKey: JWK_EC_Private;
28
+ publicKey: JWK_EC_Public;
29
+ } : TAlg extends JWK_OKP_SIGN ? {
30
+ privateKey: JWK_OKP_Private;
31
+ publicKey: JWK_OKP_Public;
32
+ } : never : TAlg extends JWK_AES_CBC_HMAC | JWK_Symmetric_Algorithm ? JWK_oct : never;
33
+ type GenerateKeyReturnCrypto<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_AES_CBC_HMAC ? Uint8Array<ArrayBuffer> : TAlg extends JWK_Asymmetric_Algorithm ? CryptoKeyPair : CryptoKey;
34
+ type GenerateKeyReturn<TAlg extends GenerateKeyAlgorithm, TOptions extends GenerateKeyOptions> = TOptions["toJWK"] extends true ? GenerateKeyReturnJWK<TAlg> : TOptions["toJWK"] extends object ? GenerateKeyReturnJWK<TAlg> : GenerateKeyReturnCrypto<TAlg>;
35
+ type GenerateJWKOptions = Omit<GenerateKeyOptions, "toJWK">;
36
+ type GenerateJWKReturn<TAlg extends GenerateKeyAlgorithm> = GenerateKeyReturnJWK<TAlg>;
37
+ /** Options for the deriveKeyFromPassword function. */
38
+ interface DeriveKeyOptions {
39
+ /** Salt value (p2s). Must be at least 8 bytes. */
40
+ salt: Uint8Array<ArrayBuffer>;
41
+ /** Iteration count (p2c). Must be a positive integer. */
42
+ iterations: number;
43
+ /** Key usages for the derived key. Defaults to ["wrapKey", "unwrapKey"]. */
44
+ keyUsage?: KeyUsage[];
45
+ /** Mark the derived key as extractable. Defaults to false. */
46
+ extractable?: boolean;
47
+ /** Export the derived key as JWK. If true, the key will be returned in JWK_oct format. */
48
+ toJWK?: undefined | boolean | Omit<JWKParameters, "alg" | "kty" | "key_ops" | "ext">;
49
+ }
50
+ type DeriveKeyReturn<TOptions extends DeriveKeyOptions> = TOptions["toJWK"] extends true ? JWK_oct : TOptions["toJWK"] extends object ? JWK_oct : CryptoKey;
51
+ type KeyManagementAlgorithm = JWK_RSA_ENC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_PBES2 | JWK_ECDH_ES;
52
+ type ContentEncryptionAlgorithm = JWK_AES_GCM | JWK_AES_CBC_HMAC;
53
+ /** Options for the wrapKey function. */
54
+ interface WrapKeyOptions {
55
+ /** Initialization Vector for AES-GCMKW. Generated if not provided. */
56
+ iv?: Uint8Array<ArrayBuffer>;
57
+ /** PBES2 Salt value (p2s). Required for PBES2 algorithms. */
58
+ p2s?: Uint8Array<ArrayBuffer>;
59
+ /** PBES2 Iteration count (p2c). Required for PBES2 algorithms. */
60
+ p2c?: number;
61
+ /** ECDH-ES Ephemeral Public Key. Generated if not provided for ECDH-ES. */
62
+ epk?: JWK_EC_Public;
63
+ /** ECDH-ES Agreement PartyUInfo. */
64
+ apu?: Uint8Array<ArrayBuffer>;
65
+ /** ECDH-ES Agreement PartyVInfo. */
66
+ apv?: Uint8Array<ArrayBuffer>;
67
+ }
68
+ /** Result of the wrapKey function. */
69
+ interface WrapKeyResult {
70
+ /** The wrapped key (Ciphertext). */
71
+ encryptedKey: Uint8Array<ArrayBuffer>;
72
+ /** Initialization Vector used (only for AES-GCMKW). Base64URL encoded. */
73
+ iv?: string;
74
+ /** Authentication Tag generated (only for AES-GCMKW). Base64URL encoded. */
75
+ tag?: string;
76
+ /** PBES2 Salt value used (only for PBES2). Base64URL encoded. */
77
+ p2s?: string;
78
+ /** PBES2 Iteration count used (only for PBES2). */
79
+ p2c?: number;
80
+ /** ECDH-ES Ephemeral Public Key used (only for ECDH-ES). */
81
+ epk?: JWK_EC_Public;
82
+ /** ECDH-ES Agreement PartyUInfo used (only for ECDH-ES). Base64URL encoded. */
83
+ apu?: string;
84
+ /** ECDH-ES Agreement PartyVInfo used (only for ECDH-ES). Base64URL encoded. */
85
+ apv?: string;
86
+ }
87
+ /** Options for the unwrapKey function. */
88
+ interface UnwrapKeyOptions {
89
+ /** Initialization Vector (required for AES-GCMKW). Base64URL encoded or Uint8Array. */
90
+ iv?: Uint8Array<ArrayBuffer> | string;
91
+ /** Authentication Tag (required for AES-GCMKW). Base64URL encoded or Uint8Array. */
92
+ tag?: Uint8Array<ArrayBuffer> | string;
93
+ /** PBES2 Salt value (required for PBES2). Base64URL encoded or Uint8Array. */
94
+ p2s?: Uint8Array<ArrayBuffer> | string;
95
+ /** PBES2 Iteration count (required for PBES2). */
96
+ p2c?: number;
97
+ /** ECDH-ES Ephemeral Public Key (required for ECDH-ES). */
98
+ epk?: JWK_EC_Public | CryptoKey;
99
+ /** ECDH-ES Agreement PartyUInfo. Base64URL encoded or Uint8Array. */
100
+ apu?: Uint8Array<ArrayBuffer> | string;
101
+ /** ECDH-ES Agreement PartyVInfo. Base64URL encoded or Uint8Array. */
102
+ apv?: Uint8Array<ArrayBuffer> | string;
103
+ /** Content Encryption Algorithm used with ECDH-ES (required for direct key agreement). */
104
+ enc?: ContentEncryptionAlgorithm;
105
+ /** Expected unwrapped key algorithm (e.g., 'AES-GCM', 'AES-CBC'). Used by crypto.subtle.unwrapKey. */
106
+ unwrappedKeyAlgorithm?: string | Algorithm | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams;
107
+ /** Expected key usages for the unwrapped key. */
108
+ keyUsage?: KeyUsage[];
109
+ /** Mark the unwrapped key as extractable. Defaults to true. */
110
+ extractable?: boolean;
111
+ returnAs?: boolean | undefined;
112
+ }
113
+ /**
114
+ * Forked from https://github.com/panva/jose/tree/v6.0.10
115
+ * Copyright (c) 2018 Filip Skokan.
116
+ * LICENSE: https://github.com/panva/jose/blob/v6.0.10/LICENSE.md
117
+ */
118
+ /** Generic JSON Web Key Parameters. */
119
+ interface JWKParameters {
120
+ /** JWK "kty" (Key Type) Parameter */
121
+ kty: string;
122
+ /**
123
+ * JWK "alg" (Algorithm) Parameter
124
+ *
125
+ * @see {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}
126
+ */
127
+ alg?: string;
128
+ /** JWK "key_ops" (Key Operations) Parameter */
129
+ key_ops?: KeyUsage[];
130
+ /** JWK "ext" (Extractable) Parameter */
131
+ ext?: boolean;
132
+ /** JWK "use" (Public Key Use) Parameter */
133
+ use?: string;
134
+ /** JWK "x5c" (X.509 Certificate Chain) Parameter */
135
+ x5c?: string[];
136
+ /** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter */
137
+ x5t?: string;
138
+ /** JWK "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter */
139
+ "x5t#S256"?: string;
140
+ /** JWK "x5u" (X.509 URL) Parameter */
141
+ x5u?: string;
142
+ /** JWK "kid" (Key ID) Parameter */
143
+ kid?: string;
144
+ }
145
+ /** Public EC JSON Web Keys */
146
+ interface JWK_EC_Public extends JWKParameters {
147
+ /** EC JWK "kty" (Key Type) Parameter */
148
+ kty: "EC";
149
+ /** EC JWK "crv" (Curve) Parameter */
150
+ crv: string;
151
+ /** EC JWK "x" (X Coordinate) Parameter */
152
+ x: string;
153
+ /** EC JWK "y" (Y Coordinate) Parameter */
154
+ y: string;
155
+ }
156
+ /** Private EC JSON Web Keys */
157
+ interface JWK_EC_Private extends JWK_EC_Public {
158
+ /** EC JWK "d" (ECC Private Key) Parameter */
159
+ d: string;
160
+ }
161
+ /** EC JSON Web Keys */
162
+ type JWK_EC = JWK_EC_Public | JWK_EC_Private;
163
+ /** Public RSA JSON Web Keys */
164
+ interface JWK_RSA_Public extends JWKParameters {
165
+ /** RSA JWK "kty" (Key Type) Parameter */
166
+ kty: "RSA";
167
+ /** RSA JWK "e" (Exponent) Parameter */
168
+ e: string;
169
+ /** RSA JWK "n" (Modulus) Parameter */
170
+ n: string;
171
+ oth?: RsaOtherPrimesInfo[];
172
+ }
173
+ /** Private RSA JSON Web Keys */
174
+ interface JWK_RSA_Private extends JWK_RSA_Public {
175
+ /** RSA JWK "d" (Private Exponent) Parameter */
176
+ d: string;
177
+ /** RSA JWK "dp" (First Factor CRT Exponent) Parameter */
178
+ dp: string;
179
+ /** RSA JWK "dq" (Second Factor CRT Exponent) Parameter */
180
+ dq: string;
181
+ /** RSA JWK "p" (First Prime Factor) Parameter */
182
+ p: string;
183
+ /** RSA JWK "q" (Second Prime Factor) Parameter */
184
+ q: string;
185
+ /** RSA JWK "qi" (First CRT Coefficient) Parameter */
186
+ qi: string;
187
+ }
188
+ /** RSA JSON Web Keys */
189
+ type JWK_RSA = JWK_RSA_Public | JWK_RSA_Private;
190
+ /** Public ED JSON Web Keys */
191
+ interface JWK_OKP_Public extends JWKParameters {
192
+ /** ED JWK "kty" (Key Type) Parameter */
193
+ kty: "OKP";
194
+ /** ED JWK "crv" (Curve) Parameter */
195
+ crv: string;
196
+ /** ED JWK "x" (X Coordinate) Parameter */
197
+ x: string;
198
+ }
199
+ /** Private ED JSON Web Keys */
200
+ interface JWK_OKP_Private extends JWK_OKP_Public {
201
+ /** ED JWK "d" (Private Key) Parameter */
202
+ d: string;
203
+ }
204
+ /** OKP JSON Web Keys */
205
+ type JWK_OKP = JWK_OKP_Public | JWK_OKP_Private;
206
+ /** oct JSON Web Keys */
207
+ interface JWK_oct extends JWKParameters {
208
+ /** Oct JWK "k" (Key Value) Parameter */
209
+ k: string;
210
+ }
211
+ /** Symmetric JSON Web Keys */
212
+ type JWK_Symmetric = JWK_oct;
213
+ /** Asymmetric JSON Web Keys */
214
+ type JWK_Asymmetric = JWK_RSA | JWK_EC | JWK_OKP;
215
+ /** Public JSON Web Keys */
216
+ type JWK_Public = JWK_RSA_Public | JWK_EC_Public | JWK_OKP_Public;
217
+ /** Private JSON Web Keys */
218
+ type JWK_Private = JWK_RSA_Private | JWK_EC_Private | JWK_OKP_Private;
219
+ /**
220
+ * JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC", "OKP" and "oct" key types are supported.
221
+ */
222
+ type JWK = JWK_oct | JWK_RSA | JWK_EC | JWK_OKP;
223
+ /**
224
+ * A pair of public and private JSON Web Keys.
225
+ */
226
+ type JWK_Pair = {
227
+ publicKey: JWK_RSA_Public;
228
+ privateKey: JWK_RSA_Private;
229
+ } | {
230
+ publicKey: JWK_EC_Public;
231
+ privateKey: JWK_EC_Private;
232
+ } | {
233
+ publicKey: JWK_OKP_Public;
234
+ privateKey: JWK_OKP_Private;
235
+ };
236
+ /**
237
+ * JSON Web Key Set ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK Set}). "RSA", "EC" and "oct" key types are supported.
238
+ */
239
+ interface JWKSet {
240
+ /** JWK Set "keys" Parameter */
241
+ keys: JWK[];
242
+ [parameter: string]: unknown;
243
+ }
244
+ /** JWK Key Algorithms */
245
+ type JWK_HMAC = "HS256" | "HS384" | "HS512";
246
+ type JWK_RSA_SIGN = "RS256" | "RS384" | "RS512";
247
+ type JWK_RSA_PSS = "PS256" | "PS384" | "PS512";
248
+ type JWK_ECDSA = "ES256" | "ES384" | "ES512";
249
+ type JWK_RSA_ENC = "RSA-OAEP" | "RSA-OAEP-256" | "RSA-OAEP-384" | "RSA-OAEP-512";
250
+ type JWK_AES_KW = "A128KW" | "A192KW" | "A256KW";
251
+ type JWK_AES_CBC_HMAC = "A128CBC-HS256" | "A192CBC-HS384" | "A256CBC-HS512";
252
+ type JWK_AES_GCM = "A128GCM" | "A192GCM" | "A256GCM";
253
+ type JWK_AES_GCM_KW = "A128GCMKW" | "A192GCMKW" | "A256GCMKW";
254
+ type JWK_PBES2 = "PBES2-HS256+A128KW" | "PBES2-HS384+A192KW" | "PBES2-HS512+A256KW";
255
+ type JWK_ECDH_ES = "ECDH-ES" | "ECDH-ES+A128KW" | "ECDH-ES+A192KW" | "ECDH-ES+A256KW";
256
+ type JWK_OKP_SIGN = "Ed25519" | "EdDSA";
257
+ type JWK_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW;
258
+ type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC | JWK_OKP_SIGN | JWK_ECDH_ES;
259
+ type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES | ("none" | "dir");
260
+ type JWKPEMAlgorithm = JWK_RSA_PSS | JWK_RSA_SIGN | JWK_RSA_ENC | JWK_ECDSA | JWK_ECDH_ES | JWK_OKP_SIGN;
261
+ //#endregion
262
+ //#region src/core/types/jwt.d.ts
263
+ /** Header Parameters common to JWE and JWS */
264
+ interface JoseHeaderParameters {
265
+ /** "kid" (Key ID) Header Parameter */
266
+ kid?: string;
267
+ /** "x5t" (X.509 Certificate SHA-1 Thumbprint) Header Parameter */
268
+ x5t?: string;
269
+ /** "x5c" (X.509 Certificate Chain) Header Parameter */
270
+ x5c?: string[];
271
+ /** "x5u" (X.509 URL) Header Parameter */
272
+ x5u?: string;
273
+ /** "jku" (JWK Set URL) Header Parameter */
274
+ jku?: string;
275
+ /** "jwk" (JSON Web Key) Header Parameter */
276
+ jwk?: JWK_Public;
277
+ /** "typ" (Type) Header Parameter */
278
+ typ?: string;
279
+ /** "cty" (Content Type) Header Parameter */
280
+ cty?: string;
281
+ /** "crit" (Critical) Header Parameter */
282
+ crit?: string[];
283
+ /** Any other JWS/JWE Header member. */
284
+ [propName: string]: unknown;
285
+ }
286
+ interface JWTClaims {
287
+ /** "iss" (Issuer) Claim */
288
+ iss?: string;
289
+ /** "sub" (Subject) Claim */
290
+ sub?: string;
291
+ /** "aud" (Audience) Claim */
292
+ aud?: string | string[];
293
+ /** "exp" (Expiration Time) Claim */
294
+ exp?: number;
295
+ /** "nbf" (Not Before) Claim */
296
+ nbf?: number;
297
+ /** "iat" (Issued At) Claim */
298
+ iat?: number;
299
+ /** "jti" (JWT ID) Claim */
300
+ jti?: string;
301
+ /** Any other JWT member. */
302
+ [propName: string]: unknown;
303
+ }
304
+ interface JWT<T = JWTClaims> {
305
+ header: JoseHeaderParameters & {
306
+ /** "alg" (Algorithm) Header Parameter */alg: string;
307
+ };
308
+ claims: T;
309
+ }
310
+ interface JWTClaimValidationOptions {
311
+ /** Expected JWT "aud" (Audience) Claim value(s). Implies presence requirement. */
312
+ audience?: string | string[];
313
+ /** Expected JWT "iss" (Issuer) Claim value(s). Implies presence requirement. */
314
+ issuer?: string | string[];
315
+ /** Expected JWT "sub" (Subject) Claim value. Implies presence requirement. */
316
+ subject?: string;
317
+ /** Maximum token age, from the JWT "iat" (Issued At) Claim value. Implies presence requirement. */
318
+ maxTokenAge?: MaxTokenAge;
319
+ /** Clock skew tolerance (in seconds) for validating time-based claims (nbf/exp/iat). */
320
+ clockTolerance?: number;
321
+ /** Expected JWT "typ" (Type) Header Parameter value. Implies presence requirement. */
322
+ typ?: string;
323
+ /** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
324
+ currentDate?: Date;
325
+ /** Additional required claim names. */
326
+ requiredClaims?: string[];
327
+ /** List of critical header parameters that must be understood and processed. */
328
+ requiredHeaders?: string[];
329
+ /**
330
+ * Critical Header Parameters to be understood and processed.
331
+ * If the JWT contains critical headers not in this list (and not inherently understood by the library), decryption will fail.
332
+ * @deprecated use {@link requiredHeaders `recognizedHeaders` option} instead.
333
+ */
334
+ critical?: string[];
335
+ }
336
+ //#endregion
337
+ //#region src/core/types/jws.d.ts
338
+ type JWS_SIGN_EXTRA = "Ed25519" | "EdDSA";
339
+ /** JWS Signing Algorithm Identifier. */
340
+ type JWSAlgorithm = JWK_HMAC | JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWS_SIGN_EXTRA;
341
+ /** Recognized JWS Header Parameters, any other Header Members may also be present. */
342
+ interface JWSHeaderParameters extends JoseHeaderParameters {
343
+ /** JWS "alg" (Algorithm) Header Parameter */
344
+ alg?: JWSAlgorithm;
345
+ /**
346
+ * This JWS Extension Header Parameter modifies the JWS Payload representation and the JWS Signing
347
+ * Input computation as per {@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}.
348
+ * If `false`, the payload is used directly without Base64URL encoding.
349
+ * Defaults to `true`.
350
+ */
351
+ b64?: boolean;
352
+ }
353
+ /** JWS Protected Header */
354
+ interface JWSProtectedHeader extends JWSHeaderParameters {
355
+ alg: JWSAlgorithm;
356
+ }
357
+ /**
358
+ * JWS (JSON Web Signature) options for signing
359
+ */
360
+ interface JWSSignOptions {
361
+ /** The JWS Algorithm to use. Must be provided. */
362
+ alg?: JWSAlgorithm;
363
+ /**
364
+ * Additional protected header parameters. `alg` is automatically included.
365
+ * `typ` defaults to "JWT" if not provided and payload is an object.
366
+ */
367
+ protectedHeader?: JWSHeaderParameters;
368
+ /** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
369
+ currentDate?: Date;
370
+ /**
371
+ * Time at which the JWS should expire, if no `exp` was already provided.
372
+ */
373
+ expiresIn?: ExpiresIn;
374
+ }
375
+ /** Result of JWS verification */
376
+ interface JWSVerifyResult<T extends JWTClaims | Uint8Array<ArrayBuffer> | string = JWTClaims | Uint8Array<ArrayBuffer> | string> {
377
+ /** The decoded and verified payload. */
378
+ payload: T;
379
+ /** The JWS Protected Header. */
380
+ protectedHeader: JWSProtectedHeader;
381
+ }
382
+ /** Options for JWS verification */
383
+ interface JWSVerifyOptions extends JWTClaimValidationOptions {
384
+ /** List of allowed algorithms. If provided, the JWS `alg` must be in this list. */
385
+ algorithms?: JWSAlgorithm[];
386
+ /** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred. */
387
+ forceUint8Array?: boolean;
388
+ /** Unless false, will parse payload as JWT and validate claims if applicable (typ "JWT"). */
389
+ validateJWT?: boolean;
390
+ }
391
+ /**
392
+ * Key lookup function for JWS verification.
393
+ * @param header The JWS Protected Header.
394
+ * @param token The JWS token.
395
+ * @returns The key material (CryptoKey, JWK, or raw Uint8Array) or a Promise resolving to it.
396
+ */
397
+ type JWSKeyLookupFunction = (header: JWSProtectedHeader, token: string) => CryptoKey | JWK | JWKSet | Uint8Array<ArrayBuffer> | Promise<CryptoKey | JWK | JWKSet | Uint8Array<ArrayBuffer>>;
398
+ //#endregion
399
+ //#region src/core/utils/types.d.ts
400
+ type StrictOmit<T, K extends keyof T | (string & {}) | (number & {}) | (symbol & {})> = { [P in keyof T as P extends K ? never : P]: T[P] };
401
+ //#endregion
402
+ //#region src/core/types/jwe.d.ts
403
+ /** Recognized JWE Header Parameters, any other Header Members may also be present. */
404
+ interface JWEHeaderParameters extends JoseHeaderParameters {
405
+ /**
406
+ * `alg` (Algorithm): Header Parameter - Key Management Algorithm
407
+ */
408
+ alg?: string;
409
+ /**
410
+ * `enc` (Encryption Algorithm): Header Parameter - Content Encryption Algorithm
411
+ */
412
+ enc?: string;
413
+ /**
414
+ * `p2c` (PBES2 Count): Header Parameter
415
+ */
416
+ p2c?: number;
417
+ /**
418
+ * `p2s` (PBES2 Salt): Header Parameter. Base64URL encoded.
419
+ */
420
+ p2s?: string;
421
+ /**
422
+ * "iv" (Initialization Vector) Header Parameter for AES GCM Key Wrapping. Base64URL encoded.
423
+ */
424
+ iv?: string;
425
+ /**
426
+ * "tag" (Authentication Tag) Header Parameter for AES GCM Key Wrapping. Base64URL encoded.
427
+ */
428
+ tag?: string;
429
+ /**
430
+ * "epk" (Ephemeral Public Key) Header Parameter for ECDH-ES.
431
+ */
432
+ epk?: JWK_EC_Public;
433
+ /**
434
+ * "apu" (Agreement PartyUInfo) Header Parameter for ECDH-ES. Base64URL encoded.
435
+ */
436
+ apu?: string;
437
+ /**
438
+ * "apv" (Agreement PartyVInfo) Header Parameter for ECDH-ES. Base64URL encoded.
439
+ */
440
+ apv?: string;
441
+ /** Any other JWE Header member. */
442
+ [propName: string]: unknown;
443
+ }
444
+ /** Recognized JWE Key Management-related Header Parameters. */
445
+ interface JWEKeyManagementHeaderParameters {
446
+ apu?: Uint8Array<ArrayBuffer>;
447
+ apv?: Uint8Array<ArrayBuffer>;
448
+ /**
449
+ * For Internal use only
450
+ */
451
+ p2c?: number;
452
+ /**
453
+ * For Internal use only
454
+ */
455
+ p2s?: Uint8Array<ArrayBuffer>;
456
+ /**
457
+ * For Internal use only
458
+ */
459
+ iv?: Uint8Array<ArrayBuffer>;
460
+ /**
461
+ * For Internal use only
462
+ */
463
+ epk?: CryptoKey | JWK_EC_Public;
464
+ /**
465
+ * For Internal use only
466
+ */
467
+ epkPrivateKey?: CryptoKey | JWK_EC_Private;
468
+ }
469
+ /**
470
+ * JWE (JSON Web Encryption) encryption options
471
+ */
472
+ interface JWEEncryptOptions {
473
+ /** JWE "alg" (Algorithm) Header Parameter. Key Management Algorithm. */
474
+ alg?: KeyManagementAlgorithm;
475
+ /** JWE "enc" (Encryption Algorithm) Header Parameter. Content Encryption Algorithm. */
476
+ enc?: ContentEncryptionAlgorithm;
477
+ /** Date to use when computing NumericDate claims, defaults to `new Date()`. */
478
+ currentDate?: Date;
479
+ /** Time at which the JWT should expire, if no `exp` was already provided (only when typ is "JWT" or explicitly parsing JWT). */
480
+ expiresIn?: ExpiresIn;
481
+ /** Additional JWE Protected Header parameters. */
482
+ protectedHeader?: StrictOmit<JWEHeaderParameters, "alg" | "enc" | "iv" | "tag" | "p2s" | "p2c" | "epk" | "apu" | "apv">;
483
+ /** Initialization Vector for AES-GCMKW key wrapping. Generated if not provided. */
484
+ keyManagementIV?: Uint8Array<ArrayBuffer>;
485
+ /** PBES2 Salt value (p2s). Required for PBES2 algorithms. */
486
+ p2s?: Uint8Array<ArrayBuffer>;
487
+ /** PBES2 Iteration count (p2c). Required for PBES2 algorithms. */
488
+ p2c?: number;
489
+ /** ECDH-ES specific options. */
490
+ ecdh?: {
491
+ /**
492
+ * ECDH-ES Ephemeral key material. Provide a private key (CryptoKey or JWK),
493
+ * a CryptoKeyPair, or an object exposing both public and private parts.
494
+ */
495
+ ephemeralKey?: CryptoKey | JWK_EC_Private | CryptoKeyPair | {
496
+ publicKey: CryptoKey | JWK_EC_Public;
497
+ privateKey: CryptoKey | JWK_EC_Private;
498
+ }; /** ECDH-ES Agreement PartyUInfo. */
499
+ partyUInfo?: Uint8Array<ArrayBuffer>; /** ECDH-ES Agreement PartyVInfo. */
500
+ partyVInfo?: Uint8Array<ArrayBuffer>;
501
+ };
502
+ /**
503
+ * Content Encryption Key (CEK) to use.
504
+ * If provided, it will be used directly. Otherwise, a CEK will be generated.
505
+ */
506
+ cek?: Uint8Array<ArrayBuffer>;
507
+ /**
508
+ * Initialization Vector for content encryption.
509
+ * If provided, it will be used. Otherwise, one will be generated.
510
+ */
511
+ contentEncryptionIV?: Uint8Array<ArrayBuffer>;
512
+ }
513
+ /**
514
+ * Key lookup function for JWE decryption.
515
+ * @param header The JWE Protected Header.
516
+ * @returns The key material (CryptoKey, JWK, password string, or raw Uint8Array) or a Promise resolving to it.
517
+ */
518
+ type JWEKeyLookupFunction = (header: JWEHeaderParameters, token: string) => CryptoKey | JWK | string | Uint8Array<ArrayBuffer> | Promise<CryptoKey | JWK | string | Uint8Array<ArrayBuffer>>;
519
+ /**
520
+ * JWE (JSON Web Encryption) decryption options
521
+ */
522
+ interface JWEDecryptOptions extends JWTClaimValidationOptions {
523
+ /** A list of allowed JWE "alg" (Algorithm) Header Parameter values for key management. */
524
+ algorithms?: KeyManagementAlgorithm[];
525
+ /** A list of allowed JWE "enc" (Encryption Algorithm) Header Parameter values for content encryption. */
526
+ encryptionAlgorithms?: ContentEncryptionAlgorithm[];
527
+ /** Algorithm to import the unwrapped CEK as (e.g., { name: 'AES-GCM' }). Defaults based on 'enc'. */
528
+ unwrappedKeyAlgorithm?: Parameters<typeof crypto.subtle.importKey>[2];
529
+ /** Key usages for the unwrapped CEK. Defaults based on 'enc' (typically ['encrypt', 'decrypt']). */
530
+ keyUsage?: KeyUsage[];
531
+ /** Mark the unwrapped CEK as extractable. Defaults to true. */
532
+ extractable?: boolean;
533
+ /** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred based on JWE headers. */
534
+ forceUint8Array?: boolean;
535
+ /** Unless false, will parse payload as JWT and validate claims if applicable (typ "JWT"). */
536
+ validateJWT?: boolean;
537
+ /** If true, include the Content Encryption Key (CEK) and Additional Authenticated Data (AAD) in the result. */
538
+ returnCek?: boolean;
539
+ }
540
+ /**
541
+ * Result of a JWE decryption operation.
542
+ */
543
+ interface JWEDecryptResult<T extends JWTClaims | Uint8Array<ArrayBuffer> | string = JWTClaims | Uint8Array<ArrayBuffer> | string> {
544
+ /** The decrypted payload. */
545
+ payload: T;
546
+ /** The JWE Protected Header. */
547
+ protectedHeader: JWEHeaderParameters;
548
+ /** The Content Encryption Key (CEK) used for decryption, as Uint8Array. Only present when `returnCek` is true. */
549
+ cek?: Uint8Array<ArrayBuffer>;
550
+ /** The Additional Authenticated Data (AAD) used, as Uint8Array. Only present when `returnCek` is true. */
551
+ aad?: Uint8Array<ArrayBuffer>;
552
+ }
553
+ //#endregion
554
+ //#region src/core/types/index.d.ts
555
+ type ExpiresIn = number | `${number}` | `${number}${"s" | "second" | "seconds" | "m" | "minute" | "minutes" | "h" | "hour" | "hours" | "D" | "day" | "days" | "W" | "week" | "weeks" | "M" | "month" | "months" | "Y" | "year" | "years"}`;
556
+ type MaxTokenAge = ExpiresIn;
557
+ //#endregion
558
+ //#region src/core/jose/asn1.d.ts
559
+ /** Key Import Function options. */
560
+ interface KeyImportOptions {
561
+ /**
562
+ * The value to use as {@link !SubtleCrypto.importKey} `extractable` argument. Default is false for
563
+ * private keys, true otherwise.
564
+ */
565
+ extractable?: boolean;
566
+ }
567
+ //#endregion
568
+ //#region src/core/jwk.d.ts
569
+ /**
570
+ * Generates a Json Web Key (JWK) for the specified algorithm.
571
+ *
572
+ * @param alg The JWA algorithm identifier (e.g., "HS256", "RS256", "A128GCM").
573
+ * @param jwkParams Optional partial JWK to merge with the generated key, allowing overrides.
574
+ * @param options Configuration options for key generation.
575
+ * @returns A Promise resolving to the generated JWK or JWK pair representation.
576
+ */
577
+ declare function generateJWK<TAlg extends GenerateKeyAlgorithm>(alg: TAlg, jwkParams?: Omit<JWKParameters, "alg" | "kty" | "key_ops" | "ext">, options?: GenerateJWKOptions): Promise<GenerateJWKReturn<TAlg>>;
578
+ /**
579
+ * Derives a Json Web Key (JWK) from a password using PBKDF2 as specified by PBES2 algorithms.
580
+ *
581
+ * @param password The password to derive the key from (string or Uint8Array).
582
+ * @param alg The PBES2 algorithm identifier (e.g., "PBES2-HS256+A128KW").
583
+ * @param jwkParams Optional partial JWK to merge with the generated key, allowing overrides.
584
+ * @param options Configuration options including salt and iterations.
585
+ * @returns A Promise resolving to the derived JWK (JWK_oct).
586
+ */
587
+ declare function deriveJWKFromPassword(password: string | Uint8Array<ArrayBuffer>, alg: JWK_PBES2, options: Omit<DeriveKeyOptions, "toJWK">, jwkParams?: Omit<JWKParameters, "alg" | "kty" | "key_ops" | "ext">): Promise<JWK_oct>;
588
+ /**
589
+ * Imports a key from a PEM-encoded string and converts it to a JWK.
590
+ *
591
+ * @param pem The PEM-encoded string.
592
+ * @param pemType The type of PEM encoding ('pkcs8' for private keys, 'spki' for public keys, 'x509' for certificates).
593
+ * @param alg The JWA algorithm identifier. This is crucial for `crypto.subtle.importKey`
594
+ * to understand the key's intended algorithm and for setting the 'alg' field in the resulting JWK.
595
+ * @param importOptions Options for the PEM import process (e.g., extractable for the CryptoKey).
596
+ * @param jwkExtras Additional properties to merge into the resulting JWK.
597
+ * @returns A Promise resolving to the imported key as a JWK.
598
+ */
599
+ declare function importJWKFromPEM<T extends JWK>(pem: string, pemType: "pkcs8" | "spki" | "x509", alg: JWKPEMAlgorithm, importOptions?: KeyImportOptions, jwkExtras?: Partial<JWK>): Promise<T>;
600
+ /**
601
+ * Exports a JWK to a PEM-encoded string.
602
+ *
603
+ * @param jwk The JWK to export.
604
+ * @param pemFormat The desired PEM format ('pkcs8' for private keys, 'spki' for public keys).
605
+ * @param algForCryptoKeyImport If the JWK does not have an 'alg' property, this algorithm hint is
606
+ * required to correctly convert it to a CryptoKey first.
607
+ * @returns A Promise resolving to the PEM-encoded key string.
608
+ */
609
+ declare function exportJWKToPEM(jwk: JWK, pemFormat: "pkcs8" | "spki", algForCryptoKeyImport?: JWKPEMAlgorithm): Promise<string>;
610
+ //#endregion
611
+ export { JWK_OKP_Public as $, GenerateJWKReturn as A, JWK_AES_GCM as B, JWTClaims as C, DeriveKeyOptions as D, ContentEncryptionAlgorithm as E, JWKAlgorithm as F, JWK_EC as G, JWK_AES_KW as H, JWKPEMAlgorithm as I, JWK_EC_Private as J, JWK_ECDH_ES as K, JWKParameters as L, GenerateKeyOptions as M, GenerateKeyReturn as N, DeriveKeyReturn as O, JWK as P, JWK_OKP_Private as Q, JWKSet as R, JWTClaimValidationOptions as S, CompositeKey as T, JWK_Asymmetric as U, JWK_AES_GCM_KW as V, JWK_Asymmetric_Algorithm as W, JWK_HMAC as X, JWK_EC_Public as Y, JWK_OKP as Z, JWSProtectedHeader as _, WrapKeyResult as _t, ExpiresIn as a, JWK_RSA as at, JWSVerifyResult as b, JWEDecryptResult as c, JWK_RSA_Private as ct, JWEKeyLookupFunction as d, JWK_Symmetric as dt, JWK_OKP_SIGN as et, JWEKeyManagementHeaderParameters as f, JWK_Symmetric_Algorithm as ft, JWSKeyLookupFunction as g, WrapKeyOptions as gt, JWSHeaderParameters as h, UnwrapKeyOptions as ht, importJWKFromPEM as i, JWK_Public as it, GenerateKeyAlgorithm as j, GenerateJWKOptions as k, JWEEncryptOptions as l, JWK_RSA_Public as lt, JWSAlgorithm as m, KeyManagementAlgorithm as mt, exportJWKToPEM as n, JWK_Pair as nt, MaxTokenAge as o, JWK_RSA_ENC as ot, StrictOmit as p, JWK_oct as pt, JWK_ECDSA as q, generateJWK as r, JWK_Private as rt, JWEDecryptOptions as s, JWK_RSA_PSS as st, deriveJWKFromPassword as t, JWK_PBES2 as tt, JWEHeaderParameters as u, JWK_RSA_SIGN as ut, JWSSignOptions as v, JoseHeaderParameters as w, JWT as x, JWSVerifyOptions as y, JWK_AES_CBC_HMAC as z };