feat: move creator pubkey to env, fix mobile TTS + signer, button loaders

Security:
- Move CREATOR_PUBKEY from hardcoded constant to BOTFIGHTS_CREATOR_PUBKEYS
  env var. Shared isCreatorPubkey() in constants.ts used by auth, admin,
  tournaments. Frontend checks authorization via API, not client-side.

Mobile fixes:
- Nostr signer: poll for window.nostr up to 3s (Amber injects late).
- TTS: auto-unlock AudioContext on first user interaction via
  installAutoUnlock() on fight page mount.

UX:
- Add loading spinners to "I BUILD BOTS" and "I FIGHT MYSELF" buttons.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-09 15:31:58 +00:00
co-authored by Claude Opus 4.6
parent dd3cbdae7f
commit 6dc50f5d5d
7 changed files with 55 additions and 40 deletions
+8 -10
View File
@@ -7,12 +7,10 @@ import { isAllowedWebhookUrl } from '../engine/orchestrator.js'
import { validateCustomization } from '../engine/customization.js'
import { testWebhook } from '../engine/webhook-test.js'
import { rateLimit } from '../middleware/rate-limit.js'
import { isCreatorPubkey } from '../lib/constants.js'
export const authRouter = new Hono()
// The Creator — game founder pubkey (auto-assigns the_creator archetype)
const CREATOR_PUBKEY = "da5e0c1b646bdb13c2300f805b0ca3e5afe5b052c594ce78bac8978d21c3fa39"
// Check name availability
authRouter.get("/check-name/:name", async (c) => {
const name = c.req.param("name")?.trim().toLowerCase()
@@ -56,7 +54,7 @@ authRouter.post('/login', rateLimit(60_000, 30), async (c) => {
if (rows.length === 0) {
// Auto-create human fighter for the Creator if not registered
if (pubkey === CREATOR_PUBKEY) {
if (isCreatorPubkey(pubkey)) {
const id = nanoid(12)
const secret = randomBytes(32).toString('hex')
await db.insert(schema.bots).values({
@@ -101,7 +99,7 @@ authRouter.post('/login', rateLimit(60_000, 30), async (c) => {
const isHuman = bot.webhookUrl === 'http://human.local/'
// Auto-upgrade: if creator logs in, ensure archetype is always the_creator
if (pubkey === CREATOR_PUBKEY && bot.archetype !== "the_creator") {
if (isCreatorPubkey(pubkey) && bot.archetype !== "the_creator") {
await db.update(schema.bots).set({ archetype: "the_creator" }).where(eq(schema.bots.id, bot.id))
bot.archetype = "the_creator"
}
@@ -203,7 +201,7 @@ authRouter.post('/register', rateLimit(600_000, 10), async (c) => {
const secret = randomBytes(32).toString('hex')
const baseArchetype = custResult.data.archetype || archetype || 'standard'
const effectiveArchetype = pubkey === CREATOR_PUBKEY ? 'the_creator' : baseArchetype
const effectiveArchetype = isCreatorPubkey(pubkey) ? 'the_creator' : baseArchetype
const custJson = Object.keys(custResult.data).length > 0 ? JSON.stringify(custResult.data) : null
await db.insert(schema.bots).values({
@@ -270,7 +268,7 @@ authRouter.post('/register-human', rateLimit(600_000, 10), async (c) => {
const id = nanoid(12)
const secret = randomBytes(32).toString('hex')
const humanArchetype = pubkey === CREATOR_PUBKEY ? 'the_creator' : 'human'
const humanArchetype = isCreatorPubkey(pubkey) ? 'the_creator' : 'human'
await db.insert(schema.bots).values({
id,
@@ -350,7 +348,7 @@ authRouter.post('/update', rateLimit(60_000, 10), async (c) => {
const merged = { ...existing, ...custResult.data }
updates.customization = JSON.stringify(merged)
// Update archetype if set in customization (but never override the_creator)
if (custResult.data.archetype && pubkey !== CREATOR_PUBKEY) {
if (custResult.data.archetype && !isCreatorPubkey(pubkey)) {
updates.archetype = custResult.data.archetype
}
}
@@ -416,7 +414,7 @@ authRouter.post('/nostr/session', rateLimit(60_000, 30), async (c) => {
const isHuman = bot.webhookUrl === 'http://human.local/'
// Auto-upgrade creator archetype
if (pubkey === CREATOR_PUBKEY && bot.archetype !== "the_creator") {
if (isCreatorPubkey(pubkey) && bot.archetype !== "the_creator") {
await db.update(schema.bots).set({ archetype: "the_creator" }).where(eq(schema.bots.id, bot.id))
bot.archetype = "the_creator"
}
@@ -440,7 +438,7 @@ authRouter.post('/nostr/session', rateLimit(60_000, 30), async (c) => {
satsWagered: bot.satsWagered ?? 0,
hasWallet: false,
}
} else if (pubkey === CREATOR_PUBKEY) {
} else if (isCreatorPubkey(pubkey)) {
// Auto-create creator
const id = nanoid(12)
const secret = randomBytes(32).toString('hex')