Class: X402::StatusEndpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/x402/status_endpoint.rb

Overview

Read-only HTTP status endpoint for the x402-rack middleware.

Renders a minimal page exposing wallet identity (public key + base P2PKH address) and the gem version. Designed to provide passive observability during development and ops without ever mutating state or making external network calls.

Auth model:

  • Bearer-token only. Every request requires +Authorization: Bearer + — there is no localhost bypass and no network-trust heuristic.
  • If +status_endpoint_token+ is unset, the configuration auto-generates one at +validate!+ time and logs it once at startup so it can be copied into a curl command. Production deployments should set the token explicitly via an environment variable.

Format selection: +?format=json+ or +Accept: application/json+ → JSON; otherwise HTML.

Phase 1 scope: identity public key, identity address, gem version. Balance, UTXOs, ARC reachability and other live signals are deferred to later phases — see issue #108.

Examples:

Enable in configuration

X402.configure do |c|
  c.wallet = my_wallet  # any BRC-100 compatible wallet
  c.enable_status_endpoint
  # c.status_endpoint_token = ENV["X402_STATUS_TOKEN"] # explicit (recommended in prod)
  # c.status_endpoint_path  = "/_x402/status"          # default
end

Constant Summary collapse

ADDRESS_NOTE =
"Identity address — used for BRC-42 derivation. " \
"Not the per-payment receive address. Payments are " \
"settled to per-payment derived addresses."

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ StatusEndpoint

Returns a new instance of StatusEndpoint.



43
44
45
# File 'lib/x402/status_endpoint.rb', line 43

def initialize(config)
  @config = config
end

Instance Method Details

#call(env) ⇒ Array(Integer, Hash, Array)

Returns Rack response triple.

Parameters:

  • env (Hash)

    Rack environment

Returns:

  • (Array(Integer, Hash, Array))

    Rack response triple



49
50
51
52
53
54
55
56
57
58
# File 'lib/x402/status_endpoint.rb', line 49

def call(env)
  return forbidden unless authorised?(env)

  data = build_data
  if json_requested?(env)
    json_response(data)
  else
    html_response(data)
  end
end