signInput :: Tx -> Int -> SigInput -> PrvKey -> Either String Tx
signInput tx i (SigInput so _ sh rdmM) key = do
    let sig = TxSignature (signMsg msg key) sh
    si <- buildInput tx i so rdmM sig $ derivePubKey key
    return tx{ txIn = updateIndex i (txIn tx) (f si) }
  where
    f si x = x{ scriptInput = encodeInputBS si }
    msg = txSigHash tx (encodeOutput $ fromMaybe so rdmM) i sh

-- Order the SigInput with respect to the transaction inputs. This allow the
-- users to provide the SigInput in any order. Users can also provide only a
-- partial set of SigInputs.
signInput :: Tx -> Int -> SigInput -> PrvKey -> Either String Tx
signInput tx i (SigInput so _ sh rdmM) key = do
    let sig = TxSignature (signMsg msg key) sh
    si <- buildInput tx i so rdmM sig $ derivePubKey key
    return tx{ txIn = updateIndex i (txIn tx) (f si) }
  where
    f si x = x{ scriptInput = encodeInputBS si }
    msg = txSigHash tx (encodeOutput $ fromMaybe so rdmM) i sh

-- Order the SigInput with respect to the transaction inputs. This allow the
-- users to provide the SigInput in any order. Users can also provide only a
-- partial set of SigInputs.
signInput tx i (SigInput so _ sh rdmM) key = do
    let sig = TxSignature (signMsg msg key) sh
    si <- buildInput tx i so rdmM sig $ derivePubKey key
    return tx{ txIn = updateIndex i (txIn tx) (f si) }
  where
    f si x = x{ scriptInput = encodeInputBS si }
    msg = txSigHash tx (encodeOutput $ fromMaybe so rdmM) i sh

-- Order the SigInput with respect to the transaction inputs. This allow the
-- users to provide the SigInput in any order. Users can also provide only a
-- partial set of SigInputs.