unjwt 0.5.39 → 0.6.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.
- package/README.md +156 -13
- package/dist/_chunks/_crypto.mjs +1014 -0
- package/dist/_chunks/error.d.mts +67 -0
- package/dist/_chunks/index.d.mts +631 -219
- package/dist/_chunks/jwk.d.mts +220 -87
- package/dist/_chunks/jws.mjs +729 -682
- package/dist/_chunks/utils.mjs +74 -69
- package/dist/adapters/h3v1/index.d.mts +282 -0
- package/dist/{_chunks/h3v1.mjs → adapters/h3v1/index.mjs} +204 -91
- package/dist/adapters/h3v2/index.d.mts +213 -0
- package/dist/adapters/{h3v2.mjs → h3v2/index.mjs} +215 -113
- package/dist/core/_crypto/index.d.mts +71 -0
- package/dist/core/_crypto/index.mjs +2 -0
- package/dist/core/jwe.d.mts +40 -0
- package/dist/{_chunks → core}/jwe.mjs +61 -32
- package/dist/core/jwk.d.mts +231 -0
- package/dist/core/jwk.mjs +686 -0
- package/dist/core/jws.d.mts +31 -0
- package/dist/core/jws.mjs +104 -0
- package/dist/{_chunks/index2.d.mts → core/utils/index.d.mts} +13 -12
- package/dist/core/utils/index.mjs +2 -0
- package/dist/index.d.mts +7 -6
- package/dist/index.mjs +5 -5
- package/package.json +50 -41
- package/dist/_chunks/chunk.mjs +0 -13
- package/dist/_chunks/jwe.d.mts +0 -43
- package/dist/_chunks/jwk.mjs +0 -1592
- package/dist/_chunks/jws.d.mts +0 -46
- package/dist/adapters/h3.d.mts +0 -3
- package/dist/adapters/h3.mjs +0 -3
- package/dist/adapters/h3v1.d.mts +0 -3
- package/dist/adapters/h3v1.mjs +0 -3
- package/dist/adapters/h3v2.d.mts +0 -184
- package/dist/jwe.d.mts +0 -3
- package/dist/jwe.mjs +0 -4
- package/dist/jwk.d.mts +0 -3
- package/dist/jwk.mjs +0 -3
- package/dist/jws.d.mts +0 -3
- package/dist/jws.mjs +0 -4
- package/dist/utils.d.mts +0 -3
- package/dist/utils.mjs +0 -2
package/dist/_chunks/jwk.d.mts
CHANGED
|
@@ -1,4 +1,58 @@
|
|
|
1
1
|
//#region src/core/types/jwk.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The decoded JOSE protected header received by a {@link JWKLookupFunction}.
|
|
4
|
+
*
|
|
5
|
+
* The most commonly inspected fields are explicitly typed; additional
|
|
6
|
+
* algorithm-specific parameters (`epk`, `p2s`, `p2c`, `apu`, `apv`, …) are
|
|
7
|
+
* accessible through the index signature.
|
|
8
|
+
*
|
|
9
|
+
* `alg` is always present on both JWS and JWE tokens. `enc` is only present
|
|
10
|
+
* on JWE tokens.
|
|
11
|
+
*/
|
|
12
|
+
type JWKLookupFunctionHeader = {
|
|
13
|
+
kid?: string;
|
|
14
|
+
alg?: string;
|
|
15
|
+
enc?: string;
|
|
16
|
+
typ?: string;
|
|
17
|
+
crit?: string[];
|
|
18
|
+
[propName: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A callback that resolves the decryption or verification key from a token's
|
|
22
|
+
* decoded protected header and the raw compact token string.
|
|
23
|
+
*
|
|
24
|
+
* Accepted by both {@link verify} (JWS) and {@link decrypt} (JWE). When a
|
|
25
|
+
* {@link JWKSet} is returned, the library tries each key whose `kid` and `alg`
|
|
26
|
+
* are compatible with the header in order, stopping at the first that succeeds
|
|
27
|
+
* — see {@link getJWKsFromSet} for the selection logic.
|
|
28
|
+
*
|
|
29
|
+
* Returning a `string` is meaningful for JWE only (PBES2 password); for JWS
|
|
30
|
+
* a string return is encoded to bytes and used as a raw symmetric key.
|
|
31
|
+
*/
|
|
32
|
+
type JWKLookupFunction = (header: JWKLookupFunctionHeader, token: string) => CryptoKey | JWK | JWKSet | string | Uint8Array<ArrayBuffer> | Promise<CryptoKey | JWK | JWKSet | string | Uint8Array<ArrayBuffer>>;
|
|
33
|
+
/**
|
|
34
|
+
* Interface for custom JWK import cache implementations.
|
|
35
|
+
*
|
|
36
|
+
* The adapter receives the full JWK object so each implementation can choose
|
|
37
|
+
* its own keying strategy:
|
|
38
|
+
* - {@link WeakMapJWKCache} uses the object reference (GC-friendly, no string hashing needed)
|
|
39
|
+
* - A `kid`-keyed cache extracts `jwk.kid` and uses it as a string key
|
|
40
|
+
* - A content-hash cache hashes `jwk.k` or `jwk.n`+`jwk.e`
|
|
41
|
+
*
|
|
42
|
+
* @example Use a custom kid-keyed cache:
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { configureJWKCache } from 'unjwt/jwk';
|
|
45
|
+
* const map = new Map<string, CryptoKey>();
|
|
46
|
+
* configureJWKCache({
|
|
47
|
+
* get: (jwk, alg) => map.get(`${jwk.kid}:${alg}`),
|
|
48
|
+
* set: (jwk, alg, key) => map.set(`${jwk.kid}:${alg}`, key),
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
interface JWKCacheAdapter {
|
|
53
|
+
get(jwk: JWK, alg: string): CryptoKey | undefined;
|
|
54
|
+
set(jwk: JWK, alg: string, key: CryptoKey): void;
|
|
55
|
+
}
|
|
2
56
|
/** Structure returned for composite AES-CBC + HMAC keys. */
|
|
3
57
|
type CompositeKey = {
|
|
4
58
|
/** The AES-CBC encryption/decryption key. */encryptionKey: CryptoKey; /** The HMAC key for integrity/authentication. */
|
|
@@ -17,8 +71,12 @@ interface GenerateKeyOptions {
|
|
|
17
71
|
publicExponent?: Uint8Array<ArrayBuffer>;
|
|
18
72
|
/** Named curve for EC or OKP keys. Defaults to "P-256" for EC and "Ed25519" for OKP. */
|
|
19
73
|
namedCurve?: "P-256" | "P-384" | "P-521" | "X25519" | "Ed25519" | "Ed448";
|
|
20
|
-
/**
|
|
21
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Export the generated key(s) as JWK. When `true`, keys are returned in JWK
|
|
76
|
+
* format with a generated `kid`. To include additional JWK parameters
|
|
77
|
+
* (e.g. a custom `kid`), use {@link generateJWK} instead.
|
|
78
|
+
*/
|
|
79
|
+
toJWK?: boolean;
|
|
22
80
|
}
|
|
23
81
|
type GenerateKeyReturnJWK<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_Asymmetric_Algorithm ? TAlg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC ? {
|
|
24
82
|
privateKey: JWK_RSA_Private;
|
|
@@ -31,7 +89,7 @@ type GenerateKeyReturnJWK<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_
|
|
|
31
89
|
publicKey: JWK_OKP_Public;
|
|
32
90
|
} : never : TAlg extends JWK_AES_CBC_HMAC | JWK_Symmetric_Algorithm ? JWK_oct : never;
|
|
33
91
|
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> :
|
|
92
|
+
type GenerateKeyReturn<TAlg extends GenerateKeyAlgorithm, TOptions extends GenerateKeyOptions> = TOptions["toJWK"] extends true ? GenerateKeyReturnJWK<TAlg> : GenerateKeyReturnCrypto<TAlg>;
|
|
35
93
|
type GenerateJWKOptions = Omit<GenerateKeyOptions, "toJWK">;
|
|
36
94
|
type GenerateJWKReturn<TAlg extends GenerateKeyAlgorithm> = GenerateKeyReturnJWK<TAlg>;
|
|
37
95
|
/** Options for the deriveKeyFromPassword function. */
|
|
@@ -44,11 +102,15 @@ interface DeriveKeyOptions {
|
|
|
44
102
|
keyUsage?: KeyUsage[];
|
|
45
103
|
/** Mark the derived key as extractable. Defaults to false. */
|
|
46
104
|
extractable?: boolean;
|
|
47
|
-
/**
|
|
48
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Export the derived key as JWK_oct. When `true`, returns the derived key in
|
|
107
|
+
* JWK format. To include additional JWK parameters (e.g. a custom `kid`),
|
|
108
|
+
* use {@link deriveJWKFromPassword} instead.
|
|
109
|
+
*/
|
|
110
|
+
toJWK?: boolean;
|
|
49
111
|
}
|
|
50
112
|
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;
|
|
113
|
+
type KeyManagementAlgorithm = JWK_RSA_ENC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_PBES2 | JWK_ECDH_ES | "dir";
|
|
52
114
|
type ContentEncryptionAlgorithm = JWK_AES_GCM | JWK_AES_CBC_HMAC;
|
|
53
115
|
/** Options for the wrapKey function. */
|
|
54
116
|
interface WrapKeyOptions {
|
|
@@ -58,12 +120,25 @@ interface WrapKeyOptions {
|
|
|
58
120
|
p2s?: Uint8Array<ArrayBuffer>;
|
|
59
121
|
/** PBES2 Iteration count (p2c). Required for PBES2 algorithms. */
|
|
60
122
|
p2c?: number;
|
|
61
|
-
/** ECDH-ES
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
123
|
+
/** ECDH-ES specific options. */
|
|
124
|
+
ecdh?: {
|
|
125
|
+
/**
|
|
126
|
+
* ECDH-ES ephemeral key material. A fresh ephemeral key pair is generated
|
|
127
|
+
* automatically when this is not provided.
|
|
128
|
+
*/
|
|
129
|
+
ephemeralKey?: CryptoKey | JWK_EC_Private | CryptoKeyPair | {
|
|
130
|
+
publicKey: CryptoKey | JWK_EC_Public;
|
|
131
|
+
privateKey: CryptoKey | JWK_EC_Private;
|
|
132
|
+
}; /** Agreement PartyUInfo (apu). */
|
|
133
|
+
partyUInfo?: Uint8Array<ArrayBuffer>; /** Agreement PartyVInfo (apv). */
|
|
134
|
+
partyVInfo?: Uint8Array<ArrayBuffer>;
|
|
135
|
+
/**
|
|
136
|
+
* Content encryption algorithm used for key-length derivation.
|
|
137
|
+
* Required only when `alg` is `"ECDH-ES"` (direct key agreement).
|
|
138
|
+
* Not needed for `ECDH-ES+A128KW`, `+A192KW`, or `+A256KW`.
|
|
139
|
+
*/
|
|
140
|
+
enc?: ContentEncryptionAlgorithm;
|
|
141
|
+
};
|
|
67
142
|
}
|
|
68
143
|
/** Result of the wrapKey function. */
|
|
69
144
|
interface WrapKeyResult {
|
|
@@ -86,6 +161,13 @@ interface WrapKeyResult {
|
|
|
86
161
|
}
|
|
87
162
|
/** Options for the unwrapKey function. */
|
|
88
163
|
interface UnwrapKeyOptions {
|
|
164
|
+
/**
|
|
165
|
+
* Output format of the unwrapped key.
|
|
166
|
+
* - `"cryptokey"` (default) — returns a `CryptoKey` ready for use with WebCrypto.
|
|
167
|
+
* - `"raw"` — returns the raw key bytes as `Uint8Array` (useful for
|
|
168
|
+
* interoperability or when the algorithm is not directly importable).
|
|
169
|
+
*/
|
|
170
|
+
format?: "cryptokey" | "raw";
|
|
89
171
|
/** Initialization Vector (required for AES-GCMKW). Base64URL encoded or Uint8Array. */
|
|
90
172
|
iv?: Uint8Array<ArrayBuffer> | string;
|
|
91
173
|
/** Authentication Tag (required for AES-GCMKW). Base64URL encoded or Uint8Array. */
|
|
@@ -108,7 +190,6 @@ interface UnwrapKeyOptions {
|
|
|
108
190
|
keyUsage?: KeyUsage[];
|
|
109
191
|
/** Mark the unwrapped key as extractable. Defaults to true. */
|
|
110
192
|
extractable?: boolean;
|
|
111
|
-
returnAs?: boolean | undefined;
|
|
112
193
|
}
|
|
113
194
|
/**
|
|
114
195
|
* Forked from https://github.com/panva/jose/tree/v6.0.10
|
|
@@ -141,6 +222,12 @@ interface JWKParameters {
|
|
|
141
222
|
x5u?: string;
|
|
142
223
|
/** JWK "kid" (Key ID) Parameter */
|
|
143
224
|
kid?: string;
|
|
225
|
+
/**
|
|
226
|
+
* Non-standard JWK content encryption algorithm hint.
|
|
227
|
+
* When `alg` is `"dir"`, the library reads this field to infer the
|
|
228
|
+
* content encryption algorithm (`enc`) when it is not provided in options.
|
|
229
|
+
*/
|
|
230
|
+
enc?: ContentEncryptionAlgorithm;
|
|
144
231
|
}
|
|
145
232
|
/** Public EC JSON Web Keys */
|
|
146
233
|
interface JWK_EC_Public extends JWKParameters {
|
|
@@ -221,6 +308,19 @@ type JWK_Private = JWK_RSA_Private | JWK_EC_Private | JWK_OKP_Private;
|
|
|
221
308
|
*/
|
|
222
309
|
type JWK = JWK_oct | JWK_RSA | JWK_EC | JWK_OKP;
|
|
223
310
|
/**
|
|
311
|
+
* A pair of public and private JSON Web Keys.
|
|
312
|
+
*/
|
|
313
|
+
type JWK_Pair = {
|
|
314
|
+
publicKey: JWK_RSA_Public;
|
|
315
|
+
privateKey: JWK_RSA_Private;
|
|
316
|
+
} | {
|
|
317
|
+
publicKey: JWK_EC_Public;
|
|
318
|
+
privateKey: JWK_EC_Private;
|
|
319
|
+
} | {
|
|
320
|
+
publicKey: JWK_OKP_Public;
|
|
321
|
+
privateKey: JWK_OKP_Private;
|
|
322
|
+
};
|
|
323
|
+
/**
|
|
224
324
|
* JSON Web Key Set ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK Set}). "RSA", "EC" and "oct" key types are supported.
|
|
225
325
|
*/
|
|
226
326
|
interface JWKSet {
|
|
@@ -243,52 +343,9 @@ type JWK_ECDH_ES = "ECDH-ES" | "ECDH-ES+A128KW" | "ECDH-ES+A192KW" | "ECDH-ES+A2
|
|
|
243
343
|
type JWK_OKP_SIGN = "Ed25519" | "EdDSA";
|
|
244
344
|
type JWK_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW;
|
|
245
345
|
type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC | JWK_OKP_SIGN | JWK_ECDH_ES;
|
|
246
|
-
type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES |
|
|
346
|
+
type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES | "dir";
|
|
247
347
|
type JWKPEMAlgorithm = JWK_RSA_PSS | JWK_RSA_SIGN | JWK_RSA_ENC | JWK_ECDSA | JWK_ECDH_ES | JWK_OKP_SIGN;
|
|
248
348
|
//#endregion
|
|
249
|
-
//#region src/core/types/jws.d.ts
|
|
250
|
-
type JWS_SIGN_EXTRA = "Ed25519" | "EdDSA";
|
|
251
|
-
/** JWS Signing Algorithm Identifier. */
|
|
252
|
-
type JWSAlgorithm = JWK_HMAC | JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWS_SIGN_EXTRA;
|
|
253
|
-
/** Recognized JWS Header Parameters, any other Header Members may also be present. */
|
|
254
|
-
interface JWSHeaderParameters extends JoseHeaderParameters {
|
|
255
|
-
/** JWS "alg" (Algorithm) Header Parameter */
|
|
256
|
-
alg?: JWSAlgorithm;
|
|
257
|
-
/**
|
|
258
|
-
* This JWS Extension Header Parameter modifies the JWS Payload representation and the JWS Signing
|
|
259
|
-
* Input computation as per {@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}.
|
|
260
|
-
* If `false`, the payload is used directly without Base64URL encoding.
|
|
261
|
-
* Defaults to `true`.
|
|
262
|
-
*/
|
|
263
|
-
b64?: boolean;
|
|
264
|
-
}
|
|
265
|
-
/** JWS Protected Header */
|
|
266
|
-
interface JWSProtectedHeader extends JWSHeaderParameters {
|
|
267
|
-
alg: JWSAlgorithm;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* JWS (JSON Web Signature) options for signing
|
|
271
|
-
*/
|
|
272
|
-
interface JWSSignOptions {
|
|
273
|
-
/** The JWS Algorithm to use. Must be provided. */
|
|
274
|
-
alg?: JWSAlgorithm;
|
|
275
|
-
/**
|
|
276
|
-
* Additional protected header parameters. `alg` is automatically included.
|
|
277
|
-
* `typ` defaults to "JWT" if not provided and payload is an object.
|
|
278
|
-
*/
|
|
279
|
-
protectedHeader?: JWSHeaderParameters;
|
|
280
|
-
/** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
|
|
281
|
-
currentDate?: Date;
|
|
282
|
-
/**
|
|
283
|
-
* Time at which the JWS should expire, if no `exp` was already provided.
|
|
284
|
-
*/
|
|
285
|
-
expiresIn?: ExpiresIn;
|
|
286
|
-
}
|
|
287
|
-
//#endregion
|
|
288
|
-
//#region src/core/types/index.d.ts
|
|
289
|
-
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"}`;
|
|
290
|
-
type MaxTokenAge = ExpiresIn;
|
|
291
|
-
//#endregion
|
|
292
349
|
//#region src/core/types/jwt.d.ts
|
|
293
350
|
/** Header Parameters common to JWE and JWS */
|
|
294
351
|
interface JoseHeaderParameters {
|
|
@@ -313,6 +370,15 @@ interface JoseHeaderParameters {
|
|
|
313
370
|
/** Any other JWS/JWE Header member. */
|
|
314
371
|
[propName: string]: unknown;
|
|
315
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Payload accepted by {@link sign} and {@link encrypt}.
|
|
375
|
+
*
|
|
376
|
+
* Covers raw strings and bytes for non-JWT use, plus any JSON-serializable
|
|
377
|
+
* object for JWT and generic structured payloads. JWT-specific claim names
|
|
378
|
+
* are not enforced at this level — use {@link JWTClaims} when you want typed
|
|
379
|
+
* claim names and spec-compliant field types.
|
|
380
|
+
*/
|
|
381
|
+
type JOSEPayload = string | Uint8Array<ArrayBuffer> | Record<string, unknown>;
|
|
316
382
|
interface JWTClaims {
|
|
317
383
|
/** "iss" (Issuer) Claim */
|
|
318
384
|
iss?: string;
|
|
@@ -354,14 +420,73 @@ interface JWTClaimValidationOptions {
|
|
|
354
420
|
currentDate?: Date;
|
|
355
421
|
/** Additional required claim names. */
|
|
356
422
|
requiredClaims?: string[];
|
|
357
|
-
/** List of critical header parameters that must be understood and processed. */
|
|
358
|
-
requiredHeaders?: string[];
|
|
359
423
|
/**
|
|
360
|
-
* Critical
|
|
361
|
-
* If the
|
|
362
|
-
*
|
|
424
|
+
* Critical header parameters that this caller understands and has processed.
|
|
425
|
+
* If the token's `crit` header lists a parameter not present in this list
|
|
426
|
+
* (and not natively understood by the library), verification will fail per
|
|
427
|
+
* RFC 7515 §4.1.11 / RFC 7516 §4.1.13.
|
|
428
|
+
*/
|
|
429
|
+
recognizedHeaders?: string[];
|
|
430
|
+
}
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region src/core/types/jws.d.ts
|
|
433
|
+
/** JWS Signing Algorithm Identifier. */
|
|
434
|
+
type JWSAlgorithm = JWK_HMAC | JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_OKP_SIGN;
|
|
435
|
+
/** Recognized JWS Header Parameters, any other Header Members may also be present. */
|
|
436
|
+
interface JWSHeaderParameters extends JoseHeaderParameters {
|
|
437
|
+
/** JWS "alg" (Algorithm) Header Parameter */
|
|
438
|
+
alg?: JWSAlgorithm;
|
|
439
|
+
/**
|
|
440
|
+
* This JWS Extension Header Parameter modifies the JWS Payload representation and the JWS Signing
|
|
441
|
+
* Input computation as per {@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}.
|
|
442
|
+
* If `false`, the payload is used directly without Base64URL encoding.
|
|
443
|
+
* Defaults to `true`.
|
|
444
|
+
*/
|
|
445
|
+
b64?: boolean;
|
|
446
|
+
}
|
|
447
|
+
/** JWS Protected Header */
|
|
448
|
+
interface JWSProtectedHeader extends JWSHeaderParameters {
|
|
449
|
+
alg: JWSAlgorithm;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* JWS (JSON Web Signature) options for signing
|
|
453
|
+
*/
|
|
454
|
+
interface JWSSignOptions {
|
|
455
|
+
/** The JWS Algorithm to use. Must be provided. */
|
|
456
|
+
alg?: JWSAlgorithm;
|
|
457
|
+
/**
|
|
458
|
+
* Additional protected header parameters. `alg` is automatically included.
|
|
459
|
+
* `typ` defaults to "JWT" if not provided and payload is an object.
|
|
460
|
+
*/
|
|
461
|
+
protectedHeader?: JWSHeaderParameters;
|
|
462
|
+
/** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
|
|
463
|
+
currentDate?: Date;
|
|
464
|
+
/**
|
|
465
|
+
* Time at which the JWS should expire, if no `exp` was already provided.
|
|
363
466
|
*/
|
|
364
|
-
|
|
467
|
+
expiresIn?: ExpiresIn;
|
|
468
|
+
}
|
|
469
|
+
/** Result of JWS verification */
|
|
470
|
+
interface JWSVerifyResult<T extends JOSEPayload = JOSEPayload> {
|
|
471
|
+
/** The decoded and verified payload. */
|
|
472
|
+
payload: T;
|
|
473
|
+
/** The JWS Protected Header. */
|
|
474
|
+
protectedHeader: JWSProtectedHeader;
|
|
475
|
+
}
|
|
476
|
+
/** Options for JWS verification */
|
|
477
|
+
interface JWSVerifyOptions extends JWTClaimValidationOptions {
|
|
478
|
+
/** List of allowed algorithms. If provided, the JWS `alg` must be in this list. */
|
|
479
|
+
algorithms?: JWSAlgorithm[];
|
|
480
|
+
/** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred. */
|
|
481
|
+
forceUint8Array?: boolean;
|
|
482
|
+
/**
|
|
483
|
+
* Controls JWT claim validation after a successful verification.
|
|
484
|
+
*
|
|
485
|
+
* - `true` — always validate claims regardless of the `typ` header
|
|
486
|
+
* - `false` — skip claim validation entirely
|
|
487
|
+
* - `undefined` (default) — validate when `typ` is `"JWT"` or contains `"jwt"`
|
|
488
|
+
*/
|
|
489
|
+
validateClaims?: boolean;
|
|
365
490
|
}
|
|
366
491
|
//#endregion
|
|
367
492
|
//#region src/core/utils/types.d.ts
|
|
@@ -373,11 +498,11 @@ interface JWEHeaderParameters extends JoseHeaderParameters {
|
|
|
373
498
|
/**
|
|
374
499
|
* `alg` (Algorithm): Header Parameter - Key Management Algorithm
|
|
375
500
|
*/
|
|
376
|
-
alg?: string;
|
|
501
|
+
alg?: KeyManagementAlgorithm | (string & {});
|
|
377
502
|
/**
|
|
378
503
|
* `enc` (Encryption Algorithm): Header Parameter - Content Encryption Algorithm
|
|
379
504
|
*/
|
|
380
|
-
enc?: string;
|
|
505
|
+
enc?: ContentEncryptionAlgorithm | (string & {});
|
|
381
506
|
/**
|
|
382
507
|
* `p2c` (PBES2 Count): Header Parameter
|
|
383
508
|
*/
|
|
@@ -479,12 +604,6 @@ interface JWEEncryptOptions {
|
|
|
479
604
|
contentEncryptionIV?: Uint8Array<ArrayBuffer>;
|
|
480
605
|
}
|
|
481
606
|
/**
|
|
482
|
-
* Key lookup function for JWE decryption.
|
|
483
|
-
* @param header The JWE Protected Header.
|
|
484
|
-
* @returns The key material (CryptoKey, JWK, password string, or raw Uint8Array) or a Promise resolving to it.
|
|
485
|
-
*/
|
|
486
|
-
type JWEKeyLookupFunction = (header: JWEHeaderParameters, token: string) => CryptoKey | JWK | string | Uint8Array<ArrayBuffer> | Promise<CryptoKey | JWK | string | Uint8Array<ArrayBuffer>>;
|
|
487
|
-
/**
|
|
488
607
|
* JWE (JSON Web Encryption) decryption options
|
|
489
608
|
*/
|
|
490
609
|
interface JWEDecryptOptions extends JWTClaimValidationOptions {
|
|
@@ -500,34 +619,45 @@ interface JWEDecryptOptions extends JWTClaimValidationOptions {
|
|
|
500
619
|
extractable?: boolean;
|
|
501
620
|
/** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred based on JWE headers. */
|
|
502
621
|
forceUint8Array?: boolean;
|
|
503
|
-
/**
|
|
504
|
-
|
|
622
|
+
/**
|
|
623
|
+
* Controls JWT claim validation after a successful decryption.
|
|
624
|
+
*
|
|
625
|
+
* - `true` — always validate claims regardless of the `typ` header
|
|
626
|
+
* - `false` — skip claim validation entirely
|
|
627
|
+
* - `undefined` (default) — validate when `typ` is `"JWT"` or contains `"jwt"`
|
|
628
|
+
*/
|
|
629
|
+
validateClaims?: boolean;
|
|
505
630
|
/** If true, include the Content Encryption Key (CEK) and Additional Authenticated Data (AAD) in the result. */
|
|
506
631
|
returnCek?: boolean;
|
|
507
632
|
}
|
|
508
633
|
/**
|
|
634
|
+
* JWE Protected Header — the parsed and validated protected header returned
|
|
635
|
+
* after a successful {@link decrypt} call. Both `alg` and `enc` are present
|
|
636
|
+
* and strongly typed because decryption could not have succeeded without them.
|
|
637
|
+
*/
|
|
638
|
+
interface JWEProtectedHeader extends JWEHeaderParameters {
|
|
639
|
+
/** Key management algorithm. */
|
|
640
|
+
alg: KeyManagementAlgorithm;
|
|
641
|
+
/** Content encryption algorithm. */
|
|
642
|
+
enc: ContentEncryptionAlgorithm;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
509
645
|
* Result of a JWE decryption operation.
|
|
510
646
|
*/
|
|
511
|
-
interface JWEDecryptResult<T extends
|
|
647
|
+
interface JWEDecryptResult<T extends JOSEPayload = JOSEPayload> {
|
|
512
648
|
/** The decrypted payload. */
|
|
513
649
|
payload: T;
|
|
514
650
|
/** The JWE Protected Header. */
|
|
515
|
-
protectedHeader:
|
|
651
|
+
protectedHeader: JWEProtectedHeader;
|
|
516
652
|
/** The Content Encryption Key (CEK) used for decryption, as Uint8Array. Only present when `returnCek` is true. */
|
|
517
653
|
cek?: Uint8Array<ArrayBuffer>;
|
|
518
654
|
/** The Additional Authenticated Data (AAD) used, as Uint8Array. Only present when `returnCek` is true. */
|
|
519
655
|
aad?: Uint8Array<ArrayBuffer>;
|
|
520
656
|
}
|
|
521
657
|
//#endregion
|
|
522
|
-
//#region src/core/
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
/**
|
|
526
|
-
* The value to use as {@link !SubtleCrypto.importKey} `extractable` argument. Default is false for
|
|
527
|
-
* private keys, true otherwise.
|
|
528
|
-
*/
|
|
529
|
-
extractable?: boolean;
|
|
530
|
-
}
|
|
658
|
+
//#region src/core/types/index.d.ts
|
|
659
|
+
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"}`;
|
|
660
|
+
type MaxTokenAge = ExpiresIn;
|
|
531
661
|
//#endregion
|
|
532
662
|
//#region src/core/jwk.d.ts
|
|
533
663
|
/**
|
|
@@ -560,7 +690,10 @@ declare function deriveJWKFromPassword(password: string | Uint8Array<ArrayBuffer
|
|
|
560
690
|
* @param jwkExtras Additional properties to merge into the resulting JWK.
|
|
561
691
|
* @returns A Promise resolving to the imported key as a JWK.
|
|
562
692
|
*/
|
|
563
|
-
declare function
|
|
693
|
+
declare function importFromPEM<T extends JWK>(pem: string, pemType: "pkcs8" | "spki" | "x509", alg: JWKPEMAlgorithm, options?: {
|
|
694
|
+
/** Passed to `crypto.subtle.importKey`. Defaults to `false` for private keys, `true` otherwise. */extractable?: boolean; /** Additional JWK properties merged into the exported key (e.g. `kid`). */
|
|
695
|
+
jwkParams?: Omit<JWKParameters, "alg" | "kty" | "key_ops" | "ext">;
|
|
696
|
+
}): Promise<T>;
|
|
564
697
|
/**
|
|
565
698
|
* Exports a JWK to a PEM-encoded string.
|
|
566
699
|
*
|
|
@@ -570,6 +703,6 @@ declare function importJWKFromPEM<T extends JWK>(pem: string, pemType: "pkcs8" |
|
|
|
570
703
|
* required to correctly convert it to a CryptoKey first.
|
|
571
704
|
* @returns A Promise resolving to the PEM-encoded key string.
|
|
572
705
|
*/
|
|
573
|
-
declare function
|
|
706
|
+
declare function exportToPEM(jwk: JWK, pemFormat: "pkcs8" | "spki", algForCryptoKeyImport?: JWKPEMAlgorithm): Promise<string>;
|
|
574
707
|
//#endregion
|
|
575
|
-
export {
|
|
708
|
+
export { JWK_HMAC as $, GenerateJWKReturn as A, JWKParameters as B, JWTClaims as C, DeriveKeyOptions as D, ContentEncryptionAlgorithm as E, JWKAlgorithm as F, JWK_AES_KW as G, JWK_AES_CBC_HMAC as H, JWKCacheAdapter as I, JWK_EC as J, JWK_Asymmetric as K, JWKLookupFunction as L, GenerateKeyOptions as M, GenerateKeyReturn as N, DeriveKeyReturn as O, JWK as P, JWK_EC_Public as Q, JWKLookupFunctionHeader as R, JWTClaimValidationOptions as S, CompositeKey as T, JWK_AES_GCM as U, JWKSet as V, JWK_AES_GCM_KW as W, JWK_ECDSA as X, JWK_ECDH_ES as Y, JWK_EC_Private as Z, JWSSignOptions as _, KeyManagementAlgorithm as _t, ExpiresIn as a, JWK_Pair as at, JOSEPayload as b, WrapKeyResult as bt, JWEDecryptResult as c, JWK_RSA as ct, JWEKeyManagementHeaderParameters as d, JWK_RSA_Private as dt, JWK_OKP as et, JWEProtectedHeader as f, JWK_RSA_Public as ft, JWSProtectedHeader as g, JWK_oct as gt, JWSHeaderParameters as h, JWK_Symmetric_Algorithm as ht, importFromPEM as i, JWK_PBES2 as it, GenerateKeyAlgorithm as j, GenerateJWKOptions as k, JWEEncryptOptions as l, JWK_RSA_ENC as lt, JWSAlgorithm as m, JWK_Symmetric as mt, exportToPEM as n, JWK_OKP_Public as nt, MaxTokenAge as o, JWK_Private as ot, StrictOmit as p, JWK_RSA_SIGN as pt, JWK_Asymmetric_Algorithm as q, generateJWK as r, JWK_OKP_SIGN as rt, JWEDecryptOptions as s, JWK_Public as st, deriveJWKFromPassword as t, JWK_OKP_Private as tt, JWEHeaderParameters as u, JWK_RSA_PSS as ut, JWSVerifyOptions as v, UnwrapKeyOptions as vt, JoseHeaderParameters as w, JWT as x, JWSVerifyResult as y, WrapKeyOptions as yt, JWKPEMAlgorithm as z };
|