Files
Marty Bostick edaf98c8f6 ViralAdSource app (Marty approved 2026-11-16): free text ads that spread by reshares, each ad with its own family tree
Watershed look from the approved mockup (hero, topo pattern, icons). Network sign-in through the hub, hub membership, activity ping.
Reshare links per member per ad with branch/step tracking; family-tree dashboard (branch, step, reshares, views, clicks, sign-ups, Boosts).
Verified views earn ad credits for the branch's resharer (L3). L2 sign-up pipeline (hub-new, confirmed email, not self device/IP,
throwaway block, daily cap, fraud score) with keeper-signed reward vouchers and a pending-rewards ledger; payouts OFF (REWARD_PAYOUTS).
L1 Boosts through VASShop with signed orders naming the sponsor line and the resharer. Trust pack, chatbot, promo kit, PolHunter embed.
All numbers are PROPOSALS until Marty sets them. qa/e2e.mjs 59/59 on a local anvil chain, chatbot test 108/108.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 09:19:34 -06:00

207 lines
16 KiB
JavaScript

// L2: a verified brand-new network member through a branch (Marty approved 2026-11-16). A visitor who arrived through a reshare link
// (the vas.via tag) joins the network free on /join. Nothing is paid for the join itself; the reward is only for a sign-up that
// passes EVERY real-time check:
// share the link belongs to a resharer (step 1+), who is a verified network member with a wallet; the ad owner's own link
// and visitors without a reshare tag never earn a reward (their sign-up still counts on the tree)
// confirmed the email was confirmed through the link we sent (MAIL_URL unset = no mail is sent: staging; the admin sees the link)
// throwaway the email domain is not a known disposable-mail domain and has a normal shape
// hubNew the network hub has never seen this email (brand new to the WHOLE network). HUB_JOIN=1 writes the join to the hub
// (join-all, sponsor = the resharer) and requires the hub's `created: true`; without it (staging) the check is a dry
// read only: nobody is created anywhere
// notSelf not the resharer's own device (rejected) or connection (held), from their seen device / IP keys here
// dailyCap the resharer has fewer than REWARD_DAILY_CAP rewards today (Central time); the contract enforces its own cap too
// fraud fraud score (0..100) below FRAUD_HOLD: form filled too fast, many sign-ups from one connection, plus-addressing,
// digit-heavy names, a bot browser, a sign-up within seconds of the click, a resharer with a burst of sign-ups
// Outcomes: passed -> a reward row in the pending-rewards ledger with a keeper-signed voucher (when KEEPER_KEY + CONTRACT_ADDRESS are
// set) and status 'pending'. Payouts are OFF (REWARD_PAYOUTS=1 relays claimReward from RELAY_KEY's wallet; the contract pays from the
// reward pot, never more than it holds). held -> waits for an admin look (score, cap, hub unreachable). rejected -> no reward ever.
// Tiers (PROPOSAL, REWARD_TIERS): every Nth verified sign-up of one resharer adds a bigger bonus credited now, withdrawable after N days.
'use strict';
const crypto = require('crypto');
const store = require('./store');
const cfgMod = require('./config');
const C = () => cfgMod.get();
const DISPOSABLE = new Set(['mailinator.com', 'yopmail.com', 'guerrillamail.com', '10minutemail.com', 'tempmail.com', 'temp-mail.org', 'trashmail.com',
'sharklasers.com', 'getnada.com', 'dispostable.com', 'maildrop.cc', 'throwawaymail.com', 'emailondeck.com', 'fakeinbox.com', 'mintemail.com',
'mailnesia.com', 'tempr.email', 'discard.email', 'grr.la', 'guerrillamail.info', 'spam4.me', 'mohmal.com', 'tempmailo.com', 'burnermail.io',
'mailpoof.com', 'moakt.com', 'tmail.ws', 'inboxkitten.com', 'emailfake.com', 'fakemail.net', 'yopmail.fr', 'cuvox.de', 'armyspy.com', 'dayrep.com',
'einrot.com', 'mailsplat.xyz', 'inboxtogo.xyz', 'inboxburn.xyz', 'apxby.com', 'alvisani.com', 'ipniel.com', 'armablog.com', 'bnovel.com', 'fleckens.hu',
'gustr.com', 'jourrapide.com', 'rhyta.com', 'superrito.com', 'teleworm.us', 'mvrht.net', 'byom.de', '33mail.com', 'guerrillamailblock.com', 'pokemail.net',
'mail.tm', 'emailnax.com', 'tempinbox.com', 'mytemp.email', 'trashmail.de', 'getairmail.com', 'mailcatch.com', 'spambox.us', 'mailbox.in.ua', 'harakirimail.com']);
const EMAIL_RE = /^[a-z0-9._%+-]{1,64}@[a-z0-9.-]{1,190}\.[a-z]{2,24}$/;
const NAME_RE = /^[A-Za-z0-9_.-]{3,30}$/;
const st = { joins: 0, confirmed: 0, passed: 0, held: 0, rejected: 0, mailed: 0, mailFailed: 0, hubJoined: 0, relayed: 0 };
let D = null; // { hub: hubpeople, hubJoin(email, ref, username), shop, netVerified(m) }
function init(deps) { D = deps; }
const lc = s => String(s || '').trim().toLowerCase();
const sha = s => crypto.createHash('sha256').update(String(s)).digest('hex');
const domainOf = e => lc(e).split('@')[1] || '';
const throwaway = e => { const d = domainOf(e); if (!d) return true; if (DISPOSABLE.has(d)) return true; for (const x of DISPOSABLE) if (d.endsWith('.' + x)) return true; return false; };
// a join form submitted. j = { email, username, share (code) | null, vk, iph, ua, formMs, clickAt } -> { ok, signup } | { error }
async function join(j) {
const email = lc(j.email); if (!EMAIL_RE.test(email)) return { error: 'Enter a working email address.' };
const username = String(j.username || '').trim(); if (username && !NAME_RE.test(username)) return { error: 'A username is 3 to 30 letters, numbers, dots, dashes or underscores.' };
if (store.signups().some(x => x.emailHash === sha(email) && x.status !== 'unconfirmed')) return { error: 'That email has already joined here. Sign in with InstantAdPay or LinkSpin instead.' };
const sh = j.share ? store.share(j.share) : null;
const token = crypto.randomBytes(24).toString('hex');
// one pending row per email: a second submit replaces the first (new confirm link)
const prev = store.signups().find(x => x.emailHash === sha(email) && x.status === 'unconfirmed');
const row = prev || store.addSignup({ emailHash: sha(email), status: 'unconfirmed' });
Object.assign(row, { email, username: username || null, share: sh ? sh.id : null, adId: sh ? sh.adId : null, resharer: sh && sh.step > 0 ? sh.owner : null,
vk: j.vk, iph: j.iph, ua: String(j.ua || '').slice(0, 200), formMs: Number(j.formMs) || null, clickAt: Number(j.clickAt) || null, tokenHash: sha(token), submittedAt: Date.now() });
store.saveSignup(row); st.joins++; store.bump('joins');
const link = 'https://' + C().site + '/confirm?t=' + token;
const sent = await mail(email, link).catch(() => false);
if (!sent) row.confirmLink = C().staging ? link : undefined; // staging only: the admin can open it (no mail is ever sent there)
store.saveSignup(row);
return { ok: true, signup: row, mailed: sent };
}
// MAIL_URL: a mail relay that takes { from, to, subject, text } (JSON POST). Unset = no mail (staging).
async function mail(to, link) {
if (!C().mail.url) return false;
const text = 'Confirm your free network account by opening this link:\n\n' + link + '\n\nIf you did not ask to join, ignore this email.\n\nViralAdSource, TrustClickz, 615 Green Valley Drive, Moody, AL 35004';
const r = await fetch(C().mail.url, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Mail-Key': String(process.env.MAIL_KEY || '') },
body: JSON.stringify({ from: C().mail.from, to, subject: 'Confirm your free account', text }), signal: AbortSignal.timeout(10000) }).catch(() => null);
if (r && r.ok) { st.mailed++; return true; } st.mailFailed++; return false;
}
// the confirm link opened -> runs the checks. -> { ok, signup } | { error }
async function confirm(token) {
const h = sha(String(token || '')); const x = store.signups().find(s => s.tokenHash === h);
if (!x) return { error: 'That confirm link is not valid or has expired. Join again to get a new one.' };
if (x.status !== 'unconfirmed') return { ok: true, signup: x, again: true };
x.confirmedAt = Date.now(); x.status = 'confirmed'; delete x.confirmLink; store.saveSignup(x); st.confirmed++; store.bump('confirms');
await check(x);
return { ok: true, signup: x };
}
function score(x, res) {
let s = 0; const why = [];
const add = (n, w) => { s += n; why.push(w + ' +' + n); };
if (x.formMs != null && x.formMs < 4000) add(30, 'form filled in under 4 s');
if (x.clickAt && x.submittedAt - x.clickAt < 8000) add(15, 'joined within 8 s of the click');
const local = x.email.split('@')[0];
if (local.includes('+')) add(15, 'plus-addressed email');
if ((local.match(/\d/g) || []).length >= 5) add(10, 'many digits in the email');
if (/bot|crawl|headless|python|curl|wget|phantom|selenium|puppeteer|playwright/i.test(x.ua || '') || !x.ua) add(40, 'bot-like browser');
const day = Date.now() - 86400000;
const sameIp = store.signups().filter(o => o.id !== x.id && o.iph === x.iph && (o.submittedAt || o.createdAt) > day).length;
if (sameIp >= 1) add(Math.min(40, sameIp * 20), sameIp + ' other sign-up(s) from this connection today');
if (x.resharer) {
const burst = store.signups().filter(o => o.id !== x.id && o.resharer === x.resharer && o.confirmedAt && o.confirmedAt > Date.now() - 3600000).length;
if (burst >= 5) add(20, 'resharer had ' + burst + ' sign-ups in the last hour');
const rm = store.member(x.resharer); const rn = lc(rm && rm.username);
if (rn && rn.length >= 4 && local.replace(/[^a-z0-9]/g, '').includes(rn.replace(/[^a-z0-9]/g, ''))) add(25, 'email looks like the resharer\'s own name');
}
res.fraud = { score: Math.min(100, s), why };
return Math.min(100, s);
}
// run (or re-run) every check on a confirmed sign-up
async function check(x) {
const R = C().reward; const res = { at: Date.now() }; const fail = [], hold = [];
// throwaway
res.throwaway = throwaway(x.email) ? 'fail' : 'pass'; if (res.throwaway === 'fail') fail.push('throwaway email');
// hub: brand new to the whole network
let hubNew = null;
const known = await D.hub.resolve({ email: x.email });
if (!known.ok) { res.hubNew = 'unreachable'; hold.push('network hub did not answer'); }
else if (known.person) { res.hubNew = 'fail'; hubNew = false; fail.push('already in the network'); }
else if (C().hubJoin) {
const sh = x.share ? store.share(x.share) : null; const ref = sh ? (store.member(sh.owner) || {}).username : null;
const j = await D.hubJoin(x.email, ref, x.username).catch(() => null);
if (!j || !j.ok) { res.hubNew = 'unreachable'; hold.push('network hub join failed'); }
else if (!j.created) { res.hubNew = 'fail'; hubNew = false; fail.push('already in the network'); }
else { res.hubNew = 'pass'; hubNew = true; x.hubId = j.person && j.person.id; st.hubJoined++; }
} else { res.hubNew = 'pass (dry: HUB_JOIN off, nothing written)'; hubNew = true; }
if (hubNew) { const sh = x.share ? store.share(x.share) : null; if (sh && !x.counted) { sh.signups = (sh.signups || 0) + 1; store.saveShare(sh); x.counted = true; } }
// who would be rewarded
const sh = x.share ? store.share(x.share) : null; const rm = x.resharer ? store.member(x.resharer) : null;
if (!sh) res.share = 'none (no reshare link: nothing to reward)';
else if (sh.step === 0) res.share = 'own ad link (the owner is never rewarded for their own link)';
else if (!rm || !D.netVerified(rm)) { res.share = 'fail'; fail.push('resharer is not a verified network member'); }
else res.share = 'pass';
// not the resharer themself
if (rm) {
const selfDev = (rm.vks || []).includes(x.vk), selfIp = (rm.iphs || []).includes(x.iph);
// the same device is never a new person; the same connection can be a household or an office: held for a person to look at
res.notSelf = selfDev ? 'fail (same device)' : selfIp ? 'hold (same connection)' : 'pass';
if (selfDev) fail.push('the resharer\'s own device'); else if (selfIp) hold.push('the resharer\'s own connection');
}
// daily cap
if (rm) {
const today = store.ctDay(); const n = store.rewards().filter(r => r.to === rm.address && r.kind === 'signup' && store.ctDay(r.createdAt) === today && r.status !== 'void').length;
res.dailyCap = n < R.dailyCap ? 'pass (' + n + ' of ' + R.dailyCap + ' today)' : 'over (' + n + ' of ' + R.dailyCap + ')';
if (n >= R.dailyCap) hold.push('daily cap reached');
}
const sc = score(x, res); if (sc >= R.fraudHold) hold.push('fraud score ' + sc);
x.checks = res; x.fail = fail; x.hold = hold;
const eligible = sh && sh.step > 0 && rm && rm.address;
if (fail.length) { x.status = 'rejected'; st.rejected++; }
else if (!eligible) { x.status = 'verified'; } // a real new member, but no resharer to reward
else if (hold.length) { x.status = 'held'; st.held++; }
else { x.status = 'passed'; st.passed++; await rewardFor(x, rm); }
store.saveSignup(x);
return x;
}
// the pending-rewards ledger: the base reward, plus a tier bonus every Nth verified sign-up of this resharer
async function rewardFor(x, rm) {
const R = C().reward; const wallet = rm.address;
const made = [];
const base = store.addReward({ kind: 'signup', signup: x.id, to: wallet, toName: rm.username || null, cents: R.cents, unlockAt: 0, status: 'pending', share: x.share, adId: x.adId });
made.push(base);
const n = store.signups().filter(o => o.resharer === wallet && o.status === 'passed').length;
for (const t of R.tiers) if (t && t.every > 0 && n % t.every === 0) made.push(store.addReward({ kind: 'tier', tier: t.every, signup: x.id, to: wallet, toName: rm.username || null, cents: Number(t.cents) || 0, unlockAt: Date.now() + (Number(t.lockDays) || 0) * 86400000, status: 'pending', share: x.share, adId: x.adId }));
for (const r of made) {
const v = await D.shop.rewardVoucher(r.to, r.cents, r.unlockAt, R.voucherDays).catch(() => null);
if (v) { r.voucher = v; r.nonce = v.nonce; } else r.note = 'no voucher yet (contract or keeper not set)';
store.saveReward(r); store.bump('rewardsPending'); store.bump('rewardCents', r.cents);
}
x.rewards = made.map(r => r.id);
if (R.payouts) await payDue();
return made;
}
// payouts ON only: relay every pending reward that is unlocked and has a voucher (oldest first)
async function payDue() {
if (!C().reward.payouts) return 0; let n = 0;
for (const r of store.rewards().filter(r => r.status === 'pending' && r.voucher && (!r.unlockAt || r.unlockAt <= Date.now())).sort((a, b) => a.createdAt - b.createdAt)) {
const out = await D.shop.relayReward(r.voucher);
if (out.tx) { r.status = 'sent'; r.tx = out.tx; r.sentAt = Date.now(); n++; st.relayed++; } else { r.lastError = out.error; if (/Pot empty|Daily cap|Pot daily cap/.test(out.error || '')) break; }
store.saveReward(r);
}
return n;
}
// the watcher saw RewardPaid for a nonce
function onPaid(ev) { const r = store.rewards().find(x => x.nonce === ev.nonce); if (r) { r.status = 'paid'; r.tx = ev.txHash; r.weiPaid = ev.weiPaid; r.paidAt = Date.now(); store.saveReward(r); } }
// admin: release a held sign-up (re-run the checks ignoring the hold reasons) or reject it
async function decide(id, action) {
const x = store.signup(id); if (!x) return { error: 'not found' };
if (action === 'reject') { x.status = 'rejected'; x.fail = (x.fail || []).concat(['rejected by admin']); store.saveSignup(x); return { ok: true, signup: x }; }
if (action === 'recheck') { if (x.status === 'unconfirmed') return { error: 'not confirmed yet' }; await check(x); return { ok: true, signup: x }; }
if (action === 'release') {
if (x.status !== 'held') return { error: 'only a held sign-up can be released' };
const rm = store.member(x.resharer); if (!rm) return { error: 'no resharer' };
x.status = 'passed'; x.released = Date.now(); await rewardFor(x, rm); store.saveSignup(x); return { ok: true, signup: x };
}
return { error: 'action reject | recheck | release' };
}
// what a member sees about rewards earned through their reshares
function mine(addr) {
const a = lc(addr); const rows = store.rewards().filter(r => r.to === a).sort((x, y) => y.createdAt - x.createdAt);
const sum = k => rows.filter(r => r.status === k).reduce((t, r) => t + r.cents, 0);
return { payoutsOn: C().reward.payouts, pendingCents: sum('pending'), paidCents: sum('paid'), sentCents: sum('sent'),
items: rows.slice(0, 50).map(r => ({ id: r.id, kind: r.kind, cents: r.cents, status: r.status, at: r.createdAt, unlockAt: r.unlockAt || null, tx: r.tx || null })),
signups: { verified: store.signups().filter(s => s.resharer === a && ['passed', 'held', 'verified'].includes(s.status)).length, held: store.signups().filter(s => s.resharer === a && s.status === 'held').length } };
}
// the public side of the ledger: sign-up rewards with no personal data (the resharer's name, amount, status, tx)
function publicRows(n) {
return store.rewards().slice().sort((a, b) => b.createdAt - a.createdAt).slice(0, n || 50)
.map(r => ({ kind: r.kind, at: r.createdAt, to: r.to, name: r.toName, cents: r.cents, status: r.status, unlockAt: r.unlockAt || null, tx: r.tx || null }));
}
function view() { return Object.assign({ payouts: C().reward.payouts, hubJoin: C().hubJoin, mail: !!C().mail.url, rules: { cents: C().reward.cents, dailyCap: C().reward.dailyCap, fraudHold: C().reward.fraudHold, tiers: C().reward.tiers },
byStatus: store.signups().reduce((o, x) => (o[x.status] = (o[x.status] || 0) + 1, o), {}), rewards: store.rewards().reduce((o, r) => (o[r.status] = (o[r.status] || 0) + 1, o), {}) }, st); }
module.exports = { init, join, confirm, check, decide, payDue, onPaid, mine, publicRows, view, throwaway, DISPOSABLE, _score: score };