freertc 0.1.32 → 0.5.0

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.
Files changed (60) hide show
  1. package/README.md +204 -12
  2. package/bin/freertc.mjs +38 -633
  3. package/migrations/0001_initial.sql +43 -0
  4. package/migrations/0002_kademlia_overlay.sql +32 -0
  5. package/migrations/0003_announcement_role.sql +4 -0
  6. package/package.json +44 -17
  7. package/public/app.js +746 -169
  8. package/public/icon-180.png +0 -0
  9. package/public/icon-192.png +0 -0
  10. package/public/index.html +200 -799
  11. package/public/pigeonlogo.svg +51 -0
  12. package/scripts/d1-schema.sql +36 -0
  13. package/scripts/deploy-cloudflare.mjs +190 -0
  14. package/scripts/dev-server.mjs +54 -7
  15. package/scripts/generate-relay-identity.mjs +14 -0
  16. package/scripts/name-setup.mjs +332 -0
  17. package/scripts/node-relay.mjs +1128 -0
  18. package/scripts/project-bootstrap.mjs +13 -6
  19. package/scripts/wrangler-install-wizard.mjs +21 -11
  20. package/src/client.js +3468 -0
  21. package/src/direct/cert.js +95 -0
  22. package/src/direct/common.js +187 -0
  23. package/src/direct/dial.js +47 -0
  24. package/src/direct/directory.js +230 -0
  25. package/src/direct/listener.js +201 -0
  26. package/src/direct/lookup.js +75 -0
  27. package/src/direct/names.js +150 -0
  28. package/src/direct/node-relay-direct.js +170 -0
  29. package/src/direct/portmap.js +214 -0
  30. package/src/direct/reachable.js +40 -0
  31. package/src/direct/record.js +188 -0
  32. package/src/index.js +1401 -199
  33. package/src/kademlia.js +133 -0
  34. package/src/node/account-sync.js +98 -0
  35. package/src/node/cost-meter.js +92 -0
  36. package/src/node/d1-sqlite.js +108 -0
  37. package/src/node/data-dir.js +66 -0
  38. package/src/node/durable-object.js +58 -0
  39. package/src/node/lan-beacon.js +55 -0
  40. package/src/node/link-crypto.js +99 -0
  41. package/src/node/relay-links.js +385 -0
  42. package/src/node/relay-name.js +193 -0
  43. package/src/node/relay-pq.js +68 -0
  44. package/src/node/relay-stats.js +276 -0
  45. package/src/node/stats-page.js +281 -0
  46. package/src/node/websocket-pair.js +117 -0
  47. package/src/punch/offer.js +143 -0
  48. package/src/punch/rendezvous.js +124 -0
  49. package/src/punch/transport.js +257 -0
  50. package/src/relay-fetch.js +131 -0
  51. package/src/relay-id.js +74 -0
  52. package/src/relay-identity.js +298 -0
  53. package/src/relay-overlay.js +857 -0
  54. package/src/tunnel/client.js +276 -0
  55. package/src/tunnel/frames.js +64 -0
  56. package/src/tunnel/home.js +271 -0
  57. package/wrangler.template.jsonc +34 -9
  58. package/wrangler.workers-dev.jsonc +20 -3
  59. package/scripts/non-cloudflare-server.mjs +0 -433
  60. package/scripts/postinstall-message.mjs +0 -133
