Class: BSV::Wallet::Substrates::HTTPWalletJSON

Inherits:
Object
  • Object
show all
Includes:
Interface::BRC100
Defined in:
lib/bsv/wallet/substrates/http_wallet_json.rb

Overview

JSON-RPC-style HTTP substrate implementing BRC-100.

Dispatches all 28 BRC-100 methods as JSON POST requests to base_url/v1/wallet/methodNameInCamelCase. Request bodies are deep-converted from snake_case to camelCase via BSV::WireFormat.to_wire; responses are deep-converted back via BSV::WireFormat.from_wire.

This substrate does NOT use the BRC-103 binary frame codec — it speaks plain JSON over HTTP, matching the Go SDK HTTPWalletJSON implementation.

Examples:

client = BSV::Wallet::Substrates::HTTPWalletJSON.new(
  base_url: 'https://wallet.example.com',
  headers: { 'Authorization' => 'Bearer token' }
)
client.get_network  # => { network: 'mainnet' }

Constant Summary collapse

WIRE_METHOD_NAMES =

Maps each BRC-100 Ruby method name to its camelCase wire name. authenticated? maps to isAuthenticated — the BRC-100 wire name uses the is_ prefix convention; the Ruby predicate suffix is dropped for the lookup.

Wire::Calls::CALL_TO_METHOD.each_with_object({}) do |(call_byte, ruby_method), map|
  snake = call_byte == Wire::Calls::IS_AUTHENTICATED ? 'is_authenticated' : ruby_method.to_s
  map[ruby_method] = BSV::WireFormat.snake_to_camel(snake)
end.freeze

Instance Method Summary collapse

Methods included from Interface::BRC100

#abort_action, #acquire_certificate, #authenticated?, #create_action, #create_hmac, #create_signature, #decrypt, #discover_by_attributes, #discover_by_identity_key, #encrypt, #get_header_for_height, #get_height, #get_network, #get_public_key, #get_version, #internalize_action, #list_actions, #list_certificates, #list_outputs, #prove_certificate, #relinquish_certificate, #relinquish_output, #reveal_counterparty_key_linkage, #reveal_specific_key_linkage, #sign_action, #verify_hmac, #verify_signature, #wait_for_authentication

Constructor Details

#initialize(base_url:, http_client: nil, headers: {}) ⇒ HTTPWalletJSON

Returns a new instance of HTTPWalletJSON.

Parameters:

  • base_url (String)

    wallet base URL (e.g. ‘wallet.example’)

  • http_client (#request, nil) (defaults to: nil)

    injectable HTTP client for testing; must respond to #request(uri, net_http_request). Defaults to Net::HTTP.

  • headers (Hash) (defaults to: {})

    additional headers merged into every request



41
42
43
44
45
# File 'lib/bsv/wallet/substrates/http_wallet_json.rb', line 41

def initialize(base_url:, http_client: nil, headers: {})
  @base_url    = base_url.to_s.chomp('/')
  @http_client = http_client
  @headers     = headers.transform_keys(&:to_s)
end