X402.Extensions.SIWX.ETSStorage (X402 v0.3.3)

Copy Markdown View Source

ETS-backed SIWX storage with TTL-based expiration.

Records are stored in an ETS table keyed by {address, resource} and cleaned up periodically by the GenServer process.

Reads are serialized through the GenServer to ensure consistency with concurrent deletes (e.g., session revocation).

Summary

Types

Storage server identifier accepted by GenServer.call/3.

Functions

Returns a child specification for X402.Extensions.SIWX.ETSStorage.

Deletes an access record from the default storage server.

Deletes an access record from a specific storage server.

Fetches an access record for a wallet/resource pair from the default server.

Fetches an access record from a specific storage server.

Stores an access record in the default storage server.

Stores an access record in a specific storage server.

Starts an ETS-backed SIWX storage process.

Types

server()

@type server() :: GenServer.server()

Storage server identifier accepted by GenServer.call/3.

state()

@type state() :: %{
  table: atom(),
  cleanup_interval_ms: pos_integer(),
  max_size: pos_integer()
}

Functions

child_spec(init_arg)

(since 0.3.0)
@spec child_spec(keyword()) :: Supervisor.child_spec()

Returns a child specification for X402.Extensions.SIWX.ETSStorage.

delete(address, resource)

(since 0.3.0)
@spec delete(String.t(), String.t()) :: :ok

Deletes an access record from the default storage server.

delete(server, address, resource)

(since 0.3.0)
@spec delete(server(), String.t(), String.t()) :: :ok

Deletes an access record from a specific storage server.

get(address, resource)

(since 0.3.0)
@spec get(String.t(), String.t()) ::
  {:ok, X402.Extensions.SIWX.Storage.access_record()} | {:error, :not_found}

Fetches an access record for a wallet/resource pair from the default server.

Reads go directly to ETS for better concurrency. Expired records return {:error, :not_found}.

get(server, address, resource)

(since 0.3.0)
@spec get(server(), String.t(), String.t()) ::
  {:ok, X402.Extensions.SIWX.Storage.access_record()} | {:error, :not_found}

Fetches an access record from a specific storage server.

Routes through the GenServer to ensure reads are serialised with concurrent deletes (e.g., session revocation). A direct ETS read on a :protected table sees the table state at read-time, which may be before a queued-but-not-yet-processed delete is applied — meaning a revoked session can appear valid until the next cleanup sweep.

put(address, resource, payment_proof, ttl_ms)

(since 0.3.0)
@spec put(String.t(), String.t(), term(), non_neg_integer()) :: :ok | {:error, term()}

Stores an access record in the default storage server.

put(server, address, resource, payment_proof, ttl_ms)

(since 0.3.0)
@spec put(server(), String.t(), String.t(), term(), non_neg_integer()) ::
  :ok | {:error, term()}

Stores an access record in a specific storage server.

start_link(opts)

(since 0.3.0)
@spec start_link(keyword()) ::
  GenServer.on_start() | {:error, NimbleOptions.ValidationError.t()}

Starts an ETS-backed SIWX storage process.

Options

  • :name (term/0) - Registered name of the ETS storage process. The default value is X402.Extensions.SIWX.ETSStorage.

  • :table (atom/0) - Named ETS table used to store SIWX access records. The default value is :x402_siwx_storage.

  • :cleanup_interval_ms (pos_integer/0) - Interval in milliseconds between cleanup sweeps. The default value is 60000.

  • :max_size (pos_integer/0) - Maximum number of {address, resource} entries to keep in the ETS table. When reached, new put/4 calls return {:error, :storage_full} until the next cleanup sweep evicts expired records. Prevents unbounded memory growth under spam attacks. The default value is 100000.