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
@@ -0,0 +1,297 @@
1
+ function applyTypCtyDefaults(header, payload) {
2
+ const isObjectPayload = typeof payload === "object" && payload !== null && !(payload instanceof Uint8Array);
3
+ if (header.typ === void 0 && isObjectPayload) {
4
+ header.typ = "JWT";
5
+ }
6
+ if (header.typ === "JWT" && isObjectPayload) {
7
+ header.cty ||= "json";
8
+ }
9
+ return header;
10
+ }
11
+ function isJsonContent(header) {
12
+ if (!header) return false;
13
+ if (header.typ === "JWT") return true;
14
+ const cty = header.cty?.toLowerCase();
15
+ return cty === "json" || cty === "application/json" || !!cty && cty.endsWith("+json");
16
+ }
17
+ function decodeMaybeJsonString(decodedString, header) {
18
+ if (isJsonContent(header)) {
19
+ const looksLikeJson = decodedString.startsWith("{") && decodedString.endsWith("}") || decodedString.startsWith("[") && decodedString.endsWith("]");
20
+ if (looksLikeJson) {
21
+ try {
22
+ return JSON.parse(decodedString);
23
+ } catch {
24
+ }
25
+ }
26
+ }
27
+ return decodedString;
28
+ }
29
+ function decodePayloadFromBytes(bytes, header, forceUint8Array) {
30
+ if (forceUint8Array) return bytes;
31
+ const decodedString = textDecoder.decode(bytes);
32
+ return decodeMaybeJsonString(decodedString, header);
33
+ }
34
+ function decodePayloadFromB64UrlSegment(payloadEncoded, header, forceUint8Array) {
35
+ if (forceUint8Array) return base64UrlDecode(payloadEncoded, false);
36
+ const decodedString = base64UrlDecode(payloadEncoded);
37
+ return decodeMaybeJsonString(decodedString, header);
38
+ }
39
+ function getPlaintextBytes(payload) {
40
+ if (payload instanceof Uint8Array) return payload;
41
+ if (typeof payload === "string") return textEncoder.encode(payload);
42
+ if (typeof payload === "object" && payload !== null)
43
+ return textEncoder.encode(JSON.stringify(payload));
44
+ throw new TypeError(
45
+ "Plaintext must be a string, Uint8Array, or a JSON-serializable object."
46
+ );
47
+ }
48
+ function computeJwtTimeClaims(payload, headerTyp, expiresIn, currentDate = /* @__PURE__ */ new Date()) {
49
+ if (expiresIn === void 0 || headerTyp !== "JWT" || !(payload && typeof payload === "object") || payload instanceof Uint8Array || payload.exp) {
50
+ return void 0;
51
+ }
52
+ const now = Math.round(currentDate.getTime() / 1e3);
53
+ const claims = { ...payload };
54
+ claims.iat ||= now;
55
+ claims.exp = now + expiresIn;
56
+ return claims;
57
+ }
58
+ function validateJwtClaims(jwtClaims, options = {}) {
59
+ const clockTolerance = options.clockTolerance ?? 0;
60
+ const currentTime = Math.round(
61
+ (options.currentDate ?? /* @__PURE__ */ new Date()).getTime() / 1e3
62
+ );
63
+ const allRequiredClaims = new Set(options.requiredClaims || []);
64
+ const missingClaims = /* @__PURE__ */ new Set();
65
+ if (options.issuer) allRequiredClaims.add("iss");
66
+ if (options.audience) allRequiredClaims.add("aud");
67
+ if (options.subject) allRequiredClaims.add("sub");
68
+ if (options.maxTokenAge) allRequiredClaims.add("iat");
69
+ for (const claimName of allRequiredClaims) {
70
+ if (!(claimName in jwtClaims)) missingClaims.add(claimName);
71
+ }
72
+ if (missingClaims.size > 0) {
73
+ throw new Error(
74
+ `Missing required JWT Claims: ${[...missingClaims].join(", ")}`
75
+ );
76
+ }
77
+ if (options.issuer) {
78
+ const expectedIssuers = maybeArray(options.issuer);
79
+ if (!jwtClaims.iss || !expectedIssuers.includes(jwtClaims.iss)) {
80
+ throw new Error(
81
+ `Invalid JWT "iss" (Issuer) Claim: Expected ${expectedIssuers.join(" or ")}, got ${jwtClaims.iss}`
82
+ );
83
+ }
84
+ }
85
+ if (options.subject && jwtClaims.sub !== options.subject) {
86
+ throw new Error(
87
+ `Invalid JWT "sub" (Subject) Claim: Expected ${options.subject}, got ${jwtClaims.sub}`
88
+ );
89
+ }
90
+ if (options.audience) {
91
+ const expectedAudiences = maybeArray(options.audience);
92
+ const claimAudience = maybeArray(jwtClaims.aud || []);
93
+ if (!claimAudience.some((aud) => expectedAudiences.includes(aud))) {
94
+ throw new Error(
95
+ `Invalid JWT "aud" (Audience) Claim: Expected ${expectedAudiences.join(" or ")}, got ${claimAudience.join(", ")}`
96
+ );
97
+ }
98
+ }
99
+ if (typeof jwtClaims.nbf === "number" && jwtClaims.nbf > currentTime + clockTolerance) {
100
+ throw new Error(
101
+ `JWT "nbf" (Not Before) Claim validation failed: Token is not yet valid (nbf: ${new Date(jwtClaims.nbf * 1e3).toISOString()})`
102
+ );
103
+ }
104
+ if (typeof jwtClaims.exp === "number" && jwtClaims.exp <= currentTime - clockTolerance) {
105
+ throw new Error(
106
+ `JWT "exp" (Expiration Time) Claim validation failed: Token has expired (exp: ${new Date(jwtClaims.exp * 1e3).toISOString()})`
107
+ );
108
+ }
109
+ if (options.maxTokenAge) {
110
+ if (typeof jwtClaims.iat !== "number") {
111
+ throw new TypeError(
112
+ 'JWT "iat" (Issued At) Claim must be a number when maxTokenAge is set.'
113
+ );
114
+ }
115
+ if (jwtClaims.iat > currentTime + clockTolerance) {
116
+ throw new Error(
117
+ `JWT "iat" (Issued At) Claim validation failed: Token was issued in the future (iat: ${new Date(jwtClaims.iat * 1e3).toISOString()})`
118
+ );
119
+ }
120
+ if (jwtClaims.iat < currentTime - options.maxTokenAge - clockTolerance) {
121
+ throw new Error(
122
+ `JWT "iat" (Issued At) Claim validation failed: Token is too old (maxTokenAge: ${options.maxTokenAge}s, iat: ${new Date(jwtClaims.iat * 1e3).toISOString()})`
123
+ );
124
+ }
125
+ }
126
+ }
127
+ function validateCriticalHeadersJWS(protectedHeader, requiredHeaders = []) {
128
+ if (!protectedHeader.crit) return;
129
+ const missingHeaderParams = /* @__PURE__ */ new Set();
130
+ const recognizedParams = /* @__PURE__ */ new Set([
131
+ ...requiredHeaders,
132
+ "alg",
133
+ "typ",
134
+ "cty",
135
+ "kid",
136
+ "jwk",
137
+ "jku",
138
+ "x5c",
139
+ "x5t",
140
+ "x5u",
141
+ "b64"
142
+ ]);
143
+ for (const param of protectedHeader.crit) {
144
+ if (recognizedParams.has(param) && (param in protectedHeader || param === "b64")) {
145
+ continue;
146
+ }
147
+ missingHeaderParams.add(param);
148
+ }
149
+ if (missingHeaderParams.size > 0) {
150
+ throw new Error(
151
+ `Missing critical header parameters: ${[...missingHeaderParams].join(", ")}`
152
+ );
153
+ }
154
+ }
155
+ function validateCriticalHeadersJWE(protectedHeader, understoodFromOptions) {
156
+ if (protectedHeader.crit && !understoodFromOptions) {
157
+ throw new Error(
158
+ `Unprocessed critical header parameters: ${protectedHeader.crit.join(", ")}`
159
+ );
160
+ }
161
+ if (!protectedHeader.crit) return;
162
+ const understoodParams = /* @__PURE__ */ new Set([
163
+ ...understoodFromOptions || [],
164
+ // JWE specific standard headers:
165
+ "alg",
166
+ "enc",
167
+ "typ",
168
+ "cty",
169
+ "kid",
170
+ "jwk",
171
+ "jku",
172
+ "x5c",
173
+ "x5t",
174
+ "x5u",
175
+ "iv",
176
+ "tag",
177
+ "p2s",
178
+ "p2c",
179
+ "epk",
180
+ "apu",
181
+ "apv"
182
+ ]);
183
+ for (const critParam of protectedHeader.crit) {
184
+ if (!Object.prototype.hasOwnProperty.call(protectedHeader, critParam)) {
185
+ throw new Error(
186
+ `Critical header parameter "${critParam}" listed in "crit" but not present in the protected header.`
187
+ );
188
+ }
189
+ if (!understoodParams.has(critParam)) {
190
+ throw new Error(`Unprocessed critical header parameters: ${critParam}`);
191
+ }
192
+ }
193
+ }
194
+
195
+ const textEncoder = /* @__PURE__ */ new TextEncoder();
196
+ const textDecoder = /* @__PURE__ */ new TextDecoder();
197
+ function base64Encode(data) {
198
+ const encodedData = data instanceof Uint8Array ? data : textEncoder.encode(data);
199
+ if (Uint8Array.prototype.toBase64) {
200
+ return encodedData.toBase64();
201
+ }
202
+ return btoa(String.fromCodePoint(...encodedData));
203
+ }
204
+ function base64UrlEncode(data) {
205
+ const encodedData = data instanceof Uint8Array ? data : textEncoder.encode(data);
206
+ if (Uint8Array.prototype.toBase64) {
207
+ return encodedData.toBase64({ alphabet: "base64url", omitPadding: true });
208
+ }
209
+ return btoa(String.fromCodePoint(...encodedData)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
210
+ }
211
+ function base64Decode(str, toString) {
212
+ const decodeToString = toString !== false;
213
+ if (!str) {
214
+ return decodeToString ? "" : new Uint8Array(0);
215
+ }
216
+ const data = Uint8Array.fromBase64 ? (
217
+ // @ts-expect-error
218
+ Uint8Array.fromBase64(str)
219
+ ) : Uint8Array.from(atob(str), (b) => b.codePointAt(0));
220
+ return decodeToString ? textDecoder.decode(data) : data;
221
+ }
222
+ function base64UrlDecode(str, toString) {
223
+ const decodeToString = toString !== false;
224
+ if (!str) {
225
+ return decodeToString ? "" : new Uint8Array(0);
226
+ }
227
+ let data;
228
+ if (Uint8Array.fromBase64) {
229
+ data = Uint8Array.fromBase64(str, { alphabet: "base64url" });
230
+ } else {
231
+ str = str.replace(/-/g, "+").replace(/_/g, "/");
232
+ while (str.length % 4) str += "=";
233
+ data = Uint8Array.from(atob(str), (b) => b.codePointAt(0));
234
+ }
235
+ return decodeToString ? textDecoder.decode(data) : data;
236
+ }
237
+ function randomBytes(length) {
238
+ return crypto.getRandomValues(new Uint8Array(length));
239
+ }
240
+ function concatUint8Arrays(...arrays) {
241
+ const totalLength = arrays.reduce((length, arr) => length + arr.length, 0);
242
+ const result = new Uint8Array(totalLength);
243
+ let offset = 0;
244
+ for (const arr of arrays) {
245
+ result.set(arr, offset);
246
+ offset += arr.length;
247
+ }
248
+ return result;
249
+ }
250
+ function maybeArray(item) {
251
+ return Array.isArray(item) ? item : [item];
252
+ }
253
+ function isJWK(key) {
254
+ return typeof key === "object" && key !== null && "kty" in key && typeof key.kty === "string";
255
+ }
256
+ function isJWKSet(key) {
257
+ return key && typeof key === "object" && "keys" in key && Array.isArray(key.keys);
258
+ }
259
+ function assertCryptoKey(key) {
260
+ if (!isCryptoKey(key)) {
261
+ throw new Error("CryptoKey instance expected");
262
+ }
263
+ }
264
+ function isCryptoKey(key) {
265
+ return key?.[Symbol.toStringTag] === "CryptoKey";
266
+ }
267
+ const isCryptoKeyPair = (key) => key && typeof key === "object" && isCryptoKey(key.publicKey) && isCryptoKey(key.privateKey);
268
+
269
+ const index = {
270
+ __proto__: null,
271
+ applyTypCtyDefaults: applyTypCtyDefaults,
272
+ assertCryptoKey: assertCryptoKey,
273
+ base64Decode: base64Decode,
274
+ base64Encode: base64Encode,
275
+ base64UrlDecode: base64UrlDecode,
276
+ base64UrlEncode: base64UrlEncode,
277
+ computeJwtTimeClaims: computeJwtTimeClaims,
278
+ concatUint8Arrays: concatUint8Arrays,
279
+ decodeMaybeJsonString: decodeMaybeJsonString,
280
+ decodePayloadFromB64UrlSegment: decodePayloadFromB64UrlSegment,
281
+ decodePayloadFromBytes: decodePayloadFromBytes,
282
+ getPlaintextBytes: getPlaintextBytes,
283
+ isCryptoKey: isCryptoKey,
284
+ isCryptoKeyPair: isCryptoKeyPair,
285
+ isJWK: isJWK,
286
+ isJWKSet: isJWKSet,
287
+ isJsonContent: isJsonContent,
288
+ maybeArray: maybeArray,
289
+ randomBytes: randomBytes,
290
+ textDecoder: textDecoder,
291
+ textEncoder: textEncoder,
292
+ validateCriticalHeadersJWE: validateCriticalHeadersJWE,
293
+ validateCriticalHeadersJWS: validateCriticalHeadersJWS,
294
+ validateJwtClaims: validateJwtClaims
295
+ };
296
+
297
+ 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, base64Encode as s, textEncoder as t, maybeArray as u, validateCriticalHeadersJWS as v, isCryptoKeyPair as w, isJsonContent as x, decodeMaybeJsonString as y };
package/dist/utils.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import './shared/unjwt.D9da8HQF.mjs';
2
- export { j as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, f as concatUint8Arrays, k as isCryptoKey, l as isCryptoKeyPair, g as isJWK, h as isJWKSet, m as maybeArray, r as randomBytes, a as textDecoder, t as textEncoder } from './shared/unjwt.CbvzYE-m.mjs';
1
+ import './shared/unjwt.CN1C8TlR.mjs';
2
+ export { n as applyTypCtyDefaults, j as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, v as computeJwtTimeClaims, f as concatUint8Arrays, p as decodeMaybeJsonString, s as decodePayloadFromB64UrlSegment, q as decodePayloadFromBytes, u as getPlaintextBytes, k as isCryptoKey, l as isCryptoKeyPair, g as isJWK, h as isJWKSet, o as isJsonContent, m as maybeArray, r as randomBytes, a as textDecoder, t as textEncoder, y as validateCriticalHeadersJWE, x as validateCriticalHeadersJWS, w as validateJwtClaims } from './shared/unjwt.CUUg6g3N.mjs';
package/dist/utils.mjs CHANGED
@@ -1 +1 @@
1
- export { g as assertCryptoKey, j as base64Decode, k as base64Encode, d as base64UrlDecode, b as base64UrlEncode, f as concatUint8Arrays, h as isCryptoKey, l as isCryptoKeyPair, a as isJWK, e as isJWKSet, m as maybeArray, r as randomBytes, c as textDecoder, t as textEncoder } from './shared/unjwt.BHpknTpg.mjs';
1
+ export { b as applyTypCtyDefaults, l as assertCryptoKey, q as base64Decode, s as base64Encode, f as base64UrlDecode, d as base64UrlEncode, c as computeJwtTimeClaims, k as concatUint8Arrays, y as decodeMaybeJsonString, h as decodePayloadFromB64UrlSegment, o as decodePayloadFromBytes, n as getPlaintextBytes, m as isCryptoKey, w as isCryptoKeyPair, a as isJWK, g as isJWKSet, x as isJsonContent, u as maybeArray, r as randomBytes, e as textDecoder, t as textEncoder, p as validateCriticalHeadersJWE, v as validateCriticalHeadersJWS, j as validateJwtClaims } from './shared/unjwt.odifuYKu.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unjwt",
3
- "version": "0.5.8",
3
+ "version": "0.5.10",
4
4
  "description": "Low-level JWT utilities",
