Raxol.Payments.SpendingPolicy (Raxol Payments v0.2.0)

Copy Markdown View Source

Spending limits for agent payment operations.

Defines per-request, per-session (sliding window), and lifetime caps. Used by the Ledger to enforce budget constraints before signing payments.

Example

policy = %SpendingPolicy{
  per_request_max: Decimal.new("1.00"),
  session_max: Decimal.new("10.00"),
  session_window_ms: 3_600_000,
  lifetime_max: Decimal.new("100.00"),
  currency: "USDC",
  approved_domains: ["api.example.com"],
  require_confirmation_above: Decimal.new("5.00")
}

Summary

Functions

Create a policy with sensible defaults for development.

Check if a domain is approved under this policy.

Check if a payment amount requires user confirmation.

Create an unrestricted policy (for testing only).

Types

t()

@type t() :: %Raxol.Payments.SpendingPolicy{
  approved_domains: [String.t()] | nil,
  currency: String.t(),
  lifetime_max: Decimal.t(),
  per_request_max: Decimal.t(),
  require_confirmation_above: Decimal.t() | nil,
  session_max: Decimal.t(),
  session_window_ms: pos_integer()
}

Functions

dev()

@spec dev() :: t()

Create a policy with sensible defaults for development.

domain_approved?(arg1, domain)

@spec domain_approved?(t(), String.t()) :: boolean()

Check if a domain is approved under this policy.

Returns true if approved_domains is nil (all domains allowed) or if the domain matches an entry in the list. Matching is case-insensitive and respects domain boundaries -- evil-example.com does not match example.com, but api.example.com does.

Empty strings in the approved list are ignored. An empty domain string never matches.

requires_confirmation?(spending_policy, amount)

@spec requires_confirmation?(t(), Decimal.t()) :: boolean()

Check if a payment amount requires user confirmation.

unrestricted()

@spec unrestricted() :: t()

Create an unrestricted policy (for testing only).