unjwt 0.8.2 → 0.8.4
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/_chunks/_codec-jwe.d.mts +24 -28
- package/dist/_chunks/_codec-jws.mjs +33 -33
- package/dist/_chunks/{jwk.mjs → _import-key.mjs} +36 -741
- package/dist/_chunks/_jwt-internal.mjs +28 -25
- package/dist/_chunks/index.d.mts +5 -3
- package/dist/_chunks/jwe.d.mts +1 -0
- package/dist/_chunks/jwe.mjs +8 -7
- package/dist/_chunks/jwk.d.mts +205 -0
- package/dist/_chunks/jws.d.mts +4 -1
- package/dist/_chunks/jws.mjs +10 -10
- package/dist/_chunks/jwt.d.mts +2 -1
- package/dist/_chunks/libs/unsecure.mjs +143 -130
- package/dist/adapters/elysia/index.d.mts +1 -1
- package/dist/adapters/elysia/index.mjs +3 -2
- package/dist/adapters/h3/index.d.mts +1 -1
- package/dist/adapters/h3/index.mjs +2 -1
- package/dist/adapters/h3v1/index.d.mts +1 -1
- package/dist/adapters/h3v1/index.mjs +2 -1
- package/dist/core/jwe.mjs +1 -1
- package/dist/core/jwk.d.mts +2 -204
- package/dist/core/jwk.mjs +712 -3
- package/dist/core/jws.mjs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -1
- package/dist/session/index.d.mts +22 -22
- package/dist/session/index.mjs +22 -19
- package/package.json +3 -2
|
@@ -26,7 +26,16 @@ const _fatalDecoder = /* @__PURE__ */ new TextDecoder("utf-8", {
|
|
|
26
26
|
fatal: true
|
|
27
27
|
});
|
|
28
28
|
/* @__NO_SIDE_EFFECTS__ */
|
|
29
|
-
function
|
|
29
|
+
function honoursViews(encode, expected) {
|
|
30
|
+
try {
|
|
31
|
+
return encode(Uint8Array.of(0, 1, 2, 3).subarray(1, 3)) === expected;
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
37
|
+
function wholeBuffer(bytes, honoured) {
|
|
38
|
+
if (honoured) return bytes;
|
|
30
39
|
return bytes.byteOffset === 0 && bytes.byteLength === bytes.buffer.byteLength ? bytes : bytes.slice();
|
|
31
40
|
}
|
|
32
41
|
const _LATIN1_CHUNK = 32768;
|
|
@@ -37,15 +46,15 @@ function _latin1(bytes) {
|
|
|
37
46
|
for (let i = 0; i < bytes.length; i += _LATIN1_CHUNK) text += String.fromCharCode(...bytes.subarray(i, i + _LATIN1_CHUNK));
|
|
38
47
|
return text;
|
|
39
48
|
}
|
|
40
|
-
function
|
|
41
|
-
if (typeof input !== "string" && !/* @__PURE__ */ _isBytes(input)) throw new UnsecureError("INVALID_TYPE", `${
|
|
49
|
+
function assertData(input, source) {
|
|
50
|
+
if (typeof input !== "string" && !/* @__PURE__ */ _isBytes(input)) throw new UnsecureError("INVALID_TYPE", `${source}: expected a string or Uint8Array, got ${/* @__PURE__ */ describeValue(input)}.`);
|
|
42
51
|
}
|
|
43
52
|
/* @__NO_SIDE_EFFECTS__ */
|
|
44
53
|
function _isBytes(input) {
|
|
45
54
|
return ArrayBuffer.isView(input) && input instanceof Uint8Array;
|
|
46
55
|
}
|
|
47
56
|
/* @__NO_SIDE_EFFECTS__ */
|
|
48
|
-
function
|
|
57
|
+
function parsePrep(input, options) {
|
|
49
58
|
const isBytes = /* @__PURE__ */ _isBytes(input);
|
|
50
59
|
const returnAs = options?.returnAs ?? (isBytes ? "uint8array" : "string");
|
|
51
60
|
return {
|
|
@@ -54,47 +63,47 @@ function _parsePrep(input, options) {
|
|
|
54
63
|
};
|
|
55
64
|
}
|
|
56
65
|
/* @__NO_SIDE_EFFECTS__ */
|
|
57
|
-
function
|
|
66
|
+
function parseFinalize(bytes, wantString, strict, source) {
|
|
58
67
|
if (!wantString) return bytes;
|
|
59
68
|
if (!strict) return textDecoder.decode(bytes);
|
|
60
69
|
try {
|
|
61
70
|
return _fatalDecoder.decode(bytes);
|
|
62
71
|
} catch {
|
|
63
|
-
throw /* @__PURE__ */
|
|
72
|
+
throw /* @__PURE__ */ malformed("decoded bytes are not valid UTF-8.", source);
|
|
64
73
|
}
|
|
65
74
|
}
|
|
66
75
|
/* @__NO_SIDE_EFFECTS__ */
|
|
67
|
-
function
|
|
68
|
-
return new UnsecureError("MALFORMED", `${
|
|
76
|
+
function malformed(detail, source) {
|
|
77
|
+
return new UnsecureError("MALFORMED", `${source}: ${detail}`);
|
|
69
78
|
}
|
|
70
79
|
/* @__NO_SIDE_EFFECTS__ */
|
|
71
|
-
function
|
|
80
|
+
function tailBits(rem, bits) {
|
|
72
81
|
if (rem === 0) return 0;
|
|
73
82
|
const leftover = rem * bits % 8;
|
|
74
83
|
return leftover >= bits ? -1 : leftover;
|
|
75
84
|
}
|
|
76
85
|
/* @__NO_SIDE_EFFECTS__ */
|
|
77
|
-
function
|
|
86
|
+
function strictBody(text, table, shape, source, padding) {
|
|
78
87
|
let end = text.length;
|
|
79
88
|
while (end > 0 && text.charCodeAt(end - 1) === 61) end--;
|
|
80
89
|
const padFound = text.length - end;
|
|
81
90
|
for (let i = 0; i < end; i++) {
|
|
82
91
|
const c = text.charCodeAt(i);
|
|
83
|
-
if ((c < 128 ? table[c] : -1) < 0) throw /* @__PURE__ */
|
|
92
|
+
if ((c < 128 ? table[c] : -1) < 0) throw /* @__PURE__ */ malformed(`invalid ${shape.name} character ${JSON.stringify(text[i])} at index ${i}.`, source);
|
|
84
93
|
}
|
|
85
94
|
const rem = end % shape.group;
|
|
86
|
-
const tail = /* @__PURE__ */
|
|
87
|
-
if (tail < 0) throw /* @__PURE__ */
|
|
95
|
+
const tail = /* @__PURE__ */ tailBits(rem, shape.bits);
|
|
96
|
+
if (tail < 0) throw /* @__PURE__ */ malformed(`${end} ${shape.name} symbols cannot encode whole bytes.`, source);
|
|
88
97
|
const padNeeded = rem === 0 ? 0 : shape.group - rem;
|
|
89
98
|
if (padFound > 0) {
|
|
90
|
-
if (padNeeded === 0 || padding === false) throw /* @__PURE__ */
|
|
91
|
-
if (padFound !== padNeeded) throw /* @__PURE__ */
|
|
92
|
-
} else if (padding === true && padNeeded > 0) throw /* @__PURE__ */
|
|
93
|
-
if (tail > 0 && (table[text.charCodeAt(end - 1)] & (1 << tail) - 1) !== 0) throw /* @__PURE__ */
|
|
99
|
+
if (padNeeded === 0 || padding === false) throw /* @__PURE__ */ malformed(`unexpected "=" padding.`, source);
|
|
100
|
+
if (padFound !== padNeeded) throw /* @__PURE__ */ malformed(`expected ${padNeeded} "=" padding characters, found ${padFound}.`, source);
|
|
101
|
+
} else if (padding === true && padNeeded > 0) throw /* @__PURE__ */ malformed(`expected ${padNeeded} "=" padding characters, found 0.`, source);
|
|
102
|
+
if (tail > 0 && (table[text.charCodeAt(end - 1)] & (1 << tail) - 1) !== 0) throw /* @__PURE__ */ malformed(`the last ${shape.name} symbol sets bits past the final byte.`, source);
|
|
94
103
|
return end === text.length ? text : text.slice(0, end);
|
|
95
104
|
}
|
|
96
105
|
/* @__NO_SIDE_EFFECTS__ */
|
|
97
|
-
function
|
|
106
|
+
function symbols(text, table) {
|
|
98
107
|
const values = new Uint8Array(text.length);
|
|
99
108
|
let n = 0;
|
|
100
109
|
for (let i = 0; i < text.length; i++) {
|
|
@@ -105,13 +114,13 @@ function _symbols(text, table) {
|
|
|
105
114
|
return n === values.length ? values : values.subarray(0, n);
|
|
106
115
|
}
|
|
107
116
|
/* @__NO_SIDE_EFFECTS__ */
|
|
108
|
-
function
|
|
117
|
+
function looseCount(n, shape) {
|
|
109
118
|
let count = n;
|
|
110
|
-
while (count > 0 && /* @__PURE__ */
|
|
119
|
+
while (count > 0 && /* @__PURE__ */ tailBits(count % shape.group, shape.bits) < 0) count--;
|
|
111
120
|
return count;
|
|
112
121
|
}
|
|
113
122
|
/* @__NO_SIDE_EFFECTS__ */
|
|
114
|
-
function
|
|
123
|
+
function decodeSymbols(values, count, bits) {
|
|
115
124
|
const out = new Uint8Array(count * bits >>> 3);
|
|
116
125
|
let acc = 0;
|
|
117
126
|
let held = 0;
|
|
@@ -127,38 +136,43 @@ function _decodeSymbols(values, count, bits) {
|
|
|
127
136
|
return out;
|
|
128
137
|
}
|
|
129
138
|
const _ON_HEAP_MAX = 64;
|
|
130
|
-
const
|
|
139
|
+
const nodeBuffer = /* @__PURE__ */ (() => {
|
|
131
140
|
try {
|
|
132
141
|
return globalThis.Buffer;
|
|
133
142
|
} catch {
|
|
134
143
|
return;
|
|
135
144
|
}
|
|
136
145
|
})();
|
|
137
|
-
const
|
|
146
|
+
const hasBuffer = /* @__PURE__ */ (() => typeof nodeBuffer?.from === "function")();
|
|
138
147
|
/* @__NO_SIDE_EFFECTS__ */
|
|
139
|
-
function
|
|
140
|
-
return bytes.byteLength <= _ON_HEAP_MAX ?
|
|
148
|
+
function toBuffer(bytes) {
|
|
149
|
+
return bytes.byteLength <= _ON_HEAP_MAX ? nodeBuffer.from(bytes) : nodeBuffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
150
|
+
}
|
|
151
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
152
|
+
function preferBuffer(byteLength, native) {
|
|
153
|
+
return hasBuffer && !(native && byteLength <= _ON_HEAP_MAX);
|
|
141
154
|
}
|
|
142
155
|
const _nativeToBase64 = /* @__PURE__ */ (() => typeof Uint8Array.prototype.toBase64 === "function")();
|
|
143
156
|
const _nativeFromBase64 = /* @__PURE__ */ (() => typeof Uint8Array.fromBase64 === "function")();
|
|
144
|
-
const
|
|
157
|
+
const _base64Views = /* @__PURE__ */ (() => !_nativeToBase64 || /* @__PURE__ */ honoursViews((view) => view.toBase64(), "AQI="))();
|
|
158
|
+
const _SHAPE = {
|
|
145
159
|
bits: 6,
|
|
146
160
|
group: 4,
|
|
147
161
|
name: "base64"
|
|
148
162
|
};
|
|
149
|
-
const
|
|
163
|
+
const _DIGITS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
150
164
|
/* @__NO_SIDE_EFFECTS__ */
|
|
151
|
-
function
|
|
165
|
+
function _table(pairs) {
|
|
152
166
|
const t = (/* @__PURE__ */ new Int16Array(128)).fill(-1);
|
|
153
|
-
for (let i = 0; i < 62; i++) t[
|
|
167
|
+
for (let i = 0; i < 62; i++) t[_DIGITS.charCodeAt(i)] = i;
|
|
154
168
|
for (let i = 0; i < pairs.length; i += 2) {
|
|
155
169
|
t[pairs.charCodeAt(i)] = 62;
|
|
156
170
|
t[pairs.charCodeAt(i + 1)] = 63;
|
|
157
171
|
}
|
|
158
172
|
return t;
|
|
159
173
|
}
|
|
160
|
-
const
|
|
161
|
-
const
|
|
174
|
+
const _TABLE_STD = /* @__PURE__ */ _table("+/");
|
|
175
|
+
const _TABLE_URL = /* @__PURE__ */ _table("-_");
|
|
162
176
|
/* @__NO_SIDE_EFFECTS__ */
|
|
163
177
|
function _unpad(s) {
|
|
164
178
|
let end = s.length;
|
|
@@ -171,14 +185,16 @@ function _padTo4(s) {
|
|
|
171
185
|
return rem === 0 ? s : s + "=".repeat(4 - rem);
|
|
172
186
|
}
|
|
173
187
|
/* @__NO_SIDE_EFFECTS__ */
|
|
174
|
-
function
|
|
188
|
+
function base64StringifyBytes(bytes, options = {}) {
|
|
189
|
+
const alphabet = options.alphabet ?? "base64";
|
|
190
|
+
const padding = options.padding ?? alphabet !== "base64url";
|
|
175
191
|
const url = alphabet === "base64url";
|
|
176
|
-
if (
|
|
177
|
-
const s = (/* @__PURE__ */
|
|
192
|
+
if (/* @__PURE__ */ preferBuffer(bytes.length, _nativeToBase64)) {
|
|
193
|
+
const s = (/* @__PURE__ */ toBuffer(bytes)).toString(url ? "base64url" : "base64");
|
|
178
194
|
if (url) return padding ? /* @__PURE__ */ _padTo4(s) : s;
|
|
179
195
|
return padding ? s : /* @__PURE__ */ _unpad(s);
|
|
180
196
|
}
|
|
181
|
-
if (_nativeToBase64) return (/* @__PURE__ */
|
|
197
|
+
if (_nativeToBase64) return (/* @__PURE__ */ wholeBuffer(bytes, _base64Views)).toBase64({
|
|
182
198
|
alphabet,
|
|
183
199
|
omitPadding: !padding
|
|
184
200
|
});
|
|
@@ -189,115 +205,36 @@ function _encodeBase64(bytes, alphabet, padding) {
|
|
|
189
205
|
return padding ? s : /* @__PURE__ */ _unpad(s);
|
|
190
206
|
}
|
|
191
207
|
/* @__NO_SIDE_EFFECTS__ */
|
|
192
|
-
function
|
|
193
|
-
|
|
194
|
-
if (_nativeFromBase64) return Uint8Array.fromBase64(padded);
|
|
195
|
-
return /* @__PURE__ */ _decodeSymbols(/* @__PURE__ */ _symbols(padded, _B64_TABLE_STD), symbols, 6);
|
|
196
|
-
}
|
|
197
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
198
|
-
function _decodeBase64(text, alphabet, loose, label, padding) {
|
|
199
|
-
const url = alphabet === "base64url";
|
|
208
|
+
function base64ParseText(text, source, options = {}) {
|
|
209
|
+
const url = (options.alphabet ?? "base64") === "base64url";
|
|
200
210
|
let body;
|
|
201
|
-
if (loose) {
|
|
211
|
+
if (options.loose) {
|
|
202
212
|
const clean = text.replace(/-/g, "+").replace(/_/g, "/").replace(/[^A-Za-z0-9+/]/g, "");
|
|
203
|
-
body = clean.slice(0, /* @__PURE__ */
|
|
213
|
+
body = clean.slice(0, /* @__PURE__ */ looseCount(clean.length, _SHAPE));
|
|
204
214
|
} else {
|
|
205
|
-
const strict = /* @__PURE__ */
|
|
215
|
+
const strict = /* @__PURE__ */ strictBody(text, url ? _TABLE_URL : _TABLE_STD, _SHAPE, source, options.padding);
|
|
206
216
|
body = url ? strict.replace(/-/g, "+").replace(/_/g, "/") : strict;
|
|
207
217
|
}
|
|
208
218
|
const rem = body.length % 4;
|
|
209
|
-
return /* @__PURE__ */
|
|
219
|
+
return /* @__PURE__ */ _bulk$1(rem === 0 ? body : body + (rem === 2 ? "==" : "="), body.length);
|
|
220
|
+
}
|
|
221
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
222
|
+
function _bulk$1(padded, count) {
|
|
223
|
+
if (/* @__PURE__ */ preferBuffer(count * 6 >>> 3, _nativeFromBase64)) return new Uint8Array(nodeBuffer.from(padded, "base64"));
|
|
224
|
+
if (_nativeFromBase64) return Uint8Array.fromBase64(padded);
|
|
225
|
+
return /* @__PURE__ */ decodeSymbols(/* @__PURE__ */ symbols(padded, _TABLE_STD), count, 6);
|
|
210
226
|
}
|
|
211
227
|
/* @__NO_SIDE_EFFECTS__ */
|
|
212
228
|
function base64Stringify(data, options) {
|
|
213
|
-
|
|
214
|
-
const padding = options?.padding ?? alphabet !== "base64url";
|
|
215
|
-
return /* @__PURE__ */ _encodeBase64(/* @__PURE__ */ toBytes(data, "Base64.stringify"), alphabet, padding);
|
|
229
|
+
return /* @__PURE__ */ base64StringifyBytes(/* @__PURE__ */ toBytes(data, "Base64.stringify"), options);
|
|
216
230
|
}
|
|
217
231
|
/* @__NO_SIDE_EFFECTS__ */
|
|
218
232
|
function base64Parse(input, options) {
|
|
219
|
-
|
|
220
|
-
const { text, wantString } = /* @__PURE__ */
|
|
233
|
+
assertData(input, "Base64.parse");
|
|
234
|
+
const { text, wantString } = /* @__PURE__ */ parsePrep(input, options);
|
|
221
235
|
if (!text) return wantString ? "" : /* @__PURE__ */ new Uint8Array(0);
|
|
222
|
-
const alphabet = options?.alphabet ?? "base64";
|
|
223
236
|
const loose = options?.loose ?? false;
|
|
224
|
-
return /* @__PURE__ */
|
|
225
|
-
}
|
|
226
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
227
|
-
function showValue(value) {
|
|
228
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
229
|
-
if (typeof value === "string") return JSON.stringify(value);
|
|
230
|
-
return /* @__PURE__ */ describeValue(value);
|
|
231
|
-
}
|
|
232
|
-
function assertInteger(source, name, value, min, max = Number.MAX_SAFE_INTEGER) {
|
|
233
|
-
if (Number.isSafeInteger(value) && value >= min && value <= max) return;
|
|
234
|
-
throw new UnsecureError("OUT_OF_RANGE", `${source}: ${name} must be ${max === Number.MAX_SAFE_INTEGER ? `an integer >= ${min}` : `an integer between ${min} and ${max}`}, got ${/* @__PURE__ */ showValue(value)}.`);
|
|
235
|
-
}
|
|
236
|
-
const SHARED_POOL_BYTES = 4096;
|
|
237
|
-
const _MAX_FILL = 65536;
|
|
238
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
239
|
-
function createEntropyPool(size) {
|
|
240
|
-
let bytes;
|
|
241
|
-
let words;
|
|
242
|
-
let offset = size;
|
|
243
|
-
function refill() {
|
|
244
|
-
if (bytes === void 0) {
|
|
245
|
-
const buffer = new ArrayBuffer(size);
|
|
246
|
-
bytes = new Uint8Array(buffer);
|
|
247
|
-
words = new Uint32Array(buffer);
|
|
248
|
-
}
|
|
249
|
-
crypto.getRandomValues(bytes);
|
|
250
|
-
offset = 0;
|
|
251
|
-
}
|
|
252
|
-
function nextUint32() {
|
|
253
|
-
offset = offset + 3 & -4;
|
|
254
|
-
if (offset >= size) refill();
|
|
255
|
-
const value = words[offset >>> 2];
|
|
256
|
-
offset += 4;
|
|
257
|
-
return value;
|
|
258
|
-
}
|
|
259
|
-
function fill(target) {
|
|
260
|
-
const length = target.length;
|
|
261
|
-
if (length === 0) return target;
|
|
262
|
-
if (length > 64) {
|
|
263
|
-
if (length <= _MAX_FILL) crypto.getRandomValues(target);
|
|
264
|
-
else for (let start = 0; start < length; start += _MAX_FILL) crypto.getRandomValues(target.subarray(start, Math.min(start + _MAX_FILL, length)));
|
|
265
|
-
return target;
|
|
266
|
-
}
|
|
267
|
-
if (offset + length > size) refill();
|
|
268
|
-
const slot = bytes.subarray(offset, offset + length);
|
|
269
|
-
target.set(slot);
|
|
270
|
-
slot.fill(0);
|
|
271
|
-
offset += length;
|
|
272
|
-
return target;
|
|
273
|
-
}
|
|
274
|
-
function reset(now = false) {
|
|
275
|
-
bytes?.fill(0);
|
|
276
|
-
bytes = words = void 0;
|
|
277
|
-
offset = size;
|
|
278
|
-
if (now) refill();
|
|
279
|
-
}
|
|
280
|
-
_onSnapshotRestore(reset);
|
|
281
|
-
return {
|
|
282
|
-
nextUint32,
|
|
283
|
-
fill,
|
|
284
|
-
reset
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
const sharedPool = /* @__PURE__ */ createEntropyPool(SHARED_POOL_BYTES);
|
|
288
|
-
function _onSnapshotRestore(callback) {
|
|
289
|
-
try {
|
|
290
|
-
const proc = globalThis.process;
|
|
291
|
-
if (typeof proc?.getBuiltinModule !== "function") return;
|
|
292
|
-
const snapshot = proc.getBuiltinModule("node:v8")?.startupSnapshot;
|
|
293
|
-
if (snapshot?.isBuildingSnapshot()) snapshot.addDeserializeCallback(callback);
|
|
294
|
-
} catch {}
|
|
295
|
-
}
|
|
296
|
-
const MAX_RANDOM_BYTES = 2 ** 31 - 1;
|
|
297
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
298
|
-
function secureRandomBytes(length) {
|
|
299
|
-
assertInteger("secureRandomBytes", "length", length, 0, MAX_RANDOM_BYTES);
|
|
300
|
-
return sharedPool.fill(new Uint8Array(length));
|
|
237
|
+
return /* @__PURE__ */ parseFinalize(/* @__PURE__ */ base64ParseText(text, "Base64.parse", options), wantString, !loose, "Base64.parse");
|
|
301
238
|
}
|
|
302
239
|
/* @__NO_SIDE_EFFECTS__ */
|
|
303
240
|
function safeJsonParse(json) {
|
|
@@ -413,4 +350,80 @@ function _copyValue(value, seen, stack) {
|
|
|
413
350
|
});
|
|
414
351
|
return target;
|
|
415
352
|
}
|
|
353
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
354
|
+
function showValue(value) {
|
|
355
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
356
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
357
|
+
return /* @__PURE__ */ describeValue(value);
|
|
358
|
+
}
|
|
359
|
+
function assertInteger(value, name, source, min, max = Number.MAX_SAFE_INTEGER) {
|
|
360
|
+
if (Number.isSafeInteger(value) && value >= min && value <= max) return;
|
|
361
|
+
throw new UnsecureError("OUT_OF_RANGE", `${source}: ${name} must be ${max === Number.MAX_SAFE_INTEGER ? `an integer >= ${min}` : `an integer between ${min} and ${max}`}, got ${/* @__PURE__ */ showValue(value)}.`);
|
|
362
|
+
}
|
|
363
|
+
const SHARED_POOL_BYTES = 4096;
|
|
364
|
+
const _MAX_FILL = 65536;
|
|
365
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
366
|
+
function createEntropyPool(size) {
|
|
367
|
+
let bytes;
|
|
368
|
+
let words;
|
|
369
|
+
let offset = size;
|
|
370
|
+
function refill() {
|
|
371
|
+
if (bytes === void 0) {
|
|
372
|
+
const buffer = new ArrayBuffer(size);
|
|
373
|
+
bytes = new Uint8Array(buffer);
|
|
374
|
+
words = new Uint32Array(buffer);
|
|
375
|
+
}
|
|
376
|
+
crypto.getRandomValues(bytes);
|
|
377
|
+
offset = 0;
|
|
378
|
+
}
|
|
379
|
+
function nextUint32() {
|
|
380
|
+
offset = offset + 3 & -4;
|
|
381
|
+
if (offset >= size) refill();
|
|
382
|
+
const value = words[offset >>> 2];
|
|
383
|
+
offset += 4;
|
|
384
|
+
return value;
|
|
385
|
+
}
|
|
386
|
+
function fill(target) {
|
|
387
|
+
const length = target.length;
|
|
388
|
+
if (length === 0) return target;
|
|
389
|
+
if (length > 64) {
|
|
390
|
+
if (length <= _MAX_FILL) crypto.getRandomValues(target);
|
|
391
|
+
else for (let start = 0; start < length; start += _MAX_FILL) crypto.getRandomValues(target.subarray(start, Math.min(start + _MAX_FILL, length)));
|
|
392
|
+
return target;
|
|
393
|
+
}
|
|
394
|
+
if (offset + length > size) refill();
|
|
395
|
+
const slot = bytes.subarray(offset, offset + length);
|
|
396
|
+
target.set(slot);
|
|
397
|
+
slot.fill(0);
|
|
398
|
+
offset += length;
|
|
399
|
+
return target;
|
|
400
|
+
}
|
|
401
|
+
function reset(now = false) {
|
|
402
|
+
bytes?.fill(0);
|
|
403
|
+
bytes = words = void 0;
|
|
404
|
+
offset = size;
|
|
405
|
+
if (now) refill();
|
|
406
|
+
}
|
|
407
|
+
_onSnapshotRestore(reset);
|
|
408
|
+
return {
|
|
409
|
+
nextUint32,
|
|
410
|
+
fill,
|
|
411
|
+
reset
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
const sharedPool = /* @__PURE__ */ createEntropyPool(SHARED_POOL_BYTES);
|
|
415
|
+
function _onSnapshotRestore(callback) {
|
|
416
|
+
try {
|
|
417
|
+
const proc = globalThis.process;
|
|
418
|
+
if (typeof proc?.getBuiltinModule !== "function") return;
|
|
419
|
+
const snapshot = proc.getBuiltinModule("node:v8")?.startupSnapshot;
|
|
420
|
+
if (snapshot?.isBuildingSnapshot()) snapshot.addDeserializeCallback(callback);
|
|
421
|
+
} catch {}
|
|
422
|
+
}
|
|
423
|
+
const MAX_RANDOM_BYTES = 2 ** 31 - 1;
|
|
424
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
425
|
+
function secureRandomBytes(length) {
|
|
426
|
+
assertInteger(length, "length", "secureRandomBytes", 0, MAX_RANDOM_BYTES);
|
|
427
|
+
return sharedPool.fill(new Uint8Array(length));
|
|
428
|
+
}
|
|
416
429
|
export { UnsecureError, base64Parse, base64Stringify, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder };
|
|
@@ -2,7 +2,7 @@ import { JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, O
|
|
|
2
2
|
import { CookieAttributes } from "../../_chunks/_cookie-attributes.mjs";
|
|
3
3
|
import { CompositeKey, ContentEncryptionAlgorithm, DeriveJWKOptions, DeriveJWKReturn, DeriveKeyOptions, DeriveKeyReturn, Duration, ECDHEphemeralKeyInput, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, ImportedPEMJWK, JOSEConsumerOptions, JOSELimits, JOSEPayload, JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyLookup, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_Algorithm, JWK_AES_CBC_HMAC, JWK_AES_GCM, JWK_AES_GCM_KW, JWK_AES_KW, JWK_Asymmetric, JWK_Asymmetric_Algorithm, JWK_EC, JWK_ECDH_ES, JWK_ECDSA, JWK_EC_Private, JWK_EC_Public, JWK_HMAC, JWK_OKP, JWK_OKP_Private, JWK_OKP_Public, JWK_OKP_SIGN, JWK_PBES2, JWK_Pair, JWK_Private, JWK_Public, JWK_RSA, JWK_RSA_ENC, JWK_RSA_PSS, JWK_RSA_Private, JWK_RSA_Public, JWK_RSA_SIGN, JWK_Symmetric, JWK_Symmetric_Algorithm, JWK_oct, JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHashedAlgorithm, JWSHeaderParameters, JWSKeyLookup, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JWTConfirmation, JWTTimeClaimOptions, JoseHeaderParameters, KeyManagementAlgorithm, KeyWrapAlgorithmOf, KeyWrappingAlgorithm, MaxTokenAge, NotBeforeIn, PEMType, PayloadOf, ToPublicJWKReturn, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor } from "../../_chunks/index.mjs";
|
|
4
4
|
import { thumbprint } from "../../_chunks/index2.mjs";
|
|
5
|
-
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../../
|
|
5
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../../_chunks/jwk.mjs";
|
|
6
6
|
import { Elysia } from "elysia";
|
|
7
7
|
interface ChunkableCookie {
|
|
8
8
|
value: unknown;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { thumbprint } from "../../_chunks/_import-key.mjs";
|
|
2
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../../core/jwk.mjs";
|
|
2
3
|
import { createJWECodec, createJWSCodec, defineSession, invalidConfigError } from "../../_chunks/_codec-jws.mjs";
|
|
3
4
|
import { Elysia } from "elysia";
|
|
4
5
|
function sessionPlugin(options) {
|
|
@@ -39,7 +40,7 @@ function reactiveCookieJar(jar) {
|
|
|
39
40
|
}
|
|
40
41
|
function reactiveCookie(jar, name) {
|
|
41
42
|
const cookie = jar[name];
|
|
42
|
-
if (!cookie || typeof cookie.set !== "function") throw invalidConfigError(`${PREFIX$1} Session cookie jar
|
|
43
|
+
if (!cookie || typeof cookie.set !== "function") throw invalidConfigError(`${PREFIX$1} Session cookie jar has no reactive cookie at "${name}", pass Elysia's \`cookie\`.`);
|
|
43
44
|
return cookie;
|
|
44
45
|
}
|
|
45
46
|
const PREFIX = "[unjwt/elysia]";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, OpenedSessionState, SessionClaims, SessionData, SessionDecryptOptions, SessionDefinition, SessionEncryptOptions, SessionIssueOptions, SessionManager, SessionRecord, SessionSignOptions, SessionState, SessionUpdate, SessionUpdateTrigger, SessionVerifyOptions } from "../../_chunks/_codec-jwe.mjs";
|
|
2
2
|
import { CompositeKey, ContentEncryptionAlgorithm, DeriveJWKOptions, DeriveJWKReturn, DeriveKeyOptions, DeriveKeyReturn, Duration, ECDHEphemeralKeyInput, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, ImportedPEMJWK, JOSEConsumerOptions, JOSELimits, JOSEPayload, JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyLookup, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_Algorithm, JWK_AES_CBC_HMAC, JWK_AES_GCM, JWK_AES_GCM_KW, JWK_AES_KW, JWK_Asymmetric, JWK_Asymmetric_Algorithm, JWK_EC, JWK_ECDH_ES, JWK_ECDSA, JWK_EC_Private, JWK_EC_Public, JWK_HMAC, JWK_OKP, JWK_OKP_Private, JWK_OKP_Public, JWK_OKP_SIGN, JWK_PBES2, JWK_Pair, JWK_Private, JWK_Public, JWK_RSA, JWK_RSA_ENC, JWK_RSA_PSS, JWK_RSA_Private, JWK_RSA_Public, JWK_RSA_SIGN, JWK_Symmetric, JWK_Symmetric_Algorithm, JWK_oct, JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHashedAlgorithm, JWSHeaderParameters, JWSKeyLookup, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JWTConfirmation, JWTTimeClaimOptions, JoseHeaderParameters, KeyManagementAlgorithm, KeyWrapAlgorithmOf, KeyWrappingAlgorithm, MaxTokenAge, NotBeforeIn, PEMType, PayloadOf, ToPublicJWKReturn, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor } from "../../_chunks/index.mjs";
|
|
3
3
|
import { thumbprint } from "../../_chunks/index2.mjs";
|
|
4
|
-
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../../
|
|
4
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../../_chunks/jwk.mjs";
|
|
5
5
|
import { HTTPEvent, setCookie } from "h3";
|
|
6
6
|
type CookieSerializeOptions = NonNullable<Parameters<typeof setCookie>[3]>;
|
|
7
7
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { thumbprint } from "../../_chunks/_import-key.mjs";
|
|
2
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../../core/jwk.mjs";
|
|
2
3
|
import { bindSession, createJWECodec, createJWSCodec, defineSession, dropSession, encodeSession, issueSession, loadSession, openSessionToken, sessionActions, setCookieName, setCookieValues } from "../../_chunks/_codec-jws.mjs";
|
|
3
4
|
import { getCookie, getEventContext, setCookie } from "h3";
|
|
4
5
|
const PREFIX = "[unjwt/h3]";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, OpenedSessionState, SessionClaims, SessionData, SessionDecryptOptions, SessionDefinition, SessionEncryptOptions, SessionIssueOptions, SessionManager, SessionRecord, SessionSignOptions, SessionState, SessionUpdate, SessionUpdateTrigger, SessionVerifyOptions } from "../../_chunks/_codec-jwe.mjs";
|
|
2
2
|
import { CompositeKey, ContentEncryptionAlgorithm, DeriveJWKOptions, DeriveJWKReturn, DeriveKeyOptions, DeriveKeyReturn, Duration, ECDHEphemeralKeyInput, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, ImportedPEMJWK, JOSEConsumerOptions, JOSELimits, JOSEPayload, JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyLookup, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_Algorithm, JWK_AES_CBC_HMAC, JWK_AES_GCM, JWK_AES_GCM_KW, JWK_AES_KW, JWK_Asymmetric, JWK_Asymmetric_Algorithm, JWK_EC, JWK_ECDH_ES, JWK_ECDSA, JWK_EC_Private, JWK_EC_Public, JWK_HMAC, JWK_OKP, JWK_OKP_Private, JWK_OKP_Public, JWK_OKP_SIGN, JWK_PBES2, JWK_Pair, JWK_Private, JWK_Public, JWK_RSA, JWK_RSA_ENC, JWK_RSA_PSS, JWK_RSA_Private, JWK_RSA_Public, JWK_RSA_SIGN, JWK_Symmetric, JWK_Symmetric_Algorithm, JWK_oct, JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHashedAlgorithm, JWSHeaderParameters, JWSKeyLookup, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JWTConfirmation, JWTTimeClaimOptions, JoseHeaderParameters, KeyManagementAlgorithm, KeyWrapAlgorithmOf, KeyWrappingAlgorithm, MaxTokenAge, NotBeforeIn, PEMType, PayloadOf, ToPublicJWKReturn, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor } from "../../_chunks/index.mjs";
|
|
3
3
|
import { thumbprint } from "../../_chunks/index2.mjs";
|
|
4
|
-
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../../
|
|
4
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../../_chunks/jwk.mjs";
|
|
5
5
|
import { H3Event, H3EventContext, setCookie } from "h3";
|
|
6
6
|
type CookieSerializeOptions = NonNullable<Parameters<typeof setCookie>[3]>;
|
|
7
7
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { thumbprint } from "../../_chunks/_import-key.mjs";
|
|
2
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../../core/jwk.mjs";
|
|
2
3
|
import { bindSession, createJWECodec, createJWSCodec, defineSession, dropSession, encodeSession, issueSession, loadSession, openSessionToken, sessionActions, setCookieValues } from "../../_chunks/_codec-jws.mjs";
|
|
3
4
|
import { parse } from "../../_chunks/libs/cookie-es.mjs";
|
|
4
5
|
import { getCookie, getRequestHeader, getResponseHeader, isEvent, setCookie } from "h3";
|
package/dist/core/jwe.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnsecureError } from "../_chunks/libs/unsecure.mjs";
|
|
2
2
|
import { JWTError, isJWTError, isUnsecureError } from "../_chunks/_jwt-internal.mjs";
|
|
3
|
-
import { DEFAULT_JOSE_LIMITS } from "../_chunks/
|
|
3
|
+
import { DEFAULT_JOSE_LIMITS } from "../_chunks/_import-key.mjs";
|
|
4
4
|
import { decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened } from "../_chunks/jwe.mjs";
|
|
5
5
|
export { DEFAULT_JOSE_LIMITS, JWTError, UnsecureError, decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened, isJWTError, isUnsecureError };
|