Skip to content

Class BSV::Transaction::P2PKH

Inherits: BSV::Transaction::UnlockingScriptTemplate

P2PKH unlocking script template for deferred transaction signing.

Holds a private key and sighash type, generating the unlocking script (signature + public key) when {#sign} is called with the full transaction.

@example Attach a P2PKH template to an input

input.unlocking_script_template = BSV::Transaction::P2PKH.new(private_key)
tx.sign_all  # generates the unlocking script

Constants

ESTIMATED_SCRIPT_LENGTH

Estimated unlocking script length: 1 + ~72 (DER sig + hashtype) + 1 + 33 (compressed pubkey).

Public Instance Methods

estimated_length(_tx, _input_index)

  • @return [Integer] estimated script length for fee calculation

initialize(private_key, sighash_type: = Sighash::ALL_FORK_ID)

  • @param private_key [Primitives::PrivateKey] the signing key
  • @param sighash_type [Integer] sighash flags (default: ALL_FORK_ID)
  • @return [P2PKH] a new instance of P2PKH

sign(tx, input_index)

Generate the P2PKH unlocking script for the given input. - @param tx [Transaction] the transaction being signed - @param input_index [Integer] the input index to sign - @return [Script::Script] the unlocking script (signature + pubkey)