@relay-federation/bridge 0.3.0 → 0.3.1

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/cli.js CHANGED
@@ -63,18 +63,19 @@ async function cmdInit () {
63
63
  const config = await initConfig(dir)
64
64
 
65
65
  console.log('Bridge initialized!\n')
66
- console.log(` Config: ${dir}/config.json`)
67
- console.log(` Pubkey: ${config.pubkeyHex}`)
68
- console.log(` Address: ${config.address}`)
69
- console.log(` Secret: ${config.statusSecret}`)
66
+ console.log(` Name: ${config.name}`)
67
+ console.log(` Config: ${dir}/config.json`)
68
+ console.log(` Endpoint: ${config.endpoint}`)
69
+ console.log(` Pubkey: ${config.pubkeyHex}`)
70
+ console.log(` Address: ${config.address}`)
71
+ console.log(` Secret: ${config.statusSecret}`)
70
72
  console.log('')
71
73
  console.log(' Save your operator secret! You need it to log into the dashboard.')
72
74
  console.log('')
73
75
  console.log('Next steps:')
74
- console.log(` 1. Edit config.json set your WSS endpoint`)
75
- console.log(` 2. Fund your bridge: send BSV to ${config.address}`)
76
- console.log(' 3. Import the funding tx: relay-bridge fund <rawTxHex>')
77
- console.log(' 4. Run: relay-bridge register')
76
+ console.log(` 1. Fund your bridge: send BSV to ${config.address}`)
77
+ console.log(' 2. Import the funding tx: relay-bridge fund <rawTxHex>')
78
+ console.log(' 3. Run: relay-bridge register')
78
79
  }
79
80
 
80
81
  async function cmdSecret () {
@@ -978,7 +978,7 @@ async function fetchBridge(bridge) {
978
978
  const r = await fetch(bridge.url + '/status' + getAuthParam(bridge.url), { signal: AbortSignal.timeout(5000) });
979
979
  if (!r.ok) throw new Error('HTTP ' + r.status);
980
980
  const data = await r.json();
981
- data._name = bridge.name; data._url = bridge.url; data._error = null; data._lastSeen = Date.now();
981
+ data._name = (data.bridge && data.bridge.name) || bridge.name; data._url = bridge.url; data._error = null; data._lastSeen = Date.now();
982
982
  return data;
983
983
  } catch (e) {
984
984
  return { _name: bridge.name, _url: bridge.url, _error: e.message,
@@ -1009,7 +1009,7 @@ async function discoverBridges() {
1009
1009
  if (!b.statusUrl) continue;
1010
1010
  const base = b.statusUrl.replace(/\/status$/, '');
1011
1011
  if (!known.has(base)) {
1012
- const name = 'bridge-' + (b.pubkeyHex ? b.pubkeyHex.slice(0, 8) : known.size);
1012
+ const name = b.name || 'bridge-' + (b.pubkeyHex ? b.pubkeyHex.slice(0, 8) : known.size);
1013
1013
  known.set(base, name);
1014
1014
  }
1015
1015
  }
package/lib/config.js CHANGED
@@ -21,16 +21,29 @@ export function defaultConfigDir () {
21
21
  * @param {string} [dir] — Config directory (default: ~/.relay-bridge)
22
22
  * @returns {Promise<object>} The generated config
23
23
  */
24
- export async function initConfig (dir = DEFAULT_DIR) {
24
+ export async function initConfig (dir = DEFAULT_DIR, opts = {}) {
25
25
  const privKey = PrivateKey.fromRandom()
26
26
 
27
27
  const address = privKey.toPublicKey().toAddress()
28
28
 
29
+ // Auto-detect public IP
30
+ let publicIp = opts.ip || null
31
+ if (!publicIp) {
32
+ try {
33
+ const res = await fetch('https://api.ipify.org?format=json', { signal: AbortSignal.timeout(5000) })
34
+ if (res.ok) publicIp = (await res.json()).ip
35
+ } catch {}
36
+ }
37
+
38
+ const name = opts.name || (publicIp ? 'bridge-' + publicIp.split('.').pop() : 'bridge-' + privKey.toPublicKey().toString().slice(0, 8))
39
+ const endpoint = publicIp ? 'ws://' + publicIp + ':8333' : 'ws://your-bridge-ip:8333'
40
+
29
41
  const config = {
42
+ name,
30
43
  wif: privKey.toWif(),
31
44
  pubkeyHex: privKey.toPublicKey().toString(),
32
45
  address,
33
- endpoint: 'wss://your-bridge.example.com:8333',
46
+ endpoint,
34
47
  meshId: '70016',
35
48
  capabilities: ['tx_relay', 'header_sync', 'broadcast', 'address_history'],
36
49
  spvEndpoint: 'https://relay.indelible.one',
@@ -112,6 +112,7 @@ export class StatusServer {
112
112
 
113
113
  const status = {
114
114
  bridge: {
115
+ name: this._config.name || null,
115
116
  pubkeyHex: this._config.pubkeyHex || null,
116
117
  meshId: this._config.meshId || null,
117
118
  uptimeSeconds: Math.floor((Date.now() - this._startedAt) / 1000)
@@ -425,6 +426,7 @@ export class StatusServer {
425
426
  const bridges = []
426
427
  // Add self
427
428
  bridges.push({
429
+ name: this._config.name || null,
428
430
  pubkeyHex: this._config.pubkeyHex || null,
429
431
  endpoint: this._config.endpoint || null,
430
432
  meshId: this._config.meshId || null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relay-federation/bridge",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Bridge server — WebSocket peering, header sync, tx relay, CLI",
5
5
  "type": "module",
6
6
  "bin": {