@php-wasm/web 1.1.3 → 1.1.5

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