@@ -0,0 +1,51 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <svg
3
+ version="1.1"
4
+ id="Layer_1"
5
+ x="0px"
6
+ y="0px"
7
+ width="100%"
8
+ viewBox="-40 -40 480 480"
9
+ enable-background="new -40 -40 480 480"
10
+ xml:space="preserve"
11
+ sodipodi:docname="pigeonlogo.svg"
12
+ inkscape:version="1.3.2 (091e20e, 2023-11-25)"
13
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
14
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
15
+ xmlns="http://www.w3.org/2000/svg"
16
+ xmlns:svg="http://www.w3.org/2000/svg"><defs
17
+ id="defs2" /><sodipodi:namedview
18
+ id="namedview2"
19
+ pagecolor="#ffffff"
20
+ bordercolor="#000000"
21
+ borderopacity="0.25"
22
+ inkscape:showpageshadow="2"
23
+ inkscape:pageopacity="0.0"
24
+ inkscape:pagecheckerboard="0"
25
+ inkscape:deskcolor="#d1d1d1"
26
+ inkscape:zoom="2.1625"
27
+ inkscape:cx="150.98266"
28
+ inkscape:cy="206.47399"
29
+ inkscape:window-width="2560"
30
+ inkscape:window-height="1412"
31
+ inkscape:window-x="2560"
32
+ inkscape:window-y="28"
33
+ inkscape:window-maximized="0"
34
+ inkscape:current-layer="Layer_1" />
35
+
36
+ <rect x="-40" y="-40" width="480" height="480" rx="96" fill="#ffffff" /><g
37
+ id="g1"
38
+ style="fill:#c07a12"><path
39
+ fill="#c07a12"
40
+ opacity="1.000000"
41
+ stroke="none"
42
+ d=" M120.468147,21.381325 C150.957001,7.007360 182.981934,2.511711 215.769806,4.990532 C264.741272,8.692862 307.189270,27.724031 341.749084,63.034561 C371.673706,93.609230 390.084351,129.914551 395.508698,172.659744 C400.219971,209.785522 396.896851,245.893478 381.415894,280.148102 C359.249359,329.195953 323.539032,364.613953 273.029633,384.369141 C248.739410,393.869568 223.576569,399.261566 197.418854,398.134613 C129.008820,395.187317 74.925789,365.637848 36.818604,308.706299 C19.690449,283.117065 9.356023,254.531311 6.509281,223.433182 C0.360511,156.263382 21.346617,99.472046 70.926376,53.611313 C85.437164,40.188988 101.969215,29.535603 120.468147,21.381325 M270.387939,108.192596 C275.618103,117.372398 279.516052,127.079475 281.337250,137.501389 C282.081421,141.759766 284.215179,144.517975 287.657196,147.061478 C304.841034,159.759628 321.036224,173.620041 335.232330,189.657059 C341.298767,196.510147 347.458191,203.404449 349.494049,212.773529 C350.531921,217.549881 348.457794,219.830002 343.695984,219.141724 C342.056458,218.904755 340.458221,218.381500 338.841492,217.987427 C319.818604,213.350662 300.455200,210.393539 280.983795,212.447937 C252.188278,215.486099 242.250076,231.618851 242.618347,257.128632 C242.830902,271.852905 247.283859,285.860596 252.465714,299.661438 C259.429108,318.207214 265.145691,337.132721 267.592407,356.939240 C268.054932,360.683441 267.341187,364.986176 270.126678,368.296021 C317.061981,351.057007 380.640472,291.725525 381.418518,201.259262 C382.126129,118.984360 326.737000,47.228451 247.962952,26.676783 C164.460785,4.891574 82.985291,41.991894 42.807281,114.625771 C9.980222,173.970566 20.332239,252.160095 41.899414,281.980133 C46.056343,276.605194 48.612194,270.544464 50.950127,264.290161 C58.917362,242.976685 62.716553,220.696869 66.730515,198.441345 C70.801041,175.872192 74.669456,153.279358 83.538956,131.858078 C100.847382,90.055397 140.921997,56.608147 193.015991,60.710079 C226.376907,63.336948 252.460632,78.618561 270.387939,108.192596 M75.957253,296.457520 C69.154053,296.298950 62.318226,295.387573 55.583069,297.069519 C50.880104,298.243958 50.315563,299.537689 53.062222,303.583221 C57.925316,310.746033 63.141083,317.649292 69.137230,323.929108 C91.349602,347.192261 116.816727,365.339447 148.279907,373.897461 C153.747467,375.384613 159.292816,377.335754 165.236130,376.342041 C160.386276,343.455292 121.047539,305.242371 75.957253,296.457520 M170.878464,171.725739 C182.350723,175.779358 192.971878,174.071259 202.157852,166.185440 C211.449387,158.208984 215.138840,147.898987 212.612289,135.748596 C208.134933,114.216660 181.203903,104.033890 163.665161,117.167091 C143.958481,131.923676 147.376968,160.484970 170.878464,171.725739 M293.165527,171.349884 C288.533569,167.822983 283.781067,164.469177 278.666992,161.673325 C276.790985,160.647690 274.883545,159.587173 272.576813,159.852905 C263.079193,160.946991 251.725357,173.430832 251.251633,182.916107 C251.040131,187.151199 252.349136,188.759674 256.752319,188.984711 C273.992737,189.865799 291.165741,191.448608 307.974518,195.735489 C312.184998,196.809326 316.339264,198.345230 321.791504,198.288239 C312.766602,188.193207 303.602844,179.623199 293.165527,171.349884 z"
43
+ id="path1"
44
+ style="fill:#c07a12" /><path
45
+ fill="#c07a12"
46
+ opacity="1.000000"
47
+ stroke="none"
48
+ d=" M164.621384,142.091873 C165.557266,130.660858 172.520447,124.145866 182.761856,124.686325 C192.462006,125.198235 200.468567,133.709045 200.133820,143.152374 C199.780228,153.126877 192.241592,160.504852 182.440079,160.468979 C171.919250,160.430496 164.941574,153.415634 164.621384,142.091873 z"
49
+ id="path2"
50
+ style="fill:#c07a12" /></g>
51
+ </svg>
@@ -42,3 +42,39 @@ CREATE TABLE IF NOT EXISTS psp_relays (
42
42
 
43
43
  CREATE INDEX IF NOT EXISTS idx_relays_last_seen
44
44
  ON psp_relays (last_seen_ms);
45
+
46
+ -- Bounded Kademlia relay routing table and replicated provider records.
47
+ CREATE TABLE IF NOT EXISTS psp_kad_nodes (
48
+ node_id TEXT PRIMARY KEY,
49
+ bucket_index INTEGER NOT NULL,
50
+ url TEXT NOT NULL,
51
+ record_json TEXT NOT NULL,
52
+ expires_at_ms INTEGER NOT NULL,
53
+ last_seen_ms INTEGER NOT NULL
54
+ );
55
+
56
+ CREATE INDEX IF NOT EXISTS idx_kad_nodes_bucket_seen
57
+ ON psp_kad_nodes (bucket_index, last_seen_ms DESC);
58
+
59
+ CREATE INDEX IF NOT EXISTS idx_kad_nodes_expires
60
+ ON psp_kad_nodes (expires_at_ms);
61
+
62
+ CREATE TABLE IF NOT EXISTS psp_kad_records (
63
+ routing_key TEXT NOT NULL,
64
+ owner_node_id TEXT NOT NULL,
65
+ kind TEXT NOT NULL,
66
+ sequence INTEGER NOT NULL,
67
+ record_json TEXT NOT NULL,
68
+ expires_at_ms INTEGER NOT NULL,
69
+ PRIMARY KEY (routing_key, owner_node_id, kind)
70
+ );
71
+
72
+ CREATE INDEX IF NOT EXISTS idx_kad_records_lookup
73
+ ON psp_kad_records (routing_key, expires_at_ms, sequence DESC);
74
+
75
+ CREATE INDEX IF NOT EXISTS idx_kad_records_expires
76
+ ON psp_kad_records (expires_at_ms);
77
+ -- What a peer is, when it says (an announce's capabilities.role, such as
78
+ -- "storage"): relays store it and list it, so peers in a scope can tell
79
+ -- the kinds of peer apart before they dial. Most peers have none.
80
+ ALTER TABLE psp_announcements ADD COLUMN role TEXT;
@@ -0,0 +1,190 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawnSync } from 'node:child_process';
4
+ import { pathToFileURL } from 'node:url';
5
+
6
+ import { generateRandomPair } from 'unsea';
7
+ import { encodeRelayIdentitySecret } from '../src/relay-identity.js';
8
+ import { resolveProjectRoot, resolveWranglerCommand } from './project-bootstrap.mjs';
9
+
10
+ const ROOT = resolveProjectRoot(process.cwd());
11
+ const RELAY_IDENTITY_SECRET = 'RELAY_IDENTITY_SECRET';
12
+ const LEGACY_RELAY_IDENTITY_SECRET = 'RELAY_SIGNING_PRIVATE_KEY';
13
+
14
+ export function firstWorkersDevUrlFromText(text) {
15
+ if (!text) return null;
16
+ const match = text.match(/https:\/\/[a-z0-9-]+\.[a-z0-9-]+\.workers\.dev/i);
17
+ return match ? match[0] : null;
18
+ }
19
+
20
+ export function relayUrlFromWorkersDevUrl(url) {
21
+ if (!url) return null;
22
+ try {
23
+ const parsed = new URL(url);
24
+ if (parsed.protocol !== 'https:' || !parsed.hostname.endsWith('.workers.dev')) return null;
25
+ return `wss://${parsed.host}/ws`;
26
+ } catch {
27
+ return null;
28
+ }
29
+ }
30
+
31
+ export function scopedWranglerArgs(args, { includeName = false } = {}) {
32
+ const valueFlags = new Set([
33
+ '--config', '-c', '--cwd', '--env', '-e', '--env-file', '--profile',
34
+ ...(includeName ? ['--name'] : []),
35
+ ]);
36
+ const longFlags = [...valueFlags].filter((flag) => flag.startsWith('--'));
37
+ const scoped = [];
38
+ for (let index = 0; index < args.length; index += 1) {
39
+ const arg = args[index];
40
+ if (valueFlags.has(arg) && index + 1 < args.length) {
41
+ scoped.push(arg, args[index + 1]);
42
+ index += 1;
43
+ continue;
44
+ }
45
+ if (longFlags.some((flag) => arg.startsWith(`${flag}=`))) scoped.push(arg);
46
+ }
47
+ return scoped;
48
+ }
49
+
50
+ export function relaySecretNames(text) {
51
+ try {
52
+ const parsed = JSON.parse(text);
53
+ if (!Array.isArray(parsed)) return [];
54
+ return parsed.map((secret) => secret?.name).filter((name) => typeof name === 'string');
55
+ } catch {
56
+ return [];
57
+ }
58
+ }
59
+
60
+ function wait(ms) {
61
+ return new Promise((resolve) => setTimeout(resolve, ms));
62
+ }
63
+
64
+ async function requestHealth(deploymentUrl) {
65
+ const healthUrl = new URL('/health', deploymentUrl).toString();
66
+ let lastError = null;
67
+
68
+ for (const delayMs of [0, 1000, 2000, 4000, 8000]) {
69
+ if (delayMs) await wait(delayMs);
70
+ try {
71
+ const response = await fetch(healthUrl, {
72
+ headers: { 'User-Agent': 'freertc-deploy-registration/1.0' }
73
+ });
74
+ if (!response.ok) {
75
+ lastError = new Error(`HTTP ${response.status}`);
76
+ continue;
77
+ }
78
+ const health = await response.json();
79
+ return { healthUrl, health };
80
+ } catch (error) {
81
+ lastError = error;
82
+ }
83
+ }
84
+
85
+ throw lastError || new Error('Health request failed');
86
+ }
87
+
88
+ function printResult(result) {
89
+ if (result.stdout) process.stdout.write(result.stdout);
90
+ if (result.stderr) process.stderr.write(result.stderr);
91
+ }
92
+
93
+ function runWrangler(wrangler, args, options = {}) {
94
+ return spawnSync(wrangler.command, [...wrangler.baseArgs, ...args], {
95
+ cwd: ROOT,
96
+ encoding: 'utf8',
97
+ env: process.env,
98
+ stdio: 'pipe',
99
+ ...options,
100
+ });
101
+ }
102
+
103
+ function failed(result, label) {
104
+ if (result.error) console.error(`[freertc] Could not start ${label}: ${result.error.message}`);
105
+ if (result.status === 0) return false;
106
+ process.exitCode = result.status || 1;
107
+ return true;
108
+ }
109
+
110
+ async function ensureRelayIdentitySecret(wrangler, deployArgs) {
111
+ const secretArgs = scopedWranglerArgs(deployArgs, { includeName: true });
112
+ const listed = runWrangler(wrangler, ['secret', 'list', '--format', 'json', ...secretArgs]);
113
+ if (failed(listed, 'Wrangler secret listing')) {
114
+ printResult(listed);
115
+ return false;
116
+ }
117
+
118
+ const names = relaySecretNames(listed.stdout || '');
119
+ if (names.includes(RELAY_IDENTITY_SECRET) || names.includes(LEGACY_RELAY_IDENTITY_SECRET)) {
120
+ console.log('[freertc] Existing relay identity secret preserved.');
121
+ return true;
122
+ }
123
+
124
+ const pair = await generateRandomPair();
125
+ const secretInput = JSON.stringify({
126
+ [RELAY_IDENTITY_SECRET]: encodeRelayIdentitySecret(pair.pub, pair.priv),
127
+ });
128
+ const uploaded = runWrangler(
129
+ wrangler,
130
+ ['secret', 'bulk', ...secretArgs],
131
+ { input: secretInput },
132
+ );
133
+ printResult(uploaded);
134
+ if (failed(uploaded, 'Wrangler secret upload')) return false;
135
+
136
+ console.log('[freertc] Generated and installed a private relay identity secret.');
137
+ return true;
138
+ }
139
+
140
+ export async function main(args = process.argv.slice(2)) {
141
+ const wrangler = resolveWranglerCommand(ROOT);
142
+ const skipHealthCheck = args.includes('--skip-health-check');
143
+ const deployArgs = args.filter((arg) => arg !== '--' && arg !== '--skip-health-check');
144
+ const dryRun = deployArgs.includes('--dry-run');
145
+
146
+ if (!dryRun) {
147
+ console.log('[freertc] Applying remote D1 migrations...');
148
+ const migrationArgs = scopedWranglerArgs(deployArgs);
149
+ const migration = runWrangler(wrangler, [
150
+ 'd1', 'migrations', 'apply', 'DB', '--remote', ...migrationArgs,
151
+ ]);
152
+ printResult(migration);
153
+ if (failed(migration, 'Wrangler D1 migration')) return;
154
+ }
155
+
156
+ const deploy = runWrangler(wrangler, ['deploy', ...deployArgs]);
157
+ printResult(deploy);
158
+ if (failed(deploy, 'Wrangler deployment')) return;
159
+
160
+ if (dryRun) return;
161
+ if (!await ensureRelayIdentitySecret(wrangler, deployArgs)) return;
162
+ if (skipHealthCheck) return;
163
+
164
+ const deploymentUrl = firstWorkersDevUrlFromText(`${deploy.stdout || ''}\n${deploy.stderr || ''}`);
165
+ const expectedRelayUrl = relayUrlFromWorkersDevUrl(deploymentUrl);
166
+ if (!deploymentUrl || !expectedRelayUrl) {
167
+ console.warn('[freertc] Deployment and private relay identity setup succeeded, but no workers.dev URL was found.');
168
+ return;
169
+ }
170
+
171
+ try {
172
+ const { healthUrl, health } = await requestHealth(deploymentUrl);
173
+ if (health?.relay_url !== expectedRelayUrl) {
174
+ throw new Error(`expected relay_url ${expectedRelayUrl}, received ${health?.relay_url || '(missing)'}`);
175
+ }
176
+ if (health?.kademlia_enabled !== true) {
177
+ throw new Error('the deployed Worker did not report Kademlia as enabled');
178
+ }
179
+ console.log(`[freertc] Kademlia relay initialized through ${healthUrl}`);
180
+ console.log(`[freertc] Relay URL: ${expectedRelayUrl}`);
181
+ } catch (error) {
182
+ console.warn(`[freertc] Worker deployed, but the health check did not complete: ${error.message}`);
183
+ console.warn(`[freertc] Open ${deploymentUrl} once to retry overlay registration.`);
184
+ }
185
+ }
186
+
187
+ const entrypointUrl = process.argv[1] ? pathToFileURL(process.argv[1]).href : null;
188
+ if (import.meta.url === entrypointUrl) {
189
+ await main();
190
+ }
@@ -4,12 +4,16 @@ import fs from 'node:fs';
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
6
  import { spawnSync } from 'node:child_process';
