Example #1
0
 def update_signatures(self, raw):
     """Add new signatures to a transaction"""
     d = deserialize(raw)
     for i, txin in enumerate(self.inputs()):
         sigs1 = txin.get('signatures')
         sigs2 = d['inputs'][i].get('signatures')
         for sig in sigs2:
             if sig in sigs1:
                 continue
             for_sig = Hash(self.tx_for_sig(i).decode('hex'))
             # der to string
             order = ecdsa.ecdsa.generator_secp256k1.order()
             r, s = ecdsa.util.sigdecode_der(sig.decode('hex'), order)
             sig_string = ecdsa.util.sigencode_string(r, s, order)
             pubkeys = txin.get('pubkeys')
             compressed = True
             for recid in range(4):
                 public_key = MyVerifyingKey.from_signature(sig_string,
                                                            recid,
                                                            for_sig,
                                                            curve=SECP256k1)
                 pubkey = point_to_ser(public_key.pubkey.point,
                                       compressed).encode('hex')
                 if pubkey in pubkeys:
                     public_key.verify_digest(
                         sig_string,
                         for_sig,
                         sigdecode=ecdsa.util.sigdecode_string)
                     j = pubkeys.index(pubkey)
                     print_error("adding sig", i, j, pubkey, sig)
                     self._inputs[i]['signatures'][j] = sig
                     self._inputs[i]['x_pubkeys'][j] = pubkey
                     break
     # redo raw
     self.raw = self.serialize()
Example #2
0
def verify_message(address, signature, message):
    try:
        EC_KEY.verify_message(address, signature, message)
        return True
    except Exception as e:
        print_error("Verification error: {0}".format(e))
        return False
Example #3
0
 def give_error(self, message, clear_client=False):
     print_error(message)
     if not self.signing:
         self.handler.show_error(message)
     else:
         self.signing = False
     if clear_client:
         self.client = None
     raise Exception(message)
Example #4
0
    def requires_fee(self, wallet):
        # see https://en.bitcoin.it/wiki/Transaction_fees
        #
        # size must be smaller than 1 kbyte for free tx
        size = len(self.serialize(-1)) / 2
        if size >= 10000:
            return True
        # all outputs must be 0.01 BTC or larger for free tx
        for addr, value in self.get_outputs():
            if value < 1000000:
                return True
        # priority must be large enough for free tx
        threshold = 57600000
        weight = 0
        for txin in self.inputs():
            age = wallet.get_confirmations(txin["prevout_hash"])[0]
            weight += txin["value"] * age
        priority = weight / size
        print_error(priority, threshold)

        return priority < threshold
Example #5
0
import sys
import platform

from uwallet.plugins import BasePlugin, hook
from uwallet_gui.qt.util import WaitingDialog, EnterButton, WindowModalDialog
from uwallet.util import print_msg, print_error
from uwallet.i18n import _

from PyQt4.QtGui import *
from PyQt4.QtCore import *

try:
    import amodem.audio
    import amodem.main
    import amodem.config
    print_error('Audio MODEM is available.')
    amodem.log.addHandler(amodem.logging.StreamHandler(sys.stderr))
    amodem.log.setLevel(amodem.logging.INFO)
except ImportError:
    amodem = None
    print_error('Audio MODEM is not found.')


class Plugin(BasePlugin):
    def __init__(self, parent, config, name):
        BasePlugin.__init__(self, parent, config, name)
        if self.is_available():
            self.modem_config = amodem.config.slowest()
            self.library_name = {'Linux': 'libportaudio.so'}[platform.system()]

    def is_available(self):
Example #6
0
def parse_scriptSig(d, bytes):
    try:
        decoded = [x for x in script_GetOp(bytes)]
    except Exception:
        # coinbase transactions raise an exception
        print_error("cannot find address in input script", bytes.encode('hex'))
        return

    # payto_pubkey
    match = [opcodes.OP_PUSHDATA4]
    if match_decoded(decoded, match):
        sig = decoded[0][1].encode('hex')
        d['address'] = "(pubkey)"
        d['signatures'] = [sig]
        d['num_sig'] = 1
        d['x_pubkeys'] = ["(pubkey)"]
        d['pubkeys'] = ["(pubkey)"]
        return

    # non-generated TxIn transactions push a signature
    # (seventy-something bytes) and then their public key
    # (65 bytes) onto the stack:
    match = [opcodes.OP_PUSHDATA4, opcodes.OP_PUSHDATA4]
    if match_decoded(decoded, match):
        sig = decoded[0][1].encode('hex')
        x_pubkey = decoded[1][1].encode('hex')
        try:
            signatures = parse_sig([sig])
            pubkey, address = parse_xpub(x_pubkey)
        except:
            import traceback
            traceback.print_exc(file=sys.stdout)
            print_error("cannot find address in input script",
                        bytes.encode('hex'))
            return
        d['signatures'] = signatures
        d['x_pubkeys'] = [x_pubkey]
        d['num_sig'] = 1
        d['pubkeys'] = [pubkey]
        d['address'] = address
        return

    # p2sh transaction, m of n
    match = [opcodes.OP_0] + [opcodes.OP_PUSHDATA4] * (len(decoded) - 1)
    if not match_decoded(decoded, match):
        print_error("cannot find address in input script", bytes.encode('hex'))
        return
    x_sig = [x[1].encode('hex') for x in decoded[1:-1]]
    dec2 = [x for x in script_GetOp(decoded[-1][1])]
    m = dec2[0][0] - opcodes.OP_1 + 1
    n = dec2[-2][0] - opcodes.OP_1 + 1
    op_m = opcodes.OP_1 + m - 1
    op_n = opcodes.OP_1 + n - 1
    match_multisig = [op_m] + [opcodes.OP_PUSHDATA4] * n + [
        op_n, opcodes.OP_CHECKMULTISIG
    ]
    if not match_decoded(dec2, match_multisig):
        print_error("cannot find address in input script", bytes.encode('hex'))
        return
    x_pubkeys = map(lambda x: x[1].encode('hex'), dec2[1:-2])
    pubkeys = [parse_xpub(x)[0]
               for x in x_pubkeys]  # xpub, addr = parse_xpub()
    redeemScript = Transaction.multisig_script(pubkeys, m)
    # write result in d

    d['num_sig'] = m
    d['signatures'] = parse_sig(x_sig)
    d['x_pubkeys'] = x_pubkeys
    d['pubkeys'] = pubkeys
    d['redeemScript'] = redeemScript
    d['address'] = hash_160_to_bc_address(hash_160(redeemScript.decode('hex')),
                                          5)