Since the Damus and Primal apps on iOS do not allow Tor connections to relays, it’s not possible to connect those apps to NOSTR RS Relay on Start9 using the ws://xxxxx.onion address that RS Relay requires.
Is it possible to create a WebSocket Bridge in StartOS?
The steps I’m reading about would require:
- Generate a Valid TLS Certificate on Start 9
- Install the Certificate on desired device (i.e. iPad or iPhone)
- Generate a script to create the Bridge between ws:// and wss://
- Run it on StartOS as a service
This code for Step 3 was Ai generated. Before I mess with anything, is this a viable solution to create a wss:// address?
This is a suggested script to use for a Websocket Bridge.
const WebSocket = require('websocket').server;
const TorSocket = require('tor-socket');
const https = require('https');
const fs = require('fs');
// CONFIGURE THESE VALUES
const BRIDGE_PORT = 8443;
const RELAY_ONION = "your-relay-address.onion"; // From Start9 Service Dashboard
const RELAY_PORT = 8080;
const START9_IP = "your-start9-ip"; // e.g., 192.168.1.100
// Load certificate
const server = https.createServer({
key: fs.readFileSync('/home/embassy/nostr-bridge/certs/bridge.key'),
cert: fs.readFileSync('/home/embassy/nostr-bridge/certs/bridge.crt')
});
server.listen(BRIDGE_PORT, () => {
console.log(`Secure bridge running on wss://${START9_IP}:${BRIDGE_PORT}`);
});
// Setup WebSocket server
const wsServer = new WebSocket({
httpServer: server,
autoAcceptConnections: false
});
wsServer.on('request', (request) => {
const connection = request.accept(null, request.origin);
// Connect to .onion relay via Tor
const torSocket = new TorSocket({
host: 'localhost',
port: 9050, // Start9's Tor port
destination: {
host: RELAY_ONION,
port: RELAY_PORT
}
});
// Handle messages from Damus
connection.on('message', (message) => {
if (message.type === 'utf8') {
torSocket.write(message.utf8Data);
}
});
// Forward relay responses to Damus
torSocket.on('data', (data) => {
connection.sendUTF(data.toString());
});
connection.on('close', () => {
torSocket.end();
});
});