@mercuryworkshop/epoxy-transport 1.1.0 → 2.0.1
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/README.md +11 -0
- package/dist/index.js +505 -562
- package/dist/module.js +505 -562
- package/package.json +3 -3
- package/src/main.ts +64 -62
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mercuryworkshop/epoxy-transport",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "a bare transport that implements end-to-end encryption with epoxy-tls and wisp",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"keywords": [],
|
|
7
7
|
"author": "",
|
|
8
8
|
"type": "module",
|
|
9
|
-
"license": "LGPL",
|
|
10
9
|
"scripts": {
|
|
11
10
|
"build": "node esbuild.bundle.mjs"
|
|
12
11
|
},
|
|
13
12
|
"dependencies": {
|
|
14
|
-
"@mercuryworkshop/epoxy-tls": "^
|
|
13
|
+
"@mercuryworkshop/epoxy-tls": "^2.0.0-3",
|
|
15
14
|
"esbuild-plugin-umd-wrapper": "^2.0.0",
|
|
16
15
|
"rollup": "^4.12.0",
|
|
17
16
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
@@ -19,6 +18,7 @@
|
|
|
19
18
|
"ws": "8.16.0"
|
|
20
19
|
},
|
|
21
20
|
"devDependencies": {
|
|
21
|
+
"@mercuryworkshop/bare-mux": "^1.1.1",
|
|
22
22
|
"esbuild": "^0.19.11",
|
|
23
23
|
"esbuild-plugin-d.ts": "^1.2.2"
|
|
24
24
|
},
|
package/src/main.ts
CHANGED
|
@@ -1,72 +1,74 @@
|
|
|
1
1
|
import { BareHeaders, BareResponse, TransferrableResponse, type BareTransport } from "@mercuryworkshop/bare-mux";
|
|
2
2
|
import epoxy from "@mercuryworkshop/epoxy-tls";
|
|
3
|
+
//@ts-expect-error typescript doesnt follow the npm exports for some reason
|
|
4
|
+
import ROOTS from "@mercuryworkshop/epoxy-tls/certs"
|
|
3
5
|
export class EpoxyClient implements BareTransport {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
canstart = true;
|
|
7
|
+
epxclient: Awaited<ReturnType<any>>["EpoxyClient"]["prototype"] = null!;
|
|
8
|
+
wisp: string;
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.epxclient = await new EpoxyClient(this.wisp, navigator.userAgent, 10);
|
|
10
|
+
constructor({ wisp }) {
|
|
11
|
+
this.wisp = wisp;
|
|
12
|
+
}
|
|
13
|
+
async init() {
|
|
14
|
+
const { EpoxyClient, EpoxyClientOptions } = await epoxy();
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
let options = new EpoxyClientOptions();
|
|
17
|
+
options.user_agent = navigator.userAgent;
|
|
18
|
+
options.udp_extension_required = false;
|
|
19
|
+
this.epxclient = await new EpoxyClient(this.wisp, ROOTS, options);
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
headers: BareHeaders,
|
|
25
|
-
signal: AbortSignal | undefined
|
|
26
|
-
): Promise<TransferrableResponse> {
|
|
27
|
-
if (body instanceof Blob)
|
|
28
|
-
body = await body.arrayBuffer();
|
|
21
|
+
this.ready = true;
|
|
22
|
+
}
|
|
23
|
+
ready = false;
|
|
24
|
+
async meta() { }
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
console.error(err);
|
|
40
|
-
throw err;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
26
|
+
async request(
|
|
27
|
+
remote: URL,
|
|
28
|
+
method: string,
|
|
29
|
+
body: BodyInit | null,
|
|
30
|
+
headers: BareHeaders,
|
|
31
|
+
signal: AbortSignal | undefined
|
|
32
|
+
): Promise<TransferrableResponse> {
|
|
33
|
+
if (body instanceof Blob)
|
|
34
|
+
body = await body.arrayBuffer();
|
|
43
35
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
onerror,
|
|
58
|
-
(data: Uint8Array | string) => data instanceof Uint8Array ? onmessage(data.buffer) : onmessage(data),
|
|
59
|
-
url.href,
|
|
60
|
-
protocols,
|
|
61
|
-
origin,
|
|
62
|
-
);
|
|
36
|
+
try {
|
|
37
|
+
let payload = await this.epxclient.fetch(remote.href, { method, body, headers, redirect: "manual" });
|
|
38
|
+
return {
|
|
39
|
+
body: payload.body!,
|
|
40
|
+
headers: (payload as any).rawHeaders,
|
|
41
|
+
status: payload.status,
|
|
42
|
+
statusText: payload.statusText,
|
|
43
|
+
};
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.error(err);
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
63
49
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
50
|
+
connect(
|
|
51
|
+
url: URL,
|
|
52
|
+
origin: string,
|
|
53
|
+
protocols: string[],
|
|
54
|
+
requestHeaders: BareHeaders,
|
|
55
|
+
onopen: (protocol: string) => void,
|
|
56
|
+
onmessage: (data: Blob | ArrayBuffer | string) => void,
|
|
57
|
+
onclose: (code: number, reason: string) => void,
|
|
58
|
+
onerror: (error: string) => void,
|
|
59
|
+
): (data: Blob | ArrayBuffer | string) => void {
|
|
60
|
+
let epsocket = this.epxclient.connect_ws(
|
|
61
|
+
onopen,
|
|
62
|
+
onclose,
|
|
63
|
+
onerror,
|
|
64
|
+
(data: Uint8Array | string) => data instanceof Uint8Array ? onmessage(data.buffer) : onmessage(data),
|
|
65
|
+
url.href,
|
|
66
|
+
protocols,
|
|
67
|
+
origin,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return async (data) => {
|
|
71
|
+
await epsocket.send(data);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
72
74
|
}
|