Example #1
0
def derive_pubkey(message: str, signature: bytes) -> Tuple[bool, bytes]:
    """Derive a public key from a message and signature.

    Return a tuple (is_verified, public_key). The public key, is returned
    as a compressed key.

    If public_key is a null bytestring, it means deriving the public
    key from the signature failed. In this case is_verified is expected
    to be always False.

    If is_verified is True, it only means that this function was able to
    derive a public key from the message and signature. This public key
    still needs to be checked against another key or bitcoin address.
    """
    h = bitcoin.Hash(bitcoin.msg_magic(message.encode("utf-8")))
    try:
        public_key_from_sig, compressed = bitcoin.pubkey_from_signature(
            signature, h)
    except Exception:
        return False, b""

    try:
        is_verified = public_key_from_sig.verify_digest(
            signature[1:], h, sigdecode=ecdsa.util.sigdecode_string)
    except Exception:
        is_verified = False
    return is_verified, public_key_from_sig.to_string(encoding="compressed")
Example #2
0
 def update(self, window):
     wallet = window.wallet
     state = window.cosigner_pool_state
     if not state:
         self.print_error("No cosigner pool state object for window",
                          window.diagnostic_name())
         return
     listener = state.listener
     state.keys = []
     state.cosigner_list = []
     for key, keystore in wallet.keystores.items():
         xpub = keystore.get_master_public_key()
         K = bitcoin.deserialize_xpub(xpub)[-1]
         _hash = bh2u(bitcoin.Hash(K))
         if not keystore.is_watching_only():
             state.keys.append((key, _hash))
         else:
             state.cosigner_list.append((xpub, K, _hash))
     listener.set_keyhashes([t[1] for t in state.keys])
     if not listener.is_running():
         self.print_error("Starting listener for", window.diagnostic_name())
         listener.start()
Example #3
0
 def update(self, window):
     wallet = window.wallet
     if type(wallet) != Multisig_Wallet:
         return
     if self.listener is None:
         self.print_error("starting listener")
         self.listener = Listener(self)
         self.listener.start()
     elif self.listener:
         self.print_error("shutting down listener")
         self.listener.stop()
         self.listener = None
     self.keys = []
     self.cosigner_list = []
     for key, keystore in wallet.keystores.items():
         xpub = keystore.get_master_public_key()
         K = bitcoin.deserialize_xpub(xpub)[-1].encode('hex')
         _hash = bitcoin.Hash(K).encode('hex')
         if not keystore.is_watching_only():
             self.keys.append((key, _hash, window))
         else:
             self.cosigner_list.append((window, xpub, K, _hash))
     if self.listener:
         self.listener.set_keyhashes([t[1] for t in self.keys])