Exemplo n.º 1
0
 def _verifying_key_from_pubkey(cls, pubkey):
     """ Converts a 33-byte compressed pubkey into an coincurve.PublicKey object. """
     if not isinstance(pubkey, (bytes, bytearray)):
         raise TypeError('pubkey must be raw bytes')
     if len(pubkey) != 33:
         raise ValueError('pubkey must be 33 bytes')
     if pubkey[0] not in (2, 3):
         raise ValueError('invalid pubkey prefix byte')
     return cPublicKey(pubkey)
Exemplo n.º 2
0
 def is_signature_valid(signature, digest, public_key_bytes):
     signature = cdata_to_der(deserialize_compact(signature))
     public_key = cPublicKey(public_key_bytes)
     is_valid = public_key.verify(signature, digest, None)
     if not is_valid:  # try old way
         # ytsync signed claims don't seem to validate with coincurve
         try:
             pk = ec.EllipticCurvePublicKey.from_encoded_point(
                 ec.SECP256K1(), public_key_bytes)
             pk.verify(signature, digest,
                       ec.ECDSA(Prehashed(hashes.SHA256())))
             return True
         except (ValueError, InvalidSignature):
             pass
     return is_valid
Exemplo n.º 3
0
 def public_key_bytes(self) -> bytes:
     if len(self.message.public_key) == 33:
         return self.message.public_key
     public_key_info = PublicKeyInfo.load(self.message.public_key)
     public_key = cPublicKey(public_key_info.native['public_key'])
     return public_key.format(compressed=True)