Zero-copy Tor protocol for the web 🏎️ (JS + WebAssembly)
npm i @hazae41/echalote
Node Package 📦 • Online Demo 🌐 • Next.js CodeSandbox 🪣
This is experimental software in early development
import { createWebSocketSnowflakeStream, TorClientDuplex, Consensus } from "@hazae41/echalote"
import { Ciphers, TlsClientDuplex } from "@hazae41/cadenas"
const tcp = await createWebSocketSnowflakeStream("wss://snowflake.bamsoftware.com/")
const tor = new TorClientDuplex()
tcp.outer.readable.pipeTo(tor.inner.writable).catch(() => {})
tor.inner.readable.pipeTo(tcp.outer.writable).catch(() => {})
await tor.waitOrThrow()
using circuit = await tor.createOrThrow()
const consensus = await Consensus.fetchOrThrow(circuit)
const middles = consensus.microdescs.filter(it => true
&& it.flags.includes("Fast")
&& it.flags.includes("Stable")
&& it.flags.includes("V2Dir"))
const exits = consensus.microdescs.filter(it => true
&& it.flags.includes("Fast")
&& it.flags.includes("Stable")
&& it.flags.includes("Exit")
&& !it.flags.includes("BadExit"))
const middle = middles[Math.floor(Math.random() * middles.length)]
const middle2 = await Consensus.Microdesc.fetchOrThrow(circuit, middle)
await circuit.extendOrThrow(middle2, AbortSignal.timeout(5000))
const exit = exits[Math.floor(Math.random() * middles.length)]
const exit2 = await Consensus.Microdesc.fetchOrThrow(circuit, exit)
await circuit.extendOrThrow(exit2, AbortSignal.timeout(5000))
const ttcp = await circuit.openOrThrow("twitter.com", 443)
const ciphers = [Ciphers.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384]
const ttls = new TlsClientDuplex({ host_name: url.hostname, ciphers })
ttcp.outer.readable.pipeTo(ttls.inner.writable).catch(() => { })
ttls.inner.readable.pipeTo(ttcp.outer.writable).catch(() => { })
const response = await fetch("https://twitter.com", { stream: ttls.outer })
const text = await response.text()