@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/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "@mercuryworkshop/epoxy-transport",
3
- "version": "1.1.0",
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": "^1.4.1",
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
- canstart = true;
5
- epxclient: Awaited<ReturnType<any>>["EpoxyClient"]["prototype"] = null!;
6
- wisp: string;
6
+ canstart = true;
7
+ epxclient: Awaited<ReturnType<any>>["EpoxyClient"]["prototype"] = null!;
8
+ wisp: string;
7
9
 
8
- constructor({ wisp }) {
9
- this.wisp = wisp;
10
- }
11
- async init() {
12
- let { EpoxyClient } = await epoxy();
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
- this.ready = true;
16
- }
17
- ready = false;
18
- async meta() { }
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
- async request(
21
- remote: URL,
22
- method: string,
23
- body: BodyInit | null,
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
- try {
31
- let payload = await this.epxclient.fetch(remote.href, { method, body, headers, redirect: "manual" });
32
- return {
33
- body: payload.body!,
34
- headers: (payload as any).rawHeaders,
35
- status: payload.status,
36
- statusText: payload.statusText,
37
- };
38
- } catch (err) {
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
- connect(
45
- url: URL,
46
- origin: string,
47
- protocols: string[],
48
- requestHeaders: BareHeaders,
49
- onopen: (protocol: string) => void,
50
- onmessage: (data: Blob | ArrayBuffer | string) => void,
51
- onclose: (code: number, reason: string) => void,
52
- onerror: (error: string) => void,
53
- ): (data: Blob | ArrayBuffer | string) => void {
54
- let epsocket = this.epxclient.connect_ws(
55
- onopen,
56
- onclose,
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
- return async (data) => {
65
- if (typeof data === 'string') {
66
- (await epsocket).send_text(data);
67
- } else {
68
- (await epsocket).send_binary(data);
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
  }