@php-wasm/web 3.1.35 → 3.1.38
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 +14 -14
- package/index.cjs.map +1 -1
- package/index.js +425 -389
- package/index.js.map +1 -1
- package/lib/extensions/load-extensions.d.ts +2 -2
- package/lib/get-php-loader-module.d.ts +2 -1
- package/lib/get-php-next-module.d.ts +7 -0
- package/package.json +19 -18
package/index.js
CHANGED
|
@@ -1,14 +1,44 @@
|
|
|
1
|
-
import { LatestSupportedPHPVersion as Se, withResolvedPHPExtensions as
|
|
2
|
-
import { consumeAPI as
|
|
3
|
-
import { concatArrayBuffers as
|
|
1
|
+
import { LatestSupportedPHPVersion as Se, withResolvedPHPExtensions as Pe, isLegacyPHPVersion as le, isPHPNextVersion as be, resolvePHPExtension as Y, createLegacyPhpIniPreRunStep as Re, loadPHPRuntime as Be, FSHelpers as v, __private__dont__use as O } from "@php-wasm/universal";
|
|
2
|
+
import { consumeAPI as qt, exposeAPI as Ft } from "@php-wasm/universal";
|
|
3
|
+
import { concatArrayBuffers as x, concatUint8Arrays as H, Semaphore as Ue, joinPaths as he, basename as xe } from "@php-wasm/util";
|
|
4
4
|
import { logger as g } from "@php-wasm/logger";
|
|
5
5
|
import { fetchWithCorsProxy as ve } from "@php-wasm/web-service-worker";
|
|
6
|
-
import { FirewallInterferenceError as
|
|
6
|
+
import { FirewallInterferenceError as jt, fetchWithCorsProxy as $t } from "@php-wasm/web-service-worker";
|
|
7
7
|
import { createMemoizedFetch as Me } from "@wp-playground/common";
|
|
8
|
-
import { jspi as
|
|
9
|
-
import { journalFSEvents as
|
|
10
|
-
async function
|
|
11
|
-
|
|
8
|
+
import { jspi as Ne } from "wasm-feature-detect";
|
|
9
|
+
import { journalFSEvents as ke, normalizeFilesystemOperations as qe } from "@php-wasm/fs-journal";
|
|
10
|
+
async function Fe() {
|
|
11
|
+
const s = Oe();
|
|
12
|
+
let e;
|
|
13
|
+
for (const t of s)
|
|
14
|
+
try {
|
|
15
|
+
return await import(
|
|
16
|
+
/* @vite-ignore */
|
|
17
|
+
t
|
|
18
|
+
);
|
|
19
|
+
} catch (n) {
|
|
20
|
+
e = n;
|
|
21
|
+
}
|
|
22
|
+
throw new Error(
|
|
23
|
+
"PHP next assets are missing. Run `npm run sync:php-next` before using PHP next locally.",
|
|
24
|
+
{ cause: e }
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
function Oe() {
|
|
28
|
+
var n, r;
|
|
29
|
+
const s = ((n = globalThis.location) == null ? void 0 : n.origin) || "", t = (((r = globalThis.location) == null ? void 0 : r.pathname) || "/").startsWith("/website-server/") ? "/website-server/" : "/";
|
|
30
|
+
return Array.from(
|
|
31
|
+
/* @__PURE__ */ new Set([
|
|
32
|
+
`${s}${t}php-next/index.js`,
|
|
33
|
+
`${s}/website-server/php-next/index.js`,
|
|
34
|
+
`${s}/php-next/index.js`
|
|
35
|
+
])
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
async function je(s = Se, e = "asyncify") {
|
|
39
|
+
switch (s) {
|
|
40
|
+
case "next":
|
|
41
|
+
return (await Fe()).getPHPLoaderModule(e);
|
|
12
42
|
case "8.5":
|
|
13
43
|
return (await import("@php-wasm/web-8-5")).getPHPLoaderModule();
|
|
14
44
|
case "8.4":
|
|
@@ -26,24 +56,24 @@ async function qe(i = Se) {
|
|
|
26
56
|
case "5.2":
|
|
27
57
|
return (await import("@php-wasm/web-5-2")).getPHPLoaderModule();
|
|
28
58
|
}
|
|
29
|
-
throw new Error(`Unsupported PHP version ${
|
|
59
|
+
throw new Error(`Unsupported PHP version ${s}`);
|
|
30
60
|
}
|
|
31
|
-
function w(
|
|
32
|
-
return Object.fromEntries(Object.entries(
|
|
61
|
+
function w(s) {
|
|
62
|
+
return Object.fromEntries(Object.entries(s).map(([e, t]) => [t, e]));
|
|
33
63
|
}
|
|
34
|
-
function W(
|
|
35
|
-
return new Uint8Array([
|
|
64
|
+
function W(s) {
|
|
65
|
+
return new Uint8Array([s >> 8 & 255, s & 255]);
|
|
36
66
|
}
|
|
37
|
-
function L(
|
|
67
|
+
function L(s) {
|
|
38
68
|
return new Uint8Array([
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
69
|
+
s >> 16 & 255,
|
|
70
|
+
s >> 8 & 255,
|
|
71
|
+
s & 255
|
|
42
72
|
]);
|
|
43
73
|
}
|
|
44
|
-
function Z(
|
|
74
|
+
function Z(s) {
|
|
45
75
|
const e = new ArrayBuffer(8);
|
|
46
|
-
return new DataView(e).setBigUint64(0, BigInt(
|
|
76
|
+
return new DataView(e).setBigUint64(0, BigInt(s), !1), new Uint8Array(e);
|
|
47
77
|
}
|
|
48
78
|
class I {
|
|
49
79
|
constructor(e) {
|
|
@@ -141,16 +171,16 @@ const P = {
|
|
|
141
171
|
transparency_info: 52,
|
|
142
172
|
connection_id: 54,
|
|
143
173
|
renegotiation_info: 65281
|
|
144
|
-
},
|
|
174
|
+
}, $e = w(P), Ce = {
|
|
145
175
|
host_name: 0
|
|
146
|
-
},
|
|
147
|
-
class
|
|
176
|
+
}, Ge = w(Ce);
|
|
177
|
+
class ue {
|
|
148
178
|
static decodeFromClient(e) {
|
|
149
179
|
const t = new DataView(e.buffer);
|
|
150
180
|
let n = 0;
|
|
151
181
|
const r = t.getUint16(n);
|
|
152
182
|
n += 2;
|
|
153
|
-
const
|
|
183
|
+
const i = [];
|
|
154
184
|
for (; n < r + 2; ) {
|
|
155
185
|
const a = e[n];
|
|
156
186
|
n += 1;
|
|
@@ -159,8 +189,8 @@ class he {
|
|
|
159
189
|
const o = e.slice(n, n + _);
|
|
160
190
|
switch (n += _, a) {
|
|
161
191
|
case Ce.host_name:
|
|
162
|
-
|
|
163
|
-
name_type:
|
|
192
|
+
i.push({
|
|
193
|
+
name_type: Ge[a],
|
|
164
194
|
name: {
|
|
165
195
|
host_name: new TextDecoder().decode(o)
|
|
166
196
|
}
|
|
@@ -170,7 +200,7 @@ class he {
|
|
|
170
200
|
throw new Error(`Unsupported name type ${a}`);
|
|
171
201
|
}
|
|
172
202
|
}
|
|
173
|
-
return { server_name_list:
|
|
203
|
+
return { server_name_list: i };
|
|
174
204
|
}
|
|
175
205
|
/**
|
|
176
206
|
* Encode the server_name extension
|
|
@@ -192,12 +222,12 @@ class he {
|
|
|
192
222
|
return t.writeUint16(P.server_name), t.writeUint16(0), t.uint8Array;
|
|
193
223
|
}
|
|
194
224
|
}
|
|
195
|
-
const
|
|
225
|
+
const Ae = {
|
|
196
226
|
uncompressed: 0,
|
|
197
227
|
ansiX962_compressed_prime: 1,
|
|
198
228
|
ansiX962_compressed_char2: 2
|
|
199
|
-
}, J = w(
|
|
200
|
-
class
|
|
229
|
+
}, J = w(Ae);
|
|
230
|
+
class He {
|
|
201
231
|
/**
|
|
202
232
|
* +--------------------------------------------------+
|
|
203
233
|
* | Payload Length [2B] |
|
|
@@ -215,7 +245,7 @@ class Ae {
|
|
|
215
245
|
*/
|
|
216
246
|
static decodeFromClient(e) {
|
|
217
247
|
const t = new I(e.buffer), n = t.readUint8(), r = [];
|
|
218
|
-
for (let
|
|
248
|
+
for (let i = 0; i < n; i++) {
|
|
219
249
|
const a = t.readUint8();
|
|
220
250
|
a in J && r.push(J[a]);
|
|
221
251
|
}
|
|
@@ -237,14 +267,14 @@ class Ae {
|
|
|
237
267
|
*/
|
|
238
268
|
static encodeForClient(e) {
|
|
239
269
|
const t = new N(6);
|
|
240
|
-
return t.writeUint16(P.ec_point_formats), t.writeUint16(2), t.writeUint8(1), t.writeUint8(
|
|
270
|
+
return t.writeUint16(P.ec_point_formats), t.writeUint16(2), t.writeUint8(1), t.writeUint8(Ae[e]), t.uint8Array;
|
|
241
271
|
}
|
|
242
272
|
}
|
|
243
|
-
const
|
|
244
|
-
decodeFromClient(
|
|
245
|
-
const e =
|
|
273
|
+
const de = {
|
|
274
|
+
decodeFromClient(s) {
|
|
275
|
+
const e = s[0] ?? 0;
|
|
246
276
|
return {
|
|
247
|
-
renegotiatedConnection:
|
|
277
|
+
renegotiatedConnection: s.slice(1, 1 + e)
|
|
248
278
|
};
|
|
249
279
|
},
|
|
250
280
|
/**
|
|
@@ -252,16 +282,16 @@ const He = {
|
|
|
252
282
|
* with an empty renegotiated_connection field.
|
|
253
283
|
*/
|
|
254
284
|
encodeForClient() {
|
|
255
|
-
const
|
|
285
|
+
const s = P.renegotiation_info, e = new Uint8Array([0]);
|
|
256
286
|
return new Uint8Array([
|
|
257
|
-
|
|
258
|
-
|
|
287
|
+
s >> 8 & 255,
|
|
288
|
+
s & 255,
|
|
259
289
|
0,
|
|
260
290
|
e.length,
|
|
261
291
|
...e
|
|
262
292
|
]);
|
|
263
293
|
}
|
|
264
|
-
},
|
|
294
|
+
}, fe = {
|
|
265
295
|
TLS1_CK_PSK_WITH_RC4_128_SHA: 138,
|
|
266
296
|
TLS1_CK_PSK_WITH_3DES_EDE_CBC_SHA: 139,
|
|
267
297
|
TLS1_CK_PSK_WITH_AES_128_CBC_SHA: 140,
|
|
@@ -464,14 +494,14 @@ const He = {
|
|
|
464
494
|
TLS1_CK_ECDHE_PSK_WITH_CHACHA20_POLY1305: 52396,
|
|
465
495
|
TLS1_CK_DHE_PSK_WITH_CHACHA20_POLY1305: 52397,
|
|
466
496
|
TLS1_CK_RSA_PSK_WITH_CHACHA20_POLY1305: 52398
|
|
467
|
-
}, X = w(
|
|
497
|
+
}, X = w(fe), Ee = {
|
|
468
498
|
secp256r1: 23,
|
|
469
499
|
secp384r1: 24,
|
|
470
500
|
secp521r1: 25,
|
|
471
501
|
x25519: 29,
|
|
472
502
|
x448: 30
|
|
473
|
-
}, Q = w(
|
|
474
|
-
class
|
|
503
|
+
}, Q = w(Ee);
|
|
504
|
+
class Ve {
|
|
475
505
|
/**
|
|
476
506
|
* +--------------------------------------------------+
|
|
477
507
|
* | Payload Length [2B] |
|
|
@@ -509,7 +539,7 @@ class je {
|
|
|
509
539
|
*/
|
|
510
540
|
static encodeForClient(e) {
|
|
511
541
|
const t = new N(6);
|
|
512
|
-
return t.writeUint16(P.supported_groups), t.writeUint16(2), t.writeUint16(
|
|
542
|
+
return t.writeUint16(P.supported_groups), t.writeUint16(2), t.writeUint16(Ee[e]), t.uint8Array;
|
|
513
543
|
}
|
|
514
544
|
}
|
|
515
545
|
const V = {
|
|
@@ -526,7 +556,7 @@ const V = {
|
|
|
526
556
|
sha384: 5,
|
|
527
557
|
sha512: 6
|
|
528
558
|
}, te = w(z);
|
|
529
|
-
class
|
|
559
|
+
class ze {
|
|
530
560
|
/**
|
|
531
561
|
* Binary layout:
|
|
532
562
|
*
|
|
@@ -547,14 +577,14 @@ class Ge {
|
|
|
547
577
|
t.readUint16();
|
|
548
578
|
const n = [];
|
|
549
579
|
for (; !t.isFinished(); ) {
|
|
550
|
-
const r = t.readUint8(),
|
|
551
|
-
if (ee[
|
|
580
|
+
const r = t.readUint8(), i = t.readUint8();
|
|
581
|
+
if (ee[i]) {
|
|
552
582
|
if (!te[r]) {
|
|
553
583
|
g.warn(`Unknown hash algorithm: ${r}`);
|
|
554
584
|
continue;
|
|
555
585
|
}
|
|
556
586
|
n.push({
|
|
557
|
-
algorithm: ee[
|
|
587
|
+
algorithm: ee[i],
|
|
558
588
|
hash: te[r]
|
|
559
589
|
});
|
|
560
590
|
}
|
|
@@ -578,57 +608,57 @@ class Ge {
|
|
|
578
608
|
}
|
|
579
609
|
}
|
|
580
610
|
const ne = {
|
|
581
|
-
server_name:
|
|
582
|
-
signature_algorithms:
|
|
583
|
-
supported_groups:
|
|
584
|
-
ec_point_formats:
|
|
585
|
-
renegotiation_info:
|
|
611
|
+
server_name: ue,
|
|
612
|
+
signature_algorithms: ze,
|
|
613
|
+
supported_groups: Ve,
|
|
614
|
+
ec_point_formats: He,
|
|
615
|
+
renegotiation_info: de
|
|
586
616
|
};
|
|
587
|
-
function
|
|
588
|
-
const e = new I(
|
|
617
|
+
function Ye(s) {
|
|
618
|
+
const e = new I(s.buffer), t = [];
|
|
589
619
|
for (; !e.isFinished(); ) {
|
|
590
|
-
const n = e.offset, r = e.readUint16(),
|
|
591
|
-
if (!(
|
|
620
|
+
const n = e.offset, r = e.readUint16(), i = $e[r], a = e.readUint16(), _ = e.readUint8Array(a);
|
|
621
|
+
if (!(i in ne))
|
|
592
622
|
continue;
|
|
593
|
-
const o = ne[
|
|
623
|
+
const o = ne[i];
|
|
594
624
|
t.push({
|
|
595
|
-
type:
|
|
625
|
+
type: i,
|
|
596
626
|
data: o.decodeFromClient(_),
|
|
597
|
-
raw:
|
|
627
|
+
raw: s.slice(n, n + 4 + a)
|
|
598
628
|
});
|
|
599
629
|
}
|
|
600
630
|
return t;
|
|
601
631
|
}
|
|
602
|
-
async function
|
|
603
|
-
const r =
|
|
632
|
+
async function $(s, e, t, n) {
|
|
633
|
+
const r = x([e, t]), i = await crypto.subtle.importKey(
|
|
604
634
|
"raw",
|
|
605
|
-
|
|
635
|
+
s,
|
|
606
636
|
{ name: "HMAC", hash: { name: "SHA-256" } },
|
|
607
637
|
!1,
|
|
608
638
|
["sign"]
|
|
609
639
|
);
|
|
610
640
|
let a = r;
|
|
611
641
|
const _ = [];
|
|
612
|
-
for (;
|
|
613
|
-
a = await re(
|
|
614
|
-
const S =
|
|
642
|
+
for (; x(_).byteLength < n; ) {
|
|
643
|
+
a = await re(i, a);
|
|
644
|
+
const S = x([a, r]), l = await re(i, S);
|
|
615
645
|
_.push(l);
|
|
616
646
|
}
|
|
617
|
-
return
|
|
647
|
+
return x(_).slice(0, n);
|
|
618
648
|
}
|
|
619
|
-
async function re(
|
|
649
|
+
async function re(s, e) {
|
|
620
650
|
return await crypto.subtle.sign(
|
|
621
651
|
{ name: "HMAC", hash: "SHA-256" },
|
|
622
|
-
|
|
652
|
+
s,
|
|
623
653
|
e
|
|
624
654
|
);
|
|
625
655
|
}
|
|
626
|
-
const
|
|
656
|
+
const Ze = {
|
|
627
657
|
Null: 0
|
|
628
|
-
},
|
|
658
|
+
}, Te = {
|
|
629
659
|
Warning: 1,
|
|
630
660
|
Fatal: 2
|
|
631
|
-
},
|
|
661
|
+
}, pe = w(Te), we = {
|
|
632
662
|
CloseNotify: 0,
|
|
633
663
|
UnexpectedMessage: 10,
|
|
634
664
|
BadRecordMac: 20,
|
|
@@ -654,7 +684,7 @@ const Ve = {
|
|
|
654
684
|
UserCanceled: 90,
|
|
655
685
|
NoRenegotiation: 100,
|
|
656
686
|
UnsupportedExtension: 110
|
|
657
|
-
},
|
|
687
|
+
}, ye = w(we), C = {
|
|
658
688
|
ChangeCipherSpec: 20,
|
|
659
689
|
Alert: 21,
|
|
660
690
|
Handshake: 22,
|
|
@@ -668,7 +698,7 @@ const Ve = {
|
|
|
668
698
|
ServerHelloDone: 14,
|
|
669
699
|
ClientKeyExchange: 16,
|
|
670
700
|
Finished: 20
|
|
671
|
-
},
|
|
701
|
+
}, Je = {
|
|
672
702
|
/**
|
|
673
703
|
* Indicates that a named curve is used. This option
|
|
674
704
|
* SHOULD be used when applicable.
|
|
@@ -677,12 +707,12 @@ const Ve = {
|
|
|
677
707
|
/**
|
|
678
708
|
* Values 248 through 255 are reserved for private use.
|
|
679
709
|
*/
|
|
680
|
-
},
|
|
710
|
+
}, Xe = {
|
|
681
711
|
secp256r1: 23
|
|
682
712
|
};
|
|
683
713
|
class j extends Error {
|
|
684
714
|
}
|
|
685
|
-
const
|
|
715
|
+
const M = new Uint8Array([3, 3]), Qe = crypto.subtle.generateKey(
|
|
686
716
|
{
|
|
687
717
|
name: "ECDH",
|
|
688
718
|
namedCurve: "P-256"
|
|
@@ -693,7 +723,7 @@ const x = new Uint8Array([3, 3]), Ze = crypto.subtle.generateKey(
|
|
|
693
723
|
["deriveKey", "deriveBits"]
|
|
694
724
|
// Key usage
|
|
695
725
|
);
|
|
696
|
-
class
|
|
726
|
+
class et {
|
|
697
727
|
constructor() {
|
|
698
728
|
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 = {
|
|
699
729
|
// We don't need to chunk the encrypted data.
|
|
@@ -710,14 +740,14 @@ class Je {
|
|
|
710
740
|
* This will spread some messages across multiple records,
|
|
711
741
|
* but TLS supports it so that's fine.
|
|
712
742
|
*/
|
|
713
|
-
downstream:
|
|
743
|
+
downstream: tt(this.MAX_CHUNK_SIZE)
|
|
714
744
|
}, this.serverUpstreamWriter = this.serverEnd.upstream.writable.getWriter();
|
|
715
745
|
const e = this;
|
|
716
746
|
this.serverEnd.downstream.readable.pipeTo(
|
|
717
747
|
new WritableStream({
|
|
718
748
|
async write(t) {
|
|
719
749
|
await e.writeTLSRecord(
|
|
720
|
-
|
|
750
|
+
C.ApplicationData,
|
|
721
751
|
t
|
|
722
752
|
);
|
|
723
753
|
},
|
|
@@ -775,33 +805,33 @@ class Je {
|
|
|
775
805
|
);
|
|
776
806
|
const r = crypto.getRandomValues(new Uint8Array(32));
|
|
777
807
|
await this.writeTLSRecord(
|
|
778
|
-
|
|
808
|
+
C.Handshake,
|
|
779
809
|
D.serverHello(
|
|
780
810
|
n.body,
|
|
781
811
|
r,
|
|
782
|
-
|
|
812
|
+
Ze.Null
|
|
783
813
|
)
|
|
784
814
|
), await this.writeTLSRecord(
|
|
785
|
-
|
|
815
|
+
C.Handshake,
|
|
786
816
|
D.certificate(t)
|
|
787
817
|
);
|
|
788
|
-
const
|
|
818
|
+
const i = await Qe, a = n.body.random, _ = await D.ECDHEServerKeyExchange(
|
|
789
819
|
a,
|
|
790
820
|
r,
|
|
791
|
-
|
|
821
|
+
i,
|
|
792
822
|
e
|
|
793
823
|
);
|
|
794
|
-
await this.writeTLSRecord(
|
|
795
|
-
|
|
824
|
+
await this.writeTLSRecord(C.Handshake, _), await this.writeTLSRecord(
|
|
825
|
+
C.Handshake,
|
|
796
826
|
D.serverHelloDone()
|
|
797
827
|
);
|
|
798
828
|
const o = await this.readNextHandshakeMessage(
|
|
799
829
|
E.ClientKeyExchange
|
|
800
830
|
);
|
|
801
|
-
await this.readNextMessage(
|
|
831
|
+
await this.readNextMessage(C.ChangeCipherSpec), this.sessionKeys = await this.deriveSessionKeys({
|
|
802
832
|
clientRandom: a,
|
|
803
833
|
serverRandom: r,
|
|
804
|
-
serverPrivateKey:
|
|
834
|
+
serverPrivateKey: i.privateKey,
|
|
805
835
|
clientPublicKey: await crypto.subtle.importKey(
|
|
806
836
|
"raw",
|
|
807
837
|
o.body.exchange_keys,
|
|
@@ -810,10 +840,10 @@ class Je {
|
|
|
810
840
|
[]
|
|
811
841
|
)
|
|
812
842
|
}), await this.readNextHandshakeMessage(E.Finished), await this.writeTLSRecord(
|
|
813
|
-
|
|
843
|
+
C.ChangeCipherSpec,
|
|
814
844
|
D.changeCipherSpec()
|
|
815
845
|
), await this.writeTLSRecord(
|
|
816
|
-
|
|
846
|
+
C.Handshake,
|
|
817
847
|
await D.createFinishedMessage(
|
|
818
848
|
this.handshakeMessages,
|
|
819
849
|
this.sessionKeys.masterSecret
|
|
@@ -830,7 +860,7 @@ class Je {
|
|
|
830
860
|
serverPrivateKey: n,
|
|
831
861
|
clientPublicKey: r
|
|
832
862
|
}) {
|
|
833
|
-
const
|
|
863
|
+
const i = await crypto.subtle.deriveBits(
|
|
834
864
|
{
|
|
835
865
|
name: "ECDH",
|
|
836
866
|
public: r
|
|
@@ -839,19 +869,19 @@ class Je {
|
|
|
839
869
|
256
|
|
840
870
|
// Length of the derived secret (256 bits for P-256)
|
|
841
871
|
), a = new Uint8Array(
|
|
842
|
-
await
|
|
843
|
-
|
|
872
|
+
await $(
|
|
873
|
+
i,
|
|
844
874
|
new TextEncoder().encode("master secret"),
|
|
845
875
|
H([e, t]),
|
|
846
876
|
48
|
|
847
877
|
)
|
|
848
|
-
), _ = await
|
|
878
|
+
), _ = await $(
|
|
849
879
|
a,
|
|
850
880
|
new TextEncoder().encode("key expansion"),
|
|
851
881
|
H([t, e]),
|
|
852
882
|
// Client key, server key, client IV, server IV
|
|
853
883
|
40
|
|
854
|
-
), o = new I(_), S = o.readUint8Array(16), l = o.readUint8Array(16),
|
|
884
|
+
), o = new I(_), S = o.readUint8Array(16), l = o.readUint8Array(16), h = o.readUint8Array(4), A = o.readUint8Array(4);
|
|
855
885
|
return {
|
|
856
886
|
masterSecret: a,
|
|
857
887
|
clientWriteKey: await crypto.subtle.importKey(
|
|
@@ -868,12 +898,12 @@ class Je {
|
|
|
868
898
|
!1,
|
|
869
899
|
["encrypt", "decrypt"]
|
|
870
900
|
),
|
|
871
|
-
clientIV:
|
|
901
|
+
clientIV: h,
|
|
872
902
|
serverIV: A
|
|
873
903
|
};
|
|
874
904
|
}
|
|
875
905
|
async readNextHandshakeMessage(e) {
|
|
876
|
-
const t = await this.readNextMessage(
|
|
906
|
+
const t = await this.readNextMessage(C.Handshake);
|
|
877
907
|
if (t.msg_type !== e)
|
|
878
908
|
throw new Error(`Expected ${e} message`);
|
|
879
909
|
return t;
|
|
@@ -887,7 +917,7 @@ class Je {
|
|
|
887
917
|
t.type,
|
|
888
918
|
n
|
|
889
919
|
);
|
|
890
|
-
return t.type ===
|
|
920
|
+
return t.type === C.Handshake && this.handshakeMessages.push(t.fragment), r;
|
|
891
921
|
}
|
|
892
922
|
async readNextTLSRecord(e) {
|
|
893
923
|
for (; ; ) {
|
|
@@ -896,18 +926,18 @@ class Je {
|
|
|
896
926
|
if (o.type === e)
|
|
897
927
|
return this.receivedTLSRecords.splice(_, 1), o;
|
|
898
928
|
}
|
|
899
|
-
const t = await this.pollBytes(5), n = t[3] << 8 | t[4], r = t[0],
|
|
929
|
+
const t = await this.pollBytes(5), n = t[3] << 8 | t[4], r = t[0], i = await this.pollBytes(n), a = {
|
|
900
930
|
type: r,
|
|
901
931
|
version: {
|
|
902
932
|
major: t[1],
|
|
903
933
|
minor: t[2]
|
|
904
934
|
},
|
|
905
935
|
length: n,
|
|
906
|
-
fragment: this.sessionKeys && r !==
|
|
936
|
+
fragment: this.sessionKeys && r !== C.ChangeCipherSpec ? await this.decryptData(r, i) : i
|
|
907
937
|
};
|
|
908
|
-
if (a.type ===
|
|
909
|
-
const _ = a.fragment[0], o = a.fragment[1], S =
|
|
910
|
-
throw _ ===
|
|
938
|
+
if (a.type === C.Alert) {
|
|
939
|
+
const _ = a.fragment[0], o = a.fragment[1], S = pe[_], l = ye[o];
|
|
940
|
+
throw _ === Te.Warning && o === we.CloseNotify ? new j(
|
|
911
941
|
"TLS connection closed by peer (CloseNotify)"
|
|
912
942
|
) : new Error(
|
|
913
943
|
`TLS alert received: ${S} ${l}`
|
|
@@ -930,7 +960,7 @@ class Je {
|
|
|
930
960
|
n
|
|
931
961
|
]), this.receivedBytesBuffer.length >= e)
|
|
932
962
|
break;
|
|
933
|
-
await new Promise((
|
|
963
|
+
await new Promise((i) => setTimeout(i, 100));
|
|
934
964
|
}
|
|
935
965
|
const t = this.receivedBytesBuffer.slice(0, e);
|
|
936
966
|
return this.receivedBytesBuffer = this.receivedBytesBuffer.slice(e), t;
|
|
@@ -943,7 +973,7 @@ class Je {
|
|
|
943
973
|
try {
|
|
944
974
|
for (; ; ) {
|
|
945
975
|
const e = await this.readNextMessage(
|
|
946
|
-
|
|
976
|
+
C.ApplicationData
|
|
947
977
|
);
|
|
948
978
|
this.serverUpstreamWriter.write(e.body);
|
|
949
979
|
}
|
|
@@ -958,14 +988,14 @@ class Je {
|
|
|
958
988
|
* the AES-GCM algorithm.
|
|
959
989
|
*/
|
|
960
990
|
async decryptData(e, t) {
|
|
961
|
-
const n = this.sessionKeys.clientIV, r = t.slice(0, 8),
|
|
991
|
+
const n = this.sessionKeys.clientIV, r = t.slice(0, 8), i = new Uint8Array([...n, ...r]), a = await crypto.subtle.decrypt(
|
|
962
992
|
{
|
|
963
993
|
name: "AES-GCM",
|
|
964
|
-
iv:
|
|
994
|
+
iv: i,
|
|
965
995
|
additionalData: new Uint8Array([
|
|
966
996
|
...Z(this.receivedRecordSequenceNumber),
|
|
967
997
|
e,
|
|
968
|
-
...
|
|
998
|
+
...M,
|
|
969
999
|
// Payload length without IV and tag
|
|
970
1000
|
...W(t.length - 8 - 16)
|
|
971
1001
|
]),
|
|
@@ -984,7 +1014,7 @@ class Je {
|
|
|
984
1014
|
]);
|
|
985
1015
|
const t = this.partialTLSMessages[e.type];
|
|
986
1016
|
switch (e.type) {
|
|
987
|
-
case
|
|
1017
|
+
case C.Handshake: {
|
|
988
1018
|
if (t.length < 4)
|
|
989
1019
|
return !1;
|
|
990
1020
|
const n = t[1] << 8 | t[2];
|
|
@@ -992,13 +1022,13 @@ class Je {
|
|
|
992
1022
|
return !1;
|
|
993
1023
|
break;
|
|
994
1024
|
}
|
|
995
|
-
case
|
|
1025
|
+
case C.Alert: {
|
|
996
1026
|
if (t.length < 2)
|
|
997
1027
|
return !1;
|
|
998
1028
|
break;
|
|
999
1029
|
}
|
|
1000
|
-
case
|
|
1001
|
-
case
|
|
1030
|
+
case C.ChangeCipherSpec:
|
|
1031
|
+
case C.ApplicationData:
|
|
1002
1032
|
break;
|
|
1003
1033
|
default:
|
|
1004
1034
|
throw new Error(`TLS: Unsupported record type ${e.type}`);
|
|
@@ -1013,10 +1043,10 @@ class Je {
|
|
|
1013
1043
|
* only kicks in after the handshake is complete.
|
|
1014
1044
|
*/
|
|
1015
1045
|
async writeTLSRecord(e, t) {
|
|
1016
|
-
e ===
|
|
1017
|
-
const n =
|
|
1018
|
-
|
|
1019
|
-
const a = H([
|
|
1046
|
+
e === C.Handshake && this.handshakeMessages.push(t), this.sessionKeys && e !== C.ChangeCipherSpec && (t = await this.encryptData(e, t));
|
|
1047
|
+
const n = M, r = t.length, i = new Uint8Array(5);
|
|
1048
|
+
i[0] = e, i[1] = n[0], i[2] = n[1], i[3] = r >> 8 & 255, i[4] = r & 255;
|
|
1049
|
+
const a = H([i, t]);
|
|
1020
1050
|
this.clientDownstreamWriter.write(a);
|
|
1021
1051
|
}
|
|
1022
1052
|
/**
|
|
@@ -1024,16 +1054,16 @@ class Je {
|
|
|
1024
1054
|
* the AES-GCM algorithm.
|
|
1025
1055
|
*/
|
|
1026
1056
|
async encryptData(e, t) {
|
|
1027
|
-
const n = this.sessionKeys.serverIV, r = crypto.getRandomValues(new Uint8Array(8)),
|
|
1057
|
+
const n = this.sessionKeys.serverIV, r = crypto.getRandomValues(new Uint8Array(8)), i = new Uint8Array([...n, ...r]), a = new Uint8Array([
|
|
1028
1058
|
...Z(this.sentRecordSequenceNumber),
|
|
1029
1059
|
e,
|
|
1030
|
-
...
|
|
1060
|
+
...M,
|
|
1031
1061
|
// Payload length without IV and tag
|
|
1032
1062
|
...W(t.length)
|
|
1033
1063
|
]), _ = await crypto.subtle.encrypt(
|
|
1034
1064
|
{
|
|
1035
1065
|
name: "AES-GCM",
|
|
1036
|
-
iv:
|
|
1066
|
+
iv: i,
|
|
1037
1067
|
additionalData: a,
|
|
1038
1068
|
tagLength: 128
|
|
1039
1069
|
},
|
|
@@ -1049,13 +1079,13 @@ class Je {
|
|
|
1049
1079
|
class T {
|
|
1050
1080
|
static TLSMessage(e, t) {
|
|
1051
1081
|
switch (e) {
|
|
1052
|
-
case
|
|
1082
|
+
case C.Handshake:
|
|
1053
1083
|
return T.clientHandshake(t);
|
|
1054
|
-
case
|
|
1084
|
+
case C.Alert:
|
|
1055
1085
|
return T.alert(t);
|
|
1056
|
-
case
|
|
1086
|
+
case C.ChangeCipherSpec:
|
|
1057
1087
|
return T.changeCipherSpec();
|
|
1058
|
-
case
|
|
1088
|
+
case C.ApplicationData:
|
|
1059
1089
|
return T.applicationData(t);
|
|
1060
1090
|
default:
|
|
1061
1091
|
throw new Error(`TLS: Unsupported TLS record type ${e}`);
|
|
@@ -1096,47 +1126,47 @@ class T {
|
|
|
1096
1126
|
}
|
|
1097
1127
|
static applicationData(e) {
|
|
1098
1128
|
return {
|
|
1099
|
-
type:
|
|
1129
|
+
type: C.ApplicationData,
|
|
1100
1130
|
body: e
|
|
1101
1131
|
};
|
|
1102
1132
|
}
|
|
1103
1133
|
static changeCipherSpec() {
|
|
1104
1134
|
return {
|
|
1105
|
-
type:
|
|
1135
|
+
type: C.ChangeCipherSpec,
|
|
1106
1136
|
body: new Uint8Array()
|
|
1107
1137
|
};
|
|
1108
1138
|
}
|
|
1109
1139
|
static alert(e) {
|
|
1110
1140
|
return {
|
|
1111
|
-
type:
|
|
1112
|
-
level:
|
|
1113
|
-
description:
|
|
1141
|
+
type: C.Alert,
|
|
1142
|
+
level: pe[e[0]],
|
|
1143
|
+
description: ye[e[1]]
|
|
1114
1144
|
};
|
|
1115
1145
|
}
|
|
1116
1146
|
static clientHandshake(e) {
|
|
1117
1147
|
const t = e[0], n = e[1] << 16 | e[2] << 8 | e[3], r = e.slice(4);
|
|
1118
|
-
let
|
|
1148
|
+
let i;
|
|
1119
1149
|
switch (t) {
|
|
1120
1150
|
case E.HelloRequest:
|
|
1121
|
-
|
|
1151
|
+
i = T.clientHelloRequestPayload();
|
|
1122
1152
|
break;
|
|
1123
1153
|
case E.ClientHello:
|
|
1124
|
-
|
|
1154
|
+
i = T.clientHelloPayload(r);
|
|
1125
1155
|
break;
|
|
1126
1156
|
case E.ClientKeyExchange:
|
|
1127
|
-
|
|
1157
|
+
i = T.clientKeyExchangePayload(r);
|
|
1128
1158
|
break;
|
|
1129
1159
|
case E.Finished:
|
|
1130
|
-
|
|
1160
|
+
i = T.clientFinishedPayload(r);
|
|
1131
1161
|
break;
|
|
1132
1162
|
default:
|
|
1133
1163
|
throw new Error(`Invalid handshake type ${t}`);
|
|
1134
1164
|
}
|
|
1135
1165
|
return {
|
|
1136
|
-
type:
|
|
1166
|
+
type: C.Handshake,
|
|
1137
1167
|
msg_type: t,
|
|
1138
1168
|
length: n,
|
|
1139
|
-
body:
|
|
1169
|
+
body: i
|
|
1140
1170
|
};
|
|
1141
1171
|
}
|
|
1142
1172
|
static clientHelloRequestPayload() {
|
|
@@ -1193,16 +1223,16 @@ class T {
|
|
|
1193
1223
|
random: t.readUint8Array(32)
|
|
1194
1224
|
}, r = t.readUint8();
|
|
1195
1225
|
n.session_id = t.readUint8Array(r);
|
|
1196
|
-
const
|
|
1226
|
+
const i = t.readUint16();
|
|
1197
1227
|
n.cipher_suites = T.parseCipherSuites(
|
|
1198
|
-
t.readUint8Array(
|
|
1228
|
+
t.readUint8Array(i).buffer
|
|
1199
1229
|
);
|
|
1200
1230
|
const a = t.readUint8();
|
|
1201
1231
|
n.compression_methods = t.readUint8Array(
|
|
1202
1232
|
a
|
|
1203
1233
|
);
|
|
1204
1234
|
const _ = t.readUint16();
|
|
1205
|
-
return n.extensions =
|
|
1235
|
+
return n.extensions = Ye(
|
|
1206
1236
|
t.readUint8Array(_)
|
|
1207
1237
|
), n;
|
|
1208
1238
|
}
|
|
@@ -1227,19 +1257,19 @@ class T {
|
|
|
1227
1257
|
};
|
|
1228
1258
|
}
|
|
1229
1259
|
}
|
|
1230
|
-
function
|
|
1260
|
+
function tt(s) {
|
|
1231
1261
|
return new TransformStream({
|
|
1232
1262
|
transform(e, t) {
|
|
1233
1263
|
for (; e.length > 0; )
|
|
1234
|
-
t.enqueue(e.slice(0,
|
|
1264
|
+
t.enqueue(e.slice(0, s)), e = e.slice(s);
|
|
1235
1265
|
}
|
|
1236
1266
|
});
|
|
1237
1267
|
}
|
|
1238
1268
|
class D {
|
|
1239
1269
|
static certificate(e) {
|
|
1240
1270
|
const t = [];
|
|
1241
|
-
for (const
|
|
1242
|
-
t.push(L(
|
|
1271
|
+
for (const i of e)
|
|
1272
|
+
t.push(L(i.byteLength)), t.push(new Uint8Array(i));
|
|
1243
1273
|
const n = H(t), r = new Uint8Array([
|
|
1244
1274
|
...L(n.byteLength),
|
|
1245
1275
|
...n
|
|
@@ -1284,17 +1314,17 @@ class D {
|
|
|
1284
1314
|
* @returns
|
|
1285
1315
|
*/
|
|
1286
1316
|
static async ECDHEServerKeyExchange(e, t, n, r) {
|
|
1287
|
-
const
|
|
1317
|
+
const i = new Uint8Array(
|
|
1288
1318
|
await crypto.subtle.exportKey("raw", n.publicKey)
|
|
1289
1319
|
), a = new Uint8Array([
|
|
1290
1320
|
// Curve type (1 byte)
|
|
1291
|
-
|
|
1321
|
+
Je.NamedCurve,
|
|
1292
1322
|
// Curve name (2 bytes)
|
|
1293
|
-
...W(
|
|
1323
|
+
...W(Xe.secp256r1),
|
|
1294
1324
|
// Public key length (1 byte)
|
|
1295
|
-
|
|
1325
|
+
i.byteLength,
|
|
1296
1326
|
// Public key (65 bytes, uncompressed format)
|
|
1297
|
-
...
|
|
1327
|
+
...i
|
|
1298
1328
|
]), _ = await crypto.subtle.sign(
|
|
1299
1329
|
{
|
|
1300
1330
|
name: "RSASSA-PKCS1-v1_5",
|
|
@@ -1356,33 +1386,33 @@ class D {
|
|
|
1356
1386
|
* +------------------------------------+
|
|
1357
1387
|
*/
|
|
1358
1388
|
static serverHello(e, t, n) {
|
|
1359
|
-
const r = e.extensions.map((
|
|
1360
|
-
switch (
|
|
1389
|
+
const r = e.extensions.map((o) => {
|
|
1390
|
+
switch (o.type) {
|
|
1361
1391
|
case "server_name":
|
|
1362
|
-
return
|
|
1392
|
+
return ue.encodeForClient();
|
|
1363
1393
|
case "ec_point_formats":
|
|
1364
|
-
return
|
|
1394
|
+
return He.encodeForClient(
|
|
1365
1395
|
"uncompressed"
|
|
1366
1396
|
);
|
|
1367
1397
|
case "renegotiation_info":
|
|
1368
|
-
return
|
|
1398
|
+
return de.encodeForClient();
|
|
1369
1399
|
}
|
|
1370
|
-
}).filter((
|
|
1400
|
+
}).filter((o) => o !== void 0), i = H(r), a = new Uint8Array(), _ = new Uint8Array([
|
|
1371
1401
|
// Version field – 0x03, 0x03 means TLS 1.2
|
|
1372
|
-
...
|
|
1402
|
+
...M,
|
|
1373
1403
|
...t,
|
|
1374
|
-
|
|
1375
|
-
...
|
|
1376
|
-
...W(
|
|
1404
|
+
a.length,
|
|
1405
|
+
...a,
|
|
1406
|
+
...W(fe.TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256),
|
|
1377
1407
|
n,
|
|
1378
1408
|
// Extensions length (2 bytes)
|
|
1379
|
-
...W(
|
|
1380
|
-
...
|
|
1409
|
+
...W(i.length),
|
|
1410
|
+
...i
|
|
1381
1411
|
]);
|
|
1382
1412
|
return new Uint8Array([
|
|
1383
1413
|
E.ServerHello,
|
|
1384
|
-
...L(
|
|
1385
|
-
...
|
|
1414
|
+
...L(_.length),
|
|
1415
|
+
..._
|
|
1386
1416
|
]);
|
|
1387
1417
|
}
|
|
1388
1418
|
static serverHelloDone() {
|
|
@@ -1411,7 +1441,7 @@ class D {
|
|
|
1411
1441
|
"SHA-256",
|
|
1412
1442
|
H(e)
|
|
1413
1443
|
), r = new Uint8Array(
|
|
1414
|
-
await
|
|
1444
|
+
await $(
|
|
1415
1445
|
t,
|
|
1416
1446
|
new TextEncoder().encode("server finished"),
|
|
1417
1447
|
n,
|
|
@@ -1429,25 +1459,25 @@ class D {
|
|
|
1429
1459
|
return new Uint8Array([1]);
|
|
1430
1460
|
}
|
|
1431
1461
|
}
|
|
1432
|
-
function
|
|
1433
|
-
return
|
|
1462
|
+
function nt(s, e) {
|
|
1463
|
+
return rt.generateCertificate(s, e);
|
|
1434
1464
|
}
|
|
1435
|
-
function
|
|
1465
|
+
function bt(s) {
|
|
1436
1466
|
return `-----BEGIN CERTIFICATE-----
|
|
1437
|
-
${
|
|
1438
|
-
|
|
1467
|
+
${Le(
|
|
1468
|
+
me(s.buffer)
|
|
1439
1469
|
)}
|
|
1440
1470
|
-----END CERTIFICATE-----`;
|
|
1441
1471
|
}
|
|
1442
|
-
async function
|
|
1443
|
-
const e = await crypto.subtle.exportKey("pkcs8",
|
|
1472
|
+
async function Rt(s) {
|
|
1473
|
+
const e = await crypto.subtle.exportKey("pkcs8", s);
|
|
1444
1474
|
return `-----BEGIN PRIVATE KEY-----
|
|
1445
|
-
${
|
|
1446
|
-
|
|
1475
|
+
${Le(
|
|
1476
|
+
me(e)
|
|
1447
1477
|
)}
|
|
1448
1478
|
-----END PRIVATE KEY-----`;
|
|
1449
1479
|
}
|
|
1450
|
-
class
|
|
1480
|
+
class rt {
|
|
1451
1481
|
static async generateCertificate(e, t) {
|
|
1452
1482
|
const n = await crypto.subtle.generateKey(
|
|
1453
1483
|
{
|
|
@@ -1462,13 +1492,13 @@ class et {
|
|
|
1462
1492
|
), r = await this.signingRequest(
|
|
1463
1493
|
e,
|
|
1464
1494
|
n.publicKey
|
|
1465
|
-
),
|
|
1495
|
+
), i = await this.sign(
|
|
1466
1496
|
r,
|
|
1467
1497
|
(t == null ? void 0 : t.privateKey) ?? n.privateKey
|
|
1468
1498
|
);
|
|
1469
1499
|
return {
|
|
1470
1500
|
keyPair: n,
|
|
1471
|
-
certificate:
|
|
1501
|
+
certificate: i,
|
|
1472
1502
|
tbsCertificate: r,
|
|
1473
1503
|
tbsDescription: e
|
|
1474
1504
|
};
|
|
@@ -1527,17 +1557,17 @@ class et {
|
|
|
1527
1557
|
static distinguishedName(e) {
|
|
1528
1558
|
const t = [];
|
|
1529
1559
|
for (const [n, r] of Object.entries(e)) {
|
|
1530
|
-
const
|
|
1560
|
+
const i = [
|
|
1531
1561
|
c.objectIdentifier(y(n))
|
|
1532
1562
|
];
|
|
1533
1563
|
switch (n) {
|
|
1534
1564
|
case "countryName":
|
|
1535
|
-
|
|
1565
|
+
i.push(c.printableString(r));
|
|
1536
1566
|
break;
|
|
1537
1567
|
default:
|
|
1538
|
-
|
|
1568
|
+
i.push(c.utf8String(r));
|
|
1539
1569
|
}
|
|
1540
|
-
t.push(c.set([c.sequence(
|
|
1570
|
+
t.push(c.set([c.sequence(i)]));
|
|
1541
1571
|
}
|
|
1542
1572
|
return c.sequence(t);
|
|
1543
1573
|
}
|
|
@@ -1553,7 +1583,7 @@ class et {
|
|
|
1553
1583
|
f.UTCTime,
|
|
1554
1584
|
new TextEncoder().encode(
|
|
1555
1585
|
ie(
|
|
1556
|
-
(e == null ? void 0 : e.notAfter) ??
|
|
1586
|
+
(e == null ? void 0 : e.notAfter) ?? it(/* @__PURE__ */ new Date(), 10)
|
|
1557
1587
|
)
|
|
1558
1588
|
)
|
|
1559
1589
|
)
|
|
@@ -1602,8 +1632,8 @@ class et {
|
|
|
1602
1632
|
]);
|
|
1603
1633
|
}
|
|
1604
1634
|
static subjectAltName(e) {
|
|
1605
|
-
var
|
|
1606
|
-
const t = ((
|
|
1635
|
+
var i, a;
|
|
1636
|
+
const t = ((i = e.dnsNames) == null ? void 0 : i.map((_) => {
|
|
1607
1637
|
const o = c.ia5String(_);
|
|
1608
1638
|
return c.contextSpecific(2, o);
|
|
1609
1639
|
})) || [], n = ((a = e.ipAddresses) == null ? void 0 : a.map((_) => {
|
|
@@ -1619,7 +1649,7 @@ class et {
|
|
|
1619
1649
|
]);
|
|
1620
1650
|
}
|
|
1621
1651
|
}
|
|
1622
|
-
const
|
|
1652
|
+
const st = {
|
|
1623
1653
|
// Algorithm OIDs
|
|
1624
1654
|
"1.2.840.113549.1.1.1": "rsaEncryption",
|
|
1625
1655
|
"1.2.840.113549.1.1.4": "md5WithRSAEncryption",
|
|
@@ -1729,11 +1759,11 @@ const tt = {
|
|
|
1729
1759
|
"1.3.6.1.5.5.7.3.4": "emailProtection",
|
|
1730
1760
|
"1.3.6.1.5.5.7.3.8": "timeStamping"
|
|
1731
1761
|
};
|
|
1732
|
-
function y(
|
|
1733
|
-
for (const [e, t] of Object.entries(
|
|
1734
|
-
if (t ===
|
|
1762
|
+
function y(s) {
|
|
1763
|
+
for (const [e, t] of Object.entries(st))
|
|
1764
|
+
if (t === s)
|
|
1735
1765
|
return e;
|
|
1736
|
-
throw new Error(`OID not found for name: ${
|
|
1766
|
+
throw new Error(`OID not found for name: ${s}`);
|
|
1737
1767
|
}
|
|
1738
1768
|
const se = 32, f = {
|
|
1739
1769
|
Boolean: 1,
|
|
@@ -1759,11 +1789,11 @@ class c {
|
|
|
1759
1789
|
const n = [];
|
|
1760
1790
|
for (; t > 0; )
|
|
1761
1791
|
n.unshift(t & 255), t >>= 8;
|
|
1762
|
-
const r = n.length,
|
|
1763
|
-
|
|
1792
|
+
const r = n.length, i = new Uint8Array(1 + r);
|
|
1793
|
+
i[0] = 128 | r;
|
|
1764
1794
|
for (let a = 0; a < r; a++)
|
|
1765
|
-
|
|
1766
|
-
return
|
|
1795
|
+
i[a + 1] = n[a];
|
|
1796
|
+
return i;
|
|
1767
1797
|
}
|
|
1768
1798
|
}
|
|
1769
1799
|
static ASN1(e, t) {
|
|
@@ -1792,8 +1822,8 @@ class c {
|
|
|
1792
1822
|
}
|
|
1793
1823
|
static objectIdentifier(e) {
|
|
1794
1824
|
const t = e.split(".").map(Number), r = [t[0] * 40 + t[1]];
|
|
1795
|
-
for (let
|
|
1796
|
-
let a = t[
|
|
1825
|
+
for (let i = 2; i < t.length; i++) {
|
|
1826
|
+
let a = t[i];
|
|
1797
1827
|
const _ = [];
|
|
1798
1828
|
do
|
|
1799
1829
|
_.unshift(a & 127), a >>= 7;
|
|
@@ -1833,30 +1863,30 @@ class c {
|
|
|
1833
1863
|
);
|
|
1834
1864
|
}
|
|
1835
1865
|
}
|
|
1836
|
-
function
|
|
1837
|
-
return btoa(String.fromCodePoint(...new Uint8Array(
|
|
1866
|
+
function me(s) {
|
|
1867
|
+
return btoa(String.fromCodePoint(...new Uint8Array(s)));
|
|
1838
1868
|
}
|
|
1839
|
-
function
|
|
1869
|
+
function Le(s) {
|
|
1840
1870
|
var e;
|
|
1841
|
-
return ((e =
|
|
1842
|
-
`)) ||
|
|
1871
|
+
return ((e = s.match(/.{1,64}/g)) == null ? void 0 : e.join(`
|
|
1872
|
+
`)) || s;
|
|
1843
1873
|
}
|
|
1844
|
-
function ie(
|
|
1845
|
-
const e =
|
|
1846
|
-
return `${e}${t}${n}${r}${
|
|
1874
|
+
function ie(s) {
|
|
1875
|
+
const e = s.getUTCFullYear().toString().substr(2), t = U(s.getUTCMonth() + 1), n = U(s.getUTCDate()), r = U(s.getUTCHours()), i = U(s.getUTCMinutes()), a = U(s.getUTCSeconds());
|
|
1876
|
+
return `${e}${t}${n}${r}${i}${a}Z`;
|
|
1847
1877
|
}
|
|
1848
|
-
function U(
|
|
1849
|
-
return
|
|
1878
|
+
function U(s) {
|
|
1879
|
+
return s.toString().padStart(2, "0");
|
|
1850
1880
|
}
|
|
1851
|
-
function
|
|
1852
|
-
const t = new Date(
|
|
1881
|
+
function it(s, e) {
|
|
1882
|
+
const t = new Date(s);
|
|
1853
1883
|
return t.setUTCFullYear(t.getUTCFullYear() + e), t;
|
|
1854
1884
|
}
|
|
1855
|
-
class
|
|
1885
|
+
class at extends TransformStream {
|
|
1856
1886
|
constructor() {
|
|
1857
1887
|
let e = new Uint8Array(0), t = "SCAN_CHUNK_SIZE", n = 0;
|
|
1858
1888
|
super({
|
|
1859
|
-
transform(r,
|
|
1889
|
+
transform(r, i) {
|
|
1860
1890
|
for (e = H([e, r]); e.length > 0; )
|
|
1861
1891
|
if (t === "SCAN_CHUNK_SIZE") {
|
|
1862
1892
|
if (e.length < 3)
|
|
@@ -1882,7 +1912,7 @@ class rt extends TransformStream {
|
|
|
1882
1912
|
e.slice(0, a)
|
|
1883
1913
|
), o = parseInt(_, 16);
|
|
1884
1914
|
if (e = e.slice(a + 2), o === 0) {
|
|
1885
|
-
t = "SCAN_FINAL_CHUNK",
|
|
1915
|
+
t = "SCAN_FINAL_CHUNK", i.terminate();
|
|
1886
1916
|
return;
|
|
1887
1917
|
}
|
|
1888
1918
|
n = o, t = "SCAN_CHUNK_DATA";
|
|
@@ -1891,7 +1921,7 @@ class rt extends TransformStream {
|
|
|
1891
1921
|
n,
|
|
1892
1922
|
e.length
|
|
1893
1923
|
), _ = e.slice(0, a);
|
|
1894
|
-
e = e.slice(a), n -= a,
|
|
1924
|
+
e = e.slice(a), n -= a, i.enqueue(_), n === 0 && (t = "SCAN_CHUNK_TRAILER");
|
|
1895
1925
|
} else if (t === "SCAN_CHUNK_TRAILER") {
|
|
1896
1926
|
if (e.length < 2)
|
|
1897
1927
|
return;
|
|
@@ -1905,15 +1935,15 @@ class rt extends TransformStream {
|
|
|
1905
1935
|
});
|
|
1906
1936
|
}
|
|
1907
1937
|
}
|
|
1908
|
-
const
|
|
1909
|
-
...
|
|
1938
|
+
const _t = (s, e) => ({
|
|
1939
|
+
...s,
|
|
1910
1940
|
websocket: {
|
|
1911
1941
|
url: (t, n, r) => `ws://playground.internal/?${new URLSearchParams({
|
|
1912
1942
|
host: n,
|
|
1913
1943
|
port: r
|
|
1914
1944
|
}).toString()}`,
|
|
1915
1945
|
subprotocol: "binary",
|
|
1916
|
-
decorator: () => class extends
|
|
1946
|
+
decorator: () => class extends ot {
|
|
1917
1947
|
constructor(t, n) {
|
|
1918
1948
|
super(t, n, {
|
|
1919
1949
|
CAroot: e.CAroot,
|
|
@@ -1923,15 +1953,15 @@ const st = (i, e) => ({
|
|
|
1923
1953
|
}
|
|
1924
1954
|
}
|
|
1925
1955
|
});
|
|
1926
|
-
class
|
|
1956
|
+
class ot {
|
|
1927
1957
|
constructor(e, t, {
|
|
1928
1958
|
CAroot: n,
|
|
1929
1959
|
corsProxyUrl: r,
|
|
1930
|
-
outputType:
|
|
1960
|
+
outputType: i = "messages"
|
|
1931
1961
|
} = {}) {
|
|
1932
1962
|
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;
|
|
1933
1963
|
const a = new URL(e);
|
|
1934
|
-
this.host = a.searchParams.get("host"), this.port = parseInt(a.searchParams.get("port"), 10), this.binaryType = "arraybuffer", this.corsProxyUrl = r, this.CAroot = n,
|
|
1964
|
+
this.host = a.searchParams.get("host"), this.port = parseInt(a.searchParams.get("port"), 10), this.binaryType = "arraybuffer", this.corsProxyUrl = r, this.CAroot = n, i === "messages" && this.clientDownstream.readable.pipeTo(
|
|
1935
1965
|
new WritableStream({
|
|
1936
1966
|
write: (_) => {
|
|
1937
1967
|
this.emit("message", { data: _ });
|
|
@@ -1994,7 +2024,7 @@ class it {
|
|
|
1994
2024
|
switch (this.bufferedBytesFromClient = H([
|
|
1995
2025
|
this.bufferedBytesFromClient,
|
|
1996
2026
|
new Uint8Array(e)
|
|
1997
|
-
]),
|
|
2027
|
+
]), St(this.port, this.bufferedBytesFromClient)) {
|
|
1998
2028
|
case !1:
|
|
1999
2029
|
return;
|
|
2000
2030
|
case "other":
|
|
@@ -2013,7 +2043,7 @@ class it {
|
|
|
2013
2043
|
throw new Error(
|
|
2014
2044
|
"TLS protocol is only supported when the TCPOverFetchWebsocket is instantiated with a CAroot"
|
|
2015
2045
|
);
|
|
2016
|
-
const e = await
|
|
2046
|
+
const e = await nt(
|
|
2017
2047
|
{
|
|
2018
2048
|
subject: {
|
|
2019
2049
|
commonName: this.host,
|
|
@@ -2023,7 +2053,7 @@ class it {
|
|
|
2023
2053
|
issuer: this.CAroot.tbsDescription.subject
|
|
2024
2054
|
},
|
|
2025
2055
|
this.CAroot.keyPair
|
|
2026
|
-
), t = new
|
|
2056
|
+
), t = new et();
|
|
2027
2057
|
this.clientUpstream.readable.pipeTo(t.clientEnd.upstream.writable).catch(() => {
|
|
2028
2058
|
}), t.clientEnd.downstream.readable.pipeTo(this.clientDownstream.writable).catch(() => {
|
|
2029
2059
|
}), await t.TLSHandshake(e.keyPair.privateKey, [
|
|
@@ -2036,12 +2066,12 @@ class it {
|
|
|
2036
2066
|
"https"
|
|
2037
2067
|
);
|
|
2038
2068
|
if (r) {
|
|
2039
|
-
const
|
|
2040
|
-
await
|
|
2069
|
+
const i = t.serverEnd.downstream.writable.getWriter();
|
|
2070
|
+
await i.write(
|
|
2041
2071
|
new TextEncoder().encode(`HTTP/1.1 100 Continue\r
|
|
2042
2072
|
\r
|
|
2043
2073
|
`)
|
|
2044
|
-
),
|
|
2074
|
+
), i.releaseLock();
|
|
2045
2075
|
}
|
|
2046
2076
|
try {
|
|
2047
2077
|
await p.fetchRawResponseBytes(
|
|
@@ -2077,7 +2107,7 @@ class it {
|
|
|
2077
2107
|
this.emit("message", { data: new Uint8Array(0) }), this.readyState = this.CLOSING, this.emit("close"), this.readyState = this.CLOSED;
|
|
2078
2108
|
}
|
|
2079
2109
|
}
|
|
2080
|
-
const
|
|
2110
|
+
const ct = [
|
|
2081
2111
|
"GET",
|
|
2082
2112
|
"POST",
|
|
2083
2113
|
"HEAD",
|
|
@@ -2087,17 +2117,17 @@ const at = [
|
|
|
2087
2117
|
"PUT",
|
|
2088
2118
|
"TRACE"
|
|
2089
2119
|
];
|
|
2090
|
-
function
|
|
2120
|
+
function St(s, e) {
|
|
2091
2121
|
if (e.length < 8)
|
|
2092
2122
|
return !1;
|
|
2093
|
-
if (
|
|
2123
|
+
if (s === 443 && e[0] === C.Handshake && // TLS versions between 1.0 and 1.2
|
|
2094
2124
|
e[1] === 3 && e[2] >= 1 && e[2] <= 3)
|
|
2095
2125
|
return "tls";
|
|
2096
2126
|
const n = new TextDecoder("latin1", {
|
|
2097
2127
|
fatal: !0
|
|
2098
2128
|
}).decode(e);
|
|
2099
|
-
return
|
|
2100
|
-
(
|
|
2129
|
+
return ct.some(
|
|
2130
|
+
(i) => n.startsWith(i + " ")
|
|
2101
2131
|
) ? "http" : "other";
|
|
2102
2132
|
}
|
|
2103
2133
|
class p {
|
|
@@ -2127,14 +2157,14 @@ Content-Length: 0\r
|
|
|
2127
2157
|
return;
|
|
2128
2158
|
}
|
|
2129
2159
|
n.enqueue(p.headersAsBytes(r));
|
|
2130
|
-
const
|
|
2131
|
-
if (!
|
|
2160
|
+
const i = (_ = r.body) == null ? void 0 : _.getReader();
|
|
2161
|
+
if (!i) {
|
|
2132
2162
|
n.close();
|
|
2133
2163
|
return;
|
|
2134
2164
|
}
|
|
2135
2165
|
const a = new TextEncoder();
|
|
2136
2166
|
for (; ; ) {
|
|
2137
|
-
const { done: o, value: S } = await
|
|
2167
|
+
const { done: o, value: S } = await i.read();
|
|
2138
2168
|
if (S && (n.enqueue(
|
|
2139
2169
|
a.encode(`${S.length.toString(16)}\r
|
|
2140
2170
|
`)
|
|
@@ -2157,26 +2187,26 @@ Content-Length: 0\r
|
|
|
2157
2187
|
const r = [];
|
|
2158
2188
|
for (const [a, _] of Object.entries(n))
|
|
2159
2189
|
r.push(`${a}: ${_}`);
|
|
2160
|
-
const
|
|
2190
|
+
const i = [t, ...r].join(`\r
|
|
2161
2191
|
`) + `\r
|
|
2162
2192
|
\r
|
|
2163
2193
|
`;
|
|
2164
|
-
return new TextEncoder().encode(
|
|
2194
|
+
return new TextEncoder().encode(i);
|
|
2165
2195
|
}
|
|
2166
2196
|
/**
|
|
2167
2197
|
* Parses a raw, streamed HTTP request into a Request object
|
|
2168
2198
|
* with known headers and a readable body stream.
|
|
2169
2199
|
*/
|
|
2170
2200
|
static async parseHttpRequest(e, t, n) {
|
|
2171
|
-
let r = new Uint8Array(0),
|
|
2201
|
+
let r = new Uint8Array(0), i = !1, a = -1;
|
|
2172
2202
|
const _ = e.getReader();
|
|
2173
2203
|
for (; a === -1; ) {
|
|
2174
2204
|
const { done: k, value: R } = await _.read();
|
|
2175
2205
|
if (k) {
|
|
2176
|
-
|
|
2206
|
+
i = !0;
|
|
2177
2207
|
break;
|
|
2178
2208
|
}
|
|
2179
|
-
r = H([r, R]), a =
|
|
2209
|
+
r = H([r, R]), a = lt(
|
|
2180
2210
|
r,
|
|
2181
2211
|
new Uint8Array([13, 10, 13, 10])
|
|
2182
2212
|
);
|
|
@@ -2184,7 +2214,7 @@ Content-Length: 0\r
|
|
|
2184
2214
|
_.releaseLock();
|
|
2185
2215
|
const o = r.slice(0, a), S = p.parseRequestHeaders(o), l = p.expectsContinue(
|
|
2186
2216
|
S.headers
|
|
2187
|
-
),
|
|
2217
|
+
), h = S.headers.get("Transfer-Encoding") !== null ? "chunked" : "content-length", A = S.headers.get("Content-Length") !== null ? parseInt(S.headers.get("Content-Length"), 10) : void 0, u = r.slice(
|
|
2188
2218
|
a + 4
|
|
2189
2219
|
/* Skip \r\n\r\n */
|
|
2190
2220
|
);
|
|
@@ -2192,38 +2222,38 @@ Content-Length: 0\r
|
|
|
2192
2222
|
if (S.method !== "GET" && S.method !== "HEAD") {
|
|
2193
2223
|
const k = e.getReader();
|
|
2194
2224
|
let R = u.length, q = u.slice(-6);
|
|
2195
|
-
const
|
|
2225
|
+
const Ke = new TextEncoder().encode(`0\r
|
|
2196
2226
|
\r
|
|
2197
2227
|
`);
|
|
2198
2228
|
d = new ReadableStream({
|
|
2199
2229
|
async start(B) {
|
|
2200
2230
|
u.length > 0 && B.enqueue(u);
|
|
2201
|
-
const F =
|
|
2202
|
-
(
|
|
2231
|
+
const F = h === "content-length" && A !== void 0 && R >= A;
|
|
2232
|
+
(i || F) && B.close();
|
|
2203
2233
|
},
|
|
2204
2234
|
async pull(B) {
|
|
2205
2235
|
const { done: F, value: K } = await k.read();
|
|
2206
2236
|
if (R += (K == null ? void 0 : K.length) || 0, K && (B.enqueue(K), q = H([
|
|
2207
2237
|
q,
|
|
2208
2238
|
K || new Uint8Array()
|
|
2209
|
-
]).slice(-5)), F ||
|
|
2210
|
-
(
|
|
2239
|
+
]).slice(-5)), F || h === "content-length" && A !== void 0 && R >= A || h === "chunked" && q.every(
|
|
2240
|
+
(De, We) => De === Ke[We]
|
|
2211
2241
|
)) {
|
|
2212
2242
|
B.close();
|
|
2213
2243
|
return;
|
|
2214
2244
|
}
|
|
2215
2245
|
}
|
|
2216
|
-
}),
|
|
2217
|
-
new
|
|
2246
|
+
}), h === "chunked" && (d = d.pipeThrough(
|
|
2247
|
+
new at()
|
|
2218
2248
|
));
|
|
2219
2249
|
}
|
|
2220
|
-
const m = S.headers.get("Host") ?? t, b = new URL(S.path, n + "://" + m),
|
|
2250
|
+
const m = S.headers.get("Host") ?? t, b = new URL(S.path, n + "://" + m), Ie = p.normalizeRequestHeadersForFetch(
|
|
2221
2251
|
S.headers
|
|
2222
2252
|
);
|
|
2223
2253
|
return {
|
|
2224
2254
|
request: new Request(b.toString(), {
|
|
2225
2255
|
method: S.method,
|
|
2226
|
-
headers:
|
|
2256
|
+
headers: Ie,
|
|
2227
2257
|
body: d,
|
|
2228
2258
|
// @ts-expect-error duplex is required for streaming request bodies
|
|
2229
2259
|
duplex: d ? "half" : void 0
|
|
@@ -2233,7 +2263,7 @@ Content-Length: 0\r
|
|
|
2233
2263
|
}
|
|
2234
2264
|
static parseRequestHeaders(e) {
|
|
2235
2265
|
const t = new TextDecoder().decode(e), n = t.split(`
|
|
2236
|
-
`)[0], [r,
|
|
2266
|
+
`)[0], [r, i] = n.split(" "), a = new Headers();
|
|
2237
2267
|
for (const _ of t.split(`\r
|
|
2238
2268
|
`).slice(1)) {
|
|
2239
2269
|
if (_ === "")
|
|
@@ -2244,7 +2274,7 @@ Content-Length: 0\r
|
|
|
2244
2274
|
const S = _.slice(0, o).trim(), l = _.slice(o + 1).trimStart();
|
|
2245
2275
|
S !== "" && a.set(S, l);
|
|
2246
2276
|
}
|
|
2247
|
-
return { method: r, path:
|
|
2277
|
+
return { method: r, path: i, headers: a };
|
|
2248
2278
|
}
|
|
2249
2279
|
static expectsContinue(e) {
|
|
2250
2280
|
var t;
|
|
@@ -2269,22 +2299,22 @@ Content-Length: 0\r
|
|
|
2269
2299
|
return t;
|
|
2270
2300
|
}
|
|
2271
2301
|
}
|
|
2272
|
-
function
|
|
2273
|
-
const t =
|
|
2274
|
-
for (let
|
|
2302
|
+
function lt(s, e) {
|
|
2303
|
+
const t = s.length, n = e.length, r = t - n;
|
|
2304
|
+
for (let i = 0; i <= r; i++) {
|
|
2275
2305
|
let a = !0;
|
|
2276
2306
|
for (let _ = 0; _ < n; _++)
|
|
2277
|
-
if (i
|
|
2307
|
+
if (s[i + _] !== e[_]) {
|
|
2278
2308
|
a = !1;
|
|
2279
2309
|
break;
|
|
2280
2310
|
}
|
|
2281
2311
|
if (a)
|
|
2282
|
-
return
|
|
2312
|
+
return i;
|
|
2283
2313
|
}
|
|
2284
2314
|
return -1;
|
|
2285
2315
|
}
|
|
2286
|
-
async function
|
|
2287
|
-
switch (
|
|
2316
|
+
async function ht(s = Se) {
|
|
2317
|
+
switch (s) {
|
|
2288
2318
|
case "8.5":
|
|
2289
2319
|
return (await import("@php-wasm/web-8-5")).getIntlExtensionPath();
|
|
2290
2320
|
case "8.4":
|
|
@@ -2300,19 +2330,25 @@ async function ct(i = Se) {
|
|
|
2300
2330
|
case "7.4":
|
|
2301
2331
|
return (await import("@php-wasm/web-7-4")).getIntlExtensionPath();
|
|
2302
2332
|
}
|
|
2303
|
-
throw new Error(`Unsupported PHP version ${
|
|
2333
|
+
throw new Error(`Unsupported PHP version ${s}`);
|
|
2304
2334
|
}
|
|
2305
|
-
async function
|
|
2335
|
+
async function Ct(s, e, t, n = []) {
|
|
2306
2336
|
if (!n.length)
|
|
2307
2337
|
return t;
|
|
2308
2338
|
const r = await Promise.all(
|
|
2309
2339
|
n.map(
|
|
2310
|
-
(
|
|
2340
|
+
(i) => ut(s, e, i)
|
|
2311
2341
|
)
|
|
2312
2342
|
);
|
|
2313
|
-
return
|
|
2343
|
+
return Pe(t, r);
|
|
2314
2344
|
}
|
|
2315
|
-
async function
|
|
2345
|
+
async function ut(s, e, t) {
|
|
2346
|
+
if (le(s))
|
|
2347
|
+
throw new Error(
|
|
2348
|
+
`Extensions are not available for legacy PHP ${s}.`
|
|
2349
|
+
);
|
|
2350
|
+
if (be(s))
|
|
2351
|
+
throw new Error("Extensions are not available for PHP next.");
|
|
2316
2352
|
if (typeof t == "object" && "source" in t) {
|
|
2317
2353
|
if (e === "asyncify")
|
|
2318
2354
|
throw new Error(
|
|
@@ -2320,14 +2356,14 @@ async function lt(i, e, t) {
|
|
|
2320
2356
|
);
|
|
2321
2357
|
return await Y({
|
|
2322
2358
|
...t,
|
|
2323
|
-
phpVersion:
|
|
2359
|
+
phpVersion: s
|
|
2324
2360
|
});
|
|
2325
2361
|
}
|
|
2326
2362
|
const n = typeof t == "string" ? t : t.name;
|
|
2327
2363
|
if (n !== "intl")
|
|
2328
2364
|
throw new Error(`Unknown bundled PHP web extension: ${String(n)}.`);
|
|
2329
|
-
const r = Me(fetch),
|
|
2330
|
-
[
|
|
2365
|
+
const r = Me(fetch), i = await ht(s), a = (await import("./shared/icu.dat")).default, [_, o] = await Promise.all(
|
|
2366
|
+
[i, a].map(async (S) => {
|
|
2331
2367
|
const l = await r(S);
|
|
2332
2368
|
if (!l.ok)
|
|
2333
2369
|
throw new Error(
|
|
@@ -2342,7 +2378,7 @@ async function lt(i, e, t) {
|
|
|
2342
2378
|
name: "intl",
|
|
2343
2379
|
bytes: new Uint8Array(_)
|
|
2344
2380
|
},
|
|
2345
|
-
phpVersion:
|
|
2381
|
+
phpVersion: s,
|
|
2346
2382
|
env: {
|
|
2347
2383
|
ICU_DATA: "/internal/shared"
|
|
2348
2384
|
},
|
|
@@ -2354,9 +2390,9 @@ async function lt(i, e, t) {
|
|
|
2354
2390
|
}
|
|
2355
2391
|
});
|
|
2356
2392
|
}
|
|
2357
|
-
const
|
|
2393
|
+
const At = () => ({
|
|
2358
2394
|
websocket: {
|
|
2359
|
-
decorator: (
|
|
2395
|
+
decorator: (s) => class extends s {
|
|
2360
2396
|
constructor() {
|
|
2361
2397
|
try {
|
|
2362
2398
|
super();
|
|
@@ -2369,71 +2405,71 @@ const Ct = () => ({
|
|
|
2369
2405
|
}
|
|
2370
2406
|
}
|
|
2371
2407
|
});
|
|
2372
|
-
async function
|
|
2408
|
+
async function Ut(s, e = {}) {
|
|
2373
2409
|
var o;
|
|
2374
2410
|
"setImmediate" in globalThis || (globalThis.setImmediate = (S) => setTimeout(S, 0));
|
|
2375
|
-
const t = await
|
|
2411
|
+
const t = await Ne() ? "jspi" : "asyncify";
|
|
2376
2412
|
let n = {
|
|
2377
|
-
...
|
|
2413
|
+
...At(),
|
|
2378
2414
|
...e.emscriptenOptions || {},
|
|
2379
2415
|
phpWasmAsyncMode: t
|
|
2380
2416
|
};
|
|
2381
|
-
e.tcpOverFetch && (n =
|
|
2417
|
+
e.tcpOverFetch && (n = _t(
|
|
2382
2418
|
n,
|
|
2383
2419
|
e.tcpOverFetch
|
|
2384
2420
|
));
|
|
2385
|
-
const r =
|
|
2386
|
-
if (e.withIntl && !
|
|
2421
|
+
const r = le(s), i = [...e.extensions ?? []];
|
|
2422
|
+
if (e.withIntl && !Ht(i, "intl") && i.push("intl"), r) {
|
|
2387
2423
|
const S = await n, l = S.preRun || [];
|
|
2388
2424
|
n = {
|
|
2389
2425
|
...S,
|
|
2390
|
-
preRun: [...l,
|
|
2426
|
+
preRun: [...l, Re()]
|
|
2391
2427
|
};
|
|
2392
2428
|
}
|
|
2393
|
-
if (r &&
|
|
2429
|
+
if (r && i.length)
|
|
2394
2430
|
throw new Error(
|
|
2395
|
-
`Extensions are not available for legacy PHP ${
|
|
2431
|
+
`Extensions are not available for legacy PHP ${s}.`
|
|
2396
2432
|
);
|
|
2397
|
-
r || (n =
|
|
2398
|
-
|
|
2433
|
+
r || (n = Ct(
|
|
2434
|
+
s,
|
|
2399
2435
|
t,
|
|
2400
2436
|
await n,
|
|
2401
|
-
|
|
2437
|
+
i
|
|
2402
2438
|
));
|
|
2403
2439
|
const [a, _] = await Promise.all([
|
|
2404
|
-
|
|
2440
|
+
je(s, t),
|
|
2405
2441
|
n
|
|
2406
2442
|
]);
|
|
2407
|
-
return (o = e.onPhpLoaderModuleLoaded) == null || o.call(e, a), await
|
|
2443
|
+
return (o = e.onPhpLoaderModuleLoaded) == null || o.call(e, a), await Be(a, _);
|
|
2408
2444
|
}
|
|
2409
|
-
function
|
|
2410
|
-
return
|
|
2445
|
+
function Ht(s, e) {
|
|
2446
|
+
return s.some((t) => typeof t == "string" ? t === e : !("source" in t) && t.name === e);
|
|
2411
2447
|
}
|
|
2412
|
-
function
|
|
2448
|
+
function xt(s, e) {
|
|
2413
2449
|
window.addEventListener("message", (t) => {
|
|
2414
|
-
t.source ===
|
|
2450
|
+
t.source === s.contentWindow && (e && t.origin !== e || typeof t.data != "object" || t.data.type !== "relay" || window.parent.postMessage(t.data, "*"));
|
|
2415
2451
|
}), window.addEventListener("message", (t) => {
|
|
2416
2452
|
var n;
|
|
2417
|
-
t.source === window.parent && (typeof t.data != "object" || t.data.type !== "relay" || (n =
|
|
2453
|
+
t.source === window.parent && (typeof t.data != "object" || t.data.type !== "relay" || (n = s == null ? void 0 : s.contentWindow) == null || n.postMessage(t.data));
|
|
2418
2454
|
});
|
|
2419
2455
|
}
|
|
2420
|
-
async function
|
|
2421
|
-
const e = new Worker(
|
|
2456
|
+
async function vt(s) {
|
|
2457
|
+
const e = new Worker(s, { type: "module" });
|
|
2422
2458
|
return new Promise((t, n) => {
|
|
2423
|
-
e.onerror = (
|
|
2459
|
+
e.onerror = (i) => {
|
|
2424
2460
|
const a = new Error(
|
|
2425
|
-
`WebWorker failed to load at ${
|
|
2461
|
+
`WebWorker failed to load at ${s}. ${i.message ? `Original error: ${i.message}` : ""}`
|
|
2426
2462
|
);
|
|
2427
|
-
a.filename =
|
|
2463
|
+
a.filename = i.filename, n(a);
|
|
2428
2464
|
};
|
|
2429
|
-
function r(
|
|
2430
|
-
|
|
2465
|
+
function r(i) {
|
|
2466
|
+
i.data === "worker-script-started" && (t(e), e.removeEventListener("message", r));
|
|
2431
2467
|
}
|
|
2432
2468
|
e.addEventListener("message", r);
|
|
2433
2469
|
});
|
|
2434
2470
|
}
|
|
2435
|
-
const
|
|
2436
|
-
function
|
|
2471
|
+
const dt = 1e3;
|
|
2472
|
+
function Mt(s, e = { initialSync: {} }) {
|
|
2437
2473
|
return e = {
|
|
2438
2474
|
...e,
|
|
2439
2475
|
initialSync: {
|
|
@@ -2441,24 +2477,24 @@ function Ut(i, e = { initialSync: {} }) {
|
|
|
2441
2477
|
direction: e.initialSync.direction ?? "opfs-to-memfs"
|
|
2442
2478
|
}
|
|
2443
2479
|
}, async function(t, n, r) {
|
|
2444
|
-
var
|
|
2480
|
+
var i, a, _, o;
|
|
2445
2481
|
if (e.initialSync.direction === "opfs-to-memfs") {
|
|
2446
|
-
|
|
2447
|
-
const S = ae(t,
|
|
2448
|
-
return (
|
|
2482
|
+
v.fileExists(n, r) && v.rmdir(n, r), v.mkdir(n, r), await ft(n, s, r);
|
|
2483
|
+
const S = ae(t, s, r);
|
|
2484
|
+
return (i = e.onMount) == null || i.call(e, S), S.unmount;
|
|
2449
2485
|
} else {
|
|
2450
|
-
const S = ae(t,
|
|
2486
|
+
const S = ae(t, s, r);
|
|
2451
2487
|
(a = e.onMount) == null || a.call(e, S);
|
|
2452
2488
|
let l;
|
|
2453
2489
|
try {
|
|
2454
|
-
await
|
|
2490
|
+
await ge(
|
|
2455
2491
|
n,
|
|
2456
|
-
|
|
2492
|
+
s,
|
|
2457
2493
|
r,
|
|
2458
|
-
async (
|
|
2494
|
+
async (h) => {
|
|
2459
2495
|
var A, u;
|
|
2460
2496
|
l = {
|
|
2461
|
-
...
|
|
2497
|
+
...h,
|
|
2462
2498
|
phase: "copying"
|
|
2463
2499
|
}, await ((u = (A = e.initialSync).onProgress) == null ? void 0 : u.call(A, l));
|
|
2464
2500
|
}
|
|
@@ -2466,45 +2502,45 @@ function Ut(i, e = { initialSync: {} }) {
|
|
|
2466
2502
|
files: (l == null ? void 0 : l.files) ?? 0,
|
|
2467
2503
|
total: (l == null ? void 0 : l.total) ?? 0,
|
|
2468
2504
|
phase: "flushing"
|
|
2469
|
-
})), S.flush().catch((
|
|
2505
|
+
})), S.flush().catch((h) => {
|
|
2470
2506
|
g.error("OPFS flush failed after initial sync", {
|
|
2471
|
-
error:
|
|
2507
|
+
error: h,
|
|
2472
2508
|
vfsMountPoint: r
|
|
2473
2509
|
});
|
|
2474
2510
|
});
|
|
2475
|
-
} catch (
|
|
2476
|
-
throw await S.unmount(),
|
|
2511
|
+
} catch (h) {
|
|
2512
|
+
throw await S.unmount(), h;
|
|
2477
2513
|
}
|
|
2478
2514
|
return S.unmount;
|
|
2479
2515
|
}
|
|
2480
2516
|
};
|
|
2481
2517
|
}
|
|
2482
|
-
async function
|
|
2483
|
-
|
|
2484
|
-
const n = new
|
|
2518
|
+
async function ft(s, e, t) {
|
|
2519
|
+
v.mkdir(s, t);
|
|
2520
|
+
const n = new Ue({
|
|
2485
2521
|
concurrency: 40
|
|
2486
|
-
}), r = [],
|
|
2522
|
+
}), r = [], i = [
|
|
2487
2523
|
[e, t]
|
|
2488
2524
|
];
|
|
2489
|
-
for (;
|
|
2490
|
-
const [a, _] =
|
|
2525
|
+
for (; i.length > 0; ) {
|
|
2526
|
+
const [a, _] = i.pop();
|
|
2491
2527
|
for await (const o of a.values()) {
|
|
2492
2528
|
const S = n.run(async () => {
|
|
2493
|
-
const l =
|
|
2529
|
+
const l = he(
|
|
2494
2530
|
_,
|
|
2495
2531
|
o.name
|
|
2496
2532
|
);
|
|
2497
2533
|
if (o.kind === "directory") {
|
|
2498
2534
|
try {
|
|
2499
|
-
|
|
2500
|
-
} catch (
|
|
2501
|
-
if ((
|
|
2502
|
-
throw g.error(
|
|
2535
|
+
s.mkdir(l);
|
|
2536
|
+
} catch (h) {
|
|
2537
|
+
if ((h == null ? void 0 : h.errno) !== 20)
|
|
2538
|
+
throw g.error(h), h;
|
|
2503
2539
|
}
|
|
2504
|
-
|
|
2540
|
+
i.push([o, l]);
|
|
2505
2541
|
} else if (o.kind === "file") {
|
|
2506
|
-
const
|
|
2507
|
-
|
|
2542
|
+
const h = await o.getFile(), A = new Uint8Array(await h.arrayBuffer());
|
|
2543
|
+
s.createDataFile(
|
|
2508
2544
|
_,
|
|
2509
2545
|
o.name,
|
|
2510
2546
|
A,
|
|
@@ -2517,44 +2553,44 @@ async function At(i, e, t) {
|
|
|
2517
2553
|
});
|
|
2518
2554
|
r.push(S);
|
|
2519
2555
|
}
|
|
2520
|
-
for (;
|
|
2556
|
+
for (; i.length === 0 && r.length > 0; )
|
|
2521
2557
|
await Promise.any(r);
|
|
2522
2558
|
}
|
|
2523
2559
|
}
|
|
2524
|
-
async function
|
|
2525
|
-
|
|
2560
|
+
async function ge(s, e, t, n) {
|
|
2561
|
+
s.mkdirTree(t);
|
|
2526
2562
|
const r = [];
|
|
2527
|
-
async function
|
|
2563
|
+
async function i(l, h) {
|
|
2528
2564
|
await Promise.all(
|
|
2529
|
-
|
|
2565
|
+
s.readdir(l).filter(
|
|
2530
2566
|
(A) => A !== "." && A !== ".."
|
|
2531
2567
|
).map(async (A) => {
|
|
2532
|
-
const u =
|
|
2533
|
-
if (!
|
|
2534
|
-
r.push([
|
|
2568
|
+
const u = he(l, A);
|
|
2569
|
+
if (!Et(s, u)) {
|
|
2570
|
+
r.push([h, u, A]);
|
|
2535
2571
|
return;
|
|
2536
2572
|
}
|
|
2537
|
-
const d = await
|
|
2573
|
+
const d = await h.getDirectoryHandle(A, {
|
|
2538
2574
|
create: !0
|
|
2539
2575
|
});
|
|
2540
|
-
return await
|
|
2576
|
+
return await i(u, d);
|
|
2541
2577
|
})
|
|
2542
2578
|
);
|
|
2543
2579
|
}
|
|
2544
|
-
await
|
|
2580
|
+
await i(t, e);
|
|
2545
2581
|
let a = 0;
|
|
2546
2582
|
await (n == null ? void 0 : n({
|
|
2547
2583
|
files: a,
|
|
2548
2584
|
total: r.length
|
|
2549
2585
|
}));
|
|
2550
|
-
const _ = n &&
|
|
2586
|
+
const _ = n && wt(n, 100), o = 100, S = /* @__PURE__ */ new Set();
|
|
2551
2587
|
try {
|
|
2552
|
-
for (const [l,
|
|
2553
|
-
const u =
|
|
2588
|
+
for (const [l, h, A] of r) {
|
|
2589
|
+
const u = G(
|
|
2554
2590
|
l,
|
|
2555
2591
|
A,
|
|
2556
|
-
|
|
2557
|
-
|
|
2592
|
+
s,
|
|
2593
|
+
h
|
|
2558
2594
|
).then(() => {
|
|
2559
2595
|
a++, S.delete(u), _ == null || _({
|
|
2560
2596
|
files: a,
|
|
@@ -2574,10 +2610,10 @@ async function Le(i, e, t, n) {
|
|
|
2574
2610
|
total: r.length
|
|
2575
2611
|
}));
|
|
2576
2612
|
}
|
|
2577
|
-
function
|
|
2578
|
-
return
|
|
2613
|
+
function Et(s, e) {
|
|
2614
|
+
return s.isDir(s.lookupPath(e, { follow: !0 }).node.mode);
|
|
2579
2615
|
}
|
|
2580
|
-
async function
|
|
2616
|
+
async function G(s, e, t, n) {
|
|
2581
2617
|
let r;
|
|
2582
2618
|
try {
|
|
2583
2619
|
r = t.readFile(n, {
|
|
@@ -2586,12 +2622,12 @@ async function $(i, e, t, n) {
|
|
|
2586
2622
|
} catch {
|
|
2587
2623
|
return;
|
|
2588
2624
|
}
|
|
2589
|
-
const
|
|
2625
|
+
const i = await s.getFileHandle(e, { create: !0 }), a = i.createWritable !== void 0 ? (
|
|
2590
2626
|
// Google Chrome, Firefox, probably more browsers
|
|
2591
|
-
await
|
|
2627
|
+
await i.createWritable()
|
|
2592
2628
|
) : (
|
|
2593
2629
|
// Safari
|
|
2594
|
-
await
|
|
2630
|
+
await i.createSyncAccessHandle()
|
|
2595
2631
|
);
|
|
2596
2632
|
try {
|
|
2597
2633
|
await a.truncate(0), await a.write(r);
|
|
@@ -2599,13 +2635,13 @@ async function $(i, e, t, n) {
|
|
|
2599
2635
|
await a.close();
|
|
2600
2636
|
}
|
|
2601
2637
|
}
|
|
2602
|
-
function ae(
|
|
2603
|
-
const r = [],
|
|
2638
|
+
function ae(s, e, t, n = {}) {
|
|
2639
|
+
const r = [], i = ke(s, t, (u) => {
|
|
2604
2640
|
r.push(u);
|
|
2605
|
-
}), a = new
|
|
2641
|
+
}), a = new Tt(s, e, t);
|
|
2606
2642
|
let _;
|
|
2607
2643
|
function o() {
|
|
2608
|
-
return _ === void 0 && (_ =
|
|
2644
|
+
return _ === void 0 && (_ = h().finally(() => {
|
|
2609
2645
|
_ = void 0;
|
|
2610
2646
|
})), _;
|
|
2611
2647
|
}
|
|
@@ -2613,7 +2649,7 @@ function ae(i, e, t, n = {}) {
|
|
|
2613
2649
|
try {
|
|
2614
2650
|
await o();
|
|
2615
2651
|
} finally {
|
|
2616
|
-
|
|
2652
|
+
i(), s.removeEventListener("request.end", l), s.removeEventListener("filesystem.write", l);
|
|
2617
2653
|
}
|
|
2618
2654
|
}
|
|
2619
2655
|
function l() {
|
|
@@ -2621,8 +2657,8 @@ function ae(i, e, t, n = {}) {
|
|
|
2621
2657
|
g.error(u);
|
|
2622
2658
|
});
|
|
2623
2659
|
}
|
|
2624
|
-
async function
|
|
2625
|
-
const u = n.maxFlushPasses ??
|
|
2660
|
+
async function h() {
|
|
2661
|
+
const u = n.maxFlushPasses ?? dt;
|
|
2626
2662
|
for (let d = 0; r.length > 0; d++) {
|
|
2627
2663
|
if (d >= u) {
|
|
2628
2664
|
const m = r.length, b = m === 1 ? `${m} journal entry remains` : `${m} journal entries remain`;
|
|
@@ -2636,9 +2672,9 @@ function ae(i, e, t, n = {}) {
|
|
|
2636
2672
|
async function A() {
|
|
2637
2673
|
if (r.length === 0)
|
|
2638
2674
|
return;
|
|
2639
|
-
const u = await
|
|
2675
|
+
const u = await s.semaphore.acquire(), d = [...r];
|
|
2640
2676
|
r.splice(0, d.length);
|
|
2641
|
-
const m =
|
|
2677
|
+
const m = qe(d);
|
|
2642
2678
|
try {
|
|
2643
2679
|
for (const b of m)
|
|
2644
2680
|
await a.processEntry(b);
|
|
@@ -2646,12 +2682,12 @@ function ae(i, e, t, n = {}) {
|
|
|
2646
2682
|
u();
|
|
2647
2683
|
}
|
|
2648
2684
|
}
|
|
2649
|
-
return
|
|
2685
|
+
return s.addEventListener("request.end", l), s.addEventListener("filesystem.write", l), {
|
|
2650
2686
|
flush: o,
|
|
2651
2687
|
unmount: S
|
|
2652
2688
|
};
|
|
2653
2689
|
}
|
|
2654
|
-
class
|
|
2690
|
+
class Tt {
|
|
2655
2691
|
constructor(e, t, n) {
|
|
2656
2692
|
this.php = e, this.opfs = t, this.memfsRoot = _e(n);
|
|
2657
2693
|
}
|
|
@@ -2661,7 +2697,7 @@ class dt {
|
|
|
2661
2697
|
async processEntry(e) {
|
|
2662
2698
|
if (!e.path.startsWith(this.memfsRoot) || e.path === this.memfsRoot)
|
|
2663
2699
|
return;
|
|
2664
|
-
const t = this.toOpfsPath(e.path), n = await oe(this.opfs, t), r =
|
|
2700
|
+
const t = this.toOpfsPath(e.path), n = await oe(this.opfs, t), r = pt(t);
|
|
2665
2701
|
if (r)
|
|
2666
2702
|
try {
|
|
2667
2703
|
if (e.operation === "DELETE")
|
|
@@ -2678,16 +2714,16 @@ class dt {
|
|
|
2678
2714
|
create: !0
|
|
2679
2715
|
});
|
|
2680
2716
|
else if (e.operation === "WRITE")
|
|
2681
|
-
await
|
|
2717
|
+
await G(
|
|
2682
2718
|
n,
|
|
2683
2719
|
r,
|
|
2684
2720
|
this.php[O].FS,
|
|
2685
2721
|
e.path
|
|
2686
2722
|
);
|
|
2687
2723
|
else if (e.operation === "RENAME" && e.toPath.startsWith(this.memfsRoot)) {
|
|
2688
|
-
const
|
|
2724
|
+
const i = this.toOpfsPath(e.toPath), a = await oe(
|
|
2689
2725
|
this.opfs,
|
|
2690
|
-
|
|
2726
|
+
i
|
|
2691
2727
|
);
|
|
2692
2728
|
if (e.nodeType === "directory") {
|
|
2693
2729
|
const _ = await a.getDirectoryHandle(
|
|
@@ -2696,7 +2732,7 @@ class dt {
|
|
|
2696
2732
|
create: !0
|
|
2697
2733
|
}
|
|
2698
2734
|
);
|
|
2699
|
-
await
|
|
2735
|
+
await ge(
|
|
2700
2736
|
this.php[O].FS,
|
|
2701
2737
|
_,
|
|
2702
2738
|
e.toPath
|
|
@@ -2708,40 +2744,40 @@ class dt {
|
|
|
2708
2744
|
await n.removeEntry(r);
|
|
2709
2745
|
} catch {
|
|
2710
2746
|
}
|
|
2711
|
-
await
|
|
2747
|
+
await G(
|
|
2712
2748
|
a,
|
|
2713
|
-
|
|
2749
|
+
xe(i),
|
|
2714
2750
|
this.php[O].FS,
|
|
2715
2751
|
e.toPath
|
|
2716
2752
|
);
|
|
2717
2753
|
}
|
|
2718
2754
|
}
|
|
2719
|
-
} catch (
|
|
2720
|
-
throw g.log({ entry: e, name: r }), g.error(
|
|
2755
|
+
} catch (i) {
|
|
2756
|
+
throw g.log({ entry: e, name: r }), g.error(i), i;
|
|
2721
2757
|
}
|
|
2722
2758
|
}
|
|
2723
2759
|
}
|
|
2724
|
-
function _e(
|
|
2725
|
-
return
|
|
2760
|
+
function _e(s) {
|
|
2761
|
+
return s.replace(/\/$/, "").replace(/\/\/+/g, "/");
|
|
2726
2762
|
}
|
|
2727
|
-
function
|
|
2728
|
-
return
|
|
2763
|
+
function pt(s) {
|
|
2764
|
+
return s.substring(s.lastIndexOf("/") + 1);
|
|
2729
2765
|
}
|
|
2730
|
-
async function oe(
|
|
2766
|
+
async function oe(s, e) {
|
|
2731
2767
|
const t = e.replace(/^\/+|\/+$/g, "").replace(/\/+/, "/");
|
|
2732
2768
|
if (!t)
|
|
2733
|
-
return
|
|
2769
|
+
return s;
|
|
2734
2770
|
const n = t.split("/");
|
|
2735
|
-
let r =
|
|
2736
|
-
for (let
|
|
2737
|
-
const a = n[
|
|
2771
|
+
let r = s;
|
|
2772
|
+
for (let i = 0; i < n.length - 1; i++) {
|
|
2773
|
+
const a = n[i];
|
|
2738
2774
|
r = await r.getDirectoryHandle(a, { create: !0 });
|
|
2739
2775
|
}
|
|
2740
2776
|
return r;
|
|
2741
2777
|
}
|
|
2742
|
-
function
|
|
2778
|
+
function wt(s, e) {
|
|
2743
2779
|
let t = 0, n, r;
|
|
2744
|
-
const
|
|
2780
|
+
const i = function(..._) {
|
|
2745
2781
|
r = _;
|
|
2746
2782
|
const o = Date.now() - t;
|
|
2747
2783
|
if (n === void 0) {
|
|
@@ -2751,34 +2787,34 @@ function Et(i, e) {
|
|
|
2751
2787
|
const l = r;
|
|
2752
2788
|
r = void 0;
|
|
2753
2789
|
try {
|
|
2754
|
-
Promise.resolve(
|
|
2790
|
+
Promise.resolve(s(...l)).catch(
|
|
2755
2791
|
ce
|
|
2756
2792
|
);
|
|
2757
|
-
} catch (
|
|
2758
|
-
ce(
|
|
2793
|
+
} catch (h) {
|
|
2794
|
+
ce(h);
|
|
2759
2795
|
}
|
|
2760
2796
|
}, S);
|
|
2761
2797
|
}
|
|
2762
2798
|
};
|
|
2763
|
-
return
|
|
2799
|
+
return i.cancel = () => {
|
|
2764
2800
|
n !== void 0 && clearTimeout(n), n = void 0, r = void 0;
|
|
2765
|
-
},
|
|
2801
|
+
}, i;
|
|
2766
2802
|
}
|
|
2767
|
-
function ce(
|
|
2768
|
-
g.error("Throttled progress callback failed", { error:
|
|
2803
|
+
function ce(s) {
|
|
2804
|
+
g.error("Throttled progress callback failed", { error: s });
|
|
2769
2805
|
}
|
|
2770
2806
|
export {
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2807
|
+
jt as FirewallInterferenceError,
|
|
2808
|
+
bt as certificateToPEM,
|
|
2809
|
+
qt as consumeAPI,
|
|
2810
|
+
Mt as createDirectoryHandleMountHandler,
|
|
2811
|
+
Ft as exposeAPI,
|
|
2812
|
+
$t as fetchWithCorsProxy,
|
|
2813
|
+
nt as generateCertificate,
|
|
2814
|
+
je as getPHPLoaderModule,
|
|
2815
|
+
Ut as loadWebRuntime,
|
|
2816
|
+
Rt as privateKeyToPEM,
|
|
2817
|
+
xt as setupPostMessageRelay,
|
|
2818
|
+
vt as spawnPHPWorkerThread
|
|
2783
2819
|
};
|
|
2784
2820
|
//# sourceMappingURL=index.js.map
|