From 0013416af7be17f39778671fdb3b2efd90438907 Mon Sep 17 00:00:00 2001 From: martbost Date: Tue, 10 Nov 2026 09:22:27 -0600 Subject: [PATCH] Forum reward lookup (Marty 2026-11-10: 1 POL for an introduction, ongoing, linked wallet + payouts on): GET /api/forum/member?email= signed with the forum secret (HMAC of email.ts, 5-minute window) returns found/username/activated (member id > 0)/address/suspended for the earnerscorner.com reward service. qa/forumsso 17/17. Co-Authored-By: Claude Opus 5.5 --- forumsso.js | 12 +++++++++++- qa/forumsso.mjs | 6 ++++++ server.js | 9 +++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/forumsso.js b/forumsso.js index 3913fdf..25671d4 100644 --- a/forumsso.js +++ b/forumsso.js @@ -41,4 +41,14 @@ function redirectFor(v, acct, site) { return v.returnUrl + (v.returnUrl.includes('?') ? '&' : '?') + 'sso=' + encodeURIComponent(out) + '&sig=' + sign(out); } -module.exports = { verify, redirectFor, sign, SECRET, FORUM_URL }; +// server-to-server: the forum's reward service asks "is this email an activated member, and where are payouts sent?" The request is +// signed with the same shared secret: header x-forum-sig = hex HMAC-SHA256 of ".", x-forum-ts = those seconds, +// valid for 5 minutes. +function verifyServer(email, ts, sig) { + if (SECRET().length < 32) return false; + const t = Number(ts); if (!(t > 0) || Math.abs(Date.now() / 1000 - t) > 300) return false; + const want = Buffer.from(sign(String(email || '').toLowerCase() + '.' + t), 'hex'), got = Buffer.from(String(sig || ''), 'hex'); + return want.length === got.length && crypto.timingSafeEqual(want, got); +} + +module.exports = { verify, verifyServer, redirectFor, sign, SECRET, FORUM_URL }; diff --git a/qa/forumsso.mjs b/qa/forumsso.mjs index aba3060..8db4dcc 100644 --- a/qa/forumsso.mjs +++ b/qa/forumsso.mjs @@ -66,6 +66,12 @@ try { const nck = (nv.headers.getSetCookie ? nv.headers.getSetCookie() : []).map(c => c.split(';')[0]).join('; '); const nme = await api('/api/me', null, { Cookie: nck + '; iap.sponsor=forumfan' }); ok(nme.j && (nme.j.sponsorName === '@forumfan' || String(nme.j.sponsorRef || '').toLowerCase() === 'forumfan' || JSON.stringify(nme.j).includes('forumfan')), 'a new sign-up through the forum invite lands under the inviter', JSON.stringify(nme.j && { sponsorName: nme.j.sponsorName, sponsorRef: nme.j.sponsorRef })); + // reward-service lookup (2026-11-10) + const ts = Math.floor(Date.now() / 1000), msig = sig('fs-a@example.com.' + ts); + let lk = await fetch(B + '/api/forum/member?email=fs-a%40example.com', { headers: { 'x-forum-ts': String(ts), 'x-forum-sig': msig } }); let lj = await lk.json(); + ok(lk.status === 200 && lj.found === true && lj.username === 'forumfan' && lj.activated === false, 'member lookup: signed request answers (free member = not activated)', JSON.stringify(lj)); + lk = await fetch(B + '/api/forum/member?email=fs-a%40example.com', { headers: { 'x-forum-ts': String(ts), 'x-forum-sig': '0'.repeat(64) } }); ok(lk.status === 401, 'member lookup: bad signature refused'); + const old = ts - 900; lk = await fetch(B + '/api/forum/member?email=fs-a%40example.com', { headers: { 'x-forum-ts': String(old), 'x-forum-sig': sig('fs-a@example.com.' + old) } }); ok(lk.status === 401, 'member lookup: stale signature refused'); } catch (e) { console.log('FAIL exception', e && e.stack || e); fails++; } finally { try { srv.kill(); } catch (e) {} try { fs.rmSync(DATA, { recursive: true, force: true }); } catch (e) {} } if (fails) console.log(log.split('\n').filter(l => /forum|error/i.test(l)).slice(-15).join('\n')); diff --git a/server.js b/server.js index c4059b7..f742642 100644 --- a/server.js +++ b/server.js @@ -3952,6 +3952,15 @@ const server = http.createServer(async (req, res) => { } res.writeHead(302, baseHeaders(Object.assign({ Location: forumsso.FORUM_URL() + path, 'Cache-Control': 'no-store' }, set.length ? { 'Set-Cookie': set } : {}))); return res.end(); } + // Earners Corner introduction reward (Marty 2026-11-10: 0.1 POL, ongoing, linked wallet + payouts switched on): the forum's reward + // service looks a member up here. Activated = an on-chain member id (the $20 start with payouts on); the address is the payout wallet. + if (p === '/api/forum/member' && req.method === 'GET') { + const email = String(u.searchParams.get('email') || '').toLowerCase(); + if (!forumsso.verifyServer(email, req.headers['x-forum-ts'], req.headers['x-forum-sig'])) return json(res, 401, { error: 'auth' }); + const a = await accounts.byEmail(email); + if (!a) return json(res, 200, { found: false }); + return json(res, 200, { found: true, username: a.username || null, activated: Number(a.memberId) > 0, address: a.address || null, suspended: !!fraud.isSuspended(email) }); + } if (p === '/forum/invite' && req.method === 'GET') { const s = await auth.fromRequest(req); if (!s || !s.email) { res.writeHead(302, { Location: forumsso.FORUM_URL() + '/session/sso', 'Cache-Control': 'no-store' }); return res.end(); }