src/node/socket.ts/SocketProxyProvider/createProxy
class SocketProxyProvider:  public async createProxy(socket: tls.TLSSocket | net.Socket | stream.Duplex): Promise<net.Socket | stream.Duplex> {
    if (!(socket instanceof tls.TLSSocket)) {
      return socket
    }

    await this.startProxyServer()

    return new Promise((resolve, reject) => {
      const id = generateUuid()
      const proxy = net.connect(this.proxyPipe)
      proxy.once("connect", () => proxy.write(id))

      const timeout = setTimeout(() => {
        listener.dispose() // eslint-disable-line @typescript-eslint/no-use-before-define
        socket.destroy()
        proxy.destroy()
        reject(new Error("TLS socket proxy timed out"))
      }, this.proxyTimeout)

      const listener = this.onProxyConnect.event((connection) => {
        connection.once("data", (data) => {
          if (!socket.destroyed && !proxy.destroyed && data.toString() === id) {
            clearTimeout(timeout)
            listener.dispose()
            ;[
              [proxy, socket],
              [socket, proxy],
            ].forEach(([a, b]) => {
              a.pipe(b)
              a.on("error", () => b.destroy())
              a.on("close", () => b.destroy())
              a.on("end", () => b.end())
            })
            resolve(connection)
          }
        })
      })
    })
  }