diff --git a/README.md b/README.md index 130f460..c5bd052 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,7 @@ # epoxy -Epoxy is an encrypted proxy for browser javascript. It allows you to make requests that bypass CORS without compromising security, by running SSL/TLS inside webassembly. +Epoxy is an encrypted proxy for browser javascript. +It allows you to make requests that bypass CORS without compromising security by running SSL/TLS inside webassembly and using the [Wisp protocol](https://github.com/mercuryworkshop/wisp-protocol/) to proxy TCP connections. -## Using the client -Here is a simple usage example: -```javascript -import epoxy from "./epoxy-module-bundled.js"; +It also has a Wisp library implementation for Rust and a performant Wisp server built in Rust. -const { EpoxyClient, EpoxyClientOptions } = await epoxy(); - -let options = new EpoxyClientOptions(); -options.user_agent = navigator.userAgent; - -let client = await new EpoxyClient("wss://localhost:4000", options); - -let response = await client.fetch("https://httpbin.org/get"); -console.log(await response.text()); -``` -See `client/demo.js` for more examples. - -## Using the server -See the [server readme](server/README.md). - -## Building - -### Server -See the [server readme](server/README.md). - -### Client -> [!IMPORTANT] -> Building the client is only supported on Linux. - -Make sure you have the `wasm32-unknown-unknown` rust target, the `rust-std` component, and the `wasm-bindgen`, `wasm-opt`, `jq`, and `base64` binaries installed. - -In the `client` directory: -``` -bash build.sh -``` - -To host a local server: -``` -python3 -m http.server -``` +See the [client readme](client/README.md) and [server readme](server/README.md) for instructions on how to build and use them. diff --git a/client/.npmignore b/client/.npmignore index 5ae40d6..c7bb833 100644 --- a/client/.npmignore +++ b/client/.npmignore @@ -7,3 +7,4 @@ demo.js serve.py build.sh publish.sh +README.md diff --git a/client/README.md b/client/README.md new file mode 100644 index 0000000..3068997 --- /dev/null +++ b/client/README.md @@ -0,0 +1,61 @@ +# epoxy-client +Fetch and WebSocket implementation for the browser written in Rust that uses the Wisp protocol. + +## Building +> [!IMPORTANT] +> Rust nightly with the `wasm32-unknown-unknown` target and `rust-std` component is required. + +The build script needs some dependencies: +- `wasm-bindgen`: installable through cargo +- `wasm-opt`: get from [WebAssembly/binaryen](https://github.com/webassembly/binaryen) +- `jq`: install from your distro's repos +- `git`: install from your distro's repos + +```bash +bash build.sh +``` +The WASM binary and JS bindings will be placed in `pkg`. + +## Usage +Examples are available in [`demo.js`](demo.js). + +```js +import init, { EpoxyClient, EpoxyClientOptions, EpoxyHandlers } from "@mercuryworkshop/epoxy-tls/epoxy"; + +// you can also pass in the wasm after fetching it. see the typescript types for all options +await init({ module_or_path: "path/to/epoxy.wasm" }); + +// or you can import "@mercuryworkshop/epoxy-tls" or "@mercuryworkshop/epoxy-tls/epoxy-bundled" +// those versions have the wasm bundled into the JS as base64 so you don't need to pass anything to init() +// +// there is also a minimal version with only HTTP/1 fetch and TLS/TCP/UDP streams if you want a smaller +// bundle size. those can be imported via "@mercuryworkshop/epoxy-tls/minimal" and "minimal-bundled" + +const options = new EpoxyClientOptions(); +options.user_agent = navigator.userAgent; +options.wisp_v2 = true; +options.udp_extension_required = true; + +// use your own selfhosted wisp server, this is the demo one with throttling +const client = new EpoxyClient("wss://wisp.mercurywork.shop", options); + +const res = await client.fetch("https://example.com"); +console.log(res.headers, res.rawHeaders); +console.log(await res.text()); + +// not available in the minimal version +let handlers = new EpoxyHandlers( + () => console.log("opened"), + () => console.log("closed"), + err => console.error(err), + msg => console.log(`got "${msg}"`) +); +let ws = await client.connect_websocket( + handlers, + "wss://echo.websocket.events", + ["protocol1"], + { "x-header": "abc" }, +); + +await ws.send("data"); +``` diff --git a/server/README.md b/server/README.md index dbcedfd..9d97570 100644 --- a/server/README.md +++ b/server/README.md @@ -1,13 +1,11 @@ # `epoxy-server` -Performant server implementation of the Wisp protocol in Rust, made for epoxy. +Performant server implementation of the Wisp protocol in Rust, made for epoxy-client. You can view a recent flamegraph of the server under load [here](flamegraph.svg?raw=true). ## Building -> [!IMPORTANT] -> Rust nightly is required. -``` +```bash cargo b -r ``` The executable will be placed at `target/release/epoxy-server`.