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