Пример #1
0
    def tx_inputs(self, tx, for_sig=False):
        inputs = []
        for txin in tx.inputs:
            txinputtype = self.types.TxInputType()
            if txin.get('is_coinbase'):
                prev_hash = "\0"*32
                prev_index = 0xffffffff  # signed int -1
            else:
                if for_sig:
                    x_pubkeys = txin['x_pubkeys']
                    if len(x_pubkeys) == 1:
                        x_pubkey = x_pubkeys[0]
                        xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
                        xpub_n = self.client_class.expand_path(self.xpub_path[xpub])
                        txinputtype.address_n.extend(xpub_n + s)
                    else:
                        def f(x_pubkey):
                            if is_extended_pubkey(x_pubkey):
                                xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
                            else:
                                xpub = xpub_from_pubkey(x_pubkey.decode('hex'))
                                s = []
                            node = ckd_public.deserialize(xpub)
                            return self.types.HDNodePathType(node=node, address_n=s)
                        pubkeys = map(f, x_pubkeys)
                        multisig = self.types.MultisigRedeemScriptType(
                            pubkeys=pubkeys,
                            signatures=map(lambda x: x.decode('hex') if x else '', txin.get('signatures')),
                            m=txin.get('num_sig'),
                        )
                        txinputtype = self.types.TxInputType(
                            script_type=self.types.SPENDMULTISIG,
                            multisig=multisig
                        )
                        # find which key is mine
                        for x_pubkey in x_pubkeys:
                            if is_extended_pubkey(x_pubkey):
                                xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
                                if xpub in self.xpub_path:
                                    xpub_n = self.client_class.expand_path(self.xpub_path[xpub])
                                    txinputtype.address_n.extend(xpub_n + s)
                                    break

                prev_hash = unhexlify(txin['prevout_hash'])
                prev_index = txin['prevout_n']

            txinputtype.prev_hash = prev_hash
            txinputtype.prev_index = prev_index

            if 'scriptSig' in txin:
                script_sig = txin['scriptSig'].decode('hex')
                txinputtype.script_sig = script_sig

            if 'sequence' in txin:
                sequence = txin['sequence']
                txinputtype.sequence = sequence

            inputs.append(txinputtype)

        return inputs
Пример #2
0
    def tx_inputs(self, tx, for_sig=False):
        inputs = []
        for txin in tx.inputs():
            txinputtype = self.types.TxInputType()
            if txin.get('is_coinbase'):
                prev_hash = "\0"*32
                prev_index = 0xffffffff  # signed int -1
            else:
                if for_sig:
                    x_pubkeys = txin['x_pubkeys']
                    if len(x_pubkeys) == 1:
                        x_pubkey = x_pubkeys[0]
                        xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
                        xpub_n = self.client_class.expand_path(self.xpub_path[xpub])
                        txinputtype.address_n.extend(xpub_n + s)
                    else:
                        def f(x_pubkey):
                            if is_extended_pubkey(x_pubkey):
                                xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
                            else:
                                xpub = xpub_from_pubkey(x_pubkey.decode('hex'))
                                s = []
                            node = self.ckd_public.deserialize(xpub)
                            return self.types.HDNodePathType(node=node, address_n=s)
                        pubkeys = map(f, x_pubkeys)
                        multisig = self.types.MultisigRedeemScriptType(
                            pubkeys=pubkeys,
                            signatures=map(lambda x: x.decode('hex') if x else '', txin.get('signatures')),
                            m=txin.get('num_sig'),
                        )
                        txinputtype = self.types.TxInputType(
                            script_type=self.types.SPENDMULTISIG,
                            multisig=multisig
                        )
                        # find which key is mine
                        for x_pubkey in x_pubkeys:
                            if is_extended_pubkey(x_pubkey):
                                xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
                                if xpub in self.xpub_path:
                                    xpub_n = self.client_class.expand_path(self.xpub_path[xpub])
                                    txinputtype.address_n.extend(xpub_n + s)
                                    break

                prev_hash = unhexlify(txin['prevout_hash'])
                prev_index = txin['prevout_n']

            txinputtype.prev_hash = prev_hash
            txinputtype.prev_index = prev_index

            if 'scriptSig' in txin:
                script_sig = txin['scriptSig'].decode('hex')
                txinputtype.script_sig = script_sig

            if 'sequence' in txin:
                sequence = txin['sequence']
                txinputtype.sequence = sequence

            inputs.append(txinputtype)

        return inputs
