Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
 def need_server(self, tx):
     from electrum_dash.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
Ejemplo n.º 4
0
 def need_server(self, tx):
     from electrum_dash.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
Ejemplo n.º 5
0
 def can_sign_xpubkey(self, x_pubkey):
     xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey)
     return xpub in self.master_public_keys.values()
Ejemplo n.º 6
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
Ejemplo n.º 7
0
 def can_sign_xpubkey(self, x_pubkey):
     xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey)
     return xpub in self.master_public_keys.values()
Ejemplo n.º 8
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