unjwt 0.5.12 → 0.5.14
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/dist/index.d.mts +5 -5
- package/dist/index.mjs +5 -5
- package/dist/jwe.d.mts +2 -2
- package/dist/jwe.mjs +4 -4
- package/dist/jwk.d.mts +2 -2
- package/dist/jwk.mjs +2 -2
- package/dist/jws.d.mts +2 -2
- package/dist/jws.mjs +4 -4
- package/dist/shared/{unjwt.DVMpKj8x.mjs → unjwt.B8wnSUll.mjs} +12 -9
- package/dist/shared/{unjwt.Ce8yMcp_.mjs → unjwt.BEjwP_9W.mjs} +92 -2
- package/dist/shared/{unjwt.DuBBF25X.mjs → unjwt.BVlHlXdP.mjs} +26 -12
- package/dist/shared/{unjwt.df8yQ5_5.d.mts → unjwt.BYaxDvLV.d.mts} +39 -2
- package/dist/shared/{unjwt.C_D0RMCp.mjs → unjwt.BaB7HUR1.mjs} +1 -1
- package/dist/shared/{unjwt.CN1C8TlR.d.mts → unjwt.BsgIQHVD.d.mts} +35 -11
- package/dist/shared/{unjwt.DtVML6Qp.d.mts → unjwt.C6b_GyXm.d.mts} +13 -3
- package/dist/shared/{unjwt.B9sSOKE3.d.mts → unjwt.Cf7vmOhS.d.mts} +1 -1
- package/dist/shared/{unjwt.BRtnm5sB.d.mts → unjwt.qWts1U9J.d.mts} +1 -1
- package/dist/shared/{unjwt.D_JFPtpW.mjs → unjwt.skuKf53c.mjs} +12 -7
- package/dist/utils.d.mts +2 -2
- package/dist/utils.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn,
|
|
2
|
-
export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.
|
|
3
|
-
export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, j as jwe } from './shared/unjwt.
|
|
4
|
-
export { i as utils } from './shared/unjwt.
|
|
5
|
-
export { j as jwk } from './shared/unjwt.
|
|
1
|
+
export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, r as JWK, M as JWKAlgorithm, N as JWKPEMAlgorithm, J as JWKParameters, s as JWKSet, A as JWK_AES_CBC_HMAC, B as JWK_AES_GCM, z as JWK_AES_GCM_KW, y as JWK_AES_KW, L as JWK_Asymmetric_Algorithm, h as JWK_EC, F as JWK_ECDH_ES, w as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, t as JWK_HMAC, n as JWK_OKP, m as JWK_OKP_Private, l as JWK_OKP_Public, H as JWK_OKP_SIGN, E as JWK_PBES2, q as JWK_Private, p as JWK_Public, k as JWK_RSA, x as JWK_RSA_ENC, v as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, u as JWK_RSA_SIGN, I as JWK_Symmetric_Algorithm, o as JWK_oct, Q as JWT, R as JWTClaimValidationOptions, P as JWTClaims, O as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.BsgIQHVD.mjs';
|
|
2
|
+
export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.qWts1U9J.mjs';
|
|
3
|
+
export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, j as jwe } from './shared/unjwt.Cf7vmOhS.mjs';
|
|
4
|
+
export { i as utils } from './shared/unjwt.BYaxDvLV.mjs';
|
|
5
|
+
export { j as jwk } from './shared/unjwt.C6b_GyXm.mjs';
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { i as utils } from './shared/unjwt.
|
|
2
|
-
export { j as jwe } from './shared/unjwt.
|
|
3
|
-
export { j as jwk } from './shared/unjwt.
|
|
4
|
-
export { j as jws } from './shared/unjwt.
|
|
5
|
-
import './shared/unjwt.
|
|
1
|
+
export { i as utils } from './shared/unjwt.BEjwP_9W.mjs';
|
|
2
|
+
export { j as jwe } from './shared/unjwt.B8wnSUll.mjs';
|
|
3
|
+
export { j as jwk } from './shared/unjwt.BVlHlXdP.mjs';
|
|
4
|
+
export { j as jws } from './shared/unjwt.skuKf53c.mjs';
|
|
5
|
+
import './shared/unjwt.BaB7HUR1.mjs';
|
package/dist/jwe.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, g as decrypt, f as encrypt } from './shared/unjwt.
|
|
1
|
+
export { Q as JWT, R as JWTClaimValidationOptions, P as JWTClaims, O as JoseHeaderParameters } from './shared/unjwt.BsgIQHVD.mjs';
|
|
2
|
+
export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, g as decrypt, f as encrypt } from './shared/unjwt.Cf7vmOhS.mjs';
|
package/dist/jwe.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
import './shared/unjwt.
|
|
3
|
-
export { d as decrypt, e as encrypt } from './shared/unjwt.
|
|
4
|
-
import './shared/unjwt.
|
|
1
|
+
import './shared/unjwt.BVlHlXdP.mjs';
|
|
2
|
+
import './shared/unjwt.BEjwP_9W.mjs';
|
|
3
|
+
export { d as decrypt, e as encrypt } from './shared/unjwt.B8wnSUll.mjs';
|
|
4
|
+
import './shared/unjwt.BaB7HUR1.mjs';
|
package/dist/jwk.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn,
|
|
2
|
-
export { d as deriveKeyFromPassword, b as exportJWKToPEM, e as exportKey, g as generateKey, c as getJWKFromSet, a as importJWKFromPEM, i as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.
|
|
1
|
+
export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, r as JWK, M as JWKAlgorithm, N as JWKPEMAlgorithm, J as JWKParameters, s as JWKSet, A as JWK_AES_CBC_HMAC, B as JWK_AES_GCM, z as JWK_AES_GCM_KW, y as JWK_AES_KW, L as JWK_Asymmetric_Algorithm, h as JWK_EC, F as JWK_ECDH_ES, w as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, t as JWK_HMAC, n as JWK_OKP, m as JWK_OKP_Private, l as JWK_OKP_Public, H as JWK_OKP_SIGN, E as JWK_PBES2, q as JWK_Private, p as JWK_Public, k as JWK_RSA, x as JWK_RSA_ENC, v as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, u as JWK_RSA_SIGN, I as JWK_Symmetric_Algorithm, o as JWK_oct, Q as JWT, R as JWTClaimValidationOptions, P as JWTClaims, O as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.BsgIQHVD.mjs';
|
|
2
|
+
export { d as deriveKeyFromPassword, b as exportJWKToPEM, e as exportKey, g as generateKey, c as getJWKFromSet, a as importJWKFromPEM, i as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.C6b_GyXm.mjs';
|
package/dist/jwk.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
export { p as deriveKeyFromPassword, t as exportJWKToPEM, q as exportKey, o as generateKey, g as getJWKFromSet, s as importJWKFromPEM, i as importKey, m as unwrapKey, r as wrapKey } from './shared/unjwt.
|
|
1
|
+
import './shared/unjwt.BEjwP_9W.mjs';
|
|
2
|
+
export { p as deriveKeyFromPassword, t as exportJWKToPEM, q as exportKey, o as generateKey, g as getJWKFromSet, s as importJWKFromPEM, i as importKey, m as unwrapKey, r as wrapKey } from './shared/unjwt.BVlHlXdP.mjs';
|
package/dist/jws.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.
|
|
1
|
+
export { Q as JWT, R as JWTClaimValidationOptions, P as JWTClaims, O as JoseHeaderParameters } from './shared/unjwt.BsgIQHVD.mjs';
|
|
2
|
+
export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.qWts1U9J.mjs';
|
package/dist/jws.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
import './shared/unjwt.
|
|
3
|
-
import './shared/unjwt.
|
|
4
|
-
export { s as sign, v as verify } from './shared/unjwt.
|
|
1
|
+
import './shared/unjwt.BVlHlXdP.mjs';
|
|
2
|
+
import './shared/unjwt.BEjwP_9W.mjs';
|
|
3
|
+
import './shared/unjwt.BaB7HUR1.mjs';
|
|
4
|
+
export { s as sign, v as verify } from './shared/unjwt.skuKf53c.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as checkEncCryptoKey, u as uint32be, b as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, d as bitLengthCEK, f as jwkTokey, i as importKey, h as generateIV, l as encrypt$1, m as unwrapKey, n as decrypt$1 } from './unjwt.
|
|
2
|
-
import { k as concatUint8Arrays, t as textEncoder, l as assertCryptoKey, d as base64UrlEncode, m as isCryptoKey, a as isJWK, f as base64UrlDecode, r as randomBytes, b as applyTypCtyDefaults, c as computeJwtTimeClaims, n as getPlaintextBytes, o as decodePayloadFromBytes, p as validateCriticalHeadersJWE } from './unjwt.
|
|
3
|
-
import { c as checkKeyLength } from './unjwt.
|
|
1
|
+
import { a as checkEncCryptoKey, u as uint32be, b as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, d as bitLengthCEK, f as jwkTokey, i as importKey, h as generateIV, l as encrypt$1, m as unwrapKey, n as decrypt$1 } from './unjwt.BVlHlXdP.mjs';
|
|
2
|
+
import { k as concatUint8Arrays, t as textEncoder, l as assertCryptoKey, d as base64UrlEncode, m as isCryptoKey, a as isJWK, s as sanitizeObject, f as base64UrlDecode, r as randomBytes, b as applyTypCtyDefaults, c as computeJwtTimeClaims, n as getPlaintextBytes, o as decodePayloadFromBytes, p as validateCriticalHeadersJWE } from './unjwt.BEjwP_9W.mjs';
|
|
3
|
+
import { c as checkKeyLength } from './unjwt.BaB7HUR1.mjs';
|
|
4
4
|
|
|
5
5
|
function lengthAndInput(input) {
|
|
6
6
|
return concatUint8Arrays(uint32be(input.length), input);
|
|
@@ -183,10 +183,11 @@ async function normalizeKey(key, alg) {
|
|
|
183
183
|
return key;
|
|
184
184
|
}
|
|
185
185
|
if (isJWK(key)) {
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
const safeJwk = sanitizeObject(key);
|
|
187
|
+
if ("k" in safeJwk && safeJwk.k) {
|
|
188
|
+
return base64UrlDecode(safeJwk.k, false);
|
|
188
189
|
}
|
|
189
|
-
return jwkTokey({ ...
|
|
190
|
+
return jwkTokey({ ...safeJwk, alg });
|
|
190
191
|
}
|
|
191
192
|
throw new Error("unreachable");
|
|
192
193
|
}
|
|
@@ -245,12 +246,12 @@ async function encrypt(payload, key, options = {}) {
|
|
|
245
246
|
const baseProtectedHeader = { ...additionalProtectedHeader };
|
|
246
247
|
delete baseProtectedHeader.alg;
|
|
247
248
|
delete baseProtectedHeader.enc;
|
|
248
|
-
const jweProtectedHeader = {
|
|
249
|
+
const jweProtectedHeader = sanitizeObject({
|
|
249
250
|
...baseProtectedHeader,
|
|
250
251
|
...keyManagementHeaderParams,
|
|
251
252
|
alg,
|
|
252
253
|
enc
|
|
253
|
-
};
|
|
254
|
+
});
|
|
254
255
|
const protectedHeader = applyTypCtyDefaults(jweProtectedHeader, payload);
|
|
255
256
|
const computedPayload = computeJwtTimeClaims(
|
|
256
257
|
payload,
|
|
@@ -309,7 +310,9 @@ async function decrypt(jwe, key, options) {
|
|
|
309
310
|
let protectedHeader;
|
|
310
311
|
try {
|
|
311
312
|
const protectedHeaderJson = base64UrlDecode(protectedHeaderEncoded);
|
|
312
|
-
protectedHeader =
|
|
313
|
+
protectedHeader = sanitizeObject(
|
|
314
|
+
JSON.parse(protectedHeaderJson)
|
|
315
|
+
);
|
|
313
316
|
} catch (error_) {
|
|
314
317
|
throw new Error(
|
|
315
318
|
`Invalid JWE: Protected header is not valid Base64URL or JSON (${error_ instanceof Error ? error_.message : error_})`
|
|
@@ -20,7 +20,8 @@ function decodeMaybeJsonString(decodedString, header) {
|
|
|
20
20
|
const looksLikeJson = decodedString.startsWith("{") && decodedString.endsWith("}") || decodedString.startsWith("[") && decodedString.endsWith("]");
|
|
21
21
|
if (looksLikeJson) {
|
|
22
22
|
try {
|
|
23
|
-
|
|
23
|
+
const obj = JSON.parse(decodedString);
|
|
24
|
+
return sanitizeObject(obj);
|
|
24
25
|
} catch {
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -193,6 +194,55 @@ function validateCriticalHeadersJWE(protectedHeader, understoodFromOptions) {
|
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
|
|
197
|
+
const DANGEROUS_KEYS = ["__proto__", "prototype", "constructor"];
|
|
198
|
+
function sanitizeObject(obj) {
|
|
199
|
+
if (!obj || typeof obj !== "object") return obj;
|
|
200
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
201
|
+
visit(obj, seen);
|
|
202
|
+
return obj;
|
|
203
|
+
}
|
|
204
|
+
function visit(current, seen) {
|
|
205
|
+
if (!current || typeof current !== "object") return;
|
|
206
|
+
if (seen.has(current)) return;
|
|
207
|
+
seen.add(current);
|
|
208
|
+
for (const key of DANGEROUS_KEYS) {
|
|
209
|
+
if (Object.prototype.hasOwnProperty.call(current, key)) {
|
|
210
|
+
try {
|
|
211
|
+
delete current[key];
|
|
212
|
+
} catch {
|
|
213
|
+
}
|
|
214
|
+
if (Object.prototype.hasOwnProperty.call(current, key)) {
|
|
215
|
+
try {
|
|
216
|
+
current[key] = void 0;
|
|
217
|
+
delete current[key];
|
|
218
|
+
} catch {
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (Object.prototype.hasOwnProperty.call(current, key)) {
|
|
222
|
+
try {
|
|
223
|
+
Object.defineProperty(current, key, {
|
|
224
|
+
value: void 0,
|
|
225
|
+
configurable: true,
|
|
226
|
+
enumerable: false,
|
|
227
|
+
writable: true
|
|
228
|
+
});
|
|
229
|
+
delete current[key];
|
|
230
|
+
} catch {
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
delete current["__proto__"];
|
|
236
|
+
delete current["prototype"];
|
|
237
|
+
delete current["constructor"];
|
|
238
|
+
if (Array.isArray(current)) {
|
|
239
|
+
for (const value of current) visit(value, seen);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
for (const k of Object.keys(current))
|
|
243
|
+
visit(current[k], seen);
|
|
244
|
+
}
|
|
245
|
+
|
|
196
246
|
const textEncoder = /* @__PURE__ */ new TextEncoder();
|
|
197
247
|
const textDecoder = /* @__PURE__ */ new TextDecoder();
|
|
198
248
|
function base64Encode(data) {
|
|
@@ -266,6 +316,41 @@ function isCryptoKey(key) {
|
|
|
266
316
|
return key?.[Symbol.toStringTag] === "CryptoKey";
|
|
267
317
|
}
|
|
268
318
|
const isCryptoKeyPair = (key) => key && typeof key === "object" && isCryptoKey(key.publicKey) && isCryptoKey(key.privateKey);
|
|
319
|
+
function isSymmetricJWK(key) {
|
|
320
|
+
return isJWK(key) && key.kty === "oct" && typeof key.k === "string";
|
|
321
|
+
}
|
|
322
|
+
function isAsymmetricJWK(key) {
|
|
323
|
+
return !isSymmetricJWK(key);
|
|
324
|
+
}
|
|
325
|
+
function isPrivateJWK(key) {
|
|
326
|
+
if (!isJWK(key)) return false;
|
|
327
|
+
if (key.kty === "EC") {
|
|
328
|
+
return typeof key.d === "string";
|
|
329
|
+
}
|
|
330
|
+
if (key.kty === "OKP") {
|
|
331
|
+
return typeof key.d === "string";
|
|
332
|
+
}
|
|
333
|
+
if (key.kty === "RSA") {
|
|
334
|
+
return typeof key.d === "string";
|
|
335
|
+
}
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
function isPublicJWK(key) {
|
|
339
|
+
if (!isJWK(key)) return false;
|
|
340
|
+
if (key.kty === "EC") {
|
|
341
|
+
const ec = key;
|
|
342
|
+
return typeof ec.x === "string" && typeof ec.y === "string" && typeof ec.d !== "string";
|
|
343
|
+
}
|
|
344
|
+
if (key.kty === "OKP") {
|
|
345
|
+
const okp = key;
|
|
346
|
+
return typeof okp.x === "string" && typeof okp.d !== "string";
|
|
347
|
+
}
|
|
348
|
+
if (key.kty === "RSA") {
|
|
349
|
+
const rsa = key;
|
|
350
|
+
return typeof rsa.n === "string" && typeof rsa.e === "string" && typeof rsa.d !== "string";
|
|
351
|
+
}
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
269
354
|
|
|
270
355
|
const index = {
|
|
271
356
|
__proto__: null,
|
|
@@ -281,13 +366,18 @@ const index = {
|
|
|
281
366
|
decodePayloadFromB64UrlSegment: decodePayloadFromB64UrlSegment,
|
|
282
367
|
decodePayloadFromBytes: decodePayloadFromBytes,
|
|
283
368
|
getPlaintextBytes: getPlaintextBytes,
|
|
369
|
+
isAsymmetricJWK: isAsymmetricJWK,
|
|
284
370
|
isCryptoKey: isCryptoKey,
|
|
285
371
|
isCryptoKeyPair: isCryptoKeyPair,
|
|
286
372
|
isJWK: isJWK,
|
|
287
373
|
isJWKSet: isJWKSet,
|
|
288
374
|
isJsonContent: isJsonContent,
|
|
375
|
+
isPrivateJWK: isPrivateJWK,
|
|
376
|
+
isPublicJWK: isPublicJWK,
|
|
377
|
+
isSymmetricJWK: isSymmetricJWK,
|
|
289
378
|
maybeArray: maybeArray,
|
|
290
379
|
randomBytes: randomBytes,
|
|
380
|
+
sanitizeObject: sanitizeObject,
|
|
291
381
|
textDecoder: textDecoder,
|
|
292
382
|
textEncoder: textEncoder,
|
|
293
383
|
validateCriticalHeadersJWE: validateCriticalHeadersJWE,
|
|
@@ -295,4 +385,4 @@ const index = {
|
|
|
295
385
|
validateJwtClaims: validateJwtClaims
|
|
296
386
|
};
|
|
297
387
|
|
|
298
|
-
export { isJWK as a, applyTypCtyDefaults as b, computeJwtTimeClaims as c, base64UrlEncode as d, textDecoder as e, base64UrlDecode as f, isJWKSet as g, decodePayloadFromB64UrlSegment as h, index as i, validateJwtClaims as j, concatUint8Arrays as k, assertCryptoKey as l, isCryptoKey as m, getPlaintextBytes as n, decodePayloadFromBytes as o, validateCriticalHeadersJWE as p, base64Decode as q, randomBytes as r,
|
|
388
|
+
export { isPrivateJWK as A, isPublicJWK as B, isJsonContent as C, decodeMaybeJsonString as D, isJWK as a, applyTypCtyDefaults as b, computeJwtTimeClaims as c, base64UrlEncode as d, textDecoder as e, base64UrlDecode as f, isJWKSet as g, decodePayloadFromB64UrlSegment as h, index as i, validateJwtClaims as j, concatUint8Arrays as k, assertCryptoKey as l, isCryptoKey as m, getPlaintextBytes as n, decodePayloadFromBytes as o, validateCriticalHeadersJWE as p, base64Decode as q, randomBytes as r, sanitizeObject as s, textEncoder as t, base64Encode as u, validateCriticalHeadersJWS as v, maybeArray as w, isCryptoKeyPair as x, isSymmetricJWK as y, isAsymmetricJWK as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as isCryptoKey, k as concatUint8Arrays, d as base64UrlEncode, q as base64Decode,
|
|
1
|
+
import { m as isCryptoKey, k as concatUint8Arrays, d as base64UrlEncode, q as base64Decode, u as base64Encode, s as sanitizeObject, t as textEncoder, r as randomBytes, a as isJWK, f as base64UrlDecode, g as isJWKSet } from './unjwt.BEjwP_9W.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This is a fork of Jose library's utility functions.
|
|
@@ -830,7 +830,10 @@ function subtleMapping(jwk) {
|
|
|
830
830
|
case "ECDH-ES+A128KW":
|
|
831
831
|
case "ECDH-ES+A192KW":
|
|
832
832
|
case "ECDH-ES+A256KW": {
|
|
833
|
-
algorithm = {
|
|
833
|
+
algorithm = {
|
|
834
|
+
name: "ECDH",
|
|
835
|
+
namedCurve: jwk.crv
|
|
836
|
+
};
|
|
834
837
|
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
835
838
|
break;
|
|
836
839
|
}
|
|
@@ -882,7 +885,7 @@ async function jwkTokey(jwk) {
|
|
|
882
885
|
);
|
|
883
886
|
}
|
|
884
887
|
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
885
|
-
const keyData = { ...jwk };
|
|
888
|
+
const keyData = { ...sanitizeObject(jwk) };
|
|
886
889
|
delete keyData.alg;
|
|
887
890
|
delete keyData.use;
|
|
888
891
|
return crypto.subtle.importKey(
|
|
@@ -1024,7 +1027,7 @@ async function _unwrap(alg, key, encryptedKey) {
|
|
|
1024
1027
|
}
|
|
1025
1028
|
|
|
1026
1029
|
async function generateKey(alg, options = {}) {
|
|
1027
|
-
const exportToJWK = options.toJWK
|
|
1030
|
+
const exportToJWK = options.toJWK !== void 0 && options.toJWK !== false;
|
|
1028
1031
|
const defaultExtractable = options.extractable !== false;
|
|
1029
1032
|
if (alg === "A128CBC-HS256" || alg === "A192CBC-HS384" || alg === "A256CBC-HS512") {
|
|
1030
1033
|
const keyLength = bitLengthCEK(alg);
|
|
@@ -1041,12 +1044,19 @@ async function generateKey(alg, options = {}) {
|
|
|
1041
1044
|
keyUsages
|
|
1042
1045
|
);
|
|
1043
1046
|
if (exportToJWK) {
|
|
1047
|
+
const {
|
|
1048
|
+
alg: _a,
|
|
1049
|
+
kty: _k,
|
|
1050
|
+
key_ops: _ko,
|
|
1051
|
+
ext: _e,
|
|
1052
|
+
...additionalKeyParams
|
|
1053
|
+
} = typeof options.toJWK === "object" ? options.toJWK : {};
|
|
1044
1054
|
if (key instanceof CryptoKey) {
|
|
1045
|
-
return exportKey(key, { alg });
|
|
1055
|
+
return exportKey(key, { ...additionalKeyParams, alg });
|
|
1046
1056
|
} else {
|
|
1047
1057
|
const [publicKey, privateKey] = await Promise.all([
|
|
1048
|
-
exportKey(key.publicKey, { alg }),
|
|
1049
|
-
exportKey(key.privateKey, { alg })
|
|
1058
|
+
exportKey(key.publicKey, { ...additionalKeyParams, alg }),
|
|
1059
|
+
exportKey(key.privateKey, { ...additionalKeyParams, alg })
|
|
1050
1060
|
]);
|
|
1051
1061
|
return { privateKey, publicKey };
|
|
1052
1062
|
}
|
|
@@ -1098,15 +1108,19 @@ async function importKey(key, alg) {
|
|
|
1098
1108
|
return key;
|
|
1099
1109
|
}
|
|
1100
1110
|
if (isJWK(key)) {
|
|
1101
|
-
|
|
1102
|
-
|
|
1111
|
+
const safeJwk = sanitizeObject(key);
|
|
1112
|
+
if ("k" in safeJwk && typeof safeJwk.k === "string") {
|
|
1113
|
+
return base64UrlDecode(safeJwk.k, false);
|
|
1103
1114
|
} else {
|
|
1104
|
-
if (!
|
|
1115
|
+
if (!safeJwk.alg && !alg) {
|
|
1105
1116
|
throw new TypeError(
|
|
1106
1117
|
"Algorithm must be provided when importing non-oct JWK"
|
|
1107
1118
|
);
|
|
1108
1119
|
}
|
|
1109
|
-
return jwkTokey({
|
|
1120
|
+
return jwkTokey({
|
|
1121
|
+
...safeJwk,
|
|
1122
|
+
alg: safeJwk.alg || alg
|
|
1123
|
+
});
|
|
1110
1124
|
}
|
|
1111
1125
|
}
|
|
1112
1126
|
throw new Error("Invalid key type provided to importKey");
|
|
@@ -1114,7 +1128,7 @@ async function importKey(key, alg) {
|
|
|
1114
1128
|
async function exportKey(key, jwk) {
|
|
1115
1129
|
const exportedJwk = await keyToJWK(key);
|
|
1116
1130
|
if (jwk) {
|
|
1117
|
-
return { ...
|
|
1131
|
+
return { ...sanitizeObject(jwk), ...exportedJwk };
|
|
1118
1132
|
}
|
|
1119
1133
|
return exportedJwk;
|
|
1120
1134
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { P as JWTClaims, R as JWTClaimValidationOptions, r as JWK, s as JWKSet, o as JWK_oct, q as JWK_Private, p as JWK_Public } from './unjwt.BsgIQHVD.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Apply default typ/cty semantics shared by JWS & JWE.
|
|
@@ -50,6 +50,19 @@ declare function validateCriticalHeadersJWE(protectedHeader: {
|
|
|
50
50
|
crit?: string[];
|
|
51
51
|
} & Record<string, any>, understoodFromOptions?: string[]): void;
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Forked from unsecure@0.0.4
|
|
55
|
+
* Licensed under the MIT License.
|
|
56
|
+
*
|
|
57
|
+
* Source: https://github.com/sandros94/unsecure/blob/913ed5580c551153a19154b4916c67a8efb2be85/src/sanitize.ts
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* Remove prototype-pollution vectors from a plain record in-place.
|
|
61
|
+
* This strips __proto__, prototype, and constructor own properties.
|
|
62
|
+
* Returns the same reference for convenience.
|
|
63
|
+
*/
|
|
64
|
+
declare function sanitizeObject<T extends Record<string, unknown> | undefined>(obj: T): T;
|
|
65
|
+
|
|
53
66
|
declare const textEncoder: TextEncoder;
|
|
54
67
|
declare const textDecoder: TextDecoder;
|
|
55
68
|
declare function base64Encode(data: Uint8Array<ArrayBuffer> | string): string;
|
|
@@ -71,6 +84,20 @@ declare function isJWKSet(key: any): key is JWKSet;
|
|
|
71
84
|
declare function assertCryptoKey(key: unknown): asserts key is CryptoKey;
|
|
72
85
|
declare function isCryptoKey(key: unknown): key is CryptoKey;
|
|
73
86
|
declare const isCryptoKeyPair: (key: any) => key is CryptoKeyPair;
|
|
87
|
+
/** Returns true if the JWK is a symmetric (oct) key. */
|
|
88
|
+
declare function isSymmetricJWK(key: unknown): key is JWK_oct;
|
|
89
|
+
/** Returns true if the JWK is an asymmetric (RSA, EC, OKP) key. */
|
|
90
|
+
declare function isAsymmetricJWK(key: unknown): key is JWK_oct;
|
|
91
|
+
/**
|
|
92
|
+
* Type guard that checks if the provided JWK contains private key material.
|
|
93
|
+
* It relies purely on the presence of private components (e.g. "d"), not on the alg value.
|
|
94
|
+
*/
|
|
95
|
+
declare function isPrivateJWK(key: unknown): key is JWK_Private;
|
|
96
|
+
/**
|
|
97
|
+
* Type guard that checks if the provided JWK is a public (asymmetric) key.
|
|
98
|
+
* This checks for the presence of public components and absence of private material.
|
|
99
|
+
*/
|
|
100
|
+
declare function isPublicJWK(key: unknown): key is JWK_Public;
|
|
74
101
|
|
|
75
102
|
declare const index_applyTypCtyDefaults: typeof applyTypCtyDefaults;
|
|
76
103
|
declare const index_assertCryptoKey: typeof assertCryptoKey;
|
|
@@ -84,13 +111,18 @@ declare const index_decodeMaybeJsonString: typeof decodeMaybeJsonString;
|
|
|
84
111
|
declare const index_decodePayloadFromB64UrlSegment: typeof decodePayloadFromB64UrlSegment;
|
|
85
112
|
declare const index_decodePayloadFromBytes: typeof decodePayloadFromBytes;
|
|
86
113
|
declare const index_getPlaintextBytes: typeof getPlaintextBytes;
|
|
114
|
+
declare const index_isAsymmetricJWK: typeof isAsymmetricJWK;
|
|
87
115
|
declare const index_isCryptoKey: typeof isCryptoKey;
|
|
88
116
|
declare const index_isCryptoKeyPair: typeof isCryptoKeyPair;
|
|
89
117
|
declare const index_isJWK: typeof isJWK;
|
|
90
118
|
declare const index_isJWKSet: typeof isJWKSet;
|
|
91
119
|
declare const index_isJsonContent: typeof isJsonContent;
|
|
120
|
+
declare const index_isPrivateJWK: typeof isPrivateJWK;
|
|
121
|
+
declare const index_isPublicJWK: typeof isPublicJWK;
|
|
122
|
+
declare const index_isSymmetricJWK: typeof isSymmetricJWK;
|
|
92
123
|
declare const index_maybeArray: typeof maybeArray;
|
|
93
124
|
declare const index_randomBytes: typeof randomBytes;
|
|
125
|
+
declare const index_sanitizeObject: typeof sanitizeObject;
|
|
94
126
|
declare const index_textDecoder: typeof textDecoder;
|
|
95
127
|
declare const index_textEncoder: typeof textEncoder;
|
|
96
128
|
declare const index_validateCriticalHeadersJWE: typeof validateCriticalHeadersJWE;
|
|
@@ -110,13 +142,18 @@ declare namespace index {
|
|
|
110
142
|
index_decodePayloadFromB64UrlSegment as decodePayloadFromB64UrlSegment,
|
|
111
143
|
index_decodePayloadFromBytes as decodePayloadFromBytes,
|
|
112
144
|
index_getPlaintextBytes as getPlaintextBytes,
|
|
145
|
+
index_isAsymmetricJWK as isAsymmetricJWK,
|
|
113
146
|
index_isCryptoKey as isCryptoKey,
|
|
114
147
|
index_isCryptoKeyPair as isCryptoKeyPair,
|
|
115
148
|
index_isJWK as isJWK,
|
|
116
149
|
index_isJWKSet as isJWKSet,
|
|
117
150
|
index_isJsonContent as isJsonContent,
|
|
151
|
+
index_isPrivateJWK as isPrivateJWK,
|
|
152
|
+
index_isPublicJWK as isPublicJWK,
|
|
153
|
+
index_isSymmetricJWK as isSymmetricJWK,
|
|
118
154
|
index_maybeArray as maybeArray,
|
|
119
155
|
index_randomBytes as randomBytes,
|
|
156
|
+
index_sanitizeObject as sanitizeObject,
|
|
120
157
|
index_textDecoder as textDecoder,
|
|
121
158
|
index_textEncoder as textEncoder,
|
|
122
159
|
index_validateCriticalHeadersJWE as validateCriticalHeadersJWE,
|
|
@@ -125,4 +162,4 @@ declare namespace index {
|
|
|
125
162
|
};
|
|
126
163
|
}
|
|
127
164
|
|
|
128
|
-
export { textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, isJWKSet as h, index as i, assertCryptoKey as j, isCryptoKey as k, isCryptoKeyPair as l, maybeArray as m,
|
|
165
|
+
export { validateJwtClaims as A, validateCriticalHeadersJWS as B, validateCriticalHeadersJWE as C, sanitizeObject as D, textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, isJWKSet as h, index as i, assertCryptoKey as j, isCryptoKey as k, isCryptoKeyPair as l, maybeArray as m, isSymmetricJWK as n, isAsymmetricJWK as o, isPrivateJWK as p, isPublicJWK as q, randomBytes as r, applyTypCtyDefaults as s, textEncoder as t, isJsonContent as u, decodeMaybeJsonString as v, decodePayloadFromBytes as w, decodePayloadFromB64UrlSegment as x, getPlaintextBytes as y, computeJwtTimeClaims as z };
|
|
@@ -17,14 +17,14 @@ interface GenerateKeyOptions {
|
|
|
17
17
|
/** RSA public exponent. Defaults to 65537 (0x010001). */
|
|
18
18
|
publicExponent?: Uint8Array<ArrayBuffer>;
|
|
19
19
|
/** Export the generated key(s) as JWK. If true, the key(s) will be returned in JWK format. */
|
|
20
|
-
toJWK?: boolean |
|
|
20
|
+
toJWK?: undefined | boolean | Omit<JWKParameters, "alg" | "kty" | "key_ops" | "ext">;
|
|
21
21
|
}
|
|
22
22
|
type GenerateKeyReturnJWK<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_Asymmetric_Algorithm ? {
|
|
23
23
|
privateKey: JWK;
|
|
24
24
|
publicKey: JWK;
|
|
25
25
|
} : JWK;
|
|
26
26
|
type GenerateKeyReturnCrypto<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_AES_CBC_HMAC ? Uint8Array<ArrayBuffer> : TAlg extends JWK_Asymmetric_Algorithm ? CryptoKeyPair : CryptoKey;
|
|
27
|
-
type GenerateKeyReturn<TAlg extends GenerateKeyAlgorithm, TOptions extends GenerateKeyOptions> = TOptions["toJWK"] extends true ? GenerateKeyReturnJWK<TAlg> : GenerateKeyReturnCrypto<TAlg>;
|
|
27
|
+
type GenerateKeyReturn<TAlg extends GenerateKeyAlgorithm, TOptions extends GenerateKeyOptions> = TOptions["toJWK"] extends true ? GenerateKeyReturnJWK<TAlg> : TOptions["toJWK"] extends object ? GenerateKeyReturnJWK<TAlg> : GenerateKeyReturnCrypto<TAlg>;
|
|
28
28
|
/** Options for the deriveKeyFromPassword function. */
|
|
29
29
|
interface DeriveKeyOptions {
|
|
30
30
|
/** Salt value (p2s). Must be at least 8 bytes. */
|
|
@@ -133,6 +133,8 @@ interface JWKParameters {
|
|
|
133
133
|
}
|
|
134
134
|
/** Public EC JSON Web Keys */
|
|
135
135
|
interface JWK_EC_Public extends JWKParameters {
|
|
136
|
+
/** EC JWK "kty" (Key Type) Parameter */
|
|
137
|
+
kty: "EC";
|
|
136
138
|
/** EC JWK "crv" (Curve) Parameter */
|
|
137
139
|
crv: string;
|
|
138
140
|
/** EC JWK "x" (X Coordinate) Parameter */
|
|
@@ -141,7 +143,7 @@ interface JWK_EC_Public extends JWKParameters {
|
|
|
141
143
|
y: string;
|
|
142
144
|
}
|
|
143
145
|
/** Private EC JSON Web Keys */
|
|
144
|
-
interface JWK_EC_Private extends JWK_EC_Public
|
|
146
|
+
interface JWK_EC_Private extends JWK_EC_Public {
|
|
145
147
|
/** EC JWK "d" (ECC Private Key) Parameter */
|
|
146
148
|
d: string;
|
|
147
149
|
}
|
|
@@ -149,6 +151,8 @@ interface JWK_EC_Private extends JWK_EC_Public, JWKParameters {
|
|
|
149
151
|
type JWK_EC = JWK_EC_Public | JWK_EC_Private;
|
|
150
152
|
/** Public RSA JSON Web Keys */
|
|
151
153
|
interface JWK_RSA_Public extends JWKParameters {
|
|
154
|
+
/** RSA JWK "kty" (Key Type) Parameter */
|
|
155
|
+
kty: "RSA";
|
|
152
156
|
/** RSA JWK "e" (Exponent) Parameter */
|
|
153
157
|
e: string;
|
|
154
158
|
/** RSA JWK "n" (Modulus) Parameter */
|
|
@@ -156,7 +160,7 @@ interface JWK_RSA_Public extends JWKParameters {
|
|
|
156
160
|
oth?: RsaOtherPrimesInfo[];
|
|
157
161
|
}
|
|
158
162
|
/** Private RSA JSON Web Keys */
|
|
159
|
-
interface JWK_RSA_Private extends JWK_RSA_Public
|
|
163
|
+
interface JWK_RSA_Private extends JWK_RSA_Public {
|
|
160
164
|
/** RSA JWK "d" (Private Exponent) Parameter */
|
|
161
165
|
d: string;
|
|
162
166
|
/** RSA JWK "dp" (First Factor CRT Exponent) Parameter */
|
|
@@ -172,15 +176,35 @@ interface JWK_RSA_Private extends JWK_RSA_Public, JWKParameters {
|
|
|
172
176
|
}
|
|
173
177
|
/** RSA JSON Web Keys */
|
|
174
178
|
type JWK_RSA = JWK_RSA_Public | JWK_RSA_Private;
|
|
179
|
+
/** Public ED JSON Web Keys */
|
|
180
|
+
interface JWK_OKP_Public extends JWKParameters {
|
|
181
|
+
/** ED JWK "kty" (Key Type) Parameter */
|
|
182
|
+
kty: "OKP";
|
|
183
|
+
/** ED JWK "crv" (Curve) Parameter */
|
|
184
|
+
crv: string;
|
|
185
|
+
/** ED JWK "x" (X Coordinate) Parameter */
|
|
186
|
+
x: string;
|
|
187
|
+
}
|
|
188
|
+
/** Private ED JSON Web Keys */
|
|
189
|
+
interface JWK_OKP_Private extends JWK_OKP_Public {
|
|
190
|
+
/** ED JWK "d" (Private Key) Parameter */
|
|
191
|
+
d: string;
|
|
192
|
+
}
|
|
193
|
+
/** OKP JSON Web Keys */
|
|
194
|
+
type JWK_OKP = JWK_OKP_Public | JWK_OKP_Private;
|
|
175
195
|
/** oct JSON Web Keys */
|
|
176
196
|
interface JWK_oct extends JWKParameters {
|
|
177
197
|
/** Oct JWK "k" (Key Value) Parameter */
|
|
178
198
|
k: string;
|
|
179
199
|
}
|
|
200
|
+
/** Public JSON Web Keys */
|
|
201
|
+
type JWK_Public = JWK_RSA_Public | JWK_EC_Public | JWK_OKP_Public | JWK_oct;
|
|
202
|
+
/** Private JSON Web Keys */
|
|
203
|
+
type JWK_Private = JWK_RSA_Private | JWK_EC_Private | JWK_OKP_Private;
|
|
180
204
|
/**
|
|
181
|
-
* JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC" and "oct" key types are supported.
|
|
205
|
+
* JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC", "OKP" and "oct" key types are supported.
|
|
182
206
|
*/
|
|
183
|
-
type JWK = JWK_oct | JWK_RSA | JWK_EC;
|
|
207
|
+
type JWK = JWK_oct | JWK_RSA | JWK_EC | JWK_OKP;
|
|
184
208
|
/**
|
|
185
209
|
* JSON Web Key Set ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK Set}). "RSA", "EC" and "oct" key types are supported.
|
|
186
210
|
*/
|
|
@@ -201,11 +225,11 @@ type JWK_AES_CBC_HMAC = "A128CBC-HS256" | "A192CBC-HS384" | "A256CBC-HS512";
|
|
|
201
225
|
type JWK_AES_GCM = "A128GCM" | "A192GCM" | "A256GCM";
|
|
202
226
|
type JWK_PBES2 = "PBES2-HS256+A128KW" | "PBES2-HS384+A192KW" | "PBES2-HS512+A256KW";
|
|
203
227
|
type JWK_ECDH_ES = "ECDH-ES" | "ECDH-ES+A128KW" | "ECDH-ES+A192KW" | "ECDH-ES+A256KW";
|
|
204
|
-
type
|
|
228
|
+
type JWK_OKP_SIGN = "Ed25519" | "EdDSA";
|
|
205
229
|
type JWK_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM;
|
|
206
|
-
type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC |
|
|
230
|
+
type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC | JWK_OKP_SIGN;
|
|
207
231
|
type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES | ("none" | "dir");
|
|
208
|
-
type JWKPEMAlgorithm = JWK_RSA_PSS | JWK_RSA_SIGN | JWK_RSA_ENC | JWK_ECDSA | JWK_ECDH_ES |
|
|
232
|
+
type JWKPEMAlgorithm = JWK_RSA_PSS | JWK_RSA_SIGN | JWK_RSA_ENC | JWK_ECDSA | JWK_ECDH_ES | JWK_OKP_SIGN;
|
|
209
233
|
|
|
210
234
|
/** Header Parameters common to JWE and JWS */
|
|
211
235
|
interface JoseHeaderParameters {
|
|
@@ -220,7 +244,7 @@ interface JoseHeaderParameters {
|
|
|
220
244
|
/** "jku" (JWK Set URL) Header Parameter */
|
|
221
245
|
jku?: string;
|
|
222
246
|
/** "jwk" (JSON Web Key) Header Parameter */
|
|
223
|
-
jwk?:
|
|
247
|
+
jwk?: JWK_Public;
|
|
224
248
|
/** "typ" (Type) Header Parameter */
|
|
225
249
|
typ?: string;
|
|
226
250
|
/** "cty" (Content Type) Header Parameter */
|
|
@@ -282,4 +306,4 @@ interface JWTClaimValidationOptions {
|
|
|
282
306
|
critical?: string[];
|
|
283
307
|
}
|
|
284
308
|
|
|
285
|
-
export type {
|
|
309
|
+
export type { JWK_AES_CBC_HMAC as A, JWK_AES_GCM as B, CompositeKey as C, DeriveKeyOptions as D, JWK_PBES2 as E, JWK_ECDH_ES as F, GenerateKeyAlgorithm as G, JWK_OKP_SIGN as H, JWK_Symmetric_Algorithm as I, JWKParameters as J, KeyManagementAlgorithm as K, JWK_Asymmetric_Algorithm as L, JWKAlgorithm as M, JWKPEMAlgorithm as N, JoseHeaderParameters as O, JWTClaims as P, JWT as Q, JWTClaimValidationOptions as R, UnwrapKeyOptions as U, WrapKeyOptions as W, GenerateKeyOptions as a, GenerateKeyReturn as b, DeriveKeyReturn as c, ContentEncryptionAlgorithm as d, WrapKeyResult as e, JWK_EC_Public as f, JWK_EC_Private as g, JWK_EC as h, JWK_RSA_Public as i, JWK_RSA_Private as j, JWK_RSA as k, JWK_OKP_Public as l, JWK_OKP_Private as m, JWK_OKP as n, JWK_oct as o, JWK_Public as p, JWK_Private as q, JWK as r, JWKSet as s, JWK_HMAC as t, JWK_RSA_SIGN as u, JWK_RSA_PSS as v, JWK_ECDSA as w, JWK_RSA_ENC as x, JWK_AES_KW as y, JWK_AES_GCM_KW as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn,
|
|
1
|
+
import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, E as JWK_PBES2, D as DeriveKeyOptions, c as DeriveKeyReturn, o as JWK_oct, r as JWK, K as KeyManagementAlgorithm, W as WrapKeyOptions, e as WrapKeyResult, U as UnwrapKeyOptions, N as JWKPEMAlgorithm, s as JWKSet, O as JoseHeaderParameters, C as CompositeKey, d as ContentEncryptionAlgorithm, M as JWKAlgorithm, J as JWKParameters, A as JWK_AES_CBC_HMAC, B as JWK_AES_GCM, z as JWK_AES_GCM_KW, y as JWK_AES_KW, L as JWK_Asymmetric_Algorithm, h as JWK_EC, F as JWK_ECDH_ES, w as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, t as JWK_HMAC, n as JWK_OKP, m as JWK_OKP_Private, l as JWK_OKP_Public, H as JWK_OKP_SIGN, q as JWK_Private, p as JWK_Public, k as JWK_RSA, x as JWK_RSA_ENC, v as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, u as JWK_RSA_SIGN, I as JWK_Symmetric_Algorithm, Q as JWT, R as JWTClaimValidationOptions, P as JWTClaims } from './unjwt.BsgIQHVD.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This is a fork of Jose library's utility functions.
|
|
@@ -142,9 +142,14 @@ declare const jwk_JWK_ECDH_ES: typeof JWK_ECDH_ES;
|
|
|
142
142
|
declare const jwk_JWK_ECDSA: typeof JWK_ECDSA;
|
|
143
143
|
declare const jwk_JWK_EC_Private: typeof JWK_EC_Private;
|
|
144
144
|
declare const jwk_JWK_EC_Public: typeof JWK_EC_Public;
|
|
145
|
-
declare const jwk_JWK_ED: typeof JWK_ED;
|
|
146
145
|
declare const jwk_JWK_HMAC: typeof JWK_HMAC;
|
|
146
|
+
declare const jwk_JWK_OKP: typeof JWK_OKP;
|
|
147
|
+
declare const jwk_JWK_OKP_Private: typeof JWK_OKP_Private;
|
|
148
|
+
declare const jwk_JWK_OKP_Public: typeof JWK_OKP_Public;
|
|
149
|
+
declare const jwk_JWK_OKP_SIGN: typeof JWK_OKP_SIGN;
|
|
147
150
|
declare const jwk_JWK_PBES2: typeof JWK_PBES2;
|
|
151
|
+
declare const jwk_JWK_Private: typeof JWK_Private;
|
|
152
|
+
declare const jwk_JWK_Public: typeof JWK_Public;
|
|
148
153
|
declare const jwk_JWK_RSA: typeof JWK_RSA;
|
|
149
154
|
declare const jwk_JWK_RSA_ENC: typeof JWK_RSA_ENC;
|
|
150
155
|
declare const jwk_JWK_RSA_PSS: typeof JWK_RSA_PSS;
|
|
@@ -194,9 +199,14 @@ declare namespace jwk {
|
|
|
194
199
|
jwk_JWK_ECDSA as JWK_ECDSA,
|
|
195
200
|
jwk_JWK_EC_Private as JWK_EC_Private,
|
|
196
201
|
jwk_JWK_EC_Public as JWK_EC_Public,
|
|
197
|
-
jwk_JWK_ED as JWK_ED,
|
|
198
202
|
jwk_JWK_HMAC as JWK_HMAC,
|
|
203
|
+
jwk_JWK_OKP as JWK_OKP,
|
|
204
|
+
jwk_JWK_OKP_Private as JWK_OKP_Private,
|
|
205
|
+
jwk_JWK_OKP_Public as JWK_OKP_Public,
|
|
206
|
+
jwk_JWK_OKP_SIGN as JWK_OKP_SIGN,
|
|
199
207
|
jwk_JWK_PBES2 as JWK_PBES2,
|
|
208
|
+
jwk_JWK_Private as JWK_Private,
|
|
209
|
+
jwk_JWK_Public as JWK_Public,
|
|
200
210
|
jwk_JWK_RSA as JWK_RSA,
|
|
201
211
|
jwk_JWK_RSA_ENC as JWK_RSA_ENC,
|
|
202
212
|
jwk_JWK_RSA_PSS as JWK_RSA_PSS,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { K as KeyManagementAlgorithm, d as ContentEncryptionAlgorithm,
|
|
1
|
+
import { K as KeyManagementAlgorithm, d as ContentEncryptionAlgorithm, O as JoseHeaderParameters, f as JWK_EC_Public, r as JWK, R as JWTClaimValidationOptions, P as JWTClaims, Q as JWT } from './unjwt.BsgIQHVD.mjs';
|
|
2
2
|
|
|
3
3
|
/** Recognized JWE Header Parameters, any other Header Members may also be present. */
|
|
4
4
|
interface JWEHeaderParameters extends JoseHeaderParameters {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as JWK_HMAC, u as JWK_RSA_SIGN, v as JWK_RSA_PSS, w as JWK_ECDSA, O as JoseHeaderParameters, r as JWK, s as JWKSet, R as JWTClaimValidationOptions, P as JWTClaims, Q as JWT } from './unjwt.BsgIQHVD.mjs';
|
|
2
2
|
|
|
3
3
|
type JWS_SIGN_EXTRA = "Ed25519" | "EdDSA";
|
|
4
4
|
/** JWS Signing Algorithm Identifier. */
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { i as importKey, g as getJWKFromSet } from './unjwt.
|
|
2
|
-
import { a as isJWK, b as applyTypCtyDefaults, c as computeJwtTimeClaims, d as base64UrlEncode, t as textEncoder, e as textDecoder, f as base64UrlDecode, g as isJWKSet, h as decodePayloadFromB64UrlSegment, v as validateCriticalHeadersJWS, j as validateJwtClaims } from './unjwt.
|
|
3
|
-
import { s as sign$1, v as verify$1 } from './unjwt.
|
|
1
|
+
import { i as importKey, g as getJWKFromSet } from './unjwt.BVlHlXdP.mjs';
|
|
2
|
+
import { s as sanitizeObject, a as isJWK, b as applyTypCtyDefaults, c as computeJwtTimeClaims, d as base64UrlEncode, t as textEncoder, e as textDecoder, f as base64UrlDecode, g as isJWKSet, h as decodePayloadFromB64UrlSegment, v as validateCriticalHeadersJWS, j as validateJwtClaims } from './unjwt.BEjwP_9W.mjs';
|
|
3
|
+
import { s as sign$1, v as verify$1 } from './unjwt.BaB7HUR1.mjs';
|
|
4
4
|
|
|
5
5
|
async function sign(payload, key, options = {}) {
|
|
6
6
|
const { protectedHeader: additionalProtectedHeader } = options;
|
|
7
|
+
const safeAdditionalHeader = sanitizeObject(
|
|
8
|
+
additionalProtectedHeader
|
|
9
|
+
);
|
|
7
10
|
let { alg } = options;
|
|
8
11
|
if (!alg) {
|
|
9
12
|
if (isJWK(key) && key.alg) {
|
|
@@ -15,11 +18,11 @@ async function sign(payload, key, options = {}) {
|
|
|
15
18
|
validateKeyLength(key, alg);
|
|
16
19
|
const signingKey = await importKey(key, alg);
|
|
17
20
|
const protectedHeader = {
|
|
18
|
-
...
|
|
19
|
-
...isJWK(key) && key.kid ? { kid:
|
|
21
|
+
...safeAdditionalHeader,
|
|
22
|
+
...isJWK(key) && key.kid ? { kid: safeAdditionalHeader?.kid || key.kid } : {},
|
|
20
23
|
// Include kid if available
|
|
21
24
|
alg,
|
|
22
|
-
typ:
|
|
25
|
+
typ: safeAdditionalHeader?.typ
|
|
23
26
|
};
|
|
24
27
|
applyTypCtyDefaults(protectedHeader, payload);
|
|
25
28
|
if (protectedHeader.b64 === true) {
|
|
@@ -64,7 +67,9 @@ async function verify(jws, key, options = {}) {
|
|
|
64
67
|
let protectedHeader;
|
|
65
68
|
try {
|
|
66
69
|
const protectedHeaderString = base64UrlDecode(protectedHeaderEncoded);
|
|
67
|
-
protectedHeader =
|
|
70
|
+
protectedHeader = sanitizeObject(
|
|
71
|
+
JSON.parse(protectedHeaderString)
|
|
72
|
+
);
|
|
68
73
|
} catch (error_) {
|
|
69
74
|
throw new Error(
|
|
70
75
|
`Invalid JWS: Protected header is not valid Base64URL or JSON (${error_ instanceof Error ? error_.message : error_})`
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './shared/unjwt.
|
|
2
|
-
export {
|
|
1
|
+
import './shared/unjwt.BsgIQHVD.mjs';
|
|
2
|
+
export { s as applyTypCtyDefaults, j as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, z as computeJwtTimeClaims, f as concatUint8Arrays, v as decodeMaybeJsonString, x as decodePayloadFromB64UrlSegment, w as decodePayloadFromBytes, y as getPlaintextBytes, o as isAsymmetricJWK, k as isCryptoKey, l as isCryptoKeyPair, g as isJWK, h as isJWKSet, u as isJsonContent, p as isPrivateJWK, q as isPublicJWK, n as isSymmetricJWK, m as maybeArray, r as randomBytes, D as sanitizeObject, a as textDecoder, t as textEncoder, C as validateCriticalHeadersJWE, B as validateCriticalHeadersJWS, A as validateJwtClaims } from './shared/unjwt.BYaxDvLV.mjs';
|
package/dist/utils.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { b as applyTypCtyDefaults, l as assertCryptoKey, q as base64Decode,
|
|
1
|
+
export { b as applyTypCtyDefaults, l as assertCryptoKey, q as base64Decode, u as base64Encode, f as base64UrlDecode, d as base64UrlEncode, c as computeJwtTimeClaims, k as concatUint8Arrays, D as decodeMaybeJsonString, h as decodePayloadFromB64UrlSegment, o as decodePayloadFromBytes, n as getPlaintextBytes, z as isAsymmetricJWK, m as isCryptoKey, x as isCryptoKeyPair, a as isJWK, g as isJWKSet, C as isJsonContent, A as isPrivateJWK, B as isPublicJWK, y as isSymmetricJWK, w as maybeArray, r as randomBytes, s as sanitizeObject, e as textDecoder, t as textEncoder, p as validateCriticalHeadersJWE, v as validateCriticalHeadersJWS, j as validateJwtClaims } from './shared/unjwt.BEjwP_9W.mjs';
|