Membership and sponsors through the network hub (Marty 2026-11-14): hubpeople.js (the Downline Banners module, signed as vbb, cached 5 minutes, never waits on a down hub); netMember asks the hub first, InstantAdPay only when the hub is unreachable. Free daily credits: verified = the hub knows this wallet, or the network member who signed in through InstantAdPay/LinkSpin (by the token's email, never stored); InstantAdPay or a network sign-in counts only while the hub is unreachable. /api/my/voucher: sponsor = the hub network sponsor for the wallet, resolved to a wallet by hub id; hub unreachable = no voucher (why hub-unavailable). Admin status shows hubLookup. Smoke 142/142 (stand-in hub answers /v1/resolve)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -82,9 +82,14 @@ function limited(req, name, max, windowMs) {
|
||||
const isAdmin = req => { const t = String(process.env.ADMIN_TOKEN || ''); const g = String(req.headers['x-admin-token'] || '');
|
||||
return t.length >= 8 && g.length === t.length && crypto.timingSafeEqual(Buffer.from(g), Buffer.from(t)); };
|
||||
|
||||
// ---- network usernames (InstantAdPay today, the network hub later: this is the one place to point at it) ----
|
||||
// ---- network usernames + membership (Marty 2026-11-14: "want everything looped through the hub to verify membership") ----
|
||||
// The network hub answers first (hubpeople.js, signed as vbb, cached 5 minutes); InstantAdPay's /api/network/member only when
|
||||
// the hub is unreachable. A person the hub does not know is unknown here too (never "verified" on InstantAdPay's word alone).
|
||||
const hubpeople = require('./hubpeople');
|
||||
const netCache = new Map();
|
||||
async function netMember(q) {
|
||||
const h = q.u ? await hubpeople.byRef(q.u) : await hubpeople.byWallet(q.a);
|
||||
if (h.ok) { const a = hubpeople.wallet(h.person); return a ? { address: a, username: h.person.username ? String(h.person.username) : null, hubId: h.person.id || null, via: 'hub' } : null; }
|
||||
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;
|
||||
@@ -92,10 +97,18 @@ async function netMember(q) {
|
||||
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), sponsor: ADDR_RE.test(j.sponsor || '') ? j.sponsor.toLowerCase() : null }; } catch (e) { return null; }
|
||||
if (j && ADDR_RE.test(j.address || '') && j.username) m = { address: j.address.toLowerCase(), username: String(j.username), via: 'iap' }; } catch (e) { return null; }
|
||||
netCache.set(k, { at: Date.now(), m }); if (netCache.size > 20000) netCache.clear();
|
||||
return m;
|
||||
}
|
||||
// the member's network sponsor as a wallet, through the hub only (a sponsor voucher binds on chain): the hub's sponsor for this
|
||||
// wallet, resolved to that sponsor's wallet by hub id. {ok: false} = the hub is unreachable; sponsor null = none known.
|
||||
async function hubSponsorWallet(addr) {
|
||||
const me = await hubpeople.byWallet(addr); if (!me.ok) return { ok: false };
|
||||
if (!me.person || !me.person.sponsor) return { ok: true, sponsor: null };
|
||||
const sp = await hubpeople.sponsorOf(me.person); if (!sp.ok) return { ok: false };
|
||||
return { ok: true, sponsor: hubpeople.wallet(sp.person) };
|
||||
}
|
||||
// ?ref=<network username or wallet> -> a VBB member's address (only members who have signed in here can be credited)
|
||||
async function resolveRef(raw) {
|
||||
const r = String(raw || '').trim().slice(0, 60); if (!r) return null;
|
||||
@@ -119,13 +132,21 @@ function signedIn(addr, patch) {
|
||||
const m = store.upsertMember(addr, patch);
|
||||
grantDaily(m); return m;
|
||||
}
|
||||
// free daily credits go to network-verified members only (Marty 2026-11-13, stops wallet farming): signed in through InstantAdPay or
|
||||
// LinkSpin, or a wallet the network knows. A plain wallet is rechecked on each visit, so joining InstantAdPay later unlocks it.
|
||||
const netVerified = m => !!m && (m.via === 'iap' || m.via === 'linkspin' || m.netOk === true);
|
||||
async function verifyNet(addr) {
|
||||
// free daily credits go to network-verified members only (Marty 2026-11-13, stops wallet farming). Verified (Marty 2026-11-14) =
|
||||
// the network hub knows this wallet, or knows the network member who signed in here through InstantAdPay or LinkSpin (looked up
|
||||
// by the email in their sign-in token, never stored). Only while the hub is unreachable: InstantAdPay's lookup by wallet, or a
|
||||
// network sign-in, as before. A plain wallet is rechecked on each visit, so joining the network later unlocks it.
|
||||
const netVerified = m => !!m && m.netOk === true;
|
||||
async function verifyNet(addr, email) {
|
||||
const m = store.member(addr); if (!m || netVerified(m)) return;
|
||||
const n = await netMember({ a: addr }).catch(() => null);
|
||||
if (n && n.address === m.address) { store.upsertMember(addr, { netOk: true }); await fillUsername(addr).catch(() => {}); }
|
||||
const h = await hubpeople.byWallet(addr);
|
||||
let known = h.ok && !!h.person, down = !h.ok;
|
||||
if (!known && !down && email) { const e = await hubpeople.resolve({ email: String(email).trim().toLowerCase() }); if (e.ok) known = !!(e.person && !e.person.blocked); else down = true; }
|
||||
if (!known && down) {
|
||||
const n = await netMember({ a: addr }).catch(() => null);
|
||||
known = (n && n.address === m.address) || m.via === 'iap' || m.via === 'linkspin';
|
||||
}
|
||||
if (known) { store.upsertMember(addr, { netOk: true, netAt: Date.now(), netBy: down ? 'fallback' : 'hub' }); await fillUsername(addr).catch(() => {}); }
|
||||
}
|
||||
// one free post credit a day (Central time), banked up to freeCreditCap
|
||||
function grantDaily(m) {
|
||||
@@ -160,6 +181,8 @@ networksso.init({ self: 'vbb', peer: 'iap', peerBase: () => C.iapBase, from: { i
|
||||
const patch = { via: v.iss };
|
||||
if (v.name && NAME_RE.test(v.name)) { const other = store.memberByName(v.name); if (!other || other.address === v.wallet) patch.username = v.name; }
|
||||
signedIn(v.wallet, patch);
|
||||
await verifyNet(v.wallet, email).catch(() => {}); // the hub knows this network member (by wallet, else by their email)
|
||||
grantDaily(store.member(v.wallet));
|
||||
return cookie('vbb.sid', store.mintSession(v.wallet), store.SESSION_TTL / 1000, true);
|
||||
},
|
||||
landing: to => to, signinPath: to => to });
|
||||
@@ -321,7 +344,9 @@ const server = http.createServer(async (req, res) => {
|
||||
if (p === '/api/my/voucher' && req.method === 'GET') {
|
||||
if (limited(req, 'voucher', 60, 3600000)) return json(res, 429, { error: 'Too many requests this hour.' });
|
||||
if (!shop.voucherOn()) return json(res, 200, { voucher: null, why: 'off' });
|
||||
const n = await netMember({ a: me }).catch(() => null); const sp = n && n.address === me ? n.sponsor : null;
|
||||
const h = await hubSponsorWallet(me).catch(() => ({ ok: false }));
|
||||
if (!h.ok) return json(res, 200, { voucher: null, why: 'hub-unavailable' }); // no voucher now; the contract binds on a later purchase
|
||||
const sp = h.sponsor;
|
||||
if (!sp || sp === me) return json(res, 200, { voucher: null, why: 'no-sponsor' });
|
||||
return json(res, 200, { voucher: await shop.voucher(me, sp) });
|
||||
}
|
||||
@@ -366,7 +391,7 @@ const server = http.createServer(async (req, res) => {
|
||||
queue: { length: S.queue.length, next: S.queue.slice(0, 20) }, progress: S.progress, held: S.progress >= C.perShift && !S.queue.length,
|
||||
today: { visits: t.visits || 0, shifts: t.shifts || 0, cycles: t.cycles || 0, posts: t.posts || 0, clicks: t.clicks || 0 },
|
||||
totals: S.totals, ledger: { entries: L.length, views: L.reduce((x, e) => x + e.views, 0), viewsByStatus: byStatus, credited: 0 },
|
||||
members: store.members().length, banners: S.banners.length, visitsKept: store.visits().length, shop: shop.view(), hub: hubreport.view(), docstore: docstore.view(), oldrefs: Object.keys(oldRefMap()).length });
|
||||
members: store.members().length, banners: S.banners.length, visitsKept: store.visits().length, shop: shop.view(), hub: hubreport.view(), hubLookup: hubpeople.view(), docstore: docstore.view(), oldrefs: Object.keys(oldRefMap()).length });
|
||||
}
|
||||
// old username -> network username map for the old-link redirects: { oldrefs: { old: network } } replaces the whole map
|
||||
if (p === '/api/admin/oldrefs' && req.method === 'POST') {
|
||||
|
||||
Reference in New Issue
Block a user