def sign_tx(certificate_metadata, last_input, allowable_wif_prefixes=None): """sign the transaction with private key""" with open(certificate_metadata.unsigned_tx_file_name, 'rb') as in_file: hextx = str(in_file.read(), 'utf-8') logging.info( 'Signing tx with private key for recipient id: %s ...', certificate_metadata.uid) tx = Tx.from_hex(hextx) if allowable_wif_prefixes: wif = wif_to_secret_exponent( helpers.import_key(), allowable_wif_prefixes) else: wif = wif_to_secret_exponent(helpers.import_key()) lookup = build_hash160_lookup([wif]) tx.set_unspents( [TxOut(coin_value=last_input.amount, script=last_input.script_pub_key)]) signed_tx = tx.sign(lookup) signed_hextx = signed_tx.as_hex() with open(certificate_metadata.unsent_tx_file_name, 'wb') as out_file: out_file.write(bytes(signed_hextx, 'utf-8')) logging.info('Finished signing transaction for certificate uid=%s', certificate_metadata.uid)
def sign_tx(certificate_metadata, last_input, allowable_wif_prefixes=None): """sign the transaction with private key""" with open(certificate_metadata.unsigned_tx_file_name, 'rb') as in_file: hextx = str(in_file.read(), 'utf-8') logging.info('Signing tx with private key for recipient id: %s ...', certificate_metadata.uid) tx = Tx.from_hex(hextx) if allowable_wif_prefixes: wif = wif_to_secret_exponent(helpers.import_key(), allowable_wif_prefixes) else: wif = wif_to_secret_exponent(helpers.import_key()) lookup = build_hash160_lookup([wif]) tx.set_unspents([ TxOut(coin_value=last_input.amount, script=last_input.script_pub_key) ]) signed_tx = tx.sign(lookup) signed_hextx = signed_tx.as_hex() with open(certificate_metadata.unsent_tx_file_name, 'wb') as out_file: out_file.write(bytes(signed_hextx, 'utf-8')) logging.info('Finished signing transaction for certificate uid=%s', certificate_metadata.uid)
def sign_tx(hextx, tx_input, allowable_wif_prefixes=None): """ Sign the transaction with private key :param hextx: :param tx_input: :param allowable_wif_prefixes: :return: """ logging.info('Signing tx with private key') tx = Tx.from_hex(hextx) if allowable_wif_prefixes: wif = wif_to_secret_exponent( helpers.import_key(), allowable_wif_prefixes) else: wif = wif_to_secret_exponent(helpers.import_key()) lookup = build_hash160_lookup([wif]) tx.set_unspents( [TxOut(coin_value=tx_input.amount, script=tx_input.script_pub_key)]) signed_tx = tx.sign(lookup) signed_hextx = signed_tx.as_hex() logging.info('Finished signing transaction') return signed_hextx
def sign_certs(certificates_metadata): """Sign certificates. Internet should be off for the scope of this function.""" logging.info('signing certificates') pk = helpers.import_key() secret_key = CBitcoinSecret(pk) for uid, certificate_metadata in certificates_metadata.items(): with open(certificate_metadata.unsigned_certificate_file_name, 'r') as cert_in, \ open(certificate_metadata.signed_certificate_file_name, 'wb') as signed_cert: cert = do_sign(cert_in.read(), secret_key) signed_cert.write(bytes(cert, 'utf-8'))
def sign_certs(certificates): """ Sign certificates. Internet should be off for the scope of this function. :param certificates: :return: """ logging.info('signing certificates') private_key = helpers.import_key() secret_key = CBitcoinSecret(private_key) for _, certificate in certificates.items(): with open(certificate.unsigned_certificate_file_name, 'r') as cert_in, \ open(certificate.signed_certificate_file_name, 'wb') as signed_cert: cert = _sign(cert_in.read(), secret_key) signed_cert.write(bytes(cert, 'utf-8'))
def sign_tx(hex_tx, tx_input): """ Sign the transaction with private key :param hex_tx: :param tx_input: :return: """ logging.info('Signing tx with private key') transaction = Tx.from_hex(hex_tx) wif = wif_to_secret_exponent(helpers.import_key(), ALLOWABLE_WIF_PREFIXES) lookup = build_hash160_lookup([wif]) transaction.set_unspents([TxOut(coin_value=tx_input.coin_value, script=tx_input.script)]) signed_tx = transaction.sign(lookup) logging.info('Finished signing transaction') return signed_tx