Skip to content

Class BSV::Auth::SimplifiedFetchTransport

Inherits: Object Includes: BSV::Auth::Transport

BRC-104 client-side HTTP transport implementing {BSV::Auth::Transport}.

Maps BRC-103 auth message types to HTTP requests:

  • Non-general messages (initialRequest, initialResponse, certificateRequest, certificateResponse) are POSTed as JSON to +#{base_url}/.well-known/auth+. Keys are converted to camelCase on the wire and back to snake_case symbols on receipt.

  • General messages have their binary payload deserialised via {AuthPayload.deserialize_request}, sent as a real HTTP request with x-bsv-auth-* headers attached, and the HTTP response serialised back to a binary payload via {AuthPayload.serialize_response}.

@example

transport = BSV::Auth::SimplifiedFetchTransport.new('https://api.example.com')
transport.on_data { |msg| peer.handle_incoming_message(msg) }
transport.send(message)

Public Instance Methods

initialize(base_url, http_client: = nil)

  • @param base_url [String] scheme + host (+ optional port), e.g. "https://api.example.com"
  • @param http_client [Class, nil] injectable HTTP client; defaults to Net::HTTP
  • @return [SimplifiedFetchTransport] a new instance of SimplifiedFetchTransport

on_data(&block)

Registers the callback invoked when a response arrives.

Must be called before {#send}. - @yieldparam message [Hash] incoming auth message with symbol keys

send(message)

Sends an auth message to the remote peer. - @param message [Hash] auth message produced by {BSV::Auth::Peer} - @raise [RuntimeError] if no callback has been registered via {#on_data}