X402.Scheme.ExactEVM (X402 v0.6.0)

Copy Markdown View Source

Built-in X402.Scheme for exact payments on EVM (eip155:*) networks.

Implements both roles:

  • Client — signs an EIP-3009 TransferWithAuthorization through X402.EIP3009, producing the %{"signature" => ..., "authorization" => ...} scheme payload. An entry is signable when its EIP-712 domain can be derived from the requirements (extra.name / extra.version present, default eip3009 transfer method).
  • Server — runs the local pre-checks on the EIP-3009 authorization object before the facilitator round-trip: to must equal the requirements' payTo, value must equal the advertised amount, and the validAfter/validBefore window must cover now plus a settlement buffer (X402.Scheme.EVM.time_buffer_seconds/0). Payloads without a payload.authorization map are skipped.

Envelope validation of the PAYMENT-SIGNATURE payload is handled by X402.PaymentSignature; this scheme adds no extra structural checks (X402.Scheme.validate_payload/3 returns :ok).

Summary

Functions

Returns ["eip155:*"] — every EVM network.

Returns "exact".

Signs the EIP-3009 scheme payload via X402.EIP3009.sign/3.

Whether the EIP-712 domain can be derived from the requirements.

Always :ok — envelope validation covers the exact payload shape.

Functions

networks()

(since 0.6.0)
@spec networks() :: [String.t()]

Returns ["eip155:*"] — every EVM network.

Examples

iex> X402.Scheme.ExactEVM.networks()
["eip155:*"]

precheck(payload, requirements, opts)

(since 0.6.0)
@spec precheck(map(), map(), keyword()) ::
  :ok | {:error, {:precheck_failed, X402.Scheme.EVM.precheck_failure()}}

Runs X402.Scheme.EVM.authorization_precheck/3 with exact-amount equality enforced.

scheme()

(since 0.6.0)
@spec scheme() :: String.t()

Returns "exact".

Examples

iex> X402.Scheme.ExactEVM.scheme()
"exact"

sign(requirements, signer, opts)

(since 0.6.0)
@spec sign(map(), X402.Signer.t(), keyword()) :: {:ok, map()} | {:error, term()}

Signs the EIP-3009 scheme payload via X402.EIP3009.sign/3.

Honors the client's :valid_after_buffer option; other options are ignored.

signable?(requirements)

(since 0.6.0)
@spec signable?(map()) :: boolean()

Whether the EIP-712 domain can be derived from the requirements.

Examples

iex> X402.Scheme.ExactEVM.signable?(%{
...>   "network" => "eip155:84532",
...>   "asset" => "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
...>   "extra" => %{"name" => "USDC", "version" => "2"}
...> })
true

iex> X402.Scheme.ExactEVM.signable?(%{"extra" => %{}})
false

validate_payload(payload, requirements, opts)

(since 0.6.0)
@spec validate_payload(map(), map(), keyword()) :: :ok

Always :ok — envelope validation covers the exact payload shape.

Examples

iex> X402.Scheme.ExactEVM.validate_payload(%{}, %{}, [])
:ok