# Class BSV::Transaction::P2PKH <a id="class-BSV-Transaction-P2PKH"></a>

**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**
```ruby
input.unlocking_script_template = BSV::Transaction::P2PKH.new(private_key)
tx.sign_all  # generates the unlocking script
```

## Constants
### `ESTIMATED_SCRIPT_LENGTH` <a id="constant-ESTIMATED_SCRIPT_LENGTH"></a> <a id="ESTIMATED_SCRIPT_LENGTH-constant"></a>
Estimated unlocking script length: 1 + ~72 (DER sig + hashtype) + 1 + 33
(compressed pubkey).

## Public Instance Methods
### `estimated_length(_tx, _input_index)` <a id="method-i-estimated_length"></a> <a id="estimated_length-instance_method"></a>
- **@return** [Integer] estimated script length for fee calculation

### `initialize(private_key, sighash_type: = Sighash::ALL_FORK_ID)` <a id="method-i-initialize"></a> <a id="initialize-instance_method"></a>
- **@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)` <a id="method-i-sign"></a> <a id="sign-instance_method"></a>
Generate the P2PKH unlocking script for the given input.
- **@param** `tx` [Transaction::Tx] the transaction being signed
- **@param** `input_index` [Integer] the input index to sign
- **@return** [Script::Script] the unlocking script (signature + pubkey)
