unjwt 0.5.8 → 0.5.10

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.
Files changed (36) hide show
  1. package/dist/index.d.mts +5 -6
  2. package/dist/index.mjs +5 -5
  3. package/dist/jwe.d.mts +2 -3
  4. package/dist/jwe.mjs +4 -4
  5. package/dist/jwk.d.mts +2 -3
  6. package/dist/jwk.mjs +2 -2
  7. package/dist/jws.d.mts +2 -3
  8. package/dist/jws.mjs +4 -4
  9. package/dist/shared/unjwt.B1dfkZSt.mjs +161 -0
  10. package/dist/shared/{unjwt.DRUXIabl.mjs → unjwt.BrOta13J.mjs} +19 -8
  11. package/dist/shared/{unjwt.Ca03jPX3.mjs → unjwt.CEjyBwhK.mjs} +1 -1
  12. package/dist/shared/{unjwt.D9da8HQF.d.mts → unjwt.CN1C8TlR.d.mts} +90 -15
  13. package/dist/shared/unjwt.CUUg6g3N.d.mts +128 -0
  14. package/dist/shared/{unjwt.CrcUJklb.d.ts → unjwt.Cz90HQhy.d.mts} +11 -12
  15. package/dist/shared/{unjwt.B2olxeGL.mjs → unjwt.D0WA_yog.mjs} +22 -86
  16. package/dist/shared/{unjwt.8w7jp2aw.d.mts → unjwt.Dof5OLMV.d.mts} +28 -30
  17. package/dist/shared/{unjwt.w-IAnI15.d.ts → unjwt.igKyF5q2.d.mts} +13 -69
  18. package/dist/shared/unjwt.odifuYKu.mjs +297 -0
  19. package/dist/utils.d.mts +2 -2
  20. package/dist/utils.mjs +1 -1
  21. package/package.json +12 -11
  22. package/dist/index.d.ts +0 -6
  23. package/dist/jwe.d.ts +0 -3
  24. package/dist/jwk.d.ts +0 -3
  25. package/dist/jws.d.ts +0 -3
  26. package/dist/shared/unjwt.BHpknTpg.mjs +0 -93
  27. package/dist/shared/unjwt.BZCtr-eB.mjs +0 -277
  28. package/dist/shared/unjwt.BvIkEGGz.d.mts +0 -52
  29. package/dist/shared/unjwt.CbvzYE-m.d.mts +0 -58
  30. package/dist/shared/unjwt.CoSilGqk.d.ts +0 -189
  31. package/dist/shared/unjwt.D4DUiNeM.d.ts +0 -58
  32. package/dist/shared/unjwt.D9da8HQF.d.ts +0 -210
  33. package/dist/shared/unjwt.DH1p_WL8.d.mts +0 -221
  34. package/dist/shared/unjwt.D_Mabhgz.d.mts +0 -172
  35. package/dist/shared/unjwt.c10n3uM8.d.ts +0 -52
  36. package/dist/utils.d.ts +0 -2
