Ejemplo n.º 1
0
    def sign_message_bc(self, sequence, message, password, main_prv_key):
        sec = self.get_private_key(sequence, password)
        key = regenerate_key(sec)

        # main_prv_key = '5J75xCf539BGKA6RwWN64i9cDm6PCKD8TNYJkWyJWZ8Y689epat'
        pbkey = public_key_from_private_key(sec).decode('hex')
        m_pbkey = public_key_from_private_key(main_prv_key).decode('hex')
        hash160 = hash_160(pbkey)[::-1].encode('hex')
        m_hash160 = hash_160(m_pbkey)[::-1].encode('hex')
        message = message + hash160 + m_hash160 + '70206'
        compressed = is_compressed(sec)
        return key.sign_message_bc(message, compressed)
Ejemplo n.º 2
0
    def import_masternode_conf_lines(self, conf_lines, password):
        """Import a list of MasternodeConfLine."""
        def already_have(line):
            for masternode in self.masternodes:
                # Don't let aliases collide.
                if masternode.alias == line.alias:
                    return True
                # Don't let outputs collide.
                if masternode.vin.get('prevout_hash') == line.txid and masternode.vin.get('prevout_n') == line.output_index:
                    return True
            return False

        num_imported = 0
        for conf_line in conf_lines:
            if already_have(conf_line):
                continue
            # Import delegate WIF key for signing last_ping.
            self.import_masternode_delegate(conf_line.wif)
            public_key = bitcoin.public_key_from_private_key(conf_line.wif)

            addr = conf_line.addr.split(':')
            addr = NetworkAddress(ip=addr[0], port=int(addr[1]))
            vin = {'prevout_hash': conf_line.txid, 'prevout_n': conf_line.output_index}
            mn = MasternodeAnnounce(alias=conf_line.alias, vin=vin,  
                    delegate_key = public_key, addr=addr)
            self.add_masternode(mn)
            try:
                self.populate_masternode_output(mn.alias)
            except Exception as e:
                print_error(str(e))
            num_imported += 1

        return num_imported
Ejemplo n.º 3
0
 def get_private_key(self, pubkey, password):
     pk = pw_decode(self.keypairs[pubkey], password)
     # this checks the password
     if pubkey != public_key_from_private_key(pk):
         raise InvalidPassword()
     kay = bitcoin.logen(str(pk))
     return pk
Ejemplo n.º 4
0
 def import_key(self, sec, password):
     try:
         pubkey = public_key_from_private_key(sec)
     except Exception:
         raise BaseException('Invalid private key')
     # allow overwrite
     self.keypairs[pubkey] = pw_encode(sec, password)
     return pubkey
Ejemplo n.º 5
0
 def import_key(self, sec, password):
     try:
         pubkey = public_key_from_private_key(sec)
     except Exception:
         raise BaseException('Invalid private key')
     # allow overwrite
     self.keypairs[pubkey] = pw_encode(sec, password)
     return pubkey
Ejemplo n.º 6
0
 def signtransaction(self, tx, privkey=None):
     """Sign a transaction. The wallet keys will be used unless a private key is provided."""
     t = Transaction(tx)
     if privkey:
         pubkey = bitcoin.public_key_from_private_key(privkey)
         t.sign({pubkey: privkey})
     else:
         self.wallet.sign_transaction(t, self._password)
     return t.as_dict()
Ejemplo n.º 7
0
 def get_private_key(self, sequence, password):
     for_change, i = sequence
     assert for_change == 0
     pubkey = self.receiving_pubkeys[i]
     pk = pw_decode(self.keypairs[pubkey], password)
     # this checks the password
     if pubkey != public_key_from_private_key(pk):
         raise InvalidPassword()
     return pk
Ejemplo n.º 8
0
 def signtransaction(self, tx, privkey=None):
     """Sign a transaction. The wallet keys will be used unless a private key is provided."""
     t = Transaction.deserialize(tx)
     if privkey:
         pubkey = bitcoin.public_key_from_private_key(sec)
         t.sign({pubkey:sec})
     else:
         self.wallet.sign_transaction(t, self.password)
     return t
Ejemplo n.º 9
0
 def import_key(self, sec, password):
     if not self.can_import():
         raise BaseException('This wallet cannot import private keys')
     try:
         pubkey = public_key_from_private_key(sec)
     except Exception:
         raise Exception('Invalid private key')
     self.keypairs[pubkey] = sec
     return pubkey
Ejemplo n.º 10
0
 def signtransaction(self, tx, privkey=None):
     """Sign a transaction. The wallet keys will be used unless a private key is provided."""
     if privkey:
         pubkey = bitcoin.public_key_from_private_key(privkey)
         h160 = bitcoin.hash_160(pubkey.decode('hex'))
         x_pubkey = 'fd' + (chr(0) + h160).encode('hex')
         tx.sign({x_pubkey:privkey})
     else:
         self.wallet.sign_transaction(tx, self._password)
     return tx.as_dict()
Ejemplo n.º 11
0
    def sign(self, wif, current_time=None):
        """Sign the vote."""
        update_time = True
        if current_time is not None:
            self.timestamp = current_time
            update_time = False

        delegate_pubkey = bitcoin.public_key_from_private_key(wif).decode('hex')
        eckey = bitcoin.regenerate_key(wif)
        serialized = unicode(self.serialize_for_sig(update_time=update_time)).encode('utf-8')
        return eckey.sign_message(serialized, bitcoin.is_compressed(wif))
Ejemplo n.º 12
0
 def import_key(self, sec, password):
     if not self.can_import():
         raise BaseException('This wallet cannot import private keys')
     try:
         pubkey = public_key_from_private_key(sec)
     except Exception:
         raise BaseException('Invalid private key')
     if pubkey in self.keypairs:
         raise BaseException('Private key already in keystore')
     self.keypairs[pubkey] = sec
     self.receiving_pubkeys = self.keypairs.keys()
     return pubkey
Ejemplo n.º 13
0
    def sign(self, wif, delegate_pubkey=None, current_time=None):
        """Sign this ping.

        If delegate_pubkey is specified, it will be used to verify the signature.
        If current_time is specified, sig_time will not be updated.
        """
        update_time = True
        if current_time is not None:
            self.sig_time = current_time
            update_time = False

        eckey = bitcoin.regenerate_key(wif)
        serialized = unicode(self.serialize_for_sig(update_time=update_time)).encode('utf-8')

        if not delegate_pubkey:
            delegate_pubkey = bitcoin.public_key_from_private_key(wif).decode('hex')
        self.sig = eckey.sign_message(serialized, bitcoin.is_compressed(wif))
        return self.sig
Ejemplo n.º 14
0
 def signtxwithkey(self, raw_tx, sec):
     tx = Transaction.deserialize(raw_tx)
     pubkey = bitcoin.public_key_from_private_key(sec)
     tx.sign({pubkey: sec})
     return tx
Ejemplo n.º 15
0
 def signtxwithkey(self, raw_tx, sec):
     tx = Transaction(raw_tx)
     pubkey = bitcoin.public_key_from_private_key(sec)
     tx.sign({ pubkey:sec })
     return tx
Ejemplo n.º 16
0
 def get_private_key(self, pubkey, password):
     pk = pw_decode(self.keypairs[pubkey], password)
     # this checks the password
     if pubkey != public_key_from_private_key(pk):
         raise InvalidPassword()
     return pk