caelum0x 38b4537a50 fix(turnstile): reject non-address TURNSTILE_PAYEE at startup instead of failing cryptically at first payment
Ran turnstile-server for real against a real local mint-server (not cargo
test) and paid its demo echo tool end-to-end with the Python client. The
README's own quickstart value, TURNSTILE_PAYEE=ait1qprovider, is not valid
bech32 -- every real payment attempt failed with an opaque "mint error
(status 400, code 'bad_address')" instead of ever reaching the real
pay/insufficient-funds boundary. from_env() only checked that TURNSTILE_PAYEE
was present, not that it was a real address, despite this module's own doc
comment promising to refuse malformed values.

Add validate_payee_address() (bech32 decode + "ait" HRP check, same encoding
mint-core uses) so a bad payee now fails fast at startup with a clear message
and a pointer to the two real Mint calls that mint a usable address, instead
of starting a server that issues 402s all day and only ever fails the first
time anyone tries to pay one. Fixed the README quickstart to mint a real
address first and confirmed live: the old placeholder still fails bad_address,
a real minted address now correctly advances to insufficient_funds (the
genuine, owner-gated funding step).

Verified: full apps/turnstile workspace test suite green (cargo test
--workspace --locked), new regression tests cover both the old placeholder
and a wrong-HRP address, cargo clippy clean on the touched file.
2026-10-24 23:10:14 +03:00

39 lines
1.5 KiB
TOML

[package]
name = "turnstile-core"
version.workspace = true
edition.workspace = true
license.workspace = true
description = "Framework-agnostic AITP-402 paywall engine: config, challenge, nonce replay-guard, server-side verifier over the reused HttpTransport seam, success-only settle, and the admit() guard."
[dependencies]
aitp-client.workspace = true
# `time` is enabled for the durable store's background nonce reaper (spawn_reaper).
tokio = { workspace = true, features = ["time"] }
async-trait.workspace = true
serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
rand.workspace = true
hex = "0.4"
# Validates TURNSTILE_PAYEE as a real `ait1…` Mint receive address at startup
# (same encoding mint-core uses) instead of accepting any opaque string that
# can only fail, cryptically, much later at first capture.
bech32 = "0.11"
# x402 `X-PAYMENT` / `X-PAYMENT-RESPONSE` headers are base64-encoded JSON.
base64 = "0.22"
# Coinbase CDP facilitator auth: per-request JWTs signed with the CDP API key,
# ES256 (PEM EC P-256 key) or EdDSA (base64 Ed25519 key), as the CDP SDKs do.
p256 = { version = "0.13", default-features = false, features = ["ecdsa", "pem", "std"] }
ed25519-dalek = "2"
# Durable Postgres NonceStore, off by default. Enabling `postgres` pulls in sqlx
# (runtime query API, no DATABASE_URL needed) and compiles the `pg` module.
sqlx = { workspace = true, optional = true }
[features]
default = []
postgres = ["dep:sqlx"]
[dev-dependencies]
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "time"] }