ClutterHunt: SEEK_SSO_SECRET tokens, in-game sign-in (game seek), one-tap hand-off, hint visits via the refuel flow, Games card + strip entry
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1283,6 +1283,26 @@ function gkPage(res, code, title, inner) {
|
||||
}
|
||||
function gkFormBody(req) { return new Promise((ok, no) => { let d = ''; req.on('data', ch => { d += ch; if (d.length > 20000) req.destroy(); }); req.on('end', () => ok(new URLSearchParams(d))); req.on('error', no); }); }
|
||||
const gkCookie = (k, v, maxAge) => k + '=' + encodeURIComponent(v) + '; Path=/; SameSite=Lax; Max-Age=' + maxAge + (IS_PROD ? '; Secure' : '');
|
||||
// -- ClutterHunt (2026-10-03): seasonal hidden-object rooms at clutterhunt.com; its own secret SEEK_SSO_SECRET (also on the game)
|
||||
const SEEK_SECRET = () => String(process.env.SEEK_SSO_SECRET || '').trim();
|
||||
const SEEK_URL = () => String(process.env.SEEK_URL || 'https://clutterhunt.com').replace(/\/+$/, '');
|
||||
const SEEK_ALT = () => String(process.env.SEEK_ALT_URLS || 'https://www.clutterhunt.com,https://clutterhunt.saasy.top').split(',').map(x => x.trim().replace(/\/+$/, '')).filter(Boolean);
|
||||
const seekSign = p => drB64u(crypto.createHmac('sha256', SEEK_SECRET()).update(p).digest());
|
||||
function seekMint(claims, ttlMs) { const payload = JSON.stringify(Object.assign({ iat: Date.now(), exp: Date.now() + (ttlMs || 300000), nonce: crypto.randomBytes(12).toString('hex') }, claims)); return drB64u(payload) + '.' + seekSign(payload); }
|
||||
function seekOpen(token) {
|
||||
if (SEEK_SECRET().length < 32) return { error: 'ClutterHunt is not connected yet.' };
|
||||
const [p, sig] = String(token || '').split('.'); if (!p || !sig) return { error: 'That link is not valid.' };
|
||||
let payload; try { payload = Buffer.from(String(p).replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf8'); } catch (e) { return { error: 'That link is not valid.' }; }
|
||||
const want = seekSign(payload); if (want.length !== sig.length || !crypto.timingSafeEqual(Buffer.from(want), Buffer.from(sig))) return { error: 'That link is not valid.' };
|
||||
let c; try { c = JSON.parse(payload); } catch (e) { return { error: 'That link is not valid.' }; }
|
||||
if (!c.exp || Date.now() > c.exp) return { error: 'That hint link has expired. Go back to ClutterHunt and tap Hint again.' };
|
||||
return { ok: true, claims: c };
|
||||
}
|
||||
const seekIsGameUrl = u => [SEEK_URL()].concat(SEEK_ALT()).some(o => String(u || '').startsWith(o + '/'));
|
||||
async function seekCallback(cbUrl, receipt) {
|
||||
if (!seekIsGameUrl(cbUrl)) return false;
|
||||
try { const r = await fetch(cbUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ t: receipt }), signal: AbortSignal.timeout(8000) }); return r.ok; } catch (e) { console.warn('clutterhunt callback', e.message); return false; }
|
||||
}
|
||||
async function gkCallback(cbUrl, receipt) {
|
||||
if (!String(cbUrl || '').startsWith(GK_URL() + '/')) return false;
|
||||
try { const r = await fetch(cbUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ t: receipt }), signal: AbortSignal.timeout(8000) }); return r.ok; } catch (e) { console.warn('gemkingdom callback', e.message); return false; }
|
||||
@@ -1378,6 +1398,8 @@ function GAMES() {
|
||||
art: GK_URL() + '/fantasy/og-gemkingdom.jpg?v=20261002', play: '/api/my/gemkingdom', cta: 'Play', pays: 'POL for first clears; Crowns from ad credits' },
|
||||
{ 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: 'clutterhunt', name: 'ClutterHunt', tag: 'Hidden objects', blurb: 'Search cozy, cluttered rooms for hidden objects. New rooms every season, starting with the Haunted Manor.',
|
||||
art: SEEK_URL() + '/og-clutterhunt.jpg', play: '/api/my/clutterhunt', pays: 'Stars now, rewards coming' },
|
||||
];
|
||||
}
|
||||
// -- cross-promo strip (2026-10-03): one short line per game and where a signed-out player lands (the game's own page)
|
||||
@@ -1386,6 +1408,7 @@ const STRIP = () => ({
|
||||
driprunner: { line: 'Hop, dodge the bots, clear chapters. Every first clear drips POL.', open: DR_URL() + '/play', host: DR_URL().replace(/^https?:\/\//, '') },
|
||||
gemkingdom: { line: 'Match gems, beat the bosses, rebuild your kingdom. First clears pay POL.', open: GK_URL() + '/play', host: GK_URL().replace(/^https?:\/\//, '') },
|
||||
polhunter: { line: 'Find hidden codes on sites across the network. Every find drips POL.', open: 'https://polhunter.com/', host: 'polhunter.com' },
|
||||
clutterhunt: { line: 'Search cozy, cluttered rooms for hidden objects. New rooms every season.', open: SEEK_URL() + '/', host: SEEK_URL().replace(/^https?:\/\//, '') },
|
||||
});
|
||||
// live for the strip: in gamesLive, and a seasonal game until its season ends (Marty 2026-10-03: Spooky Doors may show before
|
||||
// its formal announcement; "if someone manages to see it and play it, that's fine")
|
||||
@@ -1438,6 +1461,8 @@ const GAME_AUTH = {
|
||||
driprunner: { name: 'Drip Runner', origins: () => [DR_URL()], host: () => DR_URL().replace(/^https?:\/\//, ''),
|
||||
mint: (a, memberId) => drMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), wallet: a.address || null, username: a.username || null,
|
||||
sponsorRef: a.sponsorRef || null, joinedRef: a.joinedRef || null, joinedAt: a.created || null }) },
|
||||
seek: { name: 'ClutterHunt', origins: () => [SEEK_URL()].concat(SEEK_ALT()), host: () => SEEK_URL().replace(/^https?:\/\//, ''),
|
||||
mint: (a, memberId) => seekMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null }) },
|
||||
gemkingdom: { name: 'Gem Kingdom', origins: () => [GK_URL(), 'https://gemkingdom.saasy.top'], host: () => GK_URL().replace(/^https?:\/\//, ''),
|
||||
mint: (a, memberId) => gkMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null }) },
|
||||
};
|
||||
@@ -1847,7 +1872,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: ({ driprunner: '/api/my/driprunner', passivedrip: '/api/my/passivedrip', gemkingdom: '/api/my/gemkingdom', gkshop: '/gk/shop/resume', spookydoors: '/api/my/spookydoors', sdshop: '/sd/shop/resume' })[parseCookies(req)['iap.return']] || 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: ({ clutterhunt: '/api/my/clutterhunt', driprunner: '/api/my/driprunner', passivedrip: '/api/my/passivedrip', gemkingdom: '/api/my/gemkingdom', gkshop: '/gk/shop/resume', spookydoors: '/api/my/spookydoors', sdshop: '/sd/shop/resume' })[parseCookies(req)['iap.return']] || null }, { 'Set-Cookie': auth.sessionCookie(token) }); // next: Drip Runner sent them here to sign in (2026-09-30)
|
||||
}
|
||||
|
||||
// -- in-game sign-in (2026-10-03): see GAME_AUTH. Mirrors /api/auth/email/start + verify, minus cookies.
|
||||
@@ -2756,6 +2781,15 @@ 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();
|
||||
}
|
||||
// -- ClutterHunt hand-off (2026-10-03): sign the member across; the game verifies with SEEK_SSO_SECRET
|
||||
if (p === '/api/my/clutterhunt' && req.method === 'GET') {
|
||||
const s = await auth.fromRequest(req);
|
||||
if (!s || !s.email) { res.writeHead(302, { Location: '/my', 'Set-Cookie': gkCookie('iap.return', 'clutterhunt', 1800), 'Cache-Control': 'no-store' }); return res.end(); }
|
||||
if (SEEK_SECRET().length < 32) return json(res, 503, { error: 'ClutterHunt is not connected yet.' });
|
||||
const acct = await accounts.byEmail(s.email);
|
||||
const tok = seekMint({ memberId: Number((acct && acct.memberId) || s.memberId || 0), email: String(s.email).toLowerCase(), username: (acct && acct.username) || null, wallet: (acct && acct.address) || null });
|
||||
res.writeHead(302, { Location: SEEK_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': gkCookie('iap.return', '', 0) }); return res.end();
|
||||
}
|
||||
// -- Gem Kingdom hand-off (2026-10-01): sign the member across; the game verifies with GK_SSO_SECRET
|
||||
if (p === '/api/my/gemkingdom' && req.method === 'GET') {
|
||||
const s = await auth.fromRequest(req);
|
||||
@@ -2935,10 +2969,12 @@ const server = http.createServer(async (req, res) => {
|
||||
// Drip Runner refuels and Gem Kingdom continues (2026-10-03) share this flow; the token's secret says which game
|
||||
let r = drOpen(u.searchParams.get('t')), game = 'driprunner';
|
||||
if (r.error) { const g = gkOpen(u.searchParams.get('t')); if (!g.error && g.claims.game === 'gemkingdom') { r = g; game = 'gemkingdom'; } }
|
||||
if (r.error) { const g = seekOpen(u.searchParams.get('t')); if (!g.error && g.claims.game === 'seek') { r = g; game = 'seek'; } }
|
||||
if (r.error) return json(res, 400, { error: r.error });
|
||||
const c = r.claims; if (c.kind !== 'refuel' || !c.nonce || !c.email || !c.ret) return json(res, 400, { error: 'That is not a refuel link.' });
|
||||
if (game === 'gemkingdom' && !String(c.ret).startsWith(GK_URL() + '/')) return json(res, 400, { error: 'That is not a Gem Kingdom link.' });
|
||||
const G = game === 'gemkingdom' ? { game: 'Gem Kingdom', label: 'continue' } : { game: 'Drip Runner', label: 'refuel' };
|
||||
if (game === 'seek' && !seekIsGameUrl(c.ret)) return json(res, 400, { error: 'That is not a ClutterHunt link.' });
|
||||
const G = game === 'gemkingdom' ? { game: 'Gem Kingdom', label: 'continue' } : game === 'seek' ? { game: 'ClutterHunt', label: 'hint' } : { game: 'Drip Runner', label: 'refuel' };
|
||||
for (const [n, v] of refuelTokens) if (v.ts + 30 * 60000 < Date.now()) refuelTokens.delete(n);
|
||||
let t = refuelTokens.get(c.nonce);
|
||||
if (t && t.done) return json(res, 200, Object.assign({ done: true, ret: t.doneRet || t.ret }, G));
|
||||
@@ -2981,12 +3017,18 @@ const server = http.createServer(async (req, res) => {
|
||||
if (!tier) return json(res, 400, { error: 'That video just ran out of budget. Go back and try again.' });
|
||||
await ads.markVideoSeen(t.email, t.id); credits = tier.cost;
|
||||
} else {
|
||||
const r = await ads.completeVisit(t.email, t.id, { reward: false, note: t.game === 'gemkingdom' ? 'Gem Kingdom continue' : 'Drip Runner refuel' });
|
||||
const r = await ads.completeVisit(t.email, t.id, { reward: false, note: t.game === 'gemkingdom' ? 'Gem Kingdom continue' : t.game === 'seek' ? 'ClutterHunt hint' : 'Drip Runner refuel' });
|
||||
if (r.error) return json(res, 400, r);
|
||||
credits = ads.rates().visitCostPerVisit || 3;
|
||||
{ const camp = await ads.campaignById(t.id).catch(() => null); if (camp && camp.house) credits = 0; } // a house ad costs nobody anything: no POL pool income (2026-10-03)
|
||||
}
|
||||
t.done = true;
|
||||
if (t.game === 'seek') { // ClutterHunt hint: signed receipt to the game's callback and on the ret page
|
||||
const receipt = seekMint({ kind: 'seek-hint', nonce, email: t.email, campaignId: t.id, credits }, 15 * 60000);
|
||||
const posted = await seekCallback(t.cb, receipt);
|
||||
t.doneRet = t.ret + (t.ret.includes('?') ? '&' : '?') + 'ok=1&r=' + encodeURIComponent(receipt);
|
||||
return json(res, 200, { ok: true, posted, ret: t.doneRet, game: 'ClutterHunt', label: 'hint' });
|
||||
}
|
||||
if (t.game === 'gemkingdom') { // signed receipt to the game's callback (server copy) and on the ret page (fast path)
|
||||
const receipt = gkMint({ kind: 'gk-continue', nonce, email: t.email, campaignId: t.id, credits }, 15 * 60000);
|
||||
const posted = await gkCallback(t.cb || (GK_URL() + '/api/continue/callback'), receipt);
|
||||
|
||||
Reference in New Issue
Block a user