@php-wasm/web 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +10 -10
- package/index.cjs.map +1 -1
- package/index.js +519 -609
- package/index.js.map +1 -1
- package/lib/index.d.ts +1 -2
- package/package.json +9 -8
- package/lib/api.d.ts +0 -17
package/index.js
CHANGED
|
@@ -1,103 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { jspi as
|
|
4
|
-
import { concatArrayBuffers as B, concatUint8Arrays as u, Semaphore as
|
|
5
|
-
import { logger as
|
|
6
|
-
import { teeRequest as
|
|
7
|
-
import { journalFSEvents as
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return new Proxy(n, {
|
|
12
|
-
get: (i, a) => a === "isConnected" ? async () => {
|
|
13
|
-
for (; ; )
|
|
14
|
-
try {
|
|
15
|
-
await Be(r.isConnected(), 200);
|
|
16
|
-
break;
|
|
17
|
-
} catch {
|
|
18
|
-
}
|
|
19
|
-
} : r[a]
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
async function Be(s, e) {
|
|
23
|
-
return new Promise((t, r) => {
|
|
24
|
-
setTimeout(r, e), s.then(t);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function yt(s, e) {
|
|
28
|
-
ce();
|
|
29
|
-
const t = Promise.resolve();
|
|
30
|
-
let r, n;
|
|
31
|
-
const i = new Promise((c, S) => {
|
|
32
|
-
r = c, n = S;
|
|
33
|
-
}), a = j(s), _ = new Proxy(a, {
|
|
34
|
-
get: (c, S) => S === "isConnected" ? () => t : S === "isReady" ? () => i : S in c ? c[S] : e == null ? void 0 : e[S]
|
|
35
|
-
});
|
|
36
|
-
return E.expose(
|
|
37
|
-
_,
|
|
38
|
-
typeof window < "u" ? E.windowEndpoint(self.parent) : void 0
|
|
39
|
-
), [r, n, _];
|
|
40
|
-
}
|
|
41
|
-
let V = !1;
|
|
42
|
-
function ce() {
|
|
43
|
-
if (V)
|
|
44
|
-
return;
|
|
45
|
-
V = !0, E.transferHandlers.set("EVENT", {
|
|
46
|
-
canHandle: (t) => t instanceof CustomEvent,
|
|
47
|
-
serialize: (t) => [
|
|
48
|
-
{
|
|
49
|
-
detail: t.detail
|
|
50
|
-
},
|
|
51
|
-
[]
|
|
52
|
-
],
|
|
53
|
-
deserialize: (t) => t
|
|
54
|
-
}), E.transferHandlers.set("FUNCTION", {
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
56
|
-
canHandle: (t) => typeof t == "function",
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
58
|
-
serialize(t) {
|
|
59
|
-
const { port1: r, port2: n } = new MessageChannel();
|
|
60
|
-
return E.expose(t, r), [n, [n]];
|
|
61
|
-
},
|
|
62
|
-
deserialize(t) {
|
|
63
|
-
return t.start(), E.wrap(t);
|
|
64
|
-
}
|
|
65
|
-
}), E.transferHandlers.set("PHPResponse", {
|
|
66
|
-
canHandle: (t) => typeof t == "object" && t !== null && "headers" in t && "bytes" in t && "errors" in t && "exitCode" in t && "httpStatusCode" in t,
|
|
67
|
-
serialize(t) {
|
|
68
|
-
return [t.toRawData(), []];
|
|
69
|
-
},
|
|
70
|
-
deserialize(t) {
|
|
71
|
-
return Le.fromRawData(t);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
const s = E.transferHandlers.get("throw"), e = s == null ? void 0 : s.serialize;
|
|
75
|
-
s.serialize = ({ value: t }) => {
|
|
76
|
-
const r = e({ value: t });
|
|
77
|
-
return t.response && (r[0].value.response = t.response), t.source && (r[0].value.source = t.source), r;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
function j(s) {
|
|
81
|
-
return new Proxy(s, {
|
|
82
|
-
get(e, t) {
|
|
83
|
-
switch (typeof e[t]) {
|
|
84
|
-
case "function":
|
|
85
|
-
return (...r) => e[t](...r);
|
|
86
|
-
case "object":
|
|
87
|
-
return e[t] === null ? e[t] : j(e[t]);
|
|
88
|
-
case "undefined":
|
|
89
|
-
case "number":
|
|
90
|
-
case "string":
|
|
91
|
-
return e[t];
|
|
92
|
-
default:
|
|
93
|
-
return E.proxy(e[t]);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
async function Ue(s = me) {
|
|
99
|
-
if (await Ke())
|
|
100
|
-
switch (s) {
|
|
1
|
+
import { LatestSupportedPHPVersion as fe, FSHelpers as W, loadPHPRuntime as pe, __private__dont__use as k } from "@php-wasm/universal";
|
|
2
|
+
import { consumeAPI as mt, exposeAPI as gt } from "@php-wasm/universal";
|
|
3
|
+
import { jspi as we } from "wasm-feature-detect";
|
|
4
|
+
import { concatArrayBuffers as B, concatUint8Arrays as u, Semaphore as Le, joinPaths as ie, basename as ye } from "@php-wasm/util";
|
|
5
|
+
import { logger as U } from "@php-wasm/logger";
|
|
6
|
+
import { teeRequest as me, cloneRequest as ge } from "@php-wasm/web-service-worker";
|
|
7
|
+
import { journalFSEvents as Ke, normalizeFilesystemOperations as Ie } from "@php-wasm/fs-journal";
|
|
8
|
+
async function De(i = fe) {
|
|
9
|
+
if (await we())
|
|
10
|
+
switch (i) {
|
|
101
11
|
case "8.4":
|
|
102
12
|
return await import("./php/jspi/php_8_4.js");
|
|
103
13
|
case "8.3":
|
|
@@ -116,7 +26,7 @@ async function Ue(s = me) {
|
|
|
116
26
|
return await import("./php/jspi/php_7_2.js");
|
|
117
27
|
}
|
|
118
28
|
else
|
|
119
|
-
switch (
|
|
29
|
+
switch (i) {
|
|
120
30
|
case "8.4":
|
|
121
31
|
return await import("./php/asyncify/php_8_4.js");
|
|
122
32
|
case "8.3":
|
|
@@ -134,26 +44,26 @@ async function Ue(s = me) {
|
|
|
134
44
|
case "7.2":
|
|
135
45
|
return await import("./php/asyncify/php_7_2.js");
|
|
136
46
|
}
|
|
137
|
-
throw new Error(`Unsupported PHP version ${
|
|
47
|
+
throw new Error(`Unsupported PHP version ${i}`);
|
|
138
48
|
}
|
|
139
|
-
function
|
|
140
|
-
return Object.fromEntries(Object.entries(
|
|
49
|
+
function f(i) {
|
|
50
|
+
return Object.fromEntries(Object.entries(i).map(([e, t]) => [t, e]));
|
|
141
51
|
}
|
|
142
|
-
function
|
|
143
|
-
return new Uint8Array([
|
|
52
|
+
function K(i) {
|
|
53
|
+
return new Uint8Array([i >> 8 & 255, i & 255]);
|
|
144
54
|
}
|
|
145
|
-
function
|
|
55
|
+
function w(i) {
|
|
146
56
|
return new Uint8Array([
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
57
|
+
i >> 16 & 255,
|
|
58
|
+
i >> 8 & 255,
|
|
59
|
+
i & 255
|
|
150
60
|
]);
|
|
151
61
|
}
|
|
152
|
-
function
|
|
62
|
+
function $(i) {
|
|
153
63
|
const e = new ArrayBuffer(8);
|
|
154
|
-
return new DataView(e).setBigUint64(0, BigInt(
|
|
64
|
+
return new DataView(e).setBigUint64(0, BigInt(i), !1), new Uint8Array(e);
|
|
155
65
|
}
|
|
156
|
-
class
|
|
66
|
+
class y {
|
|
157
67
|
constructor(e) {
|
|
158
68
|
this.offset = 0, this.buffer = e, this.view = new DataView(e);
|
|
159
69
|
}
|
|
@@ -177,7 +87,7 @@ class m {
|
|
|
177
87
|
return this.offset >= this.buffer.byteLength;
|
|
178
88
|
}
|
|
179
89
|
}
|
|
180
|
-
class
|
|
90
|
+
class v {
|
|
181
91
|
constructor(e) {
|
|
182
92
|
this.offset = 0, this.buffer = new ArrayBuffer(e), this.uint8Array = new Uint8Array(this.buffer), this.view = new DataView(this.buffer);
|
|
183
93
|
}
|
|
@@ -248,36 +158,36 @@ const b = {
|
|
|
248
158
|
key_share: 51,
|
|
249
159
|
transparency_info: 52,
|
|
250
160
|
connection_id: 54
|
|
251
|
-
},
|
|
161
|
+
}, We = f(b), _e = {
|
|
252
162
|
host_name: 0
|
|
253
|
-
},
|
|
254
|
-
class
|
|
163
|
+
}, be = f(_e);
|
|
164
|
+
class ae {
|
|
255
165
|
static decodeFromClient(e) {
|
|
256
166
|
const t = new DataView(e.buffer);
|
|
257
167
|
let r = 0;
|
|
258
168
|
const n = t.getUint16(r);
|
|
259
169
|
r += 2;
|
|
260
|
-
const
|
|
170
|
+
const s = [];
|
|
261
171
|
for (; r < n + 2; ) {
|
|
262
|
-
const
|
|
172
|
+
const _ = e[r];
|
|
263
173
|
r += 1;
|
|
264
|
-
const
|
|
174
|
+
const a = t.getUint16(r);
|
|
265
175
|
r += 2;
|
|
266
|
-
const c = e.slice(r, r +
|
|
267
|
-
switch (r +=
|
|
268
|
-
case
|
|
269
|
-
|
|
270
|
-
name_type:
|
|
176
|
+
const c = e.slice(r, r + a);
|
|
177
|
+
switch (r += a, _) {
|
|
178
|
+
case _e.host_name:
|
|
179
|
+
s.push({
|
|
180
|
+
name_type: be[_],
|
|
271
181
|
name: {
|
|
272
182
|
host_name: new TextDecoder().decode(c)
|
|
273
183
|
}
|
|
274
184
|
});
|
|
275
185
|
break;
|
|
276
186
|
default:
|
|
277
|
-
throw new Error(`Unsupported name type ${
|
|
187
|
+
throw new Error(`Unsupported name type ${_}`);
|
|
278
188
|
}
|
|
279
189
|
}
|
|
280
|
-
return { server_name_list:
|
|
190
|
+
return { server_name_list: s };
|
|
281
191
|
}
|
|
282
192
|
/**
|
|
283
193
|
* Encode the server_name extension
|
|
@@ -295,11 +205,11 @@ class Ce {
|
|
|
295
205
|
throw new Error(
|
|
296
206
|
"Encoding non-empty lists for ClientHello is not supported yet. Only empty lists meant for ServerHello are supported today."
|
|
297
207
|
);
|
|
298
|
-
const t = new
|
|
208
|
+
const t = new v(4);
|
|
299
209
|
return t.writeUint16(b.server_name), t.writeUint16(0), t.uint8Array;
|
|
300
210
|
}
|
|
301
211
|
}
|
|
302
|
-
const
|
|
212
|
+
const oe = {
|
|
303
213
|
TLS1_CK_PSK_WITH_RC4_128_SHA: 138,
|
|
304
214
|
TLS1_CK_PSK_WITH_3DES_EDE_CBC_SHA: 139,
|
|
305
215
|
TLS1_CK_PSK_WITH_AES_128_CBC_SHA: 140,
|
|
@@ -502,14 +412,14 @@ const he = {
|
|
|
502
412
|
TLS1_CK_ECDHE_PSK_WITH_CHACHA20_POLY1305: 52396,
|
|
503
413
|
TLS1_CK_DHE_PSK_WITH_CHACHA20_POLY1305: 52397,
|
|
504
414
|
TLS1_CK_RSA_PSK_WITH_CHACHA20_POLY1305: 52398
|
|
505
|
-
},
|
|
415
|
+
}, V = f(oe), ce = {
|
|
506
416
|
secp256r1: 23,
|
|
507
417
|
secp384r1: 24,
|
|
508
418
|
secp521r1: 25,
|
|
509
419
|
x25519: 29,
|
|
510
420
|
x448: 30
|
|
511
|
-
},
|
|
512
|
-
class
|
|
421
|
+
}, z = f(ce);
|
|
422
|
+
class Re {
|
|
513
423
|
/**
|
|
514
424
|
* +--------------------------------------------------+
|
|
515
425
|
* | Payload Length [2B] |
|
|
@@ -526,12 +436,12 @@ class Ne {
|
|
|
526
436
|
* +--------------------------------------------------+
|
|
527
437
|
*/
|
|
528
438
|
static decodeFromClient(e) {
|
|
529
|
-
const t = new
|
|
439
|
+
const t = new y(e.buffer);
|
|
530
440
|
t.readUint16();
|
|
531
441
|
const r = [];
|
|
532
442
|
for (; !t.isFinished(); ) {
|
|
533
443
|
const n = t.readUint16();
|
|
534
|
-
n in
|
|
444
|
+
n in z && r.push(z[n]);
|
|
535
445
|
}
|
|
536
446
|
return r;
|
|
537
447
|
}
|
|
@@ -546,16 +456,16 @@ class Ne {
|
|
|
546
456
|
* +--------------------------------------------------+
|
|
547
457
|
*/
|
|
548
458
|
static encodeForClient(e) {
|
|
549
|
-
const t = new
|
|
550
|
-
return t.writeUint16(b.supported_groups), t.writeUint16(2), t.writeUint16(
|
|
459
|
+
const t = new v(6);
|
|
460
|
+
return t.writeUint16(b.supported_groups), t.writeUint16(2), t.writeUint16(ce[e]), t.uint8Array;
|
|
551
461
|
}
|
|
552
462
|
}
|
|
553
|
-
const
|
|
463
|
+
const Se = {
|
|
554
464
|
uncompressed: 0,
|
|
555
465
|
ansiX962_compressed_prime: 1,
|
|
556
466
|
ansiX962_compressed_char2: 2
|
|
557
|
-
},
|
|
558
|
-
class
|
|
467
|
+
}, Y = f(Se);
|
|
468
|
+
class Be {
|
|
559
469
|
/**
|
|
560
470
|
* +--------------------------------------------------+
|
|
561
471
|
* | Payload Length [2B] |
|
|
@@ -572,10 +482,10 @@ class xe {
|
|
|
572
482
|
* +--------------------------------------------------+
|
|
573
483
|
*/
|
|
574
484
|
static decodeFromClient(e) {
|
|
575
|
-
const t = new
|
|
576
|
-
for (let
|
|
577
|
-
const
|
|
578
|
-
|
|
485
|
+
const t = new y(e.buffer), r = t.readUint8(), n = [];
|
|
486
|
+
for (let s = 0; s < r; s++) {
|
|
487
|
+
const _ = t.readUint8();
|
|
488
|
+
_ in Y && n.push(Y[_]);
|
|
579
489
|
}
|
|
580
490
|
return n;
|
|
581
491
|
}
|
|
@@ -594,16 +504,16 @@ class xe {
|
|
|
594
504
|
* +--------------------------------------------------+
|
|
595
505
|
*/
|
|
596
506
|
static encodeForClient(e) {
|
|
597
|
-
const t = new
|
|
598
|
-
return t.writeUint16(b.ec_point_formats), t.writeUint16(2), t.writeUint8(1), t.writeUint8(
|
|
507
|
+
const t = new v(6);
|
|
508
|
+
return t.writeUint16(b.ec_point_formats), t.writeUint16(2), t.writeUint8(1), t.writeUint8(Se[e]), t.uint8Array;
|
|
599
509
|
}
|
|
600
510
|
}
|
|
601
|
-
const
|
|
511
|
+
const F = {
|
|
602
512
|
anonymous: 0,
|
|
603
513
|
rsa: 1,
|
|
604
514
|
dsa: 2,
|
|
605
515
|
ecdsa: 3
|
|
606
|
-
},
|
|
516
|
+
}, Z = f(F), j = {
|
|
607
517
|
none: 0,
|
|
608
518
|
md5: 1,
|
|
609
519
|
sha1: 2,
|
|
@@ -611,8 +521,8 @@ const G = {
|
|
|
611
521
|
sha256: 4,
|
|
612
522
|
sha384: 5,
|
|
613
523
|
sha512: 6
|
|
614
|
-
},
|
|
615
|
-
class
|
|
524
|
+
}, J = f(j);
|
|
525
|
+
class Pe {
|
|
616
526
|
/**
|
|
617
527
|
* Binary layout:
|
|
618
528
|
*
|
|
@@ -629,19 +539,19 @@ class ke {
|
|
|
629
539
|
* +------------------------------------+
|
|
630
540
|
*/
|
|
631
541
|
static decodeFromClient(e) {
|
|
632
|
-
const t = new
|
|
542
|
+
const t = new y(e.buffer);
|
|
633
543
|
t.readUint16();
|
|
634
544
|
const r = [];
|
|
635
545
|
for (; !t.isFinished(); ) {
|
|
636
|
-
const n = t.readUint8(),
|
|
637
|
-
if (
|
|
638
|
-
if (!
|
|
639
|
-
|
|
546
|
+
const n = t.readUint8(), s = t.readUint8();
|
|
547
|
+
if (Z[s]) {
|
|
548
|
+
if (!J[n]) {
|
|
549
|
+
U.warn(`Unknown hash algorithm: ${n}`);
|
|
640
550
|
continue;
|
|
641
551
|
}
|
|
642
552
|
r.push({
|
|
643
|
-
algorithm:
|
|
644
|
-
hash:
|
|
553
|
+
algorithm: Z[s],
|
|
554
|
+
hash: J[n]
|
|
645
555
|
});
|
|
646
556
|
}
|
|
647
557
|
}
|
|
@@ -659,61 +569,61 @@ class ke {
|
|
|
659
569
|
* +--------------------------------------------------+
|
|
660
570
|
*/
|
|
661
571
|
static encodeforClient(e, t) {
|
|
662
|
-
const r = new
|
|
663
|
-
return r.writeUint16(b.signature_algorithms), r.writeUint16(2), r.writeUint8(
|
|
572
|
+
const r = new v(6);
|
|
573
|
+
return r.writeUint16(b.signature_algorithms), r.writeUint16(2), r.writeUint8(j[e]), r.writeUint8(F[t]), r.uint8Array;
|
|
664
574
|
}
|
|
665
575
|
}
|
|
666
|
-
const
|
|
667
|
-
server_name:
|
|
668
|
-
signature_algorithms:
|
|
669
|
-
supported_groups:
|
|
670
|
-
ec_point_formats:
|
|
576
|
+
const X = {
|
|
577
|
+
server_name: ae,
|
|
578
|
+
signature_algorithms: Pe,
|
|
579
|
+
supported_groups: Re,
|
|
580
|
+
ec_point_formats: Be
|
|
671
581
|
};
|
|
672
|
-
function
|
|
673
|
-
const e = new
|
|
582
|
+
function Ue(i) {
|
|
583
|
+
const e = new y(i.buffer), t = [];
|
|
674
584
|
for (; !e.isFinished(); ) {
|
|
675
|
-
const r = e.offset, n = e.readUint16(),
|
|
676
|
-
if (!(
|
|
585
|
+
const r = e.offset, n = e.readUint16(), s = We[n], _ = e.readUint16(), a = e.readUint8Array(_);
|
|
586
|
+
if (!(s in X))
|
|
677
587
|
continue;
|
|
678
|
-
const c =
|
|
588
|
+
const c = X[s];
|
|
679
589
|
t.push({
|
|
680
|
-
type:
|
|
681
|
-
data: c.decodeFromClient(
|
|
682
|
-
raw:
|
|
590
|
+
type: s,
|
|
591
|
+
data: c.decodeFromClient(a),
|
|
592
|
+
raw: i.slice(r, r + 4 + _)
|
|
683
593
|
});
|
|
684
594
|
}
|
|
685
595
|
return t;
|
|
686
596
|
}
|
|
687
|
-
async function
|
|
688
|
-
const n = B([e, t]),
|
|
597
|
+
async function q(i, e, t, r) {
|
|
598
|
+
const n = B([e, t]), s = await crypto.subtle.importKey(
|
|
689
599
|
"raw",
|
|
690
|
-
|
|
600
|
+
i,
|
|
691
601
|
{ name: "HMAC", hash: { name: "SHA-256" } },
|
|
692
602
|
!1,
|
|
693
603
|
["sign"]
|
|
694
604
|
);
|
|
695
|
-
let
|
|
696
|
-
const
|
|
697
|
-
for (; B(
|
|
698
|
-
|
|
699
|
-
const S = B([
|
|
700
|
-
|
|
701
|
-
}
|
|
702
|
-
return B(
|
|
605
|
+
let _ = n;
|
|
606
|
+
const a = [];
|
|
607
|
+
for (; B(a).byteLength < r; ) {
|
|
608
|
+
_ = await Q(s, _);
|
|
609
|
+
const S = B([_, n]), A = await Q(s, S);
|
|
610
|
+
a.push(A);
|
|
611
|
+
}
|
|
612
|
+
return B(a).slice(0, r);
|
|
703
613
|
}
|
|
704
|
-
async function
|
|
614
|
+
async function Q(i, e) {
|
|
705
615
|
return await crypto.subtle.sign(
|
|
706
616
|
{ name: "HMAC", hash: "SHA-256" },
|
|
707
|
-
|
|
617
|
+
i,
|
|
708
618
|
e
|
|
709
619
|
);
|
|
710
620
|
}
|
|
711
|
-
const
|
|
621
|
+
const ve = {
|
|
712
622
|
Null: 0
|
|
713
|
-
},
|
|
623
|
+
}, Me = {
|
|
714
624
|
Warning: 1,
|
|
715
625
|
Fatal: 2
|
|
716
|
-
},
|
|
626
|
+
}, Ce = f(Me), Ne = {
|
|
717
627
|
CloseNotify: 0,
|
|
718
628
|
UnexpectedMessage: 10,
|
|
719
629
|
BadRecordMac: 20,
|
|
@@ -739,7 +649,7 @@ const Oe = {
|
|
|
739
649
|
UserCanceled: 90,
|
|
740
650
|
NoRenegotiation: 100,
|
|
741
651
|
UnsupportedExtension: 110
|
|
742
|
-
},
|
|
652
|
+
}, Ae = f(Ne), C = {
|
|
743
653
|
ChangeCipherSpec: 20,
|
|
744
654
|
Alert: 21,
|
|
745
655
|
Handshake: 22,
|
|
@@ -753,7 +663,7 @@ const Oe = {
|
|
|
753
663
|
ServerHelloDone: 14,
|
|
754
664
|
ClientKeyExchange: 16,
|
|
755
665
|
Finished: 20
|
|
756
|
-
},
|
|
666
|
+
}, xe = {
|
|
757
667
|
/**
|
|
758
668
|
* Indicates that a named curve is used. This option
|
|
759
669
|
* SHOULD be used when applicable.
|
|
@@ -762,12 +672,12 @@ const Oe = {
|
|
|
762
672
|
/**
|
|
763
673
|
* Values 248 through 255 are reserved for private use.
|
|
764
674
|
*/
|
|
765
|
-
},
|
|
675
|
+
}, ke = {
|
|
766
676
|
secp256r1: 23
|
|
767
677
|
};
|
|
768
|
-
class
|
|
678
|
+
class ee extends Error {
|
|
769
679
|
}
|
|
770
|
-
const
|
|
680
|
+
const P = new Uint8Array([3, 3]), qe = crypto.subtle.generateKey(
|
|
771
681
|
{
|
|
772
682
|
name: "ECDH",
|
|
773
683
|
namedCurve: "P-256"
|
|
@@ -778,7 +688,7 @@ const U = new Uint8Array([3, 3]), ze = crypto.subtle.generateKey(
|
|
|
778
688
|
["deriveKey", "deriveBits"]
|
|
779
689
|
// Key usage
|
|
780
690
|
);
|
|
781
|
-
class
|
|
691
|
+
class Oe {
|
|
782
692
|
constructor() {
|
|
783
693
|
this.receivedRecordSequenceNumber = 0, this.sentRecordSequenceNumber = 0, this.closed = !1, this.receivedBytesBuffer = new Uint8Array(), this.receivedTLSRecords = [], this.partialTLSMessages = {}, this.handshakeMessages = [], this.MAX_CHUNK_SIZE = 1024 * 16, this.clientEnd = {
|
|
784
694
|
// We don't need to chunk the encrypted data.
|
|
@@ -795,7 +705,7 @@ class Ve {
|
|
|
795
705
|
* This will spread some messages across multiple records,
|
|
796
706
|
* but TLS supports it so that's fine.
|
|
797
707
|
*/
|
|
798
|
-
downstream:
|
|
708
|
+
downstream: Fe(this.MAX_CHUNK_SIZE)
|
|
799
709
|
}, this.serverUpstreamWriter = this.serverEnd.upstream.writable.getWriter();
|
|
800
710
|
const e = this;
|
|
801
711
|
this.serverEnd.downstream.readable.pipeTo(
|
|
@@ -861,32 +771,32 @@ class Ve {
|
|
|
861
771
|
const n = crypto.getRandomValues(new Uint8Array(32));
|
|
862
772
|
await this.writeTLSRecord(
|
|
863
773
|
C.Handshake,
|
|
864
|
-
|
|
774
|
+
g.serverHello(
|
|
865
775
|
r.body,
|
|
866
776
|
n,
|
|
867
|
-
|
|
777
|
+
ve.Null
|
|
868
778
|
)
|
|
869
779
|
), await this.writeTLSRecord(
|
|
870
780
|
C.Handshake,
|
|
871
|
-
|
|
781
|
+
g.certificate(t)
|
|
872
782
|
);
|
|
873
|
-
const
|
|
874
|
-
|
|
783
|
+
const s = await qe, _ = r.body.random, a = await g.ECDHEServerKeyExchange(
|
|
784
|
+
_,
|
|
875
785
|
n,
|
|
876
|
-
|
|
786
|
+
s,
|
|
877
787
|
e
|
|
878
788
|
);
|
|
879
|
-
await this.writeTLSRecord(C.Handshake,
|
|
789
|
+
await this.writeTLSRecord(C.Handshake, a), await this.writeTLSRecord(
|
|
880
790
|
C.Handshake,
|
|
881
|
-
|
|
791
|
+
g.serverHelloDone()
|
|
882
792
|
);
|
|
883
793
|
const c = await this.readNextHandshakeMessage(
|
|
884
794
|
d.ClientKeyExchange
|
|
885
795
|
);
|
|
886
796
|
await this.readNextMessage(C.ChangeCipherSpec), this.sessionKeys = await this.deriveSessionKeys({
|
|
887
|
-
clientRandom:
|
|
797
|
+
clientRandom: _,
|
|
888
798
|
serverRandom: n,
|
|
889
|
-
serverPrivateKey:
|
|
799
|
+
serverPrivateKey: s.privateKey,
|
|
890
800
|
clientPublicKey: await crypto.subtle.importKey(
|
|
891
801
|
"raw",
|
|
892
802
|
c.body.exchange_keys,
|
|
@@ -896,10 +806,10 @@ class Ve {
|
|
|
896
806
|
)
|
|
897
807
|
}), await this.readNextHandshakeMessage(d.Finished), await this.writeTLSRecord(
|
|
898
808
|
C.ChangeCipherSpec,
|
|
899
|
-
|
|
809
|
+
g.changeCipherSpec()
|
|
900
810
|
), await this.writeTLSRecord(
|
|
901
811
|
C.Handshake,
|
|
902
|
-
await
|
|
812
|
+
await g.createFinishedMessage(
|
|
903
813
|
this.handshakeMessages,
|
|
904
814
|
this.sessionKeys.masterSecret
|
|
905
815
|
)
|
|
@@ -915,7 +825,7 @@ class Ve {
|
|
|
915
825
|
serverPrivateKey: r,
|
|
916
826
|
clientPublicKey: n
|
|
917
827
|
}) {
|
|
918
|
-
const
|
|
828
|
+
const s = await crypto.subtle.deriveBits(
|
|
919
829
|
{
|
|
920
830
|
name: "ECDH",
|
|
921
831
|
public: n
|
|
@@ -923,22 +833,22 @@ class Ve {
|
|
|
923
833
|
r,
|
|
924
834
|
256
|
|
925
835
|
// Length of the derived secret (256 bits for P-256)
|
|
926
|
-
),
|
|
927
|
-
await
|
|
928
|
-
|
|
836
|
+
), _ = new Uint8Array(
|
|
837
|
+
await q(
|
|
838
|
+
s,
|
|
929
839
|
new TextEncoder().encode("master secret"),
|
|
930
840
|
u([e, t]),
|
|
931
841
|
48
|
|
932
842
|
)
|
|
933
|
-
),
|
|
934
|
-
|
|
843
|
+
), a = await q(
|
|
844
|
+
_,
|
|
935
845
|
new TextEncoder().encode("key expansion"),
|
|
936
846
|
u([t, e]),
|
|
937
847
|
// Client key, server key, client IV, server IV
|
|
938
848
|
40
|
|
939
|
-
), c = new
|
|
849
|
+
), c = new y(a), S = c.readUint8Array(16), A = c.readUint8Array(16), h = c.readUint8Array(4), l = c.readUint8Array(4);
|
|
940
850
|
return {
|
|
941
|
-
masterSecret:
|
|
851
|
+
masterSecret: _,
|
|
942
852
|
clientWriteKey: await crypto.subtle.importKey(
|
|
943
853
|
"raw",
|
|
944
854
|
S,
|
|
@@ -948,13 +858,13 @@ class Ve {
|
|
|
948
858
|
),
|
|
949
859
|
serverWriteKey: await crypto.subtle.importKey(
|
|
950
860
|
"raw",
|
|
951
|
-
|
|
861
|
+
A,
|
|
952
862
|
{ name: "AES-GCM" },
|
|
953
863
|
!1,
|
|
954
864
|
["encrypt", "decrypt"]
|
|
955
865
|
),
|
|
956
|
-
clientIV:
|
|
957
|
-
serverIV:
|
|
866
|
+
clientIV: h,
|
|
867
|
+
serverIV: l
|
|
958
868
|
};
|
|
959
869
|
}
|
|
960
870
|
async readNextHandshakeMessage(e) {
|
|
@@ -970,7 +880,7 @@ class Ve {
|
|
|
970
880
|
t
|
|
971
881
|
);
|
|
972
882
|
while (r === !1);
|
|
973
|
-
const n =
|
|
883
|
+
const n = E.TLSMessage(
|
|
974
884
|
t.type,
|
|
975
885
|
r
|
|
976
886
|
);
|
|
@@ -978,27 +888,27 @@ class Ve {
|
|
|
978
888
|
}
|
|
979
889
|
async readNextTLSRecord(e) {
|
|
980
890
|
for (; ; ) {
|
|
981
|
-
for (let
|
|
982
|
-
const c = this.receivedTLSRecords[
|
|
891
|
+
for (let a = 0; a < this.receivedTLSRecords.length; a++) {
|
|
892
|
+
const c = this.receivedTLSRecords[a];
|
|
983
893
|
if (c.type === e)
|
|
984
|
-
return this.receivedTLSRecords.splice(
|
|
894
|
+
return this.receivedTLSRecords.splice(a, 1), c;
|
|
985
895
|
}
|
|
986
|
-
const t = await this.pollBytes(5), r = t[3] << 8 | t[4], n = t[0],
|
|
896
|
+
const t = await this.pollBytes(5), r = t[3] << 8 | t[4], n = t[0], s = await this.pollBytes(r), _ = {
|
|
987
897
|
type: n,
|
|
988
898
|
version: {
|
|
989
899
|
major: t[1],
|
|
990
900
|
minor: t[2]
|
|
991
901
|
},
|
|
992
902
|
length: r,
|
|
993
|
-
fragment: this.sessionKeys && n !== C.ChangeCipherSpec ? await this.decryptData(n,
|
|
903
|
+
fragment: this.sessionKeys && n !== C.ChangeCipherSpec ? await this.decryptData(n, s) : s
|
|
994
904
|
};
|
|
995
|
-
if (
|
|
996
|
-
const
|
|
905
|
+
if (_.type === C.Alert) {
|
|
906
|
+
const a = Ce[_.fragment[0]], c = Ae[_.fragment[1]];
|
|
997
907
|
throw new Error(
|
|
998
|
-
`TLS non-warning alert received: ${
|
|
908
|
+
`TLS non-warning alert received: ${a} ${c}`
|
|
999
909
|
);
|
|
1000
910
|
}
|
|
1001
|
-
this.receivedTLSRecords.push(
|
|
911
|
+
this.receivedTLSRecords.push(_);
|
|
1002
912
|
}
|
|
1003
913
|
}
|
|
1004
914
|
/**
|
|
@@ -1009,13 +919,13 @@ class Ve {
|
|
|
1009
919
|
for (; this.receivedBytesBuffer.length < e; ) {
|
|
1010
920
|
const { value: r, done: n } = await this.clientUpstreamReader.read();
|
|
1011
921
|
if (n)
|
|
1012
|
-
throw await this.close(), new
|
|
922
|
+
throw await this.close(), new ee("TLS connection closed");
|
|
1013
923
|
if (this.receivedBytesBuffer = u([
|
|
1014
924
|
this.receivedBytesBuffer,
|
|
1015
925
|
r
|
|
1016
926
|
]), this.receivedBytesBuffer.length >= e)
|
|
1017
927
|
break;
|
|
1018
|
-
await new Promise((
|
|
928
|
+
await new Promise((s) => setTimeout(s, 100));
|
|
1019
929
|
}
|
|
1020
930
|
const t = this.receivedBytesBuffer.slice(0, e);
|
|
1021
931
|
return this.receivedBytesBuffer = this.receivedBytesBuffer.slice(e), t;
|
|
@@ -1033,7 +943,7 @@ class Ve {
|
|
|
1033
943
|
this.serverUpstreamWriter.write(e.body);
|
|
1034
944
|
}
|
|
1035
945
|
} catch (e) {
|
|
1036
|
-
if (e instanceof
|
|
946
|
+
if (e instanceof ee)
|
|
1037
947
|
return;
|
|
1038
948
|
throw e;
|
|
1039
949
|
}
|
|
@@ -1043,16 +953,16 @@ class Ve {
|
|
|
1043
953
|
* the AES-GCM algorithm.
|
|
1044
954
|
*/
|
|
1045
955
|
async decryptData(e, t) {
|
|
1046
|
-
const r = this.sessionKeys.clientIV, n = t.slice(0, 8),
|
|
956
|
+
const r = this.sessionKeys.clientIV, n = t.slice(0, 8), s = new Uint8Array([...r, ...n]), _ = await crypto.subtle.decrypt(
|
|
1047
957
|
{
|
|
1048
958
|
name: "AES-GCM",
|
|
1049
|
-
iv:
|
|
959
|
+
iv: s,
|
|
1050
960
|
additionalData: new Uint8Array([
|
|
1051
|
-
|
|
961
|
+
...$(this.receivedRecordSequenceNumber),
|
|
1052
962
|
e,
|
|
1053
|
-
...
|
|
963
|
+
...P,
|
|
1054
964
|
// Payload length without IV and tag
|
|
1055
|
-
...
|
|
965
|
+
...K(t.length - 8 - 16)
|
|
1056
966
|
]),
|
|
1057
967
|
tagLength: 128
|
|
1058
968
|
},
|
|
@@ -1060,7 +970,7 @@ class Ve {
|
|
|
1060
970
|
// Payload without the explicit IV
|
|
1061
971
|
t.slice(8)
|
|
1062
972
|
);
|
|
1063
|
-
return ++this.receivedRecordSequenceNumber, new Uint8Array(
|
|
973
|
+
return ++this.receivedRecordSequenceNumber, new Uint8Array(_);
|
|
1064
974
|
}
|
|
1065
975
|
async accumulateUntilMessageIsComplete(e) {
|
|
1066
976
|
this.partialTLSMessages[e.type] = u([
|
|
@@ -1099,27 +1009,27 @@ class Ve {
|
|
|
1099
1009
|
*/
|
|
1100
1010
|
async writeTLSRecord(e, t) {
|
|
1101
1011
|
e === C.Handshake && this.handshakeMessages.push(t), this.sessionKeys && e !== C.ChangeCipherSpec && (t = await this.encryptData(e, t));
|
|
1102
|
-
const r =
|
|
1103
|
-
|
|
1104
|
-
const
|
|
1105
|
-
this.clientDownstreamWriter.write(
|
|
1012
|
+
const r = P, n = t.length, s = new Uint8Array(5);
|
|
1013
|
+
s[0] = e, s[1] = r[0], s[2] = r[1], s[3] = n >> 8 & 255, s[4] = n & 255;
|
|
1014
|
+
const _ = u([s, t]);
|
|
1015
|
+
this.clientDownstreamWriter.write(_);
|
|
1106
1016
|
}
|
|
1107
1017
|
/**
|
|
1108
1018
|
* Encrypts data in a TLS 1.2-compliant manner using
|
|
1109
1019
|
* the AES-GCM algorithm.
|
|
1110
1020
|
*/
|
|
1111
1021
|
async encryptData(e, t) {
|
|
1112
|
-
const r = this.sessionKeys.serverIV, n = crypto.getRandomValues(new Uint8Array(8)),
|
|
1113
|
-
|
|
1022
|
+
const r = this.sessionKeys.serverIV, n = crypto.getRandomValues(new Uint8Array(8)), s = new Uint8Array([...r, ...n]), _ = new Uint8Array([
|
|
1023
|
+
...$(this.sentRecordSequenceNumber),
|
|
1114
1024
|
e,
|
|
1115
|
-
...
|
|
1025
|
+
...P,
|
|
1116
1026
|
// Payload length without IV and tag
|
|
1117
|
-
...
|
|
1118
|
-
]),
|
|
1027
|
+
...K(t.length)
|
|
1028
|
+
]), a = await crypto.subtle.encrypt(
|
|
1119
1029
|
{
|
|
1120
1030
|
name: "AES-GCM",
|
|
1121
|
-
iv:
|
|
1122
|
-
additionalData:
|
|
1031
|
+
iv: s,
|
|
1032
|
+
additionalData: _,
|
|
1123
1033
|
tagLength: 128
|
|
1124
1034
|
},
|
|
1125
1035
|
this.sessionKeys.serverWriteKey,
|
|
@@ -1127,21 +1037,21 @@ class Ve {
|
|
|
1127
1037
|
);
|
|
1128
1038
|
return ++this.sentRecordSequenceNumber, u([
|
|
1129
1039
|
n,
|
|
1130
|
-
new Uint8Array(
|
|
1040
|
+
new Uint8Array(a)
|
|
1131
1041
|
]);
|
|
1132
1042
|
}
|
|
1133
1043
|
}
|
|
1134
|
-
class
|
|
1044
|
+
class E {
|
|
1135
1045
|
static TLSMessage(e, t) {
|
|
1136
1046
|
switch (e) {
|
|
1137
1047
|
case C.Handshake:
|
|
1138
|
-
return
|
|
1048
|
+
return E.clientHandshake(t);
|
|
1139
1049
|
case C.Alert:
|
|
1140
|
-
return
|
|
1050
|
+
return E.alert(t);
|
|
1141
1051
|
case C.ChangeCipherSpec:
|
|
1142
|
-
return
|
|
1052
|
+
return E.changeCipherSpec();
|
|
1143
1053
|
case C.ApplicationData:
|
|
1144
|
-
return
|
|
1054
|
+
return E.applicationData(t);
|
|
1145
1055
|
default:
|
|
1146
1056
|
throw new Error(`TLS: Unsupported TLS record type ${e}`);
|
|
1147
1057
|
}
|
|
@@ -1170,12 +1080,12 @@ class T {
|
|
|
1170
1080
|
* https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4
|
|
1171
1081
|
*/
|
|
1172
1082
|
static parseCipherSuites(e) {
|
|
1173
|
-
const t = new
|
|
1083
|
+
const t = new y(e);
|
|
1174
1084
|
t.readUint16();
|
|
1175
1085
|
const r = [];
|
|
1176
1086
|
for (; !t.isFinished(); ) {
|
|
1177
1087
|
const n = t.readUint16();
|
|
1178
|
-
n in
|
|
1088
|
+
n in V && r.push(V[n]);
|
|
1179
1089
|
}
|
|
1180
1090
|
return r;
|
|
1181
1091
|
}
|
|
@@ -1194,25 +1104,25 @@ class T {
|
|
|
1194
1104
|
static alert(e) {
|
|
1195
1105
|
return {
|
|
1196
1106
|
type: C.Alert,
|
|
1197
|
-
level:
|
|
1198
|
-
description:
|
|
1107
|
+
level: Ce[e[0]],
|
|
1108
|
+
description: Ae[e[1]]
|
|
1199
1109
|
};
|
|
1200
1110
|
}
|
|
1201
1111
|
static clientHandshake(e) {
|
|
1202
1112
|
const t = e[0], r = e[1] << 16 | e[2] << 8 | e[3], n = e.slice(4);
|
|
1203
|
-
let
|
|
1113
|
+
let s;
|
|
1204
1114
|
switch (t) {
|
|
1205
1115
|
case d.HelloRequest:
|
|
1206
|
-
|
|
1116
|
+
s = E.clientHelloRequestPayload();
|
|
1207
1117
|
break;
|
|
1208
1118
|
case d.ClientHello:
|
|
1209
|
-
|
|
1119
|
+
s = E.clientHelloPayload(n);
|
|
1210
1120
|
break;
|
|
1211
1121
|
case d.ClientKeyExchange:
|
|
1212
|
-
|
|
1122
|
+
s = E.clientKeyExchangePayload(n);
|
|
1213
1123
|
break;
|
|
1214
1124
|
case d.Finished:
|
|
1215
|
-
|
|
1125
|
+
s = E.clientFinishedPayload(n);
|
|
1216
1126
|
break;
|
|
1217
1127
|
default:
|
|
1218
1128
|
throw new Error(`Invalid handshake type ${t}`);
|
|
@@ -1221,7 +1131,7 @@ class T {
|
|
|
1221
1131
|
type: C.Handshake,
|
|
1222
1132
|
msg_type: t,
|
|
1223
1133
|
length: r,
|
|
1224
|
-
body:
|
|
1134
|
+
body: s
|
|
1225
1135
|
};
|
|
1226
1136
|
}
|
|
1227
1137
|
static clientHelloRequestPayload() {
|
|
@@ -1268,7 +1178,7 @@ class T {
|
|
|
1268
1178
|
* +------+------+---------------------------+
|
|
1269
1179
|
*/
|
|
1270
1180
|
static clientHelloPayload(e) {
|
|
1271
|
-
const t = new
|
|
1181
|
+
const t = new y(e.buffer), r = {
|
|
1272
1182
|
client_version: t.readUint8Array(2),
|
|
1273
1183
|
/**
|
|
1274
1184
|
* Technically this consists of a GMT timestamp
|
|
@@ -1278,17 +1188,17 @@ class T {
|
|
|
1278
1188
|
random: t.readUint8Array(32)
|
|
1279
1189
|
}, n = t.readUint8();
|
|
1280
1190
|
r.session_id = t.readUint8Array(n);
|
|
1281
|
-
const
|
|
1282
|
-
r.cipher_suites =
|
|
1283
|
-
t.readUint8Array(
|
|
1191
|
+
const s = t.readUint16();
|
|
1192
|
+
r.cipher_suites = E.parseCipherSuites(
|
|
1193
|
+
t.readUint8Array(s).buffer
|
|
1284
1194
|
);
|
|
1285
|
-
const
|
|
1195
|
+
const _ = t.readUint8();
|
|
1286
1196
|
r.compression_methods = t.readUint8Array(
|
|
1287
|
-
|
|
1197
|
+
_
|
|
1288
1198
|
);
|
|
1289
|
-
const
|
|
1290
|
-
return r.extensions =
|
|
1291
|
-
t.readUint8Array(
|
|
1199
|
+
const a = t.readUint16();
|
|
1200
|
+
return r.extensions = Ue(
|
|
1201
|
+
t.readUint8Array(a)
|
|
1292
1202
|
), r;
|
|
1293
1203
|
}
|
|
1294
1204
|
/**
|
|
@@ -1312,26 +1222,26 @@ class T {
|
|
|
1312
1222
|
};
|
|
1313
1223
|
}
|
|
1314
1224
|
}
|
|
1315
|
-
function
|
|
1225
|
+
function Fe(i) {
|
|
1316
1226
|
return new TransformStream({
|
|
1317
1227
|
transform(e, t) {
|
|
1318
1228
|
for (; e.length > 0; )
|
|
1319
|
-
t.enqueue(e.slice(0,
|
|
1229
|
+
t.enqueue(e.slice(0, i)), e = e.slice(i);
|
|
1320
1230
|
}
|
|
1321
1231
|
});
|
|
1322
1232
|
}
|
|
1323
|
-
class
|
|
1233
|
+
class g {
|
|
1324
1234
|
static certificate(e) {
|
|
1325
1235
|
const t = [];
|
|
1326
|
-
for (const
|
|
1327
|
-
t.push(
|
|
1236
|
+
for (const s of e)
|
|
1237
|
+
t.push(w(s.byteLength)), t.push(new Uint8Array(s));
|
|
1328
1238
|
const r = u(t), n = new Uint8Array([
|
|
1329
|
-
...
|
|
1239
|
+
...w(r.byteLength),
|
|
1330
1240
|
...r
|
|
1331
1241
|
]);
|
|
1332
1242
|
return new Uint8Array([
|
|
1333
1243
|
d.Certificate,
|
|
1334
|
-
...
|
|
1244
|
+
...w(n.length),
|
|
1335
1245
|
...n
|
|
1336
1246
|
]);
|
|
1337
1247
|
}
|
|
@@ -1369,37 +1279,37 @@ class K {
|
|
|
1369
1279
|
* @returns
|
|
1370
1280
|
*/
|
|
1371
1281
|
static async ECDHEServerKeyExchange(e, t, r, n) {
|
|
1372
|
-
const
|
|
1282
|
+
const s = new Uint8Array(
|
|
1373
1283
|
await crypto.subtle.exportKey("raw", r.publicKey)
|
|
1374
|
-
),
|
|
1284
|
+
), _ = new Uint8Array([
|
|
1375
1285
|
// Curve type (1 byte)
|
|
1376
|
-
|
|
1286
|
+
xe.NamedCurve,
|
|
1377
1287
|
// Curve name (2 bytes)
|
|
1378
|
-
...
|
|
1288
|
+
...K(ke.secp256r1),
|
|
1379
1289
|
// Public key length (1 byte)
|
|
1380
|
-
|
|
1290
|
+
s.byteLength,
|
|
1381
1291
|
// Public key (65 bytes, uncompressed format)
|
|
1382
|
-
...
|
|
1383
|
-
]),
|
|
1292
|
+
...s
|
|
1293
|
+
]), a = await crypto.subtle.sign(
|
|
1384
1294
|
{
|
|
1385
1295
|
name: "RSASSA-PKCS1-v1_5",
|
|
1386
1296
|
hash: "SHA-256"
|
|
1387
1297
|
},
|
|
1388
1298
|
n,
|
|
1389
|
-
new Uint8Array([...e, ...t, ...
|
|
1390
|
-
), c = new Uint8Array(
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
]),
|
|
1394
|
-
...
|
|
1299
|
+
new Uint8Array([...e, ...t, ..._])
|
|
1300
|
+
), c = new Uint8Array(a), S = new Uint8Array([
|
|
1301
|
+
j.sha256,
|
|
1302
|
+
F.rsa
|
|
1303
|
+
]), A = new Uint8Array([
|
|
1304
|
+
..._,
|
|
1395
1305
|
...S,
|
|
1396
|
-
...
|
|
1306
|
+
...K(c.length),
|
|
1397
1307
|
...c
|
|
1398
1308
|
]);
|
|
1399
1309
|
return new Uint8Array([
|
|
1400
1310
|
d.ServerKeyExchange,
|
|
1401
|
-
...
|
|
1402
|
-
...
|
|
1311
|
+
...w(A.length),
|
|
1312
|
+
...A
|
|
1403
1313
|
]);
|
|
1404
1314
|
}
|
|
1405
1315
|
/**
|
|
@@ -1441,31 +1351,31 @@ class K {
|
|
|
1441
1351
|
* +------------------------------------+
|
|
1442
1352
|
*/
|
|
1443
1353
|
static serverHello(e, t, r) {
|
|
1444
|
-
const n = e.extensions.map((
|
|
1445
|
-
switch (
|
|
1354
|
+
const n = e.extensions.map((a) => {
|
|
1355
|
+
switch (a.type) {
|
|
1446
1356
|
case "server_name":
|
|
1447
|
-
return
|
|
1357
|
+
return ae.encodeForClient();
|
|
1448
1358
|
}
|
|
1449
|
-
}).filter((
|
|
1359
|
+
}).filter((a) => a !== void 0), s = u(n), _ = new Uint8Array([
|
|
1450
1360
|
// Version field – 0x03, 0x03 means TLS 1.2
|
|
1451
|
-
...
|
|
1361
|
+
...P,
|
|
1452
1362
|
...t,
|
|
1453
1363
|
e.session_id.length,
|
|
1454
1364
|
...e.session_id,
|
|
1455
|
-
...
|
|
1365
|
+
...K(oe.TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256),
|
|
1456
1366
|
r,
|
|
1457
1367
|
// Extensions length (2 bytes)
|
|
1458
|
-
...
|
|
1459
|
-
...
|
|
1368
|
+
...K(s.length),
|
|
1369
|
+
...s
|
|
1460
1370
|
]);
|
|
1461
1371
|
return new Uint8Array([
|
|
1462
1372
|
d.ServerHello,
|
|
1463
|
-
...
|
|
1464
|
-
...
|
|
1373
|
+
...w(_.length),
|
|
1374
|
+
..._
|
|
1465
1375
|
]);
|
|
1466
1376
|
}
|
|
1467
1377
|
static serverHelloDone() {
|
|
1468
|
-
return new Uint8Array([d.ServerHelloDone, ...
|
|
1378
|
+
return new Uint8Array([d.ServerHelloDone, ...w(0)]);
|
|
1469
1379
|
}
|
|
1470
1380
|
/**
|
|
1471
1381
|
* Server finished message.
|
|
@@ -1490,7 +1400,7 @@ class K {
|
|
|
1490
1400
|
"SHA-256",
|
|
1491
1401
|
u(e)
|
|
1492
1402
|
), n = new Uint8Array(
|
|
1493
|
-
await
|
|
1403
|
+
await q(
|
|
1494
1404
|
t,
|
|
1495
1405
|
new TextEncoder().encode("server finished"),
|
|
1496
1406
|
r,
|
|
@@ -1500,7 +1410,7 @@ class K {
|
|
|
1500
1410
|
);
|
|
1501
1411
|
return new Uint8Array([
|
|
1502
1412
|
d.Finished,
|
|
1503
|
-
...
|
|
1413
|
+
...w(n.length),
|
|
1504
1414
|
...n
|
|
1505
1415
|
]);
|
|
1506
1416
|
}
|
|
@@ -1508,25 +1418,25 @@ class K {
|
|
|
1508
1418
|
return new Uint8Array([1]);
|
|
1509
1419
|
}
|
|
1510
1420
|
}
|
|
1511
|
-
function
|
|
1512
|
-
return
|
|
1421
|
+
function je(i, e) {
|
|
1422
|
+
return Ge.generateCertificate(i, e);
|
|
1513
1423
|
}
|
|
1514
|
-
function
|
|
1424
|
+
function Ht(i) {
|
|
1515
1425
|
return `-----BEGIN CERTIFICATE-----
|
|
1516
|
-
${
|
|
1517
|
-
|
|
1426
|
+
${le(
|
|
1427
|
+
he(i.buffer)
|
|
1518
1428
|
)}
|
|
1519
1429
|
-----END CERTIFICATE-----`;
|
|
1520
1430
|
}
|
|
1521
|
-
async function
|
|
1522
|
-
const e = await crypto.subtle.exportKey("pkcs8",
|
|
1431
|
+
async function dt(i) {
|
|
1432
|
+
const e = await crypto.subtle.exportKey("pkcs8", i);
|
|
1523
1433
|
return `-----BEGIN PRIVATE KEY-----
|
|
1524
|
-
${
|
|
1525
|
-
|
|
1434
|
+
${le(
|
|
1435
|
+
he(e)
|
|
1526
1436
|
)}
|
|
1527
1437
|
-----END PRIVATE KEY-----`;
|
|
1528
1438
|
}
|
|
1529
|
-
class
|
|
1439
|
+
class Ge {
|
|
1530
1440
|
static async generateCertificate(e, t) {
|
|
1531
1441
|
const r = await crypto.subtle.generateKey(
|
|
1532
1442
|
{
|
|
@@ -1541,13 +1451,13 @@ class Je {
|
|
|
1541
1451
|
), n = await this.signingRequest(
|
|
1542
1452
|
e,
|
|
1543
1453
|
r.publicKey
|
|
1544
|
-
),
|
|
1454
|
+
), s = await this.sign(
|
|
1545
1455
|
n,
|
|
1546
1456
|
(t == null ? void 0 : t.privateKey) ?? r.privateKey
|
|
1547
1457
|
);
|
|
1548
1458
|
return {
|
|
1549
1459
|
keyPair: r,
|
|
1550
|
-
certificate:
|
|
1460
|
+
certificate: s,
|
|
1551
1461
|
tbsCertificate: n,
|
|
1552
1462
|
tbsDescription: e
|
|
1553
1463
|
};
|
|
@@ -1593,7 +1503,7 @@ class Je {
|
|
|
1593
1503
|
}
|
|
1594
1504
|
static signatureAlgorithm(e = "sha256WithRSAEncryption") {
|
|
1595
1505
|
return o.sequence([
|
|
1596
|
-
o.objectIdentifier(
|
|
1506
|
+
o.objectIdentifier(p(e)),
|
|
1597
1507
|
o.null()
|
|
1598
1508
|
]);
|
|
1599
1509
|
}
|
|
@@ -1606,17 +1516,17 @@ class Je {
|
|
|
1606
1516
|
static distinguishedName(e) {
|
|
1607
1517
|
const t = [];
|
|
1608
1518
|
for (const [r, n] of Object.entries(e)) {
|
|
1609
|
-
const
|
|
1610
|
-
o.objectIdentifier(
|
|
1519
|
+
const s = [
|
|
1520
|
+
o.objectIdentifier(p(r))
|
|
1611
1521
|
];
|
|
1612
1522
|
switch (r) {
|
|
1613
1523
|
case "countryName":
|
|
1614
|
-
|
|
1524
|
+
s.push(o.printableString(n));
|
|
1615
1525
|
break;
|
|
1616
1526
|
default:
|
|
1617
|
-
|
|
1527
|
+
s.push(o.utf8String(n));
|
|
1618
1528
|
}
|
|
1619
|
-
t.push(o.set([o.sequence(
|
|
1529
|
+
t.push(o.set([o.sequence(s)]));
|
|
1620
1530
|
}
|
|
1621
1531
|
return o.sequence(t);
|
|
1622
1532
|
}
|
|
@@ -1625,14 +1535,14 @@ class Je {
|
|
|
1625
1535
|
o.ASN1(
|
|
1626
1536
|
H.UTCTime,
|
|
1627
1537
|
new TextEncoder().encode(
|
|
1628
|
-
|
|
1538
|
+
re((e == null ? void 0 : e.notBefore) ?? /* @__PURE__ */ new Date())
|
|
1629
1539
|
)
|
|
1630
1540
|
),
|
|
1631
1541
|
o.ASN1(
|
|
1632
1542
|
H.UTCTime,
|
|
1633
1543
|
new TextEncoder().encode(
|
|
1634
|
-
|
|
1635
|
-
(e == null ? void 0 : e.notAfter) ??
|
|
1544
|
+
re(
|
|
1545
|
+
(e == null ? void 0 : e.notAfter) ?? Ve(/* @__PURE__ */ new Date(), 10)
|
|
1636
1546
|
)
|
|
1637
1547
|
)
|
|
1638
1548
|
)
|
|
@@ -1646,14 +1556,14 @@ class Je {
|
|
|
1646
1556
|
return t !== void 0 && r.push(
|
|
1647
1557
|
o.integer(new Uint8Array([t]))
|
|
1648
1558
|
), o.sequence([
|
|
1649
|
-
o.objectIdentifier(
|
|
1559
|
+
o.objectIdentifier(p("basicConstraints")),
|
|
1650
1560
|
o.octetString(o.sequence(r))
|
|
1651
1561
|
]);
|
|
1652
1562
|
}
|
|
1653
1563
|
static keyUsage(e) {
|
|
1654
1564
|
const t = new Uint8Array([0]);
|
|
1655
1565
|
return e != null && e.digitalSignature && (t[0] |= 1), e != null && e.nonRepudiation && (t[0] |= 2), e != null && e.keyEncipherment && (t[0] |= 4), e != null && e.dataEncipherment && (t[0] |= 8), e != null && e.keyAgreement && (t[0] |= 16), e != null && e.keyCertSign && (t[0] |= 32), e != null && e.cRLSign && (t[0] |= 64), e != null && e.encipherOnly && (t[0] |= 128), e != null && e.decipherOnly && (t[0] |= 64), o.sequence([
|
|
1656
|
-
o.objectIdentifier(
|
|
1566
|
+
o.objectIdentifier(p("keyUsage")),
|
|
1657
1567
|
o.boolean(!0),
|
|
1658
1568
|
// Critical
|
|
1659
1569
|
o.octetString(o.bitString(t))
|
|
@@ -1661,13 +1571,13 @@ class Je {
|
|
|
1661
1571
|
}
|
|
1662
1572
|
static extKeyUsage(e = {}) {
|
|
1663
1573
|
return o.sequence([
|
|
1664
|
-
o.objectIdentifier(
|
|
1574
|
+
o.objectIdentifier(p("extKeyUsage")),
|
|
1665
1575
|
o.boolean(!0),
|
|
1666
1576
|
// Critical
|
|
1667
1577
|
o.octetString(
|
|
1668
1578
|
o.sequence(
|
|
1669
1579
|
Object.entries(e).map(([t, r]) => r ? o.objectIdentifier(
|
|
1670
|
-
|
|
1580
|
+
p(t)
|
|
1671
1581
|
) : o.null())
|
|
1672
1582
|
)
|
|
1673
1583
|
)
|
|
@@ -1676,29 +1586,29 @@ class Je {
|
|
|
1676
1586
|
static nsCertType(e) {
|
|
1677
1587
|
const t = new Uint8Array([0]);
|
|
1678
1588
|
return e.client && (t[0] |= 1), e.server && (t[0] |= 2), e.email && (t[0] |= 4), e.objsign && (t[0] |= 8), e.sslCA && (t[0] |= 16), e.emailCA && (t[0] |= 32), e.objCA && (t[0] |= 64), o.sequence([
|
|
1679
|
-
o.objectIdentifier(
|
|
1589
|
+
o.objectIdentifier(p("nsCertType")),
|
|
1680
1590
|
o.octetString(t)
|
|
1681
1591
|
]);
|
|
1682
1592
|
}
|
|
1683
1593
|
static subjectAltName(e) {
|
|
1684
|
-
var
|
|
1685
|
-
const t = ((
|
|
1686
|
-
const c = o.ia5String(
|
|
1594
|
+
var s, _;
|
|
1595
|
+
const t = ((s = e.dnsNames) == null ? void 0 : s.map((a) => {
|
|
1596
|
+
const c = o.ia5String(a);
|
|
1687
1597
|
return o.contextSpecific(2, c);
|
|
1688
|
-
})) || [], r = ((
|
|
1689
|
-
const c = o.ia5String(
|
|
1598
|
+
})) || [], r = ((_ = e.ipAddresses) == null ? void 0 : _.map((a) => {
|
|
1599
|
+
const c = o.ia5String(a);
|
|
1690
1600
|
return o.contextSpecific(7, c);
|
|
1691
1601
|
})) || [], n = o.octetString(
|
|
1692
1602
|
o.sequence([...t, ...r])
|
|
1693
1603
|
);
|
|
1694
1604
|
return o.sequence([
|
|
1695
|
-
o.objectIdentifier(
|
|
1605
|
+
o.objectIdentifier(p("subjectAltName")),
|
|
1696
1606
|
o.boolean(!0),
|
|
1697
1607
|
n
|
|
1698
1608
|
]);
|
|
1699
1609
|
}
|
|
1700
1610
|
}
|
|
1701
|
-
const
|
|
1611
|
+
const $e = {
|
|
1702
1612
|
// Algorithm OIDs
|
|
1703
1613
|
"1.2.840.113549.1.1.1": "rsaEncryption",
|
|
1704
1614
|
"1.2.840.113549.1.1.4": "md5WithRSAEncryption",
|
|
@@ -1808,13 +1718,13 @@ const Xe = {
|
|
|
1808
1718
|
"1.3.6.1.5.5.7.3.4": "emailProtection",
|
|
1809
1719
|
"1.3.6.1.5.5.7.3.8": "timeStamping"
|
|
1810
1720
|
};
|
|
1811
|
-
function
|
|
1812
|
-
for (const [e, t] of Object.entries(
|
|
1813
|
-
if (t ===
|
|
1721
|
+
function p(i) {
|
|
1722
|
+
for (const [e, t] of Object.entries($e))
|
|
1723
|
+
if (t === i)
|
|
1814
1724
|
return e;
|
|
1815
|
-
throw new Error(`OID not found for name: ${
|
|
1725
|
+
throw new Error(`OID not found for name: ${i}`);
|
|
1816
1726
|
}
|
|
1817
|
-
const
|
|
1727
|
+
const te = 32, H = {
|
|
1818
1728
|
Boolean: 1,
|
|
1819
1729
|
Integer: 2,
|
|
1820
1730
|
BitString: 3,
|
|
@@ -1822,8 +1732,8 @@ const se = 32, H = {
|
|
|
1822
1732
|
Null: 5,
|
|
1823
1733
|
OID: 6,
|
|
1824
1734
|
Utf8String: 12,
|
|
1825
|
-
Sequence: 16 |
|
|
1826
|
-
Set: 17 |
|
|
1735
|
+
Sequence: 16 | te,
|
|
1736
|
+
Set: 17 | te,
|
|
1827
1737
|
PrintableString: 19,
|
|
1828
1738
|
IA5String: 22,
|
|
1829
1739
|
UTCTime: 23
|
|
@@ -1838,11 +1748,11 @@ class o {
|
|
|
1838
1748
|
const r = [];
|
|
1839
1749
|
for (; t > 0; )
|
|
1840
1750
|
r.unshift(t & 255), t >>= 8;
|
|
1841
|
-
const n = r.length,
|
|
1842
|
-
|
|
1843
|
-
for (let
|
|
1844
|
-
|
|
1845
|
-
return
|
|
1751
|
+
const n = r.length, s = new Uint8Array(1 + n);
|
|
1752
|
+
s[0] = 128 | n;
|
|
1753
|
+
for (let _ = 0; _ < n; _++)
|
|
1754
|
+
s[_ + 1] = r[_];
|
|
1755
|
+
return s;
|
|
1846
1756
|
}
|
|
1847
1757
|
}
|
|
1848
1758
|
static ASN1(e, t) {
|
|
@@ -1868,15 +1778,15 @@ class o {
|
|
|
1868
1778
|
}
|
|
1869
1779
|
static objectIdentifier(e) {
|
|
1870
1780
|
const t = e.split(".").map(Number), n = [t[0] * 40 + t[1]];
|
|
1871
|
-
for (let
|
|
1872
|
-
let
|
|
1873
|
-
const
|
|
1781
|
+
for (let s = 2; s < t.length; s++) {
|
|
1782
|
+
let _ = t[s];
|
|
1783
|
+
const a = [];
|
|
1874
1784
|
do
|
|
1875
|
-
|
|
1876
|
-
while (
|
|
1877
|
-
for (let c = 0; c <
|
|
1878
|
-
|
|
1879
|
-
n.push(...
|
|
1785
|
+
a.unshift(_ & 127), _ >>= 7;
|
|
1786
|
+
while (_ > 0);
|
|
1787
|
+
for (let c = 0; c < a.length - 1; c++)
|
|
1788
|
+
a[c] |= 128;
|
|
1789
|
+
n.push(...a);
|
|
1880
1790
|
}
|
|
1881
1791
|
return o.ASN1(H.OID, new Uint8Array(n));
|
|
1882
1792
|
}
|
|
@@ -1909,81 +1819,81 @@ class o {
|
|
|
1909
1819
|
);
|
|
1910
1820
|
}
|
|
1911
1821
|
}
|
|
1912
|
-
function
|
|
1913
|
-
return btoa(String.fromCodePoint(...new Uint8Array(
|
|
1822
|
+
function he(i) {
|
|
1823
|
+
return btoa(String.fromCodePoint(...new Uint8Array(i)));
|
|
1914
1824
|
}
|
|
1915
|
-
function
|
|
1825
|
+
function le(i) {
|
|
1916
1826
|
var e;
|
|
1917
|
-
return ((e =
|
|
1918
|
-
`)) ||
|
|
1827
|
+
return ((e = i.match(/.{1,64}/g)) == null ? void 0 : e.join(`
|
|
1828
|
+
`)) || i;
|
|
1919
1829
|
}
|
|
1920
|
-
function
|
|
1921
|
-
const e =
|
|
1922
|
-
return `${e}${t}${r}${n}${
|
|
1830
|
+
function re(i) {
|
|
1831
|
+
const e = i.getUTCFullYear().toString().substr(2), t = D(i.getUTCMonth() + 1), r = D(i.getUTCDate()), n = D(i.getUTCHours()), s = D(i.getUTCMinutes()), _ = D(i.getUTCSeconds());
|
|
1832
|
+
return `${e}${t}${r}${n}${s}${_}Z`;
|
|
1923
1833
|
}
|
|
1924
|
-
function
|
|
1925
|
-
return
|
|
1834
|
+
function D(i) {
|
|
1835
|
+
return i.toString().padStart(2, "0");
|
|
1926
1836
|
}
|
|
1927
|
-
function
|
|
1928
|
-
const t = new Date(
|
|
1837
|
+
function Ve(i, e) {
|
|
1838
|
+
const t = new Date(i);
|
|
1929
1839
|
return t.setUTCFullYear(t.getUTCFullYear() + e), t;
|
|
1930
1840
|
}
|
|
1931
|
-
async function
|
|
1932
|
-
var
|
|
1933
|
-
const r = typeof
|
|
1841
|
+
async function ze(i, e, t) {
|
|
1842
|
+
var _;
|
|
1843
|
+
const r = typeof i == "string" ? new Request(i, e) : i;
|
|
1934
1844
|
if (!t)
|
|
1935
1845
|
return await fetch(r);
|
|
1936
|
-
const [n,
|
|
1846
|
+
const [n, s] = await me(r);
|
|
1937
1847
|
try {
|
|
1938
1848
|
return await fetch(n);
|
|
1939
1849
|
} catch {
|
|
1940
|
-
const c = ((
|
|
1850
|
+
const c = ((_ = new Headers(s.headers).get("x-cors-proxy-allowed-request-headers")) == null ? void 0 : _.split(",")) || [], S = c.includes("authorization") || c.includes("cookie"), A = await ge(s, {
|
|
1941
1851
|
url: `${t}${r.url}`,
|
|
1942
1852
|
...S && { credentials: "include" }
|
|
1943
1853
|
});
|
|
1944
|
-
return await fetch(
|
|
1854
|
+
return await fetch(A, e);
|
|
1945
1855
|
}
|
|
1946
1856
|
}
|
|
1947
|
-
class
|
|
1857
|
+
class Ye extends TransformStream {
|
|
1948
1858
|
constructor() {
|
|
1949
1859
|
let e = new Uint8Array(0), t = "SCAN_CHUNK_SIZE", r = 0;
|
|
1950
1860
|
super({
|
|
1951
|
-
transform(n,
|
|
1861
|
+
transform(n, s) {
|
|
1952
1862
|
for (e = u([e, n]); e.length > 0; )
|
|
1953
1863
|
if (t === "SCAN_CHUNK_SIZE") {
|
|
1954
1864
|
if (e.length < 3)
|
|
1955
1865
|
return;
|
|
1956
|
-
let
|
|
1957
|
-
for (;
|
|
1958
|
-
const S = e[
|
|
1866
|
+
let _ = 0;
|
|
1867
|
+
for (; _ < e.length; ) {
|
|
1868
|
+
const S = e[_];
|
|
1959
1869
|
if (!(S >= 48 && S <= 57 || // 0-9
|
|
1960
1870
|
S >= 97 && S <= 102 || // a-f
|
|
1961
1871
|
S >= 65 && S <= 70)) break;
|
|
1962
|
-
|
|
1872
|
+
_++;
|
|
1963
1873
|
}
|
|
1964
|
-
if (
|
|
1874
|
+
if (_ === 0)
|
|
1965
1875
|
throw new Error("Invalid chunk size format");
|
|
1966
|
-
if (e.length <
|
|
1876
|
+
if (e.length < _ + 2)
|
|
1967
1877
|
return;
|
|
1968
|
-
if (e[
|
|
1969
|
-
e[
|
|
1878
|
+
if (e[_] !== 13 || // \r
|
|
1879
|
+
e[_ + 1] !== 10)
|
|
1970
1880
|
throw new Error(
|
|
1971
1881
|
"Invalid chunk size format. Expected CRLF after chunk size"
|
|
1972
1882
|
);
|
|
1973
|
-
const
|
|
1974
|
-
e.slice(0,
|
|
1975
|
-
), c = parseInt(
|
|
1976
|
-
if (e = e.slice(
|
|
1977
|
-
t = "SCAN_FINAL_CHUNK",
|
|
1883
|
+
const a = new TextDecoder().decode(
|
|
1884
|
+
e.slice(0, _)
|
|
1885
|
+
), c = parseInt(a, 16);
|
|
1886
|
+
if (e = e.slice(_ + 2), c === 0) {
|
|
1887
|
+
t = "SCAN_FINAL_CHUNK", s.terminate();
|
|
1978
1888
|
return;
|
|
1979
1889
|
}
|
|
1980
1890
|
r = c, t = "SCAN_CHUNK_DATA";
|
|
1981
1891
|
} else if (t === "SCAN_CHUNK_DATA") {
|
|
1982
|
-
const
|
|
1892
|
+
const _ = Math.min(
|
|
1983
1893
|
r,
|
|
1984
1894
|
e.length
|
|
1985
|
-
),
|
|
1986
|
-
e = e.slice(
|
|
1895
|
+
), a = e.slice(0, _);
|
|
1896
|
+
e = e.slice(_), r -= _, s.enqueue(a), r === 0 && (t = "SCAN_CHUNK_TRAILER");
|
|
1987
1897
|
} else if (t === "SCAN_CHUNK_TRAILER") {
|
|
1988
1898
|
if (e.length < 2)
|
|
1989
1899
|
return;
|
|
@@ -1997,15 +1907,15 @@ class tt extends TransformStream {
|
|
|
1997
1907
|
});
|
|
1998
1908
|
}
|
|
1999
1909
|
}
|
|
2000
|
-
const
|
|
2001
|
-
...
|
|
1910
|
+
const Ze = (i, e) => ({
|
|
1911
|
+
...i,
|
|
2002
1912
|
websocket: {
|
|
2003
1913
|
url: (t, r, n) => `ws://playground.internal/?${new URLSearchParams({
|
|
2004
1914
|
host: r,
|
|
2005
1915
|
port: n
|
|
2006
1916
|
}).toString()}`,
|
|
2007
1917
|
subprotocol: "binary",
|
|
2008
|
-
decorator: () => class extends
|
|
1918
|
+
decorator: () => class extends Je {
|
|
2009
1919
|
constructor(t, r) {
|
|
2010
1920
|
super(t, r, {
|
|
2011
1921
|
CAroot: e.CAroot,
|
|
@@ -2015,18 +1925,18 @@ const rt = (s, e) => ({
|
|
|
2015
1925
|
}
|
|
2016
1926
|
}
|
|
2017
1927
|
});
|
|
2018
|
-
class
|
|
1928
|
+
class Je {
|
|
2019
1929
|
constructor(e, t, {
|
|
2020
1930
|
CAroot: r,
|
|
2021
1931
|
corsProxyUrl: n,
|
|
2022
|
-
outputType:
|
|
1932
|
+
outputType: s = "messages"
|
|
2023
1933
|
} = {}) {
|
|
2024
1934
|
this.CONNECTING = 0, this.OPEN = 1, this.CLOSING = 2, this.CLOSED = 3, this.readyState = this.CONNECTING, this.binaryType = "blob", this.bufferedAmount = 0, this.extensions = "", this.protocol = "ws", this.host = "", this.port = 0, this.listeners = /* @__PURE__ */ new Map(), this.clientUpstream = new TransformStream(), this.clientUpstreamWriter = this.clientUpstream.writable.getWriter(), this.clientDownstream = new TransformStream(), this.fetchInitiated = !1, this.bufferedBytesFromClient = new Uint8Array(0), this.url = e, this.options = t;
|
|
2025
|
-
const
|
|
2026
|
-
this.host =
|
|
1935
|
+
const _ = new URL(e);
|
|
1936
|
+
this.host = _.searchParams.get("host"), this.port = parseInt(_.searchParams.get("port"), 10), this.binaryType = "arraybuffer", this.corsProxyUrl = n, this.CAroot = r, s === "messages" && this.clientDownstream.readable.pipeTo(
|
|
2027
1937
|
new WritableStream({
|
|
2028
|
-
write: (
|
|
2029
|
-
this.emit("message", { data:
|
|
1938
|
+
write: (a) => {
|
|
1939
|
+
this.emit("message", { data: a });
|
|
2030
1940
|
},
|
|
2031
1941
|
abort: () => {
|
|
2032
1942
|
this.emit("error", new Error("ECONNREFUSED")), this.close();
|
|
@@ -2086,7 +1996,7 @@ class nt {
|
|
|
2086
1996
|
switch (this.bufferedBytesFromClient = u([
|
|
2087
1997
|
this.bufferedBytesFromClient,
|
|
2088
1998
|
new Uint8Array(e)
|
|
2089
|
-
]),
|
|
1999
|
+
]), Qe(this.port, this.bufferedBytesFromClient)) {
|
|
2090
2000
|
case !1:
|
|
2091
2001
|
return;
|
|
2092
2002
|
case "other":
|
|
@@ -2105,7 +2015,7 @@ class nt {
|
|
|
2105
2015
|
throw new Error(
|
|
2106
2016
|
"TLS protocol is only supported when the TCPOverFetchWebsocket is instantiated with a CAroot"
|
|
2107
2017
|
);
|
|
2108
|
-
const e = await
|
|
2018
|
+
const e = await je(
|
|
2109
2019
|
{
|
|
2110
2020
|
subject: {
|
|
2111
2021
|
commonName: this.host,
|
|
@@ -2115,7 +2025,7 @@ class nt {
|
|
|
2115
2025
|
issuer: this.CAroot.tbsDescription.subject
|
|
2116
2026
|
},
|
|
2117
2027
|
this.CAroot.keyPair
|
|
2118
|
-
), t = new
|
|
2028
|
+
), t = new Oe();
|
|
2119
2029
|
this.clientUpstream.readable.pipeTo(t.clientEnd.upstream.writable).catch(() => {
|
|
2120
2030
|
}), t.clientEnd.downstream.readable.pipeTo(this.clientDownstream.writable).catch(() => {
|
|
2121
2031
|
}), await t.TLSHandshake(e.keyPair.privateKey, [
|
|
@@ -2153,7 +2063,7 @@ class nt {
|
|
|
2153
2063
|
this.emit("message", { data: new Uint8Array(0) }), this.readyState = this.CLOSING, this.emit("close"), this.readyState = this.CLOSED;
|
|
2154
2064
|
}
|
|
2155
2065
|
}
|
|
2156
|
-
const
|
|
2066
|
+
const Xe = [
|
|
2157
2067
|
"GET",
|
|
2158
2068
|
"POST",
|
|
2159
2069
|
"HEAD",
|
|
@@ -2163,17 +2073,17 @@ const st = [
|
|
|
2163
2073
|
"PUT",
|
|
2164
2074
|
"TRACE"
|
|
2165
2075
|
];
|
|
2166
|
-
function
|
|
2076
|
+
function Qe(i, e) {
|
|
2167
2077
|
if (e.length < 8)
|
|
2168
2078
|
return !1;
|
|
2169
|
-
if (
|
|
2079
|
+
if (i === 443 && e[0] === C.Handshake && // TLS versions between 1.0 and 1.2
|
|
2170
2080
|
e[1] === 3 && e[2] >= 1 && e[2] <= 3)
|
|
2171
2081
|
return "tls";
|
|
2172
2082
|
const r = new TextDecoder("latin1", {
|
|
2173
2083
|
fatal: !0
|
|
2174
2084
|
}).decode(e);
|
|
2175
|
-
return
|
|
2176
|
-
(
|
|
2085
|
+
return Xe.some(
|
|
2086
|
+
(s) => r.startsWith(s + " ")
|
|
2177
2087
|
) ? "http" : "other";
|
|
2178
2088
|
}
|
|
2179
2089
|
class L {
|
|
@@ -2183,10 +2093,10 @@ class L {
|
|
|
2183
2093
|
static fetchRawResponseBytes(e, t) {
|
|
2184
2094
|
return new ReadableStream({
|
|
2185
2095
|
async start(r) {
|
|
2186
|
-
var
|
|
2096
|
+
var a;
|
|
2187
2097
|
let n;
|
|
2188
2098
|
try {
|
|
2189
|
-
n = await
|
|
2099
|
+
n = await ze(
|
|
2190
2100
|
e,
|
|
2191
2101
|
void 0,
|
|
2192
2102
|
t
|
|
@@ -2203,20 +2113,20 @@ Content-Length: 0\r
|
|
|
2203
2113
|
return;
|
|
2204
2114
|
}
|
|
2205
2115
|
r.enqueue(L.headersAsBytes(n));
|
|
2206
|
-
const
|
|
2207
|
-
if (!
|
|
2116
|
+
const s = (a = n.body) == null ? void 0 : a.getReader();
|
|
2117
|
+
if (!s) {
|
|
2208
2118
|
r.close();
|
|
2209
2119
|
return;
|
|
2210
2120
|
}
|
|
2211
|
-
const
|
|
2121
|
+
const _ = new TextEncoder();
|
|
2212
2122
|
for (; ; ) {
|
|
2213
|
-
const { done: c, value: S } = await
|
|
2123
|
+
const { done: c, value: S } = await s.read();
|
|
2214
2124
|
if (S && (r.enqueue(
|
|
2215
|
-
|
|
2125
|
+
_.encode(`${S.length.toString(16)}\r
|
|
2216
2126
|
`)
|
|
2217
|
-
), r.enqueue(S), r.enqueue(
|
|
2127
|
+
), r.enqueue(S), r.enqueue(_.encode(`\r
|
|
2218
2128
|
`))), c) {
|
|
2219
|
-
r.enqueue(
|
|
2129
|
+
r.enqueue(_.encode(`0\r
|
|
2220
2130
|
\r
|
|
2221
2131
|
`)), r.close();
|
|
2222
2132
|
return;
|
|
@@ -2227,73 +2137,73 @@ Content-Length: 0\r
|
|
|
2227
2137
|
}
|
|
2228
2138
|
static headersAsBytes(e) {
|
|
2229
2139
|
const t = `HTTP/1.1 ${e.status} ${e.statusText}`, r = {};
|
|
2230
|
-
e.headers.forEach((
|
|
2231
|
-
r[
|
|
2140
|
+
e.headers.forEach((_, a) => {
|
|
2141
|
+
r[a.toLowerCase()] = _;
|
|
2232
2142
|
}), delete r["content-length"], r["transfer-encoding"] = "chunked";
|
|
2233
2143
|
const n = [];
|
|
2234
|
-
for (const [
|
|
2235
|
-
n.push(`${
|
|
2236
|
-
const
|
|
2144
|
+
for (const [_, a] of Object.entries(r))
|
|
2145
|
+
n.push(`${_}: ${a}`);
|
|
2146
|
+
const s = [t, ...n].join(`\r
|
|
2237
2147
|
`) + `\r
|
|
2238
2148
|
\r
|
|
2239
2149
|
`;
|
|
2240
|
-
return new TextEncoder().encode(
|
|
2150
|
+
return new TextEncoder().encode(s);
|
|
2241
2151
|
}
|
|
2242
2152
|
/**
|
|
2243
2153
|
* Parses a raw, streamed HTTP request into a Request object
|
|
2244
2154
|
* with known headers and a readable body stream.
|
|
2245
2155
|
*/
|
|
2246
2156
|
static async parseHttpRequest(e, t, r) {
|
|
2247
|
-
let n = new Uint8Array(0),
|
|
2248
|
-
const
|
|
2249
|
-
for (;
|
|
2250
|
-
const { done:
|
|
2251
|
-
if (
|
|
2252
|
-
|
|
2157
|
+
let n = new Uint8Array(0), s = !1, _ = -1;
|
|
2158
|
+
const a = e.getReader();
|
|
2159
|
+
for (; _ === -1; ) {
|
|
2160
|
+
const { done: N, value: R } = await a.read();
|
|
2161
|
+
if (N) {
|
|
2162
|
+
s = !0;
|
|
2253
2163
|
break;
|
|
2254
2164
|
}
|
|
2255
|
-
n = u([n,
|
|
2165
|
+
n = u([n, R]), _ = et(
|
|
2256
2166
|
n,
|
|
2257
2167
|
new Uint8Array([13, 10, 13, 10])
|
|
2258
2168
|
);
|
|
2259
2169
|
}
|
|
2260
|
-
|
|
2261
|
-
const c = n.slice(0,
|
|
2262
|
-
|
|
2170
|
+
a.releaseLock();
|
|
2171
|
+
const c = n.slice(0, _), S = L.parseRequestHeaders(c), A = S.headers.get("Transfer-Encoding") !== null ? "chunked" : "content-length", h = S.headers.get("Content-Length") !== null ? parseInt(S.headers.get("Content-Length"), 10) : void 0, l = n.slice(
|
|
2172
|
+
_ + 4
|
|
2263
2173
|
/* Skip \r\n\r\n */
|
|
2264
2174
|
);
|
|
2265
|
-
let
|
|
2175
|
+
let T;
|
|
2266
2176
|
if (S.method !== "GET") {
|
|
2267
|
-
const
|
|
2268
|
-
let
|
|
2269
|
-
const
|
|
2177
|
+
const N = e.getReader();
|
|
2178
|
+
let R = l.length, x = l.slice(-6);
|
|
2179
|
+
const He = new TextEncoder().encode(`0\r
|
|
2270
2180
|
\r
|
|
2271
2181
|
`);
|
|
2272
|
-
|
|
2273
|
-
async start(
|
|
2274
|
-
|
|
2182
|
+
T = new ReadableStream({
|
|
2183
|
+
async start(I) {
|
|
2184
|
+
l.length > 0 && I.enqueue(l), s && I.close();
|
|
2275
2185
|
},
|
|
2276
|
-
async pull(
|
|
2277
|
-
const { done:
|
|
2278
|
-
if (
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
]).slice(-5)),
|
|
2282
|
-
(
|
|
2186
|
+
async pull(I) {
|
|
2187
|
+
const { done: de, value: m } = await N.read();
|
|
2188
|
+
if (R += (m == null ? void 0 : m.length) || 0, m && (I.enqueue(m), x = u([
|
|
2189
|
+
x,
|
|
2190
|
+
m || new Uint8Array()
|
|
2191
|
+
]).slice(-5)), de || A === "content-length" && h !== void 0 && R >= h || A === "chunked" && x.every(
|
|
2192
|
+
(Te, Ee) => Te === He[Ee]
|
|
2283
2193
|
)) {
|
|
2284
|
-
|
|
2194
|
+
I.close();
|
|
2285
2195
|
return;
|
|
2286
2196
|
}
|
|
2287
2197
|
}
|
|
2288
|
-
}),
|
|
2289
|
-
new
|
|
2198
|
+
}), A === "chunked" && (T = T.pipeThrough(
|
|
2199
|
+
new Ye()
|
|
2290
2200
|
));
|
|
2291
2201
|
}
|
|
2292
|
-
const
|
|
2293
|
-
return
|
|
2202
|
+
const M = S.headers.get("Host") ?? t, G = new URL(S.path, r + "://" + M);
|
|
2203
|
+
return G.pathname = S.path, new Request(G.toString(), {
|
|
2294
2204
|
method: S.method,
|
|
2295
2205
|
headers: S.headers,
|
|
2296
|
-
body:
|
|
2206
|
+
body: T,
|
|
2297
2207
|
// In Node.js, duplex: 'half' is required when
|
|
2298
2208
|
// the body stream is provided.
|
|
2299
2209
|
// @ts-expect-error
|
|
@@ -2302,41 +2212,41 @@ Content-Length: 0\r
|
|
|
2302
2212
|
}
|
|
2303
2213
|
static parseRequestHeaders(e) {
|
|
2304
2214
|
const t = new TextDecoder().decode(e), r = t.split(`
|
|
2305
|
-
`)[0], [n,
|
|
2306
|
-
for (const
|
|
2215
|
+
`)[0], [n, s] = r.split(" "), _ = new Headers();
|
|
2216
|
+
for (const a of t.split(`\r
|
|
2307
2217
|
`).slice(1)) {
|
|
2308
|
-
if (
|
|
2218
|
+
if (a === "")
|
|
2309
2219
|
break;
|
|
2310
|
-
const [c, S] =
|
|
2311
|
-
|
|
2220
|
+
const [c, S] = a.split(": ");
|
|
2221
|
+
_.set(c, S);
|
|
2312
2222
|
}
|
|
2313
|
-
return { method: n, path:
|
|
2223
|
+
return { method: n, path: s, headers: _ };
|
|
2314
2224
|
}
|
|
2315
2225
|
}
|
|
2316
|
-
function
|
|
2317
|
-
const t =
|
|
2318
|
-
for (let
|
|
2319
|
-
let
|
|
2320
|
-
for (let
|
|
2321
|
-
if (s
|
|
2322
|
-
|
|
2226
|
+
function et(i, e) {
|
|
2227
|
+
const t = i.length, r = e.length, n = t - r;
|
|
2228
|
+
for (let s = 0; s <= n; s++) {
|
|
2229
|
+
let _ = !0;
|
|
2230
|
+
for (let a = 0; a < r; a++)
|
|
2231
|
+
if (i[s + a] !== e[a]) {
|
|
2232
|
+
_ = !1;
|
|
2323
2233
|
break;
|
|
2324
2234
|
}
|
|
2325
|
-
if (
|
|
2326
|
-
return
|
|
2235
|
+
if (_)
|
|
2236
|
+
return s;
|
|
2327
2237
|
}
|
|
2328
2238
|
return -1;
|
|
2329
2239
|
}
|
|
2330
|
-
async function
|
|
2240
|
+
async function tt(i) {
|
|
2331
2241
|
const e = "icudt74l.dat", t = (await import("./shared/icudt74l.js")).dataFilename, r = await (await fetch(t)).arrayBuffer();
|
|
2332
2242
|
return {
|
|
2333
|
-
...
|
|
2243
|
+
...i,
|
|
2334
2244
|
ENV: {
|
|
2335
|
-
...
|
|
2245
|
+
...i.ENV,
|
|
2336
2246
|
ICU_DATA: "/internal/shared"
|
|
2337
2247
|
},
|
|
2338
2248
|
onRuntimeInitialized: (n) => {
|
|
2339
|
-
|
|
2249
|
+
i.onRuntimeInitialized && i.onRuntimeInitialized(n), W.fileExists(
|
|
2340
2250
|
n.FS,
|
|
2341
2251
|
`${n.ENV.ICU_DATA}/${e}`
|
|
2342
2252
|
) || (n.FS.mkdirTree(n.ENV.ICU_DATA), n.FS.writeFile(
|
|
@@ -2346,9 +2256,9 @@ async function _t(s) {
|
|
|
2346
2256
|
}
|
|
2347
2257
|
};
|
|
2348
2258
|
}
|
|
2349
|
-
const
|
|
2259
|
+
const rt = () => ({
|
|
2350
2260
|
websocket: {
|
|
2351
|
-
decorator: (
|
|
2261
|
+
decorator: (i) => class extends i {
|
|
2352
2262
|
constructor() {
|
|
2353
2263
|
try {
|
|
2354
2264
|
super();
|
|
@@ -2361,46 +2271,46 @@ const ot = () => ({
|
|
|
2361
2271
|
}
|
|
2362
2272
|
}
|
|
2363
2273
|
});
|
|
2364
|
-
async function
|
|
2365
|
-
var
|
|
2274
|
+
async function Et(i, e = {}) {
|
|
2275
|
+
var s;
|
|
2366
2276
|
let t = {
|
|
2367
|
-
...
|
|
2277
|
+
...rt(),
|
|
2368
2278
|
...e.emscriptenOptions || {}
|
|
2369
2279
|
};
|
|
2370
|
-
e.tcpOverFetch && (t =
|
|
2280
|
+
e.tcpOverFetch && (t = Ze(
|
|
2371
2281
|
t,
|
|
2372
2282
|
e.tcpOverFetch
|
|
2373
|
-
)), e.withICU && (t =
|
|
2283
|
+
)), e.withICU && (t = tt(t));
|
|
2374
2284
|
const [r, n] = await Promise.all([
|
|
2375
|
-
|
|
2285
|
+
De(i),
|
|
2376
2286
|
t
|
|
2377
2287
|
]);
|
|
2378
|
-
return (
|
|
2288
|
+
return (s = e.onPhpLoaderModuleLoaded) == null || s.call(e, r), await pe(r, n);
|
|
2379
2289
|
}
|
|
2380
|
-
function
|
|
2290
|
+
function ft(i, e) {
|
|
2381
2291
|
window.addEventListener("message", (t) => {
|
|
2382
|
-
t.source ===
|
|
2292
|
+
t.source === i.contentWindow && (e && t.origin !== e || typeof t.data != "object" || t.data.type !== "relay" || window.parent.postMessage(t.data, "*"));
|
|
2383
2293
|
}), window.addEventListener("message", (t) => {
|
|
2384
2294
|
var r;
|
|
2385
|
-
t.source === window.parent && (typeof t.data != "object" || t.data.type !== "relay" || (r =
|
|
2295
|
+
t.source === window.parent && (typeof t.data != "object" || t.data.type !== "relay" || (r = i == null ? void 0 : i.contentWindow) == null || r.postMessage(t.data));
|
|
2386
2296
|
});
|
|
2387
2297
|
}
|
|
2388
|
-
async function
|
|
2389
|
-
const e = new Worker(
|
|
2298
|
+
async function pt(i) {
|
|
2299
|
+
const e = new Worker(i, { type: "module" });
|
|
2390
2300
|
return new Promise((t, r) => {
|
|
2391
|
-
e.onerror = (
|
|
2392
|
-
const
|
|
2393
|
-
`WebWorker failed to load at ${
|
|
2301
|
+
e.onerror = (s) => {
|
|
2302
|
+
const _ = new Error(
|
|
2303
|
+
`WebWorker failed to load at ${i}. ${s.message ? `Original error: ${s.message}` : ""}`
|
|
2394
2304
|
);
|
|
2395
|
-
|
|
2305
|
+
_.filename = s.filename, r(_);
|
|
2396
2306
|
};
|
|
2397
|
-
function n(
|
|
2398
|
-
|
|
2307
|
+
function n(s) {
|
|
2308
|
+
s.data === "worker-script-started" && (t(e), e.removeEventListener("message", n));
|
|
2399
2309
|
}
|
|
2400
2310
|
e.addEventListener("message", n);
|
|
2401
2311
|
});
|
|
2402
2312
|
}
|
|
2403
|
-
function
|
|
2313
|
+
function wt(i, e = { initialSync: {} }) {
|
|
2404
2314
|
return e = {
|
|
2405
2315
|
...e,
|
|
2406
2316
|
initialSync: {
|
|
@@ -2408,43 +2318,43 @@ function Wt(s, e = { initialSync: {} }) {
|
|
|
2408
2318
|
direction: e.initialSync.direction ?? "opfs-to-memfs"
|
|
2409
2319
|
}
|
|
2410
2320
|
}, async function(t, r, n) {
|
|
2411
|
-
return e.initialSync.direction === "opfs-to-memfs" ? (
|
|
2321
|
+
return e.initialSync.direction === "opfs-to-memfs" ? (W.fileExists(r, n) && W.rmdir(r, n), W.mkdir(r, n), await nt(r, i, n)) : await ue(
|
|
2412
2322
|
r,
|
|
2413
|
-
|
|
2323
|
+
i,
|
|
2414
2324
|
n,
|
|
2415
2325
|
e.initialSync.onProgress
|
|
2416
|
-
),
|
|
2326
|
+
), it(t, i, n);
|
|
2417
2327
|
};
|
|
2418
2328
|
}
|
|
2419
|
-
async function
|
|
2420
|
-
|
|
2421
|
-
const r = new
|
|
2329
|
+
async function nt(i, e, t) {
|
|
2330
|
+
W.mkdir(i, t);
|
|
2331
|
+
const r = new Le({
|
|
2422
2332
|
concurrency: 40
|
|
2423
|
-
}), n = [],
|
|
2333
|
+
}), n = [], s = [
|
|
2424
2334
|
[e, t]
|
|
2425
2335
|
];
|
|
2426
|
-
for (;
|
|
2427
|
-
const [
|
|
2428
|
-
for await (const c of
|
|
2336
|
+
for (; s.length > 0; ) {
|
|
2337
|
+
const [_, a] = s.pop();
|
|
2338
|
+
for await (const c of _.values()) {
|
|
2429
2339
|
const S = r.run(async () => {
|
|
2430
|
-
const
|
|
2431
|
-
|
|
2340
|
+
const A = ie(
|
|
2341
|
+
a,
|
|
2432
2342
|
c.name
|
|
2433
2343
|
);
|
|
2434
2344
|
if (c.kind === "directory") {
|
|
2435
2345
|
try {
|
|
2436
|
-
|
|
2437
|
-
} catch (
|
|
2438
|
-
if ((
|
|
2439
|
-
throw
|
|
2346
|
+
i.mkdir(A);
|
|
2347
|
+
} catch (h) {
|
|
2348
|
+
if ((h == null ? void 0 : h.errno) !== 20)
|
|
2349
|
+
throw U.error(h), h;
|
|
2440
2350
|
}
|
|
2441
|
-
|
|
2351
|
+
s.push([c, A]);
|
|
2442
2352
|
} else if (c.kind === "file") {
|
|
2443
|
-
const
|
|
2444
|
-
|
|
2445
|
-
|
|
2353
|
+
const h = await c.getFile(), l = new Uint8Array(await h.arrayBuffer());
|
|
2354
|
+
i.createDataFile(
|
|
2355
|
+
a,
|
|
2446
2356
|
c.name,
|
|
2447
|
-
|
|
2357
|
+
l,
|
|
2448
2358
|
!0,
|
|
2449
2359
|
!0,
|
|
2450
2360
|
!0
|
|
@@ -2454,48 +2364,48 @@ async function ct(s, e, t) {
|
|
|
2454
2364
|
});
|
|
2455
2365
|
n.push(S);
|
|
2456
2366
|
}
|
|
2457
|
-
for (;
|
|
2367
|
+
for (; s.length === 0 && n.length > 0; )
|
|
2458
2368
|
await Promise.any(n);
|
|
2459
2369
|
}
|
|
2460
2370
|
}
|
|
2461
|
-
async function
|
|
2462
|
-
|
|
2371
|
+
async function ue(i, e, t, r) {
|
|
2372
|
+
i.mkdirTree(t);
|
|
2463
2373
|
const n = [];
|
|
2464
|
-
async function
|
|
2374
|
+
async function s(A, h) {
|
|
2465
2375
|
await Promise.all(
|
|
2466
|
-
|
|
2467
|
-
(
|
|
2468
|
-
).map(async (
|
|
2469
|
-
const
|
|
2470
|
-
if (!
|
|
2471
|
-
n.push([
|
|
2376
|
+
i.readdir(A).filter(
|
|
2377
|
+
(l) => l !== "." && l !== ".."
|
|
2378
|
+
).map(async (l) => {
|
|
2379
|
+
const T = ie(A, l);
|
|
2380
|
+
if (!st(i, T)) {
|
|
2381
|
+
n.push([h, T, l]);
|
|
2472
2382
|
return;
|
|
2473
2383
|
}
|
|
2474
|
-
const
|
|
2384
|
+
const M = await h.getDirectoryHandle(l, {
|
|
2475
2385
|
create: !0
|
|
2476
2386
|
});
|
|
2477
|
-
return await
|
|
2387
|
+
return await s(T, M);
|
|
2478
2388
|
})
|
|
2479
2389
|
);
|
|
2480
2390
|
}
|
|
2481
|
-
await
|
|
2482
|
-
let
|
|
2483
|
-
const
|
|
2391
|
+
await s(t, e);
|
|
2392
|
+
let _ = 0;
|
|
2393
|
+
const a = r && ot(r, 100), c = 100, S = /* @__PURE__ */ new Set();
|
|
2484
2394
|
try {
|
|
2485
|
-
for (const [h, l
|
|
2486
|
-
const
|
|
2487
|
-
h,
|
|
2395
|
+
for (const [A, h, l] of n) {
|
|
2396
|
+
const T = O(
|
|
2488
2397
|
A,
|
|
2489
|
-
|
|
2490
|
-
|
|
2398
|
+
l,
|
|
2399
|
+
i,
|
|
2400
|
+
h
|
|
2491
2401
|
).then(() => {
|
|
2492
|
-
|
|
2493
|
-
files:
|
|
2402
|
+
_++, S.delete(T), a == null || a({
|
|
2403
|
+
files: _,
|
|
2494
2404
|
total: n.length
|
|
2495
2405
|
});
|
|
2496
2406
|
});
|
|
2497
|
-
S.add(
|
|
2498
|
-
files:
|
|
2407
|
+
S.add(T), S.size >= c && (await Promise.race(S), a == null || a({
|
|
2408
|
+
files: _,
|
|
2499
2409
|
total: n.length
|
|
2500
2410
|
}));
|
|
2501
2411
|
}
|
|
@@ -2503,10 +2413,10 @@ async function Te(s, e, t, r) {
|
|
|
2503
2413
|
await Promise.allSettled(S);
|
|
2504
2414
|
}
|
|
2505
2415
|
}
|
|
2506
|
-
function
|
|
2507
|
-
return
|
|
2416
|
+
function st(i, e) {
|
|
2417
|
+
return i.isDir(i.lookupPath(e, { follow: !0 }).node.mode);
|
|
2508
2418
|
}
|
|
2509
|
-
async function
|
|
2419
|
+
async function O(i, e, t, r) {
|
|
2510
2420
|
let n;
|
|
2511
2421
|
try {
|
|
2512
2422
|
n = t.readFile(r, {
|
|
@@ -2515,51 +2425,51 @@ async function F(s, e, t, r) {
|
|
|
2515
2425
|
} catch {
|
|
2516
2426
|
return;
|
|
2517
2427
|
}
|
|
2518
|
-
const
|
|
2428
|
+
const s = await i.getFileHandle(e, { create: !0 }), _ = s.createWritable !== void 0 ? (
|
|
2519
2429
|
// Google Chrome, Firefox, probably more browsers
|
|
2520
|
-
await
|
|
2430
|
+
await s.createWritable()
|
|
2521
2431
|
) : (
|
|
2522
2432
|
// Safari
|
|
2523
|
-
await
|
|
2433
|
+
await s.createSyncAccessHandle()
|
|
2524
2434
|
);
|
|
2525
2435
|
try {
|
|
2526
|
-
await
|
|
2436
|
+
await _.truncate(0), await _.write(n);
|
|
2527
2437
|
} finally {
|
|
2528
|
-
await
|
|
2438
|
+
await _.close();
|
|
2529
2439
|
}
|
|
2530
2440
|
}
|
|
2531
|
-
function
|
|
2532
|
-
const r = [], n =
|
|
2533
|
-
r.push(
|
|
2534
|
-
}),
|
|
2535
|
-
async function
|
|
2441
|
+
function it(i, e, t) {
|
|
2442
|
+
const r = [], n = Ke(i, t, (a) => {
|
|
2443
|
+
r.push(a);
|
|
2444
|
+
}), s = new _t(i, e, t);
|
|
2445
|
+
async function _() {
|
|
2536
2446
|
if (r.length === 0)
|
|
2537
2447
|
return;
|
|
2538
|
-
const
|
|
2448
|
+
const a = await i.semaphore.acquire(), c = [...r];
|
|
2539
2449
|
r.splice(0, c.length);
|
|
2540
|
-
const S =
|
|
2450
|
+
const S = Ie(c);
|
|
2541
2451
|
try {
|
|
2542
|
-
for (const
|
|
2543
|
-
await
|
|
2452
|
+
for (const A of S)
|
|
2453
|
+
await s.processEntry(A);
|
|
2544
2454
|
} finally {
|
|
2545
|
-
|
|
2455
|
+
a();
|
|
2546
2456
|
}
|
|
2547
2457
|
}
|
|
2548
|
-
return
|
|
2549
|
-
n(),
|
|
2458
|
+
return i.addEventListener("request.end", _), function() {
|
|
2459
|
+
n(), i.removeEventListener("request.end", _);
|
|
2550
2460
|
};
|
|
2551
2461
|
}
|
|
2552
|
-
class
|
|
2462
|
+
class _t {
|
|
2553
2463
|
constructor(e, t, r) {
|
|
2554
|
-
this.php = e, this.opfs = t, this.memfsRoot =
|
|
2464
|
+
this.php = e, this.opfs = t, this.memfsRoot = ne(r);
|
|
2555
2465
|
}
|
|
2556
2466
|
toOpfsPath(e) {
|
|
2557
|
-
return
|
|
2467
|
+
return ne(e.substring(this.memfsRoot.length));
|
|
2558
2468
|
}
|
|
2559
2469
|
async processEntry(e) {
|
|
2560
2470
|
if (!e.path.startsWith(this.memfsRoot) || e.path === this.memfsRoot)
|
|
2561
2471
|
return;
|
|
2562
|
-
const t = this.toOpfsPath(e.path), r = await
|
|
2472
|
+
const t = this.toOpfsPath(e.path), r = await se(this.opfs, t), n = at(t);
|
|
2563
2473
|
if (n)
|
|
2564
2474
|
try {
|
|
2565
2475
|
if (e.operation === "DELETE")
|
|
@@ -2576,27 +2486,27 @@ class ht {
|
|
|
2576
2486
|
create: !0
|
|
2577
2487
|
});
|
|
2578
2488
|
else if (e.operation === "WRITE")
|
|
2579
|
-
await
|
|
2489
|
+
await O(
|
|
2580
2490
|
r,
|
|
2581
2491
|
n,
|
|
2582
|
-
this.php[
|
|
2492
|
+
this.php[k].FS,
|
|
2583
2493
|
e.path
|
|
2584
2494
|
);
|
|
2585
2495
|
else if (e.operation === "RENAME" && e.toPath.startsWith(this.memfsRoot)) {
|
|
2586
|
-
const
|
|
2496
|
+
const s = this.toOpfsPath(e.toPath), _ = await se(
|
|
2587
2497
|
this.opfs,
|
|
2588
|
-
|
|
2498
|
+
s
|
|
2589
2499
|
);
|
|
2590
2500
|
if (e.nodeType === "directory") {
|
|
2591
|
-
const
|
|
2501
|
+
const a = await _.getDirectoryHandle(
|
|
2592
2502
|
n,
|
|
2593
2503
|
{
|
|
2594
2504
|
create: !0
|
|
2595
2505
|
}
|
|
2596
2506
|
);
|
|
2597
|
-
await
|
|
2598
|
-
this.php[
|
|
2599
|
-
|
|
2507
|
+
await ue(
|
|
2508
|
+
this.php[k].FS,
|
|
2509
|
+
a,
|
|
2600
2510
|
e.toPath
|
|
2601
2511
|
), await r.removeEntry(n, {
|
|
2602
2512
|
recursive: !0
|
|
@@ -2606,61 +2516,61 @@ class ht {
|
|
|
2606
2516
|
await r.removeEntry(n);
|
|
2607
2517
|
} catch {
|
|
2608
2518
|
}
|
|
2609
|
-
await
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
this.php[
|
|
2519
|
+
await O(
|
|
2520
|
+
_,
|
|
2521
|
+
ye(s),
|
|
2522
|
+
this.php[k].FS,
|
|
2613
2523
|
e.toPath
|
|
2614
2524
|
);
|
|
2615
2525
|
}
|
|
2616
2526
|
}
|
|
2617
|
-
} catch (
|
|
2618
|
-
throw
|
|
2527
|
+
} catch (s) {
|
|
2528
|
+
throw U.log({ entry: e, name: n }), U.error(s), s;
|
|
2619
2529
|
}
|
|
2620
2530
|
}
|
|
2621
2531
|
}
|
|
2622
|
-
function
|
|
2623
|
-
return
|
|
2532
|
+
function ne(i) {
|
|
2533
|
+
return i.replace(/\/$/, "").replace(/\/\/+/g, "/");
|
|
2624
2534
|
}
|
|
2625
|
-
function
|
|
2626
|
-
return
|
|
2535
|
+
function at(i) {
|
|
2536
|
+
return i.substring(i.lastIndexOf("/") + 1);
|
|
2627
2537
|
}
|
|
2628
|
-
async function
|
|
2538
|
+
async function se(i, e) {
|
|
2629
2539
|
const t = e.replace(/^\/+|\/+$/g, "").replace(/\/+/, "/");
|
|
2630
2540
|
if (!t)
|
|
2631
|
-
return
|
|
2541
|
+
return i;
|
|
2632
2542
|
const r = t.split("/");
|
|
2633
|
-
let n =
|
|
2634
|
-
for (let
|
|
2635
|
-
const
|
|
2636
|
-
n = await n.getDirectoryHandle(
|
|
2543
|
+
let n = i;
|
|
2544
|
+
for (let s = 0; s < r.length - 1; s++) {
|
|
2545
|
+
const _ = r[s];
|
|
2546
|
+
n = await n.getDirectoryHandle(_, { create: !0 });
|
|
2637
2547
|
}
|
|
2638
2548
|
return n;
|
|
2639
2549
|
}
|
|
2640
|
-
function
|
|
2550
|
+
function ot(i, e) {
|
|
2641
2551
|
let t = 0, r, n;
|
|
2642
|
-
return function(...
|
|
2643
|
-
n =
|
|
2644
|
-
const
|
|
2552
|
+
return function(..._) {
|
|
2553
|
+
n = _;
|
|
2554
|
+
const a = Date.now() - t;
|
|
2645
2555
|
if (r === void 0) {
|
|
2646
|
-
const c = Math.max(0, e -
|
|
2556
|
+
const c = Math.max(0, e - a);
|
|
2647
2557
|
r = setTimeout(() => {
|
|
2648
|
-
r = void 0, t = Date.now(),
|
|
2558
|
+
r = void 0, t = Date.now(), i(...n);
|
|
2649
2559
|
}, c);
|
|
2650
2560
|
}
|
|
2651
2561
|
};
|
|
2652
2562
|
}
|
|
2653
2563
|
export {
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2564
|
+
Ht as certificateToPEM,
|
|
2565
|
+
mt as consumeAPI,
|
|
2566
|
+
wt as createDirectoryHandleMountHandler,
|
|
2567
|
+
gt as exposeAPI,
|
|
2568
|
+
ze as fetchWithCorsProxy,
|
|
2569
|
+
je as generateCertificate,
|
|
2570
|
+
De as getPHPLoaderModule,
|
|
2571
|
+
Et as loadWebRuntime,
|
|
2572
|
+
dt as privateKeyToPEM,
|
|
2573
|
+
ft as setupPostMessageRelay,
|
|
2574
|
+
pt as spawnPHPWorkerThread
|
|
2665
2575
|
};
|
|
2666
2576
|
//# sourceMappingURL=index.js.map
|