@seedprotocol/gateway-hyper 0.7.10-next.1353.g74aeeed → 0.7.10
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/README.md +24 -2
- package/dist/bin.js +164 -48
- package/dist/bin.js.map +1 -1
- package/dist/cli.d.ts +5 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/keys.d.ts +16 -0
- package/dist/keys.d.ts.map +1 -1
- package/dist/src-DHEkxp5F.js +943 -0
- package/dist/src-DHEkxp5F.js.map +1 -0
- package/dist/tunnel/allowlist.d.ts +45 -0
- package/dist/tunnel/allowlist.d.ts.map +1 -0
- package/dist/tunnel/connect.d.ts.map +1 -1
- package/dist/tunnel/events.d.ts +131 -0
- package/dist/tunnel/events.d.ts.map +1 -0
- package/dist/tunnel/proxy.d.ts +11 -0
- package/dist/tunnel/proxy.d.ts.map +1 -1
- package/dist/tunnel/proxyApp.d.ts.map +1 -1
- package/dist/tunnel/rawConnect.d.ts +14 -0
- package/dist/tunnel/rawConnect.d.ts.map +1 -0
- package/dist/tunnel/rawPipe.d.ts +35 -0
- package/dist/tunnel/rawPipe.d.ts.map +1 -0
- package/dist/tunnel/rawServe.d.ts +18 -0
- package/dist/tunnel/rawServe.d.ts.map +1 -0
- package/dist/tunnel/serve.d.ts +11 -0
- package/dist/tunnel/serve.d.ts.map +1 -1
- package/dist/tunnel/session.d.ts +15 -1
- package/dist/tunnel/session.d.ts.map +1 -1
- package/dist/types.d.ts +125 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/src-qIlmrs1H.js +0 -573
- package/dist/src-qIlmrs1H.js.map +0 -1
package/README.md
CHANGED
|
@@ -25,10 +25,29 @@ Requires Node 20+ and Holepunch native addons. Prefer Node over Bun. Installs th
|
|
|
25
25
|
# Operator
|
|
26
26
|
seed-gateway serve --upstream http://127.0.0.1:80 --key-file ./.seed/gateway-tunnel/operator.key.json
|
|
27
27
|
|
|
28
|
+
# Operator accepting only listed clients
|
|
29
|
+
seed-gateway serve --upstream http://127.0.0.1:80 --allow-keys <client-z32> --allow-ips 192.168.1.0/24
|
|
30
|
+
|
|
28
31
|
# Client sidecar (Path A)
|
|
29
32
|
seed-gateway connect <z32-key> --host 127.0.0.1 --port 1984
|
|
33
|
+
|
|
34
|
+
# Operator logging every stream and request, with a request id header upstream
|
|
35
|
+
seed-gateway serve --upstream http://127.0.0.1:80 --trace --request-id-header x-seed-tunnel-request-id
|
|
36
|
+
|
|
37
|
+
# Raw TCP mode, for an HTTP proxy in front (no size limit, streaming, WebSockets)
|
|
38
|
+
seed-gateway serve --raw --upstream http://127.0.0.1:80
|
|
39
|
+
seed-gateway connect --raw <raw-z32-key> --port 1985
|
|
40
|
+
|
|
41
|
+
# Client with a fixed key the operator can list
|
|
42
|
+
seed-gateway connect --print-key --key-file ./client.key.json
|
|
43
|
+
seed-gateway connect <z32-key> --key-file ./client.key.json
|
|
30
44
|
```
|
|
31
45
|
|
|
46
|
+
A client on the operator's LAN connects over the LAN and shows its LAN address, so list the
|
|
47
|
+
LAN range rather than the public IP. A connection relayed through another HyperDHT node shows
|
|
48
|
+
the relay's address and is refused unless its key is listed. See
|
|
49
|
+
[Restricting who can connect](https://github.com/JournoLabs/seed-protocol-sdk/blob/main/docs/GATEWAY_HYPER.md#restricting-who-can-connect).
|
|
50
|
+
|
|
32
51
|
## Library
|
|
33
52
|
|
|
34
53
|
```ts
|
|
@@ -36,6 +55,8 @@ import {
|
|
|
36
55
|
serveTunnel,
|
|
37
56
|
connectTunnel,
|
|
38
57
|
createGatewayProxy,
|
|
58
|
+
serveRawTunnel,
|
|
59
|
+
connectRawTunnel,
|
|
39
60
|
} from '@seedprotocol/gateway-hyper'
|
|
40
61
|
|
|
41
62
|
const operator = await serveTunnel({ upstream: 'http://127.0.0.1:80' })
|
|
@@ -67,8 +88,9 @@ Keep `SEED_GATEWAY_HYPER_KEY` on the server only. Authenticate / rate-limit the
|
|
|
67
88
|
|
|
68
89
|
## Tests
|
|
69
90
|
|
|
70
|
-
-
|
|
71
|
-
|
|
91
|
+
- All tests run with `bun run test` (from a checkout of the monorepo). DHT tests use a local
|
|
92
|
+
`hyperdht/testnet`.
|
|
93
|
+
- Public-DHT smoke test: `GATEWAY_HYPER_TESTS=1 bun run test`
|
|
72
94
|
|
|
73
95
|
## License
|
|
74
96
|
|
package/dist/bin.js
CHANGED
|
@@ -1,86 +1,202 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { parseArgs as
|
|
6
|
-
//#region src/
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import { P as e, _ as t, c as n, g as r, m as i, p as a, r as o, s } from "./src-DHEkxp5F.js";
|
|
3
|
+
import c from "node:path";
|
|
4
|
+
import l from "node:process";
|
|
5
|
+
import { parseArgs as u } from "node:util";
|
|
6
|
+
//#region src/cli.ts
|
|
7
|
+
var d = c.join(".seed", "gateway-tunnel", "operator.key.json"), f = 1984, p = `Usage:
|
|
8
|
+
seed-gateway serve [--upstream http://127.0.0.1:80] [--key-file <path>] [--upstream-timeout-ms 30000]
|
|
9
|
+
[--allow-keys k1,k2] [--allow-ips 192.168.1.0/24,203.0.113.7]
|
|
10
|
+
Operator: accept Hyper connections and proxy them to a local upstream (Traefik).
|
|
11
|
+
Default --key-file: ./.seed/gateway-tunnel/operator.key.json (created on first run).
|
|
12
|
+
Answers 504 when the upstream is idle for --upstream-timeout-ms (0 disables).
|
|
13
|
+
With --allow-keys or --allow-ips, only clients whose public key or address is listed
|
|
14
|
+
can connect. A client on the operator's LAN shows its LAN address.
|
|
15
|
+
--trace logs each stream and request event as a \`tunnel-trace <event> key=value\` line.
|
|
16
|
+
--request-id-header <name> sends each request's id upstream under that header.
|
|
17
|
+
|
|
18
|
+
seed-gateway connect <key> [--host 127.0.0.1] [--port 1984] [--request-timeout-ms 60000]
|
|
19
|
+
[--connect-timeout-ms 30000] [--key-file <path>]
|
|
20
|
+
Client: dial an operator key and expose a localhost HTTP sidecar.
|
|
21
|
+
Abandons a request and reconnects when the tunnel is idle for --request-timeout-ms.
|
|
22
|
+
[--max-streams 4] opens up to that many streams to the operator, one request each.
|
|
23
|
+
--key-file keeps this client's key in a file (created on first run), so the operator
|
|
24
|
+
can list it with --allow-keys. Without it, each run uses a new key.
|
|
25
|
+
|
|
26
|
+
seed-gateway connect --print-key --key-file <path>
|
|
27
|
+
Print the client public key (z32) in the key file, creating the file if missing.
|
|
28
|
+
|
|
29
|
+
seed-gateway serve --raw [--upstream http://127.0.0.1:80] [--key-file <path>]
|
|
30
|
+
[--allow-keys ...] [--allow-ips ...] [--trace]
|
|
31
|
+
Operator, raw mode: pipe each Hyper connection byte for byte to a new TCP connection to
|
|
32
|
+
the upstream, so HTTP runs end to end with no size limit, streaming and WebSockets.
|
|
33
|
+
Default --key-file: ./${a}. Raw and framed servers need
|
|
34
|
+
separate keys; clients of one can't talk to the other.
|
|
35
|
+
|
|
36
|
+
seed-gateway connect --raw <key> [--host 127.0.0.1] [--port ${s}] [--key-file <path>]
|
|
37
|
+
[--max-connections 64] [--connect-timeout-ms 30000] [--trace]
|
|
38
|
+
Client, raw mode: listen on a local TCP port and carry each connection to a raw operator
|
|
39
|
+
over its own Hyper stream. Put a client that keeps connections alive (nginx with
|
|
40
|
+
keepalive) in front; each new connection costs a DHT lookup and handshake.`;
|
|
41
|
+
function m(e) {
|
|
42
|
+
console.error(`[Seed Protocol] ${e}`), console.error(p), l.exit(1);
|
|
10
43
|
}
|
|
11
|
-
function
|
|
44
|
+
function h(e, t) {
|
|
12
45
|
if (e === void 0) return;
|
|
13
46
|
let n = Number(e);
|
|
14
|
-
return (!Number.isInteger(n) || n < 0) &&
|
|
47
|
+
return (!Number.isInteger(n) || n < 0) && m(`${t} must be a whole number of milliseconds`), n;
|
|
15
48
|
}
|
|
16
|
-
function
|
|
49
|
+
function g(e, t) {
|
|
17
50
|
if (e === void 0) return;
|
|
18
51
|
let n = Number(e);
|
|
19
|
-
return (!Number.isInteger(n) || n < 1) &&
|
|
52
|
+
return (!Number.isInteger(n) || n < 1) && m(`${t} must be a whole number of at least 1`), n;
|
|
53
|
+
}
|
|
54
|
+
function _(e, t = /* @__PURE__ */ new Date()) {
|
|
55
|
+
let n = [
|
|
56
|
+
t.toISOString(),
|
|
57
|
+
"tunnel-trace",
|
|
58
|
+
e.name
|
|
59
|
+
];
|
|
60
|
+
for (let [t, r] of Object.entries(e)) {
|
|
61
|
+
if (t === "name" || r == null) continue;
|
|
62
|
+
let e = String(r);
|
|
63
|
+
n.push(`${t}=${/[\s"=]/.test(e) ? JSON.stringify(e) : e}`);
|
|
64
|
+
}
|
|
65
|
+
return n.join(" ");
|
|
66
|
+
}
|
|
67
|
+
function v(e) {
|
|
68
|
+
console.log(_(e));
|
|
69
|
+
}
|
|
70
|
+
function y(e, t) {
|
|
71
|
+
if (e === void 0) return t;
|
|
72
|
+
let n = Number(e);
|
|
73
|
+
return (!Number.isInteger(n) || n < 0 || n > 65535) && m("--port must be 0–65535"), n;
|
|
74
|
+
}
|
|
75
|
+
function b(e) {
|
|
76
|
+
return (e ?? "").split(",").map((e) => e.trim()).filter(Boolean);
|
|
20
77
|
}
|
|
21
|
-
function
|
|
78
|
+
function x() {
|
|
22
79
|
return new Promise((e) => {
|
|
23
80
|
let t = () => {
|
|
24
|
-
|
|
81
|
+
l.off("SIGINT", t), l.off("SIGTERM", t), e();
|
|
25
82
|
};
|
|
26
|
-
|
|
83
|
+
l.on("SIGINT", t), l.on("SIGTERM", t);
|
|
27
84
|
});
|
|
28
85
|
}
|
|
29
|
-
async function
|
|
30
|
-
let [
|
|
31
|
-
if (!
|
|
32
|
-
console.log(
|
|
86
|
+
async function S(a) {
|
|
87
|
+
let [l, ..._] = a;
|
|
88
|
+
if (!l || l === "--help" || l === "-h" || l === "help") {
|
|
89
|
+
console.log(p);
|
|
33
90
|
return;
|
|
34
91
|
}
|
|
35
|
-
let { values:
|
|
36
|
-
args:
|
|
92
|
+
let { values: S, positionals: C } = u({
|
|
93
|
+
args: _,
|
|
37
94
|
allowPositionals: !0,
|
|
38
95
|
options: {
|
|
39
96
|
upstream: {
|
|
40
97
|
type: "string",
|
|
41
98
|
default: "http://127.0.0.1:80"
|
|
42
99
|
},
|
|
43
|
-
"key-file": {
|
|
44
|
-
|
|
45
|
-
|
|
100
|
+
"key-file": { type: "string" },
|
|
101
|
+
"print-key": {
|
|
102
|
+
type: "boolean",
|
|
103
|
+
default: !1
|
|
46
104
|
},
|
|
47
105
|
host: {
|
|
48
106
|
type: "string",
|
|
49
107
|
default: "127.0.0.1"
|
|
50
108
|
},
|
|
51
|
-
port: {
|
|
52
|
-
|
|
53
|
-
|
|
109
|
+
port: { type: "string" },
|
|
110
|
+
raw: {
|
|
111
|
+
type: "boolean",
|
|
112
|
+
default: !1
|
|
54
113
|
},
|
|
114
|
+
"max-connections": { type: "string" },
|
|
115
|
+
"connect-timeout-ms": { type: "string" },
|
|
55
116
|
"upstream-timeout-ms": { type: "string" },
|
|
56
117
|
"request-timeout-ms": { type: "string" },
|
|
57
|
-
"max-streams": { type: "string" }
|
|
118
|
+
"max-streams": { type: "string" },
|
|
119
|
+
"allow-keys": { type: "string" },
|
|
120
|
+
"allow-ips": { type: "string" },
|
|
121
|
+
trace: {
|
|
122
|
+
type: "boolean",
|
|
123
|
+
default: !1
|
|
124
|
+
},
|
|
125
|
+
"request-id-header": { type: "string" }
|
|
58
126
|
}
|
|
59
127
|
});
|
|
60
|
-
if (
|
|
61
|
-
let e =
|
|
62
|
-
console.log(`[Seed Protocol]
|
|
63
|
-
let
|
|
128
|
+
if (l === "serve" && S.raw) {
|
|
129
|
+
let e = S.upstream.trim(), n = c.resolve(S["key-file"] ?? ".seed/gateway-tunnel/raw-operator.key.json");
|
|
130
|
+
console.log(`[Seed Protocol] Raw tunnel upstream: ${e}`), console.log(`[Seed Protocol] Raw operator key file: ${n}`);
|
|
131
|
+
let r = {
|
|
132
|
+
keys: b(S["allow-keys"]),
|
|
133
|
+
ips: b(S["allow-ips"])
|
|
134
|
+
};
|
|
135
|
+
console.log(`[Seed Protocol] Allowlist: ${t(r).summary}`);
|
|
136
|
+
let a = await i({
|
|
64
137
|
upstream: e,
|
|
65
|
-
keyFile:
|
|
66
|
-
|
|
138
|
+
keyFile: n,
|
|
139
|
+
allowlist: r,
|
|
140
|
+
onEvent: S.trace ? v : void 0
|
|
67
141
|
});
|
|
68
|
-
console.log(`[Seed Protocol]
|
|
69
|
-
} else if (
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
-
let
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
142
|
+
console.log(`[Seed Protocol] Raw operator key (z32): ${a.key}`), console.log("[Seed Protocol] Clients connect with: seed-gateway connect --raw <key>"), console.log("[Seed Protocol] Press Ctrl+C to stop."), await x(), await a.close(), console.log("[Seed Protocol] Raw tunnel stopped.");
|
|
143
|
+
} else if (l === "serve") {
|
|
144
|
+
let e = S.upstream.trim(), n = c.resolve(S["key-file"] ?? d);
|
|
145
|
+
console.log(`[Seed Protocol] Gateway tunnel upstream: ${e}`), console.log(`[Seed Protocol] Operator key file: ${n}`);
|
|
146
|
+
let i = {
|
|
147
|
+
keys: b(S["allow-keys"]),
|
|
148
|
+
ips: b(S["allow-ips"])
|
|
149
|
+
};
|
|
150
|
+
console.log(`[Seed Protocol] Allowlist: ${t(i).summary}`);
|
|
151
|
+
let a = await r({
|
|
152
|
+
upstream: e,
|
|
153
|
+
keyFile: n,
|
|
154
|
+
allowlist: i,
|
|
155
|
+
onEvent: S.trace ? v : void 0,
|
|
156
|
+
requestIdHeader: S["request-id-header"]?.trim() || void 0,
|
|
157
|
+
upstreamTimeoutMs: h(S["upstream-timeout-ms"], "--upstream-timeout-ms")
|
|
78
158
|
});
|
|
79
|
-
console.log(`[Seed Protocol]
|
|
80
|
-
} else
|
|
159
|
+
console.log(`[Seed Protocol] Operator key (z32): ${a.key}`), console.log("[Seed Protocol] Share this key with SDK users (gatewayHyperKey)."), console.log("[Seed Protocol] Press Ctrl+C to stop."), await x(), await a.close(), console.log("[Seed Protocol] Gateway tunnel stopped.");
|
|
160
|
+
} else if (l === "connect") {
|
|
161
|
+
let t = S["key-file"] ? c.resolve(S["key-file"]) : void 0;
|
|
162
|
+
if (S["print-key"]) {
|
|
163
|
+
t || m("--print-key requires --key-file"), console.log(e(t).z32);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
let r = C[0];
|
|
167
|
+
r || m("seed-gateway connect requires an operator public key (z32 or hex)");
|
|
168
|
+
let i = h(S["connect-timeout-ms"], "--connect-timeout-ms");
|
|
169
|
+
if (S.raw) {
|
|
170
|
+
console.log(`[Seed Protocol] Connecting to raw operator ${r}`);
|
|
171
|
+
let e = await n({
|
|
172
|
+
key: r,
|
|
173
|
+
keyFile: t,
|
|
174
|
+
host: S.host,
|
|
175
|
+
port: y(S.port, s),
|
|
176
|
+
maxConnections: g(S["max-connections"], "--max-connections"),
|
|
177
|
+
connectTimeoutMs: i,
|
|
178
|
+
onEvent: S.trace ? v : void 0
|
|
179
|
+
});
|
|
180
|
+
console.log(`[Seed Protocol] Client key (z32): ${e.clientKey}${t ? "" : " (new for this run)"}`), console.log(`[Seed Protocol] Raw tunnel listening on ${e.host}:${e.port}`), console.log("[Seed Protocol] Press Ctrl+C to stop."), await x(), await e.close(), console.log("[Seed Protocol] Raw tunnel client stopped.");
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
console.log(`[Seed Protocol] Connecting to operator ${r}`);
|
|
184
|
+
let a = await o({
|
|
185
|
+
key: r,
|
|
186
|
+
keyFile: t,
|
|
187
|
+
host: S.host,
|
|
188
|
+
port: y(S.port, f),
|
|
189
|
+
connectTimeoutMs: i,
|
|
190
|
+
requestTimeoutMs: h(S["request-timeout-ms"], "--request-timeout-ms"),
|
|
191
|
+
maxStreams: g(S["max-streams"], "--max-streams")
|
|
192
|
+
});
|
|
193
|
+
console.log(`[Seed Protocol] Client key (z32): ${a.clientKey}${t ? "" : " (new for this run)"}`), console.log(`[Seed Protocol] Local sidecar: ${a.baseUrl}`), console.log("[Seed Protocol] Point SDK transport=hyper or hybrid at this URL (default sidecar port 1984)."), console.log("[Seed Protocol] Press Ctrl+C to stop."), await x(), await a.close(), console.log("[Seed Protocol] Gateway sidecar stopped.");
|
|
194
|
+
} else m(`Unknown command: ${l}`);
|
|
81
195
|
}
|
|
82
|
-
|
|
83
|
-
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/bin.ts
|
|
198
|
+
S(l.argv.slice(2)).catch((e) => {
|
|
199
|
+
console.error("[Seed Protocol]", e instanceof Error ? e.message : e), l.exit(1);
|
|
84
200
|
});
|
|
85
201
|
//#endregion
|
|
86
202
|
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","names":["connectTunnel","serveTunnel","path","process","USAGE","fail","message","parseMs","value","ms","flag","parseCount","count","waitForSignal","onStop","resolve","main","command","rest","argv","parseArgs","upstream","values","keyFile","session","key","positionals","err"],"sources":["../src/bin.ts"],"sourcesContent":["/**\n * `seed-gateway serve|connect` — HTTP tunnel to Seed gateway + upload API infrastructure over HyperDHT.\n * Run under Node (Holepunch natives may crash under Bun).\n */\nimport path from 'node:path'\nimport process from 'node:process'\nimport { parseArgs } from 'node:util'\nimport { connectTunnel, serveTunnel } from './index'\n\nconst USAGE = `Usage:\n seed-gateway serve [--upstream http://127.0.0.1:80] [--key-file <path>] [--upstream-timeout-ms 30000]\n Operator: accept Hyper connections and proxy them to a local upstream (Traefik).\n Default --key-file: ./.seed/gateway-tunnel/operator.key.json (created on first run).\n Answers 504 when the upstream is idle for --upstream-timeout-ms (0 disables).\n\n seed-gateway connect <key> [--host 127.0.0.1] [--port 1984] [--request-timeout-ms 60000]\n Client: dial an operator key and expose a localhost HTTP sidecar.\n Abandons a request and reconnects when the tunnel is idle for --request-timeout-ms.\n [--max-streams 4] opens up to that many streams to the operator, one request each.`\n\nfunction fail(message: string): never {\n console.error(`[Seed Protocol] ${message}`)\n console.error(USAGE)\n process.exit(1)\n}\n\nfunction parseMs(value: string | undefined, flag: string): number | undefined {\n if (value === undefined) return undefined\n const ms = Number(value)\n if (!Number.isInteger(ms) || ms < 0) fail(`${flag} must be a whole number of milliseconds`)\n return ms\n}\n\nfunction parseCount(value: string | undefined, flag: string): number | undefined {\n if (value === undefined) return undefined\n const count = Number(value)\n if (!Number.isInteger(count) || count < 1) fail(`${flag} must be a whole number of at least 1`)\n return count\n}\n\nfunction waitForSignal(): Promise<void> {\n return new Promise((resolve) => {\n const onStop = () => {\n process.off('SIGINT', onStop)\n process.off('SIGTERM', onStop)\n resolve()\n }\n process.on('SIGINT', onStop)\n process.on('SIGTERM', onStop)\n })\n}\n\nasync function main(argv: string[]): Promise<void> {\n const [command, ...rest] = argv\n if (!command || command === '--help' || command === '-h' || command === 'help') {\n console.log(USAGE)\n return\n }\n\n const { values, positionals } = parseArgs({\n args: rest,\n allowPositionals: true,\n options: {\n upstream: { type: 'string', default: 'http://127.0.0.1:80' },\n 'key-file': {\n type: 'string',\n default: path.join('.seed', 'gateway-tunnel', 'operator.key.json'),\n },\n host: { type: 'string', default: '127.0.0.1' },\n port: { type: 'string', default: '1984' },\n 'upstream-timeout-ms': { type: 'string' },\n 'request-timeout-ms': { type: 'string' },\n 'max-streams': { type: 'string' },\n },\n })\n\n if (command === 'serve') {\n const upstream = values.upstream.trim()\n const keyFile = path.resolve(values['key-file'])\n console.log(`[Seed Protocol] Gateway tunnel upstream: ${upstream}`)\n console.log(`[Seed Protocol] Operator key file: ${keyFile}`)\n\n const session = await serveTunnel({\n upstream,\n keyFile,\n upstreamTimeoutMs: parseMs(values['upstream-timeout-ms'], '--upstream-timeout-ms'),\n })\n console.log(`[Seed Protocol] Operator key (z32): ${session.key}`)\n console.log('[Seed Protocol] Share this key with SDK users (gatewayHyperKey).')\n console.log('[Seed Protocol] Press Ctrl+C to stop.')\n await waitForSignal()\n await session.close()\n console.log('[Seed Protocol] Gateway tunnel stopped.')\n return\n }\n\n if (command === 'connect') {\n const key = positionals[0]\n if (!key) fail('seed-gateway connect requires an operator public key (z32 or hex)')\n\n console.log(`[Seed Protocol] Connecting to operator ${key}`)\n const session = await connectTunnel({\n key,\n host: values.host,\n port: parseInt(values.port, 10) || 1984,\n requestTimeoutMs: parseMs(values['request-timeout-ms'], '--request-timeout-ms'),\n maxStreams: parseCount(values['max-streams'], '--max-streams'),\n })\n console.log(`[Seed Protocol] Local sidecar: ${session.baseUrl}`)\n console.log(\n '[Seed Protocol] Point SDK transport=hyper or hybrid at this URL (default sidecar port 1984).',\n )\n console.log('[Seed Protocol] Press Ctrl+C to stop.')\n await waitForSignal()\n await session.close()\n console.log('[Seed Protocol] Gateway sidecar stopped.')\n return\n }\n\n fail(`Unknown command: ${command}`)\n}\n\nmain(process.argv.slice(2)).catch((err) => {\n console.error('[Seed Protocol]', err instanceof Error ? err.message : err)\n process.exit(1)\n})\n"],"mappings":";;;;;;AASA,IAAMI,IAAQ;AAWd,SAASC,EAAK,GAAwB;CAGpC,AAFA,QAAQ,MAAM,mBAAmBC,GAAS,GAC1C,QAAQ,MAAMF,CAAK,GACnBD,EAAQ,KAAK,CAAC;AAChB;AAEA,SAASI,EAAQ,GAA2B,GAAkC;CAC5E,IAAIC,MAAU,KAAA,GAAW;CACzB,IAAMC,IAAK,OAAOD,CAAK;CAEvB,QADI,CAAC,OAAO,UAAUC,CAAE,KAAKA,IAAK,MAAGJ,EAAK,GAAGK,EAAK,wCAAwC,GACnFD;AACT;AAEA,SAASE,EAAW,GAA2B,GAAkC;CAC/E,IAAIH,MAAU,KAAA,GAAW;CACzB,IAAMI,IAAQ,OAAOJ,CAAK;CAE1B,QADI,CAAC,OAAO,UAAUI,CAAK,KAAKA,IAAQ,MAAGP,EA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,IAAI,uCAAuC,GACnD,MAAMX,EAAc,GACpB,MAAMW,EAAQ,MAAM,GACpB,QAAQ,IAAI,yCAAyC;CAEvD,OAEA,IAAIP,MAAY,WAAW;EACzB,IAAMQ,IAAMC,EAAY;EAGxB,AAFKD,KAAKpB,EAAK,mEAAmE,GAElF,QAAQ,IAAI,0CAA0CoB,GAAK;EAC3D,IAAMD,IAAU,MAAMxB,EAAc;GAClC;GACA,MAAMsB,EAAO;GACb,MAAM,SAASA,EAAO,MAAM,EAAE,KAAK;GACnC,kBAAkBf,EAAQe,EAAO,uBAAuB,sBAAsB;GAC9E,YAAYX,EAAWW,EAAO,gBAAgB,eAAe;EAC/D,CAAC;EAQD,AAPA,QAAQ,IAAI,kCAAkCE,EAAQ,SAAS,GAC/D,QAAQ,IACN,8FACF,GACA,QAAQ,IAAI,uCAAuC,GACnD,MAAMX,EAAc,GACpB,MAAMW,EAAQ,MAAM,GACpB,QAAQ,IAAI,0CAA0C;CAExD,OAEA,EAAK,oBAAoBP,GAAS;AACpC;AAEAD,EAAKb,EAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,MAAQ;CAEzC,AADA,QAAQ,MAAM,mBAAmBwB,aAAe,QAAQA,EAAI,UAAUA,CAAG,GACzExB,EAAQ,KAAK,CAAC;AAChB,CAAC"}
|
|
1
|
+
{"version":3,"file":"bin.js","names":["loadOrCreateOperatorKeypair","createAllowlist","connectRawTunnel","serveTunnel","serveRawTunnel","DEFAULT_RAW_OPERATOR_KEY_FILE","connectTunnel","path","process","DEFAULT_OPERATOR_KEY_FILE","DEFAULT_PORT","USAGE","DEFAULT_RAW_PORT","fail","message","parseMs","value","ms","flag","parseCount","count","formatTunnelEvent","parts","now","event","key","text","logTunnelEvent","parsePort","fallback","port","splitList","entry","waitForSignal","onStop","resolve","main","command","rest","argv","parseArgs","values","upstream","keyFile","allowlist","session","positionals","connectTimeoutMs","err"],"sources":["../src/cli.ts","../src/bin.ts"],"sourcesContent":["/**\n * `seed-gateway serve|connect`, run by `bin.ts`. Separate so tests can call `main`.\n */\nimport path from 'node:path'\nimport process from 'node:process'\nimport { parseArgs } from 'node:util'\nimport {\n connectRawTunnel,\n connectTunnel,\n createAllowlist,\n DEFAULT_RAW_OPERATOR_KEY_FILE,\n DEFAULT_RAW_PORT,\n loadOrCreateOperatorKeypair,\n serveRawTunnel,\n serveTunnel,\n type RawClientEvent,\n type RawTunnelEvent,\n type TunnelEvent,\n} from './index'\n\nconst DEFAULT_OPERATOR_KEY_FILE = path.join('.seed', 'gateway-tunnel', 'operator.key.json')\nconst DEFAULT_PORT = 1984\n\nconst USAGE = `Usage:\n seed-gateway serve [--upstream http://127.0.0.1:80] [--key-file <path>] [--upstream-timeout-ms 30000]\n [--allow-keys k1,k2] [--allow-ips 192.168.1.0/24,203.0.113.7]\n Operator: accept Hyper connections and proxy them to a local upstream (Traefik).\n Default --key-file: ./.seed/gateway-tunnel/operator.key.json (created on first run).\n Answers 504 when the upstream is idle for --upstream-timeout-ms (0 disables).\n With --allow-keys or --allow-ips, only clients whose public key or address is listed\n can connect. A client on the operator's LAN shows its LAN address.\n --trace logs each stream and request event as a \\`tunnel-trace <event> key=value\\` line.\n --request-id-header <name> sends each request's id upstream under that header.\n\n seed-gateway connect <key> [--host 127.0.0.1] [--port 1984] [--request-timeout-ms 60000]\n [--connect-timeout-ms 30000] [--key-file <path>]\n Client: dial an operator key and expose a localhost HTTP sidecar.\n Abandons a request and reconnects when the tunnel is idle for --request-timeout-ms.\n [--max-streams 4] opens up to that many streams to the operator, one request each.\n --key-file keeps this client's key in a file (created on first run), so the operator\n can list it with --allow-keys. Without it, each run uses a new key.\n\n seed-gateway connect --print-key --key-file <path>\n Print the client public key (z32) in the key file, creating the file if missing.\n\n seed-gateway serve --raw [--upstream http://127.0.0.1:80] [--key-file <path>]\n [--allow-keys ...] [--allow-ips ...] [--trace]\n Operator, raw mode: pipe each Hyper connection byte for byte to a new TCP connection to\n the upstream, so HTTP runs end to end with no size limit, streaming and WebSockets.\n Default --key-file: ./${DEFAULT_RAW_OPERATOR_KEY_FILE}. Raw and framed servers need\n separate keys; clients of one can't talk to the other.\n\n seed-gateway connect --raw <key> [--host 127.0.0.1] [--port ${DEFAULT_RAW_PORT}] [--key-file <path>]\n [--max-connections 64] [--connect-timeout-ms 30000] [--trace]\n Client, raw mode: listen on a local TCP port and carry each connection to a raw operator\n over its own Hyper stream. Put a client that keeps connections alive (nginx with\n keepalive) in front; each new connection costs a DHT lookup and handshake.`\n\nfunction fail(message: string): never {\n console.error(`[Seed Protocol] ${message}`)\n console.error(USAGE)\n process.exit(1)\n}\n\nfunction parseMs(value: string | undefined, flag: string): number | undefined {\n if (value === undefined) return undefined\n const ms = Number(value)\n if (!Number.isInteger(ms) || ms < 0) fail(`${flag} must be a whole number of milliseconds`)\n return ms\n}\n\nfunction parseCount(value: string | undefined, flag: string): number | undefined {\n if (value === undefined) return undefined\n const count = Number(value)\n if (!Number.isInteger(count) || count < 1) fail(`${flag} must be a whole number of at least 1`)\n return count\n}\n\n/** One `tunnel-trace` line per event: ISO time, event name, then `key=value` fields. */\nexport function formatTunnelEvent(\n event: TunnelEvent | RawTunnelEvent | RawClientEvent,\n now = new Date(),\n): string {\n const parts = [now.toISOString(), 'tunnel-trace', event.name]\n for (const [key, value] of Object.entries(event)) {\n if (key === 'name' || value === undefined || value === null) continue\n const text = String(value)\n parts.push(`${key}=${/[\\s\"=]/.test(text) ? JSON.stringify(text) : text}`)\n }\n return parts.join(' ')\n}\n\nfunction logTunnelEvent(event: TunnelEvent | RawTunnelEvent | RawClientEvent): void {\n console.log(formatTunnelEvent(event))\n}\n\nfunction parsePort(value: string | undefined, fallback: number): number {\n if (value === undefined) return fallback\n const port = Number(value)\n if (!Number.isInteger(port) || port < 0 || port > 65535) fail('--port must be 0–65535')\n return port\n}\n\nfunction splitList(value: string | undefined): string[] {\n return (value ?? '')\n .split(',')\n .map((entry) => entry.trim())\n .filter(Boolean)\n}\n\nfunction waitForSignal(): Promise<void> {\n return new Promise((resolve) => {\n const onStop = () => {\n process.off('SIGINT', onStop)\n process.off('SIGTERM', onStop)\n resolve()\n }\n process.on('SIGINT', onStop)\n process.on('SIGTERM', onStop)\n })\n}\n\nexport async function main(argv: string[]): Promise<void> {\n const [command, ...rest] = argv\n if (!command || command === '--help' || command === '-h' || command === 'help') {\n console.log(USAGE)\n return\n }\n\n const { values, positionals } = parseArgs({\n args: rest,\n allowPositionals: true,\n options: {\n upstream: { type: 'string', default: 'http://127.0.0.1:80' },\n // No default here: serve and connect default differently.\n 'key-file': { type: 'string' },\n 'print-key': { type: 'boolean', default: false },\n host: { type: 'string', default: '127.0.0.1' },\n // No default here: framed and raw connect default differently.\n port: { type: 'string' },\n raw: { type: 'boolean', default: false },\n 'max-connections': { type: 'string' },\n 'connect-timeout-ms': { type: 'string' },\n 'upstream-timeout-ms': { type: 'string' },\n 'request-timeout-ms': { type: 'string' },\n 'max-streams': { type: 'string' },\n 'allow-keys': { type: 'string' },\n 'allow-ips': { type: 'string' },\n trace: { type: 'boolean', default: false },\n 'request-id-header': { type: 'string' },\n },\n })\n\n if (command === 'serve' && values.raw) {\n const upstream = values.upstream.trim()\n const keyFile = path.resolve(values['key-file'] ?? DEFAULT_RAW_OPERATOR_KEY_FILE)\n console.log(`[Seed Protocol] Raw tunnel upstream: ${upstream}`)\n console.log(`[Seed Protocol] Raw operator key file: ${keyFile}`)\n const allowlist = { keys: splitList(values['allow-keys']), ips: splitList(values['allow-ips']) }\n console.log(`[Seed Protocol] Allowlist: ${createAllowlist(allowlist).summary}`)\n\n const session = await serveRawTunnel({\n upstream,\n keyFile,\n allowlist,\n onEvent: values.trace ? logTunnelEvent : undefined,\n })\n console.log(`[Seed Protocol] Raw operator key (z32): ${session.key}`)\n console.log('[Seed Protocol] Clients connect with: seed-gateway connect --raw <key>')\n console.log('[Seed Protocol] Press Ctrl+C to stop.')\n await waitForSignal()\n await session.close()\n console.log('[Seed Protocol] Raw tunnel stopped.')\n return\n }\n\n if (command === 'serve') {\n const upstream = values.upstream.trim()\n const keyFile = path.resolve(values['key-file'] ?? DEFAULT_OPERATOR_KEY_FILE)\n console.log(`[Seed Protocol] Gateway tunnel upstream: ${upstream}`)\n console.log(`[Seed Protocol] Operator key file: ${keyFile}`)\n const allowlist = { keys: splitList(values['allow-keys']), ips: splitList(values['allow-ips']) }\n console.log(`[Seed Protocol] Allowlist: ${createAllowlist(allowlist).summary}`)\n\n const session = await serveTunnel({\n upstream,\n keyFile,\n allowlist,\n onEvent: values.trace ? logTunnelEvent : undefined,\n requestIdHeader: values['request-id-header']?.trim() || undefined,\n upstreamTimeoutMs: parseMs(values['upstream-timeout-ms'], '--upstream-timeout-ms'),\n })\n console.log(`[Seed Protocol] Operator key (z32): ${session.key}`)\n console.log('[Seed Protocol] Share this key with SDK users (gatewayHyperKey).')\n console.log('[Seed Protocol] Press Ctrl+C to stop.')\n await waitForSignal()\n await session.close()\n console.log('[Seed Protocol] Gateway tunnel stopped.')\n return\n }\n\n if (command === 'connect') {\n const keyFile = values['key-file'] ? path.resolve(values['key-file']) : undefined\n if (values['print-key']) {\n if (!keyFile) fail('--print-key requires --key-file')\n console.log(loadOrCreateOperatorKeypair(keyFile).z32)\n return\n }\n\n const key = positionals[0]\n if (!key) fail('seed-gateway connect requires an operator public key (z32 or hex)')\n const connectTimeoutMs = parseMs(values['connect-timeout-ms'], '--connect-timeout-ms')\n\n if (values.raw) {\n console.log(`[Seed Protocol] Connecting to raw operator ${key}`)\n const session = await connectRawTunnel({\n key,\n keyFile,\n host: values.host,\n port: parsePort(values.port, DEFAULT_RAW_PORT),\n maxConnections: parseCount(values['max-connections'], '--max-connections'),\n connectTimeoutMs,\n onEvent: values.trace ? logTunnelEvent : undefined,\n })\n console.log(\n `[Seed Protocol] Client key (z32): ${session.clientKey}${keyFile ? '' : ' (new for this run)'}`,\n )\n console.log(`[Seed Protocol] Raw tunnel listening on ${session.host}:${session.port}`)\n console.log('[Seed Protocol] Press Ctrl+C to stop.')\n await waitForSignal()\n await session.close()\n console.log('[Seed Protocol] Raw tunnel client stopped.')\n return\n }\n\n console.log(`[Seed Protocol] Connecting to operator ${key}`)\n const session = await connectTunnel({\n key,\n keyFile,\n host: values.host,\n port: parsePort(values.port, DEFAULT_PORT),\n connectTimeoutMs,\n requestTimeoutMs: parseMs(values['request-timeout-ms'], '--request-timeout-ms'),\n maxStreams: parseCount(values['max-streams'], '--max-streams'),\n })\n console.log(\n `[Seed Protocol] Client key (z32): ${session.clientKey}${keyFile ? '' : ' (new for this run)'}`,\n )\n console.log(`[Seed Protocol] Local sidecar: ${session.baseUrl}`)\n console.log(\n '[Seed Protocol] Point SDK transport=hyper or hybrid at this URL (default sidecar port 1984).',\n )\n console.log('[Seed Protocol] Press Ctrl+C to stop.')\n await waitForSignal()\n await session.close()\n console.log('[Seed Protocol] Gateway sidecar stopped.')\n return\n }\n\n fail(`Unknown command: ${command}`)\n}\n","/**\n * `seed-gateway serve|connect` — HTTP tunnel to Seed gateway + upload API infrastructure over HyperDHT.\n * Run under Node (Holepunch natives may crash under Bun).\n */\nimport process from 'node:process'\nimport { main } from './cli'\n\nmain(process.argv.slice(2)).catch((err) => {\n console.error('[Seed Protocol]', err instanceof Error ? err.message : err)\n process.exit(1)\n})\n"],"mappings":";;;;;;AAoBA,IAAMS,IAA4BF,EAAK,KAAK,SAAS,kBAAkB,mBAAmB,GACpFG,IAAe,MAEfC,IAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;8BA0BgBN,EAA8B;;;gEAGIO,EAAiB;;;;;AAMjF,SAASC,EAAK,GAAwB;CAGpC,AAFA,QAAQ,MAAM,mBAAmBC,GAAS,GAC1C,QAAQ,MAAMH,CAAK,GACnBH,EAAQ,KAAK,CAAC;AAChB;AAEA,SAASO,EAAQ,GAA2B,GAAkC;CAC5E,IAAIC,MAAU,KAAA,GAAW;CACzB,IAAMC,IAAK,OAAOD,CAAK;CAEvB,QADI,CAAC,OAAO,UAAUC,CAAE,KAAKA,IAAK,MAAG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MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,MAAQ;CAEzC,AADA,QAAQ,MAAM,mBAAmBwC,aAAe,QAAQA,EAAI,UAAUA,CAAG,GACzExC,EAAQ,KAAK,CAAC;AAChB,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type RawClientEvent, type RawTunnelEvent, type TunnelEvent } from './index';
|
|
2
|
+
/** One `tunnel-trace` line per event: ISO time, event name, then `key=value` fields. */
|
|
3
|
+
export declare function formatTunnelEvent(event: TunnelEvent | RawTunnelEvent | RawClientEvent, now?: Date): string;
|
|
4
|
+
export declare function main(argv: string[]): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAMA,OAAO,EASL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,WAAW,EACjB,MAAM,SAAS,CAAA;AA4DhB,wFAAwF;AACxF,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,WAAW,GAAG,cAAc,GAAG,cAAc,EACpD,GAAG,OAAa,GACf,MAAM,CAQR;AAgCD,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA0IxD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
export { encodePublicKeyZ32, decodePublicKey, loadOrCreateOperatorKeypair } from './keys';
|
|
2
2
|
export { serveTunnel } from './tunnel/serve';
|
|
3
|
+
export { createAllowlist } from './tunnel/allowlist';
|
|
4
|
+
export { serveRawTunnel, DEFAULT_RAW_OPERATOR_KEY_FILE } from './tunnel/rawServe';
|
|
5
|
+
export { connectRawTunnel, DEFAULT_MAX_RAW_CONNECTIONS, DEFAULT_RAW_PORT, } from './tunnel/rawConnect';
|
|
6
|
+
export { RAW_CLOSE_GRACE_MS } from './tunnel/rawPipe';
|
|
7
|
+
export type { RawClientEvent, RawClientEventListener, RawTunnelEvent, RawTunnelEventListener, TunnelEvent, TunnelEventListener, TunnelEventName, UpstreamPhase, } from './tunnel/events';
|
|
8
|
+
export type { Allowlist, AllowlistOptions, AllowlistStream, AllowlistVerdict, AllowedBy, } from './tunnel/allowlist';
|
|
3
9
|
export { connectTunnel, localGatewayUrl } from './tunnel/connect';
|
|
4
10
|
export { createGatewayProxy } from './tunnel/proxyApp';
|
|
5
11
|
export { stripMountPath } from './tunnel/mountPath';
|
|
6
12
|
export { createTunnelSession, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_MAX_STREAMS, DEFAULT_REQUEST_TIMEOUT_MS, } from './tunnel/session';
|
|
7
13
|
export type { TunnelRequestOptions, TunnelSession, TunnelSessionOptions } from './tunnel/session';
|
|
8
|
-
export { DEFAULT_UPSTREAM_TIMEOUT_MS } from './tunnel/proxy';
|
|
14
|
+
export { DEFAULT_UPSTREAM_TIMEOUT_MS, upstreamRequestHeaders } from './tunnel/proxy';
|
|
9
15
|
export { TunnelConnectTimeoutError, TunnelTimeoutError, UpstreamTimeoutError, } from './tunnel/errors';
|
|
10
16
|
export { writeFrame, readFrame, writeTunnelRequest, readTunnelRequest, writeTunnelResponse, readTunnelResponse, flattenRequestHeaders, filterResponseHeaders, MAX_FRAME_BYTES, } from './tunnel/protocol';
|
|
11
|
-
export type { TunnelMeta, TunnelResponseMeta, ServeTunnelOptions, ServeTunnelResult, ConnectTunnelOptions, ConnectTunnelResult, OperatorKeyPair, CreateGatewayProxyOptions, GatewayProxy, } from './types';
|
|
17
|
+
export type { DhtBootstrapNode, TunnelMeta, TunnelResponseMeta, ServeTunnelOptions, ServeTunnelResult, ConnectTunnelOptions, ConnectTunnelResult, ServeRawTunnelOptions, ServeRawTunnelResult, ConnectRawTunnelOptions, ConnectRawTunnelResult, OperatorKeyPair, CreateGatewayProxyOptions, GatewayProxy, } from './types';
|
|
12
18
|
export { DEFAULT_SEED_GATEWAY_HYPER_KEY } from './constants';
|
|
13
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,QAAQ,CAAA;AAEzF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,kBAAkB,CAAA;AACzB,YAAY,EAAE,oBAAoB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACjG,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,QAAQ,CAAA;AAEzF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AACjF,OAAO,EACL,gBAAgB,EAChB,2BAA2B,EAC3B,gBAAgB,GACjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,YAAY,EACV,cAAc,EACd,sBAAsB,EACtB,cAAc,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_RAW_CONNECTIONS, u as DEFAULT_MAX_STREAMS, p as DEFAULT_RAW_OPERATOR_KEY_FILE, s as DEFAULT_RAW_PORT, d as DEFAULT_REQUEST_TIMEOUT_MS, t as DEFAULT_SEED_GATEWAY_HYPER_KEY, v as DEFAULT_UPSTREAM_TIMEOUT_MS, C as MAX_FRAME_BYTES, h as RAW_CLOSE_GRACE_MS, b as TunnelConnectTimeoutError, x as TunnelTimeoutError, S as UpstreamTimeoutError, c as connectRawTunnel, r as connectTunnel, _ as createAllowlist, n as createGatewayProxy, f as createTunnelSession, M as decodePublicKey, N as encodePublicKeyZ32, w as filterResponseHeaders, T as flattenRequestHeaders, P as loadOrCreateOperatorKeypair, i as localGatewayUrl, E as readFrame, D as readTunnelRequest, O as readTunnelResponse, m as serveRawTunnel, g as serveTunnel, a as stripMountPath, y as upstreamRequestHeaders, k as writeFrame, A as writeTunnelRequest, j as writeTunnelResponse } from "./src-DHEkxp5F.js";
|
package/dist/keys.d.ts
CHANGED
|
@@ -7,5 +7,21 @@ export interface PersistedKeyFile {
|
|
|
7
7
|
export declare function encodePublicKeyZ32(publicKey: Buffer): string;
|
|
8
8
|
export declare function decodePublicKey(key: string): Buffer;
|
|
9
9
|
export declare function loadOrCreateOperatorKeypair(keyFile: string): OperatorKeyPair;
|
|
10
|
+
/** Check a keypair passed in code and add its z32 key. */
|
|
11
|
+
export declare function toOperatorKeypair(keyPair: {
|
|
12
|
+
publicKey: Buffer;
|
|
13
|
+
secretKey: Buffer;
|
|
14
|
+
}): OperatorKeyPair;
|
|
15
|
+
/**
|
|
16
|
+
* The keypair a client presents to the operator: `keyPair` if given, else the one in
|
|
17
|
+
* `keyFile` (created on first use), else a new one for this run only.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveClientKeypair(options: {
|
|
20
|
+
keyFile?: string;
|
|
21
|
+
keyPair?: {
|
|
22
|
+
publicKey: Buffer;
|
|
23
|
+
secretKey: Buffer;
|
|
24
|
+
};
|
|
25
|
+
}): OperatorKeyPair;
|
|
10
26
|
export declare function createEphemeralClientKeypair(): OperatorKeyPair;
|
|
11
27
|
//# sourceMappingURL=keys.d.ts.map
|
package/dist/keys.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,KAAK,CAAA;CAChB;AAUD,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAanD;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CA+B5E;AAED,wBAAgB,4BAA4B,IAAI,eAAe,CAO9D"}
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,KAAK,CAAA;CAChB;AAUD,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAanD;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CA+B5E;AAED,0DAA0D;AAC1D,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,eAAe,CAUpG;AAED;;;GAG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