pithos/hosted/electrum.js
Local Dev d00bd369b7 Pithos: run your drives on Silent Mode with your own Sia account
s3d binds one Sia account per process, so the server runs one s3d per
person (pithos-hosted), started on demand and flushed and stopped when idle.
Only the connected s3d data folder moves between PC and server; the Sia
recovery phrase never leaves the PC and nothing is re-uploaded to Sia.

Because the server holds the connection key, local Pithos encrypts names and
contents before they leave the machine, with keys from the Theseus vault (or
a local key file elsewhere). What s3d cannot do on its own, the gateway now
enforces: public folders, expiring share links and S3 keys for other people
limited to one folder with read, add-only or edit rights. Files those reach
are stored readable, since visitors have no key, and go back to encrypted
when the rule is removed. Sign-up needs a BNS name signature, a deposit or
an invite, with a per-IP limit.
2026-10-04 01:33:20 +02:00

30 lines
1.3 KiB
JavaScript

// The one Electrum call the deposit gate needs: a verbose transaction.
import tls from 'node:tls';
import net from 'node:net';
export function electrumCall({ host, port, tls: useTls = true, timeoutMs = 15_000 }, method, params) {
return new Promise((resolve, reject) => {
const sock = useTls ? tls.connect({ host, port, servername: host }) : net.connect({ host, port });
let buf = '';
const timer = setTimeout(() => { sock.destroy(); reject(new Error('Electrum server did not answer')); }, timeoutMs);
const done = (err, val) => { clearTimeout(timer); sock.end(); if (err) reject(err); else resolve(val); };
sock.setEncoding('utf8');
sock.on('error', (e) => done(e));
sock.write(JSON.stringify({ jsonrpc: '2.0', id: 0, method: 'server.version', params: ['pithos-hosted', '1.4'] }) + '\n');
sock.write(JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }) + '\n');
sock.on('data', (d) => {
buf += d;
let i;
while ((i = buf.indexOf('\n')) >= 0) {
const line = buf.slice(0, i);
buf = buf.slice(i + 1);
let msg;
try { msg = JSON.parse(line); } catch { continue; }
if (msg.id !== 1) continue;
if (msg.error) return done(new Error(msg.error.message || 'Electrum error'));
return done(null, msg.result);
}
});
});
}