unjwt 0.5.9 → 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.
- package/dist/index.d.mts +5 -6
- package/dist/index.mjs +5 -5
- package/dist/jwe.d.mts +2 -3
- package/dist/jwe.mjs +4 -4
- package/dist/jwk.d.mts +2 -3
- package/dist/jwk.mjs +2 -2
- package/dist/jws.d.mts +2 -3
- package/dist/jws.mjs +4 -4
- package/dist/shared/unjwt.B1dfkZSt.mjs +161 -0
- package/dist/shared/{unjwt.DRUXIabl.mjs → unjwt.BrOta13J.mjs} +19 -8
- package/dist/shared/{unjwt.Ca03jPX3.mjs → unjwt.CEjyBwhK.mjs} +1 -1
- package/dist/shared/{unjwt.D9da8HQF.d.mts → unjwt.CN1C8TlR.d.mts} +90 -15
- package/dist/shared/unjwt.CUUg6g3N.d.mts +128 -0
- package/dist/shared/{unjwt.DH1p_WL8.d.mts → unjwt.Cz90HQhy.d.mts} +11 -12
- package/dist/shared/{unjwt.B2olxeGL.mjs → unjwt.D0WA_yog.mjs} +22 -86
- package/dist/shared/{unjwt.8w7jp2aw.d.mts → unjwt.Dof5OLMV.d.mts} +28 -30
- package/dist/shared/{unjwt.D_Mabhgz.d.mts → unjwt.igKyF5q2.d.mts} +13 -69
- package/dist/shared/unjwt.odifuYKu.mjs +297 -0
- package/dist/utils.d.mts +2 -2
- package/dist/utils.mjs +1 -1
- package/package.json +12 -11
- package/dist/shared/unjwt.BHpknTpg.mjs +0 -93
- package/dist/shared/unjwt.BvIkEGGz.d.mts +0 -52
- package/dist/shared/unjwt.CbvzYE-m.d.mts +0 -58
- package/dist/shared/unjwt.wHjOCapq.mjs +0 -279
|
@@ -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.
|
|
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.
|
|
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 {
|
|
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.
|
|
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.
|
|
54
|
-
"@vitest/coverage-v8": "^3.
|
|
53
|
+
"@types/node": "^22.13.14",
|
|
54
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
55
55
|
"automd": "^0.4.0",
|
|
56
|
-
"changelogen": "^0.6.
|
|
57
|
-
"eslint": "^9.
|
|
58
|
-
"eslint-config-unjs": "^0.
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
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.
|
|
65
|
+
"packageManager": "pnpm@10.15.0"
|
|
65
66
|
}
|
|
@@ -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 };
|
|
@@ -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 };
|