@mercuryworkshop/epoxy-transport 1.0.2 → 2.0.0
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 +621 -495
- package/dist/module.js +621 -495
- package/package.json +3 -3
- package/src/main.ts +22 -12
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mercuryworkshop/epoxy-transport",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
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,5 +1,7 @@
|
|
|
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
6
|
canstart = true;
|
|
5
7
|
epxclient: Awaited<ReturnType<any>>["EpoxyClient"]["prototype"] = null!;
|
|
@@ -8,9 +10,12 @@ export class EpoxyClient implements BareTransport {
|
|
|
8
10
|
constructor({ wisp }) {
|
|
9
11
|
this.wisp = wisp;
|
|
10
12
|
}
|
|
11
|
-
async init() {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
async init() {
|
|
14
|
+
const { EpoxyClient, EpoxyClientOptions } = await epoxy();
|
|
15
|
+
|
|
16
|
+
let options = new EpoxyClientOptions();
|
|
17
|
+
options.user_agent = navigator.userAgent;
|
|
18
|
+
this.epxclient = await new EpoxyClient(this.wisp, ROOTS, options);
|
|
14
19
|
|
|
15
20
|
this.ready = true;
|
|
16
21
|
}
|
|
@@ -26,14 +31,19 @@ export class EpoxyClient implements BareTransport {
|
|
|
26
31
|
): Promise<TransferrableResponse> {
|
|
27
32
|
if (body instanceof Blob)
|
|
28
33
|
body = await body.arrayBuffer();
|
|
29
|
-
let payload = await this.epxclient.fetch(remote.href, { method, body, headers, redirect: "manual" });
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
try {
|
|
36
|
+
let payload = await this.epxclient.fetch(remote.href, { method, body, headers, redirect: "manual" });
|
|
37
|
+
return {
|
|
38
|
+
body: payload.body!,
|
|
39
|
+
headers: (payload as any).rawHeaders,
|
|
40
|
+
status: payload.status,
|
|
41
|
+
statusText: payload.statusText,
|
|
42
|
+
};
|
|
43
|
+
} catch (err) {
|
|
44
|
+
console.error(err);
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
37
47
|
}
|
|
38
48
|
|
|
39
49
|
connect(
|
|
@@ -57,7 +67,7 @@ export class EpoxyClient implements BareTransport {
|
|
|
57
67
|
);
|
|
58
68
|
|
|
59
69
|
return async (data) => {
|
|
60
|
-
|
|
61
|
-
}
|
|
70
|
+
await epsocket.send(data);
|
|
71
|
+
}
|
|
62
72
|
}
|
|
63
73
|
}
|