unjwt 0.8.1 → 0.8.3
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 +4 -4
- package/dist/THIRD-PARTY-LICENSES.md.gz +0 -0
- package/dist/_chunks/_codec-jwe.d.mts +101 -22
- package/dist/_chunks/_codec-jws.mjs +306 -232
- package/dist/_chunks/_cookie-attributes.d.mts +12 -0
- package/dist/_chunks/_jwt-internal.mjs +9 -6
- package/dist/_chunks/digest.d.mts +8 -0
- package/dist/_chunks/{algorithms.mjs → digest.mjs} +78 -8
- package/dist/_chunks/index.d.mts +313 -268
- package/dist/_chunks/index2.d.mts +2 -1
- package/dist/_chunks/index3.d.mts +1 -0
- package/dist/_chunks/jwe.d.mts +4 -4
- package/dist/_chunks/jwe.mjs +21 -3
- package/dist/_chunks/jwk.mjs +219 -173
- package/dist/_chunks/jws.d.mts +10 -10
- package/dist/_chunks/jws.mjs +18 -6
- package/dist/_chunks/jwt.d.mts +2 -1
- package/dist/_chunks/libs/cookie-es.mjs +255 -0
- package/dist/adapters/elysia/index.d.mts +32 -15
- package/dist/adapters/elysia/index.mjs +46 -67
- package/dist/adapters/h3/index.d.mts +135 -0
- package/dist/adapters/h3/index.mjs +119 -0
- package/dist/adapters/h3v1/index.d.mts +100 -27
- package/dist/adapters/h3v1/index.mjs +59 -76
- package/dist/core/jwe.d.mts +2 -2
- package/dist/core/jwk.d.mts +22 -14
- package/dist/core/jwk.mjs +2 -2
- package/dist/core/jws.d.mts +2 -2
- package/dist/core/utils/index.d.mts +2 -1
- package/dist/core/utils/index.mjs +2 -2
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +3 -3
- package/dist/session/index.d.mts +44 -0
- package/dist/session/index.mjs +113 -0
- package/package.json +37 -18
- package/dist/adapters/h3v2/index.d.mts +0 -65
- package/dist/adapters/h3v2/index.mjs +0 -139
package/dist/_chunks/index.d.mts
CHANGED
|
@@ -100,21 +100,271 @@ export declare function isUnsecureError<T extends UnsecureErrorCode>(error: unkn
|
|
|
100
100
|
code: T;
|
|
101
101
|
};
|
|
102
102
|
export declare function isUnsecureError(error: unknown): error is UnsecureError;
|
|
103
|
-
/**
|
|
103
|
+
/** Header Parameters common to JWE and JWS. */
|
|
104
|
+
export interface JoseHeaderParameters {
|
|
105
|
+
/** "kid" (Key ID) Header Parameter */
|
|
106
|
+
kid?: string;
|
|
107
|
+
/** "x5t" (X.509 Certificate SHA-1 Thumbprint) Header Parameter */
|
|
108
|
+
x5t?: string;
|
|
109
|
+
/** "x5c" (X.509 Certificate Chain) Header Parameter */
|
|
110
|
+
x5c?: string[];
|
|
111
|
+
/** "x5u" (X.509 URL) Header Parameter */
|
|
112
|
+
x5u?: string;
|
|
113
|
+
/** "jku" (JWK Set URL) Header Parameter */
|
|
114
|
+
jku?: string;
|
|
115
|
+
/** "jwk" (JSON Web Key) Header Parameter */
|
|
116
|
+
jwk?: JWK_Public;
|
|
117
|
+
/** "typ" (Type) Header Parameter */
|
|
118
|
+
typ?: string;
|
|
119
|
+
/** "cty" (Content Type) Header Parameter */
|
|
120
|
+
cty?: string;
|
|
121
|
+
/** "crit" (Critical) Header Parameter */
|
|
122
|
+
crit?: string[];
|
|
123
|
+
[propName: string]: unknown;
|
|
124
|
+
}
|
|
125
|
+
/** Payload accepted by `sign` and `encrypt`: a string, raw bytes, or a JSON object. */
|
|
126
|
+
export type JOSEPayload = string | Uint8Array<ArrayBuffer> | object;
|
|
127
|
+
/** How a verified or decrypted payload is decoded: `"json"` object, UTF-8 `"string"`, or raw `"bytes"`. */
|
|
128
|
+
export type JOSEPayloadMode = keyof JOSEPayloadTypeMap;
|
|
129
|
+
/** The payload type each `JOSEPayloadMode` resolves to. */
|
|
130
|
+
export interface JOSEPayloadTypeMap<T = JWTClaims> {
|
|
131
|
+
json: T;
|
|
132
|
+
string: string;
|
|
133
|
+
bytes: Uint8Array<ArrayBuffer>;
|
|
134
|
+
}
|
|
135
|
+
/** The payload type returned under `Mode`; a union of modes yields the union of payloads. */
|
|
136
|
+
export type PayloadOf<Mode extends JOSEPayloadMode, T = JWTClaims> = JOSEPayloadTypeMap<T>[Mode];
|
|
137
|
+
/** "cnf" (Confirmation) Claim members (RFC 7800 §3.1), with `jkt` (RFC 9449 §6.1) and `x5t#S256` (RFC 8705 §3.1). */
|
|
138
|
+
export interface JWTConfirmation {
|
|
139
|
+
/** The proof-of-possession key as a public JWK */
|
|
140
|
+
"jwk"?: JWK_Public;
|
|
141
|
+
/** The proof-of-possession key as an encrypted JWK, a JWE in compact serialization */
|
|
142
|
+
"jwe"?: string;
|
|
143
|
+
/** A Key ID the recipient resolves out of band */
|
|
144
|
+
"kid"?: string;
|
|
145
|
+
/** A JWK Set URL holding the key, selected by `kid` */
|
|
146
|
+
"jku"?: string;
|
|
147
|
+
/** The RFC 7638 SHA-256 thumbprint of the DPoP public key */
|
|
148
|
+
"jkt"?: string;
|
|
149
|
+
/** The SHA-256 thumbprint of the client certificate, base64url */
|
|
150
|
+
"x5t#S256"?: string;
|
|
151
|
+
[member: string]: unknown;
|
|
152
|
+
}
|
|
153
|
+
export interface JWTClaims {
|
|
154
|
+
/** "iss" (Issuer) Claim */
|
|
155
|
+
iss?: string;
|
|
156
|
+
/** "sub" (Subject) Claim */
|
|
157
|
+
sub?: string;
|
|
158
|
+
/** "aud" (Audience) Claim */
|
|
159
|
+
aud?: string | string[];
|
|
160
|
+
/** "exp" (Expiration Time) Claim */
|
|
161
|
+
exp?: number;
|
|
162
|
+
/** "nbf" (Not Before) Claim */
|
|
163
|
+
nbf?: number;
|
|
164
|
+
/** "iat" (Issued At) Claim */
|
|
165
|
+
iat?: number;
|
|
166
|
+
/** "jti" (JWT ID) Claim */
|
|
167
|
+
jti?: string;
|
|
168
|
+
/** "cnf" (Confirmation) Claim, the proof-of-possession key; never validated, read by the application */
|
|
169
|
+
cnf?: JWTConfirmation;
|
|
170
|
+
[propName: string]: unknown;
|
|
171
|
+
}
|
|
172
|
+
export interface JWT<T = JWTClaims> {
|
|
173
|
+
header: JoseHeaderParameters & {
|
|
174
|
+
/** "alg" (Algorithm) Header Parameter */
|
|
175
|
+
alg: JWSAlgorithm | KeyManagementAlgorithm;
|
|
176
|
+
};
|
|
177
|
+
claims: T;
|
|
178
|
+
}
|
|
179
|
+
/** Per-call work bounds; each entry must be a positive integer, else `ERR_INVALID_OPTION`. */
|
|
180
|
+
export interface JOSELimits {
|
|
181
|
+
/** Max `signatures[]` entries in a JWS JSON serialization. @default 16 */
|
|
182
|
+
signatures?: number;
|
|
183
|
+
/** Max `recipients[]` entries in a JWE JSON serialization. @default 16 */
|
|
184
|
+
recipients?: number;
|
|
185
|
+
/** Max JWK Set candidates tried per token after `kid`/`alg`/`use` filtering. @default 8 */
|
|
186
|
+
keyCandidates?: number;
|
|
187
|
+
/** Total PBKDF2 iterations one call may spend across PBES2 attempts. @default 2_400_000 */
|
|
188
|
+
pbes2Iterations?: number;
|
|
189
|
+
}
|
|
190
|
+
/** Claim expectations, each checked when set; an empty or malformed value is `ERR_INVALID_OPTION`. */
|
|
191
|
+
export interface JWTClaimValidationOptions {
|
|
192
|
+
/** Expected "aud" value(s); `aud` is checked only when this is set (RFC 7519 §4.1.3). */
|
|
193
|
+
audience?: string | string[];
|
|
194
|
+
/** Expected "iss" value(s); implies presence. */
|
|
195
|
+
issuer?: string | string[];
|
|
196
|
+
/** Expected "sub" value; implies presence. */
|
|
197
|
+
subject?: string;
|
|
198
|
+
/** Maximum token age from "iat"; implies presence. */
|
|
199
|
+
maxTokenAge?: MaxTokenAge;
|
|
200
|
+
/** Clock skew tolerance for nbf/exp/iat, in seconds or a `Duration`. @default 0 */
|
|
201
|
+
clockTolerance?: number | Duration;
|
|
202
|
+
/** Expected "typ" header, compared as a media type (RFC 7515 §4.1.9); implies presence. */
|
|
203
|
+
typ?: string;
|
|
204
|
+
/** Date used for NumericDate comparisons. @default new Date() */
|
|
205
|
+
currentDate?: Date;
|
|
206
|
+
/** Additional required claim names. */
|
|
207
|
+
requiredClaims?: string[];
|
|
208
|
+
/** `crit` header parameters the caller understands (RFC 7515 §4.1.11, RFC 7516 §4.1.13). */
|
|
209
|
+
recognizedHeaders?: string[];
|
|
210
|
+
}
|
|
211
|
+
/** Time claims a producer computes; a claim already in the payload is kept as given. */
|
|
212
|
+
export interface JWTTimeClaimOptions {
|
|
213
|
+
/** The clock: `iat` when written, and the base of `expiresIn` / `notBeforeIn`. @default new Date() */
|
|
214
|
+
currentDate?: Date;
|
|
215
|
+
/** Writes `iat` on its own: `true` as `currentDate`, a `Date` as that instant; `false` is unset. `exp`/`nbf` options write it either way. */
|
|
216
|
+
issuedAt?: boolean | Date;
|
|
217
|
+
/** Duration from `currentDate` until `exp`; exclusive with `expiresAt`. */
|
|
218
|
+
expiresIn?: ExpiresIn;
|
|
219
|
+
/** Absolute `exp`; exclusive with `expiresIn`. */
|
|
220
|
+
expiresAt?: Date;
|
|
221
|
+
/** Duration from `currentDate` until `nbf` (`0` sets `nbf` to it); exclusive with `notBeforeAt`. */
|
|
222
|
+
notBeforeIn?: ExpiresIn;
|
|
223
|
+
/** Absolute `nbf` (RFC 7519 §4.1.5); exclusive with `notBeforeIn`. */
|
|
224
|
+
notBeforeAt?: Date;
|
|
225
|
+
}
|
|
226
|
+
/** Options shared by `verify` and `decrypt` (compact and multi). */
|
|
227
|
+
export interface JOSEConsumerOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends JWTClaimValidationOptions {
|
|
228
|
+
/** Admit `oct` entries of a JWK Set as key material; only for application-controlled sets. @default false */
|
|
229
|
+
allowSymmetricJWKSet?: boolean;
|
|
230
|
+
/** Payload decoding mode; a mismatch is `ERR_JWS_INVALID` / `ERR_JWE_INVALID`. @default "json" */
|
|
231
|
+
payload?: Mode;
|
|
232
|
+
/**
|
|
233
|
+
* If true, forces the payload to be returned as a `Uint8Array`.
|
|
234
|
+
*
|
|
235
|
+
* @deprecated Use `payload: "bytes"`. Deprecated in v0.8.0, removed in v0.9.0
|
|
236
|
+
*/
|
|
237
|
+
forceUint8Array?: boolean;
|
|
238
|
+
/** `false` skips claim validation; `true` with a non-`"json"` payload is `ERR_INVALID_OPTION`. */
|
|
239
|
+
validateClaims?: boolean;
|
|
240
|
+
}
|
|
241
|
+
export type StrictOmit<T, K extends keyof T | (string & {}) | (number & {}) | (symbol & {})> = { [P in keyof T as P extends K ? never : P]: T[P]; };
|
|
242
|
+
/** JWS Signing Algorithm Identifier. */
|
|
243
|
+
export type JWSAlgorithm = JWK_HMAC | JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_OKP_SIGN;
|
|
244
|
+
/** A key lookup for `verify`: it receives the validated JWS header. */
|
|
245
|
+
export type JWSKeyLookup<TReturn = CryptoKey | JWK | JWKSet | string | Uint8Array<ArrayBuffer>> = JWKLookupFunction<TReturn, JWSHeaderParameters>;
|
|
246
|
+
/** JWS algorithms that name their digest (`*256`/`*384`/`*512`); EdDSA does not. */
|
|
247
|
+
export type JWSHashedAlgorithm = Exclude<JWSAlgorithm, JWK_OKP_SIGN>;
|
|
248
|
+
/** Asymmetric private JWKs admissible as a signing key. */
|
|
249
|
+
export type JWSAsymmetricPrivateJWK = JWK_RSA_Private<JWK_RSA_SIGN | JWK_RSA_PSS> | JWK_EC_Private<JWK_ECDSA> | JWK_OKP_Private<JWK_OKP_SIGN>;
|
|
250
|
+
/** Asymmetric public JWKs admissible as a verification key. */
|
|
251
|
+
export type JWSAsymmetricPublicJWK = JWK_RSA_Public<JWK_RSA_SIGN | JWK_RSA_PSS> | JWK_EC_Public<JWK_ECDSA> | JWK_OKP_Public<JWK_OKP_SIGN>;
|
|
252
|
+
/** JWKs admissible as a `sign` key; a non-signing `alg` is a type error. */
|
|
253
|
+
export type JWSSignJWK = JWK_oct<JWK_HMAC> | JWSAsymmetricPrivateJWK;
|
|
254
|
+
/** JWKs admissible as a `verify` key; a non-signing `alg` is a type error. */
|
|
255
|
+
export type JWSVerifyJWK = JWK_oct<JWK_HMAC> | JWSAsymmetricPublicJWK;
|
|
256
|
+
/** Recognized JWS Header Parameters; other members may be present. */
|
|
257
|
+
export interface JWSHeaderParameters extends JoseHeaderParameters {
|
|
258
|
+
/** JWS "alg" (Algorithm) Header Parameter */
|
|
259
|
+
alg?: JWSAlgorithm;
|
|
260
|
+
/** `false` signs the payload unencoded (RFC 7797). @default true */
|
|
261
|
+
b64?: boolean;
|
|
262
|
+
}
|
|
263
|
+
/** JWS Protected Header */
|
|
264
|
+
export interface JWSProtectedHeader extends JWSHeaderParameters {
|
|
265
|
+
alg: JWSAlgorithm;
|
|
266
|
+
}
|
|
267
|
+
/** Options for `sign`. */
|
|
268
|
+
export interface JWSSignOptions extends JWTTimeClaimOptions {
|
|
269
|
+
/** JWS algorithm; inferred from the key when omitted. */
|
|
270
|
+
alg?: JWSAlgorithm;
|
|
271
|
+
/** Extra protected header parameters; `alg` cannot be set, `typ` defaults to `"JWT"` for an object payload. */
|
|
272
|
+
protectedHeader?: StrictOmit<JWSHeaderParameters, "alg"> & {
|
|
273
|
+
alg?: never;
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/** Result of JWS verification. */
|
|
277
|
+
export interface JWSVerifyResult<T extends JOSEPayload = JOSEPayload> {
|
|
278
|
+
payload: T;
|
|
279
|
+
protectedHeader: JWSProtectedHeader;
|
|
280
|
+
}
|
|
281
|
+
/** Options for `verify`; `Mode` is the `payload` option's literal. */
|
|
282
|
+
export interface JWSVerifyOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends JOSEConsumerOptions<Mode> {
|
|
283
|
+
/** Allowed `alg` values; inferred from the key when omitted, required for raw secrets, alg-less JWKs and resolvers. */
|
|
284
|
+
algorithms?: JWSAlgorithm[];
|
|
285
|
+
/** Max JWK Set candidates per token; more is `ERR_JWK_KEY_NOT_FOUND`. @default { keyCandidates: 8 } */
|
|
286
|
+
limits?: Pick<JOSELimits, "keyCandidates">;
|
|
287
|
+
}
|
|
288
|
+
/** JWS Flattened JSON Serialization (RFC 7515 §7.2.2). */
|
|
289
|
+
export interface JWSFlattenedSerialization {
|
|
290
|
+
/** The JWS Payload; base64url-encoded unless `b64: false`. */
|
|
291
|
+
payload: string;
|
|
292
|
+
/** Base64url-encoded JWS Protected Header. */
|
|
293
|
+
protected?: string;
|
|
294
|
+
/** JWS Unprotected Header (not signed). */
|
|
295
|
+
header?: JWSHeaderParameters;
|
|
296
|
+
/** Base64url-encoded signature. */
|
|
297
|
+
signature: string;
|
|
298
|
+
}
|
|
299
|
+
/** JWS General JSON Serialization (RFC 7515 §7.2.1). */
|
|
300
|
+
export interface JWSGeneralSerialization extends Omit<JWSFlattenedSerialization, "protected" | "header" | "signature"> {
|
|
301
|
+
/** One entry per signer. */
|
|
302
|
+
signatures: JWSGeneralSignature[];
|
|
303
|
+
}
|
|
304
|
+
/** A single entry of `JWSGeneralSerialization.signatures`. */
|
|
305
|
+
export type JWSGeneralSignature = Pick<JWSFlattenedSerialization, "protected" | "header" | "signature">;
|
|
306
|
+
/** One signer passed to `signMulti`. */
|
|
307
|
+
export interface JWSMultiSigner {
|
|
308
|
+
/** Signing key; `kid` is taken from a JWK, a `CryptoKey` must set it in `protectedHeader`. */
|
|
309
|
+
key: JWSSignJWK | CryptoKey;
|
|
310
|
+
/** JWS algorithm; inferred from the key when possible, else `ERR_JWS_SIGNER_ALG_INFERENCE`. */
|
|
311
|
+
alg?: JWSAlgorithm;
|
|
312
|
+
/** Per-signer protected header; `b64` must match across signers (RFC 7797 §3), `typ` defaults to `"JWT"`. */
|
|
313
|
+
protectedHeader?: StrictOmit<JWSHeaderParameters, "alg"> & {
|
|
314
|
+
alg?: never;
|
|
315
|
+
};
|
|
316
|
+
/** Per-signer JWS Unprotected Header (not signed). */
|
|
317
|
+
unprotectedHeader?: JWSHeaderParameters;
|
|
318
|
+
}
|
|
319
|
+
/** Options for `signMulti`; `alg` and `protectedHeader` are set per signer. */
|
|
320
|
+
export interface JWSMultiSignOptions extends StrictOmit<JWSSignOptions, "alg" | "protectedHeader"> {}
|
|
321
|
+
/** Options for `verifyMulti`. */
|
|
322
|
+
export interface JWSMultiVerifyOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends JWSVerifyOptions<Mode> {
|
|
323
|
+
/** Max `signatures[]` (more is `ERR_JWS_INVALID`) and JWK Set candidates per signature. @default { signatures: 16, keyCandidates: 8 } */
|
|
324
|
+
limits?: Pick<JOSELimits, "signatures" | "keyCandidates">;
|
|
325
|
+
/** Try only signatures the key could have produced (by `kid`, `kty`, curve, length), else `ERR_JWS_NO_MATCHING_SIGNER`. @default false */
|
|
326
|
+
strictSignerMatch?: boolean;
|
|
327
|
+
}
|
|
328
|
+
/** Result of `verifyMulti`. */
|
|
329
|
+
export interface JWSMultiVerifyResult<T extends JOSEPayload = JOSEPayload> extends Omit<JWSVerifyResult<T>, "protectedHeader"> {
|
|
330
|
+
/** Protected header of the verified signature as signed; `alg` may sit in `signerHeader` (RFC 7515 §7.2.1). */
|
|
331
|
+
protectedHeader: JWSHeaderParameters;
|
|
332
|
+
/** Unprotected header of the verified signature. */
|
|
333
|
+
signerHeader?: JWSHeaderParameters;
|
|
334
|
+
/** Index into `signatures` of the verified signature. */
|
|
335
|
+
signerIndex: number;
|
|
336
|
+
}
|
|
337
|
+
/** Options for `verifyMultiAll`. */
|
|
338
|
+
export interface JWSMultiVerifyAllOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends StrictOmit<JWSMultiVerifyOptions<Mode>, "strictSignerMatch"> {}
|
|
339
|
+
/** Per-signature outcome of `verifyMultiAll`, discriminated by `verified`; failures carry `error`. */
|
|
340
|
+
export type JWSMultiVerifyOutcome<T extends JOSEPayload = JOSEPayload> = {
|
|
341
|
+
signerIndex: number;
|
|
342
|
+
verified: true;
|
|
343
|
+
payload: T;
|
|
344
|
+
protectedHeader: JWSHeaderParameters;
|
|
345
|
+
signerHeader?: JWSHeaderParameters;
|
|
346
|
+
} | {
|
|
347
|
+
signerIndex: number;
|
|
348
|
+
verified: false;
|
|
349
|
+
error: JWTError;
|
|
350
|
+
protectedHeader?: JWSHeaderParameters;
|
|
351
|
+
signerHeader?: JWSHeaderParameters;
|
|
352
|
+
};
|
|
353
|
+
/** Decoded protected header a `JWKLookupFunction` receives, its algorithms already checked against the ones this version implements; `enc` is present on JWE only. */
|
|
104
354
|
export type JWKLookupFunctionHeader = {
|
|
105
355
|
kid?: string;
|
|
106
|
-
alg?:
|
|
107
|
-
enc?:
|
|
356
|
+
alg?: JWSAlgorithm | KeyManagementAlgorithm;
|
|
357
|
+
enc?: ContentEncryptionAlgorithm;
|
|
108
358
|
typ?: string;
|
|
109
359
|
crit?: string[];
|
|
110
360
|
[propName: string]: unknown;
|
|
111
361
|
};
|
|
112
|
-
/** Resolves the verify/decrypt key from the protected header and compact token; a string is a PBES2 password (JWE) or raw key bytes (JWS); `undefined`, `null` or a throw is `ERR_JWK_KEY_NOT_FOUND`. */
|
|
113
|
-
export type JWKLookupFunction<TReturn = CryptoKey | JWK | JWKSet | string | Uint8Array<ArrayBuffer
|
|
362
|
+
/** Resolves the verify/decrypt key from the protected header (`THeader`: the family's, else the generic one) and compact token; a string is a PBES2 password (JWE) or raw key bytes (JWS); `undefined`, `null` or a throw is `ERR_JWK_KEY_NOT_FOUND`. */
|
|
363
|
+
export type JWKLookupFunction<TReturn = CryptoKey | JWK | JWKSet | string | Uint8Array<ArrayBuffer>, THeader = JWKLookupFunctionHeader> = (header: THeader, token: string) => TReturn | undefined | null | Promise<TReturn | undefined | null>;
|
|
114
364
|
/** Custom JWK import cache; key on the JWK `thumbprint` plus private/public half and `alg`, never on `kid`. Both methods may return a promise. */
|
|
115
365
|
export interface JWKCacheAdapter {
|
|
116
|
-
get(jwk: JWK, alg:
|
|
117
|
-
set(jwk: JWK, alg:
|
|
366
|
+
get(jwk: JWK, alg: JWKAlgorithm): CryptoKey | undefined | Promise<CryptoKey | undefined>;
|
|
367
|
+
set(jwk: JWK, alg: JWKAlgorithm, key: CryptoKey): void | Promise<void>;
|
|
118
368
|
}
|
|
119
369
|
/** Structure returned for composite AES-CBC + HMAC keys. */
|
|
120
370
|
export type CompositeKey = {
|
|
@@ -147,7 +397,7 @@ export interface GenerateKeyOptions<ToJWK extends boolean = boolean, Kid extends
|
|
|
147
397
|
/** `generateKey` result per algorithm without `toJWK`: `CryptoKey` (symmetric), raw bytes (`A*CBC-HS*`), `CryptoKeyPair` (asymmetric). */
|
|
148
398
|
export type GeneratedKeyMap = { [A in GenerateKeyAlgorithm]: A extends JWK_AES_CBC_HMAC ? Uint8Array<ArrayBuffer> : A extends JWK_Asymmetric_Algorithm ? CryptoKeyPair : CryptoKey; };
|
|
149
399
|
/** `generateJWK` result per algorithm: an `oct` JWK or a JWK pair, each carrying `alg`, and `kid` unless `Kid` is `false`. */
|
|
150
|
-
export type GeneratedJWKMap<Kid extends string | false = string> = { [A in GenerateKeyAlgorithm]: A extends JWK_Asymmetric_Algorithm ? GeneratedJWKPair<JWK_Pair<A>, A, Kid> : JWK_oct<A
|
|
400
|
+
export type GeneratedJWKMap<Kid extends string | false = string> = { [A in GenerateKeyAlgorithm]: A extends JWK_Asymmetric_Algorithm ? GeneratedJWKPair<JWK_Pair<A>, A, Kid> : JWK_oct<Exclude<A, JWK_Asymmetric_Algorithm>> & GeneratedJWKMembers<A, Kid>; };
|
|
151
401
|
/** `generateKey` return type for `TAlg` under `TOptions`; JWKs when `toJWK` is `true`. */
|
|
152
402
|
export type GenerateKeyReturn<TAlg extends GenerateKeyAlgorithm, TOptions extends GenerateKeyOptions> = GeneratedKeyShape<TAlg, Exclude<TOptions["toJWK"], undefined>, GeneratedKid<TOptions>>;
|
|
153
403
|
/** `generateJWK` return type for `TAlg` under the `kid` option `Kid`. */
|
|
@@ -175,9 +425,24 @@ export interface DeriveKeyOptions {
|
|
|
175
425
|
/** Return the derived key as a `JWK_oct`. */
|
|
176
426
|
toJWK?: boolean;
|
|
177
427
|
}
|
|
428
|
+
/** The AES-KW algorithm a `PBES2-*` or `ECDH-ES+*` algorithm wraps the CEK with: its last six characters. */
|
|
429
|
+
export type KeyWrapAlgorithmOf<A extends KeyWrappingAlgorithm> = A extends `${string}A128KW` ? "A128KW" : A extends `${string}A192KW` ? "A192KW" : A extends `${string}A256KW` ? "A256KW" : never;
|
|
430
|
+
/** Key management algorithms that wrap the CEK with an inner AES-KW step. */
|
|
431
|
+
export type KeyWrappingAlgorithm = JWK_PBES2 | Exclude<JWK_ECDH_ES, "ECDH-ES">;
|
|
178
432
|
/** PBES2 → AES-KW `alg` stamped on the derived JWK. */
|
|
179
|
-
type DerivedJWKAlg<TAlg extends JWK_PBES2> = TAlg
|
|
433
|
+
type DerivedJWKAlg<TAlg extends JWK_PBES2> = KeyWrapAlgorithmOf<TAlg>;
|
|
180
434
|
export type DeriveKeyReturn<TOptions extends DeriveKeyOptions, TAlg extends JWK_PBES2 = JWK_PBES2> = TOptions["toJWK"] extends true ? JWK_oct<DerivedJWKAlg<TAlg>> : TOptions["toJWK"] extends object ? JWK_oct<DerivedJWKAlg<TAlg>> : CryptoKey;
|
|
435
|
+
/** Options of `deriveJWKFromPassword`: PBES2 derivation without `toJWK`/`extractable`, plus `kid` (`false` for none). */
|
|
436
|
+
export type DeriveJWKOptions<TAlg extends JWK_PBES2 = JWK_PBES2, Kid extends string | false = string> = Omit<DeriveKeyOptions, "alg" | "toJWK" | "extractable"> & {
|
|
437
|
+
alg: TAlg;
|
|
438
|
+
kid?: Kid;
|
|
439
|
+
};
|
|
440
|
+
/** `deriveJWKFromPassword` return type: the AES-KW `oct` JWK for `TAlg`, with `kid` unless `Kid` is `false`. */
|
|
441
|
+
export type DeriveJWKReturn<TAlg extends JWK_PBES2, Kid extends string | false = string> = JWK_oct<DerivedJWKAlg<TAlg>> & GeneratedJWKMembers<DerivedJWKAlg<TAlg>, Kid>;
|
|
442
|
+
/** PEM label families `importPEM` reads. */
|
|
443
|
+
export type PEMType = "pkcs8" | "spki" | "x509";
|
|
444
|
+
/** `importPEM` result for `Alg`: the private JWK of a PKCS#8 PEM, the public one of SPKI/X.509, both when the label is inferred. */
|
|
445
|
+
export type ImportedPEMJWK<Alg extends JWKPEMAlgorithm, Type extends PEMType | undefined = undefined> = Type extends "pkcs8" ? JWK_Pair<Alg>["privateKey"] : Type extends "spki" | "x509" ? JWK_Pair<Alg>["publicKey"] : JWK_Pair<Alg>["privateKey"] | JWK_Pair<Alg>["publicKey"];
|
|
181
446
|
export type KeyManagementAlgorithm = JWK_RSA_ENC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_PBES2 | JWK_ECDH_ES | "dir";
|
|
182
447
|
export type ContentEncryptionAlgorithm = JWK_AES_GCM | JWK_AES_CBC_HMAC;
|
|
183
448
|
/** Keys admissible as the `wrappingKey` of `wrapKey` for algorithm `A`; `dir` takes any symmetric key. */
|
|
@@ -256,7 +521,7 @@ export type UnwrapKeyResult<TOptions extends {
|
|
|
256
521
|
}> = "format" extends keyof TOptions ? [TOptions["format"]] extends ["raw"] ? Uint8Array<ArrayBuffer> : [TOptions["format"]] extends ["cryptokey" | undefined] ? CryptoKey : CryptoKey | Uint8Array<ArrayBuffer> : CryptoKey;
|
|
257
522
|
/** Forked from https://github.com/panva/jose/tree/v6.0.10, Copyright (c) 2018 Filip Skokan, LICENSE: https://github.com/panva/jose/blob/v6.0.10/LICENSE.md */
|
|
258
523
|
/** Generic JWK parameters; `Alg` constrains the `alg` member. */
|
|
259
|
-
export interface JWKParameters<Alg extends
|
|
524
|
+
export interface JWKParameters<Alg extends JWKAlgorithm = JWKAlgorithm> {
|
|
260
525
|
/** JWK "kty" (Key Type) Parameter */
|
|
261
526
|
"kty": string;
|
|
262
527
|
/** JWK "alg" (Algorithm) Parameter */
|
|
@@ -288,7 +553,7 @@ export type ECDHEphemeralKeyInput = CryptoKey | JWK_EC_Private | JWK_OKP_Private
|
|
|
288
553
|
privateKey: CryptoKey | JWK_EC_Private | JWK_OKP_Private;
|
|
289
554
|
};
|
|
290
555
|
/** Public EC JSON Web Keys */
|
|
291
|
-
export interface JWK_EC_Public<Alg extends JWK_ECDSA | JWK_ECDH_ES
|
|
556
|
+
export interface JWK_EC_Public<Alg extends JWK_ECDSA | JWK_ECDH_ES = JWK_ECDSA | JWK_ECDH_ES> extends JWKParameters<Alg> {
|
|
292
557
|
kty: "EC";
|
|
293
558
|
/** EC JWK "crv" (Curve) Parameter */
|
|
294
559
|
crv: string;
|
|
@@ -298,14 +563,14 @@ export interface JWK_EC_Public<Alg extends JWK_ECDSA | JWK_ECDH_ES | (string & {
|
|
|
298
563
|
y: string;
|
|
299
564
|
}
|
|
300
565
|
/** Private EC JSON Web Keys */
|
|
301
|
-
export interface JWK_EC_Private<Alg extends JWK_ECDSA | JWK_ECDH_ES
|
|
566
|
+
export interface JWK_EC_Private<Alg extends JWK_ECDSA | JWK_ECDH_ES = JWK_ECDSA | JWK_ECDH_ES> extends JWK_EC_Public<Alg> {
|
|
302
567
|
/** EC JWK "d" (ECC Private Key) Parameter */
|
|
303
568
|
d: string;
|
|
304
569
|
}
|
|
305
570
|
/** EC JSON Web Keys */
|
|
306
|
-
export type JWK_EC<Alg extends JWK_ECDSA | JWK_ECDH_ES
|
|
571
|
+
export type JWK_EC<Alg extends JWK_ECDSA | JWK_ECDH_ES = JWK_ECDSA | JWK_ECDH_ES> = JWK_EC_Public<Alg> | JWK_EC_Private<Alg>;
|
|
307
572
|
/** Public RSA JSON Web Keys */
|
|
308
|
-
export interface JWK_RSA_Public<Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC
|
|
573
|
+
export interface JWK_RSA_Public<Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC> extends JWKParameters<Alg> {
|
|
309
574
|
kty: "RSA";
|
|
310
575
|
/** RSA JWK "e" (Exponent) Parameter */
|
|
311
576
|
e: string;
|
|
@@ -314,7 +579,7 @@ export interface JWK_RSA_Public<Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA
|
|
|
314
579
|
oth?: RsaOtherPrimesInfo[];
|
|
315
580
|
}
|
|
316
581
|
/** Private RSA JSON Web Keys */
|
|
317
|
-
export interface JWK_RSA_Private<Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC
|
|
582
|
+
export interface JWK_RSA_Private<Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC> extends JWK_RSA_Public<Alg> {
|
|
318
583
|
/** RSA JWK "d" (Private Exponent) Parameter */
|
|
319
584
|
d: string;
|
|
320
585
|
/** RSA JWK "dp" (First Factor CRT Exponent) Parameter */
|
|
@@ -329,9 +594,9 @@ export interface JWK_RSA_Private<Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RS
|
|
|
329
594
|
qi: string;
|
|
330
595
|
}
|
|
331
596
|
/** RSA JSON Web Keys */
|
|
332
|
-
export type JWK_RSA<Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC
|
|
597
|
+
export type JWK_RSA<Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC> = JWK_RSA_Public<Alg> | JWK_RSA_Private<Alg>;
|
|
333
598
|
/** Public ED JSON Web Keys */
|
|
334
|
-
export interface JWK_OKP_Public<Alg extends JWK_OKP_SIGN | JWK_ECDH_ES
|
|
599
|
+
export interface JWK_OKP_Public<Alg extends JWK_OKP_SIGN | JWK_ECDH_ES = JWK_OKP_SIGN | JWK_ECDH_ES> extends JWKParameters<Alg> {
|
|
335
600
|
kty: "OKP";
|
|
336
601
|
/** ED JWK "crv" (Curve) Parameter */
|
|
337
602
|
crv: string;
|
|
@@ -339,30 +604,36 @@ export interface JWK_OKP_Public<Alg extends JWK_OKP_SIGN | JWK_ECDH_ES | (string
|
|
|
339
604
|
x: string;
|
|
340
605
|
}
|
|
341
606
|
/** Private ED JSON Web Keys */
|
|
342
|
-
export interface JWK_OKP_Private<Alg extends JWK_OKP_SIGN | JWK_ECDH_ES
|
|
607
|
+
export interface JWK_OKP_Private<Alg extends JWK_OKP_SIGN | JWK_ECDH_ES = JWK_OKP_SIGN | JWK_ECDH_ES> extends JWK_OKP_Public<Alg> {
|
|
343
608
|
/** ED JWK "d" (Private Key) Parameter */
|
|
344
609
|
d: string;
|
|
345
610
|
}
|
|
346
611
|
/** OKP JSON Web Keys */
|
|
347
|
-
export type JWK_OKP<Alg extends JWK_OKP_SIGN | JWK_ECDH_ES
|
|
612
|
+
export type JWK_OKP<Alg extends JWK_OKP_SIGN | JWK_ECDH_ES = JWK_OKP_SIGN | JWK_ECDH_ES> = JWK_OKP_Public<Alg> | JWK_OKP_Private<Alg>;
|
|
348
613
|
/** oct JSON Web Keys */
|
|
349
|
-
export interface JWK_oct<Alg extends JWK_HMAC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_AES_CBC_HMAC | JWK_PBES2 | "dir" |
|
|
614
|
+
export interface JWK_oct<Alg extends JWK_HMAC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_AES_CBC_HMAC | JWK_PBES2 | "dir" = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_AES_CBC_HMAC | JWK_PBES2 | "dir"> extends JWKParameters<Alg> {
|
|
350
615
|
kty: "oct";
|
|
351
616
|
/** Oct JWK "k" (Key Value) Parameter */
|
|
352
617
|
k: string;
|
|
353
618
|
}
|
|
354
619
|
/** Symmetric JSON Web Keys */
|
|
355
|
-
export type JWK_Symmetric<Alg extends JWK_HMAC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_AES_CBC_HMAC | JWK_PBES2 | "dir" |
|
|
356
|
-
/** Asymmetric JSON Web Keys */
|
|
357
|
-
export type JWK_Asymmetric<Alg extends
|
|
358
|
-
/** Public JSON Web Keys */
|
|
359
|
-
export type JWK_Public<Alg extends
|
|
360
|
-
/** Private JSON Web Keys */
|
|
361
|
-
export type JWK_Private<Alg extends
|
|
620
|
+
export type JWK_Symmetric<Alg extends JWK_HMAC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_AES_CBC_HMAC | JWK_PBES2 | "dir" = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_AES_CBC_HMAC | JWK_PBES2 | "dir"> = JWK_oct<Alg>;
|
|
621
|
+
/** Asymmetric JSON Web Keys. */
|
|
622
|
+
export type JWK_Asymmetric<Alg extends JWK_Asymmetric_Algorithm = JWK_Asymmetric_Algorithm> = RSAFor<Alg, JWK_RSA<Extract<Alg, JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC>>> | ECFor<Alg, JWK_EC<Extract<Alg, JWK_ECDSA | JWK_ECDH_ES>>> | OKPFor<Alg, JWK_OKP<Extract<Alg, JWK_OKP_SIGN | JWK_ECDH_ES>>>;
|
|
623
|
+
/** Public JSON Web Keys. */
|
|
624
|
+
export type JWK_Public<Alg extends JWK_Asymmetric_Algorithm = JWK_Asymmetric_Algorithm> = RSAFor<Alg, JWK_RSA_Public<Extract<Alg, JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC>>> | ECFor<Alg, JWK_EC_Public<Extract<Alg, JWK_ECDSA | JWK_ECDH_ES>>> | OKPFor<Alg, JWK_OKP_Public<Extract<Alg, JWK_OKP_SIGN | JWK_ECDH_ES>>>;
|
|
625
|
+
/** Private JSON Web Keys. */
|
|
626
|
+
export type JWK_Private<Alg extends JWK_Asymmetric_Algorithm = JWK_Asymmetric_Algorithm> = RSAFor<Alg, JWK_RSA_Private<Extract<Alg, JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC>>> | ECFor<Alg, JWK_EC_Private<Extract<Alg, JWK_ECDSA | JWK_ECDH_ES>>> | OKPFor<Alg, JWK_OKP_Private<Extract<Alg, JWK_OKP_SIGN | JWK_ECDH_ES>>>;
|
|
627
|
+
/** `toPublicJWK` result: the public interface of the input's family and `alg`, keeping a `kid` the input is typed to carry. */
|
|
628
|
+
export type ToPublicJWKReturn<T extends JWK_Asymmetric> = (T extends JWK_RSA<infer Alg> ? JWK_RSA_Public<Alg> : T extends JWK_EC<infer Alg> ? JWK_EC_Public<Alg> : T extends JWK_OKP<infer Alg> ? JWK_OKP_Public<Alg> : never) & (T extends {
|
|
629
|
+
kid: string;
|
|
630
|
+
} ? {
|
|
631
|
+
kid: string;
|
|
632
|
+
} : unknown);
|
|
362
633
|
/** JSON Web Key (RFC 7517) of type "RSA", "EC", "OKP" or "oct". */
|
|
363
|
-
export type JWK<Alg extends
|
|
634
|
+
export type JWK<Alg extends JWKAlgorithm = JWKAlgorithm> = OctFor<Alg, JWK_oct<Extract<Alg, Exclude<JWKAlgorithm, JWK_Asymmetric_Algorithm>>>> | JWK_Asymmetric<Extract<Alg, JWK_Asymmetric_Algorithm>>;
|
|
364
635
|
/** Public/private JWK pair, narrowed to the key family `Alg` identifies (ECDH-ES: EC or OKP). */
|
|
365
|
-
export type JWK_Pair<Alg extends
|
|
636
|
+
export type JWK_Pair<Alg extends JWK_Asymmetric_Algorithm = JWK_Asymmetric_Algorithm> = Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC ? {
|
|
366
637
|
publicKey: JWK_RSA_Public<Alg>;
|
|
367
638
|
privateKey: JWK_RSA_Private<Alg>;
|
|
368
639
|
} : Alg extends JWK_ECDSA ? {
|
|
@@ -377,16 +648,7 @@ export type JWK_Pair<Alg extends string = string> = Alg extends JWK_RSA_SIGN | J
|
|
|
377
648
|
} : Alg extends JWK_OKP_SIGN ? {
|
|
378
649
|
publicKey: JWK_OKP_Public<Alg>;
|
|
379
650
|
privateKey: JWK_OKP_Private<Alg>;
|
|
380
|
-
} :
|
|
381
|
-
publicKey: JWK_RSA_Public<Alg>;
|
|
382
|
-
privateKey: JWK_RSA_Private<Alg>;
|
|
383
|
-
} | {
|
|
384
|
-
publicKey: JWK_EC_Public<Alg>;
|
|
385
|
-
privateKey: JWK_EC_Private<Alg>;
|
|
386
|
-
} | {
|
|
387
|
-
publicKey: JWK_OKP_Public<Alg>;
|
|
388
|
-
privateKey: JWK_OKP_Private<Alg>;
|
|
389
|
-
};
|
|
651
|
+
} : never;
|
|
390
652
|
/** JSON Web Key Set (RFC 7517); `T` preserves a precise key tuple. */
|
|
391
653
|
export interface JWKSet<T extends readonly JWK[] = JWK[]> {
|
|
392
654
|
keys: T;
|
|
@@ -405,6 +667,8 @@ export type JWK_AES_GCM_KW = "A128GCMKW" | "A192GCMKW" | "A256GCMKW";
|
|
|
405
667
|
export type JWK_PBES2 = "PBES2-HS256+A128KW" | "PBES2-HS384+A192KW" | "PBES2-HS512+A256KW";
|
|
406
668
|
export type JWK_ECDH_ES = "ECDH-ES" | "ECDH-ES+A128KW" | "ECDH-ES+A192KW" | "ECDH-ES+A256KW";
|
|
407
669
|
export type JWK_OKP_SIGN = "Ed25519" | "EdDSA";
|
|
670
|
+
/** Every algorithm named after an AES key size: the `A128`/`A192`/`A256` families. */
|
|
671
|
+
export type JWK_AES_Algorithm = JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_AES_CBC_HMAC;
|
|
408
672
|
export type JWK_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW;
|
|
409
673
|
export type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC | JWK_OKP_SIGN | JWK_ECDH_ES;
|
|
410
674
|
export type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES | "dir";
|
|
@@ -428,232 +692,11 @@ type GeneratedJWKPair<P, A, Kid> = P extends {
|
|
|
428
692
|
type GeneratedKid<TOptions> = "kid" extends keyof TOptions ? ThumbprintIfUnset<Extract<TOptions["kid" & keyof TOptions], string | false>> : string;
|
|
429
693
|
type ThumbprintIfUnset<Kid extends string | false> = [Kid] extends [never] ? string : Kid;
|
|
430
694
|
type GeneratedKeyShape<TAlg extends GenerateKeyAlgorithm, ToJWK, Kid extends string | false> = [ToJWK] extends [never] ? GeneratedKeyMap[TAlg] : ToJWK extends true ? GeneratedJWKMap<Kid>[TAlg] : GeneratedKeyMap[TAlg];
|
|
431
|
-
/**
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
x5t?: string;
|
|
437
|
-
/** "x5c" (X.509 Certificate Chain) Header Parameter */
|
|
438
|
-
x5c?: string[];
|
|
439
|
-
/** "x5u" (X.509 URL) Header Parameter */
|
|
440
|
-
x5u?: string;
|
|
441
|
-
/** "jku" (JWK Set URL) Header Parameter */
|
|
442
|
-
jku?: string;
|
|
443
|
-
/** "jwk" (JSON Web Key) Header Parameter */
|
|
444
|
-
jwk?: JWK_Public;
|
|
445
|
-
/** "typ" (Type) Header Parameter */
|
|
446
|
-
typ?: string;
|
|
447
|
-
/** "cty" (Content Type) Header Parameter */
|
|
448
|
-
cty?: string;
|
|
449
|
-
/** "crit" (Critical) Header Parameter */
|
|
450
|
-
crit?: string[];
|
|
451
|
-
[propName: string]: unknown;
|
|
452
|
-
}
|
|
453
|
-
/** Payload accepted by `sign` and `encrypt`: a string, raw bytes, or a JSON object. */
|
|
454
|
-
export type JOSEPayload = string | Uint8Array<ArrayBuffer> | object;
|
|
455
|
-
/** How a verified or decrypted payload is decoded: `"json"` object, UTF-8 `"string"`, or raw `"bytes"`. */
|
|
456
|
-
export type JOSEPayloadMode = keyof JOSEPayloadTypeMap;
|
|
457
|
-
/** The payload type each `JOSEPayloadMode` resolves to. */
|
|
458
|
-
export interface JOSEPayloadTypeMap<T = JWTClaims> {
|
|
459
|
-
json: T;
|
|
460
|
-
string: string;
|
|
461
|
-
bytes: Uint8Array<ArrayBuffer>;
|
|
462
|
-
}
|
|
463
|
-
/** The payload type returned under `Mode`; a union of modes yields the union of payloads. */
|
|
464
|
-
export type PayloadOf<Mode extends JOSEPayloadMode, T = JWTClaims> = JOSEPayloadTypeMap<T>[Mode];
|
|
465
|
-
export interface JWTClaims {
|
|
466
|
-
/** "iss" (Issuer) Claim */
|
|
467
|
-
iss?: string;
|
|
468
|
-
/** "sub" (Subject) Claim */
|
|
469
|
-
sub?: string;
|
|
470
|
-
/** "aud" (Audience) Claim */
|
|
471
|
-
aud?: string | string[];
|
|
472
|
-
/** "exp" (Expiration Time) Claim */
|
|
473
|
-
exp?: number;
|
|
474
|
-
/** "nbf" (Not Before) Claim */
|
|
475
|
-
nbf?: number;
|
|
476
|
-
/** "iat" (Issued At) Claim */
|
|
477
|
-
iat?: number;
|
|
478
|
-
/** "jti" (JWT ID) Claim */
|
|
479
|
-
jti?: string;
|
|
480
|
-
[propName: string]: unknown;
|
|
481
|
-
}
|
|
482
|
-
export interface JWT<T = JWTClaims> {
|
|
483
|
-
header: JoseHeaderParameters & {
|
|
484
|
-
/** "alg" (Algorithm) Header Parameter */
|
|
485
|
-
alg: string;
|
|
486
|
-
};
|
|
487
|
-
claims: T;
|
|
488
|
-
}
|
|
489
|
-
/** Per-call work bounds; each entry must be a positive integer, else `ERR_INVALID_OPTION`. */
|
|
490
|
-
export interface JOSELimits {
|
|
491
|
-
/** Max `signatures[]` entries in a JWS JSON serialization. @default 16 */
|
|
492
|
-
signatures?: number;
|
|
493
|
-
/** Max `recipients[]` entries in a JWE JSON serialization. @default 16 */
|
|
494
|
-
recipients?: number;
|
|
495
|
-
/** Max JWK Set candidates tried per token after `kid`/`alg`/`use` filtering. @default 8 */
|
|
496
|
-
keyCandidates?: number;
|
|
497
|
-
/** Total PBKDF2 iterations one call may spend across PBES2 attempts. @default 2_400_000 */
|
|
498
|
-
pbes2Iterations?: number;
|
|
499
|
-
}
|
|
500
|
-
/** Claim expectations, each checked when set; an empty or malformed value is `ERR_INVALID_OPTION`. */
|
|
501
|
-
export interface JWTClaimValidationOptions {
|
|
502
|
-
/** Expected "aud" value(s); `aud` is checked only when this is set (RFC 7519 §4.1.3). */
|
|
503
|
-
audience?: string | string[];
|
|
504
|
-
/** Expected "iss" value(s); implies presence. */
|
|
505
|
-
issuer?: string | string[];
|
|
506
|
-
/** Expected "sub" value; implies presence. */
|
|
507
|
-
subject?: string;
|
|
508
|
-
/** Maximum token age from "iat"; implies presence. */
|
|
509
|
-
maxTokenAge?: MaxTokenAge;
|
|
510
|
-
/** Clock skew tolerance for nbf/exp/iat, in seconds or a `Duration`. @default 0 */
|
|
511
|
-
clockTolerance?: number | Duration;
|
|
512
|
-
/** Expected "typ" header, compared as a media type (RFC 7515 §4.1.9); implies presence. */
|
|
513
|
-
typ?: string;
|
|
514
|
-
/** Date used for NumericDate comparisons. @default new Date() */
|
|
515
|
-
currentDate?: Date;
|
|
516
|
-
/** Additional required claim names. */
|
|
517
|
-
requiredClaims?: string[];
|
|
518
|
-
/** `crit` header parameters the caller understands (RFC 7515 §4.1.11, RFC 7516 §4.1.13). */
|
|
519
|
-
recognizedHeaders?: string[];
|
|
520
|
-
}
|
|
521
|
-
/** Time claims a producer computes; a claim already in the payload is kept as given. */
|
|
522
|
-
export interface JWTTimeClaimOptions {
|
|
523
|
-
/** Reference moment for `iat` and relative durations. @default new Date() */
|
|
524
|
-
currentDate?: Date;
|
|
525
|
-
/** Duration until `exp`; exclusive with `expiresAt`. */
|
|
526
|
-
expiresIn?: ExpiresIn;
|
|
527
|
-
/** Absolute `exp`; exclusive with `expiresIn`. */
|
|
528
|
-
expiresAt?: Date;
|
|
529
|
-
/** Duration from `iat` until `nbf` (`0` sets `nbf = iat`); exclusive with `notBeforeAt`. */
|
|
530
|
-
notBeforeIn?: ExpiresIn;
|
|
531
|
-
/** Absolute `nbf` (RFC 7519 §4.1.5); exclusive with `notBeforeIn`. */
|
|
532
|
-
notBeforeAt?: Date;
|
|
533
|
-
}
|
|
534
|
-
/** Options shared by `verify` and `decrypt` (compact and multi). */
|
|
535
|
-
export interface JOSEConsumerOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends JWTClaimValidationOptions {
|
|
536
|
-
/** Admit `oct` entries of a JWK Set as key material; only for application-controlled sets. @default false */
|
|
537
|
-
allowSymmetricJWKSet?: boolean;
|
|
538
|
-
/** Payload decoding mode; a mismatch is `ERR_JWS_INVALID` / `ERR_JWE_INVALID`. @default "json" */
|
|
539
|
-
payload?: Mode;
|
|
540
|
-
/**
|
|
541
|
-
* If true, forces the payload to be returned as a `Uint8Array`.
|
|
542
|
-
*
|
|
543
|
-
* @deprecated Use `payload: "bytes"`. Deprecated in v0.8.0, removed in v0.9.0
|
|
544
|
-
*/
|
|
545
|
-
forceUint8Array?: boolean;
|
|
546
|
-
/** `false` skips claim validation; `true` with a non-`"json"` payload is `ERR_INVALID_OPTION`. */
|
|
547
|
-
validateClaims?: boolean;
|
|
548
|
-
}
|
|
549
|
-
export type StrictOmit<T, K extends keyof T | (string & {}) | (number & {}) | (symbol & {})> = { [P in keyof T as P extends K ? never : P]: T[P]; };
|
|
550
|
-
/** JWS Signing Algorithm Identifier. */
|
|
551
|
-
export type JWSAlgorithm = JWK_HMAC | JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_OKP_SIGN;
|
|
552
|
-
/** Asymmetric private JWKs admissible as a signing key. */
|
|
553
|
-
export type JWSAsymmetricPrivateJWK = JWK_RSA_Private<JWK_RSA_SIGN | JWK_RSA_PSS> | JWK_EC_Private<JWK_ECDSA> | JWK_OKP_Private<JWK_OKP_SIGN>;
|
|
554
|
-
/** Asymmetric public JWKs admissible as a verification key. */
|
|
555
|
-
export type JWSAsymmetricPublicJWK = JWK_RSA_Public<JWK_RSA_SIGN | JWK_RSA_PSS> | JWK_EC_Public<JWK_ECDSA> | JWK_OKP_Public<JWK_OKP_SIGN>;
|
|
556
|
-
/** JWKs admissible as a `sign` key; a non-signing `alg` is a type error. */
|
|
557
|
-
export type JWSSignJWK = JWK_oct<JWK_HMAC> | JWSAsymmetricPrivateJWK;
|
|
558
|
-
/** JWKs admissible as a `verify` key; a non-signing `alg` is a type error. */
|
|
559
|
-
export type JWSVerifyJWK = JWK_oct<JWK_HMAC> | JWSAsymmetricPublicJWK;
|
|
560
|
-
/** Recognized JWS Header Parameters; other members may be present. */
|
|
561
|
-
export interface JWSHeaderParameters extends JoseHeaderParameters {
|
|
562
|
-
/** JWS "alg" (Algorithm) Header Parameter */
|
|
563
|
-
alg?: JWSAlgorithm;
|
|
564
|
-
/** `false` signs the payload unencoded (RFC 7797). @default true */
|
|
565
|
-
b64?: boolean;
|
|
566
|
-
}
|
|
567
|
-
/** JWS Protected Header */
|
|
568
|
-
export interface JWSProtectedHeader extends JWSHeaderParameters {
|
|
569
|
-
alg: JWSAlgorithm;
|
|
570
|
-
}
|
|
571
|
-
/** Options for `sign`. */
|
|
572
|
-
export interface JWSSignOptions extends JWTTimeClaimOptions {
|
|
573
|
-
/** JWS algorithm; inferred from the key when omitted. */
|
|
574
|
-
alg?: JWSAlgorithm;
|
|
575
|
-
/** Extra protected header parameters; `alg` cannot be set, `typ` defaults to `"JWT"` for an object payload. */
|
|
576
|
-
protectedHeader?: StrictOmit<JWSHeaderParameters, "alg"> & {
|
|
577
|
-
alg?: never;
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
/** Result of JWS verification. */
|
|
581
|
-
export interface JWSVerifyResult<T extends JOSEPayload = JOSEPayload> {
|
|
582
|
-
payload: T;
|
|
583
|
-
protectedHeader: JWSProtectedHeader;
|
|
584
|
-
}
|
|
585
|
-
/** Options for `verify`; `Mode` is the `payload` option's literal. */
|
|
586
|
-
export interface JWSVerifyOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends JOSEConsumerOptions<Mode> {
|
|
587
|
-
/** Allowed `alg` values; inferred from the key when omitted, required for raw secrets, alg-less JWKs and resolvers. */
|
|
588
|
-
algorithms?: JWSAlgorithm[];
|
|
589
|
-
/** Max JWK Set candidates per token; more is `ERR_JWK_KEY_NOT_FOUND`. @default { keyCandidates: 8 } */
|
|
590
|
-
limits?: Pick<JOSELimits, "keyCandidates">;
|
|
591
|
-
}
|
|
592
|
-
/** JWS Flattened JSON Serialization (RFC 7515 §7.2.2). */
|
|
593
|
-
export interface JWSFlattenedSerialization {
|
|
594
|
-
/** The JWS Payload; base64url-encoded unless `b64: false`. */
|
|
595
|
-
payload: string;
|
|
596
|
-
/** Base64url-encoded JWS Protected Header. */
|
|
597
|
-
protected?: string;
|
|
598
|
-
/** JWS Unprotected Header (not signed). */
|
|
599
|
-
header?: JWSHeaderParameters;
|
|
600
|
-
/** Base64url-encoded signature. */
|
|
601
|
-
signature: string;
|
|
602
|
-
}
|
|
603
|
-
/** JWS General JSON Serialization (RFC 7515 §7.2.1). */
|
|
604
|
-
export interface JWSGeneralSerialization extends Omit<JWSFlattenedSerialization, "protected" | "header" | "signature"> {
|
|
605
|
-
/** One entry per signer. */
|
|
606
|
-
signatures: JWSGeneralSignature[];
|
|
607
|
-
}
|
|
608
|
-
/** A single entry of `JWSGeneralSerialization.signatures`. */
|
|
609
|
-
export type JWSGeneralSignature = Pick<JWSFlattenedSerialization, "protected" | "header" | "signature">;
|
|
610
|
-
/** One signer passed to `signMulti`. */
|
|
611
|
-
export interface JWSMultiSigner {
|
|
612
|
-
/** Signing key; `kid` is taken from a JWK, a `CryptoKey` must set it in `protectedHeader`. */
|
|
613
|
-
key: JWSSignJWK | CryptoKey;
|
|
614
|
-
/** JWS algorithm; inferred from the key when possible, else `ERR_JWS_SIGNER_ALG_INFERENCE`. */
|
|
615
|
-
alg?: JWSAlgorithm;
|
|
616
|
-
/** Per-signer protected header; `b64` must match across signers (RFC 7797 §3), `typ` defaults to `"JWT"`. */
|
|
617
|
-
protectedHeader?: StrictOmit<JWSHeaderParameters, "alg"> & {
|
|
618
|
-
alg?: never;
|
|
619
|
-
};
|
|
620
|
-
/** Per-signer JWS Unprotected Header (not signed). */
|
|
621
|
-
unprotectedHeader?: JWSHeaderParameters;
|
|
622
|
-
}
|
|
623
|
-
/** Options for `signMulti`; `alg` and `protectedHeader` are set per signer. */
|
|
624
|
-
export interface JWSMultiSignOptions extends StrictOmit<JWSSignOptions, "alg" | "protectedHeader"> {}
|
|
625
|
-
/** Options for `verifyMulti`. */
|
|
626
|
-
export interface JWSMultiVerifyOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends JWSVerifyOptions<Mode> {
|
|
627
|
-
/** Max `signatures[]` (more is `ERR_JWS_INVALID`) and JWK Set candidates per signature. @default { signatures: 16, keyCandidates: 8 } */
|
|
628
|
-
limits?: Pick<JOSELimits, "signatures" | "keyCandidates">;
|
|
629
|
-
/** Try only signatures the key could have produced (by `kid`, `kty`, curve, length), else `ERR_JWS_NO_MATCHING_SIGNER`. @default false */
|
|
630
|
-
strictSignerMatch?: boolean;
|
|
631
|
-
}
|
|
632
|
-
/** Result of `verifyMulti`. */
|
|
633
|
-
export interface JWSMultiVerifyResult<T extends JOSEPayload = JOSEPayload> extends Omit<JWSVerifyResult<T>, "protectedHeader"> {
|
|
634
|
-
/** Protected header of the verified signature as signed; `alg` may sit in `signerHeader` (RFC 7515 §7.2.1). */
|
|
635
|
-
protectedHeader: JWSHeaderParameters;
|
|
636
|
-
/** Unprotected header of the verified signature. */
|
|
637
|
-
signerHeader?: JWSHeaderParameters;
|
|
638
|
-
/** Index into `signatures` of the verified signature. */
|
|
639
|
-
signerIndex: number;
|
|
640
|
-
}
|
|
641
|
-
/** Options for `verifyMultiAll`. */
|
|
642
|
-
export interface JWSMultiVerifyAllOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends StrictOmit<JWSMultiVerifyOptions<Mode>, "strictSignerMatch"> {}
|
|
643
|
-
/** Per-signature outcome of `verifyMultiAll`, discriminated by `verified`; failures carry `error`. */
|
|
644
|
-
export type JWSMultiVerifyOutcome<T extends JOSEPayload = JOSEPayload> = {
|
|
645
|
-
signerIndex: number;
|
|
646
|
-
verified: true;
|
|
647
|
-
payload: T;
|
|
648
|
-
protectedHeader: JWSHeaderParameters;
|
|
649
|
-
signerHeader?: JWSHeaderParameters;
|
|
650
|
-
} | {
|
|
651
|
-
signerIndex: number;
|
|
652
|
-
verified: false;
|
|
653
|
-
error: JWTError;
|
|
654
|
-
protectedHeader?: JWSHeaderParameters;
|
|
655
|
-
signerHeader?: JWSHeaderParameters;
|
|
656
|
-
};
|
|
695
|
+
/** `Shape` when `Alg` has a member of that family, else nothing: a family never appears for an `alg` it cannot carry. */
|
|
696
|
+
type OctFor<Alg, Shape> = [Extract<Alg, Exclude<JWKAlgorithm, JWK_Asymmetric_Algorithm>>] extends [never] ? never : Shape;
|
|
697
|
+
type RSAFor<Alg, Shape> = [Extract<Alg, JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC>] extends [never] ? never : Shape;
|
|
698
|
+
type ECFor<Alg, Shape> = [Extract<Alg, JWK_ECDSA | JWK_ECDH_ES>] extends [never] ? never : Shape;
|
|
699
|
+
type OKPFor<Alg, Shape> = [Extract<Alg, JWK_OKP_SIGN | JWK_ECDH_ES>] extends [never] ? never : Shape;
|
|
657
700
|
/** `oct` JWK algorithms admissible for JWE key management (HMAC excluded). */
|
|
658
701
|
type _JWEOctAlg = JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_AES_CBC_HMAC | JWK_PBES2 | "dir";
|
|
659
702
|
/** Asymmetric public JWKs admissible for JWE encryption (RSA-OAEP or ECDH-ES). */
|
|
@@ -667,9 +710,9 @@ export type JWEDecryptJWK = JWK_oct<_JWEOctAlg> | JWEAsymmetricPrivateJWK;
|
|
|
667
710
|
/** Recognized JWE Header Parameters; other members may also be present. */
|
|
668
711
|
export interface JWEHeaderParameters extends JoseHeaderParameters {
|
|
669
712
|
/** Key Management Algorithm. */
|
|
670
|
-
alg?: KeyManagementAlgorithm
|
|
713
|
+
alg?: KeyManagementAlgorithm;
|
|
671
714
|
/** Content Encryption Algorithm. */
|
|
672
|
-
enc?: ContentEncryptionAlgorithm
|
|
715
|
+
enc?: ContentEncryptionAlgorithm;
|
|
673
716
|
/** PBES2 Count. */
|
|
674
717
|
p2c?: number;
|
|
675
718
|
/** PBES2 Salt, base64url. */
|
|
@@ -800,8 +843,10 @@ export interface JWEMultiEncryptOptions extends StrictOmit<JWEEncryptOptions, "a
|
|
|
800
843
|
/** External AAD (RFC 7516 §5.1); empty means none (RFC 7516 §7.2.1); not a string or bytes is `ERR_INVALID_OPTION`. */
|
|
801
844
|
aad?: Uint8Array<ArrayBuffer> | string;
|
|
802
845
|
}
|
|
846
|
+
/** A key lookup for `decrypt`: it receives the validated JWE header. */
|
|
847
|
+
export type JWEKeyLookup<TReturn = CryptoKey | JWK | JWKSet | string | Uint8Array<ArrayBuffer>> = JWKLookupFunction<TReturn, JWEHeaderParameters>;
|
|
803
848
|
/** Key material `decryptMulti` accepts, or a function resolving it from the recipient's header. */
|
|
804
|
-
export type JWEMultiDecryptKey = CryptoKey | JWKSet | JWEDecryptJWK | string | Uint8Array<ArrayBuffer> |
|
|
849
|
+
export type JWEMultiDecryptKey = CryptoKey | JWKSet | JWEDecryptJWK | string | Uint8Array<ArrayBuffer> | JWEKeyLookup;
|
|
805
850
|
/** Options for `decryptMulti`. */
|
|
806
851
|
export interface JWEMultiDecryptOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends JWEDecryptOptions<Mode> {
|
|
807
852
|
/** Max recipients (else `ERR_JWE_INVALID`), JWK Set candidates per recipient, and PBKDF2 iterations summed over the call. Default: `{ recipients: 16, keyCandidates: 8, pbes2Iterations: 2_400_000 }`. */
|