Estimate how long a signature is going to be, given a private key.
    privkey_info is a private key or a multisig/segwit bundle.

    This accounts for both the scriptsig and witness data.  The return
    value is the number of actual *bytes* (not vbytes) that the signature
    will count for in bitcoin (i.e. witness bytes are discounted)
    
    Return the number of bytes on success
    Raise ValueError of the key is not recognized

def tx_estimate_signature_len(privkey_info):
    """
    Estimate how long a signature is going to be, given a private key.
    privkey_info is a private key or a multisig/segwit bundle.

    This accounts for both the scriptsig and witness data.  The return
    value is the number of actual *bytes* (not vbytes) that the signature
    will count for in bitcoin (i.e. witness bytes are discounted)
    
    Return the number of bytes on success
    Raise ValueError of the key is not recognized
    """
    if btc_is_singlesig(privkey_info):
        # one signature produces a scriptsig of ~71 bytes (signature) + pubkey + encoding (4)
        log.debug("Single private key makes a ~73 byte signature")
        pubkey = ecdsa_private_key(privkey_info).public_key().to_hex().decode('hex')
        return 71 + len(pubkey) + 4

    elif btc_is_multisig(privkey_info):
        # one signature produces a scriptsig of redeem_script + (num_pubkeys * ~74 bytes) + encoding (~6)
        m, _ = parse_multisig_redeemscript( privkey_info['redeem_script'] )
        siglengths = 74 * m
        scriptlen = len(privkey_info['redeem_script']) / 2
        siglen = 6 + scriptlen + siglengths

        log.debug("Multisig private key makes ~{} byte signature".format(siglen))
        return siglen

    elif btc_is_singlesig_segwit(privkey_info):
        # bitcoin p2sh-p2wpkh script
        # one signature produces (pubkey + signature (~74 bytes)) + scriptsig len
        privkey = privkey_info['private_keys'][0]
        pubkey_hex = keylib.key_formatting.compress(ecdsa_private_key(privkey).public_key().to_hex())
        redeem_script = btc_make_p2sh_p2wpkh_redeem_script(pubkey_hex)
        witness_script = btc_witness_script_serialize(['00' * 74, pubkey_hex])

        scriptsig_len = 6 + len(redeem_script) / 2
        witness_len = len(witness_script) / 2
        siglen = int(round(float(3 * scriptsig_len + (scriptsig_len + witness_len)) / 4))
        
        log.debug("Segwit p2sh-p2wpkh private key makes ~{} byte signature".format(siglen))
        return siglen

    elif btc_is_multisig_segwit(privkey_info):
        # bitcoin p2sh-p2wsh script
        # one signature produces (witness script len + num_pubkeys * ~74) + scriptsig len 
        witness_script = privkey_info['redeem_script']
        m, _ = parse_multisig_redeemscript(witness_script)    
        redeem_script = btc_make_p2sh_p2wsh_redeem_script(witness_script)
        
        siglengths = 74 * m
        scriptsig_len = 6 + len(redeem_script) / 2
        witness_len = len(witness_script) / 2 + siglengths
        siglen = int(round(float(3 * scriptsig_len + (scriptsig_len + witness_len)) / 4))

        log.debug("Segwit p2sh-p2wsh private keys make ~{} byte signature".format(siglen))
        return siglen

    raise ValueError("Unrecognized private key foramt")