5
5
  "repository": "sandros94/unjwt",
6
6
  "license": "MIT",
@@ -50,16 +50,17 @@
50
50
  "test:types": "tsc --noEmit --skipLibCheck"
51
51
  },
52
52
  "devDependencies": {
53
- "@types/node": "^22.13.13",
54
- "@vitest/coverage-v8": "^3.1.2",
53
+ "@types/node": "^22.13.14",
54
+ "@vitest/coverage-v8": "^3.2.4",
55
55
  "automd": "^0.4.0",
56
- "changelogen": "^0.6.1",
57
- "eslint": "^9.23.0",
58
- "eslint-config-unjs": "^0.4.2",
59
- "prettier": "^3.5.3",
60
- "typescript": "^5.8.2",
61
- "unbuild": "^3.5.0",
62
- "vitest": "^3.1.2"
56
+ "changelogen": "^0.6.2",
57
+ "eslint": "^9.34.0",
58
+ "eslint-config-unjs": "^0.5.0",
59
+ "jose": "^6.0.13",
60
+ "prettier": "^3.6.2",
61
+ "typescript": "^5.9.2",
62
+ "unbuild": "^3.6.1",
63
+ "vitest": "^3.2.4"
63
64
  },
64
- "packageManager": "pnpm@10.7.0"
65
+ "packageManager": "pnpm@10.15.0"
65
66
  }
