unjwt 0.5.38 → 0.5.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -670
- package/dist/_chunks/chunk.mjs +13 -0
- package/dist/_chunks/index.d.mts +558 -0
- package/dist/_chunks/index2.d.mts +108 -0
- package/dist/_chunks/jwe.d.mts +43 -0
- package/dist/_chunks/jwe.mjs +132 -0
- package/dist/_chunks/jwk.d.mts +611 -0
- package/dist/_chunks/jwk.mjs +1592 -0
- package/dist/_chunks/jws.d.mts +242 -0
- package/dist/_chunks/jws.mjs +2070 -0
- package/dist/_chunks/jws2.mjs +598 -0
- package/dist/_chunks/utils.mjs +375 -0
- package/dist/adapters/h3.d.mts +3 -267
- package/dist/adapters/h3.mjs +3 -704
- package/dist/adapters/h3v1.d.mts +3 -8
- package/dist/adapters/h3v1.mjs +3 -7
- package/dist/adapters/h3v2.d.mts +145 -147
- package/dist/adapters/h3v2.mjs +501 -594
- package/dist/index.d.mts +6 -8
- package/dist/index.mjs +5 -4
- package/dist/jwe.d.mts +3 -4
- package/dist/jwe.mjs +2 -3
- package/dist/jwk.d.mts +3 -2
- package/dist/jwk.mjs +2 -2
- package/dist/jws.d.mts +3 -3
- package/dist/jws.mjs +2 -3
- package/dist/utils.d.mts +3 -3
- package/dist/utils.mjs +2 -1
- package/package.json +33 -31
- package/dist/shared/unjwt.4JQCoID_.d.mts +0 -161
- package/dist/shared/unjwt.B-v62plj.mjs +0 -249
- package/dist/shared/unjwt.BCi3FEWr.d.mts +0 -328
- package/dist/shared/unjwt.BYDTEWa-.d.mts +0 -269
- package/dist/shared/unjwt.Be8NxwFK.mjs +0 -438
- package/dist/shared/unjwt.BqdNUKDr.d.mts +0 -64
- package/dist/shared/unjwt.CMNtw8ek.d.mts +0 -155
- package/dist/shared/unjwt.Cy2MlkUe.d.mts +0 -174
- package/dist/shared/unjwt.D0_ccT7g.d.mts +0 -166
- package/dist/shared/unjwt.DdLN9vwI.mjs +0 -163
- package/dist/shared/unjwt.Dpl__ZAR.mjs +0 -2121
- package/dist/shared/unjwt.JdKqVANs.d.mts +0 -5
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { i as importKey, e as encryptKey, g as generateIV, a as encrypt$1, u as unwrapKey, d as decrypt$1 } from './unjwt.Dpl__ZAR.mjs';
|
|
2
|
-
import { r as randomBytes, a as isJWK, s as sanitizeObject, b as applyTypCtyDefaults, c as computeJwtTimeClaims, g as getPlaintextBytes, d as base64UrlEncode, t as textEncoder, e as base64UrlDecode, f as decodePayloadFromBytes, v as validateCriticalHeadersJWE, h as validateJwtClaims, j as isCryptoKeyPair, k as isCryptoKey } from './unjwt.Be8NxwFK.mjs';
|
|
3
|
-
|
|
4
|
-
async function encrypt(payload, key, options = {}) {
|
|
5
|
-
const {
|
|
6
|
-
protectedHeader: additionalProtectedHeader,
|
|
7
|
-
cek: providedCek,
|
|
8
|
-
contentEncryptionIV: providedContentIV,
|
|
9
|
-
keyManagementIV,
|
|
10
|
-
p2s = randomBytes(16),
|
|
11
|
-
p2c = 2048,
|
|
12
|
-
ecdh
|
|
13
|
-
} = options;
|
|
14
|
-
let { alg, enc } = options;
|
|
15
|
-
if (!alg) {
|
|
16
|
-
if (typeof key === "string" || key instanceof Uint8Array) {
|
|
17
|
-
alg = "PBES2-HS256+A128KW";
|
|
18
|
-
} else if (isJWK(key)) {
|
|
19
|
-
alg = key.alg === "A128GCM" || key.alg === "A192GCM" || key.alg === "A256GCM" ? `${key.alg}KW` : key.alg;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
if (!alg) {
|
|
23
|
-
throw new TypeError(
|
|
24
|
-
'JWE "alg" (Key Management Algorithm) must be provided in options or inferable from the key'
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
if (!enc) {
|
|
28
|
-
enc = isJWK(key) && "enc" in key ? key.enc : "A128GCM";
|
|
29
|
-
}
|
|
30
|
-
const jweKeyManagementParams = {};
|
|
31
|
-
if (keyManagementIV) jweKeyManagementParams.iv = keyManagementIV;
|
|
32
|
-
if (p2s) jweKeyManagementParams.p2s = p2s;
|
|
33
|
-
if (p2c) jweKeyManagementParams.p2c = p2c;
|
|
34
|
-
if (ecdh?.partyUInfo) jweKeyManagementParams.apu = ecdh.partyUInfo;
|
|
35
|
-
if (ecdh?.partyVInfo) jweKeyManagementParams.apv = ecdh.partyVInfo;
|
|
36
|
-
if (ecdh?.ephemeralKey) {
|
|
37
|
-
const { epk, epkPrivateKey } = parseEphemeralKey(ecdh.ephemeralKey);
|
|
38
|
-
jweKeyManagementParams.epk = epk;
|
|
39
|
-
jweKeyManagementParams.epkPrivateKey = epkPrivateKey;
|
|
40
|
-
}
|
|
41
|
-
const wrappingKeyMaterial = await importKey(key, alg);
|
|
42
|
-
const {
|
|
43
|
-
cek: finalCek,
|
|
44
|
-
// This is the CEK (CryptoKey | Uint8Array) to be used for content encryption
|
|
45
|
-
encryptedKey: jweEncryptedKey,
|
|
46
|
-
// This is the JWE Encrypted Key (Uint8Array | undefined)
|
|
47
|
-
parameters: keyManagementHeaderParams
|
|
48
|
-
// JWE header params from key encryption (e.g., epk, p2s, iv, tag)
|
|
49
|
-
} = await encryptKey(
|
|
50
|
-
alg,
|
|
51
|
-
enc,
|
|
52
|
-
wrappingKeyMaterial,
|
|
53
|
-
providedCek,
|
|
54
|
-
jweKeyManagementParams
|
|
55
|
-
);
|
|
56
|
-
const baseProtectedHeader = { ...additionalProtectedHeader };
|
|
57
|
-
delete baseProtectedHeader.alg;
|
|
58
|
-
delete baseProtectedHeader.enc;
|
|
59
|
-
const jweProtectedHeader = sanitizeObject({
|
|
60
|
-
...baseProtectedHeader,
|
|
61
|
-
...keyManagementHeaderParams,
|
|
62
|
-
...isJWK(key) && key.kid ? { kid: key.kid } : {},
|
|
63
|
-
// Include kid if available
|
|
64
|
-
alg,
|
|
65
|
-
enc
|
|
66
|
-
});
|
|
67
|
-
const protectedHeader = applyTypCtyDefaults(jweProtectedHeader, payload);
|
|
68
|
-
const computedPayload = computeJwtTimeClaims(
|
|
69
|
-
payload,
|
|
70
|
-
protectedHeader.typ,
|
|
71
|
-
options.expiresIn,
|
|
72
|
-
options.currentDate
|
|
73
|
-
);
|
|
74
|
-
const plaintextBytes = getPlaintextBytes(computedPayload || payload);
|
|
75
|
-
const protectedHeaderSerialized = JSON.stringify(protectedHeader);
|
|
76
|
-
const protectedHeaderEncoded = base64UrlEncode(protectedHeaderSerialized);
|
|
77
|
-
const aadBytes = textEncoder.encode(protectedHeaderEncoded);
|
|
78
|
-
const contentIVBytes = providedContentIV ?? generateIV(enc);
|
|
79
|
-
const {
|
|
80
|
-
ciphertext: contentCiphertext,
|
|
81
|
-
tag: contentAuthTag,
|
|
82
|
-
iv: actualContentIV
|
|
83
|
-
} = await encrypt$1(
|
|
84
|
-
enc,
|
|
85
|
-
plaintextBytes,
|
|
86
|
-
finalCek,
|
|
87
|
-
contentIVBytes,
|
|
88
|
-
aadBytes
|
|
89
|
-
);
|
|
90
|
-
if (!actualContentIV) {
|
|
91
|
-
throw new Error("Content encryption IV was not generated or returned.");
|
|
92
|
-
}
|
|
93
|
-
if (!contentAuthTag) {
|
|
94
|
-
throw new Error(
|
|
95
|
-
"Content encryption auth tag was not generated or returned."
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
const encryptedKeyEncoded = jweEncryptedKey ? base64UrlEncode(jweEncryptedKey) : "";
|
|
99
|
-
const jweParts = [
|
|
100
|
-
protectedHeaderEncoded,
|
|
101
|
-
encryptedKeyEncoded,
|
|
102
|
-
base64UrlEncode(actualContentIV),
|
|
103
|
-
base64UrlEncode(contentCiphertext),
|
|
104
|
-
base64UrlEncode(contentAuthTag)
|
|
105
|
-
];
|
|
106
|
-
return jweParts.join(".");
|
|
107
|
-
}
|
|
108
|
-
async function decrypt(jwe, key, options = {}) {
|
|
109
|
-
const parts = jwe.split(".");
|
|
110
|
-
if (parts.length !== 5) {
|
|
111
|
-
throw new Error(
|
|
112
|
-
"Invalid JWE: Must contain five sections (RFC7516, section-3)."
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
const [
|
|
116
|
-
protectedHeaderEncoded,
|
|
117
|
-
encryptedKeyEncoded,
|
|
118
|
-
ivEncoded,
|
|
119
|
-
ciphertextEncoded,
|
|
120
|
-
authTagEncoded
|
|
121
|
-
] = parts;
|
|
122
|
-
let protectedHeader;
|
|
123
|
-
try {
|
|
124
|
-
const protectedHeaderJson = base64UrlDecode(protectedHeaderEncoded);
|
|
125
|
-
protectedHeader = sanitizeObject(
|
|
126
|
-
JSON.parse(protectedHeaderJson)
|
|
127
|
-
);
|
|
128
|
-
} catch (error_) {
|
|
129
|
-
throw new Error(
|
|
130
|
-
`Invalid JWE: Protected header is not valid Base64URL or JSON (${error_ instanceof Error ? error_.message : error_})`
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
if (!protectedHeader || typeof protectedHeader !== "object" || !protectedHeader.alg || !protectedHeader.enc) {
|
|
134
|
-
throw new Error(
|
|
135
|
-
'Invalid JWE: Protected header must be an object with "alg" and "enc" properties.'
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
const alg = protectedHeader.alg;
|
|
139
|
-
const enc = protectedHeader.enc;
|
|
140
|
-
if (options?.algorithms && !options.algorithms.includes(alg)) {
|
|
141
|
-
throw new Error(`Key management algorithm not allowed: ${alg}`);
|
|
142
|
-
}
|
|
143
|
-
if (options?.encryptionAlgorithms && !options.encryptionAlgorithms.includes(enc)) {
|
|
144
|
-
throw new Error(`Content encryption algorithm not allowed: ${enc}`);
|
|
145
|
-
}
|
|
146
|
-
const resolvedKeyMaterial = typeof key === "function" ? await key(protectedHeader, jwe) : key;
|
|
147
|
-
const unwrappingKey = await importKey(resolvedKeyMaterial, alg);
|
|
148
|
-
const encryptedKeyBytes = base64UrlDecode(encryptedKeyEncoded, false);
|
|
149
|
-
const contentIVBytes = base64UrlDecode(ivEncoded, false);
|
|
150
|
-
const contentAuthTagBytes = base64UrlDecode(authTagEncoded, false);
|
|
151
|
-
const ciphertextBytes = base64UrlDecode(ciphertextEncoded, false);
|
|
152
|
-
const unwrapKeyOpts = {
|
|
153
|
-
iv: protectedHeader.iv,
|
|
154
|
-
tag: protectedHeader.tag,
|
|
155
|
-
p2s: protectedHeader.p2s,
|
|
156
|
-
p2c: protectedHeader.p2c,
|
|
157
|
-
epk: protectedHeader.epk,
|
|
158
|
-
apu: protectedHeader.apu,
|
|
159
|
-
apv: protectedHeader.apv,
|
|
160
|
-
enc,
|
|
161
|
-
unwrappedKeyAlgorithm: options?.unwrappedKeyAlgorithm,
|
|
162
|
-
keyUsage: options?.keyUsage,
|
|
163
|
-
extractable: options?.extractable,
|
|
164
|
-
returnAs: false
|
|
165
|
-
// Returning CEK as Uint8Array<ArrayBuffer>
|
|
166
|
-
};
|
|
167
|
-
const cekBytes = await unwrapKey(
|
|
168
|
-
alg,
|
|
169
|
-
encryptedKeyBytes,
|
|
170
|
-
unwrappingKey,
|
|
171
|
-
unwrapKeyOpts
|
|
172
|
-
);
|
|
173
|
-
const aadBytes = textEncoder.encode(protectedHeaderEncoded);
|
|
174
|
-
const plaintextBytes = await decrypt$1(
|
|
175
|
-
enc,
|
|
176
|
-
cekBytes,
|
|
177
|
-
ciphertextBytes,
|
|
178
|
-
contentIVBytes,
|
|
179
|
-
contentAuthTagBytes,
|
|
180
|
-
aadBytes
|
|
181
|
-
);
|
|
182
|
-
const payload = decodePayloadFromBytes(
|
|
183
|
-
plaintextBytes,
|
|
184
|
-
protectedHeader,
|
|
185
|
-
options?.forceUint8Array
|
|
186
|
-
);
|
|
187
|
-
validateCriticalHeadersJWE(protectedHeader, [
|
|
188
|
-
...options?.critical || [],
|
|
189
|
-
...options?.requiredHeaders || []
|
|
190
|
-
]);
|
|
191
|
-
if (payload && typeof payload === "object" && options.validateJWT !== false && (options.validateJWT === true || protectedHeader.typ?.toLowerCase().includes("jwt")) && !options.forceUint8Array && !(payload instanceof Uint8Array)) {
|
|
192
|
-
validateJwtClaims(payload, options);
|
|
193
|
-
}
|
|
194
|
-
return {
|
|
195
|
-
payload,
|
|
196
|
-
protectedHeader,
|
|
197
|
-
cek: cekBytes,
|
|
198
|
-
aad: aadBytes
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
function parseEphemeralKey(ephemeralKey) {
|
|
202
|
-
let epk;
|
|
203
|
-
let epkPrivateKey;
|
|
204
|
-
if (isCryptoKeyPair(ephemeralKey)) {
|
|
205
|
-
epk = ephemeralKey.publicKey;
|
|
206
|
-
epkPrivateKey = ephemeralKey.privateKey;
|
|
207
|
-
} else if (typeof ephemeralKey === "object" && ephemeralKey !== null && "publicKey" in ephemeralKey && "privateKey" in ephemeralKey) {
|
|
208
|
-
const candidate = ephemeralKey;
|
|
209
|
-
if (!candidate.publicKey || !candidate.privateKey) {
|
|
210
|
-
throw new TypeError(
|
|
211
|
-
"ECDH-ES custom ephemeral key must include both publicKey and privateKey."
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
epk = candidate.publicKey;
|
|
215
|
-
epkPrivateKey = candidate.privateKey;
|
|
216
|
-
} else if (isCryptoKey(ephemeralKey)) {
|
|
217
|
-
if (ephemeralKey.type !== "private") {
|
|
218
|
-
throw new TypeError(
|
|
219
|
-
"ECDH-ES custom ephemeral CryptoKey must include private key material."
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
epk = ephemeralKey;
|
|
223
|
-
epkPrivateKey = ephemeralKey;
|
|
224
|
-
} else if (isJWK(ephemeralKey)) {
|
|
225
|
-
if (!("d" in ephemeralKey) || typeof ephemeralKey.d !== "string") {
|
|
226
|
-
throw new TypeError(
|
|
227
|
-
'ECDH-ES custom ephemeral JWK must include private parameter "d".'
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
epk = ephemeralKey;
|
|
231
|
-
epkPrivateKey = ephemeralKey;
|
|
232
|
-
} else {
|
|
233
|
-
throw new TypeError(
|
|
234
|
-
"Unsupported ECDH-ES ephemeral key material provided in options."
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
return {
|
|
238
|
-
epk,
|
|
239
|
-
epkPrivateKey
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const jwe = {
|
|
244
|
-
__proto__: null,
|
|
245
|
-
decrypt: decrypt,
|
|
246
|
-
encrypt: encrypt
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
export { decrypt as d, encrypt as e, jwe as j };
|
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
/** Structure returned for composite AES-CBC + HMAC keys. */
|
|
2
|
-
type CompositeKey = {
|
|
3
|
-
/** The AES-CBC encryption/decryption key. */
|
|
4
|
-
encryptionKey: CryptoKey;
|
|
5
|
-
/** The HMAC key for integrity/authentication. */
|
|
6
|
-
macKey: CryptoKey;
|
|
7
|
-
};
|
|
8
|
-
type GenerateKeyAlgorithm = Exclude<JWKAlgorithm, "none" | "dir" | JWK_PBES2>;
|
|
9
|
-
/** Options for the generateKey function. */
|
|
10
|
-
interface GenerateKeyOptions {
|
|
11
|
-
/** Key usages for the generated key(s). Note: For composite keys (CBC), default usages are applied separately. */
|
|
12
|
-
keyUsage?: KeyUsage[];
|
|
13
|
-
/** Mark the key(s) as extractable. Defaults to true. */
|
|
14
|
-
extractable?: boolean;
|
|
15
|
-
/** RSA modulus length. Defaults to 2048. */
|
|
16
|
-
modulusLength?: number;
|
|
17
|
-
/** RSA public exponent. Defaults to 65537 (0x010001). */
|
|
18
|
-
publicExponent?: Uint8Array<ArrayBuffer>;
|
|
19
|
-
/** Named curve for EC or OKP keys. Defaults to "P-256" for EC and "Ed25519" for OKP. */
|
|
20
|
-
namedCurve?: "P-256" | "P-384" | "P-521" | "X25519" | "Ed25519" | "Ed448";
|
|
21
|
-
/** Export the generated key(s) as JWK. If true, the key(s) will be returned in JWK format. */
|
|
22
|
-
toJWK?: undefined | boolean | Omit<JWKParameters, "alg" | "kty" | "key_ops" | "ext">;
|
|
23
|
-
}
|
|
24
|
-
type GenerateKeyReturnJWK<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_Asymmetric_Algorithm ? TAlg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC ? {
|
|
25
|
-
privateKey: JWK_RSA_Private;
|
|
26
|
-
publicKey: JWK_RSA_Public;
|
|
27
|
-
} : TAlg extends JWK_ECDSA | JWK_ECDH_ES ? {
|
|
28
|
-
privateKey: JWK_EC_Private;
|
|
29
|
-
publicKey: JWK_EC_Public;
|
|
30
|
-
} : TAlg extends JWK_OKP_SIGN ? {
|
|
31
|
-
privateKey: JWK_OKP_Private;
|
|
32
|
-
publicKey: JWK_OKP_Public;
|
|
33
|
-
} : never : TAlg extends JWK_AES_CBC_HMAC | JWK_Symmetric_Algorithm ? JWK_oct : never;
|
|
34
|
-
type GenerateKeyReturnCrypto<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_AES_CBC_HMAC ? Uint8Array<ArrayBuffer> : TAlg extends JWK_Asymmetric_Algorithm ? CryptoKeyPair : CryptoKey;
|
|
35
|
-
type GenerateKeyReturn<TAlg extends GenerateKeyAlgorithm, TOptions extends GenerateKeyOptions> = TOptions["toJWK"] extends true ? GenerateKeyReturnJWK<TAlg> : TOptions["toJWK"] extends object ? GenerateKeyReturnJWK<TAlg> : GenerateKeyReturnCrypto<TAlg>;
|
|
36
|
-
type GenerateJWKOptions = Omit<GenerateKeyOptions, "toJWK">;
|
|
37
|
-
type GenerateJWKReturn<TAlg extends GenerateKeyAlgorithm> = GenerateKeyReturnJWK<TAlg>;
|
|
38
|
-
/** Options for the deriveKeyFromPassword function. */
|
|
39
|
-
interface DeriveKeyOptions {
|
|
40
|
-
/** Salt value (p2s). Must be at least 8 bytes. */
|
|
41
|
-
salt: Uint8Array<ArrayBuffer>;
|
|
42
|
-
/** Iteration count (p2c). Must be a positive integer. */
|
|
43
|
-
iterations: number;
|
|
44
|
-
/** Key usages for the derived key. Defaults to ["wrapKey", "unwrapKey"]. */
|
|
45
|
-
keyUsage?: KeyUsage[];
|
|
46
|
-
/** Mark the derived key as extractable. Defaults to false. */
|
|
47
|
-
extractable?: boolean;
|
|
48
|
-
/** Export the derived key as JWK. If true, the key will be returned in JWK_oct format. */
|
|
49
|
-
toJWK?: undefined | boolean | Omit<JWKParameters, "alg" | "kty" | "key_ops" | "ext">;
|
|
50
|
-
}
|
|
51
|
-
type DeriveKeyReturn<TOptions extends DeriveKeyOptions> = TOptions["toJWK"] extends true ? JWK_oct : TOptions["toJWK"] extends object ? JWK_oct : CryptoKey;
|
|
52
|
-
type KeyManagementAlgorithm = JWK_RSA_ENC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_PBES2 | JWK_ECDH_ES;
|
|
53
|
-
type ContentEncryptionAlgorithm = JWK_AES_GCM | JWK_AES_CBC_HMAC;
|
|
54
|
-
/** Options for the wrapKey function. */
|
|
55
|
-
interface WrapKeyOptions {
|
|
56
|
-
/** Initialization Vector for AES-GCMKW. Generated if not provided. */
|
|
57
|
-
iv?: Uint8Array<ArrayBuffer>;
|
|
58
|
-
/** PBES2 Salt value (p2s). Required for PBES2 algorithms. */
|
|
59
|
-
p2s?: Uint8Array<ArrayBuffer>;
|
|
60
|
-
/** PBES2 Iteration count (p2c). Required for PBES2 algorithms. */
|
|
61
|
-
p2c?: number;
|
|
62
|
-
/** ECDH-ES Ephemeral Public Key. Generated if not provided for ECDH-ES. */
|
|
63
|
-
epk?: JWK_EC_Public;
|
|
64
|
-
/** ECDH-ES Agreement PartyUInfo. */
|
|
65
|
-
apu?: Uint8Array<ArrayBuffer>;
|
|
66
|
-
/** ECDH-ES Agreement PartyVInfo. */
|
|
67
|
-
apv?: Uint8Array<ArrayBuffer>;
|
|
68
|
-
}
|
|
69
|
-
/** Result of the wrapKey function. */
|
|
70
|
-
interface WrapKeyResult {
|
|
71
|
-
/** The wrapped key (Ciphertext). */
|
|
72
|
-
encryptedKey: Uint8Array<ArrayBuffer>;
|
|
73
|
-
/** Initialization Vector used (only for AES-GCMKW). Base64URL encoded. */
|
|
74
|
-
iv?: string;
|
|
75
|
-
/** Authentication Tag generated (only for AES-GCMKW). Base64URL encoded. */
|
|
76
|
-
tag?: string;
|
|
77
|
-
/** PBES2 Salt value used (only for PBES2). Base64URL encoded. */
|
|
78
|
-
p2s?: string;
|
|
79
|
-
/** PBES2 Iteration count used (only for PBES2). */
|
|
80
|
-
p2c?: number;
|
|
81
|
-
/** ECDH-ES Ephemeral Public Key used (only for ECDH-ES). */
|
|
82
|
-
epk?: JWK_EC_Public;
|
|
83
|
-
/** ECDH-ES Agreement PartyUInfo used (only for ECDH-ES). Base64URL encoded. */
|
|
84
|
-
apu?: string;
|
|
85
|
-
/** ECDH-ES Agreement PartyVInfo used (only for ECDH-ES). Base64URL encoded. */
|
|
86
|
-
apv?: string;
|
|
87
|
-
}
|
|
88
|
-
/** Options for the unwrapKey function. */
|
|
89
|
-
interface UnwrapKeyOptions {
|
|
90
|
-
/** Initialization Vector (required for AES-GCMKW). Base64URL encoded or Uint8Array. */
|
|
91
|
-
iv?: Uint8Array<ArrayBuffer> | string;
|
|
92
|
-
/** Authentication Tag (required for AES-GCMKW). Base64URL encoded or Uint8Array. */
|
|
93
|
-
tag?: Uint8Array<ArrayBuffer> | string;
|
|
94
|
-
/** PBES2 Salt value (required for PBES2). Base64URL encoded or Uint8Array. */
|
|
95
|
-
p2s?: Uint8Array<ArrayBuffer> | string;
|
|
96
|
-
/** PBES2 Iteration count (required for PBES2). */
|
|
97
|
-
p2c?: number;
|
|
98
|
-
/** ECDH-ES Ephemeral Public Key (required for ECDH-ES). */
|
|
99
|
-
epk?: JWK_EC_Public | CryptoKey;
|
|
100
|
-
/** ECDH-ES Agreement PartyUInfo. Base64URL encoded or Uint8Array. */
|
|
101
|
-
apu?: Uint8Array<ArrayBuffer> | string;
|
|
102
|
-
/** ECDH-ES Agreement PartyVInfo. Base64URL encoded or Uint8Array. */
|
|
103
|
-
apv?: Uint8Array<ArrayBuffer> | string;
|
|
104
|
-
/** Content Encryption Algorithm used with ECDH-ES (required for direct key agreement). */
|
|
105
|
-
enc?: ContentEncryptionAlgorithm;
|
|
106
|
-
/** Expected unwrapped key algorithm (e.g., 'AES-GCM', 'AES-CBC'). Used by crypto.subtle.unwrapKey. */
|
|
107
|
-
unwrappedKeyAlgorithm?: string | Algorithm | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams;
|
|
108
|
-
/** Expected key usages for the unwrapped key. */
|
|
109
|
-
keyUsage?: KeyUsage[];
|
|
110
|
-
/** Mark the unwrapped key as extractable. Defaults to true. */
|
|
111
|
-
extractable?: boolean;
|
|
112
|
-
returnAs?: boolean | undefined;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Forked from https://github.com/panva/jose/tree/v6.0.10
|
|
116
|
-
* Copyright (c) 2018 Filip Skokan.
|
|
117
|
-
* LICENSE: https://github.com/panva/jose/blob/v6.0.10/LICENSE.md
|
|
118
|
-
*/
|
|
119
|
-
/** Generic JSON Web Key Parameters. */
|
|
120
|
-
interface JWKParameters {
|
|
121
|
-
/** JWK "kty" (Key Type) Parameter */
|
|
122
|
-
kty: string;
|
|
123
|
-
/**
|
|
124
|
-
* JWK "alg" (Algorithm) Parameter
|
|
125
|
-
*
|
|
126
|
-
* @see {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}
|
|
127
|
-
*/
|
|
128
|
-
alg?: string;
|
|
129
|
-
/** JWK "key_ops" (Key Operations) Parameter */
|
|
130
|
-
key_ops?: KeyUsage[];
|
|
131
|
-
/** JWK "ext" (Extractable) Parameter */
|
|
132
|
-
ext?: boolean;
|
|
133
|
-
/** JWK "use" (Public Key Use) Parameter */
|
|
134
|
-
use?: string;
|
|
135
|
-
/** JWK "x5c" (X.509 Certificate Chain) Parameter */
|
|
136
|
-
x5c?: string[];
|
|
137
|
-
/** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter */
|
|
138
|
-
x5t?: string;
|
|
139
|
-
/** JWK "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter */
|
|
140
|
-
"x5t#S256"?: string;
|
|
141
|
-
/** JWK "x5u" (X.509 URL) Parameter */
|
|
142
|
-
x5u?: string;
|
|
143
|
-
/** JWK "kid" (Key ID) Parameter */
|
|
144
|
-
kid?: string;
|
|
145
|
-
}
|
|
146
|
-
/** Public EC JSON Web Keys */
|
|
147
|
-
interface JWK_EC_Public extends JWKParameters {
|
|
148
|
-
/** EC JWK "kty" (Key Type) Parameter */
|
|
149
|
-
kty: "EC";
|
|
150
|
-
/** EC JWK "crv" (Curve) Parameter */
|
|
151
|
-
crv: string;
|
|
152
|
-
/** EC JWK "x" (X Coordinate) Parameter */
|
|
153
|
-
x: string;
|
|
154
|
-
/** EC JWK "y" (Y Coordinate) Parameter */
|
|
155
|
-
y: string;
|
|
156
|
-
}
|
|
157
|
-
/** Private EC JSON Web Keys */
|
|
158
|
-
interface JWK_EC_Private extends JWK_EC_Public {
|
|
159
|
-
/** EC JWK "d" (ECC Private Key) Parameter */
|
|
160
|
-
d: string;
|
|
161
|
-
}
|
|
162
|
-
/** EC JSON Web Keys */
|
|
163
|
-
type JWK_EC = JWK_EC_Public | JWK_EC_Private;
|
|
164
|
-
/** Public RSA JSON Web Keys */
|
|
165
|
-
interface JWK_RSA_Public extends JWKParameters {
|
|
166
|
-
/** RSA JWK "kty" (Key Type) Parameter */
|
|
167
|
-
kty: "RSA";
|
|
168
|
-
/** RSA JWK "e" (Exponent) Parameter */
|
|
169
|
-
e: string;
|
|
170
|
-
/** RSA JWK "n" (Modulus) Parameter */
|
|
171
|
-
n: string;
|
|
172
|
-
oth?: RsaOtherPrimesInfo[];
|
|
173
|
-
}
|
|
174
|
-
/** Private RSA JSON Web Keys */
|
|
175
|
-
interface JWK_RSA_Private extends JWK_RSA_Public {
|
|
176
|
-
/** RSA JWK "d" (Private Exponent) Parameter */
|
|
177
|
-
d: string;
|
|
178
|
-
/** RSA JWK "dp" (First Factor CRT Exponent) Parameter */
|
|
179
|
-
dp: string;
|
|
180
|
-
/** RSA JWK "dq" (Second Factor CRT Exponent) Parameter */
|
|
181
|
-
dq: string;
|
|
182
|
-
/** RSA JWK "p" (First Prime Factor) Parameter */
|
|
183
|
-
p: string;
|
|
184
|
-
/** RSA JWK "q" (Second Prime Factor) Parameter */
|
|
185
|
-
q: string;
|
|
186
|
-
/** RSA JWK "qi" (First CRT Coefficient) Parameter */
|
|
187
|
-
qi: string;
|
|
188
|
-
}
|
|
189
|
-
/** RSA JSON Web Keys */
|
|
190
|
-
type JWK_RSA = JWK_RSA_Public | JWK_RSA_Private;
|
|
191
|
-
/** Public ED JSON Web Keys */
|
|
192
|
-
interface JWK_OKP_Public extends JWKParameters {
|
|
193
|
-
/** ED JWK "kty" (Key Type) Parameter */
|
|
194
|
-
kty: "OKP";
|
|
195
|
-
/** ED JWK "crv" (Curve) Parameter */
|
|
196
|
-
crv: string;
|
|
197
|
-
/** ED JWK "x" (X Coordinate) Parameter */
|
|
198
|
-
x: string;
|
|
199
|
-
}
|
|
200
|
-
/** Private ED JSON Web Keys */
|
|
201
|
-
interface JWK_OKP_Private extends JWK_OKP_Public {
|
|
202
|
-
/** ED JWK "d" (Private Key) Parameter */
|
|
203
|
-
d: string;
|
|
204
|
-
}
|
|
205
|
-
/** OKP JSON Web Keys */
|
|
206
|
-
type JWK_OKP = JWK_OKP_Public | JWK_OKP_Private;
|
|
207
|
-
/** oct JSON Web Keys */
|
|
208
|
-
interface JWK_oct extends JWKParameters {
|
|
209
|
-
/** Oct JWK "k" (Key Value) Parameter */
|
|
210
|
-
k: string;
|
|
211
|
-
}
|
|
212
|
-
/** Symmetric JSON Web Keys */
|
|
213
|
-
type JWK_Symmetric = JWK_oct;
|
|
214
|
-
/** Asymmetric JSON Web Keys */
|
|
215
|
-
type JWK_Asymmetric = JWK_RSA | JWK_EC | JWK_OKP;
|
|
216
|
-
/** Public JSON Web Keys */
|
|
217
|
-
type JWK_Public = JWK_RSA_Public | JWK_EC_Public | JWK_OKP_Public;
|
|
218
|
-
/** Private JSON Web Keys */
|
|
219
|
-
type JWK_Private = JWK_RSA_Private | JWK_EC_Private | JWK_OKP_Private;
|
|
220
|
-
/**
|
|
221
|
-
* JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC", "OKP" and "oct" key types are supported.
|
|
222
|
-
*/
|
|
223
|
-
type JWK = JWK_oct | JWK_RSA | JWK_EC | JWK_OKP;
|
|
224
|
-
/**
|
|
225
|
-
* JSON Web Key Set ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK Set}). "RSA", "EC" and "oct" key types are supported.
|
|
226
|
-
*/
|
|
227
|
-
interface JWKSet {
|
|
228
|
-
/** JWK Set "keys" Parameter */
|
|
229
|
-
keys: JWK[];
|
|
230
|
-
[parameter: string]: unknown;
|
|
231
|
-
}
|
|
232
|
-
/** JWK Key Algorithms */
|
|
233
|
-
type JWK_HMAC = "HS256" | "HS384" | "HS512";
|
|
234
|
-
type JWK_RSA_SIGN = "RS256" | "RS384" | "RS512";
|
|
235
|
-
type JWK_RSA_PSS = "PS256" | "PS384" | "PS512";
|
|
236
|
-
type JWK_ECDSA = "ES256" | "ES384" | "ES512";
|
|
237
|
-
type JWK_RSA_ENC = "RSA-OAEP" | "RSA-OAEP-256" | "RSA-OAEP-384" | "RSA-OAEP-512";
|
|
238
|
-
type JWK_AES_KW = "A128KW" | "A192KW" | "A256KW";
|
|
239
|
-
type JWK_AES_CBC_HMAC = "A128CBC-HS256" | "A192CBC-HS384" | "A256CBC-HS512";
|
|
240
|
-
type JWK_AES_GCM = "A128GCM" | "A192GCM" | "A256GCM";
|
|
241
|
-
type JWK_AES_GCM_KW = "A128GCMKW" | "A192GCMKW" | "A256GCMKW";
|
|
242
|
-
type JWK_PBES2 = "PBES2-HS256+A128KW" | "PBES2-HS384+A192KW" | "PBES2-HS512+A256KW";
|
|
243
|
-
type JWK_ECDH_ES = "ECDH-ES" | "ECDH-ES+A128KW" | "ECDH-ES+A192KW" | "ECDH-ES+A256KW";
|
|
244
|
-
type JWK_OKP_SIGN = "Ed25519" | "EdDSA";
|
|
245
|
-
type JWK_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW;
|
|
246
|
-
type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC | JWK_OKP_SIGN | JWK_ECDH_ES;
|
|
247
|
-
type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES | ("none" | "dir");
|
|
248
|
-
type JWKPEMAlgorithm = JWK_RSA_PSS | JWK_RSA_SIGN | JWK_RSA_ENC | JWK_ECDSA | JWK_ECDH_ES | JWK_OKP_SIGN;
|
|
249
|
-
|
|
250
|
-
/** Header Parameters common to JWE and JWS */
|
|
251
|
-
interface JoseHeaderParameters {
|
|
252
|
-
/** "kid" (Key ID) Header Parameter */
|
|
253
|
-
kid?: string;
|
|
254
|
-
/** "x5t" (X.509 Certificate SHA-1 Thumbprint) Header Parameter */
|
|
255
|
-
x5t?: string;
|
|
256
|
-
/** "x5c" (X.509 Certificate Chain) Header Parameter */
|
|
257
|
-
x5c?: string[];
|
|
258
|
-
/** "x5u" (X.509 URL) Header Parameter */
|
|
259
|
-
x5u?: string;
|
|
260
|
-
/** "jku" (JWK Set URL) Header Parameter */
|
|
261
|
-
jku?: string;
|
|
262
|
-
/** "jwk" (JSON Web Key) Header Parameter */
|
|
263
|
-
jwk?: JWK_Public;
|
|
264
|
-
/** "typ" (Type) Header Parameter */
|
|
265
|
-
typ?: string;
|
|
266
|
-
/** "cty" (Content Type) Header Parameter */
|
|
267
|
-
cty?: string;
|
|
268
|
-
/** "crit" (Critical) Header Parameter */
|
|
269
|
-
crit?: string[];
|
|
270
|
-
/** Any other JWS/JWE Header member. */
|
|
271
|
-
[propName: string]: unknown;
|
|
272
|
-
}
|
|
273
|
-
interface JWTClaims {
|
|
274
|
-
/** "iss" (Issuer) Claim */
|
|
275
|
-
iss?: string;
|
|
276
|
-
/** "sub" (Subject) Claim */
|
|
277
|
-
sub?: string;
|
|
278
|
-
/** "aud" (Audience) Claim */
|
|
279
|
-
aud?: string | string[];
|
|
280
|
-
/** "exp" (Expiration Time) Claim */
|
|
281
|
-
exp?: number;
|
|
282
|
-
/** "nbf" (Not Before) Claim */
|
|
283
|
-
nbf?: number;
|
|
284
|
-
/** "iat" (Issued At) Claim */
|
|
285
|
-
iat?: number;
|
|
286
|
-
/** "jti" (JWT ID) Claim */
|
|
287
|
-
jti?: string;
|
|
288
|
-
/** Any other JWT member. */
|
|
289
|
-
[propName: string]: unknown;
|
|
290
|
-
}
|
|
291
|
-
interface JWT<T = JWTClaims> {
|
|
292
|
-
header: JoseHeaderParameters & {
|
|
293
|
-
/** "alg" (Algorithm) Header Parameter */
|
|
294
|
-
alg: string;
|
|
295
|
-
};
|
|
296
|
-
claims: T;
|
|
297
|
-
}
|
|
298
|
-
interface JWTClaimValidationOptions {
|
|
299
|
-
/** Expected JWT "aud" (Audience) Claim value(s). Implies presence requirement. */
|
|
300
|
-
audience?: string | string[];
|
|
301
|
-
/** Expected JWT "iss" (Issuer) Claim value(s). Implies presence requirement. */
|
|
302
|
-
issuer?: string | string[];
|
|
303
|
-
/** Expected JWT "sub" (Subject) Claim value. Implies presence requirement. */
|
|
304
|
-
subject?: string;
|
|
305
|
-
/** Maximum token age, from the JWT "iat" (Issued At) Claim value. Implies presence requirement. */
|
|
306
|
-
maxTokenAge?: MaxTokenAge;
|
|
307
|
-
/** Clock skew tolerance (in seconds) for validating time-based claims (nbf/exp/iat). */
|
|
308
|
-
clockTolerance?: number;
|
|
309
|
-
/** Expected JWT "typ" (Type) Header Parameter value. Implies presence requirement. */
|
|
310
|
-
typ?: string;
|
|
311
|
-
/** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
|
|
312
|
-
currentDate?: Date;
|
|
313
|
-
/** Additional required claim names. */
|
|
314
|
-
requiredClaims?: string[];
|
|
315
|
-
/** List of critical header parameters that must be understood and processed. */
|
|
316
|
-
requiredHeaders?: string[];
|
|
317
|
-
/**
|
|
318
|
-
* Critical Header Parameters to be understood and processed.
|
|
319
|
-
* If the JWT contains critical headers not in this list (and not inherently understood by the library), decryption will fail.
|
|
320
|
-
* @deprecated use {@link requiredHeaders `recognizedHeaders` option} instead.
|
|
321
|
-
*/
|
|
322
|
-
critical?: string[];
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
type ExpiresIn = number | `${number}` | `${number}${"s" | "second" | "seconds" | "m" | "minute" | "minutes" | "h" | "hour" | "hours" | "D" | "day" | "days" | "W" | "week" | "weeks" | "M" | "month" | "months" | "Y" | "year" | "years"}`;
|
|
326
|
-
type MaxTokenAge = ExpiresIn;
|
|
327
|
-
|
|
328
|
-
export type { JWK_ECDSA as A, JWK_RSA_ENC as B, CompositeKey as C, DeriveKeyOptions as D, ExpiresIn as E, JWK_AES_KW as F, GenerateKeyAlgorithm as G, JWK_AES_CBC_HMAC as H, JWK_AES_GCM as I, JWKParameters as J, KeyManagementAlgorithm as K, JWK_AES_GCM_KW as L, MaxTokenAge as M, JWK_PBES2 as N, JWK_ECDH_ES as O, JWK_OKP_SIGN as P, JWK_Symmetric_Algorithm as Q, JWK_Asymmetric_Algorithm as R, JWKAlgorithm as S, JWKPEMAlgorithm as T, UnwrapKeyOptions as U, JoseHeaderParameters as V, WrapKeyOptions as W, JWTClaims as X, JWT as Y, JWTClaimValidationOptions as Z, GenerateKeyOptions as a, GenerateKeyReturn as b, GenerateJWKOptions as c, GenerateJWKReturn as d, DeriveKeyReturn as e, ContentEncryptionAlgorithm as f, WrapKeyResult as g, JWK_EC_Public as h, JWK_EC_Private as i, JWK_EC as j, JWK_RSA_Public as k, JWK_RSA_Private as l, JWK_RSA as m, JWK_OKP_Public as n, JWK_OKP_Private as o, JWK_OKP as p, JWK_oct as q, JWK_Symmetric as r, JWK_Asymmetric as s, JWK_Public as t, JWK_Private as u, JWK as v, JWKSet as w, JWK_HMAC as x, JWK_RSA_SIGN as y, JWK_RSA_PSS as z };
|