My Spots: 'Use a LinkSpin Banner Spin' (two taps: pick a 468x60 spin, image + tracking link fill and save). Refuel spots: /api/partner/refuel-spot (signed) queues one buyFor per $50+ counted refuel tx, bought from the engine wallet with a 3 POL reserve, every cost recorded (refuelspots.js); never sends at the same time as the keeper. my.js?v=5, line.css?v=4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-13 08:55:44 -06:00
parent 34ffe2eb78
commit 9408b7af8b
10 changed files with 138 additions and 10 deletions
+28 -1
View File
@@ -13,6 +13,7 @@ const board = require('./board');
const safety = require('./safety');
const keeper = require('./keeper');
const { iface } = require('./abi');
const refuelspots = require('./refuelspots'); // refuel spots: $50+ Monthly Refuels earn a spot, engine wallet pays (2026-11-13)
const hubreport = require('./hubreport'); // network hub, shadow mode: members reported by wallet (2026-11-13), off unless HUB_ENABLED
const networksso = require('./networksso'); // network sign-in: arrive signed in from InstantAdPay or LinkSpin (2026-11-13), see networksso.js
const SEL = { buy: iface.getFunction('buy').selector, buyFor: iface.getFunction('buyFor').selector }; // the browser builds calldata from these (ABI stays in abi.js)
@@ -22,6 +23,7 @@ fs.mkdirSync(path.join(C.dataDir, 'art'), { recursive: true });
store.load();
chain.init();
hubreport.init({ dataDir: C.dataDir, members: () => chain.allMembers() });
refuelspots.init({ lock: () => keeper.busy() }); keeper.setOtherBusy(() => refuelspots.busy());
keeper.init();
const PUB = path.join(__dirname, 'public');
@@ -92,6 +94,19 @@ async function netMember(q) {
return m;
}
const nameOf = async addr => { const m = await netMember({ a: addr }); return m && m.address === addr.toLowerCase() ? m.username : null; };
// ---- LinkSpin Banner Spins for My Spots (Marty 2026-11-13: pull a Banner Spin in with a couple of clicks) ----
// Signed with NETWORK_SSO_SECRET: X-Net-Ts + X-Net-Sig = hex HMAC-SHA256('net.v1.' + ts + newline + raw body). LinkSpin answers
// for the account holding the signed-in wallet only.
async function lsSpins(body) {
const sec = String(process.env.NETWORK_SSO_SECRET || '').trim(); if (sec.length < 32) return { error: 'LinkSpin link is not set up.' };
const raw = JSON.stringify(body); const ts = String(Date.now());
const sig = crypto.createHmac('sha256', sec).update('net.v1.' + ts + '\n' + raw).digest('hex');
const ac = new AbortController(); const t = setTimeout(() => ac.abort(), 8000);
try {
const r = await fetch(C.lsBase + '/api/partner/bl/spins', { method: 'POST', body: raw, signal: ac.signal, headers: { 'Content-Type': 'application/json', 'X-Net-Ts': ts, 'X-Net-Sig': sig } });
const j = await r.json().catch(() => ({})); return r.ok ? j : { error: j.error || 'LinkSpin did not answer.' };
} catch (e) { return { error: 'LinkSpin did not answer. Try again in a minute.' }; } finally { clearTimeout(t); }
}
// ---- sponsor ref (?ref=<address or network username>) ----
async function resolveRef(raw) {
const r = String(raw || '').trim();
@@ -317,6 +332,8 @@ const server = http.createServer(async (req, res) => {
const s = session(req); if (!s) return json(res, 401, { error: 'Sign in with your wallet first.' });
const me = s.address;
if (p === '/api/my' && req.method === 'GET') return json(res, 200, await myData(me));
if (p === '/api/my/lsspins' && req.method === 'GET') { const r = await lsSpins({ wallet: me }); return json(res, r.error ? 502 : 200, r); }
if (p === '/api/my/lsspins/use' && req.method === 'POST') { const b = await readBody(req); const r = await lsSpins({ wallet: me, spinId: Number(b.spinId) || 0 }); return json(res, r.error ? 400 : 200, r); }
let m = /^\/api\/my\/spot\/(\d+)$/.exec(p);
if (m && req.method === 'POST') {
const sp = chain.spot(m[1]); if (!sp || sp.owner !== me) return json(res, 403, { error: 'That spot is not yours.' });
@@ -347,10 +364,20 @@ const server = http.createServer(async (req, res) => {
return json(res, 404, { error: 'Not found' });
}
// -- InstantAdPay -> refuel spot (signed with NETWORK_SSO_SECRET, see refuelspots.js)
if (p === '/api/partner/refuel-spot' && req.method === 'POST') {
const raw = (await readRaw(req, 4096)).toString('utf8');
const sec = String(process.env.NETWORK_SSO_SECRET || '').trim(); const ts = String(req.headers['x-net-ts'] || ''); const sig = String(req.headers['x-net-sig'] || '');
if (sec.length < 32 || !/^\d{13}$/.test(ts) || Math.abs(Date.now() - Number(ts)) > 300000) return json(res, 401, { error: 'unauthorized' });
const want = crypto.createHmac('sha256', sec).update('net.v1.' + ts + '\n' + raw).digest('hex');
if (sig.length !== want.length || !crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(want))) return json(res, 401, { error: 'unauthorized' });
let b; try { b = JSON.parse(raw || '{}'); } catch (e) { return json(res, 400, { error: 'bad json' }); }
const r = refuelspots.enqueue(b); return json(res, r.error ? 400 : 200, r);
}
// -- admin (ADMIN_TOKEN header): keeper preview + index status. No key material is ever returned.
if (p === '/api/admin/status' && req.method === 'GET') {
const tok = process.env.ADMIN_TOKEN; if (!tok || req.headers['x-admin-token'] !== tok) return json(res, 401, { error: 'no' });
return json(res, 200, { index: chain.status(), totals: chain.totals(), keeper: keeper.statusInfo(), hub: hubreport.view() });
return json(res, 200, { index: chain.status(), totals: chain.totals(), keeper: keeper.statusInfo(), hub: hubreport.view(), refuelSpots: refuelspots.view() });
}
if (p.startsWith('/api/')) return json(res, 404, { error: 'Not found' });