package/dist/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, E as JWKAlgorithm, F as JWKPEMAlgorithm, J as JWKParameters, n as JWKSet, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, x as JWK_PBES2, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.D9da8HQF.js';
2
- export { b as JWT, a as JWTClaims, J as JoseHeaderParameters } from './shared/unjwt.c10n3uM8.js';
3
- 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.w-IAnI15.js';
4
- 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.CoSilGqk.js';
5
- export { i as utils } from './shared/unjwt.D4DUiNeM.js';
6
- export { j as jwk } from './shared/unjwt.CrcUJklb.js';
package/dist/jwe.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import './shared/unjwt.D9da8HQF.js';
2
- import './shared/unjwt.c10n3uM8.js';
3
- 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.CoSilGqk.js';
package/dist/jwk.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, E as JWKAlgorithm, F as JWKPEMAlgorithm, J as JWKParameters, n as JWKSet, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, x as JWK_PBES2, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.D9da8HQF.js';
2
- import './shared/unjwt.c10n3uM8.js';
3
- 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.CrcUJklb.js';
package/dist/jws.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import './shared/unjwt.D9da8HQF.js';
2
- import './shared/unjwt.c10n3uM8.js';
3
- 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.w-IAnI15.js';
@@ -1,93 +0,0 @@
1
- const textEncoder = /* @__PURE__ */ new TextEncoder();
2
- const textDecoder = /* @__PURE__ */ new TextDecoder();
3
- function base64Encode(data) {
4
- const encodedData = data instanceof Uint8Array ? data : textEncoder.encode(data);
5
- if (Uint8Array.prototype.toBase64) {
6
- return encodedData.toBase64();
7
- }
8
- return btoa(String.fromCodePoint(...encodedData));
9
- }
10
- function base64UrlEncode(data) {
11
- const encodedData = data instanceof Uint8Array ? data : textEncoder.encode(data);
12
- if (Uint8Array.prototype.toBase64) {
13
- return encodedData.toBase64({ alphabet: "base64url", omitPadding: true });
14
- }
15
- return btoa(String.fromCodePoint(...encodedData)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
16
- }
17
- function base64Decode(str, toString) {
18
- const decodeToString = toString !== false;
19
- if (!str) {
20
- return decodeToString ? "" : new Uint8Array(0);
21
- }
22
- const data = Uint8Array.fromBase64 ? (
23
- // @ts-expect-error
24
- Uint8Array.fromBase64(str)
25
- ) : Uint8Array.from(atob(str), (b) => b.codePointAt(0));
26
- return decodeToString ? textDecoder.decode(data) : data;
27
- }
28
- function base64UrlDecode(str, toString) {
29
- const decodeToString = toString !== false;
30
- if (!str) {
31
- return decodeToString ? "" : new Uint8Array(0);
32
- }
33
- let data;
34
- if (Uint8Array.fromBase64) {
35
- data = Uint8Array.fromBase64(str, { alphabet: "base64url" });
36
- } else {
37
- str = str.replace(/-/g, "+").replace(/_/g, "/");
38
- while (str.length % 4) str += "=";
39
- data = Uint8Array.from(atob(str), (b) => b.codePointAt(0));
40
- }
41
- return decodeToString ? textDecoder.decode(data) : data;
42
- }
43
- function randomBytes(length) {
44
- return crypto.getRandomValues(new Uint8Array(length));
45
- }
46
- function concatUint8Arrays(...arrays) {
47
- const totalLength = arrays.reduce((length, arr) => length + arr.length, 0);
48
- const result = new Uint8Array(totalLength);
49
- let offset = 0;
50
- for (const arr of arrays) {
51
- result.set(arr, offset);
52
- offset += arr.length;
53
- }
54
- return result;
55
- }
56
- function maybeArray(item) {
57
- return Array.isArray(item) ? item : [item];
58
- }
59
- function isJWK(key) {
60
- return typeof key === "object" && key !== null && "kty" in key && typeof key.kty === "string";
61
- }
62
- function isJWKSet(key) {
63
- return key && typeof key === "object" && "keys" in key && Array.isArray(key.keys);
64
- }
65
- function assertCryptoKey(key) {
66
- if (!isCryptoKey(key)) {
67
- throw new Error("CryptoKey instance expected");
68
- }
69
- }
70
- function isCryptoKey(key) {
71
- return key?.[Symbol.toStringTag] === "CryptoKey";
72
- }
73
- const isCryptoKeyPair = (key) => key && typeof key === "object" && isCryptoKey(key.publicKey) && isCryptoKey(key.privateKey);
74
-
75
- const index = {
76
- __proto__: null,
77
- assertCryptoKey: assertCryptoKey,
78
- base64Decode: base64Decode,
79
- base64Encode: base64Encode,
80
- base64UrlDecode: base64UrlDecode,
81
- base64UrlEncode: base64UrlEncode,
82
- concatUint8Arrays: concatUint8Arrays,
83
- isCryptoKey: isCryptoKey,
84
- isCryptoKeyPair: isCryptoKeyPair,
85
- isJWK: isJWK,
86
- isJWKSet: isJWKSet,
87
- maybeArray: maybeArray,
88
- randomBytes: randomBytes,
89
- textDecoder: textDecoder,
90
- textEncoder: textEncoder
91
- };
92
-
93
- export { isJWK as a, base64UrlEncode as b, textDecoder as c, base64UrlDecode as d, isJWKSet as e, concatUint8Arrays as f, assertCryptoKey as g, isCryptoKey as h, index as i, base64Decode as j, base64Encode as k, isCryptoKeyPair as l, maybeArray as m, randomBytes as r, textEncoder as t };