almostnode 0.2.7 → 0.2.8
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/README.md +1 -1
- package/dist/__sw__.js +80 -84
- package/dist/assets/{runtime-worker-B8_LZkBX.js → runtime-worker-D8VYeuKv.js} +1448 -1121
- package/dist/assets/runtime-worker-D8VYeuKv.js.map +1 -0
- package/dist/frameworks/code-transforms.d.ts.map +1 -1
- package/dist/frameworks/next-config-parser.d.ts +16 -0
- package/dist/frameworks/next-config-parser.d.ts.map +1 -0
- package/dist/frameworks/next-dev-server.d.ts +6 -6
- package/dist/frameworks/next-dev-server.d.ts.map +1 -1
- package/dist/frameworks/next-html-generator.d.ts +35 -0
- package/dist/frameworks/next-html-generator.d.ts.map +1 -0
- package/dist/frameworks/next-shims.d.ts +79 -0
- package/dist/frameworks/next-shims.d.ts.map +1 -0
- package/dist/index.cjs +2895 -2454
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +3208 -2782
- package/dist/index.mjs.map +1 -1
- package/dist/runtime.d.ts +20 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/server-bridge.d.ts +2 -0
- package/dist/server-bridge.d.ts.map +1 -1
- package/dist/shims/crypto.d.ts +2 -0
- package/dist/shims/crypto.d.ts.map +1 -1
- package/dist/shims/esbuild.d.ts.map +1 -1
- package/dist/shims/fs.d.ts.map +1 -1
- package/dist/shims/http.d.ts +29 -0
- package/dist/shims/http.d.ts.map +1 -1
- package/dist/shims/path.d.ts.map +1 -1
- package/dist/shims/stream.d.ts.map +1 -1
- package/dist/shims/vfs-adapter.d.ts.map +1 -1
- package/dist/shims/ws.d.ts +2 -0
- package/dist/shims/ws.d.ts.map +1 -1
- package/dist/utils/binary-encoding.d.ts +13 -0
- package/dist/utils/binary-encoding.d.ts.map +1 -0
- package/dist/virtual-fs.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/convex-app-demo-entry.ts +229 -35
- package/src/frameworks/code-transforms.ts +5 -1
- package/src/frameworks/next-config-parser.ts +140 -0
- package/src/frameworks/next-dev-server.ts +76 -1675
- package/src/frameworks/next-html-generator.ts +597 -0
- package/src/frameworks/next-shims.ts +1050 -0
- package/src/frameworks/tailwind-config-loader.ts +1 -1
- package/src/index.ts +2 -0
- package/src/runtime.ts +94 -15
- package/src/server-bridge.ts +61 -28
- package/src/shims/crypto.ts +13 -0
- package/src/shims/esbuild.ts +4 -1
- package/src/shims/fs.ts +9 -11
- package/src/shims/http.ts +309 -3
- package/src/shims/path.ts +6 -13
- package/src/shims/stream.ts +12 -26
- package/src/shims/vfs-adapter.ts +5 -2
- package/src/shims/ws.ts +92 -2
- package/src/utils/binary-encoding.ts +43 -0
- package/src/virtual-fs.ts +7 -15
- package/dist/assets/runtime-worker-B8_LZkBX.js.map +0 -1
|
@@ -365,6 +365,36 @@
|
|
|
365
365
|
function generateUUID() {
|
|
366
366
|
return new Array(4).fill(0).map(()=>Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
367
367
|
}
|
|
368
|
+
const CHUNK = 8192;
|
|
369
|
+
function uint8ToBase64(bytes) {
|
|
370
|
+
const parts = [];
|
|
371
|
+
for(let i = 0; i < bytes.length; i += CHUNK){
|
|
372
|
+
parts.push(String.fromCharCode.apply(null, Array.from(bytes.subarray(i, i + CHUNK))));
|
|
373
|
+
}
|
|
374
|
+
return btoa(parts.join(""));
|
|
375
|
+
}
|
|
376
|
+
function base64ToUint8(base64) {
|
|
377
|
+
const binary = atob(base64);
|
|
378
|
+
const bytes = new Uint8Array(binary.length);
|
|
379
|
+
for(let i = 0; i < binary.length; i++){
|
|
380
|
+
bytes[i] = binary.charCodeAt(i);
|
|
381
|
+
}
|
|
382
|
+
return bytes;
|
|
383
|
+
}
|
|
384
|
+
function uint8ToHex(bytes) {
|
|
385
|
+
const hex = new Array(bytes.length);
|
|
386
|
+
for(let i = 0; i < bytes.length; i++){
|
|
387
|
+
hex[i] = bytes[i].toString(16).padStart(2, "0");
|
|
388
|
+
}
|
|
389
|
+
return hex.join("");
|
|
390
|
+
}
|
|
391
|
+
function uint8ToBinaryString(bytes) {
|
|
392
|
+
const parts = [];
|
|
393
|
+
for(let i = 0; i < bytes.length; i += CHUNK){
|
|
394
|
+
parts.push(String.fromCharCode.apply(null, Array.from(bytes.subarray(i, i + CHUNK))));
|
|
395
|
+
}
|
|
396
|
+
return parts.join("");
|
|
397
|
+
}
|
|
368
398
|
function createNodeError(code, syscall, path, message) {
|
|
369
399
|
const errno = {
|
|
370
400
|
ENOENT: -2,
|
|
@@ -437,11 +467,7 @@
|
|
|
437
467
|
if (node.type === "file") {
|
|
438
468
|
let content = "";
|
|
439
469
|
if (node.content && node.content.length > 0) {
|
|
440
|
-
|
|
441
|
-
for(let i = 0; i < node.content.length; i++){
|
|
442
|
-
binary += String.fromCharCode(node.content[i]);
|
|
443
|
-
}
|
|
444
|
-
content = btoa(binary);
|
|
470
|
+
content = uint8ToBase64(node.content);
|
|
445
471
|
}
|
|
446
472
|
files.push({
|
|
447
473
|
path,
|
|
@@ -463,13 +489,11 @@
|
|
|
463
489
|
}
|
|
464
490
|
static fromSnapshot(snapshot) {
|
|
465
491
|
const vfs = new VirtualFS();
|
|
466
|
-
const sortedFiles =
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
return aDepth - bDepth;
|
|
472
|
-
});
|
|
492
|
+
const sortedFiles = snapshot.files.map((entry, i)=>({
|
|
493
|
+
entry,
|
|
494
|
+
depth: entry.path.split("/").length,
|
|
495
|
+
i
|
|
496
|
+
})).sort((a, b)=>a.depth - b.depth || a.i - b.i).map((x)=>x.entry);
|
|
473
497
|
for (const entry of sortedFiles){
|
|
474
498
|
if (entry.path === "/") continue;
|
|
475
499
|
if (entry.type === "directory") {
|
|
@@ -479,11 +503,7 @@
|
|
|
479
503
|
} else if (entry.type === "file") {
|
|
480
504
|
let content;
|
|
481
505
|
if (entry.content) {
|
|
482
|
-
|
|
483
|
-
content = new Uint8Array(binary.length);
|
|
484
|
-
for(let i = 0; i < binary.length; i++){
|
|
485
|
-
content[i] = binary.charCodeAt(i);
|
|
486
|
-
}
|
|
506
|
+
content = base64ToUint8(entry.content);
|
|
487
507
|
} else {
|
|
488
508
|
content = new Uint8Array(0);
|
|
489
509
|
}
|
|
@@ -954,6 +974,8 @@
|
|
|
954
974
|
}
|
|
955
975
|
return hash.toString(36);
|
|
956
976
|
}
|
|
977
|
+
const _decoder$2 = new TextDecoder();
|
|
978
|
+
const _encoder$1 = new TextEncoder();
|
|
957
979
|
class Dirent {
|
|
958
980
|
name;
|
|
959
981
|
_isDirectory;
|
|
@@ -990,17 +1012,13 @@
|
|
|
990
1012
|
Object.defineProperty(buffer, "toString", {
|
|
991
1013
|
value: function(encoding) {
|
|
992
1014
|
if (encoding === "utf8" || encoding === "utf-8" || !encoding) {
|
|
993
|
-
return
|
|
1015
|
+
return _decoder$2.decode(this);
|
|
994
1016
|
}
|
|
995
1017
|
if (encoding === "base64") {
|
|
996
|
-
|
|
997
|
-
for(let i = 0; i < this.length; i++){
|
|
998
|
-
binary += String.fromCharCode(this[i]);
|
|
999
|
-
}
|
|
1000
|
-
return btoa(binary);
|
|
1018
|
+
return uint8ToBase64(this);
|
|
1001
1019
|
}
|
|
1002
1020
|
if (encoding === "hex") {
|
|
1003
|
-
return
|
|
1021
|
+
return uint8ToHex(this);
|
|
1004
1022
|
}
|
|
1005
1023
|
throw new Error(`Unsupported encoding: ${encoding}`);
|
|
1006
1024
|
},
|
|
@@ -1245,7 +1263,7 @@
|
|
|
1245
1263
|
err.errno = -9;
|
|
1246
1264
|
throw err;
|
|
1247
1265
|
}
|
|
1248
|
-
const bytes = typeof data === "string" ?
|
|
1266
|
+
const bytes = typeof data === "string" ? _encoder$1.encode(data) : data;
|
|
1249
1267
|
entry.content = new Uint8Array(bytes);
|
|
1250
1268
|
entry.position = bytes.length;
|
|
1251
1269
|
return;
|
|
@@ -1396,7 +1414,7 @@
|
|
|
1396
1414
|
}
|
|
1397
1415
|
let data;
|
|
1398
1416
|
if (typeof buffer === "string") {
|
|
1399
|
-
data =
|
|
1417
|
+
data = _encoder$1.encode(buffer);
|
|
1400
1418
|
offset = 0;
|
|
1401
1419
|
length = data.length;
|
|
1402
1420
|
} else {
|
|
@@ -1549,17 +1567,9 @@
|
|
|
1549
1567
|
}
|
|
1550
1568
|
return result || ".";
|
|
1551
1569
|
}
|
|
1552
|
-
let joinCallCount = 0;
|
|
1553
1570
|
function join$1(...paths) {
|
|
1554
1571
|
if (paths.length === 0) return ".";
|
|
1555
|
-
|
|
1556
|
-
if (paths.some((p)=>p && p.includes("_generated"))) {
|
|
1557
|
-
joinCallCount++;
|
|
1558
|
-
if (joinCallCount <= 20) {
|
|
1559
|
-
console.log(`[path.join] (${paths.join(", ")}) -> ${result}`);
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
return result;
|
|
1572
|
+
return normalize(paths.filter(Boolean).join("/"));
|
|
1563
1573
|
}
|
|
1564
1574
|
function resolve$2(...paths) {
|
|
1565
1575
|
let resolvedPath = "";
|
|
@@ -1569,7 +1579,8 @@
|
|
|
1569
1579
|
resolvedPath = path + (resolvedPath ? "/" + resolvedPath : "");
|
|
1570
1580
|
}
|
|
1571
1581
|
if (!resolvedPath.startsWith("/")) {
|
|
1572
|
-
|
|
1582
|
+
const cwd = typeof globalThis !== "undefined" && globalThis.process && typeof globalThis.process.cwd === "function" ? globalThis.process.cwd() : "/";
|
|
1583
|
+
resolvedPath = cwd + (resolvedPath ? "/" + resolvedPath : "");
|
|
1573
1584
|
}
|
|
1574
1585
|
return normalize(resolvedPath);
|
|
1575
1586
|
}
|
|
@@ -2064,6 +2075,8 @@
|
|
|
2064
2075
|
return proc;
|
|
2065
2076
|
}
|
|
2066
2077
|
createProcess();
|
|
2078
|
+
const _encoder = new TextEncoder();
|
|
2079
|
+
const _decoder$1 = new TextDecoder("utf-8");
|
|
2067
2080
|
class Readable extends EventEmitter {
|
|
2068
2081
|
_buffer = [];
|
|
2069
2082
|
_ended = false;
|
|
@@ -2435,8 +2448,7 @@
|
|
|
2435
2448
|
}
|
|
2436
2449
|
return new BufferPolyfill(bytes2);
|
|
2437
2450
|
}
|
|
2438
|
-
const
|
|
2439
|
-
const bytes = encoder.encode(data);
|
|
2451
|
+
const bytes = _encoder.encode(data);
|
|
2440
2452
|
return new BufferPolyfill(bytes);
|
|
2441
2453
|
}
|
|
2442
2454
|
if (data instanceof ArrayBuffer) {
|
|
@@ -2491,40 +2503,23 @@
|
|
|
2491
2503
|
if (enc === "hex") {
|
|
2492
2504
|
return string.length / 2;
|
|
2493
2505
|
}
|
|
2494
|
-
return
|
|
2506
|
+
return _encoder.encode(string).length;
|
|
2495
2507
|
}
|
|
2496
2508
|
toString(encoding = "utf8") {
|
|
2497
2509
|
const enc = (encoding || "utf8").toLowerCase();
|
|
2498
2510
|
if (enc === "base64") {
|
|
2499
|
-
|
|
2500
|
-
for(let i = 0; i < this.length; i++){
|
|
2501
|
-
binary += String.fromCharCode(this[i]);
|
|
2502
|
-
}
|
|
2503
|
-
return btoa(binary);
|
|
2511
|
+
return uint8ToBase64(this);
|
|
2504
2512
|
}
|
|
2505
2513
|
if (enc === "base64url") {
|
|
2506
|
-
|
|
2507
|
-
for(let i = 0; i < this.length; i++){
|
|
2508
|
-
binary += String.fromCharCode(this[i]);
|
|
2509
|
-
}
|
|
2510
|
-
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
2514
|
+
return uint8ToBase64(this).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
2511
2515
|
}
|
|
2512
2516
|
if (enc === "hex") {
|
|
2513
|
-
|
|
2514
|
-
for(let i = 0; i < this.length; i++){
|
|
2515
|
-
hex += this[i].toString(16).padStart(2, "0");
|
|
2516
|
-
}
|
|
2517
|
-
return hex;
|
|
2517
|
+
return uint8ToHex(this);
|
|
2518
2518
|
}
|
|
2519
2519
|
if (enc === "latin1" || enc === "binary") {
|
|
2520
|
-
|
|
2521
|
-
for(let i = 0; i < this.length; i++){
|
|
2522
|
-
str += String.fromCharCode(this[i]);
|
|
2523
|
-
}
|
|
2524
|
-
return str;
|
|
2520
|
+
return uint8ToBinaryString(this);
|
|
2525
2521
|
}
|
|
2526
|
-
|
|
2527
|
-
return decoder.decode(this);
|
|
2522
|
+
return _decoder$1.decode(this);
|
|
2528
2523
|
}
|
|
2529
2524
|
slice(start, end) {
|
|
2530
2525
|
return new BufferPolyfill(super.slice(start, end));
|
|
@@ -2533,7 +2528,7 @@
|
|
|
2533
2528
|
return new BufferPolyfill(super.subarray(start, end));
|
|
2534
2529
|
}
|
|
2535
2530
|
write(string, offset) {
|
|
2536
|
-
const bytes =
|
|
2531
|
+
const bytes = _encoder.encode(string);
|
|
2537
2532
|
this.set(bytes, offset || 0);
|
|
2538
2533
|
return bytes.length;
|
|
2539
2534
|
}
|
|
@@ -3161,295 +3156,897 @@
|
|
|
3161
3156
|
isIPv4: isIPv4,
|
|
3162
3157
|
isIPv6: isIPv6
|
|
3163
3158
|
});
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
setTimeout(msecs, callback) {
|
|
3184
|
-
if (callback) {
|
|
3185
|
-
this.once("timeout", callback);
|
|
3186
|
-
}
|
|
3187
|
-
return this;
|
|
3159
|
+
function randomBytes(size) {
|
|
3160
|
+
const array = new Uint8Array(size);
|
|
3161
|
+
crypto.getRandomValues(array);
|
|
3162
|
+
return BufferPolyfill.from(array);
|
|
3163
|
+
}
|
|
3164
|
+
function randomFillSync(buffer, offset, size) {
|
|
3165
|
+
const start = offset || 0;
|
|
3166
|
+
const len = size !== void 0 ? size : buffer.length - start;
|
|
3167
|
+
const view = new Uint8Array(buffer.buffer, buffer.byteOffset + start, len);
|
|
3168
|
+
crypto.getRandomValues(view);
|
|
3169
|
+
return buffer;
|
|
3170
|
+
}
|
|
3171
|
+
function randomUUID() {
|
|
3172
|
+
return crypto.randomUUID();
|
|
3173
|
+
}
|
|
3174
|
+
function randomInt(min, max) {
|
|
3175
|
+
if (max === void 0) {
|
|
3176
|
+
max = min;
|
|
3177
|
+
min = 0;
|
|
3188
3178
|
}
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3179
|
+
const range = max - min;
|
|
3180
|
+
const array = new Uint32Array(1);
|
|
3181
|
+
crypto.getRandomValues(array);
|
|
3182
|
+
return min + array[0] % range;
|
|
3183
|
+
}
|
|
3184
|
+
function getRandomValues(array) {
|
|
3185
|
+
return crypto.getRandomValues(array);
|
|
3186
|
+
}
|
|
3187
|
+
function createHash(algorithm) {
|
|
3188
|
+
return new Hash(algorithm);
|
|
3189
|
+
}
|
|
3190
|
+
class Hash {
|
|
3191
|
+
algorithm;
|
|
3192
|
+
data = [];
|
|
3193
|
+
constructor(algorithm){
|
|
3194
|
+
this.algorithm = normalizeHashAlgorithm(algorithm);
|
|
3192
3195
|
}
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
+
update(data, encoding) {
|
|
3197
|
+
let buffer;
|
|
3198
|
+
if (typeof data === "string") {
|
|
3199
|
+
if (encoding === "base64") {
|
|
3200
|
+
buffer = BufferPolyfill.from(atob(data));
|
|
3201
|
+
} else {
|
|
3202
|
+
buffer = BufferPolyfill.from(data);
|
|
3203
|
+
}
|
|
3196
3204
|
} else {
|
|
3197
|
-
|
|
3198
|
-
}
|
|
3199
|
-
if (this._body) {
|
|
3200
|
-
this.push(this._body);
|
|
3205
|
+
buffer = data;
|
|
3201
3206
|
}
|
|
3202
|
-
this.push(
|
|
3203
|
-
this
|
|
3207
|
+
this.data.push(buffer);
|
|
3208
|
+
return this;
|
|
3204
3209
|
}
|
|
3205
|
-
|
|
3206
|
-
const
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
...headers
|
|
3211
|
-
};
|
|
3212
|
-
for (const [key, value] of Object.entries(headers)){
|
|
3213
|
-
msg.rawHeaders.push(key, value);
|
|
3214
|
-
}
|
|
3215
|
-
if (body) {
|
|
3216
|
-
msg._setBody(body);
|
|
3217
|
-
} else {
|
|
3218
|
-
msg.push(null);
|
|
3219
|
-
msg.complete = true;
|
|
3220
|
-
}
|
|
3221
|
-
return msg;
|
|
3210
|
+
async digestAsync(encoding) {
|
|
3211
|
+
const combined = concatBuffers(this.data);
|
|
3212
|
+
const dataBuffer = new Uint8Array(combined).buffer;
|
|
3213
|
+
const hashBuffer = await crypto.subtle.digest(this.algorithm, dataBuffer);
|
|
3214
|
+
return encodeResult(new Uint8Array(hashBuffer), encoding);
|
|
3222
3215
|
}
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
headersSent = false;
|
|
3228
|
-
finished = false;
|
|
3229
|
-
sendDate = true;
|
|
3230
|
-
socket;
|
|
3231
|
-
_headers = new Map();
|
|
3232
|
-
_body = [];
|
|
3233
|
-
_resolve;
|
|
3234
|
-
constructor(req){
|
|
3235
|
-
super();
|
|
3236
|
-
this.socket = req.socket;
|
|
3216
|
+
digest(encoding) {
|
|
3217
|
+
const combined = concatBuffers(this.data);
|
|
3218
|
+
const hash = syncHash(combined, this.algorithm);
|
|
3219
|
+
return encodeResult(hash, encoding);
|
|
3237
3220
|
}
|
|
3238
|
-
|
|
3239
|
-
|
|
3221
|
+
}
|
|
3222
|
+
function createHmac(algorithm, key) {
|
|
3223
|
+
return new Hmac(algorithm, key);
|
|
3224
|
+
}
|
|
3225
|
+
class Hmac {
|
|
3226
|
+
algorithm;
|
|
3227
|
+
key;
|
|
3228
|
+
data = [];
|
|
3229
|
+
constructor(algorithm, key){
|
|
3230
|
+
this.algorithm = normalizeHashAlgorithm(algorithm);
|
|
3231
|
+
this.key = typeof key === "string" ? BufferPolyfill.from(key) : key;
|
|
3240
3232
|
}
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
}
|
|
3245
|
-
this._headers.set(name.toLowerCase(), String(value));
|
|
3233
|
+
update(data, encoding) {
|
|
3234
|
+
const buffer = typeof data === "string" ? BufferPolyfill.from(data) : data;
|
|
3235
|
+
this.data.push(buffer);
|
|
3246
3236
|
return this;
|
|
3247
3237
|
}
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
const
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
}
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
return
|
|
3260
|
-
...this._headers.keys()
|
|
3261
|
-
];
|
|
3238
|
+
async digestAsync(encoding) {
|
|
3239
|
+
const combined = concatBuffers(this.data);
|
|
3240
|
+
const keyBuffer = new Uint8Array(this.key).buffer;
|
|
3241
|
+
const dataBuffer = new Uint8Array(combined).buffer;
|
|
3242
|
+
const cryptoKey = await crypto.subtle.importKey("raw", keyBuffer, {
|
|
3243
|
+
name: "HMAC",
|
|
3244
|
+
hash: this.algorithm
|
|
3245
|
+
}, false, [
|
|
3246
|
+
"sign"
|
|
3247
|
+
]);
|
|
3248
|
+
const signature = await crypto.subtle.sign("HMAC", cryptoKey, dataBuffer);
|
|
3249
|
+
return encodeResult(new Uint8Array(signature), encoding);
|
|
3262
3250
|
}
|
|
3263
|
-
|
|
3264
|
-
|
|
3251
|
+
digest(encoding) {
|
|
3252
|
+
const combined = concatBuffers(this.data);
|
|
3253
|
+
const hash = syncHmac(combined, this.key, this.algorithm);
|
|
3254
|
+
return encodeResult(hash, encoding);
|
|
3265
3255
|
}
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3256
|
+
}
|
|
3257
|
+
async function pbkdf2Async(password, salt, iterations, keylen, digest) {
|
|
3258
|
+
const passwordBuffer = typeof password === "string" ? BufferPolyfill.from(password) : password instanceof Uint8Array ? password : BufferPolyfill.from(password);
|
|
3259
|
+
const saltBuffer = typeof salt === "string" ? BufferPolyfill.from(salt) : salt instanceof Uint8Array ? salt : BufferPolyfill.from(salt);
|
|
3260
|
+
const passwordArrayBuffer = new Uint8Array(passwordBuffer).buffer;
|
|
3261
|
+
const saltArrayBuffer = new Uint8Array(saltBuffer).buffer;
|
|
3262
|
+
const key = await crypto.subtle.importKey("raw", passwordArrayBuffer, "PBKDF2", false, [
|
|
3263
|
+
"deriveBits"
|
|
3264
|
+
]);
|
|
3265
|
+
const derivedBits = await crypto.subtle.deriveBits({
|
|
3266
|
+
name: "PBKDF2",
|
|
3267
|
+
salt: saltArrayBuffer,
|
|
3268
|
+
iterations,
|
|
3269
|
+
hash: normalizeHashAlgorithm(digest)
|
|
3270
|
+
}, key, keylen * 8);
|
|
3271
|
+
return BufferPolyfill.from(derivedBits);
|
|
3272
|
+
}
|
|
3273
|
+
function pbkdf2(password, salt, iterations, keylen, digest, callback) {
|
|
3274
|
+
pbkdf2Async(password, salt, iterations, keylen, digest).then((key)=>callback(null, key)).catch((err)=>callback(err, BufferPolyfill.alloc(0)));
|
|
3275
|
+
}
|
|
3276
|
+
function pbkdf2Sync(password, salt, iterations, keylen, digest) {
|
|
3277
|
+
const passwordBuffer = typeof password === "string" ? BufferPolyfill.from(password) : password;
|
|
3278
|
+
const saltBuffer = typeof salt === "string" ? BufferPolyfill.from(salt) : salt;
|
|
3279
|
+
const hashAlg = normalizeHashAlgorithm(digest);
|
|
3280
|
+
let hashLen;
|
|
3281
|
+
if (hashAlg.includes("512")) {
|
|
3282
|
+
hashLen = 64;
|
|
3283
|
+
} else if (hashAlg.includes("384")) {
|
|
3284
|
+
hashLen = 48;
|
|
3285
|
+
} else if (hashAlg.includes("1") || hashAlg === "SHA-1") {
|
|
3286
|
+
hashLen = 20;
|
|
3287
|
+
} else {
|
|
3288
|
+
hashLen = 32;
|
|
3271
3289
|
}
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3290
|
+
const numBlocks = Math.ceil(keylen / hashLen);
|
|
3291
|
+
const derivedKey = new Uint8Array(numBlocks * hashLen);
|
|
3292
|
+
for(let blockNum = 1; blockNum <= numBlocks; blockNum++){
|
|
3293
|
+
const blockNumBuf = new Uint8Array(4);
|
|
3294
|
+
blockNumBuf[0] = blockNum >>> 24 & 255;
|
|
3295
|
+
blockNumBuf[1] = blockNum >>> 16 & 255;
|
|
3296
|
+
blockNumBuf[2] = blockNum >>> 8 & 255;
|
|
3297
|
+
blockNumBuf[3] = blockNum & 255;
|
|
3298
|
+
const saltWithBlock = new Uint8Array(saltBuffer.length + 4);
|
|
3299
|
+
saltWithBlock.set(saltBuffer);
|
|
3300
|
+
saltWithBlock.set(blockNumBuf, saltBuffer.length);
|
|
3301
|
+
let u = syncHmac(saltWithBlock, passwordBuffer, hashAlg);
|
|
3302
|
+
const block = new Uint8Array(u);
|
|
3303
|
+
for(let i = 1; i < iterations; i++){
|
|
3304
|
+
u = syncHmac(u, passwordBuffer, hashAlg);
|
|
3305
|
+
for(let j = 0; j < block.length; j++){
|
|
3306
|
+
block[j] ^= u[j];
|
|
3284
3307
|
}
|
|
3285
3308
|
}
|
|
3286
|
-
|
|
3309
|
+
derivedKey.set(block, (blockNum - 1) * hashLen);
|
|
3287
3310
|
}
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3311
|
+
return BufferPolyfill.from(derivedKey.slice(0, keylen));
|
|
3312
|
+
}
|
|
3313
|
+
function sign(algorithm, data, key, callback) {
|
|
3314
|
+
const keyInfo = extractKeyInfo(key);
|
|
3315
|
+
const alg = algorithm || keyInfo.algorithm;
|
|
3316
|
+
if (!alg) {
|
|
3317
|
+
const error = new Error("Algorithm must be specified");
|
|
3318
|
+
if (callback) {
|
|
3319
|
+
callback(error, null);
|
|
3320
|
+
return;
|
|
3295
3321
|
}
|
|
3296
|
-
|
|
3322
|
+
throw error;
|
|
3297
3323
|
}
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
} else if (chunkOrCallback !== void 0) {
|
|
3302
|
-
this.write(chunkOrCallback);
|
|
3303
|
-
}
|
|
3304
|
-
if (typeof encodingOrCallback === "function") {
|
|
3305
|
-
callback = encodingOrCallback;
|
|
3306
|
-
}
|
|
3307
|
-
this.headersSent = true;
|
|
3308
|
-
this.finished = true;
|
|
3309
|
-
if (this._resolve) {
|
|
3310
|
-
const headers = {};
|
|
3311
|
-
for (const [key, value] of this._headers){
|
|
3312
|
-
headers[key] = Array.isArray(value) ? value.join(", ") : value;
|
|
3313
|
-
}
|
|
3314
|
-
this._resolve({
|
|
3315
|
-
statusCode: this.statusCode,
|
|
3316
|
-
statusMessage: this.statusMessage,
|
|
3317
|
-
headers,
|
|
3318
|
-
body: BufferPolyfill.concat(this._body)
|
|
3319
|
-
});
|
|
3320
|
-
}
|
|
3321
|
-
queueMicrotask(()=>{
|
|
3322
|
-
this.emit("finish");
|
|
3323
|
-
if (callback) callback();
|
|
3324
|
-
});
|
|
3325
|
-
return this;
|
|
3324
|
+
if (callback) {
|
|
3325
|
+
signAsync(alg, data, keyInfo).then((sig)=>callback(null, sig)).catch((err)=>callback(err, null));
|
|
3326
|
+
return;
|
|
3326
3327
|
}
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3328
|
+
const result = signSync(alg, data, keyInfo);
|
|
3329
|
+
return result;
|
|
3330
|
+
}
|
|
3331
|
+
function verify(algorithm, data, key, signature, callback) {
|
|
3332
|
+
const keyInfo = extractKeyInfo(key);
|
|
3333
|
+
const alg = algorithm || keyInfo.algorithm;
|
|
3334
|
+
if (!alg) {
|
|
3335
|
+
const error = new Error("Algorithm must be specified");
|
|
3336
|
+
if (callback) {
|
|
3337
|
+
callback(error, false);
|
|
3338
|
+
return;
|
|
3334
3339
|
}
|
|
3335
|
-
|
|
3336
|
-
return this.end();
|
|
3340
|
+
throw error;
|
|
3337
3341
|
}
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
return
|
|
3342
|
+
if (callback) {
|
|
3343
|
+
verifyAsync(alg, data, keyInfo, signature).then((result)=>callback(null, result)).catch((err)=>callback(err, false));
|
|
3344
|
+
return;
|
|
3341
3345
|
}
|
|
3342
|
-
|
|
3343
|
-
|
|
3346
|
+
return verifySync(alg, data, keyInfo, signature);
|
|
3347
|
+
}
|
|
3348
|
+
function createSign(algorithm) {
|
|
3349
|
+
return new Sign(algorithm);
|
|
3350
|
+
}
|
|
3351
|
+
function createVerify(algorithm) {
|
|
3352
|
+
return new Verify(algorithm);
|
|
3353
|
+
}
|
|
3354
|
+
class Sign extends EventEmitter {
|
|
3355
|
+
algorithm;
|
|
3356
|
+
data = [];
|
|
3357
|
+
constructor(algorithm){
|
|
3358
|
+
super();
|
|
3359
|
+
this.algorithm = algorithm;
|
|
3360
|
+
}
|
|
3361
|
+
update(data, encoding) {
|
|
3362
|
+
const buffer = typeof data === "string" ? BufferPolyfill.from(data) : data;
|
|
3363
|
+
this.data.push(buffer);
|
|
3344
3364
|
return this;
|
|
3345
3365
|
}
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
this.setHeader("Location", urlOrStatus);
|
|
3366
|
+
sign(privateKey, outputEncoding) {
|
|
3367
|
+
const combined = concatBuffers(this.data);
|
|
3368
|
+
const keyInfo = extractKeyInfo(privateKey);
|
|
3369
|
+
const signature = signSync(this.algorithm, combined, keyInfo);
|
|
3370
|
+
if (outputEncoding === "base64") {
|
|
3371
|
+
return btoa(String.fromCharCode(...signature));
|
|
3353
3372
|
}
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
return
|
|
3358
|
-
}
|
|
3359
|
-
_getBodyAsString() {
|
|
3360
|
-
return this._getBody().toString("utf8");
|
|
3373
|
+
if (outputEncoding === "hex") {
|
|
3374
|
+
return Array.from(signature).map((b)=>b.toString(16).padStart(2, "0")).join("");
|
|
3375
|
+
}
|
|
3376
|
+
return signature;
|
|
3361
3377
|
}
|
|
3362
3378
|
}
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
listening = false;
|
|
3368
|
-
maxHeadersCount = null;
|
|
3369
|
-
timeout = 0;
|
|
3370
|
-
keepAliveTimeout = 5e3;
|
|
3371
|
-
headersTimeout = 6e4;
|
|
3372
|
-
requestTimeout = 0;
|
|
3373
|
-
constructor(requestListener){
|
|
3379
|
+
class Verify extends EventEmitter {
|
|
3380
|
+
algorithm;
|
|
3381
|
+
data = [];
|
|
3382
|
+
constructor(algorithm){
|
|
3374
3383
|
super();
|
|
3375
|
-
this.
|
|
3376
|
-
this._netServer = new Server$3();
|
|
3377
|
-
this._netServer.on("listening", ()=>{
|
|
3378
|
-
this.listening = true;
|
|
3379
|
-
this.emit("listening");
|
|
3380
|
-
});
|
|
3381
|
-
this._netServer.on("close", ()=>{
|
|
3382
|
-
this.listening = false;
|
|
3383
|
-
this.emit("close");
|
|
3384
|
-
});
|
|
3385
|
-
this._netServer.on("error", (err)=>{
|
|
3386
|
-
this.emit("error", err);
|
|
3387
|
-
});
|
|
3384
|
+
this.algorithm = algorithm;
|
|
3388
3385
|
}
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3386
|
+
update(data, encoding) {
|
|
3387
|
+
const buffer = typeof data === "string" ? BufferPolyfill.from(data) : data;
|
|
3388
|
+
this.data.push(buffer);
|
|
3389
|
+
return this;
|
|
3390
|
+
}
|
|
3391
|
+
verify(publicKey, signature, signatureEncoding) {
|
|
3392
|
+
const combined = concatBuffers(this.data);
|
|
3393
|
+
const keyInfo = extractKeyInfo(publicKey);
|
|
3394
|
+
let sig;
|
|
3395
|
+
if (typeof signature === "string") {
|
|
3396
|
+
if (signatureEncoding === "base64") {
|
|
3397
|
+
sig = BufferPolyfill.from(atob(signature));
|
|
3398
|
+
} else if (signatureEncoding === "hex") {
|
|
3399
|
+
sig = BufferPolyfill.from(signature.match(/.{2}/g).map((byte)=>parseInt(byte, 16)));
|
|
3398
3400
|
} else {
|
|
3399
|
-
|
|
3401
|
+
sig = BufferPolyfill.from(signature);
|
|
3400
3402
|
}
|
|
3401
|
-
} else
|
|
3402
|
-
|
|
3403
|
-
host = portOrOptions.host;
|
|
3404
|
-
cb = typeof hostOrCallback === "function" ? hostOrCallback : callback;
|
|
3403
|
+
} else {
|
|
3404
|
+
sig = signature;
|
|
3405
3405
|
}
|
|
3406
|
-
|
|
3407
|
-
const self = this;
|
|
3408
|
-
cb = function() {
|
|
3409
|
-
const addr = self._netServer.address();
|
|
3410
|
-
if (addr) {
|
|
3411
|
-
_registerServer(addr.port, self);
|
|
3412
|
-
}
|
|
3413
|
-
if (originalCb) originalCb();
|
|
3414
|
-
};
|
|
3415
|
-
this._netServer.listen(port, host, cb);
|
|
3416
|
-
return this;
|
|
3406
|
+
return verifySync(this.algorithm, combined, keyInfo, sig);
|
|
3417
3407
|
}
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3408
|
+
}
|
|
3409
|
+
class KeyObject {
|
|
3410
|
+
_keyData;
|
|
3411
|
+
_type;
|
|
3412
|
+
_algorithm;
|
|
3413
|
+
constructor(type, keyData, algorithm){
|
|
3414
|
+
this._type = type;
|
|
3415
|
+
this._keyData = keyData;
|
|
3416
|
+
this._algorithm = algorithm;
|
|
3425
3417
|
}
|
|
3426
|
-
|
|
3427
|
-
return this.
|
|
3418
|
+
get type() {
|
|
3419
|
+
return this._type;
|
|
3428
3420
|
}
|
|
3429
|
-
|
|
3430
|
-
this.
|
|
3431
|
-
if (
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
return
|
|
3421
|
+
get asymmetricKeyType() {
|
|
3422
|
+
if (this._type === "secret") return void 0;
|
|
3423
|
+
if (this._algorithm?.includes("RSA")) return "rsa";
|
|
3424
|
+
if (this._algorithm?.includes("EC") || this._algorithm?.includes("ES")) return "ec";
|
|
3425
|
+
if (this._algorithm?.includes("Ed")) return "ed25519";
|
|
3426
|
+
return void 0;
|
|
3435
3427
|
}
|
|
3436
|
-
|
|
3437
|
-
this.
|
|
3438
|
-
|
|
3428
|
+
get symmetricKeySize() {
|
|
3429
|
+
if (this._type !== "secret") return void 0;
|
|
3430
|
+
if (this._keyData instanceof Uint8Array) {
|
|
3431
|
+
return this._keyData.length * 8;
|
|
3432
|
+
}
|
|
3433
|
+
return void 0;
|
|
3439
3434
|
}
|
|
3440
|
-
|
|
3441
|
-
this.
|
|
3442
|
-
|
|
3435
|
+
export(options) {
|
|
3436
|
+
if (this._keyData instanceof Uint8Array) {
|
|
3437
|
+
return BufferPolyfill.from(this._keyData);
|
|
3438
|
+
}
|
|
3439
|
+
throw new Error("Cannot export CryptoKey synchronously");
|
|
3443
3440
|
}
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3441
|
+
}
|
|
3442
|
+
function createSecretKey(key, encoding) {
|
|
3443
|
+
const keyBuffer = typeof key === "string" ? BufferPolyfill.from(key, encoding) : key;
|
|
3444
|
+
return new KeyObject("secret", keyBuffer);
|
|
3445
|
+
}
|
|
3446
|
+
function createPublicKey(key) {
|
|
3447
|
+
const keyInfo = extractKeyInfo(key);
|
|
3448
|
+
return new KeyObject("public", keyInfo.keyData, keyInfo.algorithm);
|
|
3449
|
+
}
|
|
3450
|
+
function createPrivateKey(key) {
|
|
3451
|
+
const keyInfo = extractKeyInfo(key);
|
|
3452
|
+
return new KeyObject("private", keyInfo.keyData, keyInfo.algorithm);
|
|
3453
|
+
}
|
|
3454
|
+
function timingSafeEqual(a, b) {
|
|
3455
|
+
if (a.length !== b.length) {
|
|
3456
|
+
return false;
|
|
3457
|
+
}
|
|
3458
|
+
let result = 0;
|
|
3459
|
+
for(let i = 0; i < a.length; i++){
|
|
3460
|
+
result |= a[i] ^ b[i];
|
|
3461
|
+
}
|
|
3462
|
+
return result === 0;
|
|
3463
|
+
}
|
|
3464
|
+
function getCiphers$1() {
|
|
3465
|
+
return [
|
|
3466
|
+
"aes-128-cbc",
|
|
3467
|
+
"aes-256-cbc",
|
|
3468
|
+
"aes-128-gcm",
|
|
3469
|
+
"aes-256-gcm"
|
|
3470
|
+
];
|
|
3471
|
+
}
|
|
3472
|
+
function getHashes() {
|
|
3473
|
+
return [
|
|
3474
|
+
"sha1",
|
|
3475
|
+
"sha256",
|
|
3476
|
+
"sha384",
|
|
3477
|
+
"sha512"
|
|
3478
|
+
];
|
|
3479
|
+
}
|
|
3480
|
+
const constants$5 = {
|
|
3481
|
+
SSL_OP_ALL: 0,
|
|
3482
|
+
RSA_PKCS1_PADDING: 1,
|
|
3483
|
+
RSA_PKCS1_OAEP_PADDING: 4,
|
|
3484
|
+
RSA_PKCS1_PSS_PADDING: 6
|
|
3485
|
+
};
|
|
3486
|
+
function normalizeHashAlgorithm(alg) {
|
|
3487
|
+
const normalized = alg.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
3488
|
+
switch(normalized){
|
|
3489
|
+
case "SHA1":
|
|
3490
|
+
return "SHA-1";
|
|
3491
|
+
case "SHA256":
|
|
3492
|
+
return "SHA-256";
|
|
3493
|
+
case "SHA384":
|
|
3494
|
+
return "SHA-384";
|
|
3495
|
+
case "SHA512":
|
|
3496
|
+
return "SHA-512";
|
|
3497
|
+
case "MD5":
|
|
3498
|
+
return "MD5";
|
|
3499
|
+
default:
|
|
3500
|
+
return alg;
|
|
3501
|
+
}
|
|
3502
|
+
}
|
|
3503
|
+
function getWebCryptoAlgorithm(nodeAlgorithm) {
|
|
3504
|
+
const alg = nodeAlgorithm.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
3505
|
+
if (alg.includes("RSA")) {
|
|
3506
|
+
if (alg.includes("PSS")) {
|
|
3507
|
+
const hash2 = alg.match(/SHA(\d+)/)?.[0] || "SHA-256";
|
|
3508
|
+
return {
|
|
3509
|
+
name: "RSA-PSS",
|
|
3510
|
+
hash: `SHA-${hash2.replace("SHA", "")}`
|
|
3511
|
+
};
|
|
3512
|
+
}
|
|
3513
|
+
const hash = alg.match(/SHA(\d+)/)?.[0] || "SHA-256";
|
|
3514
|
+
return {
|
|
3515
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
3516
|
+
hash: `SHA-${hash.replace("SHA", "")}`
|
|
3517
|
+
};
|
|
3518
|
+
}
|
|
3519
|
+
if (alg.startsWith("ES") || alg.includes("ECDSA")) {
|
|
3520
|
+
const bits = alg.match(/\d+/)?.[0] || "256";
|
|
3521
|
+
const hash = bits === "512" ? "SHA-512" : bits === "384" ? "SHA-384" : "SHA-256";
|
|
3522
|
+
return {
|
|
3523
|
+
name: "ECDSA",
|
|
3524
|
+
hash
|
|
3525
|
+
};
|
|
3526
|
+
}
|
|
3527
|
+
if (alg.includes("ED25519") || alg === "EDDSA") {
|
|
3528
|
+
return {
|
|
3529
|
+
name: "Ed25519"
|
|
3530
|
+
};
|
|
3531
|
+
}
|
|
3532
|
+
if (alg.includes("HS") || alg.includes("HMAC")) {
|
|
3533
|
+
const bits = alg.match(/\d+/)?.[0] || "256";
|
|
3534
|
+
return {
|
|
3535
|
+
name: "HMAC",
|
|
3536
|
+
hash: `SHA-${bits}`
|
|
3537
|
+
};
|
|
3538
|
+
}
|
|
3539
|
+
return {
|
|
3540
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
3541
|
+
hash: "SHA-256"
|
|
3542
|
+
};
|
|
3543
|
+
}
|
|
3544
|
+
function extractKeyInfo(key) {
|
|
3545
|
+
if (key instanceof KeyObject) {
|
|
3546
|
+
return {
|
|
3547
|
+
keyData: key._keyData,
|
|
3548
|
+
algorithm: key._algorithm,
|
|
3549
|
+
type: key._type,
|
|
3550
|
+
format: "raw"
|
|
3551
|
+
};
|
|
3552
|
+
}
|
|
3553
|
+
if (typeof key === "object" && "key" in key) {
|
|
3554
|
+
return extractKeyInfo(key.key);
|
|
3555
|
+
}
|
|
3556
|
+
const keyStr = typeof key === "string" ? key : key.toString();
|
|
3557
|
+
if (keyStr.includes("-----BEGIN")) {
|
|
3558
|
+
const isPrivate = keyStr.includes("PRIVATE");
|
|
3559
|
+
const isPublic = keyStr.includes("PUBLIC");
|
|
3560
|
+
const base64 = keyStr.replace(/-----BEGIN [^-]+-----/, "").replace(/-----END [^-]+-----/, "").replace(/\s/g, "");
|
|
3561
|
+
const keyData2 = BufferPolyfill.from(atob(base64));
|
|
3562
|
+
let algorithm;
|
|
3563
|
+
if (keyStr.includes("RSA")) algorithm = "RSA-SHA256";
|
|
3564
|
+
else if (keyStr.includes("EC")) algorithm = "ES256";
|
|
3565
|
+
else if (keyStr.includes("ED25519")) algorithm = "Ed25519";
|
|
3566
|
+
return {
|
|
3567
|
+
keyData: keyData2,
|
|
3568
|
+
algorithm,
|
|
3569
|
+
type: isPrivate ? "private" : isPublic ? "public" : "secret",
|
|
3570
|
+
format: "pem"
|
|
3571
|
+
};
|
|
3572
|
+
}
|
|
3573
|
+
const keyData = typeof key === "string" ? BufferPolyfill.from(key) : key;
|
|
3574
|
+
return {
|
|
3575
|
+
keyData,
|
|
3576
|
+
type: "secret",
|
|
3577
|
+
format: "raw"
|
|
3578
|
+
};
|
|
3579
|
+
}
|
|
3580
|
+
function concatBuffers(buffers) {
|
|
3581
|
+
const totalLength = buffers.reduce((acc, arr)=>acc + arr.length, 0);
|
|
3582
|
+
const result = new Uint8Array(totalLength);
|
|
3583
|
+
let offset = 0;
|
|
3584
|
+
for (const buf of buffers){
|
|
3585
|
+
result.set(buf, offset);
|
|
3586
|
+
offset += buf.length;
|
|
3587
|
+
}
|
|
3588
|
+
return result;
|
|
3589
|
+
}
|
|
3590
|
+
function encodeResult(data, encoding) {
|
|
3591
|
+
if (encoding === "hex") {
|
|
3592
|
+
return Array.from(data).map((b)=>b.toString(16).padStart(2, "0")).join("");
|
|
3593
|
+
}
|
|
3594
|
+
if (encoding === "base64") {
|
|
3595
|
+
return btoa(String.fromCharCode(...data));
|
|
3596
|
+
}
|
|
3597
|
+
return BufferPolyfill.from(data);
|
|
3598
|
+
}
|
|
3599
|
+
function syncHash(data, algorithm) {
|
|
3600
|
+
let size;
|
|
3601
|
+
if (algorithm.includes("512")) {
|
|
3602
|
+
size = 64;
|
|
3603
|
+
} else if (algorithm.includes("384")) {
|
|
3604
|
+
size = 48;
|
|
3605
|
+
} else if (algorithm.includes("1") || algorithm === "SHA-1") {
|
|
3606
|
+
size = 20;
|
|
3607
|
+
} else {
|
|
3608
|
+
size = 32;
|
|
3609
|
+
}
|
|
3610
|
+
const result = new Uint8Array(size);
|
|
3611
|
+
let h1 = 3735928559;
|
|
3612
|
+
let h2 = 1103547991;
|
|
3613
|
+
for(let i = 0; i < data.length; i++){
|
|
3614
|
+
h1 = Math.imul(h1 ^ data[i], 2654435761);
|
|
3615
|
+
h2 = Math.imul(h2 ^ data[i], 1597334677);
|
|
3616
|
+
}
|
|
3617
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
3618
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
3619
|
+
for(let i = 0; i < size; i++){
|
|
3620
|
+
const mix = i < size / 2 ? h1 : h2;
|
|
3621
|
+
result[i] = mix >>> i % 4 * 8 & 255;
|
|
3622
|
+
h1 = Math.imul(h1, 1103515245) + 12345;
|
|
3623
|
+
h2 = Math.imul(h2, 1103515245) + 12345;
|
|
3624
|
+
}
|
|
3625
|
+
return result;
|
|
3626
|
+
}
|
|
3627
|
+
function syncHmac(data, key, algorithm) {
|
|
3628
|
+
const combined = new Uint8Array(key.length + data.length);
|
|
3629
|
+
combined.set(key, 0);
|
|
3630
|
+
combined.set(data, key.length);
|
|
3631
|
+
return syncHash(combined, algorithm);
|
|
3632
|
+
}
|
|
3633
|
+
async function signAsync(algorithm, data, keyInfo) {
|
|
3634
|
+
const webCryptoAlg = getWebCryptoAlgorithm(algorithm);
|
|
3635
|
+
try {
|
|
3636
|
+
const cryptoKey = await importKey(keyInfo, webCryptoAlg, [
|
|
3637
|
+
"sign"
|
|
3638
|
+
]);
|
|
3639
|
+
const signatureAlg = webCryptoAlg.hash ? {
|
|
3640
|
+
name: webCryptoAlg.name,
|
|
3641
|
+
hash: webCryptoAlg.hash
|
|
3642
|
+
} : {
|
|
3643
|
+
name: webCryptoAlg.name
|
|
3644
|
+
};
|
|
3645
|
+
const dataBuffer = new Uint8Array(data).buffer;
|
|
3646
|
+
const signature = await crypto.subtle.sign(signatureAlg, cryptoKey, dataBuffer);
|
|
3647
|
+
return BufferPolyfill.from(signature);
|
|
3648
|
+
} catch (error) {
|
|
3649
|
+
console.warn("WebCrypto sign failed, using fallback:", error);
|
|
3650
|
+
return signSync(algorithm, data, keyInfo);
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
async function verifyAsync(algorithm, data, keyInfo, signature) {
|
|
3654
|
+
const webCryptoAlg = getWebCryptoAlgorithm(algorithm);
|
|
3655
|
+
try {
|
|
3656
|
+
const cryptoKey = await importKey(keyInfo, webCryptoAlg, [
|
|
3657
|
+
"verify"
|
|
3658
|
+
]);
|
|
3659
|
+
const verifyAlg = webCryptoAlg.hash ? {
|
|
3660
|
+
name: webCryptoAlg.name,
|
|
3661
|
+
hash: webCryptoAlg.hash
|
|
3662
|
+
} : {
|
|
3663
|
+
name: webCryptoAlg.name
|
|
3664
|
+
};
|
|
3665
|
+
const sigBuffer = new Uint8Array(signature).buffer;
|
|
3666
|
+
const dataBuffer = new Uint8Array(data).buffer;
|
|
3667
|
+
return await crypto.subtle.verify(verifyAlg, cryptoKey, sigBuffer, dataBuffer);
|
|
3668
|
+
} catch (error) {
|
|
3669
|
+
console.warn("WebCrypto verify failed, using fallback:", error);
|
|
3670
|
+
return verifySync(algorithm, data, keyInfo, signature);
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
function signSync(algorithm, data, keyInfo) {
|
|
3674
|
+
const keyData = keyInfo.keyData instanceof Uint8Array ? keyInfo.keyData : new Uint8Array(0);
|
|
3675
|
+
const combined = new Uint8Array(keyData.length + data.length);
|
|
3676
|
+
combined.set(keyData, 0);
|
|
3677
|
+
combined.set(data, keyData.length);
|
|
3678
|
+
const hash = syncHash(combined, algorithm);
|
|
3679
|
+
return BufferPolyfill.from(hash);
|
|
3680
|
+
}
|
|
3681
|
+
function verifySync(algorithm, data, keyInfo, signature) {
|
|
3682
|
+
const expectedSig = signSync(algorithm, data, keyInfo);
|
|
3683
|
+
return timingSafeEqual(BufferPolyfill.from(signature), expectedSig);
|
|
3684
|
+
}
|
|
3685
|
+
async function importKey(keyInfo, algorithm, usages) {
|
|
3686
|
+
if (keyInfo.keyData instanceof CryptoKey) {
|
|
3687
|
+
return keyInfo.keyData;
|
|
3688
|
+
}
|
|
3689
|
+
const keyData = keyInfo.keyData;
|
|
3690
|
+
const keyBuffer = new Uint8Array(keyData).buffer;
|
|
3691
|
+
if (keyInfo.format === "pem") {
|
|
3692
|
+
const format = keyInfo.type === "private" ? "pkcs8" : "spki";
|
|
3693
|
+
const importAlg = algorithm.name === "ECDSA" ? {
|
|
3694
|
+
name: "ECDSA",
|
|
3695
|
+
namedCurve: "P-256"
|
|
3696
|
+
} : algorithm.name === "Ed25519" ? {
|
|
3697
|
+
name: "Ed25519"
|
|
3698
|
+
} : {
|
|
3699
|
+
name: algorithm.name,
|
|
3700
|
+
hash: algorithm.hash || "SHA-256"
|
|
3701
|
+
};
|
|
3702
|
+
return await crypto.subtle.importKey(format, keyBuffer, importAlg, true, usages);
|
|
3703
|
+
}
|
|
3704
|
+
if (keyInfo.type === "secret") {
|
|
3705
|
+
return await crypto.subtle.importKey("raw", keyBuffer, {
|
|
3706
|
+
name: algorithm.name,
|
|
3707
|
+
hash: algorithm.hash
|
|
3708
|
+
}, true, usages);
|
|
3709
|
+
}
|
|
3710
|
+
throw new Error(`Unsupported key format: ${keyInfo.format}`);
|
|
3711
|
+
}
|
|
3712
|
+
var crypto$1 = {
|
|
3713
|
+
randomBytes,
|
|
3714
|
+
randomFillSync,
|
|
3715
|
+
randomUUID,
|
|
3716
|
+
randomInt,
|
|
3717
|
+
getRandomValues,
|
|
3718
|
+
createHash,
|
|
3719
|
+
createHmac,
|
|
3720
|
+
createSign,
|
|
3721
|
+
createVerify,
|
|
3722
|
+
sign,
|
|
3723
|
+
verify,
|
|
3724
|
+
pbkdf2,
|
|
3725
|
+
pbkdf2Sync,
|
|
3726
|
+
timingSafeEqual,
|
|
3727
|
+
getCiphers: getCiphers$1,
|
|
3728
|
+
getHashes,
|
|
3729
|
+
constants: constants$5,
|
|
3730
|
+
KeyObject,
|
|
3731
|
+
createSecretKey,
|
|
3732
|
+
createPublicKey,
|
|
3733
|
+
createPrivateKey
|
|
3734
|
+
};
|
|
3735
|
+
var cryptoShim = Object.freeze({
|
|
3736
|
+
__proto__: null,
|
|
3737
|
+
KeyObject: KeyObject,
|
|
3738
|
+
constants: constants$5,
|
|
3739
|
+
createHash: createHash,
|
|
3740
|
+
createHmac: createHmac,
|
|
3741
|
+
createPrivateKey: createPrivateKey,
|
|
3742
|
+
createPublicKey: createPublicKey,
|
|
3743
|
+
createSecretKey: createSecretKey,
|
|
3744
|
+
createSign: createSign,
|
|
3745
|
+
createVerify: createVerify,
|
|
3746
|
+
default: crypto$1,
|
|
3747
|
+
getCiphers: getCiphers$1,
|
|
3748
|
+
getHashes: getHashes,
|
|
3749
|
+
getRandomValues: getRandomValues,
|
|
3750
|
+
pbkdf2: pbkdf2,
|
|
3751
|
+
pbkdf2Sync: pbkdf2Sync,
|
|
3752
|
+
randomBytes: randomBytes,
|
|
3753
|
+
randomFillSync: randomFillSync,
|
|
3754
|
+
randomInt: randomInt,
|
|
3755
|
+
randomUUID: randomUUID,
|
|
3756
|
+
sign: sign,
|
|
3757
|
+
timingSafeEqual: timingSafeEqual,
|
|
3758
|
+
verify: verify
|
|
3759
|
+
});
|
|
3760
|
+
const _BrowserWebSocket = typeof globalThis.WebSocket === "function" ? globalThis.WebSocket : null;
|
|
3761
|
+
class IncomingMessage extends Readable {
|
|
3762
|
+
httpVersion = "1.1";
|
|
3763
|
+
httpVersionMajor = 1;
|
|
3764
|
+
httpVersionMinor = 1;
|
|
3765
|
+
complete = false;
|
|
3766
|
+
headers = {};
|
|
3767
|
+
rawHeaders = [];
|
|
3768
|
+
trailers = {};
|
|
3769
|
+
rawTrailers = [];
|
|
3770
|
+
method;
|
|
3771
|
+
url;
|
|
3772
|
+
statusCode;
|
|
3773
|
+
statusMessage;
|
|
3774
|
+
socket;
|
|
3775
|
+
_body = null;
|
|
3776
|
+
constructor(socket){
|
|
3777
|
+
super();
|
|
3778
|
+
this.socket = socket || new Socket$1();
|
|
3779
|
+
}
|
|
3780
|
+
setTimeout(msecs, callback) {
|
|
3781
|
+
if (callback) {
|
|
3782
|
+
this.once("timeout", callback);
|
|
3783
|
+
}
|
|
3784
|
+
return this;
|
|
3785
|
+
}
|
|
3786
|
+
destroy(error) {
|
|
3787
|
+
super.destroy(error);
|
|
3788
|
+
return this;
|
|
3789
|
+
}
|
|
3790
|
+
_setBody(body) {
|
|
3791
|
+
if (body === null) {
|
|
3792
|
+
this._body = null;
|
|
3793
|
+
} else {
|
|
3794
|
+
this._body = typeof body === "string" ? BufferPolyfill.from(body) : body;
|
|
3795
|
+
}
|
|
3796
|
+
if (this._body) {
|
|
3797
|
+
this.push(this._body);
|
|
3798
|
+
}
|
|
3799
|
+
this.push(null);
|
|
3800
|
+
this.complete = true;
|
|
3801
|
+
}
|
|
3802
|
+
static fromRequest(method, url, headers, body) {
|
|
3803
|
+
const msg = new IncomingMessage();
|
|
3804
|
+
msg.method = method;
|
|
3805
|
+
msg.url = url;
|
|
3806
|
+
msg.headers = {
|
|
3807
|
+
...headers
|
|
3808
|
+
};
|
|
3809
|
+
for (const [key, value] of Object.entries(headers)){
|
|
3810
|
+
msg.rawHeaders.push(key, value);
|
|
3811
|
+
}
|
|
3812
|
+
if (body) {
|
|
3813
|
+
msg._setBody(body);
|
|
3814
|
+
} else {
|
|
3815
|
+
msg.push(null);
|
|
3816
|
+
msg.complete = true;
|
|
3817
|
+
}
|
|
3818
|
+
return msg;
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
class ServerResponse extends Writable {
|
|
3822
|
+
statusCode = 200;
|
|
3823
|
+
statusMessage = "OK";
|
|
3824
|
+
headersSent = false;
|
|
3825
|
+
finished = false;
|
|
3826
|
+
sendDate = true;
|
|
3827
|
+
socket;
|
|
3828
|
+
_headers = new Map();
|
|
3829
|
+
_body = [];
|
|
3830
|
+
_resolve;
|
|
3831
|
+
constructor(req){
|
|
3832
|
+
super();
|
|
3833
|
+
this.socket = req.socket;
|
|
3834
|
+
}
|
|
3835
|
+
_setResolver(resolve) {
|
|
3836
|
+
this._resolve = resolve;
|
|
3837
|
+
}
|
|
3838
|
+
setHeader(name, value) {
|
|
3839
|
+
if (this.headersSent) {
|
|
3840
|
+
throw new Error("Cannot set headers after they are sent");
|
|
3841
|
+
}
|
|
3842
|
+
this._headers.set(name.toLowerCase(), String(value));
|
|
3843
|
+
return this;
|
|
3844
|
+
}
|
|
3845
|
+
getHeader(name) {
|
|
3846
|
+
return this._headers.get(name.toLowerCase());
|
|
3847
|
+
}
|
|
3848
|
+
getHeaders() {
|
|
3849
|
+
const headers = {};
|
|
3850
|
+
for (const [key, value] of this._headers){
|
|
3851
|
+
headers[key] = value;
|
|
3852
|
+
}
|
|
3853
|
+
return headers;
|
|
3854
|
+
}
|
|
3855
|
+
getHeaderNames() {
|
|
3856
|
+
return [
|
|
3857
|
+
...this._headers.keys()
|
|
3858
|
+
];
|
|
3859
|
+
}
|
|
3860
|
+
hasHeader(name) {
|
|
3861
|
+
return this._headers.has(name.toLowerCase());
|
|
3862
|
+
}
|
|
3863
|
+
removeHeader(name) {
|
|
3864
|
+
if (this.headersSent) {
|
|
3865
|
+
throw new Error("Cannot remove headers after they are sent");
|
|
3866
|
+
}
|
|
3867
|
+
this._headers.delete(name.toLowerCase());
|
|
3868
|
+
}
|
|
3869
|
+
writeHead(statusCode, statusMessageOrHeaders, headers) {
|
|
3870
|
+
this.statusCode = statusCode;
|
|
3871
|
+
if (typeof statusMessageOrHeaders === "string") {
|
|
3872
|
+
this.statusMessage = statusMessageOrHeaders;
|
|
3873
|
+
if (headers) {
|
|
3874
|
+
for (const [key, value] of Object.entries(headers)){
|
|
3875
|
+
this.setHeader(key, value);
|
|
3876
|
+
}
|
|
3877
|
+
}
|
|
3878
|
+
} else if (statusMessageOrHeaders) {
|
|
3879
|
+
for (const [key, value] of Object.entries(statusMessageOrHeaders)){
|
|
3880
|
+
this.setHeader(key, value);
|
|
3881
|
+
}
|
|
3882
|
+
}
|
|
3883
|
+
return this;
|
|
3884
|
+
}
|
|
3885
|
+
write(chunk, encodingOrCallback, callback) {
|
|
3886
|
+
this.headersSent = true;
|
|
3887
|
+
const buffer = typeof chunk === "string" ? BufferPolyfill.from(chunk) : chunk;
|
|
3888
|
+
this._body.push(buffer);
|
|
3889
|
+
const cb = typeof encodingOrCallback === "function" ? encodingOrCallback : callback;
|
|
3890
|
+
if (cb) {
|
|
3891
|
+
queueMicrotask(()=>cb(null));
|
|
3892
|
+
}
|
|
3893
|
+
return true;
|
|
3894
|
+
}
|
|
3895
|
+
end(chunkOrCallback, encodingOrCallback, callback) {
|
|
3896
|
+
if (typeof chunkOrCallback === "function") {
|
|
3897
|
+
callback = chunkOrCallback;
|
|
3898
|
+
} else if (chunkOrCallback !== void 0) {
|
|
3899
|
+
this.write(chunkOrCallback);
|
|
3900
|
+
}
|
|
3901
|
+
if (typeof encodingOrCallback === "function") {
|
|
3902
|
+
callback = encodingOrCallback;
|
|
3903
|
+
}
|
|
3904
|
+
this.headersSent = true;
|
|
3905
|
+
this.finished = true;
|
|
3906
|
+
if (this._resolve) {
|
|
3907
|
+
const headers = {};
|
|
3908
|
+
for (const [key, value] of this._headers){
|
|
3909
|
+
headers[key] = Array.isArray(value) ? value.join(", ") : value;
|
|
3910
|
+
}
|
|
3911
|
+
this._resolve({
|
|
3912
|
+
statusCode: this.statusCode,
|
|
3913
|
+
statusMessage: this.statusMessage,
|
|
3914
|
+
headers,
|
|
3915
|
+
body: BufferPolyfill.concat(this._body)
|
|
3916
|
+
});
|
|
3917
|
+
}
|
|
3918
|
+
queueMicrotask(()=>{
|
|
3919
|
+
this.emit("finish");
|
|
3920
|
+
if (callback) callback();
|
|
3921
|
+
});
|
|
3922
|
+
return this;
|
|
3923
|
+
}
|
|
3924
|
+
send(data) {
|
|
3925
|
+
if (typeof data === "object" && !BufferPolyfill.isBuffer(data)) {
|
|
3926
|
+
this.setHeader("Content-Type", "application/json");
|
|
3927
|
+
data = JSON.stringify(data);
|
|
3928
|
+
}
|
|
3929
|
+
if (!this.hasHeader("Content-Type")) {
|
|
3930
|
+
this.setHeader("Content-Type", "text/html");
|
|
3931
|
+
}
|
|
3932
|
+
this.write(typeof data === "string" ? data : data);
|
|
3933
|
+
return this.end();
|
|
3934
|
+
}
|
|
3935
|
+
json(data) {
|
|
3936
|
+
this.setHeader("Content-Type", "application/json");
|
|
3937
|
+
return this.end(JSON.stringify(data));
|
|
3938
|
+
}
|
|
3939
|
+
status(code) {
|
|
3940
|
+
this.statusCode = code;
|
|
3941
|
+
return this;
|
|
3942
|
+
}
|
|
3943
|
+
redirect(urlOrStatus, url) {
|
|
3944
|
+
if (typeof urlOrStatus === "number") {
|
|
3945
|
+
this.statusCode = urlOrStatus;
|
|
3946
|
+
this.setHeader("Location", url);
|
|
3947
|
+
} else {
|
|
3948
|
+
this.statusCode = 302;
|
|
3949
|
+
this.setHeader("Location", urlOrStatus);
|
|
3950
|
+
}
|
|
3951
|
+
this.end();
|
|
3952
|
+
}
|
|
3953
|
+
_getBody() {
|
|
3954
|
+
return BufferPolyfill.concat(this._body);
|
|
3955
|
+
}
|
|
3956
|
+
_getBodyAsString() {
|
|
3957
|
+
return this._getBody().toString("utf8");
|
|
3958
|
+
}
|
|
3959
|
+
}
|
|
3960
|
+
let Server$2 = class Server extends EventEmitter {
|
|
3961
|
+
_netServer;
|
|
3962
|
+
_requestListener;
|
|
3963
|
+
_pendingRequests = new Map();
|
|
3964
|
+
listening = false;
|
|
3965
|
+
maxHeadersCount = null;
|
|
3966
|
+
timeout = 0;
|
|
3967
|
+
keepAliveTimeout = 5e3;
|
|
3968
|
+
headersTimeout = 6e4;
|
|
3969
|
+
requestTimeout = 0;
|
|
3970
|
+
constructor(requestListener){
|
|
3971
|
+
super();
|
|
3972
|
+
this._requestListener = requestListener;
|
|
3973
|
+
this._netServer = new Server$3();
|
|
3974
|
+
this._netServer.on("listening", ()=>{
|
|
3975
|
+
this.listening = true;
|
|
3976
|
+
this.emit("listening");
|
|
3977
|
+
});
|
|
3978
|
+
this._netServer.on("close", ()=>{
|
|
3979
|
+
this.listening = false;
|
|
3980
|
+
this.emit("close");
|
|
3981
|
+
});
|
|
3982
|
+
this._netServer.on("error", (err)=>{
|
|
3983
|
+
this.emit("error", err);
|
|
3984
|
+
});
|
|
3985
|
+
}
|
|
3986
|
+
listen(portOrOptions, hostOrCallback, callback) {
|
|
3987
|
+
let port;
|
|
3988
|
+
let host;
|
|
3989
|
+
let cb;
|
|
3990
|
+
if (typeof portOrOptions === "number") {
|
|
3991
|
+
port = portOrOptions;
|
|
3992
|
+
if (typeof hostOrCallback === "string") {
|
|
3993
|
+
host = hostOrCallback;
|
|
3994
|
+
cb = callback;
|
|
3995
|
+
} else {
|
|
3996
|
+
cb = hostOrCallback;
|
|
3997
|
+
}
|
|
3998
|
+
} else if (portOrOptions) {
|
|
3999
|
+
port = portOrOptions.port;
|
|
4000
|
+
host = portOrOptions.host;
|
|
4001
|
+
cb = typeof hostOrCallback === "function" ? hostOrCallback : callback;
|
|
4002
|
+
}
|
|
4003
|
+
const originalCb = cb;
|
|
4004
|
+
const self = this;
|
|
4005
|
+
cb = function() {
|
|
4006
|
+
const addr = self._netServer.address();
|
|
4007
|
+
if (addr) {
|
|
4008
|
+
_registerServer(addr.port, self);
|
|
4009
|
+
}
|
|
4010
|
+
if (originalCb) originalCb();
|
|
4011
|
+
};
|
|
4012
|
+
this._netServer.listen(port, host, cb);
|
|
4013
|
+
return this;
|
|
4014
|
+
}
|
|
4015
|
+
close(callback) {
|
|
4016
|
+
const addr = this._netServer.address();
|
|
4017
|
+
if (addr) {
|
|
4018
|
+
_unregisterServer(addr.port);
|
|
4019
|
+
}
|
|
4020
|
+
this._netServer.close(callback);
|
|
4021
|
+
return this;
|
|
4022
|
+
}
|
|
4023
|
+
address() {
|
|
4024
|
+
return this._netServer.address();
|
|
4025
|
+
}
|
|
4026
|
+
setTimeout(msecs, callback) {
|
|
4027
|
+
this.timeout = msecs || 0;
|
|
4028
|
+
if (callback) {
|
|
4029
|
+
this.on("timeout", callback);
|
|
4030
|
+
}
|
|
4031
|
+
return this;
|
|
4032
|
+
}
|
|
4033
|
+
ref() {
|
|
4034
|
+
this._netServer.ref();
|
|
4035
|
+
return this;
|
|
4036
|
+
}
|
|
4037
|
+
unref() {
|
|
4038
|
+
this._netServer.unref();
|
|
4039
|
+
return this;
|
|
4040
|
+
}
|
|
4041
|
+
async handleRequest(method, url, headers, body) {
|
|
4042
|
+
return new Promise((resolve, reject)=>{
|
|
4043
|
+
const req = IncomingMessage.fromRequest(method, url, headers, body);
|
|
4044
|
+
const res = new ServerResponse(req);
|
|
4045
|
+
res._setResolver(resolve);
|
|
4046
|
+
const timeoutId = this.timeout ? setTimeout(()=>{
|
|
4047
|
+
reject(new Error("Request timeout"));
|
|
4048
|
+
}, this.timeout) : null;
|
|
4049
|
+
res.on("finish", ()=>{
|
|
3453
4050
|
if (timeoutId) clearTimeout(timeoutId);
|
|
3454
4051
|
});
|
|
3455
4052
|
try {
|
|
@@ -3584,10 +4181,22 @@
|
|
|
3584
4181
|
if (this._aborted) return;
|
|
3585
4182
|
try {
|
|
3586
4183
|
const protocol = this._protocol === "https" ? "https:" : "http:";
|
|
3587
|
-
|
|
3588
|
-
|
|
4184
|
+
let hostname = this._options.hostname || "";
|
|
4185
|
+
let port = this._options.port ? `:${this._options.port}` : "";
|
|
4186
|
+
if (!hostname && this._options.host) {
|
|
4187
|
+
const hostParts = this._options.host.split(":");
|
|
4188
|
+
hostname = hostParts[0];
|
|
4189
|
+
if (!port && hostParts[1]) {
|
|
4190
|
+
port = `:${hostParts[1]}`;
|
|
4191
|
+
}
|
|
4192
|
+
}
|
|
4193
|
+
if (!hostname) hostname = "localhost";
|
|
3589
4194
|
const path = this._options.path || "/";
|
|
3590
4195
|
const url = `${protocol}//${hostname}${port}${path}`;
|
|
4196
|
+
if (this.headers["upgrade"]?.toLowerCase() === "websocket") {
|
|
4197
|
+
this._handleWebSocketUpgrade(url);
|
|
4198
|
+
return;
|
|
4199
|
+
}
|
|
3591
4200
|
const corsProxy = getCorsProxy();
|
|
3592
4201
|
const fetchUrl = corsProxy ? corsProxy + encodeURIComponent(url) : url;
|
|
3593
4202
|
const fetchOptions = {
|
|
@@ -3621,20 +4230,134 @@
|
|
|
3621
4230
|
if (error instanceof Error && error.name === "AbortError") {
|
|
3622
4231
|
return;
|
|
3623
4232
|
}
|
|
3624
|
-
this.emit("error", error);
|
|
3625
|
-
}
|
|
3626
|
-
}
|
|
3627
|
-
async _responseToIncomingMessage(response) {
|
|
3628
|
-
const msg = new IncomingMessage();
|
|
3629
|
-
msg.statusCode = response.status;
|
|
3630
|
-
msg.statusMessage = response.statusText || STATUS_CODES[response.status] || "";
|
|
3631
|
-
response.headers.forEach((value, key)=>{
|
|
3632
|
-
msg.headers[key.toLowerCase()] = value;
|
|
3633
|
-
msg.rawHeaders.push(key, value);
|
|
3634
|
-
});
|
|
3635
|
-
const body = await response.arrayBuffer();
|
|
3636
|
-
msg._setBody(BufferPolyfill.from(body));
|
|
3637
|
-
return msg;
|
|
4233
|
+
this.emit("error", error);
|
|
4234
|
+
}
|
|
4235
|
+
}
|
|
4236
|
+
async _responseToIncomingMessage(response) {
|
|
4237
|
+
const msg = new IncomingMessage();
|
|
4238
|
+
msg.statusCode = response.status;
|
|
4239
|
+
msg.statusMessage = response.statusText || STATUS_CODES[response.status] || "";
|
|
4240
|
+
response.headers.forEach((value, key)=>{
|
|
4241
|
+
msg.headers[key.toLowerCase()] = value;
|
|
4242
|
+
msg.rawHeaders.push(key, value);
|
|
4243
|
+
});
|
|
4244
|
+
const body = await response.arrayBuffer();
|
|
4245
|
+
msg._setBody(BufferPolyfill.from(body));
|
|
4246
|
+
return msg;
|
|
4247
|
+
}
|
|
4248
|
+
_handleWebSocketUpgrade(url) {
|
|
4249
|
+
const wsUrl = url.replace(/^https:/, "wss:").replace(/^http:/, "ws:");
|
|
4250
|
+
const wsKey = this.headers["sec-websocket-key"] || "";
|
|
4251
|
+
const NativeWS = _BrowserWebSocket;
|
|
4252
|
+
if (!NativeWS) {
|
|
4253
|
+
setTimeout(()=>{
|
|
4254
|
+
this.emit("error", new TypeError("Failed to fetch"));
|
|
4255
|
+
}, 0);
|
|
4256
|
+
return;
|
|
4257
|
+
}
|
|
4258
|
+
const GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
4259
|
+
const acceptValue = createHash("sha1").update(wsKey + GUID).digest("base64");
|
|
4260
|
+
let nativeWs;
|
|
4261
|
+
try {
|
|
4262
|
+
nativeWs = new NativeWS(wsUrl);
|
|
4263
|
+
nativeWs.binaryType = "arraybuffer";
|
|
4264
|
+
} catch (e) {
|
|
4265
|
+
setTimeout(()=>{
|
|
4266
|
+
this.emit("error", e instanceof Error ? e : new Error(String(e)));
|
|
4267
|
+
}, 0);
|
|
4268
|
+
return;
|
|
4269
|
+
}
|
|
4270
|
+
const socket = new Socket$1();
|
|
4271
|
+
if (typeof socket.cork !== "function") socket.cork = ()=>{};
|
|
4272
|
+
if (typeof socket.uncork !== "function") socket.uncork = ()=>{};
|
|
4273
|
+
socket._readableState = {
|
|
4274
|
+
endEmitted: false
|
|
4275
|
+
};
|
|
4276
|
+
socket._writableState = {
|
|
4277
|
+
finished: false,
|
|
4278
|
+
errorEmitted: false
|
|
4279
|
+
};
|
|
4280
|
+
let writeBuffer = new Uint8Array(0);
|
|
4281
|
+
socket.write = (chunk, encodingOrCallback, callback)=>{
|
|
4282
|
+
const data = typeof chunk === "string" ? BufferPolyfill.from(chunk) : new Uint8Array(chunk);
|
|
4283
|
+
const cb = typeof encodingOrCallback === "function" ? encodingOrCallback : callback;
|
|
4284
|
+
const newBuf = new Uint8Array(writeBuffer.length + data.length);
|
|
4285
|
+
newBuf.set(writeBuffer, 0);
|
|
4286
|
+
newBuf.set(data, writeBuffer.length);
|
|
4287
|
+
writeBuffer = newBuf;
|
|
4288
|
+
while(writeBuffer.length >= 2){
|
|
4289
|
+
const parsed = _parseWsFrame(writeBuffer);
|
|
4290
|
+
if (!parsed) break;
|
|
4291
|
+
const { opcode, payload, totalLength } = parsed;
|
|
4292
|
+
writeBuffer = writeBuffer.slice(totalLength);
|
|
4293
|
+
if (nativeWs.readyState !== NativeWS.OPEN) continue;
|
|
4294
|
+
if (opcode === 8) {
|
|
4295
|
+
nativeWs.close();
|
|
4296
|
+
} else if (opcode === 9) {
|
|
4297
|
+
nativeWs.send(payload);
|
|
4298
|
+
} else if (opcode === 10) ;
|
|
4299
|
+
else if (opcode === 1) {
|
|
4300
|
+
const text = new TextDecoder().decode(payload);
|
|
4301
|
+
nativeWs.send(text);
|
|
4302
|
+
} else if (opcode === 2) {
|
|
4303
|
+
nativeWs.send(payload);
|
|
4304
|
+
}
|
|
4305
|
+
}
|
|
4306
|
+
if (cb) queueMicrotask(()=>cb(null));
|
|
4307
|
+
return true;
|
|
4308
|
+
};
|
|
4309
|
+
nativeWs.onopen = ()=>{
|
|
4310
|
+
const response = new IncomingMessage(socket);
|
|
4311
|
+
response.statusCode = 101;
|
|
4312
|
+
response.statusMessage = "Switching Protocols";
|
|
4313
|
+
response.headers = {
|
|
4314
|
+
"upgrade": "websocket",
|
|
4315
|
+
"connection": "Upgrade",
|
|
4316
|
+
"sec-websocket-accept": acceptValue
|
|
4317
|
+
};
|
|
4318
|
+
response.complete = true;
|
|
4319
|
+
response.push(null);
|
|
4320
|
+
this.emit("upgrade", response, socket, BufferPolyfill.alloc(0));
|
|
4321
|
+
};
|
|
4322
|
+
nativeWs.onmessage = (event)=>{
|
|
4323
|
+
let payload;
|
|
4324
|
+
let opcode;
|
|
4325
|
+
if (typeof event.data === "string") {
|
|
4326
|
+
payload = new TextEncoder().encode(event.data);
|
|
4327
|
+
opcode = 1;
|
|
4328
|
+
} else if (event.data instanceof ArrayBuffer) {
|
|
4329
|
+
payload = new Uint8Array(event.data);
|
|
4330
|
+
opcode = 2;
|
|
4331
|
+
} else {
|
|
4332
|
+
return;
|
|
4333
|
+
}
|
|
4334
|
+
const frame = _createWsFrame(opcode, payload, false);
|
|
4335
|
+
socket._receiveData(BufferPolyfill.from(frame));
|
|
4336
|
+
};
|
|
4337
|
+
nativeWs.onclose = (event)=>{
|
|
4338
|
+
const code = event.code || 1e3;
|
|
4339
|
+
const closePayload = new Uint8Array(2);
|
|
4340
|
+
closePayload[0] = code >> 8 & 255;
|
|
4341
|
+
closePayload[1] = code & 255;
|
|
4342
|
+
const frame = _createWsFrame(8, closePayload, false);
|
|
4343
|
+
socket._receiveData(BufferPolyfill.from(frame));
|
|
4344
|
+
setTimeout(()=>{
|
|
4345
|
+
socket._readableState.endEmitted = true;
|
|
4346
|
+
socket._receiveEnd();
|
|
4347
|
+
socket.emit("close", false);
|
|
4348
|
+
}, 10);
|
|
4349
|
+
};
|
|
4350
|
+
nativeWs.onerror = ()=>{
|
|
4351
|
+
socket.emit("error", new Error("WebSocket connection error"));
|
|
4352
|
+
socket.destroy();
|
|
4353
|
+
};
|
|
4354
|
+
const origDestroy = socket.destroy.bind(socket);
|
|
4355
|
+
socket.destroy = (error)=>{
|
|
4356
|
+
if (nativeWs.readyState === NativeWS.OPEN || nativeWs.readyState === NativeWS.CONNECTING) {
|
|
4357
|
+
nativeWs.close();
|
|
4358
|
+
}
|
|
4359
|
+
return origDestroy(error);
|
|
4360
|
+
};
|
|
3638
4361
|
}
|
|
3639
4362
|
}
|
|
3640
4363
|
function parseRequestArgs(urlOrOptions, optionsOrCallback, callback) {
|
|
@@ -3760,6 +4483,94 @@
|
|
|
3760
4483
|
}
|
|
3761
4484
|
}
|
|
3762
4485
|
const globalAgent = new Agent();
|
|
4486
|
+
function _parseWsFrame(data) {
|
|
4487
|
+
if (data.length < 2) return null;
|
|
4488
|
+
const opcode = data[0] & 15;
|
|
4489
|
+
const masked = (data[1] & 128) !== 0;
|
|
4490
|
+
let payloadLength = data[1] & 127;
|
|
4491
|
+
let offset = 2;
|
|
4492
|
+
if (payloadLength === 126) {
|
|
4493
|
+
if (data.length < 4) return null;
|
|
4494
|
+
payloadLength = data[2] << 8 | data[3];
|
|
4495
|
+
offset = 4;
|
|
4496
|
+
} else if (payloadLength === 127) {
|
|
4497
|
+
if (data.length < 10) return null;
|
|
4498
|
+
payloadLength = data[6] << 24 | data[7] << 16 | data[8] << 8 | data[9];
|
|
4499
|
+
offset = 10;
|
|
4500
|
+
}
|
|
4501
|
+
if (masked) {
|
|
4502
|
+
if (data.length < offset + 4 + payloadLength) return null;
|
|
4503
|
+
const maskKey = data.slice(offset, offset + 4);
|
|
4504
|
+
offset += 4;
|
|
4505
|
+
const payload = new Uint8Array(payloadLength);
|
|
4506
|
+
for(let i = 0; i < payloadLength; i++){
|
|
4507
|
+
payload[i] = data[offset + i] ^ maskKey[i % 4];
|
|
4508
|
+
}
|
|
4509
|
+
return {
|
|
4510
|
+
opcode,
|
|
4511
|
+
payload,
|
|
4512
|
+
totalLength: offset + payloadLength
|
|
4513
|
+
};
|
|
4514
|
+
} else {
|
|
4515
|
+
if (data.length < offset + payloadLength) return null;
|
|
4516
|
+
const payload = data.slice(offset, offset + payloadLength);
|
|
4517
|
+
return {
|
|
4518
|
+
opcode,
|
|
4519
|
+
payload,
|
|
4520
|
+
totalLength: offset + payloadLength
|
|
4521
|
+
};
|
|
4522
|
+
}
|
|
4523
|
+
}
|
|
4524
|
+
function _createWsFrame(opcode, payload, masked) {
|
|
4525
|
+
const length = payload.length;
|
|
4526
|
+
let headerSize = 2;
|
|
4527
|
+
if (length > 125 && length <= 65535) {
|
|
4528
|
+
headerSize += 2;
|
|
4529
|
+
} else if (length > 65535) {
|
|
4530
|
+
headerSize += 8;
|
|
4531
|
+
}
|
|
4532
|
+
if (masked) {
|
|
4533
|
+
headerSize += 4;
|
|
4534
|
+
}
|
|
4535
|
+
const frame = new Uint8Array(headerSize + length);
|
|
4536
|
+
frame[0] = 128 | opcode;
|
|
4537
|
+
let offset = 2;
|
|
4538
|
+
if (length <= 125) {
|
|
4539
|
+
frame[1] = (masked ? 128 : 0) | length;
|
|
4540
|
+
} else if (length <= 65535) {
|
|
4541
|
+
frame[1] = (masked ? 128 : 0) | 126;
|
|
4542
|
+
frame[2] = length >> 8 & 255;
|
|
4543
|
+
frame[3] = length & 255;
|
|
4544
|
+
offset = 4;
|
|
4545
|
+
} else {
|
|
4546
|
+
frame[1] = (masked ? 128 : 0) | 127;
|
|
4547
|
+
frame[2] = 0;
|
|
4548
|
+
frame[3] = 0;
|
|
4549
|
+
frame[4] = 0;
|
|
4550
|
+
frame[5] = 0;
|
|
4551
|
+
frame[6] = length >> 24 & 255;
|
|
4552
|
+
frame[7] = length >> 16 & 255;
|
|
4553
|
+
frame[8] = length >> 8 & 255;
|
|
4554
|
+
frame[9] = length & 255;
|
|
4555
|
+
offset = 10;
|
|
4556
|
+
}
|
|
4557
|
+
if (masked) {
|
|
4558
|
+
const maskKey = new Uint8Array(4);
|
|
4559
|
+
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
4560
|
+
crypto.getRandomValues(maskKey);
|
|
4561
|
+
} else {
|
|
4562
|
+
for(let i = 0; i < 4; i++)maskKey[i] = Math.floor(Math.random() * 256);
|
|
4563
|
+
}
|
|
4564
|
+
frame.set(maskKey, offset);
|
|
4565
|
+
offset += 4;
|
|
4566
|
+
for(let i = 0; i < length; i++){
|
|
4567
|
+
frame[offset + i] = payload[i] ^ maskKey[i % 4];
|
|
4568
|
+
}
|
|
4569
|
+
} else {
|
|
4570
|
+
frame.set(payload, offset);
|
|
4571
|
+
}
|
|
4572
|
+
return frame;
|
|
4573
|
+
}
|
|
3763
4574
|
var http = {
|
|
3764
4575
|
Server: Server$2,
|
|
3765
4576
|
IncomingMessage,
|
|
@@ -3776,7 +4587,9 @@
|
|
|
3776
4587
|
setServerCloseCallback,
|
|
3777
4588
|
_createClientRequest,
|
|
3778
4589
|
Agent,
|
|
3779
|
-
globalAgent
|
|
4590
|
+
globalAgent,
|
|
4591
|
+
_parseWsFrame,
|
|
4592
|
+
_createWsFrame
|
|
3780
4593
|
};
|
|
3781
4594
|
var httpShim = Object.freeze({
|
|
3782
4595
|
__proto__: null,
|
|
@@ -3788,6 +4601,8 @@
|
|
|
3788
4601
|
Server: Server$2,
|
|
3789
4602
|
ServerResponse: ServerResponse,
|
|
3790
4603
|
_createClientRequest: _createClientRequest,
|
|
4604
|
+
_createWsFrame: _createWsFrame,
|
|
4605
|
+
_parseWsFrame: _parseWsFrame,
|
|
3791
4606
|
_registerServer: _registerServer,
|
|
3792
4607
|
_unregisterServer: _unregisterServer,
|
|
3793
4608
|
createServer: createServer$2,
|
|
@@ -4356,802 +5171,210 @@
|
|
|
4356
5171
|
}
|
|
4357
5172
|
getWindowSize() {
|
|
4358
5173
|
return [
|
|
4359
|
-
this.columns,
|
|
4360
|
-
this.rows
|
|
4361
|
-
];
|
|
4362
|
-
}
|
|
4363
|
-
}
|
|
4364
|
-
function isatty(fd) {
|
|
4365
|
-
return false;
|
|
4366
|
-
}
|
|
4367
|
-
var tty = {
|
|
4368
|
-
ReadStream,
|
|
4369
|
-
WriteStream,
|
|
4370
|
-
isatty
|
|
4371
|
-
};
|
|
4372
|
-
var ttyShim = Object.freeze({
|
|
4373
|
-
__proto__: null,
|
|
4374
|
-
ReadStream: ReadStream,
|
|
4375
|
-
WriteStream: WriteStream,
|
|
4376
|
-
default: tty,
|
|
4377
|
-
isatty: isatty
|
|
4378
|
-
});
|
|
4379
|
-
function hostname() {
|
|
4380
|
-
return "localhost";
|
|
4381
|
-
}
|
|
4382
|
-
function platform() {
|
|
4383
|
-
return "linux";
|
|
4384
|
-
}
|
|
4385
|
-
function arch() {
|
|
4386
|
-
return "x64";
|
|
4387
|
-
}
|
|
4388
|
-
function type() {
|
|
4389
|
-
return "Linux";
|
|
4390
|
-
}
|
|
4391
|
-
function release() {
|
|
4392
|
-
return "5.10.0";
|
|
4393
|
-
}
|
|
4394
|
-
function version$1() {
|
|
4395
|
-
return "#1 SMP";
|
|
4396
|
-
}
|
|
4397
|
-
function machine() {
|
|
4398
|
-
return "x86_64";
|
|
4399
|
-
}
|
|
4400
|
-
function tmpdir() {
|
|
4401
|
-
return "/tmp";
|
|
4402
|
-
}
|
|
4403
|
-
function homedir() {
|
|
4404
|
-
return "/home/user";
|
|
4405
|
-
}
|
|
4406
|
-
function cpus() {
|
|
4407
|
-
const cpu = {
|
|
4408
|
-
model: "Virtual CPU",
|
|
4409
|
-
speed: 2400,
|
|
4410
|
-
times: {
|
|
4411
|
-
user: 0,
|
|
4412
|
-
nice: 0,
|
|
4413
|
-
sys: 0,
|
|
4414
|
-
idle: 0,
|
|
4415
|
-
irq: 0
|
|
4416
|
-
}
|
|
4417
|
-
};
|
|
4418
|
-
return [
|
|
4419
|
-
cpu,
|
|
4420
|
-
cpu
|
|
4421
|
-
];
|
|
4422
|
-
}
|
|
4423
|
-
function totalmem() {
|
|
4424
|
-
return 4 * 1024 * 1024 * 1024;
|
|
4425
|
-
}
|
|
4426
|
-
function freemem() {
|
|
4427
|
-
return 2 * 1024 * 1024 * 1024;
|
|
4428
|
-
}
|
|
4429
|
-
function uptime() {
|
|
4430
|
-
return Math.floor(performance.now() / 1e3);
|
|
4431
|
-
}
|
|
4432
|
-
function loadavg() {
|
|
4433
|
-
return [
|
|
4434
|
-
0.5,
|
|
4435
|
-
0.5,
|
|
4436
|
-
0.5
|
|
4437
|
-
];
|
|
4438
|
-
}
|
|
4439
|
-
function networkInterfaces() {
|
|
4440
|
-
return {
|
|
4441
|
-
lo: [
|
|
4442
|
-
{
|
|
4443
|
-
address: "127.0.0.1",
|
|
4444
|
-
netmask: "255.0.0.0",
|
|
4445
|
-
family: "IPv4",
|
|
4446
|
-
mac: "00:00:00:00:00:00",
|
|
4447
|
-
internal: true,
|
|
4448
|
-
cidr: "127.0.0.1/8"
|
|
4449
|
-
}
|
|
4450
|
-
]
|
|
4451
|
-
};
|
|
4452
|
-
}
|
|
4453
|
-
function userInfo() {
|
|
4454
|
-
return {
|
|
4455
|
-
username: "user",
|
|
4456
|
-
uid: 1e3,
|
|
4457
|
-
gid: 1e3,
|
|
4458
|
-
shell: "/bin/bash",
|
|
4459
|
-
homedir: "/home/user"
|
|
4460
|
-
};
|
|
4461
|
-
}
|
|
4462
|
-
function endianness() {
|
|
4463
|
-
return "LE";
|
|
4464
|
-
}
|
|
4465
|
-
function getPriority(pid) {
|
|
4466
|
-
return 0;
|
|
4467
|
-
}
|
|
4468
|
-
function setPriority(pid, priority) {}
|
|
4469
|
-
const EOL = "\n";
|
|
4470
|
-
const constants$5 = {
|
|
4471
|
-
signals: {
|
|
4472
|
-
SIGHUP: 1,
|
|
4473
|
-
SIGINT: 2,
|
|
4474
|
-
SIGQUIT: 3,
|
|
4475
|
-
SIGILL: 4,
|
|
4476
|
-
SIGTRAP: 5,
|
|
4477
|
-
SIGABRT: 6,
|
|
4478
|
-
SIGBUS: 7,
|
|
4479
|
-
SIGFPE: 8,
|
|
4480
|
-
SIGKILL: 9,
|
|
4481
|
-
SIGUSR1: 10,
|
|
4482
|
-
SIGSEGV: 11,
|
|
4483
|
-
SIGUSR2: 12,
|
|
4484
|
-
SIGPIPE: 13,
|
|
4485
|
-
SIGALRM: 14,
|
|
4486
|
-
SIGTERM: 15,
|
|
4487
|
-
SIGCHLD: 17,
|
|
4488
|
-
SIGCONT: 18,
|
|
4489
|
-
SIGSTOP: 19,
|
|
4490
|
-
SIGTSTP: 20,
|
|
4491
|
-
SIGTTIN: 21,
|
|
4492
|
-
SIGTTOU: 22,
|
|
4493
|
-
SIGURG: 23,
|
|
4494
|
-
SIGXCPU: 24,
|
|
4495
|
-
SIGXFSZ: 25,
|
|
4496
|
-
SIGVTALRM: 26,
|
|
4497
|
-
SIGPROF: 27,
|
|
4498
|
-
SIGWINCH: 28,
|
|
4499
|
-
SIGIO: 29,
|
|
4500
|
-
SIGPWR: 30,
|
|
4501
|
-
SIGSYS: 31
|
|
4502
|
-
},
|
|
4503
|
-
errno: {},
|
|
4504
|
-
priority: {
|
|
4505
|
-
PRIORITY_LOW: 19,
|
|
4506
|
-
PRIORITY_BELOW_NORMAL: 10,
|
|
4507
|
-
PRIORITY_NORMAL: 0,
|
|
4508
|
-
PRIORITY_ABOVE_NORMAL: -7,
|
|
4509
|
-
PRIORITY_HIGH: -14,
|
|
4510
|
-
PRIORITY_HIGHEST: -20
|
|
4511
|
-
}
|
|
4512
|
-
};
|
|
4513
|
-
const devNull = "/dev/null";
|
|
4514
|
-
var os$1 = {
|
|
4515
|
-
hostname,
|
|
4516
|
-
platform,
|
|
4517
|
-
arch,
|
|
4518
|
-
type,
|
|
4519
|
-
release,
|
|
4520
|
-
version: version$1,
|
|
4521
|
-
machine,
|
|
4522
|
-
tmpdir,
|
|
4523
|
-
homedir,
|
|
4524
|
-
cpus,
|
|
4525
|
-
totalmem,
|
|
4526
|
-
freemem,
|
|
4527
|
-
uptime,
|
|
4528
|
-
loadavg,
|
|
4529
|
-
networkInterfaces,
|
|
4530
|
-
userInfo,
|
|
4531
|
-
endianness,
|
|
4532
|
-
getPriority,
|
|
4533
|
-
setPriority,
|
|
4534
|
-
EOL,
|
|
4535
|
-
constants: constants$5,
|
|
4536
|
-
devNull
|
|
4537
|
-
};
|
|
4538
|
-
var osShim = Object.freeze({
|
|
4539
|
-
__proto__: null,
|
|
4540
|
-
EOL: EOL,
|
|
4541
|
-
arch: arch,
|
|
4542
|
-
constants: constants$5,
|
|
4543
|
-
cpus: cpus,
|
|
4544
|
-
default: os$1,
|
|
4545
|
-
devNull: devNull,
|
|
4546
|
-
endianness: endianness,
|
|
4547
|
-
freemem: freemem,
|
|
4548
|
-
getPriority: getPriority,
|
|
4549
|
-
homedir: homedir,
|
|
4550
|
-
hostname: hostname,
|
|
4551
|
-
loadavg: loadavg,
|
|
4552
|
-
machine: machine,
|
|
4553
|
-
networkInterfaces: networkInterfaces,
|
|
4554
|
-
platform: platform,
|
|
4555
|
-
release: release,
|
|
4556
|
-
setPriority: setPriority,
|
|
4557
|
-
tmpdir: tmpdir,
|
|
4558
|
-
totalmem: totalmem,
|
|
4559
|
-
type: type,
|
|
4560
|
-
uptime: uptime,
|
|
4561
|
-
userInfo: userInfo,
|
|
4562
|
-
version: version$1
|
|
4563
|
-
});
|
|
4564
|
-
function randomBytes(size) {
|
|
4565
|
-
const array = new Uint8Array(size);
|
|
4566
|
-
crypto.getRandomValues(array);
|
|
4567
|
-
return BufferPolyfill.from(array);
|
|
4568
|
-
}
|
|
4569
|
-
function randomUUID() {
|
|
4570
|
-
return crypto.randomUUID();
|
|
4571
|
-
}
|
|
4572
|
-
function randomInt(min, max) {
|
|
4573
|
-
if (max === void 0) {
|
|
4574
|
-
max = min;
|
|
4575
|
-
min = 0;
|
|
4576
|
-
}
|
|
4577
|
-
const range = max - min;
|
|
4578
|
-
const array = new Uint32Array(1);
|
|
4579
|
-
crypto.getRandomValues(array);
|
|
4580
|
-
return min + array[0] % range;
|
|
4581
|
-
}
|
|
4582
|
-
function getRandomValues(array) {
|
|
4583
|
-
return crypto.getRandomValues(array);
|
|
4584
|
-
}
|
|
4585
|
-
function createHash(algorithm) {
|
|
4586
|
-
return new Hash(algorithm);
|
|
4587
|
-
}
|
|
4588
|
-
class Hash {
|
|
4589
|
-
algorithm;
|
|
4590
|
-
data = [];
|
|
4591
|
-
constructor(algorithm){
|
|
4592
|
-
this.algorithm = normalizeHashAlgorithm(algorithm);
|
|
4593
|
-
}
|
|
4594
|
-
update(data, encoding) {
|
|
4595
|
-
let buffer;
|
|
4596
|
-
if (typeof data === "string") {
|
|
4597
|
-
if (encoding === "base64") {
|
|
4598
|
-
buffer = BufferPolyfill.from(atob(data));
|
|
4599
|
-
} else {
|
|
4600
|
-
buffer = BufferPolyfill.from(data);
|
|
4601
|
-
}
|
|
4602
|
-
} else {
|
|
4603
|
-
buffer = data;
|
|
4604
|
-
}
|
|
4605
|
-
this.data.push(buffer);
|
|
4606
|
-
return this;
|
|
4607
|
-
}
|
|
4608
|
-
async digestAsync(encoding) {
|
|
4609
|
-
const combined = concatBuffers(this.data);
|
|
4610
|
-
const dataBuffer = new Uint8Array(combined).buffer;
|
|
4611
|
-
const hashBuffer = await crypto.subtle.digest(this.algorithm, dataBuffer);
|
|
4612
|
-
return encodeResult(new Uint8Array(hashBuffer), encoding);
|
|
4613
|
-
}
|
|
4614
|
-
digest(encoding) {
|
|
4615
|
-
const combined = concatBuffers(this.data);
|
|
4616
|
-
const hash = syncHash(combined, this.algorithm);
|
|
4617
|
-
return encodeResult(hash, encoding);
|
|
4618
|
-
}
|
|
4619
|
-
}
|
|
4620
|
-
function createHmac(algorithm, key) {
|
|
4621
|
-
return new Hmac(algorithm, key);
|
|
4622
|
-
}
|
|
4623
|
-
class Hmac {
|
|
4624
|
-
algorithm;
|
|
4625
|
-
key;
|
|
4626
|
-
data = [];
|
|
4627
|
-
constructor(algorithm, key){
|
|
4628
|
-
this.algorithm = normalizeHashAlgorithm(algorithm);
|
|
4629
|
-
this.key = typeof key === "string" ? BufferPolyfill.from(key) : key;
|
|
4630
|
-
}
|
|
4631
|
-
update(data, encoding) {
|
|
4632
|
-
const buffer = typeof data === "string" ? BufferPolyfill.from(data) : data;
|
|
4633
|
-
this.data.push(buffer);
|
|
4634
|
-
return this;
|
|
4635
|
-
}
|
|
4636
|
-
async digestAsync(encoding) {
|
|
4637
|
-
const combined = concatBuffers(this.data);
|
|
4638
|
-
const keyBuffer = new Uint8Array(this.key).buffer;
|
|
4639
|
-
const dataBuffer = new Uint8Array(combined).buffer;
|
|
4640
|
-
const cryptoKey = await crypto.subtle.importKey("raw", keyBuffer, {
|
|
4641
|
-
name: "HMAC",
|
|
4642
|
-
hash: this.algorithm
|
|
4643
|
-
}, false, [
|
|
4644
|
-
"sign"
|
|
4645
|
-
]);
|
|
4646
|
-
const signature = await crypto.subtle.sign("HMAC", cryptoKey, dataBuffer);
|
|
4647
|
-
return encodeResult(new Uint8Array(signature), encoding);
|
|
4648
|
-
}
|
|
4649
|
-
digest(encoding) {
|
|
4650
|
-
const combined = concatBuffers(this.data);
|
|
4651
|
-
const hash = syncHmac(combined, this.key, this.algorithm);
|
|
4652
|
-
return encodeResult(hash, encoding);
|
|
4653
|
-
}
|
|
4654
|
-
}
|
|
4655
|
-
async function pbkdf2Async(password, salt, iterations, keylen, digest) {
|
|
4656
|
-
const passwordBuffer = typeof password === "string" ? BufferPolyfill.from(password) : password instanceof Uint8Array ? password : BufferPolyfill.from(password);
|
|
4657
|
-
const saltBuffer = typeof salt === "string" ? BufferPolyfill.from(salt) : salt instanceof Uint8Array ? salt : BufferPolyfill.from(salt);
|
|
4658
|
-
const passwordArrayBuffer = new Uint8Array(passwordBuffer).buffer;
|
|
4659
|
-
const saltArrayBuffer = new Uint8Array(saltBuffer).buffer;
|
|
4660
|
-
const key = await crypto.subtle.importKey("raw", passwordArrayBuffer, "PBKDF2", false, [
|
|
4661
|
-
"deriveBits"
|
|
4662
|
-
]);
|
|
4663
|
-
const derivedBits = await crypto.subtle.deriveBits({
|
|
4664
|
-
name: "PBKDF2",
|
|
4665
|
-
salt: saltArrayBuffer,
|
|
4666
|
-
iterations,
|
|
4667
|
-
hash: normalizeHashAlgorithm(digest)
|
|
4668
|
-
}, key, keylen * 8);
|
|
4669
|
-
return BufferPolyfill.from(derivedBits);
|
|
4670
|
-
}
|
|
4671
|
-
function pbkdf2(password, salt, iterations, keylen, digest, callback) {
|
|
4672
|
-
pbkdf2Async(password, salt, iterations, keylen, digest).then((key)=>callback(null, key)).catch((err)=>callback(err, BufferPolyfill.alloc(0)));
|
|
4673
|
-
}
|
|
4674
|
-
function pbkdf2Sync(password, salt, iterations, keylen, digest) {
|
|
4675
|
-
const passwordBuffer = typeof password === "string" ? BufferPolyfill.from(password) : password;
|
|
4676
|
-
const saltBuffer = typeof salt === "string" ? BufferPolyfill.from(salt) : salt;
|
|
4677
|
-
const hashAlg = normalizeHashAlgorithm(digest);
|
|
4678
|
-
let hashLen;
|
|
4679
|
-
if (hashAlg.includes("512")) {
|
|
4680
|
-
hashLen = 64;
|
|
4681
|
-
} else if (hashAlg.includes("384")) {
|
|
4682
|
-
hashLen = 48;
|
|
4683
|
-
} else if (hashAlg.includes("1") || hashAlg === "SHA-1") {
|
|
4684
|
-
hashLen = 20;
|
|
4685
|
-
} else {
|
|
4686
|
-
hashLen = 32;
|
|
4687
|
-
}
|
|
4688
|
-
const numBlocks = Math.ceil(keylen / hashLen);
|
|
4689
|
-
const derivedKey = new Uint8Array(numBlocks * hashLen);
|
|
4690
|
-
for(let blockNum = 1; blockNum <= numBlocks; blockNum++){
|
|
4691
|
-
const blockNumBuf = new Uint8Array(4);
|
|
4692
|
-
blockNumBuf[0] = blockNum >>> 24 & 255;
|
|
4693
|
-
blockNumBuf[1] = blockNum >>> 16 & 255;
|
|
4694
|
-
blockNumBuf[2] = blockNum >>> 8 & 255;
|
|
4695
|
-
blockNumBuf[3] = blockNum & 255;
|
|
4696
|
-
const saltWithBlock = new Uint8Array(saltBuffer.length + 4);
|
|
4697
|
-
saltWithBlock.set(saltBuffer);
|
|
4698
|
-
saltWithBlock.set(blockNumBuf, saltBuffer.length);
|
|
4699
|
-
let u = syncHmac(saltWithBlock, passwordBuffer, hashAlg);
|
|
4700
|
-
const block = new Uint8Array(u);
|
|
4701
|
-
for(let i = 1; i < iterations; i++){
|
|
4702
|
-
u = syncHmac(u, passwordBuffer, hashAlg);
|
|
4703
|
-
for(let j = 0; j < block.length; j++){
|
|
4704
|
-
block[j] ^= u[j];
|
|
4705
|
-
}
|
|
4706
|
-
}
|
|
4707
|
-
derivedKey.set(block, (blockNum - 1) * hashLen);
|
|
4708
|
-
}
|
|
4709
|
-
return BufferPolyfill.from(derivedKey.slice(0, keylen));
|
|
4710
|
-
}
|
|
4711
|
-
function sign(algorithm, data, key, callback) {
|
|
4712
|
-
const keyInfo = extractKeyInfo(key);
|
|
4713
|
-
const alg = algorithm || keyInfo.algorithm;
|
|
4714
|
-
if (!alg) {
|
|
4715
|
-
const error = new Error("Algorithm must be specified");
|
|
4716
|
-
if (callback) {
|
|
4717
|
-
callback(error, null);
|
|
4718
|
-
return;
|
|
4719
|
-
}
|
|
4720
|
-
throw error;
|
|
4721
|
-
}
|
|
4722
|
-
if (callback) {
|
|
4723
|
-
signAsync(alg, data, keyInfo).then((sig)=>callback(null, sig)).catch((err)=>callback(err, null));
|
|
4724
|
-
return;
|
|
4725
|
-
}
|
|
4726
|
-
const result = signSync(alg, data, keyInfo);
|
|
4727
|
-
return result;
|
|
4728
|
-
}
|
|
4729
|
-
function verify(algorithm, data, key, signature, callback) {
|
|
4730
|
-
const keyInfo = extractKeyInfo(key);
|
|
4731
|
-
const alg = algorithm || keyInfo.algorithm;
|
|
4732
|
-
if (!alg) {
|
|
4733
|
-
const error = new Error("Algorithm must be specified");
|
|
4734
|
-
if (callback) {
|
|
4735
|
-
callback(error, false);
|
|
4736
|
-
return;
|
|
4737
|
-
}
|
|
4738
|
-
throw error;
|
|
4739
|
-
}
|
|
4740
|
-
if (callback) {
|
|
4741
|
-
verifyAsync(alg, data, keyInfo, signature).then((result)=>callback(null, result)).catch((err)=>callback(err, false));
|
|
4742
|
-
return;
|
|
4743
|
-
}
|
|
4744
|
-
return verifySync(alg, data, keyInfo, signature);
|
|
4745
|
-
}
|
|
4746
|
-
function createSign(algorithm) {
|
|
4747
|
-
return new Sign(algorithm);
|
|
4748
|
-
}
|
|
4749
|
-
function createVerify(algorithm) {
|
|
4750
|
-
return new Verify(algorithm);
|
|
4751
|
-
}
|
|
4752
|
-
class Sign extends EventEmitter {
|
|
4753
|
-
algorithm;
|
|
4754
|
-
data = [];
|
|
4755
|
-
constructor(algorithm){
|
|
4756
|
-
super();
|
|
4757
|
-
this.algorithm = algorithm;
|
|
4758
|
-
}
|
|
4759
|
-
update(data, encoding) {
|
|
4760
|
-
const buffer = typeof data === "string" ? BufferPolyfill.from(data) : data;
|
|
4761
|
-
this.data.push(buffer);
|
|
4762
|
-
return this;
|
|
4763
|
-
}
|
|
4764
|
-
sign(privateKey, outputEncoding) {
|
|
4765
|
-
const combined = concatBuffers(this.data);
|
|
4766
|
-
const keyInfo = extractKeyInfo(privateKey);
|
|
4767
|
-
const signature = signSync(this.algorithm, combined, keyInfo);
|
|
4768
|
-
if (outputEncoding === "base64") {
|
|
4769
|
-
return btoa(String.fromCharCode(...signature));
|
|
4770
|
-
}
|
|
4771
|
-
if (outputEncoding === "hex") {
|
|
4772
|
-
return Array.from(signature).map((b)=>b.toString(16).padStart(2, "0")).join("");
|
|
4773
|
-
}
|
|
4774
|
-
return signature;
|
|
4775
|
-
}
|
|
4776
|
-
}
|
|
4777
|
-
class Verify extends EventEmitter {
|
|
4778
|
-
algorithm;
|
|
4779
|
-
data = [];
|
|
4780
|
-
constructor(algorithm){
|
|
4781
|
-
super();
|
|
4782
|
-
this.algorithm = algorithm;
|
|
4783
|
-
}
|
|
4784
|
-
update(data, encoding) {
|
|
4785
|
-
const buffer = typeof data === "string" ? BufferPolyfill.from(data) : data;
|
|
4786
|
-
this.data.push(buffer);
|
|
4787
|
-
return this;
|
|
4788
|
-
}
|
|
4789
|
-
verify(publicKey, signature, signatureEncoding) {
|
|
4790
|
-
const combined = concatBuffers(this.data);
|
|
4791
|
-
const keyInfo = extractKeyInfo(publicKey);
|
|
4792
|
-
let sig;
|
|
4793
|
-
if (typeof signature === "string") {
|
|
4794
|
-
if (signatureEncoding === "base64") {
|
|
4795
|
-
sig = BufferPolyfill.from(atob(signature));
|
|
4796
|
-
} else if (signatureEncoding === "hex") {
|
|
4797
|
-
sig = BufferPolyfill.from(signature.match(/.{2}/g).map((byte)=>parseInt(byte, 16)));
|
|
4798
|
-
} else {
|
|
4799
|
-
sig = BufferPolyfill.from(signature);
|
|
4800
|
-
}
|
|
4801
|
-
} else {
|
|
4802
|
-
sig = signature;
|
|
4803
|
-
}
|
|
4804
|
-
return verifySync(this.algorithm, combined, keyInfo, sig);
|
|
4805
|
-
}
|
|
4806
|
-
}
|
|
4807
|
-
class KeyObject {
|
|
4808
|
-
_keyData;
|
|
4809
|
-
_type;
|
|
4810
|
-
_algorithm;
|
|
4811
|
-
constructor(type, keyData, algorithm){
|
|
4812
|
-
this._type = type;
|
|
4813
|
-
this._keyData = keyData;
|
|
4814
|
-
this._algorithm = algorithm;
|
|
4815
|
-
}
|
|
4816
|
-
get type() {
|
|
4817
|
-
return this._type;
|
|
4818
|
-
}
|
|
4819
|
-
get asymmetricKeyType() {
|
|
4820
|
-
if (this._type === "secret") return void 0;
|
|
4821
|
-
if (this._algorithm?.includes("RSA")) return "rsa";
|
|
4822
|
-
if (this._algorithm?.includes("EC") || this._algorithm?.includes("ES")) return "ec";
|
|
4823
|
-
if (this._algorithm?.includes("Ed")) return "ed25519";
|
|
4824
|
-
return void 0;
|
|
4825
|
-
}
|
|
4826
|
-
get symmetricKeySize() {
|
|
4827
|
-
if (this._type !== "secret") return void 0;
|
|
4828
|
-
if (this._keyData instanceof Uint8Array) {
|
|
4829
|
-
return this._keyData.length * 8;
|
|
4830
|
-
}
|
|
4831
|
-
return void 0;
|
|
4832
|
-
}
|
|
4833
|
-
export(options) {
|
|
4834
|
-
if (this._keyData instanceof Uint8Array) {
|
|
4835
|
-
return BufferPolyfill.from(this._keyData);
|
|
4836
|
-
}
|
|
4837
|
-
throw new Error("Cannot export CryptoKey synchronously");
|
|
5174
|
+
this.columns,
|
|
5175
|
+
this.rows
|
|
5176
|
+
];
|
|
4838
5177
|
}
|
|
4839
5178
|
}
|
|
4840
|
-
function
|
|
4841
|
-
|
|
4842
|
-
return new KeyObject("secret", keyBuffer);
|
|
5179
|
+
function isatty(fd) {
|
|
5180
|
+
return false;
|
|
4843
5181
|
}
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
5182
|
+
var tty = {
|
|
5183
|
+
ReadStream,
|
|
5184
|
+
WriteStream,
|
|
5185
|
+
isatty
|
|
5186
|
+
};
|
|
5187
|
+
var ttyShim = Object.freeze({
|
|
5188
|
+
__proto__: null,
|
|
5189
|
+
ReadStream: ReadStream,
|
|
5190
|
+
WriteStream: WriteStream,
|
|
5191
|
+
default: tty,
|
|
5192
|
+
isatty: isatty
|
|
5193
|
+
});
|
|
5194
|
+
function hostname() {
|
|
5195
|
+
return "localhost";
|
|
4847
5196
|
}
|
|
4848
|
-
function
|
|
4849
|
-
|
|
4850
|
-
return new KeyObject("private", keyInfo.keyData, keyInfo.algorithm);
|
|
5197
|
+
function platform() {
|
|
5198
|
+
return "linux";
|
|
4851
5199
|
}
|
|
4852
|
-
function
|
|
4853
|
-
|
|
4854
|
-
return false;
|
|
4855
|
-
}
|
|
4856
|
-
let result = 0;
|
|
4857
|
-
for(let i = 0; i < a.length; i++){
|
|
4858
|
-
result |= a[i] ^ b[i];
|
|
4859
|
-
}
|
|
4860
|
-
return result === 0;
|
|
5200
|
+
function arch() {
|
|
5201
|
+
return "x64";
|
|
4861
5202
|
}
|
|
4862
|
-
function
|
|
4863
|
-
return
|
|
4864
|
-
"aes-128-cbc",
|
|
4865
|
-
"aes-256-cbc",
|
|
4866
|
-
"aes-128-gcm",
|
|
4867
|
-
"aes-256-gcm"
|
|
4868
|
-
];
|
|
5203
|
+
function type() {
|
|
5204
|
+
return "Linux";
|
|
4869
5205
|
}
|
|
4870
|
-
function
|
|
4871
|
-
return
|
|
4872
|
-
"sha1",
|
|
4873
|
-
"sha256",
|
|
4874
|
-
"sha384",
|
|
4875
|
-
"sha512"
|
|
4876
|
-
];
|
|
5206
|
+
function release() {
|
|
5207
|
+
return "5.10.0";
|
|
4877
5208
|
}
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
RSA_PKCS1_PADDING: 1,
|
|
4881
|
-
RSA_PKCS1_OAEP_PADDING: 4,
|
|
4882
|
-
RSA_PKCS1_PSS_PADDING: 6
|
|
4883
|
-
};
|
|
4884
|
-
function normalizeHashAlgorithm(alg) {
|
|
4885
|
-
const normalized = alg.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
4886
|
-
switch(normalized){
|
|
4887
|
-
case "SHA1":
|
|
4888
|
-
return "SHA-1";
|
|
4889
|
-
case "SHA256":
|
|
4890
|
-
return "SHA-256";
|
|
4891
|
-
case "SHA384":
|
|
4892
|
-
return "SHA-384";
|
|
4893
|
-
case "SHA512":
|
|
4894
|
-
return "SHA-512";
|
|
4895
|
-
case "MD5":
|
|
4896
|
-
return "MD5";
|
|
4897
|
-
default:
|
|
4898
|
-
return alg;
|
|
4899
|
-
}
|
|
5209
|
+
function version$1() {
|
|
5210
|
+
return "#1 SMP";
|
|
4900
5211
|
}
|
|
4901
|
-
function
|
|
4902
|
-
|
|
4903
|
-
if (alg.includes("RSA")) {
|
|
4904
|
-
if (alg.includes("PSS")) {
|
|
4905
|
-
const hash2 = alg.match(/SHA(\d+)/)?.[0] || "SHA-256";
|
|
4906
|
-
return {
|
|
4907
|
-
name: "RSA-PSS",
|
|
4908
|
-
hash: `SHA-${hash2.replace("SHA", "")}`
|
|
4909
|
-
};
|
|
4910
|
-
}
|
|
4911
|
-
const hash = alg.match(/SHA(\d+)/)?.[0] || "SHA-256";
|
|
4912
|
-
return {
|
|
4913
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
4914
|
-
hash: `SHA-${hash.replace("SHA", "")}`
|
|
4915
|
-
};
|
|
4916
|
-
}
|
|
4917
|
-
if (alg.startsWith("ES") || alg.includes("ECDSA")) {
|
|
4918
|
-
const bits = alg.match(/\d+/)?.[0] || "256";
|
|
4919
|
-
const hash = bits === "512" ? "SHA-512" : bits === "384" ? "SHA-384" : "SHA-256";
|
|
4920
|
-
return {
|
|
4921
|
-
name: "ECDSA",
|
|
4922
|
-
hash
|
|
4923
|
-
};
|
|
4924
|
-
}
|
|
4925
|
-
if (alg.includes("ED25519") || alg === "EDDSA") {
|
|
4926
|
-
return {
|
|
4927
|
-
name: "Ed25519"
|
|
4928
|
-
};
|
|
4929
|
-
}
|
|
4930
|
-
if (alg.includes("HS") || alg.includes("HMAC")) {
|
|
4931
|
-
const bits = alg.match(/\d+/)?.[0] || "256";
|
|
4932
|
-
return {
|
|
4933
|
-
name: "HMAC",
|
|
4934
|
-
hash: `SHA-${bits}`
|
|
4935
|
-
};
|
|
4936
|
-
}
|
|
4937
|
-
return {
|
|
4938
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
4939
|
-
hash: "SHA-256"
|
|
4940
|
-
};
|
|
5212
|
+
function machine() {
|
|
5213
|
+
return "x86_64";
|
|
4941
5214
|
}
|
|
4942
|
-
function
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
const keyData2 = BufferPolyfill.from(atob(base64));
|
|
4960
|
-
let algorithm;
|
|
4961
|
-
if (keyStr.includes("RSA")) algorithm = "RSA-SHA256";
|
|
4962
|
-
else if (keyStr.includes("EC")) algorithm = "ES256";
|
|
4963
|
-
else if (keyStr.includes("ED25519")) algorithm = "Ed25519";
|
|
4964
|
-
return {
|
|
4965
|
-
keyData: keyData2,
|
|
4966
|
-
algorithm,
|
|
4967
|
-
type: isPrivate ? "private" : isPublic ? "public" : "secret",
|
|
4968
|
-
format: "pem"
|
|
4969
|
-
};
|
|
4970
|
-
}
|
|
4971
|
-
const keyData = typeof key === "string" ? BufferPolyfill.from(key) : key;
|
|
4972
|
-
return {
|
|
4973
|
-
keyData,
|
|
4974
|
-
type: "secret",
|
|
4975
|
-
format: "raw"
|
|
5215
|
+
function tmpdir() {
|
|
5216
|
+
return "/tmp";
|
|
5217
|
+
}
|
|
5218
|
+
function homedir() {
|
|
5219
|
+
return "/home/user";
|
|
5220
|
+
}
|
|
5221
|
+
function cpus() {
|
|
5222
|
+
const cpu = {
|
|
5223
|
+
model: "Virtual CPU",
|
|
5224
|
+
speed: 2400,
|
|
5225
|
+
times: {
|
|
5226
|
+
user: 0,
|
|
5227
|
+
nice: 0,
|
|
5228
|
+
sys: 0,
|
|
5229
|
+
idle: 0,
|
|
5230
|
+
irq: 0
|
|
5231
|
+
}
|
|
4976
5232
|
};
|
|
5233
|
+
return [
|
|
5234
|
+
cpu,
|
|
5235
|
+
cpu
|
|
5236
|
+
];
|
|
4977
5237
|
}
|
|
4978
|
-
function
|
|
4979
|
-
|
|
4980
|
-
const result = new Uint8Array(totalLength);
|
|
4981
|
-
let offset = 0;
|
|
4982
|
-
for (const buf of buffers){
|
|
4983
|
-
result.set(buf, offset);
|
|
4984
|
-
offset += buf.length;
|
|
4985
|
-
}
|
|
4986
|
-
return result;
|
|
5238
|
+
function totalmem() {
|
|
5239
|
+
return 4 * 1024 * 1024 * 1024;
|
|
4987
5240
|
}
|
|
4988
|
-
function
|
|
4989
|
-
|
|
4990
|
-
return Array.from(data).map((b)=>b.toString(16).padStart(2, "0")).join("");
|
|
4991
|
-
}
|
|
4992
|
-
if (encoding === "base64") {
|
|
4993
|
-
return btoa(String.fromCharCode(...data));
|
|
4994
|
-
}
|
|
4995
|
-
return BufferPolyfill.from(data);
|
|
5241
|
+
function freemem() {
|
|
5242
|
+
return 2 * 1024 * 1024 * 1024;
|
|
4996
5243
|
}
|
|
4997
|
-
function
|
|
4998
|
-
|
|
4999
|
-
if (algorithm.includes("512")) {
|
|
5000
|
-
size = 64;
|
|
5001
|
-
} else if (algorithm.includes("384")) {
|
|
5002
|
-
size = 48;
|
|
5003
|
-
} else if (algorithm.includes("1") || algorithm === "SHA-1") {
|
|
5004
|
-
size = 20;
|
|
5005
|
-
} else {
|
|
5006
|
-
size = 32;
|
|
5007
|
-
}
|
|
5008
|
-
const result = new Uint8Array(size);
|
|
5009
|
-
let h1 = 3735928559;
|
|
5010
|
-
let h2 = 1103547991;
|
|
5011
|
-
for(let i = 0; i < data.length; i++){
|
|
5012
|
-
h1 = Math.imul(h1 ^ data[i], 2654435761);
|
|
5013
|
-
h2 = Math.imul(h2 ^ data[i], 1597334677);
|
|
5014
|
-
}
|
|
5015
|
-
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
5016
|
-
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
5017
|
-
for(let i = 0; i < size; i++){
|
|
5018
|
-
const mix = i < size / 2 ? h1 : h2;
|
|
5019
|
-
result[i] = mix >>> i % 4 * 8 & 255;
|
|
5020
|
-
h1 = Math.imul(h1, 1103515245) + 12345;
|
|
5021
|
-
h2 = Math.imul(h2, 1103515245) + 12345;
|
|
5022
|
-
}
|
|
5023
|
-
return result;
|
|
5244
|
+
function uptime() {
|
|
5245
|
+
return Math.floor(performance.now() / 1e3);
|
|
5024
5246
|
}
|
|
5025
|
-
function
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5247
|
+
function loadavg() {
|
|
5248
|
+
return [
|
|
5249
|
+
0.5,
|
|
5250
|
+
0.5,
|
|
5251
|
+
0.5
|
|
5252
|
+
];
|
|
5030
5253
|
}
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
const signature = await crypto.subtle.sign(signatureAlg, cryptoKey, dataBuffer);
|
|
5045
|
-
return BufferPolyfill.from(signature);
|
|
5046
|
-
} catch (error) {
|
|
5047
|
-
console.warn("WebCrypto sign failed, using fallback:", error);
|
|
5048
|
-
return signSync(algorithm, data, keyInfo);
|
|
5049
|
-
}
|
|
5254
|
+
function networkInterfaces() {
|
|
5255
|
+
return {
|
|
5256
|
+
lo: [
|
|
5257
|
+
{
|
|
5258
|
+
address: "127.0.0.1",
|
|
5259
|
+
netmask: "255.0.0.0",
|
|
5260
|
+
family: "IPv4",
|
|
5261
|
+
mac: "00:00:00:00:00:00",
|
|
5262
|
+
internal: true,
|
|
5263
|
+
cidr: "127.0.0.1/8"
|
|
5264
|
+
}
|
|
5265
|
+
]
|
|
5266
|
+
};
|
|
5050
5267
|
}
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
hash: webCryptoAlg.hash
|
|
5060
|
-
} : {
|
|
5061
|
-
name: webCryptoAlg.name
|
|
5062
|
-
};
|
|
5063
|
-
const sigBuffer = new Uint8Array(signature).buffer;
|
|
5064
|
-
const dataBuffer = new Uint8Array(data).buffer;
|
|
5065
|
-
return await crypto.subtle.verify(verifyAlg, cryptoKey, sigBuffer, dataBuffer);
|
|
5066
|
-
} catch (error) {
|
|
5067
|
-
console.warn("WebCrypto verify failed, using fallback:", error);
|
|
5068
|
-
return verifySync(algorithm, data, keyInfo, signature);
|
|
5069
|
-
}
|
|
5268
|
+
function userInfo() {
|
|
5269
|
+
return {
|
|
5270
|
+
username: "user",
|
|
5271
|
+
uid: 1e3,
|
|
5272
|
+
gid: 1e3,
|
|
5273
|
+
shell: "/bin/bash",
|
|
5274
|
+
homedir: "/home/user"
|
|
5275
|
+
};
|
|
5070
5276
|
}
|
|
5071
|
-
function
|
|
5072
|
-
|
|
5073
|
-
const combined = new Uint8Array(keyData.length + data.length);
|
|
5074
|
-
combined.set(keyData, 0);
|
|
5075
|
-
combined.set(data, keyData.length);
|
|
5076
|
-
const hash = syncHash(combined, algorithm);
|
|
5077
|
-
return BufferPolyfill.from(hash);
|
|
5277
|
+
function endianness() {
|
|
5278
|
+
return "LE";
|
|
5078
5279
|
}
|
|
5079
|
-
function
|
|
5080
|
-
|
|
5081
|
-
return timingSafeEqual(BufferPolyfill.from(signature), expectedSig);
|
|
5280
|
+
function getPriority(pid) {
|
|
5281
|
+
return 0;
|
|
5082
5282
|
}
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5283
|
+
function setPriority(pid, priority) {}
|
|
5284
|
+
const EOL = "\n";
|
|
5285
|
+
const constants$4 = {
|
|
5286
|
+
signals: {
|
|
5287
|
+
SIGHUP: 1,
|
|
5288
|
+
SIGINT: 2,
|
|
5289
|
+
SIGQUIT: 3,
|
|
5290
|
+
SIGILL: 4,
|
|
5291
|
+
SIGTRAP: 5,
|
|
5292
|
+
SIGABRT: 6,
|
|
5293
|
+
SIGBUS: 7,
|
|
5294
|
+
SIGFPE: 8,
|
|
5295
|
+
SIGKILL: 9,
|
|
5296
|
+
SIGUSR1: 10,
|
|
5297
|
+
SIGSEGV: 11,
|
|
5298
|
+
SIGUSR2: 12,
|
|
5299
|
+
SIGPIPE: 13,
|
|
5300
|
+
SIGALRM: 14,
|
|
5301
|
+
SIGTERM: 15,
|
|
5302
|
+
SIGCHLD: 17,
|
|
5303
|
+
SIGCONT: 18,
|
|
5304
|
+
SIGSTOP: 19,
|
|
5305
|
+
SIGTSTP: 20,
|
|
5306
|
+
SIGTTIN: 21,
|
|
5307
|
+
SIGTTOU: 22,
|
|
5308
|
+
SIGURG: 23,
|
|
5309
|
+
SIGXCPU: 24,
|
|
5310
|
+
SIGXFSZ: 25,
|
|
5311
|
+
SIGVTALRM: 26,
|
|
5312
|
+
SIGPROF: 27,
|
|
5313
|
+
SIGWINCH: 28,
|
|
5314
|
+
SIGIO: 29,
|
|
5315
|
+
SIGPWR: 30,
|
|
5316
|
+
SIGSYS: 31
|
|
5317
|
+
},
|
|
5318
|
+
errno: {},
|
|
5319
|
+
priority: {
|
|
5320
|
+
PRIORITY_LOW: 19,
|
|
5321
|
+
PRIORITY_BELOW_NORMAL: 10,
|
|
5322
|
+
PRIORITY_NORMAL: 0,
|
|
5323
|
+
PRIORITY_ABOVE_NORMAL: -7,
|
|
5324
|
+
PRIORITY_HIGH: -14,
|
|
5325
|
+
PRIORITY_HIGHEST: -20
|
|
5107
5326
|
}
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
var
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5327
|
+
};
|
|
5328
|
+
const devNull = "/dev/null";
|
|
5329
|
+
var os$1 = {
|
|
5330
|
+
hostname,
|
|
5331
|
+
platform,
|
|
5332
|
+
arch,
|
|
5333
|
+
type,
|
|
5334
|
+
release,
|
|
5335
|
+
version: version$1,
|
|
5336
|
+
machine,
|
|
5337
|
+
tmpdir,
|
|
5338
|
+
homedir,
|
|
5339
|
+
cpus,
|
|
5340
|
+
totalmem,
|
|
5341
|
+
freemem,
|
|
5342
|
+
uptime,
|
|
5343
|
+
loadavg,
|
|
5344
|
+
networkInterfaces,
|
|
5345
|
+
userInfo,
|
|
5346
|
+
endianness,
|
|
5347
|
+
getPriority,
|
|
5348
|
+
setPriority,
|
|
5349
|
+
EOL,
|
|
5126
5350
|
constants: constants$4,
|
|
5127
|
-
|
|
5128
|
-
createSecretKey,
|
|
5129
|
-
createPublicKey,
|
|
5130
|
-
createPrivateKey
|
|
5351
|
+
devNull
|
|
5131
5352
|
};
|
|
5132
|
-
var
|
|
5353
|
+
var osShim = Object.freeze({
|
|
5133
5354
|
__proto__: null,
|
|
5134
|
-
|
|
5355
|
+
EOL: EOL,
|
|
5356
|
+
arch: arch,
|
|
5135
5357
|
constants: constants$4,
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5358
|
+
cpus: cpus,
|
|
5359
|
+
default: os$1,
|
|
5360
|
+
devNull: devNull,
|
|
5361
|
+
endianness: endianness,
|
|
5362
|
+
freemem: freemem,
|
|
5363
|
+
getPriority: getPriority,
|
|
5364
|
+
homedir: homedir,
|
|
5365
|
+
hostname: hostname,
|
|
5366
|
+
loadavg: loadavg,
|
|
5367
|
+
machine: machine,
|
|
5368
|
+
networkInterfaces: networkInterfaces,
|
|
5369
|
+
platform: platform,
|
|
5370
|
+
release: release,
|
|
5371
|
+
setPriority: setPriority,
|
|
5372
|
+
tmpdir: tmpdir,
|
|
5373
|
+
totalmem: totalmem,
|
|
5374
|
+
type: type,
|
|
5375
|
+
uptime: uptime,
|
|
5376
|
+
userInfo: userInfo,
|
|
5377
|
+
version: version$1
|
|
5155
5378
|
});
|
|
5156
5379
|
const Z_FIXED$1 = 4;
|
|
5157
5380
|
const Z_BINARY = 0;
|
|
@@ -55868,6 +56091,7 @@ sys 0m0.000s
|
|
|
55868
56091
|
return n.join(`
|
|
55869
56092
|
`);
|
|
55870
56093
|
}
|
|
56094
|
+
const _decoder = new TextDecoder();
|
|
55871
56095
|
class VirtualFSAdapter {
|
|
55872
56096
|
constructor(vfs){
|
|
55873
56097
|
this.vfs = vfs;
|
|
@@ -55879,7 +56103,7 @@ sys 0m0.000s
|
|
|
55879
56103
|
}
|
|
55880
56104
|
if (encoding === "binary" || encoding === "latin1") {
|
|
55881
56105
|
const buffer = this.vfs.readFileSync(path);
|
|
55882
|
-
return
|
|
56106
|
+
return uint8ToBinaryString(buffer);
|
|
55883
56107
|
}
|
|
55884
56108
|
return this.vfs.readFileSync(path, "utf8");
|
|
55885
56109
|
}
|
|
@@ -55894,7 +56118,7 @@ sys 0m0.000s
|
|
|
55894
56118
|
try {
|
|
55895
56119
|
existing = this.vfs.readFileSync(path, "utf8");
|
|
55896
56120
|
} catch {}
|
|
55897
|
-
const newContent = typeof content === "string" ? content :
|
|
56121
|
+
const newContent = typeof content === "string" ? content : _decoder.decode(content);
|
|
55898
56122
|
this.vfs.writeFileSync(path, existing + newContent);
|
|
55899
56123
|
}
|
|
55900
56124
|
async exists(path) {
|
|
@@ -56711,6 +56935,7 @@ sys 0m0.000s
|
|
|
56711
56935
|
binaryType = "blob";
|
|
56712
56936
|
_id;
|
|
56713
56937
|
_server = null;
|
|
56938
|
+
_nativeWs = null;
|
|
56714
56939
|
onopen = null;
|
|
56715
56940
|
onclose = null;
|
|
56716
56941
|
onerror = null;
|
|
@@ -56731,6 +56956,10 @@ sys 0m0.000s
|
|
|
56731
56956
|
if (this.onopen) this.onopen(new Event("open"));
|
|
56732
56957
|
return;
|
|
56733
56958
|
}
|
|
56959
|
+
if (this.url.startsWith("ws://") || this.url.startsWith("wss://")) {
|
|
56960
|
+
this._connectNative();
|
|
56961
|
+
return;
|
|
56962
|
+
}
|
|
56734
56963
|
if (!messageChannel) {
|
|
56735
56964
|
setTimeout(()=>{
|
|
56736
56965
|
this.readyState = WebSocket.OPEN;
|
|
@@ -56788,10 +57017,63 @@ sys 0m0.000s
|
|
|
56788
57017
|
}
|
|
56789
57018
|
}, 100);
|
|
56790
57019
|
}
|
|
57020
|
+
_connectNative() {
|
|
57021
|
+
const NativeWS = typeof globalThis.WebSocket === "function" && globalThis.WebSocket !== WebSocket ? globalThis.WebSocket : null;
|
|
57022
|
+
if (!NativeWS) {
|
|
57023
|
+
setTimeout(()=>{
|
|
57024
|
+
this.readyState = WebSocket.OPEN;
|
|
57025
|
+
this.emit("open");
|
|
57026
|
+
if (this.onopen) this.onopen(new Event("open"));
|
|
57027
|
+
}, 0);
|
|
57028
|
+
return;
|
|
57029
|
+
}
|
|
57030
|
+
try {
|
|
57031
|
+
this._nativeWs = new NativeWS(this.url);
|
|
57032
|
+
this._nativeWs.binaryType = this.binaryType === "arraybuffer" ? "arraybuffer" : "blob";
|
|
57033
|
+
} catch {
|
|
57034
|
+
this.readyState = WebSocket.CLOSED;
|
|
57035
|
+
const errorEvent = new Event("error");
|
|
57036
|
+
this.emit("error", errorEvent);
|
|
57037
|
+
if (this.onerror) this.onerror(errorEvent);
|
|
57038
|
+
return;
|
|
57039
|
+
}
|
|
57040
|
+
this._nativeWs.onopen = ()=>{
|
|
57041
|
+
this.readyState = WebSocket.OPEN;
|
|
57042
|
+
this.emit("open");
|
|
57043
|
+
if (this.onopen) this.onopen(new Event("open"));
|
|
57044
|
+
};
|
|
57045
|
+
this._nativeWs.onmessage = (event)=>{
|
|
57046
|
+
const msgEvent = new MessageEventPolyfill("message", {
|
|
57047
|
+
data: event.data
|
|
57048
|
+
});
|
|
57049
|
+
this.emit("message", msgEvent);
|
|
57050
|
+
if (this.onmessage) this.onmessage(msgEvent);
|
|
57051
|
+
};
|
|
57052
|
+
this._nativeWs.onclose = (event)=>{
|
|
57053
|
+
this.readyState = WebSocket.CLOSED;
|
|
57054
|
+
this._nativeWs = null;
|
|
57055
|
+
const closeEvent = new CloseEventPolyfill("close", {
|
|
57056
|
+
code: event.code,
|
|
57057
|
+
reason: event.reason,
|
|
57058
|
+
wasClean: event.wasClean
|
|
57059
|
+
});
|
|
57060
|
+
this.emit("close", closeEvent);
|
|
57061
|
+
if (this.onclose) this.onclose(closeEvent);
|
|
57062
|
+
};
|
|
57063
|
+
this._nativeWs.onerror = ()=>{
|
|
57064
|
+
const errorEvent = new Event("error");
|
|
57065
|
+
this.emit("error", errorEvent);
|
|
57066
|
+
if (this.onerror) this.onerror(errorEvent);
|
|
57067
|
+
};
|
|
57068
|
+
}
|
|
56791
57069
|
send(data) {
|
|
56792
57070
|
if (this.readyState !== WebSocket.OPEN) {
|
|
56793
57071
|
throw new Error("WebSocket is not open");
|
|
56794
57072
|
}
|
|
57073
|
+
if (this._nativeWs) {
|
|
57074
|
+
this._nativeWs.send(data);
|
|
57075
|
+
return;
|
|
57076
|
+
}
|
|
56795
57077
|
if (this._server) {
|
|
56796
57078
|
this._server._handleClientMessage(this, data);
|
|
56797
57079
|
return;
|
|
@@ -56810,6 +57092,10 @@ sys 0m0.000s
|
|
|
56810
57092
|
return;
|
|
56811
57093
|
}
|
|
56812
57094
|
this.readyState = WebSocket.CLOSING;
|
|
57095
|
+
if (this._nativeWs) {
|
|
57096
|
+
this._nativeWs.close(code, reason);
|
|
57097
|
+
return;
|
|
57098
|
+
}
|
|
56813
57099
|
if (messageChannel) {
|
|
56814
57100
|
messageChannel.postMessage({
|
|
56815
57101
|
type: "disconnect",
|
|
@@ -56833,7 +57119,18 @@ sys 0m0.000s
|
|
|
56833
57119
|
ping() {}
|
|
56834
57120
|
pong() {}
|
|
56835
57121
|
terminate() {
|
|
56836
|
-
this.
|
|
57122
|
+
if (this._nativeWs) {
|
|
57123
|
+
this._nativeWs.close();
|
|
57124
|
+
this._nativeWs = null;
|
|
57125
|
+
}
|
|
57126
|
+
this.readyState = WebSocket.CLOSED;
|
|
57127
|
+
const closeEvent = new CloseEventPolyfill("close", {
|
|
57128
|
+
code: 1006,
|
|
57129
|
+
reason: "Connection terminated",
|
|
57130
|
+
wasClean: false
|
|
57131
|
+
});
|
|
57132
|
+
this.emit("close", closeEvent);
|
|
57133
|
+
if (this.onclose) this.onclose(closeEvent);
|
|
56837
57134
|
}
|
|
56838
57135
|
_setServer(server) {
|
|
56839
57136
|
this._server = server;
|
|
@@ -57747,7 +58044,7 @@ sys 0m0.000s
|
|
|
57747
58044
|
}
|
|
57748
58045
|
let entryPoints = options.entryPoints;
|
|
57749
58046
|
if (entryPoints && globalVFS) {
|
|
57750
|
-
const absWorkingDir = options.absWorkingDir || "/";
|
|
58047
|
+
const absWorkingDir = options.absWorkingDir || (typeof globalThis !== "undefined" && globalThis.process && typeof globalThis.process.cwd === "function" ? globalThis.process.cwd() : "/");
|
|
57751
58048
|
entryPoints = entryPoints.map((ep)=>{
|
|
57752
58049
|
if (ep.includes("vfs:")) {
|
|
57753
58050
|
const vfsIndex = ep.indexOf("vfs:");
|
|
@@ -57773,11 +58070,13 @@ sys 0m0.000s
|
|
|
57773
58070
|
return ep;
|
|
57774
58071
|
});
|
|
57775
58072
|
}
|
|
58073
|
+
const resolvedAbsWorkingDir = options.absWorkingDir || (typeof globalThis !== "undefined" && globalThis.process && typeof globalThis.process.cwd === "function" ? globalThis.process.cwd() : "/");
|
|
57776
58074
|
const result = await esbuildInstance.build({
|
|
57777
58075
|
...options,
|
|
57778
58076
|
entryPoints,
|
|
57779
58077
|
plugins,
|
|
57780
|
-
write: false
|
|
58078
|
+
write: false,
|
|
58079
|
+
absWorkingDir: resolvedAbsWorkingDir
|
|
57781
58080
|
});
|
|
57782
58081
|
if (result.outputFiles) {
|
|
57783
58082
|
for (const file of result.outputFiles){
|
|
@@ -59792,6 +60091,10 @@ sys 0m0.000s
|
|
|
59792
60091
|
paths: []
|
|
59793
60092
|
};
|
|
59794
60093
|
moduleCache[resolvedPath] = module;
|
|
60094
|
+
const cacheKeys = Object.keys(moduleCache);
|
|
60095
|
+
if (cacheKeys.length > 2e3) {
|
|
60096
|
+
delete moduleCache[cacheKeys[0]];
|
|
60097
|
+
}
|
|
59795
60098
|
if (resolvedPath.endsWith(".json")) {
|
|
59796
60099
|
const content = vfs.readFileSync(resolvedPath, "utf8");
|
|
59797
60100
|
module.exports = JSON.parse(content);
|
|
@@ -60035,25 +60338,13 @@ ${code}
|
|
|
60035
60338
|
if (!input) return "";
|
|
60036
60339
|
const bytes = input instanceof ArrayBuffer ? new Uint8Array(input) : new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
60037
60340
|
if (this.encoding === "base64") {
|
|
60038
|
-
|
|
60039
|
-
for(let i = 0; i < bytes.length; i++){
|
|
60040
|
-
binary += String.fromCharCode(bytes[i]);
|
|
60041
|
-
}
|
|
60042
|
-
return btoa(binary);
|
|
60341
|
+
return uint8ToBase64(bytes);
|
|
60043
60342
|
}
|
|
60044
60343
|
if (this.encoding === "base64url") {
|
|
60045
|
-
|
|
60046
|
-
for(let i = 0; i < bytes.length; i++){
|
|
60047
|
-
binary += String.fromCharCode(bytes[i]);
|
|
60048
|
-
}
|
|
60049
|
-
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
60344
|
+
return uint8ToBase64(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
60050
60345
|
}
|
|
60051
60346
|
if (this.encoding === "hex") {
|
|
60052
|
-
|
|
60053
|
-
for(let i = 0; i < bytes.length; i++){
|
|
60054
|
-
hex += bytes[i].toString(16).padStart(2, "0");
|
|
60055
|
-
}
|
|
60056
|
-
return hex;
|
|
60347
|
+
return uint8ToHex(bytes);
|
|
60057
60348
|
}
|
|
60058
60349
|
return new OriginalTextDecoder("utf-8").decode(input, options2);
|
|
60059
60350
|
}
|
|
@@ -60137,6 +60428,42 @@ ${code}
|
|
|
60137
60428
|
getProcess() {
|
|
60138
60429
|
return this.process;
|
|
60139
60430
|
}
|
|
60431
|
+
createREPL() {
|
|
60432
|
+
const require2 = createRequire(this.vfs, this.fsShim, this.process, "/", this.moduleCache, this.options, this.processedCodeCache);
|
|
60433
|
+
const consoleWrapper2 = createConsoleWrapper(this.options.onConsole);
|
|
60434
|
+
const process2 = this.process;
|
|
60435
|
+
const buffer = bufferModule.Buffer;
|
|
60436
|
+
const GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor;
|
|
60437
|
+
const replGen = new GeneratorFunction("require", "console", "process", "Buffer", `var __code, __result;
|
|
60438
|
+
while (true) {
|
|
60439
|
+
__code = yield;
|
|
60440
|
+
try {
|
|
60441
|
+
__result = eval(__code);
|
|
60442
|
+
yield { value: __result, error: null };
|
|
60443
|
+
} catch (e) {
|
|
60444
|
+
yield { value: undefined, error: e };
|
|
60445
|
+
}
|
|
60446
|
+
}`)(require2, consoleWrapper2, process2, buffer);
|
|
60447
|
+
replGen.next();
|
|
60448
|
+
return {
|
|
60449
|
+
eval (code2) {
|
|
60450
|
+
const transformed = code2.replace(/^\s*(const|let)\s+/gm, "var ");
|
|
60451
|
+
const exprResult = replGen.next("(" + transformed + ")").value;
|
|
60452
|
+
if (!exprResult.error) {
|
|
60453
|
+
replGen.next();
|
|
60454
|
+
return exprResult.value;
|
|
60455
|
+
}
|
|
60456
|
+
replGen.next();
|
|
60457
|
+
const stmtResult = replGen.next(transformed).value;
|
|
60458
|
+
if (stmtResult.error) {
|
|
60459
|
+
replGen.next();
|
|
60460
|
+
throw stmtResult.error;
|
|
60461
|
+
}
|
|
60462
|
+
replGen.next();
|
|
60463
|
+
return stmtResult.value;
|
|
60464
|
+
}
|
|
60465
|
+
};
|
|
60466
|
+
}
|
|
60140
60467
|
}
|
|
60141
60468
|
let runtime = null;
|
|
60142
60469
|
let vfs = null;
|