feat(registration): add gate mode (all|any) for alternative registration methods

The invite + payment gates were strictly conjunctive: a new wallet had to satisfy
EVERY enabled gate. Add a REGISTRATION_GATE_MODE knob so an operator can offer the
enabled gates as ALTERNATIVES instead (e.g. "an invite code OR pay to register").
PoW stays orthogonal and always applies on top, regardless of mode.

- config: GateMode { All (default) | Any } on RegistrationConfig, from
  REGISTRATION_GATE_MODE (default "all", back-compatible).
- capabilities: advertise registration_mode ("all"|"any") so the wallet can route
  onboarding (multiple gates + "any" => "pick a method"; "all" => satisfy each).
- enforcement: enforce_method_gates composes invite+payment per mode. Extracted a
  pure plan_gates() decision so the fund-critical dispatch is unit-tested. In
  "any" with both gates on, the client presents exactly ONE credential and only
  that gate runs (and only it consumes its single-use token); presenting BOTH is
  rejected so a one-of choice can never burn two tokens (an invite AND a paid
  invoice). Single-gate configs behave identically in both modes.

6 KATs on plan_gates (open / conjunction / single-gate / dispatch / reject-both /
require-one). openapi.json regenerated. 211 lib tests pass.
This commit is contained in:
jwinterm
2026-07-04 22:34:58 -04:00
parent ef6d280412
commit 6f0fca532d
5 changed files with 227 additions and 3 deletions
+6
View File
@@ -143,6 +143,11 @@ pub struct RegistrationCapability {
/// so the wallet can show "registration costs X" before minting an invoice.
pub payment_amount: Option<String>,
pub payment_currency: Option<String>,
/// How the enabled gates combine: `"all"` (satisfy every gate; the default)
/// or `"any"` (the gates are alternatives; satisfy one). PoW is orthogonal
/// and applies regardless. The wallet routes onboarding on this: multiple
/// gates + `"any"` => "pick a method" buttons; `"all"` => satisfy each.
pub registration_mode: String,
}
#[derive(Debug, Serialize, utoipa::ToSchema)]
@@ -253,6 +258,7 @@ pub fn effective_capabilities(config: &Config) -> CapabilitiesResponse {
.payment
.require_payment
.then(|| config.registration.payment.currency.clone()),
registration_mode: config.registration.gate_mode.as_str().to_string(),
},
messaging: relay_advertised(config).then(|| {
let r = &config.messaging.relay;