7
+ import { pathToFileURL } from 'node:url';
8
+ import { generateRandomPair } from 'unsea';
9
+ import { encodeRelayIdentitySecret } from '../src/relay-identity.js';
7
10
  import { resolveWranglerCommand } from './project-bootstrap.mjs';
8
11
 
9
12
  const ROOT = process.cwd();
10
13
  const CARGO_BIN = path.join(os.homedir(), '.cargo', 'bin');
11
14
  const PATH_WITH_CARGO = `${CARGO_BIN}${path.delimiter}${process.env.PATH || ''}`;
12
15
  const WASM_TARGET = 'wasm32-unknown-unknown';
16
+ const LOCAL_SECRETS_FILE = path.join(ROOT, '.dev.vars');
13
17
 
14
18
  function run(command, args, options = {}) {
15
19
  return spawnSync(command, args, {
@@ -95,12 +99,14 @@ function resolveWranglerArgs() {
95
99
  if (fs.existsSync(localConfig)) {
96
100
  return {
97
101
  args: ['dev'],
102
+ configArgs: [],
98
103
  configPath: localConfig
99
104
  };
100
105
  }
101
106
  if (fs.existsSync(workersDevConfig)) {
102
107
  return {
103
108
  args: ['dev', '--config', 'wrangler.workers-dev.jsonc'],
109
+ configArgs: ['--config', 'wrangler.workers-dev.jsonc'],
104
110
  configPath: workersDevConfig
105
111
  };
106
112
  }
@@ -108,6 +114,32 @@ function resolveWranglerArgs() {
108
114
  fail('No Wrangler config found. Create wrangler.jsonc or keep wrangler.workers-dev.jsonc.');
109
115
  }
110
116
 
117
+ export async function ensureLocalRelayIdentity(filePath = LOCAL_SECRETS_FILE) {
118
+ const ignorePath = path.join(path.dirname(filePath), '.gitignore');
119
+ const ignoreEntry = path.basename(filePath);
120
+ const ignoreText = fs.existsSync(ignorePath) ? fs.readFileSync(ignorePath, 'utf8') : '';
121
+ if (!ignoreText.split(/\r?\n/).includes(ignoreEntry)) {
122
+ const separator = ignoreText && !ignoreText.endsWith('\n') ? '\n' : '';
123
+ fs.appendFileSync(ignorePath, `${separator}${ignoreEntry}\n`, 'utf8');
124
+ }
125
+
126
+ const current = fs.existsSync(filePath)
127
+ ? fs.readFileSync(filePath, 'utf8')
128
+ : '';
129
+ if (/^\s*(RELAY_IDENTITY_SECRET|RELAY_SIGNING_PRIVATE_KEY)\s*=/m.test(current)) return;
130
+
131
+ const pair = await generateRandomPair();
132
+ const secret = encodeRelayIdentitySecret(pair.pub, pair.priv);
133
+ const separator = current && !current.endsWith('\n') ? '\n' : '';
134
+ const line = `${separator}RELAY_IDENTITY_SECRET='${secret}'\n`;
135
+ if (fs.existsSync(filePath)) {
136
+ fs.appendFileSync(filePath, line, 'utf8');
137
+ } else {
138
+ fs.writeFileSync(filePath, line, { encoding: 'utf8', mode: 0o600 });
139
+ }
140
+ console.log('[dev-setup] Generated a private relay identity in the ignored .dev.vars file.');
141
+ }
142
+
111
143
  function configUsesWorkerBuild(configPath) {
112
144
  try {
113
145
  const text = fs.readFileSync(configPath, 'utf8');
@@ -117,13 +149,28 @@ function configUsesWorkerBuild(configPath) {
117
149
  }
118
150
  }
119
151
 
120
- const resolved = resolveWranglerArgs();
121
- const wrangler = resolveWranglerCommand(ROOT);
152
+ async function main() {
153
+ const resolved = resolveWranglerArgs();
154
+ const wrangler = resolveWranglerCommand(ROOT);
122
155
 
123
- if (configUsesWorkerBuild(resolved.configPath)) {
124
- ensureWorkerBuild();
125
- ensureWasmTarget();
156
+ if (configUsesWorkerBuild(resolved.configPath)) {
157
+ ensureWorkerBuild();
158
+ ensureWasmTarget();
159
+ }
160
+
161
+ await ensureLocalRelayIdentity();
162
+ console.log('[dev-setup] Applying local D1 migrations...');
163
+ const migrated = run(wrangler.command, [
164
+ ...wrangler.baseArgs,
165
+ 'd1', 'migrations', 'apply', 'DB', '--local', ...resolved.configArgs,
166
+ ]);
167
+ if (migrated.status !== 0) fail('Failed to apply local D1 migrations.');
168
+
169
+ const started = run(wrangler.command, [...wrangler.baseArgs, ...resolved.args]);
170
+ process.exit(started.status ?? 1);
126
171
  }
127
172
 
128
- const started = run(wrangler.command, [...wrangler.baseArgs, ...resolved.args]);
129
- process.exit(started.status ?? 1);
173
+ const entrypointUrl = process.argv[1] ? pathToFileURL(process.argv[1]).href : null;
174
+ if (import.meta.url === entrypointUrl) {
175
+ await main();
176
+ }
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { generateRandomPair } from 'unsea';
4
+ import { encodeRelayIdentitySecret } from '../src/relay-identity.js';
5
+
6
+ const identity = await generateRandomPair();
7
+
8
+ console.log('Generated a stable UnSEA relay signing identity.');
9
+ console.log('Keep the private key secret and reuse this pair across deployments of the same relay.');
10
+ console.log('');
11
+ console.log(`RELAY_IDENTITY_SECRET='${encodeRelayIdentitySecret(identity.pub, identity.priv)}'`);
12
+ console.log('');
13
+ console.log('For manual recovery only, store that complete value as RELAY_IDENTITY_SECRET.');
14
+ console.log('Normal deploy and dev:cf commands generate and install it automatically.');