Class: Runar::SDK::LocalSigner
- Defined in:
- lib/runar/sdk/local_signer.rb
Overview
Holds a secp256k1 private key in memory and delegates real ECDSA signing to the bsv-sdk gem.
Suitable for CLI tooling and automated tests where a hot key is acceptable. For production wallets consider ExternalSigner with a hardware-wallet callback instead.
Instance Method Summary collapse
-
#get_address ⇒ String
Return the BSV mainnet P2PKH address for this key.
-
#get_public_key ⇒ String
Return the hex-encoded compressed public key (66 chars).
-
#initialize(key_hex) ⇒ LocalSigner
constructor
Create a LocalSigner from a hex-encoded private key.
-
#sign(tx_hex, input_index, subscript, satoshis, sighash_type = nil) ⇒ String
Sign a transaction input using BIP-143 sighash and real ECDSA.
Constructor Details
#initialize(key_hex) ⇒ LocalSigner
Create a LocalSigner from a hex-encoded private key.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/runar/sdk/local_signer.rb', line 42 def initialize(key_hex) super() unless BSV_SDK_AVAILABLE raise 'LocalSigner requires the bsv-sdk gem. ' \ "Add it to your Gemfile: gem 'bsv-sdk'" end @private_key = BSV::Primitives::PrivateKey.from_hex(key_hex) @public_key = @private_key.public_key end |
Instance Method Details
#get_address ⇒ String
Return the BSV mainnet P2PKH address for this key.
64 65 66 |
# File 'lib/runar/sdk/local_signer.rb', line 64 def get_address @public_key.address end |
#get_public_key ⇒ String
Return the hex-encoded compressed public key (66 chars).
rubocop:disable Naming/AccessorMethodName
57 58 59 |
# File 'lib/runar/sdk/local_signer.rb', line 57 def get_public_key @public_key.compressed.unpack1('H*') end |
#sign(tx_hex, input_index, subscript, satoshis, sighash_type = nil) ⇒ String
Sign a transaction input using BIP-143 sighash and real ECDSA.
Returns the DER-encoded signature with the sighash byte appended, hex-encoded.
80 81 82 83 |
# File 'lib/runar/sdk/local_signer.rb', line 80 def sign(tx_hex, input_index, subscript, satoshis, sighash_type = nil) flag = sighash_type || BSV::Transaction::Sighash::ALL_FORK_ID build_signature(tx_hex, input_index, subscript, satoshis, flag) end |