almostnode 0.2.7 → 0.2.9
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 +4 -2
- package/dist/CNAME +1 -0
- package/dist/__sw__.js +80 -84
- package/dist/assets/{runtime-worker-B8_LZkBX.js → runtime-worker-ujGAG2t7.js} +1278 -828
- package/dist/assets/runtime-worker-ujGAG2t7.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 +3024 -2465
- 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 +3336 -2787
- package/dist/index.mjs.map +1 -1
- package/dist/og-image.png +0 -0
- package/dist/runtime.d.ts +26 -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/types/package-json.d.ts +1 -0
- package/dist/types/package-json.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 +271 -25
- 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 +312 -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 +95 -2
- package/src/types/package-json.ts +1 -0
- 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,6 +3156,609 @@
|
|
|
3161
3156
|
isIPv4: isIPv4,
|
|
3162
3157
|
isIPv6: isIPv6
|
|
3163
3158
|
});
|
|
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;
|
|
3178
|
+
}
|
|
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);
|
|
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
|
+
}
|
|
3204
|
+
} else {
|
|
3205
|
+
buffer = data;
|
|
3206
|
+
}
|
|
3207
|
+
this.data.push(buffer);
|
|
3208
|
+
return this;
|
|
3209
|
+
}
|
|
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);
|
|
3215
|
+
}
|
|
3216
|
+
digest(encoding) {
|
|
3217
|
+
const combined = concatBuffers(this.data);
|
|
3218
|
+
const hash = syncHash(combined, this.algorithm);
|
|
3219
|
+
return encodeResult(hash, encoding);
|
|
3220
|
+
}
|
|
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;
|
|
3232
|
+
}
|
|
3233
|
+
update(data, encoding) {
|
|
3234
|
+
const buffer = typeof data === "string" ? BufferPolyfill.from(data) : data;
|
|
3235
|
+
this.data.push(buffer);
|
|
3236
|
+
return this;
|
|
3237
|
+
}
|
|
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);
|
|
3250
|
+
}
|
|
3251
|
+
digest(encoding) {
|
|
3252
|
+
const combined = concatBuffers(this.data);
|
|
3253
|
+
const hash = syncHmac(combined, this.key, this.algorithm);
|
|
3254
|
+
return encodeResult(hash, encoding);
|
|
3255
|
+
}
|
|
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;
|
|
3289
|
+
}
|
|
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];
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
derivedKey.set(block, (blockNum - 1) * hashLen);
|
|
3310
|
+
}
|
|
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;
|
|
3321
|
+
}
|
|
3322
|
+
throw error;
|
|
3323
|
+
}
|
|
3324
|
+
if (callback) {
|
|
3325
|
+
signAsync(alg, data, keyInfo).then((sig)=>callback(null, sig)).catch((err)=>callback(err, null));
|
|
3326
|
+
return;
|
|
3327
|
+
}
|
|
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;
|
|
3339
|
+
}
|
|
3340
|
+
throw error;
|
|
3341
|
+
}
|
|
3342
|
+
if (callback) {
|
|
3343
|
+
verifyAsync(alg, data, keyInfo, signature).then((result)=>callback(null, result)).catch((err)=>callback(err, false));
|
|
3344
|
+
return;
|
|
3345
|
+
}
|
|
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);
|
|
3364
|
+
return this;
|
|
3365
|
+
}
|
|
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));
|
|
3372
|
+
}
|
|
3373
|
+
if (outputEncoding === "hex") {
|
|
3374
|
+
return Array.from(signature).map((b)=>b.toString(16).padStart(2, "0")).join("");
|
|
3375
|
+
}
|
|
3376
|
+
return signature;
|
|
3377
|
+
}
|
|
3378
|
+
}
|
|
3379
|
+
class Verify extends EventEmitter {
|
|
3380
|
+
algorithm;
|
|
3381
|
+
data = [];
|
|
3382
|
+
constructor(algorithm){
|
|
3383
|
+
super();
|
|
3384
|
+
this.algorithm = algorithm;
|
|
3385
|
+
}
|
|
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)));
|
|
3400
|
+
} else {
|
|
3401
|
+
sig = BufferPolyfill.from(signature);
|
|
3402
|
+
}
|
|
3403
|
+
} else {
|
|
3404
|
+
sig = signature;
|
|
3405
|
+
}
|
|
3406
|
+
return verifySync(this.algorithm, combined, keyInfo, sig);
|
|
3407
|
+
}
|
|
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;
|
|
3417
|
+
}
|
|
3418
|
+
get type() {
|
|
3419
|
+
return this._type;
|
|
3420
|
+
}
|
|
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;
|
|
3427
|
+
}
|
|
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;
|
|
3434
|
+
}
|
|
3435
|
+
export(options) {
|
|
3436
|
+
if (this._keyData instanceof Uint8Array) {
|
|
3437
|
+
return BufferPolyfill.from(this._keyData);
|
|
3438
|
+
}
|
|
3439
|
+
throw new Error("Cannot export CryptoKey synchronously");
|
|
3440
|
+
}
|
|
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 _isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
3761
|
+
const _BrowserWebSocket = _isBrowser && typeof globalThis.WebSocket === "function" ? globalThis.WebSocket : null;
|
|
3164
3762
|
class IncomingMessage extends Readable {
|
|
3165
3763
|
httpVersion = "1.1";
|
|
3166
3764
|
httpVersionMajor = 1;
|
|
@@ -3584,10 +4182,22 @@
|
|
|
3584
4182
|
if (this._aborted) return;
|
|
3585
4183
|
try {
|
|
3586
4184
|
const protocol = this._protocol === "https" ? "https:" : "http:";
|
|
3587
|
-
|
|
3588
|
-
|
|
4185
|
+
let hostname = this._options.hostname || "";
|
|
4186
|
+
let port = this._options.port ? `:${this._options.port}` : "";
|
|
4187
|
+
if (!hostname && this._options.host) {
|
|
4188
|
+
const hostParts = this._options.host.split(":");
|
|
4189
|
+
hostname = hostParts[0];
|
|
4190
|
+
if (!port && hostParts[1]) {
|
|
4191
|
+
port = `:${hostParts[1]}`;
|
|
4192
|
+
}
|
|
4193
|
+
}
|
|
4194
|
+
if (!hostname) hostname = "localhost";
|
|
3589
4195
|
const path = this._options.path || "/";
|
|
3590
4196
|
const url = `${protocol}//${hostname}${port}${path}`;
|
|
4197
|
+
if (this.headers["upgrade"]?.toLowerCase() === "websocket") {
|
|
4198
|
+
this._handleWebSocketUpgrade(url);
|
|
4199
|
+
return;
|
|
4200
|
+
}
|
|
3591
4201
|
const corsProxy = getCorsProxy();
|
|
3592
4202
|
const fetchUrl = corsProxy ? corsProxy + encodeURIComponent(url) : url;
|
|
3593
4203
|
const fetchOptions = {
|
|
@@ -3636,6 +4246,120 @@
|
|
|
3636
4246
|
msg._setBody(BufferPolyfill.from(body));
|
|
3637
4247
|
return msg;
|
|
3638
4248
|
}
|
|
4249
|
+
_handleWebSocketUpgrade(url) {
|
|
4250
|
+
const wsUrl = url.replace(/^https:/, "wss:").replace(/^http:/, "ws:");
|
|
4251
|
+
const wsKey = this.headers["sec-websocket-key"] || "";
|
|
4252
|
+
const NativeWS = _BrowserWebSocket;
|
|
4253
|
+
if (!NativeWS) {
|
|
4254
|
+
setTimeout(()=>{
|
|
4255
|
+
this.emit("error", new TypeError("Failed to fetch"));
|
|
4256
|
+
}, 0);
|
|
4257
|
+
return;
|
|
4258
|
+
}
|
|
4259
|
+
const GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
4260
|
+
const acceptValue = createHash("sha1").update(wsKey + GUID).digest("base64");
|
|
4261
|
+
let nativeWs;
|
|
4262
|
+
try {
|
|
4263
|
+
nativeWs = new NativeWS(wsUrl);
|
|
4264
|
+
nativeWs.binaryType = "arraybuffer";
|
|
4265
|
+
} catch (e) {
|
|
4266
|
+
setTimeout(()=>{
|
|
4267
|
+
this.emit("error", e instanceof Error ? e : new Error(String(e)));
|
|
4268
|
+
}, 0);
|
|
4269
|
+
return;
|
|
4270
|
+
}
|
|
4271
|
+
const socket = new Socket$1();
|
|
4272
|
+
if (typeof socket.cork !== "function") socket.cork = ()=>{};
|
|
4273
|
+
if (typeof socket.uncork !== "function") socket.uncork = ()=>{};
|
|
4274
|
+
socket._readableState = {
|
|
4275
|
+
endEmitted: false
|
|
4276
|
+
};
|
|
4277
|
+
socket._writableState = {
|
|
4278
|
+
finished: false,
|
|
4279
|
+
errorEmitted: false
|
|
4280
|
+
};
|
|
4281
|
+
let writeBuffer = new Uint8Array(0);
|
|
4282
|
+
socket.write = (chunk, encodingOrCallback, callback)=>{
|
|
4283
|
+
const data = typeof chunk === "string" ? BufferPolyfill.from(chunk) : new Uint8Array(chunk);
|
|
4284
|
+
const cb = typeof encodingOrCallback === "function" ? encodingOrCallback : callback;
|
|
4285
|
+
const newBuf = new Uint8Array(writeBuffer.length + data.length);
|
|
4286
|
+
newBuf.set(writeBuffer, 0);
|
|
4287
|
+
newBuf.set(data, writeBuffer.length);
|
|
4288
|
+
writeBuffer = newBuf;
|
|
4289
|
+
while(writeBuffer.length >= 2){
|
|
4290
|
+
const parsed = _parseWsFrame(writeBuffer);
|
|
4291
|
+
if (!parsed) break;
|
|
4292
|
+
const { opcode, payload, totalLength } = parsed;
|
|
4293
|
+
writeBuffer = writeBuffer.slice(totalLength);
|
|
4294
|
+
if (nativeWs.readyState !== NativeWS.OPEN) continue;
|
|
4295
|
+
if (opcode === 8) {
|
|
4296
|
+
nativeWs.close();
|
|
4297
|
+
} else if (opcode === 9) {
|
|
4298
|
+
nativeWs.send(payload);
|
|
4299
|
+
} else if (opcode === 10) ;
|
|
4300
|
+
else if (opcode === 1) {
|
|
4301
|
+
const text = new TextDecoder().decode(payload);
|
|
4302
|
+
nativeWs.send(text);
|
|
4303
|
+
} else if (opcode === 2) {
|
|
4304
|
+
nativeWs.send(payload);
|
|
4305
|
+
}
|
|
4306
|
+
}
|
|
4307
|
+
if (cb) queueMicrotask(()=>cb(null));
|
|
4308
|
+
return true;
|
|
4309
|
+
};
|
|
4310
|
+
nativeWs.onopen = ()=>{
|
|
4311
|
+
const response = new IncomingMessage(socket);
|
|
4312
|
+
response.statusCode = 101;
|
|
4313
|
+
response.statusMessage = "Switching Protocols";
|
|
4314
|
+
response.headers = {
|
|
4315
|
+
"upgrade": "websocket",
|
|
4316
|
+
"connection": "Upgrade",
|
|
4317
|
+
"sec-websocket-accept": acceptValue
|
|
4318
|
+
};
|
|
4319
|
+
response.complete = true;
|
|
4320
|
+
response.push(null);
|
|
4321
|
+
this.emit("upgrade", response, socket, BufferPolyfill.alloc(0));
|
|
4322
|
+
};
|
|
4323
|
+
nativeWs.onmessage = (event)=>{
|
|
4324
|
+
let payload;
|
|
4325
|
+
let opcode;
|
|
4326
|
+
if (typeof event.data === "string") {
|
|
4327
|
+
payload = new TextEncoder().encode(event.data);
|
|
4328
|
+
opcode = 1;
|
|
4329
|
+
} else if (event.data instanceof ArrayBuffer) {
|
|
4330
|
+
payload = new Uint8Array(event.data);
|
|
4331
|
+
opcode = 2;
|
|
4332
|
+
} else {
|
|
4333
|
+
return;
|
|
4334
|
+
}
|
|
4335
|
+
const frame = _createWsFrame(opcode, payload, false);
|
|
4336
|
+
socket._receiveData(BufferPolyfill.from(frame));
|
|
4337
|
+
};
|
|
4338
|
+
nativeWs.onclose = (event)=>{
|
|
4339
|
+
const code = event.code || 1e3;
|
|
4340
|
+
const closePayload = new Uint8Array(2);
|
|
4341
|
+
closePayload[0] = code >> 8 & 255;
|
|
4342
|
+
closePayload[1] = code & 255;
|
|
4343
|
+
const frame = _createWsFrame(8, closePayload, false);
|
|
4344
|
+
socket._receiveData(BufferPolyfill.from(frame));
|
|
4345
|
+
setTimeout(()=>{
|
|
4346
|
+
socket._readableState.endEmitted = true;
|
|
4347
|
+
socket._receiveEnd();
|
|
4348
|
+
socket.emit("close", false);
|
|
4349
|
+
}, 10);
|
|
4350
|
+
};
|
|
4351
|
+
nativeWs.onerror = ()=>{
|
|
4352
|
+
socket.emit("error", new Error("WebSocket connection error"));
|
|
4353
|
+
socket.destroy();
|
|
4354
|
+
};
|
|
4355
|
+
const origDestroy = socket.destroy.bind(socket);
|
|
4356
|
+
socket.destroy = (error)=>{
|
|
4357
|
+
if (nativeWs.readyState === NativeWS.OPEN || nativeWs.readyState === NativeWS.CONNECTING) {
|
|
4358
|
+
nativeWs.close();
|
|
4359
|
+
}
|
|
4360
|
+
return origDestroy(error);
|
|
4361
|
+
};
|
|
4362
|
+
}
|
|
3639
4363
|
}
|
|
3640
4364
|
function parseRequestArgs(urlOrOptions, optionsOrCallback, callback) {
|
|
3641
4365
|
let options;
|
|
@@ -3760,6 +4484,94 @@
|
|
|
3760
4484
|
}
|
|
3761
4485
|
}
|
|
3762
4486
|
const globalAgent = new Agent();
|
|
4487
|
+
function _parseWsFrame(data) {
|
|
4488
|
+
if (data.length < 2) return null;
|
|
4489
|
+
const opcode = data[0] & 15;
|
|
4490
|
+
const masked = (data[1] & 128) !== 0;
|
|
4491
|
+
let payloadLength = data[1] & 127;
|
|
4492
|
+
let offset = 2;
|
|
4493
|
+
if (payloadLength === 126) {
|
|
4494
|
+
if (data.length < 4) return null;
|
|
4495
|
+
payloadLength = data[2] << 8 | data[3];
|
|
4496
|
+
offset = 4;
|
|
4497
|
+
} else if (payloadLength === 127) {
|
|
4498
|
+
if (data.length < 10) return null;
|
|
4499
|
+
payloadLength = data[6] << 24 | data[7] << 16 | data[8] << 8 | data[9];
|
|
4500
|
+
offset = 10;
|
|
4501
|
+
}
|
|
4502
|
+
if (masked) {
|
|
4503
|
+
if (data.length < offset + 4 + payloadLength) return null;
|
|
4504
|
+
const maskKey = data.slice(offset, offset + 4);
|
|
4505
|
+
offset += 4;
|
|
4506
|
+
const payload = new Uint8Array(payloadLength);
|
|
4507
|
+
for(let i = 0; i < payloadLength; i++){
|
|
4508
|
+
payload[i] = data[offset + i] ^ maskKey[i % 4];
|
|
4509
|
+
}
|
|
4510
|
+
return {
|
|
4511
|
+
opcode,
|
|
4512
|
+
payload,
|
|
4513
|
+
totalLength: offset + payloadLength
|
|
4514
|
+
};
|
|
4515
|
+
} else {
|
|
4516
|
+
if (data.length < offset + payloadLength) return null;
|
|
4517
|
+
const payload = data.slice(offset, offset + payloadLength);
|
|
4518
|
+
return {
|
|
4519
|
+
opcode,
|
|
4520
|
+
payload,
|
|
4521
|
+
totalLength: offset + payloadLength
|
|
4522
|
+
};
|
|
4523
|
+
}
|
|
4524
|
+
}
|
|
4525
|
+
function _createWsFrame(opcode, payload, masked) {
|
|
4526
|
+
const length = payload.length;
|
|
4527
|
+
let headerSize = 2;
|
|
4528
|
+
if (length > 125 && length <= 65535) {
|
|
4529
|
+
headerSize += 2;
|
|
4530
|
+
} else if (length > 65535) {
|
|
4531
|
+
headerSize += 8;
|
|
4532
|
+
}
|
|
4533
|
+
if (masked) {
|
|
4534
|
+
headerSize += 4;
|
|
4535
|
+
}
|
|
4536
|
+
const frame = new Uint8Array(headerSize + length);
|
|
4537
|
+
frame[0] = 128 | opcode;
|
|
4538
|
+
let offset = 2;
|
|
4539
|
+
if (length <= 125) {
|
|
4540
|
+
frame[1] = (masked ? 128 : 0) | length;
|
|
4541
|
+
} else if (length <= 65535) {
|
|
4542
|
+
frame[1] = (masked ? 128 : 0) | 126;
|
|
4543
|
+
frame[2] = length >> 8 & 255;
|
|
4544
|
+
frame[3] = length & 255;
|
|
4545
|
+
offset = 4;
|
|
4546
|
+
} else {
|
|
4547
|
+
frame[1] = (masked ? 128 : 0) | 127;
|
|
4548
|
+
frame[2] = 0;
|
|
4549
|
+
frame[3] = 0;
|
|
4550
|
+
frame[4] = 0;
|
|
4551
|
+
frame[5] = 0;
|
|
4552
|
+
frame[6] = length >> 24 & 255;
|
|
4553
|
+
frame[7] = length >> 16 & 255;
|
|
4554
|
+
frame[8] = length >> 8 & 255;
|
|
4555
|
+
frame[9] = length & 255;
|
|
4556
|
+
offset = 10;
|
|
4557
|
+
}
|
|
4558
|
+
if (masked) {
|
|
4559
|
+
const maskKey = new Uint8Array(4);
|
|
4560
|
+
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
4561
|
+
crypto.getRandomValues(maskKey);
|
|
4562
|
+
} else {
|
|
4563
|
+
for(let i = 0; i < 4; i++)maskKey[i] = Math.floor(Math.random() * 256);
|
|
4564
|
+
}
|
|
4565
|
+
frame.set(maskKey, offset);
|
|
4566
|
+
offset += 4;
|
|
4567
|
+
for(let i = 0; i < length; i++){
|
|
4568
|
+
frame[offset + i] = payload[i] ^ maskKey[i % 4];
|
|
4569
|
+
}
|
|
4570
|
+
} else {
|
|
4571
|
+
frame.set(payload, offset);
|
|
4572
|
+
}
|
|
4573
|
+
return frame;
|
|
4574
|
+
}
|
|
3763
4575
|
var http = {
|
|
3764
4576
|
Server: Server$2,
|
|
3765
4577
|
IncomingMessage,
|
|
@@ -3776,7 +4588,9 @@
|
|
|
3776
4588
|
setServerCloseCallback,
|
|
3777
4589
|
_createClientRequest,
|
|
3778
4590
|
Agent,
|
|
3779
|
-
globalAgent
|
|
4591
|
+
globalAgent,
|
|
4592
|
+
_parseWsFrame,
|
|
4593
|
+
_createWsFrame
|
|
3780
4594
|
};
|
|
3781
4595
|
var httpShim = Object.freeze({
|
|
3782
4596
|
__proto__: null,
|
|
@@ -3788,6 +4602,8 @@
|
|
|
3788
4602
|
Server: Server$2,
|
|
3789
4603
|
ServerResponse: ServerResponse,
|
|
3790
4604
|
_createClientRequest: _createClientRequest,
|
|
4605
|
+
_createWsFrame: _createWsFrame,
|
|
4606
|
+
_parseWsFrame: _parseWsFrame,
|
|
3791
4607
|
_registerServer: _registerServer,
|
|
3792
4608
|
_unregisterServer: _unregisterServer,
|
|
3793
4609
|
createServer: createServer$2,
|
|
@@ -4391,767 +5207,175 @@
|
|
|
4391
5207
|
function release() {
|
|
4392
5208
|
return "5.10.0";
|
|
4393
5209
|
}
|
|
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");
|
|
4838
|
-
}
|
|
4839
|
-
}
|
|
4840
|
-
function createSecretKey(key, encoding) {
|
|
4841
|
-
const keyBuffer = typeof key === "string" ? BufferPolyfill.from(key, encoding) : key;
|
|
4842
|
-
return new KeyObject("secret", keyBuffer);
|
|
4843
|
-
}
|
|
4844
|
-
function createPublicKey(key) {
|
|
4845
|
-
const keyInfo = extractKeyInfo(key);
|
|
4846
|
-
return new KeyObject("public", keyInfo.keyData, keyInfo.algorithm);
|
|
5210
|
+
function version$1() {
|
|
5211
|
+
return "#1 SMP";
|
|
4847
5212
|
}
|
|
4848
|
-
function
|
|
4849
|
-
|
|
4850
|
-
return new KeyObject("private", keyInfo.keyData, keyInfo.algorithm);
|
|
5213
|
+
function machine() {
|
|
5214
|
+
return "x86_64";
|
|
4851
5215
|
}
|
|
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;
|
|
5216
|
+
function tmpdir() {
|
|
5217
|
+
return "/tmp";
|
|
4861
5218
|
}
|
|
4862
|
-
function
|
|
5219
|
+
function homedir() {
|
|
5220
|
+
return "/home/user";
|
|
5221
|
+
}
|
|
5222
|
+
function cpus() {
|
|
5223
|
+
const cpu = {
|
|
5224
|
+
model: "Virtual CPU",
|
|
5225
|
+
speed: 2400,
|
|
5226
|
+
times: {
|
|
5227
|
+
user: 0,
|
|
5228
|
+
nice: 0,
|
|
5229
|
+
sys: 0,
|
|
5230
|
+
idle: 0,
|
|
5231
|
+
irq: 0
|
|
5232
|
+
}
|
|
5233
|
+
};
|
|
4863
5234
|
return [
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
"aes-128-gcm",
|
|
4867
|
-
"aes-256-gcm"
|
|
5235
|
+
cpu,
|
|
5236
|
+
cpu
|
|
4868
5237
|
];
|
|
4869
5238
|
}
|
|
4870
|
-
function
|
|
5239
|
+
function totalmem() {
|
|
5240
|
+
return 4 * 1024 * 1024 * 1024;
|
|
5241
|
+
}
|
|
5242
|
+
function freemem() {
|
|
5243
|
+
return 2 * 1024 * 1024 * 1024;
|
|
5244
|
+
}
|
|
5245
|
+
function uptime() {
|
|
5246
|
+
return Math.floor(performance.now() / 1e3);
|
|
5247
|
+
}
|
|
5248
|
+
function loadavg() {
|
|
4871
5249
|
return [
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
"sha512"
|
|
5250
|
+
0.5,
|
|
5251
|
+
0.5,
|
|
5252
|
+
0.5
|
|
4876
5253
|
];
|
|
4877
5254
|
}
|
|
4878
|
-
|
|
4879
|
-
SSL_OP_ALL: 0,
|
|
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
|
-
}
|
|
4900
|
-
}
|
|
4901
|
-
function getWebCryptoAlgorithm(nodeAlgorithm) {
|
|
4902
|
-
const alg = nodeAlgorithm.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
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
|
-
}
|
|
5255
|
+
function networkInterfaces() {
|
|
4937
5256
|
return {
|
|
4938
|
-
|
|
4939
|
-
|
|
5257
|
+
lo: [
|
|
5258
|
+
{
|
|
5259
|
+
address: "127.0.0.1",
|
|
5260
|
+
netmask: "255.0.0.0",
|
|
5261
|
+
family: "IPv4",
|
|
5262
|
+
mac: "00:00:00:00:00:00",
|
|
5263
|
+
internal: true,
|
|
5264
|
+
cidr: "127.0.0.1/8"
|
|
5265
|
+
}
|
|
5266
|
+
]
|
|
4940
5267
|
};
|
|
4941
5268
|
}
|
|
4942
|
-
function
|
|
4943
|
-
if (key instanceof KeyObject) {
|
|
4944
|
-
return {
|
|
4945
|
-
keyData: key._keyData,
|
|
4946
|
-
algorithm: key._algorithm,
|
|
4947
|
-
type: key._type,
|
|
4948
|
-
format: "raw"
|
|
4949
|
-
};
|
|
4950
|
-
}
|
|
4951
|
-
if (typeof key === "object" && "key" in key) {
|
|
4952
|
-
return extractKeyInfo(key.key);
|
|
4953
|
-
}
|
|
4954
|
-
const keyStr = typeof key === "string" ? key : key.toString();
|
|
4955
|
-
if (keyStr.includes("-----BEGIN")) {
|
|
4956
|
-
const isPrivate = keyStr.includes("PRIVATE");
|
|
4957
|
-
const isPublic = keyStr.includes("PUBLIC");
|
|
4958
|
-
const base64 = keyStr.replace(/-----BEGIN [^-]+-----/, "").replace(/-----END [^-]+-----/, "").replace(/\s/g, "");
|
|
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;
|
|
5269
|
+
function userInfo() {
|
|
4972
5270
|
return {
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
5271
|
+
username: "user",
|
|
5272
|
+
uid: 1e3,
|
|
5273
|
+
gid: 1e3,
|
|
5274
|
+
shell: "/bin/bash",
|
|
5275
|
+
homedir: "/home/user"
|
|
4976
5276
|
};
|
|
4977
5277
|
}
|
|
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;
|
|
4987
|
-
}
|
|
4988
|
-
function encodeResult(data, encoding) {
|
|
4989
|
-
if (encoding === "hex") {
|
|
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);
|
|
4996
|
-
}
|
|
4997
|
-
function syncHash(data, algorithm) {
|
|
4998
|
-
let size;
|
|
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;
|
|
5024
|
-
}
|
|
5025
|
-
function syncHmac(data, key, algorithm) {
|
|
5026
|
-
const combined = new Uint8Array(key.length + data.length);
|
|
5027
|
-
combined.set(key, 0);
|
|
5028
|
-
combined.set(data, key.length);
|
|
5029
|
-
return syncHash(combined, algorithm);
|
|
5030
|
-
}
|
|
5031
|
-
async function signAsync(algorithm, data, keyInfo) {
|
|
5032
|
-
const webCryptoAlg = getWebCryptoAlgorithm(algorithm);
|
|
5033
|
-
try {
|
|
5034
|
-
const cryptoKey = await importKey(keyInfo, webCryptoAlg, [
|
|
5035
|
-
"sign"
|
|
5036
|
-
]);
|
|
5037
|
-
const signatureAlg = webCryptoAlg.hash ? {
|
|
5038
|
-
name: webCryptoAlg.name,
|
|
5039
|
-
hash: webCryptoAlg.hash
|
|
5040
|
-
} : {
|
|
5041
|
-
name: webCryptoAlg.name
|
|
5042
|
-
};
|
|
5043
|
-
const dataBuffer = new Uint8Array(data).buffer;
|
|
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
|
-
}
|
|
5050
|
-
}
|
|
5051
|
-
async function verifyAsync(algorithm, data, keyInfo, signature) {
|
|
5052
|
-
const webCryptoAlg = getWebCryptoAlgorithm(algorithm);
|
|
5053
|
-
try {
|
|
5054
|
-
const cryptoKey = await importKey(keyInfo, webCryptoAlg, [
|
|
5055
|
-
"verify"
|
|
5056
|
-
]);
|
|
5057
|
-
const verifyAlg = webCryptoAlg.hash ? {
|
|
5058
|
-
name: webCryptoAlg.name,
|
|
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
|
-
}
|
|
5070
|
-
}
|
|
5071
|
-
function signSync(algorithm, data, keyInfo) {
|
|
5072
|
-
const keyData = keyInfo.keyData instanceof Uint8Array ? keyInfo.keyData : new Uint8Array(0);
|
|
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);
|
|
5278
|
+
function endianness() {
|
|
5279
|
+
return "LE";
|
|
5078
5280
|
}
|
|
5079
|
-
function
|
|
5080
|
-
|
|
5081
|
-
return timingSafeEqual(BufferPolyfill.from(signature), expectedSig);
|
|
5281
|
+
function getPriority(pid) {
|
|
5282
|
+
return 0;
|
|
5082
5283
|
}
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5284
|
+
function setPriority(pid, priority) {}
|
|
5285
|
+
const EOL = "\n";
|
|
5286
|
+
const constants$4 = {
|
|
5287
|
+
signals: {
|
|
5288
|
+
SIGHUP: 1,
|
|
5289
|
+
SIGINT: 2,
|
|
5290
|
+
SIGQUIT: 3,
|
|
5291
|
+
SIGILL: 4,
|
|
5292
|
+
SIGTRAP: 5,
|
|
5293
|
+
SIGABRT: 6,
|
|
5294
|
+
SIGBUS: 7,
|
|
5295
|
+
SIGFPE: 8,
|
|
5296
|
+
SIGKILL: 9,
|
|
5297
|
+
SIGUSR1: 10,
|
|
5298
|
+
SIGSEGV: 11,
|
|
5299
|
+
SIGUSR2: 12,
|
|
5300
|
+
SIGPIPE: 13,
|
|
5301
|
+
SIGALRM: 14,
|
|
5302
|
+
SIGTERM: 15,
|
|
5303
|
+
SIGCHLD: 17,
|
|
5304
|
+
SIGCONT: 18,
|
|
5305
|
+
SIGSTOP: 19,
|
|
5306
|
+
SIGTSTP: 20,
|
|
5307
|
+
SIGTTIN: 21,
|
|
5308
|
+
SIGTTOU: 22,
|
|
5309
|
+
SIGURG: 23,
|
|
5310
|
+
SIGXCPU: 24,
|
|
5311
|
+
SIGXFSZ: 25,
|
|
5312
|
+
SIGVTALRM: 26,
|
|
5313
|
+
SIGPROF: 27,
|
|
5314
|
+
SIGWINCH: 28,
|
|
5315
|
+
SIGIO: 29,
|
|
5316
|
+
SIGPWR: 30,
|
|
5317
|
+
SIGSYS: 31
|
|
5318
|
+
},
|
|
5319
|
+
errno: {},
|
|
5320
|
+
priority: {
|
|
5321
|
+
PRIORITY_LOW: 19,
|
|
5322
|
+
PRIORITY_BELOW_NORMAL: 10,
|
|
5323
|
+
PRIORITY_NORMAL: 0,
|
|
5324
|
+
PRIORITY_ABOVE_NORMAL: -7,
|
|
5325
|
+
PRIORITY_HIGH: -14,
|
|
5326
|
+
PRIORITY_HIGHEST: -20
|
|
5107
5327
|
}
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
var
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5328
|
+
};
|
|
5329
|
+
const devNull = "/dev/null";
|
|
5330
|
+
var os$1 = {
|
|
5331
|
+
hostname,
|
|
5332
|
+
platform,
|
|
5333
|
+
arch,
|
|
5334
|
+
type,
|
|
5335
|
+
release,
|
|
5336
|
+
version: version$1,
|
|
5337
|
+
machine,
|
|
5338
|
+
tmpdir,
|
|
5339
|
+
homedir,
|
|
5340
|
+
cpus,
|
|
5341
|
+
totalmem,
|
|
5342
|
+
freemem,
|
|
5343
|
+
uptime,
|
|
5344
|
+
loadavg,
|
|
5345
|
+
networkInterfaces,
|
|
5346
|
+
userInfo,
|
|
5347
|
+
endianness,
|
|
5348
|
+
getPriority,
|
|
5349
|
+
setPriority,
|
|
5350
|
+
EOL,
|
|
5126
5351
|
constants: constants$4,
|
|
5127
|
-
|
|
5128
|
-
createSecretKey,
|
|
5129
|
-
createPublicKey,
|
|
5130
|
-
createPrivateKey
|
|
5352
|
+
devNull
|
|
5131
5353
|
};
|
|
5132
|
-
var
|
|
5354
|
+
var osShim = Object.freeze({
|
|
5133
5355
|
__proto__: null,
|
|
5134
|
-
|
|
5356
|
+
EOL: EOL,
|
|
5357
|
+
arch: arch,
|
|
5135
5358
|
constants: constants$4,
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5359
|
+
cpus: cpus,
|
|
5360
|
+
default: os$1,
|
|
5361
|
+
devNull: devNull,
|
|
5362
|
+
endianness: endianness,
|
|
5363
|
+
freemem: freemem,
|
|
5364
|
+
getPriority: getPriority,
|
|
5365
|
+
homedir: homedir,
|
|
5366
|
+
hostname: hostname,
|
|
5367
|
+
loadavg: loadavg,
|
|
5368
|
+
machine: machine,
|
|
5369
|
+
networkInterfaces: networkInterfaces,
|
|
5370
|
+
platform: platform,
|
|
5371
|
+
release: release,
|
|
5372
|
+
setPriority: setPriority,
|
|
5373
|
+
tmpdir: tmpdir,
|
|
5374
|
+
totalmem: totalmem,
|
|
5375
|
+
type: type,
|
|
5376
|
+
uptime: uptime,
|
|
5377
|
+
userInfo: userInfo,
|
|
5378
|
+
version: version$1
|
|
5155
5379
|
});
|
|
5156
5380
|
const Z_FIXED$1 = 4;
|
|
5157
5381
|
const Z_BINARY = 0;
|
|
@@ -55868,6 +56092,7 @@ sys 0m0.000s
|
|
|
55868
56092
|
return n.join(`
|
|
55869
56093
|
`);
|
|
55870
56094
|
}
|
|
56095
|
+
const _decoder = new TextDecoder();
|
|
55871
56096
|
class VirtualFSAdapter {
|
|
55872
56097
|
constructor(vfs){
|
|
55873
56098
|
this.vfs = vfs;
|
|
@@ -55879,7 +56104,7 @@ sys 0m0.000s
|
|
|
55879
56104
|
}
|
|
55880
56105
|
if (encoding === "binary" || encoding === "latin1") {
|
|
55881
56106
|
const buffer = this.vfs.readFileSync(path);
|
|
55882
|
-
return
|
|
56107
|
+
return uint8ToBinaryString(buffer);
|
|
55883
56108
|
}
|
|
55884
56109
|
return this.vfs.readFileSync(path, "utf8");
|
|
55885
56110
|
}
|
|
@@ -55894,7 +56119,7 @@ sys 0m0.000s
|
|
|
55894
56119
|
try {
|
|
55895
56120
|
existing = this.vfs.readFileSync(path, "utf8");
|
|
55896
56121
|
} catch {}
|
|
55897
|
-
const newContent = typeof content === "string" ? content :
|
|
56122
|
+
const newContent = typeof content === "string" ? content : _decoder.decode(content);
|
|
55898
56123
|
this.vfs.writeFileSync(path, existing + newContent);
|
|
55899
56124
|
}
|
|
55900
56125
|
async exists(path) {
|
|
@@ -56711,6 +56936,7 @@ sys 0m0.000s
|
|
|
56711
56936
|
binaryType = "blob";
|
|
56712
56937
|
_id;
|
|
56713
56938
|
_server = null;
|
|
56939
|
+
_nativeWs = null;
|
|
56714
56940
|
onopen = null;
|
|
56715
56941
|
onclose = null;
|
|
56716
56942
|
onerror = null;
|
|
@@ -56731,6 +56957,10 @@ sys 0m0.000s
|
|
|
56731
56957
|
if (this.onopen) this.onopen(new Event("open"));
|
|
56732
56958
|
return;
|
|
56733
56959
|
}
|
|
56960
|
+
if (this.url.startsWith("ws://") || this.url.startsWith("wss://")) {
|
|
56961
|
+
this._connectNative();
|
|
56962
|
+
return;
|
|
56963
|
+
}
|
|
56734
56964
|
if (!messageChannel) {
|
|
56735
56965
|
setTimeout(()=>{
|
|
56736
56966
|
this.readyState = WebSocket.OPEN;
|
|
@@ -56788,10 +57018,64 @@ sys 0m0.000s
|
|
|
56788
57018
|
}
|
|
56789
57019
|
}, 100);
|
|
56790
57020
|
}
|
|
57021
|
+
_connectNative() {
|
|
57022
|
+
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
57023
|
+
const NativeWS = isBrowser && typeof globalThis.WebSocket === "function" && globalThis.WebSocket !== WebSocket ? globalThis.WebSocket : null;
|
|
57024
|
+
if (!NativeWS) {
|
|
57025
|
+
setTimeout(()=>{
|
|
57026
|
+
this.readyState = WebSocket.OPEN;
|
|
57027
|
+
this.emit("open");
|
|
57028
|
+
if (this.onopen) this.onopen(new Event("open"));
|
|
57029
|
+
}, 0);
|
|
57030
|
+
return;
|
|
57031
|
+
}
|
|
57032
|
+
try {
|
|
57033
|
+
this._nativeWs = new NativeWS(this.url);
|
|
57034
|
+
this._nativeWs.binaryType = this.binaryType === "arraybuffer" ? "arraybuffer" : "blob";
|
|
57035
|
+
} catch {
|
|
57036
|
+
this.readyState = WebSocket.CLOSED;
|
|
57037
|
+
const errorEvent = new Event("error");
|
|
57038
|
+
this.emit("error", errorEvent);
|
|
57039
|
+
if (this.onerror) this.onerror(errorEvent);
|
|
57040
|
+
return;
|
|
57041
|
+
}
|
|
57042
|
+
this._nativeWs.onopen = ()=>{
|
|
57043
|
+
this.readyState = WebSocket.OPEN;
|
|
57044
|
+
this.emit("open");
|
|
57045
|
+
if (this.onopen) this.onopen(new Event("open"));
|
|
57046
|
+
};
|
|
57047
|
+
this._nativeWs.onmessage = (event)=>{
|
|
57048
|
+
const msgEvent = new MessageEventPolyfill("message", {
|
|
57049
|
+
data: event.data
|
|
57050
|
+
});
|
|
57051
|
+
this.emit("message", msgEvent);
|
|
57052
|
+
if (this.onmessage) this.onmessage(msgEvent);
|
|
57053
|
+
};
|
|
57054
|
+
this._nativeWs.onclose = (event)=>{
|
|
57055
|
+
this.readyState = WebSocket.CLOSED;
|
|
57056
|
+
this._nativeWs = null;
|
|
57057
|
+
const closeEvent = new CloseEventPolyfill("close", {
|
|
57058
|
+
code: event.code,
|
|
57059
|
+
reason: event.reason,
|
|
57060
|
+
wasClean: event.wasClean
|
|
57061
|
+
});
|
|
57062
|
+
this.emit("close", closeEvent);
|
|
57063
|
+
if (this.onclose) this.onclose(closeEvent);
|
|
57064
|
+
};
|
|
57065
|
+
this._nativeWs.onerror = ()=>{
|
|
57066
|
+
const errorEvent = new Event("error");
|
|
57067
|
+
this.emit("error", errorEvent);
|
|
57068
|
+
if (this.onerror) this.onerror(errorEvent);
|
|
57069
|
+
};
|
|
57070
|
+
}
|
|
56791
57071
|
send(data) {
|
|
56792
57072
|
if (this.readyState !== WebSocket.OPEN) {
|
|
56793
57073
|
throw new Error("WebSocket is not open");
|
|
56794
57074
|
}
|
|
57075
|
+
if (this._nativeWs) {
|
|
57076
|
+
this._nativeWs.send(data);
|
|
57077
|
+
return;
|
|
57078
|
+
}
|
|
56795
57079
|
if (this._server) {
|
|
56796
57080
|
this._server._handleClientMessage(this, data);
|
|
56797
57081
|
return;
|
|
@@ -56810,6 +57094,10 @@ sys 0m0.000s
|
|
|
56810
57094
|
return;
|
|
56811
57095
|
}
|
|
56812
57096
|
this.readyState = WebSocket.CLOSING;
|
|
57097
|
+
if (this._nativeWs) {
|
|
57098
|
+
this._nativeWs.close(code, reason);
|
|
57099
|
+
return;
|
|
57100
|
+
}
|
|
56813
57101
|
if (messageChannel) {
|
|
56814
57102
|
messageChannel.postMessage({
|
|
56815
57103
|
type: "disconnect",
|
|
@@ -56833,7 +57121,18 @@ sys 0m0.000s
|
|
|
56833
57121
|
ping() {}
|
|
56834
57122
|
pong() {}
|
|
56835
57123
|
terminate() {
|
|
56836
|
-
this.
|
|
57124
|
+
if (this._nativeWs) {
|
|
57125
|
+
this._nativeWs.close();
|
|
57126
|
+
this._nativeWs = null;
|
|
57127
|
+
}
|
|
57128
|
+
this.readyState = WebSocket.CLOSED;
|
|
57129
|
+
const closeEvent = new CloseEventPolyfill("close", {
|
|
57130
|
+
code: 1006,
|
|
57131
|
+
reason: "Connection terminated",
|
|
57132
|
+
wasClean: false
|
|
57133
|
+
});
|
|
57134
|
+
this.emit("close", closeEvent);
|
|
57135
|
+
if (this.onclose) this.onclose(closeEvent);
|
|
56837
57136
|
}
|
|
56838
57137
|
_setServer(server) {
|
|
56839
57138
|
this._server = server;
|
|
@@ -57747,7 +58046,7 @@ sys 0m0.000s
|
|
|
57747
58046
|
}
|
|
57748
58047
|
let entryPoints = options.entryPoints;
|
|
57749
58048
|
if (entryPoints && globalVFS) {
|
|
57750
|
-
const absWorkingDir = options.absWorkingDir || "/";
|
|
58049
|
+
const absWorkingDir = options.absWorkingDir || (typeof globalThis !== "undefined" && globalThis.process && typeof globalThis.process.cwd === "function" ? globalThis.process.cwd() : "/");
|
|
57751
58050
|
entryPoints = entryPoints.map((ep)=>{
|
|
57752
58051
|
if (ep.includes("vfs:")) {
|
|
57753
58052
|
const vfsIndex = ep.indexOf("vfs:");
|
|
@@ -57773,11 +58072,13 @@ sys 0m0.000s
|
|
|
57773
58072
|
return ep;
|
|
57774
58073
|
});
|
|
57775
58074
|
}
|
|
58075
|
+
const resolvedAbsWorkingDir = options.absWorkingDir || (typeof globalThis !== "undefined" && globalThis.process && typeof globalThis.process.cwd === "function" ? globalThis.process.cwd() : "/");
|
|
57776
58076
|
const result = await esbuildInstance.build({
|
|
57777
58077
|
...options,
|
|
57778
58078
|
entryPoints,
|
|
57779
58079
|
plugins,
|
|
57780
|
-
write: false
|
|
58080
|
+
write: false,
|
|
58081
|
+
absWorkingDir: resolvedAbsWorkingDir
|
|
57781
58082
|
});
|
|
57782
58083
|
if (result.outputFiles) {
|
|
57783
58084
|
for (const file of result.outputFiles){
|
|
@@ -59730,9 +60031,6 @@ sys 0m0.000s
|
|
|
59730
60031
|
return null;
|
|
59731
60032
|
};
|
|
59732
60033
|
const tryResolveFromNodeModules = (nodeModulesDir, moduleId)=>{
|
|
59733
|
-
const fullPath = join$1(nodeModulesDir, moduleId);
|
|
59734
|
-
const resolved = tryResolveFile(fullPath);
|
|
59735
|
-
if (resolved) return resolved;
|
|
59736
60034
|
const parts = moduleId.split("/");
|
|
59737
60035
|
const pkgName = parts[0].startsWith("@") && parts.length > 1 ? `${parts[0]}/${parts[1]}` : parts[0];
|
|
59738
60036
|
const pkgRoot = join$1(nodeModulesDir, pkgName);
|
|
@@ -59753,12 +60051,21 @@ sys 0m0.000s
|
|
|
59753
60051
|
} catch {}
|
|
59754
60052
|
}
|
|
59755
60053
|
if (pkgName === moduleId) {
|
|
59756
|
-
|
|
60054
|
+
let main;
|
|
60055
|
+
if (typeof pkg.browser === "string") {
|
|
60056
|
+
main = pkg.browser;
|
|
60057
|
+
}
|
|
60058
|
+
if (!main) {
|
|
60059
|
+
main = pkg.main || "index.js";
|
|
60060
|
+
}
|
|
59757
60061
|
const mainPath = join$1(pkgRoot, main);
|
|
59758
60062
|
const resolvedMain = tryResolveFile(mainPath);
|
|
59759
60063
|
if (resolvedMain) return resolvedMain;
|
|
59760
60064
|
}
|
|
59761
60065
|
}
|
|
60066
|
+
const fullPath = join$1(nodeModulesDir, moduleId);
|
|
60067
|
+
const resolved = tryResolveFile(fullPath);
|
|
60068
|
+
if (resolved) return resolved;
|
|
59762
60069
|
return null;
|
|
59763
60070
|
};
|
|
59764
60071
|
let searchDir = fromDir;
|
|
@@ -59792,6 +60099,10 @@ sys 0m0.000s
|
|
|
59792
60099
|
paths: []
|
|
59793
60100
|
};
|
|
59794
60101
|
moduleCache[resolvedPath] = module;
|
|
60102
|
+
const cacheKeys = Object.keys(moduleCache);
|
|
60103
|
+
if (cacheKeys.length > 2e3) {
|
|
60104
|
+
delete moduleCache[cacheKeys[0]];
|
|
60105
|
+
}
|
|
59795
60106
|
if (resolvedPath.endsWith(".json")) {
|
|
59796
60107
|
const content = vfs.readFileSync(resolvedPath, "utf8");
|
|
59797
60108
|
module.exports = JSON.parse(content);
|
|
@@ -60000,6 +60311,7 @@ ${code}
|
|
|
60000
60311
|
setVFS$2(vfs2);
|
|
60001
60312
|
setVFS$1(vfs2);
|
|
60002
60313
|
setVFS(vfs2);
|
|
60314
|
+
this.setupStackTracePolyfill();
|
|
60003
60315
|
this.setupTextDecoderPolyfill();
|
|
60004
60316
|
}
|
|
60005
60317
|
setupTextDecoderPolyfill() {
|
|
@@ -60035,25 +60347,13 @@ ${code}
|
|
|
60035
60347
|
if (!input) return "";
|
|
60036
60348
|
const bytes = input instanceof ArrayBuffer ? new Uint8Array(input) : new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
60037
60349
|
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);
|
|
60350
|
+
return uint8ToBase64(bytes);
|
|
60043
60351
|
}
|
|
60044
60352
|
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, "");
|
|
60353
|
+
return uint8ToBase64(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
60050
60354
|
}
|
|
60051
60355
|
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;
|
|
60356
|
+
return uint8ToHex(bytes);
|
|
60057
60357
|
}
|
|
60058
60358
|
return new OriginalTextDecoder("utf-8").decode(input, options2);
|
|
60059
60359
|
}
|
|
@@ -60066,6 +60366,120 @@ ${code}
|
|
|
60066
60366
|
}
|
|
60067
60367
|
globalThis.TextDecoder = PolyfillTextDecoder;
|
|
60068
60368
|
}
|
|
60369
|
+
setupStackTracePolyfill() {
|
|
60370
|
+
if (typeof Error.captureStackTrace === "function") return;
|
|
60371
|
+
if (Error.stackTraceLimit === void 0) {
|
|
60372
|
+
Error.stackTraceLimit = 10;
|
|
60373
|
+
}
|
|
60374
|
+
function parseStack(stack) {
|
|
60375
|
+
if (!stack) return [];
|
|
60376
|
+
const frames = [];
|
|
60377
|
+
const lines = stack.split("\n");
|
|
60378
|
+
for (const raw of lines){
|
|
60379
|
+
const line = raw.trim();
|
|
60380
|
+
if (!line || line.startsWith("Error") || line.startsWith("TypeError")) continue;
|
|
60381
|
+
let fn2 = "", file = "", lineNo = 0, colNo = 0;
|
|
60382
|
+
const safariMatch = line.match(/^(.*)@(.*?):(\d+):(\d+)$/);
|
|
60383
|
+
if (safariMatch) {
|
|
60384
|
+
fn2 = safariMatch[1] || "";
|
|
60385
|
+
file = safariMatch[2];
|
|
60386
|
+
lineNo = parseInt(safariMatch[3], 10);
|
|
60387
|
+
colNo = parseInt(safariMatch[4], 10);
|
|
60388
|
+
frames.push({
|
|
60389
|
+
fn: fn2,
|
|
60390
|
+
file,
|
|
60391
|
+
line: lineNo,
|
|
60392
|
+
col: colNo
|
|
60393
|
+
});
|
|
60394
|
+
continue;
|
|
60395
|
+
}
|
|
60396
|
+
const chromeMatch = line.match(/^at\s+(?:(.+?)\s+\()?(.*?):(\d+):(\d+)\)?$/);
|
|
60397
|
+
if (chromeMatch) {
|
|
60398
|
+
fn2 = chromeMatch[1] || "";
|
|
60399
|
+
file = chromeMatch[2];
|
|
60400
|
+
lineNo = parseInt(chromeMatch[3], 10);
|
|
60401
|
+
colNo = parseInt(chromeMatch[4], 10);
|
|
60402
|
+
frames.push({
|
|
60403
|
+
fn: fn2,
|
|
60404
|
+
file,
|
|
60405
|
+
line: lineNo,
|
|
60406
|
+
col: colNo
|
|
60407
|
+
});
|
|
60408
|
+
continue;
|
|
60409
|
+
}
|
|
60410
|
+
}
|
|
60411
|
+
return frames;
|
|
60412
|
+
}
|
|
60413
|
+
function createCallSite(frame) {
|
|
60414
|
+
return {
|
|
60415
|
+
getFileName: ()=>frame.file || null,
|
|
60416
|
+
getLineNumber: ()=>frame.line || null,
|
|
60417
|
+
getColumnNumber: ()=>frame.col || null,
|
|
60418
|
+
getFunctionName: ()=>frame.fn || null,
|
|
60419
|
+
getMethodName: ()=>frame.fn || null,
|
|
60420
|
+
getTypeName: ()=>null,
|
|
60421
|
+
getThis: ()=>void 0,
|
|
60422
|
+
getFunction: ()=>void 0,
|
|
60423
|
+
getEvalOrigin: ()=>void 0,
|
|
60424
|
+
isNative: ()=>false,
|
|
60425
|
+
isConstructor: ()=>false,
|
|
60426
|
+
isToplevel: ()=>!frame.fn,
|
|
60427
|
+
isEval: ()=>false,
|
|
60428
|
+
toString: ()=>frame.fn ? `${frame.fn} (${frame.file}:${frame.line}:${frame.col})` : `${frame.file}:${frame.line}:${frame.col}`
|
|
60429
|
+
};
|
|
60430
|
+
}
|
|
60431
|
+
function buildCallSites(stack, constructorOpt) {
|
|
60432
|
+
const frames = parseStack(stack);
|
|
60433
|
+
let startIdx = 0;
|
|
60434
|
+
if (constructorOpt && constructorOpt.name) {
|
|
60435
|
+
for(let i = 0; i < frames.length; i++){
|
|
60436
|
+
if (frames[i].fn === constructorOpt.name) {
|
|
60437
|
+
startIdx = i + 1;
|
|
60438
|
+
break;
|
|
60439
|
+
}
|
|
60440
|
+
}
|
|
60441
|
+
}
|
|
60442
|
+
return frames.slice(startIdx).map(createCallSite);
|
|
60443
|
+
}
|
|
60444
|
+
const stackSymbol = Symbol("rawStack");
|
|
60445
|
+
Object.defineProperty(Error.prototype, "stack", {
|
|
60446
|
+
get () {
|
|
60447
|
+
const rawStack = this[stackSymbol];
|
|
60448
|
+
if (rawStack !== void 0 && typeof Error.prepareStackTrace === "function") {
|
|
60449
|
+
const callSites = buildCallSites(rawStack);
|
|
60450
|
+
try {
|
|
60451
|
+
return Error.prepareStackTrace(this, callSites);
|
|
60452
|
+
} catch {
|
|
60453
|
+
return rawStack;
|
|
60454
|
+
}
|
|
60455
|
+
}
|
|
60456
|
+
return rawStack;
|
|
60457
|
+
},
|
|
60458
|
+
set (value) {
|
|
60459
|
+
this[stackSymbol] = value;
|
|
60460
|
+
},
|
|
60461
|
+
configurable: true,
|
|
60462
|
+
enumerable: false
|
|
60463
|
+
});
|
|
60464
|
+
Error.captureStackTrace = function(target, constructorOpt) {
|
|
60465
|
+
const savedPrepare = Error.prepareStackTrace;
|
|
60466
|
+
Error.prepareStackTrace = void 0;
|
|
60467
|
+
const err = new Error();
|
|
60468
|
+
const rawStack = err.stack || "";
|
|
60469
|
+
Error.prepareStackTrace = savedPrepare;
|
|
60470
|
+
if (typeof savedPrepare === "function") {
|
|
60471
|
+
const callSites = buildCallSites(rawStack, constructorOpt);
|
|
60472
|
+
try {
|
|
60473
|
+
target.stack = savedPrepare(target, callSites);
|
|
60474
|
+
} catch (e) {
|
|
60475
|
+
console.warn("[almostnode] Error.prepareStackTrace threw:", e);
|
|
60476
|
+
target.stack = rawStack;
|
|
60477
|
+
}
|
|
60478
|
+
} else {
|
|
60479
|
+
target.stack = rawStack;
|
|
60480
|
+
}
|
|
60481
|
+
};
|
|
60482
|
+
}
|
|
60069
60483
|
execute(code, filename = "/index.js") {
|
|
60070
60484
|
const dirname$1 = dirname(filename);
|
|
60071
60485
|
this.vfs.writeFileSync(filename, code);
|
|
@@ -60137,6 +60551,42 @@ ${code}
|
|
|
60137
60551
|
getProcess() {
|
|
60138
60552
|
return this.process;
|
|
60139
60553
|
}
|
|
60554
|
+
createREPL() {
|
|
60555
|
+
const require2 = createRequire(this.vfs, this.fsShim, this.process, "/", this.moduleCache, this.options, this.processedCodeCache);
|
|
60556
|
+
const consoleWrapper2 = createConsoleWrapper(this.options.onConsole);
|
|
60557
|
+
const process2 = this.process;
|
|
60558
|
+
const buffer = bufferModule.Buffer;
|
|
60559
|
+
const GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor;
|
|
60560
|
+
const replGen = new GeneratorFunction("require", "console", "process", "Buffer", `var __code, __result;
|
|
60561
|
+
while (true) {
|
|
60562
|
+
__code = yield;
|
|
60563
|
+
try {
|
|
60564
|
+
__result = eval(__code);
|
|
60565
|
+
yield { value: __result, error: null };
|
|
60566
|
+
} catch (e) {
|
|
60567
|
+
yield { value: undefined, error: e };
|
|
60568
|
+
}
|
|
60569
|
+
}`)(require2, consoleWrapper2, process2, buffer);
|
|
60570
|
+
replGen.next();
|
|
60571
|
+
return {
|
|
60572
|
+
eval (code2) {
|
|
60573
|
+
const transformed = code2.replace(/^\s*(const|let)\s+/gm, "var ");
|
|
60574
|
+
const exprResult = replGen.next("(" + transformed + ")").value;
|
|
60575
|
+
if (!exprResult.error) {
|
|
60576
|
+
replGen.next();
|
|
60577
|
+
return exprResult.value;
|
|
60578
|
+
}
|
|
60579
|
+
replGen.next();
|
|
60580
|
+
const stmtResult = replGen.next(transformed).value;
|
|
60581
|
+
if (stmtResult.error) {
|
|
60582
|
+
replGen.next();
|
|
60583
|
+
throw stmtResult.error;
|
|
60584
|
+
}
|
|
60585
|
+
replGen.next();
|
|
60586
|
+
return stmtResult.value;
|
|
60587
|
+
}
|
|
60588
|
+
};
|
|
60589
|
+
}
|
|
60140
60590
|
}
|
|
60141
60591
|
let runtime = null;
|
|
60142
60592
|
let vfs = null;
|