Downline Banners (Marty 2026-11-13: keep the name): renamed everywhere members see it, new stacked-banner logo + favicon; network sign-in (arrive signed in from InstantAdPay/LinkSpin as your wallet); share links, sponsor and directs use network usernames (?ref=username resolves through InstantAdPay)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -47,7 +47,10 @@ function get() {
|
||||
keeperStallHours: Number(e.KEEPER_STALL_HOURS || 4),
|
||||
keeperMaxPerDay: Number(e.KEEPER_MAX_PER_DAY || 12),
|
||||
keeperEveryMs: Number(e.KEEPER_EVERY_MIN || 15) * 60000,
|
||||
iapResolveUrl: (e.IAP_RESOLVE_URL || '').trim() // optional: https://instantadpay.com/api/... returning {address} for ?ref=<username>
|
||||
iapBase: String(e.IAP_URL || 'https://instantadpay.com').replace(/\/+$/, ''),
|
||||
lsBase: String(e.LS_URL || 'https://linkspin.app').replace(/\/+$/, ''),
|
||||
// network usernames: ?u=<username> -> {address, username}, ?a=<wallet> -> the same (InstantAdPay today, the network hub later)
|
||||
networkLookupUrl: (e.NETWORK_LOOKUP_URL || String(e.IAP_URL || 'https://instantadpay.com').replace(/\/+$/, '') + '/api/network/member').trim()
|
||||
};
|
||||
return cfg;
|
||||
}
|
||||
@@ -58,7 +61,7 @@ const HOUSE_DEFAULT = [
|
||||
{ key: 'iap', title: 'InstantAdPay', img: '/art/house-iap.svg', link: 'https://instantadpay.com/', note: 'Ad credits buy advertising, not income.' },
|
||||
{ key: 'linkspin', title: 'LinkSpin', img: '/art/house-linkspin.svg', link: 'https://linkspin.app/' },
|
||||
{ key: 'games', title: 'Network games', img: '/art/house-games.svg', link: 'https://enjoybestgames.com/' },
|
||||
{ key: 'self', title: 'Banner Line', img: '/art/house-line.svg', link: '/join' }
|
||||
{ key: 'self', title: 'Downline Banners', img: '/art/house-line.svg', link: '/join' }
|
||||
];
|
||||
function house() {
|
||||
try { const h = JSON.parse(fs.readFileSync(path.join(get().dataDir, 'house.json'), 'utf8')); if (Array.isArray(h) && h.length) return h; } catch (e) {}
|
||||
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
// Network sign-in between InstantAdPay and LinkSpin (Marty approved 2026-11-12). The SAME file ships in both repos; each
|
||||
// server calls init({ self, peer, peerBase, ... hooks }) and hands every request to handle() before its own routes.
|
||||
//
|
||||
// One flow, used two ways. R = the site the member is going TO (receiver), P = the site they are signed in on (provider).
|
||||
// 1. R GET /sso/start?mode=go|check&to=/path R makes a random state, keeps it in a 5-minute HttpOnly cookie (nsso.st),
|
||||
// sets the loop guard (nsso.tried, 30 minutes) and sends the browser to P.
|
||||
// 2. P GET /sso/check?st=<state>&to=/path P looks at its OWN member session (never the admin portal). Signed in:
|
||||
// P mints a token bound to R, the state and the email, and sends the browser
|
||||
// to R /sso/in?t=<token>. Not signed in: R /sso/in?none=1&to=/path.
|
||||
// 3. R GET /sso/in?t=<token> R checks signature, audience, expiry (60 s), the state against its cookie
|
||||
// (so nobody can push their own token into someone else's browser), and spends
|
||||
// the nonce (a second use is refused). The email must already be a member
|
||||
// here; then R makes an ordinary session and redirects to the relative path.
|
||||
// Outbound links: P GET /go/<peer>?to=/path is the hop a signed-in member's cross-site link points at. Signed out (or the
|
||||
// secret not set), it is a plain redirect to the other site, so it is always safe to link through.
|
||||
// Silent check: R's sign-in page calls GET /api/sso/status; { check: true } means "bounce once through P". The guard cookie
|
||||
// stops a second bounce for 30 minutes, signing out sets nsso.off (12 hours, cleared by the next deliberate cross-site link),
|
||||
// bots and non-page fetches never bounce.
|
||||
// Token: "v1.<base64url JSON>.<base64url HMAC-SHA256(NETWORK_SSO_SECRET, 'nsso.v1.' + JSON part)>", JSON = { iss, aud, email,
|
||||
// st, to, iat, exp, n[, wallet, name] }. The token grants a plain member session and nothing else: no wallet action, payout or purchase rides on it.
|
||||
//
|
||||
// Wallet sites (Downline Banners, 2026-11-13, Marty: "sign in once and be logged into all these sites"). Downline Banners has no email
|
||||
// accounts; its members are wallets. IAP and LinkSpin list it under `wallets: { bannerline: base }` and vouch one way: /go/bannerline
|
||||
// and /sso/check?r=bannerline mint a token that also carries the member's wallet (the one they signed in with, else the main wallet
|
||||
// their account linked by signature) and username. Downline Banners runs this file with `from: { iap, linkspin }`, accepts a token from
|
||||
// either, and makes a session for that wallet. /sso/start?via=<site> picks which site to ask; old copies ignore the new parameters.
|
||||
'use strict';
|
||||
const crypto = require('crypto');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const SECRET = () => String(process.env.NETWORK_SSO_SECRET || '').trim();
|
||||
const enabled = () => SECRET().length >= 32;
|
||||
const TTL = 60 * 1000; // token life
|
||||
const SKEW = 30 * 1000; // clock skew allowed between the two servers
|
||||
const STATE_AGE = 300; // seconds: the state cookie
|
||||
const TRIED_AGE = 1800; // seconds: one silent check per browser per 30 minutes
|
||||
const OFF_AGE = 12 * 3600; // seconds: no silent check after a sign-out on this site
|
||||
const HINT_AGE = 300; // seconds: the email prefill when the member is not here yet
|
||||
const NAMES = { iap: 'InstantAdPay', linkspin: 'LinkSpin', bannerline: 'Downline Banners' };
|
||||
const WALLET_RE = /^0x[0-9a-f]{40}$/;
|
||||
|
||||
let C = null; // { self, peer, peerBase(), isProd, dataDir, db, member(req), accept(email, req, v), signIn(email, req, v), landing(to), signinPath(to), defaultPath,
|
||||
// wallets?: { site: base() } + wallet(session) -> { address, name }, from?: { site: base() } }
|
||||
|
||||
const b64u = buf => Buffer.from(buf).toString('base64').replace(/=+$/, '').replace(/\+/g, '-').replace(/\//g, '_');
|
||||
const unb64u = s => Buffer.from(String(s).replace(/-/g, '+').replace(/_/g, '/'), 'base64');
|
||||
const mac = s => crypto.createHmac('sha256', SECRET()).update('nsso.v1.' + s).digest();
|
||||
const mask = e => String(e || '').replace(/^(.).*(@.*)$/, '$1***$2');
|
||||
const log = (what, email, extra) => console.log('network-sso', what, email ? mask(email) : '-', extra || '');
|
||||
|
||||
// a same-site relative path, or the default. No scheme, no host, no protocol-relative //x, no backslashes, no control characters.
|
||||
function safePath(to, dflt) {
|
||||
const d = dflt == null ? '/' : dflt;
|
||||
const s = String(to == null ? '' : to);
|
||||
if (!s || s.length > 600 || s[0] !== '/' || s[1] === '/' || s[1] === '\\' || /[\\\u0000-\u001f\u007f\s]/.test(s)) return d;
|
||||
try { const x = new URL(s, 'http://x.invalid'); if (x.host !== 'x.invalid' || x.protocol !== 'http:') return d; return x.pathname + x.search + x.hash; } catch (e) { return d; }
|
||||
}
|
||||
|
||||
function mint(o) {
|
||||
const now = o.now || Date.now();
|
||||
const t = { iss: o.iss, aud: o.aud, email: String(o.email || '').trim().toLowerCase(), st: o.st, to: safePath(o.to), iat: now, exp: now + TTL, n: crypto.randomBytes(16).toString('hex') };
|
||||
if (o.wallet) t.wallet = String(o.wallet).toLowerCase();
|
||||
if (o.name) t.name = String(o.name).slice(0, 40);
|
||||
const body = b64u(JSON.stringify(t));
|
||||
return 'v1.' + body + '.' + b64u(mac(body));
|
||||
}
|
||||
|
||||
// -> { ok, email, to, n, exp } or { error: reason }
|
||||
function verify(tok, o) {
|
||||
if (!enabled()) return { error: 'off' };
|
||||
const m = /^v1\.([A-Za-z0-9_-]{20,2000})\.([A-Za-z0-9_-]{43})$/.exec(String(tok || ''));
|
||||
if (!m) return { error: 'malformed' };
|
||||
const want = mac(m[1]), got = unb64u(m[2]);
|
||||
if (want.length !== got.length || !crypto.timingSafeEqual(want, got)) return { error: 'signature' };
|
||||
let p; try { p = JSON.parse(unb64u(m[1]).toString('utf8')); } catch (e) { return { error: 'malformed' }; }
|
||||
const now = (o && o.now) || Date.now();
|
||||
if (!p || p.aud !== o.aud || ![].concat(o.iss).includes(p.iss)) return { error: 'audience' };
|
||||
if (!(Number(p.exp) > now) || Number(p.iat) > now + SKEW || Number(p.exp) - Number(p.iat) > TTL) return { error: 'expired' };
|
||||
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(String(p.email || ''))) return { error: 'email' };
|
||||
if (!/^[a-f0-9]{32}$/.test(String(p.n || ''))) return { error: 'malformed' };
|
||||
const st = String((o && o.st) || '');
|
||||
if (!/^[a-f0-9]{32}$/.test(st) || !/^[a-f0-9]{32}$/.test(String(p.st || '')) || !crypto.timingSafeEqual(Buffer.from(st), Buffer.from(p.st))) return { error: 'state' };
|
||||
if (p.wallet != null && !WALLET_RE.test(String(p.wallet))) return { error: 'wallet' };
|
||||
const name = p.name != null && /^[A-Za-z0-9_.-]{1,40}$/.test(String(p.name)) ? String(p.name) : null;
|
||||
return { ok: true, iss: p.iss, email: String(p.email).toLowerCase(), wallet: p.wallet || null, name, to: safePath(p.to), n: p.n, exp: Number(p.exp) };
|
||||
}
|
||||
|
||||
// single use: true the first time a nonce is spent. MySQL when the site runs on it (two app copies during a deploy share it),
|
||||
// else memory + a small file in DATA_DIR (survives a restart inside the 60-second window).
|
||||
const used = new Map(); let fileLoaded = false, tableReady = null;
|
||||
const FILE = () => C && C.dataDir ? path.join(C.dataDir, 'network-sso-nonces.json') : null;
|
||||
function prune(now) { for (const [k, exp] of used) if (exp < now) used.delete(k); }
|
||||
function loadFile() {
|
||||
if (fileLoaded) return; fileLoaded = true;
|
||||
try { const o = JSON.parse(fs.readFileSync(FILE(), 'utf8')); for (const k of Object.keys(o)) used.set(k, Number(o[k])); } catch (e) {}
|
||||
}
|
||||
function saveFile() { const f = FILE(); if (!f) return; try { fs.writeFileSync(f + '.tmp', JSON.stringify(Object.fromEntries(used))); fs.renameSync(f + '.tmp', f); } catch (e) { console.error('network-sso nonce save', e.message); } }
|
||||
async function spend(n, exp) {
|
||||
const now = Date.now(); loadFile(); prune(now);
|
||||
if (used.has(n)) return false;
|
||||
used.set(n, Number(exp) + SKEW); saveFile();
|
||||
const db = C && C.db;
|
||||
if (db && db.enabled && db.enabled()) {
|
||||
try {
|
||||
if (!tableReady) tableReady = db.q('CREATE TABLE IF NOT EXISTS network_sso_nonces (n VARCHAR(40) PRIMARY KEY, exp BIGINT NOT NULL) ENGINE=InnoDB').catch(e => { tableReady = null; throw e; });
|
||||
await tableReady;
|
||||
await db.q('INSERT INTO network_sso_nonces (n, exp) VALUES (?, ?)', [n, Number(exp) + SKEW]);
|
||||
if (Math.random() < 0.05) db.q('DELETE FROM network_sso_nonces WHERE exp < ?', [now]).catch(() => {});
|
||||
} catch (e) { if (/duplicate/i.test(e.message || '') || e.code === 'ER_DUP_ENTRY') return false; console.error('network-sso nonce db', e.message); return false; } // fail closed
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// crawlers, link previews and headless browsers never bounce
|
||||
const BOT_RE = /bot|crawl|spider|slurp|preview|facebookexternalhit|embedly|quora link|whatsapp|telegram|discord|skype|curl|wget|python|httpclient|headless|lighthouse|pingdom|monitor|go-http|java\/|okhttp|axios|node-fetch|undici/i;
|
||||
const isBot = req => { const ua = String(req.headers['user-agent'] || ''); return !ua || BOT_RE.test(ua); };
|
||||
// only a real top-level page load may start a bounce (sec-fetch-dest is sent by every current browser)
|
||||
const notPage = req => { const d = req.headers['sec-fetch-dest']; return !!d && d !== 'document'; };
|
||||
|
||||
function cookies(req) {
|
||||
const out = {};
|
||||
for (const p of String(req.headers.cookie || '').split(';')) { const i = p.indexOf('='); if (i > 0) { try { out[p.slice(0, i).trim()] = decodeURIComponent(p.slice(i + 1).trim()); } catch (e) {} } }
|
||||
return out;
|
||||
}
|
||||
const ck = (k, v, age, httpOnly) => k + '=' + encodeURIComponent(v) + '; Path=/; SameSite=Lax; Max-Age=' + age + (httpOnly ? '; HttpOnly' : '') + (C && C.isProd ? '; Secure' : '');
|
||||
const go = (res, loc, set) => { const h = { Location: loc, 'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer', 'X-Robots-Tag': 'noindex' }; if (set && set.length) h['Set-Cookie'] = set; res.writeHead(302, h); res.end(); return true; };
|
||||
const sendJson = (res, obj, set) => { const h = { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' }; if (set && set.length) h['Set-Cookie'] = set; res.writeHead(200, h); res.end(JSON.stringify(obj)); return true; };
|
||||
|
||||
function init(opts) { C = Object.assign({ defaultPath: '/' }, opts); fileLoaded = false; used.clear(); }
|
||||
|
||||
// the cookie a sign-out adds: no silent check on this site for 12 hours (a deliberate cross-site link still signs in)
|
||||
const offCookie = () => ck('nsso.off', '1', OFF_AGE, true);
|
||||
|
||||
// -> true when the request was one of ours and has been answered
|
||||
async function handle(req, res, u) {
|
||||
if (!C || req.method !== 'GET') return false;
|
||||
const p = u.pathname;
|
||||
const peerName = NAMES[C.peer] || C.peer;
|
||||
const goTo = p.startsWith('/go/') ? p.slice(4) : '';
|
||||
const walletBase = x => (C.wallets && Object.prototype.hasOwnProperty.call(C.wallets, x) ? C.wallets[x] : null);
|
||||
if (goTo && (goTo === C.peer || walletBase(goTo))) {
|
||||
const base = goTo === C.peer ? C.peerBase() : walletBase(goTo)();
|
||||
const to = safePath(u.searchParams.get('to'), '/');
|
||||
const plain = base + to;
|
||||
if (!enabled() || isBot(req)) return go(res, plain);
|
||||
let s = null; try { s = await C.member(req); } catch (e) {}
|
||||
if (!s || !s.email) return go(res, plain);
|
||||
if (goTo !== C.peer) { let w = null; try { w = await C.wallet(s); } catch (e) {} if (!w || !w.address) return go(res, plain); } // no wallet to vouch for: a plain link
|
||||
return go(res, base + '/sso/start?mode=go' + (goTo === C.peer ? '' : '&via=' + C.self) + '&to=' + encodeURIComponent(to));
|
||||
}
|
||||
if (p === '/sso/start') {
|
||||
const to = safePath(u.searchParams.get('to'), C.defaultPath);
|
||||
const mode = u.searchParams.get('mode') === 'go' ? 'go' : 'check';
|
||||
const via = String(u.searchParams.get('via') || '');
|
||||
const from = C.from && Object.prototype.hasOwnProperty.call(C.from, via) ? C.from[via] : null; // a wallet site may ask either provider
|
||||
if (!enabled() || isBot(req) || notPage(req)) return go(res, to);
|
||||
let s = null; try { s = await C.member(req); } catch (e) {}
|
||||
if (s && (s.email || s.address)) return go(res, to); // already signed in here
|
||||
const c = cookies(req);
|
||||
if (mode === 'check' && (c['nsso.tried'] || c['nsso.off'])) return go(res, to);
|
||||
const st = crypto.randomBytes(16).toString('hex');
|
||||
const set = [ck('nsso.st', st, STATE_AGE, true), ck('nsso.tried', '1', TRIED_AGE, true)];
|
||||
if (mode === 'go' && c['nsso.off']) set.push(ck('nsso.off', '', 0, true));
|
||||
return go(res, (from ? from() : C.peerBase()) + '/sso/check?st=' + st + (C.from ? '&r=' + C.self : '') + '&to=' + encodeURIComponent(to), set);
|
||||
}
|
||||
if (p === '/sso/check') {
|
||||
const st = String(u.searchParams.get('st') || '');
|
||||
const to = safePath(u.searchParams.get('to'), '/');
|
||||
const r = String(u.searchParams.get('r') || '');
|
||||
const wb = r && r !== C.peer ? walletBase(r) : null; // a wallet site asking: the token carries the wallet
|
||||
const base = wb ? wb() : C.peerBase(), aud = wb ? r : C.peer, forName = NAMES[aud] || aud;
|
||||
const none = base + '/sso/in?none=1&to=' + encodeURIComponent(to);
|
||||
if (!enabled() || !/^[a-f0-9]{32}$/.test(st)) return go(res, none);
|
||||
let s = null; try { s = await C.member(req); } catch (e) {}
|
||||
if (!s || !s.email) { log('check: not signed in here', null, 'for ' + forName); return go(res, none); }
|
||||
let w = null;
|
||||
if (wb) { try { w = await C.wallet(s); } catch (e) {} if (!w || !WALLET_RE.test(String(w.address || '').toLowerCase())) { log('check: no wallet on the account', s.email, 'for ' + forName); return go(res, none); } }
|
||||
log('token issued', s.email, 'for ' + forName);
|
||||
return go(res, base + '/sso/in?t=' + mint({ iss: C.self, aud, email: s.email, wallet: w && w.address, name: w && w.name, st, to }));
|
||||
}
|
||||
if (p === '/sso/in') {
|
||||
const c = cookies(req);
|
||||
const set = [ck('nsso.st', '', 0, true)];
|
||||
if (u.searchParams.get('none')) { log('none: not signed in on ' + peerName); return go(res, C.signinPath(safePath(u.searchParams.get('to'), C.defaultPath)), set); }
|
||||
const v = verify(u.searchParams.get('t'), { iss: [C.peer].concat(Object.keys(C.from || {})), aud: C.self, st: c['nsso.st'] });
|
||||
if (v.error) { log('refused: ' + v.error); return go(res, C.signinPath(C.defaultPath), set); }
|
||||
if (!(await spend(v.n, v.exp))) { log('refused: token already used', v.email); return go(res, C.signinPath(v.to), set); }
|
||||
let a = null; try { a = await C.accept(v.email, req, v); } catch (e) { a = { fallback: 'error ' + e.message }; }
|
||||
if (!a || !a.ok) { // not a member here yet (or not allowed to sign in): the normal email-code sign-in, email filled in
|
||||
log('fallback to email code: ' + ((a && a.fallback) || 'not accepted'), v.email);
|
||||
set.push(ck('nsso.hint', v.email, HINT_AGE, true));
|
||||
return go(res, C.signinPath(v.to), set);
|
||||
}
|
||||
let cookie = null; try { cookie = await C.signIn(v.email, req, v); } catch (e) { console.error('network-sso sign-in', e.message); }
|
||||
if (!cookie) { log('fallback to email code: session not made', v.email); return go(res, C.signinPath(v.to), set); }
|
||||
set.push(cookie); if (c['nsso.off']) set.push(ck('nsso.off', '', 0, true));
|
||||
log('signed in from ' + (NAMES[v.iss] || peerName), v.email);
|
||||
return go(res, C.landing(v.to === '/' ? C.defaultPath : v.to), set); // no page named: the dashboard, not the public home page (2026-11-13)
|
||||
}
|
||||
if (p === '/api/sso/status') {
|
||||
const c = cookies(req); const set = [];
|
||||
let s = null; try { s = await C.member(req); } catch (e) {}
|
||||
const signedIn = !!(s && (s.email || s.address));
|
||||
const out = { peer: peerName, check: enabled() && !signedIn && !isBot(req) && !c['nsso.tried'] && !c['nsso.off'] };
|
||||
if (c['nsso.hint']) { if (!signedIn) out.hint = c['nsso.hint']; set.push(ck('nsso.hint', '', 0, true)); }
|
||||
return sendJson(res, out, set);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = { init, handle, enabled, mint, verify, spend, safePath, isBot, offCookie, mask, TTL, NAMES };
|
||||
@@ -1 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="468" height="60" viewBox="0 0 468 60"><defs><linearGradient id="g" x1="0" x2="1"><stop offset="0" stop-color="#2a1f55"/><stop offset="1" stop-color="#0e0c18"/></linearGradient></defs><rect width="468" height="60" rx="6" fill="url(#g)"/><rect x="1" y="1" width="466" height="58" rx="6" fill="none" stroke="#9b7bff" stroke-opacity=".6"/><text x="18" y="27" font-family="Segoe UI,Arial,sans-serif" font-size="19" font-weight="700" fill="#f3f1fa">Banner Line: this slot is open</text><text x="18" y="46" font-family="Segoe UI,Arial,sans-serif" font-size="12.5" fill="#c9c3e3">A $5 spot = 300 guaranteed views and a place in the line.</text><rect x="368" y="17" width="84" height="26" rx="13" fill="#c6f432"/><text x="410" y="34.5" text-anchor="middle" font-family="Segoe UI,Arial,sans-serif" font-size="12.5" font-weight="700" fill="#141a02">Get a spot</text></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="468" height="60" viewBox="0 0 468 60"><defs><linearGradient id="g" x1="0" x2="1"><stop offset="0" stop-color="#2a1f55"/><stop offset="1" stop-color="#0e0c18"/></linearGradient></defs><rect width="468" height="60" rx="6" fill="url(#g)"/><rect x="1" y="1" width="466" height="58" rx="6" fill="none" stroke="#9b7bff" stroke-opacity=".6"/><text x="18" y="27" font-family="Segoe UI,Arial,sans-serif" font-size="19" font-weight="700" fill="#f3f1fa">Downline Banners: slot open</text><text x="18" y="46" font-family="Segoe UI,Arial,sans-serif" font-size="12.5" fill="#c9c3e3">A $5 spot = 300 guaranteed views and a place in the line.</text><rect x="368" y="17" width="84" height="26" rx="13" fill="#c6f432"/><text x="410" y="34.5" text-anchor="middle" font-family="Segoe UI,Arial,sans-serif" font-size="12.5" font-weight="700" fill="#141a02">Get a spot</text></svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 909 B After Width: | Height: | Size: 906 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><linearGradient id="dbg" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#c6f432"/><stop offset=".55" stop-color="#7ef0c8"/><stop offset="1" stop-color="#6fd8ff"/></linearGradient><linearGradient id="dbb" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#211b3a"/><stop offset="1" stop-color="#110e1d"/></linearGradient></defs><rect x="1" y="1" width="62" height="62" rx="16" fill="url(#dbb)" stroke="#9b7bff" stroke-opacity=".45" stroke-width="2"/><rect x="11" y="13" width="30" height="9" rx="3" fill="url(#dbg)"/><rect x="17" y="27.5" width="30" height="9" rx="3" fill="url(#dbg)" opacity=".8"/><rect x="23" y="42" width="30" height="9" rx="3" fill="url(#dbg)" opacity=".6"/><path d="M14 25v8.5a3 3 0 0 0 3 3h0M20 39.5v6a3 3 0 0 0 3 3" fill="none" stroke="#9b7bff" stroke-width="2.4" stroke-linecap="round"/></svg>
|
||||
|
After Width: | Height: | Size: 924 B |
@@ -18,8 +18,8 @@ window.BL = (function () {
|
||||
const c = await getConfig().catch(() => ({}));
|
||||
const n = document.createElement('nav');
|
||||
const links = [['/', 'Home'], ['/board', 'Board'], ['/how', 'How it works'], ['/join', 'Get a spot'], ['/my', 'My Spots']];
|
||||
n.innerHTML = '<div class="wrap"><div class="logo-wrap"><a class="logo" href="/">Banner <b>Line</b></a>'
|
||||
+ '<span class="byline">Part of the <b>Crypto Team Build</b> Network</span></div><div class="links">'
|
||||
n.innerHTML = '<div class="wrap"><a class="brand" href="/"><img src="/art/mark.svg" alt="" width="38" height="38"><span class="logo-wrap"><span class="logo">Downline <b>Banners</b></span>'
|
||||
+ '<span class="byline">Part of the <b>Crypto Team Build</b> Network</span></span></a><div class="links">'
|
||||
+ links.map(l => '<a href="' + l[0] + '"' + (l[0] === active ? ' class="active"' : '') + '>' + l[1] + '</a>').join('') + '</div></div>';
|
||||
document.body.prepend(n);
|
||||
if (c && c.chainId && c.chainId !== 137) {
|
||||
|
||||
@@ -45,3 +45,6 @@ nav .links a.active{color:var(--mint-ink);background:var(--mint)}
|
||||
.logo b{background:linear-gradient(92deg,var(--mint),var(--cyan));-webkit-background-clip:text;background-clip:text;color:transparent}
|
||||
.btn{box-shadow:0 6px 28px -6px rgba(198,244,50,.45)}
|
||||
.steps li.on{background:var(--mint-soft)}
|
||||
.brand{display:flex;align-items:center;gap:11px;color:var(--ink);text-decoration:none!important;min-width:0}
|
||||
.brand img{flex:none;filter:drop-shadow(0 4px 14px rgba(155,123,255,.35))}
|
||||
.brand .logo{letter-spacing:-.02em}
|
||||
|
||||
+4
-2
@@ -7,6 +7,8 @@
|
||||
const c = await BL.getConfig();
|
||||
const me = await BL.getJSON('/api/me');
|
||||
if (!me.signedIn) {
|
||||
// network sign-in (2026-11-13): signed in on InstantAdPay already? One quick hop there and back signs you in here too
|
||||
try { const ss = await BL.getJSON('/api/sso/status'); if (ss && ss.check) { location.replace('/sso/start?mode=check&to=' + encodeURIComponent('/my' + location.hash)); return; } } catch (e) {}
|
||||
$('signin').hidden = false;
|
||||
$('signBtn').onclick = async () => {
|
||||
try { BL.status('Check your wallet for the sign-in message.'); await BLWallet.signIn(); location.reload(); }
|
||||
@@ -18,7 +20,7 @@
|
||||
async function load() {
|
||||
const d = await BL.getJSON('/api/my');
|
||||
if (d.error) return BL.status(d.error, 'err');
|
||||
$('dash').hidden = false; $('me').textContent = d.address;
|
||||
$('dash').hidden = false; $('me').textContent = d.username ? '@' + d.username + ' (' + BL.short(d.address) + ')' : d.address;
|
||||
const delivered = d.spots.reduce((t, s) => t + s.views, 0);
|
||||
$('stats').innerHTML = [['Spots owned', d.spots.length], ['Views delivered', delivered + ' of ' + d.spots.filter(s => s.kind !== 3).length * c.viewsOwed],
|
||||
['POL paid in', BL.fmtPol(d.paidInWei)], ['POL paid out to you', BL.fmtPol(d.paidOutWei)]]
|
||||
@@ -30,7 +32,7 @@
|
||||
for (const s of d.spots) box.appendChild(editor('spot', s));
|
||||
$('defaults').innerHTML = ''; $('defaults').appendChild(editor('default', { img: d.defaults.img || '', link: d.defaults.link || '', showing: { img: d.defaults.img || '/art/house-line.svg' } }));
|
||||
$('payouts').innerHTML = d.payouts.length ? '<table class="tbl"><tr><th>Spot sold</th><th>Why</th><th>POL</th><th>Tx</th></tr>' + d.payouts.map(p => '<tr><td>#' + p.spotId + '</td><td>' + esc(ROLE[p.role] || p.role) + '</td><td>' + BL.fmtPol(p.amount, 6) + '</td><td class="mono small">' + txLink(p.tx) + '</td></tr>').join('') + '</table>' : '<p class="muted">No payments yet. You are paid when spots sell after yours, or when someone you referred buys.</p>';
|
||||
$('directs').innerHTML = d.directs.length ? '<table class="tbl"><tr><th>Member</th><th>Joined</th><th>Spots</th><th>Paid spots</th><th>POL paid in</th></tr>' + d.directs.map(m => '<tr><td class="mono small">' + esc(BL.short(m.address)) + '</td><td>' + new Date(m.joinedAt).toLocaleDateString() + '</td><td>' + m.spots + '</td><td>' + m.paidSpots + '</td><td>' + BL.fmtPol(m.paidInWei) + '</td></tr>').join('') + '</table>' : '<p class="muted">Nobody has joined through your link yet.</p>';
|
||||
$('directs').innerHTML = d.directs.length ? '<table class="tbl"><tr><th>Member</th><th>Joined</th><th>Spots</th><th>Paid spots</th><th>POL paid in</th></tr>' + d.directs.map(m => '<tr><td class="mono small">' + esc(m.username ? '@' + m.username : BL.short(m.address)) + '</td><td>' + new Date(m.joinedAt).toLocaleDateString() + '</td><td>' + m.spots + '</td><td>' + m.paidSpots + '</td><td>' + BL.fmtPol(m.paidInWei) + '</td></tr>').join('') + '</table>' : '<p class="muted">Nobody has joined through your link yet.</p>';
|
||||
}
|
||||
const txLink = h => c.explorer ? '<a target="_blank" rel="noopener" href="' + esc(c.explorer + '/tx/' + h) + '">' + esc(h.slice(0, 10)) + '...</a>' : esc(h.slice(0, 10)) + '...';
|
||||
function editor(kind, s) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Banner Line wallet plumbing: InstantAdPay's wallet.js (same AppKit build, chain guard, fee fix, dead-session
|
||||
// Downline Banners wallet plumbing: InstantAdPay's wallet.js (same AppKit build, chain guard, fee fix, dead-session
|
||||
// recovery), with buy(sponsor) / buyFor(owner, sponsor) in place of the IAP product buy. Selectors come from
|
||||
// /api/config (server abi.js), so the ABI lives in one module.
|
||||
// Wallet plumbing via Reown AppKit — the universal connector every wallet is
|
||||
@@ -49,7 +49,7 @@ window.BLWallet = (function () {
|
||||
const wagmiAdapter = new WagmiAdapter({ networks: allNets, projectId });
|
||||
modal = createAppKit({
|
||||
adapters: [wagmiAdapter], networks: allNets, projectId, defaultNetwork: net,
|
||||
metadata: { name: 'Banner Line', description: 'Spots on the board, split on-chain when spots sell.',
|
||||
metadata: { name: 'Downline Banners', description: 'Spots on the board, split on-chain when spots sell.',
|
||||
url: location.origin, icons: [location.origin + '/logo-icon.png'] },
|
||||
features: { analytics: false, email: false, socials: [] },
|
||||
// Picker order: wallets without Trust's balance-proportion block go first.
|
||||
|
||||
+5
-5
@@ -2,12 +2,12 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Board | Banner Line</title>
|
||||
<meta name="description" content="Banner Line: a $5 spot buys 300 guaranteed views on the board and a place in the line. Paid instantly on-chain when spots sell.">
|
||||
<link rel="icon" type="image/png" href="/logo-icon.png">
|
||||
<title>Board | Downline Banners</title>
|
||||
<meta name="description" content="Downline Banners: a $5 spot buys 300 guaranteed views on the board and a place in the line. Paid instantly on-chain when spots sell.">
|
||||
<link rel="icon" type="image/svg+xml" href="/art/mark.svg"><link rel="icon" type="image/png" href="/logo-icon.png">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,600;12..96,700;12..96,800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500&display=swap">
|
||||
<link rel="stylesheet" href="/assets/site.css?v=2">
|
||||
<link rel="stylesheet" href="/assets/line.css?v=2">
|
||||
<link rel="stylesheet" href="/assets/line.css?v=3">
|
||||
</head>
|
||||
<body>
|
||||
<main class="wrap">
|
||||
@@ -17,7 +17,7 @@
|
||||
<div class="card"><h3>The line so far</h3><div id="stats" class="grid2"></div></div>
|
||||
<div id="status" class="note" hidden></div>
|
||||
</main>
|
||||
<script src="/assets/common.js?v=1"></script>
|
||||
<script src="/assets/common.js?v=2"></script>
|
||||
<script src="/assets/board.js?v=1"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+6
-6
@@ -2,16 +2,16 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>How it works | Banner Line</title>
|
||||
<meta name="description" content="Banner Line: a $5 spot buys 300 guaranteed views on the board and a place in the line. Paid instantly on-chain when spots sell.">
|
||||
<link rel="icon" type="image/png" href="/logo-icon.png">
|
||||
<title>How it works | Downline Banners</title>
|
||||
<meta name="description" content="Downline Banners: a $5 spot buys 300 guaranteed views on the board and a place in the line. Paid instantly on-chain when spots sell.">
|
||||
<link rel="icon" type="image/svg+xml" href="/art/mark.svg"><link rel="icon" type="image/png" href="/logo-icon.png">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,600;12..96,700;12..96,800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500&display=swap">
|
||||
<link rel="stylesheet" href="/assets/site.css?v=2">
|
||||
<link rel="stylesheet" href="/assets/line.css?v=2">
|
||||
<link rel="stylesheet" href="/assets/line.css?v=3">
|
||||
</head>
|
||||
<body>
|
||||
<main class="wrap">
|
||||
<section class="hero"><h1>How Banner Line works</h1><p class="lead">One global line of 468x60 spots. Plain rules, all on-chain, nothing held by the site.</p></section>
|
||||
<section class="hero"><h1>How Downline Banners works</h1><p class="lead">One global line of 468x60 spots. Plain rules, all on-chain, nothing held by the site.</p></section>
|
||||
<div class="card"><h3>What a spot buys</h3><p>A spot costs $5 in POL at the Chainlink POL/USD price. It buys two things: 300 guaranteed views on the board for your image and link (delivered within 30 days, newest spots on top), and a place in the line.</p></div>
|
||||
<div class="card"><h3>Where the $5 goes, in the same transaction</h3>
|
||||
<table class="tbl"><tr><th>Share</th><th>To</th></tr>
|
||||
@@ -24,7 +24,7 @@
|
||||
<div class="card"><h3>The momentum fund</h3><p>When no spot has sold for 4 hours, the fund buys one (at most 12 a day). It gifts the spot to an active member who owns a paid spot and has not had a gift in 7 days, members who referred someone recently first. If nobody qualifies, the fund keeps the spot and its line money goes back into the fund.</p></div>
|
||||
<div class="card"><h3>The rest of the network</h3><p>Open board slots show network sites such as InstantAdPay and LinkSpin. On InstantAdPay, ad credits buy advertising, not income.</p></div>
|
||||
</main>
|
||||
<script src="/assets/common.js?v=1"></script>
|
||||
<script src="/assets/common.js?v=2"></script>
|
||||
<script src="/assets/how.js?v=1"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+5
-5
@@ -2,12 +2,12 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Banner Line | Banner real estate in one line</title>
|
||||
<meta name="description" content="Banner Line: a $5 spot buys 300 guaranteed views on the board and a place in the line. Paid instantly on‑chain when spots sell.">
|
||||
<link rel="icon" type="image/png" href="/logo-icon.png">
|
||||
<title>Downline Banners | Banner real estate in one line</title>
|
||||
<meta name="description" content="Downline Banners: a $5 spot buys 300 guaranteed views on the board and a place in the line. Paid instantly on‑chain when spots sell.">
|
||||
<link rel="icon" type="image/svg+xml" href="/art/mark.svg"><link rel="icon" type="image/png" href="/logo-icon.png">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,600;12..96,700;12..96,800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500&display=swap">
|
||||
<link rel="stylesheet" href="/assets/site.css?v=2">
|
||||
<link rel="stylesheet" href="/assets/line.css?v=2">
|
||||
<link rel="stylesheet" href="/assets/line.css?v=3">
|
||||
</head>
|
||||
<body>
|
||||
<main class="wrap">
|
||||
@@ -37,7 +37,7 @@
|
||||
</section>
|
||||
<div id="status" class="note" hidden></div>
|
||||
</main>
|
||||
<script src="/assets/common.js?v=1"></script>
|
||||
<script src="/assets/common.js?v=2"></script>
|
||||
<script src="/assets/gate.js?v=1"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+5
-5
@@ -2,12 +2,12 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Get a spot | Banner Line</title>
|
||||
<meta name="description" content="Banner Line: a $5 spot buys 300 guaranteed views on the board and a place in the line. Paid instantly on-chain when spots sell.">
|
||||
<link rel="icon" type="image/png" href="/logo-icon.png">
|
||||
<title>Get a spot | Downline Banners</title>
|
||||
<meta name="description" content="Downline Banners: a $5 spot buys 300 guaranteed views on the board and a place in the line. Paid instantly on-chain when spots sell.">
|
||||
<link rel="icon" type="image/svg+xml" href="/art/mark.svg"><link rel="icon" type="image/png" href="/logo-icon.png">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,600;12..96,700;12..96,800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500&display=swap">
|
||||
<link rel="stylesheet" href="/assets/site.css?v=2">
|
||||
<link rel="stylesheet" href="/assets/line.css?v=2">
|
||||
<link rel="stylesheet" href="/assets/line.css?v=3">
|
||||
</head>
|
||||
<body>
|
||||
<main class="wrap">
|
||||
@@ -34,7 +34,7 @@
|
||||
<div id="status" class="note" hidden></div>
|
||||
<div class="card" id="doneCard" hidden><h3>Your spot is in the line</h3><p>Next: add your image and link in My Spots. One free signature signs you in (it cannot move funds).</p><div class="row"><button class="btn" id="toMyBtn">Open My Spots</button></div><p class="small mono" id="txLink"></p></div>
|
||||
</main>
|
||||
<script src="/assets/common.js?v=1"></script>
|
||||
<script src="/assets/common.js?v=2"></script>
|
||||
<script src="/assets/wallet.js?v=1"></script>
|
||||
<script src="/assets/join.js?v=2&o=1"></script>
|
||||
</body>
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 23 KiB |
+6
-6
@@ -2,12 +2,12 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>My Spots | Banner Line</title>
|
||||
<meta name="description" content="Banner Line: a $5 spot buys 300 guaranteed views on the board and a place in the line. Paid instantly on-chain when spots sell.">
|
||||
<link rel="icon" type="image/png" href="/logo-icon.png">
|
||||
<title>My Spots | Downline Banners</title>
|
||||
<meta name="description" content="Downline Banners: a $5 spot buys 300 guaranteed views on the board and a place in the line. Paid instantly on-chain when spots sell.">
|
||||
<link rel="icon" type="image/svg+xml" href="/art/mark.svg"><link rel="icon" type="image/png" href="/logo-icon.png">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,600;12..96,700;12..96,800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500&display=swap">
|
||||
<link rel="stylesheet" href="/assets/site.css?v=2">
|
||||
<link rel="stylesheet" href="/assets/line.css?v=2">
|
||||
<link rel="stylesheet" href="/assets/line.css?v=3">
|
||||
</head>
|
||||
<body>
|
||||
<main class="wrap">
|
||||
@@ -26,8 +26,8 @@
|
||||
</div>
|
||||
<div id="status" class="note" hidden></div>
|
||||
</main>
|
||||
<script src="/assets/common.js?v=1"></script>
|
||||
<script src="/assets/common.js?v=2"></script>
|
||||
<script src="/assets/wallet.js?v=1"></script>
|
||||
<script src="/assets/my.js?v=1"></script>
|
||||
<script src="/assets/my.js?v=3"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Banner Line web app (downlinebanners.com). Plain Node http server, no framework (InstantAdPay pattern).
|
||||
// Downline Banners web app (downlinebanners.com). Plain Node http server, no framework (InstantAdPay pattern).
|
||||
// Pages: / (gate, then board + join), /board, /join (buy), /my (My Spots + dashboard), /how.
|
||||
// Chain index: chain.js. Board/rotation: board.js. Creative + link checks: safety.js. Keeper: keeper.js.
|
||||
const http = require('http');
|
||||
@@ -13,6 +13,7 @@ const board = require('./board');
|
||||
const safety = require('./safety');
|
||||
const keeper = require('./keeper');
|
||||
const { iface } = require('./abi');
|
||||
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)
|
||||
|
||||
const C = cfgMod.get();
|
||||
@@ -72,18 +73,29 @@ function limited(req, name, max, windowMs) {
|
||||
return ++b.n > max;
|
||||
}
|
||||
|
||||
// ---- sponsor ref (?ref=<address or InstantAdPay username>) ----
|
||||
const refCache = new Map();
|
||||
// ---- 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.
|
||||
const netCache = new Map();
|
||||
async function netMember(q) {
|
||||
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
|
||||
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;
|
||||
}
|
||||
const nameOf = async addr => { const m = await netMember({ a: addr }); return m && m.address === addr.toLowerCase() ? m.username : null; };
|
||||
// ---- sponsor ref (?ref=<address or network username>) ----
|
||||
async function resolveRef(raw) {
|
||||
const r = String(raw || '').trim();
|
||||
if (ADDR_RE.test(r)) return r.toLowerCase();
|
||||
if (!/^[a-zA-Z0-9_.-]{2,32}$/.test(r) || !C.iapResolveUrl) return null;
|
||||
const hit = refCache.get(r.toLowerCase()); if (hit && Date.now() - hit.at < 3600000) return hit.a;
|
||||
let a = null;
|
||||
try { const ac = new AbortController(); setTimeout(() => ac.abort(), 4000).unref();
|
||||
const j = await (await fetch(C.iapResolveUrl + encodeURIComponent(r), { signal: ac.signal })).json();
|
||||
if (j && ADDR_RE.test(j.address || '')) a = j.address.toLowerCase(); } catch (e) {}
|
||||
refCache.set(r.toLowerCase(), { at: Date.now(), a }); return a;
|
||||
if (!/^[a-zA-Z0-9_]{1,20}$/.test(r) || !C.networkLookupUrl) return null;
|
||||
const m = await netMember({ u: r }); return m ? m.address : null;
|
||||
}
|
||||
const sponsorOf = req => { const v = cookies(req)['bl.ref']; return ADDR_RE.test(v || '') ? v.toLowerCase() : null; };
|
||||
|
||||
@@ -132,18 +144,29 @@ function spotView(s) {
|
||||
clicks: store.clicks(s.id), daysLeft: left, delivering: s.kind !== 3 && left > 0 && v.total < C.viewsOwed,
|
||||
img: m.img || '', link: m.link || '', showing: cr };
|
||||
}
|
||||
function myData(addr) {
|
||||
async function myData(addr) {
|
||||
const a = addr.toLowerCase();
|
||||
const mine = chain.spotsOf(a).map(spotView);
|
||||
const w = chain.walletTotals(a);
|
||||
const dir = chain.directs(a).map(m => { const ss = chain.spotsOf(m.address); return { address: m.address, joinedAt: m.joinedAt, spots: ss.length, paidSpots: ss.filter(x => x.kind === 0).length,
|
||||
paidInWei: ss.filter(x => x.kind === 0 || x.kind === 1).reduce((t, x) => t + BigInt(x.valueWei), 0n).toString() }; });
|
||||
const me = chain.member(a);
|
||||
return { address: a, member: chain.isMember(a), sponsor: me ? me.sponsor : null, spots: mine, paidInWei: w.inWei, paidOutWei: w.outWei, byRole: w.byRole,
|
||||
payouts: chain.paidOf(a).slice(0, 50), directs: dir, defaults: store.memberDefault(a) || {}, share: 'https://' + C.site + '/?ref=' + a };
|
||||
const [username, sponsorName] = await Promise.all([nameOf(a), me && me.sponsor ? nameOf(me.sponsor) : null]);
|
||||
await Promise.all(dir.map(async d => { d.username = await nameOf(d.address); }));
|
||||
return { address: a, username, sponsorName, member: chain.isMember(a), sponsor: me ? me.sponsor : null, spots: mine, paidInWei: w.inWei, paidOutWei: w.outWei, byRole: w.byRole,
|
||||
payouts: chain.paidOf(a).slice(0, 50), directs: dir, defaults: store.memberDefault(a) || {}, share: 'https://' + C.site + '/?ref=' + (username || a) };
|
||||
}
|
||||
|
||||
// ---- server ----
|
||||
// Downline Banners only RECEIVES network sign-ins: a member signed in on InstantAdPay (or LinkSpin) arrives signed in as the wallet that
|
||||
// site vouches for (the one they signed in with there, else the main wallet their account linked by signature). No email here.
|
||||
networksso.init({ self: 'bannerline', peer: 'iap', peerBase: () => C.iapBase, from: { iap: () => C.iapBase, linkspin: () => C.lsBase },
|
||||
isProd: C.isProd, dataDir: C.dataDir, defaultPath: '/my',
|
||||
member: async req => { const s = session(req); return s ? { address: s.address } : null; },
|
||||
accept: async (email, req, v) => (v && v.wallet ? { ok: true } : { fallback: 'no wallet in the token' }),
|
||||
signIn: async (email, req, v) => { if (v.name) netCache.set('a:' + v.wallet, { at: Date.now(), m: { address: v.wallet, username: v.name } }); return cookie('bl.sid', store.mintSession(v.wallet), store.SESSION_TTL / 1000, true); },
|
||||
landing: to => to, signinPath: to => to });
|
||||
|
||||
const server = http.createServer(async (req, res) => {
|
||||
const u = new URL(req.url, 'http://x'); const p = u.pathname;
|
||||
try {
|
||||
@@ -151,6 +174,9 @@ const server = http.createServer(async (req, res) => {
|
||||
const ck = cookies(req); const setVid = !ck['bl.vid'] && !isBot(req) ? cookie('bl.vid', crypto.randomBytes(9).toString('hex'), 365 * 86400, true) : null;
|
||||
const extra = setVid ? { 'Set-Cookie': setVid } : {};
|
||||
|
||||
// -- network sign-in (2026-11-13): /sso/start, /sso/in, /api/sso/status
|
||||
if (req.method === 'GET' && (p.startsWith('/sso/') || p === '/api/sso/status') && await networksso.handle(req, res, u)) return;
|
||||
|
||||
// -- pages
|
||||
if (req.method === 'GET' || req.method === 'HEAD') {
|
||||
const PAGES = { '/': 'index.html', '/board': 'board.html', '/join': 'join.html', '/my': 'my.html', '/how': 'how.html' };
|
||||
@@ -163,7 +189,7 @@ const server = http.createServer(async (req, res) => {
|
||||
return sendFile(res, path.join(PUB, PAGES[p]), ex);
|
||||
}
|
||||
if (/^\/r\/[^/]+$/.test(p)) { res.writeHead(302, { Location: '/?ref=' + encodeURIComponent(decodeURIComponent(p.slice(3))) }); return res.end(); }
|
||||
if (p.startsWith('/assets/') || p.startsWith('/art/house-') || p === '/logo-icon.png' || p === '/robots.txt') {
|
||||
if (p.startsWith('/assets/') || p.startsWith('/art/house-') || p === '/art/mark.svg' || p === '/logo-icon.png' || p === '/robots.txt') {
|
||||
const f = path.normalize(path.join(PUB, p)); if (!f.startsWith(PUB)) { res.writeHead(400); return res.end(); }
|
||||
return sendFile(res, f);
|
||||
}
|
||||
@@ -252,7 +278,7 @@ const server = http.createServer(async (req, res) => {
|
||||
if (limited(req, 'auth', 30, 600000)) return json(res, 429, { error: 'Too many sign-in attempts. Wait a few minutes.' });
|
||||
const b = await readBody(req); if (!ADDR_RE.test(b.address || '')) return json(res, 400, { error: 'Bad address' });
|
||||
const a = b.address.toLowerCase(); const nonce = crypto.randomBytes(16).toString('hex');
|
||||
const message = C.site + ' wants you to sign in with your wallet:\n' + getAddress(a) + '\n\nBanner Line sign-in. This signature is free and cannot move funds or approve anything.\n\nChain ID: ' + C.chainId + '\nNonce: ' + nonce + '\nIssued At: ' + new Date().toISOString();
|
||||
const message = C.site + ' wants you to sign in with your wallet:\n' + getAddress(a) + '\n\nDownline Banners sign-in. This signature is free and cannot move funds or approve anything.\n\nChain ID: ' + C.chainId + '\nNonce: ' + nonce + '\nIssued At: ' + new Date().toISOString();
|
||||
challenges.set(a, { message, exp: Date.now() + 600000 });
|
||||
if (challenges.size > 20000) challenges.clear();
|
||||
return json(res, 200, { message });
|
||||
@@ -268,7 +294,7 @@ const server = http.createServer(async (req, res) => {
|
||||
}
|
||||
if (p === '/api/auth/logout' && req.method === 'POST') {
|
||||
const s = session(req); if (s) store.dropSession(s.token);
|
||||
return json(res, 200, { ok: true }, { 'Set-Cookie': cookie('bl.sid', '', 0, true) });
|
||||
return json(res, 200, { ok: true }, { 'Set-Cookie': [cookie('bl.sid', '', 0, true), networksso.offCookie()] }); // signed out stays signed out here for 12 hours
|
||||
}
|
||||
if (p === '/api/me' && req.method === 'GET') {
|
||||
const s = session(req); if (!s) return json(res, 200, { signedIn: false, sponsor: sponsorOf(req) });
|
||||
@@ -280,7 +306,7 @@ const server = http.createServer(async (req, res) => {
|
||||
if (p.startsWith('/api/my')) {
|
||||
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, myData(me));
|
||||
if (p === '/api/my' && req.method === 'GET') return json(res, 200, await myData(me));
|
||||
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.' });
|
||||
@@ -319,13 +345,13 @@ const server = http.createServer(async (req, res) => {
|
||||
|
||||
if (p.startsWith('/api/')) return json(res, 404, { error: 'Not found' });
|
||||
res.writeHead(404, headers({ 'Content-Type': 'text/html; charset=utf-8' }));
|
||||
return res.end('<!doctype html><title>Not found</title><p style="font-family:sans-serif">Not found. <a href="/">Banner Line home</a></p>');
|
||||
return res.end('<!doctype html><title>Not found</title><p style="font-family:sans-serif">Not found. <a href="/">Downline Banners home</a></p>');
|
||||
} catch (e) {
|
||||
console.error('request', p, e.message);
|
||||
if (!res.headersSent) json(res, 500, { error: 'Server error' });
|
||||
}
|
||||
});
|
||||
|
||||
server.listen(C.port, () => console.log('Banner Line on :' + C.port + ' chain ' + C.chainName + ' (' + C.chainId + ') contract ' + (C.contract || '(not set)')));
|
||||
server.listen(C.port, () => console.log('Downline Banners on :' + C.port + ' chain ' + C.chainName + ' (' + C.chainId + ') contract ' + (C.contract || '(not set)')));
|
||||
process.on('SIGTERM', () => { store.flush(); process.exit(0); });
|
||||
process.on('SIGINT', () => { store.flush(); process.exit(0); });
|
||||
|
||||
Reference in New Issue
Block a user