@php-wasm/web 1.0.14 → 1.0.16
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.js +362 -323
- package/lib/fetch-with-cors-proxy.d.ts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/tcp-over-fetch-websocket.d.ts +5 -1
- package/package.json +7 -6
package/index.js
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
1
|
import { PHPResponse as we, LatestSupportedPHPVersion as Le, loadPHPRuntime as me, FSHelpers as B, __private__dont__use as k } from "@php-wasm/universal";
|
|
2
2
|
import * as E from "comlink";
|
|
3
3
|
import { jspi as ye } from "wasm-feature-detect";
|
|
4
|
-
import { logger as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
4
|
+
import { logger as R } from "@php-wasm/logger";
|
|
5
|
+
import { cloneRequest as ge } from "@php-wasm/web-service-worker";
|
|
6
|
+
import { Semaphore as Ke, joinPaths as se } from "@php-wasm/util";
|
|
7
|
+
import { journalFSEvents as Ie } from "@php-wasm/fs-journal";
|
|
8
|
+
function ct(n, e = void 0) {
|
|
8
9
|
ie();
|
|
9
|
-
const t =
|
|
10
|
-
return new Proxy(
|
|
10
|
+
const t = n instanceof Worker ? n : E.windowEndpoint(n, e), r = E.wrap(t), s = x(r);
|
|
11
|
+
return new Proxy(s, {
|
|
11
12
|
get: (i, _) => _ === "isConnected" ? async () => {
|
|
12
13
|
for (; ; )
|
|
13
14
|
try {
|
|
14
|
-
await
|
|
15
|
+
await De(r.isConnected(), 200);
|
|
15
16
|
break;
|
|
16
17
|
} catch {
|
|
17
18
|
}
|
|
18
19
|
} : r[_]
|
|
19
20
|
});
|
|
20
21
|
}
|
|
21
|
-
async function
|
|
22
|
+
async function De(n, e) {
|
|
22
23
|
return new Promise((t, r) => {
|
|
23
|
-
setTimeout(r, e),
|
|
24
|
+
setTimeout(r, e), n.then(t);
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
|
-
function
|
|
27
|
+
function St(n, e) {
|
|
27
28
|
ie();
|
|
28
29
|
const t = Promise.resolve();
|
|
29
|
-
let r,
|
|
30
|
+
let r, s;
|
|
30
31
|
const i = new Promise((c, S) => {
|
|
31
|
-
r = c,
|
|
32
|
-
}), _ = x(
|
|
32
|
+
r = c, s = S;
|
|
33
|
+
}), _ = x(n), a = new Proxy(_, {
|
|
33
34
|
get: (c, S) => S === "isConnected" ? () => t : S === "isReady" ? () => i : S in c ? c[S] : e == null ? void 0 : e[S]
|
|
34
35
|
});
|
|
35
36
|
return E.expose(
|
|
36
37
|
a,
|
|
37
38
|
typeof window < "u" ? E.windowEndpoint(self.parent) : void 0
|
|
38
|
-
), [r,
|
|
39
|
+
), [r, s, a];
|
|
39
40
|
}
|
|
40
41
|
let F = !1;
|
|
41
42
|
function ie() {
|
|
@@ -53,8 +54,8 @@ function ie() {
|
|
|
53
54
|
}), E.transferHandlers.set("FUNCTION", {
|
|
54
55
|
canHandle: (t) => typeof t == "function",
|
|
55
56
|
serialize(t) {
|
|
56
|
-
const { port1: r, port2:
|
|
57
|
-
return E.expose(t, r), [
|
|
57
|
+
const { port1: r, port2: s } = new MessageChannel();
|
|
58
|
+
return E.expose(t, r), [s, [s]];
|
|
58
59
|
},
|
|
59
60
|
deserialize(t) {
|
|
60
61
|
return t.start(), E.wrap(t);
|
|
@@ -68,14 +69,14 @@ function ie() {
|
|
|
68
69
|
return we.fromRawData(t);
|
|
69
70
|
}
|
|
70
71
|
});
|
|
71
|
-
const
|
|
72
|
-
|
|
72
|
+
const n = E.transferHandlers.get("throw"), e = n == null ? void 0 : n.serialize;
|
|
73
|
+
n.serialize = ({ value: t }) => {
|
|
73
74
|
const r = e({ value: t });
|
|
74
75
|
return t.response && (r[0].value.response = t.response), t.source && (r[0].value.source = t.source), r;
|
|
75
76
|
};
|
|
76
77
|
}
|
|
77
|
-
function x(
|
|
78
|
-
return new Proxy(
|
|
78
|
+
function x(n) {
|
|
79
|
+
return new Proxy(n, {
|
|
79
80
|
get(e, t) {
|
|
80
81
|
switch (typeof e[t]) {
|
|
81
82
|
case "function":
|
|
@@ -92,9 +93,9 @@ function x(s) {
|
|
|
92
93
|
}
|
|
93
94
|
});
|
|
94
95
|
}
|
|
95
|
-
async function
|
|
96
|
+
async function We(n = Le) {
|
|
96
97
|
if (await ye())
|
|
97
|
-
switch (
|
|
98
|
+
switch (n) {
|
|
98
99
|
case "8.3":
|
|
99
100
|
return await import("./php/jspi/php_8_3.js");
|
|
100
101
|
case "8.2":
|
|
@@ -115,7 +116,7 @@ async function De(s = Le) {
|
|
|
115
116
|
return await import("./php/jspi/php_7_0.js");
|
|
116
117
|
}
|
|
117
118
|
else
|
|
118
|
-
switch (
|
|
119
|
+
switch (n) {
|
|
119
120
|
case "8.3":
|
|
120
121
|
return await import("./php/asyncify/php_8_3.js");
|
|
121
122
|
case "8.2":
|
|
@@ -135,36 +136,36 @@ async function De(s = Le) {
|
|
|
135
136
|
case "7.0":
|
|
136
137
|
return await import("./php/asyncify/php_7_0.js");
|
|
137
138
|
}
|
|
138
|
-
throw new Error(`Unsupported PHP version ${
|
|
139
|
+
throw new Error(`Unsupported PHP version ${n}`);
|
|
139
140
|
}
|
|
140
|
-
function p(
|
|
141
|
-
return Object.fromEntries(Object.entries(
|
|
141
|
+
function p(n) {
|
|
142
|
+
return Object.fromEntries(Object.entries(n).map(([e, t]) => [t, e]));
|
|
142
143
|
}
|
|
143
|
-
function h(
|
|
144
|
+
function h(n) {
|
|
144
145
|
let e = 0;
|
|
145
|
-
|
|
146
|
+
n.forEach((s) => e += s.length);
|
|
146
147
|
const t = new Uint8Array(e);
|
|
147
148
|
let r = 0;
|
|
148
|
-
return
|
|
149
|
-
t.set(
|
|
149
|
+
return n.forEach((s) => {
|
|
150
|
+
t.set(s, r), r += s.length;
|
|
150
151
|
}), t;
|
|
151
152
|
}
|
|
152
|
-
function P(
|
|
153
|
-
return h(
|
|
153
|
+
function P(n) {
|
|
154
|
+
return h(n.map((e) => new Uint8Array(e))).buffer;
|
|
154
155
|
}
|
|
155
|
-
function I(
|
|
156
|
-
return new Uint8Array([
|
|
156
|
+
function I(n) {
|
|
157
|
+
return new Uint8Array([n >> 8 & 255, n & 255]);
|
|
157
158
|
}
|
|
158
|
-
function m(
|
|
159
|
+
function m(n) {
|
|
159
160
|
return new Uint8Array([
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
n >> 16 & 255,
|
|
162
|
+
n >> 8 & 255,
|
|
163
|
+
n & 255
|
|
163
164
|
]);
|
|
164
165
|
}
|
|
165
|
-
function G(
|
|
166
|
+
function G(n) {
|
|
166
167
|
const e = new ArrayBuffer(8);
|
|
167
|
-
return new DataView(e).setBigUint64(0, BigInt(
|
|
168
|
+
return new DataView(e).setBigUint64(0, BigInt(n), !1), new Uint8Array(e);
|
|
168
169
|
}
|
|
169
170
|
class g {
|
|
170
171
|
constructor(e) {
|
|
@@ -207,7 +208,7 @@ class v {
|
|
|
207
208
|
this.uint8Array.set(e, this.offset), this.offset += e.length;
|
|
208
209
|
}
|
|
209
210
|
}
|
|
210
|
-
const
|
|
211
|
+
const b = {
|
|
211
212
|
server_name: 0,
|
|
212
213
|
max_fragment_length: 1,
|
|
213
214
|
client_certificate_url: 2,
|
|
@@ -261,17 +262,17 @@ const R = {
|
|
|
261
262
|
key_share: 51,
|
|
262
263
|
transparency_info: 52,
|
|
263
264
|
connection_id: 54
|
|
264
|
-
},
|
|
265
|
+
}, Re = p(b), _e = {
|
|
265
266
|
host_name: 0
|
|
266
267
|
}, be = p(_e);
|
|
267
268
|
class ae {
|
|
268
269
|
static decodeFromClient(e) {
|
|
269
270
|
const t = new DataView(e.buffer);
|
|
270
271
|
let r = 0;
|
|
271
|
-
const
|
|
272
|
+
const s = t.getUint16(r);
|
|
272
273
|
r += 2;
|
|
273
274
|
const i = [];
|
|
274
|
-
for (; r <
|
|
275
|
+
for (; r < s + 2; ) {
|
|
275
276
|
const _ = e[r];
|
|
276
277
|
r += 1;
|
|
277
278
|
const a = t.getUint16(r);
|
|
@@ -309,7 +310,7 @@ class ae {
|
|
|
309
310
|
"Encoding non-empty lists for ClientHello is not supported yet. Only empty lists meant for ServerHello are supported today."
|
|
310
311
|
);
|
|
311
312
|
const t = new v(4);
|
|
312
|
-
return t.writeUint16(
|
|
313
|
+
return t.writeUint16(b.server_name), t.writeUint16(0), t.uint8Array;
|
|
313
314
|
}
|
|
314
315
|
}
|
|
315
316
|
const oe = {
|
|
@@ -543,8 +544,8 @@ class Se {
|
|
|
543
544
|
t.readUint16();
|
|
544
545
|
const r = [];
|
|
545
546
|
for (; !t.isFinished(); ) {
|
|
546
|
-
const
|
|
547
|
-
|
|
547
|
+
const s = t.readUint16();
|
|
548
|
+
s in $ && r.push($[s]);
|
|
548
549
|
}
|
|
549
550
|
return r;
|
|
550
551
|
}
|
|
@@ -560,7 +561,7 @@ class Se {
|
|
|
560
561
|
*/
|
|
561
562
|
static encodeForClient(e) {
|
|
562
563
|
const t = new v(6);
|
|
563
|
-
return t.writeUint16(
|
|
564
|
+
return t.writeUint16(b.supported_groups), t.writeUint16(2), t.writeUint16(ce[e]), t.uint8Array;
|
|
564
565
|
}
|
|
565
566
|
}
|
|
566
567
|
const Ce = {
|
|
@@ -585,12 +586,12 @@ class le {
|
|
|
585
586
|
* +--------------------------------------------------+
|
|
586
587
|
*/
|
|
587
588
|
static decodeFromClient(e) {
|
|
588
|
-
const t = new g(e.buffer), r = t.readUint8(),
|
|
589
|
+
const t = new g(e.buffer), r = t.readUint8(), s = [];
|
|
589
590
|
for (let i = 0; i < r; i++) {
|
|
590
591
|
const _ = t.readUint8();
|
|
591
|
-
_ in V &&
|
|
592
|
+
_ in V && s.push(V[_]);
|
|
592
593
|
}
|
|
593
|
-
return
|
|
594
|
+
return s;
|
|
594
595
|
}
|
|
595
596
|
/**
|
|
596
597
|
* Encode the ec_point_formats extension
|
|
@@ -608,7 +609,7 @@ class le {
|
|
|
608
609
|
*/
|
|
609
610
|
static encodeForClient(e) {
|
|
610
611
|
const t = new v(6);
|
|
611
|
-
return t.writeUint16(
|
|
612
|
+
return t.writeUint16(b.ec_point_formats), t.writeUint16(2), t.writeUint8(1), t.writeUint8(Ce[e]), t.uint8Array;
|
|
612
613
|
}
|
|
613
614
|
}
|
|
614
615
|
const N = {
|
|
@@ -646,18 +647,18 @@ class Ae {
|
|
|
646
647
|
t.readUint16();
|
|
647
648
|
const r = [];
|
|
648
649
|
for (; !t.isFinished(); ) {
|
|
649
|
-
const
|
|
650
|
+
const s = t.readUint8(), i = t.readUint8();
|
|
650
651
|
if (!z[i]) {
|
|
651
|
-
|
|
652
|
+
R.warn(`Unknown signature algorithm: ${i}`);
|
|
652
653
|
continue;
|
|
653
654
|
}
|
|
654
|
-
if (!Y[
|
|
655
|
-
|
|
655
|
+
if (!Y[s]) {
|
|
656
|
+
R.warn(`Unknown hash algorithm: ${s}`);
|
|
656
657
|
continue;
|
|
657
658
|
}
|
|
658
659
|
r.push({
|
|
659
660
|
algorithm: z[i],
|
|
660
|
-
hash: Y[
|
|
661
|
+
hash: Y[s]
|
|
661
662
|
});
|
|
662
663
|
}
|
|
663
664
|
return r;
|
|
@@ -675,7 +676,7 @@ class Ae {
|
|
|
675
676
|
*/
|
|
676
677
|
static encodeforClient(e, t) {
|
|
677
678
|
const r = new v(6);
|
|
678
|
-
return r.writeUint16(
|
|
679
|
+
return r.writeUint16(b.signature_algorithms), r.writeUint16(2), r.writeUint8(O[e]), r.writeUint8(N[t]), r.uint8Array;
|
|
679
680
|
}
|
|
680
681
|
}
|
|
681
682
|
const J = {
|
|
@@ -684,50 +685,50 @@ const J = {
|
|
|
684
685
|
supported_groups: Se,
|
|
685
686
|
ec_point_formats: le
|
|
686
687
|
};
|
|
687
|
-
function
|
|
688
|
-
const e = new g(
|
|
688
|
+
function Pe(n) {
|
|
689
|
+
const e = new g(n.buffer), t = [];
|
|
689
690
|
for (; !e.isFinished(); ) {
|
|
690
|
-
const r = e.offset,
|
|
691
|
+
const r = e.offset, s = e.readUint16(), i = Re[s], _ = e.readUint16(), a = e.readUint8Array(_);
|
|
691
692
|
if (!(i in J))
|
|
692
693
|
continue;
|
|
693
694
|
const c = J[i];
|
|
694
695
|
t.push({
|
|
695
696
|
type: i,
|
|
696
697
|
data: c.decodeFromClient(a),
|
|
697
|
-
raw:
|
|
698
|
+
raw: n.slice(r, r + 4 + _)
|
|
698
699
|
});
|
|
699
700
|
}
|
|
700
701
|
return t;
|
|
701
702
|
}
|
|
702
|
-
async function M(
|
|
703
|
-
const
|
|
703
|
+
async function M(n, e, t, r) {
|
|
704
|
+
const s = P([e, t]), i = await crypto.subtle.importKey(
|
|
704
705
|
"raw",
|
|
705
|
-
|
|
706
|
+
n,
|
|
706
707
|
{ name: "HMAC", hash: { name: "SHA-256" } },
|
|
707
708
|
!1,
|
|
708
709
|
["sign"]
|
|
709
710
|
);
|
|
710
|
-
let _ =
|
|
711
|
+
let _ = s;
|
|
711
712
|
const a = [];
|
|
712
713
|
for (; P(a).byteLength < r; ) {
|
|
713
714
|
_ = await X(i, _);
|
|
714
|
-
const S = P([_,
|
|
715
|
+
const S = P([_, s]), l = await X(i, S);
|
|
715
716
|
a.push(l);
|
|
716
717
|
}
|
|
717
718
|
return P(a).slice(0, r);
|
|
718
719
|
}
|
|
719
|
-
async function X(
|
|
720
|
+
async function X(n, e) {
|
|
720
721
|
return await crypto.subtle.sign(
|
|
721
722
|
{ name: "HMAC", hash: "SHA-256" },
|
|
722
|
-
|
|
723
|
+
n,
|
|
723
724
|
e
|
|
724
725
|
);
|
|
725
726
|
}
|
|
726
|
-
var ue = /* @__PURE__ */ ((
|
|
727
|
-
const
|
|
727
|
+
var ue = /* @__PURE__ */ ((n) => (n[n.Null = 0] = "Null", n[n.Deflate = 1] = "Deflate", n))(ue || {});
|
|
728
|
+
const Be = {
|
|
728
729
|
Warning: 1,
|
|
729
730
|
Fatal: 2
|
|
730
|
-
}, he = p(
|
|
731
|
+
}, he = p(Be), Ue = {
|
|
731
732
|
CloseNotify: 0,
|
|
732
733
|
UnexpectedMessage: 10,
|
|
733
734
|
BadRecordMac: 20,
|
|
@@ -753,14 +754,14 @@ const Pe = {
|
|
|
753
754
|
UserCanceled: 90,
|
|
754
755
|
NoRenegotiation: 100,
|
|
755
756
|
UnsupportedExtension: 110
|
|
756
|
-
}, He = p(
|
|
757
|
+
}, He = p(Ue), C = {
|
|
757
758
|
ChangeCipherSpec: 20,
|
|
758
759
|
Alert: 21,
|
|
759
760
|
Handshake: 22,
|
|
760
761
|
ApplicationData: 23
|
|
761
762
|
};
|
|
762
|
-
var d = /* @__PURE__ */ ((
|
|
763
|
-
const
|
|
763
|
+
var d = /* @__PURE__ */ ((n) => (n[n.HelloRequest = 0] = "HelloRequest", n[n.ClientHello = 1] = "ClientHello", n[n.ServerHello = 2] = "ServerHello", n[n.Certificate = 11] = "Certificate", n[n.ServerKeyExchange = 12] = "ServerKeyExchange", n[n.CertificateRequest = 13] = "CertificateRequest", n[n.ServerHelloDone = 14] = "ServerHelloDone", n[n.CertificateVerify = 15] = "CertificateVerify", n[n.ClientKeyExchange = 16] = "ClientKeyExchange", n[n.Finished = 20] = "Finished", n))(d || {});
|
|
764
|
+
const ve = {
|
|
764
765
|
/**
|
|
765
766
|
* Indicates the elliptic curve domain parameters are
|
|
766
767
|
* conveyed verbosely, and the underlying finite field is a prime
|
|
@@ -781,7 +782,7 @@ const Ue = {
|
|
|
781
782
|
/**
|
|
782
783
|
* Values 248 through 255 are reserved for private use.
|
|
783
784
|
*/
|
|
784
|
-
},
|
|
785
|
+
}, Me = {
|
|
785
786
|
sect163k1: 1,
|
|
786
787
|
sect163r1: 2,
|
|
787
788
|
sect163r2: 3,
|
|
@@ -803,7 +804,7 @@ const Ue = {
|
|
|
803
804
|
};
|
|
804
805
|
class Z extends Error {
|
|
805
806
|
}
|
|
806
|
-
const U = new Uint8Array([3, 3]),
|
|
807
|
+
const U = new Uint8Array([3, 3]), xe = crypto.subtle.generateKey(
|
|
807
808
|
{
|
|
808
809
|
name: "ECDH",
|
|
809
810
|
namedCurve: "P-256"
|
|
@@ -814,7 +815,7 @@ const U = new Uint8Array([3, 3]), Me = crypto.subtle.generateKey(
|
|
|
814
815
|
["deriveKey", "deriveBits"]
|
|
815
816
|
// Key usage
|
|
816
817
|
);
|
|
817
|
-
class
|
|
818
|
+
class Ne {
|
|
818
819
|
constructor() {
|
|
819
820
|
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 = {
|
|
820
821
|
// We don't need to chunk the encrypted data.
|
|
@@ -831,7 +832,7 @@ class xe {
|
|
|
831
832
|
* This will spread some messages across multiple records,
|
|
832
833
|
* but TLS supports it so that's fine.
|
|
833
834
|
*/
|
|
834
|
-
downstream:
|
|
835
|
+
downstream: Oe(this.MAX_CHUNK_SIZE)
|
|
835
836
|
}, this.serverUpstreamWriter = this.serverEnd.upstream.writable.getWriter();
|
|
836
837
|
const e = this;
|
|
837
838
|
this.serverEnd.downstream.readable.pipeTo(
|
|
@@ -894,21 +895,21 @@ class xe {
|
|
|
894
895
|
throw new Error(
|
|
895
896
|
"Client did not propose any supported cipher suites."
|
|
896
897
|
);
|
|
897
|
-
const
|
|
898
|
+
const s = crypto.getRandomValues(new Uint8Array(32));
|
|
898
899
|
await this.writeTLSRecord(
|
|
899
900
|
C.Handshake,
|
|
900
901
|
K.serverHello(
|
|
901
902
|
r.body,
|
|
902
|
-
|
|
903
|
+
s,
|
|
903
904
|
ue.Null
|
|
904
905
|
)
|
|
905
906
|
), await this.writeTLSRecord(
|
|
906
907
|
C.Handshake,
|
|
907
908
|
K.certificate(t)
|
|
908
909
|
);
|
|
909
|
-
const i = await
|
|
910
|
+
const i = await xe, _ = r.body.random, a = await K.ECDHEServerKeyExchange(
|
|
910
911
|
_,
|
|
911
|
-
|
|
912
|
+
s,
|
|
912
913
|
i,
|
|
913
914
|
e
|
|
914
915
|
);
|
|
@@ -921,7 +922,7 @@ class xe {
|
|
|
921
922
|
);
|
|
922
923
|
await this.readNextMessage(C.ChangeCipherSpec), this.sessionKeys = await this.deriveSessionKeys({
|
|
923
924
|
clientRandom: _,
|
|
924
|
-
serverRandom:
|
|
925
|
+
serverRandom: s,
|
|
925
926
|
serverPrivateKey: i.privateKey,
|
|
926
927
|
clientPublicKey: await crypto.subtle.importKey(
|
|
927
928
|
"raw",
|
|
@@ -949,12 +950,12 @@ class xe {
|
|
|
949
950
|
clientRandom: e,
|
|
950
951
|
serverRandom: t,
|
|
951
952
|
serverPrivateKey: r,
|
|
952
|
-
clientPublicKey:
|
|
953
|
+
clientPublicKey: s
|
|
953
954
|
}) {
|
|
954
955
|
const i = await crypto.subtle.deriveBits(
|
|
955
956
|
{
|
|
956
957
|
name: "ECDH",
|
|
957
|
-
public:
|
|
958
|
+
public: s
|
|
958
959
|
},
|
|
959
960
|
r,
|
|
960
961
|
256
|
|
@@ -1006,36 +1007,35 @@ class xe {
|
|
|
1006
1007
|
t
|
|
1007
1008
|
);
|
|
1008
1009
|
while (r === !1);
|
|
1009
|
-
const
|
|
1010
|
+
const s = f.TLSMessage(
|
|
1010
1011
|
t.type,
|
|
1011
1012
|
r
|
|
1012
1013
|
);
|
|
1013
|
-
return t.type === C.Handshake && this.handshakeMessages.push(t.fragment),
|
|
1014
|
+
return t.type === C.Handshake && this.handshakeMessages.push(t.fragment), s;
|
|
1014
1015
|
}
|
|
1015
1016
|
async readNextTLSRecord(e) {
|
|
1016
1017
|
for (; ; ) {
|
|
1017
|
-
for (let
|
|
1018
|
-
const
|
|
1019
|
-
if (
|
|
1020
|
-
|
|
1021
|
-
`Alert message received: ${he[_.fragment[0]]} ${He[_.fragment[1]]}`
|
|
1022
|
-
);
|
|
1023
|
-
if (_.type === e)
|
|
1024
|
-
return this.receivedTLSRecords.splice(i, 1), this.sessionKeys && _.type !== C.ChangeCipherSpec && (_.fragment = await this.decryptData(
|
|
1025
|
-
_.type,
|
|
1026
|
-
_.fragment
|
|
1027
|
-
)), _;
|
|
1018
|
+
for (let a = 0; a < this.receivedTLSRecords.length; a++) {
|
|
1019
|
+
const c = this.receivedTLSRecords[a];
|
|
1020
|
+
if (c.type === e)
|
|
1021
|
+
return this.receivedTLSRecords.splice(a, 1), c;
|
|
1028
1022
|
}
|
|
1029
|
-
const t = await this.pollBytes(5), r = t[3] << 8 | t[4],
|
|
1030
|
-
type:
|
|
1023
|
+
const t = await this.pollBytes(5), r = t[3] << 8 | t[4], s = t[0], i = await this.pollBytes(r), _ = {
|
|
1024
|
+
type: s,
|
|
1031
1025
|
version: {
|
|
1032
1026
|
major: t[1],
|
|
1033
1027
|
minor: t[2]
|
|
1034
1028
|
},
|
|
1035
1029
|
length: r,
|
|
1036
|
-
fragment: await this.
|
|
1030
|
+
fragment: this.sessionKeys && s !== C.ChangeCipherSpec ? await this.decryptData(s, i) : i
|
|
1037
1031
|
};
|
|
1038
|
-
|
|
1032
|
+
if (_.type === C.Alert) {
|
|
1033
|
+
const a = he[_.fragment[0]], c = He[_.fragment[1]];
|
|
1034
|
+
throw new Error(
|
|
1035
|
+
`TLS non-warning alert received: ${a} ${c}`
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
this.receivedTLSRecords.push(_);
|
|
1039
1039
|
}
|
|
1040
1040
|
}
|
|
1041
1041
|
/**
|
|
@@ -1044,8 +1044,8 @@ class xe {
|
|
|
1044
1044
|
*/
|
|
1045
1045
|
async pollBytes(e) {
|
|
1046
1046
|
for (; this.receivedBytesBuffer.length < e; ) {
|
|
1047
|
-
const { value: r, done:
|
|
1048
|
-
if (
|
|
1047
|
+
const { value: r, done: s } = await this.clientUpstreamReader.read();
|
|
1048
|
+
if (s)
|
|
1049
1049
|
throw await this.close(), new Z("TLS connection closed");
|
|
1050
1050
|
if (this.receivedBytesBuffer = h([
|
|
1051
1051
|
this.receivedBytesBuffer,
|
|
@@ -1080,7 +1080,7 @@ class xe {
|
|
|
1080
1080
|
* the AES-GCM algorithm.
|
|
1081
1081
|
*/
|
|
1082
1082
|
async decryptData(e, t) {
|
|
1083
|
-
const r = this.sessionKeys.clientIV,
|
|
1083
|
+
const r = this.sessionKeys.clientIV, s = t.slice(0, 8), i = new Uint8Array([...r, ...s]), _ = await crypto.subtle.decrypt(
|
|
1084
1084
|
{
|
|
1085
1085
|
name: "AES-GCM",
|
|
1086
1086
|
iv: i,
|
|
@@ -1136,8 +1136,8 @@ class xe {
|
|
|
1136
1136
|
*/
|
|
1137
1137
|
async writeTLSRecord(e, t) {
|
|
1138
1138
|
e === C.Handshake && this.handshakeMessages.push(t), this.sessionKeys && e !== C.ChangeCipherSpec && (t = await this.encryptData(e, t));
|
|
1139
|
-
const r = U,
|
|
1140
|
-
i[0] = e, i[1] = r[0], i[2] = r[1], i[3] =
|
|
1139
|
+
const r = U, s = t.length, i = new Uint8Array(5);
|
|
1140
|
+
i[0] = e, i[1] = r[0], i[2] = r[1], i[3] = s >> 8 & 255, i[4] = s & 255;
|
|
1141
1141
|
const _ = h([i, t]);
|
|
1142
1142
|
this.clientDownstreamWriter.write(_);
|
|
1143
1143
|
}
|
|
@@ -1146,7 +1146,7 @@ class xe {
|
|
|
1146
1146
|
* the AES-GCM algorithm.
|
|
1147
1147
|
*/
|
|
1148
1148
|
async encryptData(e, t) {
|
|
1149
|
-
const r = this.sessionKeys.serverIV,
|
|
1149
|
+
const r = this.sessionKeys.serverIV, s = crypto.getRandomValues(new Uint8Array(8)), i = new Uint8Array([...r, ...s]), _ = new Uint8Array([
|
|
1150
1150
|
...G(this.sentRecordSequenceNumber),
|
|
1151
1151
|
e,
|
|
1152
1152
|
...U,
|
|
@@ -1163,7 +1163,7 @@ class xe {
|
|
|
1163
1163
|
t
|
|
1164
1164
|
);
|
|
1165
1165
|
return ++this.sentRecordSequenceNumber, h([
|
|
1166
|
-
|
|
1166
|
+
s,
|
|
1167
1167
|
new Uint8Array(a)
|
|
1168
1168
|
]);
|
|
1169
1169
|
}
|
|
@@ -1211,8 +1211,8 @@ class f {
|
|
|
1211
1211
|
t.readUint16();
|
|
1212
1212
|
const r = [];
|
|
1213
1213
|
for (; !t.isFinished(); ) {
|
|
1214
|
-
const
|
|
1215
|
-
|
|
1214
|
+
const s = t.readUint16();
|
|
1215
|
+
s in j && r.push(j[s]);
|
|
1216
1216
|
}
|
|
1217
1217
|
return r;
|
|
1218
1218
|
}
|
|
@@ -1236,20 +1236,20 @@ class f {
|
|
|
1236
1236
|
};
|
|
1237
1237
|
}
|
|
1238
1238
|
static clientHandshake(e) {
|
|
1239
|
-
const t = e[0], r = e[1] << 16 | e[2] << 8 | e[3],
|
|
1239
|
+
const t = e[0], r = e[1] << 16 | e[2] << 8 | e[3], s = e.slice(4);
|
|
1240
1240
|
let i;
|
|
1241
1241
|
switch (t) {
|
|
1242
1242
|
case d.HelloRequest:
|
|
1243
1243
|
i = f.clientHelloRequestPayload();
|
|
1244
1244
|
break;
|
|
1245
1245
|
case d.ClientHello:
|
|
1246
|
-
i = f.clientHelloPayload(
|
|
1246
|
+
i = f.clientHelloPayload(s);
|
|
1247
1247
|
break;
|
|
1248
1248
|
case d.ClientKeyExchange:
|
|
1249
|
-
i = f.clientKeyExchangePayload(
|
|
1249
|
+
i = f.clientKeyExchangePayload(s);
|
|
1250
1250
|
break;
|
|
1251
1251
|
case d.Finished:
|
|
1252
|
-
i = f.clientFinishedPayload(
|
|
1252
|
+
i = f.clientFinishedPayload(s);
|
|
1253
1253
|
break;
|
|
1254
1254
|
default:
|
|
1255
1255
|
throw new Error(`Invalid handshake type ${t}`);
|
|
@@ -1313,8 +1313,8 @@ class f {
|
|
|
1313
1313
|
* parse this further.
|
|
1314
1314
|
*/
|
|
1315
1315
|
random: t.readUint8Array(32)
|
|
1316
|
-
},
|
|
1317
|
-
r.session_id = t.readUint8Array(
|
|
1316
|
+
}, s = t.readUint8();
|
|
1317
|
+
r.session_id = t.readUint8Array(s);
|
|
1318
1318
|
const i = t.readUint16();
|
|
1319
1319
|
r.cipher_suites = f.parseCipherSuites(
|
|
1320
1320
|
t.readUint8Array(i).buffer
|
|
@@ -1324,7 +1324,7 @@ class f {
|
|
|
1324
1324
|
_
|
|
1325
1325
|
);
|
|
1326
1326
|
const a = t.readUint16();
|
|
1327
|
-
return r.extensions =
|
|
1327
|
+
return r.extensions = Pe(
|
|
1328
1328
|
t.readUint8Array(a)
|
|
1329
1329
|
), r;
|
|
1330
1330
|
}
|
|
@@ -1349,11 +1349,11 @@ class f {
|
|
|
1349
1349
|
};
|
|
1350
1350
|
}
|
|
1351
1351
|
}
|
|
1352
|
-
function
|
|
1352
|
+
function Oe(n) {
|
|
1353
1353
|
return new TransformStream({
|
|
1354
1354
|
transform(e, t) {
|
|
1355
1355
|
for (; e.length > 0; )
|
|
1356
|
-
t.enqueue(e.slice(0,
|
|
1356
|
+
t.enqueue(e.slice(0, n)), e = e.slice(n);
|
|
1357
1357
|
}
|
|
1358
1358
|
});
|
|
1359
1359
|
}
|
|
@@ -1362,14 +1362,14 @@ class K {
|
|
|
1362
1362
|
const t = [];
|
|
1363
1363
|
for (const i of e)
|
|
1364
1364
|
t.push(m(i.byteLength)), t.push(new Uint8Array(i));
|
|
1365
|
-
const r = h(t),
|
|
1365
|
+
const r = h(t), s = new Uint8Array([
|
|
1366
1366
|
...m(r.byteLength),
|
|
1367
1367
|
...r
|
|
1368
1368
|
]);
|
|
1369
1369
|
return new Uint8Array([
|
|
1370
1370
|
d.Certificate,
|
|
1371
|
-
...m(
|
|
1372
|
-
...
|
|
1371
|
+
...m(s.length),
|
|
1372
|
+
...s
|
|
1373
1373
|
]);
|
|
1374
1374
|
}
|
|
1375
1375
|
/*
|
|
@@ -1405,14 +1405,14 @@ class K {
|
|
|
1405
1405
|
* @param rsaPrivateKey - RSA private key for signing
|
|
1406
1406
|
* @returns
|
|
1407
1407
|
*/
|
|
1408
|
-
static async ECDHEServerKeyExchange(e, t, r,
|
|
1408
|
+
static async ECDHEServerKeyExchange(e, t, r, s) {
|
|
1409
1409
|
const i = new Uint8Array(
|
|
1410
1410
|
await crypto.subtle.exportKey("raw", r.publicKey)
|
|
1411
1411
|
), _ = new Uint8Array([
|
|
1412
1412
|
// Curve type (1 byte)
|
|
1413
|
-
|
|
1413
|
+
ve.NamedCurve,
|
|
1414
1414
|
// Curve name (2 bytes)
|
|
1415
|
-
...I(
|
|
1415
|
+
...I(Me.secp256r1),
|
|
1416
1416
|
// Public key length (1 byte)
|
|
1417
1417
|
i.byteLength,
|
|
1418
1418
|
// Public key (65 bytes, uncompressed format)
|
|
@@ -1422,7 +1422,7 @@ class K {
|
|
|
1422
1422
|
name: "RSASSA-PKCS1-v1_5",
|
|
1423
1423
|
hash: "SHA-256"
|
|
1424
1424
|
},
|
|
1425
|
-
|
|
1425
|
+
s,
|
|
1426
1426
|
new Uint8Array([...e, ...t, ..._])
|
|
1427
1427
|
), c = new Uint8Array(a), S = new Uint8Array([
|
|
1428
1428
|
O.sha256,
|
|
@@ -1478,7 +1478,7 @@ class K {
|
|
|
1478
1478
|
* +------------------------------------+
|
|
1479
1479
|
*/
|
|
1480
1480
|
static serverHello(e, t, r) {
|
|
1481
|
-
const
|
|
1481
|
+
const s = e.extensions.map((a) => {
|
|
1482
1482
|
switch (a.type) {
|
|
1483
1483
|
case "server_name":
|
|
1484
1484
|
return ae.encodeForClient();
|
|
@@ -1496,7 +1496,7 @@ class K {
|
|
|
1496
1496
|
"rsa"
|
|
1497
1497
|
);
|
|
1498
1498
|
}
|
|
1499
|
-
}).filter((a) => a !== void 0), i = h(
|
|
1499
|
+
}).filter((a) => a !== void 0), i = h(s), _ = new Uint8Array([
|
|
1500
1500
|
// Version field – 0x03, 0x03 means TLS 1.2
|
|
1501
1501
|
...U,
|
|
1502
1502
|
...t,
|
|
@@ -1539,7 +1539,7 @@ class K {
|
|
|
1539
1539
|
const r = await crypto.subtle.digest(
|
|
1540
1540
|
"SHA-256",
|
|
1541
1541
|
h(e)
|
|
1542
|
-
),
|
|
1542
|
+
), s = new Uint8Array(
|
|
1543
1543
|
await M(
|
|
1544
1544
|
t,
|
|
1545
1545
|
new TextEncoder().encode("server finished"),
|
|
@@ -1550,33 +1550,33 @@ class K {
|
|
|
1550
1550
|
);
|
|
1551
1551
|
return new Uint8Array([
|
|
1552
1552
|
d.Finished,
|
|
1553
|
-
...m(
|
|
1554
|
-
...
|
|
1553
|
+
...m(s.length),
|
|
1554
|
+
...s
|
|
1555
1555
|
]);
|
|
1556
1556
|
}
|
|
1557
1557
|
static changeCipherSpec() {
|
|
1558
1558
|
return new Uint8Array([1]);
|
|
1559
1559
|
}
|
|
1560
1560
|
}
|
|
1561
|
-
function
|
|
1562
|
-
return
|
|
1561
|
+
function qe(n, e) {
|
|
1562
|
+
return ke.generateCertificate(n, e);
|
|
1563
1563
|
}
|
|
1564
|
-
function
|
|
1564
|
+
function Ct(n) {
|
|
1565
1565
|
return `-----BEGIN CERTIFICATE-----
|
|
1566
1566
|
${fe(
|
|
1567
|
-
de(
|
|
1567
|
+
de(n.buffer)
|
|
1568
1568
|
)}
|
|
1569
1569
|
-----END CERTIFICATE-----`;
|
|
1570
1570
|
}
|
|
1571
|
-
async function
|
|
1572
|
-
const e = await crypto.subtle.exportKey("pkcs8",
|
|
1571
|
+
async function lt(n) {
|
|
1572
|
+
const e = await crypto.subtle.exportKey("pkcs8", n);
|
|
1573
1573
|
return `-----BEGIN PRIVATE KEY-----
|
|
1574
1574
|
${fe(
|
|
1575
1575
|
de(e)
|
|
1576
1576
|
)}
|
|
1577
1577
|
-----END PRIVATE KEY-----`;
|
|
1578
1578
|
}
|
|
1579
|
-
class
|
|
1579
|
+
class ke {
|
|
1580
1580
|
static async generateCertificate(e, t) {
|
|
1581
1581
|
const r = await crypto.subtle.generateKey(
|
|
1582
1582
|
{
|
|
@@ -1588,17 +1588,17 @@ class qe {
|
|
|
1588
1588
|
!0,
|
|
1589
1589
|
// extractable
|
|
1590
1590
|
["sign", "verify"]
|
|
1591
|
-
),
|
|
1591
|
+
), s = await this.signingRequest(
|
|
1592
1592
|
e,
|
|
1593
1593
|
r.publicKey
|
|
1594
1594
|
), i = await this.sign(
|
|
1595
|
-
|
|
1595
|
+
s,
|
|
1596
1596
|
(t == null ? void 0 : t.privateKey) ?? r.privateKey
|
|
1597
1597
|
);
|
|
1598
1598
|
return {
|
|
1599
1599
|
keyPair: r,
|
|
1600
1600
|
certificate: i,
|
|
1601
|
-
tbsCertificate:
|
|
1601
|
+
tbsCertificate: s,
|
|
1602
1602
|
tbsDescription: e
|
|
1603
1603
|
};
|
|
1604
1604
|
}
|
|
@@ -1655,16 +1655,16 @@ class qe {
|
|
|
1655
1655
|
}
|
|
1656
1656
|
static distinguishedName(e) {
|
|
1657
1657
|
const t = [];
|
|
1658
|
-
for (const [r,
|
|
1658
|
+
for (const [r, s] of Object.entries(e)) {
|
|
1659
1659
|
const i = [
|
|
1660
1660
|
o.objectIdentifier(w(r))
|
|
1661
1661
|
];
|
|
1662
1662
|
switch (r) {
|
|
1663
1663
|
case "countryName":
|
|
1664
|
-
i.push(o.printableString(
|
|
1664
|
+
i.push(o.printableString(s));
|
|
1665
1665
|
break;
|
|
1666
1666
|
default:
|
|
1667
|
-
i.push(o.utf8String(
|
|
1667
|
+
i.push(o.utf8String(s));
|
|
1668
1668
|
}
|
|
1669
1669
|
t.push(o.set([o.sequence(i)]));
|
|
1670
1670
|
}
|
|
@@ -1682,7 +1682,7 @@ class qe {
|
|
|
1682
1682
|
H.UTCTime,
|
|
1683
1683
|
new TextEncoder().encode(
|
|
1684
1684
|
ee(
|
|
1685
|
-
(e == null ? void 0 : e.notAfter) ??
|
|
1685
|
+
(e == null ? void 0 : e.notAfter) ?? Ge(/* @__PURE__ */ new Date(), 10)
|
|
1686
1686
|
)
|
|
1687
1687
|
)
|
|
1688
1688
|
)
|
|
@@ -1738,17 +1738,17 @@ class qe {
|
|
|
1738
1738
|
})) || [], r = ((_ = e.ipAddresses) == null ? void 0 : _.map((a) => {
|
|
1739
1739
|
const c = o.ia5String(a);
|
|
1740
1740
|
return o.contextSpecific(7, c);
|
|
1741
|
-
})) || [],
|
|
1741
|
+
})) || [], s = o.octetString(
|
|
1742
1742
|
o.sequence([...t, ...r])
|
|
1743
1743
|
);
|
|
1744
1744
|
return o.sequence([
|
|
1745
1745
|
o.objectIdentifier(w("subjectAltName")),
|
|
1746
1746
|
o.boolean(!0),
|
|
1747
|
-
|
|
1747
|
+
s
|
|
1748
1748
|
]);
|
|
1749
1749
|
}
|
|
1750
1750
|
}
|
|
1751
|
-
const
|
|
1751
|
+
const Fe = {
|
|
1752
1752
|
// Algorithm OIDs
|
|
1753
1753
|
"1.2.840.113549.1.1.1": "rsaEncryption",
|
|
1754
1754
|
"1.2.840.113549.1.1.4": "md5WithRSAEncryption",
|
|
@@ -1858,11 +1858,11 @@ const ke = {
|
|
|
1858
1858
|
"1.3.6.1.5.5.7.3.4": "emailProtection",
|
|
1859
1859
|
"1.3.6.1.5.5.7.3.8": "timeStamping"
|
|
1860
1860
|
};
|
|
1861
|
-
function w(
|
|
1862
|
-
for (const [e, t] of Object.entries(
|
|
1863
|
-
if (t ===
|
|
1861
|
+
function w(n) {
|
|
1862
|
+
for (const [e, t] of Object.entries(Fe))
|
|
1863
|
+
if (t === n)
|
|
1864
1864
|
return e;
|
|
1865
|
-
throw new Error(`OID not found for name: ${
|
|
1865
|
+
throw new Error(`OID not found for name: ${n}`);
|
|
1866
1866
|
}
|
|
1867
1867
|
const Q = 32, H = {
|
|
1868
1868
|
EOC: 0,
|
|
@@ -1908,16 +1908,16 @@ class o {
|
|
|
1908
1908
|
const r = [];
|
|
1909
1909
|
for (; t > 0; )
|
|
1910
1910
|
r.unshift(t & 255), t >>= 8;
|
|
1911
|
-
const
|
|
1912
|
-
i[0] = 128 |
|
|
1913
|
-
for (let _ = 0; _ <
|
|
1911
|
+
const s = r.length, i = new Uint8Array(1 + s);
|
|
1912
|
+
i[0] = 128 | s;
|
|
1913
|
+
for (let _ = 0; _ < s; _++)
|
|
1914
1914
|
i[_ + 1] = r[_];
|
|
1915
1915
|
return i;
|
|
1916
1916
|
}
|
|
1917
1917
|
}
|
|
1918
1918
|
static ASN1(e, t) {
|
|
1919
|
-
const r = o.length_(t.length),
|
|
1920
|
-
return
|
|
1919
|
+
const r = o.length_(t.length), s = new Uint8Array(1 + r.length + t.length);
|
|
1920
|
+
return s[0] = e, s.set(r, 1), s.set(t, 1 + r.length), s;
|
|
1921
1921
|
}
|
|
1922
1922
|
static integer(e) {
|
|
1923
1923
|
if (e[0] > 127) {
|
|
@@ -1937,7 +1937,7 @@ class o {
|
|
|
1937
1937
|
return o.ASN1(H.Null, new Uint8Array(0));
|
|
1938
1938
|
}
|
|
1939
1939
|
static objectIdentifier(e) {
|
|
1940
|
-
const t = e.split(".").map(Number),
|
|
1940
|
+
const t = e.split(".").map(Number), s = [t[0] * 40 + t[1]];
|
|
1941
1941
|
for (let i = 2; i < t.length; i++) {
|
|
1942
1942
|
let _ = t[i];
|
|
1943
1943
|
const a = [];
|
|
@@ -1946,9 +1946,9 @@ class o {
|
|
|
1946
1946
|
while (_ > 0);
|
|
1947
1947
|
for (let c = 0; c < a.length - 1; c++)
|
|
1948
1948
|
a[c] |= 128;
|
|
1949
|
-
|
|
1949
|
+
s.push(...a);
|
|
1950
1950
|
}
|
|
1951
|
-
return o.ASN1(H.OID, new Uint8Array(
|
|
1951
|
+
return o.ASN1(H.OID, new Uint8Array(s));
|
|
1952
1952
|
}
|
|
1953
1953
|
static utf8String(e) {
|
|
1954
1954
|
const t = new TextEncoder().encode(e);
|
|
@@ -1969,8 +1969,8 @@ class o {
|
|
|
1969
1969
|
return o.ASN1(H.IA5String, t);
|
|
1970
1970
|
}
|
|
1971
1971
|
static contextSpecific(e, t, r = !1) {
|
|
1972
|
-
const
|
|
1973
|
-
return o.ASN1(
|
|
1972
|
+
const s = (r ? 160 : 128) | e;
|
|
1973
|
+
return o.ASN1(s, t);
|
|
1974
1974
|
}
|
|
1975
1975
|
static boolean(e) {
|
|
1976
1976
|
return o.ASN1(
|
|
@@ -1979,49 +1979,73 @@ class o {
|
|
|
1979
1979
|
);
|
|
1980
1980
|
}
|
|
1981
1981
|
}
|
|
1982
|
-
function de(
|
|
1983
|
-
return btoa(String.fromCodePoint(...new Uint8Array(
|
|
1982
|
+
function de(n) {
|
|
1983
|
+
return btoa(String.fromCodePoint(...new Uint8Array(n)));
|
|
1984
1984
|
}
|
|
1985
|
-
function fe(
|
|
1985
|
+
function fe(n) {
|
|
1986
1986
|
var e;
|
|
1987
|
-
return ((e =
|
|
1988
|
-
`)) ||
|
|
1987
|
+
return ((e = n.match(/.{1,64}/g)) == null ? void 0 : e.join(`
|
|
1988
|
+
`)) || n;
|
|
1989
1989
|
}
|
|
1990
|
-
function ee(
|
|
1991
|
-
const e =
|
|
1992
|
-
return `${e}${t}${r}${
|
|
1990
|
+
function ee(n) {
|
|
1991
|
+
const e = n.getUTCFullYear().toString().substr(2), t = W(n.getUTCMonth() + 1), r = W(n.getUTCDate()), s = W(n.getUTCHours()), i = W(n.getUTCMinutes()), _ = W(n.getUTCSeconds());
|
|
1992
|
+
return `${e}${t}${r}${s}${i}${_}Z`;
|
|
1993
1993
|
}
|
|
1994
|
-
function W(
|
|
1995
|
-
return
|
|
1994
|
+
function W(n) {
|
|
1995
|
+
return n.toString().padStart(2, "0");
|
|
1996
1996
|
}
|
|
1997
|
-
function
|
|
1998
|
-
const t = new Date(
|
|
1997
|
+
function Ge(n, e) {
|
|
1998
|
+
const t = new Date(n);
|
|
1999
1999
|
return t.setUTCFullYear(t.getUTCFullYear() + e), t;
|
|
2000
2000
|
}
|
|
2001
|
-
|
|
2001
|
+
async function je(n, e, t) {
|
|
2002
|
+
const r = fetch(n, e);
|
|
2003
|
+
if (!t)
|
|
2004
|
+
return r;
|
|
2005
|
+
try {
|
|
2006
|
+
return await r;
|
|
2007
|
+
} catch {
|
|
2008
|
+
let s;
|
|
2009
|
+
if (typeof n == "string" || n instanceof URL)
|
|
2010
|
+
s = `${t}${n}`;
|
|
2011
|
+
else if (n instanceof Request)
|
|
2012
|
+
s = await ge(n, {
|
|
2013
|
+
url: `${t}${n.url}`
|
|
2014
|
+
});
|
|
2015
|
+
else
|
|
2016
|
+
throw new Error("Invalid input type for fetch");
|
|
2017
|
+
return fetch(s, e);
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
const $e = (n) => ({
|
|
2002
2021
|
websocket: {
|
|
2003
2022
|
url: (e, t, r) => `ws://playground.internal/?${new URLSearchParams({
|
|
2004
2023
|
host: t,
|
|
2005
2024
|
port: r
|
|
2006
2025
|
}).toString()}`,
|
|
2007
2026
|
subprotocol: "binary",
|
|
2008
|
-
decorator: () => class extends
|
|
2027
|
+
decorator: () => class extends Ve {
|
|
2009
2028
|
constructor(e, t) {
|
|
2010
2029
|
super(e, t, {
|
|
2011
|
-
CAroot:
|
|
2030
|
+
CAroot: n.CAroot,
|
|
2031
|
+
corsProxyUrl: n.corsProxyUrl
|
|
2012
2032
|
});
|
|
2013
2033
|
}
|
|
2014
2034
|
}
|
|
2015
2035
|
}
|
|
2016
2036
|
});
|
|
2017
|
-
class
|
|
2018
|
-
constructor(e, t, {
|
|
2037
|
+
class Ve {
|
|
2038
|
+
constructor(e, t, {
|
|
2039
|
+
CAroot: r,
|
|
2040
|
+
corsProxyUrl: s,
|
|
2041
|
+
outputType: i = "messages"
|
|
2042
|
+
} = {}) {
|
|
2019
2043
|
this.url = e, this.options = t, 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);
|
|
2020
|
-
const
|
|
2021
|
-
this.host =
|
|
2044
|
+
const _ = new URL(e);
|
|
2045
|
+
this.host = _.searchParams.get("host"), this.port = parseInt(_.searchParams.get("port"), 10), this.binaryType = "arraybuffer", this.corsProxyUrl = s, this.CAroot = r, i === "messages" && this.clientDownstream.readable.pipeTo(
|
|
2022
2046
|
new WritableStream({
|
|
2023
|
-
write: (
|
|
2024
|
-
this.emit("message", { data:
|
|
2047
|
+
write: (a) => {
|
|
2048
|
+
this.emit("message", { data: a });
|
|
2025
2049
|
},
|
|
2026
2050
|
abort: () => {
|
|
2027
2051
|
this.emit("error", new Error("ECONNREFUSED")), this.close();
|
|
@@ -2037,8 +2061,8 @@ class je {
|
|
|
2037
2061
|
this.addEventListener(e, t);
|
|
2038
2062
|
}
|
|
2039
2063
|
once(e, t) {
|
|
2040
|
-
const r = (
|
|
2041
|
-
t(
|
|
2064
|
+
const r = (s) => {
|
|
2065
|
+
t(s), this.removeEventListener(e, r);
|
|
2042
2066
|
};
|
|
2043
2067
|
this.addEventListener(e, r);
|
|
2044
2068
|
}
|
|
@@ -2056,8 +2080,8 @@ class je {
|
|
|
2056
2080
|
e === "message" ? this.onmessage(t) : e === "close" ? this.onclose(t) : e === "error" ? this.onerror(t) : e === "open" && this.onopen(t);
|
|
2057
2081
|
const r = this.listeners.get(e);
|
|
2058
2082
|
if (r)
|
|
2059
|
-
for (const
|
|
2060
|
-
|
|
2083
|
+
for (const s of r)
|
|
2084
|
+
s(t);
|
|
2061
2085
|
}
|
|
2062
2086
|
// Default event handlers that can be overridden by the user
|
|
2063
2087
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -2081,7 +2105,7 @@ class je {
|
|
|
2081
2105
|
switch (this.bufferedBytesFromClient = h([
|
|
2082
2106
|
this.bufferedBytesFromClient,
|
|
2083
2107
|
new Uint8Array(e)
|
|
2084
|
-
]),
|
|
2108
|
+
]), Ye(this.port, this.bufferedBytesFromClient)) {
|
|
2085
2109
|
case !1:
|
|
2086
2110
|
return;
|
|
2087
2111
|
case "other":
|
|
@@ -2100,7 +2124,7 @@ class je {
|
|
|
2100
2124
|
throw new Error(
|
|
2101
2125
|
"TLS protocol is only supported when the TCPOverFetchWebsocket is instantiated with a CAroot"
|
|
2102
2126
|
);
|
|
2103
|
-
const e = await
|
|
2127
|
+
const e = await qe(
|
|
2104
2128
|
{
|
|
2105
2129
|
subject: {
|
|
2106
2130
|
commonName: this.host,
|
|
@@ -2110,7 +2134,7 @@ class je {
|
|
|
2110
2134
|
issuer: this.CAroot.tbsDescription.subject
|
|
2111
2135
|
},
|
|
2112
2136
|
this.CAroot.keyPair
|
|
2113
|
-
), t = new
|
|
2137
|
+
), t = new Ne();
|
|
2114
2138
|
this.clientUpstream.readable.pipeTo(t.clientEnd.upstream.writable).catch(() => {
|
|
2115
2139
|
}), t.clientEnd.downstream.readable.pipeTo(this.clientDownstream.writable).catch(() => {
|
|
2116
2140
|
}), await t.TLSHandshake(e.keyPair.privateKey, [
|
|
@@ -2123,9 +2147,10 @@ class je {
|
|
|
2123
2147
|
"https"
|
|
2124
2148
|
);
|
|
2125
2149
|
try {
|
|
2126
|
-
await y.fetchRawResponseBytes(
|
|
2127
|
-
|
|
2128
|
-
|
|
2150
|
+
await y.fetchRawResponseBytes(
|
|
2151
|
+
r,
|
|
2152
|
+
this.corsProxyUrl
|
|
2153
|
+
).pipeTo(t.serverEnd.downstream.writable);
|
|
2129
2154
|
} catch {
|
|
2130
2155
|
}
|
|
2131
2156
|
}
|
|
@@ -2136,9 +2161,10 @@ class je {
|
|
|
2136
2161
|
"http"
|
|
2137
2162
|
);
|
|
2138
2163
|
try {
|
|
2139
|
-
await y.fetchRawResponseBytes(
|
|
2140
|
-
|
|
2141
|
-
|
|
2164
|
+
await y.fetchRawResponseBytes(
|
|
2165
|
+
e,
|
|
2166
|
+
this.corsProxyUrl
|
|
2167
|
+
).pipeTo(this.clientDownstream.writable);
|
|
2142
2168
|
} catch {
|
|
2143
2169
|
}
|
|
2144
2170
|
}
|
|
@@ -2146,7 +2172,7 @@ class je {
|
|
|
2146
2172
|
this.emit("message", { data: new Uint8Array(0) }), this.readyState = this.CLOSING, this.emit("close"), this.readyState = this.CLOSED;
|
|
2147
2173
|
}
|
|
2148
2174
|
}
|
|
2149
|
-
const
|
|
2175
|
+
const ze = [
|
|
2150
2176
|
"GET",
|
|
2151
2177
|
"POST",
|
|
2152
2178
|
"HEAD",
|
|
@@ -2156,16 +2182,16 @@ const $e = [
|
|
|
2156
2182
|
"PUT",
|
|
2157
2183
|
"TRACE"
|
|
2158
2184
|
];
|
|
2159
|
-
function
|
|
2185
|
+
function Ye(n, e) {
|
|
2160
2186
|
if (e.length < 8)
|
|
2161
2187
|
return !1;
|
|
2162
|
-
if (
|
|
2188
|
+
if (n === 443 && e[0] === C.Handshake && // TLS versions between 1.0 and 1.2
|
|
2163
2189
|
e[1] === 3 && e[2] >= 1 && e[2] <= 3)
|
|
2164
2190
|
return "tls";
|
|
2165
2191
|
const r = new TextDecoder("latin1", {
|
|
2166
2192
|
fatal: !0
|
|
2167
2193
|
}).decode(e);
|
|
2168
|
-
return
|
|
2194
|
+
return ze.some(
|
|
2169
2195
|
(i) => r.startsWith(i + " ")
|
|
2170
2196
|
) ? "http" : "other";
|
|
2171
2197
|
}
|
|
@@ -2173,33 +2199,45 @@ class y {
|
|
|
2173
2199
|
/**
|
|
2174
2200
|
* Streams a HTTP response including the status line and headers.
|
|
2175
2201
|
*/
|
|
2176
|
-
static fetchRawResponseBytes(e) {
|
|
2202
|
+
static fetchRawResponseBytes(e, t) {
|
|
2177
2203
|
return new ReadableStream({
|
|
2178
|
-
async start(
|
|
2179
|
-
var
|
|
2180
|
-
let
|
|
2204
|
+
async start(r) {
|
|
2205
|
+
var a;
|
|
2206
|
+
let s;
|
|
2181
2207
|
try {
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2208
|
+
s = await je(
|
|
2209
|
+
e,
|
|
2210
|
+
void 0,
|
|
2211
|
+
t
|
|
2212
|
+
);
|
|
2213
|
+
} catch (c) {
|
|
2214
|
+
r.enqueue(
|
|
2215
|
+
new TextEncoder().encode(
|
|
2216
|
+
`HTTP/1.1 400 Bad Request\r
|
|
2217
|
+
Content-Length: 0\r
|
|
2218
|
+
\r
|
|
2219
|
+
`
|
|
2220
|
+
)
|
|
2221
|
+
), r.error(c);
|
|
2185
2222
|
return;
|
|
2186
2223
|
}
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2224
|
+
r.enqueue(y.headersAsBytes(s));
|
|
2225
|
+
const i = (a = s.body) == null ? void 0 : a.getReader();
|
|
2226
|
+
if (!i) {
|
|
2227
|
+
r.close();
|
|
2190
2228
|
return;
|
|
2191
2229
|
}
|
|
2192
|
-
const
|
|
2230
|
+
const _ = new TextEncoder();
|
|
2193
2231
|
for (; ; ) {
|
|
2194
|
-
const { done:
|
|
2195
|
-
if (
|
|
2196
|
-
|
|
2232
|
+
const { done: c, value: S } = await i.read();
|
|
2233
|
+
if (S && (r.enqueue(
|
|
2234
|
+
_.encode(`${S.length.toString(16)}\r
|
|
2197
2235
|
`)
|
|
2198
|
-
),
|
|
2199
|
-
`))),
|
|
2200
|
-
|
|
2236
|
+
), r.enqueue(S), r.enqueue(_.encode(`\r
|
|
2237
|
+
`))), c) {
|
|
2238
|
+
r.enqueue(_.encode(`0\r
|
|
2201
2239
|
\r
|
|
2202
|
-
`)),
|
|
2240
|
+
`)), r.close();
|
|
2203
2241
|
return;
|
|
2204
2242
|
}
|
|
2205
2243
|
}
|
|
@@ -2211,10 +2249,10 @@ class y {
|
|
|
2211
2249
|
e.headers.forEach((_, a) => {
|
|
2212
2250
|
r[a.toLowerCase()] = _;
|
|
2213
2251
|
}), delete r["content-length"], r["transfer-encoding"] = "chunked";
|
|
2214
|
-
const
|
|
2252
|
+
const s = [];
|
|
2215
2253
|
for (const [_, a] of Object.entries(r))
|
|
2216
|
-
|
|
2217
|
-
const i = [t, ...
|
|
2254
|
+
s.push(`${_}: ${a}`);
|
|
2255
|
+
const i = [t, ...s].join(`\r
|
|
2218
2256
|
`) + `\r
|
|
2219
2257
|
\r
|
|
2220
2258
|
`;
|
|
@@ -2225,7 +2263,7 @@ class y {
|
|
|
2225
2263
|
* with known headers and a readable body stream.
|
|
2226
2264
|
*/
|
|
2227
2265
|
static async parseHttpRequest(e, t, r) {
|
|
2228
|
-
let
|
|
2266
|
+
let s = new Uint8Array(0), i = !1, _ = -1;
|
|
2229
2267
|
const a = e.getReader();
|
|
2230
2268
|
for (; _ === -1; ) {
|
|
2231
2269
|
const { done: D, value: L } = await a.read();
|
|
@@ -2233,13 +2271,13 @@ class y {
|
|
|
2233
2271
|
i = !0;
|
|
2234
2272
|
break;
|
|
2235
2273
|
}
|
|
2236
|
-
|
|
2237
|
-
|
|
2274
|
+
s = h([s, L]), _ = Je(
|
|
2275
|
+
s,
|
|
2238
2276
|
new Uint8Array([13, 10, 13, 10])
|
|
2239
2277
|
);
|
|
2240
2278
|
}
|
|
2241
2279
|
a.releaseLock();
|
|
2242
|
-
const c =
|
|
2280
|
+
const c = s.slice(0, _), S = y.parseRequestHeaders(c), l = s.slice(
|
|
2243
2281
|
_ + 4
|
|
2244
2282
|
/* Skip \r\n\r\n */
|
|
2245
2283
|
);
|
|
@@ -2272,7 +2310,7 @@ class y {
|
|
|
2272
2310
|
}
|
|
2273
2311
|
static parseRequestHeaders(e) {
|
|
2274
2312
|
const t = new TextDecoder().decode(e), r = t.split(`
|
|
2275
|
-
`)[0], [
|
|
2313
|
+
`)[0], [s, i] = r.split(" "), _ = new Headers();
|
|
2276
2314
|
for (const a of t.split(`\r
|
|
2277
2315
|
`).slice(1)) {
|
|
2278
2316
|
if (a === "")
|
|
@@ -2280,15 +2318,15 @@ class y {
|
|
|
2280
2318
|
const [c, S] = a.split(": ");
|
|
2281
2319
|
_.set(c, S);
|
|
2282
2320
|
}
|
|
2283
|
-
return { method:
|
|
2321
|
+
return { method: s, path: i, headers: _ };
|
|
2284
2322
|
}
|
|
2285
2323
|
}
|
|
2286
|
-
function
|
|
2287
|
-
const t =
|
|
2288
|
-
for (let i = 0; i <=
|
|
2324
|
+
function Je(n, e) {
|
|
2325
|
+
const t = n.length, r = e.length, s = t - r;
|
|
2326
|
+
for (let i = 0; i <= s; i++) {
|
|
2289
2327
|
let _ = !0;
|
|
2290
2328
|
for (let a = 0; a < r; a++)
|
|
2291
|
-
if (
|
|
2329
|
+
if (n[i + a] !== e[a]) {
|
|
2292
2330
|
_ = !1;
|
|
2293
2331
|
break;
|
|
2294
2332
|
}
|
|
@@ -2297,9 +2335,9 @@ function ze(s, e) {
|
|
|
2297
2335
|
}
|
|
2298
2336
|
return -1;
|
|
2299
2337
|
}
|
|
2300
|
-
const
|
|
2338
|
+
const Xe = () => ({
|
|
2301
2339
|
websocket: {
|
|
2302
|
-
decorator: (
|
|
2340
|
+
decorator: (n) => class extends n {
|
|
2303
2341
|
constructor() {
|
|
2304
2342
|
try {
|
|
2305
2343
|
super();
|
|
@@ -2312,60 +2350,60 @@ const Ye = () => ({
|
|
|
2312
2350
|
}
|
|
2313
2351
|
}
|
|
2314
2352
|
});
|
|
2315
|
-
async function
|
|
2316
|
-
var
|
|
2317
|
-
const t = await
|
|
2318
|
-
(
|
|
2319
|
-
const r = e.tcpOverFetch ?
|
|
2353
|
+
async function ut(n, e = {}) {
|
|
2354
|
+
var s;
|
|
2355
|
+
const t = await We(n);
|
|
2356
|
+
(s = e.onPhpLoaderModuleLoaded) == null || s.call(e, t);
|
|
2357
|
+
const r = e.tcpOverFetch ? $e(e.tcpOverFetch) : Xe();
|
|
2320
2358
|
return await me(t, {
|
|
2321
2359
|
...e.emscriptenOptions || {},
|
|
2322
2360
|
...r
|
|
2323
2361
|
});
|
|
2324
2362
|
}
|
|
2325
|
-
function
|
|
2363
|
+
function ht(n, e) {
|
|
2326
2364
|
window.addEventListener("message", (t) => {
|
|
2327
|
-
t.source ===
|
|
2365
|
+
t.source === n.contentWindow && (e && t.origin !== e || typeof t.data != "object" || t.data.type !== "relay" || window.parent.postMessage(t.data, "*"));
|
|
2328
2366
|
}), window.addEventListener("message", (t) => {
|
|
2329
2367
|
var r;
|
|
2330
|
-
t.source === window.parent && (typeof t.data != "object" || t.data.type !== "relay" || (r =
|
|
2368
|
+
t.source === window.parent && (typeof t.data != "object" || t.data.type !== "relay" || (r = n == null ? void 0 : n.contentWindow) == null || r.postMessage(t.data));
|
|
2331
2369
|
});
|
|
2332
2370
|
}
|
|
2333
|
-
async function
|
|
2334
|
-
const e = new Worker(
|
|
2371
|
+
async function Ht(n) {
|
|
2372
|
+
const e = new Worker(n, { type: "module" });
|
|
2335
2373
|
return new Promise((t, r) => {
|
|
2336
2374
|
e.onerror = (i) => {
|
|
2337
2375
|
const _ = new Error(
|
|
2338
|
-
`WebWorker failed to load at ${
|
|
2376
|
+
`WebWorker failed to load at ${n}. ${i.message ? `Original error: ${i.message}` : ""}`
|
|
2339
2377
|
);
|
|
2340
2378
|
_.filename = i.filename, r(_);
|
|
2341
2379
|
};
|
|
2342
|
-
function
|
|
2343
|
-
i.data === "worker-script-started" && (t(e), e.removeEventListener("message",
|
|
2380
|
+
function s(i) {
|
|
2381
|
+
i.data === "worker-script-started" && (t(e), e.removeEventListener("message", s));
|
|
2344
2382
|
}
|
|
2345
|
-
e.addEventListener("message",
|
|
2383
|
+
e.addEventListener("message", s);
|
|
2346
2384
|
});
|
|
2347
2385
|
}
|
|
2348
|
-
function
|
|
2386
|
+
function dt(n, e = { initialSync: {} }) {
|
|
2349
2387
|
return e = {
|
|
2350
2388
|
...e,
|
|
2351
2389
|
initialSync: {
|
|
2352
2390
|
...e.initialSync,
|
|
2353
2391
|
direction: e.initialSync.direction ?? "opfs-to-memfs"
|
|
2354
2392
|
}
|
|
2355
|
-
}, async function(t, r,
|
|
2356
|
-
return e.initialSync.direction === "opfs-to-memfs" ? (B.fileExists(r,
|
|
2393
|
+
}, async function(t, r, s) {
|
|
2394
|
+
return e.initialSync.direction === "opfs-to-memfs" ? (B.fileExists(r, s) && B.rmdir(r, s), B.mkdir(r, s), await Ze(r, n, s)) : await Ee(
|
|
2357
2395
|
r,
|
|
2358
|
-
s,
|
|
2359
2396
|
n,
|
|
2397
|
+
s,
|
|
2360
2398
|
e.initialSync.onProgress
|
|
2361
|
-
),
|
|
2399
|
+
), et(t, n, s);
|
|
2362
2400
|
};
|
|
2363
2401
|
}
|
|
2364
|
-
async function
|
|
2365
|
-
B.mkdir(
|
|
2366
|
-
const r = new
|
|
2402
|
+
async function Ze(n, e, t) {
|
|
2403
|
+
B.mkdir(n, t);
|
|
2404
|
+
const r = new Ke({
|
|
2367
2405
|
concurrency: 40
|
|
2368
|
-
}),
|
|
2406
|
+
}), s = [], i = [
|
|
2369
2407
|
[e, t]
|
|
2370
2408
|
];
|
|
2371
2409
|
for (; i.length > 0; ) {
|
|
@@ -2378,15 +2416,15 @@ async function Je(s, e, t) {
|
|
|
2378
2416
|
);
|
|
2379
2417
|
if (c.kind === "directory") {
|
|
2380
2418
|
try {
|
|
2381
|
-
|
|
2419
|
+
n.mkdir(l);
|
|
2382
2420
|
} catch (A) {
|
|
2383
2421
|
if ((A == null ? void 0 : A.errno) !== 20)
|
|
2384
|
-
throw
|
|
2422
|
+
throw R.error(A), A;
|
|
2385
2423
|
}
|
|
2386
2424
|
i.push([c, l]);
|
|
2387
2425
|
} else if (c.kind === "file") {
|
|
2388
2426
|
const A = await c.getFile(), u = new Uint8Array(await A.arrayBuffer());
|
|
2389
|
-
|
|
2427
|
+
n.createDataFile(
|
|
2390
2428
|
a,
|
|
2391
2429
|
c.name,
|
|
2392
2430
|
u,
|
|
@@ -2395,25 +2433,25 @@ async function Je(s, e, t) {
|
|
|
2395
2433
|
!0
|
|
2396
2434
|
);
|
|
2397
2435
|
}
|
|
2398
|
-
|
|
2436
|
+
s.splice(s.indexOf(S), 1);
|
|
2399
2437
|
});
|
|
2400
|
-
|
|
2438
|
+
s.push(S);
|
|
2401
2439
|
}
|
|
2402
|
-
for (; i.length === 0 &&
|
|
2403
|
-
await Promise.any(
|
|
2440
|
+
for (; i.length === 0 && s.length > 0; )
|
|
2441
|
+
await Promise.any(s);
|
|
2404
2442
|
}
|
|
2405
2443
|
}
|
|
2406
|
-
async function Ee(
|
|
2407
|
-
|
|
2408
|
-
const
|
|
2444
|
+
async function Ee(n, e, t, r) {
|
|
2445
|
+
n.mkdirTree(t);
|
|
2446
|
+
const s = [];
|
|
2409
2447
|
async function i(l, A) {
|
|
2410
2448
|
await Promise.all(
|
|
2411
|
-
|
|
2449
|
+
n.readdir(l).filter(
|
|
2412
2450
|
(u) => u !== "." && u !== ".."
|
|
2413
2451
|
).map(async (u) => {
|
|
2414
2452
|
const T = se(l, u);
|
|
2415
|
-
if (!
|
|
2416
|
-
|
|
2453
|
+
if (!Qe(n, T)) {
|
|
2454
|
+
s.push([A, T, u]);
|
|
2417
2455
|
return;
|
|
2418
2456
|
}
|
|
2419
2457
|
const D = await A.getDirectoryHandle(u, {
|
|
@@ -2425,42 +2463,42 @@ async function Ee(s, e, t, r) {
|
|
|
2425
2463
|
}
|
|
2426
2464
|
await i(t, e);
|
|
2427
2465
|
let _ = 0;
|
|
2428
|
-
const a = r &&
|
|
2466
|
+
const a = r && rt(r, 100), c = 100, S = /* @__PURE__ */ new Set();
|
|
2429
2467
|
try {
|
|
2430
|
-
for (const [l, A, u] of
|
|
2468
|
+
for (const [l, A, u] of s) {
|
|
2431
2469
|
const T = Te(
|
|
2432
2470
|
l,
|
|
2433
2471
|
u,
|
|
2434
|
-
|
|
2472
|
+
n,
|
|
2435
2473
|
A
|
|
2436
2474
|
).then(() => {
|
|
2437
2475
|
_++, S.delete(T), a == null || a({
|
|
2438
2476
|
files: _,
|
|
2439
|
-
total:
|
|
2477
|
+
total: s.length
|
|
2440
2478
|
});
|
|
2441
2479
|
});
|
|
2442
2480
|
S.add(T), S.size >= c && (await Promise.race(S), a == null || a({
|
|
2443
2481
|
files: _,
|
|
2444
|
-
total:
|
|
2482
|
+
total: s.length
|
|
2445
2483
|
}));
|
|
2446
2484
|
}
|
|
2447
2485
|
} finally {
|
|
2448
2486
|
await Promise.allSettled(S);
|
|
2449
2487
|
}
|
|
2450
2488
|
}
|
|
2451
|
-
function
|
|
2452
|
-
return
|
|
2489
|
+
function Qe(n, e) {
|
|
2490
|
+
return n.isDir(n.lookupPath(e, { follow: !0 }).node.mode);
|
|
2453
2491
|
}
|
|
2454
|
-
async function Te(
|
|
2455
|
-
let
|
|
2492
|
+
async function Te(n, e, t, r) {
|
|
2493
|
+
let s;
|
|
2456
2494
|
try {
|
|
2457
|
-
|
|
2495
|
+
s = t.readFile(r, {
|
|
2458
2496
|
encoding: "binary"
|
|
2459
2497
|
});
|
|
2460
2498
|
} catch {
|
|
2461
2499
|
return;
|
|
2462
2500
|
}
|
|
2463
|
-
const i = await
|
|
2501
|
+
const i = await n.getFileHandle(e, { create: !0 }), _ = i.createWritable !== void 0 ? (
|
|
2464
2502
|
// Google Chrome, Firefox, probably more browsers
|
|
2465
2503
|
await i.createWritable()
|
|
2466
2504
|
) : (
|
|
@@ -2468,17 +2506,17 @@ async function Te(s, e, t, r) {
|
|
|
2468
2506
|
await i.createSyncAccessHandle()
|
|
2469
2507
|
);
|
|
2470
2508
|
try {
|
|
2471
|
-
await _.truncate(0), await _.write(
|
|
2509
|
+
await _.truncate(0), await _.write(s);
|
|
2472
2510
|
} finally {
|
|
2473
2511
|
await _.close();
|
|
2474
2512
|
}
|
|
2475
2513
|
}
|
|
2476
|
-
function
|
|
2477
|
-
const r = [],
|
|
2514
|
+
function et(n, e, t) {
|
|
2515
|
+
const r = [], s = Ie(n, t, (a) => {
|
|
2478
2516
|
r.push(a);
|
|
2479
|
-
}), i = new
|
|
2517
|
+
}), i = new tt(n, e, t);
|
|
2480
2518
|
async function _() {
|
|
2481
|
-
const a = await
|
|
2519
|
+
const a = await n.semaphore.acquire();
|
|
2482
2520
|
try {
|
|
2483
2521
|
for (; r.length; )
|
|
2484
2522
|
await i.processEntry(r.shift());
|
|
@@ -2486,11 +2524,11 @@ function Ze(s, e, t) {
|
|
|
2486
2524
|
a();
|
|
2487
2525
|
}
|
|
2488
2526
|
}
|
|
2489
|
-
return
|
|
2490
|
-
|
|
2527
|
+
return n.addEventListener("request.end", _), function() {
|
|
2528
|
+
s(), n.removeEventListener("request.end", _);
|
|
2491
2529
|
};
|
|
2492
2530
|
}
|
|
2493
|
-
class
|
|
2531
|
+
class tt {
|
|
2494
2532
|
constructor(e, t, r) {
|
|
2495
2533
|
this.php = e, this.opfs = t, this.memfsRoot = te(r);
|
|
2496
2534
|
}
|
|
@@ -2500,26 +2538,26 @@ class Qe {
|
|
|
2500
2538
|
async processEntry(e) {
|
|
2501
2539
|
if (!e.path.startsWith(this.memfsRoot) || e.path === this.memfsRoot)
|
|
2502
2540
|
return;
|
|
2503
|
-
const t = this.toOpfsPath(e.path), r = await ne(this.opfs, t),
|
|
2504
|
-
if (
|
|
2541
|
+
const t = this.toOpfsPath(e.path), r = await ne(this.opfs, t), s = re(t);
|
|
2542
|
+
if (s)
|
|
2505
2543
|
try {
|
|
2506
2544
|
if (e.operation === "DELETE")
|
|
2507
2545
|
try {
|
|
2508
|
-
await r.removeEntry(
|
|
2546
|
+
await r.removeEntry(s, {
|
|
2509
2547
|
recursive: !0
|
|
2510
2548
|
});
|
|
2511
2549
|
} catch {
|
|
2512
2550
|
}
|
|
2513
2551
|
else if (e.operation === "CREATE")
|
|
2514
|
-
e.nodeType === "directory" ? await r.getDirectoryHandle(
|
|
2552
|
+
e.nodeType === "directory" ? await r.getDirectoryHandle(s, {
|
|
2515
2553
|
create: !0
|
|
2516
|
-
}) : await r.getFileHandle(
|
|
2554
|
+
}) : await r.getFileHandle(s, {
|
|
2517
2555
|
create: !0
|
|
2518
2556
|
});
|
|
2519
2557
|
else if (e.operation === "WRITE")
|
|
2520
2558
|
await Te(
|
|
2521
2559
|
r,
|
|
2522
|
-
|
|
2560
|
+
s,
|
|
2523
2561
|
this.php[k].FS,
|
|
2524
2562
|
e.path
|
|
2525
2563
|
);
|
|
@@ -2530,7 +2568,7 @@ class Qe {
|
|
|
2530
2568
|
), a = re(i);
|
|
2531
2569
|
if (e.nodeType === "directory") {
|
|
2532
2570
|
const c = await _.getDirectoryHandle(
|
|
2533
|
-
|
|
2571
|
+
s,
|
|
2534
2572
|
{
|
|
2535
2573
|
create: !0
|
|
2536
2574
|
}
|
|
@@ -2539,57 +2577,58 @@ class Qe {
|
|
|
2539
2577
|
this.php[k].FS,
|
|
2540
2578
|
c,
|
|
2541
2579
|
e.toPath
|
|
2542
|
-
), await r.removeEntry(
|
|
2580
|
+
), await r.removeEntry(s, {
|
|
2543
2581
|
recursive: !0
|
|
2544
2582
|
});
|
|
2545
2583
|
} else
|
|
2546
|
-
(await r.getFileHandle(
|
|
2584
|
+
(await r.getFileHandle(s)).move(_, a);
|
|
2547
2585
|
}
|
|
2548
2586
|
} catch (i) {
|
|
2549
|
-
throw
|
|
2587
|
+
throw R.log({ entry: e, name: s }), R.error(i), i;
|
|
2550
2588
|
}
|
|
2551
2589
|
}
|
|
2552
2590
|
}
|
|
2553
|
-
function te(
|
|
2554
|
-
return
|
|
2591
|
+
function te(n) {
|
|
2592
|
+
return n.replace(/\/$/, "").replace(/\/\/+/g, "/");
|
|
2555
2593
|
}
|
|
2556
|
-
function re(
|
|
2557
|
-
return
|
|
2594
|
+
function re(n) {
|
|
2595
|
+
return n.substring(n.lastIndexOf("/") + 1);
|
|
2558
2596
|
}
|
|
2559
|
-
async function ne(
|
|
2597
|
+
async function ne(n, e) {
|
|
2560
2598
|
const t = e.replace(/^\/+|\/+$/g, "").replace(/\/+/, "/");
|
|
2561
2599
|
if (!t)
|
|
2562
|
-
return
|
|
2600
|
+
return n;
|
|
2563
2601
|
const r = t.split("/");
|
|
2564
|
-
let
|
|
2602
|
+
let s = n;
|
|
2565
2603
|
for (let i = 0; i < r.length - 1; i++) {
|
|
2566
2604
|
const _ = r[i];
|
|
2567
|
-
|
|
2605
|
+
s = await s.getDirectoryHandle(_, { create: !0 });
|
|
2568
2606
|
}
|
|
2569
|
-
return
|
|
2607
|
+
return s;
|
|
2570
2608
|
}
|
|
2571
|
-
function
|
|
2572
|
-
let t = 0, r,
|
|
2609
|
+
function rt(n, e) {
|
|
2610
|
+
let t = 0, r, s;
|
|
2573
2611
|
return function(..._) {
|
|
2574
|
-
|
|
2612
|
+
s = _;
|
|
2575
2613
|
const a = Date.now() - t;
|
|
2576
2614
|
if (r === void 0) {
|
|
2577
2615
|
const c = Math.max(0, e - a);
|
|
2578
2616
|
r = setTimeout(() => {
|
|
2579
|
-
r = void 0, t = Date.now(),
|
|
2617
|
+
r = void 0, t = Date.now(), n(...s);
|
|
2580
2618
|
}, c);
|
|
2581
2619
|
}
|
|
2582
2620
|
};
|
|
2583
2621
|
}
|
|
2584
2622
|
export {
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
lt as
|
|
2594
|
-
|
|
2623
|
+
Ct as certificateToPEM,
|
|
2624
|
+
ct as consumeAPI,
|
|
2625
|
+
dt as createDirectoryHandleMountHandler,
|
|
2626
|
+
St as exposeAPI,
|
|
2627
|
+
je as fetchWithCorsProxy,
|
|
2628
|
+
qe as generateCertificate,
|
|
2629
|
+
We as getPHPLoaderModule,
|
|
2630
|
+
ut as loadWebRuntime,
|
|
2631
|
+
lt as privateKeyToPEM,
|
|
2632
|
+
ht as setupPostMessageRelay,
|
|
2633
|
+
Ht as spawnPHPWorkerThread
|
|
2595
2634
|
};
|