Class: BSV::MCP::Tools::GenerateKey

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/bsv/mcp/tools/generate_key.rb

Overview

Generates a new random BSV private key and derives the corresponding public key and address.

Each invocation produces a cryptographically fresh key — the result is never reused or persisted by the server. Store the WIF securely; it cannot be recovered from the address alone.

Class Method Summary collapse

Class Method Details

.call(network: nil, server_context: nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bsv/mcp/tools/generate_key.rb', line 41

def self.call(network: nil, server_context: nil)
  net_sym = Helpers.resolve_network_sym(network, server_context)

  key = BSV::Primitives::PrivateKey.generate
  pub = key.public_key

  result = {
    wif: key.to_wif(network: net_sym),
    public_key_hex: pub.to_hex,
    address: pub.address(network: net_sym),
    network: net_sym.to_s
  }

  ::MCP::Tool::Response.new(
    [::MCP::Content::Text.new(result.to_json)],
    structured_content: result
  )
end