@@ -1,277 +0,0 @@
1
- import { i as importKey, g as getJWKFromSet } from './unjwt.DRUXIabl.mjs';
2
- import { a as isJWK, b as base64UrlEncode, t as textEncoder, c as textDecoder, d as base64UrlDecode, e as isJWKSet, m as maybeArray } from './unjwt.BHpknTpg.mjs';
3
- import { s as sign$1, v as verify$1 } from './unjwt.Ca03jPX3.mjs';
4
-
5
- async function sign(payload, key, options = {}) {
6
- const { protectedHeader: additionalProtectedHeader } = options;
7
- let { alg } = options;
8
- if (!alg) {
9
- if (isJWK(key) && key.alg) {
10
- alg = key.alg;
11
- } else {
12
- throw new TypeError('JWS "alg" (Algorithm) must be provided in options');
13
- }
14
- }
15
- validateKeyLength(key, alg);
16
- const signingKey = await importKey(key, alg);
17
- const protectedHeader = {
18
- ...additionalProtectedHeader,
19
- alg,
20
- typ: additionalProtectedHeader?.typ ?? (typeof payload === "object" && !(payload instanceof Uint8Array) ? "JWT" : void 0)
21
- // Default typ to JWT for objects
22
- };
23
- if (protectedHeader.typ === void 0 && typeof payload === "object" && !(payload instanceof Uint8Array)) {
24
- protectedHeader.typ = "JWT";
25
- protectedHeader.cty ||= "json";
26
- }
27
- if (protectedHeader.b64 === true) {
28
- delete protectedHeader.b64;
29
- }
30
- let computedPayload = void 0;
31
- if (options.expiresIn !== void 0 && protectedHeader.typ === "JWT" && typeof payload === "object" && !(payload instanceof Uint8Array) && !payload.exp) {
32
- computedPayload = { ...payload };
33
- const currentTime = Math.round(
34
- (options.currentDate ?? /* @__PURE__ */ new Date()).getTime() / 1e3
35
- );
36
- computedPayload.iat ||= currentTime;
37
- computedPayload.exp = currentTime + options.expiresIn;
38
- }
39
- const protectedHeaderString = JSON.stringify(protectedHeader);
40
- const protectedHeaderEncoded = base64UrlEncode(protectedHeaderString);
41
- let payloadBytes;
42
- if (payload instanceof Uint8Array) {
43
- payloadBytes = payload;
44
- } else if (typeof payload === "string") {
45
- payloadBytes = textEncoder.encode(payload);
46
- } else if (typeof payload === "object" && payload !== null) {
47
- payloadBytes = textEncoder.encode(
48
- JSON.stringify(computedPayload || payload)
49
- );
50
- } else {
51
- throw new TypeError(
52
- "Payload must be a string, Uint8Array, or a JSON-serializable object."
53
- );
54
- }
55
- const useB64 = protectedHeader.b64 !== false;
56
- const payloadEncoded = useB64 ? base64UrlEncode(payloadBytes) : textDecoder.decode(payloadBytes);
57
- const signingInputString = `${protectedHeaderEncoded}.${payloadEncoded}`;
58
- const signingInputBytes = textEncoder.encode(signingInputString);
59
- const signatureBytes = await sign$1(alg, signingKey, signingInputBytes);
60
- const signatureEncoded = base64UrlEncode(signatureBytes);
61
- return `${signingInputString}.${signatureEncoded}`;
62
- }
63
- async function verify(jws, key, options = {}) {
64
- const parts = jws.split(".");
65
- if (parts.length !== 3) {
66
- throw new Error("Invalid JWS: Must contain three parts separated by dots.");
67
- }
68
- const [protectedHeaderEncoded, payloadEncoded, signatureEncoded] = parts;
69
- let protectedHeader;
70
- try {
71
- const protectedHeaderString = base64UrlDecode(protectedHeaderEncoded);
72
- protectedHeader = JSON.parse(protectedHeaderString);
73
- } catch (error_) {
74
- throw new Error(
75
- `Invalid JWS: Protected header is not valid Base64URL or JSON (${error_ instanceof Error ? error_.message : error_})`
76
- );
77
- }
78
- if (!protectedHeader || typeof protectedHeader !== "object" || !protectedHeader.alg) {
79
- throw new Error(
80
- 'Invalid JWS: Protected header must be an object with an "alg" property.'
81
- );
82
- }
83
- const alg = protectedHeader.alg;
84
- if (options.algorithms && !options.algorithms.includes(alg)) {
85
- throw new Error(`Algorithm not allowed: ${alg}`);
86
- }
87
- if (options.typ && protectedHeader.typ !== options.typ) {
88
- throw new Error(
89
- `Invalid JWS: "typ" (Type) Header Parameter mismatch. Expected "${options.typ}", got "${protectedHeader.typ}".`
90
- );
91
- }
92
- let signatureBytes;
93
- try {
94
- signatureBytes = base64UrlDecode(signatureEncoded, false);
95
- } catch (error_) {
96
- throw new Error(
97
- `Invalid JWS: Signature is not valid Base64URL (${error_ instanceof Error ? error_.message : error_})`
98
- );
99
- }
100
- const keyInput = typeof key === "function" ? await key(protectedHeader, jws) : key;
101
- const resolvedKey = isJWKSet(keyInput) ? getJWKFromSet(keyInput, protectedHeader) : keyInput;
102
- const verificationKey = await importKey(resolvedKey, alg);
103
- const signingInputString = `${protectedHeaderEncoded}.${payloadEncoded}`;
104
- const signingInputBytes = textEncoder.encode(signingInputString);
105
- const isValid = await verify$1(
106
- alg,
107
- verificationKey,
108
- signatureBytes,
109
- signingInputBytes
110
- );
111
- if (!isValid) {
112
- throw new Error("JWS signature verification failed.");
113
- }
114
- const useB64 = protectedHeader.b64 !== false;
115
- let payload;
116
- try {
117
- if (useB64) {
118
- if (options.forceUint8Array) {
119
- payload = base64UrlDecode(payloadEncoded, false);
120
- } else {
121
- const cty = protectedHeader.cty?.toLowerCase();
122
- const isJsonOutput = protectedHeader.typ === "JWT" || cty === "json" || cty === "application/json" || cty && cty.endsWith("+json");
123
- const decodedString = base64UrlDecode(payloadEncoded);
124
- if (isJsonOutput) {
125
- if (decodedString.startsWith("{") && decodedString.endsWith("}") || decodedString.startsWith("[") && decodedString.endsWith("]")) {
126
- try {
127
- payload = JSON.parse(decodedString);
128
- } catch {
129
- payload = decodedString;
130
- }
131
- } else {
132
- payload = decodedString;
133
- }
134
- } else {
135
- payload = decodedString;
136
- }
137
- }
138
- } else {
139
- payload = options.forceUint8Array ? textEncoder.encode(payloadEncoded) : payloadEncoded;
140
- }
141
- } catch (error_) {
142
- throw new Error(
143
- `Invalid JWS: Payload decoding failed (${error_ instanceof Error ? error_.message : error_})`
144
- );
145
- }
146
- if (protectedHeader.crit) {
147
- const missingHeaderParams = /* @__PURE__ */ new Set();
148
- const recognizedParams = /* @__PURE__ */ new Set([
149
- ...options.critical || [],
150
- // TODO: remove deprecated option
151
- ...options.requiredHeaders || [],
152
- "alg",
153
- "typ",
154
- "cty",
155
- "kid",
156
- "jwk",
157
- "jku",
158
- "x5c",
159
- "x5t",
160
- "x5u",
161
- "b64"
162
- ]);
163
- for (const param of protectedHeader.crit) {
164
- if (recognizedParams.has(param) && (param in protectedHeader || param === "b64")) {
165
- continue;
166
- }
167
- missingHeaderParams.add(param);
168
- }
169
- if (missingHeaderParams.size > 0) {
170
- throw new Error(
171
- `Missing critical header parameters: ${[...missingHeaderParams].join(", ")}`
172
- );
173
- }
174
- }
175
- if (payload && typeof payload === "object" && protectedHeader.typ === "JWT" && !options.forceUint8Array) {
176
- const jwtClaims = payload;
177
- const clockTolerance = options.clockTolerance ?? 0;
178
- const currentTime = Math.round(
179
- (options.currentDate ?? /* @__PURE__ */ new Date()).getTime() / 1e3
180
- );
181
- const allRequiredClaims = new Set(options.requiredClaims || []);
182
- const missingClaims = /* @__PURE__ */ new Set();
183
- if (options.issuer) allRequiredClaims.add("iss");
184
- if (options.audience) allRequiredClaims.add("aud");
185
- if (options.subject) allRequiredClaims.add("sub");
186
- if (options.maxTokenAge) allRequiredClaims.add("iat");
187
- for (const claimName of allRequiredClaims) {
188
- if (!(claimName in jwtClaims)) {
189
- missingClaims.add(claimName);
190
- }
191
- }
192
- if (missingClaims.size > 0) {
193
- throw new Error(
194
- `Missing required JWT Claims: ${[...missingClaims].join(", ")}`
195
- );
196
- }
197
- if (options.issuer) {
198
- const expectedIssuers = maybeArray(options.issuer);
199
- if (!jwtClaims.iss || !expectedIssuers.includes(jwtClaims.iss)) {
200
- throw new Error(
201
- `Invalid JWT "iss" (Issuer) Claim: Expected ${expectedIssuers.join(" or ")}, got ${jwtClaims.iss}`
202
- );
203
- }
204
- }
205
- if (options.subject && jwtClaims.sub !== options.subject) {
206
- throw new Error(
207
- `Invalid JWT "sub" (Subject) Claim: Expected ${options.subject}, got ${jwtClaims.sub}`
208
- );
209
- }
210
- if (options.audience) {
211
- const expectedAudiences = maybeArray(options.audience);
212
- const claimAudience = maybeArray(jwtClaims.aud || []);
213
- if (!claimAudience.some((aud) => expectedAudiences.includes(aud))) {
214
- throw new Error(
215
- `Invalid JWT "aud" (Audience) Claim: Expected ${expectedAudiences.join(" or ")}, got ${claimAudience.join(", ")}`
216
- );
217
- }
218
- }
219
- if (typeof jwtClaims.nbf === "number" && jwtClaims.nbf > currentTime + clockTolerance) {
220
- throw new Error(
221
- `JWT "nbf" (Not Before) Claim validation failed: Token is not yet valid (nbf: ${new Date(jwtClaims.nbf * 1e3).toISOString()})`
222
- );
223
- }
224
- if (typeof jwtClaims.exp === "number" && jwtClaims.exp <= currentTime - clockTolerance) {
225
- throw new Error(
226
- `JWT "exp" (Expiration Time) Claim validation failed: Token has expired (exp: ${new Date(jwtClaims.exp * 1e3).toISOString()})`
227
- );
228
- }
229
- if (options.maxTokenAge) {
230
- if (typeof jwtClaims.iat !== "number") {
231
- throw new TypeError(
232
- 'JWT "iat" (Issued At) Claim must be a number when maxTokenAge is set.'
233
- );
234
- }
235
- if (jwtClaims.iat > currentTime + clockTolerance) {
236
- throw new Error(
237
- `JWT "iat" (Issued At) Claim validation failed: Token was issued in the future (iat: ${new Date(jwtClaims.iat * 1e3).toISOString()})`
238
- );
239
- }
240
- if (jwtClaims.iat < currentTime - options.maxTokenAge - clockTolerance) {
241
- throw new Error(
242
- `JWT "iat" (Issued At) Claim validation failed: Token is too old (maxTokenAge: ${options.maxTokenAge}s, iat: ${new Date(jwtClaims.iat * 1e3).toISOString()})`
243
- );
244
- }
245
- }
246
- }
247
- return {
248
- payload,
249
- protectedHeader
250
- };
251
- }
252
- function validateKeyLength(key, alg) {
253
- if (!alg || isJWK(key)) return;
254
- if (alg.startsWith("HS") && key instanceof Uint8Array) {
255
- const algLength = Number.parseInt(alg.slice(2)) / 8;
256
- if (key.length < algLength) {
257
- throw new TypeError(
258
- `${alg} requires key length to be ${algLength} bytes or larger`
259
- );
260
- }
261
- } else if ((alg.startsWith("RS") || alg.startsWith("PS")) && key instanceof CryptoKey) {
262
- const { modulusLength } = key.algorithm;
263
- if (typeof modulusLength !== "number" || modulusLength < 2048) {
264
- throw new TypeError(
265
- `${alg} requires key modulusLength to be 2048 bits or larger`
266
- );
267
- }
268
- }
269
- }
270
-
271
- const jws = {
272
- __proto__: null,
273
- sign: sign,
274
- verify: verify
275
- };
276
-
277
- export { jws as j, sign as s, verify as v };
@@ -1,52 +0,0 @@
1
- import { i as JWK_RSA_Public } from './unjwt.D9da8HQF.mjs';
2
-
3
- /** Header Parameters common to JWE and JWS */
4
- interface JoseHeaderParameters {
5
- /** "kid" (Key ID) Header Parameter */
6
- kid?: string;
7
- /** "x5t" (X.509 Certificate SHA-1 Thumbprint) Header Parameter */
8
- x5t?: string;
9
- /** "x5c" (X.509 Certificate Chain) Header Parameter */
10
- x5c?: string[];
11
- /** "x5u" (X.509 URL) Header Parameter */
12
- x5u?: string;
13
- /** "jku" (JWK Set URL) Header Parameter */
14
- jku?: string;
15
- /** "jwk" (JSON Web Key) Header Parameter */
16
- jwk?: JWK_RSA_Public;
17
- /** "typ" (Type) Header Parameter */
18
- typ?: string;
19
- /** "cty" (Content Type) Header Parameter */
20
- cty?: string;
21
- /** "crit" (Critical) Header Parameter */
22
- crit?: string[];
23
- /** Any other JWS/JWE Header member. */
24
- [propName: string]: unknown;
25
- }
26
- interface JWTClaims {
27
- /** "iss" (Issuer) Claim */
28
- iss?: string;
29
- /** "sub" (Subject) Claim */
30
- sub?: string;
31
- /** "aud" (Audience) Claim */
32
- aud?: string | string[];
33
- /** "exp" (Expiration Time) Claim */
34
- exp?: number;
35
- /** "nbf" (Not Before) Claim */
36
- nbf?: number;
37
- /** "iat" (Issued At) Claim */
38
- iat?: number;
39
- /** "jti" (JWT ID) Claim */
40
- jti?: string;
41
- /** Any other JWT member. */
42
- [propName: string]: unknown;
43
- }
44
- interface JWT<T = JWTClaims> {
45
- header: JoseHeaderParameters & {
46
- /** "alg" (Algorithm) Header Parameter */
47
- alg: string;
48
- };
49
- claims: T;
50
- }
51
-
52
- export type { JoseHeaderParameters as J, JWTClaims as a, JWT as b };
@@ -1,58 +0,0 @@
1
- import { m as JWK, n as JWKSet } from './unjwt.D9da8HQF.mjs';
2
-
3
- declare const textEncoder: TextEncoder;
4
- declare const textDecoder: TextDecoder;
5
- declare function base64Encode(data: Uint8Array | string): string;
6
- declare function base64UrlEncode(data: Uint8Array | string): string;
7
- declare function base64Decode(str: string | undefined): string;
8
- declare function base64Decode<T extends boolean | undefined>(str?: string | undefined, toString?: T): T extends false ? Uint8Array : string;
9
- declare function base64UrlDecode(str: string | undefined): string;
10
- declare function base64UrlDecode<T extends boolean | undefined>(str?: string | undefined, toString?: T): T extends false ? Uint8Array : string;
11
- declare function randomBytes(length: Readonly<number>): Uint8Array;
12
- /**
13
- * Concatenates multiple Uint8Arrays
14
- * @param arrays Arrays to concatenate
15
- * @returns Concatenated array
16
- */
17
- declare function concatUint8Arrays(...arrays: Readonly<Uint8Array[]>): Uint8Array;
18
- declare function maybeArray<T>(item: T | T[]): T[];
19
- declare function isJWK(key: any): key is JWK;
20
- declare function isJWKSet(key: any): key is JWKSet;
21
- declare function assertCryptoKey(key: unknown): asserts key is CryptoKey;
22
- declare function isCryptoKey(key: unknown): key is CryptoKey;
23
- declare const isCryptoKeyPair: (key: any) => key is CryptoKeyPair;
24
-
25
- declare const index_assertCryptoKey: typeof assertCryptoKey;
26
- declare const index_base64Decode: typeof base64Decode;
27
- declare const index_base64Encode: typeof base64Encode;
28
- declare const index_base64UrlDecode: typeof base64UrlDecode;
29
- declare const index_base64UrlEncode: typeof base64UrlEncode;
30
- declare const index_concatUint8Arrays: typeof concatUint8Arrays;
31
- declare const index_isCryptoKey: typeof isCryptoKey;
32
- declare const index_isCryptoKeyPair: typeof isCryptoKeyPair;
33
- declare const index_isJWK: typeof isJWK;
34
- declare const index_isJWKSet: typeof isJWKSet;
35
- declare const index_maybeArray: typeof maybeArray;
36
- declare const index_randomBytes: typeof randomBytes;
37
- declare const index_textDecoder: typeof textDecoder;
38
- declare const index_textEncoder: typeof textEncoder;
39
- declare namespace index {
40
- export {
41
- index_assertCryptoKey as assertCryptoKey,
42
- index_base64Decode as base64Decode,
43
- index_base64Encode as base64Encode,
44
- index_base64UrlDecode as base64UrlDecode,
45
- index_base64UrlEncode as base64UrlEncode,
46
- index_concatUint8Arrays as concatUint8Arrays,
47
- index_isCryptoKey as isCryptoKey,
48
- index_isCryptoKeyPair as isCryptoKeyPair,
49
- index_isJWK as isJWK,
50
- index_isJWKSet as isJWKSet,
51
- index_maybeArray as maybeArray,
52
- index_randomBytes as randomBytes,
53
- index_textDecoder as textDecoder,
54
- index_textEncoder as textEncoder,
55
- };
56
- }
57
-
58
- 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, randomBytes as r, textEncoder as t };
@@ -1,189 +0,0 @@
1
- import { K as KeyManagementAlgorithm, d as ContentEncryptionAlgorithm, f as JWK_EC_Public, m as JWK } from './unjwt.D9da8HQF.js';
2
- import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.c10n3uM8.js';
3
-
4
- /** Recognized JWE Header Parameters, any other Header Members may also be present. */
5
- interface JWEHeaderParameters extends JoseHeaderParameters {
6
- /**
7
- * `alg` (Algorithm): Header Parameter - Key Management Algorithm
8
- */
9
- alg?: string;
10
- /**
11
- * `enc` (Encryption Algorithm): Header Parameter - Content Encryption Algorithm
12
- */
13
- enc?: string;
14
- /**
15
- * `p2c` (PBES2 Count): Header Parameter
16
- */
17
- p2c?: number;
18
- /**
19
- * `p2s` (PBES2 Salt): Header Parameter. Base64URL encoded.
20
- */
21
- p2s?: string;
22
- /**
23
- * "iv" (Initialization Vector) Header Parameter for AES GCM Key Wrapping. Base64URL encoded.
24
- */
25
- iv?: string;
26
- /**
27
- * "tag" (Authentication Tag) Header Parameter for AES GCM Key Wrapping. Base64URL encoded.
28
- */
29
- tag?: string;
30
- /**
31
- * "epk" (Ephemeral Public Key) Header Parameter for ECDH-ES.
32
- */
33
- epk?: JWK_EC_Public;
34
- /**
35
- * "apu" (Agreement PartyUInfo) Header Parameter for ECDH-ES. Base64URL encoded.
36
- */
37
- apu?: string;
38
- /**
39
- * "apv" (Agreement PartyVInfo) Header Parameter for ECDH-ES. Base64URL encoded.
40
- */
41
- apv?: string;
42
- /** Any other JWE Header member. */
43
- [propName: string]: unknown;
44
- }
45
- /** Recognized JWE Key Management-related Header Parameters. */
46
- interface JWEKeyManagementHeaderParameters {
47
- apu?: Uint8Array;
48
- apv?: Uint8Array;
49
- /**
50
- * For Internal use only
51
- */
52
- p2c?: number;
53
- /**
54
- * For Internal use only
55
- */
56
- p2s?: Uint8Array;
57
- /**
58
- * For Internal use only
59
- */
60
- iv?: Uint8Array;
61
- /**
62
- * For Internal use only
63
- */
64
- epk?: CryptoKey;
65
- }
66
- /**
67
- * JWE (JSON Web Encryption) encryption options
68
- */
69
- interface JWEEncryptOptions {
70
- /** JWE "alg" (Algorithm) Header Parameter. Key Management Algorithm. */
71
- alg?: KeyManagementAlgorithm;
72
- /** JWE "enc" (Encryption Algorithm) Header Parameter. Content Encryption Algorithm. */
73
- enc?: ContentEncryptionAlgorithm;
74
- /** Additional JWE Protected Header parameters. */
75
- protectedHeader?: Omit<JWEHeaderParameters, "alg" | "enc" | "iv" | "tag" | "p2s" | "p2c" | "apu" | "apv">;
76
- /** Initialization Vector for AES-GCMKW key wrapping. Generated if not provided. */
77
- keyManagementIV?: Uint8Array;
78
- /** PBES2 Salt value (p2s). Required for PBES2 algorithms. */
79
- p2s?: Uint8Array;
80
- /** PBES2 Iteration count (p2c). Required for PBES2 algorithms. */
81
- p2c?: number;
82
- /** ECDH-ES Agreement PartyUInfo. */
83
- ecdhPartyUInfo?: Uint8Array;
84
- /** ECDH-ES Agreement PartyVInfo. */
85
- ecdhPartyVInfo?: Uint8Array;
86
- /**
87
- * Content Encryption Key (CEK) to use.
88
- * If provided, it will be used directly. Otherwise, a CEK will be generated.
89
- */
90
- cek?: Uint8Array;
91
- /**
92
- * Initialization Vector for content encryption.
93
- * If provided, it will be used. Otherwise, one will be generated.
94
- */
95
- contentEncryptionIV?: Uint8Array;
96
- }
97
- /**
98
- * Key lookup function for JWE decryption.
99
- * @param header The JWE Protected Header.
100
- * @returns The key material (CryptoKey, JWK, password string, or raw Uint8Array) or a Promise resolving to it.
101
- */
102
- type JWEKeyLookupFunction = (header: JWEHeaderParameters, token: string) => CryptoKey | JWK | string | Uint8Array | Promise<CryptoKey | JWK | string | Uint8Array>;
103
- /**
104
- * JWE (JSON Web Encryption) decryption options
105
- */
106
- interface JWEDecryptOptions {
107
- /** A list of allowed JWE "alg" (Algorithm) Header Parameter values for key management. */
108
- algorithms?: KeyManagementAlgorithm[];
109
- /** A list of allowed JWE "enc" (Encryption Algorithm) Header Parameter values for content encryption. */
110
- encryptionAlgorithms?: ContentEncryptionAlgorithm[];
111
- /**
112
- * Critical Header Parameters to be understood and processed.
113
- * If the JWE contains critical headers not in this list (and not inherently understood by the library), decryption will fail.
114
- */
115
- critical?: string[];
116
- /** Algorithm to import the unwrapped CEK as (e.g., { name: 'AES-GCM' }). Defaults based on 'enc'. */
117
- unwrappedKeyAlgorithm?: Parameters<typeof crypto.subtle.importKey>[2];
118
- /** Key usages for the unwrapped CEK. Defaults based on 'enc' (typically ['encrypt', 'decrypt']). */
119
- keyUsage?: KeyUsage[];
120
- /** Mark the unwrapped CEK as extractable. Defaults to true. */
121
- extractable?: boolean;
122
- /** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred based on JWE headers. */
123
- forceUint8Array?: boolean;
124
- }
125
- /**
126
- * Result of a JWE decryption operation.
127
- */
128
- interface JWEDecryptResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> {
129
- /** The decrypted payload. */
130
- payload: T;
131
- /** The JWE Protected Header. */
132
- protectedHeader: JWEHeaderParameters;
133
- /** The Content Encryption Key (CEK) used for decryption, as Uint8Array. */
134
- cek: Uint8Array;
135
- /** The Additional Authenticated Data (AAD) used, as Uint8Array. */
136
- aad: Uint8Array;
137
- }
138
-
139
- /**
140
- * Encrypts a payload to produce a JWE Compact Serialization string.
141
- *
142
- * @param payload The payload to encrypt. Can be a string, Uint8Array, or a JSON-serializable object.
143
- * @param key The key encryption key (KEK). Can be a CryptoKey, JWK, or for PBES2, a password string/Uint8Array.
144
- * @param options JWE encryption options, including `alg` (key management algorithm) and `enc` (content encryption algorithm).
145
- * @returns A Promise resolving to the JWE Compact Serialization string.
146
- */
147
- declare function encrypt(payload: JWTClaims, key: JWK | string | Uint8Array, options?: JWEEncryptOptions): Promise<string>;
148
- declare function encrypt(payload: string | Uint8Array | Record<string, any>, key: JWK | string | Uint8Array, options?: JWEEncryptOptions): Promise<string>;
149
- declare function encrypt(payload: JWTClaims, key: CryptoKey, options: JWEEncryptOptions & {
150
- alg: KeyManagementAlgorithm;
151
- enc: ContentEncryptionAlgorithm;
152
- }): Promise<string>;
153
- declare function encrypt(payload: string | Uint8Array | Record<string, any>, key: CryptoKey, options: JWEEncryptOptions & {
154
- alg: KeyManagementAlgorithm;
155
- enc: ContentEncryptionAlgorithm;
156
- }): Promise<string>;
157
- declare function encrypt(payload: string | Uint8Array | Record<string, any>, key: CryptoKey | JWK | string | Uint8Array, options: JWEEncryptOptions & {
158
- alg: KeyManagementAlgorithm;
159
- enc: ContentEncryptionAlgorithm;
160
- }): Promise<string>;
161
- /**
162
- * Decrypts a JWE Compact Serialization string.
163
- *
164
- * @param jwe The JWE Compact Serialization string.
165
- * @param key The key decryption key (KEK) or a function to look up the key.
166
- * @param options JWE decryption options.
167
- * @returns A Promise resolving to an object containing the decrypted plaintext, protected header, CEK, and AAD.
168
- * @throws If JWE is invalid, decryption fails, or options are not met.
169
- */
170
- declare function decrypt<T extends JWTClaims | Uint8Array | string>(jwe: string, key: CryptoKey | JWK | string | Uint8Array | JWEKeyLookupFunction, options?: JWEDecryptOptions): Promise<JWEDecryptResult<T>>;
171
- declare function decrypt(jwe: string, key: CryptoKey | JWK | string | Uint8Array | JWEKeyLookupFunction, options: JWEDecryptOptions & {
172
- forceUint8Array: true;
173
- }): Promise<JWEDecryptResult<Uint8Array>>;
174
-
175
- type jwe_JWEDecryptOptions = JWEDecryptOptions;
176
- type jwe_JWEDecryptResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> = JWEDecryptResult<T>;
177
- type jwe_JWEEncryptOptions = JWEEncryptOptions;
178
- type jwe_JWEHeaderParameters = JWEHeaderParameters;
179
- type jwe_JWEKeyLookupFunction = JWEKeyLookupFunction;
180
- type jwe_JWEKeyManagementHeaderParameters = JWEKeyManagementHeaderParameters;
181
- declare const jwe_decrypt: typeof decrypt;
182
- declare const jwe_encrypt: typeof encrypt;
183
- declare namespace jwe {
184
- export { jwe_decrypt as decrypt, jwe_encrypt as encrypt };
185
- export type { jwe_JWEDecryptOptions as JWEDecryptOptions, jwe_JWEDecryptResult as JWEDecryptResult, jwe_JWEEncryptOptions as JWEEncryptOptions, jwe_JWEHeaderParameters as JWEHeaderParameters, jwe_JWEKeyLookupFunction as JWEKeyLookupFunction, jwe_JWEKeyManagementHeaderParameters as JWEKeyManagementHeaderParameters };
186
- }
187
-
188
- export { encrypt as f, decrypt as g, jwe as j };
189
- export type { JWEHeaderParameters as J, JWEKeyManagementHeaderParameters as a, JWEEncryptOptions as b, JWEKeyLookupFunction as c, JWEDecryptOptions as d, JWEDecryptResult as e };
@@ -1,58 +0,0 @@
1
- import { m as JWK, n as JWKSet } from './unjwt.D9da8HQF.js';
2
-
3
- declare const textEncoder: TextEncoder;
4
- declare const textDecoder: TextDecoder;
5
- declare function base64Encode(data: Uint8Array | string): string;
6
- declare function base64UrlEncode(data: Uint8Array | string): string;
7
- declare function base64Decode(str: string | undefined): string;
8
- declare function base64Decode<T extends boolean | undefined>(str?: string | undefined, toString?: T): T extends false ? Uint8Array : string;
9
- declare function base64UrlDecode(str: string | undefined): string;
10
- declare function base64UrlDecode<T extends boolean | undefined>(str?: string | undefined, toString?: T): T extends false ? Uint8Array : string;
11
- declare function randomBytes(length: Readonly<number>): Uint8Array;
12
- /**
13
- * Concatenates multiple Uint8Arrays
14
- * @param arrays Arrays to concatenate
15
- * @returns Concatenated array
16
- */
17
- declare function concatUint8Arrays(...arrays: Readonly<Uint8Array[]>): Uint8Array;
18
- declare function maybeArray<T>(item: T | T[]): T[];
19
- declare function isJWK(key: any): key is JWK;
20
- declare function isJWKSet(key: any): key is JWKSet;
21
- declare function assertCryptoKey(key: unknown): asserts key is CryptoKey;
22
- declare function isCryptoKey(key: unknown): key is CryptoKey;
23
- declare const isCryptoKeyPair: (key: any) => key is CryptoKeyPair;
24
-
25
- declare const index_assertCryptoKey: typeof assertCryptoKey;
26
- declare const index_base64Decode: typeof base64Decode;
27
- declare const index_base64Encode: typeof base64Encode;
28
- declare const index_base64UrlDecode: typeof base64UrlDecode;
29
- declare const index_base64UrlEncode: typeof base64UrlEncode;
30
- declare const index_concatUint8Arrays: typeof concatUint8Arrays;
31
- declare const index_isCryptoKey: typeof isCryptoKey;
32
- declare const index_isCryptoKeyPair: typeof isCryptoKeyPair;
33
- declare const index_isJWK: typeof isJWK;
34
- declare const index_isJWKSet: typeof isJWKSet;
35
- declare const index_maybeArray: typeof maybeArray;
36
- declare const index_randomBytes: typeof randomBytes;
37
- declare const index_textDecoder: typeof textDecoder;
38
- declare const index_textEncoder: typeof textEncoder;
39
- declare namespace index {
40
- export {
41
- index_assertCryptoKey as assertCryptoKey,
42
- index_base64Decode as base64Decode,
43
- index_base64Encode as base64Encode,
44
- index_base64UrlDecode as base64UrlDecode,
45
- index_base64UrlEncode as base64UrlEncode,
46
- index_concatUint8Arrays as concatUint8Arrays,
47
- index_isCryptoKey as isCryptoKey,
48
- index_isCryptoKeyPair as isCryptoKeyPair,
49
- index_isJWK as isJWK,
50
- index_isJWKSet as isJWKSet,
51
- index_maybeArray as maybeArray,
52
- index_randomBytes as randomBytes,
53
- index_textDecoder as textDecoder,
54
- index_textEncoder as textEncoder,
55
- };
56
- }
57
-
58
- 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, randomBytes as r, textEncoder as t };