unjwt 0.8.5 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -21
- package/dist/_chunks/algorithms.mjs +44 -20
- package/dist/_chunks/digest.d.mts +4 -4
- package/dist/_chunks/digest.mjs +23 -15
- package/dist/_chunks/error.d.mts +29 -42
- package/dist/_chunks/export.mjs +1 -4
- package/dist/_chunks/index.d.mts +270 -234
- package/dist/_chunks/index2.d.mts +82 -189
- package/dist/_chunks/index4.d.mts +223 -60
- package/dist/_chunks/index5.d.mts +68 -31
- package/dist/_chunks/index6.d.mts +45 -64
- package/dist/_chunks/jwe.mjs +53 -48
- package/dist/_chunks/jwk.mjs +9 -3
- package/dist/_chunks/jws.mjs +55 -50
- package/dist/_chunks/jwt.d.mts +13 -49
- package/dist/_chunks/jwt.mjs +4 -158
- package/dist/_chunks/jwt2.mjs +162 -0
- package/dist/_chunks/libs/unsecure.d.mts +0 -6
- package/dist/_chunks/limits.d.mts +3 -2
- package/dist/_chunks/payload.mjs +13 -7
- package/dist/_chunks/wrap.mjs +3 -1
- package/dist/core/internal.d.mts +50 -2
- package/dist/core/internal.mjs +3 -1
- package/dist/core/jwe/index.d.mts +1 -1
- package/dist/core/jwk/index.d.mts +2 -2
- package/dist/core/jwk/index.mjs +2 -2
- package/dist/dpop/index.d.mts +77 -18
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +4 -4
- package/dist/session/index.d.mts +568 -22
- package/dist/session/index.mjs +1386 -34
- package/dist/utils/index.d.mts +4 -4
- package/dist/utils/index.mjs +2 -10
- package/package.json +4 -32
- package/dist/_chunks/codec-jwe.d.mts +0 -280
- package/dist/_chunks/codec-jws.mjs +0 -1005
- package/dist/_chunks/cookie-attributes.d.mts +0 -12
- package/dist/_chunks/cookie.mjs +0 -50
- package/dist/adapters/elysia/index.d.mts +0 -123
- package/dist/adapters/elysia/index.mjs +0 -120
- package/dist/adapters/h3/index.d.mts +0 -135
- package/dist/adapters/h3/index.mjs +0 -117
- package/dist/adapters/h3v1/index.d.mts +0 -148
- package/dist/adapters/h3v1/index.mjs +0 -128
package/dist/_chunks/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JWTError } from "./error.mjs";
|
|
2
|
-
/** Header Parameters common to
|
|
2
|
+
/** Header Parameters common to JWS and JWE (RFC 7515 §4.1, RFC 7516 §4.1). */
|
|
3
3
|
export interface JoseHeaderParameters {
|
|
4
4
|
/** "kid" (Key ID) Header Parameter */
|
|
5
5
|
kid?: string;
|
|
@@ -21,9 +21,9 @@ export interface JoseHeaderParameters {
|
|
|
21
21
|
crit?: string[];
|
|
22
22
|
[propName: string]: unknown;
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
24
|
+
/** A payload for `sign` and `encrypt`: a string, raw bytes, or an object serialized as JSON. */
|
|
25
25
|
export type JOSEPayload = string | Uint8Array<ArrayBuffer> | object;
|
|
26
|
-
/** How a verified or decrypted payload is
|
|
26
|
+
/** How a verified or decrypted payload is returned: a `"json"` object, a UTF-8 `"string"`, or raw `"bytes"`. */
|
|
27
27
|
export type JOSEPayloadMode = keyof JOSEPayloadTypeMap;
|
|
28
28
|
/** The payload type each `JOSEPayloadMode` resolves to. */
|
|
29
29
|
export interface JOSEPayloadTypeMap<T = JWTClaims> {
|
|
@@ -31,24 +31,25 @@ export interface JOSEPayloadTypeMap<T = JWTClaims> {
|
|
|
31
31
|
string: string;
|
|
32
32
|
bytes: Uint8Array<ArrayBuffer>;
|
|
33
33
|
}
|
|
34
|
-
/** The payload type returned under `Mode
|
|
34
|
+
/** The payload type returned under `Mode`. A union of modes gives the union of their payloads. */
|
|
35
35
|
export type PayloadOf<Mode extends JOSEPayloadMode, T = JWTClaims> = JOSEPayloadTypeMap<T>[Mode];
|
|
36
36
|
/** "cnf" (Confirmation) Claim members (RFC 7800 §3.1), with `jkt` (RFC 9449 §6.1) and `x5t#S256` (RFC 8705 §3.1). */
|
|
37
37
|
export interface JWTConfirmation {
|
|
38
|
-
/** The proof-of-possession key as a public JWK */
|
|
38
|
+
/** The proof-of-possession key as a public JWK. `sign` and `encrypt` throw `ERR_JWT_CLAIM_INVALID` for a private or malformed one. */
|
|
39
39
|
"jwk"?: JWK_Public;
|
|
40
|
-
/** The proof-of-possession key as an encrypted JWK,
|
|
40
|
+
/** The proof-of-possession key as an encrypted JWK, in JWE Compact Serialization. */
|
|
41
41
|
"jwe"?: string;
|
|
42
|
-
/**
|
|
42
|
+
/** The Key ID of a proof-of-possession key the recipient already holds. */
|
|
43
43
|
"kid"?: string;
|
|
44
|
-
/**
|
|
44
|
+
/** The URL of a JWK Set that holds the key, selected by `kid`. */
|
|
45
45
|
"jku"?: string;
|
|
46
|
-
/** The RFC 7638 SHA-256 thumbprint of the DPoP public key */
|
|
46
|
+
/** The RFC 7638 SHA-256 thumbprint of the DPoP public key. */
|
|
47
47
|
"jkt"?: string;
|
|
48
|
-
/** The SHA-256 thumbprint of the client certificate
|
|
48
|
+
/** The base64url SHA-256 thumbprint of the client certificate. */
|
|
49
49
|
"x5t#S256"?: string;
|
|
50
50
|
[member: string]: unknown;
|
|
51
51
|
}
|
|
52
|
+
/** JWT claims (RFC 7519 §4.1). `verify` and `decrypt` check the registered ones against {@link JWTClaimValidationOptions}. */
|
|
52
53
|
export interface JWTClaims {
|
|
53
54
|
/** "iss" (Issuer) Claim */
|
|
54
55
|
iss?: string;
|
|
@@ -64,10 +65,11 @@ export interface JWTClaims {
|
|
|
64
65
|
iat?: number;
|
|
65
66
|
/** "jti" (JWT ID) Claim */
|
|
66
67
|
jti?: string;
|
|
67
|
-
/** "cnf" (Confirmation) Claim
|
|
68
|
+
/** "cnf" (Confirmation) Claim: the proof-of-possession key (RFC 7800). `verify` and `decrypt` do not check it. */
|
|
68
69
|
cnf?: JWTConfirmation;
|
|
69
70
|
[propName: string]: unknown;
|
|
70
71
|
}
|
|
72
|
+
/** A decoded JWT: its JOSE header and its claims. */
|
|
71
73
|
export interface JWT<T = JWTClaims> {
|
|
72
74
|
header: JoseHeaderParameters & {
|
|
73
75
|
/** "alg" (Algorithm) Header Parameter */
|
|
@@ -75,127 +77,130 @@ export interface JWT<T = JWTClaims> {
|
|
|
75
77
|
};
|
|
76
78
|
claims: T;
|
|
77
79
|
}
|
|
78
|
-
/**
|
|
80
|
+
/** Work limits for one call. Each entry is a positive integer, else the call throws `ERR_INVALID_OPTION`. */
|
|
79
81
|
export interface JOSELimits {
|
|
80
|
-
/** Max `signatures[]` entries in a JWS JSON
|
|
82
|
+
/** Max `signatures[]` entries in a JWS JSON Serialization. More throws `ERR_JWS_INVALID`. @default 16 */
|
|
81
83
|
signatures?: number;
|
|
82
|
-
/** Max `recipients[]` entries in a JWE JSON
|
|
84
|
+
/** Max `recipients[]` entries in a JWE JSON Serialization. More throws `ERR_JWE_INVALID`. @default 16 */
|
|
83
85
|
recipients?: number;
|
|
84
|
-
/** Max JWK Set
|
|
86
|
+
/** Max JWK Set keys tried per token, after filtering by `kid`, `alg` and `use`. More throws `ERR_JWK_KEY_NOT_FOUND`. @default 8 */
|
|
85
87
|
keyCandidates?: number;
|
|
86
|
-
/**
|
|
88
|
+
/** Max key trials over all entries of one `verifyMulti`, `verifyMultiAll` or `decryptMulti` call. One trial is one signature check or unwrap with one key. More throws `ERR_JWK_KEY_NOT_FOUND`. @default 16 */
|
|
89
|
+
keyAttempts?: number;
|
|
90
|
+
/** Max PBKDF2 iterations over all PBES2 attempts of one call. More throws `ERR_JWE_INVALID`. @default 2_400_000 */
|
|
87
91
|
pbes2Iterations?: number;
|
|
88
92
|
}
|
|
89
|
-
/** Claim expectations, each checked when set
|
|
93
|
+
/** Claim expectations, each checked when set. A malformed value throws `ERR_INVALID_OPTION`. */
|
|
90
94
|
export interface JWTClaimValidationOptions {
|
|
91
|
-
/**
|
|
95
|
+
/** Accepted `aud` values. The token passes when its `aud` holds one of them (RFC 7519 §4.1.3). Implies presence. */
|
|
92
96
|
audience?: string | string[];
|
|
93
|
-
/**
|
|
97
|
+
/** Accepted `iss` values. Implies presence. */
|
|
94
98
|
issuer?: string | string[];
|
|
95
|
-
/** Expected
|
|
99
|
+
/** Expected `sub` value. Implies presence. */
|
|
96
100
|
subject?: string;
|
|
97
|
-
/**
|
|
101
|
+
/** Oldest accepted `iat`, counted back from `currentDate`. Older throws `ERR_JWT_EXPIRED`. Implies `iat` presence. */
|
|
98
102
|
maxTokenAge?: MaxTokenAge;
|
|
99
|
-
/** Clock skew
|
|
103
|
+
/** Clock skew allowed on `exp`, `nbf` and `iat`: non-negative seconds or a `Duration`. @default 0 */
|
|
100
104
|
clockTolerance?: number | Duration;
|
|
101
|
-
/** Expected
|
|
105
|
+
/** Expected `typ` of the protected header, compared as a media type (RFC 7515 §4.1.9). A missing or different `typ` throws `ERR_JWS_INVALID` or `ERR_JWE_INVALID`. */
|
|
102
106
|
typ?: string;
|
|
103
|
-
/**
|
|
107
|
+
/** The time the claims are checked against. @default new Date() */
|
|
104
108
|
currentDate?: Date;
|
|
105
|
-
/**
|
|
109
|
+
/** Claim names the token must contain, else `ERR_JWT_CLAIM_MISSING`. */
|
|
106
110
|
requiredClaims?: string[];
|
|
107
|
-
/** `crit`
|
|
111
|
+
/** `crit` Header Parameters the caller understands (RFC 7515 §4.1.11, RFC 7516 §4.1.13). Any other `crit` entry throws. */
|
|
108
112
|
recognizedHeaders?: string[];
|
|
109
113
|
}
|
|
110
|
-
/** Time claims
|
|
114
|
+
/** Time claims `sign` and `encrypt` write into an object payload. A claim already in the payload is kept. Any of these options with a string or bytes payload throws `ERR_INVALID_OPTION`. */
|
|
111
115
|
export interface JWTTimeClaimOptions {
|
|
112
|
-
/** The
|
|
116
|
+
/** The current time: the written `iat`, and the base of `expiresIn` and `notBeforeIn`. @default new Date() */
|
|
113
117
|
currentDate?: Date;
|
|
114
|
-
/** Writes `iat
|
|
118
|
+
/** Writes `iat`: `true` as `currentDate`, a `Date` as that instant. Any `exp` or `nbf` option writes `iat` too, even when this is `false`. */
|
|
115
119
|
issuedAt?: boolean | Date;
|
|
116
|
-
/**
|
|
120
|
+
/** Sets `exp` to `currentDate` plus this positive duration. Setting `expiresAt` too throws `ERR_JWT_CLAIM_INVALID`. */
|
|
117
121
|
expiresIn?: ExpiresIn;
|
|
118
|
-
/**
|
|
122
|
+
/** Sets `exp` to this instant. Setting `expiresIn` too throws `ERR_JWT_CLAIM_INVALID`. */
|
|
119
123
|
expiresAt?: Date;
|
|
120
|
-
/**
|
|
124
|
+
/** Sets `nbf` to `currentDate` plus this duration, zero or more. Setting `notBeforeAt` too throws `ERR_JWT_CLAIM_INVALID`. */
|
|
121
125
|
notBeforeIn?: ExpiresIn;
|
|
122
|
-
/**
|
|
126
|
+
/** Sets `nbf` to this instant (RFC 7519 §4.1.5). Setting `notBeforeIn` too throws `ERR_JWT_CLAIM_INVALID`. */
|
|
123
127
|
notBeforeAt?: Date;
|
|
124
128
|
}
|
|
125
|
-
/** Options shared by `verify
|
|
129
|
+
/** Options shared by `verify`, `decrypt` and their multi variants. */
|
|
126
130
|
export interface JOSEConsumerOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends JWTClaimValidationOptions {
|
|
127
|
-
/**
|
|
128
|
-
* Admit `oct` entries of a JWK Set as key material; only for application-controlled sets. @default false
|
|
129
|
-
* @deprecated A JWK Set is key material the caller chose to trust, so its `oct` entries count like any other; the option goes away and symmetric entries are admitted without it.
|
|
130
|
-
*/
|
|
131
|
-
allowSymmetricJWKSet?: boolean;
|
|
132
|
-
/** Payload decoding mode; a mismatch is `ERR_JWS_INVALID` / `ERR_JWE_INVALID`. @default "json" */
|
|
131
|
+
/** How the payload is returned. Under `"json"`, a payload that is not a JSON object throws `ERR_JWS_INVALID` or `ERR_JWE_INVALID`. @default "json" */
|
|
133
132
|
payload?: Mode;
|
|
134
133
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* @
|
|
134
|
+
* `false` skips claim validation. Claims are checked only under `payload: "json"`.
|
|
135
|
+
* `true` with another payload, or a claim option (`audience`, `issuer`, `subject`, `maxTokenAge`, `requiredClaims`) while claims go unchecked, throws `ERR_INVALID_OPTION`.
|
|
136
|
+
* @default true
|
|
138
137
|
*/
|
|
139
|
-
forceUint8Array?: boolean;
|
|
140
|
-
/** `false` skips claim validation; `true` with a non-`"json"` payload is `ERR_INVALID_OPTION`. */
|
|
141
138
|
validateClaims?: boolean;
|
|
142
139
|
}
|
|
143
140
|
export type StrictOmit<T, K extends keyof T | (string & {}) | (number & {}) | (symbol & {})> = { [P in keyof T as P extends K ? never : P]: T[P]; };
|
|
144
|
-
/** JWS
|
|
141
|
+
/** A JWS signing algorithm (RFC 7518 §3, RFC 8037 §3.1). */
|
|
145
142
|
export type JWSAlgorithm = JWK_HMAC | JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_OKP_SIGN;
|
|
146
|
-
/** A key lookup for `verify
|
|
143
|
+
/** A key lookup for `verify` and the multi variants. It receives `{ header, token }`: the decoded JWS header and the token. */
|
|
147
144
|
export type JWSKeyLookup<TReturn = CryptoKey | JWK | JWKSet | string | Uint8Array<ArrayBuffer>> = JWKLookupFunction<TReturn, JWSHeaderParameters>;
|
|
148
|
-
/** JWS algorithms that name their digest (`*256
|
|
145
|
+
/** The JWS algorithms that name their digest (`*256`, `*384`, `*512`). `EdDSA` and `Ed25519` do not. */
|
|
149
146
|
export type JWSHashedAlgorithm = Exclude<JWSAlgorithm, JWK_OKP_SIGN>;
|
|
150
|
-
/**
|
|
147
|
+
/** The asymmetric private JWKs that can sign. */
|
|
151
148
|
export type JWSAsymmetricPrivateJWK = JWK_RSA_Private<JWK_RSA_SIGN | JWK_RSA_PSS> | JWK_EC_Private<JWK_ECDSA> | JWK_OKP_Private<JWK_OKP_SIGN>;
|
|
152
|
-
/**
|
|
149
|
+
/** The asymmetric public JWKs that can verify. */
|
|
153
150
|
export type JWSAsymmetricPublicJWK = JWK_RSA_Public<JWK_RSA_SIGN | JWK_RSA_PSS> | JWK_EC_Public<JWK_ECDSA> | JWK_OKP_Public<JWK_OKP_SIGN>;
|
|
154
|
-
/** JWKs
|
|
151
|
+
/** The JWKs `sign` accepts. A JWK whose `alg` is not a signing algorithm is a type error. */
|
|
155
152
|
export type JWSSignJWK = JWK_oct<JWK_HMAC> | JWSAsymmetricPrivateJWK;
|
|
156
|
-
/** JWKs
|
|
153
|
+
/** The JWKs `verify` accepts. A JWK whose `alg` is not a signing algorithm is a type error. */
|
|
157
154
|
export type JWSVerifyJWK = JWK_oct<JWK_HMAC> | JWSAsymmetricPublicJWK;
|
|
158
|
-
/**
|
|
155
|
+
/** JWS Header Parameters (RFC 7515 §4.1). Other members are allowed. */
|
|
159
156
|
export interface JWSHeaderParameters extends JoseHeaderParameters {
|
|
160
|
-
/**
|
|
157
|
+
/** "alg" (Algorithm) Header Parameter */
|
|
161
158
|
alg?: JWSAlgorithm;
|
|
162
|
-
/** `false` signs the payload unencoded (RFC 7797). @default true */
|
|
159
|
+
/** `false` signs the payload unencoded (RFC 7797). Allowed in the protected header only. @default true */
|
|
163
160
|
b64?: boolean;
|
|
164
161
|
}
|
|
165
|
-
/** JWS Protected Header */
|
|
162
|
+
/** A JWS Protected Header, which always holds `alg`. */
|
|
166
163
|
export interface JWSProtectedHeader extends JWSHeaderParameters {
|
|
167
164
|
alg: JWSAlgorithm;
|
|
168
165
|
}
|
|
169
166
|
/** Options for `sign`. */
|
|
170
167
|
export interface JWSSignOptions extends JWTTimeClaimOptions {
|
|
171
|
-
/**
|
|
168
|
+
/** The signing algorithm. Defaults to the JWK's `alg`, else to the one an EC or Ed25519 JWK's curve names. A key that names none throws `ERR_JWS_ALG_MISSING`. */
|
|
172
169
|
alg?: JWSAlgorithm;
|
|
173
|
-
/**
|
|
170
|
+
/**
|
|
171
|
+
* Protected Header Parameters to add. `alg` cannot be set here.
|
|
172
|
+
* `kid` defaults to the JWK's `kid`. `typ` defaults to `"JWT"` for an object payload.
|
|
173
|
+
* A `jwk` member must be a public JWK, else `ERR_INVALID_OPTION`.
|
|
174
|
+
*/
|
|
174
175
|
protectedHeader?: StrictOmit<JWSHeaderParameters, "alg"> & {
|
|
175
176
|
alg?: never;
|
|
176
177
|
};
|
|
177
178
|
}
|
|
178
|
-
/**
|
|
179
|
+
/** The result of `verify`. */
|
|
179
180
|
export interface JWSVerifyResult<T extends JOSEPayload = JOSEPayload> {
|
|
180
181
|
payload: T;
|
|
181
182
|
protectedHeader: JWSProtectedHeader;
|
|
182
183
|
}
|
|
183
|
-
/** Options for `verify
|
|
184
|
+
/** Options for `verify`. `Mode` is the literal of the `payload` option. */
|
|
184
185
|
export interface JWSVerifyOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends JOSEConsumerOptions<Mode> {
|
|
185
|
-
/**
|
|
186
|
+
/**
|
|
187
|
+
* The accepted header `alg` values, else `ERR_JWS_ALG_NOT_ALLOWED`.
|
|
188
|
+
* When omitted, the key's JWK `alg` is the policy, else the algorithms its type serves.
|
|
189
|
+
* Pass it for raw bytes and for an `oct` or RSA JWK without `alg`.
|
|
190
|
+
*/
|
|
186
191
|
algorithms?: JWSAlgorithm[];
|
|
187
|
-
/** Max JWK Set
|
|
192
|
+
/** Max JWK Set keys tried per token. More throws `ERR_JWK_KEY_NOT_FOUND`. @default { keyCandidates: 8 } */
|
|
188
193
|
limits?: Pick<JOSELimits, "keyCandidates">;
|
|
189
194
|
}
|
|
190
195
|
/** JWS Flattened JSON Serialization (RFC 7515 §7.2.2). */
|
|
191
196
|
export interface JWSFlattenedSerialization {
|
|
192
|
-
/** The JWS Payload
|
|
197
|
+
/** The JWS Payload, base64url-encoded unless `b64` is `false`. */
|
|
193
198
|
payload: string;
|
|
194
|
-
/**
|
|
199
|
+
/** The base64url-encoded JWS Protected Header. */
|
|
195
200
|
protected?: string;
|
|
196
|
-
/** JWS Unprotected Header
|
|
201
|
+
/** The JWS Unprotected Header, which the signature does not cover. */
|
|
197
202
|
header?: JWSHeaderParameters;
|
|
198
|
-
/**
|
|
203
|
+
/** The base64url-encoded signature. */
|
|
199
204
|
signature: string;
|
|
200
205
|
}
|
|
201
206
|
/** JWS General JSON Serialization (RFC 7515 §7.2.1). */
|
|
@@ -203,42 +208,46 @@ export interface JWSGeneralSerialization extends Omit<JWSFlattenedSerialization,
|
|
|
203
208
|
/** One entry per signer. */
|
|
204
209
|
signatures: JWSGeneralSignature[];
|
|
205
210
|
}
|
|
206
|
-
/**
|
|
211
|
+
/** One entry of `JWSGeneralSerialization.signatures`. */
|
|
207
212
|
export type JWSGeneralSignature = Pick<JWSFlattenedSerialization, "protected" | "header" | "signature">;
|
|
208
|
-
/** One signer
|
|
213
|
+
/** One signer of `signMulti`. */
|
|
209
214
|
export interface JWSMultiSigner {
|
|
210
|
-
/**
|
|
215
|
+
/** The signing key. A JWK's `kid` is written to the protected header. For a `CryptoKey`, set `kid` in `protectedHeader`. */
|
|
211
216
|
key: JWSSignJWK | CryptoKey;
|
|
212
|
-
/**
|
|
217
|
+
/** The signing algorithm. Defaults to the one the key names, an EC or Ed25519 JWK's curve included, else `ERR_JWS_SIGNER_ALG_INFERENCE`. */
|
|
213
218
|
alg?: JWSAlgorithm;
|
|
214
|
-
/**
|
|
219
|
+
/** This signer's Protected Header Parameters. `b64` must match across signers (RFC 7797 §3). `typ` defaults to `"JWT"` for an object payload. */
|
|
215
220
|
protectedHeader?: StrictOmit<JWSHeaderParameters, "alg"> & {
|
|
216
221
|
alg?: never;
|
|
217
222
|
};
|
|
218
|
-
/**
|
|
223
|
+
/** This signer's JWS Unprotected Header. It cannot hold `crit`, `b64`, or a name the protected header holds. */
|
|
219
224
|
unprotectedHeader?: JWSHeaderParameters;
|
|
220
225
|
}
|
|
221
|
-
/** Options for `signMulti
|
|
226
|
+
/** Options for `signMulti`. `alg` and `protectedHeader` are set per signer. */
|
|
222
227
|
export interface JWSMultiSignOptions extends StrictOmit<JWSSignOptions, "alg" | "protectedHeader"> {}
|
|
223
228
|
/** Options for `verifyMulti`. */
|
|
224
229
|
export interface JWSMultiVerifyOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends JWSVerifyOptions<Mode> {
|
|
225
|
-
/**
|
|
226
|
-
|
|
227
|
-
|
|
230
|
+
/**
|
|
231
|
+
* Max `signatures[]` entries (more throws `ERR_JWS_INVALID`), JWK Set keys per signature, and key trials over the call.
|
|
232
|
+
* Too many keys or trials throws `ERR_JWK_KEY_NOT_FOUND`.
|
|
233
|
+
* @default { signatures: 16, keyCandidates: 8, keyAttempts: 16 }
|
|
234
|
+
*/
|
|
235
|
+
limits?: Pick<JOSELimits, "signatures" | "keyCandidates" | "keyAttempts">;
|
|
236
|
+
/** Skips signatures whose `kid` or `alg` the key cannot serve. No signature left throws `ERR_JWS_NO_MATCHING_SIGNER`. @default false */
|
|
228
237
|
strictSignerMatch?: boolean;
|
|
229
238
|
}
|
|
230
|
-
/**
|
|
239
|
+
/** The result of `verifyMulti`: the first signature that verified. */
|
|
231
240
|
export interface JWSMultiVerifyResult<T extends JOSEPayload = JOSEPayload> extends Omit<JWSVerifyResult<T>, "protectedHeader"> {
|
|
232
|
-
/**
|
|
241
|
+
/** The verified signature's protected header, as signed. `alg` can be in `signerHeader` instead (RFC 7515 §7.2.1). */
|
|
233
242
|
protectedHeader: JWSHeaderParameters;
|
|
234
|
-
/**
|
|
243
|
+
/** The verified signature's unprotected header. */
|
|
235
244
|
signerHeader?: JWSHeaderParameters;
|
|
236
|
-
/**
|
|
245
|
+
/** The verified signature's index in `signatures`. */
|
|
237
246
|
signerIndex: number;
|
|
238
247
|
}
|
|
239
248
|
/** Options for `verifyMultiAll`. */
|
|
240
249
|
export interface JWSMultiVerifyAllOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends StrictOmit<JWSMultiVerifyOptions<Mode>, "strictSignerMatch"> {}
|
|
241
|
-
/**
|
|
250
|
+
/** One signature's outcome in `verifyMultiAll`. `verified: false` holds the `error`. */
|
|
242
251
|
export type JWSMultiVerifyOutcome<T extends JOSEPayload = JOSEPayload> = {
|
|
243
252
|
signerIndex: number;
|
|
244
253
|
verified: true;
|
|
@@ -252,7 +261,7 @@ export type JWSMultiVerifyOutcome<T extends JOSEPayload = JOSEPayload> = {
|
|
|
252
261
|
protectedHeader?: JWSHeaderParameters;
|
|
253
262
|
signerHeader?: JWSHeaderParameters;
|
|
254
263
|
};
|
|
255
|
-
/**
|
|
264
|
+
/** The decoded header a `JWKLookupFunction` receives. Its `alg` and `enc` are already checked as supported. `enc` is set on a JWE only. */
|
|
256
265
|
export type JWKLookupFunctionHeader = {
|
|
257
266
|
kid?: string;
|
|
258
267
|
alg?: JWSAlgorithm | KeyManagementAlgorithm;
|
|
@@ -261,117 +270,125 @@ export type JWKLookupFunctionHeader = {
|
|
|
261
270
|
crit?: string[];
|
|
262
271
|
[propName: string]: unknown;
|
|
263
272
|
};
|
|
264
|
-
/**
|
|
265
|
-
|
|
266
|
-
|
|
273
|
+
/**
|
|
274
|
+
* Returns the key that verifies or decrypts a token, from `{ header, token }`: its decoded header and the token itself.
|
|
275
|
+
* A string is a PBES2 password on a JWE. Any other use of a string throws `ERR_JWK_INVALID`.
|
|
276
|
+
* `undefined` means no key for this token, reported as `ERR_JWK_KEY_NOT_FOUND`. A thrown `JWTError` propagates as it is,
|
|
277
|
+
* and any other throw is `ERR_JWK_KEY_NOT_FOUND` with the thrown error as `cause`.
|
|
278
|
+
*/
|
|
279
|
+
export type JWKLookupFunction<TReturn = CryptoKey | JWK | JWKSet | string | Uint8Array<ArrayBuffer>, THeader = JWKLookupFunctionHeader> = (lookup: {
|
|
280
|
+
header: THeader;
|
|
281
|
+
token: string;
|
|
282
|
+
}) => TReturn | undefined | Promise<TReturn | undefined>;
|
|
283
|
+
/** A JWK import cache for `configureJWKCache`. Both methods can return a promise. Key the entries on the RFC 7638 thumbprint, the private or public half, and `alg`, never on `kid`. */
|
|
267
284
|
export interface JWKCacheAdapter {
|
|
268
285
|
get(jwk: JWK, alg: JWKAlgorithm): CryptoKey | undefined | Promise<CryptoKey | undefined>;
|
|
269
286
|
set(jwk: JWK, alg: JWKAlgorithm, key: CryptoKey): void | Promise<void>;
|
|
270
287
|
}
|
|
271
|
-
/**
|
|
288
|
+
/** A composite AES-CBC with HMAC key, split into its two halves. */
|
|
272
289
|
export type CompositeKey = {
|
|
273
290
|
encryptionKey: CryptoKey;
|
|
274
291
|
macKey: CryptoKey;
|
|
275
292
|
};
|
|
276
293
|
export type GenerateKeyAlgorithm = Exclude<JWKAlgorithm, "none" | "dir" | JWK_PBES2>;
|
|
277
|
-
/** Options for `generateJWK
|
|
294
|
+
/** Options for `generateJWK`. `Kid` is the type of the `kid` option, which types the generated `kid`. */
|
|
278
295
|
export interface GenerateJWKOptions<Kid extends string | false = string | false> {
|
|
279
|
-
/**
|
|
296
|
+
/** Narrows the usages `alg` admits and is written as `key_ops`. Without it, the key has every usage `alg` admits and no `key_ops`. */
|
|
280
297
|
keyUsage?: KeyUsage[];
|
|
281
|
-
/** RSA modulus length. Default: `2048`. */
|
|
298
|
+
/** The RSA modulus length in bits, at least 2048. Default: `2048`. */
|
|
282
299
|
modulusLength?: number;
|
|
283
|
-
/** RSA public exponent. Default: `65537`. */
|
|
300
|
+
/** The RSA public exponent as big-endian bytes. Default: `65537`. */
|
|
284
301
|
publicExponent?: Uint8Array<ArrayBuffer>;
|
|
285
|
-
/**
|
|
302
|
+
/** The curve for `ECDH-ES*` and `EdDSA`. `ES*` and `Ed25519` fix their own curve. Default: `"P-256"` for `ECDH-ES*`, `"Ed25519"` for `EdDSA`. */
|
|
286
303
|
namedCurve?: "P-256" | "P-384" | "P-521" | "X25519" | "Ed25519";
|
|
287
|
-
/** `kid` to set
|
|
304
|
+
/** The `kid` to set as given, or `false` for none. Default: the key's RFC 7638 SHA-256 thumbprint. */
|
|
288
305
|
kid?: Kid;
|
|
289
306
|
}
|
|
290
|
-
/** Options for `generateKey
|
|
307
|
+
/** Options for `generateKey`. `ToJWK` is the literal of the `toJWK` option, which picks key objects or JWKs. */
|
|
291
308
|
export interface GenerateKeyOptions<ToJWK extends boolean = boolean, Kid extends string | false = string | false> extends GenerateJWKOptions<Kid> {
|
|
292
|
-
/**
|
|
309
|
+
/** Makes the generated keys extractable. Ignored with `toJWK`. Default: `true`. */
|
|
293
310
|
extractable?: boolean;
|
|
294
|
-
/**
|
|
311
|
+
/** Returns JWKs instead of key objects. Default: `false`. */
|
|
295
312
|
toJWK?: ToJWK;
|
|
296
|
-
/**
|
|
313
|
+
/** With `toJWK`, the `kid` to set as given, or `false` for none. Ignored without `toJWK`. Default: the key's RFC 7638 SHA-256 thumbprint. */
|
|
297
314
|
kid?: Kid;
|
|
298
315
|
}
|
|
299
|
-
/** `generateKey` result per algorithm without `toJWK`: `CryptoKey` (symmetric), raw bytes (`A*CBC-HS*`), `CryptoKeyPair` (asymmetric). */
|
|
316
|
+
/** The `generateKey` result per algorithm without `toJWK`: a `CryptoKey` (symmetric), raw bytes (`A*CBC-HS*`), or a `CryptoKeyPair` (asymmetric). */
|
|
300
317
|
export type GeneratedKeyMap = { [A in GenerateKeyAlgorithm]: A extends JWK_AES_CBC_HMAC ? Uint8Array<ArrayBuffer> : A extends JWK_Asymmetric_Algorithm ? CryptoKeyPair : CryptoKey; };
|
|
301
|
-
/** `generateJWK` result per algorithm: an `oct` JWK or a JWK pair
|
|
318
|
+
/** The `generateJWK` result per algorithm: an `oct` JWK or a JWK pair. Each JWK has `alg`, and `kid` unless `Kid` is `false`. */
|
|
302
319
|
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>; };
|
|
303
|
-
/** `generateKey` return type for `TAlg` under `TOptions
|
|
320
|
+
/** The `generateKey` return type for `TAlg` under `TOptions`. JWKs when `toJWK` is `true`. */
|
|
304
321
|
export type GenerateKeyReturn<TAlg extends GenerateKeyAlgorithm, TOptions extends GenerateKeyOptions> = GeneratedKeyShape<TAlg, Exclude<TOptions["toJWK"], undefined>, GeneratedKid<TOptions>>;
|
|
305
|
-
/** `generateJWK` return type for `TAlg` under the `kid` option `Kid`. */
|
|
322
|
+
/** The `generateJWK` return type for `TAlg` under the `kid` option `Kid`. */
|
|
306
323
|
export type GenerateJWKReturn<TAlg extends GenerateKeyAlgorithm, Kid extends string | false = string> = GeneratedJWKMap<Kid>[TAlg];
|
|
307
|
-
/** What `importKey`
|
|
324
|
+
/** What `importKey` returns per input: raw bytes for bytes and `oct` JWKs, the same `CryptoKey` for a `CryptoKey`, and a `CryptoKey` for an asymmetric JWK. */
|
|
308
325
|
export interface ImportedKeyMap {
|
|
309
326
|
bytes: Uint8Array<ArrayBuffer>;
|
|
310
327
|
oct: Uint8Array<ArrayBuffer>;
|
|
311
328
|
cryptoKey: CryptoKey;
|
|
312
329
|
asymmetric: CryptoKey;
|
|
313
330
|
}
|
|
314
|
-
/** `ImportedKeyMap` entry for key input `K
|
|
331
|
+
/** The `ImportedKeyMap` entry for key input `K`. A union input gives a union. */
|
|
315
332
|
export type ImportedKey<K> = ImportedKeyMap[K extends Uint8Array ? "bytes" : K extends CryptoKey ? "cryptoKey" : K extends JWK_oct ? "oct" : "asymmetric"];
|
|
316
333
|
/** Options for `deriveKeyFromPassword`. */
|
|
317
334
|
export interface DeriveKeyOptions {
|
|
318
335
|
alg: JWK_PBES2;
|
|
319
|
-
/**
|
|
336
|
+
/** The salt (`p2s`) as bytes or UTF-8 text, at least 8 octets (RFC 7518 §4.8.1.1). */
|
|
320
337
|
salt: string | Uint8Array<ArrayBuffer>;
|
|
321
|
-
/**
|
|
338
|
+
/** The iteration count (`p2c`), an integer of at least 1000 (RFC 7518 §4.8.1.2). */
|
|
322
339
|
iterations: number;
|
|
323
|
-
/**
|
|
340
|
+
/** The derived key's usages, written as `key_ops` with `toJWK`. Default: `["wrapKey", "unwrapKey"]`. */
|
|
324
341
|
keyUsage?: KeyUsage[];
|
|
325
|
-
/**
|
|
342
|
+
/** Makes the derived key extractable. Ignored with `toJWK`. Default: `false`. */
|
|
326
343
|
extractable?: boolean;
|
|
327
|
-
/**
|
|
344
|
+
/** Returns the derived key as a `JWK_oct` with the inner AES-KW `alg`. Default: `false`. */
|
|
328
345
|
toJWK?: boolean;
|
|
329
346
|
}
|
|
330
|
-
/** The AES-KW algorithm a `PBES2-*` or `ECDH-ES+*` algorithm wraps the CEK with
|
|
347
|
+
/** The AES-KW algorithm a `PBES2-*` or `ECDH-ES+*` algorithm wraps the CEK with. */
|
|
331
348
|
export type KeyWrapAlgorithmOf<A extends KeyWrappingAlgorithm> = A extends `${string}A128KW` ? "A128KW" : A extends `${string}A192KW` ? "A192KW" : A extends `${string}A256KW` ? "A256KW" : never;
|
|
332
|
-
/**
|
|
349
|
+
/** The key management algorithms that wrap the CEK with an inner AES-KW step. */
|
|
333
350
|
export type KeyWrappingAlgorithm = JWK_PBES2 | Exclude<JWK_ECDH_ES, "ECDH-ES">;
|
|
334
|
-
/**
|
|
351
|
+
/** The AES-KW `alg` of the JWK derived for a PBES2 algorithm. */
|
|
335
352
|
type DerivedJWKAlg<TAlg extends JWK_PBES2> = KeyWrapAlgorithmOf<TAlg>;
|
|
336
353
|
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;
|
|
337
|
-
/** Options
|
|
354
|
+
/** Options for `deriveJWKFromPassword`: the `deriveKeyFromPassword` options without `toJWK` and `extractable`, plus `kid` (`false` for none). */
|
|
338
355
|
export type DeriveJWKOptions<TAlg extends JWK_PBES2 = JWK_PBES2, Kid extends string | false = string> = Omit<DeriveKeyOptions, "alg" | "toJWK" | "extractable"> & {
|
|
339
356
|
alg: TAlg;
|
|
340
357
|
kid?: Kid;
|
|
341
358
|
};
|
|
342
|
-
/** `deriveJWKFromPassword` return type: the AES-KW `oct` JWK for `TAlg`, with `kid` unless `Kid` is `false`. */
|
|
359
|
+
/** The `deriveJWKFromPassword` return type: the AES-KW `oct` JWK for `TAlg`, with `kid` unless `Kid` is `false`. */
|
|
343
360
|
export type DeriveJWKReturn<TAlg extends JWK_PBES2, Kid extends string | false = string> = JWK_oct<DerivedJWKAlg<TAlg>> & GeneratedJWKMembers<DerivedJWKAlg<TAlg>, Kid>;
|
|
344
|
-
/** PEM
|
|
361
|
+
/** The PEM types `importPEM` reads. */
|
|
345
362
|
export type PEMType = "pkcs8" | "spki" | "x509";
|
|
346
|
-
/** `importPEM` result for `Alg`:
|
|
363
|
+
/** The `importPEM` result for `Alg`: a private JWK for PKCS#8, a public JWK for SPKI or X.509, and either when the type is inferred. */
|
|
347
364
|
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"];
|
|
348
365
|
export type KeyManagementAlgorithm = JWK_RSA_ENC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_PBES2 | JWK_ECDH_ES | "dir";
|
|
349
366
|
export type ContentEncryptionAlgorithm = JWK_AES_GCM | JWK_AES_CBC_HMAC;
|
|
350
|
-
/**
|
|
367
|
+
/** The keys `wrapKey` accepts as `wrappingKey` for algorithm `A`. `dir` takes any symmetric key. */
|
|
351
368
|
export type WrappingKeyFor<A extends KeyManagementAlgorithm> = A extends JWK_RSA_ENC ? CryptoKey | JWK_RSA_Public<A> : A extends JWK_ECDH_ES ? CryptoKey | JWK_EC_Public<A> | JWK_OKP_Public<A> : A extends JWK_PBES2 ? string | Uint8Array<ArrayBuffer> | JWK_oct<A> : A extends JWK_AES_KW ? CryptoKey | JWK_oct<A> : A extends JWK_AES_GCM_KW ? CryptoKey | JWK_oct<A> : A extends "dir" ? CryptoKey | JWK_oct | Uint8Array<ArrayBuffer> : never;
|
|
352
|
-
/**
|
|
369
|
+
/** The keys `unwrapKey` accepts as `unwrappingKey` for algorithm `A`. */
|
|
353
370
|
export type UnwrappingKeyFor<A extends KeyManagementAlgorithm> = A extends JWK_RSA_ENC ? CryptoKey | JWK_RSA_Private<A> : A extends JWK_ECDH_ES ? CryptoKey | JWK_EC_Private<A> | JWK_OKP_Private<A> : A extends JWK_PBES2 ? string | Uint8Array<ArrayBuffer> | JWK_oct<A> : A extends JWK_AES_KW ? CryptoKey | JWK_oct<A> : A extends JWK_AES_GCM_KW ? CryptoKey | JWK_oct<A> : A extends "dir" ? CryptoKey | JWK_oct | Uint8Array<ArrayBuffer> : never;
|
|
354
371
|
/** Options for `wrapKey`. */
|
|
355
372
|
export interface WrapKeyOptions<TAlg extends KeyManagementAlgorithm = KeyManagementAlgorithm> {
|
|
356
373
|
alg: TAlg;
|
|
357
|
-
/** AES-GCMKW IV
|
|
374
|
+
/** The AES-GCMKW IV. Random when omitted. Pass one only for tests and known vectors: an IV reused under one key breaks AES-GCM. */
|
|
358
375
|
iv?: Uint8Array<ArrayBuffer>;
|
|
359
|
-
/** PBES2
|
|
376
|
+
/** The PBES2 salt (`p2s`), at least 8 octets. Required for PBES2, else `ERR_JWE_INVALID`. */
|
|
360
377
|
p2s?: Uint8Array<ArrayBuffer>;
|
|
361
|
-
/** PBES2
|
|
378
|
+
/** The PBES2 iteration count (`p2c`), from 1000 to `600_000`. Required for PBES2, else `ERR_JWE_INVALID`. */
|
|
362
379
|
p2c?: number;
|
|
363
380
|
ecdh?: {
|
|
364
|
-
/**
|
|
381
|
+
/** The ephemeral key. Generated when omitted. */
|
|
365
382
|
ephemeralKey?: ECDHEphemeralKeyInput;
|
|
366
|
-
/**
|
|
383
|
+
/** The agreement PartyUInfo (`apu`), at most 1024 bytes. */
|
|
367
384
|
partyUInfo?: Uint8Array<ArrayBuffer>;
|
|
368
|
-
/**
|
|
385
|
+
/** The agreement PartyVInfo (`apv`), at most 1024 bytes. */
|
|
369
386
|
partyVInfo?: Uint8Array<ArrayBuffer>;
|
|
370
|
-
/** Required
|
|
387
|
+
/** The content encryption algorithm. Required for direct `"ECDH-ES"`, else `ERR_JWK_INVALID`. */
|
|
371
388
|
enc?: ContentEncryptionAlgorithm;
|
|
372
389
|
};
|
|
373
390
|
}
|
|
374
|
-
/**
|
|
391
|
+
/** The result of `wrapKey`, shaped by the `alg` family. String members are base64url. */
|
|
375
392
|
export type WrapKeyResult<TAlg extends KeyManagementAlgorithm = KeyManagementAlgorithm> = TAlg extends JWK_PBES2 ? {
|
|
376
393
|
encryptedKey: Uint8Array<ArrayBuffer>;
|
|
377
394
|
p2s: string;
|
|
@@ -391,38 +408,41 @@ export type WrapKeyResult<TAlg extends KeyManagementAlgorithm = KeyManagementAlg
|
|
|
391
408
|
/** Options for `unwrapKey`. */
|
|
392
409
|
export interface UnwrapKeyOptions<TAlg extends KeyManagementAlgorithm = KeyManagementAlgorithm> {
|
|
393
410
|
alg: TAlg;
|
|
394
|
-
/** `"cryptokey"` returns a `CryptoKey`, `"raw"` the key bytes. Default: `"cryptokey"`. */
|
|
411
|
+
/** `"cryptokey"` returns a `CryptoKey`, `"raw"` returns the key bytes. Default: `"cryptokey"`. */
|
|
395
412
|
format?: "cryptokey" | "raw";
|
|
396
|
-
/**
|
|
413
|
+
/** The AES-GCMKW IV, as base64url or bytes. Required for AES-GCMKW. */
|
|
397
414
|
iv?: Uint8Array<ArrayBuffer> | string;
|
|
398
|
-
/**
|
|
415
|
+
/** The AES-GCMKW tag, as base64url or bytes. Required for AES-GCMKW. */
|
|
399
416
|
tag?: Uint8Array<ArrayBuffer> | string;
|
|
400
|
-
/**
|
|
417
|
+
/** The PBES2 salt, as base64url or bytes. Required for PBES2. */
|
|
401
418
|
p2s?: Uint8Array<ArrayBuffer> | string;
|
|
402
|
-
/** Required for PBES2. */
|
|
419
|
+
/** The PBES2 iteration count. Required for PBES2. */
|
|
403
420
|
p2c?: number;
|
|
404
|
-
/**
|
|
421
|
+
/** The lowest PBES2 `p2c` accepted, else `ERR_JWE_INVALID` (RFC 7518 §4.8.1.2). Default: `1000`. */
|
|
405
422
|
minIterations?: number;
|
|
406
|
-
/**
|
|
423
|
+
/** The highest PBES2 `p2c` accepted, else `ERR_JWE_INVALID`. Default: `600_000`. */
|
|
407
424
|
maxIterations?: number;
|
|
408
|
-
/** Required for ECDH-ES. */
|
|
425
|
+
/** The sender's ephemeral public key. Required for ECDH-ES. */
|
|
409
426
|
epk?: JWK_EC_Public | JWK_OKP_Public | CryptoKey;
|
|
427
|
+
/** The agreement PartyUInfo, as base64url or bytes, at most 1024 bytes. */
|
|
410
428
|
apu?: Uint8Array<ArrayBuffer> | string;
|
|
429
|
+
/** The agreement PartyVInfo, as base64url or bytes, at most 1024 bytes. */
|
|
411
430
|
apv?: Uint8Array<ArrayBuffer> | string;
|
|
412
|
-
/** Required for direct ECDH-ES key
|
|
431
|
+
/** The content encryption algorithm. Required for direct ECDH-ES. With `dir` and RSA-OAEP, it checks the key length and picks the import algorithm. */
|
|
413
432
|
enc?: ContentEncryptionAlgorithm;
|
|
414
|
-
/**
|
|
433
|
+
/** The algorithm the unwrapped key is imported as. Default: AES-GCM, or for RSA-OAEP the one `enc` and the key length name. */
|
|
415
434
|
unwrappedKeyAlgorithm?: string | Algorithm | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams;
|
|
435
|
+
/** The unwrapped key's usages. Default: `["encrypt", "decrypt"]`. */
|
|
416
436
|
keyUsage?: KeyUsage[];
|
|
417
|
-
/**
|
|
437
|
+
/** Makes the unwrapped key extractable. Default: `true`. */
|
|
418
438
|
extractable?: boolean;
|
|
419
439
|
}
|
|
420
|
-
/**
|
|
440
|
+
/** The result of `unwrapKey`: bytes for `format: "raw"`, else a `CryptoKey`. A non-literal `format` gives both. */
|
|
421
441
|
export type UnwrapKeyResult<TOptions extends {
|
|
422
442
|
format?: "cryptokey" | "raw";
|
|
423
443
|
}> = "format" extends keyof TOptions ? [TOptions["format"]] extends ["raw"] ? Uint8Array<ArrayBuffer> : [TOptions["format"]] extends ["cryptokey" | undefined] ? CryptoKey : CryptoKey | Uint8Array<ArrayBuffer> : CryptoKey;
|
|
424
444
|
/** 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 */
|
|
425
|
-
/**
|
|
445
|
+
/** The JWK members common to every key type (RFC 7517 §4). `Alg` constrains `alg`. */
|
|
426
446
|
export interface JWKParameters<Alg extends JWKAlgorithm = JWKAlgorithm> {
|
|
427
447
|
/** JWK "kty" (Key Type) Parameter */
|
|
428
448
|
"kty": string;
|
|
@@ -444,17 +464,17 @@ export interface JWKParameters<Alg extends JWKAlgorithm = JWKAlgorithm> {
|
|
|
444
464
|
"x5u"?: string;
|
|
445
465
|
/** JWK "kid" (Key ID) Parameter */
|
|
446
466
|
"kid"?: string;
|
|
447
|
-
/**
|
|
467
|
+
/** A content encryption hint outside RFC 7517. `encrypt` reads it when no `enc` option is given. */
|
|
448
468
|
"enc"?: ContentEncryptionAlgorithm;
|
|
449
469
|
}
|
|
450
|
-
/** JWK members a caller
|
|
470
|
+
/** The JWK members a caller can set on a generated or derived key: all but `alg`, `kty`, `key_ops` and `ext`. */
|
|
451
471
|
export type JWKMetadata = Omit<JWKParameters, "alg" | "kty" | "key_ops" | "ext">;
|
|
452
|
-
/** ECDH-ES ephemeral key
|
|
472
|
+
/** An ECDH-ES ephemeral key: a private key, a `CryptoKeyPair`, or an object with both halves. */
|
|
453
473
|
export type ECDHEphemeralKeyInput = CryptoKey | JWK_EC_Private | JWK_OKP_Private | CryptoKeyPair | {
|
|
454
474
|
publicKey: CryptoKey | JWK_EC_Public | JWK_OKP_Public;
|
|
455
475
|
privateKey: CryptoKey | JWK_EC_Private | JWK_OKP_Private;
|
|
456
476
|
};
|
|
457
|
-
/**
|
|
477
|
+
/** A public EC JWK. */
|
|
458
478
|
export interface JWK_EC_Public<Alg extends JWK_ECDSA | JWK_ECDH_ES = JWK_ECDSA | JWK_ECDH_ES> extends JWKParameters<Alg> {
|
|
459
479
|
kty: "EC";
|
|
460
480
|
/** EC JWK "crv" (Curve) Parameter */
|
|
@@ -464,14 +484,14 @@ export interface JWK_EC_Public<Alg extends JWK_ECDSA | JWK_ECDH_ES = JWK_ECDSA |
|
|
|
464
484
|
/** EC JWK "y" (Y Coordinate) Parameter */
|
|
465
485
|
y: string;
|
|
466
486
|
}
|
|
467
|
-
/**
|
|
487
|
+
/** A private EC JWK. */
|
|
468
488
|
export interface JWK_EC_Private<Alg extends JWK_ECDSA | JWK_ECDH_ES = JWK_ECDSA | JWK_ECDH_ES> extends JWK_EC_Public<Alg> {
|
|
469
489
|
/** EC JWK "d" (ECC Private Key) Parameter */
|
|
470
490
|
d: string;
|
|
471
491
|
}
|
|
472
|
-
/**
|
|
492
|
+
/** A public or private EC JWK. */
|
|
473
493
|
export type JWK_EC<Alg extends JWK_ECDSA | JWK_ECDH_ES = JWK_ECDSA | JWK_ECDH_ES> = JWK_EC_Public<Alg> | JWK_EC_Private<Alg>;
|
|
474
|
-
/**
|
|
494
|
+
/** A public RSA JWK. */
|
|
475
495
|
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> {
|
|
476
496
|
kty: "RSA";
|
|
477
497
|
/** RSA JWK "e" (Exponent) Parameter */
|
|
@@ -480,7 +500,7 @@ export interface JWK_RSA_Public<Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA
|
|
|
480
500
|
n: string;
|
|
481
501
|
oth?: RsaOtherPrimesInfo[];
|
|
482
502
|
}
|
|
483
|
-
/**
|
|
503
|
+
/** A private RSA JWK. */
|
|
484
504
|
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> {
|
|
485
505
|
/** RSA JWK "d" (Private Exponent) Parameter */
|
|
486
506
|
d: string;
|
|
@@ -495,46 +515,46 @@ export interface JWK_RSA_Private<Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RS
|
|
|
495
515
|
/** RSA JWK "qi" (First CRT Coefficient) Parameter */
|
|
496
516
|
qi: string;
|
|
497
517
|
}
|
|
498
|
-
/**
|
|
518
|
+
/** A public or private RSA JWK. */
|
|
499
519
|
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>;
|
|
500
|
-
/**
|
|
520
|
+
/** A public OKP JWK (RFC 8037). */
|
|
501
521
|
export interface JWK_OKP_Public<Alg extends JWK_OKP_SIGN | JWK_ECDH_ES = JWK_OKP_SIGN | JWK_ECDH_ES> extends JWKParameters<Alg> {
|
|
502
522
|
kty: "OKP";
|
|
503
|
-
/**
|
|
523
|
+
/** OKP JWK "crv" (Curve) Parameter */
|
|
504
524
|
crv: string;
|
|
505
|
-
/**
|
|
525
|
+
/** OKP JWK "x" (Public Key) Parameter */
|
|
506
526
|
x: string;
|
|
507
527
|
}
|
|
508
|
-
/**
|
|
528
|
+
/** A private OKP JWK (RFC 8037). */
|
|
509
529
|
export interface JWK_OKP_Private<Alg extends JWK_OKP_SIGN | JWK_ECDH_ES = JWK_OKP_SIGN | JWK_ECDH_ES> extends JWK_OKP_Public<Alg> {
|
|
510
|
-
/**
|
|
530
|
+
/** OKP JWK "d" (Private Key) Parameter */
|
|
511
531
|
d: string;
|
|
512
532
|
}
|
|
513
|
-
/**
|
|
533
|
+
/** A public or private OKP JWK. */
|
|
514
534
|
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>;
|
|
515
|
-
/**
|
|
535
|
+
/** A symmetric (`oct`) JWK. */
|
|
516
536
|
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> {
|
|
517
537
|
kty: "oct";
|
|
518
538
|
/** Oct JWK "k" (Key Value) Parameter */
|
|
519
539
|
k: string;
|
|
520
540
|
}
|
|
521
|
-
/**
|
|
541
|
+
/** A symmetric JWK, the same as `JWK_oct`. */
|
|
522
542
|
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>;
|
|
523
|
-
/**
|
|
543
|
+
/** An asymmetric JWK, narrowed to the key types `Alg` can use. */
|
|
524
544
|
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>>>;
|
|
525
|
-
/**
|
|
545
|
+
/** A public JWK, narrowed to the key types `Alg` can use. */
|
|
526
546
|
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>>>;
|
|
527
|
-
/**
|
|
547
|
+
/** A private JWK, narrowed to the key types `Alg` can use. */
|
|
528
548
|
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>>>;
|
|
529
|
-
/** `toPublicJWK` result: the public
|
|
549
|
+
/** The `toPublicJWK` result: the public JWK of the input's key type and `alg`, with `kid` when the input type has one. */
|
|
530
550
|
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 {
|
|
531
551
|
kid: string;
|
|
532
552
|
} ? {
|
|
533
553
|
kid: string;
|
|
534
554
|
} : unknown);
|
|
535
|
-
/**
|
|
555
|
+
/** A JWK (RFC 7517) of type `"RSA"`, `"EC"`, `"OKP"` or `"oct"`, narrowed to the key types `Alg` can use. */
|
|
536
556
|
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>>;
|
|
537
|
-
/**
|
|
557
|
+
/** A public and private JWK pair of the key type `Alg` names. ECDH-ES gives an EC or an OKP pair. */
|
|
538
558
|
export type JWK_Pair<Alg extends JWK_Asymmetric_Algorithm = JWK_Asymmetric_Algorithm> = Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC ? {
|
|
539
559
|
publicKey: JWK_RSA_Public<Alg>;
|
|
540
560
|
privateKey: JWK_RSA_Private<Alg>;
|
|
@@ -551,12 +571,12 @@ export type JWK_Pair<Alg extends JWK_Asymmetric_Algorithm = JWK_Asymmetric_Algor
|
|
|
551
571
|
publicKey: JWK_OKP_Public<Alg>;
|
|
552
572
|
privateKey: JWK_OKP_Private<Alg>;
|
|
553
573
|
} : never;
|
|
554
|
-
/**
|
|
574
|
+
/** A JWK Set (RFC 7517 §5). `T` keeps a precise key tuple. */
|
|
555
575
|
export interface JWKSet<T extends readonly JWK[] = JWK[]> {
|
|
556
576
|
keys: T;
|
|
557
577
|
[parameter: string]: unknown;
|
|
558
578
|
}
|
|
559
|
-
/**
|
|
579
|
+
/** JWA algorithm identifiers, grouped by family (RFC 7518, RFC 8037). */
|
|
560
580
|
export type JWK_HMAC = "HS256" | "HS384" | "HS512";
|
|
561
581
|
export type JWK_RSA_SIGN = "RS256" | "RS384" | "RS512";
|
|
562
582
|
export type JWK_RSA_PSS = "PS256" | "PS384" | "PS512";
|
|
@@ -569,7 +589,7 @@ export type JWK_AES_GCM_KW = "A128GCMKW" | "A192GCMKW" | "A256GCMKW";
|
|
|
569
589
|
export type JWK_PBES2 = "PBES2-HS256+A128KW" | "PBES2-HS384+A192KW" | "PBES2-HS512+A256KW";
|
|
570
590
|
export type JWK_ECDH_ES = "ECDH-ES" | "ECDH-ES+A128KW" | "ECDH-ES+A192KW" | "ECDH-ES+A256KW";
|
|
571
591
|
export type JWK_OKP_SIGN = "Ed25519" | "EdDSA";
|
|
572
|
-
/** Every algorithm named after an AES key size: the `A128
|
|
592
|
+
/** Every algorithm named after an AES key size: the `A128`, `A192` and `A256` families. */
|
|
573
593
|
export type JWK_AES_Algorithm = JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_AES_CBC_HMAC;
|
|
574
594
|
export type JWK_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW;
|
|
575
595
|
export type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC | JWK_OKP_SIGN | JWK_ECDH_ES;
|
|
@@ -594,46 +614,46 @@ type GeneratedJWKPair<P, A, Kid> = P extends {
|
|
|
594
614
|
type GeneratedKid<TOptions> = "kid" extends keyof TOptions ? ThumbprintIfUnset<Extract<TOptions["kid" & keyof TOptions], string | false>> : string;
|
|
595
615
|
type ThumbprintIfUnset<Kid extends string | false> = [Kid] extends [never] ? string : Kid;
|
|
596
616
|
type GeneratedKeyShape<TAlg extends GenerateKeyAlgorithm, ToJWK, Kid extends string | false> = [ToJWK] extends [never] ? GeneratedKeyMap[TAlg] : ToJWK extends true ? GeneratedJWKMap<Kid>[TAlg] : GeneratedKeyMap[TAlg];
|
|
597
|
-
/** `Shape` when `Alg` has a member of that
|
|
617
|
+
/** `Shape` when `Alg` has a member of that key type, else `never`. */
|
|
598
618
|
type OctFor<Alg, Shape> = [Extract<Alg, Exclude<JWKAlgorithm, JWK_Asymmetric_Algorithm>>] extends [never] ? never : Shape;
|
|
599
619
|
type RSAFor<Alg, Shape> = [Extract<Alg, JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC>] extends [never] ? never : Shape;
|
|
600
620
|
type ECFor<Alg, Shape> = [Extract<Alg, JWK_ECDSA | JWK_ECDH_ES>] extends [never] ? never : Shape;
|
|
601
621
|
type OKPFor<Alg, Shape> = [Extract<Alg, JWK_OKP_SIGN | JWK_ECDH_ES>] extends [never] ? never : Shape;
|
|
602
|
-
/** `oct` JWK
|
|
622
|
+
/** The `oct` JWK `alg` values a JWE key accepts: all but HMAC. */
|
|
603
623
|
type _JWEOctAlg = JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_AES_CBC_HMAC | JWK_PBES2 | "dir";
|
|
604
|
-
/**
|
|
624
|
+
/** The asymmetric public JWKs that can encrypt: RSA-OAEP or ECDH-ES. */
|
|
605
625
|
export type JWEAsymmetricPublicJWK = JWK_RSA_Public<JWK_RSA_ENC> | JWK_EC_Public<JWK_ECDH_ES> | JWK_OKP_Public<JWK_ECDH_ES>;
|
|
606
|
-
/**
|
|
626
|
+
/** The asymmetric private JWKs that can decrypt: RSA-OAEP or ECDH-ES. */
|
|
607
627
|
export type JWEAsymmetricPrivateJWK = JWK_RSA_Private<JWK_RSA_ENC> | JWK_EC_Private<JWK_ECDH_ES> | JWK_OKP_Private<JWK_ECDH_ES>;
|
|
608
|
-
/** JWKs
|
|
628
|
+
/** The JWKs `encrypt` accepts. A JWK whose `alg` is not a JWE algorithm is a type error. */
|
|
609
629
|
export type JWEEncryptJWK = JWK_oct<_JWEOctAlg> | JWEAsymmetricPublicJWK;
|
|
610
|
-
/** JWKs
|
|
630
|
+
/** The JWKs `decrypt` accepts. A JWK whose `alg` is not a JWE algorithm is a type error. */
|
|
611
631
|
export type JWEDecryptJWK = JWK_oct<_JWEOctAlg> | JWEAsymmetricPrivateJWK;
|
|
612
|
-
/**
|
|
632
|
+
/** JWE Header Parameters (RFC 7516 §4.1, RFC 7518 §4.6 to §4.8). Other members are allowed. */
|
|
613
633
|
export interface JWEHeaderParameters extends JoseHeaderParameters {
|
|
614
|
-
/** Key Management Algorithm
|
|
634
|
+
/** "alg" (Key Management Algorithm) Header Parameter */
|
|
615
635
|
alg?: KeyManagementAlgorithm;
|
|
616
|
-
/** Content Encryption Algorithm
|
|
636
|
+
/** "enc" (Content Encryption Algorithm) Header Parameter */
|
|
617
637
|
enc?: ContentEncryptionAlgorithm;
|
|
618
|
-
/** PBES2 Count
|
|
638
|
+
/** "p2c" (PBES2 Count) Header Parameter */
|
|
619
639
|
p2c?: number;
|
|
620
|
-
/** PBES2 Salt, base64url
|
|
640
|
+
/** "p2s" (PBES2 Salt Input) Header Parameter, base64url */
|
|
621
641
|
p2s?: string;
|
|
622
|
-
/** AES-GCMKW Initialization Vector, base64url
|
|
642
|
+
/** "iv" (AES-GCMKW Initialization Vector) Header Parameter, base64url */
|
|
623
643
|
iv?: string;
|
|
624
|
-
/** AES-GCMKW Authentication Tag, base64url
|
|
644
|
+
/** "tag" (AES-GCMKW Authentication Tag) Header Parameter, base64url */
|
|
625
645
|
tag?: string;
|
|
626
|
-
/** ECDH-ES Ephemeral Public Key
|
|
646
|
+
/** "epk" (ECDH-ES Ephemeral Public Key) Header Parameter */
|
|
627
647
|
epk?: JWK_EC_Public | JWK_OKP_Public;
|
|
628
|
-
/** ECDH-ES Agreement PartyUInfo, base64url
|
|
648
|
+
/** "apu" (ECDH-ES Agreement PartyUInfo) Header Parameter, base64url */
|
|
629
649
|
apu?: string;
|
|
630
|
-
/** ECDH-ES Agreement PartyVInfo, base64url
|
|
650
|
+
/** "apv" (ECDH-ES Agreement PartyVInfo) Header Parameter, base64url */
|
|
631
651
|
apv?: string;
|
|
632
|
-
/** Compression (RFC 7516 §4.1.3) is not supported
|
|
652
|
+
/** Compression (RFC 7516 §4.1.3) is not supported. Decrypting a token with `zip` throws `ERR_JWE_INVALID`. */
|
|
633
653
|
zip?: never;
|
|
634
654
|
[propName: string]: unknown;
|
|
635
655
|
}
|
|
636
|
-
/**
|
|
656
|
+
/** Key management inputs as bytes and keys, before they are written to the header. */
|
|
637
657
|
export interface JWEKeyManagementHeaderParameters {
|
|
638
658
|
apu?: Uint8Array<ArrayBuffer>;
|
|
639
659
|
apv?: Uint8Array<ArrayBuffer>;
|
|
@@ -643,141 +663,157 @@ export interface JWEKeyManagementHeaderParameters {
|
|
|
643
663
|
epk?: CryptoKey | JWK_EC_Public | JWK_OKP_Public;
|
|
644
664
|
epkPrivateKey?: CryptoKey | JWK_EC_Private | JWK_OKP_Private;
|
|
645
665
|
}
|
|
646
|
-
/** Header
|
|
666
|
+
/** The Header Parameters unjwt writes, which no caller header can set (RFC 7516 §4.1, RFC 7518 §4.6 to §4.8). */
|
|
647
667
|
export type JWELibraryHeaderName = "alg" | "enc" | "iv" | "tag" | "p2s" | "p2c" | "epk" | "apu" | "apv";
|
|
648
|
-
/**
|
|
668
|
+
/** Options for `encrypt`. */
|
|
649
669
|
export interface JWEEncryptOptions extends JWTTimeClaimOptions {
|
|
670
|
+
/** The key management algorithm. Without it, a password uses `PBES2-HS256+A128KW`, an `oct` JWK whose `alg` is an `enc` uses `dir`, and any other JWK uses its `alg`. */
|
|
650
671
|
alg?: KeyManagementAlgorithm;
|
|
672
|
+
/** The content encryption algorithm. Without it, the JWK's `enc` applies, else `A256GCM`. For `dir`, the CEK JWK's `alg` or `enc` applies, else `ERR_JWE_ENC_MISSING`. */
|
|
651
673
|
enc?: ContentEncryptionAlgorithm;
|
|
652
|
-
/**
|
|
674
|
+
/**
|
|
675
|
+
* Protected Header Parameters to add. `kid` defaults to the JWK's `kid`. `typ` defaults to `"JWT"` for an object payload.
|
|
676
|
+
* `cty` is never added. Set it to `"JWT"` for a nested JWT (RFC 7519 §5.2). A `zip` member throws `ERR_INVALID_OPTION`.
|
|
677
|
+
*/
|
|
653
678
|
protectedHeader?: StrictOmit<JWEHeaderParameters, JWELibraryHeaderName>;
|
|
654
|
-
/** AES-GCMKW key
|
|
679
|
+
/** The AES-GCMKW key wrapping IV. Random when omitted. */
|
|
655
680
|
keyManagementIV?: Uint8Array<ArrayBuffer>;
|
|
656
|
-
/** PBES2
|
|
681
|
+
/** The PBES2 salt (`p2s`), at least 8 octets. Default: 16 random bytes. */
|
|
657
682
|
p2s?: Uint8Array<ArrayBuffer>;
|
|
658
|
-
/** PBES2 iteration count (p2c),
|
|
683
|
+
/** The PBES2 iteration count (`p2c`), from `1000` to `600_000`. Default: `600_000`. */
|
|
659
684
|
p2c?: number;
|
|
685
|
+
/** ECDH-ES inputs: the ephemeral key (generated when omitted), and `partyUInfo` and `partyVInfo` of at most 1024 bytes each. */
|
|
660
686
|
ecdh?: {
|
|
661
687
|
ephemeralKey?: ECDHEphemeralKeyInput;
|
|
662
688
|
partyUInfo?: Uint8Array<ArrayBuffer>;
|
|
663
689
|
partyVInfo?: Uint8Array<ArrayBuffer>;
|
|
664
690
|
};
|
|
665
|
-
/** Content Encryption Key
|
|
691
|
+
/** The Content Encryption Key, sized for `enc`. Random when omitted. */
|
|
666
692
|
cek?: Uint8Array<ArrayBuffer>;
|
|
667
|
-
/**
|
|
693
|
+
/** The content encryption IV, sized for `enc`. Random when omitted. */
|
|
668
694
|
contentEncryptionIV?: Uint8Array<ArrayBuffer>;
|
|
669
695
|
}
|
|
670
|
-
/**
|
|
696
|
+
/** Options for `decrypt`. `Mode` is the literal of the `payload` option, which sets the returned payload type. */
|
|
671
697
|
export interface JWEDecryptOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends JOSEConsumerOptions<Mode> {
|
|
672
|
-
/**
|
|
698
|
+
/**
|
|
699
|
+
* The accepted header `alg` values, else `ERR_JWE_ALG_NOT_ALLOWED`.
|
|
700
|
+
* When omitted, the key's JWK `alg` is the policy, else the algorithms its type serves. A password accepts the three PBES2 algorithms.
|
|
701
|
+
* Pass it for raw bytes and for a JWK whose type does not narrow the algorithm.
|
|
702
|
+
*/
|
|
673
703
|
algorithms?: KeyManagementAlgorithm[];
|
|
674
|
-
/** Max JWK Set
|
|
704
|
+
/** Max JWK Set keys per token (more throws `ERR_JWK_KEY_NOT_FOUND`) and PBKDF2 iterations per call (more throws `ERR_JWE_INVALID`). Default: `{ keyCandidates: 8, pbes2Iterations: 2_400_000 }`. */
|
|
675
705
|
limits?: Pick<JOSELimits, "keyCandidates" | "pbes2Iterations">;
|
|
676
|
-
/**
|
|
706
|
+
/** The accepted header `enc` values, else `ERR_JWE_ALG_NOT_ALLOWED`. Any supported `enc` when omitted. */
|
|
677
707
|
encryptionAlgorithms?: ContentEncryptionAlgorithm[];
|
|
678
|
-
/**
|
|
708
|
+
/** The algorithm an AES-GCM CEK is imported as. Default: AES-GCM. */
|
|
679
709
|
unwrappedKeyAlgorithm?: Parameters<typeof crypto.subtle.importKey>[2];
|
|
680
|
-
/**
|
|
710
|
+
/** The usages of an imported CEK. Default: `["decrypt"]`. */
|
|
681
711
|
keyUsage?: KeyUsage[];
|
|
682
|
-
/**
|
|
712
|
+
/** Makes an imported CEK extractable. `returnCek` needs it. Default: `true`. */
|
|
683
713
|
extractable?: boolean;
|
|
684
|
-
/**
|
|
714
|
+
/** Adds the CEK and the AAD to the result. Default: `false`. */
|
|
685
715
|
returnCek?: boolean;
|
|
686
|
-
/**
|
|
716
|
+
/** The lowest PBES2 `p2c` accepted, else `ERR_JWE_INVALID` (RFC 7518 §4.8.1.2). Default: `1000`. */
|
|
687
717
|
minIterations?: number;
|
|
688
|
-
/**
|
|
718
|
+
/** The highest PBES2 `p2c` accepted, else `ERR_JWE_INVALID`. Default: `600_000`. */
|
|
689
719
|
maxIterations?: number;
|
|
690
720
|
}
|
|
691
|
-
/**
|
|
721
|
+
/** The protected header `decrypt` returns, which always holds `alg` and `enc`. */
|
|
692
722
|
export interface JWEProtectedHeader extends JWEHeaderParameters {
|
|
693
723
|
alg: KeyManagementAlgorithm;
|
|
694
724
|
enc: ContentEncryptionAlgorithm;
|
|
695
725
|
}
|
|
696
|
-
/**
|
|
726
|
+
/** The result of `decrypt`. */
|
|
697
727
|
export interface JWEDecryptResult<T extends JOSEPayload = JOSEPayload> {
|
|
698
728
|
payload: T;
|
|
699
729
|
protectedHeader: JWEProtectedHeader;
|
|
700
|
-
/**
|
|
730
|
+
/** The CEK bytes. Set only with `returnCek`. */
|
|
701
731
|
cek?: Uint8Array<ArrayBuffer>;
|
|
702
|
-
/**
|
|
732
|
+
/** The AAD that authenticates the content. Set only with `returnCek`. */
|
|
703
733
|
aad?: Uint8Array<ArrayBuffer>;
|
|
704
734
|
}
|
|
705
|
-
/** JWE Flattened JSON Serialization (RFC 7516 §7.2.2)
|
|
735
|
+
/** A JWE Flattened JSON Serialization (RFC 7516 §7.2.2). String members are base64url. */
|
|
706
736
|
export interface JWEFlattenedSerialization {
|
|
707
737
|
header?: JWEHeaderParameters;
|
|
708
738
|
encrypted_key?: string;
|
|
709
|
-
/** JWE Protected Header
|
|
739
|
+
/** The JWE Protected Header, covered by the AAD. */
|
|
710
740
|
protected?: string;
|
|
711
|
-
/** Shared Unprotected Header
|
|
741
|
+
/** The JWE Shared Unprotected Header, not covered by the AAD. */
|
|
712
742
|
unprotected?: JWEHeaderParameters;
|
|
713
|
-
/**
|
|
743
|
+
/** The JWE AAD supplied by the producer. */
|
|
714
744
|
aad?: string;
|
|
715
745
|
iv: string;
|
|
716
746
|
ciphertext: string;
|
|
717
747
|
tag: string;
|
|
718
748
|
}
|
|
719
|
-
/** JWE General JSON Serialization (RFC 7516 §7.2.1),
|
|
749
|
+
/** A JWE General JSON Serialization (RFC 7516 §7.2.1), as `encryptMulti` returns. */
|
|
720
750
|
export interface JWEGeneralSerialization extends Omit<JWEFlattenedSerialization, "encrypted_key" | "header"> {
|
|
721
751
|
recipients: JWEGeneralRecipient[];
|
|
722
752
|
}
|
|
723
|
-
/** One recipient
|
|
753
|
+
/** One recipient of a JWE General JSON Serialization. */
|
|
724
754
|
export interface JWEGeneralRecipient {
|
|
725
|
-
/** Per-
|
|
755
|
+
/** The JWE Per-Recipient Unprotected Header, not covered by the AAD. */
|
|
726
756
|
header?: JWEHeaderParameters;
|
|
727
757
|
encrypted_key?: string;
|
|
728
758
|
}
|
|
729
|
-
/** One recipient of `encryptMulti
|
|
759
|
+
/** One recipient of `encryptMulti`. `alg` is the JWK's `alg`, else `ERR_JWE_RECIPIENT_ALG_INFERENCE`. */
|
|
730
760
|
export interface JWEMultiRecipient {
|
|
761
|
+
/** The recipient's JWK. Its `kid` is written to the recipient header. */
|
|
731
762
|
key: JWEEncryptJWK;
|
|
732
|
-
/**
|
|
763
|
+
/** Per-Recipient Unprotected Header Parameters to add (RFC 7516 §7.2.1). They override the JWK's `kid`. */
|
|
733
764
|
header?: StrictOmit<JWEHeaderParameters, JWELibraryHeaderName>;
|
|
765
|
+
/** ECDH-ES inputs for this recipient, as on `encrypt`. */
|
|
734
766
|
ecdh?: JWEEncryptOptions["ecdh"];
|
|
735
|
-
/** PBES2 salt.
|
|
767
|
+
/** The PBES2 salt, at least 8 octets. Default: 16 random bytes. */
|
|
736
768
|
p2s?: Uint8Array<ArrayBuffer>;
|
|
737
|
-
/** PBES2 iteration count,
|
|
769
|
+
/** The PBES2 iteration count, from `1000` to `600_000`. Default: `600_000`. */
|
|
738
770
|
p2c?: number;
|
|
771
|
+
/** The AES-GCMKW key wrapping IV. Random when omitted. */
|
|
739
772
|
keyManagementIV?: Uint8Array<ArrayBuffer>;
|
|
740
773
|
}
|
|
741
|
-
/** Options for `encryptMulti
|
|
774
|
+
/** Options for `encryptMulti`. Key management fields are set on each `JWEMultiRecipient`. */
|
|
742
775
|
export interface JWEMultiEncryptOptions extends StrictOmit<JWEEncryptOptions, "alg" | "ecdh" | "p2s" | "p2c" | "keyManagementIV"> {
|
|
743
|
-
/** Shared Unprotected Header, written as `unprotected`. */
|
|
776
|
+
/** The JWE Shared Unprotected Header, written as `unprotected`. It cannot hold `crit` or `zip`. */
|
|
744
777
|
sharedUnprotectedHeader?: Record<string, unknown>;
|
|
745
|
-
/**
|
|
778
|
+
/** The JWE AAD (RFC 7516 §5.1), as UTF-8 text or bytes. An empty value writes no `aad` member (RFC 7516 §7.2.1). Any other type throws `ERR_INVALID_OPTION`. */
|
|
746
779
|
aad?: Uint8Array<ArrayBuffer> | string;
|
|
747
780
|
}
|
|
748
|
-
/** A key lookup for `decrypt
|
|
781
|
+
/** A key lookup for `decrypt` and `decryptMulti`. It receives `{ header, token }`: the decoded JWE header and the token. */
|
|
749
782
|
export type JWEKeyLookup<TReturn = CryptoKey | JWK | JWKSet | string | Uint8Array<ArrayBuffer>> = JWKLookupFunction<TReturn, JWEHeaderParameters>;
|
|
750
|
-
/**
|
|
783
|
+
/** The key `decryptMulti` accepts, or a lookup that returns it from a recipient's header. */
|
|
751
784
|
export type JWEMultiDecryptKey = CryptoKey | JWKSet | JWEDecryptJWK | string | Uint8Array<ArrayBuffer> | JWEKeyLookup;
|
|
752
785
|
/** Options for `decryptMulti`. */
|
|
753
786
|
export interface JWEMultiDecryptOptions<Mode extends JOSEPayloadMode = JOSEPayloadMode> extends JWEDecryptOptions<Mode> {
|
|
754
|
-
/**
|
|
755
|
-
|
|
756
|
-
|
|
787
|
+
/**
|
|
788
|
+
* Max `recipients[]` entries (more throws `ERR_JWE_INVALID`), JWK Set keys per recipient, key trials over the call, and PBKDF2 iterations over the call.
|
|
789
|
+
* Too many keys or trials throws `ERR_JWK_KEY_NOT_FOUND`.
|
|
790
|
+
* Default: `{ recipients: 16, keyCandidates: 8, keyAttempts: 16, pbes2Iterations: 2_400_000 }`.
|
|
791
|
+
*/
|
|
792
|
+
limits?: Pick<JOSELimits, "recipients" | "keyCandidates" | "keyAttempts" | "pbes2Iterations">;
|
|
793
|
+
/** Skips recipients whose `kid` or `alg` the key cannot serve. No recipient left throws `ERR_JWE_NO_MATCHING_RECIPIENT`. Default: `false`, which tries every recipient in order. */
|
|
757
794
|
strictRecipientMatch?: boolean;
|
|
758
795
|
}
|
|
759
|
-
/**
|
|
796
|
+
/** The result of `decryptMulti`, with the headers of the recipient that decrypted. */
|
|
760
797
|
export interface JWEMultiDecryptResult<T extends JOSEPayload = JOSEPayload> extends Omit<JWEDecryptResult<T>, "protectedHeader"> {
|
|
761
|
-
/**
|
|
798
|
+
/** The protected header as encrypted, `{}` when absent. `alg` and `enc` can be in the unprotected headers instead (RFC 7516 §7.2.1). */
|
|
762
799
|
protectedHeader: JWEHeaderParameters;
|
|
800
|
+
/** The JWE Shared Unprotected Header, when present. */
|
|
763
801
|
sharedUnprotectedHeader?: JWEHeaderParameters;
|
|
764
|
-
/**
|
|
802
|
+
/** The unprotected header of the recipient that decrypted. */
|
|
765
803
|
recipientHeader?: JWEHeaderParameters;
|
|
766
|
-
/**
|
|
804
|
+
/** The index in `recipients` of the recipient that decrypted. */
|
|
767
805
|
recipientIndex: number;
|
|
768
806
|
}
|
|
769
807
|
/**
|
|
770
|
-
* A
|
|
771
|
-
*
|
|
772
|
-
*
|
|
773
|
-
* Shared base type for every duration-valued option in the library:
|
|
774
|
-
* {@link ExpiresIn}, {@link NotBeforeIn}, {@link MaxTokenAge}.
|
|
808
|
+
* A duration: an integer number of seconds, or a string such as `"10m"`, `"2h"` or `"7D"`.
|
|
809
|
+
* A string without a unit counts seconds. `"M"` is 30 days and `"Y"` is 365 days.
|
|
810
|
+
* A non-integer number or an unparsed string throws `ERR_INVALID_OPTION`.
|
|
775
811
|
*/
|
|
776
812
|
export type Duration = number | `${number}` | `${number}${"s" | "second" | "seconds" | "m" | "minute" | "minutes" | "h" | "hour" | "hours" | "D" | "day" | "days" | "W" | "week" | "weeks" | "M" | "month" | "months" | "Y" | "year" | "years"}`;
|
|
777
|
-
/**
|
|
813
|
+
/** The `expiresIn` option of `sign` and `encrypt`: `exp` is the current time plus this positive duration. */
|
|
778
814
|
export type ExpiresIn = Duration;
|
|
779
|
-
/**
|
|
815
|
+
/** The `notBeforeIn` option of `sign` and `encrypt`: `nbf` is the current time plus this duration, zero or more. */
|
|
780
816
|
export type NotBeforeIn = Duration;
|
|
781
|
-
/**
|
|
817
|
+
/** The `maxTokenAge` option of `verify` and `decrypt`: the oldest `iat` accepted, as a positive duration. */
|
|
782
818
|
export type MaxTokenAge = Duration;
|
|
783
819
|
export {};
|