MPP.X402.Plug (mpp v0.19.0)

Copy Markdown View Source

Server-side x402 v2 exact settlement through a configurable facilitator.

Verifies PAYMENT-SIGNATURE, binds route and body, claims the authorization nonce, settles, and attaches PAYMENT-RESPONSE. Coexists with native Payment-auth on the same MPP.Plug endpoint.

The facilitator always receives the server-configured requirements that the echoed accepted matched (including extra), never the client's copy — refs/mppx/src/x402/server/EvmCharge.ts facilitatorPayment. A route-bound credential (extensions.mppx.info.nonce) must echo the advertised :extensions (schema and info, minus the client nonce salt) before its nonce is recomputed — mppx containsExtensions.

Summary

Functions

Build x402 plug options from MPP.Plug :x402 config.

Settle a PAYMENT-SIGNATURE when present; otherwise continue the native handshake.

Attach PAYMENT-REQUIRED to a 402 response when x402 is configured.

Types

t()

@type t() :: %MPP.X402.Plug{
  accepts: [map()],
  digest: String.t() | nil,
  extensions: map() | nil,
  facilitator: MPP.X402.Facilitator.t(),
  resource: map() | nil,
  route_binding: :resource | :required
}

Functions

configure(opts)

@spec configure(nil | false | keyword() | map()) :: t() | nil

Build x402 plug options from MPP.Plug :x402 config.

maybe_settle(conn, x402, store)

@spec maybe_settle(Plug.Conn.t(), t() | nil, term()) ::
  :continue | {:ok, Plug.Conn.t()} | {:error, MPP.Errors.t()}

Settle a PAYMENT-SIGNATURE when present; otherwise continue the native handshake.

put_challenge(conn, x402)

@spec put_challenge(Plug.Conn.t(), t() | nil) :: Plug.Conn.t()

Attach PAYMENT-REQUIRED to a 402 response when x402 is configured.