Weekly member email as sectioned HTML (plain-text twin kept); PassiveDrip one-tap hand-off (inert until PD_SSO_SECRET)

- coach.js: weeklyDigest() builds one card per topic (credits, streak, contest, tank, team) with the key number up front and one button; mailer.send takes optional html
- server.js: /api/my/passivedrip mints a signed hand-off (memberId, email, username, verified wallet, sponsor email); Games card for PassiveDrip (admin preview until gamesLive includes passivedrip) with the member's own coins line via the bridge 'member' lookup; sign-in return path
- my.js: card button label, return redirect; v=20261001b

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-01 08:43:22 -05:00
parent dd53d132d6
commit 5a522f0ede
7 changed files with 160 additions and 51 deletions
+29 -3
View File
@@ -1255,8 +1255,22 @@ function GAMES() {
art: DR_URL() + '/badges/ch5.jpg', play: '/api/my/driprunner', pays: 'POL to your wallet at 0.25', progress: drProgress },
{ slug: 'polhunter', name: 'PolHunter', tag: 'Scavenger hunt', blurb: 'Hunt hidden codes on sites across the network. Every find drips POL straight to your wallet.',
art: 'https://polhunter.com/img/hero-800.webp', play: '/api/my/polhunter', pays: 'POL per find' },
{ slug: 'passivedrip', name: 'PassiveDrip', tag: 'Faucet + games', blurb: 'Claim the faucet, view paid-to-click ads, roll the bonus and play the mini games for coins. One tap signs you in with this account, no new password.',
art: '/assets/passivedrip-card.svg', play: '/api/my/passivedrip', cta: 'Open', pays: 'POL to your wallet at 2,000 coins ($1)', progress: pdProgress },
];
}
// -- PassiveDrip hand-off (2026-10-01): same token shape as Drip Runner, its own secret (PD_SSO_SECRET, also stored in
// PassiveDrip's site_config iap_sso_secret). PassiveDrip signs the member in or creates the account, carries the sponsor
// over by email, and OFFERS the wallet with one confirm tap; it never writes or overwrites a payout address silently.
const PD_SECRET = () => String(process.env.PD_SSO_SECRET || '').trim();
const PD_URL = () => String(process.env.PD_URL || 'https://passivedrip.com').replace(/\/+$/, '');
function pdMint(claims) { const payload = JSON.stringify(Object.assign({ aud: 'passivedrip', iat: Date.now(), exp: Date.now() + 5 * 60000, nonce: crypto.randomBytes(16).toString('hex') }, claims)); return drB64u(payload) + '.' + drB64u(crypto.createHmac('sha256', PD_SECRET()).update(payload).digest()); }
async function pdProgress(memberId, email) {
const j = await pdsync.member(memberId, email); if (!j) return null;
if (!j.exists) return { line: 'No PassiveDrip account yet. Open it and one is made for you.' };
const coins = Math.floor(Number(j.coins) || 0);
return { line: '@' + j.username + ' · ' + coins.toLocaleString('en-US') + ' of ' + Number(j.threshold || 2000).toLocaleString('en-US') + ' coins' + (j.hasWallet ? '' : ' · no payout wallet yet') + (j.paidPol ? ' · ' + Number(j.paidPol).toFixed(2) + ' POL paid out' : '') };
}
// the player's own line on the Drip Runner card, read from the game with a signed request
async function drProgress(memberId) {
if (DR_SECRET().length < 32) return null;
@@ -1636,7 +1650,7 @@ const server = http.createServer(async (req, res) => {
let memberId = 0;
if (r.account.address) { try { memberId = await chain.memberIdByAccount(r.account.address); } catch (err) {} }
const token = await auth.mintSession({ email: r.account.email, address: r.account.address, memberId });
return json(res, 200, { ok: true, account: r.account, created: !!r.created, next: parseCookies(req)['iap.return'] === 'driprunner' ? '/api/my/driprunner' : null }, { 'Set-Cookie': auth.sessionCookie(token) }); // next: Drip Runner sent them here to sign in (2026-09-30)
return json(res, 200, { ok: true, account: r.account, created: !!r.created, next: ({ driprunner: '/api/my/driprunner', passivedrip: '/api/my/passivedrip' })[parseCookies(req)['iap.return']] || null }, { 'Set-Cookie': auth.sessionCookie(token) }); // next: Drip Runner sent them here to sign in (2026-09-30)
}
// -- wallet auth: link-to-account when an email session exists, or
@@ -1715,7 +1729,7 @@ const server = http.createServer(async (req, res) => {
const _defSpon = Number(siteConfig().defaultSponsorId) || 1;
if (!sponsorId && memberId !== _defSpon) sponsorId = _defSpon; // orphan fallback → #1 (never self-sponsor)
if (memberId && acct && acct.memberId !== memberId) accounts.setMemberId(acct.email, memberId).catch(() => {});
const out = { signedIn: true, returnTo: ['polhunter', 'driprunner'].includes(parseCookies(req)['iap.return']) ? parseCookies(req)['iap.return'] : null, sponsorBlocked, sponsorRouted, sponsorName: spdMe.name || null, email: s.email || (acct && acct.email) || null,
const out = { signedIn: true, returnTo: ['polhunter', 'driprunner', 'passivedrip'].includes(parseCookies(req)['iap.return']) ? parseCookies(req)['iap.return'] : null, sponsorBlocked, sponsorRouted, sponsorName: spdMe.name || null, email: s.email || (acct && acct.email) || null,
address: s.address || (acct && acct.address) || null, memberId,
username: (acct && acct.username) || null,
refCode: (acct && acct.code) || null, sponsorId,
@@ -2455,6 +2469,18 @@ const server = http.createServer(async (req, res) => {
sponsorRef: (acct && acct.sponsorRef) || null, joinedRef: (acct && acct.joinedRef) || null, joinedAt: (acct && acct.created) || null }); // the game credits referrals to the IAP sponsor
res.writeHead(302, { Location: DR_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': 'iap.return=; Path=/; SameSite=Lax; Max-Age=0' + (IS_PROD ? '; Secure' : '') }); return res.end();
}
// -- PassiveDrip hand-off (2026-10-01): sign the member across; PassiveDrip verifies with the shared secret.
// wallet = the signature-verified main wallet (accounts.linkWallet runs only after /api/auth/verify), offered there, never imposed.
if (p === '/api/my/passivedrip' && req.method === 'GET') {
const s = await auth.fromRequest(req);
if (!s || !s.email) { res.writeHead(302, { Location: '/my', 'Set-Cookie': 'iap.return=passivedrip; Path=/; SameSite=Lax; Max-Age=1800' + (IS_PROD ? '; Secure' : ''), 'Cache-Control': 'no-store' }); return res.end(); } // sign in first, then straight across
if (PD_SECRET().length < 32) return json(res, 503, { error: 'PassiveDrip is not connected yet.' });
const acct = await accounts.byEmail(s.email);
const memberId = (acct && acct.memberId) || s.memberId || 0;
let sponsorEmail = null; try { const up = await uplineSlides(s.email, 1); sponsorEmail = (up[0] && up[0].email) || null; } catch (e) {}
const tok = pdMint({ memberId: Number(memberId), email: String(s.email).toLowerCase(), username: (acct && acct.username) || null, wallet: (acct && acct.address) || null, sponsorEmail });
res.writeHead(302, { Location: PD_URL() + '/iap-signin.php?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': 'iap.return=; Path=/; SameSite=Lax; Max-Age=0' + (IS_PROD ? '; Secure' : '') }); return res.end();
}
// -- Drip Runner refuel: a real verified visit (advertiser charged as usual); the player gets fuel, not credits
if (p === '/api/refuel/open' && req.method === 'GET') {
const r = drOpen(u.searchParams.get('t')); if (r.error) return json(res, 400, { error: r.error });
@@ -2521,7 +2547,7 @@ const server = http.createServer(async (req, res) => {
for (const g of GAMES()) {
const isLive = live.has(g.slug); if (!isLive && !admin) continue;
const card = Object.assign({}, g, { live: isLive, preview: !isLive });
if (g.progress && memberId) { try { card.progress = await g.progress(memberId); } catch (e) {} }
if (g.progress && (memberId || g.slug === 'passivedrip')) { try { card.progress = await g.progress(memberId, s.email); } catch (e) {} }
out.push(card);
}
return json(res, 200, { games: out.map(g => { const c = Object.assign({}, g); if (typeof c.progress === 'function') delete c.progress; return c; }) });