Description
src/auth/challenge.ts already builds SNIP-12 typed data (CHALLENGE_TYPES, buildTypedChallenge) for wallet-signature login, but that pattern is not reused anywhere for individual mutating actions after login. src/routes/billing.ts mutating endpoints currently rely solely on the session bearer token plus an Idempotency-Key. For the highest-value billing mutations, require a fresh SNIP-12 signature over the specific request payload so a stolen/replayed session token alone cannot mutate billing state.
Requirements and context
- Extend the typed-data pattern from
src/auth/challenge.ts with a BillingAction type covering profile/payment-method mutations
- Add a
requireSignedAction middleware verifying the signature against the caller's known wallet public key before the handler runs
- Return a clear, non-sensitive 400 (not 401/403) when the signature is missing or invalid, distinct from session auth failures
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested execution
Fork the repo and create a branch
git checkout -b feature/billing-request-signing
Implement changes
- Update/Write:
src/routes/billing.ts
- Update/Write:
src/auth/challenge.ts
- Add/Update tests:
src/routes/billing.test.ts
- Add documentation:
docs/routes/billing.md
- Include clear code comments and TS types
- Validate security assumptions
Test and commit
- Run tests:
pnpm test
- Cover edge cases
- Include test output and security notes
Example commit message
feat: require SNIP-12 request signing on billing mutations
Guidelines
- Minimum 95 percent test coverage
- Clear documentation
- Timeframe: 96 hours
Description
src/auth/challenge.tsalready builds SNIP-12 typed data (CHALLENGE_TYPES,buildTypedChallenge) for wallet-signature login, but that pattern is not reused anywhere for individual mutating actions after login.src/routes/billing.tsmutating endpoints currently rely solely on the session bearer token plus anIdempotency-Key. For the highest-value billing mutations, require a fresh SNIP-12 signature over the specific request payload so a stolen/replayed session token alone cannot mutate billing state.Requirements and context
src/auth/challenge.tswith aBillingActiontype covering profile/payment-method mutationsrequireSignedActionmiddleware verifying the signature against the caller's known wallet public key before the handler runsSuggested execution
Fork the repo and create a branch
Implement changes
src/routes/billing.tssrc/auth/challenge.tssrc/routes/billing.test.tsdocs/routes/billing.mdTest and commit
pnpm testExample commit message
Guidelines