Пример #3
0
    def tx_inputs(self, tx, for_sig=False):
        inputs = []
        for txin in tx.inputs:
            txinputtype = types.TxInputType()
            if txin.get("is_coinbase"):
                prev_hash = "\0" * 32
                prev_index = 0xFFFFFFFF  # signed int -1
            else:
                if for_sig:
                    x_pubkeys = txin["x_pubkeys"]
                    if len(x_pubkeys) == 1:
                        x_pubkey = x_pubkeys[0]
                        xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
                        xpub_n = self.get_client().expand_path(self.xpub_path[xpub])
                        txinputtype.address_n.extend(xpub_n + s)
                    else:

                        def f(x_pubkey):
                            if is_extended_pubkey(x_pubkey):
                                xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
                            else:
                                xpub = xpub_from_pubkey(x_pubkey.decode("hex"))
                                s = []
                            node = ckd_public.deserialize(xpub)
                            return types.HDNodePathType(node=node, address_n=s)

                        pubkeys = map(f, x_pubkeys)
                        multisig = types.MultisigRedeemScriptType(
                            pubkeys=pubkeys,
                            signatures=map(lambda x: x.decode("hex") if x else "", txin.get("signatures")),
                            m=txin.get("num_sig"),
                        )
                        txinputtype = types.TxInputType(script_type=types.SPENDMULTISIG, multisig=multisig)
                        # find which key is mine
                        for x_pubkey in x_pubkeys:
                            xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
                            if xpub in self.xpub_path:
                                xpub_n = self.get_client().expand_path(self.xpub_path[xpub])
                                txinputtype.address_n.extend(xpub_n + s)
                                break
                            else:
                                raise

                prev_hash = unhexlify(txin["prevout_hash"])
                prev_index = txin["prevout_n"]

            txinputtype.prev_hash = prev_hash
            txinputtype.prev_index = prev_index

            if "scriptSig" in txin:
                script_sig = txin["scriptSig"].decode("hex")
                txinputtype.script_sig = script_sig

            if "sequence" in txin:
                sequence = txin["sequence"]
                txinputtype.sequence = sequence

            inputs.append(txinputtype)

        return inputs
Пример #4
0
    def tx_inputs(self, tx, for_sig=False):
        inputs = []
        for txinput in tx.inputs:
            txinputtype = types.TxInputType()
            if ('is_coinbase' in txinput and txinput['is_coinbase']):
                prev_hash = "\0"*32
                prev_index = 0xffffffff # signed int -1
            else:

                if for_sig:
                    x_pubkey = txinput['x_pubkeys'][0]
                    xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
                    xpub_n = self.get_client().expand_path(self.xpub_path[xpub])
                    txinputtype.address_n.extend(xpub_n + s)

                prev_hash = unhexlify(txinput['prevout_hash'])
                prev_index = txinput['prevout_n']

            txinputtype.prev_hash = prev_hash
            txinputtype.prev_index = prev_index

            if 'scriptSig' in txinput:
                script_sig = txinput['scriptSig'].decode('hex')
                txinputtype.script_sig = script_sig

            if 'sequence' in txinput:
                sequence = txinput['sequence']
                txinputtype.sequence = sequence

            inputs.append(txinputtype)
            #TODO P2SH
        return inputs
Пример #5
0
 def f(x_pubkey):
     if is_extended_pubkey(x_pubkey):
         xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
     else:
         xpub = xpub_from_pubkey(x_pubkey.decode('hex'))
         s = []
     node = ckd_public.deserialize(xpub)
     return types.HDNodePathType(node=node, address_n=s)
Пример #6
0
 def f(x_pubkey):
     if is_extended_pubkey(x_pubkey):
         xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
     else:
         xpub = xpub_from_pubkey(x_pubkey.decode('hex'))
         s = []
     node = self.ckd_public.deserialize(xpub)
     return self.types.HDNodePathType(node=node, address_n=s)
Пример #7
0
def need_server(wallet, tx):
    from electrum.account import BIP32_Account
    # Detect if the server is needed
    long_id, short_id = wallet.get_user_id()
    xpub3 = wallet.master_public_keys['x3/']
    for x in tx.inputs_to_sign():
        if x[0:2] == 'ff':
            xpub, sequence = BIP32_Account.parse_xpubkey(x)
            if xpub == xpub3:
                return True
    return False
Пример #8
0
 def need_server(self, tx):
     from electrum.account import BIP32_Account
     # Detect if the server is needed
     long_id, short_id = self.get_user_id()
     xpub3 = self.wallet.master_public_keys['x3/']
     for x in tx.inputs_to_sign():
         if x[0:2] == 'ff':
             xpub, sequence = BIP32_Account.parse_xpubkey(x)
             if xpub == xpub3:
                 return True
     return False
Пример #9
0
    def sign_transaction(self, tx, password):
        if tx.is_complete():
            return
        if not self.check_proper_device():
            give_error('Wrong device or password')
        # previous transactions used as inputs
        prev_tx = {}
        # path of the xpubs that are involved
        xpub_path = {}
        for txin in tx.inputs:
            tx_hash = txin['prevout_hash']
            prev_tx[tx_hash] = self.transactions[tx_hash]
            address = txin['address']
            address_path = self.address_id(address)
            account_id, (change, address_index) = self.get_address_index(address)

            for x_pubkey in txin['x_pubkeys']:
                xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
                xpub_path[xpub] = "44'/0'/%s'"%account_id

        self.plugin.sign_transaction(tx, prev_tx, xpub_path)
Пример #10
0
 def can_sign_xpubkey(self, x_pubkey):
     xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey)
     return xpub in self.master_public_keys.values()
Пример #11
0
 def can_sign_xpubkey(self, x_pubkey):
     xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey)
     return xpub in self.master_public_keys.values()
Пример #12
0
 def make_account(self, account_id, password):
     xpub = self.get_public_key(account_id)
     self.add_master_public_key(account_id, xpub)
     account = BIP32_Account({'xpub': xpub})
     return account
Пример #13
0
 def f(x_pubkey):
     xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
     node = ckd_public.deserialize(xpub)
     return types.HDNodePathType(node=node, address_n=s)
Пример #14
0
 def f(x_pubkey):
     xpub, s = BIP32_Account.parse_xpubkey(x_pubkey)
     node = ckd_public.deserialize(xpub)
     return types.HDNodePathType(node=node, address_n=s)