{"id":51121827,"url":"https://github.com/tegmentum/ws-gateway-server","last_synced_at":"2026-06-25T03:30:32.433Z","repository":{"id":361703251,"uuid":"1255459850","full_name":"tegmentum/ws-gateway-server","owner":"tegmentum","description":"Reference Node WebSocket server for the KSW1 protocol — bridges browser-hosted wasi-polyfill (TCP + PKCS#11 tunnels) to real host resources.","archived":false,"fork":false,"pushed_at":"2026-05-31T21:28:42.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-31T23:17:42.439Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tegmentum.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-31T21:17:14.000Z","updated_at":"2026-05-31T21:28:45.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tegmentum/ws-gateway-server","commit_stats":null,"previous_names":["tegmentum/ws-gateway-server"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/tegmentum/ws-gateway-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tegmentum%2Fws-gateway-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tegmentum%2Fws-gateway-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tegmentum%2Fws-gateway-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tegmentum%2Fws-gateway-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tegmentum","download_url":"https://codeload.github.com/tegmentum/ws-gateway-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tegmentum%2Fws-gateway-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34758773,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-25T02:00:05.521Z","response_time":101,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-25T03:30:31.818Z","updated_at":"2026-06-25T03:30:32.416Z","avatar_url":"https://github.com/tegmentum.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @tegmentum/ws-gateway-server\n\nReference Node server for the **KSW1** (KeyStone WebSocket v1) protocol used by [`@tegmentum/wasi-polyfill`](https://github.com/tegmentum/wasi-polyfill). Lets a browser-hosted wasm component reach real host resources — TCP sockets and PKCS#11 HSM tokens — through a single WebSocket.\n\nBuilt as part of the [tegmentum/openssl-wasm](https://github.com/tegmentum/openssl-wasm) component stack; usable standalone for any project that needs the same browser↔host bridge.\n\n## What it does\n\n| Browser side (wasi-polyfill)          | This server                       | Reaches                            |\n|---------------------------------------|-----------------------------------|------------------------------------|\n| TCP socket via `wasi:sockets/tcp`     | `net.createConnection`            | Any host:port                      |\n| DNS lookup via `wasi:sockets/ip-name-lookup` | `dns.lookup`               | System resolver                    |\n| PKCS#11 calls via `tegmentum:pkcs11-tunnel` | `pkcs11js` → `libpkcs11.so` | SoftHSM / YubiHSM / Luna / any module |\n\nMultiplexes many concurrent streams over one WebSocket; half-close + DnsQuery + Pkcs11 framing all on the same wire.\n\n## Install\n\n```sh\nnpm install @tegmentum/ws-gateway-server\n# optional, for PKCS#11 backend:\nnpm install pkcs11js\n```\n\n## Use — CLI\n\n```sh\n# Stub PKCS#11 backend (proves the wire format works without a token):\nnpx ws-gateway-server\n\n# Real PKCS#11 backend against SoftHSM (or any libpkcs11):\nPKCS11_BACKEND=pkcs11js \\\nPKCS11_LIB=$(brew --prefix)/lib/softhsm/libsofthsm2.so \\\n  npx ws-gateway-server\n```\n\nListens on `ws://127.0.0.1:8088/ws` by default. Override with `GATEWAY_HOST` / `GATEWAY_PORT` / `GATEWAY_PATH`.\n\n## Use — Programmatic\n\n```js\nimport { startGateway } from '@tegmentum/ws-gateway-server'\n\nconst gw = await startGateway({\n  port: 9000,\n  // Optional: a custom Pkcs11 backend object. Defaults to env-driven\n  // (PKCS11_BACKEND=stub by default, or PKCS11_BACKEND=pkcs11js +\n  // PKCS11_LIB for a real module).\n})\n\n// gw.address  -\u003e \"ws://127.0.0.1:9000/ws\"\n// gw.close()  -\u003e stop listening; returns Promise\u003cvoid\u003e\n```\n\nFor a custom Pkcs11 backend implementation, look at `src/pkcs11-backend.mjs` for the stub + pkcs11js examples. The contract is one `handle(fnId, argBytes) -\u003e Promise\u003c{ status, body }\u003e` method per `Pkcs11Fn` enum value from the polyfill's `plugins/ws-gateway` codec.\n\n## Protocol\n\nKSW1 frames are defined in `@tegmentum/wasi-polyfill/plugins/ws-gateway`:\n\n- Hello / HelloAck handshake (feature negotiation)\n- Open / OpenOk / OpenErr (per-stream TCP connect)\n- Data (bidirectional; supports half-close)\n- Close / CloseAck\n- DnsQuery / DnsResult / DnsErr\n- Pkcs11Request / Pkcs11Response (queryId-multiplexed RPC)\n\nAll framed as binary WebSocket messages with a 4-byte magic prefix (`KSW1`) + version byte + per-frame type tag. See `@tegmentum/wasi-polyfill` source for the byte-level spec.\n\n## Threat model\n\nDefault config is **dev-only** — no auth, listens on localhost. For production:\n\n- Bind to a non-loopback interface (`GATEWAY_HOST=0.0.0.0`).\n- Front with a reverse proxy that adds TLS + auth (the WebSocket protocol carries an `optional` token field in Hello that the current build ignores).\n- Run pkcs11js with a token whose PIN is supplied via environment, not URI.\n\n## License\n\nApache-2.0. See [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftegmentum%2Fws-gateway-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftegmentum%2Fws-gateway-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftegmentum%2Fws-gateway-server/lists"}