Member lookups through the network hub (Marty 2026-11-14: "want everything looped through the hub to verify membership"): hubpeople.js asks POST /v1/resolve (ref / wallet / hub id, signed as bannerline, cached 5 minutes, 2.5 s timeout, hub skipped 30 s after a failure); netMember / nameOf ask the hub first and InstantAdPay's /api/network/member only when the hub is unreachable (wallet-aliases.json still first). Sponsor pick: the hub network sponsor for the wallet that will own the spot (the buy page asks /api/sponsor?for=<owner> just before the buy; else the signed-in wallet), resolved to a wallet by hub id, nearest up the network line who owns a spot here, none = no sponsor; then the /w/ welcome line (usernames resolved through the hub), then the ?ref= cookie. Admin status shows hubLookup. join.js?v=20261114h. Smoke 91/91 (stand-in hub + stand-in InstantAdPay)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -82,17 +82,23 @@ function limited(req, name, max, windowMs) {
|
||||
}
|
||||
|
||||
// ---- network usernames (Marty 2026-11-13: share links use the member's network username, not the wallet) ----
|
||||
// One lookup for both directions. Today the usernames live in InstantAdPay (GET /api/network/member ?u= / ?a=); when the
|
||||
// network hub goes live this is the one place to point at it. Cached an hour, misses too.
|
||||
// One lookup for both directions. The network hub answers first (Marty 2026-11-14: "want everything looped through the hub to
|
||||
// verify membership"; hubpeople.js, cached 5 minutes); InstantAdPay's GET /api/network/member ?u= / ?a= only when the hub is
|
||||
// unreachable (cached an hour, misses too; a failed call is not cached). A person the hub does not know is unknown here too.
|
||||
const hubpeople = require('./hubpeople');
|
||||
const netCache = new Map();
|
||||
const fromHub = p => { const a = hubpeople.wallet(p); return a ? { address: a, username: p.username ? String(p.username) : null, hubId: p.id || null, via: 'hub' } : null; };
|
||||
async function netMember(q) {
|
||||
const h = q.u ? await hubpeople.byRef(q.u) : await hubpeople.byWallet(q.a);
|
||||
if (h.ok) return fromHub(h.person);
|
||||
if (!C.networkLookupUrl) return null;
|
||||
const k = q.u ? 'u:' + q.u.toLowerCase() : 'a:' + q.a.toLowerCase();
|
||||
const hit = netCache.get(k); if (hit && Date.now() - hit.at < 3600000) return hit.m;
|
||||
let m = null;
|
||||
try { const ac = new AbortController(); setTimeout(() => ac.abort(), 4000).unref();
|
||||
const qs = q.u ? 'u=' + encodeURIComponent(q.u) : 'a=' + encodeURIComponent(q.a);
|
||||
const j = await (await fetch(C.networkLookupUrl + '?' + qs, { signal: ac.signal })).json();
|
||||
if (j && ADDR_RE.test(j.address || '') && j.username) m = { address: j.address.toLowerCase(), username: String(j.username) }; } catch (e) { return null; } // a failed call is not cached
|
||||
if (j && ADDR_RE.test(j.address || '') && j.username) m = { address: j.address.toLowerCase(), username: String(j.username), via: 'iap' }; } catch (e) { return null; } // a failed call is not cached
|
||||
netCache.set(k, { at: Date.now(), m }); if (netCache.size > 20000) netCache.clear();
|
||||
if (m) netCache.set('a:' + m.address, { at: Date.now(), m });
|
||||
return m;
|
||||
@@ -101,7 +107,7 @@ async function netMember(q) {
|
||||
// wallet -> network username, set by the admin; wallet-aliases.json is a MySQL document (docstore)
|
||||
const ALIAS_F = () => path.join(C.dataDir, 'wallet-aliases.json');
|
||||
function aliases() { try { return JSON.parse(fs.readFileSync(ALIAS_F(), 'utf8')); } catch (e) { return {}; } }
|
||||
const nameOf = async addr => { const al = aliases()[String(addr || '').toLowerCase()]; if (al) return al.username; const m = await netMember({ a: addr }); return m && m.address === addr.toLowerCase() ? m.username : null; };
|
||||
const nameOf = async addr => { const al = aliases()[String(addr || '').toLowerCase()]; if (al) return al.username; const m = await netMember({ a: addr }); return m && m.address === String(addr).toLowerCase() ? m.username || null : 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.
|
||||
@@ -159,7 +165,34 @@ async function lineSponsor(req) {
|
||||
}
|
||||
return { address: null, via: 'line' };
|
||||
}
|
||||
async function sponsorFor(req) { const l = await lineSponsor(req); if (l) return l.address; return sponsorOf(req); }
|
||||
// The network sponsor from the hub (Marty 2026-11-14), for a buyer whose wallet the hub knows: their network sponsor, resolved to
|
||||
// a wallet through the hub by hub id, if that wallet owns a spot here (the contract only binds a sponsor who is already a member);
|
||||
// else that sponsor's own network sponsor, and so on up the network line (the same nearest-first rule as the /w/ welcome line, at
|
||||
// most 12 up). Nobody up the line qualifies: no sponsor, never the company, and no ?ref= or welcome code overrides the network.
|
||||
// undefined = the hub does not decide (unreachable, the wallet or its sponsor unknown, or the buyer is already a member here):
|
||||
// the welcome line and the ?ref= cookie decide as before.
|
||||
async function hubSponsor(wallet) {
|
||||
const a = String(wallet || '').toLowerCase(); if (!ADDR_RE.test(a) || chain.isMember(a)) return undefined;
|
||||
const me = await hubpeople.byWallet(a); if (!me.ok || !me.person || !me.person.sponsor) return undefined;
|
||||
let cur = me.person; const seen = new Set([cur.id]);
|
||||
for (let i = 0; i < 12 && cur.sponsor && cur.sponsor.id && !seen.has(cur.sponsor.id); i++) {
|
||||
seen.add(cur.sponsor.id);
|
||||
const s = await hubpeople.sponsorOf(cur); if (!s.ok) return undefined; if (!s.person) break;
|
||||
const sw = hubpeople.wallet(s.person);
|
||||
if (sw && sw !== a && chain.isMember(sw)) return { address: sw, username: s.person.username || null, via: 'hub', network: i === 0 };
|
||||
cur = s.person;
|
||||
}
|
||||
return { address: null, via: 'hub' };
|
||||
}
|
||||
// the sponsor this buyer gets: forWallet = the wallet that will own the spot (the buy page asks just before the buy), else the
|
||||
// signed-in wallet. Hub network sponsor first, then the personal welcome line, then the ?ref= cookie.
|
||||
async function sponsorPick(req, forWallet) {
|
||||
const s = session(req); const w = ADDR_RE.test(forWallet || '') ? forWallet.toLowerCase() : s ? s.address : null;
|
||||
const h = w ? await hubSponsor(w).catch(() => undefined) : undefined; if (h) return h;
|
||||
const l = await lineSponsor(req); if (l) return l;
|
||||
const c = sponsorOf(req); return { address: c, via: c ? 'ref' : null };
|
||||
}
|
||||
async function sponsorFor(req, forWallet) { return (await sponsorPick(req, forWallet)).address; }
|
||||
|
||||
// ---- sessions (wallet signature sign-in) ----
|
||||
const challenges = new Map();
|
||||
@@ -335,8 +368,11 @@ const server = http.createServer(async (req, res) => {
|
||||
return json(res, 200, { totals: t, index: chain.status(), recent, daily: store.daily() });
|
||||
}
|
||||
if (p === '/api/sponsor' && req.method === 'GET') {
|
||||
const raw = u.searchParams.get('ref'); const a = raw ? await resolveRef(raw) : await sponsorFor(req);
|
||||
return json(res, 200, { address: a || null, member: a ? chain.isMember(a) : false });
|
||||
const raw = u.searchParams.get('ref'); const fw = u.searchParams.get('for');
|
||||
if (fw && limited(req, 'sponsor-for', 120, 3600000)) return json(res, 429, { error: 'Too many requests this hour.' });
|
||||
const pick = raw ? { address: await resolveRef(raw), via: 'ref' } : await sponsorPick(req, ADDR_RE.test(fw || '') ? fw : null);
|
||||
const a = pick.address || null;
|
||||
return json(res, 200, { address: a, member: a ? chain.isMember(a) : false, via: pick.via || null });
|
||||
}
|
||||
|
||||
// board: organic view counting with a one-time token, after 5 s on screen
|
||||
@@ -486,7 +522,7 @@ const server = http.createServer(async (req, res) => {
|
||||
// -- 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(), refuelSpots: refuelspots.view(), nas: dlbnas.view() });
|
||||
return json(res, 200, { index: chain.status(), totals: chain.totals(), keeper: keeper.statusInfo(), hub: hubreport.view(), hubLookup: hubpeople.view(), refuelSpots: refuelspots.view(), nas: dlbnas.view() });
|
||||
}
|
||||
|
||||
if (p.startsWith('/api/')) return json(res, 404, { error: 'Not found' });
|
||||
|
||||
Reference in New Issue
Block a user