@seedprotocol/gateway-hyper 0.7.12-next.1434.gd03298c → 0.7.12-next.1475.gf78a8a4
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/dist/bin.js +171 -119
- package/dist/bin.js.map +1 -1
- package/dist/cli.d.ts +3 -3
- package/dist/cli.d.ts.map +1 -1
- package/dist/index.d.ts +19 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/keys.d.ts +12 -1
- package/dist/keys.d.ts.map +1 -1
- package/dist/{src-DHEkxp5F.js → src-C_1bcYLA.js} +124 -85
- package/dist/src-C_1bcYLA.js.map +1 -0
- package/dist/tunnel/connect.d.ts +1 -1
- package/dist/tunnel/connect.d.ts.map +1 -1
- package/dist/tunnel/events.d.ts +3 -1
- package/dist/tunnel/events.d.ts.map +1 -1
- package/dist/tunnel/forward.d.ts +1 -1
- package/dist/tunnel/protocol.d.ts +1 -1
- package/dist/tunnel/protocol.d.ts.map +1 -1
- package/dist/tunnel/proxy.d.ts +7 -3
- package/dist/tunnel/proxy.d.ts.map +1 -1
- package/dist/tunnel/proxyApp.d.ts +1 -1
- package/dist/tunnel/proxyApp.d.ts.map +1 -1
- package/dist/tunnel/rawConnect.d.ts +1 -1
- package/dist/tunnel/rawServe.d.ts +1 -1
- package/dist/tunnel/rawServe.d.ts.map +1 -1
- package/dist/tunnel/serve.d.ts +3 -3
- package/dist/tunnel/serve.d.ts.map +1 -1
- package/dist/tunnel/session.d.ts +4 -5
- package/dist/tunnel/session.d.ts.map +1 -1
- package/dist/types.d.ts +15 -13
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/src-DHEkxp5F.js.map +0 -1
package/dist/bin.js
CHANGED
|
@@ -1,116 +1,155 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { parseArgs as
|
|
2
|
+
import { F as e, _ as t, c as n, g as r, m as i, p as a, r as o, s, v as c } from "./src-C_1bcYLA.js";
|
|
3
|
+
import l from "node:path";
|
|
4
|
+
import u from "node:process";
|
|
5
|
+
import { parseArgs as d } from "node:util";
|
|
6
6
|
//#region src/cli.ts
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Operator: accept Hyper connections and proxy them to a local HTTP upstream.
|
|
7
|
+
var f = l.join(".seed", "gateway-tunnel", "operator.key.json"), p = 1984, m = " --bootstrap host:port,host:port joins a private or local HyperDHT network instead of the\n public one (both sides need the same nodes).", h = ` seed-gateway serve [--upstream http://127.0.0.1:80] [--key-file <path>] [--upstream-timeout-ms 130000]
|
|
8
|
+
[--allow-keys k1,k2] [--allow-ips 192.168.1.0/24,203.0.113.7] [--bootstrap host:port,...]
|
|
9
|
+
Operator: accept Hyper connections and proxy them to a local HTTP upstream (http:// only).
|
|
11
10
|
Default --key-file: ./.seed/gateway-tunnel/operator.key.json (created on first run).
|
|
12
11
|
Answers 504 when the upstream is idle for --upstream-timeout-ms (0 disables).
|
|
13
12
|
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.
|
|
13
|
+
can connect. A client on the operator's LAN shows its LAN address. A client refused by
|
|
14
|
+
address gets a 403 for its request.
|
|
15
15
|
--trace logs each stream and request event as a \`tunnel-trace <event> key=value\` line.
|
|
16
16
|
--request-id-header <name> sends each request's id upstream under that header.
|
|
17
|
+
${m}
|
|
17
18
|
|
|
18
|
-
seed-gateway
|
|
19
|
-
|
|
19
|
+
seed-gateway serve --raw [--upstream http://127.0.0.1:80] [--key-file <path>]
|
|
20
|
+
[--allow-keys ...] [--allow-ips ...] [--trace] [--bootstrap host:port,...]
|
|
21
|
+
Operator, raw mode: pipe each Hyper connection byte for byte to a new TCP connection to
|
|
22
|
+
the upstream, so HTTP runs end to end with no size limit, streaming and WebSockets.
|
|
23
|
+
Default --key-file: ./${a}. Raw and framed servers need
|
|
24
|
+
separate keys; clients of one can't talk to the other.`, g = ` seed-gateway connect <key> [--host 127.0.0.1] [--port 1984] [--request-timeout-ms 150000]
|
|
25
|
+
[--connect-timeout-ms 30000] [--key-file <path>] [--bootstrap host:port,...]
|
|
20
26
|
Client: dial an operator key and expose a localhost HTTP sidecar.
|
|
21
27
|
Abandons a request and reconnects when the tunnel is idle for --request-timeout-ms.
|
|
22
28
|
[--max-streams 4] opens up to that many streams to the operator, one request each.
|
|
23
29
|
--key-file keeps this client's key in a file (created on first run), so the operator
|
|
24
30
|
can list it with --allow-keys. Without it, each run uses a new key.
|
|
31
|
+
${m}
|
|
25
32
|
|
|
26
33
|
seed-gateway connect --print-key --key-file <path>
|
|
27
34
|
Print the client public key (z32) in the key file, creating the file if missing.
|
|
28
35
|
|
|
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
36
|
seed-gateway connect --raw <key> [--host 127.0.0.1] [--port ${s}] [--key-file <path>]
|
|
37
37
|
[--max-connections 64] [--connect-timeout-ms 30000] [--trace]
|
|
38
|
+
[--bootstrap host:port,...]
|
|
38
39
|
Client, raw mode: listen on a local TCP port and carry each connection to a raw operator
|
|
39
40
|
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
|
-
|
|
42
|
-
|
|
41
|
+
keepalive) in front; each new connection costs a DHT lookup and handshake.`, _ = `Usage:
|
|
42
|
+
${h}
|
|
43
|
+
|
|
44
|
+
${g}`, v = {
|
|
45
|
+
serve: [
|
|
46
|
+
"upstream",
|
|
47
|
+
"key-file",
|
|
48
|
+
"upstream-timeout-ms",
|
|
49
|
+
"allow-keys",
|
|
50
|
+
"allow-ips",
|
|
51
|
+
"trace",
|
|
52
|
+
"request-id-header",
|
|
53
|
+
"bootstrap"
|
|
54
|
+
],
|
|
55
|
+
"serve --raw": [
|
|
56
|
+
"raw",
|
|
57
|
+
"upstream",
|
|
58
|
+
"key-file",
|
|
59
|
+
"allow-keys",
|
|
60
|
+
"allow-ips",
|
|
61
|
+
"trace",
|
|
62
|
+
"bootstrap"
|
|
63
|
+
],
|
|
64
|
+
connect: [
|
|
65
|
+
"host",
|
|
66
|
+
"port",
|
|
67
|
+
"request-timeout-ms",
|
|
68
|
+
"connect-timeout-ms",
|
|
69
|
+
"key-file",
|
|
70
|
+
"max-streams",
|
|
71
|
+
"bootstrap"
|
|
72
|
+
],
|
|
73
|
+
"connect --print-key": ["print-key", "key-file"],
|
|
74
|
+
"connect --raw": [
|
|
75
|
+
"raw",
|
|
76
|
+
"host",
|
|
77
|
+
"port",
|
|
78
|
+
"key-file",
|
|
79
|
+
"max-connections",
|
|
80
|
+
"connect-timeout-ms",
|
|
81
|
+
"trace",
|
|
82
|
+
"bootstrap"
|
|
83
|
+
]
|
|
84
|
+
};
|
|
85
|
+
function y(e, t) {
|
|
86
|
+
let n = v[e] ?? [];
|
|
87
|
+
for (let [r, i] of Object.entries(t)) i === void 0 || i === !1 || n.includes(r) || console.warn(`[Seed Protocol] --${r} has no effect with ${e}; ignoring it.`);
|
|
88
|
+
}
|
|
89
|
+
function b(e) {
|
|
90
|
+
console.error(`[Seed Protocol] ${e}`), console.error(_), u.exit(1);
|
|
43
91
|
}
|
|
44
|
-
function
|
|
92
|
+
function x(e, t) {
|
|
45
93
|
if (e === void 0) return;
|
|
46
94
|
let n = Number(e);
|
|
47
|
-
return (!Number.isInteger(n) || n < 0) &&
|
|
95
|
+
return (!Number.isInteger(n) || n < 0) && b(`${t} must be a whole number of milliseconds`), n;
|
|
48
96
|
}
|
|
49
|
-
function
|
|
97
|
+
function S(e, t) {
|
|
50
98
|
if (e === void 0) return;
|
|
51
99
|
let n = Number(e);
|
|
52
|
-
return (!Number.isInteger(n) || n < 1) &&
|
|
100
|
+
return (!Number.isInteger(n) || n < 1) && b(`${t} must be a whole number of at least 1`), n;
|
|
53
101
|
}
|
|
54
|
-
function
|
|
55
|
-
|
|
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));
|
|
102
|
+
function C(e) {
|
|
103
|
+
console.log(t(e));
|
|
69
104
|
}
|
|
70
|
-
function
|
|
105
|
+
function w(e, t) {
|
|
71
106
|
if (e === void 0) return t;
|
|
72
107
|
let n = Number(e);
|
|
73
|
-
return (!Number.isInteger(n) || n < 0 || n > 65535) &&
|
|
108
|
+
return (!Number.isInteger(n) || n < 0 || n > 65535) && b("--port must be 0–65535"), n;
|
|
74
109
|
}
|
|
75
|
-
function
|
|
110
|
+
function T(e) {
|
|
111
|
+
if (e === void 0) return;
|
|
112
|
+
let t = E(e).map((e) => {
|
|
113
|
+
let t = e.lastIndexOf(":"), n = e.slice(0, t).replace(/^\[(.*)\]$/, "$1"), r = Number(e.slice(t + 1));
|
|
114
|
+
return (t <= 0 || !n || !Number.isInteger(r) || r < 1 || r > 65535) && b(`--bootstrap entries must be host:port, got "${e}"`), {
|
|
115
|
+
host: n,
|
|
116
|
+
port: r
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
return t.length === 0 && b("--bootstrap needs at least one host:port"), t;
|
|
120
|
+
}
|
|
121
|
+
function E(e) {
|
|
76
122
|
return (e ?? "").split(",").map((e) => e.trim()).filter(Boolean);
|
|
77
123
|
}
|
|
78
|
-
function
|
|
124
|
+
function D() {
|
|
79
125
|
return new Promise((e) => {
|
|
80
126
|
let t = () => {
|
|
81
|
-
|
|
127
|
+
u.off("SIGINT", t), u.off("SIGTERM", t), e();
|
|
82
128
|
};
|
|
83
|
-
|
|
129
|
+
u.on("SIGINT", t), u.on("SIGTERM", t);
|
|
84
130
|
});
|
|
85
131
|
}
|
|
86
|
-
async function
|
|
87
|
-
let [
|
|
88
|
-
if (!
|
|
89
|
-
console.log(
|
|
132
|
+
async function O(t) {
|
|
133
|
+
let [a, ...u] = t;
|
|
134
|
+
if (!a || a === "--help" || a === "-h" || a === "help") {
|
|
135
|
+
console.log(_);
|
|
90
136
|
return;
|
|
91
137
|
}
|
|
92
|
-
|
|
93
|
-
|
|
138
|
+
a !== "serve" && a !== "connect" && b(`Unknown command: ${a}`);
|
|
139
|
+
let { values: m, positionals: v } = d({
|
|
140
|
+
args: u,
|
|
94
141
|
allowPositionals: !0,
|
|
95
142
|
options: {
|
|
96
|
-
|
|
97
|
-
type: "string",
|
|
98
|
-
default: "http://127.0.0.1:80"
|
|
99
|
-
},
|
|
100
|
-
"key-file": { type: "string" },
|
|
101
|
-
"print-key": {
|
|
143
|
+
help: {
|
|
102
144
|
type: "boolean",
|
|
103
|
-
|
|
104
|
-
},
|
|
105
|
-
host: {
|
|
106
|
-
type: "string",
|
|
107
|
-
default: "127.0.0.1"
|
|
145
|
+
short: "h"
|
|
108
146
|
},
|
|
147
|
+
upstream: { type: "string" },
|
|
148
|
+
"key-file": { type: "string" },
|
|
149
|
+
"print-key": { type: "boolean" },
|
|
150
|
+
host: { type: "string" },
|
|
109
151
|
port: { type: "string" },
|
|
110
|
-
raw: {
|
|
111
|
-
type: "boolean",
|
|
112
|
-
default: !1
|
|
113
|
-
},
|
|
152
|
+
raw: { type: "boolean" },
|
|
114
153
|
"max-connections": { type: "string" },
|
|
115
154
|
"connect-timeout-ms": { type: "string" },
|
|
116
155
|
"upstream-timeout-ms": { type: "string" },
|
|
@@ -118,85 +157,98 @@ async function S(a) {
|
|
|
118
157
|
"max-streams": { type: "string" },
|
|
119
158
|
"allow-keys": { type: "string" },
|
|
120
159
|
"allow-ips": { type: "string" },
|
|
121
|
-
trace: {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
},
|
|
125
|
-
"request-id-header": { type: "string" }
|
|
160
|
+
trace: { type: "boolean" },
|
|
161
|
+
"request-id-header": { type: "string" },
|
|
162
|
+
bootstrap: { type: "string" }
|
|
126
163
|
}
|
|
127
164
|
});
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
165
|
+
if (m.help) {
|
|
166
|
+
console.log(`Usage:\n${a === "serve" ? h : g}`);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
y(m["print-key"] && a === "connect" ? "connect --print-key" : m.raw ? `${a} --raw` : a, m);
|
|
170
|
+
let O = {
|
|
171
|
+
...m,
|
|
172
|
+
upstream: m.upstream ?? "http://127.0.0.1:80",
|
|
173
|
+
host: m.host ?? "127.0.0.1",
|
|
174
|
+
trace: m.trace ?? !1
|
|
175
|
+
}, k = T(m.bootstrap);
|
|
176
|
+
if (a === "serve" && O.raw) {
|
|
177
|
+
let e = O.upstream.trim(), t = l.resolve(O["key-file"] ?? ".seed/gateway-tunnel/raw-operator.key.json");
|
|
178
|
+
console.log(`[Seed Protocol] Raw tunnel upstream: ${e}`), console.log(`[Seed Protocol] Raw operator key file: ${t}`);
|
|
179
|
+
let n = {
|
|
180
|
+
keys: E(O["allow-keys"]),
|
|
181
|
+
ips: E(O["allow-ips"])
|
|
134
182
|
};
|
|
135
|
-
console.log(`[Seed Protocol] Allowlist: ${
|
|
136
|
-
let
|
|
183
|
+
console.log(`[Seed Protocol] Allowlist: ${c(n).summary}`);
|
|
184
|
+
let r = await i({
|
|
137
185
|
upstream: e,
|
|
138
|
-
keyFile:
|
|
139
|
-
allowlist:
|
|
140
|
-
|
|
186
|
+
keyFile: t,
|
|
187
|
+
allowlist: n,
|
|
188
|
+
bootstrap: k,
|
|
189
|
+
onEvent: O.trace ? C : void 0
|
|
141
190
|
});
|
|
142
|
-
console.log(`[Seed Protocol] Raw operator key (z32): ${
|
|
143
|
-
} else if (
|
|
144
|
-
let e =
|
|
145
|
-
console.log(`[Seed Protocol] Gateway tunnel upstream: ${e}`), console.log(`[Seed Protocol] Operator key file: ${
|
|
146
|
-
let
|
|
147
|
-
keys:
|
|
148
|
-
ips:
|
|
191
|
+
console.log(`[Seed Protocol] Raw operator key (z32): ${r.key}`), console.log("[Seed Protocol] Clients connect with: seed-gateway connect --raw <key>"), console.log("[Seed Protocol] Press Ctrl+C to stop."), await D(), await r.close(), console.log("[Seed Protocol] Raw tunnel stopped.");
|
|
192
|
+
} else if (a === "serve") {
|
|
193
|
+
let e = O.upstream.trim(), t = l.resolve(O["key-file"] ?? f);
|
|
194
|
+
console.log(`[Seed Protocol] Gateway tunnel upstream: ${e}`), console.log(`[Seed Protocol] Operator key file: ${t}`);
|
|
195
|
+
let n = {
|
|
196
|
+
keys: E(O["allow-keys"]),
|
|
197
|
+
ips: E(O["allow-ips"])
|
|
149
198
|
};
|
|
150
|
-
console.log(`[Seed Protocol] Allowlist: ${
|
|
151
|
-
let
|
|
199
|
+
console.log(`[Seed Protocol] Allowlist: ${c(n).summary}`);
|
|
200
|
+
let i = await r({
|
|
152
201
|
upstream: e,
|
|
153
|
-
keyFile:
|
|
154
|
-
allowlist:
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
202
|
+
keyFile: t,
|
|
203
|
+
allowlist: n,
|
|
204
|
+
bootstrap: k,
|
|
205
|
+
onEvent: O.trace ? C : void 0,
|
|
206
|
+
requestIdHeader: O["request-id-header"]?.trim() || void 0,
|
|
207
|
+
upstreamTimeoutMs: x(O["upstream-timeout-ms"], "--upstream-timeout-ms")
|
|
158
208
|
});
|
|
159
|
-
console.log(`[Seed Protocol] Operator key (z32): ${
|
|
160
|
-
} else if (
|
|
161
|
-
let t =
|
|
162
|
-
if (
|
|
163
|
-
t ||
|
|
209
|
+
console.log(`[Seed Protocol] Operator key (z32): ${i.key}`), console.log("[Seed Protocol] Share this key with SDK users (gatewayHyperKey)."), console.log("[Seed Protocol] Press Ctrl+C to stop."), await D(), await i.close(), console.log("[Seed Protocol] Gateway tunnel stopped.");
|
|
210
|
+
} else if (a === "connect") {
|
|
211
|
+
let t = O["key-file"] ? l.resolve(O["key-file"]) : void 0;
|
|
212
|
+
if (O["print-key"]) {
|
|
213
|
+
t || b("--print-key requires --key-file"), console.log(e(t).z32);
|
|
164
214
|
return;
|
|
165
215
|
}
|
|
166
|
-
let r =
|
|
167
|
-
r ||
|
|
168
|
-
let i =
|
|
169
|
-
if (
|
|
216
|
+
let r = v[0];
|
|
217
|
+
r || b("seed-gateway connect requires an operator public key (z32 or hex)");
|
|
218
|
+
let i = x(O["connect-timeout-ms"], "--connect-timeout-ms");
|
|
219
|
+
if (O.raw) {
|
|
170
220
|
console.log(`[Seed Protocol] Connecting to raw operator ${r}`);
|
|
171
221
|
let e = await n({
|
|
172
222
|
key: r,
|
|
173
223
|
keyFile: t,
|
|
174
|
-
host:
|
|
175
|
-
port:
|
|
176
|
-
maxConnections:
|
|
224
|
+
host: O.host,
|
|
225
|
+
port: w(O.port, s),
|
|
226
|
+
maxConnections: S(O["max-connections"], "--max-connections"),
|
|
177
227
|
connectTimeoutMs: i,
|
|
178
|
-
|
|
228
|
+
bootstrap: k,
|
|
229
|
+
onEvent: O.trace ? C : void 0
|
|
179
230
|
});
|
|
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
|
|
231
|
+
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 D(), await e.close(), console.log("[Seed Protocol] Raw tunnel client stopped.");
|
|
181
232
|
return;
|
|
182
233
|
}
|
|
183
234
|
console.log(`[Seed Protocol] Connecting to operator ${r}`);
|
|
184
235
|
let a = await o({
|
|
185
236
|
key: r,
|
|
186
237
|
keyFile: t,
|
|
187
|
-
host:
|
|
188
|
-
port:
|
|
238
|
+
host: O.host,
|
|
239
|
+
port: w(O.port, p),
|
|
189
240
|
connectTimeoutMs: i,
|
|
190
|
-
|
|
191
|
-
|
|
241
|
+
bootstrap: k,
|
|
242
|
+
requestTimeoutMs: x(O["request-timeout-ms"], "--request-timeout-ms"),
|
|
243
|
+
maxStreams: S(O["max-streams"], "--max-streams")
|
|
192
244
|
});
|
|
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
|
|
194
|
-
}
|
|
245
|
+
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 D(), await a.close(), console.log("[Seed Protocol] Gateway sidecar stopped.");
|
|
246
|
+
}
|
|
195
247
|
}
|
|
196
248
|
//#endregion
|
|
197
249
|
//#region src/bin.ts
|
|
198
|
-
|
|
199
|
-
console.error("[Seed Protocol]", e instanceof Error ? e.message : e),
|
|
250
|
+
O(u.argv.slice(2)).catch((e) => {
|
|
251
|
+
console.error("[Seed Protocol]", e instanceof Error ? e.message : e), u.exit(1);
|
|
200
252
|
});
|
|
201
253
|
//#endregion
|
|
202
254
|
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 HTTP upstream.\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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GACA;GACA,MAAMmC,EAAO;GACb,MAAMb,EAAUa,EAAO,MAAM/B,CAAY;GACzC;GACA,kBAAkBK,EAAQ0B,EAAO,uBAAuB,sBAAsB;GAC9E,YAAYtB,EAAWsB,EAAO,gBAAgB,eAAe;EAC/D,CAAC;EAWD,AAVA,QAAQ,IACN,qCAAqCI,EAAQ,YAAYF,IAAU,KAAK,uBAC1E,GACA,QAAQ,IAAI,kCAAkCE,EAAQ,SAAS,GAC/D,QAAQ,IACN,8FACF,GACA,QAAQ,IAAI,uCAAuC,GACnD,MAAMZ,EAAc,GACpB,MAAMY,EAAQ,MAAM,GACpB,QAAQ,IAAI,0CAA0C;CAExD,OAEA,EAAK,oBAAoBR,GAAS;AACpC;;;AC7PAD,EAAK5B,EAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,MAAQ;CAEzC,AADA,QAAQ,MAAM,mBAAmBwC,aAAe,QAAQA,EAAI,UAAUA,CAAG,GACzExC,EAAQ,KAAK,CAAC;AAChB,CAAC"}
|
|
1
|
+
{"version":3,"file":"bin.js","names":["loadOrCreateOperatorKeypair","formatTunnelEvent","connectRawTunnel","serveTunnel","serveRawTunnel","DEFAULT_RAW_OPERATOR_KEY_FILE","connectTunnel","createAllowlist","path","process","DEFAULT_OPERATOR_KEY_FILE","DEFAULT_PORT","BOOTSTRAP_HELP","SERVE_USAGE","CONNECT_USAGE","DEFAULT_RAW_PORT","USAGE","MODE_FLAGS","warnIgnoredFlags","read","mode","flag","value","given","fail","message","parseMs","ms","parseCount","count","logTunnelEvent","event","parsePort","fallback","port","parseBootstrap","nodes","splitList","colon","entry","host","waitForSignal","onStop","resolve","main","command","rest","argv","parseArgs","values","bootstrap","upstream","keyFile","allowlist","session","key","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 formatTunnelEvent,\n DEFAULT_RAW_OPERATOR_KEY_FILE,\n DEFAULT_RAW_PORT,\n loadOrCreateOperatorKeypair,\n serveRawTunnel,\n serveTunnel,\n type DhtBootstrapNode,\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 BOOTSTRAP_HELP = ` --bootstrap host:port,host:port joins a private or local HyperDHT network instead of the\n public one (both sides need the same nodes).`\n\nconst SERVE_USAGE = ` seed-gateway serve [--upstream http://127.0.0.1:80] [--key-file <path>] [--upstream-timeout-ms 130000]\n [--allow-keys k1,k2] [--allow-ips 192.168.1.0/24,203.0.113.7] [--bootstrap host:port,...]\n Operator: accept Hyper connections and proxy them to a local HTTP upstream (http:// only).\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. A client refused by\n address gets a 403 for its request.\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${BOOTSTRAP_HELP}\n\n seed-gateway serve --raw [--upstream http://127.0.0.1:80] [--key-file <path>]\n [--allow-keys ...] [--allow-ips ...] [--trace] [--bootstrap host:port,...]\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\nconst CONNECT_USAGE = ` seed-gateway connect <key> [--host 127.0.0.1] [--port 1984] [--request-timeout-ms 150000]\n [--connect-timeout-ms 30000] [--key-file <path>] [--bootstrap host:port,...]\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${BOOTSTRAP_HELP}\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 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 [--bootstrap host:port,...]\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\nconst USAGE = `Usage:\n${SERVE_USAGE}\n\n${CONNECT_USAGE}`\n\n/** Flags each mode reads; any other flag given is ignored, with a warning. */\nconst MODE_FLAGS: Record<string, readonly string[]> = {\n serve: ['upstream', 'key-file', 'upstream-timeout-ms', 'allow-keys', 'allow-ips', 'trace', 'request-id-header', 'bootstrap'],\n 'serve --raw': ['raw', 'upstream', 'key-file', 'allow-keys', 'allow-ips', 'trace', 'bootstrap'],\n connect: ['host', 'port', 'request-timeout-ms', 'connect-timeout-ms', 'key-file', 'max-streams', 'bootstrap'],\n 'connect --print-key': ['print-key', 'key-file'],\n 'connect --raw': ['raw', 'host', 'port', 'key-file', 'max-connections', 'connect-timeout-ms', 'trace', 'bootstrap'],\n}\n\nfunction warnIgnoredFlags(mode: string, given: Record<string, unknown>): void {\n const read = MODE_FLAGS[mode] ?? []\n for (const [flag, value] of Object.entries(given)) {\n if (value === undefined || value === false || read.includes(flag)) continue\n console.warn(`[Seed Protocol] --${flag} has no effect with ${mode}; ignoring it.`)\n }\n}\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 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\n/** `host:port,host:port` (IPv6 hosts in brackets) as HyperDHT bootstrap nodes. */\nexport function parseBootstrap(value: string | undefined): DhtBootstrapNode[] | undefined {\n if (value === undefined) return undefined\n const nodes = splitList(value).map((entry) => {\n const colon = entry.lastIndexOf(':')\n const host = entry.slice(0, colon).replace(/^\\[(.*)\\]$/, '$1')\n const port = Number(entry.slice(colon + 1))\n if (colon <= 0 || !host || !Number.isInteger(port) || port < 1 || port > 65535) {\n fail(`--bootstrap entries must be host:port, got \"${entry}\"`)\n }\n return { host, port }\n })\n if (nodes.length === 0) fail('--bootstrap needs at least one host:port')\n return nodes\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 if (command !== 'serve' && command !== 'connect') fail(`Unknown command: ${command}`)\n\n const { values: given, positionals } = parseArgs({\n args: rest,\n allowPositionals: true,\n // No defaults here: a flag is \"given\" only when typed, so flags a mode ignores can be named.\n options: {\n help: { type: 'boolean', short: 'h' },\n upstream: { type: 'string' },\n 'key-file': { type: 'string' },\n 'print-key': { type: 'boolean' },\n host: { type: 'string' },\n port: { type: 'string' },\n raw: { type: 'boolean' },\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' },\n 'request-id-header': { type: 'string' },\n bootstrap: { type: 'string' },\n },\n })\n\n if (given.help) {\n console.log(`Usage:\\n${command === 'serve' ? SERVE_USAGE : CONNECT_USAGE}`)\n return\n }\n\n const mode = given['print-key'] && command === 'connect' ? 'connect --print-key' : given.raw ? `${command} --raw` : command\n warnIgnoredFlags(mode, given)\n const values = {\n ...given,\n upstream: given.upstream ?? 'http://127.0.0.1:80',\n host: given.host ?? '127.0.0.1',\n trace: given.trace ?? false,\n }\n const bootstrap = parseBootstrap(given.bootstrap)\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 bootstrap,\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 bootstrap,\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 bootstrap,\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 bootstrap,\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","/**\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":";;;;;;AAsBA,IAAMU,IAA4BF,EAAK,KAAK,SAAS,kBAAkB,mBAAmB,GACpFG,IAAe,MAEfC,IAAiB,sJAGjBC,IAAc;;;;;;;;;;EAUlBD,EAAe;;;;;;8BAMaP,EAA8B;+DAGtDS,IAAgB;;;;;;;EAOpBF,EAAe;;;;;gEAK+CG,EAAiB;;;;;mFAO3EC,IAAQ;EACZH,EAAY;;EAEZC,KAGIG,IAAgD;CACpD,OAAO;EAAC;EAAY;EAAY;EAAuB;EAAc;EAAa;EAAS;EAAqB;CAAW;CAC3H,eAAe;EAAC;EAAO;EAAY;EAAY;EAAc;EAAa;EAAS;CAAW;CAC9F,SAAS;EAAC;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,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,MAAQ;CAEzC,AADA,QAAQ,MAAM,mBAAmBiD,aAAe,QAAQA,EAAI,UAAUA,CAAG,GACzEjD,EAAQ,KAAK,CAAC;AAChB,CAAC"}
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
/**
|
|
3
|
-
export declare function
|
|
1
|
+
import { type DhtBootstrapNode } from './index.js';
|
|
2
|
+
/** `host:port,host:port` (IPv6 hosts in brackets) as HyperDHT bootstrap nodes. */
|
|
3
|
+
export declare function parseBootstrap(value: string | undefined): DhtBootstrapNode[] | undefined;
|
|
4
4
|
export declare function main(argv: string[]): Promise<void>;
|
|
5
5
|
//# sourceMappingURL=cli.d.ts.map
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAMA,OAAO,
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAMA,OAAO,EAUL,KAAK,gBAAgB,EAItB,MAAM,SAAS,CAAA;AAmGhB,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,gBAAgB,EAAE,GAAG,SAAS,CAaxF;AAqBD,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA8JxD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
export { encodePublicKeyZ32, decodePublicKey, loadOrCreateOperatorKeypair } from './keys';
|
|
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
|
|
8
|
-
export type {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
17
|
-
export
|
|
18
|
-
export {
|
|
1
|
+
export { encodePublicKeyZ32, decodePublicKey, loadOrCreateOperatorKeypair } from './keys.js';
|
|
2
|
+
export { serveTunnel } from './tunnel/serve.js';
|
|
3
|
+
export { createAllowlist } from './tunnel/allowlist.js';
|
|
4
|
+
export { serveRawTunnel, DEFAULT_RAW_OPERATOR_KEY_FILE } from './tunnel/rawServe.js';
|
|
5
|
+
export { connectRawTunnel, DEFAULT_MAX_RAW_CONNECTIONS, DEFAULT_RAW_PORT, } from './tunnel/rawConnect.js';
|
|
6
|
+
export { RAW_CLOSE_GRACE_MS } from './tunnel/rawPipe.js';
|
|
7
|
+
export { formatTunnelEvent } from './tunnel/events.js';
|
|
8
|
+
export type { RawClientEvent, RawClientEventListener, RawTunnelEvent, RawTunnelEventListener, TunnelEvent, TunnelEventListener, TunnelEventName, UpstreamPhase, } from './tunnel/events.js';
|
|
9
|
+
export type { Allowlist, AllowlistOptions, AllowlistStream, AllowlistVerdict, AllowedBy, } from './tunnel/allowlist.js';
|
|
10
|
+
export { connectTunnel, localGatewayUrl } from './tunnel/connect.js';
|
|
11
|
+
export { createGatewayProxy } from './tunnel/proxyApp.js';
|
|
12
|
+
export { stripMountPath } from './tunnel/mountPath.js';
|
|
13
|
+
export { createTunnelSession, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_MAX_STREAMS, DEFAULT_REQUEST_TIMEOUT_MS, } from './tunnel/session.js';
|
|
14
|
+
export type { TunnelRequestOptions, TunnelSession, TunnelSessionOptions } from './tunnel/session.js';
|
|
15
|
+
export { DEFAULT_UPSTREAM_TIMEOUT_MS, upstreamRequestHeaders } from './tunnel/proxy.js';
|
|
16
|
+
export { TunnelConnectTimeoutError, TunnelTimeoutError, UpstreamTimeoutError, } from './tunnel/errors.js';
|
|
17
|
+
export { writeFrame, readFrame, writeTunnelRequest, readTunnelRequest, writeTunnelResponse, readTunnelResponse, flattenRequestHeaders, filterResponseHeaders, MAX_FRAME_BYTES, } from './tunnel/protocol.js';
|
|
18
|
+
export type { DhtBootstrapNode, TunnelMeta, TunnelResponseMeta, ServeTunnelOptions, ServeTunnelResult, ConnectTunnelOptions, ConnectTunnelResult, ServeRawTunnelOptions, ServeRawTunnelResult, ConnectRawTunnelOptions, ConnectRawTunnelResult, OperatorKeyPair, CreateGatewayProxyOptions, GatewayProxy, } from './types.js';
|
|
19
|
+
export { DEFAULT_SEED_GATEWAY_HYPER_KEY } from './constants.js';
|
|
19
20
|
//# 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,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,EACd,sBAAsB,EACtB,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,aAAa,GACd,MA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,EAChB,UAAU,EACV,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EACtB,eAAe,EACf,yBAAyB,EACzB,YAAY,GACb,MAAM,SAAS,CAAA;AAEhB,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { l as DEFAULT_CONNECT_TIMEOUT_MS, o as DEFAULT_MAX_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,
|
|
1
|
+
export { l as DEFAULT_CONNECT_TIMEOUT_MS, o as DEFAULT_MAX_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, y as DEFAULT_UPSTREAM_TIMEOUT_MS, w as MAX_FRAME_BYTES, h as RAW_CLOSE_GRACE_MS, x as TunnelConnectTimeoutError, S as TunnelTimeoutError, C as UpstreamTimeoutError, c as connectRawTunnel, r as connectTunnel, v as createAllowlist, n as createGatewayProxy, f as createTunnelSession, N as decodePublicKey, P as encodePublicKeyZ32, T as filterResponseHeaders, E as flattenRequestHeaders, _ as formatTunnelEvent, F as loadOrCreateOperatorKeypair, i as localGatewayUrl, D as readFrame, O as readTunnelRequest, k as readTunnelResponse, m as serveRawTunnel, g as serveTunnel, a as stripMountPath, b as upstreamRequestHeaders, A as writeFrame, j as writeTunnelRequest, M as writeTunnelResponse } from "./src-C_1bcYLA.js";
|
package/dist/keys.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { OperatorKeyPair } from './types';
|
|
1
|
+
import type { OperatorKeyPair } from './types.js';
|
|
2
2
|
export interface PersistedKeyFile {
|
|
3
3
|
publicKey: string;
|
|
4
4
|
secretKey: string;
|
|
@@ -23,5 +23,16 @@ export declare function resolveClientKeypair(options: {
|
|
|
23
23
|
secretKey: Buffer;
|
|
24
24
|
};
|
|
25
25
|
}): OperatorKeyPair;
|
|
26
|
+
/**
|
|
27
|
+
* The operator's keypair: `keyPair` if given, else the one in `keyFile` (`defaultKeyFile` when
|
|
28
|
+
* unset), created on first use. Passing both throws, as for a client.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveOperatorKeypair(options: {
|
|
31
|
+
keyFile?: string;
|
|
32
|
+
keyPair?: {
|
|
33
|
+
publicKey: Buffer;
|
|
34
|
+
secretKey: Buffer;
|
|
35
|
+
};
|
|
36
|
+
}, defaultKeyFile: string): OperatorKeyPair;
|
|
26
37
|
export declare function createEphemeralClientKeypair(): OperatorKeyPair;
|
|
27
38
|
//# 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,0DAA0D;AAC1D,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM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