// POST /api/activate {"owner", "blank", "tier"}: the co-signing service. Builds the one // transaction that burns the blank and exactly the published $GLITCH for that tier and mints the // card, signs it with the card's key and the co-signer key, and returns it for the wallet to sign. // It only ever signs transactions it built itself (server/card.ts explains why that's the check). import { buildActivate } from '../../server/card.ts' import { ConfigError, configFailure, contextFor, cosignerFor, gate, type CardEnv } from '../../server/env.ts' import { failure, json, readBody } from '../../server/http.ts' export const onRequestPost: PagesFunction = async ({ request, env }) => { const body = await readBody(request, ['owner', 'blank', 'tier']) if (!body) return json({ error: 'Expected {"owner", "blank", "tier"}.', code: 'bad-request' }, 400) const refused = await gate(request, env, 'activate', 20) if (refused) return refused try { const ctx = await contextFor(env) const built = await buildActivate(ctx, await cosignerFor(env, ctx), { owner: body.owner, blank: body.blank, tier: body.tier }) console.log('activation built', String(body.tier), String(body.owner)) return json(built) } catch (err) { return err instanceof ConfigError ? configFailure(err) : failure(err, 'activate') } }